Skip to content

Fill every probe's records-file contract in one lean_probe helper - #511

Merged
Deicyde merged 1 commit into
mainfrom
cleanup/probe-template-contract
Oct 31, 2026
Merged

Deicyde merged 1 commit into
mainfrom
cleanup/probe-template-contract

Conversation

@Deicyde

@Deicyde Deicyde commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

A follow-up to #482: the skeleton, impact and library index probes get their records-file contract from one lean_probe helper instead of filling it in three places.

Change

  • One helper. lean_probe.render_probe_template(name, **fields) loads probes/<name>, fills fields, and adds the two contract fields every probe template uses: output_env (the variable naming the records file, which run_probe sets) and output_limit (the byte cap _read_probe_records enforces). It is in lean_probe.__all__, since impact and library.generate import it.
  • Read at call time. The helper reads PROBE_OUTPUT_ENV and DEFAULT_PROBE_OUTPUT_LIMIT when it runs, not as default arguments, so tests that patch autoform_cli.lean_probe.DEFAULT_PROBE_OUTPUT_LIMIT still reach the rendered program. A caller that passes either field itself gets a TypeError.
  • Three callers. _render_probe_helper, render_impact_probe and render_library_probe call the helper and drop their two contract lines. lean_probe._probe_template, impact._impact_template and generate.py's inline template load are deleted.
  • Template headers. The header comments of skeleton_probe.lean, impact_probe.lean and library_probe.lean now say the fields are filled through lean_probe.render_probe_template, which adds output_env and output_limit. The templates are format strings, so the comments spell the field names without braces.
  • One test. test_every_probe_template_gets_the_records_file_contract renders all three probes with the limit patched to 1234 and checks that each reads the records-file variable and declares probeOutputLimit as 1234. It passes on main too, since main's three renderers already read the limit at call time; it is there to fail if the helper ever binds the limit as a default argument.

No command, flag, JSON key or message changes, so there is no CHANGELOG entry.

Net: +45/−22 across 7 files.

Verification

  • Rendering the three probes on main and on this branch (pure string rendering, no Lean) gives 803/216/181 lines on main and 805/218/183 here. diff -u shows only the edited header comment lines; every other line is identical.
  • Replacing the helper with a version that binds the limit as a default argument makes all three cases of the new test fail.
  • When called directly on macOS, the new test's three cases pass, as do the existing pins on the rendered probes: the helper's probeOutputLimit line in tests/test_lean_probe.py, the records-file variable in tests/test_impact.py, and no unfilled output_limit field in tests/test_library_generate.py. So does the fake-Lean records-file limit test; the real-Lean one skips there.
  • The locked ruff 0.15.17 check passes on the touched Python files. ruff format --check reports the same findings on them as on the base; CI does not run the formatter.
  • No file in the tree names _probe_template or _impact_template.
  • CI coverage:
    • test (Python 3.10 and 3.13) runs ruff check autoform_cli servers tests and pytest -q, which runs the new test and the render pins; none needs Lean.
    • real-lean runs tests/test_impact.py and tests/test_library_generate.py against real Lean, so the rendered impact and library probes, header comments included, are run by Lean.
    • real-lean-skeleton runs tests/test_lean_probe.py against real Lean. test_probe_stops_before_its_records_file_exceeds_the_limit patches the limit to 1024, builds the helper module from the rendered skeleton template, and checks that the probe stops before its records file passes that size.
    • windows-hardening runs only the node IDs it lists, none of which this branch changes.

Overlap

The skeleton, impact and library index probes each loaded their
template from probes/ and filled `output_env` and `output_limit` by
hand. Those two fields are the probe's half of the records-file contract
that run_probe and _read_probe_records hold on the Python side, so three
copies could drift apart.

lean_probe.render_probe_template(name, **fields) now loads
`probes/<name>` and adds both fields. It reads PROBE_OUTPUT_ENV and
DEFAULT_PROBE_OUTPUT_LIMIT when called, not as default arguments, so
tests that patch the limit still reach the rendered program. It replaces
_probe_template and impact's _impact_template, and generate.py's inline
load. The template header comments now name the helper; they spell the
field names without braces, since the templates are format strings.

The new test renders all three probes with the limit patched to 1234 and
checks each reads the records-file variable and declares the patched
limit. Rendered output is unchanged apart from the header comments.
@Deicyde

Deicyde commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Review at 0e1b812: merge.

Nothing blocks merge, and there are no notes.

  • Output is unchanged apart from the comments. I rendered the skeleton helper, an impact probe (with selected modules, module evidence and an artifact directory) and a library probe on main 8155f23 and on this head. The only differences are the three edited header comments, 12 lines in all. No caller passes output_env or output_limit any more, and nothing in the tree still names _probe_template or _impact_template.
  • The limit is read at call time. The new test patches DEFAULT_PROBE_OUTPUT_LIMIT and finds the patched value in all three rendered probes. So the existing tests that patch the limit, such as test_probe_stops_before_its_records_file_exceeds_the_limit, still reach the program Lean runs.
  • audit_probe.lean is not a format template and has no records file, so leaving it out is right.

Checks

Posted by Claude Code (session jackmccarthy-eb).

@Deicyde
Deicyde merged commit 11e5a9e into main Oct 31, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant