Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions examples/semantic-vocabulary-drift-smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@
BUDGET_ANCHOR = {
"same_runtime_forks": 18,
"same_runtime_fork_definitions": 41,
"conflicting_values": 18,
"conflicting_definitions": 59,
"conflicting_values": 16,
"conflicting_definitions": 55,
"schema_version_same_runtime_forks": 7,
"multi_value_twins": 13,
"multi_value_forks": 4,
Expand Down Expand Up @@ -692,9 +692,17 @@ def check_inventory(registry: dict[str, Any], sources: list[SourceFile]) -> tupl
for item in review['magnitude_regressions']]
require(review['ok'], '; '.join(failures))
parts = []
slack = []
for key in RATCHET_KEYS:
actual = semantic_multi_value_forks if key == "multi_value_forks_semantic" else summary[key]
parts.append(f"{key}={actual}/{ratchets[key]}")
if ratchets[key] > actual:
# Disclose unlocked headroom so a merge that reverts a tightened
# budget shows up as new slack in this line instead of passing
# silently (the guard only fails on overflow, never on slack).
slack.append(f"{key}={ratchets[key] - actual}")
if slack:
parts.append("slack=" + ",".join(slack))
if review['reviewed_exception_count']:
parts.append(f"reviewed_inventory_exceptions={review['reviewed_exception_count']}")
return inventory, " ".join(parts)
Expand Down
6 changes: 3 additions & 3 deletions loopx/semantics/vocabulary_v0.json
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,8 @@
"meaning": "Counts read from the generated inventory. A same-runtime fork is one constant name with one value defined in two or more modules of the same runtime; a conflicting value is one name with different values. Both the number of affected names and the number of definitions are budgets, so a third spelling of an already-conflicting name is still a regression.",
"same_runtime_forks": 18,
"same_runtime_fork_definitions": 41,
"conflicting_values": 18,
"conflicting_definitions": 59,
"conflicting_values": 16,
"conflicting_definitions": 55,
"schema_version_same_runtime_forks": 7,
"multi_value_twins": 13,
"multi_value_forks": 4,
Expand Down Expand Up @@ -986,4 +986,4 @@
]
}
}
}
}
31 changes: 31 additions & 0 deletions tests/architecture/test_semantic_vocabulary_drift.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,34 @@ def test_remaining_kernel_values_each_carry_a_note(name):
if not str(notes.get(value) or '').strip()
]
assert not undocumented, f'{name}: values with no value_notes entry: {undocumented}'


def test_inventory_report_discloses_budget_slack(monkeypatch):
"""Budget slack (budget above the measured value) must be disclosed.

The guard only fails on overflow (measured > budget), so a merge that
reverts a tightened budget passes silently unless the report line shows
the reopened headroom. See the same_runtime_forks hunk straddle when
merging two budget-tightening branches.
"""
import copy

smoke = runpy.run_path(str(SMOKE))
registry = smoke["load_registry"]()
sources = smoke["load_sources"](REPO_ROOT)
# Pinned budgets disclose no slack for the counters this change locks
# (the multi_value_twins slack belongs to the multi-value single-source
# batch, not this one).
_, pinned = smoke["check_inventory"](registry, sources)
assert "slack=conflicting_values" not in pinned, pinned
assert "slack=conflicting_definitions" not in pinned, pinned
# A two-file budget revert (the merge-trap shape: registry and anchor
# move back together, so the equality anchor stays satisfied) must show
# up as disclosed slack instead of passing silently.
widened = copy.deepcopy(registry)
widened["inventory_ratchets"]["conflicting_values"] += 2
monkeypatch.setitem(
smoke["BUDGET_ANCHOR"], "conflicting_values", widened["inventory_ratchets"]["conflicting_values"],
)
_, line = smoke["check_inventory"](widened, sources)
assert "slack=conflicting_values=2" in line, line