diff --git a/docs/5-project/process/ci-checks.md b/docs/5-project/process/ci-checks.md index 16919874d..a34bd4410 100644 --- a/docs/5-project/process/ci-checks.md +++ b/docs/5-project/process/ci-checks.md @@ -90,7 +90,14 @@ read node config or an agent toplevel into their script, so each builds the scri with stand-in values (`passthru.typecheckScript`), from the same function as the real one. `vm-test-typecheck-control` passes only when the checker rejects a known type error, which shows the -checker resolves `test_driver`. [`.forgejo/workflows/vm-nightly.yml`](../../../.forgejo/workflows/vm-nightly.yml) +checker resolves `test_driver`. +Each check also runs `nix/vm-test-shadow-scan.py`, which fails when a step of the script +binds a name at module level that the script also defines as a function (`pod = ...` +after `def pod`, for example, including inside a `with subtest(...)`). A script and +`lib/k3s.py` share one namespace, so the assignment replaces the helper for every later +call, and neither `ty` nor `ruff` sees it. `vm-test-typecheck-shadow-control` passes only +when the scan rejects each way of rebinding a function and accepts the same names where +they're local. [`.forgejo/workflows/vm-nightly.yml`](../../../.forgejo/workflows/vm-nightly.yml) builds them nightly at 02:30, one job per test, so the runner's one-hour job limit applies to each test alone and a stuck test no longer hides the others' results. The matrix in `vm-nightly.yml` is the list of tests; diff --git a/nix/vm-test-shadow-scan.py b/nix/vm-test-shadow-scan.py new file mode 100644 index 000000000..b539e152b --- /dev/null +++ b/nix/vm-test-shadow-scan.py @@ -0,0 +1,83 @@ +"""Fail when a VM test script rebinds a function it defines. + +A VM test script is one module: `lib/k3s.py` and the test's own helpers are +concatenated in front of the steps, and every `with subtest(...)` body runs in +that module's namespace. A step that assigns `pod = ...` replaces the library's +`pod()` for every later call, and the test dies mid-run with +`TypeError: 'dict' object is not callable`. `ty` and `ruff --select F` don't see +it, because a rebinding at module level is legal Python. + +The scan names every module-level binding (assignment, `for`/`with`/`except` +target, walrus, `import ... as`) whose name is also a module-level `def`. It +looks into blocks that share the module's namespace (`with`, `if`, `for`, +`while`, `try`), and not into function, class or comprehension bodies, whose +bindings are local. + +Usage: shadow-scan.py