test(repo): Prevent Python test bytecode drift

Set PYTHONDONTWRITEBYTECODE for the shared Python runner and the
root test-suite launcher so local test runs do not create __pycache__
artifacts inside skills.

This keeps npm run test deterministic and avoids false negatives in the
editorial bundle inventory checks.
This commit is contained in:
sickn33
2026-03-29 09:27:19 +02:00
parent 08a31cacf5
commit 3367cf2fdd
2 changed files with 13 additions and 1 deletions

View File

@@ -5,6 +5,10 @@
const { spawn, spawnSync } = require('node:child_process');
const args = process.argv.slice(2);
const PYTHON_ENV = {
...process.env,
PYTHONDONTWRITEBYTECODE: process.env.PYTHONDONTWRITEBYTECODE || '1',
};
if (args.length === 0) {
console.error('Usage: node tools/scripts/run-python.js <script.py> [args...]');
@@ -47,6 +51,7 @@ function canRun(candidate) {
command,
[...baseArgs, '-c', 'import sys; raise SystemExit(0 if sys.version_info[0] == 3 else 1)'],
{
env: PYTHON_ENV,
stdio: 'ignore',
shell: false,
},
@@ -67,6 +72,7 @@ if (!selected) {
const [command, ...baseArgs] = selected;
const child = spawn(command, [...baseArgs, ...args], {
env: PYTHON_ENV,
stdio: 'inherit',
shell: false,
});

View File

@@ -58,7 +58,13 @@ function isNetworkTestsEnabled() {
}
function runNodeCommand(args) {
const result = spawnSync(process.execPath, args, { stdio: "inherit" });
const result = spawnSync(process.execPath, args, {
env: {
...process.env,
PYTHONDONTWRITEBYTECODE: process.env.PYTHONDONTWRITEBYTECODE || "1",
},
stdio: "inherit",
});
if (result.error) {
throw result.error;