feat(ledger): reason codes, case-insensitive repo filter, next action on the coverage line (#2874, milestone 294)
CI & Build / Python lint (push) Successful in 4s
CI & Build / Plugin hooks (push) Successful in 9s
CI & Build / integration (push) Failing after 25s
CI & Build / TypeScript typecheck (push) Canceled after 32s
CI & Build / Python tests (push) Canceled after 31s
CI & Build / Build & push image (push) Canceled after 0s
CI & Build / Python lint (push) Successful in 4s
CI & Build / Plugin hooks (push) Successful in 9s
CI & Build / integration (push) Failing after 25s
CI & Build / TypeScript typecheck (push) Canceled after 32s
CI & Build / Python tests (push) Canceled after 31s
CI & Build / Build & push image (push) Canceled after 0s
- code_shapes.reason_code (migration 0083): an optional code from a fixed catalogue (scoped-css, one-off-handler, test-helper, convention-plumbing, pure-helper, generated, script, typed-record) beside the prose reason, so the ledger can be filtered/aggregated by kind of one-off; validated in classify_shapes and classify_shapes_by_rule; on to_dict/to_compact. - Snippet location lookups match repo case-insensitively in both dialects (location_matches / location_jsonpath via like_regex flag "i") — "Scribe" vs "FabledScribe" vs "fabledscribe" recorded free-form hid half the canon from list_snippets(repo=, path=). - coverage line names the next action: "top canon #N ×k" (biggest proposal queue) and "top copy <label> ×files" (widest body-identical group). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -497,6 +497,12 @@ def test_coverage_line_names_the_proposers_standing():
|
||||
assert "; 90 unclassified (40 proposed, 2 derive groups), largest: src" in line
|
||||
line = coverage_line({**base, "proposed": 0, "derive_groups": [{"group": "a"}]})
|
||||
assert "(1 derive group)" in line
|
||||
# #2874: the next action on the line — biggest canon queue, widest copy.
|
||||
line = coverage_line({
|
||||
**base, "proposed": 40, "top_canon": {"snippet_id": 2844, "count": 78},
|
||||
"derive_groups": [{"group": "dup:abc", "label": "closed-msg (identical body)", "files": 3}],
|
||||
})
|
||||
assert "top canon #2844 ×78" in line and "top copy closed-msg (identical body) ×3 files" in line
|
||||
|
||||
|
||||
def test_coverage_line_names_divergence_and_recheck():
|
||||
|
||||
@@ -391,6 +391,22 @@ def test_compact_row_carries_identity_standing_and_the_proposers_word_only():
|
||||
assert noisy not in compact
|
||||
|
||||
|
||||
def test_reason_codes_are_a_fixed_catalogue_and_validated():
|
||||
"""#2874: an optional index beside the prose reason; unknown codes are a
|
||||
structural error (the batch applies nothing)."""
|
||||
from scribe.models.code_shape import REASON_CODES
|
||||
from scribe.services.shape_ledger import validate_classifications
|
||||
assert set(REASON_CODES) == {
|
||||
"scoped-css", "one-off-handler", "test-helper", "convention-plumbing",
|
||||
"pure-helper", "generated", "script", "typed-record",
|
||||
}
|
||||
assert "reason_code" in CodeShape.__table__.c
|
||||
ok = [{"path": "a.py", "symbol": "f", "status": "exempt", "reason": "x", "reason_code": "pure-helper"}]
|
||||
assert validate_classifications(ok) is None
|
||||
bad = [{"path": "a.py", "symbol": "f", "status": "exempt", "reason": "x", "reason_code": "nope"}]
|
||||
assert "unknown reason_code" in validate_classifications(bad)
|
||||
|
||||
|
||||
def test_rule_matches_is_directory_glob_and_kind_aware():
|
||||
from scribe.models.code_shape import CodeShape
|
||||
from scribe.services.shape_ledger import rule_matches
|
||||
|
||||
@@ -56,6 +56,7 @@ def test_no_parts_matches_everything():
|
||||
def test_matches_exact_repo_path_and_symbol():
|
||||
data = _data({"repo": "Scribe", "path": "src/scribe/x.py", "symbol": "helper"})
|
||||
assert location_matches(data, {"repo": "Scribe"})
|
||||
assert location_matches(data, {"repo": "scribe"}) # repo names: case never distinguishes (#2874)
|
||||
assert location_matches(data, {"path": "src/scribe/x.py"})
|
||||
assert location_matches(data, {"symbol": "helper"})
|
||||
assert location_matches(data, {"repo": "Scribe", "symbol": "helper"})
|
||||
@@ -101,7 +102,8 @@ def test_blank_recorded_part_does_not_match_a_requested_one():
|
||||
def test_jsonpath_filters_within_one_locations_entry():
|
||||
expr = location_jsonpath({"repo": "Scribe", "symbol": "helper"})
|
||||
assert expr.startswith("$.locations[*] ? (")
|
||||
assert '@.repo == "Scribe"' in expr
|
||||
# repo: anchored, case-insensitive (#2874) — mirrors location_matches.
|
||||
assert '@.repo like_regex "^Scribe$" flag "i"' in expr
|
||||
assert '@.symbol == "helper"' in expr
|
||||
assert " && " in expr
|
||||
|
||||
@@ -121,8 +123,9 @@ def test_jsonpath_quotes_values_as_json_literals():
|
||||
"""A quote in a repo name must stay inside the literal, not end it."""
|
||||
nasty = 'we"ird'
|
||||
expr = location_jsonpath({"repo": nasty})
|
||||
assert json.dumps(nasty) in expr
|
||||
assert json.dumps("^" + nasty + "$") in expr # the regex is a JSON literal too
|
||||
assert '\\"' in expr
|
||||
assert json.dumps(nasty) in location_jsonpath({"symbol": nasty})
|
||||
|
||||
|
||||
def test_jsonpath_emits_parts_in_a_fixed_key_order():
|
||||
|
||||
Reference in New Issue
Block a user