Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Remove the access members four serve-http E2E files add

garrytanf2f9eb4c7af4
diff --git a/test/e2e/helpers.ts b/test/e2e/helpers.ts
index 8cc7e06879..59e7dd0b2f 100644
--- a/test/e2e/helpers.ts
+++ b/test/e2e/helpers.ts
@@ -229,6 +229,17 @@ export async function setupLegacyEmbeddingDB(): Promise<PostgresEngine> {
return target;
}
+/**
+ * Delete the access members a file added. Two or more enabled members make the
+ * shared brain serve several people, and every later file's unbound remote
+ * reads are then refused with requester_scope_required. Deleting (not
+ * disabling) fires the serves trigger, which writes access.serves_derived
+ * back to one. Call in afterAll() before teardownDB().
+ */
+export async function removeMembers(ids: readonly string[]): Promise<void> {
+ await engine?.executeRaw('DELETE FROM access_members WHERE id = ANY($1::text[])', [ids]);
+}
+
/**
* Disconnect from DB. Call in afterAll() of each test file.
*/
diff --git a/test/e2e/serve-http-member-sweep.test.ts b/test/e2e/serve-http-member-sweep.test.ts
index 4367df1434..a2ada2832d 100644
--- a/test/e2e/serve-http-member-sweep.test.ts
+++ b/test/e2e/serve-http-member-sweep.test.ts
@@ -24,11 +24,12 @@ import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { operations } from '../../src/core/operations.ts';
import { attestableOp } from '../../src/core/access/actor.ts';
-import { hasDatabase, setupDB, teardownDB } from './helpers.ts';
+import { hasDatabase, removeMembers, setupDB, teardownDB } from './helpers.ts';
import { sweepArgs, type SweepFixture } from '../helpers/member-sweep.ts';
const ALICE_ID = 'U0ALICE';
const BOB_ID = 'oidc:3f2a:bob-example';
+const MEMBERS = ['alice-example', 'bob-example'];
const CANARY = { actor: 'canaryhttpaliceactor', key: 'canaryhttpalicekey', bob: 'canaryhttpbob' } as const;
const ATTESTABLE = operations.filter(op => attestableOp(op.name, op));
const KEYLESS_ENV = { OPENAI_API_KEY: '', ANTHROPIC_API_KEY: '', VOYAGE_API_KEY: '', GEMINI_API_KEY: '', GOOGLE_API_KEY: '', GBRAIN_SKIP_STARTUP_HOOKS: '1' };
@@ -52,7 +53,7 @@ for (const [index, backend] of backends.entries()) {
beforeAll(async () => {
if (backend === 'postgres') await setupDB();
else cli('init', '--pglite', '--no-embedding');
- for (const id of ['alice-example', 'bob-example']) cli('access', 'member', 'add', id);
+ for (const id of MEMBERS) cli('access', 'member', 'add', id);
bearer.alice = token(cli('auth', 'create', 'c2-alice-key', '--member', 'alice-example', '--scopes', 'read,write'));
bearer.bob = token(cli('auth', 'create', 'c2-bob-key', '--member', 'bob-example', '--scopes', 'read,write'));
bearer.plain = token(cli('auth', 'create', 'c2-plain-key', '--scopes', 'read,write', '--reads-unscoped', '--yes'));
@@ -84,7 +85,10 @@ for (const [index, backend] of backends.entries()) {
await new Promise(r => setTimeout(r, 1000));
if (!server.killed) server.kill('SIGKILL');
}
- if (backend === 'postgres') await teardownDB();
+ if (backend === 'postgres') {
+ await removeMembers(MEMBERS);
+ await teardownDB();
+ }
rmSync(home, { recursive: true, force: true });
}, 30_000);
diff --git a/test/e2e/serve-http-on-behalf-of.test.ts b/test/e2e/serve-http-on-behalf-of.test.ts
index baaead4784..9ece5c6241 100644
--- a/test/e2e/serve-http-on-behalf-of.test.ts
+++ b/test/e2e/serve-http-on-behalf-of.test.ts
@@ -13,7 +13,7 @@
* Run: DATABASE_URL=... GBRAIN_TEST_ALLOW_DATABASE_URL=1 bun test test/e2e/serve-http-on-behalf-of.test.ts
*/
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
-import { setupDB, teardownDB, hasDatabase } from './helpers.ts';
+import { setupDB, teardownDB, hasDatabase, removeMembers } from './helpers.ts';
import type { PostgresEngine } from '../../src/core/postgres-engine.ts';
import { importFromContent } from '../../src/core/import-file.ts';
import { mintLegacyToken } from '../../src/core/token-mint.ts';
@@ -24,6 +24,7 @@ const describeE2E = skip ? describe.skip : describe;
if (skip) console.log('Skipping E2E serve-http-on-behalf-of tests (DATABASE_URL not set)');
const PORT = 19162;
+const MEMBERS = ['alice-example', 'bob-example', 'dan-example'];
const BASE = `http://localhost:${PORT}`;
const PAGES = {
alice: { slug: 'notes/obo-alice', readers: '[alice-example]', canary: 'canaryoboealice' },
@@ -39,7 +40,7 @@ describeE2E('/mcp shared agent on_behalf_of over serve --http', () => {
beforeAll(async () => {
engine = await setupDB();
- for (const id of ['alice-example', 'bob-example', 'dan-example']) await addMember(engine, id);
+ for (const id of MEMBERS) await addMember(engine, id);
for (const key of Object.keys(PAGES) as Key[]) {
const p = PAGES[key];
const out = await importFromContent(engine, p.slug, `---\ntype: note\nreadable_by: ${p.readers}\n---\n# Harbor plan ${key}\n\nHarbor plan notes ${p.canary}.`, { noEmbed: true });
@@ -68,6 +69,7 @@ describeE2E('/mcp shared agent on_behalf_of over serve --http', () => {
await new Promise(r => setTimeout(r, 1000));
if (!serverProcess.killed) serverProcess.kill('SIGKILL');
}
+ await removeMembers(MEMBERS);
await teardownDB();
}, 30_000);
diff --git a/test/e2e/serve-http-qm-actor.test.ts b/test/e2e/serve-http-qm-actor.test.ts
index eb4f28d5e7..a5dcac376b 100644
--- a/test/e2e/serve-http-qm-actor.test.ts
+++ b/test/e2e/serve-http-qm-actor.test.ts
@@ -16,7 +16,7 @@
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
import { execFileSync } from 'node:child_process';
import { randomUUID } from 'node:crypto';
-import { setupDB, teardownDB, hasDatabase } from './helpers.ts';
+import { setupDB, teardownDB, hasDatabase, removeMembers } from './helpers.ts';
import type { PostgresEngine } from '../../src/core/postgres-engine.ts';
import { importFromContent } from '../../src/core/import-file.ts';
import { GBrainOAuthProvider } from '../../src/core/oauth-provider.ts';
@@ -36,6 +36,7 @@ const PAGES = {
} as const;
const ALICE_ID = 'U0ALICE';
const BOB_ID = 'oidc:3f2a:bob-example';
+const MEMBERS = ['alice-example', 'bob-example'];
describeE2E('/mcp attested actor (x-qm-actor) over serve --http', () => {
let serverProcess: ReturnType<typeof import('child_process').spawn> | null = null;
@@ -47,7 +48,7 @@ describeE2E('/mcp attested actor (x-qm-actor) over serve --http', () => {
beforeAll(async () => {
engine = await setupDB();
- for (const id of ['alice-example', 'bob-example']) await addMember(engine, id);
+ for (const id of MEMBERS) await addMember(engine, id);
for (const p of Object.values(PAGES)) {
const out = await importFromContent(engine, p.slug, `---\ntype: note\nreadable_by: ${p.readers}\n---\n# Harbor plan\n\nHarbor plan notes ${p.canary}.`, { noEmbed: true });
expect(out.status).toBe('imported');
@@ -88,6 +89,7 @@ describeE2E('/mcp attested actor (x-qm-actor) over serve --http', () => {
await new Promise(r => setTimeout(r, 1000));
if (!serverProcess.killed) serverProcess.kill('SIGKILL');
}
+ await removeMembers(MEMBERS);
await teardownDB();
}, 30_000);
diff --git a/test/e2e/serve-http-qm-memory.test.ts b/test/e2e/serve-http-qm-memory.test.ts
index 1718d0c374..b7ce1226ad 100644
--- a/test/e2e/serve-http-qm-memory.test.ts
+++ b/test/e2e/serve-http-qm-memory.test.ts
@@ -16,7 +16,7 @@
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
import { execFileSync } from 'node:child_process';
import { randomUUID } from 'node:crypto';
-import { setupDB, teardownDB, hasDatabase } from './helpers.ts';
+import { setupDB, teardownDB, hasDatabase, removeMembers } from './helpers.ts';
import type { PostgresEngine } from '../../src/core/postgres-engine.ts';
import { GBrainOAuthProvider } from '../../src/core/oauth-provider.ts';
import { sqlQueryForEngine } from '../../src/core/sql-query.ts';
@@ -30,6 +30,7 @@ const PORT = 19164;
const BASE = 'http://localhost:' + PORT;
const ALICE_ID = 'U0ALICE';
const BOB_ID = 'oidc:3f2a:bob-example';
+const MEMBERS = ['alice-example', 'bob-example'];
const KEYLESS: Record<string, string> = Object.fromEntries(Object.entries(process.env).filter(([k, v]) => v !== undefined && !/_API_(KEY|TOKEN)$/.test(k)) as Array<[string, string]>);
describeE2E('/mcp memory_recall and memory_write over keyless serve --http', () => {
@@ -40,7 +41,7 @@ describeE2E('/mcp memory_recall and memory_write over keyless serve --http', ()
beforeAll(async () => {
engine = await setupDB();
- for (const id of ['alice-example', 'bob-example']) await addMember(engine, id);
+ for (const id of MEMBERS) await addMember(engine, id);
const provider = new GBrainOAuthProvider({ sql: sqlQueryForEngine(engine), transaction: fn => engine.transaction(tx => fn(sqlQueryForEngine(tx))) });
const qm = await provider.registerClientManual('qm-mem-e2e-' + randomUUID().slice(0, 8), ['client_credentials'], 'read write', [], 'default');
const plain = await provider.registerClientManual('qm-mem-e2e-plain-' + randomUUID().slice(0, 8), ['client_credentials'], 'read write', [], 'default');
@@ -76,6 +77,7 @@ describeE2E('/mcp memory_recall and memory_write over keyless serve --http', ()
await new Promise(r => setTimeout(r, 1000));
if (!serverProcess.killed) serverProcess.kill('SIGKILL');
}
+ await removeMembers(MEMBERS);
await teardownDB();
}, 30_000);