Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(ci): never narrow native CI scope on a large, capped or incomplete PR file list (#5900)
garrytan91ec77eb6f12
diff --git a/.github/workflows/test.yml b/.github/workflows/test.ymlindex ed22d6a4ff..30df00cf85 100644--- a/.github/workflows/test.yml+++ b/.github/workflows/test.yml@@ -57,12 +57,22 @@ jobs:EVENT: ${{ github.event_name }}PR: ${{ github.event.pull_request.number }}REPO: ${{ github.repository }}+ CHANGED_FILES: ${{ github.event.pull_request.changed_files }}run: |set -euo pipefailif [ "$EVENT" != pull_request ]; thenscope=full+ elif ! [[ "$CHANGED_FILES" =~ ^[0-9]{1,4}$ ]] || [ "$CHANGED_FILES" -ge 3000 ]; then+ # The PR files API returns at most 3000 files. An unknown or+ # capped diff cannot establish that native paths are untouched.+ scope=primaryelif files=$(gh api --paginate "repos/$REPO/pulls/$PR/files?per_page=100" --jq '.[].filename'); then- scope=$(printf '%s' "$files" | bash scripts/ci-native-scope.sh)+ listed=$(printf '%s\n' "$files" | awk 'NF { count++ } END { print count+0 }')+ if [ "$listed" -ne "$CHANGED_FILES" ]; then+ scope=primary+ else+ scope=$(printf '%s' "$files" | bash scripts/ci-native-scope.sh) || scope=primary+ fielsescope=primaryfidiff --git a/scripts/ci-native-scope.sh b/scripts/ci-native-scope.shindex 1f16848e05..fd3e14f40e 100755--- a/scripts/ci-native-scope.sh+++ b/scripts/ci-native-scope.sh@@ -10,9 +10,12 @@ set -euo pipefailNATIVE_PATHS='^(native/|scripts/native/|src/core/persistence/|src/core/context/|test/fixtures/native|\.github/workflows/(native-locks|test)\.yml$|package\.json$|bun\.lock$|openclaw\.plugin\.json$|docker-compose\.ci\.yml$)|^src/core/(pglite-[^/]*|engine|postgres-engine|sync[^/]*|export-[^/]*|import-file|markdown|write-through|page-lock)\.ts$|^src/commands/(backup|export|restore|sync)[^/]*\.ts$|openclaw|native|-lock|local-ipc-path|persistence-(publication|git-publication|sync-origin)|backup-portability|export-publication'-files=$(cat)-if [ -z "$files" ] || printf '%s\n' "$files" | grep -Eq "$NATIVE_PATHS"; then+files=$(cat) || { echo primary; exit 0; }+# Consume the full input: grep -q closes an early match's pipe and printf+# then fails with SIGPIPE under pipefail, incorrectly selecting smoke.+if [ -z "$files" ] || grep -E "$NATIVE_PATHS" >/dev/null <<< "$files"; thenecho primaryelse- echo smoke+ status=$?+ if [ "$status" -eq 1 ]; then echo smoke; else echo primary; fifidiff --git a/test/scripts/ci-pr-scope.test.ts b/test/scripts/ci-pr-scope.test.tsindex f43c20564f..517736df07 100644--- a/test/scripts/ci-pr-scope.test.ts+++ b/test/scripts/ci-pr-scope.test.ts@@ -71,19 +71,27 @@ describe('pull-request CI scope', () => {expect(classify(`README.md\n${path}\n`), path).toBe('primary');}expect(classify('')).toBe('primary');+ const large = Array.from({ length: 8000 }, (_, i) => `docs/guides/fixture-${i}-${'x'.repeat(72)}.md`);+ expect(Buffer.byteLength(large.join('\n'))).toBeGreaterThan(64 * 1024);+ expect(classify(large.join('\n'))).toBe('smoke');+ for (const at of [0, large.length >> 1, large.length]) {+ const files = [...large];+ files.splice(at, 0, 'src/core/pglite-lock.ts');+ expect(classify(files.join('\n')), `native marker at ${at}`).toBe('primary');+ }});test('the planning job runs the full matrix off pull requests and never narrows on an unreadable diff', () => {const step = load('test.yml').jobs.changes.steps!.find(entry => entry.id === 'scope')!;const dir = mkdtempSync(join(tmpdir(), 'gbrain-ci-scope-'));try {- const run = (event: string, gh: string) => {+ const run = (event: string, gh: string, changedFiles = '1') => {writeFileSync(join(dir, 'gh'), `#!/usr/bin/env bash\n${gh}\n`);chmodSync(join(dir, 'gh'), 0o755);const output = join(dir, 'out');writeFileSync(output, '');const result = spawnSync('bash', ['-c', step.run!], { cwd: root, encoding: 'utf8',- env: { PATH: `${dir}:${process.env.PATH}`, EVENT: event, PR: '7', REPO: 'example/repo', GITHUB_OUTPUT: output } });+ env: { PATH: `${dir}:${process.env.PATH}`, EVENT: event, PR: '7', REPO: 'example/repo', CHANGED_FILES: changedFiles, GITHUB_OUTPUT: output } });expect(result.status, result.stderr).toBe(0);return readFileSync(output, 'utf8').trim();};@@ -93,6 +101,20 @@ describe('pull-request CI scope', () => {expect(run('pull_request', 'exit 1')).toBe('native=primary');expect(run('pull_request', "printf 'docs/a.md\\n'")).toBe('native=smoke');expect(run('pull_request', "printf 'src/core/pglite-lock.ts\\n'")).toBe('native=primary');+ for (const count of ['', 'invalid', '3000', '4230', '99999']) {+ expect(run('pull_request', "printf 'docs/a.md\\n'", count), count).toBe('native=primary');+ }+ // Even below the API cap, an incomplete or overlong successful response+ // is unknown. A complete large docs-only response can still use smoke.+ expect(run('pull_request', "printf 'docs/a.md\\n'", '2')).toBe('native=primary');+ expect(run('pull_request', "printf 'docs/a.md\\ndocs/b.md\\n'", '1')).toBe('native=primary');+ const fixture = join(dir, 'paths');+ const docs = Array.from({ length: 2999 }, (_, i) => `docs/guides/fixture-${i}-${'x'.repeat(72)}.md`);+ writeFileSync(fixture, docs.join('\n'));+ expect(run('pull_request', `cat '${fixture}'`, '2999')).toBe('native=smoke');+ docs[0] = 'src/core/pglite-lock.ts';+ writeFileSync(fixture, docs.join('\n'));+ expect(run('pull_request', `cat '${fixture}'`, '2999')).toBe('native=primary');} finally { rmSync(dir, { recursive: true, force: true }); }});