mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-05 10:22:53 +00:00
Move task run, delivery, and flow registry persistence onto the shared OpenClaw state SQLite database.
Summary:
- Store task runs, delivery state, and flow runs in state/openclaw.sqlite via the generated Kysely schema.
- Migrate shipped task sidecars into the shared state DB and archive old sidecars, including invalid-config/read-only CLI paths.
- Keep startup migration lightweight for read-only status/tasks paths while still detecting known legacy state markers and custom session stores.
Verification:
- .agents/skills/autoreview/scripts/autoreview --mode local: clean after final fix
- pnpm test src/tasks/task-registry.store.test.ts src/tasks/task-flow-registry.store.test.ts src/commands/doctor-state-migrations.test.ts -- --reporter=verbose
- pnpm test src/commands/doctor-state-migrations.test.ts src/cli/program/config-guard.test.ts src/cli/route.test.ts src/cli/command-path-policy.test.ts -- --reporter=verbose
- pnpm test src/cli/program/config-guard.test.ts src/cli/route.test.ts src/cli/command-startup-policy.test.ts src/cli/command-path-policy.test.ts src/cli/command-execution-startup.test.ts -- --reporter=verbose
- pnpm test src/cli/program/config-guard.test.ts src/cli/argv.test.ts src/cli/route.test.ts src/commands/doctor-config-preflight.state-migration.test.ts -- --reporter=verbose
- pnpm test src/tasks/task-flow-registry.store.test.ts -- --reporter=verbose
- pnpm test test/scripts/lint-suppressions.test.ts -- --reporter=verbose
- pnpm db:kysely:check
- pnpm lint:kysely
- git diff --check HEAD
- pnpm test:startup:memory
- PR CI green on 2f7d76f0d5
213 lines
6.0 KiB
TypeScript
213 lines
6.0 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const emitCliBannerMock = vi.hoisted(() => vi.fn());
|
|
const routeLogsToStderrMock = vi.hoisted(() => vi.fn());
|
|
const ensureCliCommandBootstrapMock = vi.hoisted(() => vi.fn(async () => {}));
|
|
|
|
vi.mock("./banner.js", () => ({
|
|
emitCliBanner: emitCliBannerMock,
|
|
}));
|
|
|
|
vi.mock("../logging/console.js", () => ({
|
|
routeLogsToStderr: routeLogsToStderrMock,
|
|
}));
|
|
|
|
vi.mock("./command-bootstrap.js", () => ({
|
|
ensureCliCommandBootstrap: ensureCliCommandBootstrapMock,
|
|
}));
|
|
|
|
describe("command-execution-startup", () => {
|
|
let mod: typeof import("./command-execution-startup.js");
|
|
|
|
beforeEach(async () => {
|
|
vi.clearAllMocks();
|
|
vi.resetModules();
|
|
mod = await import("./command-execution-startup.js");
|
|
});
|
|
|
|
it("resolves startup context from argv and mode", () => {
|
|
expect(
|
|
mod.resolveCliExecutionStartupContext({
|
|
argv: ["node", "openclaw", "status", "--json"],
|
|
jsonOutputMode: true,
|
|
env: {},
|
|
routeMode: true,
|
|
}),
|
|
).toEqual({
|
|
invocation: {
|
|
argv: ["node", "openclaw", "status", "--json"],
|
|
commandPath: ["status"],
|
|
primary: "status",
|
|
hasHelpOrVersion: false,
|
|
isRootHelpInvocation: false,
|
|
},
|
|
commandPath: ["status"],
|
|
startupPolicy: {
|
|
suppressDoctorStdout: true,
|
|
hideBanner: false,
|
|
skipConfigGuard: false,
|
|
loadPlugins: false,
|
|
pluginRegistry: { scope: "channels" },
|
|
},
|
|
});
|
|
});
|
|
|
|
it("uses process env banner suppression when startup env is omitted", () => {
|
|
const originalHideBanner = process.env.OPENCLAW_HIDE_BANNER;
|
|
try {
|
|
process.env.OPENCLAW_HIDE_BANNER = "1";
|
|
|
|
expect(
|
|
mod.resolveCliExecutionStartupContext({
|
|
argv: ["node", "openclaw", "status"],
|
|
jsonOutputMode: false,
|
|
}).startupPolicy.hideBanner,
|
|
).toBe(true);
|
|
expect(
|
|
mod.resolveCliExecutionStartupContext({
|
|
argv: ["node", "openclaw", "status"],
|
|
jsonOutputMode: false,
|
|
env: {},
|
|
}).startupPolicy.hideBanner,
|
|
).toBe(false);
|
|
} finally {
|
|
if (originalHideBanner === undefined) {
|
|
delete process.env.OPENCLAW_HIDE_BANNER;
|
|
} else {
|
|
process.env.OPENCLAW_HIDE_BANNER = originalHideBanner;
|
|
}
|
|
}
|
|
});
|
|
|
|
it("skips local plugin bootstrap for JSON gateway agent calls", () => {
|
|
expect(
|
|
mod.resolveCliExecutionStartupContext({
|
|
argv: ["node", "openclaw", "agent", "--agent", "main", "--message", "hi", "--json"],
|
|
jsonOutputMode: true,
|
|
}).startupPolicy.loadPlugins,
|
|
).toBe(false);
|
|
expect(
|
|
mod.resolveCliExecutionStartupContext({
|
|
argv: [
|
|
"node",
|
|
"openclaw",
|
|
"agent",
|
|
"--agent",
|
|
"main",
|
|
"--message",
|
|
"hi",
|
|
"--json",
|
|
"--local",
|
|
],
|
|
jsonOutputMode: true,
|
|
}).startupPolicy.loadPlugins,
|
|
).toBe(true);
|
|
expect(
|
|
mod.resolveCliExecutionStartupContext({
|
|
argv: ["node", "openclaw", "agent", "--agent", "main", "--message", "hi"],
|
|
jsonOutputMode: false,
|
|
}).startupPolicy.loadPlugins,
|
|
).toBe(true);
|
|
});
|
|
|
|
it("routes logs to stderr and emits banner only when allowed", async () => {
|
|
await mod.applyCliExecutionStartupPresentation({
|
|
startupPolicy: {
|
|
suppressDoctorStdout: true,
|
|
hideBanner: false,
|
|
skipConfigGuard: false,
|
|
loadPlugins: true,
|
|
pluginRegistry: { scope: "all" },
|
|
},
|
|
version: "1.2.3",
|
|
argv: ["node", "openclaw", "status"],
|
|
});
|
|
|
|
expect(routeLogsToStderrMock).toHaveBeenCalledTimes(1);
|
|
expect(emitCliBannerMock).toHaveBeenCalledWith("1.2.3", {
|
|
argv: ["node", "openclaw", "status"],
|
|
});
|
|
|
|
await mod.applyCliExecutionStartupPresentation({
|
|
startupPolicy: {
|
|
suppressDoctorStdout: false,
|
|
hideBanner: true,
|
|
skipConfigGuard: false,
|
|
loadPlugins: true,
|
|
pluginRegistry: { scope: "all" },
|
|
},
|
|
version: "1.2.3",
|
|
showBanner: true,
|
|
});
|
|
|
|
expect(emitCliBannerMock).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("does not import the banner module for JSON output", async () => {
|
|
await mod.applyCliExecutionStartupPresentation({
|
|
startupPolicy: {
|
|
suppressDoctorStdout: true,
|
|
hideBanner: false,
|
|
skipConfigGuard: false,
|
|
loadPlugins: false,
|
|
pluginRegistry: { scope: "channels" },
|
|
},
|
|
version: "1.2.3",
|
|
argv: ["node", "openclaw", "status", "--json"],
|
|
});
|
|
|
|
expect(routeLogsToStderrMock).toHaveBeenCalledTimes(1);
|
|
expect(emitCliBannerMock).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("forwards startup policy into bootstrap defaults and overrides", async () => {
|
|
const statusRuntime = {} as never;
|
|
await mod.ensureCliExecutionBootstrap({
|
|
runtime: statusRuntime,
|
|
commandPath: ["status"],
|
|
startupPolicy: {
|
|
suppressDoctorStdout: true,
|
|
hideBanner: false,
|
|
skipConfigGuard: false,
|
|
loadPlugins: false,
|
|
pluginRegistry: { scope: "channels" },
|
|
},
|
|
});
|
|
|
|
expect(ensureCliCommandBootstrapMock).toHaveBeenCalledWith({
|
|
runtime: statusRuntime,
|
|
commandPath: ["status"],
|
|
suppressDoctorStdout: true,
|
|
allowInvalid: undefined,
|
|
loadPlugins: false,
|
|
pluginRegistry: { scope: "channels" },
|
|
skipConfigGuard: false,
|
|
});
|
|
|
|
const messageRuntime = {} as never;
|
|
await mod.ensureCliExecutionBootstrap({
|
|
runtime: messageRuntime,
|
|
commandPath: ["message", "send"],
|
|
startupPolicy: {
|
|
suppressDoctorStdout: false,
|
|
hideBanner: false,
|
|
skipConfigGuard: false,
|
|
loadPlugins: false,
|
|
pluginRegistry: { scope: "all" },
|
|
},
|
|
allowInvalid: true,
|
|
loadPlugins: true,
|
|
});
|
|
|
|
expect(ensureCliCommandBootstrapMock).toHaveBeenLastCalledWith({
|
|
runtime: messageRuntime,
|
|
commandPath: ["message", "send"],
|
|
suppressDoctorStdout: false,
|
|
allowInvalid: true,
|
|
loadPlugins: true,
|
|
pluginRegistry: { scope: "all" },
|
|
skipConfigGuard: false,
|
|
});
|
|
});
|
|
});
|