mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-16 01:40:43 +00:00
Summary: - Merged fix: simplify bundled runtime dependency repair after ClawSweeper review. ClawSweeper fixups: - Included follow-up commit: fix: verify cached bundled runtime roots - Included follow-up commit: refactor: simplify plugin runtime startup paths - Included follow-up commit: refactor: trim plugin startup policy helpers - Included follow-up commit: refactor: trust package manager runtime deps materialization - Included follow-up commit: fix: narrow channel runtime deps skip policy - Included follow-up commit: refactor: defer startup plugin runtime deps - Ran the ClawSweeper repair loop before final review. Validation: - ClawSweeper review passed for head04dc566534. - Required merge gates passed before the squash merge. Prepared head SHA:04dc566534Review: https://github.com/openclaw/openclaw/pull/75183#issuecomment-4358383786 Co-authored-by: Peter Steinberger <steipete@gmail.com> Co-authored-by: Shakker <shakkerdroid@gmail.com> Co-authored-by: clawsweeper-repair <clawsweeper-repair@users.noreply.github.com>
246 lines
7.0 KiB
TypeScript
246 lines
7.0 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", "validate"])).toBe(true);
|
|
expect(shouldBypassConfigGuardForCommandPath(["config", "schema"])).toBe(true);
|
|
expect(shouldBypassConfigGuardForCommandPath(["status"])).toBe(false);
|
|
});
|
|
|
|
it("matches route-first config guard skip policy", () => {
|
|
expect(
|
|
shouldSkipRouteConfigGuardForCommandPath({
|
|
commandPath: ["status"],
|
|
suppressDoctorStdout: true,
|
|
}),
|
|
).toBe(true);
|
|
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", installBundledRuntimeDeps: false },
|
|
});
|
|
|
|
expect(
|
|
resolveCliStartupPolicy({
|
|
commandPath: ["status"],
|
|
jsonOutputMode: true,
|
|
env: {},
|
|
routeMode: true,
|
|
}),
|
|
).toEqual({
|
|
suppressDoctorStdout: true,
|
|
hideBanner: false,
|
|
skipConfigGuard: true,
|
|
loadPlugins: false,
|
|
pluginRegistry: { scope: "channels", installBundledRuntimeDeps: false },
|
|
});
|
|
});
|
|
});
|