Finish native migration cleanup and restore whole-tree compilation

This commit is contained in:
2026-11-22 05:37:15 +00:00
parent 4fa437aee8
commit 3ef55f4668
12 changed files with 123 additions and 445 deletions

View File

@@ -5,7 +5,6 @@ package registry
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
@@ -26,12 +25,11 @@ const (
// Registry is an immutable, validated location registry prepared for prompt
// grounding. All accessors return defensive copies.
type Registry struct {
bound bool
list dnd.LocationRegistry
canonical []byte
digest string
identityDigest string
lookupByID map[string]int
bound bool
list dnd.LocationRegistry
canonical []byte
digest string
lookupByID map[string]int
}
// Resolver selects and memoizes immutable location registry views.
@@ -99,12 +97,10 @@ func locationReferenceSpec() registryresolver.ReferenceSpec {
func emptyRegistry() *Registry {
content := []byte(emptyRegistryContent)
identityDigest := semanticDigest(content)
return &Registry{
list: dnd.LocationRegistry{Locations: []dnd.Location{}},
canonical: append([]byte(nil), content...),
identityDigest: identityDigest,
lookupByID: map[string]int{},
list: dnd.LocationRegistry{Locations: []dnd.Location{}},
canonical: append([]byte(nil), content...),
lookupByID: map[string]int{},
}
}
@@ -127,19 +123,13 @@ func loadRegistry(referenceContent []byte) (*Registry, error) {
for index, location := range list.Locations {
lookupByID[location.ID] = index
}
projection, err := identityProjection(list)
if err != nil {
return nil, fmt.Errorf("encode location prompt projection: %w", err)
}
digest := semanticDigest(content)
identityDigest := semanticDigest(projection)
return &Registry{
bound: true,
list: list,
canonical: append([]byte(nil), content...),
digest: digest,
identityDigest: identityDigest,
lookupByID: lookupByID,
bound: true,
list: list,
canonical: append([]byte(nil), content...),
digest: digest,
lookupByID: lookupByID,
}, nil
}
@@ -179,15 +169,6 @@ func (r *Registry) Digest() string {
return r.digest
}
// IdentityDigest returns the digest of the ordered ID/name identity projection
// used by deterministic consumers.
func (r *Registry) IdentityDigest() string {
if r == nil {
return ""
}
return r.identityDigest
}
// Count returns the number of validated location records.
func (r *Registry) Count() int {
if r == nil {
@@ -219,23 +200,6 @@ func semanticDigest(content []byte) string {
return "sha256:" + hex.EncodeToString(sum[:])
}
type identityProjectedLocation struct {
ID string `json:"id"`
Name string `json:"name"`
}
type identityProjectedLocationRegistry struct {
Locations []identityProjectedLocation `json:"locations"`
}
func identityProjection(list dnd.LocationRegistry) ([]byte, error) {
projection := identityProjectedLocationRegistry{Locations: make([]identityProjectedLocation, len(list.Locations))}
for index, location := range list.Locations {
projection.Locations[index] = identityProjectedLocation{ID: location.ID, Name: location.Name}
}
return json.Marshal(projection)
}
func formatIdentityIssues(issues []identity.Issue) string {
parts := make([]string, len(issues))
for index, issue := range issues {

View File

@@ -22,18 +22,19 @@ func TestResolveUnboundRegistryHasEmptyIdentity(t *testing.T) {
if registry.Bound() || registry.Digest() != "" || registry.Count() != 0 || string(registry.CanonicalBytes()) != emptyRegistryContent {
t.Fatalf("unbound registry = %#v", registry)
}
if registry.IdentityDigest() == "" {
t.Fatal("unbound registry identity digest is empty")
}
}
func TestResolveRetainsSeparateDurableAndIdentityDigests(t *testing.T) {
func TestResolveRetainsCanonicalDurableRegistry(t *testing.T) {
registry := resolveList(t, registryFixture())
if !registry.Bound() || registry.Count() != 2 || registry.Digest() == "" {
t.Fatalf("registry identity = bound %t count %d digest %q", registry.Bound(), registry.Count(), registry.Digest())
}
if registry.IdentityDigest() == "" || registry.Digest() == registry.IdentityDigest() {
t.Fatalf("full/identity digests = %q/%q", registry.Digest(), registry.IdentityDigest())
content, err := locationcodec.New().Encode(registryFixture())
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(content, registry.CanonicalBytes()) {
t.Fatalf("canonical registry=%s, want %s", registry.CanonicalBytes(), content)
}
}
@@ -228,8 +229,8 @@ func TestGroundingProjectsAndResolvesUniqueAndSameNameLocations(t *testing.T) {
if bytes.Contains(grounding.PromptInput().Content, []byte("location:sha256:")) || bytes.Contains(grounding.PromptInput().Content, []byte(`"source_id"`)) {
t.Fatalf("grounding projection exposed durable identity: %s", grounding.PromptInput().Content)
}
if grounding.PromptInput().Digest == "" || grounding.PromptInput().Digest == registry.IdentityDigest() {
t.Fatalf("grounding/identity digests = %q/%q", grounding.PromptInput().Digest, registry.IdentityDigest())
if grounding.PromptInput().Digest == "" {
t.Fatal("grounding projection has no content digest")
}
resolved, ok := grounding.Resolve(Selector{Name: " the tavern ", RegistryRefs: []RegistryRef{{StartUnitID: 30, EndUnitID: 30}, {StartUnitID: 20, EndUnitID: 20}}})
@@ -262,7 +263,7 @@ func TestGroundingProjectsAndResolvesUniqueAndSameNameLocations(t *testing.T) {
}
}
func TestGroundingHandlesEmptyRegistriesAndIdentityFingerprints(t *testing.T) {
func TestGroundingHandlesEmptyRegistriesAndStableUniqueNameProjection(t *testing.T) {
doc := groundingDocument()
empty := resolveList(t, dnd.LocationRegistry{Locations: []dnd.Location{}})
grounding, err := NewGrounding(empty, doc)
@@ -288,8 +289,8 @@ func TestGroundingHandlesEmptyRegistriesAndIdentityFingerprints(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if base.IdentityDigest() != expanded.IdentityDigest() || baseGrounding.PromptInput().Digest != expandedGrounding.PromptInput().Digest {
t.Fatalf("identity/model fingerprints = %q/%q and %q/%q", base.IdentityDigest(), expanded.IdentityDigest(), baseGrounding.PromptInput().Digest, expandedGrounding.PromptInput().Digest)
if base.Locations()[0].ID != expanded.Locations()[0].ID || !bytes.Equal(baseGrounding.PromptInput().Content, expandedGrounding.PromptInput().Content) {
t.Fatalf("additional evidence changed unique location identity or projection: %#v %#v", base.Locations(), expanded.Locations())
}
}