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()