fix: handle cli metadata flags before startup#145
Conversation
📝 WalkthroughWalkthroughThis PR adds CLI metadata flag handling ( ChangesCLI Metadata Flags and Cross-Platform Integration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
mcp-server/src/package-published-esm.integration.test.ts (1)
40-40: ⚡ Quick winConsider extracting shared test utilities.
Both
npmCommandand thepackTarballfunction are duplicated between this file andcli-bin.integration.test.ts(context snippet 1). Extracting them to a shared test utility module would eliminate duplication and make future changes easier.♻️ Suggested approach
Create
mcp-server/src/test/test-utils.ts:import { execFileSync } from "node:child_process"; import { readdirSync } from "node:fs"; import path from "node:path"; export const npmCommand = process.platform === "win32" ? "npm.cmd" : "npm"; export const npxCommand = process.platform === "win32" ? "npx.cmd" : "npx"; export function packTarball(root: string, packDest: string): string { execFileSync( npmCommand, ["pack", "--ignore-scripts", "--pack-destination", packDest], { cwd: root, shell: process.platform === "win32", stdio: ["ignore", "pipe", "pipe"], }, ); const tgz = readdirSync(packDest).filter((f) => f.endsWith(".tgz")); if (tgz.length !== 1) { throw new Error(`expected one .tgz in ${packDest}, got: ${tgz.join(", ")}`); } return path.join(packDest, tgz[0]); }Then import in both test files:
-const npmCommand = process.platform === "win32" ? "npm.cmd" : "npm"; +import { npmCommand, packTarball } from "./test/test-utils.js";Also applies to: 43-59
🤖 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 `@mcp-server/src/package-published-esm.integration.test.ts` at line 40, The tests duplicate the npmCommand constant and packTarball function across test files; extract them into a shared test utility module (e.g., test-utils.ts) and export npmCommand and packTarball so both tests can import them; update the tests to import the shared npmCommand constant and packTarball function instead of redefining them, ensuring packTarball still uses execFileSync with the same args and behavior (including platform-aware shell and the single-tgz validation) and that npmCommand remains platform-aware (process.platform === "win32" ? "npm.cmd" : "npm").
🤖 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.
Nitpick comments:
In `@mcp-server/src/package-published-esm.integration.test.ts`:
- Line 40: The tests duplicate the npmCommand constant and packTarball function
across test files; extract them into a shared test utility module (e.g.,
test-utils.ts) and export npmCommand and packTarball so both tests can import
them; update the tests to import the shared npmCommand constant and packTarball
function instead of redefining them, ensuring packTarball still uses
execFileSync with the same args and behavior (including platform-aware shell and
the single-tgz validation) and that npmCommand remains platform-aware
(process.platform === "win32" ? "npm.cmd" : "npm").
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 43c86ae4-b416-4c1d-bdf3-ff3ad99be370
📒 Files selected for processing (5)
mcp-server/src/cli-bin.integration.test.tsmcp-server/src/cli.test.tsmcp-server/src/cli.tsmcp-server/src/index.tsmcp-server/src/package-published-esm.integration.test.ts
Summary
--help/-hand--version/-vbefore starting the MCP serverCURRENTS_API_KEYCURRENTS_API_KEYReproduction before this change
With
@currents/mcp@2.3.2installed and noCURRENTS_API_KEYset:Both commands exited 1 with
CURRENTS_API_KEY is not setinstead of showing CLI metadata.Verification
Results:
--helpexits 0 and prints usage withoutCURRENTS_API_KEY--versionexits 0 and prints2.3.2withoutCURRENTS_API_KEYSummary by CodeRabbit
Release Notes
New Features
--helpand--versionCLI flags with proper error handling for unknown optionsTests