Resolve supplied products from local records

This commit is contained in:
2026-12-02 15:13:04 +00:00
parent eb146d3298
commit 93c8695250
10 changed files with 235 additions and 12 deletions

View File

@@ -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")
}
}