#!/usr/bin/env node import assert from "node:assert/strict"; import { handleCodeAgentChat, validateCodeAgentChatSchema } from "../internal/cloud/code-agent-chat.mjs"; function logOk(name) { process.stdout.write(`[code-agent-chat-smoke] ok ${name}\n`); } const completed = await handleCodeAgentChat( { conversationId: "cnv_code-agent-chat-smoke", traceId: "trc_code-agent-chat-smoke", projectId: "prj_code-agent-chat-smoke", message: "请用一句话说明当前 HWLAB 工作台可以做什么。" }, { now: () => "2026-05-22T00:00:00.000Z", callProvider: async ({ providerPlan }) => ({ provider: providerPlan.provider, model: providerPlan.model, backend: providerPlan.backend, content: "HWLAB 工作台可以用 Code Agent 对话来整理任务、查看资源并保持硬件变更受控。", usage: null, providerTrace: { source: "schema-smoke-provider" } }) } ); validateCodeAgentChatSchema(completed); assert.equal(completed.conversationId, "cnv_code-agent-chat-smoke"); assert.equal(completed.sessionId, "cnv_code-agent-chat-smoke"); assert.match(completed.messageId, /^msg_/); assert.equal(completed.status, "completed"); assert.equal(completed.createdAt, "2026-05-22T00:00:00.000Z"); assert.equal(completed.updatedAt, "2026-05-22T00:00:00.000Z"); assert.equal(completed.traceId, "trc_code-agent-chat-smoke"); assert.equal(completed.error, undefined); assert.match(completed.reply.content, /Code Agent/); logOk("completed schema"); const failed = await handleCodeAgentChat( { traceId: "trc_code-agent-chat-smoke-failed", message: "你好" }, { now: () => "2026-05-22T00:01:00.000Z", env: { PATH: "", HWLAB_CODE_AGENT_PROVIDER: "codex-cli", HWLAB_CODE_AGENT_MODEL: "gpt-test" } } ); validateCodeAgentChatSchema(failed); assert.match(failed.conversationId, /^cnv_/); assert.match(failed.sessionId, /^cnv_/); assert.match(failed.messageId, /^msg_/); assert.equal(failed.status, "failed"); assert.equal(failed.createdAt, "2026-05-22T00:01:00.000Z"); assert.equal(failed.updatedAt, "2026-05-22T00:01:00.000Z"); assert.equal(failed.traceId, "trc_code-agent-chat-smoke-failed"); assert.equal(failed.provider, "codex-cli"); assert.equal(failed.model, "gpt-test"); assert.equal(failed.backend, "hwlab-cloud-api/codex-cli"); assert.equal(failed.error.code, "provider_unavailable"); assert.match(failed.error.message, /Codex CLI command is not available/); assert.deepEqual(failed.error.missingCommands, ["codex"]); assert.ok(failed.error.missingEnv.includes("OPENAI_API_KEY")); assert.equal(Object.hasOwn(failed, "reply"), false); logOk("failed provider-gap schema"); process.stdout.write("[code-agent-chat-smoke] passed\n");