mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 19:34:29 +00:00
Merge pull request #437 from nwparker/cloud/premerge-same-folder-tests
chore(cloud): premerge runs same-folder and importer tests via run-vitest.mjs; PREMERGE_FULL=1 runs pnpm test (PM-gap, P1)
This commit is contained in:
@@ -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,40 @@ 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
|
||||
node config/scripts/native-build/node-addons/ensure-native-runtime.mjs --runtime=node >/dev/null
|
||||
npx vitest run --config config/vitest.config.ts "${tests[@]}"
|
||||
if [[ "${PREMERGE_FULL:-}" == 1 ]]; then
|
||||
# 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
|
||||
# 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/workspace-package-build/build-workspace-packages.mjs >/dev/null
|
||||
node config/scripts/native-build/node-addons/ensure-native-runtime.mjs --runtime=node >/dev/null
|
||||
# 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
|
||||
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."
|
||||
|
||||
Reference in New Issue
Block a user