add appended .md unconditionally, so openapi.json became openapi.json.md. Reported from use against a repository that publishes an OpenAPI document beside its prose. It is now supplied only when the name carries no extension of its own. Two consequences came with it that the report could not have seen. A facet's name was built by stripping the extension, so openapi.json would have taken openapi.usages.md and collided with the facet for a sibling openapi.md; only a trailing .md is stripped now. And the unlocked walk matched *.md only, so a hand-fetched .json under .loom/externals was adopted, unlocked, and invisible to check; it now walks everything that is not the lock file or a dotfile. The assumption was never decided, it was typed. externals says a repository publishes documents and publication says prose in whatever form its readers need. Neither says markdown and three places in this tool did. Also records that the wrong diagnosis cost more than the bug: the repository is private, a scratch config with no token made every fetch look broken, and loomctl config would have said so in one line. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018UTxuSizozEA8yDitPuris
113 lines
3.0 KiB
Go
113 lines
3.0 KiB
Go
package external
|
|
|
|
import (
|
|
"path"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestLocalPath(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name, url, want string
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "gitea raw, published document",
|
|
url: "https://git.hypertheory-labs.dev/loom/bedrock/raw/branch/main/.loom/published/starting.md",
|
|
want: "git.hypertheory-labs.dev/loom/bedrock/starting.md",
|
|
},
|
|
{
|
|
name: "github raw host",
|
|
url: "https://raw.githubusercontent.com/octocat/Hello-World/main/README.md",
|
|
want: "raw.githubusercontent.com/octocat/Hello-World/README.md",
|
|
},
|
|
{
|
|
name: "not enough path to name an owner and repository",
|
|
url: "https://example.com/thing.md",
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "not absolute",
|
|
url: "/loom/bedrock/starting.md",
|
|
wantErr: true,
|
|
},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
got, err := localPath(tc.url)
|
|
if tc.wantErr {
|
|
if err == nil {
|
|
t.Fatalf("localPath(%q) = %q, want an error", tc.url, got)
|
|
}
|
|
return
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("localPath(%q): %v", tc.url, err)
|
|
}
|
|
if got != tc.want {
|
|
t.Errorf("localPath(%q) = %q, want %q", tc.url, got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestIsFacet(t *testing.T) {
|
|
// A facet is something we wrote beside an adopted document. check must not
|
|
// report our own writing as an unlocked external.
|
|
facets := []string{
|
|
"host/loom/cart/cart.usages.md",
|
|
"host/loom/externals/externals.gaps.md",
|
|
"host/o/r/plan.notes.md",
|
|
}
|
|
documents := []string{
|
|
"host/loom/cart/cart.md",
|
|
"host/loom/bedrock/recording-decisions.md", // a hyphen is not a facet
|
|
"host/o/r/starting.md",
|
|
}
|
|
for _, p := range facets {
|
|
if !isFacet(p) {
|
|
t.Errorf("isFacet(%q) = false, want true", p)
|
|
}
|
|
}
|
|
for _, p := range documents {
|
|
if isFacet(p) {
|
|
t.Errorf("isFacet(%q) = true, want false", p)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPublishedNameExtension(t *testing.T) {
|
|
// A published surface is not only markdown, and .md must never be appended
|
|
// to a name that already carries an extension of its own.
|
|
for _, tc := range []struct{ in, want string }{
|
|
{"cart", "cart.md"},
|
|
{"cart.md", "cart.md"},
|
|
{"recovering-data", "recovering-data.md"},
|
|
{"openapi.json", "openapi.json"},
|
|
{"entitlement-examples.json", "entitlement-examples.json"},
|
|
} {
|
|
got := tc.in
|
|
if path.Ext(got) == "" {
|
|
got += ".md"
|
|
}
|
|
if got != tc.want {
|
|
t.Errorf("%q -> %q, want %q", tc.in, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestFacetNameKeepsANonMarkdownExtension(t *testing.T) {
|
|
// openapi.json.usages.md, never openapi.usages.md — which would collide with
|
|
// the facet for a sibling openapi.md.
|
|
for _, tc := range []struct{ doc, want string }{
|
|
{"h/o/r/cart.md", "h/o/r/cart.usages.md"},
|
|
{"h/o/r/openapi.json", "h/o/r/openapi.json.usages.md"},
|
|
} {
|
|
if got := strings.TrimSuffix(tc.doc, ".md") + ".usages.md"; got != tc.want {
|
|
t.Errorf("facet for %q = %q, want %q", tc.doc, got, tc.want)
|
|
}
|
|
}
|
|
if !isFacet("h/o/r/openapi.json.usages.md") {
|
|
t.Error("a facet beside a non-markdown document should still read as a facet")
|
|
}
|
|
}
|