diff --git a/docs/roadmap/remediation.md b/docs/roadmap/remediation.md index 67dc18d..83cfac8 100644 --- a/docs/roadmap/remediation.md +++ b/docs/roadmap/remediation.md @@ -146,7 +146,13 @@ CLI syntax compatibility. **Priority:** P2 -**Status:** Pending +**Status:** Complete + +Shared session-relative identity now covers fingerprints, checkpoints, catalog +evidence, publication defaults, and restore fallback mapping. Configuration +remains unchanged. Verified equivalent-path reuse, forced generation with a +dependent artifact, portable records, publication mapping, confined paths, and +committed restore with focused stage/artifact/policy/application tests. **Stages:** 10 and 16; analysis reuse and lifecycle integration in 18–19 and 21. diff --git a/internal/app/restore_commit_test.go b/internal/app/restore_commit_test.go index 0fb695b..8b47771 100644 --- a/internal/app/restore_commit_test.go +++ b/internal/app/restore_commit_test.go @@ -77,6 +77,26 @@ func TestCommittedRestoreInstallsPreparedInputsAndFlatProducts(t *testing.T) { } } +func TestCommittedRestoreUsesAbsoluteConfiguredProductDestination(t *testing.T) { + cfg := restorePlanConfig(t) + root := artifacts.SessionWorkDirForCampaign(cfg.Pipeline.Workspace.Root, cfg.Session.Campaign, cfg.Session.SessionID) + cfg.ArtifactCatalog = &config.ArtifactCatalog{Artifacts: map[string]config.ScriptoriumArtifactConfig{ + "session_recap": {Enabled: true, OutputPath: filepath.Join(root, "artifacts", "session_recap.md")}, + }} + fake := &storage.FakeBackend{} + current := seedCommittedRestoreSnapshot(t, cfg, fake, "20260519T010203Z-a1b2c3d4", map[string][]byte{ + "artifacts/session_recap.md": []byte("recap"), + }) + plan, err := buildRestorePlan(context.Background(), cfg, current, fake, RestorePlanOptions{}) + if err != nil { + t.Fatal(err) + } + if _, err := executeRestorePlan(context.Background(), cfg, current, plan, nil, fake); err != nil { + t.Fatal(err) + } + mustReadEquals(t, filepath.Join(root, "artifacts", "session_recap.md"), "recap") +} + func TestCommittedRestoreDoesNotRequirePolishRunDiagnostics(t *testing.T) { cfg := restorePlanConfig(t) fake := &storage.FakeBackend{} diff --git a/internal/app/restore_plan.go b/internal/app/restore_plan.go index 2f40834..39a9dec 100644 --- a/internal/app/restore_plan.go +++ b/internal/app/restore_plan.go @@ -253,7 +253,11 @@ func restoreProductRelativePath(cfg *config.Config, m *manifest.Manifest, destin return "", err } if entry, ok := catalog.Lookup(source); ok { - result = filepath.ToSlash(entry.CanonicalRelPath) + relative, err := artifacts.ProductRelativePath(destinationRoot, entry.CanonicalRelPath) + if err != nil { + return "", err + } + result = relative parts := strings.Split(result, "/") if len(parts) != 2 || (parts[0] != config.PathArtifactsDirSegment && parts[0] != config.PathTranscriptsSegment) || parts[1] == "" || parts[1] == "." || parts[1] == ".." { return "", fmt.Errorf("configured product path %q is not flat", result) diff --git a/internal/artifactpolicy/policy.go b/internal/artifactpolicy/policy.go index 970d3bc..177d26f 100644 --- a/internal/artifactpolicy/policy.go +++ b/internal/artifactpolicy/policy.go @@ -3,6 +3,7 @@ package artifactpolicy import ( "errors" "fmt" + "path/filepath" "regexp" "strings" @@ -340,6 +341,9 @@ func DeriveDefaultPublishedDestination(source Source, configured map[string]stri if strings.TrimSpace(outputPath) == "" { return "", fmt.Errorf("pipeline.scriptorium.artifacts.%s.output_path is empty", source.ConfiguredKey) } + if filepath.IsAbs(outputPath) { + outputPath = filepath.Join("artifacts", filepath.Base(outputPath)) + } return pathsafe.NormalizeRelativeDestination(outputPath) default: return "", fmt.Errorf("publish destination cannot be derived from source %q", source.ID) diff --git a/internal/artifacts/analyze_evidence.go b/internal/artifacts/analyze_evidence.go index c0e4623..2c26071 100644 --- a/internal/artifacts/analyze_evidence.go +++ b/internal/artifacts/analyze_evidence.go @@ -11,7 +11,6 @@ import ( "gitea.maximumdirect.net/eric/narratio/internal/artifactmodel" "gitea.maximumdirect.net/eric/narratio/internal/manifest" - "gitea.maximumdirect.net/eric/narratio/internal/pathsafe" ) // AnalyzeEvidenceState distinguishes a verified current configured artifact @@ -74,7 +73,7 @@ func InspectAnalyzeEvidence( return nonCurrent("configured artifact manifest evidence is malformed; regenerate the artifact") } - configuredPath, err := pathsafe.NormalizeRelativeDestination(strings.TrimSpace(configured.OutputPath)) + configuredPath, err := ProductRelativePath(paths.Root, configured.OutputPath) if err != nil { return nonCurrent("configured artifact output path is unsafe; correct the configuration") } @@ -136,6 +135,13 @@ func (c *ArtifactCatalog) HydrateAnalyzeArtifacts( if evidence.State != AnalyzeEvidenceCurrent { continue } + relative, err := ProductRelativePath(paths.Root, evidence.Path) + if err != nil { + continue + } + entry := c.entries[evidence.SourceID] + entry.CanonicalRelPath = relative + c.entries[evidence.SourceID] = entry _ = c.markAvailableFromAnalyzeManifest( evidence.SourceID, evidence.Path, evidence.ProducerRunID, evidence.Checksum, evidence.Size, evidence.Contract, diff --git a/internal/artifacts/product_path.go b/internal/artifacts/product_path.go new file mode 100644 index 0000000..a85a5f2 --- /dev/null +++ b/internal/artifacts/product_path.go @@ -0,0 +1,22 @@ +package artifacts + +import ( + "path/filepath" + "strings" + + "gitea.maximumdirect.net/eric/narratio/internal/pathsafe" +) + +// ProductRelativePath derives portable identity without changing configuration. +// Configuration validation separately enforces the product's flat category. +func ProductRelativePath(sessionRoot, configured string) (string, error) { + value := strings.TrimSpace(configured) + if filepath.IsAbs(value) { + root, err := filepath.Abs(sessionRoot) + if err != nil { + return "", err + } + return pathsafe.SlashRelativeFromRoot(root, value) + } + return pathsafe.NormalizeRelativeDestination(filepath.ToSlash(value)) +} diff --git a/internal/artifacts/product_path_test.go b/internal/artifacts/product_path_test.go new file mode 100644 index 0000000..1036e0e --- /dev/null +++ b/internal/artifacts/product_path_test.go @@ -0,0 +1,19 @@ +package artifacts + +import ( + "path/filepath" + "testing" +) + +func TestProductRelativePath(t *testing.T) { + root := t.TempDir() + for _, configured := range []string{"artifacts/recap.md", filepath.Join(root, "artifacts", "recap.md")} { + got, err := ProductRelativePath(root, configured) + if err != nil || got != "artifacts/recap.md" { + t.Fatalf("%q: %q, %v", configured, got, err) + } + } + if _, err := ProductRelativePath(root, filepath.Join(t.TempDir(), "recap.md")); err == nil { + t.Fatal("outside absolute path accepted") + } +} diff --git a/internal/stage/analyze.go b/internal/stage/analyze.go index 92c3687..41f5992 100644 --- a/internal/stage/analyze.go +++ b/internal/stage/analyze.go @@ -209,7 +209,7 @@ func currentAnalyzeArtifactRecord( return manifest.AnalyzeArtifactRecord{}, fmt.Errorf("execution result is required") } producerRunID := analyzeProducerRunID(execution) - relativePath, err := normalizedAnalyzeOutputIdentity(plan.Cfg.OutputPath) + relativePath, err := normalizedAnalyzeOutputIdentity(execution.Paths, plan.Cfg.OutputPath) if err != nil { return manifest.AnalyzeArtifactRecord{}, err } diff --git a/internal/stage/analyze_absolute_path_test.go b/internal/stage/analyze_absolute_path_test.go new file mode 100644 index 0000000..5da4bfb --- /dev/null +++ b/internal/stage/analyze_absolute_path_test.go @@ -0,0 +1,45 @@ +package stage + +import ( + "context" + "path/filepath" + "testing" + + "gitea.maximumdirect.net/eric/narratio/internal/artifacts" + "gitea.maximumdirect.net/eric/narratio/internal/config" +) + +func TestAnalyzeAbsolutePathSharesPortableIdentity(t *testing.T) { + env, m, _ := currentAnalyzeFixture(t, true) + paths := sessionPathsForEnv(env, m.SessionID) + item := env.Config.ArtifactCatalog.Artifacts["session_recap"] + item.OutputPath = filepath.Join(paths.ArtifactsDir, "session_recap.md") + env.Config.ArtifactCatalog.Artifacts["session_recap"] = item + validation, err := (analyzeStage{}).ValidateResume(context.Background(), env, m) + if err != nil || !validation.Resumable { + t.Fatalf("equivalent path not reusable: %#v, %v", validation, err) + } + env.Force = true + if _, err := (analyzeStage{}).Run(context.Background(), env, m); err != nil { + t.Fatal(err) + } + if got := m.Stages["analyze"].AnalyzeArtifacts["session_recap"].Output.LocalPath; got != "artifacts/session_recap.md" { + t.Fatalf("checkpoint is not portable: %q", got) + } + catalog, err := buildPublishRuntimeArtifactCatalog(paths, m, env.Config.ConcreteArtifacts(), nil) + if err != nil { + t.Fatal(err) + } + source := artifacts.ConfiguredArtifactSourceID("session_recap") + resolved, err := artifacts.ResolveSessionArtifactWithCatalog(paths, m, source, catalog) + if err != nil || resolved.Path != item.OutputPath { + t.Fatalf("current product unavailable: %#v, %v", resolved, err) + } + actions, err := PlanPublicationOutputs(catalog, []config.PublishOutputRule{{Source: source}}, nil) + if err != nil || len(actions) != 1 || actions[0].Destination != "artifacts/session_recap.md" { + t.Fatalf("publication mapping: %#v, %v", actions, err) + } + if env.Config.ConcreteArtifacts()["session_recap"].OutputPath != item.OutputPath { + t.Fatal("configuration was mutated") + } +} diff --git a/internal/stage/analyze_artifact_execution.go b/internal/stage/analyze_artifact_execution.go index 43816a2..18647f6 100644 --- a/internal/stage/analyze_artifact_execution.go +++ b/internal/stage/analyze_artifact_execution.go @@ -284,7 +284,7 @@ func validateAndMaterializeAnalyzeArtifact( contract := &artifactmodel.ContractMetadata{ MediaType: "text/markdown", SchemaID: "narratio." + prepared.name, SchemaVersion: "1", } - relativeOutputPath, err := normalizedAnalyzeOutputIdentity(plan.Cfg.OutputPath) + relativeOutputPath, err := normalizedAnalyzeOutputIdentity(execution.Paths, plan.Cfg.OutputPath) if err != nil { return analyzeArtifactMaterialization{}, fmt.Errorf("analyze: normalize output identity for artifact %q: %w", prepared.name, err) } diff --git a/internal/stage/analyze_fingerprint.go b/internal/stage/analyze_fingerprint.go index e0bde8b..42380ce 100644 --- a/internal/stage/analyze_fingerprint.go +++ b/internal/stage/analyze_fingerprint.go @@ -5,14 +5,12 @@ import ( "encoding/hex" "encoding/json" "fmt" - "path/filepath" "sort" "strings" "gitea.maximumdirect.net/eric/narratio/internal/artifacts" "gitea.maximumdirect.net/eric/narratio/internal/config" "gitea.maximumdirect.net/eric/narratio/internal/manifest" - "gitea.maximumdirect.net/eric/narratio/internal/pathsafe" ) type analyzeFingerprintCandidate struct { @@ -156,7 +154,7 @@ func computeAnalyzeArtifactFingerprint( if err != nil { return "", inputs, dependencyOutputs, err } - outputIdentity, err := normalizedAnalyzeOutputIdentity(artifactCfg.OutputPath) + outputIdentity, err := normalizedAnalyzeOutputIdentity(execution.Paths, artifactCfg.OutputPath) if err != nil { return "", inputs, dependencyOutputs, err } @@ -248,12 +246,12 @@ func normalizedAnalyzeDependencyKeys(values []string) []string { return result } -func normalizedAnalyzeOutputIdentity(value string) (string, error) { +func normalizedAnalyzeOutputIdentity(paths artifacts.SessionPaths, value string) (string, error) { trimmed := strings.TrimSpace(value) if trimmed == "" { return "", nil } - normalized, err := pathsafe.NormalizeRelativeDestination(filepath.ToSlash(trimmed)) + normalized, err := artifacts.ProductRelativePath(paths.Root, trimmed) if err != nil { return "", fmt.Errorf("normalize configured output identity %q: %w", value, err) }