mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-22 18:35:21 -06:00
d115fb4cf9
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
248 lines
7.1 KiB
TypeScript
248 lines
7.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
resolveCliStartupPolicy,
|
|
shouldBypassConfigGuardForCommandPath,
|
|
shouldEnsureCliPathForCommandPath,
|
|
shouldHideCliBannerForCommandPath,
|
|
shouldLoadPluginsForCommandPath,
|
|
shouldSkipRouteConfigGuardForCommandPath,
|
|
} from "./command-startup-policy.js";
|
|
|
|
describe("command-startup-policy", () => {
|
|
it("matches config guard bypass commands", () => {
|
|
expect(shouldBypassConfigGuardForCommandPath(["backup", "create"])).toBe(true);
|
|
expect(shouldBypassConfigGuardForCommandPath(["config"])).toBe(true);
|
|
expect(shouldBypassConfigGuardForCommandPath(["config", "validate"])).toBe(true);
|
|
expect(shouldBypassConfigGuardForCommandPath(["config", "schema"])).toBe(true);
|
|
expect(shouldBypassConfigGuardForCommandPath(["config", "set"])).toBe(false);
|
|
expect(shouldBypassConfigGuardForCommandPath(["status"])).toBe(false);
|
|
});
|
|
|
|
it("matches route-first config guard skip policy", () => {
|
|
expect(
|
|
shouldSkipRouteConfigGuardForCommandPath({
|
|
commandPath: ["status"],
|
|
suppressDoctorStdout: true,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldSkipRouteConfigGuardForCommandPath({
|
|
commandPath: ["gateway", "status"],
|
|
suppressDoctorStdout: false,
|
|
}),
|
|
).toBe(true);
|
|
expect(
|
|
shouldSkipRouteConfigGuardForCommandPath({
|
|
commandPath: ["status"],
|
|
suppressDoctorStdout: false,
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("matches plugin preload policy", () => {
|
|
expect(
|
|
shouldLoadPluginsForCommandPath({
|
|
commandPath: ["status"],
|
|
jsonOutputMode: false,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldLoadPluginsForCommandPath({
|
|
commandPath: ["status"],
|
|
jsonOutputMode: true,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldLoadPluginsForCommandPath({
|
|
commandPath: ["health"],
|
|
jsonOutputMode: false,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldLoadPluginsForCommandPath({
|
|
commandPath: ["channels", "status"],
|
|
jsonOutputMode: false,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldLoadPluginsForCommandPath({
|
|
commandPath: ["channels", "list"],
|
|
jsonOutputMode: false,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldLoadPluginsForCommandPath({
|
|
commandPath: ["channels", "add"],
|
|
jsonOutputMode: false,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldLoadPluginsForCommandPath({
|
|
commandPath: ["channels", "logs"],
|
|
jsonOutputMode: false,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldLoadPluginsForCommandPath({
|
|
commandPath: ["message", "send"],
|
|
jsonOutputMode: false,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldLoadPluginsForCommandPath({
|
|
commandPath: ["message", "send"],
|
|
jsonOutputMode: true,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldLoadPluginsForCommandPath({
|
|
argv: ["node", "openclaw", "agent", "--json"],
|
|
commandPath: ["agent"],
|
|
jsonOutputMode: true,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldLoadPluginsForCommandPath({
|
|
argv: ["node", "openclaw", "agent", "--json", "--local"],
|
|
commandPath: ["agent"],
|
|
jsonOutputMode: true,
|
|
}),
|
|
).toBe(true);
|
|
expect(
|
|
shouldLoadPluginsForCommandPath({
|
|
argv: ["node", "openclaw", "agent"],
|
|
commandPath: ["agent"],
|
|
jsonOutputMode: false,
|
|
}),
|
|
).toBe(true);
|
|
expect(
|
|
shouldLoadPluginsForCommandPath({
|
|
commandPath: ["agents"],
|
|
jsonOutputMode: false,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldLoadPluginsForCommandPath({
|
|
commandPath: ["agents", "list"],
|
|
jsonOutputMode: false,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldLoadPluginsForCommandPath({
|
|
commandPath: ["agents", "list"],
|
|
jsonOutputMode: true,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldLoadPluginsForCommandPath({
|
|
commandPath: ["agents", "bind"],
|
|
jsonOutputMode: false,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldLoadPluginsForCommandPath({
|
|
commandPath: ["agents", "bindings"],
|
|
jsonOutputMode: true,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldLoadPluginsForCommandPath({
|
|
commandPath: ["agents", "unbind"],
|
|
jsonOutputMode: false,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldLoadPluginsForCommandPath({
|
|
commandPath: ["agents", "set-identity"],
|
|
jsonOutputMode: false,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldLoadPluginsForCommandPath({
|
|
commandPath: ["agents", "delete"],
|
|
jsonOutputMode: true,
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("matches banner suppression policy", () => {
|
|
expect(shouldHideCliBannerForCommandPath(["update", "status"])).toBe(true);
|
|
expect(shouldHideCliBannerForCommandPath(["completion"])).toBe(true);
|
|
expect(
|
|
shouldHideCliBannerForCommandPath(["status"], {
|
|
...process.env,
|
|
OPENCLAW_HIDE_BANNER: "1",
|
|
}),
|
|
).toBe(true);
|
|
expect(shouldHideCliBannerForCommandPath(["status"], {})).toBe(false);
|
|
});
|
|
|
|
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(
|
|
resolveCliStartupPolicy({
|
|
commandPath: ["status"],
|
|
jsonOutputMode: false,
|
|
}).hideBanner,
|
|
).toBe(true);
|
|
expect(
|
|
resolveCliStartupPolicy({
|
|
commandPath: ["status"],
|
|
jsonOutputMode: false,
|
|
env: {},
|
|
}).hideBanner,
|
|
).toBe(false);
|
|
} finally {
|
|
if (originalHideBanner === undefined) {
|
|
delete process.env.OPENCLAW_HIDE_BANNER;
|
|
} else {
|
|
process.env.OPENCLAW_HIDE_BANNER = originalHideBanner;
|
|
}
|
|
}
|
|
});
|
|
|
|
it("matches CLI PATH bootstrap policy", () => {
|
|
expect(shouldEnsureCliPathForCommandPath(["status"])).toBe(false);
|
|
expect(shouldEnsureCliPathForCommandPath(["sessions"])).toBe(false);
|
|
expect(shouldEnsureCliPathForCommandPath(["config", "get"])).toBe(false);
|
|
expect(shouldEnsureCliPathForCommandPath(["models", "status"])).toBe(false);
|
|
expect(shouldEnsureCliPathForCommandPath(["tools", "effective"])).toBe(false);
|
|
expect(shouldEnsureCliPathForCommandPath(["message", "send"])).toBe(true);
|
|
expect(shouldEnsureCliPathForCommandPath([])).toBe(true);
|
|
});
|
|
|
|
it("aggregates startup policy for commander and route-first callers", () => {
|
|
expect(
|
|
resolveCliStartupPolicy({
|
|
commandPath: ["status"],
|
|
jsonOutputMode: true,
|
|
env: {},
|
|
}),
|
|
).toEqual({
|
|
suppressDoctorStdout: true,
|
|
hideBanner: false,
|
|
skipConfigGuard: false,
|
|
loadPlugins: false,
|
|
pluginRegistry: { scope: "channels" },
|
|
});
|
|
|
|
expect(
|
|
resolveCliStartupPolicy({
|
|
commandPath: ["status"],
|
|
jsonOutputMode: true,
|
|
env: {},
|
|
routeMode: true,
|
|
}),
|
|
).toEqual({
|
|
suppressDoctorStdout: true,
|
|
hideBanner: false,
|
|
skipConfigGuard: false,
|
|
loadPlugins: false,
|
|
pluginRegistry: { scope: "channels" },
|
|
});
|
|
});
|
|
});
|