Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/command-surface/src/command-output-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']),
Expand All @@ -99,7 +103,7 @@ const settleObservationSchema: JsonSchema = objectSchema(
},
truncated: booleanSchema('Lines were capped to the response bound.'),
},
['summary', 'lines'],
['summary'],
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
'Settled diff vs the pre-action tree (changed lines only).',
),
tail: {
Expand Down
18 changes: 13 additions & 5 deletions scripts/node-test-tmpdir.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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,
Expand All @@ -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');
}
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/cli-config-trust.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 });
});
Expand Down
43 changes: 43 additions & 0 deletions test/output-economy/mcp-output-schema.test.ts
Original file line number Diff line number Diff line change
@@ -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<string, unknown>]> = [
['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']),
);
});
Loading