Skip to content

Commit b365f7e

Browse files
authored
test: move core coverage to owner boundaries (#124184)
* test: move core coverage to owner boundaries * ci: lower plugin SDK surface budget
1 parent 9663cc7 commit b365f7e

9 files changed

Lines changed: 52 additions & 160 deletions

File tree

‎scripts/plugin-sdk-surface-report.mts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ export function readPluginSdkSurfaceBudgets(env: NodeJS.ProcessEnv = process.env
284284
// +6: load-only bridges for published pre-split plugin artifacts
285285
// (voice-call/matrix runtime-doctor repair names, WhatsApp ack policy,
286286
// Slack progress-draft render) so installed plugins survive upgrade (#124041 class).
287-
4330,
287+
// -1: remove the orphan diagnostic traceparent propagation export.
288+
4329,
288289
env,
289290
),
290291
publicFunctionExports: readPluginSdkSurfaceBudgetEnv(
@@ -357,7 +358,8 @@ export function readPluginSdkSurfaceBudgets(env: NodeJS.ProcessEnv = process.env
357358
// +3: load-only bridges for published pre-split plugin artifacts
358359
// (voice-call/matrix runtime-doctor repair names, WhatsApp ack policy,
359360
// Slack progress-draft render) so installed plugins survive upgrade (#124041 class).
360-
2577,
361+
// -1: remove the orphan diagnostic traceparent propagation export.
362+
2576,
361363
env,
362364
),
363365
publicDeprecatedExports: readPluginSdkSurfaceBudgetEnv(

‎src/commands/agent-via-gateway.test.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,18 @@ describe("agentCliCommand", () => {
360360
expect(zeroTimeoutGatewayRequestMs).toBe(2_147_000_000);
361361
});
362362

363-
it("clamps oversized gateway timeout seconds", () => {
364-
expect(agentViaGatewayTesting.resolveGatewayAgentTimeoutMs(Number.MAX_SAFE_INTEGER)).toBe(
365-
MAX_TIMER_TIMEOUT_MS,
366-
);
363+
it("clamps oversized gateway timeout seconds at the command boundary", async () => {
364+
await withTempStore(async () => {
365+
mockGatewaySuccessReply();
366+
367+
await agentCliCommand(
368+
{ message: "hi", to: "+1555", timeout: String(Number.MAX_SAFE_INTEGER) },
369+
runtime,
370+
);
371+
372+
const request = requireFirstCallArg(callGateway, "gateway") as { timeoutMs?: number };
373+
expect(request.timeoutMs).toBe(MAX_TIMER_TIMEOUT_MS);
374+
});
367375
});
368376

369377
it("rejects partial gateway timeout values", async () => {

‎src/commands/agent-via-gateway.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ export const agentViaGatewayTesting = {
357357
agentSessionModuleCache.clear();
358358
agentSessionModuleLoader = loader;
359359
},
360-
resolveGatewayAgentTimeoutMs,
361360
setGatewayAbortRetryDelaysMsForTests(delays?: readonly number[]): void {
362361
gatewayAbortRetryDelaysMsForTests = delays;
363362
},

‎src/docker-healthcheck.test.ts‎

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import { describe, expect, it, vi } from "vitest";
2-
import { probeDockerGatewayHealth, resolveDockerHealthcheckPort } from "./docker-healthcheck.js";
2+
import { probeDockerGatewayHealth } from "./docker-healthcheck.js";
33

44
describe("Docker healthcheck", () => {
5-
it("prefers the active Gateway lock port used by --port", async () => {
5+
it("probes the active Gateway lock port used by --port", async () => {
66
const getRuntimeConfig = vi.fn(() => ({ gateway: { port: 19002 } }));
77
const resolveGatewayPort = vi.fn(() => 19003);
8+
const fetch = vi.fn(async () => ({ ok: true }) as Response);
89

910
await expect(
10-
resolveDockerHealthcheckPort({
11+
probeDockerGatewayHealth({
1112
env: { OPENCLAW_GATEWAY_PORT: "19001" },
13+
fetch,
1214
getRuntimeConfig,
1315
readActiveGatewayLockPort: vi.fn(async () => 19000),
1416
resolveGatewayPort,
1517
}),
16-
).resolves.toBe(19000);
18+
).resolves.toBe(true);
19+
expect(fetch).toHaveBeenCalledWith("http://127.0.0.1:19000/healthz");
1720
expect(getRuntimeConfig).not.toHaveBeenCalled();
1821
expect(resolveGatewayPort).not.toHaveBeenCalled();
1922
});
@@ -31,42 +34,38 @@ describe("Docker healthcheck", () => {
3134
config: { gateway: { port: 19002 } },
3235
expected: 19002,
3336
},
34-
])("falls back to the canonical $name port", async ({ env, config, expected }) => {
35-
await expect(
36-
resolveDockerHealthcheckPort({
37-
env,
38-
getRuntimeConfig: () => config,
39-
readActiveGatewayLockPort: vi.fn(async () => undefined),
40-
}),
41-
).resolves.toBe(expected);
42-
});
37+
])(
38+
"probes the canonical $name port when no active lock exists",
39+
async ({ env, config, expected }) => {
40+
const fetch = vi.fn(async () => ({ ok: true }) as Response);
4341

44-
it("falls back to config when the active lock cannot be read", async () => {
45-
await expect(
46-
resolveDockerHealthcheckPort({
47-
env: {},
48-
getRuntimeConfig: () => ({ gateway: { port: 19002 } }),
49-
readActiveGatewayLockPort: vi.fn(async () => {
50-
throw new Error("lock unavailable");
42+
await expect(
43+
probeDockerGatewayHealth({
44+
env,
45+
fetch,
46+
getRuntimeConfig: () => config,
47+
readActiveGatewayLockPort: vi.fn(async () => undefined),
5148
}),
52-
resolveGatewayPort: (config) => config.gateway?.port ?? 18789,
53-
}),
54-
).resolves.toBe(19002);
55-
});
49+
).resolves.toBe(true);
50+
expect(fetch).toHaveBeenCalledWith(`http://127.0.0.1:${expected}/healthz`);
51+
},
52+
);
5653

57-
it("probes the unauthenticated liveness endpoint on the resolved port", async () => {
54+
it("probes the configured port when the active lock cannot be read", async () => {
5855
const fetch = vi.fn(async () => ({ ok: true }) as Response);
5956

6057
await expect(
6158
probeDockerGatewayHealth({
6259
env: {},
6360
fetch,
6461
getRuntimeConfig: () => ({ gateway: { port: 19002 } }),
65-
readActiveGatewayLockPort: vi.fn(async () => 19000),
66-
resolveGatewayPort: vi.fn(() => 19002),
62+
readActiveGatewayLockPort: vi.fn(async () => {
63+
throw new Error("lock unavailable");
64+
}),
65+
resolveGatewayPort: (config) => config.gateway?.port ?? 18789,
6766
}),
6867
).resolves.toBe(true);
69-
expect(fetch).toHaveBeenCalledWith("http://127.0.0.1:19000/healthz");
68+
expect(fetch).toHaveBeenCalledWith("http://127.0.0.1:19002/healthz");
7069
});
7170

7271
it("reports an unsuccessful or unreachable liveness endpoint as unhealthy", async () => {

‎src/docker-healthcheck.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type DockerHealthcheckDeps = Partial<DockerHealthcheckPortDeps> & {
1717
fetch?: typeof globalThis.fetch;
1818
};
1919

20-
export async function resolveDockerHealthcheckPort(
20+
async function resolveDockerHealthcheckPort(
2121
deps: Partial<DockerHealthcheckPortDeps> = {},
2222
): Promise<number> {
2323
const env = deps.env ?? process.env;

‎src/gateway/server-methods/usage.test.ts‎

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ describe("gateway usage helpers", () => {
9595
endDate: string,
9696
) {
9797
const range = expectDateRange(result);
98-
expect(range.startMs).toBe(testApi.parseDateToMs(startDate));
99-
expect(range.endMs).toBe(testApi.parseDateToMs(endDate)! + dayMs - 1);
98+
expect(range.startMs).toBe(Date.parse(`${startDate}T00:00:00.000Z`));
99+
expect(range.endMs).toBe(Date.parse(`${endDate}T00:00:00.000Z`) + dayMs - 1);
100100
}
101101

102102
function expectDateRange(result: ReturnType<typeof testApi.resolveDateRange>) {
@@ -128,26 +128,6 @@ describe("gateway usage helpers", () => {
128128
vi.clearAllMocks();
129129
});
130130

131-
it("parseDateToMs accepts YYYY-MM-DD and rejects invalid input", () => {
132-
expect(testApi.parseDateToMs("2026-02-05")).toBe(Date.UTC(2026, 1, 5));
133-
expect(testApi.parseDateToMs(" 2026-02-05 ")).toBe(Date.UTC(2026, 1, 5));
134-
expect(testApi.parseDateToMs("2026-2-5")).toBeUndefined();
135-
expect(testApi.parseDateToMs("nope")).toBeUndefined();
136-
expect(testApi.parseDateToMs(undefined)).toBeUndefined();
137-
});
138-
139-
it("parseDateToMs rejects out-of-range calendar dates instead of rolling them over", () => {
140-
// Impossible dates that still match the YYYY-MM-DD shape must not silently shift to a real day.
141-
expect(testApi.parseDateToMs("2026-02-30")).toBeUndefined(); // would roll to Mar 2
142-
expect(testApi.parseDateToMs("2026-04-31")).toBeUndefined(); // would roll to May 1
143-
expect(testApi.parseDateToMs("2025-02-29")).toBeUndefined(); // non-leap Feb 29
144-
expect(testApi.parseDateToMs("2026-13-01")).toBeUndefined(); // month too large
145-
expect(testApi.parseDateToMs("2026-00-10")).toBeUndefined(); // month zero
146-
expect(testApi.parseDateToMs("2026-01-00")).toBeUndefined(); // day zero
147-
// Real leap day must stay valid (guard against over-rejection).
148-
expect(testApi.parseDateToMs("2024-02-29")).toBe(Date.UTC(2024, 1, 29));
149-
});
150-
151131
it.each([
152132
[{ startDate: "2026-02-30" }, "invalid startDate"],
153133
[{ endDate: "2026-2-5" }, "invalid endDate"],
@@ -275,34 +255,6 @@ describe("gateway usage helpers", () => {
275255
expect(vi.mocked(discoverAllSessions)).not.toHaveBeenCalled();
276256
});
277257

278-
it("parseUtcOffsetToMinutes supports whole-hour and half-hour offsets", () => {
279-
expect(testApi.parseUtcOffsetToMinutes("UTC-4")).toBe(-240);
280-
expect(testApi.parseUtcOffsetToMinutes("UTC+5:30")).toBe(330);
281-
expect(testApi.parseUtcOffsetToMinutes(" UTC+14 ")).toBe(14 * 60);
282-
});
283-
284-
it("parseUtcOffsetToMinutes rejects invalid offsets", () => {
285-
expect(testApi.parseUtcOffsetToMinutes("UTC+14:30")).toBeUndefined();
286-
expect(testApi.parseUtcOffsetToMinutes("UTC+5:99")).toBeUndefined();
287-
expect(testApi.parseUtcOffsetToMinutes("UTC+25")).toBeUndefined();
288-
expect(testApi.parseUtcOffsetToMinutes("GMT+5")).toBeUndefined();
289-
expect(testApi.parseUtcOffsetToMinutes(undefined)).toBeUndefined();
290-
});
291-
292-
it("parseDays coerces strings/numbers to integers", () => {
293-
expect(testApi.parseDays(7.9)).toBe(7);
294-
expect(testApi.parseDays("30")).toBe(30);
295-
expect(testApi.parseDays("")).toBeUndefined();
296-
expect(testApi.parseDays("nope")).toBeUndefined();
297-
});
298-
299-
it("parseDays caps day counts before Date arithmetic can overflow", () => {
300-
expect(testApi.parseDays(1e300)).toBe(36600);
301-
expect(testApi.parseDays("1e300")).toBe(36600);
302-
expect(testApi.parseDays(Number.MAX_SAFE_INTEGER)).toBe(36600);
303-
expect(testApi.parseDays(366 * 100)).toBe(36600);
304-
});
305-
306258
it("resolveDateRange uses explicit start/end as UTC when mode is missing (backward compatible)", () => {
307259
const result = testApi.resolveDateRange({
308260
startDate: "2026-02-01",
@@ -311,13 +263,13 @@ describe("gateway usage helpers", () => {
311263
expectUtcDateRange(result, "2026-02-01", "2026-02-02");
312264
});
313265

314-
it("resolveDateRange uses explicit UTC mode", () => {
266+
it("resolveDateRange accepts a leap day in explicit UTC mode", () => {
315267
const result = testApi.resolveDateRange({
316-
startDate: "2026-02-01",
317-
endDate: "2026-02-02",
268+
startDate: "2024-02-29",
269+
endDate: "2024-03-01",
318270
mode: "utc",
319271
});
320-
expectUtcDateRange(result, "2026-02-01", "2026-02-02");
272+
expectUtcDateRange(result, "2024-02-29", "2024-03-01");
321273
});
322274

323275
it("resolveDateRange uses specific UTC offset for explicit dates", () => {
@@ -389,7 +341,7 @@ describe("gateway usage helpers", () => {
389341
startDate: "2026-02-01",
390342
endDate: "2026-02-02",
391343
mode: "specific",
392-
utcOffset: "bad-value",
344+
utcOffset: "UTC+14:30",
393345
}),
394346
);
395347
expect(missingOffset.startMs).toBe(Date.UTC(2026, 1, 1));

‎src/gateway/server-methods/usage.ts‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -522,21 +522,6 @@ const getDateParts = (date: Date, interpretation: DateInterpretation): DateParts
522522
};
523523
};
524524

525-
/**
526-
* Parse a date string (YYYY-MM-DD) to start-of-day timestamp based on interpretation mode.
527-
* Returns undefined if invalid.
528-
*/
529-
const parseDateToMs = (
530-
raw: unknown,
531-
interpretation: DateInterpretation = { mode: "utc" },
532-
): number | undefined => {
533-
const parts = parseDateParts(raw);
534-
if (!parts) {
535-
return undefined;
536-
}
537-
return datePartsToStartMs(parts, interpretation);
538-
};
539-
540525
const formatDateLabel = (ms: number, interpretation: DateInterpretation): string => {
541526
const parts = getDateParts(new Date(ms), interpretation);
542527
return formatDateParts(parts.year, parts.monthIndex, parts.day);
@@ -1141,9 +1126,6 @@ function mergeUsageCacheStatus(
11411126

11421127
// Exposed for unit tests (kept as a single export to avoid widening the public API surface).
11431128
export const testApi = {
1144-
parseUtcOffsetToMinutes,
1145-
parseDateToMs,
1146-
parseDays,
11471129
resolveDateRange,
11481130
loadCostUsageSummaryCached,
11491131
costUsageCache,

‎src/infra/diagnostic-events.test.ts‎

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
emitTrustedDiagnosticEventWithPrivateData,
1010
emitTrustedSkillUsedDiagnosticEvent,
1111
emitTrustedSecurityEvent,
12-
formatDiagnosticTraceparentForPropagation,
1312
hasPendingInternalDiagnosticEvent,
1413
isInternalDiagnosticEventMetadata,
1514
isDiagnosticsEnabled,
@@ -246,38 +245,6 @@ describe("diagnostic-events", () => {
246245
expect(isInternalDiagnosticEventMetadata({ trusted: false })).toBe(false);
247246
});
248247

249-
it("formats traceparent for propagation only from dispatcher-trusted metadata", () => {
250-
const trace = createDiagnosticTraceContext({
251-
traceId: "4bf92f3577b34da6a3ce929d0e0e4736",
252-
spanId: "00f067aa0ba902b7",
253-
traceFlags: "01",
254-
});
255-
const traceparents: Array<string | undefined> = [];
256-
onInternalDiagnosticEvent((event, metadata) => {
257-
traceparents.push(formatDiagnosticTraceparentForPropagation(event, metadata));
258-
});
259-
260-
emitDiagnosticEvent({
261-
type: "message.queued",
262-
source: "plugin",
263-
trace,
264-
});
265-
emitTrustedDiagnosticEvent({
266-
type: "model.usage",
267-
usage: { total: 1 },
268-
trace,
269-
});
270-
271-
expect(traceparents).toEqual([undefined, `00-${trace.traceId}-${trace.spanId}-01`]);
272-
expect(formatDiagnosticTraceparentForPropagation({ trace }, { trusted: true })).toBeUndefined();
273-
expect(
274-
formatDiagnosticTraceparentForPropagation(
275-
{ trace },
276-
{ trusted: false, trustedTraceContext: true },
277-
),
278-
).toBeUndefined();
279-
});
280-
281248
it("prepares trusted events synchronously without cloning private data", async () => {
282249
const diagnosticTrace = createDiagnosticTraceContext({
283250
traceId: "4bf92f3577b34da6a3ce929d0e0e4736",

‎src/infra/diagnostic-events.ts‎

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
type DiagnosticTraceContext,
2020
} from "./diagnostic-trace-context.js";
2121
import {
22-
formatPropagatedDiagnosticTraceparent,
2322
prepareDiagnosticTracePropagation,
2423
resetDiagnosticTracePropagationForTest,
2524
shouldPrepareDiagnosticTracePropagation,
@@ -959,7 +958,6 @@ type DiagnosticEventsGlobalState = {
959958
const MAX_ASYNC_DIAGNOSTIC_EVENTS = 10_000;
960959
const MAX_ASYNC_DIAGNOSTIC_EVENTS_PER_TURN = 100;
961960
const DIAGNOSTIC_EVENTS_STATE_KEY = Symbol.for("openclaw.diagnosticEvents.state.v1");
962-
const dispatchedTrustedDiagnosticMetadata = new WeakSet<object>();
963961
const ASYNC_DIAGNOSTIC_EVENT_TYPES = new Set<DiagnosticEventPayload["type"]>([
964962
"tool.execution.started",
965963
"tool.execution.completed",
@@ -1145,11 +1143,7 @@ function dispatchDiagnosticEvent(
11451143
function createDiagnosticMetadataForListener(
11461144
metadata: DiagnosticEventMetadata,
11471145
): DiagnosticEventMetadata {
1148-
const listenerMetadata = Object.freeze({ ...metadata });
1149-
if (listenerMetadata.trusted) {
1150-
dispatchedTrustedDiagnosticMetadata.add(listenerMetadata);
1151-
}
1152-
return listenerMetadata;
1146+
return Object.freeze({ ...metadata });
11531147
}
11541148

11551149
function cloneDiagnosticEventForListener(event: DiagnosticEventPayload): DiagnosticEventPayload {
@@ -1585,17 +1579,6 @@ export function onDiagnosticEvent(listener: (evt: DiagnosticEventPayload) => voi
15851579
});
15861580
}
15871581

1588-
/** Formats traceparent only for trusted metadata created by the diagnostic dispatcher. */
1589-
export function formatDiagnosticTraceparentForPropagation(
1590-
event: { trace?: DiagnosticTraceContext },
1591-
metadata: DiagnosticEventMetadata,
1592-
): string | undefined {
1593-
if (!metadata.trusted || !dispatchedTrustedDiagnosticMetadata.has(metadata)) {
1594-
return undefined;
1595-
}
1596-
return formatPropagatedDiagnosticTraceparent(event.trace);
1597-
}
1598-
15991582
/** Returns whether listener metadata marks dispatcher-internal provenance. */
16001583
export function isInternalDiagnosticEventMetadata(metadata: DiagnosticEventMetadata): boolean {
16011584
return metadata.internal === true;

0 commit comments

Comments
 (0)