Skip to content

Commit c7d92a6

Browse files
committed
refactor(mcp): project push management family output schemas from their owning module
Moves the 2 hand-authored MCP outputSchema entries for push and trigger-app-event out of command-output-schemas.ts into a frozen PUSH_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS map exported from src/commands/management/push.ts, following the #2810 projection seam already used by the replay, system, interaction, and device-management families on this stack. Registers the family in the PROJECTED_FAMILIES disjointness check and adds a colocated command-tools-management-push-schemas.test.ts proving reference equality with the module object. Neither command carries the post-action observation trait, so no settle-graft copy applies here. The moved code is byte-identical to what command-output-schemas.ts held: same objectSchema/stringSchema/numberSchema calls and field order, with a locally duplicated constSchema helper matching the precedent from the interaction, system, and device-management families' moves. Part of #2819.
1 parent 5f47c18 commit c7d92a6

4 files changed

Lines changed: 84 additions & 32 deletions

File tree

‎src/commands/management/push.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
JsonObject,
55
} from '@agent-device/contracts/client';
66
import type { CommandSchemaOverride } from '@agent-device/command-registry/command-schema';
7+
import type { CommandResultMap } from '@agent-device/command-registry/command-result';
78
import { PUBLIC_COMMANDS } from '@agent-device/command-registry/catalog';
89
import {
910
commonInputFromFlags,
@@ -12,10 +13,13 @@ import {
1213
requiredString,
1314
} from '../cli-grammar/common.ts';
1415
import type { CliReader, DaemonWriter } from '../cli-grammar/types.ts';
16+
import type { JsonSchema } from '../command-contract.ts';
1517
import {
1618
jsonSchemaField,
1719
looseObjectField,
1820
looseObjectSchema,
21+
numberSchema,
22+
objectSchema,
1923
requiredField,
2024
stringField,
2125
stringSchema,
@@ -24,6 +28,51 @@ import {
2428
import { defineCommandFacet } from '../family/types.ts';
2529
import { defineFieldCommandMetadata } from '../field-command-contract.ts';
2630

31+
function constSchema(value: string): JsonSchema {
32+
return { type: 'string', const: value };
33+
}
34+
35+
/**
36+
* This family's advertised MCP `outputSchema`s, keyed by daemon command name and projected into
37+
* the command map by `src/mcp/command-output-schemas.ts`. Non-strict like every other entry: no
38+
* `additionalProperties: false`, so additive response fields such as `cost` keep validating.
39+
* Neither command carries the post-action observation trait (#1652): both fire-and-report a push
40+
* delivery or an app event, not an interaction, so no settle graft applies here.
41+
*/
42+
export const PUSH_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS = {
43+
// packages/contracts/src/push.ts — discriminated union on public platform.
44+
push: {
45+
type: 'object',
46+
oneOf: [
47+
objectSchema(
48+
{ platform: constSchema('ios'), bundleId: stringSchema(), message: stringSchema() },
49+
['platform', 'bundleId', 'message'],
50+
),
51+
objectSchema(
52+
{
53+
platform: constSchema('android'),
54+
package: stringSchema(),
55+
action: stringSchema(),
56+
extrasCount: numberSchema(),
57+
message: stringSchema(),
58+
},
59+
['platform', 'package', 'action', 'extrasCount', 'message'],
60+
),
61+
],
62+
},
63+
64+
// packages/contracts/src/app-events.ts
65+
'trigger-app-event': objectSchema(
66+
{
67+
event: stringSchema(),
68+
eventUrl: stringSchema(),
69+
transport: constSchema('deep-link'),
70+
message: stringSchema(),
71+
},
72+
['event', 'eventUrl', 'transport', 'message'],
73+
),
74+
} satisfies Pick<Record<keyof CommandResultMap, JsonSchema>, 'push' | 'trigger-app-event'>;
75+
2776
const pushCommandMetadata = defineFieldCommandMetadata(
2877
'push',
2978
'Deliver push notification payloads to an installed app.',
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import assert from 'node:assert/strict';
2+
import { test } from 'vitest';
3+
import { ownerFilesForCommand } from '@agent-device/command-registry/owner-files';
4+
import { PUSH_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS } from '../../commands/management/push.ts';
5+
import { COMMAND_OUTPUT_SCHEMAS } from '../command-output-schemas.ts';
6+
7+
const PUSH_MANAGEMENT_COMMANDS = Object.keys(PUSH_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS) as Array<
8+
keyof typeof PUSH_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS
9+
>;
10+
11+
// Neither push nor trigger-app-event carries the post-action observation trait (#1652): both
12+
// fire-and-report a push delivery or an app event, not an interaction, so the composed map never
13+
// copies either entry and reference equality must hold for both.
14+
test('MCP push management family output schemas are the family module entries, not copies', () => {
15+
for (const command of PUSH_MANAGEMENT_COMMANDS) {
16+
assert.equal(
17+
COMMAND_OUTPUT_SCHEMAS[command],
18+
PUSH_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS[command],
19+
`${command} is not reference-equal to the push management module's own schema object`,
20+
);
21+
}
22+
});
23+
24+
test('the projected family map declares exactly the commands its module owns', () => {
25+
for (const command of PUSH_MANAGEMENT_COMMANDS) {
26+
assert.ok(
27+
ownerFilesForCommand(command).includes('src/commands/management/push.ts'),
28+
`${command} projects its output schema from this module but does not name it as its owner`,
29+
);
30+
}
31+
});

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { ReplayCommandResult, ReplaySuiteResult } from '@agent-device/contr
44
import { ownerFilesForCommand } from '@agent-device/command-registry/owner-files';
55
import { commandSupportsSettleObservation } from '@agent-device/command-registry/registry';
66
import { DEVICE_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS } from '../../commands/management/device.ts';
7+
import { PUSH_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS } from '../../commands/management/push.ts';
78
import { INTERACTION_COMMAND_OUTPUT_SCHEMAS } from '../../commands/interaction/index.ts';
89
import { REPLAY_COMMAND_OUTPUT_SCHEMAS } from '../../commands/replay/index.ts';
910
import { SYSTEM_COMMAND_OUTPUT_SCHEMAS } from '../../commands/system/index.ts';
@@ -75,6 +76,7 @@ const PROJECTED_FAMILIES = [
7576
{ name: 'system', schemas: SYSTEM_COMMAND_OUTPUT_SCHEMAS },
7677
{ name: 'interaction', schemas: INTERACTION_COMMAND_OUTPUT_SCHEMAS },
7778
{ name: 'management-device', schemas: DEVICE_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS },
79+
{ name: 'management-push', schemas: PUSH_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS },
7880
] as const;
7981

8082
test('projected output-schema families claim disjoint commands and survive the composition intact', () => {

‎src/mcp/command-output-schemas.ts‎

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
stringSchema,
1212
} from '../commands/command-input.ts';
1313
import { DEVICE_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS } from '../commands/management/device.ts';
14+
import { PUSH_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS } from '../commands/management/push.ts';
1415
import { INTERACTION_COMMAND_OUTPUT_SCHEMAS } from '../commands/interaction/index.ts';
1516
import { REPLAY_COMMAND_OUTPUT_SCHEMAS } from '../commands/replay/index.ts';
1617
import { SYSTEM_COMMAND_OUTPUT_SCHEMAS } from '../commands/system/index.ts';
@@ -289,38 +290,6 @@ const BASE_COMMAND_OUTPUT_SCHEMAS = {
289290
],
290291
),
291292

292-
// packages/contracts/src/push.ts — discriminated union on public platform.
293-
push: {
294-
type: 'object',
295-
oneOf: [
296-
objectSchema(
297-
{ platform: constSchema('ios'), bundleId: stringSchema(), message: stringSchema() },
298-
['platform', 'bundleId', 'message'],
299-
),
300-
objectSchema(
301-
{
302-
platform: constSchema('android'),
303-
package: stringSchema(),
304-
action: stringSchema(),
305-
extrasCount: numberSchema(),
306-
message: stringSchema(),
307-
},
308-
['platform', 'package', 'action', 'extrasCount', 'message'],
309-
),
310-
],
311-
},
312-
313-
// packages/contracts/src/app-events.ts
314-
'trigger-app-event': objectSchema(
315-
{
316-
event: stringSchema(),
317-
eventUrl: stringSchema(),
318-
transport: constSchema('deep-link'),
319-
message: stringSchema(),
320-
},
321-
['event', 'eventUrl', 'transport', 'message'],
322-
),
323-
324293
// packages/contracts/src/doctor.ts
325294
doctor: objectSchema(
326295
{
@@ -447,6 +416,7 @@ const BASE_COMMAND_OUTPUT_SCHEMAS = {
447416
// a projected command then fails as TS2783 instead of quietly overriding the family's,
448417
// and this map's `satisfies` still refuses a missing `CommandResultMap` key.
449418
...DEVICE_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS,
419+
...PUSH_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS,
450420
...INTERACTION_COMMAND_OUTPUT_SCHEMAS,
451421
...REPLAY_COMMAND_OUTPUT_SCHEMAS,
452422
...SYSTEM_COMMAND_OUTPUT_SCHEMAS,

0 commit comments

Comments
 (0)