Skip to content

Commit 2f7299e

Browse files
authored
test(qa): add provider runtime evidence (#101051)
1 parent 80537c1 commit 2f7299e

12 files changed

Lines changed: 766 additions & 634 deletions

‎extensions/diagnostics-otel/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Diagnostics Otel plugin entrypoint registers its OpenClaw integration.
22
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
3-
import { createDiagnosticsOtelService } from "./src/service.js";
3+
import { createDiagnosticsOtelService } from "./runtime-api.js";
44

55
export default definePluginEntry({
66
id: "diagnostics-otel",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Diagnostics Otel runtime API exposes the service factory to trusted runtime callers.
2+
export { createDiagnosticsOtelService } from "./src/service.js";
3+
export type { OpenClawPluginServiceContext } from "./api.js";

‎extensions/qa-lab/src/scenario-catalog.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ describe("qa scenario catalog", () => {
222222
it("loads native test execution scenarios from YAML", () => {
223223
const scenario = readQaScenarioById("control-ui-chat-flow-playwright");
224224
const uxMatrix = readQaScenarioById("ux-matrix-evidence-dashboard");
225+
const otelSmoke = readQaScenarioById("qa-otel-smoke");
225226

226227
expect(scenario.execution.kind).toBe("playwright");
227228
if (scenario.execution.kind !== "playwright") {
@@ -238,6 +239,17 @@ describe("qa scenario catalog", () => {
238239
expect(uxMatrix.execution.args).toStrictEqual(["--artifact-base", "${outputDir}"]);
239240
expect(uxMatrix.execution.config).toBeUndefined();
240241
expect(uxMatrix.coverage?.primary).toContain("qa.artifact-safety");
242+
expect(otelSmoke.execution.kind).toBe("script");
243+
if (otelSmoke.execution.kind !== "script") {
244+
throw new Error(`expected script scenario, got ${otelSmoke.execution.kind}`);
245+
}
246+
expect(otelSmoke.execution.args).toStrictEqual([
247+
"--output-dir",
248+
"${outputDir}",
249+
"--logs-exporter",
250+
"both",
251+
]);
252+
expect(otelSmoke.coverage?.secondary).not.toContain("harness.qa-lab");
241253
});
242254

243255
it("loads helper-backed HTTP API scenarios as supporting taxonomy coverage", () => {

‎qa/scenarios/runtime/qa-otel-smoke.yaml‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ scenario:
77
primary:
88
- telemetry.otel
99
secondary:
10-
- harness.qa-lab
1110
- telemetry.plugin-sdk-runtime-exports
1211
objective: Execute the bounded local OTLP runtime producer directly and publish its OpenTelemetry assertions through the shared QA script evidence writer.
1312
successCriteria:
1413
- QA Lab launches the runtime producer directly with a bounded local collector configuration.
1514
- The producer emits shared script evidence plus its OTEL assertion summary.
16-
- The producer captures release-critical traces, metrics, and correlated logs from a real QA runtime execution.
15+
- The producer captures release-critical traces, metrics, and correlated logs from the diagnostics runtime.
1716
- Smoke assertions reject failed OTLP requests, missing required signals, and configured leak needles.
1817
docsRefs:
1918
- docs/gateway/opentelemetry.md
2019
- docs/concepts/qa-e2e-automation.md
2120
codeRefs:
2221
- test/e2e/qa-lab/runtime/script-evidence.ts
2322
- test/e2e/qa-lab/runtime/qa-otel-smoke-runtime.ts
23+
- extensions/diagnostics-otel/runtime-api.ts
2424
execution:
2525
kind: script
2626
path: test/e2e/qa-lab/runtime/qa-otel-smoke-runtime.ts
@@ -29,10 +29,6 @@ scenario:
2929
args:
3030
- --output-dir
3131
- ${outputDir}
32-
- --provider-mode
33-
- mock-openai
34-
- --scenario
35-
- otel-both-log-smoke
3632
- --logs-exporter
3733
- both
3834
timeoutMs: 120000

‎scripts/test-projects.test-support.mjs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,6 +2077,14 @@ const SOURCE_TEST_TARGETS = new Map([
20772077
"test/e2e/qa-lab/runtime/qa-otel-smoke-runtime.ts",
20782078
["test/e2e/qa-lab/runtime/qa-otel-smoke.e2e.test.ts"],
20792079
],
2080+
[
2081+
"test/e2e/qa-lab/runtime/heartbeat-active-hours-runtime.ts",
2082+
["test/e2e/qa-lab/runtime/heartbeat-active-hours-runtime.test.ts"],
2083+
],
2084+
[
2085+
"test/e2e/qa-lab/runtime/telegram-bot-token-runtime.ts",
2086+
["test/e2e/qa-lab/runtime/telegram-bot-token-runtime.test.ts"],
2087+
],
20802088
["src/plugins/runtime-sidecar-paths-baseline.ts", RUNTIME_SIDECAR_BASELINE_OWNER_TEST_TARGETS],
20812089
["src/plugins/runtime-sidecar-paths.ts", RUNTIME_SIDECAR_PATH_CONSUMER_TEST_TARGETS],
20822090
["ui/config/control-ui-chunking.ts", ["ui/src/app/control-ui-chunking.test.ts"]],

‎src/plugins/contracts/plugin-sdk-runtime-api-guardrails.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ const UNGUARDED_RUNTIME_API_PLUGIN_IDS = [
4343
] as const;
4444

4545
const RUNTIME_API_EXPORT_GUARDS: Record<string, readonly string[]> = {
46+
[bundledPluginFile({
47+
rootDir: ROOT_DIR,
48+
pluginId: "diagnostics-otel",
49+
relativePath: "runtime-api.ts",
50+
})]: [
51+
'export { createDiagnosticsOtelService } from "./src/service.js";',
52+
'export type { OpenClawPluginServiceContext } from "./api.js";',
53+
],
4654
[bundledPluginFile({ rootDir: ROOT_DIR, pluginId: "discord", relativePath: "runtime-api.ts" })]: [
4755
'export { discordMessageActions, handleDiscordAction, isDiscordModerationAction, readDiscordChannelCreateParams, readDiscordChannelEditParams, readDiscordChannelMoveParams, readDiscordModerationCommand, readDiscordParentIdParam, requiredGuildPermissionForModerationAction, type DiscordModerationAction, type DiscordModerationCommand } from "./runtime-api.actions.js";',
4856
'export { auditDiscordChannelPermissions, collectDiscordAuditChannelIds, fetchDiscordApplicationId, fetchDiscordApplicationSummary, listDiscordDirectoryGroupsLive, listDiscordDirectoryPeersLive, parseApplicationIdFromToken, probeDiscord, resolveDiscordChannelAllowlist, resolveDiscordPrivilegedIntentsFromFlags, resolveDiscordUserAllowlist, setDiscordRuntime, type DiscordApplicationSummary, type DiscordChannelResolution, type DiscordPrivilegedIntentsSummary, type DiscordPrivilegedIntentStatus, type DiscordProbe, type DiscordUserResolution } from "./runtime-api.lookup.js";',
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import fs from "node:fs/promises";
2+
import os from "node:os";
3+
import path from "node:path";
4+
import { afterEach, describe, expect, it } from "vitest";
5+
import { runHeartbeatActiveHoursRuntime } from "./heartbeat-active-hours-runtime.js";
6+
7+
const tempDirs: string[] = [];
8+
9+
afterEach(async () => {
10+
await Promise.all(tempDirs.splice(0).map((dir) => fs.rm(dir, { force: true, recursive: true })));
11+
});
12+
13+
describe("heartbeat active-hours runtime evidence", () => {
14+
it("observes active fire, quiet-hours skip, and reload fire", async () => {
15+
const artifactBase = await fs.mkdtemp(path.join(os.tmpdir(), "heartbeat-active-hours-"));
16+
tempDirs.push(artifactBase);
17+
const evidence = await runHeartbeatActiveHoursRuntime({
18+
artifactBase,
19+
repoRoot: process.cwd(),
20+
timeoutMs: 2_000,
21+
});
22+
23+
expect(evidence.entries[0]?.result.status).toBe("pass");
24+
const summary = JSON.parse(
25+
await fs.readFile(path.join(artifactBase, "heartbeat-active-hours-summary.json"), "utf8"),
26+
) as { observations: Array<{ outcome: string }> };
27+
expect(summary.observations.map((entry) => entry.outcome)).toEqual([
28+
"active-fire",
29+
"quiet-hours-skip",
30+
"active-fire",
31+
]);
32+
});
33+
});
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
// Heartbeat active-hours evidence runs the real bounded scheduler and reload path.
2+
import fs from "node:fs/promises";
3+
import path from "node:path";
4+
import { pathToFileURL } from "node:url";
5+
import type { OpenClawConfig } from "../../../../src/config/types.openclaw.js";
6+
import { formatErrorMessage } from "../../../../src/infra/errors.js";
7+
import { isWithinActiveHours } from "../../../../src/infra/heartbeat-active-hours.js";
8+
import { startHeartbeatRunner } from "../../../../src/infra/heartbeat-runner.js";
9+
import { createQaScriptEvidenceWriter } from "./script-evidence.js";
10+
11+
const DEFAULT_TIMEOUT_MS = 5_000;
12+
const HEARTBEAT_INTERVAL = "100ms";
13+
14+
type HeartbeatRuntimeOptions = {
15+
artifactBase: string;
16+
repoRoot: string;
17+
timeoutMs: number;
18+
};
19+
20+
type SchedulerObservation = {
21+
at: string;
22+
outcome: "active-fire" | "quiet-hours-skip";
23+
};
24+
25+
function parseOptions(argv: string[], repoRoot = process.cwd()): HeartbeatRuntimeOptions {
26+
let artifactBase = path.join(repoRoot, ".artifacts", "qa-e2e", "heartbeat-active-hours");
27+
let timeoutMs = DEFAULT_TIMEOUT_MS;
28+
for (let index = 0; index < argv.length; index += 1) {
29+
const arg = argv[index];
30+
if (arg === "--output-dir") {
31+
artifactBase = path.resolve(repoRoot, argv[++index] ?? "");
32+
continue;
33+
}
34+
if (arg === "--timeout-ms") {
35+
timeoutMs = Number(argv[++index]);
36+
continue;
37+
}
38+
if (arg === "--") {
39+
continue;
40+
}
41+
throw new Error(`Unknown argument: ${arg}`);
42+
}
43+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
44+
throw new Error("--timeout-ms must be a positive number");
45+
}
46+
return { artifactBase, repoRoot, timeoutMs };
47+
}
48+
49+
function heartbeatConfig(quietHours: boolean): OpenClawConfig {
50+
return {
51+
agents: {
52+
defaults: {
53+
heartbeat: {
54+
activeHours: quietHours
55+
? { start: "00:00", end: "00:00", timezone: "UTC" }
56+
: { start: "00:00", end: "24:00", timezone: "UTC" },
57+
every: HEARTBEAT_INTERVAL,
58+
target: "none",
59+
},
60+
},
61+
},
62+
};
63+
}
64+
65+
async function waitForObservation(
66+
observations: SchedulerObservation[],
67+
outcome: SchedulerObservation["outcome"],
68+
afterCount: number,
69+
timeoutMs: number,
70+
) {
71+
const deadline = Date.now() + timeoutMs;
72+
while (Date.now() < deadline) {
73+
if (observations.slice(afterCount).some((entry) => entry.outcome === outcome)) {
74+
return;
75+
}
76+
await new Promise((resolve) => setTimeout(resolve, 20));
77+
}
78+
throw new Error(`heartbeat scheduler did not observe ${outcome} within ${timeoutMs}ms`);
79+
}
80+
81+
function createWriter(options: HeartbeatRuntimeOptions) {
82+
return createQaScriptEvidenceWriter({
83+
artifactBase: options.artifactBase,
84+
logFileName: "heartbeat-active-hours.log",
85+
primaryModel: "heartbeat/scheduler",
86+
providerMode: "mock-openai",
87+
repoRoot: options.repoRoot,
88+
target: {
89+
id: "heartbeat-active-hours",
90+
title: "Heartbeat active-hours scheduler",
91+
sourcePath: "test/e2e/qa-lab/runtime/heartbeat-active-hours-runtime.ts",
92+
primaryCoverageIds: ["automation.active-hours"],
93+
docsRefs: ["docs/gateway/heartbeat.md"],
94+
codeRefs: [
95+
"test/e2e/qa-lab/runtime/heartbeat-active-hours-runtime.ts",
96+
"src/infra/heartbeat-runner.ts",
97+
"src/infra/heartbeat-active-hours.ts",
98+
],
99+
},
100+
});
101+
}
102+
103+
export async function runHeartbeatActiveHoursRuntime(options: HeartbeatRuntimeOptions) {
104+
await fs.mkdir(options.artifactBase, { recursive: true });
105+
const writer = createWriter(options);
106+
const startedAt = Date.now();
107+
const observations: SchedulerObservation[] = [];
108+
let currentConfig = heartbeatConfig(false);
109+
const runner = startHeartbeatRunner({
110+
cfg: currentConfig,
111+
readCurrentConfig: () => currentConfig,
112+
runOnce: async ({ cfg, heartbeat }) => {
113+
const active = isWithinActiveHours(cfg, heartbeat);
114+
const outcome = active ? "active-fire" : "quiet-hours-skip";
115+
observations.push({ at: new Date().toISOString(), outcome });
116+
writer.appendLog(`heartbeat-active-hours: ${outcome}\n`);
117+
return active
118+
? { status: "ran", durationMs: 1 }
119+
: { status: "skipped", reason: "quiet-hours" };
120+
},
121+
stableSchedulerSeed: "qa-heartbeat-active-hours",
122+
});
123+
try {
124+
await waitForObservation(observations, "active-fire", 0, options.timeoutMs);
125+
const beforeQuiet = observations.length;
126+
currentConfig = heartbeatConfig(true);
127+
runner.updateConfig(currentConfig);
128+
await waitForObservation(observations, "quiet-hours-skip", beforeQuiet, options.timeoutMs);
129+
const beforeReload = observations.length;
130+
currentConfig = heartbeatConfig(false);
131+
runner.updateConfig(currentConfig);
132+
await waitForObservation(observations, "active-fire", beforeReload, options.timeoutMs);
133+
134+
const summaryPath = path.join(options.artifactBase, "heartbeat-active-hours-summary.json");
135+
await fs.writeFile(summaryPath, `${JSON.stringify({ observations }, null, 2)}\n`, "utf8");
136+
return await writer.write({
137+
artifacts: [{ kind: "summary", filePath: summaryPath }],
138+
details: "Observed active fire, quiet-hours skip, and active-hours reload fire",
139+
durationMs: Math.max(1, Date.now() - startedAt),
140+
status: "pass",
141+
});
142+
} catch (error) {
143+
const details = formatErrorMessage(error);
144+
writer.appendLog(`heartbeat-active-hours: ${details}\n`);
145+
return await writer.write({
146+
details,
147+
durationMs: Math.max(1, Date.now() - startedAt),
148+
status: "fail",
149+
});
150+
} finally {
151+
runner.stop();
152+
}
153+
}
154+
155+
export const testing = { heartbeatConfig, parseOptions, waitForObservation };
156+
157+
if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {
158+
runHeartbeatActiveHoursRuntime(parseOptions(process.argv.slice(2)))
159+
.then((evidence) => {
160+
const status = evidence.entries[0]?.result.status;
161+
process.stdout.write(`heartbeat-active-hours: ${status}\n`);
162+
process.exitCode = status === "pass" ? 0 : 1;
163+
})
164+
.catch((error: unknown) => {
165+
process.stderr.write(`heartbeat-active-hours: ${formatErrorMessage(error)}\n`);
166+
process.exitCode = 1;
167+
});
168+
}

0 commit comments

Comments
 (0)