From 6b67c18242d97c0fb0298669a0c58bf3a67f9ee2 Mon Sep 17 00:00:00 2001 From: Jasper Duizendstra Date: Sun, 8 Nov 2026 11:20:06 +0100 Subject: [PATCH 1/6] Name a row of the wrong width in every reader (#43) check_review.py's Scorecard dropped a row that was not two cells wide and then reported the row as missing; render_scorecard.py passed such a row through uncorrected; score_seeds.py skipped a wrong-width index row, so the seed score could undercount without a word. All three now fail the row by name, through one helper, with the escape hint PROMPT.md states: a literal | inside a cell is written \|. The Scorecard row is reported once, by check_scorecard only. Fixtures for each reader in test_scripts.py; MANIFEST regenerated. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 8 ++++++-- scripts/MANIFEST | 8 ++++---- scripts/check_review.py | 35 +++++++++++++++++++++++++++++------ scripts/render_scorecard.py | 8 +++++++- scripts/score_seeds.py | 11 +++++++++-- scripts/test_scripts.py | 35 ++++++++++++++++++++++++++++++++++- 6 files changed, 89 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d97936..a63b343 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,8 +24,12 @@ file to it (#39). Two holes the checker had are closed: a `Lenses run` claim higher than the lens sections present now fails instead of being corrected away (#50), and an Evidence citation must be a trailing part of a supplied path, not just share its basename (#49). Table rows split only -on unescaped pipes (#43). The checks pass their failure list explicitly -(#47), and `scripts/MANIFEST` pins each script's hash, gated by +on unescaped pipes (#43), and a row of the wrong width now fails by +name in every reader: `check_review.py`'s Scorecard, which used to drop +it and report a missing row instead, `render_scorecard.py`, which passed +it through uncorrected, and `score_seeds.py`, which skipped it; each +failure says a literal `|` is written `\|`. The checks pass their +failure list explicitly (#47), and `scripts/MANIFEST` pins each script's hash, gated by `check.py` (#46). Each of these comes with a regression test in `scripts/test_scripts.py`, which CI runs. diff --git a/scripts/MANIFEST b/scripts/MANIFEST index e3b07da..ade6943 100644 --- a/scripts/MANIFEST +++ b/scripts/MANIFEST @@ -1,5 +1,5 @@ f3d35ca8359d423aed41693095ca8eef9108e9c510824b3b84e81f0ee3008ba7 check.py -4dcec07435a68c47c230eb27d70595bd76b44a401c6960e66beb514cd8c03a05 check_review.py -cad6924afe9884328306dd13a20d5857555fe4868d831262eac1cc3d0783a382 render_scorecard.py -0db5a9cb54c36cd6953208e87387383f056017fa2e0a7ebd99c46cb9783e9122 score_seeds.py -86c632bc45e16c539754c8c9de4fab234e5f13e59a74c0405fa2bfb8a93ff3f6 test_scripts.py +d5d5ded28fa6e00beafe6fb40b949fdbe9de058cb3f2ffeb08d1a8362d90573a check_review.py +3878730b4228b6b978ecba28addb42d076b8efe86ab72fec8c61065d56aeb94b render_scorecard.py +7ec304443a9d3d8db6474e1e9a8be4531bf33aef3b79915b75cbf810cb1df33b score_seeds.py +ea37307e8d4fd0adfc0ade137044749db2a8f91fd74d4e776b3545f670ca5807 test_scripts.py diff --git a/scripts/check_review.py b/scripts/check_review.py index 4a580c8..d685f1c 100755 --- a/scripts/check_review.py +++ b/scripts/check_review.py @@ -87,6 +87,19 @@ def unescape(cell): return plain(cell.replace('\\|', '|')) +def wrong_width(where, cells, want): + """The failure for a table row that is not `want` cells wide. + + Every reader of a mandated table names a row of the wrong width rather + than dropping it: an unescaped `|` inside a cell ends it (PROMPT.md, the + literal-pipe rule), and a dropped row surfaced later as "Scorecard has no + 'Governors' row", or as nothing at all (issue #43, D1). + """ + first = unescape(cells[0]) if cells else '' + return (f'{where} row {first[:40]!r} is {len(cells)} columns, expected ' + f'{want}: a literal | inside a cell is written \\|') + + def table_rows(body): """Raw cells of every table row in a body, header and rule rows dropped.""" rows = [] @@ -451,10 +464,20 @@ def lenses_run_row(review, vocab): return (int(m.group(1)), value) if m else None -def scorecard_cells(table): - """{metric: value} for every two-cell row of a Scorecard table body.""" - return {unescape(cells[0]): unescape(cells[1]) - for cells in table_rows(table) if len(cells) == 2} +def scorecard_cells(table, failures=None): + """{metric: value} for every two-cell row of a Scorecard table body. + + A row of any other width is named in `failures`, when given. Only + check_scorecard passes it; lenses_run_row reads the same table and does + not, so each such row is reported once per review. + """ + card = {} + for cells in table_rows(table): + if len(cells) == 2: + card[unescape(cells[0])] = unescape(cells[1]) + elif failures is not None: + failures.append(wrong_width('Scorecard', cells, 2)) + return card def check_lenses(review, lenses, scope, vocab, failures): @@ -535,7 +558,7 @@ def index_rows(review, vocab, failures): if unescape(cells[0]) != 'ID'] for row in rows: if len(row) != 8: - failures.append(f'index row is {len(row)} columns, expected 8: {row[:1]}') + failures.append(wrong_width('index', row, 8)) continue prefix = vocab['id_prefixes'].get(lens_name(row[1])) if not re.fullmatch(r'[A-Z0-9]+-\d+', row[0]) or ( @@ -571,7 +594,7 @@ def check_scorecard(review, rows, prompt_path, vocab, failures): if table is None: failures.append('no "### Scorecard" section') return - card = scorecard_cells(table) + card = scorecard_cells(table, failures) version = instrument_version(review) if version is None: diff --git a/scripts/render_scorecard.py b/scripts/render_scorecard.py index 5911e09..ea8d5ee 100755 --- a/scripts/render_scorecard.py +++ b/scripts/render_scorecard.py @@ -127,7 +127,13 @@ def fix_row(line): # Escape-aware, as check_review.py parses it: a value carrying a # literal `\|` is one cell, not two (cycle-6 VAR-3, issue #43). cells = check_review.split_row(line) - if cells is None or len(cells) != 2: + if cells is None: + return line + if len(cells) != 2: + # Named, not passed through: a row this script cannot read is a + # row it silently left uncorrected (issue #43, D1). + if not all(re.match(r'^:?-*:?$', c) for c in cells): + refused.append(check_review.wrong_width('Scorecard', cells, 2)) return line raw_key, value = cells key = check_review.unescape(raw_key) diff --git a/scripts/score_seeds.py b/scripts/score_seeds.py index 4fe41fa..816349d 100755 --- a/scripts/score_seeds.py +++ b/scripts/score_seeds.py @@ -35,15 +35,22 @@ def findings(path): body = check_review.section(open(path).read(), 'FINDINGS INDEX', level=2) if body is None: sys.exit('no FINDINGS INDEX in review') - out = [] + out, wrong = [], [] for cells in check_review.table_rows(body): c = [check_review.unescape(x) for x in cells] - if len(c) != 8 or c[0] == 'ID': + if c and c[0] == 'ID': + continue + if len(c) != 8: + # Named, not skipped: a skipped row is a finding the score never + # saw, so the seed count could undercount silently (issue #43, D1). + wrong.append(check_review.wrong_width('index', cells, 8)) continue m = re.search(r':(\d+)(?:[-–](\d+))?', c[3]) if m: out.append((c[0], c[1], int(m.group(1)), int(m.group(2) or m.group(1)), c[4], c[5], c[6])) + if wrong: + sys.exit('\n'.join(wrong)) return out diff --git a/scripts/test_scripts.py b/scripts/test_scripts.py index 1d317a0..400baf0 100644 --- a/scripts/test_scripts.py +++ b/scripts/test_scripts.py @@ -212,7 +212,40 @@ def test_43_an_unescaped_pipe_still_fails(self): review = self.write('bare-pipes.md', text) code, out = self.check(review, EXAMPLE_ARTIFACT) self.assertEqual(code, 1, out) - self.assertIn('index row is 10 columns, expected 8', out) + self.assertIn("index row 'SUB-1' is 10 columns, expected 8: " + "a literal | inside a cell is written \\|", out) + + # -- issue #43 D1: every reader names a row of the wrong width --------- + + def with_bare_scorecard_pipe(self): + text = read(EXAMPLE) + governors = '· 🐍 Library/Framework ·' + self.assertIn(governors, text) + return text.replace(governors, '· 🐍 Library | Framework ·', 1) + + def test_43_a_bare_pipe_in_the_scorecard_is_named_once(self): + review = self.write('scorecard-pipe.md', self.with_bare_scorecard_pipe()) + code, out = self.check(review, EXAMPLE_ARTIFACT) + self.assertEqual(code, 1, out) + named = "Scorecard row 'Governors' is 3 columns, expected 2" + self.assertEqual(out.count(named), 1, out) + + def test_43_render_scorecard_refuses_a_wrong_width_row(self): + review = self.write('scorecard-pipe.md', self.with_bare_scorecard_pipe()) + code, out = run('render_scorecard.py', review) + self.assertEqual(code, 2, out) + self.assertIn("REFUSED: Scorecard row 'Governors' is 3 columns, expected 2", out) + + def test_43_score_seeds_names_a_wrong_width_row(self): + claim = '| SUB-2 | Subtract | 1 | semver-2.0.0-seeded.md:84-85 | Minor | Skip:Cobra | Clause 7' + text = read(SEEDED) + self.assertIn(claim, text) + review = self.write('seeded-pipe.md', text.replace( + claim, claim.replace('Clause 7', 'Clause | 7'), 1)) + code, out = run('score_seeds.py', review, '--seeds', + os.path.join(ROOT, 'calibration', 'seeds.md')) + self.assertNotEqual(code, 0, out) + self.assertIn("index row 'SUB-2' is 9 columns, expected 8", out) # -- issue #47: no failure state survives between calls ---------------- From 1ef0f95876495107b1b7cd0d0272ee6065bda31f Mon Sep 17 00:00:00 2001 From: Jasper Duizendstra Date: Sun, 8 Nov 2026 11:26:41 +0100 Subject: [PATCH 2/6] Name header, rule and empty rows of the wrong width too (#43) The first commit named data rows only. A rule row of any width and a header row of any width were still dropped unread, and `^:?-*:?$` matched an empty cell, so a row of empty cells was taken for a rule row. Rule rows now need a dash (RULE_CELL), rule_rows() returns what table_rows() drops so each reader can name one of the wrong width, and an index header is dropped only at width 8. The pipe hint is given only to a row that is too wide. The row with no closing pipe is a different class, left and filed as #64. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 8 +++-- scripts/MANIFEST | 8 ++--- scripts/check_review.py | 43 +++++++++++++++++++++--- scripts/render_scorecard.py | 6 ++-- scripts/score_seeds.py | 6 ++-- scripts/test_scripts.py | 67 ++++++++++++++++++++++++++++++++++++- 6 files changed, 122 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a63b343..81688b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,8 +27,12 @@ a supplied path, not just share its basename (#49). Table rows split only on unescaped pipes (#43), and a row of the wrong width now fails by name in every reader: `check_review.py`'s Scorecard, which used to drop it and report a missing row instead, `render_scorecard.py`, which passed -it through uncorrected, and `score_seeds.py`, which skipped it; each -failure says a literal `|` is written `\|`. The checks pass their +it through uncorrected, and `score_seeds.py`, which skipped it. That +includes header and rule rows, which were dropped at any width, and a +row of empty cells, which was taken for a rule row. A row too wide says +a literal `|` is written `\|`. One sibling is left: a row with no +closing `|`, which GitHub renders but no reader treats as a row; it is +older than this and is filed as #64. The checks pass their failure list explicitly (#47), and `scripts/MANIFEST` pins each script's hash, gated by `check.py` (#46). Each of these comes with a regression test in `scripts/test_scripts.py`, which CI runs. diff --git a/scripts/MANIFEST b/scripts/MANIFEST index ade6943..8243124 100644 --- a/scripts/MANIFEST +++ b/scripts/MANIFEST @@ -1,5 +1,5 @@ f3d35ca8359d423aed41693095ca8eef9108e9c510824b3b84e81f0ee3008ba7 check.py -d5d5ded28fa6e00beafe6fb40b949fdbe9de058cb3f2ffeb08d1a8362d90573a check_review.py -3878730b4228b6b978ecba28addb42d076b8efe86ab72fec8c61065d56aeb94b render_scorecard.py -7ec304443a9d3d8db6474e1e9a8be4531bf33aef3b79915b75cbf810cb1df33b score_seeds.py -ea37307e8d4fd0adfc0ade137044749db2a8f91fd74d4e776b3545f670ca5807 test_scripts.py +118cae972e21c18be2f60e1e7e3afcf72f6a3b322621586f5cc78b384f14c544 check_review.py +a4476de746b4822f1d4970a863ea3dabcb5f5fba5d8008f0b784d98fa91488c2 render_scorecard.py +3c41fc8b99aa13c6e549abea56c0efb9caf11da9759c1cdfaa1ae52f5d0243a0 score_seeds.py +0c4e75ec61b55b64206e75e4e35ef02af620bd29982350e3509e24a658229807 test_scripts.py diff --git a/scripts/check_review.py b/scripts/check_review.py index d685f1c..55a3a0b 100755 --- a/scripts/check_review.py +++ b/scripts/check_review.py @@ -96,8 +96,31 @@ def wrong_width(where, cells, want): 'Governors' row", or as nothing at all (issue #43, D1). """ first = unescape(cells[0]) if cells else '' + # The hint only where it is the likely cause: a row too narrow has lost a + # cell, and no pipe escape restores one. + hint = ': a literal | inside a cell is written \\|' if len(cells) > want else '' return (f'{where} row {first[:40]!r} is {len(cells)} columns, expected ' - f'{want}: a literal | inside a cell is written \\|') + f'{want}{hint}') + + +# A rule row (`|---|:--:|`) is one whose every cell is dashes with optional +# colons. At least one dash: `^:?-*:?$` also matched an empty cell, so a row +# of empty cells was dropped as a rule row and never read (issue #43, D1). +RULE_CELL = re.compile(r'^:?-+:?$') + + +def is_rule(cells): + return all(RULE_CELL.match(c) for c in cells) + + +def rule_rows(body): + """Cells of every rule row in a body: the rows table_rows drops. + + GFM does not render a table whose rule row is not the header's width, so + a reader that drops rule rows must still name one of the wrong width. + """ + return [cells for cells in map(split_row, body.split('\n')) + if cells is not None and is_rule(cells)] def table_rows(body): @@ -105,7 +128,7 @@ def table_rows(body): rows = [] for line in body.split('\n'): cells = split_row(line) - if cells is None or all(re.match(r'^:?-*:?$', c) for c in cells): + if cells is None or is_rule(cells): continue rows.append(cells) return rows @@ -477,6 +500,9 @@ def scorecard_cells(table, failures=None): card[unescape(cells[0])] = unescape(cells[1]) elif failures is not None: failures.append(wrong_width('Scorecard', cells, 2)) + if failures is not None: + failures.extend(wrong_width('Scorecard', cells, 2) + for cells in rule_rows(table) if len(cells) != 2) return card @@ -554,8 +580,17 @@ def index_rows(review, vocab, failures): if body is None: failures.append('no "## FINDINGS INDEX" section') return [] - rows = [[unescape(c) for c in cells] for cells in table_rows(body) - if unescape(cells[0]) != 'ID'] + # The header and rule rows are dropped, but only once they are the right + # width: either one of the wrong width was dropped unnamed (issue #43, D1). + failures.extend(wrong_width('index', cells, 8) + for cells in rule_rows(body) if len(cells) != 8) + rows = [] + for cells in table_rows(body): + if unescape(cells[0]) == 'ID': + if len(cells) != 8: + failures.append(wrong_width('index', cells, 8)) + continue + rows.append([unescape(c) for c in cells]) for row in rows: if len(row) != 8: failures.append(wrong_width('index', row, 8)) diff --git a/scripts/render_scorecard.py b/scripts/render_scorecard.py index ea8d5ee..3fbea44 100755 --- a/scripts/render_scorecard.py +++ b/scripts/render_scorecard.py @@ -131,9 +131,9 @@ def fix_row(line): return line if len(cells) != 2: # Named, not passed through: a row this script cannot read is a - # row it silently left uncorrected (issue #43, D1). - if not all(re.match(r'^:?-*:?$', c) for c in cells): - refused.append(check_review.wrong_width('Scorecard', cells, 2)) + # row it silently left uncorrected, and a rule row of the wrong + # width means GFM renders no table at all (issue #43, D1). + refused.append(check_review.wrong_width('Scorecard', cells, 2)) return line raw_key, value = cells key = check_review.unescape(raw_key) diff --git a/scripts/score_seeds.py b/scripts/score_seeds.py index 816349d..7dd431c 100755 --- a/scripts/score_seeds.py +++ b/scripts/score_seeds.py @@ -35,10 +35,12 @@ def findings(path): body = check_review.section(open(path).read(), 'FINDINGS INDEX', level=2) if body is None: sys.exit('no FINDINGS INDEX in review') - out, wrong = [], [] + out = [] + wrong = [check_review.wrong_width('index', cells, 8) + for cells in check_review.rule_rows(body) if len(cells) != 8] for cells in check_review.table_rows(body): c = [check_review.unescape(x) for x in cells] - if c and c[0] == 'ID': + if c and c[0] == 'ID' and len(c) == 8: continue if len(c) != 8: # Named, not skipped: a skipped row is a finding the score never diff --git a/scripts/test_scripts.py b/scripts/test_scripts.py index 400baf0..5df47f3 100644 --- a/scripts/test_scripts.py +++ b/scripts/test_scripts.py @@ -236,6 +236,71 @@ def test_43_render_scorecard_refuses_a_wrong_width_row(self): self.assertEqual(code, 2, out) self.assertIn("REFUSED: Scorecard row 'Governors' is 3 columns, expected 2", out) + def scorecard_mutant(self, old, new): + text = read(EXAMPLE) + self.assertIn(old, text) + return self.write('scorecard-mutant.md', text.replace(old, new, 1)) + + def test_43_a_rule_row_of_the_wrong_width_is_named(self): + review = self.scorecard_mutant('| Metric | Value |\n|--------|-------|', + '| Metric | Value |\n|--------|-------|-------|') + named = "Scorecard row '--------' is 3 columns, expected 2" + code, out = self.check(review, EXAMPLE_ARTIFACT) + self.assertEqual(code, 1, out) + self.assertEqual(out.count(named), 1, out) + code, out = run('render_scorecard.py', review) + self.assertEqual(code, 2, out) + self.assertIn(f'REFUSED: {named}', out) + + def test_43_a_row_of_empty_cells_is_not_a_rule_row(self): + # Eight empty cells is the index's width, so only the rule-row + # pattern decides whether it is read: `^:?-*:?$` dropped it unread. + rule = '|----|------|-------|---------|----------|---------|----------------------|------------|\n' + text = read(EXAMPLE) + self.assertIn(rule, text) + review = self.write('empty-row.md', text.replace(rule, rule + '|' + ' |' * 8 + '\n', 1)) + code, out = self.check(review, EXAMPLE_ARTIFACT) + self.assertEqual(code, 1, out) + self.assertIn('index rows 18 |', out) + self.assertIn("FAIL: : Lens '' is not a lens or W5H1", out) + + def test_43_an_index_rule_row_of_the_wrong_width_is_named(self): + rule = '|----|------|-------|---------|----------|---------|----------------------|------------|' + named = "index row '----' is 9 columns, expected 8" + text = read(SEEDED) + self.assertIn(rule, text) + review = self.write('index-rule.md', text.replace(rule, rule + '---|', 1)) + code, out = self.check(review, SEEDED_ARTIFACT) + self.assertEqual(code, 1, out) + self.assertEqual(out.count(named), 1, out) + code, out = run('score_seeds.py', review, '--seeds', + os.path.join(ROOT, 'calibration', 'seeds.md')) + self.assertNotEqual(code, 0, out) + self.assertIn(named, out) + + def test_43_a_narrow_row_gets_no_pipe_hint(self): + review = self.scorecard_mutant('|--------|-------|\n', + '|--------|-------|\n| Spare |\n') + code, out = self.check(review, EXAMPLE_ARTIFACT) + self.assertEqual(code, 1, out) + line = [l for l in out.splitlines() if "Scorecard row 'Spare'" in l] + self.assertEqual(len(line), 1, out) + self.assertTrue(line[0].rstrip().endswith('is 1 columns, expected 2'), out) + + def test_43_an_index_header_of_the_wrong_width_is_named(self): + header = '| ID | Lens | Cycle | Line(s) | Severity | Verdict | Claim (one sentence) | Confidence |' + for review_path, artifact in ((EXAMPLE, EXAMPLE_ARTIFACT), (SEEDED, SEEDED_ARTIFACT)): + text = read(review_path) + self.assertIn(header, text) + review = self.write('header.md', text.replace(header, header + ' Extra |', 1)) + code, out = self.check(review, artifact) + self.assertEqual(code, 1, out) + self.assertIn("index row 'ID' is 9 columns, expected 8", out) + code, out = run('score_seeds.py', review, '--seeds', + os.path.join(ROOT, 'calibration', 'seeds.md')) + self.assertNotEqual(code, 0, out) + self.assertIn("index row 'ID' is 9 columns, expected 8", out) + def test_43_score_seeds_names_a_wrong_width_row(self): claim = '| SUB-2 | Subtract | 1 | semver-2.0.0-seeded.md:84-85 | Minor | Skip:Cobra | Clause 7' text = read(SEEDED) @@ -454,7 +519,7 @@ def entry_tables(self): if current is None: current = [] tables.append(current) - if not all(re.match(r'^:?-*:?$', c) for c in cells): + if not check_review.is_rule(cells): current.append([check_review.unescape(c) for c in cells]) self.assertEqual(len(tables), 2, tables) return [rows[1:] for rows in tables] From df1e985d2dcdadec5390c973d3c0e12d9decc0e7 Mon Sep 17 00:00:00 2001 From: Jasper Duizendstra Date: Sun, 8 Nov 2026 11:35:38 +0100 Subject: [PATCH 3/6] Treat only the line after a table's header as its rule row (#43) A later row of dashes was dropped as a rule row by all three readers, though GitHub shows it as a data row. table_parts() now counts the rule row per table, and every reader names a stray by its position. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 ++- scripts/MANIFEST | 8 +++--- scripts/check_review.py | 52 +++++++++++++++++++++++++++++-------- scripts/render_scorecard.py | 3 +++ scripts/score_seeds.py | 1 + scripts/test_scripts.py | 44 +++++++++++++++++++++++++++++++ 6 files changed, 96 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81688b6..3d53a54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,9 @@ name in every reader: `check_review.py`'s Scorecard, which used to drop it and report a missing row instead, `render_scorecard.py`, which passed it through uncorrected, and `score_seeds.py`, which skipped it. That includes header and rule rows, which were dropped at any width, and a -row of empty cells, which was taken for a rule row. A row too wide says +row of empty cells, which was taken for a rule row. Only the line after +a table's header is its rule row; a later row of dashes, which GitHub +shows as data, is named too. A row too wide says a literal `|` is written `\|`. One sibling is left: a row with no closing `|`, which GitHub renders but no reader treats as a row; it is older than this and is filed as #64. The checks pass their diff --git a/scripts/MANIFEST b/scripts/MANIFEST index 8243124..11f2215 100644 --- a/scripts/MANIFEST +++ b/scripts/MANIFEST @@ -1,5 +1,5 @@ f3d35ca8359d423aed41693095ca8eef9108e9c510824b3b84e81f0ee3008ba7 check.py -118cae972e21c18be2f60e1e7e3afcf72f6a3b322621586f5cc78b384f14c544 check_review.py -a4476de746b4822f1d4970a863ea3dabcb5f5fba5d8008f0b784d98fa91488c2 render_scorecard.py -3c41fc8b99aa13c6e549abea56c0efb9caf11da9759c1cdfaa1ae52f5d0243a0 score_seeds.py -0c4e75ec61b55b64206e75e4e35ef02af620bd29982350e3509e24a658229807 test_scripts.py +a791debf3e2af9bb057126fd31b9054ec3c8e53219c627b1ade7d0a1e3e352fb check_review.py +0e4cbbeecd19d1c5491302873ee531de7f2a67cfe6c8ee5704dc58f3f1e8c2b0 render_scorecard.py +b433e25ff3bf2b2d97a50cc07017cababb07c8ee868980ded67d1dca94f91530 score_seeds.py +888169326ae91e567b28eb94f114fba0005ac27aa39c8f5fa0400da69862c1a0 test_scripts.py diff --git a/scripts/check_review.py b/scripts/check_review.py index 55a3a0b..3cea629 100755 --- a/scripts/check_review.py +++ b/scripts/check_review.py @@ -113,25 +113,53 @@ def is_rule(cells): return all(RULE_CELL.match(c) for c in cells) +def table_parts(body): + """(rows, rules, strays) of the tables in a body. + + The rule row is the line straight after a table's header: GFM reads only + that one as the rule. `rules` holds those, `strays` every other row whose + cells are all dashes, and `rows` everything else, header included. A stray + used to be dropped as a rule row wherever it sat; GFM renders it as a data + row, so a reader that dropped it read a table GitHub does not show (issue + #43, D1). + """ + rows, rules, strays = [], [], [] + at = 0 + for line in body.split('\n'): + cells = split_row(line) + if cells is None: + at = 0 + continue + if is_rule(cells): + (rules if at == 1 else strays).append(cells) + else: + rows.append(cells) + at += 1 + return rows, rules, strays + + def rule_rows(body): - """Cells of every rule row in a body: the rows table_rows drops. + """Cells of each table's rule row: the rows table_rows drops. GFM does not render a table whose rule row is not the header's width, so a reader that drops rule rows must still name one of the wrong width. """ - return [cells for cells in map(split_row, body.split('\n')) - if cells is not None and is_rule(cells)] + return table_parts(body)[1] + + +def stray_rules(where, body): + """The failure for each all-dash row that is not a table's rule row.""" + return [f'{where} row {unescape(cells[0])[:40]!r} is all dashes below the ' + f'rule row: GitHub shows it as a data row' + for cells in table_parts(body)[2]] def table_rows(body): - """Raw cells of every table row in a body, header and rule rows dropped.""" - rows = [] - for line in body.split('\n'): - cells = split_row(line) - if cells is None or is_rule(cells): - continue - rows.append(cells) - return rows + """Raw cells of every table row in a body; rule rows and strays dropped. + + A caller that reads a mandated table names the strays with stray_rules(). + """ + return table_parts(body)[0] def outside_fences(lines): @@ -503,6 +531,7 @@ def scorecard_cells(table, failures=None): if failures is not None: failures.extend(wrong_width('Scorecard', cells, 2) for cells in rule_rows(table) if len(cells) != 2) + failures.extend(stray_rules('Scorecard', table)) return card @@ -584,6 +613,7 @@ def index_rows(review, vocab, failures): # width: either one of the wrong width was dropped unnamed (issue #43, D1). failures.extend(wrong_width('index', cells, 8) for cells in rule_rows(body) if len(cells) != 8) + failures.extend(stray_rules('index', body)) rows = [] for cells in table_rows(body): if unescape(cells[0]) == 'ID': diff --git a/scripts/render_scorecard.py b/scripts/render_scorecard.py index 3fbea44..5847352 100755 --- a/scripts/render_scorecard.py +++ b/scripts/render_scorecard.py @@ -203,6 +203,9 @@ def fix_row(line): return line table = '\n'.join(fix_row(line) for line in table.split('\n')) + # A stray is two cells wide, so fix_row reads it as a row named '---'; + # it is named here instead (issue #43, D1). + refused.extend(check_review.stray_rules('Scorecard', table)) refused.extend(f'instrument rejected: {f}' for f in failures) return '\n'.join(prefix + table.split('\n') + suffix), changes, notes, refused diff --git a/scripts/score_seeds.py b/scripts/score_seeds.py index 7dd431c..92d7f4f 100755 --- a/scripts/score_seeds.py +++ b/scripts/score_seeds.py @@ -38,6 +38,7 @@ def findings(path): out = [] wrong = [check_review.wrong_width('index', cells, 8) for cells in check_review.rule_rows(body) if len(cells) != 8] + wrong += check_review.stray_rules('index', body) for cells in check_review.table_rows(body): c = [check_review.unescape(x) for x in cells] if c and c[0] == 'ID' and len(c) == 8: diff --git a/scripts/test_scripts.py b/scripts/test_scripts.py index 5df47f3..42b57c9 100644 --- a/scripts/test_scripts.py +++ b/scripts/test_scripts.py @@ -278,6 +278,50 @@ def test_43_an_index_rule_row_of_the_wrong_width_is_named(self): self.assertNotEqual(code, 0, out) self.assertIn(named, out) + def test_43_a_dash_row_below_the_index_rule_is_named(self): + # Only the line after the header is a rule row; GitHub shows a later + # all-dash row as data, so dropping it read a table it does not show. + rule = '|----|------|-------|---------|----------|---------|----------------------|------------|' + text = read(SEEDED) + self.assertIn(rule, text) + for extra, first in (('|' + ' - |' * 8, '-'), (rule, '----')): + named = (f"index row {first!r} is all dashes below the rule row: " + f"GitHub shows it as a data row") + review = self.write('index-dashes.md', text.replace(rule, rule + '\n' + extra, 1)) + code, out = self.check(review, SEEDED_ARTIFACT) + self.assertEqual(code, 1, out) + self.assertEqual(out.count(named), 1, out) + code, out = run('score_seeds.py', review, '--seeds', + os.path.join(ROOT, 'calibration', 'seeds.md')) + self.assertNotEqual(code, 0, out) + self.assertIn(named, out) + + def test_43_each_table_has_its_own_rule_row(self): + # The rule row is counted from each table's header, not the body's + # first line: a second table's rule is not a stray. + sys.path.insert(0, SCRIPTS) + try: + import check_review + finally: + sys.path.pop(0) + body = '| A | B |\n|---|---|\n| 1 | 2 |\n\ntext\n\n| C | D |\n|---|---|\n| 3 | 4 |\n' + rows, rules, strays = check_review.table_parts(body) + self.assertEqual(len(rules), 2, (rules, strays)) + self.assertEqual(strays, []) + self.assertEqual(len(rows), 4, rows) + + def test_43_a_dash_row_in_the_scorecard_body_is_named(self): + review = self.scorecard_mutant('|--------|-------|\n', + '|--------|-------|\n| Spare | x |\n|---|---|\n') + named = ("Scorecard row '---' is all dashes below the rule row: " + "GitHub shows it as a data row") + code, out = self.check(review, EXAMPLE_ARTIFACT) + self.assertEqual(code, 1, out) + self.assertEqual(out.count(named), 1, out) + code, out = run('render_scorecard.py', review) + self.assertEqual(code, 2, out) + self.assertIn(f'REFUSED: {named}', out) + def test_43_a_narrow_row_gets_no_pipe_hint(self): review = self.scorecard_mutant('|--------|-------|\n', '|--------|-------|\n| Spare |\n') From b632fdfaaba2addba850bbc9402195719787bc51 Mon Sep 17 00:00:00 2001 From: Jasper Duizendstra Date: Sun, 8 Nov 2026 11:41:10 +0100 Subject: [PATCH 4/6] Name the three older table siblings, and say "1 column" (#43) The CHANGELOG said one sibling was left. Review found two more shapes and a duplicate-key case, all older than this; #64 is widened and #65 and #66 are filed, and the sentence names all three. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 13 +++++++------ scripts/MANIFEST | 4 ++-- scripts/check_review.py | 3 ++- scripts/test_scripts.py | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d53a54..c3425b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,12 +32,13 @@ includes header and rule rows, which were dropped at any width, and a row of empty cells, which was taken for a rule row. Only the line after a table's header is its rule row; a later row of dashes, which GitHub shows as data, is named too. A row too wide says -a literal `|` is written `\|`. One sibling is left: a row with no -closing `|`, which GitHub renders but no reader treats as a row; it is -older than this and is filed as #64. The checks pass their -failure list explicitly (#47), and `scripts/MANIFEST` pins each script's hash, gated by -`check.py` (#46). Each of these comes with a regression test in -`scripts/test_scripts.py`, which CI runs. +a literal `|` is written `\|`. Three siblings are older and filed: a +row GitHub renders that no reader reads, with no outer `|` or indented +(#64); a mandated table with no rule row or split by a blank line (#65); +and a Scorecard metric written twice (#66). The checks pass their +failure list explicitly (#47), and `scripts/MANIFEST` pins each +script's hash, gated by `check.py` (#46). Each of these comes with a +regression test in `scripts/test_scripts.py`, which CI runs. **Every published review now passes the checker in CI.** `examples/web-service.md` had only its Scorecard arithmetic checked, and diff --git a/scripts/MANIFEST b/scripts/MANIFEST index 11f2215..945b7a9 100644 --- a/scripts/MANIFEST +++ b/scripts/MANIFEST @@ -1,5 +1,5 @@ f3d35ca8359d423aed41693095ca8eef9108e9c510824b3b84e81f0ee3008ba7 check.py -a791debf3e2af9bb057126fd31b9054ec3c8e53219c627b1ade7d0a1e3e352fb check_review.py +9b806d42d45dd7db6cc515eee4920fcea3d1f391fd918c4b795973810365652d check_review.py 0e4cbbeecd19d1c5491302873ee531de7f2a67cfe6c8ee5704dc58f3f1e8c2b0 render_scorecard.py b433e25ff3bf2b2d97a50cc07017cababb07c8ee868980ded67d1dca94f91530 score_seeds.py -888169326ae91e567b28eb94f114fba0005ac27aa39c8f5fa0400da69862c1a0 test_scripts.py +f8c553dd25fe1576e3a819fc7df4e3617df2c42d2713e7f4be89916382a3a5fd test_scripts.py diff --git a/scripts/check_review.py b/scripts/check_review.py index 3cea629..96b7af2 100755 --- a/scripts/check_review.py +++ b/scripts/check_review.py @@ -99,7 +99,8 @@ def wrong_width(where, cells, want): # The hint only where it is the likely cause: a row too narrow has lost a # cell, and no pipe escape restores one. hint = ': a literal | inside a cell is written \\|' if len(cells) > want else '' - return (f'{where} row {first[:40]!r} is {len(cells)} columns, expected ' + columns = 'column' if len(cells) == 1 else 'columns' + return (f'{where} row {first[:40]!r} is {len(cells)} {columns}, expected ' f'{want}{hint}') diff --git a/scripts/test_scripts.py b/scripts/test_scripts.py index 42b57c9..38d68a0 100644 --- a/scripts/test_scripts.py +++ b/scripts/test_scripts.py @@ -329,7 +329,7 @@ def test_43_a_narrow_row_gets_no_pipe_hint(self): self.assertEqual(code, 1, out) line = [l for l in out.splitlines() if "Scorecard row 'Spare'" in l] self.assertEqual(len(line), 1, out) - self.assertTrue(line[0].rstrip().endswith('is 1 columns, expected 2'), out) + self.assertTrue(line[0].rstrip().endswith('is 1 column, expected 2'), out) def test_43_an_index_header_of_the_wrong_width_is_named(self): header = '| ID | Lens | Cycle | Line(s) | Severity | Verdict | Claim (one sentence) | Confidence |' From 65809dcf1b9071a27f58ecb8504ba2c0b5a8eec1 Mon Sep 17 00:00:00 2001 From: Jasper Duizendstra Date: Sun, 8 Nov 2026 11:46:39 +0100 Subject: [PATCH 5/6] Choose a table's header by position, not by its ID cell (#43) A data row whose first cell read ID was skipped as the header wherever it sat, by check_review.py and score_seeds.py alike. table_parts() now records each table's header as the row above its rule row, and a later row repeating it is named. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 5 +++-- scripts/MANIFEST | 6 +++--- scripts/check_review.py | 40 ++++++++++++++++++++++++++++++++-------- scripts/score_seeds.py | 10 ++++++++-- scripts/test_scripts.py | 21 ++++++++++++++++++++- 5 files changed, 66 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3425b2..1b66a4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,11 +31,12 @@ it through uncorrected, and `score_seeds.py`, which skipped it. That includes header and rule rows, which were dropped at any width, and a row of empty cells, which was taken for a rule row. Only the line after a table's header is its rule row; a later row of dashes, which GitHub -shows as data, is named too. A row too wide says +shows as data, is named too, and so is a +row below it that repeats the index header's `ID`. A row too wide says a literal `|` is written `\|`. Three siblings are older and filed: a row GitHub renders that no reader reads, with no outer `|` or indented (#64); a mandated table with no rule row or split by a blank line (#65); -and a Scorecard metric written twice (#66). The checks pass their +and a Scorecard metric written twice or not in the template (#66). The checks pass their failure list explicitly (#47), and `scripts/MANIFEST` pins each script's hash, gated by `check.py` (#46). Each of these comes with a regression test in `scripts/test_scripts.py`, which CI runs. diff --git a/scripts/MANIFEST b/scripts/MANIFEST index 945b7a9..333981f 100644 --- a/scripts/MANIFEST +++ b/scripts/MANIFEST @@ -1,5 +1,5 @@ f3d35ca8359d423aed41693095ca8eef9108e9c510824b3b84e81f0ee3008ba7 check.py -9b806d42d45dd7db6cc515eee4920fcea3d1f391fd918c4b795973810365652d check_review.py +e70ad015b88ccb003f668e1770c721fa5af11d15c031af8b41a8971a80921bf1 check_review.py 0e4cbbeecd19d1c5491302873ee531de7f2a67cfe6c8ee5704dc58f3f1e8c2b0 render_scorecard.py -b433e25ff3bf2b2d97a50cc07017cababb07c8ee868980ded67d1dca94f91530 score_seeds.py -f8c553dd25fe1576e3a819fc7df4e3617df2c42d2713e7f4be89916382a3a5fd test_scripts.py +a1620ac6b4ac072415873d575ba1358252ecc924bdcf431b8836ae1430276014 score_seeds.py +0ec41302796c051edf5f5cccd41aaa4496165e830ce5c17453497e9629cb6e31 test_scripts.py diff --git a/scripts/check_review.py b/scripts/check_review.py index 96b7af2..38a65c6 100755 --- a/scripts/check_review.py +++ b/scripts/check_review.py @@ -115,28 +115,47 @@ def is_rule(cells): def table_parts(body): - """(rows, rules, strays) of the tables in a body. + """(rows, rules, strays, heads) of the tables in a body. The rule row is the line straight after a table's header: GFM reads only that one as the rule. `rules` holds those, `strays` every other row whose cells are all dashes, and `rows` everything else, header included. A stray used to be dropped as a rule row wherever it sat; GFM renders it as a data row, so a reader that dropped it read a table GitHub does not show (issue - #43, D1). + #43, D1). `heads` holds each table's header, the row above its rule row, + by position: a reader that skips its header by content skipped a data row + that merely repeated it. """ - rows, rules, strays = [], [], [] - at = 0 + rows, rules, strays, heads = [], [], [], [] + at, first = 0, None for line in body.split('\n'): cells = split_row(line) if cells is None: at = 0 continue + if at == 0: + first = cells if is_rule(cells): - (rules if at == 1 else strays).append(cells) + if at == 1: + rules.append(cells) + heads.append(first) + else: + strays.append(cells) else: rows.append(cells) at += 1 - return rows, rules, strays + return rows, rules, strays, heads + + +def is_header(cells, heads): + """Whether these cells are, by identity, one of table_parts()'s heads.""" + return any(cells is head for head in heads) + + +def repeated_header(where, cells): + """The failure for a data row that repeats the header's first cell.""" + return (f'{where} row {unescape(cells[0])[:40]!r} repeats the header but is ' + f'not the table\'s header: GitHub shows it as a data row') def rule_rows(body): @@ -616,11 +635,16 @@ def index_rows(review, vocab, failures): for cells in rule_rows(body) if len(cells) != 8) failures.extend(stray_rules('index', body)) rows = [] - for cells in table_rows(body): - if unescape(cells[0]) == 'ID': + parts, _, _, heads = table_parts(body) + for cells in parts: + if is_header(cells, heads): if len(cells) != 8: failures.append(wrong_width('index', cells, 8)) continue + if unescape(cells[0]) == 'ID': + # Skipped by content, this row was a finding no check read. + failures.append(repeated_header('index', cells)) + continue rows.append([unescape(c) for c in cells]) for row in rows: if len(row) != 8: diff --git a/scripts/score_seeds.py b/scripts/score_seeds.py index 92d7f4f..07de1cc 100755 --- a/scripts/score_seeds.py +++ b/scripts/score_seeds.py @@ -39,9 +39,15 @@ def findings(path): wrong = [check_review.wrong_width('index', cells, 8) for cells in check_review.rule_rows(body) if len(cells) != 8] wrong += check_review.stray_rules('index', body) - for cells in check_review.table_rows(body): + parts, _, _, heads = check_review.table_parts(body) + for cells in parts: c = [check_review.unescape(x) for x in cells] - if c and c[0] == 'ID' and len(c) == 8: + if check_review.is_header(cells, heads): + if len(c) != 8: + wrong.append(check_review.wrong_width('index', cells, 8)) + continue + if c and c[0] == 'ID': + wrong.append(check_review.repeated_header('index', cells)) continue if len(c) != 8: # Named, not skipped: a skipped row is a finding the score never diff --git a/scripts/test_scripts.py b/scripts/test_scripts.py index 38d68a0..268e10d 100644 --- a/scripts/test_scripts.py +++ b/scripts/test_scripts.py @@ -305,11 +305,30 @@ def test_43_each_table_has_its_own_rule_row(self): finally: sys.path.pop(0) body = '| A | B |\n|---|---|\n| 1 | 2 |\n\ntext\n\n| C | D |\n|---|---|\n| 3 | 4 |\n' - rows, rules, strays = check_review.table_parts(body) + rows, rules, strays, heads = check_review.table_parts(body) + self.assertEqual([h[0] for h in heads], ['A', 'C']) self.assertEqual(len(rules), 2, (rules, strays)) self.assertEqual(strays, []) self.assertEqual(len(rows), 4, rows) + def test_43_a_row_repeating_the_index_header_is_named(self): + # The header is the row above the rule row, by position. Skipped by + # content, a data row whose ID cell read 'ID' was never checked. + rule = '|----|------|-------|---------|----------|---------|----------------------|------------|' + extra = '| ID | Subtract | 1 | x | Major | Fix | hidden finding | High |' + named = ("index row 'ID' repeats the header but is not the table's " + "header: GitHub shows it as a data row") + text = read(SEEDED) + self.assertIn(rule, text) + review = self.write('index-id.md', text.replace(rule, rule + '\n' + extra, 1)) + code, out = self.check(review, SEEDED_ARTIFACT) + self.assertEqual(code, 1, out) + self.assertEqual(out.count(named), 1, out) + code, out = run('score_seeds.py', review, '--seeds', + os.path.join(ROOT, 'calibration', 'seeds.md')) + self.assertNotEqual(code, 0, out) + self.assertIn(named, out) + def test_43_a_dash_row_in_the_scorecard_body_is_named(self): review = self.scorecard_mutant('|--------|-------|\n', '|--------|-------|\n| Spare | x |\n|---|---|\n') From cb14b0e282decf4a726341b3708ca1ff954ad23a Mon Sep 17 00:00:00 2001 From: Jasper Duizendstra Date: Sun, 8 Nov 2026 11:53:50 +0100 Subject: [PATCH 6/6] Name a finding in the index header's place instead of skipping it 65809dc took the header by position and skipped it whatever it read. A finding above a rule row was then dropped unread: a second table under the index opened by one, or an index whose ID line was lost, so score_seeds.py undercounted where main had failed. A row in the header's place is now skipped only when it reads ID; any other is named, in check_review.py and score_seeds.py alike. Refs #43. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 17 +++++++++-------- scripts/MANIFEST | 6 +++--- scripts/check_review.py | 15 ++++++++++++++- scripts/score_seeds.py | 4 +++- scripts/test_scripts.py | 30 ++++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b66a4b..e261df2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,14 +31,15 @@ it through uncorrected, and `score_seeds.py`, which skipped it. That includes header and rule rows, which were dropped at any width, and a row of empty cells, which was taken for a rule row. Only the line after a table's header is its rule row; a later row of dashes, which GitHub -shows as data, is named too, and so is a -row below it that repeats the index header's `ID`. A row too wide says -a literal `|` is written `\|`. Three siblings are older and filed: a -row GitHub renders that no reader reads, with no outer `|` or indented -(#64); a mandated table with no rule row or split by a blank line (#65); -and a Scorecard metric written twice or not in the template (#66). The checks pass their -failure list explicitly (#47), and `scripts/MANIFEST` pins each -script's hash, gated by `check.py` (#46). Each of these comes with a +shows as data, is named too. So is a row below the index header that +repeats its `ID`, and a finding in a header's place, which GitHub shows +as a header. A row too wide says a literal `|` is written `\|`. Three +siblings are older and filed: a row GitHub renders that no reader +reads, with no outer `|` or indented (#64); a mandated table with no +rule row or split by a blank line (#65); and a Scorecard metric written +twice or not in the template (#66). The checks pass their failure list +explicitly (#47), and `scripts/MANIFEST` pins each script's hash, gated +by `check.py` (#46). Each of these comes with a regression test in `scripts/test_scripts.py`, which CI runs. **Every published review now passes the checker in CI.** diff --git a/scripts/MANIFEST b/scripts/MANIFEST index 333981f..7a4f0c4 100644 --- a/scripts/MANIFEST +++ b/scripts/MANIFEST @@ -1,5 +1,5 @@ f3d35ca8359d423aed41693095ca8eef9108e9c510824b3b84e81f0ee3008ba7 check.py -e70ad015b88ccb003f668e1770c721fa5af11d15c031af8b41a8971a80921bf1 check_review.py +b35395c9ae9a71c163a5b19a9f0f716dd24d6221aa0db159ba31b20e8aa1ce09 check_review.py 0e4cbbeecd19d1c5491302873ee531de7f2a67cfe6c8ee5704dc58f3f1e8c2b0 render_scorecard.py -a1620ac6b4ac072415873d575ba1358252ecc924bdcf431b8836ae1430276014 score_seeds.py -0ec41302796c051edf5f5cccd41aaa4496165e830ce5c17453497e9629cb6e31 test_scripts.py +1826ba11b67423970a48b619ac1cb874db7fedda78e6557d097bdc72ac63b445 score_seeds.py +71b4fd11f8460536bbeaaffa0705a75c1d3d22379b0dc86720e7a25534d26ab0 test_scripts.py diff --git a/scripts/check_review.py b/scripts/check_review.py index 38a65c6..23d247c 100755 --- a/scripts/check_review.py +++ b/scripts/check_review.py @@ -158,6 +158,17 @@ def repeated_header(where, cells): f'not the table\'s header: GitHub shows it as a data row') +def misplaced_header(where, cells): + """The failure for a header-position row that is not the header. + + The row above a rule row is what GitHub shows as the header, so a finding + there is a finding no reader may skip: skipped by position, it was dropped + and the seed score undercounted without a word (issue #43, D1). + """ + return (f'{where} row {unescape(cells[0])[:40]!r} is above the rule row: ' + f'GitHub shows it as the header, not as a row') + + def rule_rows(body): """Cells of each table's rule row: the rows table_rows drops. @@ -638,7 +649,9 @@ def index_rows(review, vocab, failures): parts, _, _, heads = table_parts(body) for cells in parts: if is_header(cells, heads): - if len(cells) != 8: + if unescape(cells[0]) != 'ID': + failures.append(misplaced_header('index', cells)) + elif len(cells) != 8: failures.append(wrong_width('index', cells, 8)) continue if unescape(cells[0]) == 'ID': diff --git a/scripts/score_seeds.py b/scripts/score_seeds.py index 07de1cc..03ede66 100755 --- a/scripts/score_seeds.py +++ b/scripts/score_seeds.py @@ -43,7 +43,9 @@ def findings(path): for cells in parts: c = [check_review.unescape(x) for x in cells] if check_review.is_header(cells, heads): - if len(c) != 8: + if c[0] != 'ID': + wrong.append(check_review.misplaced_header('index', cells)) + elif len(c) != 8: wrong.append(check_review.wrong_width('index', cells, 8)) continue if c and c[0] == 'ID': diff --git a/scripts/test_scripts.py b/scripts/test_scripts.py index 268e10d..e4c46ed 100644 --- a/scripts/test_scripts.py +++ b/scripts/test_scripts.py @@ -329,6 +329,36 @@ def test_43_a_row_repeating_the_index_header_is_named(self): self.assertNotEqual(code, 0, out) self.assertIn(named, out) + def test_43_a_finding_in_the_header_place_is_named(self): + # Skipped by position, a finding above a rule row was dropped: a + # second table opened by one, or an index whose ID line was lost. + rule = '|----|------|-------|---------|----------|---------|----------------------|------------|' + header = '| ID | Lens | Cycle | Line(s) | Severity | Verdict | Claim (one sentence) | Confidence |' + sub9 = '| SUB-9 | Subtract | 1 | semver-2.0.0-seeded.md:10-11 | Major | Fix | hidden finding | High |' + text = read(SEEDED) + self.assertIn(header + '\n' + rule, text) + index = text.split('\n## FINDINGS INDEX\n', 1)[1] + rows = [l for l in index.split('\n') if l.startswith('| SUB-')] + first, last = rows[0], rows[-1] + # B: a second table under the index, opened by a finding. + second = text.replace(last, last + '\n\n' + sub9 + '\n' + rule, 1) + self.assertNotEqual(second, text) + # D: the ID line lost, so the first finding sits in the header's place. + lost = text.replace(header + '\n' + rule + '\n' + first, + first + '\n' + rule, 1) + self.assertNotEqual(lost, text) + for review_text, fid in ((second, 'SUB-9'), (lost, 'SUB-1')): + named = (f"index row {fid!r} is above the rule row: GitHub shows it " + f"as the header, not as a row") + review = self.write('header-place.md', review_text) + code, out = self.check(review, SEEDED_ARTIFACT) + self.assertEqual(code, 1, out) + self.assertEqual(out.count(named), 1, out) + code, out = run('score_seeds.py', review, '--seeds', + os.path.join(ROOT, 'calibration', 'seeds.md')) + self.assertNotEqual(code, 0, out) + self.assertIn(named, out) + def test_43_a_dash_row_in_the_scorecard_body_is_named(self): review = self.scorecard_mutant('|--------|-------|\n', '|--------|-------|\n| Spare | x |\n|---|---|\n')