From 253f506e5c76cfd393d0f1ce5aa55bee1532af96 Mon Sep 17 00:00:00 2001 From: ggbdpq Date: Fri, 9 Oct 2026 12:51:44 +0800 Subject: [PATCH] test(runtime-host): pin the settlement coverage window to the usage window Follow-up to #5890 (merged): the runner passes the same startedAt/settledAt window to the completeness check and to the usage summary, and nothing asserted it - the review noted a later edit could quietly separate the two and re-open the delegated-Session undercount. The coverage stub now records its calls and the residencies test asserts it received exactly the window the usage summary read (100, 200 with the harness clock). Swapping the arguments in the runner turns the assertion red. Implements the non-blocking suggestion from the #5890 review. Generated-by: GLM-5.3-Flash (ZCode) --- .../__tests__/hosted-execution-runner.test.ts | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/runtime-host/src/__tests__/hosted-execution-runner.test.ts b/packages/runtime-host/src/__tests__/hosted-execution-runner.test.ts index 40624dc78c1..0ca619095b8 100644 --- a/packages/runtime-host/src/__tests__/hosted-execution-runner.test.ts +++ b/packages/runtime-host/src/__tests__/hosted-execution-runner.test.ts @@ -26,6 +26,7 @@ import { HostHostedExecutionRunner } from '../server/hosted-execution-runner.js' test('hosted execution reads usage only after execution residencies settle', async () => { const residency = deferred(); let usageRead = false; + const coverage = settlementCoverage(); const runner = new HostHostedExecutionRunner({ handlers: handlers({ usage: () => { @@ -33,7 +34,7 @@ test('hosted execution reads usage only after execution residencies settle', asy return usageSummary(); }, }), - runSettlementCoverage: settlementCoverage(), + runSettlementCoverage: coverage, context: context(), requestDrain: () => {}, waitForExecutionResidencies: () => residency.promise, @@ -61,6 +62,10 @@ test('hosted execution reads usage only after execution residencies settle', asy costUsd: 0.25, }); assert.equal(usageRead, true); + // The completeness check must read the exact window the usage summary read + // (#5890 review): separating the two silently re-opens the delegated-Session + // undercount that window scoping closed. + assert.deepEqual(coverage.calls, [[100, 200]]); }); test('a run-owned unsettled attempt refuses settlement with its fixed safe cause', async () => { @@ -376,16 +381,24 @@ function usageSummary() { /** * The run-scoped incompleteness check's stub: a hosted execution owns no - * usage-unknown rows unless the test says otherwise. + * usage-unknown rows unless the test says otherwise. Calls are recorded so a + * test can pin the window the runner passed in. */ function settlementCoverage( overrides: { usageMissingAttempts?: number; usagePartialAttempts?: number } = {}, ) { - return async (_from: number, _to: number) => ({ - usageMissingAttempts: 0, - usagePartialAttempts: 0, - ...overrides, - }); + const calls: Array<[number, number]> = []; + return Object.assign( + async (from: number, to: number) => { + calls.push([from, to]); + return { + usageMissingAttempts: 0, + usagePartialAttempts: 0, + ...overrides, + }; + }, + { calls }, + ); } function emptySkillInvocation() {