Skip to content

Cookbook checker: hold each recipe to its own imports (#75) - #77

Open
craigmcchesney wants to merge 1 commit into
mainfrom
feat/75-cookbook-import-check
Open

craigmcchesney wants to merge 1 commit into
mainfrom
feat/75-cookbook-import-check

Conversation

@craigmcchesney

Copy link
Copy Markdown
Collaborator

Closes #75. Plan: plan/tickets/75/plan.md (in this PR; single-PR shape agreed at triage).

What changed

  • .dev/tools/check-cookbook-snippets.py gains a third pass. Every name a # cookbook:partial snippet 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 from PREAMBLE'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:
    doc/cookbook/query.md:434: 'dfc' is used but never imported by this recipe (the checker preamble supplies it; add it to the recipe's imports) [+3 more uses]
    
  • A second self-test canary checks the pass in both directions. A recipe that uses dfc without importing it must be reported, and the same recipe with the import must not be. It also asserts that the preamble import set contains dfc.
  • The six "Imports used by the examples" blocks are no longer # 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.
  • The two real misses the pass found are fixed: conventions.md gets an imports block, and connecting.md's one partial block gets an inline import.
  • Cookbook README "Verifying the examples" and CLAUDE.md describe the rule.

No NEXT.md entry: 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.md from eedae6a~1 (imports block unskipped): reports dfc, and nothing else.
    • ingestion.md with the three imports removed: reports QueryParams, PV and bc.
  • PvQuery as PV → PvQuerry as PV in query.md's imports block is now a mypy error; before this change nothing reported it.

  • Self-test, with the checker deliberately broken three ways:

    • the rule never matching
    • the recipe's own imports ignored
    • the preamble parse finding nothing

    Each fails with its own SELF-TEST FAILED message.

  • ruff check / ruff format --check clean (repo, and the checker explicitly); release-notes checker OK.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CajTMkjkkzeoWXLSgMpn5k

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
Copilot AI balanced review requested due to automatic review settings October 2, 2026 20:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cookbook checker: verify each recipe imports the names its snippets use

2 participants