mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-16 23:21:38 +00:00
* chore(types): add declaration files for scripts/lib and scripts/e2e modules
* chore(types): add declaration files for top-level script modules (a-m)
* chore(types): add declaration files for top-level script modules (n-z)
* test: use a non-secret-shaped gateway token fixture
* test: type ci workflow guard helpers for the root test lane
* chore(tooling): typecheck root test/** with a dedicated tsgo lane
- test/tsconfig/tsconfig.test.root.json: root-test program (strict unused checks,
fixtures excluded; two Docker E2E clients that import built dist/** stay out,
same rationale as the scripts/e2e exclusion in tsconfig.scripts.json)
- tsgo:test:root wired into tsgo:test, check:test-types, scripts/check.mjs, and
the ci.yml test-types shard, mirroring the tsgo:scripts lane (#104348)
- changed-lane routing: test/**/*.ts (excluding fixtures) and the lane tsconfig
now trigger 'typecheck test root' in check:changed; previously test/ paths ran
lint only, so harness type errors surfaced first in CI (#104287 envDir case)
- burn down all 1071 latent type errors in the program: precise param/local
types across test/scripts, test/vitest, test/e2e, and transitive scripts/e2e
program members; 205 sibling .d.mts declaration files for imported .mjs
modules (committed separately); zero any, zero ts-expect-error
- resolve the pre-existing testing star-export ambiguity in
scripts/e2e/parallels/common.ts with an explicit re-export
Closes #104388
* chore(types): correct declaration fidelity per structured review
- re-derive 51 .d.mts files from implementation data flow instead of
initializers: fix a wrong never return (runTestProjectsDelegation returns
the child), add encoding-sensitive exec/spawn overloads (plain-gh), restore
the full release profile union, make parsed paths string | null, add missing
parseArgs fields via help/non-help unions, add a missing sibling declaration
(budget-number-args), drop 15 unused lint directives
- precise install-record/tuple typing removes the type-aware oxlint
regressions the first declarations caused in scripts/e2e implementations
- route .mts declaration edits under test/ to the testRoot lane and reference
the test-root project from tsconfig.projects.json so tsgo:all covers it
(closes both review findings against the lane wiring)
* chore(scripts): keep telegram runner dist typing structural for the boundary guard
* chore(types): declare runtime pack and gateway readiness exports added on main
* test: pin the importTargetPlan form of the plugin-contract plan import
The guard expectation still referenced the raw await import( form that
7ae5996bb3 (#103975) replaced with the importTargetPlan fallback helper;
the assertion fails on current main.
174 lines
5.9 KiB
TypeScript
174 lines
5.9 KiB
TypeScript
// Zai Fallback Repro tests cover zai fallback repro script behavior.
|
|
import fs from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import {
|
|
appendBoundedReproOutput,
|
|
outputContainsStandaloneToolOk,
|
|
runZaiFallbackRepro,
|
|
resolveZaiFallbackPnpmCommand,
|
|
sessionTranscriptHasToolResult,
|
|
} from "../../scripts/zai-fallback-repro.ts";
|
|
|
|
describe("zai fallback repro command resolution", () => {
|
|
it("wraps Windows pnpm.cmd without Node shell argv", () => {
|
|
expect(
|
|
resolveZaiFallbackPnpmCommand(["openclaw", "agent", "--message", "hello world"], {
|
|
comSpec: String.raw`C:\Windows\System32\cmd.exe`,
|
|
npmExecPath: String.raw`C:\Program Files\nodejs\pnpm.cmd`,
|
|
platform: "win32",
|
|
}),
|
|
).toEqual({
|
|
args: [
|
|
"/d",
|
|
"/s",
|
|
"/c",
|
|
String.raw`""C:\Program Files\nodejs\pnpm.cmd" openclaw agent --message "hello world""`,
|
|
],
|
|
command: String.raw`C:\Windows\System32\cmd.exe`,
|
|
shell: false,
|
|
windowsVerbatimArguments: true,
|
|
});
|
|
});
|
|
|
|
it("keeps only a bounded child output tail", () => {
|
|
const first = appendBoundedReproOutput({ text: "", truncatedChars: 0 }, "abcdef", 5);
|
|
const second = appendBoundedReproOutput(first, "ghij", 5);
|
|
|
|
expect(first).toEqual({ text: "bcdef", truncatedChars: 1 });
|
|
expect(second).toEqual({ text: "fghij", truncatedChars: 5 });
|
|
});
|
|
|
|
it("scans session transcripts with a byte cap", async () => {
|
|
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-zai-session-test-"));
|
|
try {
|
|
const sessionFile = path.join(root, "session.jsonl");
|
|
await fs.writeFile(
|
|
sessionFile,
|
|
`${"x".repeat(70_000)}\n{"event":"message","toolResult":true}\n`,
|
|
"utf8",
|
|
);
|
|
|
|
await expect(sessionTranscriptHasToolResult(sessionFile)).resolves.toBe(true);
|
|
await expect(sessionTranscriptHasToolResult(sessionFile, 1024)).resolves.toBe(false);
|
|
await expect(sessionTranscriptHasToolResult(path.join(root, "missing.jsonl"))).resolves.toBe(
|
|
false,
|
|
);
|
|
} finally {
|
|
await fs.rm(root, { force: true, recursive: true });
|
|
}
|
|
});
|
|
|
|
it("requires tool-ok as a standalone output line", () => {
|
|
expect(outputContainsStandaloneToolOk("before\ntool-ok\nafter\n")).toBe(true);
|
|
expect(outputContainsStandaloneToolOk("before tool-ok after\n")).toBe(false);
|
|
expect(outputContainsStandaloneToolOk("tool-okay\n")).toBe(false);
|
|
});
|
|
|
|
it("cleans temporary repro state after fallback proof", async () => {
|
|
const tempRoots: string[] = [];
|
|
const calls: string[] = [];
|
|
|
|
const exitCode = await runZaiFallbackRepro({
|
|
env: {
|
|
ANTHROPIC_API_KEY: "anthropic-test-key",
|
|
OPENCLAW_ZAI_FALLBACK_SESSION_ID: "session-test",
|
|
PATH: process.env.PATH,
|
|
ZAI_API_KEY: "zai-test-key",
|
|
},
|
|
error: () => {},
|
|
log: () => {},
|
|
mkdtemp: (async () => {
|
|
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-zai-fallback-test-"));
|
|
tempRoots.push(root);
|
|
return root;
|
|
}) as unknown as typeof fs.mkdtemp,
|
|
randomUUID: (() => "uuid-test") as unknown as NonNullable<
|
|
NonNullable<Parameters<typeof runZaiFallbackRepro>[0]>["randomUUID"]
|
|
>,
|
|
runCommand: async (label, _args, env) => {
|
|
calls.push(label);
|
|
if (label === "run1") {
|
|
const sessionFile = path.join(
|
|
String(env.OPENCLAW_STATE_DIR),
|
|
"agents",
|
|
"main",
|
|
"sessions",
|
|
"session-test.jsonl",
|
|
);
|
|
await fs.mkdir(path.dirname(sessionFile), { recursive: true });
|
|
await fs.writeFile(sessionFile, '{"toolResult":true}\n', "utf8");
|
|
}
|
|
return {
|
|
code: 0,
|
|
signal: null,
|
|
stderr: "",
|
|
stdout: label === "run2" ? "tool-ok\n" : "",
|
|
};
|
|
},
|
|
});
|
|
|
|
expect(exitCode).toBe(0);
|
|
expect(calls).toEqual(["run1", "run2"]);
|
|
expect(tempRoots).toHaveLength(1);
|
|
await expect(fs.stat(tempRoots[0])).rejects.toMatchObject({ code: "ENOENT" });
|
|
});
|
|
|
|
it("fails when run 1 does not leave tool result evidence", async () => {
|
|
const calls: string[] = [];
|
|
const errors: string[] = [];
|
|
|
|
const exitCode = await runZaiFallbackRepro({
|
|
env: {
|
|
ANTHROPIC_API_KEY: "anthropic-test-key",
|
|
OPENCLAW_ZAI_FALLBACK_SESSION_ID: "session-test",
|
|
PATH: process.env.PATH,
|
|
ZAI_API_KEY: "zai-test-key",
|
|
},
|
|
error: (message) => errors.push(message),
|
|
log: () => {},
|
|
runCommand: async (label) => {
|
|
calls.push(label);
|
|
return { code: 0, signal: null, stderr: "", stdout: "" };
|
|
},
|
|
});
|
|
|
|
expect(exitCode).toBe(1);
|
|
expect(calls).toEqual(["run1"]);
|
|
expect(errors).toContain("FAIL: no toolResult entries detected in session history.");
|
|
});
|
|
|
|
it("fails when fallback exits zero without returning tool-ok", async () => {
|
|
const errors: string[] = [];
|
|
|
|
const exitCode = await runZaiFallbackRepro({
|
|
env: {
|
|
ANTHROPIC_API_KEY: "anthropic-test-key",
|
|
OPENCLAW_ZAI_FALLBACK_SESSION_ID: "session-test",
|
|
PATH: process.env.PATH,
|
|
ZAI_API_KEY: "zai-test-key",
|
|
},
|
|
error: (message) => errors.push(message),
|
|
log: () => {},
|
|
runCommand: async (label, _args, env) => {
|
|
if (label === "run1") {
|
|
const sessionFile = path.join(
|
|
String(env.OPENCLAW_STATE_DIR),
|
|
"agents",
|
|
"main",
|
|
"sessions",
|
|
"session-test.jsonl",
|
|
);
|
|
await fs.mkdir(path.dirname(sessionFile), { recursive: true });
|
|
await fs.writeFile(sessionFile, '{"toolResult":true}\n', "utf8");
|
|
}
|
|
return { code: 0, signal: null, stderr: "", stdout: "not-it\n" };
|
|
},
|
|
});
|
|
|
|
expect(exitCode).toBe(1);
|
|
expect(errors).toContain("FAIL: fallback run did not return standalone tool-ok.");
|
|
});
|
|
});
|