Add artifact provenance and stage skip outcomes
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifactmodel"
|
||||
)
|
||||
|
||||
func TestLocalStoreCreateSaveLoadRoundTrip(t *testing.T) {
|
||||
@@ -64,6 +66,76 @@ func TestLocalStoreCreateSaveLoadRoundTrip(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLocalStoreArtifactMetadataCompatibility(t *testing.T) {
|
||||
store := &LocalStore{}
|
||||
ctx := context.Background()
|
||||
dir := t.TempDir()
|
||||
oldPath := filepath.Join(dir, "old-manifest.json")
|
||||
oldJSON := `{
|
||||
"session_id": "2026-05-03",
|
||||
"created_at": "2026-05-03T10:00:00Z",
|
||||
"updated_at": "2026-05-03T10:01:00Z",
|
||||
"stages": {
|
||||
"analyze": {
|
||||
"name": "analyze",
|
||||
"status": "succeeded",
|
||||
"created_at": "2026-05-03T10:00:00Z",
|
||||
"updated_at": "2026-05-03T10:01:00Z",
|
||||
"outputs": [{"kind":"scriptorium_artifact","local_path":"artifacts/recap.md"}]
|
||||
}
|
||||
}
|
||||
}`
|
||||
if err := os.WriteFile(oldPath, []byte(oldJSON), 0o644); err != nil {
|
||||
t.Fatalf("WriteFile() old manifest error = %v", err)
|
||||
}
|
||||
|
||||
loaded, err := store.Load(ctx, oldPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Load() old manifest error = %v", err)
|
||||
}
|
||||
oldOutput := loaded.Stages["analyze"].Outputs[0]
|
||||
if oldOutput.Contract != nil || oldOutput.ExternalProvenance != nil {
|
||||
t.Fatalf("old output metadata = %#v, %#v; want nil", oldOutput.Contract, oldOutput.ExternalProvenance)
|
||||
}
|
||||
if err := store.Save(ctx, oldPath, loaded); err != nil {
|
||||
t.Fatalf("Save() old manifest error = %v", err)
|
||||
}
|
||||
roundTripped, err := os.ReadFile(oldPath)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadFile() round-tripped old manifest error = %v", err)
|
||||
}
|
||||
if strings.Contains(string(roundTripped), `"contract"`) || strings.Contains(string(roundTripped), `"external_provenance"`) {
|
||||
t.Fatalf("old manifest gained fabricated metadata:\n%s", roundTripped)
|
||||
}
|
||||
|
||||
loaded.Stages["analyze"].Outputs[0].Contract = &artifactmodel.ContractMetadata{
|
||||
MediaType: "application/json",
|
||||
SchemaID: "example.recap",
|
||||
SchemaVersion: "v1",
|
||||
}
|
||||
loaded.Stages["analyze"].Outputs[0].ExternalProvenance = &artifactmodel.ExternalProvenance{
|
||||
System: "example",
|
||||
RunID: "external-run",
|
||||
PipelineID: "pipeline",
|
||||
ArtifactID: "recap",
|
||||
}
|
||||
metadataPath := filepath.Join(dir, "metadata-manifest.json")
|
||||
if err := store.Save(ctx, metadataPath, loaded); err != nil {
|
||||
t.Fatalf("Save() metadata manifest error = %v", err)
|
||||
}
|
||||
withMetadata, err := store.Load(ctx, metadataPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Load() metadata manifest error = %v", err)
|
||||
}
|
||||
got := withMetadata.Stages["analyze"].Outputs[0]
|
||||
if got.Contract == nil || got.Contract.SchemaID != "example.recap" {
|
||||
t.Fatalf("contract = %#v, want persisted contract", got.Contract)
|
||||
}
|
||||
if got.ExternalProvenance == nil || got.ExternalProvenance.RunID != "external-run" {
|
||||
t.Fatalf("external provenance = %#v, want persisted provenance", got.ExternalProvenance)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLocalStoreSaveUpdatesTimestamp(t *testing.T) {
|
||||
store := &LocalStore{}
|
||||
ctx := context.Background()
|
||||
|
||||
Reference in New Issue
Block a user