From 6cf0d87f0bb8e57e2cbfef190dc364fcc3867dd7 Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Tue, 25 Aug 2026 11:21:33 +0900 Subject: [PATCH] test(persistence): cover uppercase-label and scanner edge branches The production branch gate reported 2028/2030 after the consolidation vehicle landed: validate_entity_label and validate_project_label never observed an uppercase byte that passes the alphanumeric clause yet fails the lowercase clause, so the final || operand stayed uncovered. The quality suite likewise missed three Python arcs in scripts/ check_coverage.py: the previous-line scan exhausting over blank-only history (211->215, 212->211) and the escaped-character arc inside char literal scanning (318->311). Add exact red-to-green cases for each. --- crates/persistence_postgres/src/entity_sql.rs | 3 ++ .../persistence_postgres/src/project_sql.rs | 3 ++ tests/quality/test_check_coverage.py | 43 ++++++++++--------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/crates/persistence_postgres/src/entity_sql.rs b/crates/persistence_postgres/src/entity_sql.rs index fcb5c196a..0a576b39f 100644 --- a/crates/persistence_postgres/src/entity_sql.rs +++ b/crates/persistence_postgres/src/entity_sql.rs @@ -123,6 +123,9 @@ mod tests { "author;role".into(), "author\\".into(), "author\nrole".into(), + // Uppercase bytes pass the alphanumeric gate yet fail the lowercase + // gate, so this exercises the final clause of the validation chain. + "AUTHOR".into(), "a".repeat(129), ] { assert_eq!( diff --git a/crates/persistence_postgres/src/project_sql.rs b/crates/persistence_postgres/src/project_sql.rs index 1ea7daf26..b3ef010ae 100644 --- a/crates/persistence_postgres/src/project_sql.rs +++ b/crates/persistence_postgres/src/project_sql.rs @@ -123,6 +123,9 @@ mod tests { "active;closed".into(), "active\\".into(), "active\nclosed".into(), + // Uppercase bytes pass the alphanumeric gate yet fail the lowercase + // gate, so this exercises the final clause of the validation chain. + "ACTIVE".into(), "s".repeat(129), ] { assert_eq!( diff --git a/tests/quality/test_check_coverage.py b/tests/quality/test_check_coverage.py index caabc0013..ec4a736b2 100644 --- a/tests/quality/test_check_coverage.py +++ b/tests/quality/test_check_coverage.py @@ -640,32 +640,33 @@ def test_structural_comma_continuation_edge_cases(self) -> None: with tempfile.TemporaryDirectory() as temporary: source = Path(temporary) / "commas.rs" - # Lines 211->215 and 212->211: loop skips blank lines and non-matching - source.write_text( - "fn example() {\n" - " let value = foo(\n" - "\n" - " 1,\n" - " );\n" - "}\n", - encoding="utf-8", - ) + # A comma-terminated line whose preceding lines are entirely blank + # exhausts the previous-line scan (arcs 211->215 and 212->211). + source.write_text("\n\nfoo,\n", encoding="utf-8") self.assertTrue( - coverage_contract.is_executable_source_line(str(source), 2) + coverage_contract.is_executable_source_line(str(source), 3) ) - # Line 318->311: while loop with backslash at end of line inside string - source.write_text( - 'fn path() {\n' - ' let s = "a\\\n' - 'b";\n' - "}\n", - encoding="utf-8", - ) - self.assertTrue( - coverage_contract.is_executable_source_line(str(source), 2) + # A blank candidate between the comma line and its previous + # non-empty line is skipped by the same scan. + source.write_text("bar(\n\n baz,\n", encoding="utf-8") + self.assertFalse( + coverage_contract.is_executable_source_line(str(source), 3) ) + def test_multiline_string_scanner_covers_escaped_char_literals(self) -> None: + """An escaped character inside a char literal keeps the scanner in loop. + + The backslash inside a character literal must clear through the + escape-tracking branch so a following quote cannot close the literal + early; this exercises the scanner's escaped-character arc (318->311). + """ + + lines = ["fn f() {", r" let newline = '\n';", "}"] + self.assertFalse( + coverage_contract._line_in_multiline_string(lines, 3) + ) + if __name__ == "__main__": # pragma: no cover unittest.main()