Resolve supplied products from local records
This commit is contained in:
@@ -131,6 +131,14 @@ func (c *ArtifactCatalog) HydrateAnalyzeArtifacts(
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if c.hydrateSuppliedProduct(paths, m, entry.SourceID, definition.OutputPath) {
|
||||
continue
|
||||
}
|
||||
if m != nil && m.SuppliedProducts != nil {
|
||||
if _, exists := m.SuppliedProducts.Products[entry.SourceID]; exists {
|
||||
continue
|
||||
}
|
||||
}
|
||||
evidence := InspectAnalyzeEvidence(paths, m, entry.ConfiguredKey, definition)
|
||||
if evidence.State != AnalyzeEvidenceCurrent {
|
||||
continue
|
||||
|
||||
@@ -187,6 +187,14 @@ func ResolveSessionArtifact(paths SessionPaths, m *manifest.Manifest, source str
|
||||
return ResolvedSessionArtifact{}, err
|
||||
}
|
||||
spec := artifactRegistry[id]
|
||||
if m != nil && m.SuppliedProducts != nil {
|
||||
if record, ok := m.SuppliedProducts.Products[id]; ok {
|
||||
if err := ValidateSuppliedProduct(paths, id, spec.CanonicalRelPath, record); err != nil {
|
||||
return ResolvedSessionArtifact{}, fmt.Errorf("validate supplied %q: %w", id, err)
|
||||
}
|
||||
return ResolvedSessionArtifact{ID: id, Path: filepath.Join(paths.Root, filepath.FromSlash(record.Path)), ProducerStage: spec.ProducerStage, OutputKind: spec.OutputKind, Provenance: ArtifactProvenanceSupplied, Contract: cloneArtifactContract(record.Contract), Checksum: record.Checksum, Size: record.Size}, nil
|
||||
}
|
||||
}
|
||||
|
||||
candidate, err := manifestArtifactCandidate(paths, m, spec)
|
||||
if err != nil {
|
||||
|
||||
@@ -15,6 +15,7 @@ const (
|
||||
ArtifactProvenanceGeneratedCurrentAnalyzeRun = "generated.current_analyze_run"
|
||||
ArtifactProvenanceCurrentAnalyzeManifest = "manifest.current_analyze_artifact"
|
||||
ArtifactProvenanceCurrentExtractManifest = "manifest.current_extract_run"
|
||||
ArtifactProvenanceSupplied = "manifest.supplied_product"
|
||||
)
|
||||
|
||||
// ConfiguredArtifactDefinition describes one configured analyze artifact.
|
||||
|
||||
@@ -38,6 +38,11 @@ func (c *ArtifactCatalog) HydrateExtractionArtifactsExcept(
|
||||
if c == nil || m == nil || len(configured) == 0 {
|
||||
return
|
||||
}
|
||||
for _, entry := range c.ListExtraction() {
|
||||
if _, ok := configured[entry.ExtractionKey]; ok && !excluded[entry.SourceID] {
|
||||
c.hydrateSuppliedProduct(paths, m, entry.SourceID, entry.CanonicalRelPath)
|
||||
}
|
||||
}
|
||||
input, err := ResolveExtractionInputIdentity(paths, m)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -47,6 +52,11 @@ func (c *ArtifactCatalog) HydrateExtractionArtifactsExcept(
|
||||
return
|
||||
}
|
||||
for sourceID, output := range proof.Outputs {
|
||||
if m.SuppliedProducts != nil {
|
||||
if _, exists := m.SuppliedProducts.Products[sourceID]; exists {
|
||||
continue
|
||||
}
|
||||
}
|
||||
_ = c.markAvailableFromExtractManifest(
|
||||
sourceID, output.Path, proof.ProducerRunID,
|
||||
output.Checksum, output.Size, output.Contract,
|
||||
|
||||
@@ -78,3 +78,53 @@ func SuppliedTranscriptCoverage(paths SessionPaths, collection *manifest.Supplie
|
||||
}
|
||||
return covered
|
||||
}
|
||||
|
||||
// hydrateSuppliedProduct publishes one valid supplied identity to the runtime catalog.
|
||||
func (c *ArtifactCatalog) hydrateSuppliedProduct(paths SessionPaths, m *manifest.Manifest, source, configuredPath string) bool {
|
||||
if c == nil || m == nil || m.SuppliedProducts == nil {
|
||||
return false
|
||||
}
|
||||
record, ok := m.SuppliedProducts.Products[source]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
canonical, err := ProductRelativePath(paths.Root, configuredPath)
|
||||
if err != nil || ValidateSuppliedProduct(paths, source, canonical, record) != nil {
|
||||
return false
|
||||
}
|
||||
path := filepath.Join(paths.Root, filepath.FromSlash(record.Path))
|
||||
if err := c.markAvailable(source, path, ArtifactProvenanceSupplied); err != nil {
|
||||
return false
|
||||
}
|
||||
entry := c.entries[source]
|
||||
entry.CanonicalRelPath = canonical
|
||||
entry.Contract = cloneArtifactContract(record.Contract)
|
||||
entry.Checksum = record.Checksum
|
||||
entry.Size = record.Size
|
||||
c.entries[source] = entry
|
||||
return true
|
||||
}
|
||||
|
||||
// SuppliedExtractionComplete reports whether every configured extraction product
|
||||
// is available as a valid supplied product, independent of generation history.
|
||||
func SuppliedExtractionComplete(paths SessionPaths, m *manifest.Manifest, configured map[string]ExtractionArtifactDefinition) bool {
|
||||
if m == nil || m.SuppliedProducts == nil || len(configured) == 0 {
|
||||
return false
|
||||
}
|
||||
for key, definition := range configured {
|
||||
source := ExtractionArtifactSourceID(key)
|
||||
filename := definition.Filename
|
||||
if filename == "" {
|
||||
filename = key + ".json"
|
||||
}
|
||||
path, err := ProductRelativePath(paths.Root, filepath.Join("artifacts", filename))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
record, ok := m.SuppliedProducts.Products[source]
|
||||
if !ok || ValidateSuppliedProduct(paths, source, path, record) != nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package artifacts
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
)
|
||||
@@ -94,3 +97,70 @@ func TestSuppliedIndependentProducts(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSuppliedProductsResolveAfterReload(t *testing.T) {
|
||||
paths := SessionPaths{Root: t.TempDir()}
|
||||
m := manifest.New("session", time.Now())
|
||||
m.SuppliedProducts = &manifest.SuppliedProductCollection{Version: manifest.SuppliedProductVersion, Products: map[string]manifest.SuppliedProduct{}}
|
||||
add := func(source, path, content string) {
|
||||
absolute := filepath.Join(paths.Root, filepath.FromSlash(path))
|
||||
if err := os.MkdirAll(filepath.Dir(absolute), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(absolute, []byte(content), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
checksum, err := SHA256File(absolute)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m.SuppliedProducts.Products[source] = manifest.SuppliedProduct{Path: path, Size: int64(len(content)), Checksum: checksum}
|
||||
}
|
||||
add(ArtifactTranscriptFinalTrimmed, TranscriptPathFinalTrimmed, `{"segments":[]}`)
|
||||
add(ArtifactBoundsSession, "artifacts/session_bounds.json", `{}`)
|
||||
add(ConfiguredArtifactSourceID("summary"), "artifacts/summary.md", "summary")
|
||||
add(ExtractionArtifactSourceID("events"), "artifacts/events.json", `{"events":[]}`)
|
||||
store := &manifest.LocalStore{}
|
||||
manifestPath := filepath.Join(paths.Root, "manifest.json")
|
||||
if err := store.Save(context.Background(), manifestPath, m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loaded, err := store.Load(context.Background(), manifestPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, source := range []string{ArtifactTranscriptFinalTrimmed, ArtifactBoundsSession} {
|
||||
resolved, err := ResolveSessionArtifact(paths, loaded, source)
|
||||
if err != nil || resolved.Provenance != ArtifactProvenanceSupplied {
|
||||
t.Fatalf("resolve %s: %+v %v", source, resolved, err)
|
||||
}
|
||||
}
|
||||
if _, err := ResolveSessionArtifact(paths, loaded, ArtifactTranscriptFinal); !errors.Is(err, ErrSessionArtifactNotFound) {
|
||||
t.Fatalf("absent intermediate: %v", err)
|
||||
}
|
||||
configured := map[string]ConfiguredArtifactDefinition{"summary": {Enabled: true, OutputPath: "artifacts/summary.md"}}
|
||||
extraction := map[string]ExtractionArtifactDefinition{"events": {Filename: "events.json"}, "npcs": {Filename: "npcs.json"}}
|
||||
catalog, err := BootstrapRuntimeCatalog(configured, EffectiveArtifactSet{}, extraction)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
catalog.HydrateAnalyzeArtifacts(paths, loaded, configured)
|
||||
catalog.HydrateExtractionArtifacts(paths, loaded, extraction)
|
||||
for _, source := range []string{ConfiguredArtifactSourceID("summary"), ExtractionArtifactSourceID("events")} {
|
||||
resolved, err := ResolveSessionArtifactWithCatalog(paths, loaded, source, catalog)
|
||||
if err != nil || resolved.Provenance != ArtifactProvenanceSupplied {
|
||||
t.Fatalf("resolve %s: %+v %v", source, resolved, err)
|
||||
}
|
||||
}
|
||||
if SuppliedExtractionComplete(paths, loaded, extraction) {
|
||||
t.Fatal("partial extraction reported complete")
|
||||
}
|
||||
if _, err := ResolveSessionArtifactWithCatalog(paths, loaded, ExtractionArtifactSourceID("npcs"), catalog); !errors.Is(err, ErrSessionArtifactNotFound) {
|
||||
t.Fatalf("missing lane: %v", err)
|
||||
}
|
||||
add(ExtractionArtifactSourceID("npcs"), "artifacts/npcs.json", `{}`)
|
||||
loaded.SuppliedProducts = manifest.CloneSuppliedProducts(m.SuppliedProducts)
|
||||
if !SuppliedExtractionComplete(paths, loaded, extraction) {
|
||||
t.Fatal("complete supplied extraction not recognized")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user