From f8905467c9a58110c47e8e8a84ba15fc3754f67e Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Wed, 11 Nov 2026 07:55:05 -0600 Subject: [PATCH 1/2] fix(scripts): make update-nixpkgs-inputs flake.lock readers total over wrong shapes (#6847) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- pkgs/id/scripts/update-nixpkgs-inputs.py | 101 ++++++++--- scripts/tests/test_update_nixpkgs_inputs.py | 180 ++++++++++++++++++++ scripts/update-nixpkgs-inputs.py | 101 ++++++++--- 3 files changed, 326 insertions(+), 56 deletions(-) diff --git a/pkgs/id/scripts/update-nixpkgs-inputs.py b/pkgs/id/scripts/update-nixpkgs-inputs.py index 24b49c2411..7440e025e7 100755 --- a/pkgs/id/scripts/update-nixpkgs-inputs.py +++ b/pkgs/id/scripts/update-nixpkgs-inputs.py @@ -177,34 +177,68 @@ def load_flake_lock(repo_dir): return json.load(f) +# --- flake.lock shape discipline (#6847) ----------------------------------- +# flake.lock is normally nix-generated, but it is also hand-edited, +# hand-pinned (pin_input below writes it), merged, and occasionally +# truncated or conflicted — exactly the states this repair tool is +# re-run against. Every reader below is therefore a TOTAL function +# over any JSON shape: a non-object node, a null/non-object +# "original"/"locked", a non-string type/ref/rev, and a missing +# node/root are all treated the way discover_inputs has always +# treated a missing node — the input is skipped / reported unknown — +# never a raw AttributeError/TypeError/KeyError. The planning pass +# (discover_inputs over the pristine lock) decides what runs, and +# because the execution loop's readers share the same discipline, a +# malformed lock cannot crash the run after earlier inputs have +# already been updated. + + +def _as_dict(value): + """`value` if it is a JSON object, else an empty dict.""" + return value if isinstance(value, dict) else {} + + +def _as_str(value): + """`value` if it is a string, else None.""" + return value if isinstance(value, str) else None + + +def _lock_nodes(lock_data): + """The lock's "nodes" object ({} for any wrong shape).""" + return _as_dict(_as_dict(lock_data).get("nodes")) + + +def _root_inputs(lock_data): + """The root node's "inputs" object ({} for any wrong shape).""" + return _as_dict(_as_dict(_lock_nodes(lock_data).get("root")).get("inputs")) + + def get_input_info(lock_data, input_name): """Extract rev, source URL, and ref for an input from parsed flake.lock. - Returns: (short_rev, source_url, ref_display) + Returns: (short_rev, source_url, ref_display) — "unknown" fields + for a missing or wrong-shape node, mirroring discover's skip. """ - root_inputs = lock_data["nodes"]["root"]["inputs"] - node_name = root_inputs.get(input_name) - - if not isinstance(node_name, str): + node = get_input_node(lock_data, input_name) + if node is None: return ("unknown", "unknown", "unknown") - node = lock_data["nodes"][node_name] - original = node.get("original", {}) - locked = node.get("locked", {}) + original = _as_dict(node.get("original")) + locked = _as_dict(node.get("locked")) - type_ = (original.get("type") or locked.get("type") or "").lower() - full_rev = locked.get("rev", "unknown") + type_ = (_as_str(original.get("type")) or _as_str(locked.get("type")) or "").lower() + full_rev = _as_str(locked.get("rev")) or "unknown" rev = full_rev[:12] if len(full_rev) > 12 else full_rev - branch = original.get("ref") + branch = _as_str(original.get("ref")) ref_display = branch if branch else "(default)" if type_ == "github": - owner = original.get("owner") or locked.get("owner") or "?" - repo = original.get("repo") or locked.get("repo") or "?" + owner = _as_str(original.get("owner")) or _as_str(locked.get("owner")) or "?" + repo = _as_str(original.get("repo")) or _as_str(locked.get("repo")) or "?" slug = f"{owner}/{repo}" url = f"github:{slug}/{branch}" if branch else f"github:{slug}" elif type_ == "tarball": - url = original.get("url") or locked.get("url") or "?" + url = _as_str(original.get("url")) or _as_str(locked.get("url")) or "?" else: url = f"{type_}:{json.dumps(original or locked)}" @@ -212,28 +246,34 @@ def get_input_info(lock_data, input_name): def get_input_node(lock_data, input_name): - """Return the lock node for a root input name, or None.""" - root_inputs = lock_data.get("nodes", {}).get("root", {}).get("inputs", {}) - node_name = root_inputs.get(input_name) + """Return the lock node for a root input name, or None. + + None covers every "not usable" shape uniformly: input not in the + root inputs, a non-string node reference (follows), a node + missing from "nodes", and a node that is not an object. + """ + node_name = _root_inputs(lock_data).get(input_name) if not isinstance(node_name, str): return None - return lock_data.get("nodes", {}).get(node_name) + return _as_dict(_lock_nodes(lock_data).get(node_name)) or None def get_input_ref(lock_data, input_name): - """Return the input's original.ref (None when unset / not found).""" + """Return the input's original.ref (None when unset / not found / + not a string).""" node = get_input_node(lock_data, input_name) if not node: return None - return node.get("original", {}).get("ref") + return _as_str(_as_dict(node.get("original")).get("ref")) def get_locked_rev(lock_data, input_name): - """Return the input's full locked revision (None when not locked).""" + """Return the input's full locked revision (None when not locked / + not a string).""" node = get_input_node(lock_data, input_name) if not node: return None - return node.get("locked", {}).get("rev") + return _as_str(_as_dict(node.get("locked")).get("rev")) def discover_inputs(lock_data, ref): @@ -248,7 +288,8 @@ def discover_inputs(lock_data, ref): ref="master" → inputs with ref="master" or no ref (default branch) ref= → inputs with that exact ref """ - root_inputs = lock_data.get("nodes", {}).get("root", {}).get("inputs", {}) + root_inputs = _root_inputs(lock_data) + nodes = _lock_nodes(lock_data) results = [] for name, node_ref in root_inputs.items(): @@ -256,14 +297,14 @@ def discover_inputs(lock_data, ref): if not isinstance(node_ref, str): continue - node = lock_data["nodes"].get(node_ref) - if not node: + node = nodes.get(node_ref) + if not isinstance(node, dict): continue - original = node.get("original", {}) + original = _as_dict(node.get("original")) # Match by URL: github:NixOS/nixpkgs - if original.get("type", "").lower() != "github": + if (_as_str(original.get("type")) or "").lower() != "github": continue owner = original.get("owner") if not isinstance(owner, str) or owner.lower() != "nixos": @@ -271,8 +312,12 @@ def discover_inputs(lock_data, ref): if original.get("repo", "") != "nixpkgs": continue - # Filter by ref + # Filter by ref. A ref that is present but not a string is a + # poison entry (#6847): the input cannot be classified, so it + # is skipped in every pass rather than read as no ref. input_ref = original.get("ref") + if input_ref is not None and not isinstance(input_ref, str): + continue if ref is not None: if ref == "master": # master matches explicit "master" or no ref (github default) diff --git a/scripts/tests/test_update_nixpkgs_inputs.py b/scripts/tests/test_update_nixpkgs_inputs.py index c584f6b70a..2810df001b 100644 --- a/scripts/tests/test_update_nixpkgs_inputs.py +++ b/scripts/tests/test_update_nixpkgs_inputs.py @@ -750,5 +750,185 @@ def test_verification_stays_on_in_both_copies(self): self.assertTrue(ctx.check_hostname) +UNKNOWN = ("unknown", "unknown", "unknown") + + +class TestLockReadersWrongShapes(unittest.TestCase): + """#6847: every flake.lock reader is total over wrong shapes. + + A non-object node, a null/non-object original/locked, a + non-string type/ref/rev, and a missing node/root are treated the + way discover_inputs has always treated a missing node — the input + is skipped / reported unknown — never a raw AttributeError / + TypeError / KeyError. The mid-run case matters most: locked.rev + as a number passes discovery (which never reads it) and used to + crash get_input_info inside the execution loop, after earlier + inputs had already been updated. + """ + + def _module(self, script_dir: Path): + return runpy.run_path(str(script_dir / "update-nixpkgs-inputs.py")) + + def _lock(self, node, root_inputs=None, nodes_extra=None): + nodes = {"root": {"inputs": root_inputs or {"nixpkgs": "nixpkgs-node"}}} + if node is not _MISSING: + nodes["nixpkgs-node"] = node + if nodes_extra: + nodes.update(nodes_extra) + return {"nodes": nodes, "root": "root", "version": 7} + + def _readers(self, mod): + return ( + mod["discover_inputs"], + mod["get_input_info"], + mod["get_input_ref"], + mod["get_locked_rev"], + ) + + def test_well_formed_lock_unchanged_in_both_copies(self): + for label, script_dir in COPIES.items(): + with self.subTest(copy=label): + discover, info, ref, locked_rev = self._readers(self._module(script_dir)) + self.assertEqual(discover(FLAKE_LOCK, None), ["nixpkgs"]) + self.assertEqual( + info(FLAKE_LOCK, "nixpkgs"), + ("0123456789ab", "github:NixOS/nixpkgs", "(default)"), + ) + self.assertIsNone(ref(FLAKE_LOCK, "nixpkgs")) + self.assertEqual( + locked_rev(FLAKE_LOCK, "nixpkgs"), + "0123456789abcdef0123456789abcdef01234567", + ) + + def test_wrong_shape_nodes_are_skipped_in_both_copies(self): + good_original = {"type": "github", "owner": "NixOS", "repo": "nixpkgs"} + good_locked = {"type": "github", "rev": "a" * 40} + # (node, discover, info, ref, locked_rev) + cases = { + "node is a string": ("nixpkgs-node", [], UNKNOWN, None, None), + "node is null": (None, [], UNKNOWN, None, None), + "node is a list": (["nixpkgs"], [], UNKNOWN, None, None), + "node missing from nodes": (_MISSING, [], UNKNOWN, None, None), + # original unusable: discovery cannot match, but the + # locked entry still reports (the readers' original -> + # locked fallback chains), with owner/repo unknown. + "original is null": ( + {"original": None, "locked": good_locked}, + [], + ("aaaaaaaaaaaa", "github:?/?", "(default)"), + None, + "a" * 40, + ), + "original is a string": ( + {"original": "github", "locked": good_locked}, + [], + ("aaaaaaaaaaaa", "github:?/?", "(default)"), + None, + "a" * 40, + ), + "original.type is a number": ( + {"original": {**good_original, "type": 7}, "locked": good_locked}, + [], + ("aaaaaaaaaaaa", "github:NixOS/nixpkgs", "(default)"), + None, + "a" * 40, + ), + # locked unusable: discovery matches on original; the rev + # readers report unknown/None instead of crashing. + "locked is null": ( + {"original": good_original, "locked": None}, + ["nixpkgs"], + ("unknown", "github:NixOS/nixpkgs", "(default)"), + None, + None, + ), + } + for label, script_dir in COPIES.items(): + with self.subTest(copy=label): + discover, info, ref, locked_rev = self._readers(self._module(script_dir)) + for name, (node, want_discover, want_info, want_ref, want_rev) in cases.items(): + with self.subTest(shape=name): + lock = self._lock(node) + self.assertEqual(discover(lock, None), want_discover) + self.assertEqual(info(lock, "nixpkgs"), want_info) + self.assertEqual(ref(lock, "nixpkgs"), want_ref) + self.assertEqual(locked_rev(lock, "nixpkgs"), want_rev) + + def test_non_string_rev_never_crashes_the_execution_loop_readers(self): + # The dangerous shape: discovery passes it (rev is not read + # there), so get_input_info/get_locked_rev must not crash + # when the execution loop reaches this input. + node = { + "original": {"type": "github", "owner": "NixOS", "repo": "nixpkgs"}, + "locked": {"type": "github", "rev": 123}, + } + for label, script_dir in COPIES.items(): + with self.subTest(copy=label): + discover, info, ref, locked_rev = self._readers(self._module(script_dir)) + lock = self._lock(node) + self.assertEqual(discover(lock, None), ["nixpkgs"]) + self.assertIsNone(locked_rev(lock, "nixpkgs")) + rev, url, _ = info(lock, "nixpkgs") + self.assertEqual(rev, "unknown") + self.assertEqual(url, "github:NixOS/nixpkgs") + + def test_non_string_ref_is_unclassifiable_in_both_copies(self): + node = { + "original": { + "type": "github", + "owner": "NixOS", + "repo": "nixpkgs", + "ref": 7, + }, + "locked": {"type": "github", "rev": "a" * 40}, + } + for label, script_dir in COPIES.items(): + with self.subTest(copy=label): + discover, info, ref, locked_rev = self._readers(self._module(script_dir)) + lock = self._lock(node) + self.assertEqual(discover(lock, None), []) + self.assertEqual(discover(lock, "master"), []) + self.assertIsNone(ref(lock, "nixpkgs")) + + def test_missing_root_and_missing_nodes_in_both_copies(self): + locks = ( + {"nodes": {"nixpkgs-node": {"original": {}}}}, + {"root": "root", "version": 7}, + {"nodes": None}, + {"nodes": {"root": None}}, + {"nodes": {"root": {"inputs": None}}}, + ["not", "an", "object"], + ) + for label, script_dir in COPIES.items(): + with self.subTest(copy=label): + discover, info, ref, locked_rev = self._readers(self._module(script_dir)) + for lock in locks: + self.assertEqual(discover(lock, None), []) + self.assertEqual( + info(lock, "nixpkgs"), ("unknown", "unknown", "unknown") + ) + self.assertIsNone(ref(lock, "nixpkgs")) + self.assertIsNone(locked_rev(lock, "nixpkgs")) + + def test_pin_input_refuses_a_wrong_shape_node_in_both_copies(self): + for label, script_dir in COPIES.items(): + with self.subTest(copy=label): + mod = self._module(script_dir) + tree = Path(tempfile.mkdtemp(prefix="uni-shape-pin-")) + (tree / "flake.lock").write_text( + json.dumps(self._lock("nixpkgs-node")) + ) + self.assertFalse( + mod["pin_input"]("nixpkgs", tree, {"rev": "a" * 40}) + ) + + +class _Missing: + pass + + +_MISSING = _Missing() + + if __name__ == "__main__": unittest.main() diff --git a/scripts/update-nixpkgs-inputs.py b/scripts/update-nixpkgs-inputs.py index 24b49c2411..7440e025e7 100755 --- a/scripts/update-nixpkgs-inputs.py +++ b/scripts/update-nixpkgs-inputs.py @@ -177,34 +177,68 @@ def load_flake_lock(repo_dir): return json.load(f) +# --- flake.lock shape discipline (#6847) ----------------------------------- +# flake.lock is normally nix-generated, but it is also hand-edited, +# hand-pinned (pin_input below writes it), merged, and occasionally +# truncated or conflicted — exactly the states this repair tool is +# re-run against. Every reader below is therefore a TOTAL function +# over any JSON shape: a non-object node, a null/non-object +# "original"/"locked", a non-string type/ref/rev, and a missing +# node/root are all treated the way discover_inputs has always +# treated a missing node — the input is skipped / reported unknown — +# never a raw AttributeError/TypeError/KeyError. The planning pass +# (discover_inputs over the pristine lock) decides what runs, and +# because the execution loop's readers share the same discipline, a +# malformed lock cannot crash the run after earlier inputs have +# already been updated. + + +def _as_dict(value): + """`value` if it is a JSON object, else an empty dict.""" + return value if isinstance(value, dict) else {} + + +def _as_str(value): + """`value` if it is a string, else None.""" + return value if isinstance(value, str) else None + + +def _lock_nodes(lock_data): + """The lock's "nodes" object ({} for any wrong shape).""" + return _as_dict(_as_dict(lock_data).get("nodes")) + + +def _root_inputs(lock_data): + """The root node's "inputs" object ({} for any wrong shape).""" + return _as_dict(_as_dict(_lock_nodes(lock_data).get("root")).get("inputs")) + + def get_input_info(lock_data, input_name): """Extract rev, source URL, and ref for an input from parsed flake.lock. - Returns: (short_rev, source_url, ref_display) + Returns: (short_rev, source_url, ref_display) — "unknown" fields + for a missing or wrong-shape node, mirroring discover's skip. """ - root_inputs = lock_data["nodes"]["root"]["inputs"] - node_name = root_inputs.get(input_name) - - if not isinstance(node_name, str): + node = get_input_node(lock_data, input_name) + if node is None: return ("unknown", "unknown", "unknown") - node = lock_data["nodes"][node_name] - original = node.get("original", {}) - locked = node.get("locked", {}) + original = _as_dict(node.get("original")) + locked = _as_dict(node.get("locked")) - type_ = (original.get("type") or locked.get("type") or "").lower() - full_rev = locked.get("rev", "unknown") + type_ = (_as_str(original.get("type")) or _as_str(locked.get("type")) or "").lower() + full_rev = _as_str(locked.get("rev")) or "unknown" rev = full_rev[:12] if len(full_rev) > 12 else full_rev - branch = original.get("ref") + branch = _as_str(original.get("ref")) ref_display = branch if branch else "(default)" if type_ == "github": - owner = original.get("owner") or locked.get("owner") or "?" - repo = original.get("repo") or locked.get("repo") or "?" + owner = _as_str(original.get("owner")) or _as_str(locked.get("owner")) or "?" + repo = _as_str(original.get("repo")) or _as_str(locked.get("repo")) or "?" slug = f"{owner}/{repo}" url = f"github:{slug}/{branch}" if branch else f"github:{slug}" elif type_ == "tarball": - url = original.get("url") or locked.get("url") or "?" + url = _as_str(original.get("url")) or _as_str(locked.get("url")) or "?" else: url = f"{type_}:{json.dumps(original or locked)}" @@ -212,28 +246,34 @@ def get_input_info(lock_data, input_name): def get_input_node(lock_data, input_name): - """Return the lock node for a root input name, or None.""" - root_inputs = lock_data.get("nodes", {}).get("root", {}).get("inputs", {}) - node_name = root_inputs.get(input_name) + """Return the lock node for a root input name, or None. + + None covers every "not usable" shape uniformly: input not in the + root inputs, a non-string node reference (follows), a node + missing from "nodes", and a node that is not an object. + """ + node_name = _root_inputs(lock_data).get(input_name) if not isinstance(node_name, str): return None - return lock_data.get("nodes", {}).get(node_name) + return _as_dict(_lock_nodes(lock_data).get(node_name)) or None def get_input_ref(lock_data, input_name): - """Return the input's original.ref (None when unset / not found).""" + """Return the input's original.ref (None when unset / not found / + not a string).""" node = get_input_node(lock_data, input_name) if not node: return None - return node.get("original", {}).get("ref") + return _as_str(_as_dict(node.get("original")).get("ref")) def get_locked_rev(lock_data, input_name): - """Return the input's full locked revision (None when not locked).""" + """Return the input's full locked revision (None when not locked / + not a string).""" node = get_input_node(lock_data, input_name) if not node: return None - return node.get("locked", {}).get("rev") + return _as_str(_as_dict(node.get("locked")).get("rev")) def discover_inputs(lock_data, ref): @@ -248,7 +288,8 @@ def discover_inputs(lock_data, ref): ref="master" → inputs with ref="master" or no ref (default branch) ref= → inputs with that exact ref """ - root_inputs = lock_data.get("nodes", {}).get("root", {}).get("inputs", {}) + root_inputs = _root_inputs(lock_data) + nodes = _lock_nodes(lock_data) results = [] for name, node_ref in root_inputs.items(): @@ -256,14 +297,14 @@ def discover_inputs(lock_data, ref): if not isinstance(node_ref, str): continue - node = lock_data["nodes"].get(node_ref) - if not node: + node = nodes.get(node_ref) + if not isinstance(node, dict): continue - original = node.get("original", {}) + original = _as_dict(node.get("original")) # Match by URL: github:NixOS/nixpkgs - if original.get("type", "").lower() != "github": + if (_as_str(original.get("type")) or "").lower() != "github": continue owner = original.get("owner") if not isinstance(owner, str) or owner.lower() != "nixos": @@ -271,8 +312,12 @@ def discover_inputs(lock_data, ref): if original.get("repo", "") != "nixpkgs": continue - # Filter by ref + # Filter by ref. A ref that is present but not a string is a + # poison entry (#6847): the input cannot be classified, so it + # is skipped in every pass rather than read as no ref. input_ref = original.get("ref") + if input_ref is not None and not isinstance(input_ref, str): + continue if ref is not None: if ref == "master": # master matches explicit "master" or no ref (github default) From 76eedc4730614efae4eb87959cad7f5c91d71ff8 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Wed, 11 Nov 2026 08:25:15 -0600 Subject: [PATCH 2/2] test(scripts): property coverage for the lock-reader totality invariant (#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. --- scripts/tests/test_update_nixpkgs_inputs.py | 100 ++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/scripts/tests/test_update_nixpkgs_inputs.py b/scripts/tests/test_update_nixpkgs_inputs.py index 2810df001b..756d80c24c 100644 --- a/scripts/tests/test_update_nixpkgs_inputs.py +++ b/scripts/tests/test_update_nixpkgs_inputs.py @@ -34,6 +34,7 @@ import json import os +import random import runpy import shutil import subprocess @@ -930,5 +931,104 @@ class _Missing: _MISSING = _Missing() +def _random_json(rng, depth): + """A random JSON-shaped value: scalars, lists, and objects with + keys drawn from the flake.lock vocabulary, so mutations land in + positions the readers actually consult.""" + kind = rng.randrange(6 if depth < 3 else 3) + if kind == 0: + return None + if kind == 1: + return rng.choice([True, False, 0, 1, 7, 123, -1, 2.5]) + if kind == 2: + return rng.choice([ + "", "nixpkgs", "github", "NixOS", "master", "root", + "a" * 40, "nixos-unstable", + ]) + if kind == 3: + return [_random_json(rng, depth + 1) for _ in range(rng.randrange(3))] + keys = ["nodes", "root", "inputs", "original", "locked", "type", + "owner", "repo", "ref", "rev", "nixpkgs", "nixpkgs-node"] + return { + rng.choice(keys): _random_json(rng, depth + 1) + for _ in range(rng.randrange(4)) + } + + +def _mutate(rng, value, depth=0): + """Return `value` with one random subtree replaced by a random + JSON value (or the whole value replaced at the top).""" + if depth > 3 or rng.random() < 0.35: + return _random_json(rng, 1) + if isinstance(value, dict) and value: + key = rng.choice(list(value)) + clone = dict(value) + clone[key] = _mutate(rng, value[key], depth + 1) + return clone + if isinstance(value, list) and value: + idx = rng.randrange(len(value)) + clone = list(value) + clone[idx] = _mutate(rng, value[idx], depth + 1) + return clone + return _random_json(rng, 1) + + +class TestLockReaderTotalityProperty(unittest.TestCase): + """Property coverage for the #6847 totality invariant. + + Oracle: for ANY JSON value in any flake.lock position, every + reader returns a value of its documented type and never raises — + discover_inputs -> list[str] drawn from the root input names; + get_input_info -> a 3-tuple of strings; get_input_ref / + get_locked_rev -> str or None; get_input_node -> dict or None. + Deterministic seeds keep failures reproducible. + """ + + def test_readers_are_total_over_generated_shapes_in_both_copies(self): + rng = random.Random(0x6847) + for label, script_dir in COPIES.items(): + with self.subTest(copy=label): + mod = runpy.run_path(str(script_dir / "update-nixpkgs-inputs.py")) + discover = mod["discover_inputs"] + info = mod["get_input_info"] + get_ref = mod["get_input_ref"] + locked_rev = mod["get_locked_rev"] + get_node = mod["get_input_node"] + for i in range(400): + if i % 2: + lock = _mutate(rng, FLAKE_LOCK) + else: + lock = _random_json(rng, 0) + names = set() + if isinstance(lock, dict): + nodes = lock.get("nodes") + if isinstance(nodes, dict): + root = nodes.get("root") + if isinstance(root, dict): + inputs = root.get("inputs") + if isinstance(inputs, dict): + names = set(inputs) + found = discover(lock, None) + self.assertIsInstance(found, list) + self.assertLessEqual(set(found), names | {"nixpkgs"}) + for name in ("nixpkgs", "candidate", ""): + rev_info = info(lock, name) + self.assertEqual(len(rev_info), 3) + self.assertTrue( + all(isinstance(part, str) for part in rev_info), + f"info({name!r}) = {rev_info!r} for lock {lock!r}", + ) + self.assertTrue( + get_ref(lock, name) is None + or isinstance(get_ref(lock, name), str) + ) + self.assertTrue( + locked_rev(lock, name) is None + or isinstance(locked_rev(lock, name), str) + ) + node = get_node(lock, name) + self.assertTrue(node is None or isinstance(node, dict)) + + if __name__ == "__main__": unittest.main()