Skip to content

[#121] Add sandbox tests for core doctor checks#261

Merged
bguidolim merged 5 commits intomainfrom
bruno/121-doctor-check-sandbox-tests
Mar 21, 2026
Merged

[#121] Add sandbox tests for core doctor checks#261
bguidolim merged 5 commits intomainfrom
bruno/121-doctor-check-sandbox-tests

Conversation

@bguidolim
Copy link
Collaborator

Summary

Add sandbox tests for all core doctor check structs that were made injectable in #256. Each test creates a temp directory, constructs Environment(home: tmpDir), and verifies check behavior against controlled file fixtures — no real ~/ paths are touched. Also fixes pre-existing test failures caused by 1Password SSH agent interfering with git commit in test fixture repos.

Replaces closed PR #257. Part 2 of the #121 series (builds on merged #256).

Changes

  • Add CoreDoctorCheckSandboxTests.swift with 23 tests across 5 suites:
    • MCPServerCheckSandboxTests (5 tests): global/project-scoped servers, missing server, missing file, invalid JSON
    • PluginCheckSandboxTests (3 tests): enabled/not-enabled plugin, missing settings
    • HookCheckSandboxTests (6 tests): present+executable, missing, optional skip, not-executable, fix makes executable, fix when missing
    • ProjectIndexCheckSandboxTests (5 tests): all paths valid, stale paths, empty index, fix prunes stale, global sentinel
    • DerivedDoctorCheckSandboxTests (4 tests): copyPackFile global URL, copyPackFile with project root + fallback, mcpServer uses env, allDoctorChecks forwards env
  • Add commit.gpgsign=false to test repo config in PackFetcherTests and PackUpdaterTests to prevent 1Password SSH agent failures

Test plan

  • swift test passes locally (758 tests, 0 failures)
  • swiftformat --lint . and swiftlint pass without violations
  • Affected commands verified with a real pack (e.g. mcs sync, mcs doctor)

- Add `environment` property to DoctorRunner and 10 check structs
  (CommandCheck, MCPServerCheck, PluginCheck, HookCheck, GitignoreCheck,
  ProjectIndexCheck, PackGitignoreCheck, ExternalCommandExistsCheck,
  ExternalHookEventExistsCheck, ExternalSettingsKeyEqualsCheck),
  replacing all hardcoded `Environment()` calls
- Add `projectRootOverride` to DoctorRunner to bypass
  ProjectDetector.findProjectRoot() in tests
- Flow environment through DerivedDoctorChecks and standaloneDoctorChecks
- Thread environment from DoctorCommand to DoctorRunner
- Pass environment to PackGitignoreCheck in artifactChecks()
- Remove redundant environment parameter from private standaloneDoctorChecks()
- Add 23 tests across 5 suites verifying doctor checks work correctly
  with injected Environment(home: tmpDir)
- Cover MCPServerCheck, PluginCheck, HookCheck, ProjectIndexCheck,
  and DerivedDoctorChecks with full sandbox isolation
- Verify check/fix behavior for pass, fail, warn, skip, and fix paths
- Add `commit.gpgsign=false` to test repo config in PackFetcherTests
  and PackUpdaterTests to prevent 1Password SSH agent interference
- Fix ambiguous #require assertion in CoreDoctorCheckSandboxTests
- Replace duplicated makeSandboxHome with existing makeGlobalTmpDir
- Add PluginCheck invalid JSON test for parity with MCPServerCheck
- Add ExternalHookEventExistsCheck sandbox tests (4 tests: pass,
  fail, skip optional, missing settings)
- Add ExternalSettingsKeyEqualsCheck sandbox tests (4 tests: pass,
  warn mismatch, warn absent, missing settings)
@bguidolim bguidolim merged commit 00c2166 into main Mar 21, 2026
4 checks passed
@bguidolim bguidolim deleted the bruno/121-doctor-check-sandbox-tests branch March 21, 2026 15:59
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