Skip to content

Commit 209a7d4

Browse files
fix: print formatted CLI version to stderr (#569)
Co-authored-by: CharlieHelps <charlie@charlielabs.ai>
1 parent 92379c8 commit 209a7d4

3 files changed

Lines changed: 29 additions & 9 deletions

File tree

.changeset/calm-lions-report.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"hevy-mcp": patch
3+
---
4+
5+
Print the CLI version with the package name to stderr.

src/index.test.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,29 +225,44 @@ describe("Server entry", () => {
225225
});
226226

227227
describe("runServer", () => {
228-
it.each(["--version", "-v"])(
229-
"prints version for %s and exits before server startup",
230-
async (flag) => {
231-
process.env = {
232-
...originalEnv,
233-
HEVY_API_KEY: "test-api-key",
234-
};
228+
it.each([
229+
["--version", undefined],
230+
["-v", ""],
231+
])(
232+
"prints version for %s without an API key and exits before server startup",
233+
async (flag, apiKey) => {
234+
process.env = { ...originalEnv };
235+
if (apiKey === undefined) {
236+
delete process.env.HEVY_API_KEY;
237+
} else {
238+
process.env.HEVY_API_KEY = apiKey;
239+
}
235240
process.argv = [...originalArgv.slice(0, 2), flag];
236241

237242
const logSpy = vi
238243
.spyOn(console, "log")
239244
.mockImplementation(() => undefined);
245+
const errorSpy = vi
246+
.spyOn(console, "error")
247+
.mockImplementation(() => undefined);
248+
const exitSpy = vi
249+
.spyOn(process, "exit")
250+
.mockImplementation(() => undefined as never);
240251

241252
await runServer();
242253

243-
expect(logSpy).toHaveBeenCalledWith("dev");
254+
expect(errorSpy).toHaveBeenCalledExactlyOnceWith("hevy-mcp vdev");
255+
expect(logSpy).not.toHaveBeenCalled();
256+
expect(exitSpy).not.toHaveBeenCalled();
244257
expect(createClient).not.toHaveBeenCalled();
245258
expect(testDoubles.startActiveSpan).not.toHaveBeenCalled();
246259

247260
const anyStdioModule = stdioModule as { __transports?: unknown[] };
248261
expect(anyStdioModule.__transports).toHaveLength(0);
249262

250263
logSpy.mockRestore();
264+
errorSpy.mockRestore();
265+
exitSpy.mockRestore();
251266
},
252267
);
253268

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export async function runServer() {
222222
const cliAction = getCliAction(args);
223223

224224
if (cliAction === "version") {
225-
console.log(version);
225+
console.error(`${name} v${version}`);
226226
return;
227227
}
228228

0 commit comments

Comments
 (0)