Skip to content

test(isolation): reject temporary directories inside Git checkouts - #1349

Merged
SaulMoro merged 1 commit into
Tencent:mainfrom
nateEc:fix/1338-test-tmpdir-guard
Oct 23, 2026
Merged

SaulMoro merged 1 commit into
Tencent:mainfrom
nateEc:fix/1338-test-tmpdir-guard

Conversation

@nateEc

@nateEc nateEc commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

If TMPDIR lives inside a contributor's checkout, a temporary fixture without its own .git can inherit that checkout's Git root and deliver TeamAI files into the source tree. HOME isolation alone cannot prevent this.

Run a shared temporary-directory guard before workers in both Vitest configurations, before the shared OpenCode installer in E2E. Resolve the real temporary path and reject any ancestor .git directory or file with an actionable environment-variable message. This is tests-only; production CLI behavior is unchanged.

Validation:

  • RED: four unsafe-directory regression cases failed with the initial no-op guard.
  • npx vitest run src/__tests__/test-tmpdir-safety.test.ts: 7 passed, covering safe roots, nested Git directories, linked-worktree .git files, symlinks and checkout roots. Subprocesses load each actual runner configuration and prove rejection before any later setup/worker marker write.
  • npx tsc --noEmit, npm run lint, and git diff --check: passed.
  • npm run test:e2e completed the entire 182-file suite: 175 files passed, 6 skipped, 1 failed; 1,404 tests passed, 64 skipped, 1 failed. The sole failure is the existing submodule-checkout-1041.test.ts case delivers, inherits, cleans up and uninstalls submodules through the real CLI, at the missing hook.teamai-post-checkout.command assertion. A clean main (83f6d1db) build independently reproduced the same case and assertion (focused baseline run with the already-prepared OpenCode installer omitted). Environment: macOS, Node 22.22.1, Apple Git 2.50.1. The final probe-fixture slash normalization also passed all 7 guard/subprocess tests, TypeScript and lint; E2E runtime/setup sources were unchanged by that final test-only adjustment.

State review: global setup only reads os.tmpdir(), real paths and ancestor Git markers; it runs before HOME/TMP fixture creation and before OpenCode preparation. It neither changes process environment nor writes contributor files. Contributor instructions explain how to select a safe temporary directory.

Broader regression: npx vitest run --maxWorkers=6 in a frozen integration worktree containing the five changes finished with 500 files passed, 12,285 tests passed, 36 skipped, 2 failed. Both failures are the pre-existing submodule-checkout.test.ts empty legacy hook-file cases; a clean 83f6d1db worktree independently reproduced 24 passed / the same 2 failed. This is an integration-suite record, not a claim that the baseline is fully green.

Refs #1338. One independently reviewable defect from the issue; the audit/issue remains open for its other items.

- Resolve the real temporary-directory path and reject any ancestor .git directory or linked-worktree file before fixtures can inherit a contributor's repository root and deliver files into it.
- Install the same global preflight in both Vitest configurations, before worker HOME/TMP setup and before the E2E OpenCode installer, with actionable TMPDIR/TMP/TEMP guidance.
- Cover safe roots, nested repositories, checkout roots and symlink targets; load each actual runner config in a subprocess and prove that later setup and worker writes never run after rejection.
- Verify all 7 guard and runner-subprocess cases, TypeScript and lint, and document safe temporary-directory selection in the contributor guide.

Refs: Tencent#1338
@github-actions

Copy link
Copy Markdown

No findings in the specified PR diff.

The changes are limited to test infrastructure and contributor documentation, so no real-CLI/E2E record is required under the review rules. The PR description nevertheless provides detailed validation records and identifies independently reproduced baseline failures.

I did not run, build, or install anything from the PR.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generated by AI during triage.

@nateEc Thanks, approving. This is tests-only, so no real-CLI record is needed.

We ran both Vitest configs on fresh clones of this head, its merge-base 83f6d1db and main 54622c3a, with TMPDIR pointing inside the clone.

  • base and main: the run writes .agents/, .codex/ and .mcp.json into the clone and adds six hook.teamai-* entries to its .git/config.
  • this head: it stops with exit 1 before writing anything: "TMPDIR … is inside the Git checkout …. Set TMPDIR, TMP and TEMP to a directory outside every Git checkout before running tests."

With TMPDIR outside the checkout, the new unit file passes 7/7 and muse-support passes 6/6. tsc, lint and CI pass. Refs #1338 fits: this covers the issue's test-isolation part, and the init subdirectory anchoring stays open.

Optional:

  • [P3 nit] The unit-config probe spreads base.test.globalSetup without a fallback, so if that wiring is ever removed it fails with globalSetup is not iterable instead of the guard message. ?? [] would cover it.
  • [P3 nit] A TMPDIR that doesn't exist fails with a bare ENOENT. Base does the same, so it isn't a regression.
  • The body's full-suite failure in submodule-checkout-1041 passes 21/21 in isolation on both this head and base here, so we couldn't reproduce it.

CI review: it reported no findings and said no real-CLI record is needed for a tests-only change. We agree on both. We couldn't reproduce the baseline failures it refers to (above).

@SaulMoro
SaulMoro merged commit a44493f into Tencent:main Oct 23, 2026
18 checks passed
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…encent#1349)

- Resolve the real temporary-directory path and reject any ancestor .git directory or linked-worktree file before fixtures can inherit a contributor's repository root and deliver files into it.
- Install the same global preflight in both Vitest configurations, before worker HOME/TMP setup and before the E2E OpenCode installer, with actionable TMPDIR/TMP/TEMP guidance.
- Cover safe roots, nested repositories, checkout roots and symlink targets; load each actual runner config in a subprocess and prove that later setup and worker writes never run after rejection.
- Verify all 7 guard and runner-subprocess cases, TypeScript and lint, and document safe temporary-directory selection in the contributor guide.

Refs: Tencent#1338
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.

3 participants