






















@@ -0,0 +1,122 @@
1+import fs from "node:fs";
2+import path from "node:path";
3+4+const command = process.argv[2];
5+const readJson = (file) => JSON.parse(fs.readFileSync(file, "utf8"));
6+7+function assertOnboardState() {
8+const home = process.argv[3];
9+const stateDir = path.join(home, ".openclaw");
10+const configPath = path.join(stateDir, "openclaw.json");
11+const agentDir = path.join(stateDir, "agents", "main", "agent");
12+const authPath = path.join(agentDir, "auth-profiles.json");
13+14+if (!fs.existsSync(configPath)) {
15+throw new Error("onboard did not write openclaw.json");
16+}
17+if (!fs.existsSync(agentDir)) {
18+throw new Error("onboard did not create main agent dir");
19+}
20+if (!fs.existsSync(authPath)) {
21+throw new Error("onboard did not create auth-profiles.json");
22+}
23+const authRaw = fs.readFileSync(authPath, "utf8");
24+if (!authRaw.includes("OPENAI_API_KEY")) {
25+throw new Error("auth profile did not persist OPENAI_API_KEY env ref");
26+}
27+if (authRaw.includes("sk-openclaw-npm-onboard-e2e")) {
28+throw new Error("auth profile persisted the raw OpenAI test key");
29+}
30+}
31+32+function configureMockModel() {
33+const mockPort = Number(process.argv[3]);
34+const configPath = path.join(process.env.HOME, ".openclaw", "openclaw.json");
35+const cfg = readJson(configPath);
36+const modelRef = "openai/gpt-5.5";
37+const cost = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
38+39+cfg.models = {
40+ ...cfg.models,
41+mode: "merge",
42+providers: {
43+ ...cfg.models?.providers,
44+openai: {
45+ ...cfg.models?.providers?.openai,
46+baseUrl: `http://127.0.0.1:${mockPort}/v1`,
47+apiKey: { source: "env", provider: "default", id: "OPENAI_API_KEY" },
48+api: "openai-responses",
49+request: { ...cfg.models?.providers?.openai?.request, allowPrivateNetwork: true },
50+models: [
51+{
52+id: "gpt-5.5",
53+name: "gpt-5.5",
54+api: "openai-responses",
55+reasoning: false,
56+input: ["text", "image"],
57+ cost,
58+contextWindow: 128000,
59+contextTokens: 96000,
60+maxTokens: 4096,
61+},
62+],
63+},
64+},
65+};
66+cfg.agents = {
67+ ...cfg.agents,
68+defaults: {
69+ ...cfg.agents?.defaults,
70+model: { primary: modelRef },
71+models: {
72+ ...cfg.agents?.defaults?.models,
73+[modelRef]: { params: { transport: "sse", openaiWsWarmup: false } },
74+},
75+},
76+};
77+cfg.plugins = {
78+ ...cfg.plugins,
79+enabled: true,
80+};
81+fs.writeFileSync(configPath, `${JSON.stringify(cfg, null, 2)}\n`);
82+}
83+84+function assertChannelConfig() {
85+const channel = process.argv[3];
86+const token = process.argv[4];
87+const configPath = path.join(process.env.HOME, ".openclaw", "openclaw.json");
88+const cfg = readJson(configPath);
89+const entry = cfg.channels?.[channel];
90+if (!entry || entry.enabled === false) {
91+throw new Error(`${channel} was not enabled`);
92+}
93+if (!JSON.stringify(entry).includes(token)) {
94+throw new Error(`${channel} token was not persisted`);
95+}
96+}
97+98+function assertAgentTurn() {
99+const marker = process.argv[3];
100+const logPath = process.argv[4];
101+const output = fs.readFileSync("/tmp/openclaw-agent.combined", "utf8");
102+if (!output.includes(marker)) {
103+throw new Error(`agent JSON did not contain success marker. Output: ${output}`);
104+}
105+const requestLog = fs.existsSync(logPath) ? fs.readFileSync(logPath, "utf8") : "";
106+if (!/\/v1\/(responses|chat\/completions)/u.test(requestLog)) {
107+throw new Error(`mock OpenAI server was not used. Requests: ${requestLog}`);
108+}
109+}
110+111+const commands = {
112+"assert-onboard-state": assertOnboardState,
113+"configure-mock-model": configureMockModel,
114+"assert-channel-config": assertChannelConfig,
115+"assert-agent-turn": assertAgentTurn,
116+};
117+118+const fn = commands[command];
119+if (!fn) {
120+throw new Error(`unknown npm onboard/channel/agent assertion command: ${command}`);
121+}
122+fn();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。