Skip to content

Commit 3bbc4ad

Browse files
authored
test(qa): cover managed gateway service lifecycle (#118855)
1 parent dc11c78 commit 3bbc4ad

5 files changed

Lines changed: 446 additions & 2 deletions
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// QA Lab owns the real child/provider fixture used by the managed service proof.
2+
import { fileURLToPath } from "node:url";
3+
import { describe, expect, it } from "vitest";
4+
import { startQaGatewayChild } from "./gateway-child.js";
5+
import { startQaProviderServer } from "./providers/server-runtime.js";
6+
7+
const repoRoot = fileURLToPath(new URL("../../../", import.meta.url));
8+
9+
async function fetchJson(url: string, label: string): Promise<Record<string, unknown>> {
10+
const response = await fetch(url);
11+
if (!response.ok) {
12+
throw new Error(`${label} returned HTTP ${response.status}`);
13+
}
14+
const body: unknown = await response.json();
15+
if (!body || typeof body !== "object" || Array.isArray(body)) {
16+
throw new Error(`${label} did not return a JSON object`);
17+
}
18+
return body as Record<string, unknown>;
19+
}
20+
21+
describe("managed gateway service lifecycle product proof", () => {
22+
it(
23+
"runs a foreground gateway with live, ready, and RPC health",
24+
{ timeout: 180_000 },
25+
async () => {
26+
const provider = await startQaProviderServer("mock-openai");
27+
if (!provider) {
28+
throw new Error("mock OpenAI provider did not start");
29+
}
30+
let gateway: Awaited<ReturnType<typeof startQaGatewayChild>> | undefined;
31+
let proofFailure: Error | undefined;
32+
try {
33+
gateway = await startQaGatewayChild({
34+
repoRoot,
35+
useRepoCli: true,
36+
providerBaseUrl: `${provider.baseUrl}/v1`,
37+
providerMode: "mock-openai",
38+
transportBaseUrl: "http://127.0.0.1",
39+
controlUiEnabled: false,
40+
});
41+
expect(gateway.pid).toBeGreaterThan(0);
42+
await expect(
43+
fetchJson(`${gateway.baseUrl}/healthz`, "gateway /healthz"),
44+
).resolves.toMatchObject({ status: "live" });
45+
await expect(
46+
fetchJson(`${gateway.baseUrl}/readyz`, "gateway /readyz"),
47+
).resolves.toMatchObject({ ready: true });
48+
const rpcHealth = await gateway.call("health", {});
49+
expect(rpcHealth).not.toBeNull();
50+
expect(Array.isArray(rpcHealth)).toBe(false);
51+
expect(typeof rpcHealth).toBe("object");
52+
} catch (error) {
53+
proofFailure = error instanceof Error ? error : new Error(String(error));
54+
}
55+
const cleanup = await Promise.allSettled([gateway?.stop(), provider.stop()]);
56+
const cleanupFailures = cleanup.flatMap((result) =>
57+
result.status === "rejected" ? [result.reason] : [],
58+
);
59+
if (proofFailure && cleanupFailures.length > 0) {
60+
throw new AggregateError(
61+
[proofFailure, ...cleanupFailures],
62+
"foreground gateway proof and cleanup failed",
63+
);
64+
}
65+
if (proofFailure) {
66+
throw proofFailure;
67+
}
68+
if (cleanupFailures.length > 0) {
69+
throw new AggregateError(cleanupFailures, "foreground gateway cleanup failed");
70+
}
71+
},
72+
);
73+
});
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
title: Managed gateway service lifecycle
2+
3+
scenario:
4+
id: managed-gateway-service-lifecycle
5+
surface: cli
6+
category: cli.gateway-service-management
7+
coverage:
8+
primary:
9+
- cli.foreground-gateway-runs
10+
- cli.service-install-and-control
11+
- cli.drift-and-reinstall-recovery
12+
- cli.service-health-checks
13+
objective: Exercise foreground startup and the managed gateway install, control, repair, and health boundaries across the supported service adapters.
14+
successCriteria:
15+
- The real foreground gateway CLI starts in an isolated state dir, reports live and ready HTTP probes plus RPC health, and terminates cleanly.
16+
- Foreground option validation reports invalid or unsafe startup requests before launch.
17+
- Managed install and control exercise the CLI owner boundary plus launchd, systemd, and Windows Scheduled Task adapter contracts.
18+
- Drifted service definitions and environments trigger explicit reinstall or repair behavior instead of being accepted as current.
19+
- Restart and status flows distinguish healthy, stale, failed, and timed-out post-operation outcomes.
20+
- On macOS and Windows hosts, the producer also runs the native launchd or Scheduled Task integration lane.
21+
docsRefs:
22+
- docs/cli/gateway.md
23+
- docs/install/updating.md
24+
- docs/gateway/troubleshooting.md
25+
- docs/reference/test.md
26+
codeRefs:
27+
- test/e2e/qa-lab/runtime/managed-gateway-service-lifecycle-product-proof.ts
28+
- extensions/qa-lab/src/managed-gateway-service-lifecycle.e2e.test.ts
29+
- src/cli/gateway-cli/run.option-collisions.test.ts
30+
- src/cli/daemon-cli/install.integration.test.ts
31+
- src/cli/daemon-cli/lifecycle.test.ts
32+
- src/cli/daemon-cli/restart-health.test.ts
33+
- src/daemon/launchd.integration.e2e.test.ts
34+
- src/daemon/systemd.test.ts
35+
- src/daemon/schtasks.integration.e2e.test.ts
36+
execution:
37+
kind: script
38+
path: test/e2e/qa-lab/runtime/managed-gateway-service-lifecycle-product-proof.ts
39+
summary: Runs four separately reported CLI lifecycle phases, all supported service-adapter contracts, and the current host's native service integration lane.
40+
timeoutMs: 1800000
41+
args:
42+
- --artifact-base
43+
- ${outputDir}

‎qa/scenarios/config/system-agent-ring-zero-setup.yaml‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ scenario:
44
id: system-agent-ring-zero-setup
55
surface: config
66
coverage:
7+
primary:
8+
- cli.service-auth-wiring-create
9+
- cli.service-auth-wiring-system-agent-setup
710
secondary:
811
- channels.setup-onboarding-flows-system-agent-setup
912
- discord.token-and-application-id-configuration
@@ -13,7 +16,8 @@ scenario:
1316
- OpenClaw fails closed in an empty state dir and directs the user to inference onboarding.
1417
- The packaged activation module tests a fake Claude inference backend before persisting its model, with remaining setup deferred to OpenClaw.
1518
- A fuzzy packaged CLI request reaches the verified planner and resolves to a typed setup operation only after activation.
16-
- Supporting one-shot commands write the workspace/model and create a non-main agent.
19+
- The approved openclaw.setup operation independently writes the default workspace and model.
20+
- The approved agents.create operation independently creates a non-main agent with its own workspace.
1721
- Discord is enabled and configured through an env SecretRef without persisting the raw token.
1822
- Config validation passes and audit entries exist for every applied write.
1923
docsRefs:
@@ -27,7 +31,7 @@ scenario:
2731
execution:
2832
kind: script
2933
path: test/e2e/qa-lab/runtime/docker-e2e-lane.ts
30-
summary: Redirects to the packaged inference-gate and typed-operation Docker lane; coverage remains secondary until a real interactive agent/tool/approval flow is exercised.
34+
summary: Runs the packaged inference-gate and typed-operation Docker lane, with separate assertions for openclaw.setup and agents.create; interactive channel coverage remains secondary.
3135
args:
3236
- --lane
3337
- system-agent-first-run
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { spawnSync } from "node:child_process";
2+
import fs from "node:fs/promises";
3+
import os from "node:os";
4+
import path from "node:path";
5+
import { afterEach, describe, expect, it, vi } from "vitest";
6+
import {
7+
QA_EVIDENCE_FILENAME,
8+
validateQaEvidenceSummaryJson,
9+
} from "../../../../extensions/qa-lab/api.js";
10+
import { testing } from "./managed-gateway-service-lifecycle-product-proof.js";
11+
12+
vi.mock("node:child_process", async (importOriginal) => ({
13+
...(await importOriginal<typeof import("node:child_process")>()),
14+
spawnSync: vi.fn(),
15+
}));
16+
17+
const tempRoots: string[] = [];
18+
19+
afterEach(async () => {
20+
vi.mocked(spawnSync).mockReset();
21+
await Promise.all(
22+
tempRoots.splice(0).map((root) => fs.rm(root, { recursive: true, force: true })),
23+
);
24+
});
25+
26+
describe("managed gateway service lifecycle evidence producer", () => {
27+
it("records failed evidence and exits nonzero when a child phase is signaled", async () => {
28+
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-service-lifecycle-"));
29+
const artifactBase = path.join(root, "artifacts");
30+
tempRoots.push(root);
31+
vi.mocked(spawnSync).mockReturnValue({
32+
output: [null, null, null],
33+
pid: 123,
34+
signal: "SIGTERM",
35+
status: null,
36+
stderr: Buffer.alloc(0),
37+
stdout: Buffer.alloc(0),
38+
});
39+
40+
await expect(testing.main(["--artifact-base", artifactBase])).resolves.toBe(1);
41+
42+
const evidence = validateQaEvidenceSummaryJson(
43+
JSON.parse(await fs.readFile(path.join(artifactBase, QA_EVIDENCE_FILENAME), "utf8")),
44+
);
45+
expect(evidence.entries[0]).toMatchObject({
46+
result: {
47+
failure: {
48+
reason: expect.stringContaining("terminated by signal SIGTERM"),
49+
},
50+
status: "fail",
51+
},
52+
});
53+
await expect(
54+
fs.readFile(path.join(artifactBase, "managed-gateway-service-lifecycle.log"), "utf8"),
55+
).resolves.toContain("fail: foreground-cli-runtime terminated by signal SIGTERM");
56+
});
57+
});

0 commit comments

Comments
 (0)