diff --git a/config/scripts/cloud-integration/filter-base-list-tests.sh b/config/scripts/cloud-integration/filter-base-list-tests.sh new file mode 100755 index 00000000000..334ee2ae9b2 --- /dev/null +++ b/config/scripts/cloud-integration/filter-base-list-tests.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +# usage: filter-base-list-tests.sh < test-paths +# Prints each test path from stdin that is NOT an exact line of the base list (stdout), and logs every path it drops +# as "premerge: skipping base-list test " (stderr). Matching is whole-line and literal, so a path that merely +# shares a prefix, a directory or a suffix with a base-list entry is kept. A missing base list drops nothing. +set -euo pipefail +base_list=${1:?usage: filter-base-list-tests.sh < test-paths} +while IFS= read -r t; do + if [[ -z "$t" ]]; then continue; fi + if [[ -f "$base_list" ]] && grep -qxF -- "$t" "$base_list"; then + echo "premerge: skipping base-list test $t" >&2 + else + printf '%s\n' "$t" + fi +done diff --git a/config/scripts/cloud-integration/filter-base-list-tests.test.mjs b/config/scripts/cloud-integration/filter-base-list-tests.test.mjs new file mode 100644 index 00000000000..ed062dbb2bf --- /dev/null +++ b/config/scripts/cloud-integration/filter-base-list-tests.test.mjs @@ -0,0 +1,69 @@ +import { spawnSync } from 'node:child_process' +import { mkdtempSync, rmSync, writeFileSync } from 'node:fs' +import { tmpdir } from 'node:os' +import path from 'node:path' +import { afterEach, describe, expect, it } from 'vitest' + +const script = path.join(import.meta.dirname, 'filter-base-list-tests.sh') +const roots = [] +afterEach(() => { + for (const root of roots.splice(0)) { + rmSync(root, { recursive: true, force: true }) + } +}) + +function run(baseListLines, testPaths) { + const root = mkdtempSync(path.join(tmpdir(), 'base-list-')) + roots.push(root) + const baseList = path.join(root, 'base-list.txt') + if (baseListLines !== null) { + writeFileSync(baseList, `${baseListLines.join('\n')}\n`) + } + const r = spawnSync('bash', [script, baseList], { + input: `${testPaths.join('\n')}\n`, + encoding: 'utf8' + }) + return { + status: r.status, + kept: r.stdout.split('\n').filter(Boolean), + log: r.stderr.split('\n').filter(Boolean) + } +} + +const ON_LIST = 'src/main/agent-hooks/server/testing/replay/spool.test.ts' +const OFF_LIST = + 'src/renderer/src/components/orca-cloud/cloud-workspace-archive-delete-race.test.ts' + +describe('premerge base-list filter', () => { + it('drops a base-list test and logs the skip, while a test off the list is still selected', () => { + const r = run(['# comment', ON_LIST], [ON_LIST, OFF_LIST]) + expect(r.status).toBe(0) + expect(r.kept).toEqual([OFF_LIST]) + expect(r.log).toEqual([`premerge: skipping base-list test ${ON_LIST}`]) + }) + + it('matches whole lines only: a shared prefix, suffix or folder never skips a test', () => { + const r = run( + [ON_LIST], + [ + 'src/main/agent-hooks/server/testing/replay/spool.test.tsx', + 'src/main/agent-hooks/server/testing/replay/other-spool.test.ts', + 'src/main/agent-hooks/server/testing/replay/spool.extra.test.ts', + 'x/src/main/agent-hooks/server/testing/replay/spool.test.ts' + ] + ) + expect(r.kept).toHaveLength(4) + expect(r.log).toEqual([]) + }) + + it('treats list entries literally (no regex) and ignores comment lines', () => { + const r = run(['src/main/a.test.ts', '.*', `# ${OFF_LIST}`], ['src/main/a_test.ts', OFF_LIST]) + expect(r.kept).toEqual(['src/main/a_test.ts', OFF_LIST]) + }) + + it('keeps everything when the base list is missing', () => { + const r = run(null, [ON_LIST, OFF_LIST]) + expect(r.status).toBe(0) + expect(r.kept).toEqual([ON_LIST, OFF_LIST]) + }) +}) diff --git a/config/scripts/cloud-integration/premerge-check.sh b/config/scripts/cloud-integration/premerge-check.sh index f6e3dbdb2ea..d090a8f661c 100755 --- a/config/scripts/cloud-integration/premerge-check.sh +++ b/config/scripts/cloud-integration/premerge-check.sh @@ -56,16 +56,10 @@ else esac done < <(git diff --name-only --diff-filter=AMR "$base"...HEAD -- 'src/*') if ((${#tests[@]} > 0)); then - tests=($(printf "%s\n" "${tests[@]}" | sort -u)) # repo paths have no spaces - # Skip files on the full-suite base list: they fail on upstream too (this Mac's environment), so they would only block. - base_list=config/scripts/cloud-integration/full-suite-base-list.txt - if [[ -f "$base_list" ]]; then - kept=() - for t in "${tests[@]}"; do - if grep -qxF "$t" "$base_list"; then echo "premerge: skipping base-list test $t"; else kept+=("$t"); fi - done - tests=(${kept[@]+"${kept[@]}"}) - fi + # Skip files on the full-suite base list: they fail on upstream too (this Mac's environment), so they would only + # block. Exact whole-line matches only (filter-base-list-tests.sh, unit-tested); repo paths have no spaces. + tests=($(printf "%s\n" "${tests[@]}" | sort -u | + bash config/scripts/cloud-integration/filter-base-list-tests.sh config/scripts/cloud-integration/full-suite-base-list.txt)) echo "premerge: ${#tests[@]} targeted test file(s):" fi if ((${#tests[@]} > 0)); then