Watch
0
0
Fork
You've already forked hyperhive
0

vm-tests: the typecheck fails a step that rebinds a function of its script

A VM test script and `lib/k3s.py` share one namespace, so 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` accept a module-level rebinding, so this cost a full VM round
on #6947.

`vm-test-shadow-scan.py` parses the script and fails when a name bound at module
level (assignment, `for` or `with` target, `import ... as`, walrus, `except ... as`)
is also a module-level `def`. It looks into `with`, `if`, `for`, `while` and `try`
bodies, where `with subtest(...)` steps live, and not into function or
comprehension bodies. Every `vm-test-typecheck-<name>` runs it on the script alone.
`vm-test-typecheck-shadow-control` passes only when it rejects each form of
rebinding and accepts the same names where they are local.

The one existing case, `sources` in `k8s-services`, is renamed `cred_sources`.

Closes #6951
This commit is contained in:
maia 2026-11-28 01:54:14 +01:00 • committed by maia
commit 132d876668

View file

@ -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;