Resolve supplied products from local records
This commit is contained in:
@@ -29,6 +29,10 @@ func (extractStage) ValidateResume(_ context.Context, env *Env, m *manifest.Mani
|
||||
return ResumeValidation{}, fmt.Errorf("extract resume: session ID is required")
|
||||
}
|
||||
paths := sessionPathsForEnv(env, sessionID)
|
||||
definitions := artifacts.ExtractionDefinitionsFromConfig(cfg)
|
||||
if artifacts.SuppliedExtractionComplete(paths, m, definitions) {
|
||||
return Resumable(), nil
|
||||
}
|
||||
input, err := artifacts.ResolveExtractionInputIdentity(paths, m)
|
||||
if err != nil {
|
||||
return NonResumable("final-trimmed transcript evidence is unavailable or changed"), nil
|
||||
@@ -45,7 +49,6 @@ func (extractStage) ValidateResume(_ context.Context, env *Env, m *manifest.Mani
|
||||
if record == nil || metadataString(record.Metadata, "configuration_fingerprint") != fingerprint {
|
||||
return NonResumable("Notarius invocation contract changed"), nil
|
||||
}
|
||||
definitions := artifacts.ExtractionDefinitionsFromConfig(cfg)
|
||||
proof := artifacts.InspectExtractionEvidence(paths, m, definitions, input)
|
||||
if proof.State == artifacts.ExtractionEvidenceUnsafe {
|
||||
return ResumeValidation{}, fmt.Errorf("extract resume: %s", proof.Reason)
|
||||
|
||||
66
internal/stage/supplied_publication_test.go
Normal file
66
internal/stage/supplied_publication_test.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package stage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
)
|
||||
|
||||
func TestDiscoverPublicationFromSuppliedProducts(t *testing.T) {
|
||||
env, m, _ := setupRenderEnv(t)
|
||||
paths := sessionPathsForEnv(env, m.SessionID)
|
||||
m.SuppliedProducts = &manifest.SuppliedProductCollection{Version: manifest.SuppliedProductVersion, Products: map[string]manifest.SuppliedProduct{}}
|
||||
for _, item := range []struct{ source, path, body string }{
|
||||
{artifacts.ArtifactTranscriptFinalTrimmed, artifacts.TranscriptPathFinalTrimmed, `{"segments":[]}`},
|
||||
{artifacts.ConfiguredArtifactSourceID("summary"), "artifacts/summary.md", "summary"},
|
||||
} {
|
||||
path := filepath.Join(paths.Root, filepath.FromSlash(item.path))
|
||||
writeFile(t, path, item.body)
|
||||
checksum, err := artifacts.SHA256File(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m.SuppliedProducts.Products[item.source] = manifest.SuppliedProduct{Path: item.path, Checksum: checksum, Size: int64(len(item.body))}
|
||||
}
|
||||
configured := map[string]artifacts.ConfiguredArtifactDefinition{"summary": {Enabled: true, OutputPath: "artifacts/summary.md"}}
|
||||
catalog, err := artifacts.BootstrapRuntimeCatalog(configured, artifacts.EffectiveArtifactSet{}, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
catalog.HydrateAnalyzeArtifacts(paths, m, configured)
|
||||
actions := []PublicationAction{{Source: artifacts.ArtifactTranscriptFinalTrimmed, Selected: true}, {Source: artifacts.ConfiguredArtifactSourceID("summary"), Selected: true}}
|
||||
found, err := discoverPublishOutputs(paths, m, catalog, actions, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(found) != 2 {
|
||||
t.Fatalf("found %v", found)
|
||||
}
|
||||
for _, product := range found {
|
||||
if product.Provenance != artifacts.ArtifactProvenanceSupplied {
|
||||
t.Fatalf("product %+v", product)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractResumeAcceptsSuppliedProductsWithoutHistory(t *testing.T) {
|
||||
env, m, _ := setupExtractEnv(t)
|
||||
m.Stages = map[string]*manifest.StageRecord{}
|
||||
paths := sessionPathsForEnv(env, m.SessionID)
|
||||
source := artifacts.ExtractionArtifactSourceID("npc_registry")
|
||||
path := filepath.Join(paths.Root, "artifacts", "npc_registry.json")
|
||||
body := `{"npcs":[]}`
|
||||
writeFile(t, path, body)
|
||||
checksum, err := artifacts.SHA256File(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m.SuppliedProducts = &manifest.SuppliedProductCollection{Version: manifest.SuppliedProductVersion, Products: map[string]manifest.SuppliedProduct{source: {Path: "artifacts/npc_registry.json", Checksum: checksum, Size: int64(len(body))}}}
|
||||
result, err := (extractStage{}).ValidateResume(context.Background(), env, m)
|
||||
if err != nil || !result.Resumable {
|
||||
t.Fatalf("validation %+v: %v", result, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user