Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(git): await git in persistence-git-publication; a git call with no exit status fails loudly
garrytanca68d34879a3
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 041c06d21e..dacbf65ccb 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,19 @@ credits are retained; no result has been reassigned to another provider. Originaidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).+## [0.60.140.0] - 2026-10-09++**CI only: unit shard 7 no longer loses its tail to a Bun runtime defect, and a red shard that does names the defect instead of blaming the tests. Nothing in gbrain itself changes.**++Three runs out of three of the `Test` workflow's shard 7 at the current file composition (d4dc2d4d8 twice, c12e14adf once) went bad about ten minutes in, inside `test/persistence-git-publication.test.ts`: a `git` run through `Bun.spawnSync` spun until the test deadline printed `killed 1 dangling process`, and from then on every synchronous child spawn in the process (`spawnSync`, `execSync`, `execFileSync`) in unrelated files timed out with empty output while asynchronous spawns and in-process tests kept passing. That is oven-sh/bun#34069 in Bun 1.4.0 and 1.4.2: a GC finalizer that runs while `Bun.spawnSync` waits leaves the runtime's private spawnSync loop with a drifted poll count for the life of the process. Bun fixed it upstream on 2026-10-05 (oven-sh/bun#44581, commit 13a98b0); no release carries it yet. The release gate refused v0.60.139.0 on it.++### Itemized changes++- `test/helpers/git-publication.ts`: `gitAsync` and `gitFixtureAsync` run git through `Bun.spawn` on the main loop; `test/persistence-git-publication.test.ts` uses them for every call, so the shard's densest run of `spawnSync` windows is gone. The synchronous `git` stays for callers that cannot await, and both now throw on any exit that is not 0: a null exit code (signal, or a `spawnSync` that returned without a status) used to pass as success and return `''`, which turned the poisoned run into a bogus fixture and a `durability_not_enabled` assertion two lines later. Both spawns pass the live `process.env`, so a test's `PATH` or `GIT_*` override reaches the child.+- `scripts/capture-test-log.ts`: a red shard whose log shows `killed N dangling process` followed by nothing but timeouts, at least three of them in at least two files, is named `bun_spawnsync_poisoned` in the job's step summary and on stderr, with the Bun version, the upstream issue and fix, and "rerun the job". A signal only; nothing is resumed or retried. One hung test with a dangling child, timeouts with no killed child, timeouts confined to one file, or any non-timeout failure after the kill are left for their own diagnosis.+- `TODOS.md`: bump Bun when a release carries 13a98b0; check the compare, not the version number. `docs/TESTING.md` describes the signal.+- Tests: `test/git-publication-helper.test.ts` (a git that ends by signal throws from both helpers with the command and the status; a non-zero exit carries git's stderr; the signal case returned `''` on the previous helper), `test/scripts/capture-test-log.test.ts` (the signature is named; the four look-alike shapes are not). The detector names both real shard-7 logs and not the same shard's unrelated recall-budget failure.+## [0.60.139.0] - 2026-10-09**Your agent can now tell your own notes from something a web page told it. Everything it reads back from memory says where it came from, text that reads like instructions to an agent is flagged when it is saved, and you can remove a fact you saved by mistake with a receipt that says exactly what was removed and what was out of reach.**diff --git a/test/git-publication-helper.test.ts b/test/git-publication-helper.test.tsnew file mode 100644index 0000000000..b9b54ce40e--- /dev/null+++ b/test/git-publication-helper.test.ts@@ -0,0 +1,34 @@+import { expect, test } from 'bun:test';+import { chmodSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { delimiter, join } from 'node:path';+import { git, gitAsync } from './helpers/git-publication.ts';+import { withEnv } from './helpers/with-env.ts';++// A git that ends without an exit status (by signal here; a Bun.spawnSync that+// gave up under oven-sh/bun#34069 looks the same to the caller) must fail the+// test that called it, not return '' as if it had succeeded.+async function withSignalledGit<T>(run: () => Promise<T>): Promise<T> {+ const dir = mkdtempSync(join(tmpdir(), 'gbrain-fake-git-'));+ try {+ const fake = join(dir, 'git');+ writeFileSync(fake, '#!/bin/sh\nkill -KILL $$\n');+ chmodSync(fake, 0o755);+ return await withEnv({ PATH: `${dir}${delimiter}${process.env.PATH ?? ''}` }, run);+ } finally { rmSync(dir, { recursive: true, force: true }); }+}++test.skipIf(process.platform === 'win32')('a git call that ends without an exit status throws, synchronously and asynchronously', async () => {+ await withSignalledGit(async () => {+ expect(() => git(tmpdir(), 'rev-parse', 'HEAD')).toThrow(/git rev-parse HEAD in .*: no exit status \(signal SIGKILL\)/);+ await expect(gitAsync(tmpdir(), 'rev-parse', 'HEAD')).rejects.toThrow(/git rev-parse HEAD in .*: (?:no exit status|exit 137) \(signal SIGKILL\)/);+ });+});++test('a non-zero exit carries the command, the status and git\'s stderr', async () => {+ const dir = mkdtempSync(join(tmpdir(), 'gbrain-not-a-repo-'));+ try {+ expect(() => git(dir, 'rev-parse', 'HEAD')).toThrow(/git rev-parse HEAD in .*: exit 128\n.*not a git repository/i);+ await expect(gitAsync(dir, 'rev-parse', 'HEAD')).rejects.toThrow(/exit 128\n.*not a git repository/i);+ } finally { rmSync(dir, { recursive: true, force: true }); }+});diff --git a/test/helpers/git-publication.ts b/test/helpers/git-publication.tsindex 8cda5138c0..c2abb0fe82 100644--- a/test/helpers/git-publication.ts+++ b/test/helpers/git-publication.ts@@ -2,12 +2,37 @@ import { chmodSync, existsSync, mkdirSync, mkdtempSync, realpathSync, rmSync, wrimport { tmpdir } from 'node:os';import { join } from 'node:path';+/**+ * A git call that did not exit 0. A null exit code is a child that ended by+ * signal or that `Bun.spawnSync` gave up on without a status: Bun 1.4.x+ * (oven-sh/bun#34069) returns one with empty output after a GC finalizer+ * ran inside an earlier sync spawn, and treating it as success turned that+ * into a bogus fixture and a `durability_not_enabled` assertion later on.+ */+function gitFailure(root: string, args: string[], exitCode: number | null, signalCode: string | null, stderr: string): Error {+ const status = `${exitCode === null ? 'no exit status' : `exit ${exitCode}`}${signalCode ? ` (signal ${signalCode})` : ''}`;+ return new Error(`git ${args.join(' ')} in ${root}: ${status}${stderr.trim() ? `\n${stderr.trim()}` : ''}`);+}++/**+ * Synchronous git for fixtures that cannot await. Prefer {@link gitAsync} in+ * test bodies: `Bun.spawnSync` is where oven-sh/bun#34069 bites (a GC+ * finalizer during the wait poisons every later sync spawn in the process).+ */export function git(root: string, ...args: string[]): string {- const result = Bun.spawnSync(['git', '-C', root, ...args]);- if (result.exitCode) throw new Error(result.stderr.toString());+ const result = Bun.spawnSync(['git', '-C', root, ...args], { env: process.env });+ if (result.exitCode !== 0) throw gitFailure(root, args, result.exitCode, result.signalCode ?? null, result.stderr.toString());return result.stdout.toString();}+/** Asynchronous git on the main event loop: no `spawnSync` window for oven-sh/bun#34069 to land in. */+export async function gitAsync(root: string, ...args: string[]): Promise<string> {+ const proc = Bun.spawn(['git', '-C', root, ...args], { env: process.env, stdin: 'ignore', stdout: 'pipe', stderr: 'pipe' });+ const [stdout, stderr, exitCode] = await Promise.all([new Response(proc.stdout).text(), new Response(proc.stderr).text(), proc.exited]);+ if (exitCode !== 0) throw gitFailure(root, args, exitCode, proc.signalCode, stderr);+ return stdout;+}+/** A durability-hardened repo with no remote: Git effects publish for real and the hook is inert. */export function durableGitRepo(root: string, committed: string[]): void {git(root, 'init', '-q');@@ -19,11 +44,30 @@ export function durableGitRepo(root: string, committed: string[]): void {chmodSync(hook, 0o755);}-export function gitFixture() {+export interface GitFixture { home: string; root: string; requestedRoot: string; remote: string; caseInsensitive: boolean; cleanup: () => void }++function gitFixtureDirs() {const requestedHome = mkdtempSync(join(tmpdir(), 'gbrain-git-publication-'));const home = realpathSync.native(requestedHome);const root = join(home, 'worktree'), remote = join(home, 'remote.git');mkdirSync(root); mkdirSync(remote);+ return { requestedHome, home, root, remote };+}++/** The hook that marks the fixture durability-hardened (and fails loudly if a Git effect ever ran it), plus the Notes directory. */+function finishGitFixture({ requestedHome, home, root, remote }: ReturnType<typeof gitFixtureDirs>): GitFixture {+ const hook = join(root, '.git', 'hooks', 'post-commit');+ writeFileSync(hook, '#!/bin/sh\n# gbrain brain-durability post-commit hook (v0.42.44+)\nexit 99\n');+ chmodSync(hook, 0o755);+ mkdirSync(join(root, 'Notes'));+ const caseInsensitive = existsSync(join(root, 'notes'));+ return { home, root, requestedRoot: join(requestedHome, 'worktree'), remote, caseInsensitive,+ cleanup: () => rmSync(home, { recursive: true, force: true }) };+}++export function gitFixture(): GitFixture {+ const dirs = gitFixtureDirs();+ const { root, remote } = dirs;git(root, 'init', '-b', 'main');git(root, 'config', 'user.name', 'Example Writer');git(root, 'config', 'user.email', '[email protected]');@@ -31,12 +75,19 @@ export function gitFixture() {git(root, 'add', 'initial.md'); git(root, 'commit', '-m', 'Initial');git(remote, 'init', '--bare');git(root, 'remote', 'add', 'origin', remote); git(root, 'push', '-u', 'origin', 'main');- const hooks = join(root, '.git', 'hooks');- const hook = join(hooks, 'post-commit');- writeFileSync(hook, '#!/bin/sh\n# gbrain brain-durability post-commit hook (v0.42.44+)\nexit 99\n');- chmodSync(hook, 0o755);- mkdirSync(join(root, 'Notes'));- const caseInsensitive = existsSync(join(root, 'notes'));- return { home, root, requestedRoot: join(requestedHome, 'worktree'), remote, caseInsensitive,- cleanup: () => rmSync(home, { recursive: true, force: true }) };+ return finishGitFixture(dirs);+}++/** {@link gitFixture} with every git call awaited on the main loop. */+export async function gitFixtureAsync(): Promise<GitFixture> {+ const dirs = gitFixtureDirs();+ const { root, remote } = dirs;+ await gitAsync(root, 'init', '-b', 'main');+ await gitAsync(root, 'config', 'user.name', 'Example Writer');+ await gitAsync(root, 'config', 'user.email', '[email protected]');+ writeFileSync(join(root, 'initial.md'), 'Initial\n');+ await gitAsync(root, 'add', 'initial.md'); await gitAsync(root, 'commit', '-m', 'Initial');+ await gitAsync(remote, 'init', '--bare');+ await gitAsync(root, 'remote', 'add', 'origin', remote); await gitAsync(root, 'push', '-u', 'origin', 'main');+ return finishGitFixture(dirs);}diff --git a/test/persistence-git-publication.test.ts b/test/persistence-git-publication.test.tsindex 4fbc076696..ffc8f0c803 100644--- a/test/persistence-git-publication.test.ts+++ b/test/persistence-git-publication.test.ts@@ -2,173 +2,176 @@ import { afterEach, expect, test } from 'bun:test';import { existsSync, linkSync, mkdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';import { join } from 'node:path';import { publishGitEffect } from '../src/core/persistence/effect-git.ts';-import { git, gitFixture } from './helpers/git-publication.ts';+import { gitAsync as git, gitFixtureAsync as gitFixture, type GitFixture } from './helpers/git-publication.ts';import { withEnv } from './helpers/with-env.ts';-const fixtures: ReturnType<typeof gitFixture>[] = [];-const caseInsensitiveFs = (() => { const probe = gitFixture(); try { return probe.caseInsensitive; } finally { probe.cleanup(); } })();-function fixture() { const f = gitFixture(); fixtures.push(f); return f; }+// Every git call here is awaited on the main loop: this file's dense run of+// `Bun.spawnSync` calls was where oven-sh/bun#34069 landed in CI shard 7+// (three runs out of three), poisoning every later sync spawn in the process.+const fixtures: GitFixture[] = [];+const caseInsensitiveFs = await (async () => { const probe = await gitFixture(); try { return probe.caseInsensitive; } finally { probe.cleanup(); } })();+async function fixture() { const f = await gitFixture(); fixtures.push(f); return f; }afterEach(() => { for (const f of fixtures.splice(0)) f.cleanup(); });-function published(f: ReturnType<typeof fixture>, path: string, content: string) {- expect(git(f.root, 'show', `HEAD:${path}`)).toBe(content);- expect(git(f.remote, 'show', `refs/heads/main:${path}`)).toBe(content);+async function published(f: GitFixture, path: string, content: string) {+ expect(await git(f.root, 'show', `HEAD:${path}`)).toBe(content);+ expect(await git(f.remote, 'show', `refs/heads/main:${path}`)).toBe(content);}test('literal Git pathspecs publish only the bracketed target and preserve the index', async () => {- const f = fixture();+ const f = await fixture();for (const name of ['a[1].md', 'a1.md', 'unrelated.md']) writeFileSync(join(f.root, name), `Before ${name}\n`);- git(f.root, 'add', '.'); git(f.root, '-c', 'core.hooksPath=', 'commit', '-m', 'Tracked files');+ await git(f.root, 'add', '.'); await git(f.root, '-c', 'core.hooksPath=', 'commit', '-m', 'Tracked files');for (const name of ['a[1].md', 'a1.md', 'unrelated.md']) writeFileSync(join(f.root, name), `After ${name}\n`);- git(f.root, 'add', '--', 'a1.md', 'unrelated.md');- const beforeIndex = git(f.root, 'ls-files', '--stage', '-z', '--', 'a1.md', 'unrelated.md');+ await git(f.root, 'add', '--', 'a1.md', 'unrelated.md');+ const beforeIndex = await git(f.root, 'ls-files', '--stage', '-z', '--', 'a1.md', 'unrelated.md');expect(await withEnv({ GIT_GLOB_PATHSPECS: '1', GIT_ICASE_PATHSPECS: '1' }, () => publishGitEffect(f.root, 'a[1].md'))).toEqual({ git: 'committed', push: 'committed' });- published(f, 'a[1].md', 'After a[1].md\n');- published(f, 'a1.md', 'Before a1.md\n');- expect(git(f.root, 'ls-files', '--stage', '-z', '--', 'a1.md', 'unrelated.md')).toBe(beforeIndex);- expect(git(f.root, 'diff', '--cached', '--name-only', '-z')).toBe('a1.md\0unrelated.md\0');+ await published(f, 'a[1].md', 'After a[1].md\n');+ await published(f, 'a1.md', 'Before a1.md\n');+ expect(await git(f.root, 'ls-files', '--stage', '-z', '--', 'a1.md', 'unrelated.md')).toBe(beforeIndex);+ expect(await git(f.root, 'diff', '--cached', '--name-only', '-z')).toBe('a1.md\0unrelated.md\0');});test.skipIf(process.platform === 'win32')('pathspec magic and POSIX backslashes remain literal filenames', async () => {- const f = fixture();+ const f = await fixture();for (const name of [':(glob)*.md', 'literal\\name.md']) {writeFileSync(join(f.root, name), `Exact ${name}\n`);expect(await publishGitEffect(f.root, name)).toEqual({ git: 'committed', push: 'committed' });- published(f, name, `Exact ${name}\n`);+ await published(f, name, `Exact ${name}\n`);}- expect(git(f.root, 'ls-tree', '--name-only', '-r', '-z', 'HEAD').split('\0').filter(Boolean).sort())+ expect((await git(f.root, 'ls-tree', '--name-only', '-r', '-z', 'HEAD')).split('\0').filter(Boolean).sort()).toEqual([':(glob)*.md', 'initial.md', 'literal\\name.md']);});test('unchanged replay, missing target and tracked deletion keep distinct outcomes', async () => {- const f = fixture();+ const f = await fixture();writeFileSync(join(f.root, 'Notes', 'page.md'), 'Published\n');expect(await publishGitEffect(f.root, 'Notes/page.md')).toEqual({ git: 'committed', push: 'committed' });- const head = git(f.root, 'rev-parse', 'HEAD');+ const head = await git(f.root, 'rev-parse', 'HEAD');expect(await publishGitEffect(f.root, 'Notes/page.md')).toEqual({ git: 'unchanged', push: 'committed' });- expect(git(f.root, 'rev-parse', 'HEAD')).toBe(head);+ expect(await git(f.root, 'rev-parse', 'HEAD')).toBe(head);expect(await publishGitEffect(f.root, 'Notes/missing.md')).toEqual({ git: 'skipped', reason: 'target_absent', push: 'skipped' });rmSync(join(f.root, 'Notes', 'page.md'));expect(await publishGitEffect(f.root, 'Notes/page.md')).toEqual({ git: 'committed', push: 'committed' });- expect(git(f.root, 'ls-tree', '-r', '--name-only', 'HEAD')).toBe('initial.md\n');- expect(git(f.remote, 'ls-tree', '-r', '--name-only', 'refs/heads/main')).toBe('initial.md\n');- const deletedHead = git(f.root, 'rev-parse', 'HEAD');+ expect(await git(f.root, 'ls-tree', '-r', '--name-only', 'HEAD')).toBe('initial.md\n');+ expect(await git(f.remote, 'ls-tree', '-r', '--name-only', 'refs/heads/main')).toBe('initial.md\n');+ const deletedHead = await git(f.root, 'rev-parse', 'HEAD');expect(await publishGitEffect(f.root, 'Notes/page.md')).toEqual({ git: 'skipped', reason: 'target_absent', push: 'skipped' });- expect(git(f.root, 'rev-parse', 'HEAD')).toBe(deletedHead);+ expect(await git(f.root, 'rev-parse', 'HEAD')).toBe(deletedHead);});test('push rejection leaves one durable local commit and retries it unchanged', async () => {- const f = fixture();- git(f.remote, 'config', 'receive.denyNonFastForwards', 'true');- const original = git(f.root, 'rev-parse', 'HEAD').trim();+ const f = await fixture();+ await git(f.remote, 'config', 'receive.denyNonFastForwards', 'true');+ const original = (await git(f.root, 'rev-parse', 'HEAD')).trim();writeFileSync(join(f.root, 'ahead.md'), 'Remote ahead\n');- git(f.root, 'add', 'ahead.md'); git(f.root, '-c', 'core.hooksPath=', 'commit', '-m', 'Remote ahead');- git(f.root, 'push'); git(f.root, 'reset', '--hard', original);+ await git(f.root, 'add', 'ahead.md'); await git(f.root, '-c', 'core.hooksPath=', 'commit', '-m', 'Remote ahead');+ await git(f.root, 'push'); await git(f.root, 'reset', '--hard', original);writeFileSync(join(f.root, 'page.md'), 'Local durable\n');await expect(publishGitEffect(f.root, 'page.md')).rejects.toMatchObject({ code: 'git_push_unavailable' });- expect(git(f.root, 'show', 'HEAD:page.md')).toBe('Local durable\n');- const head = git(f.root, 'rev-parse', 'HEAD');- git(f.remote, 'update-ref', 'refs/heads/main', original);+ expect(await git(f.root, 'show', 'HEAD:page.md')).toBe('Local durable\n');+ const head = await git(f.root, 'rev-parse', 'HEAD');+ await git(f.remote, 'update-ref', 'refs/heads/main', original);expect(await publishGitEffect(f.root, 'page.md')).toEqual({ git: 'unchanged', push: 'committed' });- expect(git(f.root, 'rev-parse', 'HEAD')).toBe(head);- published(f, 'page.md', 'Local durable\n');+ expect(await git(f.root, 'rev-parse', 'HEAD')).toBe(head);+ await published(f, 'page.md', 'Local durable\n');});test('native path lookup fixes existing aliases but never folds POSIX case-distinct names', async () => {- const f = fixture();+ const f = await fixture();if (!f.caseInsensitive) mkdirSync(join(f.root, 'notes'));writeFileSync(join(f.root, 'Notes', 'Old.md'), 'Native\n');writeFileSync(join(f.root, 'notes', 'new.md'), 'New\n');if (f.caseInsensitive) {expect(await publishGitEffect(f.root, 'notes/old.md')).toEqual({ git: 'committed', push: 'committed' });- published(f, 'Notes/Old.md', 'Native\n');+ await published(f, 'Notes/Old.md', 'Native\n');} else {expect(await publishGitEffect(f.root, 'notes/old.md')).toMatchObject({ reason: 'target_absent' });expect(await publishGitEffect(f.root, 'Notes/Old.md')).toEqual({ git: 'committed', push: 'committed' });}expect(await publishGitEffect(f.root, 'notes/new.md')).toEqual({ git: 'committed', push: 'committed' });- published(f, f.caseInsensitive ? 'Notes/new.md' : 'notes/new.md', 'New\n');+ await published(f, f.caseInsensitive ? 'Notes/new.md' : 'notes/new.md', 'New\n');});test.skipIf(!caseInsensitiveFs)('native ambiguous aliases refuse instead of picking one hardlink name', async () => {- const f = fixture();+ const f = await fixture();writeFileSync(join(f.root, 'Notes', 'Old.md'), 'Native\n');linkSync(join(f.root, 'Notes', 'Old.md'), join(f.root, 'Notes', 'Other.md'));- const before = git(f.root, 'rev-parse', 'HEAD');+ const before = await git(f.root, 'rev-parse', 'HEAD');await expect(publishGitEffect(f.root, 'notes/old.md')).rejects.toMatchObject({ code: 'git_target_unsafe' });- expect(git(f.root, 'rev-parse', 'HEAD')).toBe(before);+ expect(await git(f.root, 'rev-parse', 'HEAD')).toBe(before);});test.skipIf(caseInsensitiveFs)('case-distinct directories retain separate files and staged changes', async () => {- const f = fixture();+ const f = await fixture();mkdirSync(join(f.root, 'notes'));for (const directory of ['Notes', 'notes']) writeFileSync(join(f.root, directory, 'page.md'), `Before ${directory}\n`);- git(f.root, 'add', '.'); git(f.root, '-c', 'core.hooksPath=', 'commit', '-m', 'Distinct paths');+ await git(f.root, 'add', '.'); await git(f.root, '-c', 'core.hooksPath=', 'commit', '-m', 'Distinct paths');for (const directory of ['Notes', 'notes']) writeFileSync(join(f.root, directory, 'page.md'), `After ${directory}\n`);- git(f.root, 'add', '--', 'Notes/page.md');- const index = git(f.root, 'ls-files', '--stage', '-z', '--', 'Notes/page.md');+ await git(f.root, 'add', '--', 'Notes/page.md');+ const index = await git(f.root, 'ls-files', '--stage', '-z', '--', 'Notes/page.md');expect(await publishGitEffect(f.root, 'notes/page.md')).toEqual({ git: 'committed', push: 'committed' });- published(f, 'notes/page.md', 'After notes\n');- published(f, 'Notes/page.md', 'Before Notes\n');- expect(git(f.root, 'ls-files', '--stage', '-z', '--', 'Notes/page.md')).toBe(index);+ await published(f, 'notes/page.md', 'After notes\n');+ await published(f, 'Notes/page.md', 'Before Notes\n');+ expect(await git(f.root, 'ls-files', '--stage', '-z', '--', 'Notes/page.md')).toBe(index);});for (const staged of [false, true]) test(`a missing old spelling cannot hide an indexed deletion (staged=${staged})`, async () => {- const f = fixture();+ const f = await fixture();writeFileSync(join(f.root, 'Notes', 'Old.md'), 'Tracked\n');- git(f.root, 'add', 'Notes/Old.md'); git(f.root, '-c', 'core.hooksPath=', 'commit', '-m', 'Tracked target');- git(f.root, 'push');+ await git(f.root, 'add', 'Notes/Old.md'); await git(f.root, '-c', 'core.hooksPath=', 'commit', '-m', 'Tracked target');+ await git(f.root, 'push');rmSync(join(f.root, 'Notes', 'Old.md'));- if (staged) git(f.root, 'add', '-u', '--', 'Notes/Old.md');- const head = git(f.root, 'rev-parse', 'HEAD');+ if (staged) await git(f.root, 'add', '-u', '--', 'Notes/Old.md');+ const head = await git(f.root, 'rev-parse', 'HEAD');const index = readFileSync(join(f.root, '.git', 'index'));await expect(publishGitEffect(f.root, 'Notes/old.md')).rejects.toMatchObject({ code: 'git_target_unsafe' });- expect(git(f.root, 'rev-parse', 'HEAD')).toBe(head);+ expect(await git(f.root, 'rev-parse', 'HEAD')).toBe(head);expect(readFileSync(join(f.root, '.git', 'index'))).toEqual(index);- expect(git(f.remote, 'show', 'refs/heads/main:Notes/Old.md')).toBe('Tracked\n');+ expect(await git(f.remote, 'show', 'refs/heads/main:Notes/Old.md')).toBe('Tracked\n');expect(await publishGitEffect(f.root, 'Notes/Old.md')).toEqual({ git: 'committed', push: 'committed' });- expect(git(f.remote, 'ls-tree', '-r', '--name-only', 'refs/heads/main')).toBe('initial.md\n');- const deletion = git(f.root, 'rev-parse', 'HEAD');+ expect(await git(f.remote, 'ls-tree', '-r', '--name-only', 'refs/heads/main')).toBe('initial.md\n');+ const deletion = await git(f.root, 'rev-parse', 'HEAD');expect(await publishGitEffect(f.root, 'Notes/Old.md')).toEqual({ git: 'skipped', reason: 'target_absent', push: 'skipped' });- expect(git(f.root, 'rev-parse', 'HEAD')).toBe(deletion);+ expect(await git(f.root, 'rev-parse', 'HEAD')).toBe(deletion);});for (const deleted of [false, true]) test(`unborn HEAD preserves a new index while checking absence (deleted=${deleted})`, async () => {- const f = fixture();- git(f.root, 'checkout', '--orphan', 'unborn');- git(f.root, 'rm', '--cached', '--', 'initial.md');+ const f = await fixture();+ await git(f.root, 'checkout', '--orphan', 'unborn');+ await git(f.root, 'rm', '--cached', '--', 'initial.md');writeFileSync(join(f.root, 'Notes', 'New.md'), 'New index entry\n');- git(f.root, 'add', '--', 'Notes/New.md');+ await git(f.root, 'add', '--', 'Notes/New.md');if (deleted) rmSync(join(f.root, 'Notes', 'New.md'));const index = readFileSync(join(f.root, '.git', 'index'));if (deleted) await expect(publishGitEffect(f.root, 'Notes/new.md')).rejects.toMatchObject({ code: 'git_target_unsafe' });else expect(await publishGitEffect(f.root, 'Notes/missing.md')).toEqual({ git: 'skipped', reason: 'target_absent', push: 'skipped' });expect(readFileSync(join(f.root, '.git', 'index'))).toEqual(index);- expect(git(f.root, 'ls-files', '-z')).toBe('Notes/New.md\0');- expect(git(f.remote, 'ls-tree', '-r', '--name-only', 'refs/heads/main')).toBe('initial.md\n');+ expect(await git(f.root, 'ls-files', '-z')).toBe('Notes/New.md\0');+ expect(await git(f.remote, 'ls-tree', '-r', '--name-only', 'refs/heads/main')).toBe('initial.md\n');});test('an exact staged deletion commits alone and replays without another commit', async () => {- const f = fixture();- rmSync(join(f.root, 'initial.md')); git(f.root, 'add', '-u', '--', 'initial.md');- writeFileSync(join(f.root, 'unrelated.md'), 'Unrelated staging\n'); git(f.root, 'add', '--', 'unrelated.md');- const index = git(f.root, 'ls-files', '--stage', '-z', '--', 'unrelated.md');+ const f = await fixture();+ rmSync(join(f.root, 'initial.md')); await git(f.root, 'add', '-u', '--', 'initial.md');+ writeFileSync(join(f.root, 'unrelated.md'), 'Unrelated staging\n'); await git(f.root, 'add', '--', 'unrelated.md');+ const index = await git(f.root, 'ls-files', '--stage', '-z', '--', 'unrelated.md');expect(await publishGitEffect(f.root, 'initial.md')).toEqual({ git: 'committed', push: 'committed' });- expect(git(f.root, 'ls-tree', '-r', '--name-only', 'HEAD')).toBe('');- expect(git(f.remote, 'ls-tree', '-r', '--name-only', 'refs/heads/main')).toBe('');- expect(git(f.root, 'ls-files', '--stage', '-z', '--', 'unrelated.md')).toBe(index);- const head = git(f.root, 'rev-parse', 'HEAD');+ expect(await git(f.root, 'ls-tree', '-r', '--name-only', 'HEAD')).toBe('');+ expect(await git(f.remote, 'ls-tree', '-r', '--name-only', 'refs/heads/main')).toBe('');+ expect(await git(f.root, 'ls-files', '--stage', '-z', '--', 'unrelated.md')).toBe(index);+ const head = await git(f.root, 'rev-parse', 'HEAD');expect(await publishGitEffect(f.root, 'initial.md')).toEqual({ git: 'skipped', reason: 'target_absent', push: 'skipped' });- expect(git(f.root, 'rev-parse', 'HEAD')).toBe(head);+ expect(await git(f.root, 'rev-parse', 'HEAD')).toBe(head);});test('symlinked root works while escaping descendants and directory targets refuse', async () => {- const f = fixture();+ const f = await fixture();const alias = join(f.home, 'alias'); symlinkSync(f.root, alias, process.platform === 'win32' ? 'junction' : 'dir');writeFileSync(join(f.root, 'page.md'), 'Exact\n');expect(await publishGitEffect(alias, 'page.md')).toEqual({ git: 'committed', push: 'committed' });- published(f, 'page.md', 'Exact\n');+ await published(f, 'page.md', 'Exact\n');const outside = join(f.home, 'outside'); mkdirSync(outside);writeFileSync(join(outside, 'page.md'), 'Outside\n');symlinkSync(outside, join(f.root, 'escape'), process.platform === 'win32' ? 'junction' : 'dir');