Skip to content

test: isolates temp test fixtures - #1569

Merged
rdimitrov merged 2 commits into
modelcontextprotocol:mainfrom
yowainwright:fix/test-temp-dir-isolation
Sep 5, 2026
Merged

test: isolates temp test fixtures#1569
rdimitrov merged 2 commits into
modelcontextprotocol:mainfrom
yowainwright:fix/test-temp-dir-isolation

Conversation

@yowainwright

@yowainwright yowainwright commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Motivation and Context

Replace shared temp paths with `t.TempDir()`` so each test gets its own cleanup-scoped directory.

  • This avoids leftover files and cross-test interference. No production code changed.

How Has This Been Tested?

GitHub CI passed.

Breaking Changes

No breaking changes; just tests.

Types of changes

  • chore

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Small test-only cleanup. No production code paths are changed.

@yowainwright

Copy link
Copy Markdown
Contributor Author

@rdimitrov quick cleanup PR. Would love to help more here! No urgency!

@yowainwright yowainwright changed the title test: isolates temp test fixtures fix: isolates temp test fixtures Aug 28, 2026

@JosephDoUrden JosephDoUrden left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested this one properly. Planted /tmp/non-existent-file.json on main and TestImportService_ErrorHandling really does fail there, the non-existent case "succeeds" and then nil derefs. Same planted file against this branch, immune, t.TempDir() is guaranteed empty. So the importer_test change is a real fix, not just cleanup. The commands ones were already unique via MkdirTemp so those are cleanup, but the autocleanup is still nicer. Also the chdir error is now actually checked instead of swallowed, good.

go test -race -count=2 on both packages green, golangci-lint v2.13.1 0 issues, branch is 0 behind main.

One small thing btw, the title got renamed to fix: but the change is test only and the single commit still says test:. Squash takes the PR title here so this would land in the changelog as a bug fix. I'd rename it back to test:.

Looks merge-ready apart from that.

@yowainwright yowainwright changed the title fix: isolates temp test fixtures test: isolates temp test fixtures Aug 28, 2026
@yowainwright

Copy link
Copy Markdown
Contributor Author

@JosephDoUrden updated the PR title. Thank you for the review!

@JosephDoUrden

Copy link
Copy Markdown
Contributor

Title looks right now and the branch is unchanged since my review, so nothing else from me. Still merge-ready.

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@yowainwright @JosephDoUrden - Thank you both! 🚀 🙌

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The changes are test-only, improve isolation/cleanup, and the updated temp-dir usage and error checks look correct and consistent across the touched tests.

Pull request overview

This PR improves test isolation by replacing shared/global temp paths with t.TempDir() so each test gets its own automatically cleaned-up temporary directory, reducing cross-test interference and leftover files.

Changes:

  • Updated importer tests to write seed/invalid JSON files under t.TempDir() instead of OS-level temp locations and manual cleanup.
  • Updated publisher command tests to use t.TempDir() and to fail fast if os.Chdir fails.
  • Simplified test utilities by using t.TempDir() rather than manually creating/removing temp directories.
File summaries
File Description
internal/importer/importer_test.go Moves temp file usage to t.TempDir() and simplifies error-case fixtures for missing/invalid files.
cmd/publisher/commands/validate_test.go Uses t.TempDir() for per-test working directories and checks os.Chdir errors.
cmd/publisher/commands/testutil_test.go Uses t.TempDir() for server.json fixtures and relies on Go’s built-in temp cleanup.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@rdimitrov
rdimitrov merged commit dd4b293 into modelcontextprotocol:main Sep 5, 2026
3 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.

4 participants