package httpapi import ( "context" "encoding/json" "knowledge-governance/internal/governance" "knowledge-governance/internal/librarysnapshot" "testing" ) func (f *fakeLibraryStore) LibrarySourceCandidate(_ context.Context, scope, sourceID string) (governance.LibraryVersion, bool, error) { if f.sourceCandidate != nil && f.sourceCandidate.Scope == scope && f.sourceCandidate.Evidence["source_id"] == sourceID { return *f.sourceCandidate, true, nil } return governance.LibraryVersion{}, false, nil } // These fixtures now contain the same capture identity and real immutable // manifest required by the production admission path. No production bypass. func bindSourceFixture(t *testing.T, config *Config, store *fakeLibraryStore, target *string) string { t.Helper() if config.LibraryArchiveRoot == "" { config.LibraryArchiveRoot = libraryFixtureRoot(t) *target = sealSharedVersions(t, config.LibraryArchiveRoot, 1, 4)[0] } archive, err := librarysnapshot.Open(config.LibraryArchiveRoot, 256*1024*1024) if err != nil { t.Fatal(err) } defer archive.Close() manifest, err := archive.Load(*target) if err != nil { t.Fatal(err) } config.LibrarySourceProject = "fixture-project" config.LibrarySourceApp = "fixture-app" config.LibrarySourceTenantID = manifest.TenantID config.LibrarySourceInternalKB = manifest.KnowledgeBaseID source := configuredLibrarySource(*config, "internal") id, err := source.ID() if err != nil { t.Fatal(err) } store.sourceCandidate = &governance.LibraryVersion{Scope: "internal", Kind: governance.LibraryVersionTestSealed, SnapshotID: *target, Evidence: map[string]any{"source_id": id}} if store.grant != nil { store.grant.SnapshotID = *target store.grant.ParamsDigest, _ = librarySyncParamsDigest("internal", *target) } return id } func sourceRequestBody(t *testing.T, body, id string) string { t.Helper() var v map[string]any if err := json.Unmarshal([]byte(body), &v); err != nil { t.Fatal(err) } v["source_id"] = id raw, err := json.Marshal(v) if err != nil { t.Fatal(err) } return string(raw) }