From 11e0015c8edd09867b6f1f97d4478d2edca8237d Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Sat, 31 Oct 2026 09:52:55 -0700 Subject: [PATCH 1/3] Read a Move Out of an Unread Source Whole and Skip a Compose Block Scalar in the Prose Gate In diff mode, a renamed file's destination is now read in full when its source sat outside the run's narrowed paths, since no run read it there. A move out of a file a rule's exemption list names, the root runbook for home-path, is read in full for that rule alone. The rule-to-list mapping lives in prose-gate.json as the rule's file_exemption key. container_paths now treats a key or sequence line ending in a `|` or `>` block-scalar indicator as opening opaque text, so mount-shaped lines inside it are no longer read as a volume entry's container side. Co-Authored-By: Claude Opus 5.5 --- .github/actions/prose-gate/prose-gate.json | 2 +- .github/actions/prose-gate/prose_lint.py | 70 ++++++++++++++++---- tests/test_prose_lint.py | 75 +++++++++++++++++++++- 3 files changed, 132 insertions(+), 15 deletions(-) diff --git a/.github/actions/prose-gate/prose-gate.json b/.github/actions/prose-gate/prose-gate.json index 244d5741a..5f80e4c0b 100644 --- a/.github/actions/prose-gate/prose-gate.json +++ b/.github/actions/prose-gate/prose-gate.json @@ -12,7 +12,7 @@ "sentence-split": { "default": false, "summary": "a sentence wrapping across lines" }, "sentence-length": { "default": true, "summary": "a sentence over the word cap" }, "spelling": { "default": true, "summary": "a British spelling where the repo convention is US English" }, - "home-path": { "default": true, "summary": "an absolute home path naming a real account" }, + "home-path": { "default": true, "summary": "an absolute home path naming a real account", "file_exemption": "home_path_exempt" }, "dead-path": { "default": true, "summary": "a mention of a path git once tracked and the tree no longer holds" }, "issue-ref": { "default": true, "summary": "an issue or pull request reference in a leading comment, a Python docstring, or instruction text" } }, diff --git a/.github/actions/prose-gate/prose_lint.py b/.github/actions/prose-gate/prose_lint.py index 243105e63..661fde5db 100755 --- a/.github/actions/prose-gate/prose_lint.py +++ b/.github/actions/prose-gate/prose_lint.py @@ -72,6 +72,9 @@ OVERRIDE_NAME = ".prose-gate.json" RULES: dict[str, str] = {name: rule["summary"] for name, rule in BASE["rules"].items()} DEFAULT_RULES = frozenset(name for name, rule in BASE["rules"].items() if rule["default"]) +FILE_EXEMPTION: dict[str, str] = { + name: rule["file_exemption"] for name, rule in BASE["rules"].items() if "file_exemption" in rule +} MESSAGES: dict[str, str] = BASE["messages"] SENTENCE_WORD_CAP: int = BASE["sentence_word_cap"] # The data file names each character as `U+XXXX`, which keeps the file itself ASCII. @@ -275,20 +278,29 @@ def undiffable_paths(base: str, root: Path) -> set[str] | None: def changed_lines( - base: str, root: Path, excludes: tuple[str, ...] = () + base: str, + root: Path, + excludes: tuple[str, ...] = (), + paths: list[str] | None = None, + whole: dict[str, frozenset[str]] | None = None, ) -> dict[str, set[int]] | None: """Map path -> lines this tree adds vs `base`, an untracked or undiffable text file in full. - A file moved out of a generated tree or an excluded path is read in full too, since no run read - it there. A move between read paths adds only what it changed. + No run read a file in a generated tree, an excluded path, or a path outside `paths`. So a file + moved out of one is read in full too. A move out of a file some rule's `file_exemption` names + is read in full for that rule alone, recorded in `whole`. A move between read paths adds only + what it changed. """ raw = git_bytes(root, DIFF_ARGS, base) undiffable = undiffable_paths(base, root) if raw is not None else None if raw is None or undiffable is None: return None - trees = config_for(str(root)).exempt["generated_trees"] + config = config_for(str(root)) + trees = config.exempt["generated_trees"] + asked = None if paths is None else [repo_key(Path(p), root) for p in paths] out: dict[str, set[int]] = {} unread: list[str] = [] + skipped: dict[str, frozenset[str]] = {} cur = None source = "" # A header is honored only in the block a `diff --git` line opens, which content cannot forge. @@ -299,8 +311,15 @@ def changed_lines( elif in_header and line.startswith("rename from "): source = unquoted(line.removeprefix("rename from ")) elif in_header and line.startswith("rename to "): - if not trees.isdisjoint(Path(source).parts) or any(x in source for x in excludes): - unread.append(unquoted(line.removeprefix("rename to "))) + dest = unquoted(line.removeprefix("rename to ")) + if ( + not trees.isdisjoint(Path(source).parts) + or any(x in source for x in excludes) + or (asked is not None and not asked_about(source, asked)) + ): + unread.append(dest) + elif rules := exempt_rules(root / source, root, config): + skipped[dest] = rules elif in_header and line.startswith("+++ "): in_header = False cur = diff_header_path(line[4:]) @@ -317,9 +336,23 @@ def changed_lines( for name in [*undiffable, *untracked_paths(root), *unread]: if is_text(root / name): out[name] = set(range(1, len((root / name).read_bytes().splitlines()) + 1)) + for name, rules in skipped.items(): + if is_text(root / name): + out.setdefault(name, set()) + if whole is not None: + whole[name] = rules return out +def exempt_rules(path: Path, root: Path, config: Config) -> frozenset[str]: + """The rules that never read `path`, each because the list its `file_exemption` names holds it.""" + return frozenset( + rule + for rule, key in FILE_EXEMPTION.items() + if path.resolve() in {(root / p).resolve() for p in config.exempt[key]} + ) + + def asked_about(key: str, paths: list[str]) -> bool: """Whether a repository-relative diff key falls under one of the requested paths.""" for raw in paths: @@ -1252,21 +1285,31 @@ def rule_sentence_split(unit: Unit, ctx: Context) -> list[Finding]: r"""^\s*-\s+["']?(?:[A-Za-z]:(?=[\\/]))?(?:\$\{[^}]*\}|[^:\s"'{}])+:(?P/[^:\s"']*)""" ) LONG_MOUNT = re.compile(r"""^\s*(?:-\s+)?target:\s+["']?(?P/[^\s"']*)""") +BLOCK_SCALAR = re.compile( + r"^(?P\s*(?:-\s+)*)(?P[^\s#][^#]*?:\s+)?(?:[!&]\S*\s+)*[|>][-+1-9]{0,2}\s*(?:#.*)?$" +) def container_paths(lines: tuple[Line, ...]) -> dict[int, range]: """Where a Compose volume entry names its container path, a path an image ships, not a host. The host side keeps a `${...}` expansion and a drive letter whole, so neither colon splits it. - A sequence may sit at its key's own indent, so only a sibling key closes the block. + A sequence may sit at its key's own indent, so only a sibling key closes the block. A `|` or + `>` block scalar is text, so every line deeper than the node that opens one is skipped. """ out: dict[int, range] = {} block: int | None = None + opaque: int | None = None for line in lines: body = line.text.lstrip() if not body or body.startswith("#"): continue indent = len(line.text) - len(body) + if opaque is not None and indent > opaque: + continue + opaque = None + if scalar := BLOCK_SCALAR.match(line.text): + opaque = len(scalar["lead"]) if scalar["key"] else indent if block is not None and (indent < block or (indent == block and body[0] != "-")): block = None if VOLUMES_KEY.match(line.text): @@ -1281,9 +1324,7 @@ def container_paths(lines: tuple[Line, ...]) -> dict[int, range]: def rule_home_path(unit: Unit, ctx: Context) -> list[Finding]: """An absolute home path naming a real account, on any line, a fenced transcript included.""" exempt = ctx.config.exempt - if ctx.root is not None and ctx.path.resolve() in { - (ctx.root / p).resolve() for p in exempt["home_path_exempt"] - }: + if ctx.root is not None and "home-path" in exempt_rules(ctx.path, ctx.root, ctx.config): return [] inside = container_paths(unit.lines) if COMPOSE_FILE.fullmatch(ctx.path.name) else {} return [ @@ -1955,7 +1996,12 @@ def main(argv: list[str] | None = None) -> int: return 0 discovered = len(files) # Presence rather than truthiness, since an empty value is a base that failed to compute. - scope = changed_lines(a.diff, scan_root, tuple(a.exclude)) if a.diff is not None else None + whole: dict[str, frozenset[str]] = {} + scope = ( + changed_lines(a.diff, scan_root, tuple(a.exclude), scan_paths, whole) + if a.diff is not None + else None + ) if a.diff is not None and scope is None: return refuse("error-no-diff", base=a.diff) if scope is not None: @@ -1977,7 +2023,7 @@ def main(argv: list[str] | None = None) -> int: for f in files: allowed = scope.get(keys[f]) if scope is not None else None for ln, kind, msg in check_file(f, rules, scan_root, allowed, plain, undecoded): - if allowed is not None and ln not in allowed: + if allowed is not None and ln not in allowed and kind not in whole.get(keys[f], ()): continue total += 1 bykind[kind] = bykind.get(kind, 0) + 1 diff --git a/tests/test_prose_lint.py b/tests/test_prose_lint.py index 5bd4f58d7..f0b5ba518 100755 --- a/tests/test_prose_lint.py +++ b/tests/test_prose_lint.py @@ -3612,6 +3612,31 @@ def test_a_compose_host_path_is_still_a_home(self) -> None: ["home-path"], self.kinds(self.compose(entry), {"home-path"}, name) ) + def test_a_compose_block_scalar_is_text_rather_than_a_volume(self) -> None: + """A `volumes:` key or a mount inside a `|` or `>` scalar is text, so the rule reads it. + + The real volume entry after each scalar still names a container path, so exactly one + finding means the scalar ended where its indentation returned. + """ + real = f" volumes:\n - ledger-cache:{NIX_HOME}/data\n" + for indicator in ("|", ">", "|-", ">+", "|2", "|-2", "¬e |", "!!str >", "| # note"): + text = ( + f"services:\n ledger:\n x-readme: {indicator}\n volumes:\n" + f" - ledger-cache:{NIX_HOME}/data\n{real}" + ) + with self.subTest(indicator=indicator): + self.assertEqual(["home-path"], self.kinds(text, {"home-path"}, "compose.yml")) + target = f" target: {NIX_HOME}/media" + for entry in ( + f" - type: bind\n x-note: |\n - ./old:{NIX_HOME}/media\n{target}", + f" - x-note: >-\n - ./old:{NIX_HOME}/media\n{target}", + f" - |\n - ./old:{NIX_HOME}/media\n - ./config:{NIX_HOME}/media", + ): + with self.subTest(entry=entry): + self.assertEqual( + ["home-path"], self.kinds(self.compose(entry), {"home-path"}, "compose.yml") + ) + class TestDeadPathRule(unittest.TestCase): """The `dead-path` rule on Markdown prose units.""" @@ -5629,11 +5654,14 @@ def moved( edit: bool = False, excludes: tuple[str, ...] = (), keep: bool = False, + paths: tuple[str, ...] | None = None, + whole: dict[str, frozenset[str]] | None = None, ) -> dict[str, set[int]]: """The scope a move of a committed four-line file from `source` to `docs/ledger.md` gets. With `keep`, the file is copied rather than moved, and the source gains a fifth line. - Copy detection looks for a source only among the files a change modifies. + Copy detection looks for a source only among the files a change modifies. Each of `paths` + is relative to the repository, as a run narrowed to it would ask. """ root = self.real_repo() subprocess.run(["git", "-C", str(root), "config", "diff.renames", renames], check=True) @@ -5653,7 +5681,8 @@ def moved( (root / "docs" / "ledger.md").write_text( "One.\nTwo.\nEdited.\nFour.\n", encoding="utf-8" ) - got = prose_lint.changed_lines("HEAD", root, excludes) + asked = None if paths is None else [str(root / p) for p in paths] + got = prose_lint.changed_lines("HEAD", root, excludes, asked, whole) assert got is not None, "git failed, so this case proved nothing about scoping" return got @@ -5678,6 +5707,48 @@ def test_a_rename_out_of_an_excluded_path_is_read_whole(self) -> None: got = self.moved("drafts/ledger.md", excludes=("drafts/",)) self.assertEqual({"docs/ledger.md": {1, 2, 3, 4}}, got) + def test_a_rename_from_outside_the_asked_paths_is_read_whole(self) -> None: + """A run narrowed to some paths never read a file outside them, so a move in is all new.""" + got = self.moved("drafts/ledger.md", paths=("docs",)) + self.assertEqual({"docs/ledger.md": {1, 2, 3, 4}}, got) + got = self.moved("docs/old/ledger.md", paths=("docs",), edit=True) + self.assertEqual({"docs/ledger.md": {3}}, got) + + def test_a_rename_out_of_a_rules_exempt_file_is_read_whole_for_that_rule(self) -> None: + """`home-path` never read the root runbook, so its move is read in full for that rule alone. + + Every other rule read the file where it sat, so its scope stays what the move changed. + """ + for edit, lines in ((False, set()), (True, {3})): + with self.subTest(edit=edit): + whole: dict[str, frozenset[str]] = {} + got = self.moved("OPERATIONS.md", edit=edit, whole=whole) + self.assertEqual({"docs/ledger.md": lines}, got) + self.assertEqual({"docs/ledger.md": frozenset({"home-path"})}, whole) + whole = {} + self.assertEqual({}, self.moved("notes/OPERATIONS.md", whole=whole)) + self.assertEqual({}, whole) + + def test_a_moved_runbook_reports_its_home_path_and_no_older_finding(self) -> None: + """The run end to end: the moved line reports for `home-path` and for no other rule.""" + root = self.real_repo() + text = f"Deploy into {NIX_HOME}/stack here.\nOne; two.\n" + (root / "OPERATIONS.md").write_text(text, encoding="utf-8") + subprocess.run(["git", "-C", str(root), "add", "OPERATIONS.md"], check=True) + subprocess.run(["git", "-C", str(root), "commit", "--quiet", "-m", "baseline"], check=True) + (root / "docs").mkdir() + subprocess.run(["git", "-C", str(root), "mv", "OPERATIONS.md", "docs/ops.md"], check=True) + out = io.StringIO() + with contextlib.redirect_stdout(out), contextlib.redirect_stderr(io.StringIO()): + code = prose_lint.main( + ["--check", "home-path", "--check", "semicolon", "--diff", "HEAD", str(root)] + ) + self.assertEqual(1, code) + self.assertEqual( + ["docs/ops.md:1: home-path"], + [ln.rsplit(":", 1)[0] for ln in out.getvalue().splitlines()], + ) + def test_a_rename_between_read_paths_adds_only_what_it_changed(self) -> None: """A run already read the file where it sat, so a move brings no line into scope unedited. From 07f37ae40e3eb3b686dfa8b8059b0d21499e1432 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Sat, 31 Oct 2026 10:01:12 -0700 Subject: [PATCH 2/3] Read a Move Whole for Each Rule Its Path Decides, and Narrow Only by Directory A rename is now compared by what its path decides: the lexer for every rule, and per rule the file exemption and Compose name for home-path, instruction text for issue-ref, and the directory a relative link resolves from for dead-path. A run's paths narrow only when each names a directory, since a hook's file list names the destination alone. The scope note counts a file read whole for a rule in full. Co-Authored-By: Claude Opus 5.5 --- .github/actions/prose-gate/prose_lint.py | 58 ++++++++++++++++------ tests/test_prose_lint.py | 62 +++++++++++++++--------- 2 files changed, 82 insertions(+), 38 deletions(-) diff --git a/.github/actions/prose-gate/prose_lint.py b/.github/actions/prose-gate/prose_lint.py index 661fde5db..0d7b65342 100755 --- a/.github/actions/prose-gate/prose_lint.py +++ b/.github/actions/prose-gate/prose_lint.py @@ -287,9 +287,11 @@ def changed_lines( """Map path -> lines this tree adds vs `base`, an untracked or undiffable text file in full. No run read a file in a generated tree, an excluded path, or a path outside `paths`. So a file - moved out of one is read in full too. A move out of a file some rule's `file_exemption` names - is read in full for that rule alone, recorded in `whole`. A move between read paths adds only - what it changed. + moved out of one is read in full too, as is one whose move changes the lexer it reads through. + Only directories narrow. A list naming a file is what a hook passes from a commit, which says + what this run reads rather than what every run does. A move changing what its path + decides for a rule is read in full for that rule alone, recorded in `whole`. Any other move + adds only what it changed. """ raw = git_bytes(root, DIFF_ARGS, base) undiffable = undiffable_paths(base, root) if raw is not None else None @@ -297,10 +299,11 @@ def changed_lines( return None config = config_for(str(root)) trees = config.exempt["generated_trees"] - asked = None if paths is None else [repo_key(Path(p), root) for p in paths] + narrowed = paths is not None and all(Path(p).is_dir() for p in paths) + asked = [repo_key(Path(p), root) for p in paths] if paths is not None and narrowed else None out: dict[str, set[int]] = {} unread: list[str] = [] - skipped: dict[str, frozenset[str]] = {} + moved: dict[str, str] = {} cur = None source = "" # A header is honored only in the block a `diff --git` line opens, which content cannot forge. @@ -318,8 +321,8 @@ def changed_lines( or (asked is not None and not asked_about(source, asked)) ): unread.append(dest) - elif rules := exempt_rules(root / source, root, config): - skipped[dest] = rules + else: + moved[dest] = source elif in_header and line.startswith("+++ "): in_header = False cur = diff_header_path(line[4:]) @@ -333,17 +336,36 @@ def changed_lines( if m: start = int(m.group(1)) out[cur].update(range(start, start + int(m.group(2) or 1))) + for dest, source in moved.items(): + if not is_text(root / dest): + continue + first = (root / dest).read_bytes().split(b"\n", 1)[0].decode("utf-8", "replace") + before = path_readings(root / source, root, config, first.rstrip("\r")) + after = path_readings(root / dest, root, config, first.rstrip("\r")) + if before["*"] != after["*"]: + unread.append(dest) + elif rules := frozenset(r for r in after if r != "*" and before[r] != after[r]): + out.setdefault(dest, set()) + if whole is not None: + whole[dest] = rules for name in [*undiffable, *untracked_paths(root), *unread]: if is_text(root / name): out[name] = set(range(1, len((root / name).read_bytes().splitlines()) + 1)) - for name, rules in skipped.items(): - if is_text(root / name): - out.setdefault(name, set()) - if whole is not None: - whole[name] = rules return out +def path_readings(path: Path, root: Path, config: Config, first: str) -> dict[str, object]: + """What a file's path alone decides for each rule that reads by path, `*` for every rule.""" + exempt = exempt_rules(path, root, config) + return { + **{rule: rule in exempt for rule in FILE_EXEMPTION}, + "*": lexer_name(path, first), + "home-path": ("home-path" in exempt, bool(COMPOSE_FILE.fullmatch(path.name))), + "issue-ref": is_instruction_text(path, root), + "dead-path": path.parent.resolve(), + } + + def exempt_rules(path: Path, root: Path, config: Config) -> frozenset[str]: """The rules that never read `path`, each because the list its `file_exemption` names holds it.""" return frozenset( @@ -1286,7 +1308,8 @@ def rule_sentence_split(unit: Unit, ctx: Context) -> list[Finding]: ) LONG_MOUNT = re.compile(r"""^\s*(?:-\s+)?target:\s+["']?(?P/[^\s"']*)""") BLOCK_SCALAR = re.compile( - r"^(?P\s*(?:-\s+)*)(?P[^\s#][^#]*?:\s+)?(?:[!&]\S*\s+)*[|>][-+1-9]{0,2}\s*(?:#.*)?$" + r"^(?P\s*(?:-\s+)*)(?P[^\s#][^#]*?:\s+)?(?:[!&]\S*\s+)*[|>]" + r"(?:[-+][1-9]?|[1-9][-+]?)?\s*(?:#.*)?$" ) @@ -2030,7 +2053,14 @@ def main(argv: list[str] | None = None) -> int: byfile[keys[f]] = byfile.get(keys[f], 0) + 1 if not a.summary: print(printable(f"{keys[f]}:{ln}: {kind}: {msg}")) - inscope = sum(len(scope[keys[f]]) for f in files) if scope is not None else None + inscope = ( + sum( + len(f.read_bytes().splitlines()) if keys[f] in whole else len(scope[keys[f]]) + for f in files + ) + if scope is not None + else None + ) provenance = gate_provenance(a.provenance) named = [[keys[f] for f in group] for group in (plain, undecoded)] note_line = scope_note(len(files), discovered, inscope, a.diff, provenance, *named) diff --git a/tests/test_prose_lint.py b/tests/test_prose_lint.py index f0b5ba518..11c70e37a 100755 --- a/tests/test_prose_lint.py +++ b/tests/test_prose_lint.py @@ -5656,8 +5656,9 @@ def moved( keep: bool = False, paths: tuple[str, ...] | None = None, whole: dict[str, frozenset[str]] | None = None, + dest: str = "docs/ledger.md", ) -> dict[str, set[int]]: - """The scope a move of a committed four-line file from `source` to `docs/ledger.md` gets. + """The scope a move of a committed four-line file from `source` to `dest` gets. With `keep`, the file is copied rather than moved, and the source gains a fifth line. Copy detection looks for a source only among the files a change modifies. Each of `paths` @@ -5671,16 +5672,14 @@ def moved( subprocess.run(["git", "-C", str(root), "commit", "--quiet", "-m", "baseline"], check=True) (root / "docs").mkdir(exist_ok=True) if keep: - shutil.copyfile(root / source, root / "docs" / "ledger.md") + shutil.copyfile(root / source, root / dest) with (root / source).open("a", encoding="utf-8") as fh: fh.write("Five.\n") - subprocess.run(["git", "-C", str(root), "add", "docs/ledger.md", source], check=True) + subprocess.run(["git", "-C", str(root), "add", dest, source], check=True) else: - subprocess.run(["git", "-C", str(root), "mv", source, "docs/ledger.md"], check=True) + subprocess.run(["git", "-C", str(root), "mv", source, dest], check=True) if edit: - (root / "docs" / "ledger.md").write_text( - "One.\nTwo.\nEdited.\nFour.\n", encoding="utf-8" - ) + (root / dest).write_text("One.\nTwo.\nEdited.\nFour.\n", encoding="utf-8") asked = None if paths is None else [str(root / p) for p in paths] got = prose_lint.changed_lines("HEAD", root, excludes, asked, whole) assert got is not None, "git failed, so this case proved nothing about scoping" @@ -5711,23 +5710,38 @@ def test_a_rename_from_outside_the_asked_paths_is_read_whole(self) -> None: """A run narrowed to some paths never read a file outside them, so a move in is all new.""" got = self.moved("drafts/ledger.md", paths=("docs",)) self.assertEqual({"docs/ledger.md": {1, 2, 3, 4}}, got) - got = self.moved("docs/old/ledger.md", paths=("docs",), edit=True) + got = self.moved("docs/draft.md", paths=("docs",), edit=True) self.assertEqual({"docs/ledger.md": {3}}, got) - def test_a_rename_out_of_a_rules_exempt_file_is_read_whole_for_that_rule(self) -> None: - """`home-path` never read the root runbook, so its move is read in full for that rule alone. - - Every other rule read the file where it sat, so its scope stays what the move changed. - """ - for edit, lines in ((False, set()), (True, {3})): - with self.subTest(edit=edit): - whole: dict[str, frozenset[str]] = {} - got = self.moved("OPERATIONS.md", edit=edit, whole=whole) - self.assertEqual({"docs/ledger.md": lines}, got) - self.assertEqual({"docs/ledger.md": frozenset({"home-path"})}, whole) - whole = {} - self.assertEqual({}, self.moved("notes/OPERATIONS.md", whole=whole)) - self.assertEqual({}, whole) + def test_a_file_list_narrows_nothing(self) -> None: + """A hook passes the files a commit stages, a move's destination alone, not a run's scope.""" + self.assertEqual({}, self.moved("docs/draft.md", paths=("docs/ledger.md",))) + + def test_a_rename_changing_what_its_path_decides_is_read_whole_for_that_rule(self) -> None: + """A rule that read the file another way where it sat reads it in full, and no other rule. + + The root runbook is exempt from `home-path` and is instruction text for `issue-ref`. A + Compose name decides which lines `home-path` reads, and a directory decides what a relative + link resolves to. A move keeping each of them adds only what it changed. + """ + for source, dest, rules in ( + ("OPERATIONS.md", "docs/ledger.md", {"home-path", "issue-ref", "dead-path"}), + ("docs/compose.yml", "docs/ledger.yml", {"home-path"}), + ("docs/guide.md", "docs/OPERATIONS.md", set()), + ("notes/guide.md", "AGENTS.md", {"issue-ref", "dead-path"}), + ("docs/draft.md", "docs/ledger.md", set()), + ): + for edit, lines in ((False, set()), (True, {3})): + with self.subTest(source=source, dest=dest, edit=edit): + whole: dict[str, frozenset[str]] = {} + got = self.moved(source, edit=edit, whole=whole, dest=dest) + self.assertEqual({dest: lines} if rules or edit else {}, got) + self.assertEqual({dest: frozenset(rules)} if rules else {}, whole) + + def test_a_rename_changing_its_lexer_is_read_whole(self) -> None: + """A file read as plain text where it sat had no comment or Markdown unit read at all.""" + got = self.moved("docs/notes.txt") + self.assertEqual({"docs/ledger.md": {1, 2, 3, 4}}, got) def test_a_moved_runbook_reports_its_home_path_and_no_older_finding(self) -> None: """The run end to end: the moved line reports for `home-path` and for no other rule.""" @@ -5757,8 +5771,8 @@ def test_a_rename_between_read_paths_adds_only_what_it_changed(self) -> None: """ for renames in ("true", "false", "copies"): with self.subTest(renames=renames): - self.assertEqual({}, self.moved("notes/ledger.md", renames)) - got = self.moved("notes/ledger.md", renames, edit=True) + self.assertEqual({}, self.moved("docs/notes.md", renames)) + got = self.moved("docs/notes.md", renames, edit=True) self.assertEqual({"docs/ledger.md": {3}}, got) def test_a_binary_change_contributes_no_scope_entry(self) -> None: From 3236578c4df682ae09e1efeb8164afcb911da777 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Sat, 31 Oct 2026 10:05:02 -0700 Subject: [PATCH 3/3] Read a Move Whole Only for a Rule That Read None of It at Its Source A Compose name and a Markdown file's directory change only part of what home-path and dead-path report, so a whole-file read for them surfaced every older finding in a moved file. They are left to #3711, which compares findings across the move instead. Co-Authored-By: Claude Opus 5.5 --- .github/actions/prose-gate/prose_lint.py | 7 ++++--- tests/test_prose_lint.py | 16 +++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.github/actions/prose-gate/prose_lint.py b/.github/actions/prose-gate/prose_lint.py index 0d7b65342..e9f464874 100755 --- a/.github/actions/prose-gate/prose_lint.py +++ b/.github/actions/prose-gate/prose_lint.py @@ -355,14 +355,15 @@ def changed_lines( def path_readings(path: Path, root: Path, config: Config, first: str) -> dict[str, object]: - """What a file's path alone decides for each rule that reads by path, `*` for every rule.""" + """Whether a rule reads a file at all, or the lexer every rule reads it through, as `*`. + + Only these leave a path's every line unread by a rule, so a move changing one is new to it. + """ exempt = exempt_rules(path, root, config) return { **{rule: rule in exempt for rule in FILE_EXEMPTION}, "*": lexer_name(path, first), - "home-path": ("home-path" in exempt, bool(COMPOSE_FILE.fullmatch(path.name))), "issue-ref": is_instruction_text(path, root), - "dead-path": path.parent.resolve(), } diff --git a/tests/test_prose_lint.py b/tests/test_prose_lint.py index 11c70e37a..c72d9599b 100755 --- a/tests/test_prose_lint.py +++ b/tests/test_prose_lint.py @@ -5720,16 +5720,14 @@ def test_a_file_list_narrows_nothing(self) -> None: def test_a_rename_changing_what_its_path_decides_is_read_whole_for_that_rule(self) -> None: """A rule that read the file another way where it sat reads it in full, and no other rule. - The root runbook is exempt from `home-path` and is instruction text for `issue-ref`. A - Compose name decides which lines `home-path` reads, and a directory decides what a relative - link resolves to. A move keeping each of them adds only what it changed. + The root runbook is exempt from `home-path` and is instruction text, which only + `issue-ref` reads as prose. A move keeping both adds only what it changed. """ for source, dest, rules in ( - ("OPERATIONS.md", "docs/ledger.md", {"home-path", "issue-ref", "dead-path"}), - ("docs/compose.yml", "docs/ledger.yml", {"home-path"}), + ("OPERATIONS.md", "docs/ledger.md", {"home-path", "issue-ref"}), ("docs/guide.md", "docs/OPERATIONS.md", set()), - ("notes/guide.md", "AGENTS.md", {"issue-ref", "dead-path"}), - ("docs/draft.md", "docs/ledger.md", set()), + ("notes/guide.md", "AGENTS.md", {"issue-ref"}), + ("notes/draft.md", "docs/ledger.md", set()), ): for edit, lines in ((False, set()), (True, {3})): with self.subTest(source=source, dest=dest, edit=edit): @@ -5771,8 +5769,8 @@ def test_a_rename_between_read_paths_adds_only_what_it_changed(self) -> None: """ for renames in ("true", "false", "copies"): with self.subTest(renames=renames): - self.assertEqual({}, self.moved("docs/notes.md", renames)) - got = self.moved("docs/notes.md", renames, edit=True) + self.assertEqual({}, self.moved("notes/ledger.md", renames)) + got = self.moved("notes/ledger.md", renames, edit=True) self.assertEqual({"docs/ledger.md": {3}}, got) def test_a_binary_change_contributes_no_scope_entry(self) -> None: