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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-INDEX-005 | measured | |
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-SCHEMA-013 | measured |
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
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.
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-INDEX-005 | measured | |
| REQ-DDB-SCHEMA-013 | measured |
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
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.
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-INDEX-005 | measured | |
| REQ-DDB-SCHEMA-013 | measured |
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
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.
Checks
assert names == ["B12_DRIVE_WHEEL_LINEAR_VEL", "B12_DRIVE_WHEEL_LINEAR_VEL"], namesassert define_name("B12", "Drive", "wheel linear vel") == "B12_DRIVE_WHEELLINEARVEL"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-INDEX-005 | measured | |
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-SCHEMA-013 | measured |
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
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.
Checks
assert loads["n"] > 0, "an edited document must be read again, not served from the cache"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-INDEX-002 | measured | |
| REQ-DDB-INDEX-005 | measured | |
| REQ-DDB-SCHEMA-013 | measured |
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
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.
Checks
assert big.stat().st_size > 2 * 1024 * 1024assert found.oversized == 1assert found.as_meta()["documents_oversized"] == "1"assert "PADDING_KEY_0" not in found.listedassert {k.define_name for k in found.keys} == set(DEFINES)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-CONFIG-007 | measured | |
| REQ-DDB-INDEX-005 | measured | |
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-SCHEMA-013 | measured |
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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-INDEX-002 | measured | |
| REQ-DDB-INDEX-005 | measured | |
| REQ-DDB-SCHEMA-013 | measured |
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
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.
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) == 2assert meta["unresolved_note"].startswith("udm declares")assert DIALECT_INGOT not in meta["unresolved_note"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-CONFIG-007 | measured | |
| REQ-DDB-INDEX-005 | measured | |
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-SCHEMA-013 | measured |
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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-INDEX-005 | measured | |
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-SCHEMA-013 | measured |
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
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.
Checks
assert define_name("widgetbus", "telemetry", "Sample of Rate") == ("WIDGETBUS_TELEMETRY_SAMPLEOFRATE" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-SCHEMA-013 | measured | test_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
test_define_name_preserves_an_underscore
None test_datamodel.test_define_name_preserves_an_underscore()
An underscore inside a segment SURVIVES composition.
Checks
assert define_name("alerts_group", "telemetry", "Is_Charging") == ("ALERTS_GROUP_TELEMETRY_IS_CHARGING" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-INDEX-005 | measured | |
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-SCHEMA-013 | measured |
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
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.
Checks
assert keys is not Noneassert by_id["Is_Charging"] == "False"assert by_id["Threshold"] == "0"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | test_false_default_is_not_zero → parse_ingot_manifest → rel_key |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Checks
assert (None if names is None else len(names)) == expected
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-SCHEMA-013 | measured | test_key_list_recognition → read_key_list |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert found.keys == ()assert found.manifests_unlisted == 0, "premise: the manifest is excluded, not declined"assert found.list_count == 1assert [r for r in caplog.records if "NESTED GIT TREE" in r.getMessage()]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-CONFIG-007 | measured | |
| REQ-DDB-INDEX-005 | measured | |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Checks
assert keys is not Noneassert tuple(k.define_name for k in keys) == DEFINESassert (charge.value_type, charge.default_value, charge.enum_name) == ("bool", "False", "widget_mode", )assert charge.helpers is Trueassert charge.dialect == DIALECT_INGOTassert not Path(charge.manifest).is_absolute()assert charge.manifest == "widgetbus.toml"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | test_manifest_is_parsed → parse_ingot_manifest → rel_key |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Checks
assert parse_udm_manifest(ingot, tmp_path) is Noneassert parse_ingot_manifest(udm, tmp_path) is None
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | inferred | test_neither_parser_reads_the_other_dialect → parse_ingot_manifest → rel_key |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Checks
assert found.keys == ()assert found.manifests_unlisted == 0assert found.as_meta()["dialect"] == ""assert found.as_meta()["keys"] == "0"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-CONFIG-007 | measured | |
| REQ-DDB-INDEX-005 | measured | |
| REQ-DDB-SCHEMA-013 | measured |
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
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.
Checks
assert found.keys == ()assert found.manifests_unlisted == 1assert found.list_count == 0assert found.as_meta()["manifests_unlisted"] == "1"assert found.as_meta()["keys"] == "0"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-CONFIG-007 | measured | |
| REQ-DDB-INDEX-005 | measured | |
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-SCHEMA-013 | measured |
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
test_ordinary_toml_is_declined
None test_datamodel.test_ordinary_toml_is_declined(Path tmp_path)
The shape gate declines ordinary project TOML.
Checks
assert parse_ingot_manifest(path, tmp_path) is None
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | inferred | test_ordinary_toml_is_declined → parse_ingot_manifest → rel_key |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Checks
assert {k.define_name for k in found.keys} == set(DEFINES)assert found.manifests == ("conf/datamodel/widgetbus.toml",)assert found.manifests_unlisted == 1assert found.list_count == 1
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-INDEX-005 | measured | |
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-SCHEMA-013 | measured |
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
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.
Checks
assert conn.execute("SELECT COUNT(*) FROM data_model_keys").fetchone()[0] == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-CONFIG-007 | measured | |
| REQ-DDB-INDEX-005 | measured | |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Checks
assert keys is not Noneassert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | test_udm_default_is_unresolved_not_absent → parse_udm_manifest → rel_key |
| REQ-DDB-SCHEMA-013 | measured | test_udm_default_is_unresolved_not_absent → parse_udm_manifest |
| REQ-DDB-WIKI-054 | inferred | test_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
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 .
Checks
assert keys is not Noneassert composed == set(UDM_DEFINES)assert not any("4" in name or "11" in name for name in composed)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | test_udm_identity_is_the_name_not_the_int_id → parse_udm_manifest → rel_key |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Checks
assert found.toml_unavailable is Trueassert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-CONFIG-007 | measured | |
| REQ-DDB-INDEX-005 | measured | |
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-SCHEMA-013 | measured |
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
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.
Checks
assert keys is not Noneassert tuple(k.define_name for k in keys) == UDM_DEFINESassert {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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | test_udm_manifest_is_parsed → parse_udm_manifest → rel_key |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Checks
assert found.keys == ()assert found.manifests_unlisted == 1assert found.as_meta()["dialect"] == ""
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-CONFIG-007 | measured | |
| REQ-DDB-INDEX-005 | measured | |
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-SCHEMA-013 | measured |
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
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.
Checks
assert parse_udm_manifest(path, tmp_path) is None
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | inferred | test_udm_manifest_without_a_namespace_is_declined → parse_udm_manifest → rel_key |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Checks
assert rows == {assert dialects == {DIALECT_UDM}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-CONFIG-007 | measured | |
| REQ-DDB-INDEX-005 | measured | |
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Checks
assert "default_value" in note and "enum_set" in noteassert "unresolved_fields" in noteassert discover(ingot_root).as_meta()["unresolved_note"] == ""
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-CONFIG-007 | measured | |
| REQ-DDB-INDEX-005 | measured | |
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-SCHEMA-013 | measured |
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"] == ""