diff --git a/packages/command-surface/src/command-output-schemas.ts b/packages/command-surface/src/command-output-schemas.ts index 080bea4def..c78c596f15 100644 --- a/packages/command-surface/src/command-output-schemas.ts +++ b/packages/command-surface/src/command-output-schemas.ts @@ -44,7 +44,9 @@ import { SYSTEM_COMMAND_OUTPUT_SCHEMAS } from './system/index.ts'; * `cost` object (opted in via `--cost` / `includeCost`) and any other additive * fields ride into `structuredContent` and still validate. * - Accurate, never invented: required-vs-optional, enums, `const` discriminants - * and discriminated-union branches mirror the source contract types. + * and discriminated-union branches mirror the source contract types. One schema + * serves every response level, so a field a digest view drops is optional here + * even when the contract type requires it at the default level. * * The opt-in `--settle` observation (#1101) is not hand-listed per entry: the * base map carries none and `deriveSettleObservationSchemas` grafts it onto @@ -88,6 +90,8 @@ const settleObservationSchema: JsonSchema = objectSchema( ), lines: { type: 'array', + description: + 'Changed lines. Absent at the digest response level, which keeps summary and settle.refs.', items: objectSchema( { kind: enumSchema(['added', 'removed']), @@ -99,7 +103,7 @@ const settleObservationSchema: JsonSchema = objectSchema( }, truncated: booleanSchema('Lines were capped to the response bound.'), }, - ['summary', 'lines'], + ['summary'], 'Settled diff vs the pre-action tree (changed lines only).', ), tail: { diff --git a/scripts/node-test-tmpdir.test.ts b/scripts/node-test-tmpdir.test.ts index 8a01d83489..9b38fbee6e 100644 --- a/scripts/node-test-tmpdir.test.ts +++ b/scripts/node-test-tmpdir.test.ts @@ -145,7 +145,7 @@ function killLeftovers(evidenceRoot: string): void { const pids = JSON.parse(fs.readFileSync(evidencePath, 'utf8')) as LeftoverPids; for (const pid of [pids.fixture, pids.fixtureChild, pids.tool]) { // pid 0 or a negative pid would address a whole process group. - if (Number.isInteger(pid) && pid > 0 && isAlive(pid)) process.kill(pid, 'SIGKILL'); + if (Number.isInteger(pid) && pid > 0) killIfAlive(pid); } } @@ -553,7 +553,7 @@ test('probe starts a long-lived detached child that inherits TMPDIR, then waits // Once every consumer is gone — the detached child AND the orphaned node --test chain, // which holds the same TMPDIR — it is an ordinary abandoned directory. - for (const pid of consumersOf(evidence!)) if (isAlive(pid)) process.kill(pid, 'SIGKILL'); + for (const pid of consumersOf(evidence!)) killIfAlive(pid); await waitFor( () => !liveRunDirectoryConsumers().has(path.basename(runDir)), 20_000, @@ -565,9 +565,7 @@ test('probe starts a long-lived detached child that inherits TMPDIR, then waits ); assert.equal(fs.existsSync(runDir), false, 'with no owner and no consumer it is pruned'); } finally { - for (const pid of evidence ? consumersOf(evidence) : []) { - if (isAlive(pid)) process.kill(pid, 'SIGKILL'); - } + for (const pid of evidence ? consumersOf(evidence) : []) killIfAlive(pid); if (wrapper.child.exitCode === null && wrapper.child.signalCode === null) { wrapper.child.kill('SIGKILL'); } @@ -577,6 +575,16 @@ test('probe starts a long-lived detached child that inherits TMPDIR, then waits } }); +// A pid can exit between a liveness check and the signal (killing a probe ends its runner), so +// "already gone" is the outcome the caller wanted, not an error. +function killIfAlive(pid: number): void { + try { + process.kill(pid, 'SIGKILL'); + } catch (error) { + if ((error as NodeJS.ErrnoException).code !== 'ESRCH') throw error; + } +} + function isAlive(pid: number): boolean { try { process.kill(pid, 0); diff --git a/src/__tests__/cli-config-trust.test.ts b/src/__tests__/cli-config-trust.test.ts index 4fee8a118d..da3007755b 100644 --- a/src/__tests__/cli-config-trust.test.ts +++ b/src/__tests__/cli-config-trust.test.ts @@ -17,11 +17,11 @@ test('project config rejects remote connection fields before daemon dispatch wit path.join(project, 'agent-device.json'), JSON.stringify({ daemonBaseUrl: 'https://daemon.example.test', - daemonAuthToken: 'token-123', + daemonAuthToken: 'leak-sentinel-token', daemonTransport: 'http', - tenant: 'tenant-123', - runId: 'run-123', - leaseId: 'lease-123', + tenant: 'leak-sentinel-tenant', + runId: 'leak-sentinel-run', + leaseId: 'leak-sentinel-lease', platform: 'ios', }), 'utf8', @@ -37,7 +37,7 @@ test('project config rejects remote connection fields before daemon dispatch wit const output = `${result.stdout}\n${result.stderr}`; assert.match(output, /daemonBaseUrl/); assert.match(output, /not allowed in project config file/i); - assert.doesNotMatch(output, /daemon\.example\.test|token-123|tenant-123|run-123|lease-123/); + assert.doesNotMatch(output, /daemon\.example\.test|leak-sentinel/); fs.rmSync(root, { recursive: true, force: true }); }); diff --git a/test/output-economy/mcp-output-schema.test.ts b/test/output-economy/mcp-output-schema.test.ts new file mode 100644 index 0000000000..de99f1f91a --- /dev/null +++ b/test/output-economy/mcp-output-schema.test.ts @@ -0,0 +1,43 @@ +import { expect, test } from 'vitest'; +import type { CommandName } from '@agent-device/command-surface'; +import { listCommandTools } from '../../src/mcp/command-tools.ts'; +import { validateAgainstSchema } from '../../src/mcp/__tests__/output-schema-validator.ts'; +import { captureOutputEconomyDaemonResponses } from './daemon-route-fixtures.ts'; + +const daemon = await captureOutputEconomyDaemonResponses(); + +// Real daemon output at each response level, keyed by the command that produced it. +const samples: Array<[string, CommandName, Record]> = [ + ['snapshot default', 'snapshot', daemon.snapshotDefault], + ['snapshot digest', 'snapshot', daemon.snapshotDigest], + ['get default', 'get', daemon.selectorDefault], + ['get digest', 'get', daemon.selectorDigest], + ['settled click default', 'click', daemon.settleDefault], + ['settled click digest', 'click', daemon.settleDigest], + ['settled click tail default', 'click', daemon.settleTailDefault], + ['settled click tail digest', 'click', daemon.settleTailDigest], + ['screenshot default', 'screenshot', daemon.screenshotDefault], + ['screenshot digest', 'screenshot', daemon.screenshotDigest], + ['network default', 'network', daemon.networkDefault], + ['network digest', 'network', daemon.networkDigest], +]; + +const outputSchemas = new Map(listCommandTools().map((tool) => [tool.name, tool.outputSchema])); +// A sample is checked once its tool advertises an outputSchema; untyped tools have nothing to violate. +const typedSamples = samples.flatMap(([label, name, data]) => { + const schema = outputSchemas.get(name); + return schema ? [[label, schema, data] as const] : []; +}); + +test.each(typedSamples)( + '%s validates against the advertised MCP outputSchema', + (_label, schema, data) => { + expect(validateAgainstSchema(data, schema)).toEqual([]); + }, +); + +test('settled interaction output is checked at both response levels', () => { + expect(typedSamples.map(([label]) => label)).toEqual( + expect.arrayContaining(['settled click default', 'settled click digest']), + ); +});