mirror of https://github.com/openclaw/openclaw.git
test: trim stale legacy coverage and repair mocks
This commit is contained in:
parent
63e5c3349e
commit
d014f173f1
|
|
@ -57,10 +57,10 @@ describe("createOpenClawCodingTools", () => {
|
|||
}
|
||||
});
|
||||
it("filters tools by sandbox policy", () => {
|
||||
const sandboxDir = path.join(os.tmpdir(), "moltbot-sandbox");
|
||||
const sandboxDir = path.join(os.tmpdir(), "openclaw-sandbox");
|
||||
const sandbox = createPiToolsSandboxContext({
|
||||
workspaceDir: sandboxDir,
|
||||
agentWorkspaceDir: path.join(os.tmpdir(), "moltbot-workspace"),
|
||||
agentWorkspaceDir: path.join(os.tmpdir(), "openclaw-workspace"),
|
||||
workspaceAccess: "none" as const,
|
||||
fsBridge: createHostSandboxFsBridge(sandboxDir),
|
||||
tools: {
|
||||
|
|
@ -74,10 +74,10 @@ describe("createOpenClawCodingTools", () => {
|
|||
expect(tools.some((tool) => tool.name === "browser")).toBe(false);
|
||||
});
|
||||
it("hard-disables write/edit when sandbox workspaceAccess is ro", () => {
|
||||
const sandboxDir = path.join(os.tmpdir(), "moltbot-sandbox");
|
||||
const sandboxDir = path.join(os.tmpdir(), "openclaw-sandbox");
|
||||
const sandbox = createPiToolsSandboxContext({
|
||||
workspaceDir: sandboxDir,
|
||||
agentWorkspaceDir: path.join(os.tmpdir(), "moltbot-workspace"),
|
||||
agentWorkspaceDir: path.join(os.tmpdir(), "openclaw-workspace"),
|
||||
workspaceAccess: "ro" as const,
|
||||
fsBridge: createHostSandboxFsBridge(sandboxDir),
|
||||
tools: {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ function runWritePlan(args: string[], input?: string) {
|
|||
mkdir: args[4] === "1",
|
||||
});
|
||||
|
||||
return spawnSync("sh", ["-c", plan.script, "moltbot-sandbox-fs", ...(plan.args ?? [])], {
|
||||
return spawnSync("sh", ["-c", plan.script, "openclaw-sandbox-fs", ...(plan.args ?? [])], {
|
||||
input,
|
||||
encoding: "utf8",
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
|
|
|
|||
|
|
@ -103,12 +103,12 @@ export function dockerExecResult(stdout: string) {
|
|||
export function createSandbox(overrides?: Partial<SandboxContext>): SandboxContext {
|
||||
return createSandboxTestContext({
|
||||
overrides: {
|
||||
containerName: "moltbot-sbx-test",
|
||||
containerName: "openclaw-sbx-test",
|
||||
...overrides,
|
||||
},
|
||||
dockerOverrides: {
|
||||
image: "moltbot-sandbox:bookworm-slim",
|
||||
containerPrefix: "moltbot-sbx-",
|
||||
image: "openclaw-sandbox:bookworm-slim",
|
||||
containerPrefix: "openclaw-sbx-",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -272,7 +272,7 @@ describe("buildAgentSystemPrompt", () => {
|
|||
});
|
||||
|
||||
expect(prompt).toContain(
|
||||
'For requests like "do this in codex/claude code/gemini", treat it as ACP harness intent',
|
||||
'For requests like "do this in codex/claude code/cursor/gemini" or similar ACP harnesses, treat it as ACP harness intent',
|
||||
);
|
||||
expect(prompt).toContain(
|
||||
'On Discord, default ACP harness requests to thread-bound persistent sessions (`thread: true`, `mode: "session"`)',
|
||||
|
|
@ -414,10 +414,7 @@ describe("buildAgentSystemPrompt", () => {
|
|||
|
||||
// The system prompt intentionally does NOT include the current date/time.
|
||||
// Only the timezone is included, to keep the prompt stable for caching.
|
||||
// See: https://github.com/moltbot/moltbot/commit/66eec295b894bce8333886cfbca3b960c57c4946
|
||||
// Agents should use session_status or message timestamps to determine the date/time.
|
||||
// Related: https://github.com/moltbot/moltbot/issues/1897
|
||||
// https://github.com/moltbot/moltbot/issues/3658
|
||||
it("does NOT include a date or time in the system prompt (cache stability)", () => {
|
||||
const prompt = buildAgentSystemPrompt({
|
||||
workspaceDir: "/tmp/clawd",
|
||||
|
|
@ -427,10 +424,9 @@ describe("buildAgentSystemPrompt", () => {
|
|||
});
|
||||
|
||||
// The prompt should contain the timezone but NOT the formatted date/time string.
|
||||
// This is intentional for prompt cache stability — the date/time was removed in
|
||||
// commit 66eec295b. If you're here because you want to add it back, please see
|
||||
// https://github.com/moltbot/moltbot/issues/3658 for the preferred approach:
|
||||
// gateway-level timestamp injection into messages, not the system prompt.
|
||||
// This is intentional for prompt cache stability. If you want to add date/time
|
||||
// awareness, do it through gateway-level timestamp injection into messages, not
|
||||
// the system prompt.
|
||||
expect(prompt).toContain("Time zone: America/Chicago");
|
||||
expect(prompt).not.toContain("Monday, January 5th, 2026");
|
||||
expect(prompt).not.toContain("3:26 PM");
|
||||
|
|
|
|||
|
|
@ -27,4 +27,5 @@ vi.mock("../tools/web-tools.js", () => ({
|
|||
vi.mock("../../plugins/tools.js", () => ({
|
||||
resolvePluginTools: () => [],
|
||||
getPluginToolMeta: () => undefined,
|
||||
copyPluginToolMeta: (_source: unknown, target: unknown) => target,
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -44,9 +44,13 @@ vi.mock("../config/paths.js", () => ({
|
|||
resolveIsNixMode: mocks.resolveIsNixMode,
|
||||
}));
|
||||
|
||||
vi.mock("../config/config.js", () => ({
|
||||
writeConfigFile: mocks.writeConfigFile,
|
||||
}));
|
||||
vi.mock("../config/config.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../config/config.js")>("../config/config.js");
|
||||
return {
|
||||
...actual,
|
||||
writeConfigFile: mocks.writeConfigFile,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../daemon/inspect.js", () => ({
|
||||
findExtraGatewayServices: mocks.findExtraGatewayServices,
|
||||
|
|
@ -603,16 +607,16 @@ describe("maybeScanExtraGatewayServices", () => {
|
|||
mocks.findExtraGatewayServices.mockResolvedValue([
|
||||
{
|
||||
platform: "linux",
|
||||
label: "moltbot-gateway.service",
|
||||
detail: "unit: /home/test/.config/systemd/user/moltbot-gateway.service",
|
||||
label: "clawdbot-gateway.service",
|
||||
detail: "unit: /home/test/.config/systemd/user/clawdbot-gateway.service",
|
||||
scope: "user",
|
||||
legacy: true,
|
||||
},
|
||||
]);
|
||||
mocks.uninstallLegacySystemdUnits.mockResolvedValue([
|
||||
{
|
||||
name: "moltbot-gateway",
|
||||
unitPath: "/home/test/.config/systemd/user/moltbot-gateway.service",
|
||||
name: "clawdbot-gateway",
|
||||
unitPath: "/home/test/.config/systemd/user/clawdbot-gateway.service",
|
||||
enabled: true,
|
||||
exists: true,
|
||||
},
|
||||
|
|
@ -644,7 +648,7 @@ describe("maybeScanExtraGatewayServices", () => {
|
|||
stdout: process.stdout,
|
||||
});
|
||||
expect(mocks.note).toHaveBeenCalledWith(
|
||||
expect.stringContaining("moltbot-gateway.service"),
|
||||
expect.stringContaining("clawdbot-gateway.service"),
|
||||
"Legacy gateway removed",
|
||||
);
|
||||
expect(runtime.log).toHaveBeenCalledWith(
|
||||
|
|
|
|||
|
|
@ -144,13 +144,8 @@ describe("state + config path candidates", () => {
|
|||
const expected = [
|
||||
path.join(resolvedHome, ".openclaw", "openclaw.json"),
|
||||
path.join(resolvedHome, ".openclaw", "clawdbot.json"),
|
||||
path.join(resolvedHome, ".openclaw", "moldbot.json"),
|
||||
path.join(resolvedHome, ".clawdbot", "openclaw.json"),
|
||||
path.join(resolvedHome, ".clawdbot", "clawdbot.json"),
|
||||
path.join(resolvedHome, ".clawdbot", "moldbot.json"),
|
||||
path.join(resolvedHome, ".moldbot", "openclaw.json"),
|
||||
path.join(resolvedHome, ".moldbot", "clawdbot.json"),
|
||||
path.join(resolvedHome, ".moldbot", "moldbot.json"),
|
||||
];
|
||||
expect(candidates).toEqual(expected);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -133,6 +133,5 @@ describe("resolveGatewayServiceDescription", () => {
|
|||
describe("LEGACY_GATEWAY_SYSTEMD_SERVICE_NAMES", () => {
|
||||
it("includes known pre-rebrand gateway unit names", () => {
|
||||
expect(LEGACY_GATEWAY_SYSTEMD_SERVICE_NAMES).toContain("clawdbot-gateway");
|
||||
expect(LEGACY_GATEWAY_SYSTEMD_SERVICE_NAMES).toContain("moltbot-gateway");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -185,9 +185,6 @@ describe("findExtraGatewayServices (win32)", () => {
|
|||
"TaskName: Other Task",
|
||||
"Task To Run: C:\\tools\\helper.exe",
|
||||
"",
|
||||
"TaskName: MoltBot Legacy",
|
||||
"Task To Run: C:\\moltbot\\moltbot.exe run",
|
||||
"",
|
||||
].join("\n"),
|
||||
stderr: "",
|
||||
});
|
||||
|
|
@ -202,14 +199,6 @@ describe("findExtraGatewayServices (win32)", () => {
|
|||
marker: "clawdbot",
|
||||
legacy: true,
|
||||
},
|
||||
{
|
||||
platform: "win32",
|
||||
label: "MoltBot Legacy",
|
||||
detail: "task: MoltBot Legacy, run: C:\\moltbot\\moltbot.exe run",
|
||||
scope: "system",
|
||||
marker: "moltbot",
|
||||
legacy: true,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -25,10 +25,10 @@ afterEach(async () => {
|
|||
});
|
||||
|
||||
describe("legacy state dir auto-migration", () => {
|
||||
it("follows legacy symlink when it points at another legacy dir (clawdbot -> moldbot)", async () => {
|
||||
it("skips a legacy symlinked state dir when it points outside supported legacy roots", async () => {
|
||||
const root = await makeTempRoot();
|
||||
const legacySymlink = path.join(root, ".clawdbot");
|
||||
const legacyDir = path.join(root, ".moldbot");
|
||||
const legacyDir = path.join(root, "legacy-state-source");
|
||||
|
||||
fs.mkdirSync(legacyDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(legacyDir, "marker.txt"), "ok", "utf-8");
|
||||
|
|
@ -41,12 +41,13 @@ describe("legacy state dir auto-migration", () => {
|
|||
homedir: () => root,
|
||||
});
|
||||
|
||||
expect(result.migrated).toBe(true);
|
||||
expect(result.warnings).toEqual([]);
|
||||
|
||||
const targetMarker = path.join(root, ".openclaw", "marker.txt");
|
||||
expect(fs.readFileSync(targetMarker, "utf-8")).toBe("ok");
|
||||
expect(fs.readFileSync(path.join(root, ".moldbot", "marker.txt"), "utf-8")).toBe("ok");
|
||||
expect(result.migrated).toBe(false);
|
||||
expect(result.warnings).toEqual([
|
||||
`Legacy state dir is a symlink (${legacySymlink} → ${legacyDir}); skipping auto-migration.`,
|
||||
]);
|
||||
expect(fs.readFileSync(path.join(root, "legacy-state-source", "marker.txt"), "utf-8")).toBe(
|
||||
"ok",
|
||||
);
|
||||
expect(fs.readFileSync(path.join(root, ".clawdbot", "marker.txt"), "utf-8")).toBe("ok");
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ function createPluginSdkAliasFixture(params?: {
|
|||
distFile?: string;
|
||||
srcBody?: string;
|
||||
distBody?: string;
|
||||
packageName?: string;
|
||||
packageExports?: Record<string, unknown>;
|
||||
trustedRootIndicators?: boolean;
|
||||
trustedRootIndicatorMode?: "bin+marker" | "cli-entry-only" | "none";
|
||||
|
|
@ -67,7 +66,7 @@ function createPluginSdkAliasFixture(params?: {
|
|||
params?.trustedRootIndicatorMode ??
|
||||
(params?.trustedRootIndicators === false ? "none" : "bin+marker");
|
||||
const packageJson: Record<string, unknown> = {
|
||||
name: params?.packageName ?? "openclaw",
|
||||
name: "openclaw",
|
||||
type: "module",
|
||||
};
|
||||
if (trustedRootIndicatorMode === "bin+marker") {
|
||||
|
|
@ -469,39 +468,11 @@ describe("plugin sdk alias helpers", () => {
|
|||
expect(subpaths).toEqual(["compat", "telegram"]);
|
||||
});
|
||||
|
||||
it("derives plugin-sdk subpaths from nearest package exports even when package name is renamed", () => {
|
||||
const fixture = createPluginSdkAliasFixture({
|
||||
packageName: "moltbot",
|
||||
packageExports: {
|
||||
"./plugin-sdk/core": { default: "./dist/plugin-sdk/core.js" },
|
||||
"./plugin-sdk/channel-runtime": { default: "./dist/plugin-sdk/channel-runtime.js" },
|
||||
"./plugin-sdk/compat": { default: "./dist/plugin-sdk/compat.js" },
|
||||
},
|
||||
});
|
||||
const subpaths = listPluginSdkExportedSubpaths({
|
||||
modulePath: path.join(fixture.root, "src", "plugins", "loader.ts"),
|
||||
});
|
||||
expect(subpaths).toEqual(["channel-runtime", "compat", "core"]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
name: "derives plugin-sdk subpaths via cwd fallback when module path is a transpiler cache and package is renamed",
|
||||
fixture: () =>
|
||||
createPluginSdkAliasFixture({
|
||||
packageName: "moltbot",
|
||||
packageExports: {
|
||||
"./plugin-sdk/core": { default: "./dist/plugin-sdk/core.js" },
|
||||
"./plugin-sdk/channel-runtime": { default: "./dist/plugin-sdk/channel-runtime.js" },
|
||||
},
|
||||
}),
|
||||
expected: ["channel-runtime", "core"],
|
||||
},
|
||||
{
|
||||
name: "does not derive plugin-sdk subpaths from cwd fallback when package root is not an OpenClaw root",
|
||||
fixture: () =>
|
||||
createPluginSdkAliasFixture({
|
||||
packageName: "moltbot",
|
||||
trustedRootIndicators: false,
|
||||
packageExports: {
|
||||
"./plugin-sdk/core": { default: "./dist/plugin-sdk/core.js" },
|
||||
|
|
@ -514,7 +485,6 @@ describe("plugin sdk alias helpers", () => {
|
|||
name: "derives plugin-sdk subpaths via cwd fallback when trusted root indicator is cli-entry export",
|
||||
fixture: () =>
|
||||
createPluginSdkAliasFixture({
|
||||
packageName: "moltbot",
|
||||
trustedRootIndicatorMode: "cli-entry-only",
|
||||
packageExports: {
|
||||
"./plugin-sdk/core": { default: "./dist/plugin-sdk/core.js" },
|
||||
|
|
@ -630,26 +600,12 @@ describe("plugin sdk alias helpers", () => {
|
|||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
name: "resolves plugin-sdk alias files via cwd fallback when module path is a transpiler cache and package is renamed",
|
||||
fixture: () =>
|
||||
createPluginSdkAliasFixture({
|
||||
srcFile: "channel-runtime.ts",
|
||||
distFile: "channel-runtime.js",
|
||||
packageName: "moltbot",
|
||||
packageExports: {
|
||||
"./plugin-sdk/channel-runtime": { default: "./dist/plugin-sdk/channel-runtime.js" },
|
||||
},
|
||||
}),
|
||||
expected: "src" as const,
|
||||
},
|
||||
{
|
||||
name: "does not resolve plugin-sdk alias files from cwd fallback when package root is not an OpenClaw root",
|
||||
fixture: () =>
|
||||
createPluginSdkAliasFixture({
|
||||
srcFile: "channel-runtime.ts",
|
||||
distFile: "channel-runtime.js",
|
||||
packageName: "moltbot",
|
||||
trustedRootIndicators: false,
|
||||
packageExports: {
|
||||
"./plugin-sdk/channel-runtime": { default: "./dist/plugin-sdk/channel-runtime.js" },
|
||||
|
|
|
|||
Loading…
Reference in New Issue