Add artifact provenance and stage skip outcomes
This commit is contained in:
17
internal/artifactmodel/metadata.go
Normal file
17
internal/artifactmodel/metadata.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package artifactmodel
|
||||
|
||||
// ContractMetadata identifies the data contract implemented by an artifact.
|
||||
type ContractMetadata struct {
|
||||
MediaType string `json:"media_type"`
|
||||
SchemaID string `json:"schema_id"`
|
||||
SchemaVersion string `json:"schema_version"`
|
||||
ModuleKey string `json:"module_key,omitempty"`
|
||||
}
|
||||
|
||||
// ExternalProvenance identifies an artifact produced by an external system.
|
||||
type ExternalProvenance struct {
|
||||
System string `json:"system"`
|
||||
RunID string `json:"run_id"`
|
||||
PipelineID string `json:"pipeline_id"`
|
||||
ArtifactID string `json:"artifact_id"`
|
||||
}
|
||||
56
internal/artifactmodel/metadata_test.go
Normal file
56
internal/artifactmodel/metadata_test.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package artifactmodel
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestArtifactMetadataJSON(t *testing.T) {
|
||||
type envelope struct {
|
||||
Contract *ContractMetadata `json:"contract,omitempty"`
|
||||
ExternalProvenance *ExternalProvenance `json:"external_provenance,omitempty"`
|
||||
}
|
||||
|
||||
complete, err := json.Marshal(envelope{
|
||||
Contract: &ContractMetadata{
|
||||
MediaType: "application/json",
|
||||
SchemaID: "notarius.dnd.npc_registry",
|
||||
SchemaVersion: "v1",
|
||||
ModuleKey: "dnd/npc-registry",
|
||||
},
|
||||
ExternalProvenance: &ExternalProvenance{
|
||||
System: "notarius",
|
||||
RunID: "run-123",
|
||||
PipelineID: "dnd-session",
|
||||
ArtifactID: "npc-registry",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal() complete metadata error = %v", err)
|
||||
}
|
||||
wantComplete := `{"contract":{"media_type":"application/json","schema_id":"notarius.dnd.npc_registry","schema_version":"v1","module_key":"dnd/npc-registry"},"external_provenance":{"system":"notarius","run_id":"run-123","pipeline_id":"dnd-session","artifact_id":"npc-registry"}}`
|
||||
if string(complete) != wantComplete {
|
||||
t.Fatalf("complete metadata JSON = %s, want %s", complete, wantComplete)
|
||||
}
|
||||
|
||||
omitted, err := json.Marshal(envelope{})
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal() omitted metadata error = %v", err)
|
||||
}
|
||||
if string(omitted) != `{}` {
|
||||
t.Fatalf("omitted metadata JSON = %s, want {}", omitted)
|
||||
}
|
||||
|
||||
withoutModule, err := json.Marshal(envelope{Contract: &ContractMetadata{
|
||||
MediaType: "application/json",
|
||||
SchemaID: "notarius.dnd.npc_registry",
|
||||
SchemaVersion: "v1",
|
||||
}})
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal() contract without module key error = %v", err)
|
||||
}
|
||||
if strings.Contains(string(withoutModule), "module_key") {
|
||||
t.Fatalf("contract JSON unexpectedly contains omitted module_key: %s", withoutModule)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user