Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test: /ship coverage audit for #7630 (claimed-source activation, install fallthrough, skip advice, CLI exit 3, archived doctor)
garrytanf9a7d266efef
diff --git a/test/activation-missing-source-path.test.ts b/test/activation-missing-source-path.test.tsindex 0c0b0b5795..2f58186a6b 100644--- a/test/activation-missing-source-path.test.ts+++ b/test/activation-missing-source-path.test.ts@@ -81,3 +81,22 @@ test('a claimed source whose recorded local_path vanished names its claimed chectry { await runSetPath(engine, ['default-example', claimed]); } finally { console.log = log; }expect(await activatePersistence(engine, { confirmQuiesced: true, dryRun: true })).toMatchObject({ enabled: false, activated: false, filesystem_sources: 2 });}), 60_000);++// /ship coverage audit (GBRA-207, #7630).+// Value: protects=a claimed source whose recorded local_path is relative (".") blocks activation as source_path_missing naming+// the relative path and its claimed checkout, never resolving "." against the process cwd; fails_when=the owner-host branch+// drops its isAbsolute guard, so "." resolves to the cwd and activation reports source_changed (or matches a cwd checkout);+// why_new=the 7630 suite covers only the unclaimed branch (no binding); seam=none; no_claim=a Postgres brain (PGLite only)+test('#7630: a claimed source whose recorded local_path is relative names the relative path and its claimed checkout', () => fixture(async home => {+ const claimed = join(home, 'claimed'); mkdirSync(claimed);+ await engine.executeRaw('INSERT INTO sources(id,name,local_path) VALUES($1,$1,$2)', ['default-example', claimed]);+ await claimWorktree(engine, 'default-example', claimed);+ await engine.executeRaw("UPDATE sources SET local_path='.' WHERE id=$1", ['default-example']);+ for (const dryRun of [true, false]) {+ const error = await activatePersistence(engine, { confirmQuiesced: true, dryRun }).catch(e => e);+ expect(error).toMatchObject({ code: 'source_changed', detail: 'source_path_missing' });+ expect(error.message).toContain("Source 'default-example' records the relative local path .");+ expect(error.suggestion).toContain(`gbrain sources set-path default-example ${JSON.stringify(claimed)}`);+ }+ expect(await managedPersistenceEnabled(engine)).toBe(false);+}), 60_000);diff --git a/test/autopilot-install-repo-fallback-6755.test.ts b/test/autopilot-install-repo-fallback-6755.test.tsindex adc67dfc14..2645469871 100644--- a/test/autopilot-install-repo-fallback-6755.test.ts+++ b/test/autopilot-install-repo-fallback-6755.test.ts@@ -73,6 +73,23 @@ describe('autopilot --install repo resolution (#6755)', () => {expect(r.wrapper).toContain(`autopilot --repo '${flag}'`);});+ // /ship coverage audit (GBRA-207, #7630).+ // Value: protects=a relative sync.repo_path is skipped, not fatal: install falls through to an absolute default local_path, and refuses when both are relative;+ // fails_when=installRepoFallback returns null on a relative sync.repo_path without consulting local_path, or bakes "." into the wrapper;+ // why_new=sync-relative-anchor-refusal-7630 asserts only the all-relative null, never the fall-through to an absolute local_path; seam=none;+ // no_claim=a real supervisor install (ephemeral-container target, stub engine)+ test('#7630: a relative sync.repo_path falls through to an absolute default local_path; relative everywhere refuses', async () => {+ const repo = mkdtempSync(join(tmpdir(), 'gbrain-ap-fallback-relative-'));+ const fellThrough = await install({ syncRepoPath: '.', defaultSourcePath: repo });+ expect(fellThrough.exitCode).toBeUndefined();+ expect(fellThrough.wrapper).toContain(`autopilot --repo '${repo}'`);+ expect(fellThrough.wrapper).not.toContain("autopilot --repo '.'");+ const refused = await install({ syncRepoPath: '.', defaultSourcePath: 'notes' });+ expect(refused.exitCode).toBe(1);+ expect(refused.stderr).toContain('No repo path');+ expect(refused.wrapper).toBeNull();+ });+test('no path anywhere: refuses with exit 1 and writes nothing', async () => {const r = await install({});expect(r.exitCode).toBe(1);diff --git a/test/sources-load.test.ts b/test/sources-load.test.tsindex 7f1ffb7ea5..5132ecab0a 100644--- a/test/sources-load.test.ts+++ b/test/sources-load.test.ts@@ -212,6 +212,12 @@ describe('sourceLocalPathSkipWarning', () => {expect(asked).toEqual([]);expect(warn).toContain("source 'legacy'");expect(warn).toContain('relative local_path');+ // /ship coverage audit (GBRA-207, #7630).+ // Value: protects=the skip names the fix that works (sources set-path <id> <absolute-directory>), never "run gbrain sync once to self-heal";+ // fails_when=the advice reverts to the pre-#7630 sync self-heal, which now refuses sync_anchor_relative; why_new=no test read the advice+ // (only "relative local_path" and "cannot be resolved from a daemon"); seam=none; no_claim=none beyond protects+ expect(warn).toContain("gbrain sources set-path legacy <absolute-directory>");+ expect(warn).not.toContain('self-heal');});test('skips absolute paths missing from this machine', () => {diff --git a/test/sync-relative-anchor-cli-exit-7630.test.ts b/test/sync-relative-anchor-cli-exit-7630.test.tsnew file mode 100644index 0000000000..23f42e8a3a--- /dev/null+++ b/test/sync-relative-anchor-cli-exit-7630.test.ts@@ -0,0 +1,55 @@+/**+ * #7630 through the real CLI: `gbrain sync --source default` run from an unrelated folder, on a brain whose default source+ * has the relative local_path ".", exits 3 (stop and ask the user) with `sync_anchor_relative` and leaves the folder alone.+ *+ * /ship coverage audit (GBRA-207, #7630).+ * Value: protects=the CLI exit 3 contract (stop and ask the user) for sync_anchor_relative, and that the folder gets no .git;+ * fails_when=the registry entry loses exit 3 or the CLI maps the refusal to exit 1, so an agent retries instead of asking;+ * why_new=sync-relative-anchor-refusal-7630 catches the thrown error in-process and never reads the CLI exit; seam=none;+ * no_claim=Postgres (PGLite only) and the --all fan-out exit (exit 1, covered in-process)+ */+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';+import { existsSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { PGLiteEngine } from '../src/core/pglite-engine.ts';+import { runCli } from './helpers/cli-spawn.ts';+import { withEnv } from './helpers/with-env.ts';++let home: string;+let folder: string;++beforeAll(async () => {+ home = mkdtempSync(join(tmpdir(), 'gbrain-7630-cli-home-'));+ folder = realpathSync(mkdtempSync(join(tmpdir(), 'gbrain-7630-cli-unrelated-')));+ writeFileSync(join(folder, 'notes.md'), '---\ntype: note\ntitle: Notes\n---\n\nA note that is not part of any brain.\n');+ const init = await runCli(['init', '--pglite', '--no-embedding', '--json'], { home, cwd: home, timeoutMs: 110_000 });+ expect(init.exitCode, init.stderr).toBe(0);+ await withEnv({ HOME: home, GBRAIN_HOME: home, DATABASE_URL: undefined, GBRAIN_DATABASE_URL: undefined }, async () => {+ const engine = new PGLiteEngine();+ await engine.connect({ engine: 'pglite', database_path: join(home, '.gbrain', 'brain.pglite') });+ try {+ await engine.transaction(async tx => {+ await tx.executeRaw("SELECT set_config('gbrain.topology_change','on',true)");+ await tx.executeRaw("UPDATE sources SET local_path='.' WHERE id='default'");+ });+ await engine.unsetConfig('sync.repo_path');+ } finally {+ await engine.disconnect();+ }+ });+}, 120_000);++afterAll(() => {+ rmSync(folder, { recursive: true, force: true });+ rmSync(home, { recursive: true, force: true });+});++describe('#7630 CLI: a relative stored anchor', () => {+ test('gbrain sync --source default from an unrelated folder exits 3 sync_anchor_relative and creates no .git', async () => {+ const r = await runCli(['sync', '--source', 'default', '--no-pull', '--no-embed'], { home, cwd: folder, timeoutMs: 110_000 });+ expect(r.exitCode, `${r.stdout}\n${r.stderr}`).toBe(3);+ expect(`${r.stdout}\n${r.stderr}`).toContain('sync_anchor_relative');+ expect(existsSync(join(folder, '.git'))).toBe(false);+ }, 120_000);+});diff --git a/test/sync-relative-anchor-refusal-7630.test.ts b/test/sync-relative-anchor-refusal-7630.test.tsindex d4e5334f2d..055ccc06f8 100644--- a/test/sync-relative-anchor-refusal-7630.test.ts+++ b/test/sync-relative-anchor-refusal-7630.test.ts@@ -401,6 +401,24 @@ for (const backend of testBackends()) {expect(check?.message).toContain('gbrain sources set-path <id> <absolute-directory>');}, 120_000);+ // /ship coverage audit (GBRA-207, #7630).+ // Value: protects=doctor default_source_local_path stays ok when every live source path is absolute and only an archived source is relative;+ // fails_when=the relative-source query drops its isAbsolute filter or its archived exclusion, so every multi-source brain warns;+ // why_new=the two doctor cases above assert only the warn side; seam=none; no_claim=other doctor checks (only this check runs)+ test('doctor default_source_local_path stays ok with absolute sources and a relative path only on an archived source', async () => {+ const repo = realpathSync(mkdtempSync(join(tmpdir(), 'gbrain-7630-abs-')));+ try {+ await engine.executeRaw("UPDATE sources SET local_path=$1 WHERE id='default'", [folder]);+ await engine.executeRaw("INSERT INTO sources (id, name, local_path) VALUES ('notes-a', 'notes-a', $1)", [repo]);+ await engine.executeRaw("INSERT INTO sources (id, name, local_path, archived, archived_at) VALUES ('notes-b', 'notes-b', 'notes', true, now())");+ const check = await defaultSourceLocalPathCheck(engine);+ expect(check?.status).toBe('ok');+ expect(check?.message).not.toContain('relative local_path');+ } finally {+ rmSync(repo, { recursive: true, force: true });+ }+ }, 120_000);+test('gbrain import of the cwd into a source whose local_path is "." does not stamp it fresh', async () => {await engine.executeRaw("INSERT INTO sources (id, name, local_path) VALUES ('notes-a', 'notes-a', '.')");const { runImport } = await import('../src/commands/import.ts');