From cbc0a18bd97d76bcfae061ec92e409a6c33916e6 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 8 Nov 2026 19:02:50 -0400 Subject: [PATCH] checks: an untracked file whose comment style is unknown is debris, not repo content (refs #1564) My #1414 made `copyright.py --check` walk untracked files so a new source file cannot pass before `git add`. The cost surfaced as engine#1564: an untracked `.hrx123/logs/*.jsonl` reds a developer clone while `main` is clean, because an unknown extension has no comment style -- the shape that teaches people to skip the gate. The distinction the tool was missing: an unknown style is a real gap only for a file that is IN the repo, which would ship without a licence header. An untracked file is not repo content yet -- run output, a probe's dump, a scratch file -- so it is skipped, and a tracked file of the same name is still an error. Measured in a worktree of this branch, one command each: clean tree rc 0 untracked probe-dump.jsonl / scratchlogs/ rc 0 (was rc 1 on main) the same file `git add`ed rc 1 "no comment style known" tests/copyright_check_untracked_test.py gains that pair as a test, and it bites: reverting only this tool change leaves the suite red on exactly one check ("an UNTRACKED file with no known comment style is skipped, not failed") and green everywhere else. #1568 fixes the instance with a `.gitignore` line, which is right for that directory; this is the class, so the next lane's debris does not have to be ignored directory by directory. The two do not conflict: once a file is ignored neither patch sees it, and where it is not ignored this one skips it. --- tests/copyright_check_untracked_test.py | 17 +++++++++++++++++ tools/copyright.py | 13 +++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/tests/copyright_check_untracked_test.py b/tests/copyright_check_untracked_test.py index 72b1a6b88..9e5fd37b8 100755 --- a/tests/copyright_check_untracked_test.py +++ b/tests/copyright_check_untracked_test.py @@ -130,5 +130,22 @@ def git(repo, *args): check(rc.returncode == 0, "a second occurrence past the window (emitted notice) stays green", rc.stdout + rc.stderr) + # engine#1564: an untracked file whose comment style the tool does not know is debris, not repo content — + # run output a probe dropped (`.hrx123/logs/*.jsonl`), a scratch file. Skipping it is what stops the gate + # from reding a developer clone while `main` is clean; a TRACKED file of the same name is still an error. + with open(os.path.join(repo, "probe-dump.jsonl"), "w") as f: + f.write('{"x": 1}\n') + rc = run(repo, "--check") + check(rc.returncode == 0, + "an UNTRACKED file with no known comment style is skipped, not failed (engine#1564)", + rc.stdout + rc.stderr) + git(repo, "add", "probe-dump.jsonl") + git(repo, "commit", "-q", "-m", "track a jsonl") + rc = run(repo, "--check") + check(rc.returncode != 0, "the same file TRACKED is still an error: it would ship without a notice", + rc.stdout + rc.stderr) + check("no comment style known" in (rc.stdout + rc.stderr), "and it is named as an unknown style", + rc.stdout + rc.stderr) + print(f"copyright_check_untracked_test: {len(FAIL)} failure(s)") sys.exit(1 if FAIL else 0) diff --git a/tools/copyright.py b/tools/copyright.py index f92fda290..df4a0f73a 100644 --- a/tools/copyright.py +++ b/tools/copyright.py @@ -168,14 +168,23 @@ def main(): def listing(*args): return subprocess.run(["git", "ls-files", *args], capture_output=True, text=True, check=True).stdout.split("\n") - files = sorted(set(filter(None, listing())) | set(filter(None, listing("--others", "--exclude-standard")))) + tracked = set(filter(None, listing())) + untracked = set(filter(None, listing("--others", "--exclude-standard"))) + files = sorted(tracked | untracked) missing, unknown, duplicated = [], [], [] for path in filter(None, files): if exempt(path): continue block = notice_block(path) if block is None: - unknown.append(path) + # A file this tool cannot attach a notice to. If it is IN the repository that is a real gap -- a source + # file whose style nobody taught the tool, which would ship without a licence header. If it is merely + # untracked, it is not repo content yet: run output, a probe's dump, a scratch file. Failing on that is + # the shape that teaches people to skip the gate (engine#1564: `.hrx123/logs/*.jsonl` reddened a + # developer clone while `main` was clean), so an untracked unknown-style file is skipped and a tracked + # one is still an error. + if path not in untracked: + unknown.append(path) continue with open(path, encoding="utf-8") as f: text = f.read()