Skip to content

test: add MCP config and provider lifecycle test coverage - #31

Merged
ranvier2d2 merged 1 commit into
mainfrom
test/mcp-and-lifecycle-coverage
Mar 29, 2026
Merged

test: add MCP config and provider lifecycle test coverage#31
ranvier2d2 merged 1 commit into
mainfrom
test/mcp-and-lifecycle-coverage

Conversation

@ranvier2d2

@ranvier2d2 ranvier2d2 commented Mar 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add 29 tests across 3 new files covering previously untested MCP config and provider lifecycle paths
  • mcpTranslation.test.ts (11 tests): TOML/JSON generation, merge-with-marker, server name sanitization
  • McpConfig.test.ts (14 tests): config resolution (project, global, override, format normalization), snapshot persistence, version hashing
  • lifecycle.integration.test.ts (4 tests): resume cursor recovery after adapter death, MCP snapshot survival, stopSession cleanup, concurrent session isolation

Test plan

  • All 29 tests pass locally (bunx vitest run)
  • oxfmt --check clean
  • oxlint 0 warnings, 0 errors
  • tsc --noEmit clean

🤖 Generated with Claude Code


Open with Devin

Summary by CodeRabbit

  • Tests
    • Added integration tests for provider session lifecycle management, including session recovery, MCP snapshot persistence, session teardown, and session isolation.
    • Added test suite for MCP configuration service covering config resolution, snapshot lifecycle, and version hashing.
    • Added test suite for MCP translation utilities validating TOML formatting, config merging, and OpenCode config mapping.

Add 29 tests across 3 files covering previously untested MCP config
resolution, snapshot persistence, translation functions, and provider
session lifecycle (recovery, cleanup, isolation).

- mcpTranslation.test.ts (11 tests): TOML/JSON generation, merge, sanitization
- McpConfig.test.ts (14 tests): config resolution, snapshots, version hashing
- lifecycle.integration.test.ts (4 tests): resume cursor recovery, MCP snapshot
  survival after adapter death, stopSession cleanup, concurrent session isolation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Mar 29, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Three new test suites added to verify MCP configuration service behavior, provider session lifecycle management, and translation utilities. Tests cover adapter recovery, snapshot persistence, configuration resolution, teardown correctness, session isolation, and transport normalization.

Changes

Cohort / File(s) Summary
Integration Tests
apps/server/integration/lifecycle.integration.test.ts
Comprehensive integration tests for ProviderService session lifecycle: adapter death and automatic recovery with persisted resume cursor, MCP snapshot persistence across adapter restarts, session teardown and cleanup, and thread-isolated concurrent session management.
McpConfig Layer Tests
apps/server/src/provider/Layers/McpConfig.test.ts
End-to-end tests for McpConfigService: project and global config resolution with override behavior, transport type normalization, snapshot lifecycle (persist/retrieve/clear), deterministic version hashing, and persisted MCP config reference extraction.
MCP Translation Tests
apps/server/src/provider/mcpTranslation.test.ts
Unit tests for MCP translation utilities: TOML generation and formatting from resolved configs, merge behavior with generated markers, OpenCode config JSON mapping from MCP servers, server name sanitization, and session-specific directory computation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

size:XXL, vouch:trusted

Poem

🐰 With whiskers twitching, tests are spun,
Session recovery, one by one,
Snapshots persist through adapter's fall,
Isolation checks ensure all goes well—
Nine hundred lines of thoughtful test,
To keep your code performing best!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description includes a comprehensive summary of changes with test counts and file breakdown, and documents the test plan with verification steps, but does not follow the template structure (missing 'What Changed', 'Why', 'UI Changes' sections and the checklist). Consider restructuring the description to follow the repository template with explicit 'What Changed' and 'Why' sections, even though the core information is present in summary form.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding test coverage for MCP config and provider lifecycle paths across three new test files with 29 tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/mcp-and-lifecycle-coverage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions github-actions Bot added size:XL vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels Mar 29, 2026

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
apps/server/src/provider/Layers/McpConfig.test.ts (1)

19-24: Consider adding temp directory cleanup for CI environments.

While the OS eventually cleans up temp directories, long-running CI systems can accumulate many temp directories. Consider using a test hook to clean up.

Optional: Add cleanup hook
import { afterEach, beforeEach } from "@effect/vitest";

let tempDirs: string[] = [];

function makeTempContext() {
  const cwd = nodeFs.mkdtempSync(path.join(os.tmpdir(), "mcp-cwd-"));
  const baseDir = nodeFs.mkdtempSync(path.join(os.tmpdir(), "mcp-base-"));
  const stateDir = path.join(baseDir, "userdata");
  tempDirs.push(cwd, baseDir);
  return { cwd, baseDir, stateDir };
}

afterEach(() => {
  for (const dir of tempDirs) {
    nodeFs.rmSync(dir, { recursive: true, force: true });
  }
  tempDirs = [];
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/server/src/provider/Layers/McpConfig.test.ts` around lines 19 - 24, Add
temp-dir tracking and a cleanup hook so CI doesn't accumulate temp folders: in
the test file, import afterEach from "@effect/vitest", introduce a tempDirs:
string[] array, update makeTempContext to push cwd and baseDir into tempDirs,
and add an afterEach() hook that iterates tempDirs and removes each with
nodeFs.rmSync(dir, { recursive: true, force: true }) then clears tempDirs;
reference symbols: makeTempContext, tempDirs, afterEach, nodeFs.rmSync.
apps/server/integration/lifecycle.integration.test.ts (1)

75-93: Consider adding a timeout to prevent indefinite blocking if event count is incorrect.

If the harness produces fewer events than expected, Queue.take will block indefinitely. While this is acceptable since tests control event emission, adding a timeout improves debuggability when tests fail.

Optional: Add timeout for better test failure messages
 return yield* Effect.forEach(
   Array.from({ length: count }, () => undefined),
-  () => Queue.take(queue),
+  () => Queue.take(queue).pipe(
+    Effect.timeout("5 seconds"),
+    Effect.catchTag("TimeoutException", () =>
+      Effect.fail(new Error(`Timed out waiting for event ${count}`))
+    )
+  ),
   { discard: false },
 );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/server/integration/lifecycle.integration.test.ts` around lines 75 - 93,
The helper collectEventsDuring can block forever when Queue.take waits for
missing events; update the implementation so each Queue.take is guarded by a
timeout (e.g., use Effect.timeoutFail or Effect.raceWith) and fail with a clear
error including the expected count and which take timed out; locate the
Array.from(...).forEach -> Queue.take(...) call and replace the plain Queue.take
with a timed variant, ensuring the test receives a deterministic failure instead
of hanging while keeping the same return shape.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/server/integration/lifecycle.integration.test.ts`:
- Around line 75-93: The helper collectEventsDuring can block forever when
Queue.take waits for missing events; update the implementation so each
Queue.take is guarded by a timeout (e.g., use Effect.timeoutFail or
Effect.raceWith) and fail with a clear error including the expected count and
which take timed out; locate the Array.from(...).forEach -> Queue.take(...) call
and replace the plain Queue.take with a timed variant, ensuring the test
receives a deterministic failure instead of hanging while keeping the same
return shape.

In `@apps/server/src/provider/Layers/McpConfig.test.ts`:
- Around line 19-24: Add temp-dir tracking and a cleanup hook so CI doesn't
accumulate temp folders: in the test file, import afterEach from
"@effect/vitest", introduce a tempDirs: string[] array, update makeTempContext
to push cwd and baseDir into tempDirs, and add an afterEach() hook that iterates
tempDirs and removes each with nodeFs.rmSync(dir, { recursive: true, force: true
}) then clears tempDirs; reference symbols: makeTempContext, tempDirs,
afterEach, nodeFs.rmSync.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 15f99200-7469-4b6b-aa79-3c53271995c9

📥 Commits

Reviewing files that changed from the base of the PR and between 6094733 and 2c4c5c3.

📒 Files selected for processing (3)
  • apps/server/integration/lifecycle.integration.test.ts
  • apps/server/src/provider/Layers/McpConfig.test.ts
  • apps/server/src/provider/mcpTranslation.test.ts

@ranvier2d2
ranvier2d2 merged commit cd6d8f8 into main Mar 29, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant