|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { test } from 'vitest'; |
| 3 | +import { |
| 4 | + COMMON_INPUT_AUDIENCE, |
| 5 | + commonProperties, |
| 6 | + commonToClientOptions, |
| 7 | + readCommonInput, |
| 8 | +} from '../common-input-fields.ts'; |
| 9 | +import { operatorInputRefusal } from '../input-audience.ts'; |
| 10 | + |
| 11 | +// The guidance a refused operator key answers with is rendered from the key's |
| 12 | +// declared source, not written per key. These pin the four shapes the |
| 13 | +// declarations use, so a change to the template or to `buildPrimaryEnvVarName` |
| 14 | +// fails here instead of silently degrading every operator refusal at once. |
| 15 | +test('an operator refusal names the environment variable and the config key', () => { |
| 16 | + assert.equal( |
| 17 | + operatorInputRefusal('daemonAuthToken', { operatorConfig: true }), |
| 18 | + 'daemonAuthToken is not accepted as a tool argument. Set the AGENT_DEVICE_DAEMON_AUTH_TOKEN environment variable (or daemonAuthToken in ~/.agent-device/config.json) for the process serving these tools.', |
| 19 | + ); |
| 20 | +}); |
| 21 | + |
| 22 | +test('an operator refusal names every environment variable that carries the value', () => { |
| 23 | + assert.equal( |
| 24 | + operatorInputRefusal('bearerToken', { envFlagKeys: ['metroBearerToken', 'daemonAuthToken'] }), |
| 25 | + 'bearerToken is not accepted as a tool argument. Set the AGENT_DEVICE_METRO_BEARER_TOKEN or AGENT_DEVICE_DAEMON_AUTH_TOKEN environment variable for the process serving these tools.', |
| 26 | + ); |
| 27 | +}); |
| 28 | + |
| 29 | +test('a key with no environment variable points at the operator config file alone', () => { |
| 30 | + assert.equal( |
| 31 | + operatorInputRefusal('iosSimulatorDeviceSet', { envFlagKeys: [], operatorConfig: true }), |
| 32 | + 'iosSimulatorDeviceSet is not accepted as a tool argument. Set iosSimulatorDeviceSet in ~/.agent-device/config.json for the process serving these tools.', |
| 33 | + ); |
| 34 | +}); |
| 35 | + |
| 36 | +test('a key neither env nor config resolves states its own operator path', () => { |
| 37 | + assert.equal( |
| 38 | + operatorInputRefusal('cwd', { operatorPath: 'Start the process elsewhere.' }), |
| 39 | + 'cwd is not accepted as a tool argument. Start the process elsewhere.', |
| 40 | + ); |
| 41 | +}); |
| 42 | + |
| 43 | +// `audience` narrows the MODEL-facing surfaces only. The CLI and the Node client |
| 44 | +// still accept an operator key as ordinary input -- that is how an operator |
| 45 | +// supplies it, and how env/config defaults reach the command route. A |
| 46 | +// classification that also narrowed `commonProperties()` would break both |
| 47 | +// without failing the MCP tests, which only assert absence. |
| 48 | +// (Which keys are operator-owned is pinned at the boundary that enforces it, |
| 49 | +// in `mcp/__tests__/command-tools-operator-inputs.test.ts`.) |
| 50 | +test('an operator-owned common key stays in the CLI and Node input schema', () => { |
| 51 | + const advertised = commonProperties(); |
| 52 | + const operatorKeys = Object.keys(COMMON_INPUT_AUDIENCE); |
| 53 | + assert.ok(operatorKeys.length > 0, 'the table declares operator-owned common keys'); |
| 54 | + for (const key of operatorKeys) { |
| 55 | + assert.equal(COMMON_INPUT_AUDIENCE[key]?.kind, 'operator'); |
| 56 | + assert.ok(key in advertised, `${key} must stay readable by the CLI and Node client`); |
| 57 | + } |
| 58 | +}); |
| 59 | + |
| 60 | +// Schema, readers, and projection are three derivations of one table. A row |
| 61 | +// that loses its reader or its projection entry drops the key silently at the |
| 62 | +// seam nothing else covers, which is the failure `--no-record` hit twice |
| 63 | +// (#1304/#1305). Round-tripping every advertised key catches it. |
| 64 | +test('every advertised common key is read and projected onto the client options', () => { |
| 65 | + const advertised = Object.keys(commonProperties()); |
| 66 | + const record = Object.fromEntries( |
| 67 | + advertised.map((key) => [key, commonInputValueFor(key)]), |
| 68 | + ) as Record<string, unknown>; |
| 69 | + record.noRecord = true; |
| 70 | + |
| 71 | + const input = readCommonInput(record); |
| 72 | + const options = commonToClientOptions(input) as Record<string, unknown>; |
| 73 | + |
| 74 | + for (const key of advertised) { |
| 75 | + // `deviceTarget` and its `target` alias are one value under two spellings; |
| 76 | + // the projection emits the client-facing `target`. |
| 77 | + const projected = key === 'deviceTarget' ? 'target' : key; |
| 78 | + assert.ok(projected in options, `${key} is dropped between reader and projection`); |
| 79 | + } |
| 80 | + assert.equal(options.noRecord, true, 'noRecord rides the common seam with no schema of its own'); |
| 81 | + assert.equal(options.target, 'mobile'); |
| 82 | +}); |
| 83 | + |
| 84 | +function commonInputValueFor(key: string): unknown { |
| 85 | + if (key === 'platform') return 'ios'; |
| 86 | + if (key === 'deviceTarget' || key === 'target') return 'mobile'; |
| 87 | + if (key === 'debug') return true; |
| 88 | + return `value-${key}`; |
| 89 | +} |
0 commit comments