Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Let a managed Git effect create a missing remote branch after scanning its history

garrytana5f60f493b92
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e87907afa3..4d7259d394 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,16 +12,16 @@ identifiers and attribution are available in the pre-removal Git revision
## [0.60.621.0] - 2026-11-09
-**The Git effects of page writes no longer publish a script's secret.** A script that commits into a managed checkout with plain `git commit` never passes the write path's secret scan. The refresh publish refused such a commit with `publish_secret_found`, but the next page write's Git effect pushed it anyway: its plain push published every unpublished commit unscanned, and when the remote had moved its keep-checkout publish ran without the scan. Both paths now scan the exact commits they push. A value that looks like a secret, added text too large to scan, a commit that changes `.gbrain-scan-allow` or a `.gitattributes` holds the effects with `publish_secret_found`; commits the scan cannot read in full, or a remote without the branch, hold them with `publish_scan_unreadable`. Nothing is pushed, and the page writes stay safe in the database and in local commits. `gbrain sync status` and doctor name the user's choice: remove the value from those commits, or allowlist a false positive by fingerprint. Then `gbrain sources writer retry-effects <source> --parked-pushes` runs the effects that parked. Every scanned push is also leased on the remote tip it scanned against. Before, a remote rewound past a pushed secret (an admin removing it with a force-push) left a stale tracking ref that hid the commit from the scan, and the next fast-forward put it back; now the scan runs against the remote's real tip.
+**The Git effects of page writes no longer publish a script's secret.** A script that commits into a managed checkout with plain `git commit` never passes the write path's secret scan. The refresh publish refused such a commit with `publish_secret_found`, but the next page write's Git effect pushed it anyway: its plain push published every unpublished commit unscanned, and when the remote had moved its keep-checkout publish ran without the scan. Both paths now scan the exact commits they push. A value that looks like a secret, added text too large to scan, a commit that changes `.gbrain-scan-allow` or a `.gitattributes` holds the effects with `publish_secret_found`; commits the scan cannot read in full hold them with `publish_scan_unreadable`. A first push to a remote that has no such branch yet scans the branch's whole history and creates the branch only when that scan passes. A commit that changes `.gbrain-scan-allow` or a `.gitattributes` is never published automatically: the user reviews it and pushes it. Nothing is pushed, and the page writes stay safe in the database and in local commits. `gbrain sync status` and doctor name the user's choice: remove the value from those commits, or allowlist a false positive by fingerprint. Then `gbrain sources writer retry-effects <source> --parked-pushes` runs the effects that parked. Every scanned push is also leased on the remote tip it scanned against. Before, a remote rewound past a pushed secret (an admin removing it with a force-push) left a stale tracking ref that hid the commit from the scan, and the next fast-forward put it back; now the scan runs against the remote's real tip. The in-process scan on the owner's event loop is capped at 10 seconds, inside the writer heartbeat's live window; a longer range goes to the keep-checkout publish, whose child process scans with the full budget.
### Itemized changes
-- `src/core/persistence/effect-git.ts`: `pushGitRoot` reads the remote branch tip with `git ls-remote`, scans `<tip>..<HEAD sha>` and pushes that sha only as a fast-forward of the tip, leased on it; a tip that is not an ancestor, or a remote that moves before the push lands (`stale info`), goes to the keep-checkout publish, which now runs with `--scan-secrets`. A remote without the branch refuses. A refusal from either path holds the effects as `publish_secret_found` with the user's fix.
+- `src/core/persistence/effect-git.ts`: `pushGitRoot` reads the remote branch tip with `git ls-remote`, scans `<tip>..<HEAD sha>` and pushes that sha only as a fast-forward of the tip, leased on it; a tip that is not an ancestor, or a remote that moves before the push lands (`stale info`), goes to the keep-checkout publish, which now runs with `--scan-secrets`. The in-process scan gets 10 s; a range it cannot finish goes to the keep-checkout publish. A remote without the branch gets HEAD's whole history scanned and the branch created with a lease that it does not exist; one too large to scan in process holds with `publish_scan_unreadable` naming `git ls-remote --heads`. A refusal from either path holds the effects as `publish_secret_found` with the user's fix.
- `src/core/git/commit-push.ts`: a `scanSecrets` publish scans `<base>..<candidate>` before every push and leases the push on that base, so each merge with a newly fetched remote tip is scanned again.
-- `src/core/git/range-secret-scan.ts`: `rangeSecretRefusal`, the one refusal both callers throw (`publish_scan_unreadable` for a scan that could not read the range, `publish_secret_found` otherwise).
+- `src/core/git/range-secret-scan.ts`: `rangeSecretRefusal`, the one refusal both callers throw (`publish_scan_unreadable` for a scan that could not read the range, `publish_secret_found` otherwise; a gate-file change says the user pushes it). `scanRange` marks a scan that ran past its budget (`timed_out`) and scans a whole history when the base is empty.
- `src/core/persistence/git-push-holds.ts`: `publish_secret_found` and `publish_scan_unreadable` are held push codes, so doctor, `gbrain sync status` and `retry-effects --parked-pushes` cover them, with an ask-the-user fix (the refused commits, or `git fsck`).
- Docs: `docs/guides/shared-checkout-git.md` (`publish_secret_found` and `publish_scan_unreadable` rows), `docs/guides/live-sync.md`.
-- Tests: `test/effect-git-secret-gate.test.ts` (an ahead checkout, a diverged one, a remote rewound past a pushed secret and a remote without the branch each refuse with nothing pushed; a clean ahead checkout pushes; through the effect worker the page write's effect holds, sync status names the fix, and an allowlisted false positive releases it); `test/guarded-publish.test.ts` (a remote rewound past a pushed secret is not published again); `test/git-literal-pathspec-hooks-7759.test.ts` publishes its probe `.gitattributes` commit first, since the effect's push now refuses one; `test/cli-flag-equals.test.ts` lists `range-secret-scan.ts` as a git child argv reader.
+- Tests: `test/effect-git-secret-gate.test.ts` (an ahead checkout, a diverged one, a remote rewound past a pushed secret, a `.gitattributes` change and a remote without the branch whose history holds a secret each refuse with nothing pushed; a clean ahead checkout pushes, a clean history creates a missing branch, and a scan past the in-process budget still scans in the child; through the effect worker the page write's effect holds, sync status names the fix, and an allowlisted false positive releases it); `test/guarded-publish.test.ts` (a remote rewound past a pushed secret is not published again); `test/git-literal-pathspec-hooks-7759.test.ts` publishes its probe `.gitattributes` commit first, since the effect's push now refuses one; `test/cli-flag-equals.test.ts` lists `range-secret-scan.ts` as a git child argv reader.
## [0.60.620.0] - 2026-11-09
diff --git a/docs/guides/shared-checkout-git.md b/docs/guides/shared-checkout-git.md
index 7a84d6d1e2..605dd892d6 100644
--- a/docs/guides/shared-checkout-git.md
+++ b/docs/guides/shared-checkout-git.md
@@ -186,7 +186,7 @@ Follow the error's `fix.next` as the
| `git_operation_in_progress` | 1 | A rebase, merge, cherry-pick or revert is unfinished in the checkout. gbrain never aborts it for you. Follow [stuck rebase](#stuck-rebase). |
| `git_detached_head` | 1 | The checkout is on a detached HEAD or an unborn branch. Check out the branch the remote tracks (`git switch <branch>`), or make the first commit, then rerun. |
| <a id="publish_secret_found"></a>`publish_secret_found` | 1 | Only with `--scan-secrets`, which every automatic publish uses: the one `gbrain sources refresh` runs on its own and the push of a managed worktree's Git effects. A commit about to be pushed adds a value that looks like a secret, in its message, an added line (even one a later commit removed) or a merge resolution, adds text too large to scan, or changes `.gbrain-scan-allow` or a `.gitattributes` (files that decide what the scan sees); nothing was pushed. The message names each file, line, rule and commit, never the value. Ask the user: remove the value from those unpushed commits, or add a false positive's fingerprint to `.gbrain-scan-allow`, then retry. A commit that changes `.gbrain-scan-allow` or a `.gitattributes` is never published automatically: the user reviews it and pushes it. Never publish them with a command that skips the scan. On a managed worktree its Git effects hold meanwhile (`gbrain sync status` and doctor list them; the page writes are safe in the database and in local commits); after the fix, `gbrain sources writer retry-effects <source> --parked-pushes` runs the ones that parked. |
-| <a id="publish_scan_unreadable"></a>`publish_scan_unreadable` | 1 | Only with `--scan-secrets`: the scan could not read the commits about to be pushed in full (a missing or corrupt object, git output it does not recognise, or its 300 s budget), so it reported no secret and nothing was pushed. Run `git fsck` in the checkout, fix what it names, then retry. A managed worktree's Git effects also refuse this when the remote has no such branch to compare against: check the upstream with `git ls-remote --heads <remote>`, then point it at the right branch or review the commits and push the branch yourself (gbrain never creates a remote branch from unscanned commits). Never publish with a command that skips the scan. On a managed worktree its Git effects hold meanwhile, as for `publish_secret_found`. |
+| <a id="publish_scan_unreadable"></a>`publish_scan_unreadable` | 1 | Only with `--scan-secrets`: the scan could not read the commits about to be pushed in full (a missing or corrupt object, git output it does not recognise, or its 300 s budget), so it reported no secret and nothing was pushed. Run `git fsck` in the checkout, fix what it names, then retry. When the remote has no such branch, a managed worktree's Git effect scans the branch's whole history and creates it only when that scan passes; a history too large to scan in the owner process holds the effects with this code and names `git ls-remote --heads <remote>`: check the upstream, then point it at the right branch or review the history and push the branch yourself. Never publish with a command that skips the scan. On a managed worktree its Git effects hold meanwhile, as for `publish_secret_found`. |
| `integrate_conflict` | 1 | Local and remote commits changed the same file; nothing was merged and the checkout is unchanged. Stop, relay the question to the user, then [resolve](#conflicts). |
| `push_unconfirmed` | 4 | The commit is durable locally but no push destination confirmed it (network, credentials, branch protection, a remote that kept moving, or another push that held the push lock for the whole wait). Fix what the message names, then run `gbrain git commit-push --push-only`. Never force-push. |
| `writer_coordinator_required` | 1 | This is a managed worktree. Stop using git for pages; save them through `put_page` and the other gbrain write tools. |
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index ffc2cfb466..08766ae365 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -1489,7 +1489,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;
{ since: '0.60.618.0', id: 'refresh_replan_own_commits_8828', text: 'A `gbrain sources refresh` whose checkout HEAD moved while it waited for writes admitted before its fence no longer refuses `refresh_source_changed` when every commit since its start is one of gbrain\'s own (in the commit ledger) and the upstream branch holds them: it takes HEAD as its start and fast-forwards to the upstream. A HEAD move that includes a commit gbrain did not make, or gbrain\'s commits the upstream does not hold yet, still refuses as before.' },
{ since: '0.60.619.0', id: 'managed_commit_push_unpublished_gst1923', text: 'On a managed checkout, `gbrain git commit-push -m <msg> -- <paths>` now reports how many commits the upstream lacks as last fetched (`unpublished` in `--json`, `null` when there is no upstream) and says nothing was pushed, instead of answering `nothing to commit; <remote>/<branch> at -` and logging `[push] ok-already-on-remote` for a commit that already existed. It writes no push-log line on a managed checkout. It still never pushes there; `gbrain git commit-push --push-only --keep-checkout --path <checkout>` publishes.' },
{ since: '0.60.620.0', id: 'refresh_publish_diverged_default_gbra386', text: 'A diverged managed checkout now publishes its local commits on `gbrain sources refresh` by default when the worktree\'s Git durability is on: `sources.refresh_publish_diverged` unset now means on there (it used to mean off), merged with the upstream in memory, never rebased or forced. The refresh publish first scans what the local commits add (messages, added lines, merge resolutions) and refuses the new `publish_secret_found` naming the file, line and rule, never the value, when one looks like a secret; `gbrain git commit-push --push-only --scan-secrets` runs the same gate. Unset with durability not on still refuses, naming `gbrain sources writer git-durability <source> --enable`; `false` turns it off.' },
- { since: '0.60.621.0', id: 'effect_git_secret_gate_gst1923', text: 'The Git effects of page writes on a managed worktree now scan the unpublished commits they push, as the refresh publish does: a value that looks like a secret (or text too large to scan, or a change to `.gbrain-scan-allow` or a `.gitattributes`) in a commit a script made with plain `git commit` holds the effects with `publish_secret_found` and nothing is pushed, where they used to push it with the next page write. The push now reads the remote branch tip and scans exactly what it adds, leased on that tip, so a remote rewound since the last fetch never gets a removed commit back; commits the scan cannot read in full, or a remote without the branch, hold the effects with `publish_scan_unreadable`. After the user removes the value or allowlists a false positive, `gbrain sources writer retry-effects <source> --parked-pushes` runs the effects that parked.' },
+ { since: '0.60.621.0', id: 'effect_git_secret_gate_gst1923', text: 'The Git effects of page writes on a managed worktree now scan the unpublished commits they push, as the refresh publish does: a value that looks like a secret (or text too large to scan, or a change to `.gbrain-scan-allow` or a `.gitattributes`) in a commit a script made with plain `git commit` holds the effects with `publish_secret_found` and nothing is pushed, where they used to push it with the next page write. The push now reads the remote branch tip and scans exactly what it adds, leased on that tip, so a remote rewound since the last fetch never gets a removed commit back; commits the scan cannot read in full hold the effects with `publish_scan_unreadable`, and a first push to a remote without the branch scans the whole history first. A commit that changes `.gbrain-scan-allow` or a `.gitattributes` is never published automatically; the user reviews it and pushes it. After the user removes the value or allowlists a false positive, `gbrain sources writer retry-effects <source> --parked-pushes` runs the effects that parked.' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */
diff --git a/src/core/git/range-secret-scan.ts b/src/core/git/range-secret-scan.ts
index cb57819393..766d3c863f 100644
--- a/src/core/git/range-secret-scan.ts
+++ b/src/core/git/range-secret-scan.ts
@@ -103,6 +103,7 @@ function attributesNeutral(root: string, deadline: number): boolean {
return !existsSync(file) || readFileSync(file, 'utf8').split('\n').every(line => !line.trim() || line.trim().startsWith('#'));
}
+/** An empty `base` scans `head` and its whole history (a first push that creates the remote branch). */
export function scanRange(root: string, base: string, head: string, timeoutMs = 300_000): RangeScan {
const deadline = Date.now() + timeoutMs;
const scan: RangeScan = { findings: [], unscanned: [], gate_changes: [] };
@@ -113,7 +114,7 @@ export function scanRange(root: string, base: string, head: string, timeoutMs =
};
const dir = mkdtempSync(join(tmpdir(), 'gbrain-range-scan-'));
try {
- const commits = must(run(root, ['rev-list', `${base}..${head}`, '--'], deadline), 'rev-list').toString().split('\n').filter(Boolean);
+ const commits = must(run(root, ['rev-list', base ? `${base}..${head}` : head, '--'], deadline), 'rev-list').toString().split('\n').filter(Boolean);
if (!commits.length) return scan;
for (const commit of commits) {
@@ -235,8 +236,9 @@ export function scanRange(root: string, base: string, head: string, timeoutMs =
* otherwise `publish_secret_found` naming each finding, unscanned file and gate change (never a value).
*/
export function rangeSecretRefusal(root: string, base: string, target: string, scan: RangeScan): OperationError | null {
+ const range = base ? `${base}..${target.slice(0, 12)}` : `${target.slice(0, 12)} and its whole history`;
if (scan.unreadable !== undefined) {
- return opError('publish_scan_unreadable', `The secret scan could not read the local commits ${base}..${target.slice(0, 12)} (${scan.unreadable}). No secret was reported. Nothing was pushed.`,
+ return opError('publish_scan_unreadable', `The secret scan could not read the local commits ${range} (${scan.unreadable}). No secret was reported. Nothing was pushed.`,
`The publish pushes only commits it has read in full. Check the checkout with git fsck in ${root} (a missing or corrupt object, a full disk, or a git too slow for the 300 s budget), fix what it reports, then retry. Never publish with a command that skips this scan.`,
{ detail: JSON.stringify({ unreadable: scan.unreadable }), fix: { ask_user: true, consent: [], actor: 'user', requires_exclusive: false,
argv: ['git', '-C', root, 'fsck'],
@@ -248,11 +250,11 @@ export function rangeSecretRefusal(root: string, base: string, target: string, s
const named = [...scan.findings.map(f => `${f.path}:${f.line} (${f.pattern}, ${f.commit.slice(0, 7)})`), ...scan.unscanned.map(u => `${u.path} (too large to scan, ${u.commit.slice(0, 7)})`),
...scan.gate_changes.map(g => `${g.path} (changes what the scan sees, ${g.commit.slice(0, 7)})`)];
return opError('publish_secret_found',
- `${named.length} item(s) in the local commits ${base}..${target.slice(0, 12)} look like secrets or could not be scanned: ${named.slice(0, 10).join(', ')}${named.length > 10 ? ', ...' : ''}. Nothing was pushed.`,
+ `${named.length} item(s) in the local commits ${range} look like secrets or could not be scanned: ${named.slice(0, 10).join(', ')}${named.length > 10 ? ', ...' : ''}. Nothing was pushed.`,
`Remove the value from those commits (rewriting unpushed local commits is the user's call), or add a false positive's fingerprint to .gbrain-scan-allow, then retry. Never publish them with a command that skips this scan.${scan.gate_changes.length ? ` A commit that changes .gbrain-scan-allow or a .gitattributes is never published automatically, because it changes what the scan sees: review it and push it yourself (git -C ${root} push), then retry.` : ''}`,
{ detail: JSON.stringify(scan),
fix: { ask_user: true, consent: [], actor: 'user', requires_exclusive: false,
- argv: ['git', '-C', root, 'log', '--stat', `${base}..${target}`],
+ argv: ['git', '-C', root, 'log', '--stat', base ? `${base}..${target}` : target],
why: 'Lists the unpublished commits the scan refused; read-only. A secret pushed to the remote stays in its history.',
user_message: `Unpublished commits in ${root} hold ${named.length || 'some'} item(s) that look like secrets or could not be scanned (${named.slice(0, 3).join(', ')}). Nothing was pushed. Remove them from those commits, or confirm a false positive so it can be allowlisted by fingerprint?`,
docs: 'docs/guides/shared-checkout-git.md#publish_secret_found' } });
diff --git a/src/core/persistence/effect-git.ts b/src/core/persistence/effect-git.ts
index c47719f060..e0dd8ed69b 100644
--- a/src/core/persistence/effect-git.ts
+++ b/src/core/persistence/effect-git.ts
@@ -420,11 +420,13 @@ const OWNER_SCAN_BUDGET_MS = 10_000;
* they publish. The plain push reads the remote branch tip (`git ls-remote`, never a possibly stale tracking ref,
* which would hide a commit a rewound remote no longer has), scans exactly `<tip>..<HEAD sha>` and pushes that sha
* only as a fast-forward of the tip, leased on it; a tip that is not an ancestor, or a remote that moves before the
- * push lands, goes to the shared publish, which fetches first and runs with `--scan-secrets`. A finding, an
- * unscannable file or a commit changing what the scan sees holds the effect with `publish_secret_found`; a range git
- * cannot read in full or a remote with no such branch holds it with `publish_scan_unreadable`. The in-process scan
+ * push lands, goes to the shared publish, which fetches first and runs with `--scan-secrets`. A remote with no such
+ * branch (a first push to a new remote) gets HEAD's whole history scanned and the branch created only if it does not
+ * exist yet. A finding, an unscannable file or a commit changing what the scan sees holds the effect with
+ * `publish_secret_found`; a range git cannot read in full holds it with `publish_scan_unreadable`. The in-process scan
* runs synchronously on the owner's event loop, so it gets `scanBudgetMs` (well inside the consumer heartbeat's live
- * window); a range it cannot finish in that time goes to the shared publish, whose child process scans with the full budget.
+ * window); a range it cannot finish in that time goes to the shared publish, whose child process scans with the full budget,
+ * except a whole history for a missing branch, which holds the effect with `publish_scan_unreadable` naming the upstream.
*/
export async function pushGitRoot(root: string, signal?: AbortSignal, scanBudgetMs = OWNER_SCAN_BUDGET_MS): Promise<{ push: 'committed'; integrated?: number } | { push: 'skipped'; reason: 'no_tracking_remote' }> {
return withSession(root, signal, undefined, false, async session => {
@@ -442,15 +444,7 @@ export async function pushGitRoot(root: string, signal?: AbortSignal, scanBudget
const listed = await git(session, ['ls-remote', '--', remote.stdout.trim(), ref]);
if (listed.code !== 0) throw unavailable();
const tip = listed.stdout.split('\n').map(line => line.split('\t')).find(([, name]) => name === ref)?.[0] ?? '';
- if (!tip) throw heldSecret(root, opError('publish_scan_unreadable',
- `${remote.stdout.trim()} has no branch ${short}, so the secret scan has no published tip to compare the local commits against. Nothing was pushed.`,
- `Check that the checkout's upstream (branch.${branch.stdout.trim()}.merge) names a branch the remote still has (git ls-remote --heads ${remote.stdout.trim()}). If the branch was deleted or renamed on purpose, point the upstream at the right branch, or review the commits and push the branch yourself; gbrain never creates a remote branch from commits it has not scanned against one.`,
- { detail: JSON.stringify({ unreadable: `${remote.stdout.trim()} has no branch ${short}` }), fix: { ask_user: true, consent: [], actor: 'user', requires_exclusive: false,
- argv: ['git', '-C', root, 'ls-remote', '--heads', '--', remote.stdout.trim()],
- why: 'Read-only: lists the branches the remote has, to check the checkout\'s upstream.',
- user_message: `The remote ${remote.stdout.trim()} has no branch ${short} for ${root}, so nothing was pushed. Should the checkout's upstream point at another branch, or will you review the commits and push this branch yourself?`,
- docs: 'docs/guides/shared-checkout-git.md#publish_scan_unreadable' } }));
- if ((await git(session, ['merge-base', '--is-ancestor', tip, sha])).code === 0) {
+ if (!tip || (await git(session, ['merge-base', '--is-ancestor', tip, sha])).code === 0) {
const scan = scanRange(root, tip, sha, scanBudgetMs);
if (!scan.timed_out) {
const refusal = rangeSecretRefusal(root, tip, sha, scan);
@@ -459,7 +453,14 @@ export async function pushGitRoot(root: string, signal?: AbortSignal, scanBudget
const push = await git(session, ['push', `--force-with-lease=${ref}:${tip}`, '--', remote.stdout.trim(), `${sha}:${ref}`]);
if (push.code === 0) return { push: 'committed' } as const;
if (!NON_FAST_FORWARD.test(push.stderr) && !STALE_LEASE.test(push.stderr)) throw unavailable();
- }
+ } else if (!tip) throw heldSecret(root, opError('publish_scan_unreadable',
+ `${remote.stdout.trim()} has no branch ${short}, and the secret scan of the whole history a first push would create it with ran past its in-process budget. Nothing was pushed.`,
+ `Check that the checkout's upstream (branch.${branch.stdout.trim()}.merge) names a branch the remote should have (git ls-remote --heads ${remote.stdout.trim()}). If the branch was deleted or renamed on purpose, point the upstream at the right branch, or review the history and push the branch yourself; gbrain never creates a remote branch from history it has not scanned.`,
+ { detail: JSON.stringify({ unreadable: scan.unreadable }), fix: { ask_user: true, consent: [], actor: 'user', requires_exclusive: false,
+ argv: ['git', '-C', root, 'ls-remote', '--heads', '--', remote.stdout.trim()],
+ why: 'Read-only: lists the branches the remote has, to check the checkout\'s upstream.',
+ user_message: `The remote ${remote.stdout.trim()} has no branch ${short} for ${root}, and its whole history is too large to scan here, so nothing was pushed. Should the checkout's upstream point at another branch, or will you review the history and push this branch yourself?`,
+ docs: 'docs/guides/shared-checkout-git.md#publish_scan_unreadable' } }));
}
signal?.throwIfAborted();
return publishKeepingCheckout(root, signal);
diff --git a/test/effect-git-secret-gate.test.ts b/test/effect-git-secret-gate.test.ts
index 3b6597140e..0e8d6c34d6 100644
--- a/test/effect-git-secret-gate.test.ts
+++ b/test/effect-git-secret-gate.test.ts
@@ -126,11 +126,32 @@ describe('#8896 pushGitRoot scans the commits it publishes', () => {
expect(remoteTip(c)).toBe(base);
}, 120_000);
- test('a remote without the branch refuses instead of scanning nothing', async () => {
+ test('a remote without the branch (a first push): a clean history creates it', async () => {
const c = checkout();
scriptCommit(c.root, 'notes/page.md', 'A clean page\n');
git(c.remote, 'update-ref', '-d', 'refs/heads/main');
+ expect(await withEnv(childEnv(c), () => pushGitRoot(c.root))).toEqual({ push: 'committed' });
+ expect(remoteTip(c)).toBe(git(c.root, 'rev-parse', 'HEAD').trim());
+ }, 60_000);
+
+ test('a remote without the branch: a secret anywhere in the history refuses, and no branch is created', async () => {
+ const c = checkout();
+ scriptCommit(c.root, 'notes/deploy.md', `Deploy token ${token}\n`);
+ git(c.root, 'push', '-q');
+ scriptCommit(c.root, 'notes/page.md', 'A clean page write on top\n');
+ git(c.remote, 'update-ref', '-d', 'refs/heads/main');
const error = await withEnv(childEnv(c), () => refusal(pushGitRoot(c.root)));
+ expect(error.code).toBe('publish_secret_found');
+ expect(error.message).toContain('notes/deploy.md:1 (');
+ expect(error.message).toContain('and its whole history');
+ expect(() => git(c.remote, 'rev-parse', '--verify', 'refs/heads/main')).toThrow();
+ }, 60_000);
+
+ test('a remote without the branch whose history scan runs past the in-process budget holds, naming the upstream check', async () => {
+ const c = checkout();
+ scriptCommit(c.root, 'notes/page.md', 'A clean page\n');
+ git(c.remote, 'update-ref', '-d', 'refs/heads/main');
+ const error = await withEnv(childEnv(c), () => refusal(pushGitRoot(c.root, undefined, 0)));
expect(error.code).toBe('publish_scan_unreadable');
expect(error.message).toContain('origin has no branch main');
expect(error.fix?.argv).toEqual(['git', '-C', c.root, 'ls-remote', '--heads', '--', 'origin']);