Adopt location registry durable contract
This commit is contained in:
@@ -15,9 +15,9 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/locations/identity"
|
||||
)
|
||||
|
||||
func validList() dnd.LocationList {
|
||||
func validList() dnd.LocationRegistry {
|
||||
refs := []source.SourceRef{{SourceID: "session-alpha", StartUnitID: 1, EndUnitID: 2}}
|
||||
return dnd.LocationList{Locations: []dnd.Location{{
|
||||
return dnd.LocationRegistry{Locations: []dnd.Location{{
|
||||
ID: identity.DeriveID("The Old Tavern", refs),
|
||||
Name: "The Old Tavern",
|
||||
SourceRefs: refs,
|
||||
@@ -25,7 +25,7 @@ func validList() dnd.LocationList {
|
||||
}
|
||||
|
||||
func TestCodecMatchesMaintainedDurableFixture(t *testing.T) {
|
||||
raw, err := os.ReadFile("testdata/dnd_locations.v1.json")
|
||||
raw, err := os.ReadFile("testdata/dnd_location_registry.v1.json")
|
||||
if err != nil {
|
||||
t.Fatalf("read durable fixture: %v", err)
|
||||
}
|
||||
@@ -53,7 +53,7 @@ func TestCodecMatchesMaintainedDurableFixture(t *testing.T) {
|
||||
func TestCodecOwnsDurableSchemaAndMetadata(t *testing.T) {
|
||||
codec := New()
|
||||
schema := codec.Schema()
|
||||
if codec.Kind() != dnd.LocationListKind || codec.MediaType() != MediaType {
|
||||
if codec.Kind() != dnd.LocationRegistryKind || codec.MediaType() != MediaType {
|
||||
t.Fatalf("codec identity = %q/%q", codec.Kind(), codec.MediaType())
|
||||
}
|
||||
if schema.ID != SchemaID || schema.Name != SchemaName || schema.Version != SchemaVersion || !json.Valid(schema.JSONSchema) {
|
||||
@@ -67,7 +67,7 @@ func TestCodecOwnsDurableSchemaAndMetadata(t *testing.T) {
|
||||
if err := pipeline.RegisterArtifactCodec(registry, codec); err != nil {
|
||||
t.Fatalf("RegisterArtifactCodec() error = %v", err)
|
||||
}
|
||||
if spec, ok := registry.Spec(dnd.LocationListKind); !ok || spec.SchemaDigest != contracts.DigestArtifactSchema(schema) {
|
||||
if spec, ok := registry.Spec(dnd.LocationRegistryKind); !ok || spec.SchemaDigest != contracts.DigestArtifactSchema(schema) {
|
||||
t.Fatalf("registered spec = %#v, %t", spec, ok)
|
||||
}
|
||||
first := schema.JSONSchema
|
||||
@@ -84,11 +84,11 @@ func TestCodecOwnsDurableSchemaAndMetadata(t *testing.T) {
|
||||
|
||||
func TestCodecSupportsEmptyListsAndCandidateSemanticFailures(t *testing.T) {
|
||||
codec := New()
|
||||
empty := dnd.LocationList{Locations: []dnd.Location{}}
|
||||
empty := dnd.LocationRegistry{Locations: []dnd.Location{}}
|
||||
if content, err := codec.Encode(empty); err != nil || string(content) != `{"locations":[]}` {
|
||||
t.Fatalf("Encode() = %s, %v", content, err)
|
||||
}
|
||||
for _, candidate := range []dnd.LocationList{
|
||||
for _, candidate := range []dnd.LocationRegistry{
|
||||
{},
|
||||
empty,
|
||||
{Locations: []dnd.Location{{ID: "bad", Name: " ", SourceRefs: nil}}},
|
||||
@@ -109,7 +109,7 @@ func TestCodecSupportsEmptyListsAndCandidateSemanticFailures(t *testing.T) {
|
||||
func TestCodecRejectsStructuralJSONBeforeSemanticApproval(t *testing.T) {
|
||||
valid := `{"locations":[{"id":"location:sha256:0000000000000000000000000000000000000000000000000000000000000000","name":"The Tavern","source_refs":[{"source_id":"session","start_unit_id":1,"end_unit_id":1}]}]}`
|
||||
for _, test := range []struct{ name, raw, want string }{
|
||||
{"malformed", `{`, "decode dnd location list"},
|
||||
{"malformed", `{`, "decode dnd location registry"},
|
||||
{"unknown top-level", `{"locations":[],"unexpected":true}`, "unknown field"},
|
||||
{"unknown location field", strings.Replace(valid, `"name":"The Tavern"`, `"name":"The Tavern","unexpected":true`, 1), "unknown field"},
|
||||
{"unknown source reference field", strings.Replace(valid, `"end_unit_id":1`, `"end_unit_id":1,"unexpected":true`, 1), "unknown field"},
|
||||
@@ -128,14 +128,14 @@ func TestCodecRejectsApprovedShapeBoundaries(t *testing.T) {
|
||||
base := validList().Locations[0]
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
value dnd.LocationList
|
||||
value dnd.LocationRegistry
|
||||
want string
|
||||
}{
|
||||
{"nil locations", dnd.LocationList{}, "locations must be present"},
|
||||
{"invalid ID", dnd.LocationList{Locations: []dnd.Location{{ID: "bad", Name: base.Name, SourceRefs: base.SourceRefs}}}, "id must match location ID pattern"},
|
||||
{"blank name", dnd.LocationList{Locations: []dnd.Location{{ID: base.ID, Name: " ", SourceRefs: base.SourceRefs}}}, "name must not be empty"},
|
||||
{"empty source refs", dnd.LocationList{Locations: []dnd.Location{{ID: base.ID, Name: base.Name, SourceRefs: nil}}}, "source_refs must contain"},
|
||||
{"malformed source reference", dnd.LocationList{Locations: []dnd.Location{{ID: base.ID, Name: base.Name, SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 0, EndUnitID: 1}}}}}, "start_unit_id must be positive"},
|
||||
{"nil locations", dnd.LocationRegistry{}, "locations must be present"},
|
||||
{"invalid ID", dnd.LocationRegistry{Locations: []dnd.Location{{ID: "bad", Name: base.Name, SourceRefs: base.SourceRefs}}}, "id must match location ID pattern"},
|
||||
{"blank name", dnd.LocationRegistry{Locations: []dnd.Location{{ID: base.ID, Name: " ", SourceRefs: base.SourceRefs}}}, "name must not be empty"},
|
||||
{"empty source refs", dnd.LocationRegistry{Locations: []dnd.Location{{ID: base.ID, Name: base.Name, SourceRefs: nil}}}, "source_refs must contain"},
|
||||
{"malformed source reference", dnd.LocationRegistry{Locations: []dnd.Location{{ID: base.ID, Name: base.Name, SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 0, EndUnitID: 1}}}}}, "start_unit_id must be positive"},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if _, err := New().Encode(test.value); err == nil || !strings.Contains(err.Error(), test.want) {
|
||||
|
||||
Reference in New Issue
Block a user