Skip to content

test: take the probe and prewarm scratch dirs from pytest-owned roots - #38265

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix-semgrep-tmpdir
Nov 17, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix-semgrep-tmpdir

Conversation

@jeeshofone

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A PR whose merge-base predates two test files no longer fails SAST on five lines it never touched.

Five tempfile.mkdtemp calls in two test modules match kirocrew.test-shared-tmp-dir, which #38029 widened to every test file. The SAST job scans only lines that are new against the PR's merge-base. When the merge-base predates these files, the job counts the five lines as new and the PR fails SAST: run 44008212922 on #38238 is the example. Main's own CI never reports them because the SAST job does not run on pushes to main.

Why it matters

Until the files are fixed, any contributor whose branch is older than #36922 or #30671 gets a red SAST check for code outside their diff, and has to rebase to clear it.

Not a goal

What changed (motivation → approach → change)

The rule asks for a pytest-owned directory. test_mcp_footprint_stub_probe.py made its socket dirs with mkdtemp(prefix=SHORT_TMP_PREFIX, dir=short_tmp_base()) because macOS caps an AF_UNIX path at 104 bytes and a deep tmp_path exceeds that. The suite already has a fixture for exactly that case, short_sock_dir in test/conftest_opt_in.py, built on the same short_tmp_base() and SHORT_TMP_PREFIX and removed at teardown. The four probe tests now take it, so the short path is kept and the hand-written try/rmtree blocks go. The 15% PSS test already used short_sock_dir for the daemon socket, so its probe gets an empty probe/ subdirectory of it.

test_acp_node_compile_cache_engine.py made the prewarm sandbox scratch with mkdtemp(dir=run_parent) under the data home. The data home in a test is that test's own isolation dir under pytest's basetemp, so the scratch is now a fixed scratch child of the same parent: still inside the data home the sandbox reads, unique per test, and removed with the run.

Backwards compatibility

Compatible: test files only; no production code changes.

Removes nothing: the diff drops two unused imports and test-local rmtree cleanup that the fixture now does.

Tests

Both modules pass before and after on Linux: 18 passed, 2 skipped (no agent engine or sandbox backend on the test host, the same two skips as main). semgrep --config semgrep/ reports nothing on either file. Pre-push gate: 21 ran, 0 failed.

Proof: not provable -- test-only change

Manual verification

N/A — test-only change; the module runs and the Semgrep rule are the check.

Related Issues

Fixes #38264

Surfaced by #38238 (run 44008212922). Rule widened in #38029; earlier conversions under #37621.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@jeeshofone
jeeshofone requested review from a team and KiroCrewCaptain as code owners November 17, 2026 05:03
@jeeshofone
jeeshofone requested a review from CrysisDeu November 17, 2026 05:03
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 17, 2026
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ⏭️ skipped

Revision 45b6a29298d098b607f9e45a3d4cca3a8e431724 ships no reviewable capability (docs, tests or generated files only), so there is nothing to inventory. Does not block merge.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 45b6a29298d098b607f9e45a3d4cca3a8e431724 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 45b6a29298d098b607f9e45a3d4cca3a8e431724 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the change is test-only, reuses the suite's existing short_sock_dir seam, and keeps the short socket path.

Notes

  • The description and the diff disagree. The description says the 15% PSS probe gets "an empty probe/ subdirectory", but the diff passes short_sock_dir directly, and its comment says another level would overflow sun_path. The description also doesn't mention the new test_the_short_sock_dir_socket_fits_sun_path test. Correct the description in a PR comment, since the goal sections are frozen.

[DESIGN-REVIEWED] 45b6a29

Description read

[DESCRIPTION-READ] 9690cf3249871af5ab69839cdc84a18cf00b79ab9ec29d9c06d183fdc92b107e

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 45b6a29298d098b607f9e45a3d4cca3a8e431724 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 45b6a29

Verdict parsed from the review's SHA-scoped output markers for commit 45b6a29298d098b607f9e45a3d4cca3a8e431724.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 45b6a29298d098b607f9e45a3d4cca3a8e431724 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 45b6a29298d098b607f9e45a3d4cca3a8e431724 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 45b6a29

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 45b6a29298d098b607f9e45a3d4cca3a8e431724 false-positive: <reason, 20 to 500 characters>

The test-shared-tmp-dir rule (widened in #38029) matches five mkdtemp
sites that predate it. The footprint probe tests now take the existing
short_sock_dir fixture, which keeps the short AF_UNIX path from
short_tmp_base() and SHORT_TMP_PREFIX. The prewarm sandbox test makes its
scratch inside the per-test data home.

Fixes #38264
@jeeshofone

Copy link
Copy Markdown
Contributor Author

GPT F1 (socket path over sun_path): fixed in 45b6a29. The 15% PSS test now passes short_sock_dir straight to _probe(), which makes its own kc-fp- child, so the extra probe/ level is gone. The new test_the_short_sock_dir_socket_fits_sun_path builds the worst-case path from the run's own prefix (32-character login, which the root caps at 24, and a 7-digit PID). That path is 104 bytes, under _MAX_SOCKET_PATH = 107. With the old probe/ level back it reaches 110 bytes and the test fails, which a mutation check confirmed.

CodeQL neutral: "configuration not found" comes from main having no codeql.yml configuration for this check. It is a repo-side setting, outside this diff.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 17, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider estimates a 6% chance that this change introduces a defect, within the 12% limit for approving on its own, but it is held at tier pending: being reviewed.

Test-only change that replaces five tempfile.mkdtemp calls with pytest-owned dirs. The probe tests now take the existing short_sock_dir fixture. It is built on the same short_tmp_base() and SHORT_TMP_PREFIX as the old code and cleans up at teardown, so the removed try/rmtree blocks lose nothing. On Linux the fixture never falls back to tmp_path, and _probe() makes and removes its own kc-fp- subdir, so the empty-directory assertions stay meaningful. The extra "unixsock-" label makes the worst-case socket path 104 bytes, under the 107-byte _MAX_SOCKET_PATH, and a new test pins that calculation. The prewarm scratch moves to a fixed name under the data home, which is unique per test because of the _isolation_dirs counter. CI is green, including SAST.

Tier: pending: being reviewed.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit 45b6a29298 · 94 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) November 17, 2026 07:12

@KiroCrewCaptain KiroCrewCaptain 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.

I reviewed head 45b6a29. All five flagged tempfile.mkdtemp sites are gone. The four footprint probe tests now use the existing short_sock_dir fixture. That fixture uses the same short root and SHORT_TMP_PREFIX, and it cleans up at teardown, so the removed try/rmtree blocks lose nothing and the iterdir() == [] checks still start from an empty directory. The prewarm test's fixed scratch child sits under a per-test data home taken from tmp_path_factory, so two tests cannot collide. I recomputed the worst-case socket path: 104 bytes against the 107-byte limit, and 110 if the old probe/ level comes back. No assertion, rule or baseline is loosened. The change adds no sleep, clock or port, and the getpass.getuser patch goes through monkeypatch. PR Readiness is green on this head.

Done well: the fix uses the suite's one short-path fixture instead of a suppression, and it pins the sun_path budget that the move to the fixture tightens.

Optional:

  • test_the_short_sock_dir_socket_fits_sun_path builds its path from its own copies of short-, unixsock- and kc-fp-. If any of those labels gets longer, the test stays green. Making them constants in the modules that own them, and importing those constants, would let the pin catch that.
  • The edited hunk in test_acp_node_compile_cache_engine.py is in a @needs_sandbox test, and that test is skipped in CI. If you have a host with the engine and a sandbox backend, a single local run would add evidence for that hunk.

@KiroCrewCaptain
KiroCrewCaptain merged commit 542fb4b into main Nov 17, 2026
98 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix-semgrep-tmpdir branch November 17, 2026 07:12
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 17, 2026
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.

ci: SAST reports test-shared-tmp-dir lines a PR never touched when its merge-base predates them

2 participants