Adopt location registry durable contract

This commit is contained in:
2026-08-05 19:05:42 +00:00
parent 2f61118e78
commit c006b163d5
41 changed files with 196 additions and 196 deletions

View File

@@ -27,7 +27,7 @@ const (
// grounding. All accessors return defensive copies.
type Registry struct {
bound bool
list dnd.LocationList
list dnd.LocationRegistry
canonical []byte
digest string
projectionDigest string
@@ -68,7 +68,7 @@ func (r *Resolver) Resolve(references contracts.ReferenceSet) (*Registry, error)
return r.resolver.Resolve(references)
}
// Resolve validates an optional location-list reference. An absent reference
// Resolve validates an optional location-registry reference. An absent reference
// uses the canonical empty projection and has no durable registry identity.
func Resolve(references contracts.ReferenceSet) (*Registry, error) {
item, present, err := registryresolver.ResolveOptionalSingleItem(references, locationReferenceSpec())
@@ -102,7 +102,7 @@ func emptyRegistry() *Registry {
content := []byte(emptyPrompt)
projectionDigest := semanticDigest(content)
return &Registry{
list: dnd.LocationList{Locations: []dnd.Location{}},
list: dnd.LocationRegistry{Locations: []dnd.Location{}},
canonical: append([]byte(nil), content...),
projectionDigest: projectionDigest,
promptInput: contracts.NewLLMInputMaterial(ReferenceSlot, locationcodec.MediaType, content, projectionDigest, ""),
@@ -124,7 +124,7 @@ func loadRegistry(referenceContent []byte) (*Registry, error) {
return nil, fmt.Errorf("encode canonical location registry: approved location value could not be encoded")
}
list := cloneLocationList(value)
list := cloneLocationRegistry(value)
lookupByID := make(map[string]int, len(list.Locations))
for index, location := range list.Locations {
lookupByID[location.ID] = index
@@ -157,12 +157,12 @@ func (r *Registry) Locations() []dnd.Location {
return cloneLocations(r.list.Locations)
}
// List returns a defensive copy of the validated location list.
func (r *Registry) List() dnd.LocationList {
// List returns a defensive copy of the validated location registry.
func (r *Registry) List() dnd.LocationRegistry {
if r == nil {
return dnd.LocationList{}
return dnd.LocationRegistry{}
}
return cloneLocationList(r.list)
return cloneLocationRegistry(r.list)
}
// CanonicalBytes returns a defensive copy of the canonical durable JSON.
@@ -236,12 +236,12 @@ type projectedLocation struct {
Name string `json:"name"`
}
type projectedLocationList struct {
type projectedLocationRegistry struct {
Locations []projectedLocation `json:"locations"`
}
func promptProjection(list dnd.LocationList) ([]byte, error) {
projection := projectedLocationList{Locations: make([]projectedLocation, len(list.Locations))}
func promptProjection(list dnd.LocationRegistry) ([]byte, error) {
projection := projectedLocationRegistry{Locations: make([]projectedLocation, len(list.Locations))}
for index, location := range list.Locations {
projection.Locations[index] = projectedLocation{ID: location.ID, Name: location.Name}
}
@@ -256,8 +256,8 @@ func formatIdentityIssues(issues []identity.Issue) string {
return diagnostics.Aggregate("validate location registry identity", parts)
}
func cloneLocationList(value dnd.LocationList) dnd.LocationList {
return dnd.LocationList{Locations: cloneLocations(value.Locations)}
func cloneLocationRegistry(value dnd.LocationRegistry) dnd.LocationRegistry {
return dnd.LocationRegistry{Locations: cloneLocations(value.Locations)}
}
func cloneLocations(values []dnd.Location) []dnd.Location {

View File

@@ -155,16 +155,16 @@ func TestResolverReusesEquivalentCanonicalRegistries(t *testing.T) {
}
}
func registryFixture() dnd.LocationList {
func registryFixture() dnd.LocationRegistry {
firstRefs := []source.SourceRef{{SourceID: "session-alpha", StartUnitID: 1, EndUnitID: 1}}
secondRefs := []source.SourceRef{{SourceID: "session-alpha", StartUnitID: 2, EndUnitID: 2}}
return dnd.LocationList{Locations: []dnd.Location{
return dnd.LocationRegistry{Locations: []dnd.Location{
{ID: identity.DeriveID("The Tavern", firstRefs), Name: "The Tavern", SourceRefs: firstRefs},
{ID: identity.DeriveID("The Tavern", secondRefs), Name: "The Tavern", SourceRefs: secondRefs},
}}
}
func resolveList(t *testing.T, list dnd.LocationList) *Registry {
func resolveList(t *testing.T, list dnd.LocationRegistry) *Registry {
t.Helper()
registry, err := Resolve(referenceSet(item(encodeList(t, list))))
if err != nil {
@@ -173,7 +173,7 @@ func resolveList(t *testing.T, list dnd.LocationList) *Registry {
return registry
}
func encodeList(t *testing.T, list dnd.LocationList) []byte {
func encodeList(t *testing.T, list dnd.LocationRegistry) []byte {
t.Helper()
content, err := locationcodec.New().Encode(list)
if err != nil {