Skip to content

cli: add shared test coverage for the 7 connect-*-mcp wrappers - #66

Merged
lukaadzic merged 2 commits into
gnt-ai:mainfrom
waterlemonnn:test/connect-mcp-wrapper-coverage
Aug 6, 2026
Merged

lukaadzic merged 2 commits into
gnt-ai:mainfrom
waterlemonnn:test/connect-mcp-wrapper-coverage

Conversation

@waterlemonnn

@waterlemonnn waterlemonnn commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

What & why

Seven gnt connect <x>-mcp commands (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 the
connector framework's shared flow-runner (runConnectFlow / runOAuthConnectFlow /
runManagedConnectFlow). The adapters one layer down have their own tests, but nothing ever
asserted 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 three
flow-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.ts imports the same
barrel to test runConnectFlow/runOAuthConnectFlow's actual behavior directly, so an outright
mock (even one put back in afterAll) broke that file's tests for the rest of the bun test
process — Bun's module mocks are live-bound across every file sharing the process, and restoring
in afterAll didn't reliably take effect before that file's tests ran. Instead, the three mocked
exports here delegate to the real implementation unless a test in this file is actively
"intercepting" (a flag scoped to a single connectXMcp() call), so framework.test.ts keeps
exercising the real flow logic untouched.

Test plan

$ bun test connect-mcp-wrappers.test.ts
bun test v1.3.14

 7 pass
 0 fail
 42 expect() calls
Ran 7 tests across 1 file. [172.00ms]

Also ran the full suite (bun test) before and after this change — same 7 pre-existing failures
both times (all zip-binary/POSIX-permissions tests that don't run on this machine, unrelated to
this change), confirming this file doesn't regress framework.test.ts or anything else that
touches the same barrel module.

bun run typecheck and bun run lint both clean.

Before you open this

  • Commits are signed off (git commit -s)
  • Functionally correct: ran bun test connect-mcp-wrappers.test.ts and the full suite locally
  • No dead code
  • Non-trivial logic (new test file covering 7 wrappers) has tests, by definition
  • N/A — doesn't touch multi-tenant data paths, this is CLI-side wiring only
  • Matches existing patterns (mock.module for the framework barrel, same precedent as
    org.test.ts/connect-hermes.test.ts mocking other shared modules; node:readline mock
    shape matches connect-hermes.test.ts)
  • N/A — doesn't touch apps/cli/src/prebrain/extraction/

Closes #46

Summary by CodeRabbit

  • Tests
    • Added coverage for all seven MCP connection command wrappers.
    • Verified command metadata, prompts, validation, adapter selection, flow types, and saved connection hints.
    • Added coverage for interactive board selection during Monday setup.

Greptile Summary

Adds shared tests for the seven MCP connection-command wrappers.

  • Intercepts the shared connect-flow runners and verifies each wrapper’s flow type, adapter, command metadata, prompts, and saved hint.
  • Exercises Monday’s interactive board-ID path with a readline stub.

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.createInterface without delegating to the real implementation outside the Monday interception.

Files Needing Attention: apps/cli/test/connect-mcp-wrappers.test.ts

Important Files Changed

Filename Overview
apps/cli/test/connect-mcp-wrappers.test.ts Adds consolidated wrapper-wiring coverage for all seven MCP connection commands.

Reviews (2): Last reviewed commit: "Merge branch 'main' into test/connect-mc..." | Re-trigger Greptile

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>
@waterlemonnn
waterlemonnn requested a review from lukaadzic as a code owner August 6, 2026 08:58
@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Connect MCP wrapper coverage

Layer / File(s) Summary
Shared MCP wrapper test harness
apps/cli/test/connect-mcp-wrappers.test.ts
The test setup intercepts shared MCP flow runners, preserves real behavior outside interception, stubs Monday’s readline prompt, imports all wrappers and adapters, and resets state before each test.
Seven wrapper configuration checks
apps/cli/test/connect-mcp-wrappers.test.ts
Tests cover Jira, Linear, Monday, Notion, Sentry, Zoom, and Granola. They verify flow selection, adapter identity, command metadata, prompts or intros, saved hints, and Monday board validation wiring.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: lukaadzic

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The test file covers all seven wrappers and verifies the required flow runners, adapters, and non-empty copy from issue #46.
Out of Scope Changes check ✅ Passed The changes are limited to wrapper test coverage and supporting test isolation, which directly matches issue #46.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly and concisely identifies the added shared test coverage for all seven connect MCP wrappers.
Description check ✅ Passed The description covers the change rationale, test plan, checklist, known suite failures, tooling results, and linked issue.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment on lines +75 to +83
mock.module("node:readline", () => ({
...realReadline,
createInterface: () => ({
question: (_prompt: string, cb: (answer: string) => void) => {
cb(boardIdAnswer);
},
close: () => {},
}),
}));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 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.

Fix in Claude Code

@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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 562cac6 and 4cdd2b9.

📒 Files selected for processing (1)
  • apps/cli/test/connect-mcp-wrappers.test.ts

Comment on lines +75 to +83
mock.module("node:readline", () => ({
...realReadline,
createInterface: () => ({
question: (_prompt: string, cb: (answer: string) => void) => {
cb(boardIdAnswer);
},
close: () => {},
}),
}));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 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 || true

Repository: 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:


🏁 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 -200

Repository: 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:


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.

@lukaadzic

Copy link
Copy Markdown
Member

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.

@lukaadzic
lukaadzic merged commit a48dd8d into gnt-ai:main Aug 6, 2026
13 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.

Add shared test coverage for the 7 connect-*-mcp command wrappers

2 participants