refactor(test): remove duplicate cron tool harnesses

This commit is contained in:
Peter Steinberger
2026-02-21 12:25:13 +00:00
parent f4c89aa66e
commit b2d84528f8
3 changed files with 17 additions and 36 deletions

View File

@@ -13,13 +13,12 @@ function createConnection(): AgentSideConnection {
}
describe("acp prompt cwd prefix", () => {
it("redacts home directory in prompt prefix", async () => {
async function runPromptWithCwd(cwd: string) {
const sessionStore = createInMemorySessionStore();
const homeCwd = path.join(os.homedir(), "openclaw-test");
sessionStore.createSession({
sessionId: "session-1",
sessionKey: "agent:main:main",
cwd: homeCwd,
cwd,
});
const requestSpy = vi.fn(async (method: string) => {
@@ -44,7 +43,11 @@ describe("acp prompt cwd prefix", () => {
_meta: {},
} as unknown as PromptRequest),
).rejects.toThrow("stop-after-send");
return requestSpy;
}
it("redacts home directory in prompt prefix", async () => {
const requestSpy = await runPromptWithCwd(path.join(os.homedir(), "openclaw-test"));
expect(requestSpy).toHaveBeenCalledWith(
"chat.send",
expect.objectContaining({
@@ -53,4 +56,15 @@ describe("acp prompt cwd prefix", () => {
{ expectFinal: true },
);
});
it("keeps backslash separators when cwd uses them", async () => {
const requestSpy = await runPromptWithCwd(`${os.homedir()}\\openclaw-test`);
expect(requestSpy).toHaveBeenCalledWith(
"chat.send",
expect.objectContaining({
message: expect.stringContaining("[Working directory: ~\\openclaw-test]"),
}),
{ expectFinal: true },
);
});
});

View File

@@ -1,12 +0,0 @@
import { vi } from "vitest";
import type { MockFn } from "../../test-utils/vitest-mock-fn.js";
export const callGatewayMock = vi.fn() as unknown as MockFn;
vi.mock("../../gateway/call.js", () => ({
callGateway: (opts: unknown) => callGatewayMock(opts),
}));
vi.mock("../agent-scope.js", () => ({
resolveSessionAgentId: () => "agent-123",
}));

View File

@@ -1,21 +0,0 @@
import { vi } from "vitest";
type GatewayMockFn = ((opts: unknown) => unknown) & {
mockReset: () => void;
mockResolvedValue: (value: unknown) => void;
};
export const callGatewayMock = vi.fn() as GatewayMockFn;
vi.mock("../../gateway/call.js", () => ({
callGateway: (opts: unknown) => callGatewayMock(opts),
}));
vi.mock("../agent-scope.js", () => ({
resolveSessionAgentId: () => "agent-123",
}));
export function resetCronToolGatewayMock() {
callGatewayMock.mockReset();
callGatewayMock.mockResolvedValue({ ok: true });
}