index.Module is gone: the indexer and its registry carry the credential's module (findings' observer and ids, its own entry and graph key, the history subject, the views emitter and reader), the tools take the served-as module. Builds: design 47 G A-296, §428 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
59 lines
2.9 KiB
Go
59 lines
2.9 KiB
Go
package index
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
)
|
|
|
|
// Design 47 G §675: the entry kept for a build-input fingerprint is found by it, through the key entry-index holds for the
|
|
// digest of its object; a fingerprint no entry carries is answered with an error naming it.
|
|
func TestEntryFindsAnEntryByItsFingerprint(t *testing.T) {
|
|
ctx := context.Background()
|
|
fp := "src2:" + strings.Repeat("b", 64)
|
|
ix := &Indexer{Module: testSelf, Revisions: newMemObjects(1 << 20), EntryIndex: newMem(), Now: func() time.Time { return time.Date(2026, 11, 1, 3, 0, 0, 0, time.UTC) }}
|
|
entries := map[string]meshcatalog.CatalogEntry{
|
|
"avahi": {Module: "avahi", Repository: "novox/r", Commit: "c", Fp: fp, Manifest: map[string]any{}},
|
|
"none": {Module: "none", Repository: "novox/r", Commit: "c", Manifest: map[string]any{}},
|
|
}
|
|
rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: 1, Kind: "trunk"}, entries)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := ix.indexEntries(ctx, rev, entries); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got, err := Entry(ctx, ix.Revisions, ix.EntryIndex, meshcatalog.EntryInput{Fingerprint: fp}); err != nil || got.Entry.Module != "avahi" {
|
|
t.Fatalf("entry of %s: %+v %v, want avahi's", fp, got, err)
|
|
}
|
|
if keys, _ := ix.EntryIndex.Keys(ctx); len(keys) != 1 {
|
|
t.Errorf("entry-index holds %v, want the one key of the entry that has a fingerprint", keys)
|
|
}
|
|
if _, err := Entry(ctx, ix.Revisions, ix.EntryIndex, meshcatalog.EntryInput{Fingerprint: "src2:" + strings.Repeat("c", 64)}); err == nil || !strings.Contains(err.Error(), "no entry of fingerprint") {
|
|
t.Errorf("an unknown fingerprint: %v, want an error naming it", err)
|
|
}
|
|
if _, err := Entry(ctx, ix.Revisions, ix.EntryIndex, meshcatalog.EntryInput{}); err == nil {
|
|
t.Errorf("no fingerprint was answered")
|
|
}
|
|
}
|
|
|
|
// Design 47 G §675: the revision the indexer keeps writes entry-index for every entry that has a fingerprint, before it keeps
|
|
// the revision, so entry finds the entry as soon as the revision is kept.
|
|
func TestAKeptRevisionIndexesItsEntries(t *testing.T) {
|
|
ctx := context.Background()
|
|
fp := "src2:" + strings.Repeat("d", 64)
|
|
ix := &Indexer{Module: testSelf, Revisions: newMemObjects(1 << 20), EntryIndex: newMem(), Now: func() time.Time { return time.Date(2026, 11, 1, 3, 0, 0, 0, time.UTC) }}
|
|
if err := ix.keepEntries(ctx, map[string]meshcatalog.CatalogEntry{"avahi": {Module: "avahi", Repository: "novox/r", Commit: "c", Fp: fp, Manifest: map[string]any{}}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got, err := Entry(ctx, ix.Revisions, ix.EntryIndex, meshcatalog.EntryInput{Fingerprint: fp}); err != nil || got.Entry.Module != "avahi" {
|
|
t.Fatalf("entry of %s after the revision was kept: %+v %v", fp, got, err)
|
|
}
|
|
}
|