Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: Step 11 review fixes (git policy keeps invalid coverage until the corrected rules are installed; remove_link answers hidden pages as missing)
garrytanae5cc8939be4
diff --git a/src/core/access/policy-git.ts b/src/core/access/policy-git.tsindex 5d66beb583..e339166a97 100644--- a/src/core/access/policy-git.ts+++ b/src/core/access/policy-git.ts@@ -100,8 +100,8 @@ export async function syncGitPolicy(engine: BrainEngine, sourceId: string, root:if (store !== 'git') await writeAccessStore(engine, sourceId, 'git');return { source_id: sourceId, state: 'invalid', problems: desired.problems, commit: files.commit, approved_file: approvedFile };}- await clearPolicyInvalid(engine, sourceId);const proposal = await proposeRevision(engine, sourceId, desired.rules, { origin: 'git', store: 'git', proposedBy: files.commit ? `git:${files.commit}` : 'git', onProgress: opts.onProgress });+ await clearPolicyInvalid(engine, sourceId);return { source_id: sourceId, state: proposal.state, proposal, commit: files.commit, approved_file: approvedFile };}diff --git a/src/core/ops/links.ts b/src/core/ops/links.tsindex ce5a92e7a2..7d0c2ba88e 100644--- a/src/core/ops/links.ts+++ b/src/core/ops/links.ts@@ -1,5 +1,6 @@import { managedPersistenceEnabled } from '../persistence/ownership.ts';import { submitPageMutation } from '../persistence/page-mutations.ts';+import { remoteTargetHidden } from '../persistence/page-visibility.ts';import { WRITE_REQUEST_PARAM } from '../persistence/params.ts';import { MANAGED_LINK_SOURCES } from '../links-fence.ts';import { backlinkTypeFilter, readBacklinkPage, withLinkPageStatus } from './backlinks-paged.ts';@@ -200,6 +201,9 @@ const remove_link: Operation = {handler: async (ctx, p) => {enforceClientSlugFence(ctx, p.from as string, 'remove_link');if (ctx.dryRun) return { dry_run: true, action: 'remove_link', from: p.from, to: p.to };+ const writeSource = ctx.sourceId || 'default';+ if (await remoteTargetHidden(ctx.engine, ctx.remote, writeSource, p.from as string)+ || await remoteTargetHidden(ctx.engine, ctx.remote, writeSource, p.to as string)) return { status: 'ok', removed: 0 };await primeRelationSemantics(ctx.engine);const linkOpts = ctx.sourceId? { fromSourceId: ctx.sourceId, toSourceId: ctx.sourceId }diff --git a/test/access-folder-rules-git.test.ts b/test/access-folder-rules-git.test.tsindex 1faa44fb1e..5569d548d0 100644--- a/test/access-folder-rules-git.test.ts+++ b/test/access-folder-rules-git.test.ts@@ -154,6 +154,29 @@ describe('folder access rules, git store', () => {expect((await policyStatus(engine, SRC)).invalid).toEqual([]);}, 120_000);+ test('correcting an invalid file keeps its coverage until the replacement rules are installed: an interrupted sync reveals nothing', async () => {+ writePolicy(root, 'version: 1\nrules: [\n');+ git(root, 'commit', '-q', '-am', 'broken yaml again');+ await syncAccessPolicyAt(engine, SRC, root);+ expect((await policyStatus(engine, SRC)).invalid.map(c => c.prefix)).toEqual(['']);+ writePolicy(root, POLICY([['team', 'partners/', 'alice-example, bob-example'], ['hr', 'hr/', 'alice-example']]));+ git(root, 'commit', '-q', '-am', 'fixed with a new rule');+ await engine.executeRaw(`CREATE FUNCTION zz_refuse_revision() RETURNS trigger LANGUAGE plpgsql AS $fn$ BEGIN RAISE EXCEPTION 'interrupted install'; END $fn$`);+ await engine.executeRaw('CREATE TRIGGER zz_refuse_revision BEFORE INSERT ON access_policy_revisions FOR EACH ROW EXECUTE FUNCTION zz_refuse_revision()');+ try {+ await expect(syncAccessPolicyAt(engine, SRC, root)).rejects.toThrow('interrupted install');+ expect((await policyStatus(engine, SRC)).invalid.map(c => c.prefix)).toEqual(['']);+ } finally {+ await engine.executeRaw('DROP TRIGGER zz_refuse_revision ON access_policy_revisions');+ await engine.executeRaw('DROP FUNCTION zz_refuse_revision()');+ }+ writePolicy(root, POLICY([['team', 'partners/', 'alice-example, bob-example']]));+ git(root, 'commit', '-q', '-am', 'fixed');+ await syncAccessPolicyAt(engine, SRC, root);+ const s = await policyStatus(engine, SRC);+ expect({ rules: s.rules.map(r => r.id), invalid: s.invalid }).toEqual({ rules: ['team'], invalid: [] });+ }, 120_000);+test('gbrain access rule add on a git source commits access.yml through the door and applies it at once', async () => {const r = await cli(engine, ['rule', 'add', '--source', SRC, '--prefix', 'partners/alice-example/', '--readers', 'alice-example', '--id', 'alice', '--yes']);expect({ store: r.store, state: r.state, outcome: r.git.outcome, path: r.git.path }).toEqual({ store: 'git', state: 'applied', outcome: 'committed_local', path: POLICY_FILE });diff --git a/test/access-writes.test.ts b/test/access-writes.test.tsindex 6c0fd5faff..83e8e69946 100644--- a/test/access-writes.test.ts+++ b/test/access-writes.test.ts@@ -10,7 +10,9 @@* Publication re-resolves the writer's member from the stored principal, so* a member disabled after submission (a queued job, a replay) loses the page* before commit; no operator hatch relaxes that.- * 2. Fails when: add_link, put_raw_data or any persistence write lands on an+ * remove_link on an edge of an unreadable page answers as for a missing+ * page and removes nothing.+ * 2. Fails when: add_link, remove_link, put_raw_data or any persistence write lands on an* unreadable page, a listed member is refused its own page, a malformed or* lock-out readable_by is written, or a stored write still publishes after* its member was disabled.@@ -234,6 +236,23 @@ for (const kind of testBackends()) {expect((await state(slug)).deleted).toBe(true);}, 240_000);+ test('remove_link on an edge of a page the caller cannot read answers exactly as for a missing page and removes nothing', async () => {+ await local('add_link', { from: ALICE_PAGE, to: OPEN_PAGE, link_type: 'mentions' });+ await local('add_link', { from: OPEN_PAGE, to: ALICE_PAGE, link_type: 'mentions' });+ const before = (await state()).links;+ expect(before).toBeGreaterThanOrEqual(2);+ const missing = await call('bob', 'remove_link', { from: 'notes/never-written', to: OPEN_PAGE, link_type: 'mentions' });+ for (const who of ['bob', 'unbound']) {+ for (const [from, to] of [[ALICE_PAGE, OPEN_PAGE], [OPEN_PAGE, ALICE_PAGE]]) {+ const out = await call(who, 'remove_link', { from, to, link_type: 'mentions' });+ expect({ who, from, isError: out.isError, json: out.json }).toEqual({ who, from, isError: missing.isError, json: missing.json });+ }+ }+ expect((await state()).links).toBe(before);+ const own = await call('alice', 'remove_link', { from: ALICE_PAGE, to: OPEN_PAGE, link_type: 'mentions' });+ expect({ isError: own.isError, removed: own.json.removed }).toEqual({ isError: false, removed: 1 });+ }, 120_000);+test('extract_facts treats a restricted source_slug exactly like a missing one', async () => {const hidden = await call('bob', 'extract_facts', { turn_text: 'Bob likes tea.', source_slug: ALICE_PAGE, visibility: 'world' });const missing = await call('bob', 'extract_facts', { turn_text: 'Bob likes tea.', source_slug: 'notes/never-written', visibility: 'world' });