Skip to content

test(mcpx): bind test sockets in a short socket dir, not t.TempDir (dezren39/nix#434) - #333

Merged
dezren39 merged 1 commit into
mainfrom
sweep/434-short-socket-dir
Oct 19, 2026
Merged

dezren39 merged 1 commit into
mainfrom
sweep/434-short-socket-dir

Conversation

@dezren39

@dezren39 dezren39 commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Port of the fix for dezren39/darwin-nix#434 (origin issue for this cross-repo set; the identical mcpx copy lives in both repos)

Problem

TestStopAllStopsDaemonFoundInDefaultDir rooted its fake XDG home in t.TempDir(), then bound a unix socket at <tmp>/mcpx/daemon.sock. Under a nix sandbox build the per-build TMPDIR is long and deeply nested, and t.TempDir() nests further (<tmp>/<TestName><rand>/001/...), pushing the socket path past Darwin's 104-byte sockaddr_un limit — bind: invalid argument before any stop logic runs. Reproduced on Linux (108-byte limit) with an artificially long TMPDIR: pre-fix the test fails at stopall_test.go:85 with the issue's exact error.

Solution

  • New shared helper testsupport.SocketDir: a symlink-resolved scratch directory created directly under /tmp (the pattern testsupport.TempDir's out-of-home fallback and the daemon tests' isolate() already use), which fails the test if a daemon.sock inside it would exceed the 100-byte ceiling the product itself uses (daemon.maxSocketPath). New TestSocketDirStaysShortUnderALongTmpDir pins it.
  • stopall_test.go: customStateApp roots the XDG home (the socket's host dir) in SocketDir.
  • Sibling audit (the issue asked for it): sdnotify's TestReadyAndMainPIDReachTheSocket binds its notify socket on a t.TempDir() path and fails identically under the same long TMPDIR — fixed the same way. The daemon package's socket tests are already safe: the product's socketPath hashed fallback moves over-long sockets (verified: TestResolveReportsRunningOnlyWhenSomethingAccepts passes under the long TMPDIR), and the server tests use os.MkdirTemp("", ...) directly under TMPDIR. A full internal/daemon run under the long TMPDIR is green.

Test-only change; no product code touched.

Verification

  • Pre-fix, long TMPDIR: TestStopAllStopsDaemonFoundInDefaultDir FAIL (bind EINVAL), internal/sdnotify FAIL the same way; internal/cli suite fails on only that one test.
  • Post-fix, same long TMPDIR: stop-all -count=5 pass (the issue's acceptance command), internal/sdnotify + internal/testsupport pass.
  • Normal env: full internal/cli (23.5s), internal/daemon (79.6s), internal/sdnotify, internal/testsupport suites green; go vet clean on the touched packages; edited files gofmt-clean.

The identical mcpx copy in developing-today/code gets the byte-identical change in a companion PR referencing this issue (one issue tracks the set, per the cross-repo rule).

Companion PR in dezren39/nix: dezren39/darwin-nix#444 (byte-identical change).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Tests
    • Improved reliability of socket-related tests on macOS by ensuring temporary socket paths stay within platform length limits, including when the system’s temporary directory path is long.

)

TestStopAllStopsDaemonFoundInDefaultDir rooted its XDG home in t.TempDir(), so under a nix sandbox build's long TMPDIR the daemon socket path exceeded Darwin's 104-byte sockaddr_un limit and bind failed with EINVAL before the stop logic ran. Add testsupport.SocketDir (a resolved scratch dir directly under /tmp that fails the test if a daemon.sock inside it would exceed the 100-byte ceiling), root the stop-all test's XDG home in it, and apply the same fix to sdnotify's TestReadyAndMainPIDReachTheSocket, which binds its notify socket on a t.TempDir path and fails identically under a long TMPDIR. Sibling audit: daemon socket tests are already safe (product socketPath hashed fallback / MkdirTemp directly under TMPDIR), verified by a full internal/daemon run under the same long TMPDIR.
@dezren39
dezren39 requested a review from a team as a code owner October 19, 2026 03:39
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T03:42:41.423852Z 31202f1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 56d0e8d9-e7a6-466e-b746-5d5bbfa9db11
📥 Commits

Reviewing files that changed from the base of the PR and between 9cc54fd and 31202f1.

📒 Files selected for processing: 4
  • pkgs/mcpx/internal/cli/stopall_test.go
  • pkgs/mcpx/internal/sdnotify/sdnotify_test.go
  • pkgs/mcpx/internal/testsupport/tempdir.go
  • pkgs/mcpx/internal/testsupport/tempdir_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

📝 Walkthrough

Tests that create Unix sockets now use a shared helper to create short temporary directories. The helper checks the socket path length, and a new test verifies it works when TMPDIR and GOTMPDIR point to a long path.

Changes: Short Unix Socket Paths

Layer / File(s) Summary
Create and use short socket directories
pkgs/mcpx/internal/testsupport/tempdir.go, pkgs/mcpx/internal/testsupport/tempdir_test.go, pkgs/mcpx/internal/cli/stopall_test.go, pkgs/mcpx/internal/sdnotify/sdnotify_test.go
SocketDir creates a temporary directory under /tmp, registers cleanup, resolves the path, and fails if the daemon.sock path exceeds 100 bytes. Its test checks behavior with long temporary-directory environment paths. The stop-all and sdnotify tests use the helper for their socket directories.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Merge Risk: ⚪ Minimal · up to 31202

No merge-blocking issue is identified; merge after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the main change: test sockets now use a short socket directory instead of t.TempDir. It is specific and related to the changeset.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

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