Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

The public-surface check finds its base on shallow CI checkouts (#9476)

Garry Tan8574af5479bb
diff --git a/changelog.d/capy-public-surface-deepen-fix.md b/changelog.d/capy-public-surface-deepen-fix.md
new file mode 100644
index 0000000000..17d45e71fd
--- /dev/null
+++ b/changelog.d/capy-public-surface-deepen-fix.md
@@ -0,0 +1,4 @@
+**The public-surface check no longer fails with "no merge base … even after deepening the clone" on shallow CI checkouts whose head is more than one commit past master.**
+
+### Fixed
+- `bun run check:public-surface` deepened a depth-1 CI checkout with `--filter=tree:0`, which GitHub's server fails on for a shallow clone that is not partial. It now deepens with `--filter=blob:none`, and when a fetch fails it prints git's own error under the FAIL line.
diff --git a/scripts/check-public-surface.ts b/scripts/check-public-surface.ts
index 0003b86b96..a92c3e1f9f 100644
--- a/scripts/check-public-surface.ts
+++ b/scripts/check-public-surface.ts
@@ -23,7 +23,9 @@
* The manifest's freshness is regen:all's (scripts/build-public-surface.ts --check). Dates are UTC days;
* GBRAIN_SURFACE_TODAY (YYYY-MM-DD) overrides today for tests. When the base ref or a merge base is unavailable the
* check fails under CI=true and skips locally. Fetches (the stable ref, deepening a shallow clone with
- * --filter=tree:0) stop after 20 s and 30 s, or $GBRAIN_SURFACE_FETCH_TIMEOUT_S. Exit: 0 ok or skipped, 1 refused.
+ * --filter=blob:none, since GitHub's pack-objects crashes on tree:0 for a shallow clone that is not partial) stop after
+ * 20 s and 30 s, or $GBRAIN_SURFACE_FETCH_TIMEOUT_S; a failed fetch prints git's own error. Exit: 0 ok or skipped,
+ * 1 refused.
*/
import { spawnSync } from 'node:child_process';
import { existsSync, readdirSync, readFileSync } from 'node:fs';
@@ -76,11 +78,16 @@ export function main(opts: { cwd?: string; env?: Record<string, string | undefin
return { ok: r.status === 0, out: r.stdout ?? '' };
};
const fetchTimeout = (seconds: number) => Number(env.GBRAIN_SURFACE_FETCH_TIMEOUT_S) || seconds;
+ let fetchError = '';
const fetch = (seconds: number, ...args: string[]): 'ok' | 'timeout' | 'failed' => {
- const r = spawnSync('git', ['fetch', '--no-tags', '--quiet', ...args], { cwd: root, stdio: 'ignore', timeout: fetchTimeout(seconds) * 1000, killSignal: 'SIGKILL' });
+ fetchError = '';
+ const r = spawnSync('git', ['fetch', '--no-tags', '--quiet', ...args], { cwd: root, encoding: 'utf8', stdio: ['ignore', 'ignore', 'pipe'], timeout: fetchTimeout(seconds) * 1000, killSignal: 'SIGKILL' });
if (r.status === 0) return 'ok';
- return (r.error as NodeJS.ErrnoException | undefined)?.code === 'ETIMEDOUT' ? 'timeout' : 'failed';
+ if ((r.error as NodeJS.ErrnoException | undefined)?.code === 'ETIMEDOUT') return 'timeout';
+ fetchError = (r.stderr ?? '').split('\n').map(l => l.trim()).filter(Boolean).slice(-4).join(' / ').slice(-600);
+ return 'failed';
};
+ const logFetchError = (result: string | null) => { if (result === 'failed' && fetchError) log(`git: ${fetchError}`); };
const ref = env.GBRAIN_SURFACE_BASE_REF || 'origin/master';
if (!git('rev-parse', '--verify', '-q', `${ref}^{commit}`).ok) {
if (env.CI === 'true') {
@@ -99,13 +106,14 @@ export function main(opts: { cwd?: string; env?: Record<string, string | undefin
if (parents.includes(tip)) mergeBase = { ok: true, out: tip };
for (const depth of [200, 2000]) {
if (mergeBase.ok || deepened === 'timeout') break;
- deepened = fetch(30, '--filter=tree:0', `--deepen=${depth}`, 'origin', git('rev-parse', 'HEAD').out.trim(), tip);
+ deepened = fetch(30, '--filter=blob:none', `--deepen=${depth}`, 'origin', git('rev-parse', 'HEAD').out.trim(), tip);
mergeBase = git('merge-base', ref, 'HEAD');
}
}
if (!mergeBase.ok) {
if (env.CI === 'true') {
log(`FAIL: check-public-surface: no merge base between HEAD and ${ref}, ${deepened === 'timeout' ? `because the fetch that deepens the clone timed out after ${fetchTimeout(30)} s` : 'even after deepening the clone'}.`);
+ logFetchError(deepened);
log('Fix: fetch more history in the workflow (actions/checkout fetch-depth: 0)');
return 1;
}
@@ -163,6 +171,7 @@ export function main(opts: { cwd?: string; env?: Record<string, string | undefin
stableCommit = resolveStable();
if (!stableCommit.ok && env.CI === 'true') {
log(`FAIL: check-public-surface: this change drops public entries, and the stable ref ${stableRef} could not be fetched from origin${fetched === 'timeout' ? ` (timed out after ${fetchTimeout(20)} s)` : ''}, so it cannot tell which of them reached stable.`);
+ logFetchError(fetched);
log(`Fix: rerun once origin answers, or fetch it in the workflow (git fetch --no-tags --depth=1 origin +${stableRef}:${stableRef})`);
return 1;
}
diff --git a/scripts/structural-suites.tsv b/scripts/structural-suites.tsv
index 2068a7f261..56da26a436 100644
--- a/scripts/structural-suites.tsv
+++ b/scripts/structural-suites.tsv
@@ -313,6 +313,7 @@ test/scripts/check-dynamic-ci.test.ts check-dynamic-ci.ts 1 exec-scan,readFileSy
test/scripts/check-function-size.test.ts check-function-size.ts rules 11 readFileSync
test/scripts/check-item-allowlist-catches.test.ts CLI 2 readFileSync
test/scripts/check-public-surface.test.ts dropped manifest entries 5 bun-file
+test/scripts/check-public-surface.test.ts the base it compares with 9 bun-file
test/scripts/check-public-surface.test.ts the committed manifest 2 bun-file
test/scripts/chunk-visibility-ratchet.test.ts check-chunk-visibility.ts 6 readFileSync
test/scripts/ci-bounded-run.test.ts (file-level) 7 readFileSync
diff --git a/test/scripts/check-public-surface.test.ts b/test/scripts/check-public-surface.test.ts
index d800427a64..11a47e1e8f 100644
--- a/test/scripts/check-public-surface.test.ts
+++ b/test/scripts/check-public-surface.test.ts
@@ -221,6 +221,35 @@ describe('the base it compares with', () => {
expect(r.code).toBe(0);
});
+ test('a shallow clone is deepened with a blob filter, the one GitHub serves to a shallow clone that is not partial', () => {
+ const origin = repo({}, {});
+ git(origin, 'config', 'uploadpack.allowFilter', 'true');
+ git(origin, 'config', 'uploadpackfilter.allow', 'false');
+ git(origin, 'config', 'uploadpackfilter.blob:none.allow', 'true');
+ git(origin, 'commit', '-q', '--allow-empty', '-m', 'head after the base merge');
+ git(origin, 'checkout', '-q', 'base');
+ write(origin, { [MANIFEST]: manifest({ 'mcp-tool': ['search', 'think'] }) });
+ git(origin, 'commit', '-qam', 'base adds think');
+ const clone = mkdtempSync(join(tmpdir(), 'gbrain-public-surface-clone-'));
+ roots.push(clone);
+ git(clone, 'clone', '-q', '--depth=1', '--no-tags', '--branch', 'head', `file://${origin}`, '.');
+ git(clone, 'fetch', '-q', '--no-tags', '--depth=1', 'origin', '+refs/heads/base:refs/remotes/origin/base');
+ const r = run(clone, { GBRAIN_SURFACE_BASE_REF: 'origin/base', CI: 'true' });
+ expect(r.out).not.toContain('FAIL');
+ expect(r.code).toBe(0);
+ });
+
+ test('a deepen fetch that fails prints git\'s own error', () => {
+ const origin = repo({}, {});
+ git(origin, 'commit', '-q', '--allow-empty', '-m', 'head after the base merge');
+ const clone = shallowClone(origin, 'head');
+ git(clone, 'remote', 'set-url', 'origin', join(clone, 'no-such-remote'));
+ const r = run(clone, { GBRAIN_SURFACE_BASE_REF: 'origin/base', CI: 'true' });
+ expect(r.code).toBe(1);
+ expect(r.out).toContain('no merge base between HEAD and origin/base');
+ expect(r.out).toMatch(/git: .*(does not appear to be a git repository|not found|No such file)/);
+ });
+
test('a shallow pull-request merge commit whose parent is the base tip needs no fetch', () => {
const origin = repo({}, { [MANIFEST]: manifest({ 'mcp-tool': ['search', 'think'] }) });
git(origin, 'checkout', '-q', 'base');
@@ -252,6 +281,7 @@ describe('the base it compares with', () => {
const ci = run(clone, { GBRAIN_SURFACE_BASE_REF: 'origin/base', CI: 'true' });
expect(ci.code).toBe(1);
expect(ci.out).toContain('FAIL: check-public-surface: this change drops public entries, and the stable ref refs/tags/stable could not be fetched from origin, so it cannot tell which of them reached stable.');
+ expect(ci.out).toMatch(/git: .*(does not appear to be a git repository|not found|No such file)/);
expect(ci.out).not.toContain('mcp-tool `search`');
const local = run(clone, { GBRAIN_SURFACE_BASE_REF: 'origin/base' });
expect(local.code).toBe(1);