Cookbook checker: hold each recipe to its own imports (#75) - #77
Open
craigmcchesney wants to merge 1 commit into
Open
craigmcchesney wants to merge 1 commit into
craigmcchesney wants to merge 1 commit into
Conversation
The checker prepends a shared preamble to every partial snippet, and that preamble imports the whole client API, so a recipe's own imports were never consulted: #74 shipped a recipe using dfc, and another using QueryParams, PV and bc, that type-checked cleanly and raised NameError when run on its own. A third pass (pure ast) now requires every name a partial snippet uses that the preamble imports to be bound somewhere in the same recipe. The set of names is parsed from the preamble itself, so its fixtures (client, params, the carried-forward ids) stay out of scope. A second canary self-tests the pass in both directions. The six "Imports used by the examples" blocks were all cookbook:skip, so a misspelled import there was never checked either; they are now checked like any other snippet and supply the bindings the pass looks for. conventions.md gains an imports block and connecting.md's one partial block an inline import, the two real misses the pass found. Plan: plan/tickets/75/plan.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CajTMkjkkzeoWXLSgMpn5k
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The implementation matches the stated design, includes bidirectional self-test coverage, and updates all affected recipes and documentation consistently.
Review effort: Balanced
Findings: None
What changed in this PR
Adds recipe-local import validation to the cookbook checker, preventing its shared preamble from masking missing imports.
Changes:
- Adds an AST-based import-validation pass with self-tests.
- Type-checks cookbook import blocks and fixes missing imports.
- Documents the checker behavior and implementation plan.
| File | Description |
|---|---|
.dev/tools/check-cookbook-snippets.py |
Adds import validation and canaries. |
CLAUDE.md |
Documents the recipe import rule. |
plan/tickets/75/plan.md |
Records design and implementation decisions. |
doc/cookbook/README.md |
Explains cookbook validation. |
doc/cookbook/connecting.md |
Adds required query imports. |
doc/cookbook/conventions.md |
Adds an imports block. |
doc/cookbook/datasets-and-annotations.md |
Enables checking of imports. |
doc/cookbook/ingestion.md |
Enables checking of imports. |
doc/cookbook/machine-configuration.md |
Enables checking of imports. |
doc/cookbook/pv-metadata.md |
Enables checking of imports. |
doc/cookbook/query.md |
Enables checking of imports. |
doc/cookbook/sample-status.md |
Enables checking of imports. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #75. Plan:
plan/tickets/75/plan.md(in this PR; single-PR shape agreed at triage).What changed
.dev/tools/check-cookbook-snippets.pygains a third pass. Every name a# cookbook:partialsnippet uses that the checker preamble imports must be bound somewhere in the same recipe: by an import, assignment,def, parameter, etc., in any checked block, in any order. The set of names is parsed fromPREAMBLE's own import statements, so its fixtures (client,params, the carried-forward ids) stay out of scope with no second list to maintain. One error per name per file, at the first use:dfcwithout importing it must be reported, and the same recipe with the import must not be. It also asserts that the preamble import set containsdfc.# cookbook:skip. Triage found that they had been skipped since the cookbook was written, so a misspelled import in one of them was never checked. They are now type-checked like any other block, and they provide the imports the new pass looks for.conventions.mdgets an imports block, andconnecting.md's one partial block gets an inline import.CLAUDE.mddescribe the rule.No
NEXT.mdentry: this changes repository tooling and cookbook import lines only (same call as #70).Verification
check-cookbook-snippets.py:OK: 129 snippets in 9 files(previously 122 checked, 6 skipped).Against the Live bucket query tests and docs (#16 PR B) #74 misses:
query.mdfromeedae6a~1(imports block unskipped): reportsdfc, and nothing else.ingestion.mdwith the three imports removed: reportsQueryParams,PVandbc.PvQuery as PV→PvQuerry as PVinquery.md's imports block is now a mypy error; before this change nothing reported it.Self-test, with the checker deliberately broken three ways:
Each fails with its own
SELF-TEST FAILEDmessage.ruff check/ruff format --checkclean (repo, and the checker explicitly); release-notes checker OK.🤖 Generated with Claude Code
https://claude.ai/code/session_01CajTMkjkkzeoWXLSgMpn5k