Skip to content

test: REUSE gate tests clean up on setUp failure and cover a subdirectory run - #88

Merged
futurebuildai merged 1 commit into
refactor/v1from
refactor/reuse-gate-test-p3
Oct 10, 2026
Merged

futurebuildai merged 1 commit into
refactor/v1from
refactor/reuse-gate-test-p3

Conversation

@futurebuildai

Copy link
Copy Markdown
Contributor

Two follow-ups from the PR 87 review r3, neither blocking.

P3-A: temp dir cleanup runs even if setUp raises

Both test classes of .github/scripts/test_reuse_gate.py (InlineHeaderCheck and MainSubprocessCheck) used to call tempfile.mkdtemp in setUp and then _init_repo straight after, with the cleanup in tearDown. If _init_repo raised for any reason (for example git is missing on PATH), tearDown would not execute and the temp directory would leak on disk.

This change registers self.addCleanup(shutil.rmtree, self.tmp, ignore_errors=True) immediately after mkdtemp, before _init_repo is called. addCleanup runs even when setUp itself fails partway through, so the directory is gone regardless. shutil is imported at the top of the module now and the now-redundant tearDown blocks are dropped (their only job was the rmtree call).

P3-B: a subdirectory run is covered

MainSubprocessCheck now also has a test_main_from_subdirectory_still_finds_root_headerless_file case. It puts a headerless .go file at the throwaway repo's root and runs the gate with cwd set to a subdirectory (tmp/deep/nested). The assertion is exit 1 and that the summary names the file. Without a git-root scan in main() (for example if the lookup fell back to os.getcwd()), the empty subdirectory would produce zero missing files, the gate would print REUSE gate **passed**, exit 0, and this test would fail.

Mutation proof:

  1. With the suite green, change reuse_gate.py main()'s git-root lookup from git rev-parse --show-toplevel to os.getcwd() and run:
$ python3 -m unittest discover -s .github/scripts -p test_reuse_gate.py
...
test_main_from_subdirectory_still_finds_root_headerless_file ... FAIL
======================================================================
FAIL: test_main_from_subdirectory_still_finds_root_headerless_file
----------------------------------------------------------------------
AssertionError: 0 != 1 : stdout=
## REUSE licensing gate

- reuse stub-0.0.0, spec stub
- Files scanned: **0**
- With copyright info: **0**
- With licensing info: **0**
- Licenses in use: none

REUSE gate **passed**.

stderr=

Ran 9 tests in 0.221s

FAILED (failures=1)
  1. Restore the one file: git checkout -- .github/scripts/reuse_gate.py, rerun the suite, the same case is green again and the full 9-test run is OK:
Ran 9 tests in 0.217s

OK

Exit tests

  • python3 -m unittest discover -s .github/scripts -p test_reuse_gate.py: 9 tests, OK
  • python3 .github/scripts/reuse_gate.py against this checkout: REUSE gate **passed**., exit 0 (uses the installed reuse 6.2.0)

🤖 Generated with Claude Code

… run

Two follow-ups from PR 87 review r3:

P3-A: in both test classes, setUp now registers

self.addCleanup(shutil.rmtree, self.tmp, ignore_errors=True)

before calling _init_repo, so a half-failed setUp cannot

leak the temp directory. shutil is imported at the top;

the now-redundant tearDown blocks are dropped.

P3-B: MainSubprocessCheck now also runs the gate with

cwd set to a subdirectory of the throwaway repo and a

headerless .go file at the repo root; the assertion proves

exit 1 and that the summary names that file. This is the

automated check for the git-root scan in main().

Mutation: swapping main()'s git-root lookup for os.getcwd()

(and restoring via git checkout -- .github/scripts/reuse_gate.py)

makes the new subdir test fail with exit 0 and 'REUSE gate

**passed**' against an empty cwd, then the suite is green

again with the original lookup restored.

Signed-off-by: colton <colton@futurebuild.ai>
@futurebuildai
futurebuildai merged commit 6d987a2 into refactor/v1 Oct 10, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant