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
32 changes: 24 additions & 8 deletions hydra-gates/scripts/lib/check_sig_floor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@
Without a floor file the gate is NOT APPLICABLE (exit 4) before any tool is
loaded or any base resolved.

The 5-star checks (half of every 4-star limit, gate 122's five-star profile)
are reported next to the 4-star ones and never block.
The 5-star checks (gate 122's five-star profile, derived from the v18.1 4-star
limits) are reported next to the 4-star ones and never block.

`write` never lowers a floor. When the floor file already exists, every check
it lists stays in it, also one the current limits no longer meet (the 4-star
limits moved from v17.0 to v18.1, stricter on coupling and independence). Such
a check is printed as floored but missed, so the change of status is visible;
a check stays inherited until development meets it again.

When the head meets checks the committed floor does not list, `--proposed`
receives the raised floor file, for the workflow to offer as a pull request.
Expand Down Expand Up @@ -250,6 +256,7 @@ def floor_document(app, labels):
"Generated by check_sig_floor.py write; raised by the workflow, never lowered by hand.",
"schema": SCHEMA,
"profile": "four-star",
"limits": sig.GUIDANCE,
"tools": {"lizard": sig.LIZARD_VERSION},
"unit_reader": sig.UNIT_READER_VERSION,
"measured_at": head,
Expand Down Expand Up @@ -327,8 +334,8 @@ def cell(r):
return "n/a" if r is None else sig.pct(r["share"]) + ("" if r["ok"] else " ✗")

out = [f"## SIG score floor: {app_name}", "",
"Every 4-star check in the floor must stay met. 5-star (half of each 4-star limit) "
"is reported only and never blocks. ✗ marks a miss.", "",
f"Every 4-star check in the floor must stay met ({sig.GUIDANCE}). 5-star (derived from the "
"4-star limits) is reported only and never blocks. ✗ marks a miss.", "",
"| check | base | head | 4-star limit | floored | 5-star |", "|---|---|---|---|---|---|"]
for label in sorted(set(head4) | set(floor) | set(base4 or {})):
h, b, h5 = head4.get(label), (base4 or {}).get(label), head5.get(label)
Expand All @@ -349,7 +356,7 @@ def cell(r):
[f"- {lbl}: {why}" for lbl, why in inherited]
five_missed = sorted(lbl for lbl, r in head5.items() if not r["ok"])
if five_missed:
out += ["", f"5-star findings (not blocking): {len(five_missed)} check(s) above half the 4-star limit: "
out += ["", f"5-star findings (not blocking): {len(five_missed)} check(s) miss the 5-star limit: "
+ ", ".join(five_missed)]
if proposed:
out += ["", "The head meets checks the committed floor does not list yet: " + ", ".join(proposed)
Expand All @@ -370,13 +377,22 @@ def cmd_write(args, lizard):
print(f"{GATE}: no measured source file in this repository, so there is no floor to write")
return 4
rows = check_rows(report, "four-star")
met = [lbl for lbl, r in rows.items() if r["ok"]]
met = {lbl for lbl, r in rows.items() if r["ok"]}
path = os.path.join(args.app, args.floor)
# A floored check that left the measured scope (a sigrid.yaml change) leaves the file too.
kept = set(parse_floor(sig.read_text(path), args.floor)) & set(rows) if os.path.isfile(path) else set()
missed = sorted(kept - met)
for lbl in missed:
r = rows[lbl]
cmp = "<" if r["higher_is_better"] else ">"
print(f" floored but missed at the current limits, kept in the floor: {lbl}: "
f"{sig.pct(r['share'])} {cmp} limit {sig.pct(r['limit'])}")
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "w") as fh:
json.dump(floor_document(args.app, met), fh, indent=1)
json.dump(floor_document(args.app, met | kept), fh, indent=1)
fh.write("\n")
print(f"{GATE}: wrote {args.floor}: {len(met)} of {len(rows)} 4-star checks met and floored")
print(f"{GATE}: wrote {args.floor}: {len(met)} of {len(rows)} 4-star checks met, "
f"{len(met | kept)} floored ({len(missed)} floored but missed)")
return 0


Expand Down
419 changes: 372 additions & 47 deletions hydra-gates/scripts/lib/check_sig_maintainability.py

Large diffs are not rendered by default.

30 changes: 25 additions & 5 deletions hydra-gates/scripts/lib/test_check_sig_floor.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,26 @@ def test_the_floor_is_the_met_four_star_checks_under_gate_122_names(self):
self.assertEqual(self.repo.floor_file()["checks"], met)
self.assertIn("php unit_size >60", met)
self.assertEqual(self.repo.floor_file()["profile"], "four-star")
self.assertIn("v18.1", self.repo.floor_file()["limits"])

def test_re_recording_never_lowers_the_floor_and_names_the_missed_check(self):
# A check floored under older limits that the current limits miss stays.
wide = [m.replace("(int $p0)", "(int $p0, int $q, int $r)") for m in SMALL[:3]]
self.repo.write("lib/Service/Small.php", php_class("Small", wide + SMALL[3:]))
self.repo.commit("three wide units")
before = self.repo.floor_file()["checks"]
self.assertIn("php unit_interfacing >2", before)
rc, out = run("write", self.repo.dir)
self.assertEqual(rc, 0, out)
self.assertEqual(self.repo.floor_file()["checks"], before)
self.assertIn("floored but missed at the current limits, kept in the floor: php unit_interfacing >2", out)
self.assertIn("(1 floored but missed)", out)

def test_re_recording_drops_a_check_that_left_the_measured_scope(self):
self.repo.set_floor(self.repo.floor_file()["checks"] + ["python duplication"])
rc, out = run("write", self.repo.dir)
self.assertEqual(rc, 0, out)
self.assertNotIn("python duplication", self.repo.floor_file()["checks"])

def test_check_rows_agree_with_gate_122_checks(self):
self.repo.write("lib/Service/Big.php", php_class("Big", [php_method("huge", lines=70, tag="h")]))
Expand Down Expand Up @@ -241,10 +261,10 @@ def test_sigrid_yaml_excludes_are_honoured(self):

class FiveStar(FloorCase):
def test_a_five_star_miss_is_reported_and_never_blocks(self):
# One of twelve equal units takes three parameters: 8.3% of the code,
# above the 5-star 7.5% and below the 4-star 15%.
# One of seven equal units takes three parameters: 14.3% of the code,
# above the 5-star 12.5% and below the 4-star 15.4%.
wide = [SMALL[0].replace("(int $p0)", "(int $p0, int $q, int $r)")]
self.repo.write("lib/Service/Small.php", php_class("Small", wide + SMALL[1:]))
self.repo.write("lib/Service/Small.php", php_class("Small", wide + SMALL[1:7]))
md = os.path.join(self.repo.dir, "..", os.path.basename(self.repo.dir) + ".md")
rc, out = self.check("--md", md)
try:
Expand Down Expand Up @@ -346,7 +366,7 @@ def report(self, size, dup, coupling, hidden):
"component_independence": {"hidden_share": hidden}}}}

def test_a_share_equal_to_the_limit_meets_it(self):
rows = floor.check_rows(self.report(.471, .056, .100, .937), "four-star")
rows = floor.check_rows(self.report(.480, .058, .097, .945), "four-star")
for label in ("php unit_size >15", "php duplication", "php module_coupling >10",
"php component_independence"):
self.assertTrue(rows[label]["ok"], label)
Expand All @@ -358,7 +378,7 @@ def test_an_equal_share_is_not_worse_in_either_direction(self):
self.assertTrue(floor.worse(row, dict(row, share=.6 if better_high else .4)))

def test_just_past_the_limit_misses_it(self):
rows = floor.check_rows(self.report(.4711, .0561, .1001, .9369), "four-star")
rows = floor.check_rows(self.report(.4801, .0581, .0971, .9449), "four-star")
for label in ("php unit_size >15", "php duplication", "php module_coupling >10",
"php component_independence"):
self.assertFalse(rows[label]["ok"], label)
Expand Down
Loading
Loading