From 144707f18b1d52b6e393ebb29e119ed994bd25f9 Mon Sep 17 00:00:00 2001 From: Neil Date: Wed, 11 Nov 2026 04:59:14 -0800 Subject: [PATCH 1/2] chore(cloud): premerge also runs same-folder tests and tests that import a changed module; PREMERGE_FULL=1 runs the full suite (PM-gap) #347 (c267ae36761) broke cloud-workspace-archive-delete-race.test.ts and the premerge never ran it, because it only mapped changed sources to sibling-named tests (foo.ts -> foo.test.ts). #435 then ran 0 targeted files for the same reason. Now each changed source also selects every test in its folder and every src test that imports it by module name; for cloud-workspace-actions.ts that is 14 files including the race test. PREMERGE_FULL=1 runs the whole vitest suite. --- .../cloud-integration/premerge-check.sh | 50 ++++++++++++------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/config/scripts/cloud-integration/premerge-check.sh b/config/scripts/cloud-integration/premerge-check.sh index 3c9754e8135..af39baf871b 100755 --- a/config/scripts/cloud-integration/premerge-check.sh +++ b/config/scripts/cloud-integration/premerge-check.sh @@ -3,8 +3,8 @@ # config/scripts/cloud-integration/premerge-check.sh # Merges the current private/cloud/integration into a throwaway worktree with your branch, then requires # pnpm typecheck, the full pnpm lint suite (pre-commit hooks only lint staged files), and vitest for the tests your -# branch touched: changed *.test.ts(x) plus the sibling tests of changed sources (foo.ts -> foo.test.ts, foo.*.test.ts), -# and each touched cloud/apps/* package's own suite. +# branch touched: changed *.test.ts(x), every test in the folder of each changed source, every test that imports a +# changed module, and each touched cloud/apps/* package's own suite. PREMERGE_FULL=1 runs the whole vitest suite. # Prints "premerge OK" only when everything passes. Nothing here reads /tmp state. On macOS (no flock) wrap heavy runs # as /tmp/vdrv/heavy.sh 'config/scripts/cloud-integration/premerge-check.sh'. set -euo pipefail @@ -21,23 +21,39 @@ pnpm typecheck pnpm lint tests=() -while IFS= read -r file; do - case "$file" in - *.test.ts | *.test.tsx) if [[ -f "$file" ]]; then tests+=("$file"); fi ;; - *.ts | *.tsx) - stem=${file%.*} - for candidate in "$stem".test.ts "$stem".test.tsx "$stem".*.test.ts "$stem".*.test.tsx; do - if [[ -f "$candidate" ]]; then tests+=("$candidate"); fi - done - ;; - 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 +if [[ "${PREMERGE_FULL:-}" == 1 ]]; then + # Full suite (what every build cut runs before its smoke). Slow; use for risky or wide changes. node config/scripts/native-build/node-addons/ensure-native-runtime.mjs --runtime=node >/dev/null - npx vitest run --config config/vitest.config.ts "${tests[@]}" + npx vitest run --config config/vitest.config.ts +else + # Targeted tests. Sibling filenames alone missed real regressions (#347 broke a *-race.test.ts in the same folder), + # so for each changed source this also runs (a) every test in its folder and (b) every test under src/ that + # imports it by module name (relative path, '@/' alias, vi.mock or dynamic import). Over-selection is fine. + all_tests=$(git ls-files 'src/*.test.ts' 'src/*.test.tsx') + while IFS= read -r file; do + case "$file" in + *.test.ts | *.test.tsx) if [[ -f "$file" ]]; then tests+=("$file"); fi ;; + *.ts | *.tsx) + folder=$(dirname "$file") + while IFS= read -r t; do + if [[ -n "$t" && "$(dirname "$t")" == "$folder" ]]; then tests+=("$t"); fi + done <<<"$all_tests" + module=$(basename "${file%.*}") + if [[ "$module" == index ]]; then module=$(basename "$folder"); fi + while IFS= read -r t; do + if [[ -n "$t" ]]; then tests+=("$t"); fi + done < <(printf "%s\n" "$all_tests" | xargs grep -lE "['\"][^'\"]*/${module}(\\.tsx?)?['\"]" 2>/dev/null || true) + ;; + 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 + node config/scripts/native-build/node-addons/ensure-native-runtime.mjs --runtime=node >/dev/null + npx vitest run --config config/vitest.config.ts "${tests[@]}" + fi fi for app in $(git diff --name-only "$base"...HEAD -- cloud/apps | cut -d/ -f1-3 | sort -u); do if [[ -d "$app" ]]; then (cd "$app" && npx vitest run); fi done -echo "premerge OK: $branch merges cleanly into cloud/integration with typecheck, lint and ${#tests[@]} targeted test file(s) green." +if [[ "${PREMERGE_FULL:-}" == 1 ]]; then scope="the full vitest suite"; else scope="${#tests[@]} targeted test file(s)"; fi +echo "premerge OK: $branch merges cleanly into cloud/integration with typecheck, lint and $scope green." From 4d67445d8cc8bc2d913d9c444c1fdab080544b69 Mon Sep 17 00:00:00 2001 From: Neil Date: Wed, 11 Nov 2026 05:11:21 -0800 Subject: [PATCH 2/2] chore(cloud): premerge runs tests through the repo's run-vitest.mjs (env policy) and PREMERGE_FULL=1 runs pnpm test Bare 'npx vitest' skips run-vitest.mjs's env (e.g. ORCA_BACKGROUND_LAUNCH=1) and the workspace package build, which made 37 tests fail spuriously in a full run on integration HEAD. --- config/scripts/cloud-integration/premerge-check.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/config/scripts/cloud-integration/premerge-check.sh b/config/scripts/cloud-integration/premerge-check.sh index af39baf871b..094060062ea 100755 --- a/config/scripts/cloud-integration/premerge-check.sh +++ b/config/scripts/cloud-integration/premerge-check.sh @@ -22,9 +22,8 @@ pnpm lint tests=() if [[ "${PREMERGE_FULL:-}" == 1 ]]; then - # Full suite (what every build cut runs before its smoke). Slow; use for risky or wide changes. - node config/scripts/native-build/node-addons/ensure-native-runtime.mjs --runtime=node >/dev/null - npx vitest run --config config/vitest.config.ts + # Full suite via the repo's own runner (what every build cut runs before its smoke). Slow; use for wide changes. + pnpm test else # Targeted tests. Sibling filenames alone missed real regressions (#347 broke a *-race.test.ts in the same folder), # so for each changed source this also runs (a) every test in its folder and (b) every test under src/ that @@ -48,8 +47,10 @@ else 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 + node config/scripts/workspace-package-build/build-workspace-packages.mjs >/dev/null node config/scripts/native-build/node-addons/ensure-native-runtime.mjs --runtime=node >/dev/null - npx vitest run --config config/vitest.config.ts "${tests[@]}" + # run-vitest.mjs applies the repo's test env policy (e.g. ORCA_BACKGROUND_LAUNCH=1); bare vitest gives false failures. + node config/scripts/test-runtime/execution-policy/run-vitest.mjs run --config config/vitest.config.ts "${tests[@]}" fi fi for app in $(git diff --name-only "$base"...HEAD -- cloud/apps | cut -d/ -f1-3 | sort -u); do