Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Tests: a scoped reader no longer sees a link written by a page outside its grant

garrytane073a843b052
diff --git a/test/attendance-retrieval.test.ts b/test/attendance-retrieval.test.ts
index 6adf454527..79f050a871 100644
--- a/test/attendance-retrieval.test.ts
+++ b/test/attendance-retrieval.test.ts
@@ -724,7 +724,13 @@ for (const kind of testBackends()) {
await engine.putPage('notes/hidden', { type: 'note', title: 'Hidden origin', compiled_truth: 'Independent.' }, { sourceId: hidden });
await engine.addLink(person, meeting, 'Other origin', 'mentions', 'markdown', 'notes/hidden', undefined,
{ fromSourceId: sourceId, toSourceId: sourceId, originSourceId: hidden });
- expect((await engine.getLinks(person, { sourceIds: [sourceId] })).find(row => row.link_type === 'mentions')).toMatchObject({ origin_slug: null, origin_source_id: null });
+ await engine.addLink(person, meeting, 'Granted origin', 'mentions', 'markdown', meeting, undefined,
+ { fromSourceId: sourceId, toSourceId: sourceId, originSourceId: sourceId });
+ const scoped = await engine.getLinks(person, { sourceIds: [sourceId] });
+ expect(scoped.filter(row => row.link_type === 'mentions')).toMatchObject([{ origin_slug: meeting, origin_source_id: sourceId, context: 'Granted origin' }]);
+ expect(scoped.map(row => row.origin_slug)).not.toContain('notes/hidden');
+ expect(scoped.map(row => row.origin_source_id)).not.toContain(hidden);
+ expect(scoped.map(row => row.context)).not.toContain('Other origin');
});
test('failed filesystem attendance replacement stays retryable and preserves the last good graph', async () => {
await seed(meeting, 'meeting', positive);
diff --git a/test/e2e/engine-parity.test.ts b/test/e2e/engine-parity.test.ts
index d6b601c87d..94cefb71db 100644
--- a/test/e2e/engine-parity.test.ts
+++ b/test/e2e/engine-parity.test.ts
@@ -1437,8 +1437,10 @@ async function seedFederated(eng: BrainEngine) {
await eng.addLink('fed/doc', 'fed/outside', 'leak', 'cites', 'markdown', undefined, undefined, { fromSourceId: 'beta', toSourceId: 'default' });
await eng.addLink('fed/target', 'fed/doc', 'inback', 'cites', 'markdown', undefined, undefined, { fromSourceId: 'beta', toSourceId: 'beta' });
await eng.addLink('fed/outside', 'fed/doc', 'leakback', 'cites', 'markdown', undefined, undefined, { fromSourceId: 'default', toSourceId: 'beta' });
- // F1: in-grant edge authored by an out-of-grant origin — origin_slug must null out.
+ // F1: in-grant edge authored by an out-of-grant origin is withheld under the grant;
+ // the same edge authored by an in-grant origin is the control that stays visible.
await eng.addLink('fed/doc', 'fed/target', 'originleak', 'mentions', 'frontmatter', 'fed/outside', 'related', { fromSourceId: 'beta', toSourceId: 'beta', originSourceId: 'default' });
+ await eng.addLink('fed/doc', 'fed/target', 'origingranted', 'mentions', 'frontmatter', 'fed/target', 'related', { fromSourceId: 'beta', toSourceId: 'beta', originSourceId: 'beta' });
await eng.addTimelineEntry('fed/doc', { date: '2026-02-02', source: 't', summary: 'fed event', detail: 'd' }, { sourceId: 'beta' });
// Second-dated entry so the after/before fragment paths (D5A Postgres refactor) are exercised.
await eng.addTimelineEntry('fed/doc', { date: '2026-08-08', source: 't', summary: 'late event', detail: 'd' }, { sourceId: 'beta' });
@@ -1488,10 +1490,14 @@ describeBoth('Engine parity — federated sourceIds[] secondary reads (#2200)',
expect(exactLinkShape(pgLinks)).toEqual(exactLinkShape(pgliteLinks));
expect([...new Set(pgLinks.map(l => `${l.to_source_id}:${l.to_slug}`))])
.toEqual(['beta:fed/target']); // far-endpoint 'fed/outside' excluded
- // F1: origin identity nulls identically when origin is out-of-grant.
+ // F1: an edge whose origin is out-of-grant is absent on both engines; the in-grant-origin control stays.
const pgOrigins = pgLinks.map(l => [l.origin_source_id ?? null, l.origin_slug ?? null]);
const pgliteOrigins = pgliteLinks.map(l => [l.origin_source_id ?? null, l.origin_slug ?? null]);
expect(pgOrigins.sort()).toEqual(pgliteOrigins.sort());
+ for (const links of [pgLinks, pgliteLinks]) {
+ expect(links.filter(l => l.link_type === 'mentions').map(l => [l.origin_source_id, l.origin_slug, l.context])).toEqual([['beta', 'fed/target', 'origingranted']]);
+ expect(links.map(l => l.context)).not.toContain('originleak');
+ }
expect(pgOrigins).not.toContainEqual(['default', 'fed/outside']);
});
diff --git a/test/get-page-federated-scope.test.ts b/test/get-page-federated-scope.test.ts
index b8bb17a2b6..60b7444464 100644
--- a/test/get-page-federated-scope.test.ts
+++ b/test/get-page-federated-scope.test.ts
@@ -370,14 +370,22 @@ describe('#2200 get_links honors the grant and scopes BOTH endpoints (D4A)', ()
expect(links).toEqual([]);
});
- test('F1: in-grant link authored by an out-of-grant origin does NOT leak origin_slug', async () => {
- const links = (await get_links.handler(remoteCtx(['alpha', 'beta']), { slug: 'secret/beta-doc' })) as any[];
- const originLeakLink = links.find(l => l.link_type === 'mentions' && l.to_slug === 'secret/beta-target');
- expect(originLeakLink).toBeDefined();
- // origin page 'default/only-doc' is out of the [alpha,beta] grant → origin identity nulled.
- expect(originLeakLink.origin_slug ?? null).toBeNull();
- expect(originLeakLink.origin_source_id ?? null).toBeNull();
- expect(links.map(l => l.origin_slug)).not.toContain('default/only-doc');
+ test('F1: in-grant link authored by an out-of-grant origin is withheld, origin and context included', async () => {
+ await engine.addLink('secret/beta-doc', 'secret/beta-target', 'granted-origin ctx', 'mentions', 'frontmatter', 'secret/beta-target', 'related', { fromSourceId: 'beta', toSourceId: 'beta', originSourceId: 'beta' });
+ try {
+ const links = (await get_links.handler(remoteCtx(['alpha', 'beta']), { slug: 'secret/beta-doc' })) as any[];
+ const mentions = links.filter(l => l.link_type === 'mentions' && l.to_slug === 'secret/beta-target');
+ // Control: the same edge authored by an in-grant origin comes back with its origin.
+ expect(mentions).toHaveLength(1);
+ expect(mentions[0]).toMatchObject({ origin_source_id: 'beta', origin_slug: 'secret/beta-target' });
+ expect(String(mentions[0].context)).toContain('granted-origin ctx');
+ // origin page 'default/only-doc' is out of the [alpha,beta] grant → its edge is absent.
+ expect(links.map(l => l.origin_slug)).not.toContain('default/only-doc');
+ expect(links.map(l => l.origin_source_id)).not.toContain('default');
+ expect(links.some(l => String(l.context).includes('origin-leak ctx'))).toBe(false);
+ } finally {
+ await engine.executeRaw(`DELETE FROM links WHERE context = 'granted-origin ctx'`);
+ }
});
test('D1: UNTRUSTED remote with a scalar source scope is promoted to all-endpoint scoping (no far-endpoint leak)', async () => {