Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(attribution): pre-attribution rows survive F1a triggers; enumerate attribution-backfill in repair kind lists

garrytan311ccdcfc248
diff --git a/test/corrective-containment.test.ts b/test/corrective-containment.test.ts
index f47bd9e2c8..916c9f0c9b 100644
--- a/test/corrective-containment.test.ts
+++ b/test/corrective-containment.test.ts
@@ -63,6 +63,8 @@ describe('remote history uses strict body sanitization', () => {
const getVersions = mock(async () => [version]);
const result = await operationsByName.get_versions.handler(context({
getVersions: getVersions as never,
+ // Trusted local history also reads write attribution (Foundations 1 F1b); none is recorded here.
+ executeRaw: (async () => []) as never,
// Even an operator opt-out cannot disable the Facts/Takes boundary.
getConfig: async () => 'visible',
}, { remote: remote as boolean, sourceId: 'default', takesHoldersAllowList }), { slug: 'example-page' }) as Array<{ compiled_truth: string }>;
diff --git a/test/fix-wave-3-integration.test.ts b/test/fix-wave-3-integration.test.ts
index 49c98ed9be..e3ae5841c9 100644
--- a/test/fix-wave-3-integration.test.ts
+++ b/test/fix-wave-3-integration.test.ts
@@ -431,7 +431,7 @@ test('check 9: every registered repair kind reaches the remediation plan with it
await engine.executeRaw("UPDATE pages SET contextual_retrieval_mode=NULL,chunker_version=1,text_projection_revision=gen_random_uuid() WHERE source_id=$1 AND slug='people/second-example'", [f.id]);
await engine.executeRaw("INSERT INTO op_checkpoints(op,fingerprint,completed_keys,updated_at) VALUES('managed-connector',$1,'[]'::jsonb,now()-interval '9 days')", [`orphan-${randomUUID()}`]);
const kinds = AUTO_REPAIR_REGISTRY.map(spec => spec.kind);
- expect(kinds).toEqual(['timeline', 'visibility', 'safe-chunks', 'contextual-mode', 'connector-checkpoints', 'request-indexes', 'connector-fences', 'orphan-bindings', 'embedding-effects']);
+ expect(kinds).toEqual(['timeline', 'visibility', 'safe-chunks', 'contextual-mode', 'connector-checkpoints', 'request-indexes', 'connector-fences', 'orphan-bindings', 'embedding-effects', 'attribution-backfill']);
const planned = Object.fromEntries((await planRepairSteps(engine, { noEmbed: true })).map(step => [step.kind, step]));
expect(planned['contextual-mode']).toMatchObject({ paid: false, embeds: 'inline', command: 'gbrain repair contextual-mode --no-embed --apply' });
expect(planned['connector-checkpoints']).toMatchObject({ paid: false, embeds: 'none' });
diff --git a/test/fix-wave-4-integration.test.ts b/test/fix-wave-4-integration.test.ts
index 0c53d5db09..b8d9ff0b2b 100644
--- a/test/fix-wave-4-integration.test.ts
+++ b/test/fix-wave-4-integration.test.ts
@@ -210,7 +210,7 @@ test('X6: deactivate carries a held connector item into classic state (wave 5):
test('X11: the remediation run reaches every new repair kind, runs the free ones under --max-usd 0 and clears their doctor findings', async () => withEnv(env, async () => {
for (const engine of engines) {
expect(AUTO_REPAIR_REGISTRY.map(spec => spec.kind)).toEqual(['timeline', 'visibility', 'safe-chunks', 'contextual-mode', 'connector-checkpoints',
- 'request-indexes', 'connector-fences', 'orphan-bindings', 'embedding-effects']);
+ 'request-indexes', 'connector-fences', 'orphan-bindings', 'embedding-effects', 'attribution-backfill']);
// Pending work for Lane A (a dropped index) and Lane D (an orphan binding of a removed source).
await engine.executeRaw('DROP INDEX IF EXISTS persistence_requests_sync_run_open');
await withPersistenceOff(engine, async () => {
diff --git a/test/repair-command.test.ts b/test/repair-command.test.ts
index 6a01e3aec2..153f3f5a89 100644
--- a/test/repair-command.test.ts
+++ b/test/repair-command.test.ts
@@ -174,7 +174,7 @@ describe('gbrain repair timeline', () => {
} finally { console.log = log; }
const json = JSON.parse(out[0]);
expect(json.scope.source_ids).toEqual([source]);
- expect(json.results.map((r: { kind: string }) => r.kind)).toEqual(['timeline', 'visibility', 'safe-chunks', 'contextual-mode', 'connector-checkpoints', 'request-indexes', 'connector-fences', 'orphan-bindings', 'embedding-effects']);
+ expect(json.results.map((r: { kind: string }) => r.kind)).toEqual(['timeline', 'visibility', 'safe-chunks', 'contextual-mode', 'connector-checkpoints', 'request-indexes', 'connector-fences', 'orphan-bindings', 'embedding-effects', 'attribution-backfill']);
expect(json.results[0]).toMatchObject({ mode: 'dry_run', affected: 1 });
expect(out[1]).toContain(`Scope: brain `);
expect(out[1]).toContain(`sources ${source}`);
diff --git a/test/write-attribution-read.test.ts b/test/write-attribution-read.test.ts
index 40ff3e7c3f..ee4d043ab6 100644
--- a/test/write-attribution-read.test.ts
+++ b/test/write-attribution-read.test.ts
@@ -60,6 +60,30 @@ function remote(sourceId: string, scopes: string[]): OperationContext {
const ATTRIBUTION_KEY = /write|archived|principal|written_by|archived_by/;
+/**
+ * Make a source's rows look written before attribution existed. With lane
+ * F1a's stamping triggers present, journaled writes are attributed at write
+ * time and attribution is immutable once set, so only a trigger-bypassing
+ * session (test setup only) can recreate pre-attribution rows.
+ */
+async function rawAttributionWrite(sql: string, params: unknown[]) {
+ await engine.transaction(async tx => {
+ await tx.executeRaw('SET LOCAL session_replication_role = replica');
+ await tx.executeRaw(sql, params);
+ });
+}
+
+async function asPreAttributionRows(sourceId: string) {
+ await rawAttributionWrite(`UPDATE pages SET revision_write_request_id=NULL, revision_principal_kind=NULL, revision_principal_id=NULL
+ WHERE source_id=$1`, [sourceId]);
+ await rawAttributionWrite(`UPDATE page_versions SET write_request_id=NULL, write_principal_kind=NULL, write_principal_id=NULL,
+ archived_write_request_id=NULL, archived_principal_kind=NULL, archived_principal_id=NULL
+ WHERE page_id IN (SELECT id FROM pages WHERE source_id=$1)`, [sourceId]);
+ await rawAttributionWrite(`UPDATE facts SET write_request_id=NULL, write_principal_kind=NULL, write_principal_id=NULL,
+ last_write_request_id=NULL, last_write_principal_kind=NULL, last_write_principal_id=NULL, last_written_at=NULL
+ WHERE source_id=$1`, [sourceId]);
+}
+
async function seedNames() {
await engine.executeRaw(`INSERT INTO oauth_clients(client_id, client_name) VALUES('client-example', 'agent-example') ON CONFLICT DO NOTHING`);
const [token] = await engine.executeRaw<{ id: string }>(
@@ -222,6 +246,7 @@ describe('attribution-backfill (spec 2.6, test 13)', () => {
const revisionOf = async (slug: string) => (await engine.executeRaw<Record<string, string | null>>(
'SELECT revision_write_request_id::text AS req, revision_principal_kind AS kind FROM pages WHERE source_id=$1 AND slug=$2', [sourceId, slug]))[0];
+ await asPreAttributionRows(sourceId);
const scope = await resolveRepairScope(engine, sourceId);
const preview = await runRepair(ctx, attributionBackfillRepair, scope, { apply: false });
expect(preview.mode).toBe('dry_run');
@@ -249,7 +274,7 @@ describe('attribution-backfill (spec 2.6, test 13)', () => {
expect(again).toMatchObject({ affected: 0, applied: 0, complete: true, resumed_from: null });
expect(await alpha()).toEqual({ req: r2.id, kind: 'local_cli', pid: r2.principal_id });
- await engine.executeRaw(`UPDATE pages SET revision_write_request_id=NULL, revision_principal_kind='oauth_client', revision_principal_id='client-example'
+ await rawAttributionWrite(`UPDATE pages SET revision_write_request_id=NULL, revision_principal_kind='oauth_client', revision_principal_id='client-example'
WHERE source_id=$1 AND slug='notes/alpha'`, [sourceId]);
await runRepair(ctx, attributionBackfillRepair, scope, { apply: true });
expect(await alpha()).toEqual({ req: null, kind: 'oauth_client', pid: 'client-example' });