web lint hook: run the reviewed copy's source checks when a push also changes scripts/cmux-next; INPUTS typos fail the tests

Merged
LA
3d ago
+349-17

Summary

Stacked on #34046 (land it first; until then this diff also shows its two commits). Three follow-ups to the pre-push web lint's per-check INPUTS:

  1. A typo in INPUTS turned coverage off with no error. A new test reads every python3 source check of the real webviews check. If a script assigns INPUTS, declared_inputs() must be able to read it, and every entry must match at least one tracked file (a glob must have a match). A wrong path now fails tests/test_web_lint_prepush.py; I confirmed this by changing check-toast-targets.py's entry to Sourcesx/**/*.swift.

  2. The c0230efd501 case.

    • Why the hook refused: the trust boundary. The hook never runs code that a push changes. c0230efd501 changed scripts/cmux-next/media/states/*.json, and scripts/cmux-next/ is code the webviews check executes, so the hook did not lint that push at all, and the ringed Swift field passed.
    • The hook can still check that push. It holds a reviewed copy of scripts/cmux-next (--trusted-scripts-dir, refreshed from feat-cmux-next). When every executed file that the push changes is in that folder, the hook now runs the declared source checks that the changed files feed, from that copy, on the pushed tree. Their INPUTS also come from the copy.
    • Each check runs under the hook's own interpreter with -I, as though it sat at its own path in the pushed tree. (Each check finds the repository from __file__.)
    • '' and the working directory leave sys.path before any import, so a module that the push adds can never stand in for the standard library. A test pushes scripts/cmux-next/argparse.py and confirms that it never loads.
    • A check whose own script the push changes is not run, and the hook names it. The copy would judge the push by the rule that the push replaces; CI's web lint checks the new rule.
    • On the real c0230efd501, the hook now refuses the push at AllThemesPlaygroundView.swift:18. Text-focus, toast-targets, dialog-keys and catalog-keys run in 2.5 s or less each.
    • The module docstring states the trust boundary and this case. It no longer claims that #34046 covered c0230efd501.
  3. A check that cannot fail is not in the pre-push set. check-system-blue.py only warns (it always exits 0), so it no longer declares INPUTS. This matches check-attachment-caps. A test keeps both without INPUTS.

No CI job, step or gate is added.

Testing

Red on 925f866d056 (#34046's head; the tests are in their own commit), green on the head:

(cd tests && python3 -m unittest -k scripts_cmux_next -k reviewed_copy -k check_script -k only_warns -k swift test_web_lint_prepush)

On the base, 6 tests fail: the push with a state file and a ringed field reaches origin (on a build host and with CMUX_LOCAL_HEAVY_CHECKS=0); the shadowing-module push and the changed-rule push are not handled; system-blue still declares INPUTS. On the head, all pass.

Observed / Not run

Observed:

  • python3 tests/test_web_lint_prepush.py: 67 tests OK.
  • The INPUTS test fails on a wrong path ('Packages/macOS/CmuxNext/Sourcesx/**/*.swift' matches no tracked file) and passes on the real paths.
  • make_plan and run_plan on c0230efd501 (a worktree of that commit, this branch's scripts/cmux-next as the trusted copy): text-focus is red at AllThemesPlaygroundView.swift:18; toast-targets, dialog-keys and catalog-keys pass.
  • python3 scripts/cmux-next/prepush-gate.py: no new violations.
  • scripts/web-lint.sh: only the base red at AllThemesPlaygroundView.swift:18 (#34025 fixes it).

Not run:

  • A real push of c0230efd501's shape through an installed hook on a Mac. The tests use the real git push and the installed hook in a throwaway repository.
  • This Linux host's git guard refuses the existing tree_of's -c core.hooksPath=/dev/null. That code is older than this PR and this PR does not change it.

Changelog

none

Proof

No capture: hook tooling only.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


Summary by cubic

Improves the pre-push web lint so Swift-only changes and pushes that also modify scripts/cmux-next are still linted. The hook now runs the specific source-check pieces that read changed files (declared in each script's INPUTS) instead of skipping or refusing the push, and INPUTS typos now fail the test suite.

Key changes

  • Source-check scripts declare what they read via INPUTS; the hook runs only those pieces when a push touches them, skipping installs and the rest of the check.
  • Pushes that change executed script code under scripts/cmux-next use the hook's reviewed copy to run the affected pieces on the pushed tree, as long as no check script itself changed; the runner blocks every way to load or start code from the pushed tree (imports, module spec loads, code-file opens, ctypes.dlopen, and subprocess or os.exec* of a tree program) and reads the reviewed script before the guards go in, and a piece the copy lacks is named instead of dropped silently.
  • check-system-blue.py and check-attachment-caps.py declare no INPUTS since they only warn.
  • A new test verifies every declared INPUTS pattern matches at least one tracked file, and finds the bindings via ast, so typed or unspaced declarations count and a typo can't silently disable coverage.