Files
Orkas/scripts/run-python-tests.mjs
T
wyt b35d6f6f80 Retain native dependencies and diagnostic test execution
Preserve the reviewed user-facing behavior, public-edition boundaries and owning regression coverage.

Prompt audit: Keep existing permission, ownership and recovery contracts at their current tool, runtime or test owner (Hard constraint). No separate resident instruction is added. Drop excluded hosted-only branches; retain shared side effects and tests. No optional prompt rewrite.

Prompt confirmation: The requester confirmed the exact proposed final behaviors and existing resource placements by directing that the primary implementation be followed, then explicitly requested this PR and merge. Preserve that confirmed scope only.

- Keep: The behavior and placement detailed in the audit above. Type: Hard constraint. Why: Preserve its existing canonical owner without duplicated resident instructions.
- Drop: Superseded overlapping wording and excluded hosted-only behavior. Type: Hard constraint. Why: Preserve the confirmed public capability and authority boundary.

Confirmed-by: Requester, exact final-state proposal and subsequent delivery request.
Scope: The previously confirmed final behavior and existing placement described above; no optional prompt rewrite.
2026-11-04 23:22:49 +08:00

57 lines
2.2 KiB
JavaScript

#!/usr/bin/env node
import { existsSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { spawnSync } from 'node:child_process';
import { withWindowsGitOnPath, withWindowsPowerShellModules } from './test-runtime-env.mjs';
const here = dirname(fileURLToPath(import.meta.url));
// The open-source app and its test virtual environment share this flat root.
const repoRoot = resolve(here, '..');
const localPython = process.platform === 'win32'
? resolve(repoRoot, 'venv', 'Scripts', 'python.exe')
: resolve(repoRoot, 'venv', 'bin', 'python');
const testEnvironment = withWindowsPowerShellModules(withWindowsGitOnPath(process.env));
const candidates = [testEnvironment.ORKAS_TEST_PYTHON, localPython, 'python3', 'python']
.filter((value, index, all) => value && all.indexOf(value) === index);
const python = candidates.find((candidate) => {
if (candidate.includes('/') || candidate.includes('\\')) {
if (!existsSync(candidate)) return false;
}
const probe = spawnSync(candidate, ['--version'], { stdio: 'ignore', env: testEnvironment });
return probe.status === 0;
});
if (!python) {
console.error(`[run-python-tests] Python not found; tried: ${candidates.join(', ')}`);
process.exit(2);
}
testEnvironment.ORKAS_TEST_PYTHON = python;
const args = process.argv.slice(2);
const cwdFlag = args.findIndex(arg => arg.startsWith('--cwd='));
const cwd = cwdFlag < 0 ? repoRoot : resolve(args.splice(cwdFlag, 1)[0].slice(6));
if (args.length === 0) args.push('resources/builtin');
if (args.some(arg => arg === '--resume' || arg.startsWith('--checkpoint-dir') || arg.startsWith('--batch-count'))) {
try {
const { runRunnerCheckpoint } = await import('./runner-checkpoint.mjs');
process.exitCode = await runRunnerCheckpoint('python', args, { cwd, env: testEnvironment, python });
} catch (error) {
console.error(`[run-python-tests] ${error.message}`);
process.exitCode = 1;
}
} else {
const result = spawnSync(python, ['-m', 'pytest', ...args], {
cwd,
stdio: 'inherit',
env: testEnvironment,
});
if (result.error) {
console.error(`[run-python-tests] failed to start pytest: ${result.error.message}`);
process.exit(1);
}
process.exit(result.status ?? 1);
}