Unify analysis product path identity
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user