Skip to content

Commit 89301e8

Browse files
committed
test(daemon): pin that wire-supplied internal never reaches a daemon request
#1271 stage 2 made `DaemonRequest.internal` semantics-affecting: `internal.replayPlanStep` decides whether an observation-only command is an authored plan step (kept in a repair heal) or an out-of-band diagnostic (excluded). That makes "internal means internally-stamped" worth pinning rather than leaving to convention. The invariant already holds, structurally and twice over: the boundary's `commandRpcParamsSchema` is an allowlist projection emitting only its eight named fields, and `toDaemonRequest` then builds the request field by field. Neither can carry `internal` off the wire. This posts a real JSON-RPC request carrying `internal: { replayPlanStep: true }` through a loopback server and asserts the dispatched request has no `internal`. Verified it fails ("a wire-supplied `internal` must never reach the daemon request") when both allowlists are regressed, so it guards the composite contract instead of restating one layer.
1 parent e1f2fed commit 89301e8

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

‎src/daemon/__tests__/http-server-rpc-validation.test.ts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,50 @@ test('malformed command params (command as number) yield 400 / -32602', async (t
7676
assert.equal(body.error?.data?.code, 'INVALID_ARGS');
7777
}, t);
7878
});
79+
80+
// `DaemonRequest.internal` carries semantics-affecting bits stamped inside the
81+
// daemon — `replayPlanStep` (#1271 stage 2) decides whether a read is an
82+
// authored plan step or an out-of-band diagnostic, and so whether it lands in a
83+
// repair heal. Two independent allowlists keep it unreachable from the wire:
84+
// `commandRpcParamsSchema` projects only its eight named fields, and
85+
// `toDaemonRequest` then builds the request field by field. Both would have to
86+
// regress for a caller to stamp its own provenance; this pins the resulting
87+
// boundary contract so neither drifts silently.
88+
test('the rpc boundary never accepts internal request fields from the wire', async (t) => {
89+
if (await skipWhenLoopbackUnavailable(t)) return;
90+
91+
const received: DaemonRequest[] = [];
92+
const handleRequest = async (req: DaemonRequest): Promise<DaemonResponse> => {
93+
received.push(req);
94+
return { ok: true, data: { ok: true } };
95+
};
96+
const server = await createDaemonHttpServer({ handleRequest });
97+
98+
try {
99+
const port = await listenOnLoopback(server);
100+
const response = await fetch(`http://127.0.0.1:${port}/rpc`, {
101+
method: 'POST',
102+
headers: { 'content-type': 'application/json' },
103+
body: JSON.stringify({
104+
jsonrpc: '2.0',
105+
id: 'req-1',
106+
method: 'agent_device.command',
107+
params: {
108+
command: 'get',
109+
positionals: ['text', 'id=whatever'],
110+
internal: { replayPlanStep: true, replayTargetGuard: { ref: '@e1' } },
111+
},
112+
}),
113+
});
114+
115+
assert.equal(response.status, 200);
116+
assert.equal(received.length, 1);
117+
assert.equal(
118+
received[0]?.internal,
119+
undefined,
120+
'a wire-supplied `internal` must never reach the daemon request',
121+
);
122+
} finally {
123+
await closeLoopbackServer(server);
124+
}
125+
});

0 commit comments

Comments
 (0)