Move Notarius path and executable resolution into its adapter
This commit is contained in:
@@ -70,7 +70,8 @@ factories for all enabled readiness checks. See
|
|||||||
|
|
||||||
Notarius is composed only when extraction is enabled. The stage resolves
|
Notarius is composed only when extraction is enabled. The stage resolves
|
||||||
prepared references and promotes configured products; the adapter builds native
|
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.
|
Force selects native cache refresh before request construction.
|
||||||
Its request may also carry already-resolved ConfigKit secret references.
|
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
|
Audita and Scriptorium requests carry the same kind of list. All three adapters use the shared
|
||||||
|
|||||||
@@ -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
|
remediation. Shared code does not make a refactoring a prerequisite or assign
|
||||||
the whole finding to a roadmap.
|
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,
|
planning, prerequisite-history, publication-import, CLI classification,
|
||||||
inspection aggregation, test maintenance, dead-code removal, and associated
|
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
|
an agreed remedy awaiting implementation. **Potentially eliminated** requires verification that the offending
|
||||||
lifecycle is removed. **Coordinate** identifies shared changes, not a commitment
|
lifecycle is removed. **Coordinate** identifies shared changes, not a commitment
|
||||||
that a related feature implements the entire finding. Findings close only after their
|
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
|
### 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).
|
Original findings: [BN-02](11-boundaries.md#bn-02--p3-notarius-output-protocol-translation-partly-lives-in-stage-orchestration).
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
## 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).
|
Read [BN-02](audit/11-boundaries.md#bn-02--p3-notarius-output-protocol-translation-partly-lives-in-stage-orchestration).
|
||||||
|
|
||||||
|
|||||||
37
internal/adapters/notarius/paths.go
Normal file
37
internal/adapters/notarius/paths.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
38
internal/adapters/notarius/paths_test.go
Normal file
38
internal/adapters/notarius/paths_test.go
Normal file
@@ -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")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -91,7 +90,7 @@ func (extractStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (re
|
|||||||
if err != nil || timeout <= 0 {
|
if err != nil || timeout <= 0 {
|
||||||
return nil, fmt.Errorf("extract: invalid notarius timeout %q", notariusConfig.Timeout)
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("extract: resolve notarius binary: %w", err)
|
return nil, fmt.Errorf("extract: resolve notarius binary: %w", err)
|
||||||
}
|
}
|
||||||
@@ -310,14 +309,6 @@ func extractionFingerprint(
|
|||||||
return hex.EncodeToString(digest[:]), nil
|
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) {
|
func absolutePath(value string) (string, error) {
|
||||||
trimmed := strings.TrimSpace(value)
|
trimmed := strings.TrimSpace(value)
|
||||||
if trimmed == "" {
|
if trimmed == "" {
|
||||||
|
|||||||
@@ -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) {
|
func TestNativeExtractionReportsPartialPromotionFailure(t *testing.T) {
|
||||||
env, m, fake := nativeExtractFixture(t)
|
env, m, fake := nativeExtractFixture(t)
|
||||||
env.Config.Pipeline.Notarius.Outputs = map[string]config.NotariusOutputConfig{"alpha": {LaneID: "alpha"}, "zeta": {LaneID: "zeta"}}
|
env.Config.Pipeline.Notarius.Outputs = map[string]config.NotariusOutputConfig{"alpha": {LaneID: "alpha"}, "zeta": {LaneID: "zeta"}}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ func BuildNotariusReadiness(cfg *config.Config, paths artifacts.SessionPaths, m
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return NotariusReadiness{}, err
|
return NotariusReadiness{}, err
|
||||||
}
|
}
|
||||||
binary, err := resolveExecutable(n.Binary)
|
binary, err := notarius.ResolveExecutable(n.Binary)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return NotariusReadiness{}, fmt.Errorf("resolve Notarius binary: %w", err)
|
return NotariusReadiness{}, fmt.Errorf("resolve Notarius binary: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,31 +7,16 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/notarius"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/fileops"
|
"gitea.maximumdirect.net/eric/narratio/internal/fileops"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/pathsafe"
|
"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 {
|
type stagedNotariusLane struct {
|
||||||
Key, LaneID, Filename, StagedPath, Checksum string
|
Key, LaneID, Filename, StagedPath, Checksum string
|
||||||
Size int64
|
Size int64
|
||||||
@@ -67,7 +52,7 @@ func stageRequiredNotariusLanes(bundle, staging string, required map[string]conf
|
|||||||
laneOwners, filenameOwners := map[string]string{}, map[string]string{}
|
laneOwners, filenameOwners := map[string]string{}, map[string]string{}
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
output := required[key]
|
output := required[key]
|
||||||
relative, err := notariusLanePath(output.LaneID)
|
relative, err := notarius.LaneRelativePath(output.LaneID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,23 @@
|
|||||||
package stage
|
package stage
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNotariusLanePath(t *testing.T) {
|
func TestNativeExtractionRejectsMappedLaneCollisions(t *testing.T) {
|
||||||
for _, test := range []struct{ id, want string }{
|
staging, bundle := t.TempDir(), t.TempDir()
|
||||||
{"npc-registry", "lanes/npc-registry.json"},
|
if err := os.Mkdir(filepath.Join(bundle, "lanes"), 0o755); err != nil {
|
||||||
{" a/b..c ", "lanes/a_b__c.json"},
|
t.Fatal(err)
|
||||||
{"._...", ""},
|
|
||||||
} {
|
|
||||||
got, err := notariusLanePath(test.id)
|
|
||||||
if got != test.want || (err != nil) != (test.want == "") {
|
|
||||||
t.Errorf("notariusLanePath(%q) = %q, %v", test.id, got, 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user