mirror of
https://github.com/hanzoai/bot.git
synced 2026-10-30 17:24:26 +00:00
Three coordinated things:
1. Resolve the committed upstream/main merge conflicts. 94 files were
sitting with raw <<<<<<< HEAD ... >>>>>>> upstream/main blocks. Every
conflict had HanzoBot/Bot on HEAD and OpenClaw on upstream. Resolved
by keeping HEAD everywhere — 540 conflict blocks.
2. Rewrite remaining OpenClaw text refs.
OPENCLAW → HANZO_BOT
OpenClaw → HanzoBot (PascalCase type identifiers)
openclaw → bot (codebase convention — botToken,
botUsername etc.; avoids invalid
hyphenated JS identifiers)
openclaw[_]/openclaw[A-Z] → bot[_]/bot[A-Z] (compound)
ai.openclaw.x → ai.hanzo.bot.x (JVM package path)
3. Delete or rename openclaw-named file paths (116 of them). Dead
duplicates with a Bot-named canonical from the partial migration:
deleted. Otherwise renamed.
ai/openclaw/** → deleted (ai/hanzo/bot/** canonical)
Sources/OpenClaw*/ → deleted (Sources/Bot* canonical)
Tests/OpenClawIPCTests/ → deleted (Tests/BotIPCTests canonical)
OpenClawKit/ → deleted (BotKit canonical)
openclaw-tools.*.ts → deleted (bot-tools.*.ts canonical)
openclaw-root.ts etc. → deleted (bot-root.ts canonical)
types.openclaw.ts → deleted (types.bot.ts canonical)
extensions/*/openclaw.plugin.json → renamed hanzo-bot.plugin.json
docs/start/openclaw.md → renamed hanzo-bot.md (+ zh-CN)
docs/assets/openclaw-*.png, whatsapp-openclaw*.jpg → deleted
scripts/.../openclaw-* → deleted (bot/hanzo-bot parallels)
openclaw.mjs → deleted (hanzo-bot.mjs is package.bin)
Then patched 65 broken JS/TS import strings where hanzo-bot had ended
up inside an import path ('./types.hanzo-bot.js' → './types.bot.js'
etc., since the on-disk filename uses the brand-neutral bot- prefix).
Pre-existing lint debt cleaned up to get oxlint --type-aware to 0/0:
removed the dead i18n test that referenced a path no longer existing;
defined the missing DIDConfig and WalletConfig types in types.base.ts
(they were imported but never declared); dropped unused imports;
collapsed redundant type assertion and a tautological meta.bot lookup
that the openclaw→bot rename made redundant.
The a2ui.bundle.js generated artifact is kept at its pre-rebrand
contents — it gets regenerated by 'pnpm canvas:a2ui:bundle' from
sources I cannot rebuild in this commit; the source side is clean.
Verified: 0 occurrences of openclaw (case-insensitive) in tree source
content, 0 file or directory paths with openclaw in the name; oxlint
--type-aware src test reports 0/0.
318 lines
8.6 KiB
TypeScript
318 lines
8.6 KiB
TypeScript
import fs from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import type { BotConfig } from "../config/config.js";
|
|
import { runCliAgent } from "./cli-runner.js";
|
|
import { resolveCliNoOutputTimeoutMs } from "./cli-runner/helpers.js";
|
|
|
|
const supervisorSpawnMock = vi.fn();
|
|
const enqueueSystemEventMock = vi.fn();
|
|
const requestHeartbeatNowMock = vi.fn();
|
|
|
|
vi.mock("../process/supervisor/index.js", () => ({
|
|
getProcessSupervisor: () => ({
|
|
spawn: (...args: unknown[]) => supervisorSpawnMock(...args),
|
|
cancel: vi.fn(),
|
|
cancelScope: vi.fn(),
|
|
reconcileOrphans: vi.fn(),
|
|
getRecord: vi.fn(),
|
|
}),
|
|
}));
|
|
|
|
vi.mock("../infra/system-events.js", () => ({
|
|
enqueueSystemEvent: (...args: unknown[]) => enqueueSystemEventMock(...args),
|
|
}));
|
|
|
|
vi.mock("../infra/heartbeat-wake.js", () => ({
|
|
requestHeartbeatNow: (...args: unknown[]) => requestHeartbeatNowMock(...args),
|
|
}));
|
|
|
|
type MockRunExit = {
|
|
reason:
|
|
| "manual-cancel"
|
|
| "overall-timeout"
|
|
| "no-output-timeout"
|
|
| "spawn-error"
|
|
| "signal"
|
|
| "exit";
|
|
exitCode: number | null;
|
|
exitSignal: NodeJS.Signals | number | null;
|
|
durationMs: number;
|
|
stdout: string;
|
|
stderr: string;
|
|
timedOut: boolean;
|
|
noOutputTimedOut: boolean;
|
|
};
|
|
|
|
function createManagedRun(exit: MockRunExit, pid = 1234) {
|
|
return {
|
|
runId: "run-supervisor",
|
|
pid,
|
|
startedAtMs: Date.now(),
|
|
stdin: undefined,
|
|
wait: vi.fn().mockResolvedValue(exit),
|
|
cancel: vi.fn(),
|
|
};
|
|
}
|
|
|
|
describe("runCliAgent with process supervisor", () => {
|
|
beforeEach(() => {
|
|
supervisorSpawnMock.mockClear();
|
|
enqueueSystemEventMock.mockClear();
|
|
requestHeartbeatNowMock.mockClear();
|
|
});
|
|
|
|
it("runs CLI through supervisor and returns payload", async () => {
|
|
supervisorSpawnMock.mockResolvedValueOnce(
|
|
createManagedRun({
|
|
reason: "exit",
|
|
exitCode: 0,
|
|
exitSignal: null,
|
|
durationMs: 50,
|
|
stdout: "ok",
|
|
stderr: "",
|
|
timedOut: false,
|
|
noOutputTimedOut: false,
|
|
}),
|
|
);
|
|
|
|
const result = await runCliAgent({
|
|
sessionId: "s1",
|
|
sessionFile: "/tmp/session.jsonl",
|
|
workspaceDir: "/tmp",
|
|
prompt: "hi",
|
|
provider: "codex-cli",
|
|
model: "gpt-5.2-codex",
|
|
timeoutMs: 1_000,
|
|
runId: "run-1",
|
|
cliSessionId: "thread-123",
|
|
});
|
|
|
|
expect(result.payloads?.[0]?.text).toBe("ok");
|
|
expect(supervisorSpawnMock).toHaveBeenCalledTimes(1);
|
|
const input = supervisorSpawnMock.mock.calls[0]?.[0] as {
|
|
argv?: string[];
|
|
mode?: string;
|
|
timeoutMs?: number;
|
|
noOutputTimeoutMs?: number;
|
|
replaceExistingScope?: boolean;
|
|
scopeKey?: string;
|
|
};
|
|
expect(input.mode).toBe("child");
|
|
expect(input.argv?.[0]).toBe("codex");
|
|
expect(input.timeoutMs).toBe(1_000);
|
|
expect(input.noOutputTimeoutMs).toBeGreaterThanOrEqual(1_000);
|
|
expect(input.replaceExistingScope).toBe(true);
|
|
expect(input.scopeKey).toContain("thread-123");
|
|
});
|
|
|
|
it("fails with timeout when no-output watchdog trips", async () => {
|
|
supervisorSpawnMock.mockResolvedValueOnce(
|
|
createManagedRun({
|
|
reason: "no-output-timeout",
|
|
exitCode: null,
|
|
exitSignal: "SIGKILL",
|
|
durationMs: 200,
|
|
stdout: "",
|
|
stderr: "",
|
|
timedOut: true,
|
|
noOutputTimedOut: true,
|
|
}),
|
|
);
|
|
|
|
await expect(
|
|
runCliAgent({
|
|
sessionId: "s1",
|
|
sessionFile: "/tmp/session.jsonl",
|
|
workspaceDir: "/tmp",
|
|
prompt: "hi",
|
|
provider: "codex-cli",
|
|
model: "gpt-5.2-codex",
|
|
timeoutMs: 1_000,
|
|
runId: "run-2",
|
|
cliSessionId: "thread-123",
|
|
}),
|
|
).rejects.toThrow("produced no output");
|
|
});
|
|
|
|
it("enqueues a system event and heartbeat wake on no-output watchdog timeout for session runs", async () => {
|
|
supervisorSpawnMock.mockResolvedValueOnce(
|
|
createManagedRun({
|
|
reason: "no-output-timeout",
|
|
exitCode: null,
|
|
exitSignal: "SIGKILL",
|
|
durationMs: 200,
|
|
stdout: "",
|
|
stderr: "",
|
|
timedOut: true,
|
|
noOutputTimedOut: true,
|
|
}),
|
|
);
|
|
|
|
await expect(
|
|
runCliAgent({
|
|
sessionId: "s1",
|
|
sessionKey: "agent:main:main",
|
|
sessionFile: "/tmp/session.jsonl",
|
|
workspaceDir: "/tmp",
|
|
prompt: "hi",
|
|
provider: "codex-cli",
|
|
model: "gpt-5.2-codex",
|
|
timeoutMs: 1_000,
|
|
runId: "run-2b",
|
|
cliSessionId: "thread-123",
|
|
}),
|
|
).rejects.toThrow("produced no output");
|
|
|
|
expect(enqueueSystemEventMock).toHaveBeenCalledTimes(1);
|
|
const [notice, opts] = enqueueSystemEventMock.mock.calls[0] ?? [];
|
|
expect(String(notice)).toContain("produced no output");
|
|
expect(String(notice)).toContain("interactive input or an approval prompt");
|
|
expect(opts).toMatchObject({ sessionKey: "agent:main:main" });
|
|
expect(requestHeartbeatNowMock).toHaveBeenCalledWith({
|
|
reason: "cli:watchdog:stall",
|
|
sessionKey: "agent:main:main",
|
|
});
|
|
});
|
|
|
|
it("fails with timeout when overall timeout trips", async () => {
|
|
supervisorSpawnMock.mockResolvedValueOnce(
|
|
createManagedRun({
|
|
reason: "overall-timeout",
|
|
exitCode: null,
|
|
exitSignal: "SIGKILL",
|
|
durationMs: 200,
|
|
stdout: "",
|
|
stderr: "",
|
|
timedOut: true,
|
|
noOutputTimedOut: false,
|
|
}),
|
|
);
|
|
|
|
await expect(
|
|
runCliAgent({
|
|
sessionId: "s1",
|
|
sessionFile: "/tmp/session.jsonl",
|
|
workspaceDir: "/tmp",
|
|
prompt: "hi",
|
|
provider: "codex-cli",
|
|
model: "gpt-5.2-codex",
|
|
timeoutMs: 1_000,
|
|
runId: "run-3",
|
|
cliSessionId: "thread-123",
|
|
}),
|
|
).rejects.toThrow("exceeded timeout");
|
|
});
|
|
|
|
it("rethrows the retry failure when session-expired recovery retry also fails", async () => {
|
|
supervisorSpawnMock.mockResolvedValueOnce(
|
|
createManagedRun({
|
|
reason: "exit",
|
|
exitCode: 1,
|
|
exitSignal: null,
|
|
durationMs: 150,
|
|
stdout: "",
|
|
stderr: "session expired",
|
|
timedOut: false,
|
|
noOutputTimedOut: false,
|
|
}),
|
|
);
|
|
supervisorSpawnMock.mockResolvedValueOnce(
|
|
createManagedRun({
|
|
reason: "exit",
|
|
exitCode: 1,
|
|
exitSignal: null,
|
|
durationMs: 150,
|
|
stdout: "",
|
|
stderr: "rate limit exceeded",
|
|
timedOut: false,
|
|
noOutputTimedOut: false,
|
|
}),
|
|
);
|
|
|
|
await expect(
|
|
runCliAgent({
|
|
sessionId: "s1",
|
|
sessionKey: "agent:main:subagent:retry",
|
|
sessionFile: "/tmp/session.jsonl",
|
|
workspaceDir: "/tmp",
|
|
prompt: "hi",
|
|
provider: "codex-cli",
|
|
model: "gpt-5.2-codex",
|
|
timeoutMs: 1_000,
|
|
runId: "run-retry-failure",
|
|
cliSessionId: "thread-123",
|
|
}),
|
|
).rejects.toThrow("rate limit exceeded");
|
|
|
|
expect(supervisorSpawnMock).toHaveBeenCalledTimes(2);
|
|
});
|
|
|
|
it("falls back to per-agent workspace when workspaceDir is missing", async () => {
|
|
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "bot-cli-runner-"));
|
|
const fallbackWorkspace = path.join(tempDir, "workspace-main");
|
|
await fs.mkdir(fallbackWorkspace, { recursive: true });
|
|
const cfg = {
|
|
agents: {
|
|
defaults: {
|
|
workspace: fallbackWorkspace,
|
|
},
|
|
},
|
|
} satisfies BotConfig;
|
|
|
|
supervisorSpawnMock.mockResolvedValueOnce(
|
|
createManagedRun({
|
|
reason: "exit",
|
|
exitCode: 0,
|
|
exitSignal: null,
|
|
durationMs: 25,
|
|
stdout: "ok",
|
|
stderr: "",
|
|
timedOut: false,
|
|
noOutputTimedOut: false,
|
|
}),
|
|
);
|
|
|
|
try {
|
|
await runCliAgent({
|
|
sessionId: "s1",
|
|
sessionKey: "agent:main:subagent:missing-workspace",
|
|
sessionFile: "/tmp/session.jsonl",
|
|
workspaceDir: undefined as unknown as string,
|
|
config: cfg,
|
|
prompt: "hi",
|
|
provider: "codex-cli",
|
|
model: "gpt-5.2-codex",
|
|
timeoutMs: 1_000,
|
|
runId: "run-4",
|
|
});
|
|
} finally {
|
|
await fs.rm(tempDir, { recursive: true, force: true });
|
|
}
|
|
|
|
const input = supervisorSpawnMock.mock.calls[0]?.[0] as { cwd?: string };
|
|
expect(input.cwd).toBe(path.resolve(fallbackWorkspace));
|
|
});
|
|
});
|
|
|
|
describe("resolveCliNoOutputTimeoutMs", () => {
|
|
it("uses backend-configured resume watchdog override", () => {
|
|
const timeoutMs = resolveCliNoOutputTimeoutMs({
|
|
backend: {
|
|
command: "codex",
|
|
reliability: {
|
|
watchdog: {
|
|
resume: {
|
|
noOutputTimeoutMs: 42_000,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
timeoutMs: 120_000,
|
|
useResume: true,
|
|
});
|
|
expect(timeoutMs).toBe(42_000);
|
|
});
|
|
});
|