Skip to content

Commit af9efc5

Browse files
committed
test(cli): address review layout and assertion nits
Move the auth command test beside connection and proxy, assert the command's render closure against the exported renderProxyStartup payload, and replace the proxy test's blind client cast with a typed stub that throws on any access.
1 parent f78c2a1 commit af9efc5

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import assert from 'node:assert/strict';
22
import fs from 'node:fs';
33
import path from 'node:path';
44
import { afterEach, test, vi } from 'vitest';
5-
import { runCliCapture } from './cli-capture.ts';
6-
import { writeCliSession } from '../cli/auth-session.ts';
7-
import { mkdtempForTestSync } from './test-utils/tmp-dir.ts';
5+
import { runCliCapture } from '../../../__tests__/cli-capture.ts';
6+
import { writeCliSession } from '../../auth-session.ts';
7+
import { mkdtempForTestSync } from '../../../__tests__/test-utils/tmp-dir.ts';
88

99
afterEach(() => {
1010
vi.unstubAllGlobals();

‎src/cli/commands/__tests__/proxy.test.ts‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ vi.mock('@agent-device/proxy', async (importOriginal) => {
4343
});
4444
vi.mock('../shared.ts', () => ({ writeCommandOutput: mocks.writeCommandOutput }));
4545

46-
import { proxyCommand } from '../proxy.ts';
46+
import { proxyCommand, renderProxyStartup } from '../proxy.ts';
47+
import type { AgentDeviceClient } from '../../../agent-device-client.ts';
48+
49+
// The proxy command never reads the client; a typed stub that throws on any access proves it
50+
// without the `{} as never` blind cast.
51+
const unreferencedClient = new Proxy({} as AgentDeviceClient, {
52+
get: () => {
53+
throw new Error('proxy must not touch the client');
54+
},
55+
});
4756

4857
afterEach(async () => {
4958
vi.clearAllMocks();
@@ -60,7 +69,7 @@ function runProxy(flags: Partial<Parameters<typeof proxyCommand>[0]['flags']> =
6069
void proxyCommand({
6170
positionals: [],
6271
flags: { json: true, help: false, version: false, ...flags },
63-
client: {} as never,
72+
client: unreferencedClient,
6473
});
6574
}
6675

@@ -83,7 +92,7 @@ test('proxy rejects positional arguments', async () => {
8392
proxyCommand({
8493
positionals: ['extra'],
8594
flags: { json: true, help: false, version: false },
86-
client: {} as never,
95+
client: unreferencedClient,
8796
}),
8897
(error: { code?: string }) => error.code === 'INVALID_ARGS',
8998
);
@@ -100,7 +109,7 @@ test('proxy refuses to start when the local daemon has no HTTP endpoint', async
100109
proxyCommand({
101110
positionals: [],
102111
flags: { json: true, help: false, version: false },
103-
client: {} as never,
112+
client: unreferencedClient,
104113
}),
105114
(error: { code?: string; details?: { hint?: string } }) =>
106115
error.code === 'COMMAND_FAILED' && /fresh --state-dir/.test(String(error.details?.hint)),
@@ -131,6 +140,11 @@ test('proxy binds a loopback listener and reports the supplied client token', as
131140
assert.match(proxyBaseUrl, /^http:\/\/(127\.0\.0\.1|\[::1\]):\d+$/);
132141
assert.equal(data.agentDeviceBaseUrl, `${proxyBaseUrl}/agent-device`);
133142
const startupCard = render();
143+
// The human render is the exported startup-card renderer applied to the emitted payload.
144+
assert.equal(
145+
startupCard,
146+
renderProxyStartup(data as unknown as Parameters<typeof renderProxyStartup>[0]),
147+
);
134148
assert.match(startupCard, /Proxy listening at/);
135149
assert.ok(startupCard.includes(proxyBaseUrl));
136150
// The daemon the proxy fronts is the local one of the resolved state dir, never a remote URL.

0 commit comments

Comments
 (0)