test_tiers.py¶
tests/test_tiers.py
Five-tier layered-option resolution (gh#319).
test_a_corrupt_record_refuses_rather_than_reverting_silently
None test_tiers.test_a_corrupt_record_refuses_rather_than_reverting_silently()
FAIL CLOSED. Reverting to the target's declaration because the record could not be read is the exact defect the read-back exists to remove: the build would report success over a policy nobody chose. Nothing but `tiers` writes this row, so reaching here means the database was hand-edited.
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_a_corrupt_record_refuses_rather_than_reverting_silently → recorded_document |
Source · 16 lines
def test_a_corrupt_record_refuses_rather_than_reverting_silently() -> None:
"""FAIL CLOSED. Reverting to the target's declaration because the record could not
be read is the exact defect the read-back exists to remove: the build would report
success over a policy nobody chose. Nothing but `tiers` writes this row, so
reaching here means the database was hand-edited.
"""
## Both halves of the refusal: JSON that will not parse, and JSON that parses to a
## shape no manifest loader can read. The second is the quieter one — it would
## otherwise fail several frames away, in a parser whose message names a shape
## rather than a corrupt record.
for raw in ("{not json", "[1,2]"):
section = {f"o.{TIER_KEY}": TIER_EXPLICIT, f"o.{EXPLICIT_KEY}": raw}
with pytest.raises(ValueError, match="'o'"):
recorded_document(section, "o")
Activity · 4 steps
test_a_declaration_displaces_the_guesses_and_keeps_the_facts
None test_tiers.test_a_declaration_displaces_the_guesses_and_keeps_the_facts()
Tier 2 behaves exactly as tier 1 does against the guesses.
Checks
assert resolved.values == (*FACTS, *ECOSYSTEM, "%theirs%")assert resolved.tier == TIER_DECLARED
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_a_declaration_displaces_the_guesses_and_keeps_the_facts → resolve_layered |
Source · 9 lines
def test_a_declaration_displaces_the_guesses_and_keeps_the_facts() -> None:
"""Tier 2 behaves exactly as tier 1 does against the guesses."""
resolved = resolve_layered(
facts=FACTS, ecosystem=ECOSYSTEM, heuristics=GUESSES, declared=["%theirs%"]
)
assert resolved.values == (*FACTS, *ECOSYSTEM, "%theirs%")
assert resolved.tier == TIER_DECLARED
Activity · 3 steps
test_a_declaration_is_not_replayed_from_the_record
None test_tiers.test_a_declaration_is_not_replayed_from_the_record(Path tmp_path)
The recorded row for a tier-2 win carries no statement, so a later build re-reads the declaration file rather than a frozen copy of it.
Checks
assert _recorded_entry_patterns(args, db) is None
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_a_declaration_is_not_replayed_from_the_record → _entry_patterns → string_list |
| REQ-DDB-CONFIG-006 | measured | test_a_declaration_is_not_replayed_from_the_record → _stamp → write_build_signature |
| REQ-DDB-CONFIG-007 | measured | test_a_declaration_is_not_replayed_from_the_record → _stamp → write_build_signature |
| REQ-DDB-MCP-001 | measured | test_a_declaration_is_not_replayed_from_the_record → _recorded_entry_patterns → meta_section |
| REQ-DDB-PIPE-005 | measured | test_a_declaration_is_not_replayed_from_the_record → _stamp → write_build_signature |
Source · 10 lines
def test_a_declaration_is_not_replayed_from_the_record(tmp_path: Path) -> None:
"""The recorded row for a tier-2 win carries no statement, so a later build
re-reads the declaration file rather than a frozen copy of it.
"""
db = tmp_path / "clew.db"
args = argparse.Namespace(entry_patterns=None)
_stamp(db, _entry_patterns(args, {SECTION_ENTRY_PATTERNS: ["%trampoline%"]}))
assert _recorded_entry_patterns(args, db) is None
Activity · 4 steps
test_a_declared_alias_prefix_does_not_drop_the_ingot_default
None test_tiers.test_a_declared_alias_prefix_does_not_drop_the_ingot_default()
THE BUG, watched failing before the change: `tuple(declared) or DEFAULTS` meant declaring `APP_KEY_` resolved to `('APP_KEY_',)` and the ingot `DM_KEY_` normalization silently stopped, leaving an orphan write-half.
Checks
assert set(resolved.values) == {"APP_KEY_", *DEFAULT_KEY_ALIAS_PREFIXES}assert resolved.tier == TIER_DECLARED
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_a_declared_alias_prefix_does_not_drop_the_ingot_default → resolve_key_alias_prefixes |
| REQ-DDB-SCHEMA-005 | measured | test_a_declared_alias_prefix_does_not_drop_the_ingot_default → resolve_key_alias_prefixes |
Source · 10 lines
def test_a_declared_alias_prefix_does_not_drop_the_ingot_default() -> None:
"""THE BUG, watched failing before the change: `tuple(declared) or DEFAULTS`
meant declaring `APP_KEY_` resolved to `('APP_KEY_',)` and the ingot `DM_KEY_`
normalization silently stopped, leaving an orphan write-half.
"""
resolved = resolve_key_alias_prefixes({KEY_ALIAS_FIELD: ["APP_KEY_"]})
assert set(resolved.values) == {"APP_KEY_", *DEFAULT_KEY_ALIAS_PREFIXES}
assert resolved.tier == TIER_DECLARED
Activity · 3 steps
test_a_declared_manifest_is_not_replayed_from_the_record
None test_tiers.test_a_declared_manifest_is_not_replayed_from_the_record(Path tmp_path)
A tier-2 declaration re-derives from a file that may have changed since, so no statement is recorded for it and a later build re-reads the declaration rather than a frozen copy.
Called by none
Calls _options_meta_section, _stamp_manifest, recorded_document, resolve_document
Checks
assert resolution.tier == TIER_DECLAREDassert f"{SECTION_SHARED_KEY}.{EXPLICIT_KEY}" not in sectionassert recorded_document(section, SECTION_SHARED_KEY) is None
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_a_declared_manifest_is_not_replayed_from_the_record → resolve_document |
| REQ-DDB-CONFIG-007 | measured | test_a_declared_manifest_is_not_replayed_from_the_record → _stamp_manifest → write_build_signature |
| REQ-DDB-MCP-001 | measured | test_a_declared_manifest_is_not_replayed_from_the_record → _options_meta_section → _options_meta → _meta_section |
| REQ-DDB-PIPE-005 | measured | test_a_declared_manifest_is_not_replayed_from_the_record → _stamp_manifest → write_build_signature |
Source · 15 lines
def test_a_declared_manifest_is_not_replayed_from_the_record(tmp_path: Path) -> None:
"""A tier-2 declaration re-derives from a file that may have changed since, so no
statement is recorded for it and a later build re-reads the declaration rather
than a frozen copy.
"""
db = tmp_path / "clew.db"
resolution = resolve_document(explicit=None, declared=STATED_MANIFEST)
assert resolution.tier == TIER_DECLARED
_stamp_manifest(db, SECTION_SHARED_KEY, resolution)
section = _options_meta_section(db)
assert f"{SECTION_SHARED_KEY}.{EXPLICIT_KEY}" not in section
assert recorded_document(section, SECTION_SHARED_KEY) is None
Activity · 7 steps
test_a_declared_vocabulary_replaces_the_guesses_and_keeps_the_facts
None test_tiers.test_a_declared_vocabulary_replaces_the_guesses_and_keeps_the_facts()
Also watched failing before the change, in the other direction: the declaration used to EXTEND the whole default set, so `%init%` survived.
Checks
assert resolved.values == ("main", "app_main", "%trampoline%", "dispatch_%")assert resolved.tier == TIER_DECLARED
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_a_declared_vocabulary_replaces_the_guesses_and_keeps_the_facts → _entry_patterns → string_list |
| REQ-DDB-CONFIG-006 | measured | test_a_declared_vocabulary_replaces_the_guesses_and_keeps_the_facts → _entry_patterns → resolve_layered |
Source · 10 lines
def test_a_declared_vocabulary_replaces_the_guesses_and_keeps_the_facts() -> None:
"""Also watched failing before the change, in the other direction: the
declaration used to EXTEND the whole default set, so `%init%` survived.
"""
args = argparse.Namespace(entry_patterns=None)
resolved = _entry_patterns(args, {SECTION_ENTRY_PATTERNS: ["%trampoline%", "dispatch_%"]})
assert resolved.values == ("main", "app_main", "%trampoline%", "dispatch_%")
assert resolved.tier == TIER_DECLARED
Activity · 4 steps
test_a_manifest_statement_survives_a_later_build_that_states_nothing
None test_tiers.test_a_manifest_statement_survives_a_later_build_that_states_nothing(Path tmp_path)
THE DEFECT, at the unit level. gh#360 made a manifest statable inline and did not persist it, so the next build resolved the manifest from the target's own declaration and the stated layer vanished with the build reporting success — measured on this repo's self-index as a 1.7 s pass that reverted to the undeclared policy. gh#332 shipped the same hole for the path form.
Called by none
Calls _manifest_namespace, _replay_manifest_statements, _stamp_manifest, resolve_document
Checks
assert _replay_manifest_statements(args, db) == [SECTION_SHARED_KEY]assert args.shared_key_patterns == STATED_MANIFESTassert args.locks is Noneassert args.thread_patterns is None
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_a_manifest_statement_survives_a_later_build_that_states_nothing → resolve_document |
| REQ-DDB-CONFIG-007 | measured | test_a_manifest_statement_survives_a_later_build_that_states_nothing → _stamp_manifest → write_build_signature |
| REQ-DDB-MCP-001 | measured | test_a_manifest_statement_survives_a_later_build_that_states_nothing → _replay_manifest_statements → meta_section |
| REQ-DDB-PIPE-005 | measured | test_a_manifest_statement_survives_a_later_build_that_states_nothing → _stamp_manifest → write_build_signature |
Source · 27 lines
def test_a_manifest_statement_survives_a_later_build_that_states_nothing(
tmp_path: Path,
) -> None:
"""THE DEFECT, at the unit level. gh#360 made a manifest statable inline and did
not persist it, so the next build resolved the manifest from the target's own
declaration and the stated layer vanished with the build reporting success —
measured on this repo's self-index as a 1.7 s pass that reverted to the undeclared
policy. gh#332 shipped the same hole for the path form.
The build that discards it is usually the MCP server's, which passes no flags at
all: `status` reports staleness and the guidance says refresh, so a cell's agent
that brought the index up loses its own bringup work mid-cell and is never told.
"""
db = tmp_path / "clew.db"
_stamp_manifest(
db, SECTION_SHARED_KEY, resolve_document(explicit=STATED_MANIFEST, declared=None)
)
args = _manifest_namespace()
assert _replay_manifest_statements(args, db) == [SECTION_SHARED_KEY]
assert args.shared_key_patterns == STATED_MANIFEST
## The other four are untouched — a replay must not invent a statement for an
## option nobody stated.
assert args.locks is None
assert args.thread_patterns is None
Activity · 7 steps
test_a_manifest_that_states_no_prefixes_does_not_claim_the_tier
None test_tiers.test_a_manifest_that_states_no_prefixes_does_not_claim_the_tier(Path tmp_path)
A `--shared-key-patterns` file declaring only writers has stated NOTHING about alias prefixes, so recording `tier=explicit` would be a provenance record that is checkable and wrong — the failure `_scope_provenance` calls out.
Checks
assert alone.values == DEFAULT_KEY_ALIAS_PREFIXESassert alone.tier == TIER_HEURISTICassert beside_a_declaration.tier == TIER_DECLARED, ("the flag stated nothing about prefixes — the DECLARATION did" )assert set(beside_a_declaration.values) == {"DECL_KEY_", *DEFAULT_KEY_ALIAS_PREFIXES}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_a_manifest_that_states_no_prefixes_does_not_claim_the_tier → resolve_key_alias_prefixes |
| REQ-DDB-SCHEMA-005 | measured | test_a_manifest_that_states_no_prefixes_does_not_claim_the_tier → resolve_key_alias_prefixes |
Source · 28 lines
def test_a_manifest_that_states_no_prefixes_does_not_claim_the_tier(tmp_path: Path) -> None:
"""A `--shared-key-patterns` file declaring only writers has stated NOTHING
about alias prefixes, so recording `tier=explicit` would be a provenance record
that is checkable and wrong — the failure `_scope_provenance` calls out.
THE SECOND CASE IS THE ONE THAT BITES, and the first version of this test did
not have it. With `extra=None` the two readings are indistinguishable: dropping
the `bool(contributed)` guard makes `by_flag` true, but the statement is then
the empty list, which `resolve_layered` treats as a WITHDRAWAL and falls through
to the same answer. A mutation removing the guard passed. It takes a flag file
that states nothing ALONGSIDE a declaration that states something to tell them
apart — and there the wrong reading attributes the DECLARATION's prefixes to the
flag.
"""
manifest = tmp_path / "patterns.yaml"
manifest.write_text("writers:\n - name_prefix: 'App_Set_'\n", encoding="utf-8")
alone = resolve_key_alias_prefixes(manifest)
assert alone.values == DEFAULT_KEY_ALIAS_PREFIXES
assert alone.tier == TIER_HEURISTIC
beside_a_declaration = resolve_key_alias_prefixes(manifest, {KEY_ALIAS_FIELD: ["DECL_KEY_"]})
assert beside_a_declaration.tier == TIER_DECLARED, (
"the flag stated nothing about prefixes — the DECLARATION did"
)
assert set(beside_a_declaration.values) == {"DECL_KEY_", *DEFAULT_KEY_ALIAS_PREFIXES}
Activity · 8 steps
test_a_multi_value_statement_round_trips_through_the_stored_form
None test_tiers.test_a_multi_value_statement_round_trips_through_the_stored_form()
The separator has to survive values containing commas and spaces, which a SQL LIKE pattern legitimately does.
Checks
assert recorded_explicit(options_meta(o=resolution), "o") == tuple(stated)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_a_multi_value_statement_round_trips_through_the_stored_form → resolve_layered |
Source · 12 lines
def test_a_multi_value_statement_round_trips_through_the_stored_form() -> None:
"""The separator has to survive values containing commas and spaces, which a
SQL LIKE pattern legitimately does.
"""
stated = ["handle,%", "on %", "%weird%"]
resolution = resolve_layered(facts=FACTS, heuristics=GUESSES, explicit=stated)
# `options_meta` emits the section as `meta_section` hands it back: the
# `options.` prefix is added by the writer and stripped by the reader, so what
# `recorded_explicit` sees is exactly this mapping.
assert recorded_explicit(options_meta(o=resolution), "o") == tuple(stated)
Activity · 3 steps
test_a_recorded_statement_can_be_withdrawn
None test_tiers.test_a_recorded_statement_can_be_withdrawn(Path tmp_path)
Three states: absent inherits, EMPTY withdraws, non-empty replaces.
Checks
assert withdrawn == []assert list(_entry_patterns(argparse.Namespace(entry_patterns=withdrawn), {}).values) == (DEFAULT_ENTRY_PATTERNS )assert replaced == ["%other%"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_a_recorded_statement_can_be_withdrawn → _entry_patterns → string_list |
| REQ-DDB-CONFIG-006 | measured | test_a_recorded_statement_can_be_withdrawn → _stamp → write_build_signature |
| REQ-DDB-CONFIG-007 | measured | test_a_recorded_statement_can_be_withdrawn → _stamp → write_build_signature |
| REQ-DDB-MCP-001 | inferred | test_a_recorded_statement_can_be_withdrawn → _recorded_entry_patterns → meta_section |
| REQ-DDB-PIPE-005 | measured | test_a_recorded_statement_can_be_withdrawn → _stamp → write_build_signature |
Source · 15 lines
def test_a_recorded_statement_can_be_withdrawn(tmp_path: Path) -> None:
"""Three states: absent inherits, EMPTY withdraws, non-empty replaces."""
db = tmp_path / "clew.db"
_stamp(db, _entry_patterns(argparse.Namespace(entry_patterns=["%mystyle%"]), {}))
withdrawn = _recorded_entry_patterns(argparse.Namespace(entry_patterns=[]), db)
assert withdrawn == []
assert list(_entry_patterns(argparse.Namespace(entry_patterns=withdrawn), {}).values) == (
DEFAULT_ENTRY_PATTERNS
)
replaced = _recorded_entry_patterns(argparse.Namespace(entry_patterns=["%other%"]), db)
assert replaced == ["%other%"]
Activity · 7 steps
test_a_restated_fact_is_not_duplicated
None test_tiers.test_a_restated_fact_is_not_duplicated()
An operator restating `main` gets one seed, not two.
Checks
assert resolved.values == (*FACTS, "%mine%")
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_a_restated_fact_is_not_duplicated → resolve_layered |
Source · 6 lines
def test_a_restated_fact_is_not_duplicated() -> None:
"""An operator restating `main` gets one seed, not two."""
resolved = resolve_layered(facts=FACTS, heuristics=GUESSES, explicit=["fact_a", "%mine%"])
assert resolved.values == (*FACTS, "%mine%")
Activity · 2 steps
test_a_silent_target_resolves_to_the_whole_built_in_set
None test_tiers.test_a_silent_target_resolves_to_the_whole_built_in_set()
The success path for the migrated consumer specifically.
Checks
assert list(resolved.values) == DEFAULT_ENTRY_PATTERNSassert resolved.tier == TIER_HEURISTIC
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_a_silent_target_resolves_to_the_whole_built_in_set → _entry_patterns → string_list |
| REQ-DDB-CONFIG-006 | measured | test_a_silent_target_resolves_to_the_whole_built_in_set → _entry_patterns → resolve_layered |
Source · 9 lines
def test_a_silent_target_resolves_to_the_whole_built_in_set() -> None:
"""The success path for the migrated consumer specifically."""
resolved = _entry_patterns(argparse.Namespace(entry_patterns=None), {})
assert list(resolved.values) == DEFAULT_ENTRY_PATTERNS
assert resolved.tier == TIER_HEURISTIC
# ── the second consumer ─────────────────────────────────────────────────────
Activity · 3 steps
test_a_stated_data_model_records_its_tier
None test_tiers.test_a_stated_data_model_records_its_tier()
A stated data_model records its tier like every other stated option.
Checks
assert "data_model" in stated, ("a stated data_model must reach the options meta like every other stated option" )assert options_meta(**stated)[f"data_model.{TIER_KEY}"] == TIER_EXPLICITassert options_meta(**declared)[f"data_model.{TIER_KEY}"] == TIER_DECLARED
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-CONFIG-006 | measured | test_a_stated_data_model_records_its_tier → options_meta |
Source · 41 lines
def test_a_stated_data_model_records_its_tier() -> None:
"""gh#42. `status.options` CARRIED TIER ROWS FOR NINE SECTIONS AND NONE FOR
`data_model`. The reporter stated it through `options`, watched the build log it as tier 1,
and then found no record of it anywhere in the index — so a consumer reading an unexpected
data-model catalog could not tell "this operator stated a manifest" from "this repository
declares one" from "nobody said anything".
THE STAMP IS THE OWNER'S CONDITION FOR ALLOWING A REPLAYED STATEMENT AT ALL, as
`_manifest_option_tiers` records: a statement that survives a rebuild means the index
carries a policy the repository does not declare, so two operators of one commit can hold
different indexes. That is acceptable only because it is deliberate AND recorded. An option
that is replayed and NOT recorded is the defect gh#352 rejected.
IT WAS MISSED BECAUSE OF WHERE IT SITS IN THE OPTION TAXONOMY, not by an argument that it
should not be stamped: `_manifest_option_tiers` iterates `MANIFEST_OPTIONS`, and
`data_model` is a PATH option — the one manifest that is not YAML, named by path rather
than inlined. The taxonomy is right and the stamping loop was reading only half of it.
@brief The `data_model` option appears in the options meta with its tier.
@return None.
@version 1
"""
from clew.cli import _manifest_option_tiers
from clew.tiers import TIER_DECLARED, TIER_EXPLICIT, TIER_KEY
class _Args:
"""@brief A namespace carrying only the stated option."""
data_model = "app/data/model.toml"
stated = _manifest_option_tiers(_Args(), {})
assert "data_model" in stated, (
"a stated data_model must reach the options meta like every other stated option"
)
assert options_meta(**stated)[f"data_model.{TIER_KEY}"] == TIER_EXPLICIT
class _Bare:
"""@brief A namespace stating nothing."""
declared = _manifest_option_tiers(_Bare(), {"data_model": "app/data/model.toml"})
assert options_meta(**declared)[f"data_model.{TIER_KEY}"] == TIER_DECLARED1 more lines, not shown
Activity · 9 steps
test_a_stated_path_replays_as_a_path
None test_tiers.test_a_stated_path_replays_as_a_path(Path tmp_path)
BOTH INPUT FORMS ARE PERSISTED, because both had the hole (gh#332 shipped the path form). JSON tells them apart with no second key: a path is a string, a document is an object, so the reader cannot get the form wrong.
Called by none
Calls _manifest_namespace, _replay_manifest_statements, _stamp_manifest, resolve_document
Checks
assert _replay_manifest_statements(args, db) == [SECTION_LOCKS]assert args.locks == stated
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_a_stated_path_replays_as_a_path → resolve_document |
| REQ-DDB-CONFIG-007 | measured | test_a_stated_path_replays_as_a_path → _stamp_manifest → write_build_signature |
| REQ-DDB-MCP-001 | measured | test_a_stated_path_replays_as_a_path → _replay_manifest_statements → meta_section |
| REQ-DDB-PIPE-005 | measured | test_a_stated_path_replays_as_a_path → _stamp_manifest → write_build_signature |
Source · 14 lines
def test_a_stated_path_replays_as_a_path(tmp_path: Path) -> None:
"""BOTH INPUT FORMS ARE PERSISTED, because both had the hole (gh#332 shipped the
path form). JSON tells them apart with no second key: a path is a string, a
document is an object, so the reader cannot get the form wrong.
"""
db = tmp_path / "clew.db"
stated = str(tmp_path / "locks.yaml")
_stamp_manifest(db, SECTION_LOCKS, resolve_document(explicit=stated))
args = _manifest_namespace()
assert _replay_manifest_statements(args, db) == [SECTION_LOCKS]
assert args.locks == stated
Activity · 6 steps
test_a_statement_made_on_this_call_is_not_overwritten_by_the_record
None test_tiers.test_a_statement_made_on_this_call_is_not_overwritten_by_the_record(Path tmp_path)
The three states, and this is the REPLACE one: what an operator says now wins over what they said before.
Called by none
Calls _manifest_namespace, _replay_manifest_statements, _stamp_manifest, resolve_document
Checks
assert _replay_manifest_statements(args, db) == []assert args.shared_key_patterns == {"writers": [{"pattern": "Now_Set"}]}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_a_statement_made_on_this_call_is_not_overwritten_by_the_record → resolve_document |
| REQ-DDB-CONFIG-007 | measured | test_a_statement_made_on_this_call_is_not_overwritten_by_the_record → _stamp_manifest → write_build_signature |
| REQ-DDB-MCP-001 | measured | test_a_statement_made_on_this_call_is_not_overwritten_by_the_record → _replay_manifest_statements → meta_section |
| REQ-DDB-PIPE-005 | measured | test_a_statement_made_on_this_call_is_not_overwritten_by_the_record → _stamp_manifest → write_build_signature |
Source · 14 lines
def test_a_statement_made_on_this_call_is_not_overwritten_by_the_record(
tmp_path: Path,
) -> None:
"""The three states, and this is the REPLACE one: what an operator says now wins
over what they said before.
"""
db = tmp_path / "clew.db"
_stamp_manifest(db, SECTION_SHARED_KEY, resolve_document(explicit=STATED_MANIFEST))
args = _manifest_namespace(shared_key_patterns={"writers": [{"pattern": "Now_Set"}]})
assert _replay_manifest_statements(args, db) == []
assert args.shared_key_patterns == {"writers": [{"pattern": "Now_Set"}]}
Activity · 5 steps
test_a_target_declaring_no_alias_prefixes_gets_the_ingot_defaults
None test_tiers.test_a_target_declaring_no_alias_prefixes_gets_the_ingot_defaults()
THE SUCCESS PATH. The equivalent of the entry-pattern control that catches the inverse failure — a rule that protects the defaults by dropping everything else, or one that resolves to nothing at all when no declaration exists.
Checks
assert resolved.values == DEFAULT_KEY_ALIAS_PREFIXESassert resolved.tier == TIER_HEURISTICassert resolved.stated == ()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_a_target_declaring_no_alias_prefixes_gets_the_ingot_defaults → resolve_key_alias_prefixes |
| REQ-DDB-SCHEMA-005 | measured | test_a_target_declaring_no_alias_prefixes_gets_the_ingot_defaults → resolve_key_alias_prefixes |
Source · 15 lines
def test_a_target_declaring_no_alias_prefixes_gets_the_ingot_defaults() -> None:
"""THE SUCCESS PATH. The equivalent of the entry-pattern control that catches
the inverse failure — a rule that protects the defaults by dropping everything
else, or one that resolves to nothing at all when no declaration exists.
The tier reads `heuristic` because nothing was stated and this option has an
EMPTY tier-5 layer; for `key_alias_prefixes` that label means "defaults only",
not "a guess was used".
"""
resolved = resolve_key_alias_prefixes(None)
assert resolved.values == DEFAULT_KEY_ALIAS_PREFIXES
assert resolved.tier == TIER_HEURISTIC
assert resolved.stated == ()
Activity · 4 steps
test_a_target_stating_nothing_gets_facts_and_guesses_together
None test_tiers.test_a_target_stating_nothing_gets_facts_and_guesses_together()
THE SUCCESS PATH, and it is here deliberately.
Checks
assert resolved.values == (*FACTS, *ECOSYSTEM, *GUESSES)assert resolved.tier == TIER_HEURISTICassert resolved.stated == GUESSES
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_a_target_stating_nothing_gets_facts_and_guesses_together → resolve_layered |
Source · 14 lines
def test_a_target_stating_nothing_gets_facts_and_guesses_together() -> None:
"""THE SUCCESS PATH, and it is here deliberately.
A check with a test for its failure path and none for its success path shipped
a completely broken install path in this repo while the suite stayed green. The
interesting failure of a rule that protects facts from being dropped is that it
drops the guesses instead, and only this asserts otherwise.
"""
resolved = resolve_layered(facts=FACTS, ecosystem=ECOSYSTEM, heuristics=GUESSES)
assert resolved.values == (*FACTS, *ECOSYSTEM, *GUESSES)
assert resolved.tier == TIER_HEURISTIC
assert resolved.stated == GUESSES
Activity · 4 steps
test_a_withdrawn_manifest_statement_is_not_replayed_from_a_stale_row
None test_tiers.test_a_withdrawn_manifest_statement_is_not_replayed_from_a_stale_row(Path tmp_path)
THE TIER CROSS-CHECK, CONFIRMED FOR THE DOCUMENT FORM RATHER THAN ASSUMED.
Called by none
Calls _manifest_namespace, _options_meta_section, _replay_manifest_statements, _stamp_manifest, canonical_document, recorded_document, resolve_document
Checks
assert section[f"{SECTION_SHARED_KEY}.{EXPLICIT_KEY}"] == canonical_document(STATED_MANIFEST), ("the stale row must still be present — otherwise this test proves nothing" )assert section[f"{SECTION_SHARED_KEY}.{TIER_KEY}"] == TIER_HEURISTICassert recorded_document(section, SECTION_SHARED_KEY) is Noneassert _replay_manifest_statements(_manifest_namespace(), db) == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_a_withdrawn_manifest_statement_is_not_replayed_from_a_stale_row → canonical_document |
| REQ-DDB-CONFIG-007 | measured | test_a_withdrawn_manifest_statement_is_not_replayed_from_a_stale_row → _stamp_manifest → write_build_signature |
| REQ-DDB-MCP-001 | measured | test_a_withdrawn_manifest_statement_is_not_replayed_from_a_stale_row → _replay_manifest_statements → meta_section |
| REQ-DDB-PIPE-005 | measured | test_a_withdrawn_manifest_statement_is_not_replayed_from_a_stale_row → _stamp_manifest → write_build_signature |
Source · 25 lines
def test_a_withdrawn_manifest_statement_is_not_replayed_from_a_stale_row(
tmp_path: Path,
) -> None:
"""THE TIER CROSS-CHECK, CONFIRMED FOR THE DOCUMENT FORM RATHER THAN ASSUMED.
The guard lives in the READER, so a second reader that skipped it would replay a
withdrawn statement while `recorded_explicit` refused to — and the task asked for
this to be confirmed, not inherited. `write_build_signature` upserts and never
deletes, so stamping a withdrawal onto a database that already carries a statement
leaves the retracted `<option>.explicit` row beside a fresh
`<option>.tier = heuristic`.
"""
db = tmp_path / "clew.db"
_stamp_manifest(db, SECTION_SHARED_KEY, resolve_document(explicit=STATED_MANIFEST))
_stamp_manifest(db, SECTION_SHARED_KEY, resolve_document())
section = _options_meta_section(db)
assert section[f"{SECTION_SHARED_KEY}.{EXPLICIT_KEY}"] == canonical_document(STATED_MANIFEST), (
"the stale row must still be present — otherwise this test proves nothing"
)
assert section[f"{SECTION_SHARED_KEY}.{TIER_KEY}"] == TIER_HEURISTIC
assert recorded_document(section, SECTION_SHARED_KEY) is None
assert _replay_manifest_statements(_manifest_namespace(), db) == []
Activity · 8 steps
test_a_withdrawn_statement_is_not_replayed_from_a_stale_row
None test_tiers.test_a_withdrawn_statement_is_not_replayed_from_a_stale_row(Path tmp_path)
FOUND BY WRITING THE CONTROL IN THE AWKWARD DIRECTION.
Called by none
Calls _entry_patterns, _options_meta_section, _recorded_entry_patterns, _stamp, recorded_explicit
Checks
assert section[f"{OPTION_ENTRY_PATTERNS}.{EXPLICIT_KEY}"] == "%mine%", ("the stale row must still be present — otherwise this test proves nothing" )assert section[f"{OPTION_ENTRY_PATTERNS}.{TIER_KEY}"] == TIER_HEURISTICassert recorded_explicit(section, OPTION_ENTRY_PATTERNS) == ()assert _recorded_entry_patterns(argparse.Namespace(entry_patterns=None), db) is None
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_a_withdrawn_statement_is_not_replayed_from_a_stale_row → _entry_patterns → string_list |
| REQ-DDB-CONFIG-006 | measured | test_a_withdrawn_statement_is_not_replayed_from_a_stale_row → recorded_explicit |
| REQ-DDB-CONFIG-007 | measured | test_a_withdrawn_statement_is_not_replayed_from_a_stale_row → _stamp → write_build_signature |
| REQ-DDB-MCP-001 | measured | test_a_withdrawn_statement_is_not_replayed_from_a_stale_row → _recorded_entry_patterns → meta_section |
| REQ-DDB-PIPE-005 | measured | test_a_withdrawn_statement_is_not_replayed_from_a_stale_row → _stamp → write_build_signature |
Source · 30 lines
def test_a_withdrawn_statement_is_not_replayed_from_a_stale_row(tmp_path: Path) -> None:
"""FOUND BY WRITING THE CONTROL IN THE AWKWARD DIRECTION.
`write_build_signature` upserts and never deletes, so stamping a withdrawal
onto a database that already carries a statement leaves the retracted
`<option>.explicit` row beside a fresh `<option>.tier = heuristic`. The first
version of `recorded_explicit` read the statement key alone and replayed it —
turning a retraction into a silent re-application.
The real pipeline does not reach this (every build stamps a fresh temp database
that then replaces the live one), which is exactly why it needs a test: the
safety lives in a DIFFERENT module, and `_stamp_refresh_metrics` already stamps
onto the live database for another section. The tier row is written on every
stamp, so it is authoritative and a disagreeing statement replays nothing.
"""
db = tmp_path / "clew.db"
_stamp(db, _entry_patterns(argparse.Namespace(entry_patterns=["%mine%"]), {}))
_stamp(db, _entry_patterns(argparse.Namespace(entry_patterns=None), {}))
section = _options_meta_section(db)
assert section[f"{OPTION_ENTRY_PATTERNS}.{EXPLICIT_KEY}"] == "%mine%", (
"the stale row must still be present — otherwise this test proves nothing"
)
assert section[f"{OPTION_ENTRY_PATTERNS}.{TIER_KEY}"] == TIER_HEURISTIC
assert recorded_explicit(section, OPTION_ENTRY_PATTERNS) == ()
assert _recorded_entry_patterns(argparse.Namespace(entry_patterns=None), db) is None
# ── manifest statements: recorded, replayed, withdrawn (gh#364) ──────────────
Activity · 8 steps
test_alias_prefixes_accumulate_exactly_as_their_siblings_do
None test_tiers.test_alias_prefixes_accumulate_exactly_as_their_siblings_do()
The inconsistency the migration closes, asserted against the control arm: the writers from the SAME generator already accumulated while the prefixes replaced.
Checks
assert {"App_Set_", "DataModel_Set_"} <= surviving, "writers accumulate — control arm"assert set(prefixes) == {"APP_KEY_", *DEFAULT_KEY_ALIAS_PREFIXES}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_alias_prefixes_accumulate_exactly_as_their_siblings_do → resolve_shared_key_patterns |
| REQ-DDB-SCHEMA-005 | measured | test_alias_prefixes_accumulate_exactly_as_their_siblings_do → resolve_shared_key_patterns |
| REQ-DDB-SCHEMA-012 | measured | test_alias_prefixes_accumulate_exactly_as_their_siblings_do → resolve_shared_key_patterns → load_shared_key_patterns → declaration_origin |
Source · 13 lines
def test_alias_prefixes_accumulate_exactly_as_their_siblings_do() -> None:
"""The inconsistency the migration closes, asserted against the control arm:
the writers from the SAME generator already accumulated while the prefixes
replaced.
"""
writers, _readers, prefixes = resolve_shared_key_patterns(
{KEY_ALIAS_FIELD: ["APP_KEY_"], "writers": [{"name_prefix": "App_Set_"}]}
)
surviving = {getattr(w, "prefix", None) for w in writers}
assert {"App_Set_", "DataModel_Set_"} <= surviving, "writers accumulate — control arm"
assert set(prefixes) == {"APP_KEY_", *DEFAULT_KEY_ALIAS_PREFIXES}
Activity · 4 steps
test_an_empty_document_withdraws_the_record_rather_than_ignoring_it
None test_tiers.test_an_empty_document_withdraws_the_record_rather_than_ignoring_it(Path tmp_path)
`{}` DOES BOTH JOBS WITH ONE SPELLING (owner decision, gh#364): it stops overriding this run AND removes the record, because those are one intent.
Called by none
Calls _manifest_namespace, _manifest_option_tiers, _options_meta_section, _replay_manifest_statements, _stamp_manifest, recorded_document, resolve_document
Checks
assert _replay_manifest_statements(args, db) == [], "an empty document states nothing"assert args.shared_key_patterns == {}assert withdrawn.tier == TIER_HEURISTICassert withdrawn.as_meta(SECTION_SHARED_KEY) == {assert recorded_document(_options_meta_section(fresh), SECTION_SHARED_KEY) is Noneassert _replay_manifest_statements(_manifest_namespace(), fresh) == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-CONFIG-006 | measured | test_an_empty_document_withdraws_the_record_rather_than_ignoring_it → resolve_document |
| REQ-DDB-CONFIG-007 | measured | test_an_empty_document_withdraws_the_record_rather_than_ignoring_it → _stamp_manifest → write_build_signature |
| REQ-DDB-MCP-001 | measured | test_an_empty_document_withdraws_the_record_rather_than_ignoring_it → _replay_manifest_statements → meta_section |
| REQ-DDB-PIPE-005 | measured | test_an_empty_document_withdraws_the_record_rather_than_ignoring_it → _stamp_manifest → write_build_signature |
Source · 32 lines
def test_an_empty_document_withdraws_the_record_rather_than_ignoring_it(
tmp_path: Path,
) -> None:
"""`{}` DOES BOTH JOBS WITH ONE SPELLING (owner decision, gh#364): it stops
overriding this run AND removes the record, because those are one intent.
THE ASSERTION THAT MATTERS IS THAT THE RECORD IS GONE, not that this run ignored
it. A withdrawal that silently fails to withdraw is the `key_arg_idx`-for
-`key_arg_index` class of defect — a valid mapping no consumer reads — so this
checks the row a NEXT build would read, not the absence of an error.
"""
db = tmp_path / "clew.db"
_stamp_manifest(db, SECTION_SHARED_KEY, resolve_document(explicit=STATED_MANIFEST))
args = _manifest_namespace(shared_key_patterns={})
assert _replay_manifest_statements(args, db) == [], "an empty document states nothing"
assert args.shared_key_patterns == {}
## What THIS build would stamp for the withdrawn option: a tier, and no statement.
## Every build writes a fresh `build_meta` into the temp database that replaces the
## live one, so an absent statement here IS the record being gone.
withdrawn = _manifest_option_tiers(args, {})[SECTION_SHARED_KEY]
assert withdrawn.tier == TIER_HEURISTIC
assert withdrawn.as_meta(SECTION_SHARED_KEY) == {
f"{SECTION_SHARED_KEY}.{TIER_KEY}": TIER_HEURISTIC
}
fresh = tmp_path / "next.db"
_stamp_manifest(fresh, SECTION_SHARED_KEY, withdrawn)
assert recorded_document(_options_meta_section(fresh), SECTION_SHARED_KEY) is None
assert _replay_manifest_statements(_manifest_namespace(), fresh) == []
Activity · 12 steps
test_an_empty_explicit_list_withdraws_rather_than_states
None test_tiers.test_an_empty_explicit_list_withdraws_rather_than_states()
`--entry-patterns` with no values falls back, it does not resolve to nothing.
Checks
assert resolved.tier == TIER_DECLAREDassert resolved.values == (*FACTS, "%theirs%")assert bare.tier == TIER_HEURISTICassert bare.values == (*FACTS, *GUESSES)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_an_empty_explicit_list_withdraws_rather_than_states → resolve_layered |
Source · 16 lines
def test_an_empty_explicit_list_withdraws_rather_than_states() -> None:
"""`--entry-patterns` with no values falls back, it does not resolve to nothing.
Collapsing this into "states an empty set" would make a recorded statement
unwithdrawable except by deleting the database, and would seed reachability
from the facts alone.
"""
resolved = resolve_layered(facts=FACTS, heuristics=GUESSES, declared=["%theirs%"], explicit=[])
assert resolved.tier == TIER_DECLARED
assert resolved.values == (*FACTS, "%theirs%")
bare = resolve_layered(facts=FACTS, heuristics=GUESSES, explicit=[])
assert bare.tier == TIER_HEURISTIC
assert bare.values == (*FACTS, *GUESSES)
Activity · 6 steps
test_an_explicit_flag_no_longer_drops_the_language_entry_point
None test_tiers.test_an_explicit_flag_no_longer_drops_the_language_entry_point()
THE BUG. Watched failing before the change: `--entry-patterns %mystyle%` resolved to `['%mystyle%']`, so `main` and `app_main` were not seeds, liveness collapsed, and nothing in the build or the index said so.
Checks
assert "main" in resolved.valuesassert "app_main" in resolved.valuesassert "%mystyle%" in resolved.valuesassert "%init%" not in resolved.valuesassert resolved.tier == TIER_EXPLICIT
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_an_explicit_flag_no_longer_drops_the_language_entry_point → _entry_patterns → string_list |
| REQ-DDB-CONFIG-006 | measured | test_an_explicit_flag_no_longer_drops_the_language_entry_point → _entry_patterns → resolve_layered |
Source · 14 lines
def test_an_explicit_flag_no_longer_drops_the_language_entry_point() -> None:
"""THE BUG. Watched failing before the change: `--entry-patterns %mystyle%`
resolved to `['%mystyle%']`, so `main` and `app_main` were not seeds, liveness
collapsed, and nothing in the build or the index said so.
"""
args = argparse.Namespace(entry_patterns=["%mystyle%"])
resolved = _entry_patterns(args, {})
assert "main" in resolved.values
assert "app_main" in resolved.values
assert "%mystyle%" in resolved.values
assert "%init%" not in resolved.values
assert resolved.tier == TIER_EXPLICIT
Activity · 7 steps
test_an_explicit_manifest_file_outranks_a_declared_section
None test_tiers.test_an_explicit_manifest_file_outranks_a_declared_section(Path tmp_path)
Tier 1 beats tier 2, and the split is read from the SOURCE TYPE — `cli._declared_or_flag` hands back a Path for `--shared-key-patterns` and the parsed mapping for a declaration, so no second argument has to be kept in sync.
Checks
assert resolved.tier == TIER_EXPLICITassert set(resolved.values) == {"FLAG_KEY_", "DECL_KEY_", *DEFAULT_KEY_ALIAS_PREFIXES}, ("tier 1 wins the TIER, but tier 2 is still a stated layer contributing values" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_an_explicit_manifest_file_outranks_a_declared_section → resolve_key_alias_prefixes |
| REQ-DDB-SCHEMA-005 | measured | test_an_explicit_manifest_file_outranks_a_declared_section → resolve_key_alias_prefixes |
Source · 15 lines
def test_an_explicit_manifest_file_outranks_a_declared_section(tmp_path: Path) -> None:
"""Tier 1 beats tier 2, and the split is read from the SOURCE TYPE —
`cli._declared_or_flag` hands back a Path for `--shared-key-patterns` and the
parsed mapping for a declaration, so no second argument has to be kept in sync.
"""
manifest = tmp_path / "patterns.yaml"
manifest.write_text(f"{KEY_ALIAS_FIELD}: ['FLAG_KEY_']\n", encoding="utf-8")
resolved = resolve_key_alias_prefixes(manifest, {KEY_ALIAS_FIELD: ["DECL_KEY_"]})
assert resolved.tier == TIER_EXPLICIT
assert set(resolved.values) == {"FLAG_KEY_", "DECL_KEY_", *DEFAULT_KEY_ALIAS_PREFIXES}, (
"tier 1 wins the TIER, but tier 2 is still a stated layer contributing values"
)
Activity · 5 steps
test_an_explicit_statement_displaces_the_guesses_and_keeps_the_facts
None test_tiers.test_an_explicit_statement_displaces_the_guesses_and_keeps_the_facts()
Tier 1 replaces tier 5; tiers 3 and 4 accumulate underneath.
Checks
assert resolved.values == (*FACTS, *ECOSYSTEM, "%mine%")assert resolved.tier == TIER_EXPLICITassert guess not in resolved.values
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_an_explicit_statement_displaces_the_guesses_and_keeps_the_facts → resolve_layered |
Source · 11 lines
def test_an_explicit_statement_displaces_the_guesses_and_keeps_the_facts() -> None:
"""Tier 1 replaces tier 5; tiers 3 and 4 accumulate underneath."""
resolved = resolve_layered(
facts=FACTS, ecosystem=ECOSYSTEM, heuristics=GUESSES, explicit=["%mine%"]
)
assert resolved.values == (*FACTS, *ECOSYSTEM, "%mine%")
assert resolved.tier == TIER_EXPLICIT
for guess in GUESSES:
assert guess not in resolved.values
Activity · 5 steps
test_nothing_is_stated_and_nothing_replays_for_a_target_that_states_nothing
None test_tiers.test_nothing_is_stated_and_nothing_replays_for_a_target_that_states_nothing(Path tmp_path)
THE SUCCESS PATH, and the control for "entropic and mbedtls are unchanged". A target that states nothing must record nothing and replay nothing — asserted strictly (an exact section) rather than by absence of a single key, because this repo has shipped a check that tested only its failure path.
Called by none
Calls _manifest_namespace, _manifest_option_tiers, _options_meta_section, _replay_manifest_statements, options_meta, stated_options, write_build_signature
Checks
assert _options_meta_section(db) == {assert stated_options(_options_meta_section(db)) == ()assert _replay_manifest_statements(_manifest_namespace(), db) == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-CONFIG-006 | measured | test_nothing_is_stated_and_nothing_replays_for_a_target_that_states_nothing → write_build_signature |
| REQ-DDB-CONFIG-007 | measured | test_nothing_is_stated_and_nothing_replays_for_a_target_that_states_nothing → write_build_signature |
| REQ-DDB-MCP-001 | measured | test_nothing_is_stated_and_nothing_replays_for_a_target_that_states_nothing → _replay_manifest_statements → meta_section |
| REQ-DDB-PIPE-005 | measured | test_nothing_is_stated_and_nothing_replays_for_a_target_that_states_nothing → write_build_signature |
Source · 27 lines
def test_nothing_is_stated_and_nothing_replays_for_a_target_that_states_nothing(
tmp_path: Path,
) -> None:
"""THE SUCCESS PATH, and the control for "entropic and mbedtls are unchanged". A
target that states nothing must record nothing and replay nothing — asserted
strictly (an exact section) rather than by absence of a single key, because this
repo has shipped a check that tested only its failure path.
"""
db = tmp_path / "clew.db"
args = _manifest_namespace()
write_build_signature(db, options=options_meta(**_manifest_option_tiers(args, {})))
## gh#42 widened the stamped set: `data_model` is a PATH option rather than a manifest one
## — the single manifest that is not YAML — and was previously the one stated option that
## recorded nothing. gh#47 widened it again to the SECTION-DOCUMENT options, for the same
## reason and found the same way: a consumer asked whether a declaration reached the build
## and the row it reads did not exist, so `index_scope` was refused on a build where it had
## landed. The assertion stays EXACT, which is the property this test is written for; only
## the enumeration follows the set that is actually stamped.
assert _options_meta_section(db) == {
f"{option}.{TIER_KEY}": TIER_HEURISTIC
for option in (*MANIFEST_OPTIONS, SECTION_DATA_MODEL, *SECTION_DOCUMENT_OPTIONS)
}
assert stated_options(_options_meta_section(db)) == ()
assert _replay_manifest_statements(_manifest_namespace(), db) == []
Activity · 6 steps
test_only_a_tier_one_statement_is_recorded_for_replay
None test_tiers.test_only_a_tier_one_statement_is_recorded_for_replay()
A declaration re-derives from a file that may have changed since, so replaying a stored copy would freeze a stale declaration.
Checks
assert options_meta(opt=explicit) == {assert options_meta(opt=declared) == {f"opt.{TIER_KEY}": TIER_DECLARED}assert options_meta(opt=silent) == {f"opt.{TIER_KEY}": TIER_HEURISTIC}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_only_a_tier_one_statement_is_recorded_for_replay → resolve_layered |
Source · 16 lines
def test_only_a_tier_one_statement_is_recorded_for_replay() -> None:
"""A declaration re-derives from a file that may have changed since, so
replaying a stored copy would freeze a stale declaration.
"""
explicit = resolve_layered(facts=FACTS, heuristics=GUESSES, explicit=["%mine%"])
declared = resolve_layered(facts=FACTS, heuristics=GUESSES, declared=["%theirs%"])
silent = resolve_layered(facts=FACTS, heuristics=GUESSES)
assert options_meta(opt=explicit) == {
f"opt.{TIER_KEY}": TIER_EXPLICIT,
f"opt.{EXPLICIT_KEY}": "%mine%",
}
assert options_meta(opt=declared) == {f"opt.{TIER_KEY}": TIER_DECLARED}
assert options_meta(opt=silent) == {f"opt.{TIER_KEY}": TIER_HEURISTIC}
Activity · 6 steps
test_options_meta_refuses_a_bare_manifest_mapping
None test_tiers.test_options_meta_refuses_a_bare_manifest_mapping()
The refusal that makes recording the tier structural has to cover the document form too — a bare manifest mapping is exactly what a caller would reach for.
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_options_meta_refuses_a_bare_manifest_mapping → options_meta |
Source · 8 lines
def test_options_meta_refuses_a_bare_manifest_mapping() -> None:
"""The refusal that makes recording the tier structural has to cover the document
form too — a bare manifest mapping is exactly what a caller would reach for.
"""
with pytest.raises(TypeError, match="DocumentResolution"):
options_meta(**{SECTION_SHARED_KEY: STATED_MANIFEST}) # type: ignore[arg-type]
Activity · 2 steps
test_options_meta_refuses_values_whose_tier_was_discarded
None test_tiers.test_options_meta_refuses_values_whose_tier_was_discarded()
THE "CANNOT FORGET" MECHANISM. There is no code path from a bare list to the `options.*` rows, so recording the tier is structural rather than a habit.
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_options_meta_refuses_values_whose_tier_was_discarded → options_meta |
Source · 8 lines
def test_options_meta_refuses_values_whose_tier_was_discarded() -> None:
"""THE "CANNOT FORGET" MECHANISM. There is no code path from a bare list to the
`options.*` rows, so recording the tier is structural rather than a habit.
"""
with pytest.raises(TypeError, match="LayeredResolution"):
options_meta(entry_patterns=["main", "%init%"]) # type: ignore[arg-type]
Activity · 2 steps
test_reading_provenance_off_an_older_index_is_empty_not_an_error
None test_tiers.test_reading_provenance_off_an_older_index_is_empty_not_an_error(Path tmp_path)
An index built before this section existed answers "not recorded".
Checks
assert _recorded_entry_patterns(argparse.Namespace(entry_patterns=None), db) is None
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_reading_provenance_off_an_older_index_is_empty_not_an_error → write_build_signature |
| REQ-DDB-CONFIG-007 | measured | test_reading_provenance_off_an_older_index_is_empty_not_an_error → write_build_signature |
| REQ-DDB-MCP-001 | measured | test_reading_provenance_off_an_older_index_is_empty_not_an_error → _recorded_entry_patterns → meta_section |
| REQ-DDB-PIPE-005 | measured | test_reading_provenance_off_an_older_index_is_empty_not_an_error → write_build_signature |
Source · 7 lines
def test_reading_provenance_off_an_older_index_is_empty_not_an_error(tmp_path: Path) -> None:
"""An index built before this section existed answers "not recorded"."""
db = tmp_path / "clew.db"
write_build_signature(db)
assert _recorded_entry_patterns(argparse.Namespace(entry_patterns=None), db) is None
Activity · 3 steps
test_recorded_explicit_is_empty_when_nothing_was_recorded
None test_tiers.test_recorded_explicit_is_empty_when_nothing_was_recorded()
An absent key means "nothing to replay", not an empty statement.
Checks
assert recorded_explicit({}, OPTION_ENTRY_PATTERNS) == ()assert recorded_explicit({f"{OPTION_ENTRY_PATTERNS}.{TIER_KEY}": TIER_HEURISTIC}, "x") == ()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_recorded_explicit_is_empty_when_nothing_was_recorded → recorded_explicit |
Source · 6 lines
def test_recorded_explicit_is_empty_when_nothing_was_recorded() -> None:
"""An absent key means "nothing to replay", not an empty statement."""
assert recorded_explicit({}, OPTION_ENTRY_PATTERNS) == ()
assert recorded_explicit({f"{OPTION_ENTRY_PATTERNS}.{TIER_KEY}": TIER_HEURISTIC}, "x") == ()
Activity · 2 steps
test_status_names_the_options_an_operator_stated
None test_tiers.test_status_names_the_options_an_operator_stated(Path tmp_path)
THE VISIBLE STAMP — the owner's condition for allowing the replay at all. A replayed statement means the index carries a policy the repository does not declare, so two operators of one commit can hold different indexes; that is the shape of the defect rejected in gh#352 and it is acceptable only because it is deliberate AND visible. They may differ; never silently.
Called by none
Calls _entry_patterns, _options_meta, options_meta, resolve_document, stated_options, write_build_signature
Checks
assert stated_options(_options_meta(db)) == (SECTION_SHARED_KEY,), ("only a tier-1 win is a STATEMENT — a declaration is the repository's own, and " "the built-in floor is nobody's" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_status_names_the_options_an_operator_stated → _entry_patterns → string_list |
| REQ-DDB-CONFIG-006 | measured | test_status_names_the_options_an_operator_stated → _options_meta |
| REQ-DDB-CONFIG-007 | measured | test_status_names_the_options_an_operator_stated → write_build_signature |
| REQ-DDB-MCP-001 | measured | test_status_names_the_options_an_operator_stated → _options_meta → _meta_section |
| REQ-DDB-PIPE-005 | measured | test_status_names_the_options_an_operator_stated → write_build_signature |
Source · 26 lines
def test_status_names_the_options_an_operator_stated(tmp_path: Path) -> None:
"""THE VISIBLE STAMP — the owner's condition for allowing the replay at all. A
replayed statement means the index carries a policy the repository does not
declare, so two operators of one commit can hold different indexes; that is the
shape of the defect rejected in gh#352 and it is acceptable only because it is
deliberate AND visible. They may differ; never silently.
"""
from clew.mcp_server.state import _options_meta
db = tmp_path / "clew.db"
write_build_signature(
db,
options=options_meta(
**{
OPTION_ENTRY_PATTERNS: _entry_patterns(argparse.Namespace(entry_patterns=None), {}),
SECTION_SHARED_KEY: resolve_document(explicit=STATED_MANIFEST),
SECTION_LOCKS: resolve_document(declared=STATED_MANIFEST),
}
),
)
assert stated_options(_options_meta(db)) == (SECTION_SHARED_KEY,), (
"only a tier-1 win is a STATEMENT — a declaration is the repository's own, and "
"the built-in floor is nobody's"
)
Activity · 4 steps
test_status_reports_which_tier_chose_the_seeds
None test_tiers.test_status_reports_which_tier_chose_the_seeds(Path tmp_path)
RECORDED IS NOT ENOUGH — it has to be REPORTED. A tiered resolution whose winner never reaches a consumer is the same opacity as an untiered one with more moving parts, so `status` carries the section beside scope and coverage.
Checks
assert _options_meta(db) == {}, "a nonexistent index reports nothing, not a default"assert _options_meta(db) == {assert _options_meta(db)[f"{OPTION_ENTRY_PATTERNS}.{TIER_KEY}"] == TIER_HEURISTIC
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_status_reports_which_tier_chose_the_seeds → _entry_patterns → string_list |
| REQ-DDB-CONFIG-006 | measured | test_status_reports_which_tier_chose_the_seeds → _options_meta |
| REQ-DDB-CONFIG-007 | measured | test_status_reports_which_tier_chose_the_seeds → _stamp → write_build_signature |
| REQ-DDB-MCP-001 | measured | test_status_reports_which_tier_chose_the_seeds → _options_meta → _meta_section |
| REQ-DDB-PIPE-005 | measured | test_status_reports_which_tier_chose_the_seeds → _stamp → write_build_signature |
Source · 20 lines
def test_status_reports_which_tier_chose_the_seeds(tmp_path: Path) -> None:
"""RECORDED IS NOT ENOUGH — it has to be REPORTED. A tiered resolution whose
winner never reaches a consumer is the same opacity as an untiered one with
more moving parts, so `status` carries the section beside scope and coverage.
"""
from clew.mcp_server.state import _options_meta
db = tmp_path / "clew.db"
assert _options_meta(db) == {}, "a nonexistent index reports nothing, not a default"
_stamp(db, _entry_patterns(argparse.Namespace(entry_patterns=["%mine%"]), {}))
assert _options_meta(db) == {
f"{OPTION_ENTRY_PATTERNS}.{TIER_KEY}": TIER_EXPLICIT,
f"{OPTION_ENTRY_PATTERNS}.{EXPLICIT_KEY}": "%mine%",
}
_stamp(db, _entry_patterns(argparse.Namespace(entry_patterns=None), {}))
assert _options_meta(db)[f"{OPTION_ENTRY_PATTERNS}.{TIER_KEY}"] == TIER_HEURISTIC
Activity · 7 steps
test_the_alias_tier_is_stamped_beside_the_entry_pattern_tier
None test_tiers.test_the_alias_tier_is_stamped_beside_the_entry_pattern_tier(Path tmp_path)
Both layered options reach `build_meta` through the one producer that refuses values whose tier was discarded.
Called by none
Calls _entry_patterns, _options_meta_section, options_meta, recorded_explicit, resolve_key_alias_prefixes, write_build_signature
Checks
assert section[f"{OPTION_ENTRY_PATTERNS}.{TIER_KEY}"] == TIER_HEURISTICassert section[f"{OPTION_KEY_ALIAS_PREFIXES}.{TIER_KEY}"] == TIER_DECLAREDassert f"{OPTION_KEY_ALIAS_PREFIXES}.{EXPLICIT_KEY}" not in sectionassert recorded_explicit(section, OPTION_KEY_ALIAS_PREFIXES) == ()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_the_alias_tier_is_stamped_beside_the_entry_pattern_tier → _entry_patterns → string_list |
| REQ-DDB-CONFIG-006 | measured | test_the_alias_tier_is_stamped_beside_the_entry_pattern_tier → resolve_key_alias_prefixes |
| REQ-DDB-CONFIG-007 | measured | test_the_alias_tier_is_stamped_beside_the_entry_pattern_tier → write_build_signature |
| REQ-DDB-MCP-001 | measured | test_the_alias_tier_is_stamped_beside_the_entry_pattern_tier → _options_meta_section → _options_meta → _meta_section |
| REQ-DDB-PIPE-005 | measured | test_the_alias_tier_is_stamped_beside_the_entry_pattern_tier → write_build_signature |
| REQ-DDB-SCHEMA-005 | measured | test_the_alias_tier_is_stamped_beside_the_entry_pattern_tier → resolve_key_alias_prefixes |
Source · 30 lines
def test_the_alias_tier_is_stamped_beside_the_entry_pattern_tier(tmp_path: Path) -> None:
"""Both layered options reach `build_meta` through the one producer that refuses
values whose tier was discarded.
"""
db = tmp_path / "clew.db"
write_build_signature(
db,
options=options_meta(
**{
OPTION_ENTRY_PATTERNS: _entry_patterns(argparse.Namespace(entry_patterns=None), {}),
OPTION_KEY_ALIAS_PREFIXES: resolve_key_alias_prefixes(
{KEY_ALIAS_FIELD: ["APP_KEY_"]}
),
}
),
)
section = _options_meta_section(db)
assert section[f"{OPTION_ENTRY_PATTERNS}.{TIER_KEY}"] == TIER_HEURISTIC
assert section[f"{OPTION_KEY_ALIAS_PREFIXES}.{TIER_KEY}"] == TIER_DECLARED
## NOT REPLAYED, and this asserts the absence rather than assuming it. Only a
## tier-1 statement is recorded for replay, and a declaration re-derives from a
## file that may have changed — so the stale-row hazard `recorded_explicit`
## guards against cannot arise for a declared win in the first place.
assert f"{OPTION_KEY_ALIAS_PREFIXES}.{EXPLICIT_KEY}" not in section
assert recorded_explicit(section, OPTION_KEY_ALIAS_PREFIXES) == ()
# ── provenance: stamped, and read back rather than re-derived ───────────────
Activity · 7 steps
test_the_default_entry_pattern_set_is_exactly_the_two_halves
None test_tiers.test_the_default_entry_pattern_set_is_exactly_the_two_halves()
The composed constant is the ONE answer for "what a silent target gets".
Checks
assert DEFAULT_ENTRY_PATTERNS == [*ENTRY_PATTERN_FACTS, *ENTRY_PATTERN_HEURISTICS]assert set(ENTRY_PATTERN_FACTS) == {"main", "app_main"}assert not set(ENTRY_PATTERN_FACTS) & set(ENTRY_PATTERN_HEURISTICS)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | catalog |
Source · 7 lines
def test_the_default_entry_pattern_set_is_exactly_the_two_halves() -> None:
"""The composed constant is the ONE answer for "what a silent target gets"."""
assert DEFAULT_ENTRY_PATTERNS == [*ENTRY_PATTERN_FACTS, *ENTRY_PATTERN_HEURISTICS]
assert set(ENTRY_PATTERN_FACTS) == {"main", "app_main"}
assert not set(ENTRY_PATTERN_FACTS) & set(ENTRY_PATTERN_HEURISTICS)
Activity · 3 steps
test_the_manifest_option_names_are_the_declaration_section_names
None test_tiers.test_the_manifest_option_names_are_the_declaration_section_names()
AN IDENTITY THE REPLAY DEPENDS ON, pinned rather than trusted.
Checks
assert set(MANIFEST_OPTIONS) == {assert set(MANIFEST_OPTIONS) <= KNOWN_SECTIONS
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | catalog |
Source · 21 lines
def test_the_manifest_option_names_are_the_declaration_section_names() -> None:
"""AN IDENTITY THE REPLAY DEPENDS ON, pinned rather than trusted.
`_manifest_option_tiers` reads the target's declared document with
`section(decl, option)` and `_replay_manifest_statements` reads the argparse dest
with `getattr(args, option)`, so ONE string serves as the option name, the
declaration section name and the flag's dest. That is the design
(`buildoptions`: "THE VOCABULARY IS THE DECLARATION FILE'S"), but nothing enforced
it — and a renamed section would leave the replay reading a declaration that is
always empty, stamping `heuristic` over a repo that declares its own conventions.
"""
assert set(MANIFEST_OPTIONS) == {
SECTION_SHARED_KEY,
SECTION_THREADS,
SECTION_LOCKS,
SECTION_DISPATCH,
SECTION_MQTT,
}
assert set(MANIFEST_OPTIONS) <= KNOWN_SECTIONS
Activity · 2 steps
test_the_probe_set_straddles_both_halves_of_the_split
None test_tiers.test_the_probe_set_straddles_both_halves_of_the_split()
Without this the agreement test could pass on a consumer reading one half.
Checks
assert len(fact_only) >= 2, fact_onlyassert len(guess_only) >= 2, guess_onlyassert any(not seeds_reachability(n) for n in _PROBES), "no negative probe"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_the_probe_set_straddles_both_halves_of_the_split → seeds_reachability |
| REQ-DDB-CONFIG-006 | catalog |
Source · 16 lines
def test_the_probe_set_straddles_both_halves_of_the_split() -> None:
"""Without this the agreement test could pass on a consumer reading one half.
A probe set that happened to contain only fact-matching names would be
satisfied by a `seeds_reachability` that had dropped the heuristics entirely.
"""
fact_only = [n for n in _PROBES if any(_like(n.lower(), p) for p in ENTRY_PATTERN_FACTS)]
guess_only = [n for n in _PROBES if any(_like(n.lower(), p) for p in ENTRY_PATTERN_HEURISTICS)]
assert len(fact_only) >= 2, fact_only
assert len(guess_only) >= 2, guess_only
assert any(not seeds_reachability(n) for n in _PROBES), "no negative probe"
# ── key alias prefixes: the second migrated consumer (tier 4) ───────────────
Activity · 5 steps
test_the_proposer_and_reachability_agree_on_what_an_entry_point_is
None test_tiers.test_the_proposer_and_reachability_agree_on_what_an_entry_point_is()
CONTROL FOR THE SPLIT'S SECOND CONSUMER.
Checks
assert seeds_reachability(name) is expected, name
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_the_proposer_and_reachability_agree_on_what_an_entry_point_is → seeds_reachability |
| REQ-DDB-CONFIG-006 | measured | test_the_proposer_and_reachability_agree_on_what_an_entry_point_is → _entry_patterns → resolve_layered |
Source · 19 lines
def test_the_proposer_and_reachability_agree_on_what_an_entry_point_is() -> None:
"""CONTROL FOR THE SPLIT'S SECOND CONSUMER.
`propose/notindexed.seeds_reachability` mirrors the pattern set "as SQLite
would apply it", so after splitting the constant it can silently disagree with
the pass it claims to mirror — and the disagreement surfaces as a hazard report
that omits the `main` collision the module exists to warn about.
Compared against the RESOLVER's own no-statement result, not against the
constant, so a change to how the default set is composed fails here too. Both
sides use the same `_like`, which is the point: the question under test is
WHICH PATTERNS each side uses, not how LIKE is implemented.
"""
expected_patterns = _entry_patterns(argparse.Namespace(entry_patterns=None), {}).values
for name in _PROBES:
expected = any(_like(name.lower(), pattern) for pattern in expected_patterns)
assert seeds_reachability(name) is expected, name
Activity · 4 steps
test_the_stamped_alias_resolution_matches_the_one_the_pass_uses
None test_tiers.test_the_stamped_alias_resolution_matches_the_one_the_pass_uses()
PINS THE DOUBLE RESOLUTION. `resolve_key_alias_prefixes` is called twice per build — once inside `import_shared_key_edges_inferred` and once in `_build_stages` to stamp the tier — because the value is computed several frames below the stamping stage. It is pure and both calls take the same two locals, so they cannot disagree; this asserts that rather than trusting it, and would fail the moment either call site starts resolving something else.
Checks
assert via_pass == via_stamp, sources
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_the_stamped_alias_resolution_matches_the_one_the_pass_uses → resolve_shared_key_patterns |
| REQ-DDB-SCHEMA-005 | measured | test_the_stamped_alias_resolution_matches_the_one_the_pass_uses → resolve_shared_key_patterns |
| REQ-DDB-SCHEMA-012 | measured | test_the_stamped_alias_resolution_matches_the_one_the_pass_uses → resolve_shared_key_patterns → load_shared_key_patterns → declaration_origin |
Source · 18 lines
def test_the_stamped_alias_resolution_matches_the_one_the_pass_uses() -> None:
"""PINS THE DOUBLE RESOLUTION. `resolve_key_alias_prefixes` is called twice per
build — once inside `import_shared_key_edges_inferred` and once in
`_build_stages` to stamp the tier — because the value is computed several frames
below the stamping stage. It is pure and both calls take the same two locals, so
they cannot disagree; this asserts that rather than trusting it, and would fail
the moment either call site starts resolving something else.
"""
for sources in (
(None, None),
({KEY_ALIAS_FIELD: ["APP_KEY_"]}, None),
({"writers": [{"name_prefix": "App_Set_"}]}, {KEY_ALIAS_FIELD: ["WRAP_KEY_"]}),
):
via_pass = resolve_shared_key_patterns(*sources)[2]
via_stamp = resolve_key_alias_prefixes(*sources).values
assert via_pass == via_stamp, sources
Activity · 4 steps
test_the_stored_document_is_byte_STABLE_across_key_orderings
None test_tiers.test_the_stored_document_is_byte_STABLE_across_key_orderings()
WHAT PINS THE CANONICAL FORM. `test_warm_rebuild_is_deterministic` compares two real builds' `build_meta` VERBATIM, so a serialisation that preserved insertion order would make the stored row a function of how the caller spelled its mapping — an intermittent failure there rather than a useful one.
Called by none
Calls canonical_document, options_meta, recorded_document, resolve_document
Checks
assert canonical_document(STATED_MANIFEST) == canonical_document(STATED_MANIFEST_REORDERED)assert " " not in canonical_document(STATED_MANIFEST)assert (recorded_document(options_meta(o=resolve_document(explicit=STATED_MANIFEST_REORDERED)), "o") == STATED_MANIFEST )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_the_stored_document_is_byte_STABLE_across_key_orderings → canonical_document |
Source · 14 lines
def test_the_stored_document_is_byte_STABLE_across_key_orderings() -> None:
"""WHAT PINS THE CANONICAL FORM. `test_warm_rebuild_is_deterministic` compares two
real builds' `build_meta` VERBATIM, so a serialisation that preserved insertion
order would make the stored row a function of how the caller spelled its mapping —
an intermittent failure there rather than a useful one.
"""
assert canonical_document(STATED_MANIFEST) == canonical_document(STATED_MANIFEST_REORDERED)
assert " " not in canonical_document(STATED_MANIFEST)
assert (
recorded_document(options_meta(o=resolve_document(explicit=STATED_MANIFEST_REORDERED)), "o")
== STATED_MANIFEST
)
Activity · 3 steps
test_the_tier_names_partition_into_stated_and_accumulating
None test_tiers.test_the_tier_names_partition_into_stated_and_accumulating()
Nothing may be in both groups, and nothing may be in neither.
Checks
assert set(STATED_TIERS) | set(ACCUMULATING_TIERS) == set(TIER_ORDER)assert not set(STATED_TIERS) & set(ACCUMULATING_TIERS)assert set(ACCUMULATING_TIERS) == {TIER_TARGET_FACT, TIER_ECOSYSTEM}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | catalog |
Source · 10 lines
def test_the_tier_names_partition_into_stated_and_accumulating() -> None:
"""Nothing may be in both groups, and nothing may be in neither."""
assert set(STATED_TIERS) | set(ACCUMULATING_TIERS) == set(TIER_ORDER)
assert not set(STATED_TIERS) & set(ACCUMULATING_TIERS)
assert set(ACCUMULATING_TIERS) == {TIER_TARGET_FACT, TIER_ECOSYSTEM}
# ── entry patterns: the first migrated consumer ─────────────────────────────
Activity · 3 steps
test_the_winning_tier_reaches_build_meta_and_is_read_back
None test_tiers.test_the_winning_tier_reaches_build_meta_and_is_read_back(Path tmp_path)
PROVENANCE SURVIVES A REFRESH. Scope is re-derived from scratch on every build and nothing consulted what a previous build stamped, so an applied and recorded statement was discarded by the next refresh — which then reported success over a policy the operator had replaced. This is the same read-back `_operator_excludes` does, asserted end to end through the real writer.
Checks
assert rows[f"{OPTIONS_META_PREFIX}.{OPTION_ENTRY_PATTERNS}.{TIER_KEY}"] == TIER_EXPLICITassert rows[f"{OPTIONS_META_PREFIX}.{OPTION_ENTRY_PATTERNS}.{EXPLICIT_KEY}"] == "%mystyle%"assert inherited == ["%mystyle%"]assert list(_entry_patterns(argparse.Namespace(entry_patterns=inherited), {}).values) == [
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_the_winning_tier_reaches_build_meta_and_is_read_back → _entry_patterns → string_list |
| REQ-DDB-CONFIG-006 | measured | test_the_winning_tier_reaches_build_meta_and_is_read_back → _stamp → write_build_signature |
| REQ-DDB-CONFIG-007 | measured | test_the_winning_tier_reaches_build_meta_and_is_read_back → _stamp → write_build_signature |
| REQ-DDB-MCP-001 | measured | test_the_winning_tier_reaches_build_meta_and_is_read_back → _recorded_entry_patterns → meta_section |
| REQ-DDB-PIPE-005 | measured | test_the_winning_tier_reaches_build_meta_and_is_read_back → _stamp → write_build_signature |
Source · 30 lines
def test_the_winning_tier_reaches_build_meta_and_is_read_back(tmp_path: Path) -> None:
"""PROVENANCE SURVIVES A REFRESH. Scope is re-derived from scratch on every
build and nothing consulted what a previous build stamped, so an applied and
recorded statement was discarded by the next refresh — which then reported
success over a policy the operator had replaced. This is the same read-back
`_operator_excludes` does, asserted end to end through the real writer.
"""
db = tmp_path / "clew.db"
resolution = _entry_patterns(argparse.Namespace(entry_patterns=["%mystyle%"]), {})
_stamp(db, resolution)
rows = dict(
sqlite3.connect(str(db))
.execute(f"SELECT key, value FROM build_meta WHERE key LIKE '{OPTIONS_META_PREFIX}.%'")
.fetchall()
)
assert rows[f"{OPTIONS_META_PREFIX}.{OPTION_ENTRY_PATTERNS}.{TIER_KEY}"] == TIER_EXPLICIT
assert rows[f"{OPTIONS_META_PREFIX}.{OPTION_ENTRY_PATTERNS}.{EXPLICIT_KEY}"] == "%mystyle%"
# A later build passing NO flag inherits the recorded statement rather than
# silently re-deriving the built-in guesses.
inherited = _recorded_entry_patterns(argparse.Namespace(entry_patterns=None), db)
assert inherited == ["%mystyle%"]
assert list(_entry_patterns(argparse.Namespace(entry_patterns=inherited), {}).values) == [
"main",
"app_main",
"%mystyle%",
]
Activity · 9 steps
test_tier_one_beats_tier_two
None test_tiers.test_tier_one_beats_tier_two()
A flag is a deliberate one-off override of the repo's standing statement.
Checks
assert resolved.values == (*FACTS, "%mine%")assert resolved.tier == TIER_EXPLICIT
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-006 | measured | test_tier_one_beats_tier_two → resolve_layered |
Source · 9 lines
def test_tier_one_beats_tier_two() -> None:
"""A flag is a deliberate one-off override of the repo's standing statement."""
resolved = resolve_layered(
facts=FACTS, heuristics=GUESSES, declared=["%theirs%"], explicit=["%mine%"]
)
assert resolved.values == (*FACTS, "%mine%")
assert resolved.tier == TIER_EXPLICIT