Repository navigation
cli: add shared test coverage for the 7 connect-*-mcp wrappers - #66
Conversation
connect-jira-mcp.ts, connect-linear-mcp.ts, connect-monday-mcp.ts, connect-notion-mcp.ts, connect-sentry-mcp.ts, connect-zoom-mcp.ts, and connect-granola-mcp.ts are each a thin config object handed to the connector framework's shared flow-runner. The adapters one layer down have their own tests, but nothing ever asserted these seven wrapper files actually pass the right adapter and non-empty copy through -- a typo in one file's config (wrong adapter reference, wrong prompt text) would ship silently. Adds apps/cli/test/connect-mcp-wrappers.test.ts covering all seven, mocking runConnectFlow/runOAuthConnectFlow/runManagedConnectFlow from the framework barrel. Those three delegate to the real implementation unless a test in this file is actively intercepting -- framework.test.ts imports the same barrel to test their actual behavior directly, and an outright replacement (even one restored in afterAll) broke that file's tests for the rest of the process. Closes gnt-ai#46 Signed-off-by: waterlemonnn <renjiearl06@gmail.com>
📝 WalkthroughWalkthroughChangesConnect MCP wrapper coverage
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
| mock.module("node:readline", () => ({ | ||
| ...realReadline, | ||
| createInterface: () => ({ | ||
| question: (_prompt: string, cb: (answer: string) => void) => { | ||
| cb(boardIdAnswer); | ||
| }, | ||
| close: () => {}, | ||
| }), | ||
| })); |
There was a problem hiding this comment.
Process-wide readline mock leaks
When the full bun test suite loads another readline-using test or command after this file, the unconditional module mock returns the fixed two-method fake instead of the native interface, causing order-dependent failures or false-positive coverage in unrelated tests. Delegate to realReadline.createInterface whenever the Monday prompt is not actively being intercepted, as the existing Hermes and OpenClaw tests do.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/cli/test/connect-mcp-wrappers.test.ts
Line: 75-83
Comment:
**Process-wide readline mock leaks**
When the full `bun test` suite loads another readline-using test or command after this file, the unconditional module mock returns the fixed two-method fake instead of the native interface, causing order-dependent failures or false-positive coverage in unrelated tests. Delegate to `realReadline.createInterface` whenever the Monday prompt is not actively being intercepted, as the existing Hermes and OpenClaw tests do.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/cli/test/connect-mcp-wrappers.test.ts`:
- Around line 75-83: Update the process.stdin setup and cleanup around the
readline mock to save Object.getOwnPropertyDescriptor(process.stdin, "isTTY")
instead of only its value. Restore the saved descriptor after the test, or
delete process.stdin.isTTY when no original descriptor existed, preserving the
original stdin state.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: d2e85d3d-1fec-4ac6-939c-ad5a5f812e57
📒 Files selected for processing (1)
apps/cli/test/connect-mcp-wrappers.test.ts
| mock.module("node:readline", () => ({ | ||
| ...realReadline, | ||
| createInterface: () => ({ | ||
| question: (_prompt: string, cb: (answer: string) => void) => { | ||
| cb(boardIdAnswer); | ||
| }, | ||
| close: () => {}, | ||
| }), | ||
| })); |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Find later tests that can observe the persistent readline or stdin overrides.
rg -n -C 3 \
--glob '*.{test,spec}.{ts,tsx,js,jsx}' \
'node:readline|createInterface\s*\(|process\.stdin\.isTTY' .Repository: gnt-ai/gnt
Length of output: 6604
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- test file ---'
cat -n apps/cli/test/connect-mcp-wrappers.test.ts | sed -n '1,170p'
printf '%s\n' '--- readline consumers ---'
rg -n -C 5 'createInterface|readline|isTTY' apps/cli/src apps/cli/test \
--glob '*.{ts,tsx,js,jsx}' || true
printf '%s\n' '--- test configuration and Bun version references ---'
rg -n -C 3 'bun test|mock\.module|test\s*:' package.json bunfig.toml apps/cli/package.json .github 2>/dev/null || trueRepository: gnt-ai/gnt
Length of output: 50366
🌐 Web query:
Bun test mock.module global module mock scope test files restore mock.module documentation
💡 Result:
In Bun's test runner, mock.module is used to override the behavior of modules [1][2]. Module Mocking Basics To mock a module, use mock.module(path: string, factory: => Object), where the factory function returns an object containing the module's exports [1][3]. Placement and Preloading Because mock.module is a runtime call rather than a hoisted static directive, it must be executed before the module is imported or used by the code under test [4]. If your tests use static imports (e.g., import {... } from './module'), the mock must be registered before those imports are evaluated [5][4]. To ensure mocks are registered before imports, use the --preload flag to load a setup file containing your mock.module calls [1][4]. Example: bun test --preload./test-setup.ts [4] Scope and Isolation Bun automatically scopes module mocks to the test file that registered them [6]. In recent versions, Bun ensures that mocks are cleared after each test file finishes, preventing interference across different files [6]. If you are using an older version of Bun and experiencing persistence issues, run tests with the --isolate flag to ensure each test file receives a fresh global environment [7]. Restoring Mocks You can use mock.restore to revert mocks [3][8]. Recent updates to Bun have improved the implementation of mock.restore to properly handle module mocks, meaning it will now remove the override and allow subsequent imports to load the original module implementation [8][9]. Best Practices For consistent results, define module mocks in a preload script if they are needed globally across many tests [1][4]. If a mock is only needed for a specific file, call mock.module at the top of that test file, ensuring it precedes any imports of the module being mocked [5][4]. Note: Ensure your factory function returns an object that matches the structure of the original module's exports (including the default export if applicable) [1][10].
Citations:
- 1: https://bun.com/docs/test/mocks
- 2: https://github.com/oven-sh/bun/blob/main/docs/test/mocks.mdx
- 3: https://github.com/oven-sh/bun/blob/74e191b3/packages/bun-types/test.d.ts
- 4: https://dev.to/gabrielanhaia/mocking-esm-in-2026-vitest-bun-and-nodes-mockmodule-hep
- 5: https://helpmetest.com/blog/bun-test-runner-deep-dive/
- 6: bun test: scope mock.module() to the test file that registered it oven-sh/bun#31319
- 7: Restore mock.module using mock.restore not work as expect oven-sh/bun#7823
- 8: bun:test: make mock.restore() revert mock.module() overrides oven-sh/bun#35669
- 9: fix:
mock.restore()properly handlesmock.module()oven-sh/bun#18171 - 10: Bun test module mocking not working oven-sh/bun#12062
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- Bun version declarations ---'
rg -n -C 2 '"packageManager"|"bun"|"`@types/bun`"|bunfig|--isolate' \
package.json apps/cli/package.json bunfig.toml \
bun.lock bun.lockb .github 2>/dev/null || true
printf '%s\n' '--- mock lifecycle APIs in tests ---'
rg -n -C 3 'mock\.(module|restore|clearAllMocks|restoreAllMocks)|afterEach|afterAll' \
apps/cli/test --glob '*.{test,spec}.ts' | head -250
printf '%s\n' '--- exact framework test imports ---'
rg -n -C 5 'mcp-framework/index\.js|runConnectFlow|runOAuthConnectFlow|runManagedConnectFlow' \
apps/cli/test --glob '*.{test,spec}.ts' | head -200Repository: gnt-ai/gnt
Length of output: 31263
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- CI Bun setup ---'
rg -n -C 4 'oven-sh/setup-bun|bun-version|bun install|bun test' \
.github package.json apps/cli 2>/dev/null | head -250 || true
printf '%s\n' '--- direct createInterface imports in wrapper dependencies ---'
for f in apps/cli/src/commands/connect-{jira,linear,monday,notion,sentry,zoom,granola}-mcp.ts; do
printf '\n--- %s ---\n' "$f"
sed -n '1,80p' "$f"
done
rg -n 'createInterface' apps/cli/src/prebrain/mcp-framework apps/cli/src/prebrain/mcp-{jira,linear,monday,notion,sentry,zoom,granola}.ts 2>/dev/null || true
printf '%s\n' '--- runtime descriptor and Bun availability ---'
node - <<'JS'
const descriptor = Object.getOwnPropertyDescriptor(process.stdin, "isTTY");
console.log(JSON.stringify({
node: process.version,
ownDescriptor: descriptor && {
configurable: descriptor.configurable,
enumerable: descriptor.enumerable,
writable: descriptor.writable,
hasValue: "value" in descriptor,
value: descriptor.value,
hasGetter: typeof descriptor.get === "function",
hasSetter: typeof descriptor.set === "function",
},
inherited: process.stdin.isTTY,
}));
JS
command -v bun && bun --version || echo 'bun: unavailable'Repository: gnt-ai/gnt
Length of output: 35110
🌐 Web query:
Bun 1.3.14 bun:test mock.module scoped to test file module mocks automatically cleared after each test file
💡 Result:
In Bun, mock.module() is now automatically scoped to the test file that registered it [1][2]. This functionality was introduced to ensure that mocks do not leak across different test files when running in the default, shared-process test runner [1][2]. When a test file finishes execution, Bun triggers a teardown routine that clears these "transient" module mocks, ensuring that subsequent test files receive the original, un-mocked modules [1][2]. This behavior is handled automatically by the test runner and does not require manual clearing for file-level isolation [1][2]. Key details regarding this behavior include: * Automatic Scoping: The test runner tracks mocks created via mock.module() and associates them with the specific file where they were registered [1]. Upon completion of that file's tests, the runner performs a cleanup to remove these specific mocks from the internal module registry [1]. * Persistent Mocks: Mocks registered during the --preload phase or through Bun.plugin({module}) are considered persistent and are not automatically cleared during the per-file teardown [1][3]. * Isolating Test Files: While mock.module() is now scoped per file, you can still use the --isolate flag when running bun test. This flag runs each test file in a completely fresh JavaScript Global Object (a new VM environment) on the same JSC VM, which provides an even stronger isolation guarantee by completely resetting the module graph, globals, and mock state between files [4]. This change allows Bun to maintain high performance by avoiding the overhead of spawning a new process for every single test file while still ensuring that module mocks remain isolated to the file that defined them [2].
Citations:
- 1: bun test: scope mock.module() to the test file that registered it oven-sh/bun#31319
- 2: Real-world vitest → bun test migration: gaps that force per-file process isolation oven-sh/bun#31316
- 3: bun:test: make mock.restore() revert mock.module() overrides oven-sh/bun#35669
- 4: Bun mocks to be scoped to test file oven-sh/bun#12823
Restore the original process.stdin.isTTY descriptor.
mock.module("node:readline", ...) is scoped to this test file in Bun 1.3.14. The remaining issue is lines 131-136: they save only the isTTY value. Save Object.getOwnPropertyDescriptor(process.stdin, "isTTY") and restore that descriptor; delete the property if no descriptor existed originally.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/cli/test/connect-mcp-wrappers.test.ts` around lines 75 - 83, Update the
process.stdin setup and cleanup around the readline mock to save
Object.getOwnPropertyDescriptor(process.stdin, "isTTY") instead of only its
value. Restore the saved descriptor after the test, or delete
process.stdin.isTTY when no original descriptor existed, preserving the original
stdin state.
|
Great work on this — covers all seven wrappers cleanly and matches the issue exactly. Thanks for contributing! If you're into what we're building, feel free to star the repo and share it with others. |
What & why
Seven
gnt connect <x>-mcpcommands (connect-jira-mcp.ts,connect-linear-mcp.ts,connect-monday-mcp.ts,connect-notion-mcp.ts,connect-sentry-mcp.ts,connect-zoom-mcp.ts,connect-granola-mcp.ts) are each a thin config object handed to theconnector framework's shared flow-runner (
runConnectFlow/runOAuthConnectFlow/runManagedConnectFlow). The adapters one layer down have their own tests, but nothing everasserted these seven wrapper files pass the right adapter and non-empty copy through — a typo in
one file's config (wrong adapter reference, wrong prompt text) would ship silently.
Adds one shared test file,
apps/cli/test/connect-mcp-wrappers.test.ts, mocking the threeflow-runners and asserting each wrapper invokes the right one with the right adapter reference
and non-empty intro/prompt copy.
One wrinkle worth flagging:
test/prebrain/mcp-framework/framework.test.tsimports the samebarrel to test
runConnectFlow/runOAuthConnectFlow's actual behavior directly, so an outrightmock (even one put back in
afterAll) broke that file's tests for the rest of thebun testprocess — Bun's module mocks are live-bound across every file sharing the process, and restoring
in
afterAlldidn't reliably take effect before that file's tests ran. Instead, the three mockedexports here delegate to the real implementation unless a test in this file is actively
"intercepting" (a flag scoped to a single
connectXMcp()call), soframework.test.tskeepsexercising the real flow logic untouched.
Test plan
Also ran the full suite (
bun test) before and after this change — same 7 pre-existing failuresboth times (all
zip-binary/POSIX-permissions tests that don't run on this machine, unrelated tothis change), confirming this file doesn't regress
framework.test.tsor anything else thattouches the same barrel module.
bun run typecheckandbun run lintboth clean.Before you open this
git commit -s)bun test connect-mcp-wrappers.test.tsand the full suite locallymock.modulefor the framework barrel, same precedent asorg.test.ts/connect-hermes.test.tsmocking other shared modules;node:readlinemockshape matches
connect-hermes.test.ts)apps/cli/src/prebrain/extraction/Closes #46
Summary by CodeRabbit
Greptile Summary
Adds shared tests for the seven MCP connection-command wrappers.
Confidence Score: 4/5
The PR is not yet safe to merge because its readline mock still leaks across the shared Bun test process and can alter unrelated tests.
The previously reported issue remains in the current code: the test installs an unconditional process-wide replacement for
node:readline.createInterfacewithout delegating to the real implementation outside the Monday interception.Files Needing Attention: apps/cli/test/connect-mcp-wrappers.test.ts
Important Files Changed
Reviews (2): Last reviewed commit: "Merge branch 'main' into test/connect-mc..." | Re-trigger Greptile