Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(persistence): request-index suites list the #6757 request-id index (#6757)

garrytan4286691d0155
diff --git a/test/e2e/persistence-request-indexes-postgres.test.ts b/test/e2e/persistence-request-indexes-postgres.test.ts
index e355372658..6e31b7cc4e 100644
--- a/test/e2e/persistence-request-indexes-postgres.test.ts
+++ b/test/e2e/persistence-request-indexes-postgres.test.ts
@@ -107,23 +107,23 @@ test('#5762 the Postgres blob never builds the indexes; v179 builds them concurr
try { await v179.handler!(engine); } finally { engine.withReservedConnection = reserve; }
expect(statements.filter(sql => sql.startsWith('CREATE INDEX CONCURRENTLY IF NOT EXISTS')).map(sql => sql.split(/\s+/)[6])).toEqual(NAMES);
expect(statements.filter(sql => /^(SET|RESET)\b/i.test(sql))).toEqual([]);
- expect(await states()).toEqual(['valid', 'valid', 'valid']);
+ expect(await states()).toEqual(['valid', 'valid', 'valid', 'valid']);
}), 120_000);
test('#5762 gbrain repair request-indexes rebuilds a dropped and an INVALID index on a current schema; a second run is a no-op', async () => withEnv(env, async () => {
await engine.executeRaw('DROP INDEX persistence_requests_sync_run_open');
await engine.executeRaw("UPDATE pg_index SET indisvalid=false WHERE indexrelid='persistence_requests_sync_run_committed'::regclass");
- expect(await readRequestIndexStates(engine)).toEqual([{ name: NAMES[0], state: 'missing' }, { name: NAMES[1], state: 'invalid' }, { name: ALL_NAMES[2], state: 'valid' }]);
+ expect(await readRequestIndexStates(engine)).toEqual([{ name: NAMES[0], state: 'missing' }, { name: NAMES[1], state: 'invalid' }, { name: ALL_NAMES[2], state: 'valid' }, { name: ALL_NAMES[3], state: 'valid' }]);
const doctor = await requestIndexesCheck(engine);
expect(doctor).toMatchObject({ name: 'persistence_request_indexes', status: 'warn', details: { count: 2, command: 'gbrain repair request-indexes --apply' } });
expect(doctor.message).toContain('persistence_requests_sync_run_committed is INVALID');
const scope = await resolveRepairScope(engine);
const preview = await runRepair(ctx(), requestIndexesRepair, scope, { apply: false });
expect(preview).toMatchObject({ affected: 2, cost: { lifetime_ids: 0 }, apply_command: 'gbrain repair request-indexes --apply' });
- expect(await states()).toEqual(['missing', 'invalid', 'valid']);
+ expect(await states()).toEqual(['missing', 'invalid', 'valid', 'valid']);
const applied = await runRepair(ctx(), requestIndexesRepair, scope, { apply: true });
expect(applied).toMatchObject({ applied: 2, complete: true });
- expect(await states()).toEqual(['valid', 'valid', 'valid']);
+ expect(await states()).toEqual(['valid', 'valid', 'valid', 'valid']);
expect((await requestIndexesCheck(engine)).status).toBe('ok');
expect(await runRepair(ctx(), requestIndexesRepair, scope, { apply: true })).toMatchObject({ affected: 0, applied: 0, complete: true });
}), 120_000);
@@ -142,7 +142,7 @@ test('#5762 a build that leaves the index INVALID (a concurrent caller failed fi
try { await expect(buildIndexOnline(engine, 0, index)).rejects.toThrow(`Index ${index.name} is not valid after its concurrent build`); }
finally { engine.withReservedConnection = reserve; }
expect(await buildIndexOnline(engine, 0, index)).toBe('rebuilt');
- expect(await states()).toEqual(['valid', 'valid', 'valid']);
+ expect(await states()).toEqual(['valid', 'valid', 'valid', 'valid']);
}), 60_000);
test('#5762 recovery journey: a checkpoint timeout with a dropped index is fixed by the two printed commands', async () => withEnv(env, async () => {
diff --git a/test/fix-wave-4-integration.test.ts b/test/fix-wave-4-integration.test.ts
index b0c040cd6a..878ff4bf15 100644
--- a/test/fix-wave-4-integration.test.ts
+++ b/test/fix-wave-4-integration.test.ts
@@ -77,8 +77,8 @@ test('X1: an upgrade from v178 builds the request indexes; managed working-tree
await engine.executeRaw('DROP INDEX IF EXISTS persistence_requests_sync_run_committed');
await engine.setConfig('version', '178');
expect(await runMigrations(engine)).toEqual({ applied: LATEST_VERSION - 178, current: LATEST_VERSION });
- // #6511: the online-built set is the checkpoint pair plus the purge slug index.
- expect((await readRequestIndexStates(engine)).map(index => index.state)).toEqual(['valid', 'valid', 'valid']);
+ // #6511/#6757: the online-built set is the checkpoint pair, the purge slug index and the request-id index.
+ expect((await readRequestIndexStates(engine)).map(index => index.state)).toEqual(['valid', 'valid', 'valid', 'valid']);
expect((await requestIndexesCheck(engine)).status).toBe('ok');
const id = `x1-${randomUUID().slice(0, 8)}`, root = join(home, id);
@@ -230,7 +230,7 @@ test('X11: the remediation run reaches every new repair kind, runs the free ones
const byKind = Object.fromEntries(run.repairs.map((r: { kind: string }) => [r.kind, r]));
expect(byKind['request-indexes']).toMatchObject({ status: 'completed' });
expect(byKind['orphan-bindings']).toMatchObject({ status: 'completed' });
- expect((await readRequestIndexStates(engine)).map(index => index.state)).toEqual(['valid', 'valid', 'valid']);
+ expect((await readRequestIndexStates(engine)).map(index => index.state)).toEqual(['valid', 'valid', 'valid', 'valid']);
expect(await engine.executeRaw("SELECT 1 FROM persistence_source_bindings WHERE source_id='x11-orphan'")).toEqual([]);
const replanned = (await planRepairSteps(engine, { noEmbed: true })).map(step => step.kind);
expect(replanned).not.toContain('request-indexes');
diff --git a/test/migration-persistence-request-id-index.test.ts b/test/migration-persistence-request-id-index.test.ts
index 7e148dc6c3..6c7a63c513 100644
--- a/test/migration-persistence-request-id-index.test.ts
+++ b/test/migration-persistence-request-id-index.test.ts
@@ -38,7 +38,7 @@ describe('#6757 the request-id index migration module', () => {
test('is registered once in the v179 online-index shape', () => {
expect(MIGRATIONS.filter(m => m.name === 'persistence_request_id_index')).toHaveLength(1);
expect(migration).toMatchObject({ idempotent: true, transaction: false, sql: '' });
- expect(migration!.version).toBeGreaterThan(249);
+ expect(migration!.version).toBeGreaterThan(MIGRATIONS.find(m => m.name === 'persistence_request_slug_intent_index')!.version);
expect(migration!.version).toBeLessThanOrEqual(LATEST_SCHEMA_VERSION);
expect(typeof migration!.handler).toBe('function');
});
diff --git a/test/persistence-request-indexes.test.ts b/test/persistence-request-indexes.test.ts
index 8cbec83d2b..e57c1a8d5f 100644
--- a/test/persistence-request-indexes.test.ts
+++ b/test/persistence-request-indexes.test.ts
@@ -42,12 +42,12 @@ test('#5762 gbrain repair request-indexes rebuilds a dropped index inline on PGL
await engine.executeRaw(`DROP INDEX ${NAMES[1]}`);
const doctor = await requestIndexesCheck(engine);
expect(doctor).toMatchObject({ status: 'warn', details: { count: 1, repair: 'request-indexes', docs: 'docs/guides/repair.md#request-indexes' } });
- expect(doctor.message).toBe(`${NAMES[1]} is missing: managed sync checkpoints can time out on a large request table. Rebuild on the brain host: gbrain repair request-indexes --apply`);
+ expect(doctor.message).toBe(`${NAMES[1]} is missing: request-table reads (managed sync checkpoints, page purges, dream synthesis postprocessing) can time out on a large request table. Rebuild on the brain host: gbrain repair request-indexes --apply`);
const scope = await resolveRepairScope(engine);
expect(await runRepair(ctx(), requestIndexesRepair, scope, { apply: false })).toMatchObject({ affected: 1, sample: [`(brain):${NAMES[1]}`], cost: { lifetime_ids: 0, embedding_pages: 0 } });
expect(await runRepair(ctx(), requestIndexesRepair, scope, { apply: true })).toMatchObject({ applied: 1, complete: true });
// #6511: the online-built set is the checkpoint pair plus the purge slug index.
- expect((await readRequestIndexStates(engine)).map(index => index.state)).toEqual(['valid', 'valid', 'valid']);
+ expect((await readRequestIndexStates(engine)).map(index => index.state)).toEqual(['valid', 'valid', 'valid', 'valid']);
expect(await runRepair(ctx(), requestIndexesRepair, scope, { apply: true })).toMatchObject({ affected: 0, applied: 0 });
}, 60_000);
diff --git a/test/persistence-sync-checkpoint-validation.test.ts b/test/persistence-sync-checkpoint-validation.test.ts
index 69e4fe530f..1dbbd61ee1 100644
--- a/test/persistence-sync-checkpoint-validation.test.ts
+++ b/test/persistence-sync-checkpoint-validation.test.ts
@@ -196,12 +196,13 @@ test('#5762 the hint names one of three index states and keeps the saved process
});
test('#5762 a dropped index reads as missing and the hint then names the rebuild command', async () => each(async engine => {
- // #6511 added the purge slug index to the online-built set; the default read lists it after the checkpoint pair.
- expect((await readRequestIndexStates(engine)).map(index => index.state)).toEqual(['valid', 'valid', 'valid']);
+ // #6511 and #6757 added the purge slug and request-id indexes to the online-built set; the default read lists them after the checkpoint pair.
+ expect((await readRequestIndexStates(engine)).map(index => index.state)).toEqual(['valid', 'valid', 'valid', 'valid']);
await engine.executeRaw('DROP INDEX persistence_requests_sync_run_committed');
try {
expect(await readRequestIndexStates(engine)).toEqual([{ name: 'persistence_requests_sync_run_open', state: 'valid' },
- { name: 'persistence_requests_sync_run_committed', state: 'missing' }, { name: 'persistence_requests_slug_intent', state: 'valid' }]);
+ { name: 'persistence_requests_sync_run_committed', state: 'missing' }, { name: 'persistence_requests_slug_intent', state: 'valid' },
+ { name: 'persistence_requests_request_id', state: 'valid' }]);
} finally {
const { PERSISTENCE_SYNC_RUN_COMMITTED_INDEX_SQL } = await import('../src/core/persistence/schema.ts');
await engine.executeRaw(PERSISTENCE_SYNC_RUN_COMMITTED_INDEX_SQL);
diff --git a/test/postgres-unit-arms.txt b/test/postgres-unit-arms.txt
index d58b06db4a..d9729bfb3a 100644
--- a/test/postgres-unit-arms.txt
+++ b/test/postgres-unit-arms.txt
@@ -114,6 +114,7 @@ test/managed-sync-pinned-reads.test.ts
test/managed-sync-preparation-stalled-holds.test.ts
test/managed-sync-row-parity.test.ts
test/managed-sync-stale-group-head.test.ts
+test/migration-persistence-request-id-index.test.ts
test/migration-persistence-request-slug-index.test.ts
test/owner-refusal.test.ts
test/pack-relation-direction-engine.test.ts