test: 覆盖 Workbench CLI 双模式 smoke
This commit is contained in:
@@ -4,16 +4,21 @@ import { mkdtemp, rm } from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import { runWorkbenchCli } from "../tools/src/workbench-cli.ts";
|
||||
|
||||
const root = path.resolve(import.meta.dirname, "..");
|
||||
const stateDir = await mkdtemp(path.join(os.tmpdir(), "hwlab-workbench-native-"));
|
||||
const children = [];
|
||||
const logs = [];
|
||||
|
||||
try {
|
||||
const api = start(["bun", "cmd/hwlab-workbench-api/main.ts"], {
|
||||
const nativeEnv = {
|
||||
...process.env,
|
||||
WORKBENCH_MODE: "native-test",
|
||||
WORKBENCH_NATIVE_STATE_FILE: path.join(stateDir, "state.json"),
|
||||
WORKBENCH_NATIVE_STATE_FILE: path.join(stateDir, "state.json")
|
||||
};
|
||||
const api = start(["bun", "cmd/hwlab-workbench-api/main.ts"], {
|
||||
...nativeEnv,
|
||||
WORKBENCH_API_HOST: "127.0.0.1",
|
||||
WORKBENCH_API_PORT: "6677"
|
||||
}, "api");
|
||||
@@ -27,6 +32,27 @@ try {
|
||||
const commandHealth = await requiredJson(await fetch("http://127.0.0.1:6677/v1/workbench/commands", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ operation: "health" }) }), "command.health");
|
||||
if (commandHealth.mode !== "native-test") throw new Error("native command transport did not expose mode=native-test");
|
||||
|
||||
const localSession = await runWorkbenchCli(["session", "create", "--actor-id", "usr_native", "--provider-profile", "native-test"], nativeEnv);
|
||||
const localSessionId = localSession.identity?.sessionId;
|
||||
if (localSession.transport !== "local" || !localSessionId) throw new Error("CLI local session transport contract failed");
|
||||
const localTraceId = "trc_native_cli_local";
|
||||
const localSubmit = await runWorkbenchCli(["turn", "submit", "--actor-id", "usr_native", "--session-id", localSessionId, "--trace-id", localTraceId, "--message", "native CLI local smoke"], nativeEnv);
|
||||
if (localSubmit.transport !== "local" || localSubmit.data?.resultSynthesized !== false) throw new Error("CLI local submit authority contract failed");
|
||||
const localCancel = await runWorkbenchCli(["turn", "cancel", "--actor-id", "usr_native", "--trace-id", localTraceId], nativeEnv);
|
||||
if (localCancel.data?.status !== "cancel_requested") throw new Error("CLI local cancel was not accepted");
|
||||
|
||||
const overApiArgs = ["--over-api", "--api-url", "http://127.0.0.1:6677"];
|
||||
const apiHealth = await runWorkbenchCli(["health", ...overApiArgs], nativeEnv);
|
||||
if (apiHealth.transport !== "api" || apiHealth.httpStatus !== 200) throw new Error("CLI --over-api health transport contract failed");
|
||||
const apiSession = await runWorkbenchCli(["session", "create", "--actor-id", "usr_native", "--provider-profile", "native-test", ...overApiArgs], nativeEnv);
|
||||
const apiSessionId = apiSession.identity?.sessionId;
|
||||
if (apiSession.transport !== "api" || !apiSessionId) throw new Error("CLI --over-api session transport contract failed");
|
||||
const apiTraceId = "trc_native_cli_over_api";
|
||||
const apiSubmit = await runWorkbenchCli(["turn", "submit", "--actor-id", "usr_native", "--session-id", apiSessionId, "--trace-id", apiTraceId, "--message", "native CLI over API smoke", ...overApiArgs], nativeEnv);
|
||||
if (apiSubmit.transport !== "api" || apiSubmit.data?.resultSynthesized !== false) throw new Error("CLI --over-api submit authority contract failed");
|
||||
const apiCancel = await runWorkbenchCli(["turn", "cancel", "--actor-id", "usr_native", "--trace-id", apiTraceId, ...overApiArgs], nativeEnv);
|
||||
if (apiCancel.data?.status !== "cancel_requested") throw new Error("CLI --over-api cancel was not accepted");
|
||||
|
||||
const actorHeaders = { "content-type": "application/json", cookie: "hwlab_session=native-test" };
|
||||
const sessionResponse = await fetch("http://127.0.0.1:6677/v1/agent/sessions", { method: "POST", headers: actorHeaders, body: JSON.stringify({ providerProfile: "native-test" }) });
|
||||
const session = await requiredJson(sessionResponse, "session.create");
|
||||
@@ -39,7 +65,7 @@ try {
|
||||
const cancel = await requiredJson(await fetch("http://127.0.0.1:6677/v1/agent/chat/cancel", { method: "POST", headers: actorHeaders, body: JSON.stringify({ sessionId, traceId }) }), "turn.cancel");
|
||||
if (cancel.status !== "cancel_requested") throw new Error("native cancel was not accepted");
|
||||
|
||||
process.stdout.write(`${JSON.stringify({ ok: true, mode: "native-test", apiUrl: "http://127.0.0.1:6677", webUrl: "http://127.0.0.1:5173/workbench", sessionId, traceId, services: { api: "independent", web: "vite-hmr" }, terminalAuthority: "fixture-only", resultSynthesized: false })}\n`);
|
||||
process.stdout.write(`${JSON.stringify({ ok: true, mode: "native-test", apiUrl: "http://127.0.0.1:6677", webUrl: "http://127.0.0.1:5173/workbench", sessionId, traceId, cli: { local: "application-dispatcher", overApi: "POST /v1/workbench/commands" }, services: { api: "independent", web: "vite-hmr" }, terminalAuthority: "fixture-only", resultSynthesized: false })}\n`);
|
||||
} catch (error) {
|
||||
process.stderr.write(`${JSON.stringify({ ok: false, error: { code: "workbench_native_smoke_failed", message: error instanceof Error ? error.message : String(error) }, logs: logs.slice(-20) })}\n`);
|
||||
process.exitCode = 1;
|
||||
|
||||
Reference in New Issue
Block a user