Repository navigation
fix(scripts): make update-nixpkgs-inputs flake.lock readers total over wrong shapes (#6847) - #8688
Conversation
…r wrong shapes (#6847) All five flake.lock readers (get_input_info, get_input_node, get_input_ref, get_locked_rev, discover_inputs) now treat a non-object node, a null/non-object original/locked, a non-string type/ref/rev, and a missing node/root the way discover_inputs has always treated a missing node: the input is skipped or reported unknown, never a raw AttributeError/TypeError/KeyError. A non-string ref makes the input unclassifiable (skipped in every discovery pass); a non-string locked rev reports unknown/None — that shape passes discovery and used to crash get_input_info inside the execution loop, after earlier inputs had already been updated. Both byte-identical copies updated; TestLockReadersWrongShapes covers the shapes against both copies (suite 22/22).
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 44 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f8905467c9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| class TestLockReadersWrongShapes(unittest.TestCase): | ||
| """#6847: every flake.lock reader is total over wrong shapes. |
There was a problem hiding this comment.
Add property coverage for the lock-reader totality invariant
The new suite asserts totality over arbitrary JSON shapes, but exercises only manually enumerated examples. This violates the root AGENTS.md requirement to state meaningful parser invariants and cover them with property tests; example-based coverage explicitly does not replace those tests. Add generated recursive JSON values and mutations of structured locks for both script copies, asserting that the readers never raise and return the expected result types/fallbacks, while retaining these examples as regression cases.
AGENTS.md reference: AGENTS.md:L42-L46
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Added in 76eedc4730 — agreed, the invariant deserved property coverage, not just enumerated examples. TestLockReaderTotalityProperty states the oracle in its docstring (for any JSON value in any lock position, every reader returns its documented type and never raises: discover → list of root-input names, info → 3-tuple of strings, ref/rev → string or None, node → dict or None) and exercises it with a deterministic-seed generator: recursive JSON values built from the flake.lock vocabulary, plus subtree mutations of the well-formed lock — 400 cases against each of the two byte-identical copies. Suite now 23/23.
…nt (#6847) Codex P1 on #8688: the wrong-shape suite enumerated examples only. Add TestLockReaderTotalityProperty: a deterministic-seed generator produces recursive JSON values from the flake.lock vocabulary plus subtree mutations of the well-formed lock (400 cases per copy, both copies); the named oracle asserts every reader returns its documented type and never raises.
Refs #6847
The five
flake.lockreaders inupdate-nixpkgs-inputs.pydisagreed about shape safety:discover_inputsguarded its lookups, whileget_input_infodirect-indexedlock_data["nodes"]["root"], every reader's.get("original", {})default was defeated by an explicit JSONnull,.lower()ran on an uncheckedtype, andlen(rev)ran on an uncheckedlocked.rev— the dangerous one, since discovery never readsrev, so a numeric rev passed the planning pass and crashed inside the execution loop, potentially after earlier inputs had already been updated.Fix
Both byte-identical copies (
scripts/andpkgs/id/scripts/) now share one shape discipline, stated in a comment block at the readers:_as_dict/_as_strcoercion helpers and_lock_nodes/_root_inputschains make every reader a total function over any JSON shape.get_input_nodereturns None,get_input_inforeturns the("unknown", "unknown", "unknown")tuple it already used for unresolvable inputs,get_input_ref/get_locked_revreturn None,pin_inputrefuses cleanly (False → per-input failure record).originalorlockedreads as{}— the readers' original→locked fallback chains then report whatever is well-formed.typereads as no type; a non-stringrevreports unknown/None; a non-stringrefmakes the input unclassifiable —discover_inputsskips it in every pass rather than reading it as "no ref".Because discovery (the planning pass, over the pristine lock) and the execution loop now share the same total readers, a malformed lock cannot crash the run after partial updates.
Tests
New
TestLockReadersWrongShapesinscripts/tests/test_update_nixpkgs_inputs.py, following the suite's both-copies pattern: well-formed lock unchanged; string/null/list/missing node; null/stringoriginal; numericoriginal.type; nulllocked; numericlocked.rev(discovery passes it, execution-loop readers stay safe); numericref; missing root/nodes in several shapes, including a non-object top level;pin_inputrefusing a string node. Full suite: 22/22 pass, including the byte-identity, exit-code, wrapper, and Hydra-gate contracts.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.