test_datamodel.py

tests/test_datamodel.py

gh#351: the tier-4 data-model manifest reader.

test_a_declared_key_is_observed_under_ingots_own_spellings

None test_datamodel.test_a_declared_key_is_observed_under_ingots_own_spellings(Path tmp_path)

The observed join accepts the prefixed and normalized spellings.

tests/test_datamodel.py:1191

Checks

  • assert observed_match(declared, frozenset({declared})), "the bare spelling must match"
  • assert observed_match(declared, frozenset({f"DM_KEY_{declared}"})), ("ingot's generated key_definitions.h emits the DM_KEY_ form" )
  • assert observed_match(declared, frozenset({"B12BATTERYSTATEOFCHARGE"})), ("ingot normalizes by stripping underscores, so a YAML-era name still matches" )
  • assert not observed_match(declared, frozenset({"B12_BATTERY_VOLTAGE"})), ("a different key must not match, or every declared key would read as observed" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-SCHEMA-013measuredtest_a_declared_key_is_observed_under_ingots_own_spellings → observed_match
Source · 32 lines
def test_a_declared_key_is_observed_under_ingots_own_spellings(tmp_path: Path) -> None:
    """gh#42. THE JOIN MUST MATCH THE WAY INGOT MATCHES, or a declared key sits beside the
    identical observed key reading `observed = 0`. `filter.rs` accepts three spellings of one
    key, and its own comment says why the third exists::

        list.names.contains(name)
        || list.names.contains(&format!("DM_KEY_{name}"))
        || normalized (uppercase, underscores STRIPPED) — "so that TOML snake_case IDs
           (e.g. STATE_OF_CHARGE) match YAML-era names (STATEOFCHARGE)"

    Ingot's generated `key_definitions.h` emits the `DM_KEY_` form
    (`DM_KEY_APPLIANCE_IDENTITY_PRODUCT_NAME`, checked against its shipped
    `examples/generated/full/`), while the accessor spelling a codebase actually calls carries
    no prefix — so which spelling the shared-key layer observes depends on which artifact the
    code uses, and an exact-string join is wrong for at least one of them.

    @brief The observed join accepts the prefixed and normalized spellings.
    @version 1
    """
    from clew.datamodel import observed_match

    declared = "B12_BATTERY_STATE_OF_CHARGE"
    assert observed_match(declared, frozenset({declared})), "the bare spelling must match"
    assert observed_match(declared, frozenset({f"DM_KEY_{declared}"})), (
        "ingot's generated key_definitions.h emits the DM_KEY_ form"
    )
    assert observed_match(declared, frozenset({"B12BATTERYSTATEOFCHARGE"})), (
        "ingot normalizes by stripping underscores, so a YAML-era name still matches"
    )
    assert not observed_match(declared, frozenset({"B12_BATTERY_VOLTAGE"})), (
        "a different key must not match, or every declared key would read as observed"
    )

1 more lines, not shown

Activity · 6 steps
lines 1210–1210from clew.datamodel import observed_matchlines 1212–1212declared = "B12_BATTERY_STATE_OF_CHARGE"lines 1213–1213assert observed_match(declared, frozenset({declared})), "the bare spelling must match"lines 1214–1216assert observed_match(declared, frozenset({f"DM_KEY_{declared}"})), ( "ingot's generated key_definitions.h emits the DM_KEY_ form" )lines 1217–1219assert observed_match(declared, frozenset({"B12BATTERYSTATEOFCHARGE"})), ( "ingot normalizes by stripping underscores, so a YAML-era name still matches" )lines 1220–1222assert not observed_match(declared, frozenset({"B12_BATTERY_VOLTAGE"})), ( "a different key must not match, or every declared key would read as observed" )

test_a_declared_manifest_is_admitted_without_a_key_list

None test_datamodel.test_a_declared_manifest_is_admitted_without_a_key_list(Path tmp_path)

A declared manifest contributes its keys with no key list present.

tests/test_datamodel.py:1087

Show on the map →

Called by none

Calls _ingot_manifest

Checks

  • assert [k.define_name for k in found.keys], "the declared manifest's keys must be admitted"
  • assert any("shim_datamodel.toml" in m for m in found.manifests), found.manifests

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-INDEX-005measured
REQ-DDB-PIPE-003measured
REQ-DDB-SCHEMA-013measured
Source · 26 lines
def test_a_declared_manifest_is_admitted_without_a_key_list(tmp_path: Path) -> None:
    """gh#42. THE OPERATOR NAMING THE PATH IS THE EVIDENCE. The key-list gate exists because a
    vendored generator's `examples/` parse identically to a real manifest during a WALK — a
    concern that does not survive somebody stating the path. On the reporting repository the
    model is declared in TOML alone, so every one of its 14 shape-matching documents was
    declined and `dossier` on a real key answered a definitive negative.

    THE DECLARED MANIFEST IS ADMITTED, NOT THE REST. The other documents the walk found stay
    subject to the key-list rule, so declaring one path does not open the repository to a
    vendored generator's examples.

    @brief A declared manifest contributes its keys with no key list present.
    @return None.
    @version 1
    """
    from clew.datamodel import discover

    repo = tmp_path / "repo"
    repo.mkdir()
    manifest = _ingot_manifest(repo)

    found = discover(repo, (), declared=manifest)
    assert [k.define_name for k in found.keys], "the declared manifest's keys must be admitted"
    assert any("shim_datamodel.toml" in m for m in found.manifests), found.manifests

Activity · 7 steps
lines 1102–1102from clew.datamodel import discoverlines 1104–1104repo = tmp_path / "repo"lines 1105–1105repo.mkdir()lines 1106–1106manifest = _ingot_manifest(repo)lines 1108–1108found = discover(repo, (), declared=manifest)lines 1109–1109assert [k.define_name for k in found.keys], "the declared manifest's keys must be admitted"lines 1110–1110assert any("shim_datamodel.toml" in m for m in found.manifests), found.manifests

test_a_declared_manifest_that_cannot_be_read_is_refused

None test_datamodel.test_a_declared_manifest_that_cannot_be_read_is_refused(Path tmp_path)

A declared path that is not a manifest is refused by name.

tests/test_datamodel.py:1113

Show on the map →

Called by none

Calls none

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-INDEX-005measured
REQ-DDB-SCHEMA-013measured
Source · 24 lines
def test_a_declared_manifest_that_cannot_be_read_is_refused(tmp_path: Path) -> None:
    """NEVER SILENTLY SKIPPED, which is what this issue is really about. The reporter stated
    `data_model` through `options`, watched the build log it as tier 1, and then watched the
    stage report `0 key(s) ... from 0 manifest(s) in dialect(s) none` with no line saying the
    declared path had been opened, parsed or rejected. A statement that is accepted and has no
    effect is worse than one that is refused: it reads as agreement.

    @brief A declared path that is not a manifest is refused by name.
    @return None.
    @version 1
    """
    import pytest

    from clew.datamodel import DeclaredModelError, discover

    repo = tmp_path / "repo"
    repo.mkdir()
    plain = repo / "pyproject.toml"
    plain.write_text("[tool.black]\nline-length = 100\n", encoding="utf-8")

    with pytest.raises(DeclaredModelError, match="pyproject.toml"):
        discover(repo, (), declared=plain)

Activity · 8 steps
lines 1124–1124import pytestlines 1126–1126from clew.datamodel import DeclaredModelError, discoverlines 1128–1128repo = tmp_path / "repo"lines 1129–1129repo.mkdir()lines 1130–1130plain = repo / "pyproject.toml"lines 1131–1131plain.write_text("[tool.black]\nline-length = 100\n", encoding="utf-8")lines 1133–1133with pytest.raises(DeclaredModelError, match="pyproject.toml")lines 1134–1134discover(repo, (), declared=plain)

test_a_declared_path_that_is_absent_is_refused

None test_datamodel.test_a_declared_path_that_is_absent_is_refused(Path tmp_path)

A declared path that does not exist is refused.

tests/test_datamodel.py:1137

Show on the map →

Called by none

Calls none

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-INDEX-005measured
REQ-DDB-SCHEMA-013measured
Source · 20 lines
def test_a_declared_path_that_is_absent_is_refused(tmp_path: Path) -> None:
    """THE OTHER WAY A STATEMENT GOES WRONG, and the one a typo produces. Refused with the
    path named, rather than degrading to the discovery answer that would have been given
    anyway — which is precisely the outcome that reads as agreement.

    @brief A declared path that does not exist is refused.
    @return None.
    @version 1
    """
    import pytest

    from clew.datamodel import DeclaredModelError, discover

    repo = tmp_path / "repo"
    repo.mkdir()

    with pytest.raises(DeclaredModelError, match="missing.toml"):
        discover(repo, (), declared=repo / "missing.toml")

Activity · 6 steps
lines 1146–1146import pytestlines 1148–1148from clew.datamodel import DeclaredModelError, discoverlines 1150–1150repo = tmp_path / "repo"lines 1151–1151repo.mkdir()lines 1153–1153with pytest.raises(DeclaredModelError, match="missing.toml")lines 1154–1154discover(repo, (), declared=repo / "missing.toml")

test_a_space_in_a_key_id_becomes_an_underscore

None test_datamodel.test_a_space_in_a_key_id_becomes_an_underscore(Path tmp_path)

A space composes as an underscore, like ingot's generator.

tests/test_datamodel.py:1157

Show on the map →

Called by none

Calls _ingot_keys, define_name

Checks

  • assert names == ["B12_DRIVE_WHEEL_LINEAR_VEL", "B12_DRIVE_WHEEL_LINEAR_VEL"], names
  • assert define_name("B12", "Drive", "wheel linear vel") == "B12_DRIVE_WHEELLINEARVEL"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-SCHEMA-013measuredtest_a_space_in_a_key_id_becomes_an_underscore → define_name
Source · 34 lines
def test_a_space_in_a_key_id_becomes_an_underscore(tmp_path: Path) -> None:
    """gh#42. INGOT'S OWN RULE, read from its source rather than inferred from an example.
    `src/model/filter.rs` composes the bare define name as::

        format!("{}_{}_{}", ns.to_uppercase(),
                class.to_uppercase().replace(' ', "_"),
                key.to_uppercase().replace(' ', "_"))

    A space becomes an underscore. `_DROPPED_FROM_SEGMENT` dropped it instead, so a key id
    written with spaces composed `WHEELLINEARVEL` where the generator emits
    `WHEEL_LINEAR_VEL` — and the declared catalog then named a macro that appears nowhere in
    the source.

    UNDERSCORES ALREADY INSIDE A SEGMENT ARE STILL PRESERVED, which the module docstring
    records as the difference between 104 and 135 of 135 against a real target's key list. This
    adds the space rule; it does not revisit that one.

    @brief A space composes as an underscore, like ingot's generator.
    @version 1
    """
    from clew.datamodel import _ingot_keys

    manifest = [{"id": "Drive", "keys": [{"id": "wheel linear vel"}, {"id": "wheel_linear_vel"}]}]
    names = [key.define_name for key in _ingot_keys(manifest, "B12", "m.toml")]
    assert names == ["B12_DRIVE_WHEEL_LINEAR_VEL", "B12_DRIVE_WHEEL_LINEAR_VEL"], names

    ## AND THE UDM DIALECT IS UNTOUCHED. Its rule drops the space, measured at 135 of 135
    ## against a real target's own key list, so ingot's rule lives at ingot's call site rather
    ## than in the composer both dialects share.
    from clew.datamodel import define_name

    assert define_name("B12", "Drive", "wheel linear vel") == "B12_DRIVE_WHEELLINEARVEL"

Activity · 6 steps
lines 1177–1177from clew.datamodel import _ingot_keyslines 1179–1179manifest = [{"id": "Drive", "keys": [{"id": "wheel linear vel"}, {"id": "wheel_linear_vel"}]}]lines 1180–1180names = [key.define_name for key in _ingot_keys(manifest, "B12", "m.toml")]lines 1181–1181assert names == ["B12_DRIVE_WHEEL_LINEAR_VEL", "B12_DRIVE_WHEEL_LINEAR_VEL"], nameslines 1186–1186from clew.datamodel import define_namelines 1188–1188assert define_name("B12", "Drive", "wheel linear vel") == "B12_DRIVE_WHEELLINEARVEL"

test_a_submodules_manifest_is_excluded

None test_datamodel.test_a_submodules_manifest_is_excluded(Path tmp_path)

A manifest inside a nested dependency tree is excluded by its TREE.

tests/test_datamodel.py:422

Show on the map →

Called by none

Calls _repo, repo_with_submodules

Checks

  • assert {k.define_name for k in found.keys} == set(DEFINES)
  • assert "DEMO_SAMPLE_WIDGET" not in {k.define_name for k in found.keys}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-INDEX-005measured
REQ-DDB-PIPE-003measured
REQ-DDB-SCHEMA-013measured
Source · 26 lines
def test_a_submodules_manifest_is_excluded(tmp_path: Path) -> None:
    """The generator itself is a dependency, and its examples come with it. Excluding them by
    the TREE that owns them rather than by a directory NAME is the rule this repository already
    holds: `vendor/` and `examples/` are conventions, a git tree is a fact.

    The fixture gives the nested tree its OWN key list naming its own keys, so the selection
    gate alone would admit it. Only the tree exclusion can decline it, which is exactly what
    makes this test pin that mechanism rather than the gate.

    MUTATION: in `_candidates`, drop the `any(path.is_relative_to(tree) ...)` filter. This test
    fails — the dependency's key appears.

    @brief A nested dependency tree's manifests are not the repository's model.
    @version 1
    """
    root = repo_with_submodules(tmp_path, "deps/generator")
    _repo(tmp_path, {"widgetbus.toml": MANIFEST}, DEFINES)
    vendored = tmp_path / "deps" / "generator" / "examples"
    vendored.mkdir(parents=True, exist_ok=True)
    (vendored / "demo.toml").write_text(EXAMPLE_MANIFEST, encoding="utf-8")
    (vendored / "its_list.yaml").write_text("---\n- DEMO_SAMPLE_WIDGET\n", encoding="utf-8")
    found = discover(root)
    assert {k.define_name for k in found.keys} == set(DEFINES)
    assert "DEMO_SAMPLE_WIDGET" not in {k.define_name for k in found.keys}

Activity · 9 steps
lines 437–437root = repo_with_submodules(tmp_path, "deps/generator")lines 438–438_repo(tmp_path, {"widgetbus.toml": MANIFEST}, DEFINES)lines 439–439vendored = tmp_path / "deps" / "generator" / "examples"lines 440–440vendored.mkdir(parents=True, exist_ok=True)lines 441–441(vendored / "demo.toml").write_text(EXAMPLE_MANIFEST, encoding="utf-8")lines 442–442(vendored / "its_list.yaml").write_text("---\n- DEMO_SAMPLE_WIDGET\n", encoding="utf-8")lines 443–443found = discover(root)lines 444–444assert {k.define_name for k in found.keys} == set(DEFINES)lines 445–445assert "DEMO_SAMPLE_WIDGET" not in {k.define_name for k in found.keys}

test_an_edited_yaml_document_is_parsed_again

None test_datamodel.test_an_edited_yaml_document_is_parsed_again(Path tmp_path, monkeypatch)

Editing a candidate re-parses it.

tests/test_datamodel.py:1005

Show on the map →

Called by none

Calls none

Checks

  • assert loads["n"] > 0, "an edited document must be read again, not served from the cache"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-INDEX-002measured
REQ-DDB-INDEX-005measured
REQ-DDB-SCHEMA-013measured
Source · 38 lines
def test_an_edited_yaml_document_is_parsed_again(tmp_path: Path, monkeypatch) -> None:
    """THE CONTROL. Content is the key, so an edit must re-derive — a cache that served a
    stale key list would put keys in the catalog that the repository no longer declares, and
    the declared-vs-observed diagnostic reads that as a fact about the code.

    @brief Editing a candidate re-parses it.
    @version 1
    """
    import yaml

    from clew.datamodel import discover
    from clew.indexcache import IndexCache

    repo = tmp_path / "repo"
    (repo / "conf").mkdir(parents=True)
    listed = repo / "conf" / "keys.yaml"
    listed.write_text("- ALPHA_KEY\n", encoding="utf-8")

    cache_path = tmp_path / "clew.db.idxcache"
    cache = IndexCache(cache_path, repo)
    discover(repo, (), cache=cache)
    cache.commit()

    loads = {"n": 0}
    original = yaml.safe_load

    def counting(*args, **kwargs):  # noqa: ANN002, ANN003, ANN202
        loads["n"] += 1
        return original(*args, **kwargs)

    monkeypatch.setattr(yaml, "safe_load", counting)
    listed.write_text("- ALPHA_KEY\n- GAMMA_KEY\n", encoding="utf-8")
    cache = IndexCache(cache_path, repo)
    discover(repo, (), cache=cache)

    assert loads["n"] > 0, "an edited document must be read again, not served from the cache"

Activity · 19 steps
lines 1013–1013import yamllines 1015–1015from clew.datamodel import discoverlines 1016–1016from clew.indexcache import IndexCachelines 1018–1018repo = tmp_path / "repo"lines 1019–1019(repo / "conf").mkdir(parents=True)lines 1020–1020listed = repo / "conf" / "keys.yaml"lines 1021–1021listed.write_text("- ALPHA_KEY\n", encoding="utf-8")lines 1023–1023cache_path = tmp_path / "clew.db.idxcache"lines 1024–1024cache = IndexCache(cache_path, repo)lines 1025–1025discover(repo, (), cache=cache)lines 1026–1026cache.commit()lines 1028–1028loads = {"n": 0}lines 1029–1029original = yaml.safe_loadlines 1031–1033def counting(*args, **kwargs): # noqa: ANN002, ANN003, ANN202 loads["n"] += 1 return original(*args, **kwargs)lines 1035–1035monkeypatch.setattr(yaml, "safe_load", counting)lines 1036–1036listed.write_text("- ALPHA_KEY\n- GAMMA_KEY\n", encoding="utf-8")lines 1037–1037cache = IndexCache(cache_path, repo)lines 1038–1038discover(repo, (), cache=cache)lines 1040–1040assert loads["n"] > 0, "an edited document must be read again, not served from the cache"

test_an_oversized_document_is_refused_unread

None test_datamodel.test_an_oversized_document_is_refused_unread(Path tmp_path)

An oversized document is refused UNREAD, and the refusal is counted.

tests/test_datamodel.py:855

Show on the map →

Called by none

Calls _repo

Checks

  • assert big.stat().st_size > 2 * 1024 * 1024
  • assert found.oversized == 1
  • assert found.as_meta()["documents_oversized"] == "1"
  • assert "PADDING_KEY_0" not in found.listed
  • assert {k.define_name for k in found.keys} == set(DEFINES)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-005measured
REQ-DDB-PIPE-003measured
REQ-DDB-SCHEMA-013measured
Source · 29 lines
def test_an_oversized_document_is_refused_unread(tmp_path: Path) -> None:
    """MEASURED CAUSE, not a hypothetical. One control target vendors a YAML parser's benchmark
    corpus, including a 10.7 MB deliberately-pathological document, and the first version of
    this stage did not finish walking it in twenty-five minutes at full CPU. Recognising
    documents by SHAPE means parsing documents nobody declared, so the parse needs a bound
    that content cannot defeat.

    The fixture writes an oversized document that WOULD be a valid key list at a legal size, so
    the ceiling is what declines it and not the shape gate — and the real manifest beside it
    still lands, which is what stops the ceiling from being a way to disable the layer.

    MUTATION: raise `_MAX_DOCUMENT_BYTES` to `2 * 1024 * 1024 * 1024`. This test fails on the
    oversized count, and the key list is read.

    @brief A document over the ceiling is counted, not parsed.
    @version 1
    """
    root = _repo(tmp_path, {"widgetbus.toml": MANIFEST}, DEFINES)
    big = root / "conf" / "datamodel" / "huge.yaml"
    filler = "".join(f"- PADDING_KEY_{n}\n" for n in range(200_000))
    big.write_text("---\n" + filler, encoding="utf-8")
    assert big.stat().st_size > 2 * 1024 * 1024
    found = discover(root)
    assert found.oversized == 1
    assert found.as_meta()["documents_oversized"] == "1"
    assert "PADDING_KEY_0" not in found.listed
    assert {k.define_name for k in found.keys} == set(DEFINES)

Activity · 10 steps
lines 872–872root = _repo(tmp_path, {"widgetbus.toml": MANIFEST}, DEFINES)lines 873–873big = root / "conf" / "datamodel" / "huge.yaml"lines 874–874filler = "".join(f"- PADDING_KEY_{n}\n" for n in range(200_000))lines 875–875big.write_text("---\n" + filler, encoding="utf-8")lines 876–876assert big.stat().st_size > 2 * 1024 * 1024lines 877–877found = discover(root)lines 878–878assert found.oversized == 1lines 879–879assert found.as_meta()["documents_oversized"] == "1"lines 880–880assert "PADDING_KEY_0" not in found.listedlines 881–881assert {k.define_name for k in found.keys} == set(DEFINES)

test_an_unchanged_yaml_document_is_parsed_once_across_builds

None test_datamodel.test_an_unchanged_yaml_document_is_parsed_once_across_builds(Path tmp_path, monkeypatch)

A YAML candidate is parsed once, then served from the cache.

tests/test_datamodel.py:942

Show on the map →

Called by none

Calls none

Checks

  • assert after_cold > 0, "the cold pass must actually parse, or this asserts nothing"
  • assert loads["n"] == after_cold, (f"an unchanged document must not be re-parsed; {loads['n'] - after_cold} extra load(s)" )
  • assert second == first, "the cached discovery must equal the parsed one"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-INDEX-002measured
REQ-DDB-INDEX-005measured
REQ-DDB-SCHEMA-013measured
Source · 63 lines
def test_an_unchanged_yaml_document_is_parsed_once_across_builds(
    tmp_path: Path, monkeypatch
) -> None:
    """gh#34. `data_model_keys` WAS 1,304 ms OF A 6,634 ms REFRESH — 20%, the largest single
    stage — on a repository that declares NO data model at all. I assumed the whole-tree walk,
    the way gh#36's walk had been the cost. Profiling said otherwise:

        _candidates (the walk)      237 ms   3 toml, 45 yaml
        yaml.safe_load            2,688 ms   90 documents

    Ninety loads for forty-five files, because the shape gate reads each document and the
    selection pass reads the survivors again. Neither depends on anything but the file's
    bytes, so on a refresh where nothing changed, all of it is re-derivation — and the answer
    is the same "no data model" it was last build.

    THE WALK IS STILL NOT THE COST, which is worth recording because the previous fix in this
    area was a walk and the resemblance is misleading. `_candidates` already prunes during
    descent and honours the build's excludes; a comment above it records a control target
    where an unbounded version did not finish in twenty-five minutes.

    ASSERTED ON PARSE COUNT rather than time, for the same reason as the self-edge guard's
    test: a document that was not parsed is the mechanism, while a stopwatch measures the
    machine.

    @brief A YAML candidate is parsed once, then served from the cache.
    @version 1
    """
    import yaml

    from clew.datamodel import discover
    from clew.indexcache import IndexCache

    repo = tmp_path / "repo"
    (repo / "conf").mkdir(parents=True)
    (repo / "conf" / "keys.yaml").write_text("- ALPHA_KEY\n- BETA_KEY\n", encoding="utf-8")
    (repo / "conf" / "notes.yaml").write_text("title: not a key list\n", encoding="utf-8")

    loads = {"n": 0}
    original = yaml.safe_load

    def counting(*args, **kwargs):  # noqa: ANN002, ANN003, ANN202
        loads["n"] += 1
        return original(*args, **kwargs)

    monkeypatch.setattr(yaml, "safe_load", counting)

    cache_path = tmp_path / "clew.db.idxcache"
    cache = IndexCache(cache_path, repo)
    first = discover(repo, (), cache=cache)
    cache.commit()
    after_cold = loads["n"]

    cache = IndexCache(cache_path, repo)
    second = discover(repo, (), cache=cache)
    cache.commit()

    assert after_cold > 0, "the cold pass must actually parse, or this asserts nothing"
    assert loads["n"] == after_cold, (
        f"an unchanged document must not be re-parsed; {loads['n'] - after_cold} extra load(s)"
    )
    assert second == first, "the cached discovery must equal the parsed one"

Activity · 22 steps
lines 969–969import yamllines 971–971from clew.datamodel import discoverlines 972–972from clew.indexcache import IndexCachelines 974–974repo = tmp_path / "repo"lines 975–975(repo / "conf").mkdir(parents=True)lines 976–976(repo / "conf" / "keys.yaml").write_text("- ALPHA_KEY\n- BETA_KEY\n", encoding="utf-8")lines 977–977(repo / "conf" / "notes.yaml").write_text("title: not a key list\n", encoding="utf-8")lines 979–979loads = {"n": 0}lines 980–980original = yaml.safe_loadlines 982–984def counting(*args, **kwargs): # noqa: ANN002, ANN003, ANN202 loads["n"] += 1 return original(*args, **kwargs)lines 986–986monkeypatch.setattr(yaml, "safe_load", counting)lines 988–988cache_path = tmp_path / "clew.db.idxcache"lines 989–989cache = IndexCache(cache_path, repo)lines 990–990first = discover(repo, (), cache=cache)lines 991–991cache.commit()lines 992–992after_cold = loads["n"]lines 994–994cache = IndexCache(cache_path, repo)lines 995–995second = discover(repo, (), cache=cache)lines 996–996cache.commit()lines 998–998assert after_cold > 0, "the cold pass must actually parse, or this asserts nothing"lines 999–1001assert loads["n"] == after_cold, ( f"an unchanged document must not be re-parsed; {loads['n'] - after_cold} extra load(s)" )lines 1002–1002assert second == first, "the cached discovery must equal the parsed one"

test_both_dialects_coexist_under_one_key_list_gate

None test_datamodel.test_both_dialects_coexist_under_one_key_list_gate(Path tmp_path)

The selection gate and the composition rule are dialect-blind.

tests/test_datamodel.py:598

Show on the map →

Called by none

Calls _repo

Checks

  • assert found.dialects() == (DIALECT_INGOT, DIALECT_UDM)
  • assert meta["dialect"] == "ingot+udm"
  • assert meta["keys_by_dialect"] == "ingot=3,udm=3"
  • assert meta["keys"] == "6"
  • assert meta["keys_with_unresolved_fields"] == "2"
  • assert len(found.manifests) == 2
  • assert meta["unresolved_note"].startswith("udm declares")
  • assert DIALECT_INGOT not in meta["unresolved_note"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-005measured
REQ-DDB-PIPE-003measured
REQ-DDB-SCHEMA-013measured
Source · 40 lines
def test_both_dialects_coexist_under_one_key_list_gate(tmp_path: Path) -> None:
    """ONE REPOSITORY, TWO GENERATORS is a real state — an app pulls one model in while
    migrating off another — so the counts have to stay attributable. `dialect` alone stops
    being informative the moment both appear, which is why `keys_by_dialect` is asserted here
    rather than trusted.

    The key list names keys from BOTH manifests, so a gate that only ever consulted the ingot
    half would admit the UDM manifest anyway; what pins the gate for the new dialect is
    `test_udm_manifest_with_no_key_list_is_declined` below.

    THE NOTE MUST NAME ONLY THE DIALECT THAT LEFT SOMETHING UNRESOLVED. With both present, a
    note built from every dialect would put "ingot" into a sentence about per-variant defaults
    ingot does not have — authoritative-sounding prose that is wrong about half its subject, in
    the one field of this payload a consumer reads as an explanation rather than a count.

    MUTATION 1: in `_parsed_manifests`, drop the `udm_paths` loop. This test fails — `dialect`
    is "ingot" and the UDM keys are gone.
    MUTATION 2: in `_unresolved_note`, build `owners` from `self.dialects()`. This test fails on
    the note, and ONLY here — the single-dialect note test cannot see it.

    @brief Both dialects are selected and separately counted.
    @version 2
    """
    root = _repo(
        tmp_path,
        {"widgetbus.toml": MANIFEST, "widgetbus_001.yaml": UDM_MANIFEST},
        DEFINES + UDM_DEFINES,
    )
    found = discover(root)
    assert found.dialects() == (DIALECT_INGOT, DIALECT_UDM)
    meta = found.as_meta()
    assert meta["dialect"] == "ingot+udm"
    assert meta["keys_by_dialect"] == "ingot=3,udm=3"
    assert meta["keys"] == "6"
    assert meta["keys_with_unresolved_fields"] == "2"
    assert len(found.manifests) == 2
    assert meta["unresolved_note"].startswith("udm declares")
    assert DIALECT_INGOT not in meta["unresolved_note"]

Activity · 11 steps
lines 621–625root = _repo( tmp_path, {"widgetbus.toml": MANIFEST, "widgetbus_001.yaml": UDM_MANIFEST}, DEFINES + UDM_DEFINES, )lines 626–626found = discover(root)lines 627–627assert found.dialects() == (DIALECT_INGOT, DIALECT_UDM)lines 628–628meta = found.as_meta()lines 629–629assert meta["dialect"] == "ingot+udm"lines 630–630assert meta["keys_by_dialect"] == "ingot=3,udm=3"lines 631–631assert meta["keys"] == "6"lines 632–632assert meta["keys_with_unresolved_fields"] == "2"lines 633–633assert len(found.manifests) == 2lines 634–634assert meta["unresolved_note"].startswith("udm declares")lines 635–635assert DIALECT_INGOT not in meta["unresolved_note"]

test_build_excludes_are_honoured

None test_datamodel.test_build_excludes_are_honoured(Path tmp_path)

A subtree the BUILD excluded is not walked for candidates.

tests/test_datamodel.py:888

Show on the map →

Called by none

Calls _repo

Checks

  • assert "DEMO_SAMPLE_WIDGET" in {k.define_name for k in unbounded.keys}
  • assert {k.define_name for k in bounded.keys} == set(DEFINES)
  • assert "DEMO_SAMPLE_WIDGET" not in bounded.listed

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-INDEX-005measured
REQ-DDB-PIPE-003measured
REQ-DDB-SCHEMA-013measured
Source · 30 lines
def test_build_excludes_are_honoured(tmp_path: Path) -> None:
    """A CORRECTNESS REQUIREMENT, not a speed one. A generated data model's OUTPUT lands in a
    build directory, and this layer's whole premise is that it reads the generator's SOURCES —
    an index that is a function of whether somebody ran a build would make two indexes of one
    commit disagree about which keys exist. The build already excludes its own output, so
    honouring that list is what makes the guarantee structural rather than a naming convention.

    The fixture puts a manifest AND a key list naming its keys inside the excluded tree, so the
    selection gate alone would admit it: only the exclusion can decline it.

    MUTATION: in `_candidates`, drop `foreign |= set(excludes)`. This test fails — the generated
    manifest's key appears.

    @brief An excluded subtree contributes no candidates.
    @version 1
    """
    _repo(tmp_path, {"widgetbus.toml": MANIFEST}, DEFINES)
    generated = tmp_path / "build" / "gen"
    generated.mkdir(parents=True)
    (generated / "dm_full.toml").write_text(EXAMPLE_MANIFEST, encoding="utf-8")
    (generated / "gen_list.yaml").write_text("---\n- DEMO_SAMPLE_WIDGET\n", encoding="utf-8")

    unbounded = discover(tmp_path)
    assert "DEMO_SAMPLE_WIDGET" in {k.define_name for k in unbounded.keys}

    bounded = discover(tmp_path, (tmp_path / "build",))
    assert {k.define_name for k in bounded.keys} == set(DEFINES)
    assert "DEMO_SAMPLE_WIDGET" not in bounded.listed

Activity · 10 steps
lines 904–904_repo(tmp_path, {"widgetbus.toml": MANIFEST}, DEFINES)lines 905–905generated = tmp_path / "build" / "gen"lines 906–906generated.mkdir(parents=True)lines 907–907(generated / "dm_full.toml").write_text(EXAMPLE_MANIFEST, encoding="utf-8")lines 908–908(generated / "gen_list.yaml").write_text("---\n- DEMO_SAMPLE_WIDGET\n", encoding="utf-8")lines 910–910unbounded = discover(tmp_path)lines 911–911assert "DEMO_SAMPLE_WIDGET" in {k.define_name for k in unbounded.keys}lines 913–913bounded = discover(tmp_path, (tmp_path / "build",))lines 914–914assert {k.define_name for k in bounded.keys} == set(DEFINES)lines 915–915assert "DEMO_SAMPLE_WIDGET" not in bounded.listed

test_define_name_drops_a_space

None test_datamodel.test_define_name_drops_a_space()

A space inside a key name is DROPPED, not turned into an underscore.

tests/test_datamodel.py:217

Show on the map →

Called by none

Calls define_name

Checks

  • assert define_name("widgetbus", "telemetry", "Sample of Rate") == ("WIDGETBUS_TELEMETRY_SAMPLEOFRATE" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-SCHEMA-013measuredtest_define_name_drops_a_space → define_name
Source · 17 lines
def test_define_name_drops_a_space() -> None:
    """The other discriminating character. The unread dialect writes key names with spaces
    ("Sample of Rate"), and a repository's key list spells that key with the spaces GONE
    rather than underscored — so a rule that mapped every separator to `_` would compose a
    name no accessor carries and every key would read as never observed.

    MUTATION: change `_DROPPED_FROM_SEGMENT` to `[^0-9A-Za-z_ ]+`, keeping spaces. This test
    fails with a space in the composed name.

    @brief Spaces are removed rather than underscored.
    @version 1
    """
    assert define_name("widgetbus", "telemetry", "Sample of Rate") == (
        "WIDGETBUS_TELEMETRY_SAMPLEOFRATE"
    )

Activity · 1 steps
lines 229–231assert define_name("widgetbus", "telemetry", "Sample of Rate") == ( "WIDGETBUS_TELEMETRY_SAMPLEOFRATE" )

test_define_name_preserves_an_underscore

None test_datamodel.test_define_name_preserves_an_underscore()

An underscore inside a segment SURVIVES composition.

tests/test_datamodel.py:197

Show on the map →

Called by none

Calls define_name

Checks

  • assert define_name("alerts_group", "telemetry", "Is_Charging") == ("ALERTS_GROUP_TELEMETRY_IS_CHARGING" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-SCHEMA-013measuredtest_define_name_preserves_an_underscore → define_name
Source · 17 lines
def test_define_name_preserves_an_underscore() -> None:
    """THE MEASURED RULE, and the one an obvious reading gets wrong. Stripping every
    non-alphanumeric character scored 104 of 135 against a real target's own key list; keeping
    underscores scored 135. Both the segment and the separator underscores appear here, so a
    rule that dropped either is caught.

    MUTATION: add `_` to `_DROPPED_FROM_SEGMENT`'s character class in `datamodel.py`. This
    test fails, reporting `ALERTS_GROUP_TELEMETRY_ISCHARGING`.

    @brief Underscores inside a manifest segment survive.
    @version 1
    """
    assert define_name("alerts_group", "telemetry", "Is_Charging") == (
        "ALERTS_GROUP_TELEMETRY_IS_CHARGING"
    )

Activity · 1 steps
lines 209–211assert define_name("alerts_group", "telemetry", "Is_Charging") == ( "ALERTS_GROUP_TELEMETRY_IS_CHARGING" )

test_discovery_still_declines_a_manifest_no_key_list_names

None test_datamodel.test_discovery_still_declines_a_manifest_no_key_list_names(Path tmp_path)

An undeclared, unlisted manifest contributes nothing.

tests/test_datamodel.py:1067

Show on the map →

Called by none

Calls _ingot_manifest

Checks

  • assert found.keys == (), "discovery must not admit a manifest no key list names"
  • assert found.manifests_unlisted == 1, "and must say so by count"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-INDEX-005measured
REQ-DDB-PIPE-003measured
REQ-DDB-SCHEMA-013measured
Source · 20 lines
def test_discovery_still_declines_a_manifest_no_key_list_names(tmp_path: Path) -> None:
    """THE RULE THAT MUST NOT MOVE. A generator ships example manifests that parse identically
    to a real one, so during DISCOVERY a shape match is not evidence — the repository's own key
    list is. `manifests_unlisted` counts what that rule declined, and this pins it.

    @brief An undeclared, unlisted manifest contributes nothing.
    @return None.
    @version 1
    """
    from clew.datamodel import discover

    repo = tmp_path / "repo"
    repo.mkdir()
    _ingot_manifest(repo)

    found = discover(repo, ())
    assert found.keys == (), "discovery must not admit a manifest no key list names"
    assert found.manifests_unlisted == 1, "and must say so by count"

Activity · 7 steps
lines 1076–1076from clew.datamodel import discoverlines 1078–1078repo = tmp_path / "repo"lines 1079–1079repo.mkdir()lines 1080–1080_ingot_manifest(repo)lines 1082–1082found = discover(repo, ())lines 1083–1083assert found.keys == (), "discovery must not admit a manifest no key list names"lines 1084–1084assert found.manifests_unlisted == 1, "and must say so by count"

test_false_default_is_not_zero

None test_datamodel.test_false_default_is_not_zero(Path tmp_path)

A boolean default stays a boolean, not a zero.

tests/test_datamodel.py:293

Checks

  • assert keys is not None
  • assert by_id["Is_Charging"] == "False"
  • assert by_id["Threshold"] == "0"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_false_default_is_not_zero → parse_ingot_manifest → rel_key
REQ-DDB-SCHEMA-013measuredtest_false_default_is_not_zero → parse_ingot_manifest
Source · 19 lines
def test_false_default_is_not_zero(tmp_path: Path) -> None:
    """A boolean default and a numeric zero default are different facts about a key, and
    `str(False)` is not `"0"`. The `Threshold` key's default IS `0`, so the two appear in one
    fixture and a coercion that flattened them together is visible.

    MUTATION: in `_scalar`, return `str(int(value))` for a bool. This test fails.

    @brief False and 0 are distinguishable defaults.
    @version 1
    """
    path = tmp_path / "widgetbus.toml"
    path.write_text(MANIFEST, encoding="utf-8")
    keys = parse_ingot_manifest(path, tmp_path)
    assert keys is not None
    by_id = {k.key_id: k.default_value for k in keys}
    assert by_id["Is_Charging"] == "False"
    assert by_id["Threshold"] == "0"

Activity · 7 steps
lines 303–303path = tmp_path / "widgetbus.toml"lines 304–304path.write_text(MANIFEST, encoding="utf-8")lines 305–305keys = parse_ingot_manifest(path, tmp_path)lines 306–306assert keys is not Nonelines 307–307by_id = {k.key_id: k.default_value for k in keys}lines 308–308assert by_id["Is_Charging"] == "False"lines 309–309assert by_id["Threshold"] == "0"

test_key_list_recognition

None test_datamodel.test_key_list_recognition(Path tmp_path, str body, int|None expected)

A key list is recognised by shape; a path list and a word list are not.

tests/test_datamodel.py:326

Checks

  • assert (None if names is None else len(names)) == expected

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-SCHEMA-013measuredtest_key_list_recognition → read_key_list
REQ-DDB-WIKI-054inferredtest_key_list_recognition → read_key_list → all
Source · 18 lines
def test_key_list_recognition(tmp_path: Path, body: str, expected: int | None) -> None:
    """THE LOOSENING THAT WOULD BE INVISIBLE. A relaxed entry pattern still recognises the
    real key list, so the positive case cannot detect it — what detects it is the manifest-set
    selection file (a sequence of PATHS, which the other generator ships) being mistaken for a
    key list, at which point every shape-matching manifest in the tree is vouched for by names
    that are really file paths.

    MUTATION: relax `_LIST_ENTRY` to `^.+$`. The path-list and word-list cases fail.

    @brief Only a flat sequence of define-name tokens is a key list.
    @version 1
    """
    path = tmp_path / "candidate.yaml"
    path.write_text(body, encoding="utf-8")
    names = read_key_list(path)
    assert (None if names is None else len(names)) == expected

Activity · 4 steps
lines 338–338path = tmp_path / "candidate.yaml"lines 339–339path.write_text(body, encoding="utf-8")lines 340–340names = read_key_list(path)lines 341–341assert (None if names is None else len(names)) == expected

test_key_lists_with_no_manifest_warns_about_the_tree_boundary

None test_datamodel.test_key_lists_with_no_manifest_warns_about_the_tree_boundary(Path tmp_path, pytest.LogCaptureFixture caplog)

Key lists with no selected manifest is a NAMED state, not a silent zero.

tests/test_datamodel.py:755

Show on the map →

Called by none

Calls _repo, import_data_model_keys, repo_with_submodules

Checks

  • assert found.keys == ()
  • assert found.manifests_unlisted == 0, "premise: the manifest is excluded, not declined"
  • assert found.list_count == 1
  • assert [r for r in caplog.records if "NESTED GIT TREE" in r.getMessage()]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-005measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_key_lists_with_no_manifest_warns_about_the_tree_boundary → import_data_model_keys
Source · 33 lines
def test_key_lists_with_no_manifest_warns_about_the_tree_boundary(
    tmp_path: Path,
    caplog: pytest.LogCaptureFixture,
) -> None:
    """MEASURED ON A REAL TARGET, which is why this exists at all. A repository can declare its
    model in a SHARED SUBMODULE and keep the key list that selects from it in the app; nested
    git trees are excluded, so the manifests and the evidence that vouches for them land on
    opposite sides of that boundary. The result is a catalog of zero keys with
    `manifests_unlisted` ALSO zero — byte-identical to a repository with no data model, which
    is the silence this module's every other count exists to break.

    The fixture reproduces exactly that split: the manifest and its own key list are inside the
    nested tree, and the app has a key list of its own naming keys nothing declares.

    MUTATION: drop the `if found.list_count and not found.manifests` branch in `_log`. This
    test fails — the two states become indistinguishable again.

    @brief The lists-without-manifests state is warned about.
    @version 1
    """
    root = repo_with_submodules(tmp_path, "deps/model")
    _repo(tmp_path, {}, DEFINES)
    vendored = tmp_path / "deps" / "model"
    (vendored / "widgetbus.toml").write_text(MANIFEST, encoding="utf-8")

    with caplog.at_level("WARNING"):
        found = import_data_model_keys(tmp_path / "clew.db", root)
    assert found.keys == ()
    assert found.manifests_unlisted == 0, "premise: the manifest is excluded, not declined"
    assert found.list_count == 1
    assert [r for r in caplog.records if "NESTED GIT TREE" in r.getMessage()]

Activity · 10 steps
lines 775–775root = repo_with_submodules(tmp_path, "deps/model")lines 776–776_repo(tmp_path, {}, DEFINES)lines 777–777vendored = tmp_path / "deps" / "model"lines 778–778(vendored / "widgetbus.toml").write_text(MANIFEST, encoding="utf-8")lines 780–780with caplog.at_level("WARNING")lines 781–781found = import_data_model_keys(tmp_path / "clew.db", root)lines 782–782assert found.keys == ()lines 783–783assert found.manifests_unlisted == 0, "premise: the manifest is excluded, not declined"lines 784–784assert found.list_count == 1lines 785–785assert [r for r in caplog.records if "NESTED GIT TREE" in r.getMessage()]

test_manifest_is_parsed

None test_datamodel.test_manifest_is_parsed(Path tmp_path)

A manifest parses to its declared keys, with metadata and a relative path.

tests/test_datamodel.py:259

Checks

  • assert keys is not None
  • assert tuple(k.define_name for k in keys) == DEFINES
  • assert (charge.value_type, charge.default_value, charge.enum_name) == ("bool", "False", "widget_mode", )
  • assert charge.helpers is True
  • assert charge.dialect == DIALECT_INGOT
  • assert not Path(charge.manifest).is_absolute()
  • assert charge.manifest == "widgetbus.toml"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_manifest_is_parsed → parse_ingot_manifest → rel_key
REQ-DDB-SCHEMA-013measuredtest_manifest_is_parsed → parse_ingot_manifest
Source · 31 lines
def test_manifest_is_parsed(tmp_path: Path) -> None:
    """Asserts the per-key metadata as well as the names, because the metadata IS the second
    of the three gains and nothing else in the index carries a key's type or default.

    The path assertion is not cosmetic: anything reachable over MCP is published, and an
    absolute manifest path here would reintroduce the machine-layout disclosure that forced an
    earlier build-version bump.

    MUTATION: in `parse_ingot_manifest`, replace `rel_key(path, repo_root)` with `str(path)`.
    The relative-path assertion fails.

    @brief A manifest's keys and metadata are read.
    @version 1
    """
    path = tmp_path / "widgetbus.toml"
    path.write_text(MANIFEST, encoding="utf-8")
    keys = parse_ingot_manifest(path, tmp_path)
    assert keys is not None
    assert tuple(k.define_name for k in keys) == DEFINES
    charge = next(k for k in keys if k.key_id == "Is_Charging")
    assert (charge.value_type, charge.default_value, charge.enum_name) == (
        "bool",
        "False",
        "widget_mode",
    )
    assert charge.helpers is True
    assert charge.dialect == DIALECT_INGOT
    assert not Path(charge.manifest).is_absolute()
    assert charge.manifest == "widgetbus.toml"

Activity · 11 steps
lines 273–273path = tmp_path / "widgetbus.toml"lines 274–274path.write_text(MANIFEST, encoding="utf-8")lines 275–275keys = parse_ingot_manifest(path, tmp_path)lines 276–276assert keys is not Nonelines 277–277assert tuple(k.define_name for k in keys) == DEFINESlines 278–278charge = next(k for k in keys if k.key_id == "Is_Charging")lines 279–283assert (charge.value_type, charge.default_value, charge.enum_name) == ( "bool", "False", "widget_mode", )lines 284–284assert charge.helpers is Truelines 285–285assert charge.dialect == DIALECT_INGOTlines 286–286assert not Path(charge.manifest).is_absolute()lines 287–287assert charge.manifest == "widgetbus.toml"

test_missing_shared_key_table_is_tolerated

None test_datamodel.test_missing_shared_key_table_is_tolerated(Path tmp_path)

The stage tolerates a database with no shared-key table at all.

tests/test_datamodel.py:827

Checks

  • assert len(found.keys) == 3
  • assert (conn.execute("SELECT COUNT(*) FROM data_model_keys WHERE observed=1").fetchone()[0] == 0 )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-005measured
REQ-DDB-PIPE-003measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_missing_shared_key_table_is_tolerated → import_data_model_keys
Source · 24 lines
def test_missing_shared_key_table_is_tolerated(tmp_path: Path) -> None:
    """`shared_key_edges` is created by whichever of its two stages runs first, and a target
    with no accessor convention legitimately has neither. Raising here would turn "this
    repository has no dataflow" into a build failure.

    MUTATION: remove the `except sqlite3.OperationalError` in `_observed_keys`. This test
    fails with an OperationalError.

    @brief No shared-key table is not an error.
    @version 1
    """
    root = _repo(tmp_path, {"widgetbus.toml": MANIFEST}, DEFINES)
    db = tmp_path / "clew.db"
    found = import_data_model_keys(db, root)
    assert len(found.keys) == 3
    conn = sqlite3.connect(str(db))
    try:
        assert (
            conn.execute("SELECT COUNT(*) FROM data_model_keys WHERE observed=1").fetchone()[0] == 0
        )
    finally:
        conn.close()

Activity · 7 steps
lines 838–838root = _repo(tmp_path, {"widgetbus.toml": MANIFEST}, DEFINES)lines 839–839db = tmp_path / "clew.db"lines 840–840found = import_data_model_keys(db, root)lines 841–841assert len(found.keys) == 3lines 842–842conn = sqlite3.connect(str(db))lines 843–843trylines 844–846assert ( conn.execute("SELECT COUNT(*) FROM data_model_keys WHERE observed=1").fetchone()[0] == 0 )

test_neither_parser_reads_the_other_dialect

None test_datamodel.test_neither_parser_reads_the_other_dialect(Path tmp_path)

The ingot parser DECLINES a UDM manifest, and vice versa.

tests/test_datamodel.py:481

Checks

  • assert parse_udm_manifest(ingot, tmp_path) is None
  • assert parse_ingot_manifest(udm, tmp_path) is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003inferredtest_neither_parser_reads_the_other_dialect → parse_ingot_manifest → rel_key
REQ-DDB-SCHEMA-013measuredtest_neither_parser_reads_the_other_dialect → parse_ingot_manifest
Source · 27 lines
def test_neither_parser_reads_the_other_dialect(tmp_path: Path) -> None:
    """THE NEGATIVE HALF, and it is what stops the two parsers becoming one by accident. Each
    positive test above passes with a parser that accepted anything shaped roughly right; only
    a refusal pins that the shape gate discriminates. It also pins the file-extension split not
    being what does the work — the ingot parser is handed the YAML document directly.

    WHAT MUTATION CONTROLS SAID THIS TEST ACTUALLY GUARDS, which is less than it looks: in
    BOTH directions the refusal comes from the document FORMAT, not from either shape gate.
    Deleting the `"namespace" not in doc` conjunct changes nothing here, because
    `yaml.safe_load` of a TOML document yields a string that `isinstance(doc, dict)` already
    refuses; deleting `_is_ingot_class_list` changes nothing either, because `toml.loads` of a
    YAML document raises. So this test pins the CROSS-DIALECT refusal and the two shape gates
    are pinned by the two tests that can see them —
    `test_udm_manifest_without_a_namespace_is_declined` and `test_ordinary_toml_is_declined`,
    both written or re-aimed because a control showed nothing else covered them.

    @brief Each parser refuses the other dialect's document.
    @version 2
    """
    ingot = tmp_path / "widgetbus.toml"
    ingot.write_text(MANIFEST, encoding="utf-8")
    udm = tmp_path / "widgetbus_001.yaml"
    udm.write_text(UDM_MANIFEST, encoding="utf-8")
    assert parse_udm_manifest(ingot, tmp_path) is None
    assert parse_ingot_manifest(udm, tmp_path) is None

Activity · 6 steps
lines 500–500ingot = tmp_path / "widgetbus.toml"lines 501–501ingot.write_text(MANIFEST, encoding="utf-8")lines 502–502udm = tmp_path / "widgetbus_001.yaml"lines 503–503udm.write_text(UDM_MANIFEST, encoding="utf-8")lines 504–504assert parse_udm_manifest(ingot, tmp_path) is Nonelines 505–505assert parse_ingot_manifest(udm, tmp_path) is None

test_no_data_model_is_a_correct_negative

None test_datamodel.test_no_data_model_is_a_correct_negative(Path tmp_path)

A repository with no data model is a correct negative, not an error.

tests/test_datamodel.py:401

Show on the map →

Called by none

Calls none

Checks

  • assert found.keys == ()
  • assert found.manifests_unlisted == 0
  • assert found.as_meta()["dialect"] == ""
  • assert found.as_meta()["keys"] == "0"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-005measured
REQ-DDB-SCHEMA-013measured
Source · 17 lines
def test_no_data_model_is_a_correct_negative(tmp_path: Path) -> None:
    """Most repositories have no generated data model, and the two public control targets are
    both in this state. Raising here would turn the stage into a gate on a feature nobody
    asked for — and the recorded zeros are what make the answer a measurement.

    @brief No data model yields an empty set and no exception.
    @version 1
    """
    (tmp_path / "src").mkdir()
    (tmp_path / "src" / "main.c").write_text("int main(void){return 0;}\n", encoding="utf-8")
    found = discover(tmp_path)
    assert found.keys == ()
    assert found.manifests_unlisted == 0
    assert found.as_meta()["dialect"] == ""
    assert found.as_meta()["keys"] == "0"

Activity · 7 steps
lines 409–409(tmp_path / "src").mkdir()lines 410–410(tmp_path / "src" / "main.c").write_text("int main(void){return 0;}\n", encoding="utf-8")lines 411–411found = discover(tmp_path)lines 412–412assert found.keys == ()lines 413–413assert found.manifests_unlisted == 0lines 414–414assert found.as_meta()["dialect"] == ""lines 415–415assert found.as_meta()["keys"] == "0"

test_no_key_list_selects_nothing_and_says_so

None test_datamodel.test_no_key_list_selects_nothing_and_says_so(Path tmp_path)

With no key list at all, nothing is selected and the refusal is counted.

tests/test_datamodel.py:376

Show on the map →

Called by none

Calls _repo

Checks

  • assert found.keys == ()
  • assert found.manifests_unlisted == 1
  • assert found.list_count == 0
  • assert found.as_meta()["manifests_unlisted"] == "1"
  • assert found.as_meta()["keys"] == "0"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-005measured
REQ-DDB-PIPE-003measured
REQ-DDB-SCHEMA-013measured
Source · 21 lines
def test_no_key_list_selects_nothing_and_says_so(tmp_path: Path) -> None:
    """FAIL CLOSED, and the COUNT is the whole value. Zero keys on its own is
    indistinguishable from a repository with no data model; zero keys beside
    `manifests_unlisted == 1` says a manifest was found and nothing vouched for it, which an
    operator can act on.

    MUTATION: in `_select`, count the refusal without the `continue` (i.e. admit it anyway).
    This test fails on the key count.

    @brief A manifest with no key list contributes nothing, visibly.
    @version 1
    """
    root = _repo(tmp_path, {"widgetbus.toml": MANIFEST}, None)
    found = discover(root)
    assert found.keys == ()
    assert found.manifests_unlisted == 1
    assert found.list_count == 0
    assert found.as_meta()["manifests_unlisted"] == "1"
    assert found.as_meta()["keys"] == "0"

Activity · 7 steps
lines 388–388root = _repo(tmp_path, {"widgetbus.toml": MANIFEST}, None)lines 389–389found = discover(root)lines 390–390assert found.keys == ()lines 391–391assert found.manifests_unlisted == 1lines 392–392assert found.list_count == 0lines 393–393assert found.as_meta()["manifests_unlisted"] == "1"lines 394–394assert found.as_meta()["keys"] == "0"

test_observed_flag_joins_the_shared_key_layer

None test_datamodel.test_observed_flag_joins_the_shared_key_layer(Path tmp_path)

observed joins the shared-key vocabulary the earlier stages wrote.

tests/test_datamodel.py:792

Checks

  • assert rows == {DEFINES[0]: 0, DEFINES[1]: 1, DEFINES[2]: 0}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-005measured
REQ-DDB-PIPE-003measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_observed_flag_joins_the_shared_key_layer → import_data_model_keys
Source · 31 lines
def test_observed_flag_joins_the_shared_key_layer(tmp_path: Path) -> None:
    """THE THIRD GAIN, and the reason the stage runs below the shared-key stages rather than
    beside them. Run above and every row reads `observed = 0`, which is a plausible answer —
    a repository touching none of its own data model — rather than an obviously wrong one.

    The fixture writes ONE of the three names into `shared_key_edges`, so a join that ignored
    the vocabulary and flagged everything is caught as surely as one that flagged nothing.

    MUTATION: make `_observed_keys` return `frozenset()`. This test fails: the observed count
    drops to 0.

    @brief The observed flag reflects the shared-key vocabulary.
    @version 1
    """
    root = _repo(tmp_path, {"widgetbus.toml": MANIFEST}, DEFINES)
    db = tmp_path / "clew.db"
    conn = sqlite3.connect(str(db))
    conn.execute("CREATE TABLE shared_key_edges (key_name TEXT)")
    conn.execute("INSERT INTO shared_key_edges VALUES (?)", (DEFINES[1],))
    conn.commit()
    conn.close()

    import_data_model_keys(db, root)
    conn = sqlite3.connect(str(db))
    try:
        rows = dict(conn.execute("SELECT define_name, observed FROM data_model_keys"))
    finally:
        conn.close()
    assert rows == {DEFINES[0]: 0, DEFINES[1]: 1, DEFINES[2]: 0}

Activity · 12 steps
lines 806–806root = _repo(tmp_path, {"widgetbus.toml": MANIFEST}, DEFINES)lines 807–807db = tmp_path / "clew.db"lines 808–808conn = sqlite3.connect(str(db))lines 809–809conn.execute("CREATE TABLE shared_key_edges (key_name TEXT)")lines 810–810conn.execute("INSERT INTO shared_key_edges VALUES (?)", (DEFINES[1],))lines 811–811conn.commit()lines 812–812conn.close()lines 814–814import_data_model_keys(db, root)lines 815–815conn = sqlite3.connect(str(db))lines 816–816trylines 817–817rows = dict(conn.execute("SELECT define_name, observed FROM data_model_keys"))lines 820–820assert rows == {DEFINES[0]: 0, DEFINES[1]: 1, DEFINES[2]: 0}

test_ordinary_toml_is_declined

None test_datamodel.test_ordinary_toml_is_declined(Path tmp_path)

The shape gate declines ordinary project TOML.

tests/test_datamodel.py:238

Checks

  • assert parse_ingot_manifest(path, tmp_path) is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003inferredtest_ordinary_toml_is_declined → parse_ingot_manifest → rel_key
REQ-DDB-SCHEMA-013measuredtest_ordinary_toml_is_declined → parse_ingot_manifest
Source · 17 lines
def test_ordinary_toml_is_declined(tmp_path: Path) -> None:
    """The SUCCESS half is `test_manifest_is_parsed` below; this is the half that pins the
    gate. `NOT_A_MANIFEST` carries a TOP-LEVEL `classes` list on purpose, so a gate that
    checked only for that key's presence and its type admits it and this test fails. See the
    fixture's own note: the first version nested that key and therefore tested nothing.

    MUTATION: in `parse_ingot_manifest`, drop the `_is_ingot_class_list(classes)` conjunct.
    This test fails — the lint config parses as a manifest declaring nothing.

    @brief Ordinary TOML is not a manifest.
    @version 1
    """
    path = tmp_path / "pyproject.toml"
    path.write_text(NOT_A_MANIFEST, encoding="utf-8")
    assert parse_ingot_manifest(path, tmp_path) is None

Activity · 3 steps
lines 250–250path = tmp_path / "pyproject.toml"lines 251–251path.write_text(NOT_A_MANIFEST, encoding="utf-8")lines 252–252assert parse_ingot_manifest(path, tmp_path) is None

test_selection_admits_only_what_a_key_list_vouches_for

None test_datamodel.test_selection_admits_only_what_a_key_list_vouches_for(Path tmp_path)

A repository's own manifest is admitted and the generator's example is not.

tests/test_datamodel.py:348

Show on the map →

Called by none

Calls _repo

Checks

  • assert {k.define_name for k in found.keys} == set(DEFINES)
  • assert found.manifests == ("conf/datamodel/widgetbus.toml",)
  • assert found.manifests_unlisted == 1
  • assert found.list_count == 1

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-INDEX-005measured
REQ-DDB-PIPE-003measured
REQ-DDB-SCHEMA-013measured
Source · 24 lines
def test_selection_admits_only_what_a_key_list_vouches_for(tmp_path: Path) -> None:
    """BOTH HALVES IN ONE TEST, because separated they mislead. The positive half passes with
    the gate deleted (everything is admitted), and the negative half passes if the parser is
    broken (nothing is admitted). Asserting the SPLIT — one in, one out, and the refusal
    counted — is what cannot be satisfied by either failure.

    MUTATION: in `_select`, drop the `if not any(key.define_name in listed ...)` branch. This
    test fails: the example's key appears and `manifests_unlisted` is 0.

    @brief Selection separates the repository's model from a shipped example.
    @version 1
    """
    root = _repo(
        tmp_path,
        {"widgetbus.toml": MANIFEST, "example.toml": EXAMPLE_MANIFEST},
        DEFINES,
    )
    found = discover(root)
    assert {k.define_name for k in found.keys} == set(DEFINES)
    assert found.manifests == ("conf/datamodel/widgetbus.toml",)
    assert found.manifests_unlisted == 1
    assert found.list_count == 1

Activity · 6 steps
lines 360–364root = _repo( tmp_path, {"widgetbus.toml": MANIFEST, "example.toml": EXAMPLE_MANIFEST}, DEFINES, )lines 365–365found = discover(root)lines 366–366assert {k.define_name for k in found.keys} == set(DEFINES)lines 367–367assert found.manifests == ("conf/datamodel/widgetbus.toml",)lines 368–368assert found.manifests_unlisted == 1lines 369–369assert found.list_count == 1

test_table_is_created_with_no_rows

None test_datamodel.test_table_is_created_with_no_rows(Path tmp_path)

The table exists even when the repository declares no keys.

tests/test_datamodel.py:922

Checks

  • assert conn.execute("SELECT COUNT(*) FROM data_model_keys").fetchone()[0] == 0

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-005measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_table_is_created_with_no_rows → import_data_model_keys
Source · 20 lines
def test_table_is_created_with_no_rows(tmp_path: Path) -> None:
    """An empty answer from a real table is a measurement; a missing table is not — it cannot
    be told apart from an index built before this layer existed, which is the ambiguity every
    structured zero in this pipeline exists to remove.

    MUTATION: move `_ensure_table(conn)` inside a `if found.keys:` guard. This test fails with
    `no such table`.

    @brief A target with no data model still gets the table.
    @version 1
    """
    db = tmp_path / "clew.db"
    import_data_model_keys(db, tmp_path)
    conn = sqlite3.connect(str(db))
    try:
        assert conn.execute("SELECT COUNT(*) FROM data_model_keys").fetchone()[0] == 0
    finally:
        conn.close()

Activity · 5 steps
lines 933–933db = tmp_path / "clew.db"lines 934–934import_data_model_keys(db, tmp_path)lines 935–935conn = sqlite3.connect(str(db))lines 936–936trylines 937–937assert conn.execute("SELECT COUNT(*) FROM data_model_keys").fetchone()[0] == 0

test_udm_default_is_unresolved_not_absent

None test_datamodel.test_udm_default_is_unresolved_not_absent(Path tmp_path)

A UDM default is recorded as DECLARED-AND-UNRESOLVED, never as absent.

tests/test_datamodel.py:562

Checks

  • assert keys is not None
  • assert all(k.default_value is None and k.enum_name is None for k in keys)
  • assert by_id["Sample of Rate"].unresolved_fields == ("default_value",)
  • assert by_id["Mode_Select"].unresolved_fields == ("default_value", "enum_set")
  • assert by_id["Uptime"].unresolved_fields == ()

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_udm_default_is_unresolved_not_absent → parse_udm_manifest → rel_key
REQ-DDB-SCHEMA-013measuredtest_udm_default_is_unresolved_not_absent → parse_udm_manifest
REQ-DDB-WIKI-054inferredtest_udm_default_is_unresolved_not_absent → all
Source · 32 lines
def test_udm_default_is_unresolved_not_absent(tmp_path: Path) -> None:
    """THE DISTINCTION THIS COLUMN EXISTS FOR, and all three states are in one assertion
    because separated they mislead. A UDM key's default is a base plus per-variant siblings
    that only a build's variant selection resolves, so no value is stored — but a key that
    declares NO default (280 of 1,606 in the measured corpus) must be distinguishable from one
    that declares several. `Uptime` is the empty case, and it is what makes this test fail
    against an implementation that simply marks every UDM key unresolved.

    `enum_set` rides the same mechanism: its value is a variant-to-inlined-member map with no
    name anywhere inside it, so there is nothing an `enum_name` column could honestly hold.

    MUTATION 1: in `_udm_keys`, set `default_value=_scalar(type_block["default_value"]["default"])`.
    This test fails — the base default is stored and would silently disagree with a variant
    build.
    MUTATION 2: make `_udm_unresolved` return `()` unconditionally. This test fails on the two
    keys that declare defaults, and PASSES on `Uptime` — which is why `Uptime` is in the
    fixture.

    @brief Declared-but-unresolved is distinct from not declared.
    @version 1
    """
    path = tmp_path / "widgetbus_001.yaml"
    path.write_text(UDM_MANIFEST, encoding="utf-8")
    keys = parse_udm_manifest(path, tmp_path)
    assert keys is not None
    by_id = {k.key_id: k for k in keys}
    assert all(k.default_value is None and k.enum_name is None for k in keys)
    assert by_id["Sample of Rate"].unresolved_fields == ("default_value",)
    assert by_id["Mode_Select"].unresolved_fields == ("default_value", "enum_set")
    assert by_id["Uptime"].unresolved_fields == ()

Activity · 9 steps
lines 583–583path = tmp_path / "widgetbus_001.yaml"lines 584–584path.write_text(UDM_MANIFEST, encoding="utf-8")lines 585–585keys = parse_udm_manifest(path, tmp_path)lines 586–586assert keys is not Nonelines 587–587by_id = {k.key_id: k for k in keys}lines 588–588assert all(k.default_value is None and k.enum_name is None for k in keys)lines 589–589assert by_id["Sample of Rate"].unresolved_fields == ("default_value",)lines 590–590assert by_id["Mode_Select"].unresolved_fields == ("default_value", "enum_set")lines 591–591assert by_id["Uptime"].unresolved_fields == ()

test_udm_identity_is_the_name_not_the_int_id

None test_datamodel.test_udm_identity_is_the_name_not_the_int_id(Path tmp_path)

A UDM key's identity is its NAME, never the optional int id .

tests/test_datamodel.py:537

Checks

  • assert keys is not None
  • assert composed == set(UDM_DEFINES)
  • assert not any("4" in name or "11" in name for name in composed)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_udm_identity_is_the_name_not_the_int_id → parse_udm_manifest → rel_key
REQ-DDB-SCHEMA-013measuredtest_udm_identity_is_the_name_not_the_int_id → parse_udm_manifest
Source · 21 lines
def test_udm_identity_is_the_name_not_the_int_id(tmp_path: Path) -> None:
    """4 of 233 classes and 14 of 1,606 keys in the measured corpus carry an int `id`, so a
    reader keying off it would key off a field the corpus almost entirely omits — and would
    compose an accessor name no generated code carries, making every such key read as never
    observed. The fixture puts an `id` on the class AND on one key so both levels are covered.

    MUTATION: in `_udm_keys`, compose from `entry.get("id", entry.get("name"))`. This test
    fails: the composed name carries the integer.

    @brief The int id is not the key identity.
    @version 1
    """
    path = tmp_path / "widgetbus_001.yaml"
    path.write_text(UDM_MANIFEST, encoding="utf-8")
    keys = parse_udm_manifest(path, tmp_path)
    assert keys is not None
    composed = {k.define_name for k in keys}
    assert composed == set(UDM_DEFINES)
    assert not any("4" in name or "11" in name for name in composed)

Activity · 7 steps
lines 549–549path = tmp_path / "widgetbus_001.yaml"lines 550–550path.write_text(UDM_MANIFEST, encoding="utf-8")lines 551–551keys = parse_udm_manifest(path, tmp_path)lines 552–552assert keys is not Nonelines 553–553composed = {k.define_name for k in keys}lines 554–554assert composed == set(UDM_DEFINES)lines 555–555assert not any("4" in name or "11" in name for name in composed)

test_udm_is_read_without_a_toml_parser

None test_datamodel.test_udm_is_read_without_a_toml_parser(Path tmp_path, monkeypatch)

The UDM half is read even with no TOML parser on the interpreter.

tests/test_datamodel.py:724

Show on the map →

Called by none

Calls _repo

Checks

  • assert found.toml_unavailable is True
  • assert found.as_meta()["toml_unavailable"] == "1"
  • assert {k.define_name for k in found.keys} == set(UDM_DEFINES)
  • assert found.dialects() == (DIALECT_UDM,)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-005measured
REQ-DDB-PIPE-003measured
REQ-DDB-SCHEMA-013measured
Source · 26 lines
def test_udm_is_read_without_a_toml_parser(tmp_path: Path, monkeypatch) -> None:
    """A MISSING TOML PARSER USED TO STOP THE WHOLE PASS, and once the second dialect became
    readable that was a "could not look" about a half that was perfectly readable. The UDM
    dialect is YAML; only the ingot dialect needs `tomllib` or the `tomli` backport. So
    `toml_unavailable` narrows to what it can honestly claim, and the ingot manifest beside the
    UDM one is what proves the flag still means something.

    MUTATION: restore the early `return ManifestSet(toml_unavailable=True)` in `discover`. This
    test fails — no UDM keys are found.

    @brief No TOML parser blocks only the ingot half.
    @version 1
    """
    root = _repo(
        tmp_path,
        {"widgetbus.toml": MANIFEST, "widgetbus_001.yaml": UDM_MANIFEST},
        DEFINES + UDM_DEFINES,
    )
    monkeypatch.setattr("clew.datamodel.toml_module", lambda: None)
    found = discover(root)
    assert found.toml_unavailable is True
    assert found.as_meta()["toml_unavailable"] == "1"
    assert {k.define_name for k in found.keys} == set(UDM_DEFINES)
    assert found.dialects() == (DIALECT_UDM,)

Activity · 7 steps
lines 737–741root = _repo( tmp_path, {"widgetbus.toml": MANIFEST, "widgetbus_001.yaml": UDM_MANIFEST}, DEFINES + UDM_DEFINES, )lines 742–742monkeypatch.setattr("clew.datamodel.toml_module", lambda: None)lines 743–743found = discover(root)lines 744–744assert found.toml_unavailable is Truelines 745–745assert found.as_meta()["toml_unavailable"] == "1"lines 746–746assert {k.define_name for k in found.keys} == set(UDM_DEFINES)lines 747–747assert found.dialects() == (DIALECT_UDM,)

test_udm_manifest_is_parsed

None test_datamodel.test_udm_manifest_is_parsed(Path tmp_path)

The second dialect parses to its declared keys, with its OWN field mapping.

tests/test_datamodel.py:452

Checks

  • assert keys is not None
  • assert tuple(k.define_name for k in keys) == UDM_DEFINES
  • assert {k.dialect for k in keys} == {DIALECT_UDM}
  • assert [k.value_type for k in keys] == ["uint16", "uint8", "uint32"]
  • assert [k.helpers for k in keys] == [True, False, True]
  • assert {k.namespace for k in keys} == {"widgetbus"}
  • assert {k.class_name for k in keys} == {"telemetry"}
  • assert keys[0].manifest == "widgetbus_001.yaml"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_udm_manifest_is_parsed → parse_udm_manifest → rel_key
REQ-DDB-SCHEMA-013measuredtest_udm_manifest_is_parsed → parse_udm_manifest
Source · 25 lines
def test_udm_manifest_is_parsed(tmp_path: Path) -> None:
    """EVERY FIELD NAME HERE DIFFERS FROM THE OTHER DIALECT'S, which is the whole argument for
    a second parser: `namespace` not `meta.id`, `name` not `id`, `data` not `keys`, and the type
    one level down at `type.mem` rather than a flat `type`. A mapping table shared with the
    ingot parser would have to guess which spelling it was looking at.

    MUTATION: in `_udm_keys`, read `type_block.get("type")` instead of `type_block.get("mem")`.
    This test fails — every value_type comes back None.

    @brief A UDM manifest's keys and metadata are read.
    @version 1
    """
    path = tmp_path / "widgetbus_001.yaml"
    path.write_text(UDM_MANIFEST, encoding="utf-8")
    keys = parse_udm_manifest(path, tmp_path)
    assert keys is not None
    assert tuple(k.define_name for k in keys) == UDM_DEFINES
    assert {k.dialect for k in keys} == {DIALECT_UDM}
    assert [k.value_type for k in keys] == ["uint16", "uint8", "uint32"]
    assert [k.helpers for k in keys] == [True, False, True]
    assert {k.namespace for k in keys} == {"widgetbus"}
    assert {k.class_name for k in keys} == {"telemetry"}
    assert keys[0].manifest == "widgetbus_001.yaml"

Activity · 11 steps
lines 464–464path = tmp_path / "widgetbus_001.yaml"lines 465–465path.write_text(UDM_MANIFEST, encoding="utf-8")lines 466–466keys = parse_udm_manifest(path, tmp_path)lines 467–467assert keys is not Nonelines 468–468assert tuple(k.define_name for k in keys) == UDM_DEFINESlines 469–469assert {k.dialect for k in keys} == {DIALECT_UDM}lines 470–470assert [k.value_type for k in keys] == ["uint16", "uint8", "uint32"]lines 471–471assert [k.helpers for k in keys] == [True, False, True]lines 472–472assert {k.namespace for k in keys} == {"widgetbus"}lines 473–473assert {k.class_name for k in keys} == {"telemetry"}lines 474–474assert keys[0].manifest == "widgetbus_001.yaml"

test_udm_manifest_with_no_key_list_is_declined

None test_datamodel.test_udm_manifest_with_no_key_list_is_declined(Path tmp_path)

A UDM manifest no key list vouches for is declined, and counted.

tests/test_datamodel.py:642

Show on the map →

Called by none

Calls _repo

Checks

  • assert found.keys == ()
  • assert found.manifests_unlisted == 1
  • assert found.as_meta()["dialect"] == ""

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-005measured
REQ-DDB-PIPE-003measured
REQ-DDB-SCHEMA-013measured
Source · 19 lines
def test_udm_manifest_with_no_key_list_is_declined(tmp_path: Path) -> None:
    """THE NEGATIVE HALF OF THE GATE FOR THE NEW DIALECT. The positive half passes with the
    gate deleted, since without a gate everything is admitted — so this is the assertion that
    pins it, and it is what stops a vendored generator's example YAML from being read as the
    repository's model.

    MUTATION: in `_select`, drop the `if not any(key.define_name in listed ...)` branch. This
    test fails: the UDM keys appear and `manifests_unlisted` is 0.

    @brief An unvouched-for UDM manifest contributes nothing, visibly.
    @version 1
    """
    root = _repo(tmp_path, {"widgetbus_001.yaml": UDM_MANIFEST}, None)
    found = discover(root)
    assert found.keys == ()
    assert found.manifests_unlisted == 1
    assert found.as_meta()["dialect"] == ""

Activity · 5 steps
lines 654–654root = _repo(tmp_path, {"widgetbus_001.yaml": UDM_MANIFEST}, None)lines 655–655found = discover(root)lines 656–656assert found.keys == ()lines 657–657assert found.manifests_unlisted == 1lines 658–658assert found.as_meta()["dialect"] == ""

test_udm_manifest_without_a_namespace_is_declined

None test_datamodel.test_udm_manifest_without_a_namespace_is_declined(Path tmp_path)

A UDM-shaped document with no namespace is declined.

tests/test_datamodel.py:512

Checks

  • assert parse_udm_manifest(path, tmp_path) is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003inferredtest_udm_manifest_without_a_namespace_is_declined → parse_udm_manifest → rel_key
REQ-DDB-SCHEMA-013measuredtest_udm_manifest_without_a_namespace_is_declined → parse_udm_manifest
Source · 21 lines
def test_udm_manifest_without_a_namespace_is_declined(tmp_path: Path) -> None:
    """WRITTEN BECAUSE A MUTATION CONTROL SAID IT WAS MISSING. Deleting the `namespace`
    conjunct from the UDM shape gate broke no test, so the conjunct was undefended — and it is
    load-bearing: with no namespace every composed name would be `_CLASS_KEY`, a leading
    underscore that matches no generated accessor, so every key in such a document would read
    as declared-and-never-observed rather than as a document that should not have been read.

    MUTATION: in `_udm_document`, drop the `"namespace" not in doc` conjunct. This test fails —
    the document parses and yields a key.

    @brief A namespace-less UDM document is not a manifest.
    @version 1
    """
    path = tmp_path / "nameless.yaml"
    path.write_text(
        "classes:\n  - name: telemetry\n    data:\n      - name: Uptime\n",
        encoding="utf-8",
    )
    assert parse_udm_manifest(path, tmp_path) is None

Activity · 3 steps
lines 525–525path = tmp_path / "nameless.yaml"lines 526–529path.write_text( "classes:\n - name: telemetry\n data:\n - name: Uptime\n", encoding="utf-8", )lines 530–530assert parse_udm_manifest(path, tmp_path) is None

test_unresolved_fields_column_is_null_when_nothing_is_unresolved

None test_datamodel.test_unresolved_fields_column_is_null_when_nothing_is_unresolved(Path tmp_path)

The per-row column stores the names, and NULL when there are none.

tests/test_datamodel.py:691

Checks

  • assert rows == {
  • assert dialects == {DIALECT_UDM}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-005measured
REQ-DDB-PIPE-003measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_unresolved_fields_column_is_null_when_nothing_is_unresolved → import_data_model_keys
Source · 28 lines
def test_unresolved_fields_column_is_null_when_nothing_is_unresolved(tmp_path: Path) -> None:
    """NULL, NOT AN EMPTY STRING, so that a consumer's test for "unresolved" is the same NULL
    test every other optional column here takes. An empty string would be a value that looks
    declared and is not — the same defect `_scalar` avoids one column over.

    MUTATION: change the insert to `",".join(key.unresolved_fields)` without the `or None`.
    This test fails: the `Uptime` row holds "" instead of NULL.

    @brief The column is NULL exactly when nothing was declared-and-unresolved.
    @version 1
    """
    root = _repo(tmp_path, {"widgetbus_001.yaml": UDM_MANIFEST}, UDM_DEFINES)
    db = tmp_path / "clew.db"
    import_data_model_keys(db, root)
    conn = sqlite3.connect(str(db))
    try:
        rows = dict(conn.execute("SELECT key_id, unresolved_fields FROM data_model_keys"))
        dialects = {r[0] for r in conn.execute("SELECT DISTINCT dialect FROM data_model_keys")}
    finally:
        conn.close()
    assert rows == {
        "Sample of Rate": "default_value",
        "Mode_Select": "default_value,enum_set",
        "Uptime": None,
    }
    assert dialects == {DIALECT_UDM}

Activity · 9 steps
lines 702–702root = _repo(tmp_path, {"widgetbus_001.yaml": UDM_MANIFEST}, UDM_DEFINES)lines 703–703db = tmp_path / "clew.db"lines 704–704import_data_model_keys(db, root)lines 705–705conn = sqlite3.connect(str(db))lines 706–706trylines 707–707rows = dict(conn.execute("SELECT key_id, unresolved_fields FROM data_model_keys"))lines 708–708dialects = {r[0] for r in conn.execute("SELECT DISTINCT dialect FROM data_model_keys")}lines 711–715assert rows == { "Sample of Rate": "default_value", "Mode_Select": "default_value,enum_set", "Uptime": None, }lines 716–716assert dialects == {DIALECT_UDM}

test_unresolved_note_is_emitted_only_when_it_applies

None test_datamodel.test_unresolved_note_is_emitted_only_when_it_applies(Path tmp_path)

The unresolved-fields note is emitted for UDM and withheld for ingot.

tests/test_datamodel.py:665

Show on the map →

Called by none

Calls _repo

Checks

  • assert "default_value" in note and "enum_set" in note
  • assert "unresolved_fields" in note
  • assert discover(ingot_root).as_meta()["unresolved_note"] == ""

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-005measured
REQ-DDB-PIPE-003measured
REQ-DDB-SCHEMA-013measured
Source · 22 lines
def test_unresolved_note_is_emitted_only_when_it_applies(tmp_path: Path) -> None:
    """THE PAYLOAD HAS TO SAY IT, because a consumer reading a NULL `default_value` will
    otherwise conclude the manifest was silent — and for a UDM row that conclusion is wrong.
    The ingot half is the control: a repository whose every declared default WAS resolved must
    get no note at all, or the note becomes boilerplate that asserts a policy which did not
    apply and stops being read.

    MUTATION: make `_unresolved_note` return its prose unconditionally. The ingot half of this
    test fails.

    @brief The note appears exactly when something was left unresolved.
    @version 1
    """
    udm_root = _repo(tmp_path / "udm", {"widgetbus_001.yaml": UDM_MANIFEST}, UDM_DEFINES)
    note = discover(udm_root).as_meta()["unresolved_note"]
    assert "default_value" in note and "enum_set" in note
    assert "unresolved_fields" in note

    ingot_root = _repo(tmp_path / "ingot", {"widgetbus.toml": MANIFEST}, DEFINES)
    assert discover(ingot_root).as_meta()["unresolved_note"] == ""

Activity · 6 steps
lines 678–678udm_root = _repo(tmp_path / "udm", {"widgetbus_001.yaml": UDM_MANIFEST}, UDM_DEFINES)lines 679–679note = discover(udm_root).as_meta()["unresolved_note"]lines 680–680assert "default_value" in note and "enum_set" in notelines 681–681assert "unresolved_fields" in notelines 683–683ingot_root = _repo(tmp_path / "ingot", {"widgetbus.toml": MANIFEST}, DEFINES)lines 684–684assert discover(ingot_root).as_meta()["unresolved_note"] == ""