diff --git a/docs/internal/adapters.md b/docs/internal/adapters.md index e5b374c..6473c94 100644 --- a/docs/internal/adapters.md +++ b/docs/internal/adapters.md @@ -70,7 +70,8 @@ factories for all enabled readiness checks. See Notarius is composed only when extraction is enabled. The stage resolves prepared references and promotes configured products; the adapter builds native -inspection, preflight, and run commands and validates the completion report. +inspection, preflight, and run commands, resolves the executable and native +lane paths, and validates the completion report. Force selects native cache refresh before request construction. Its request may also carry already-resolved ConfigKit secret references. Audita and Scriptorium requests carry the same kind of list. All three adapters use the shared diff --git a/docs/roadmap/audit/catalog.md b/docs/roadmap/audit/catalog.md index cfa1e28..3414334 100644 --- a/docs/roadmap/audit/catalog.md +++ b/docs/roadmap/audit/catalog.md @@ -41,10 +41,10 @@ their scope. Unless assigned otherwise, a finding remains independent audit remediation. Shared code does not make a refactoring a prerequisite or assign the whole finding to a roadmap. -Thirty-four entries are closed by the safety, transfer, audio discovery, S3 +Thirty-five entries are closed by the safety, transfer, audio discovery, S3 planning, prerequisite-history, publication-import, CLI classification, inspection aggregation, test maintenance, dead-code removal, and associated -documentation work; 9 remain open. **Planned** identifies +documentation work; 8 remain open. **Planned** identifies an agreed remedy awaiting implementation. **Potentially eliminated** requires verification that the offending lifecycle is removed. **Coordinate** identifies shared changes, not a commitment that a related feature implements the entire finding. Findings close only after their @@ -682,7 +682,10 @@ representative adapter/consumer tests. ### CAT-23 — P3: Move Notarius native output mapping and executable lookup to their boundary -Status: Open +Status: Closed + +**Closure.** The Notarius adapter resolves native lane paths and executable +selection; stage promotion, collision and readiness tests remain in place. Original findings: [BN-02](11-boundaries.md#bn-02--p3-notarius-output-protocol-translation-partly-lives-in-stage-orchestration). diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index 0db7f01..117eab2 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -467,7 +467,7 @@ Validation: `go test ./internal/fileops ./internal/artifacts ./internal/stage ./ ## Stage 16: Put Notarius Native Mapping And Launch Resolution In Its Adapter -CAT IDs: CAT-23. Status: Pending. +CAT IDs: CAT-23. Status: Complete. Read [BN-02](audit/11-boundaries.md#bn-02--p3-notarius-output-protocol-translation-partly-lives-in-stage-orchestration). diff --git a/internal/adapters/notarius/paths.go b/internal/adapters/notarius/paths.go new file mode 100644 index 0000000..4ae09c7 --- /dev/null +++ b/internal/adapters/notarius/paths.go @@ -0,0 +1,37 @@ +package notarius + +import ( + "fmt" + "os/exec" + "path/filepath" + "regexp" + "strings" +) + +var unsafeLaneCharacters = regexp.MustCompile(`[^a-zA-Z0-9._-]`) + +// LaneRelativePath maps a native lane identifier to its bundle-relative JSON path. +func LaneRelativePath(laneID string) (string, error) { + name := unsafeLaneCharacters.ReplaceAllString(strings.TrimSpace(laneID), "_") + for strings.Contains(name, "..") { + name = strings.ReplaceAll(name, "..", "__") + } + name = strings.Trim(name, "._") + if name == "" { + return "", fmt.Errorf("notarius lane ID %q cannot produce a filename", laneID) + } + return "lanes/" + name + ".json", nil +} + +// ResolveExecutable resolves an explicit binary or PATH entry to an absolute path. +func ResolveExecutable(value string) (string, error) { + resolved, err := exec.LookPath(strings.TrimSpace(value)) + if err != nil { + return "", err + } + resolved, err = filepath.Abs(strings.TrimSpace(resolved)) + if err != nil { + return "", err + } + return filepath.Clean(resolved), nil +} diff --git a/internal/adapters/notarius/paths_test.go b/internal/adapters/notarius/paths_test.go new file mode 100644 index 0000000..30f9c37 --- /dev/null +++ b/internal/adapters/notarius/paths_test.go @@ -0,0 +1,38 @@ +package notarius + +import ( + "os" + "path/filepath" + "testing" +) + +func TestLaneRelativePath(t *testing.T) { + for _, test := range []struct{ id, want string }{ + {"npc-registry", "lanes/npc-registry.json"}, + {" a/b..c ", "lanes/a_b__c.json"}, + {"._...", ""}, + } { + got, err := LaneRelativePath(test.id) + if got != test.want || (err != nil) != (test.want == "") { + t.Errorf("LaneRelativePath(%q) = %q, %v", test.id, got, err) + } + } +} + +func TestResolveExecutableUsesExplicitPathAndSearchPath(t *testing.T) { + dir := t.TempDir() + binary := filepath.Join(dir, "notarius-test") + if err := os.WriteFile(binary, []byte("#!/bin/sh\nexit 0\n"), 0755); err != nil { + t.Fatal(err) + } + t.Setenv("PATH", dir) + for _, value := range []string{binary, "notarius-test"} { + got, err := ResolveExecutable(value) + if err != nil || got != binary { + t.Fatalf("resolve %q = %q, %v", value, got, err) + } + } + if _, err := ResolveExecutable("missing-notarius"); err == nil { + t.Fatal("missing binary was accepted") + } +} diff --git a/internal/stage/extract.go b/internal/stage/extract.go index 26d4a63..1da153e 100644 --- a/internal/stage/extract.go +++ b/internal/stage/extract.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "os" - "os/exec" "path/filepath" "sort" "strings" @@ -91,7 +90,7 @@ func (extractStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (re if err != nil || timeout <= 0 { return nil, fmt.Errorf("extract: invalid notarius timeout %q", notariusConfig.Timeout) } - resolvedBinary, err := resolveExecutable(notariusConfig.Binary) + resolvedBinary, err := notarius.ResolveExecutable(notariusConfig.Binary) if err != nil { return nil, fmt.Errorf("extract: resolve notarius binary: %w", err) } @@ -310,14 +309,6 @@ func extractionFingerprint( return hex.EncodeToString(digest[:]), nil } -func resolveExecutable(value string) (string, error) { - resolved, err := exec.LookPath(strings.TrimSpace(value)) - if err != nil { - return "", err - } - return absolutePath(resolved) -} - func absolutePath(value string) (string, error) { trimmed := strings.TrimSpace(value) if trimmed == "" { diff --git a/internal/stage/extract_native_test.go b/internal/stage/extract_native_test.go index 8661638..4b468e8 100644 --- a/internal/stage/extract_native_test.go +++ b/internal/stage/extract_native_test.go @@ -291,20 +291,6 @@ func TestNativeExtractionReuseIdentityIgnoresCacheAndDebug(t *testing.T) { } } -func TestNativeExtractionRejectsMappedLaneCollisions(t *testing.T) { - staging, bundle := t.TempDir(), t.TempDir() - if err := os.Mkdir(filepath.Join(bundle, "lanes"), 0o755); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(bundle, "lanes", "a_b.json"), []byte(`{}`), 0o644); err != nil { - t.Fatal(err) - } - required := map[string]config.NotariusOutputConfig{"first": {LaneID: "a/b"}, "second": {LaneID: "a?b"}} - if _, err := stageRequiredNotariusLanes(bundle, staging, required); err == nil || !strings.Contains(err.Error(), "same file") { - t.Fatalf("collision error = %v", err) - } -} - func TestNativeExtractionReportsPartialPromotionFailure(t *testing.T) { env, m, fake := nativeExtractFixture(t) env.Config.Pipeline.Notarius.Outputs = map[string]config.NotariusOutputConfig{"alpha": {LaneID: "alpha"}, "zeta": {LaneID: "zeta"}} diff --git a/internal/stage/extract_preflight.go b/internal/stage/extract_preflight.go index 6313757..6a7ba7b 100644 --- a/internal/stage/extract_preflight.go +++ b/internal/stage/extract_preflight.go @@ -63,7 +63,7 @@ func BuildNotariusReadiness(cfg *config.Config, paths artifacts.SessionPaths, m if err != nil { return NotariusReadiness{}, err } - binary, err := resolveExecutable(n.Binary) + binary, err := notarius.ResolveExecutable(n.Binary) if err != nil { return NotariusReadiness{}, fmt.Errorf("resolve Notarius binary: %w", err) } diff --git a/internal/stage/notarius_lanes.go b/internal/stage/notarius_lanes.go index 12eb587..8924e3e 100644 --- a/internal/stage/notarius_lanes.go +++ b/internal/stage/notarius_lanes.go @@ -7,31 +7,16 @@ import ( "fmt" "os" "path/filepath" - "regexp" "sort" "strings" + "gitea.maximumdirect.net/eric/narratio/internal/adapters/notarius" "gitea.maximumdirect.net/eric/narratio/internal/artifacts" "gitea.maximumdirect.net/eric/narratio/internal/config" "gitea.maximumdirect.net/eric/narratio/internal/fileops" "gitea.maximumdirect.net/eric/narratio/internal/pathsafe" ) -var notariusUnsafeLaneCharacters = regexp.MustCompile(`[^a-zA-Z0-9._-]`) - -// notariusLanePath follows the documented Notarius lane filename mapping. -func notariusLanePath(laneID string) (string, error) { - name := notariusUnsafeLaneCharacters.ReplaceAllString(strings.TrimSpace(laneID), "_") - for strings.Contains(name, "..") { - name = strings.ReplaceAll(name, "..", "__") - } - name = strings.Trim(name, "._") - if name == "" { - return "", fmt.Errorf("notarius lane ID %q cannot produce a filename", laneID) - } - return "lanes/" + name + ".json", nil -} - type stagedNotariusLane struct { Key, LaneID, Filename, StagedPath, Checksum string Size int64 @@ -67,7 +52,7 @@ func stageRequiredNotariusLanes(bundle, staging string, required map[string]conf laneOwners, filenameOwners := map[string]string{}, map[string]string{} for _, key := range keys { output := required[key] - relative, err := notariusLanePath(output.LaneID) + relative, err := notarius.LaneRelativePath(output.LaneID) if err != nil { return nil, err } diff --git a/internal/stage/notarius_lanes_test.go b/internal/stage/notarius_lanes_test.go index c67782c..eb43841 100644 --- a/internal/stage/notarius_lanes_test.go +++ b/internal/stage/notarius_lanes_test.go @@ -1,16 +1,23 @@ package stage -import "testing" +import ( + "gitea.maximumdirect.net/eric/narratio/internal/config" + "os" + "path/filepath" + "strings" + "testing" +) -func TestNotariusLanePath(t *testing.T) { - for _, test := range []struct{ id, want string }{ - {"npc-registry", "lanes/npc-registry.json"}, - {" a/b..c ", "lanes/a_b__c.json"}, - {"._...", ""}, - } { - got, err := notariusLanePath(test.id) - if got != test.want || (err != nil) != (test.want == "") { - t.Errorf("notariusLanePath(%q) = %q, %v", test.id, got, err) - } +func TestNativeExtractionRejectsMappedLaneCollisions(t *testing.T) { + staging, bundle := t.TempDir(), t.TempDir() + if err := os.Mkdir(filepath.Join(bundle, "lanes"), 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(bundle, "lanes", "a_b.json"), []byte(`{}`), 0o644); err != nil { + t.Fatal(err) + } + required := map[string]config.NotariusOutputConfig{"first": {LaneID: "a/b"}, "second": {LaneID: "a?b"}} + if _, err := stageRequiredNotariusLanes(bundle, staging, required); err == nil || !strings.Contains(err.Error(), "same file") { + t.Fatalf("collision error = %v", err) } }