Skip to content

Commit 335506b

Browse files
committed
test(mcp): split the navigation schema tests out of command-tools.test.ts
1 parent d85f157 commit 335506b

2 files changed

Lines changed: 83 additions & 82 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import assert from 'node:assert/strict';
2+
import { test } from 'vitest';
3+
import { commandSupportsSettleObservation } from '../../core/command-descriptor/registry.ts';
4+
import { COMMAND_OUTPUT_SCHEMAS } from '../command-output-schemas.ts';
5+
6+
// The closed dispatch shape each navigation command's runtime returns
7+
// (packages/contracts/src/navigation.ts). `back` is the settle-capable one, so
8+
// its published schema is this shape PLUS the opt-in `--settle` observation and
9+
// nothing else; the other four must match verbatim.
10+
const NAVIGATION_DISPATCH_SHAPES: Readonly<
11+
Record<string, { properties: Record<string, unknown>; required: readonly string[] }>
12+
> = {
13+
back: {
14+
properties: {
15+
action: { type: 'string', const: 'back' },
16+
mode: { type: 'string', enum: ['in-app', 'system'] },
17+
message: { type: 'string' },
18+
},
19+
required: ['action', 'mode', 'message'],
20+
},
21+
home: {
22+
properties: {
23+
action: { type: 'string', const: 'home' },
24+
message: { type: 'string' },
25+
},
26+
required: ['action', 'message'],
27+
},
28+
orientation: {
29+
properties: {
30+
action: { type: 'string', const: 'orientation' },
31+
orientation: {
32+
type: 'string',
33+
enum: ['portrait', 'portrait-upside-down', 'landscape-left', 'landscape-right'],
34+
},
35+
message: { type: 'string' },
36+
},
37+
required: ['action', 'orientation', 'message'],
38+
},
39+
'app-switcher': {
40+
properties: {
41+
action: { type: 'string', const: 'app-switcher' },
42+
message: { type: 'string' },
43+
},
44+
required: ['action', 'message'],
45+
},
46+
'tv-remote': {
47+
properties: {
48+
action: { type: 'string', const: 'tv-remote' },
49+
button: {
50+
type: 'string',
51+
enum: ['up', 'down', 'left', 'right', 'select', 'menu', 'home', 'back'],
52+
},
53+
durationMs: { type: 'number' },
54+
message: { type: 'string' },
55+
},
56+
required: ['action', 'button', 'message'],
57+
},
58+
};
59+
60+
test('MCP navigation output schemas advertise the closed dispatch shapes', () => {
61+
for (const [name, dispatchShape] of Object.entries(NAVIGATION_DISPATCH_SHAPES)) {
62+
const schema = COMMAND_OUTPUT_SCHEMAS[name as keyof typeof COMMAND_OUTPUT_SCHEMAS] as {
63+
type?: unknown;
64+
properties?: Record<string, unknown>;
65+
required?: unknown;
66+
};
67+
assert.deepEqual(
68+
Object.keys(schema).sort(),
69+
['properties', 'required', 'type'],
70+
`${name}: must advertise exactly type/properties/required at the top level`,
71+
);
72+
assert.equal(schema.type, 'object', `${name}: must advertise an object schema`);
73+
const { settle, ...dispatchProperties } = schema.properties ?? {};
74+
assert.equal(
75+
Boolean(settle),
76+
commandSupportsSettleObservation(name),
77+
`${name}: settle property must track the post-action observation trait`,
78+
);
79+
assert.deepEqual(dispatchProperties, dispatchShape.properties);
80+
assert.deepEqual(schema.required, dispatchShape.required);
81+
}
82+
});

‎src/mcp/__tests__/command-tools.test.ts‎

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import assert from 'node:assert/strict';
22
import { test } from 'vitest';
33
import type { AgentDeviceClient } from '../../client/client-types.ts';
44
import { createCommandToolExecutor, listCommandTools } from '../command-tools.ts';
5-
import {
6-
commandSupportsSettleObservation,
7-
resolveCommandRecordsSessionAction,
8-
} from '../../core/command-descriptor/registry.ts';
5+
import { resolveCommandRecordsSessionAction } from '../../core/command-descriptor/registry.ts';
96
import { COMMAND_OUTPUT_SCHEMAS } from '../command-output-schemas.ts';
107
import { AppError } from '@agent-device/kernel/errors';
118
import { validateAgainstSchema } from './output-schema-validator.ts';
@@ -447,84 +444,6 @@ test('MCP tv remote outputSchema advertises button values', () => {
447444
);
448445
});
449446

450-
// The closed dispatch shape each navigation command's runtime returns
451-
// (packages/contracts/src/navigation.ts). `back` is the settle-capable one, so
452-
// its published schema is this shape PLUS the opt-in `--settle` observation and
453-
// nothing else; the other four must match verbatim.
454-
const NAVIGATION_DISPATCH_SHAPES: Readonly<
455-
Record<string, { properties: Record<string, unknown>; required: readonly string[] }>
456-
> = {
457-
back: {
458-
properties: {
459-
action: { type: 'string', const: 'back' },
460-
mode: { type: 'string', enum: ['in-app', 'system'] },
461-
message: { type: 'string' },
462-
},
463-
required: ['action', 'mode', 'message'],
464-
},
465-
home: {
466-
properties: {
467-
action: { type: 'string', const: 'home' },
468-
message: { type: 'string' },
469-
},
470-
required: ['action', 'message'],
471-
},
472-
orientation: {
473-
properties: {
474-
action: { type: 'string', const: 'orientation' },
475-
orientation: {
476-
type: 'string',
477-
enum: ['portrait', 'portrait-upside-down', 'landscape-left', 'landscape-right'],
478-
},
479-
message: { type: 'string' },
480-
},
481-
required: ['action', 'orientation', 'message'],
482-
},
483-
'app-switcher': {
484-
properties: {
485-
action: { type: 'string', const: 'app-switcher' },
486-
message: { type: 'string' },
487-
},
488-
required: ['action', 'message'],
489-
},
490-
'tv-remote': {
491-
properties: {
492-
action: { type: 'string', const: 'tv-remote' },
493-
button: {
494-
type: 'string',
495-
enum: ['up', 'down', 'left', 'right', 'select', 'menu', 'home', 'back'],
496-
},
497-
durationMs: { type: 'number' },
498-
message: { type: 'string' },
499-
},
500-
required: ['action', 'button', 'message'],
501-
},
502-
};
503-
504-
test('MCP navigation output schemas advertise the closed dispatch shapes', () => {
505-
for (const [name, dispatchShape] of Object.entries(NAVIGATION_DISPATCH_SHAPES)) {
506-
const schema = COMMAND_OUTPUT_SCHEMAS[name as keyof typeof COMMAND_OUTPUT_SCHEMAS] as {
507-
type?: unknown;
508-
properties?: Record<string, unknown>;
509-
required?: unknown;
510-
};
511-
assert.deepEqual(
512-
Object.keys(schema).sort(),
513-
['properties', 'required', 'type'],
514-
`${name}: must advertise exactly type/properties/required at the top level`,
515-
);
516-
assert.equal(schema.type, 'object', `${name}: must advertise an object schema`);
517-
const { settle, ...dispatchProperties } = schema.properties ?? {};
518-
assert.equal(
519-
Boolean(settle),
520-
commandSupportsSettleObservation(name),
521-
`${name}: settle property must track the post-action observation trait`,
522-
);
523-
assert.deepEqual(dispatchProperties, dispatchShape.properties);
524-
assert.deepEqual(schema.required, dispatchShape.required);
525-
}
526-
});
527-
528447
test('MCP newly typed outputSchemas advertise public contract keys', () => {
529448
const tools = listCommandTools();
530449

0 commit comments

Comments
 (0)