Unify analysis product path identity
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -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{}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
22
internal/artifacts/product_path.go
Normal file
22
internal/artifacts/product_path.go
Normal file
@@ -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))
|
||||
}
|
||||
19
internal/artifacts/product_path_test.go
Normal file
19
internal/artifacts/product_path_test.go
Normal file
@@ -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")
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
45
internal/stage/analyze_absolute_path_test.go
Normal file
45
internal/stage/analyze_absolute_path_test.go
Normal file
@@ -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")
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user