test(memory): make mcporter EINVAL retry test deterministic

This commit is contained in:
Peter Steinberger
2026-03-07 10:49:03 +00:00
parent 1aa77e4603
commit b85005194e

View File

@@ -1641,7 +1641,11 @@ describe("QmdMemoryManager", () => {
} as OpenClawConfig;
let sawRetry = false;
let firstCallCommand: string | null = null;
spawnMock.mockImplementation((cmd: string, args: string[]) => {
if (args[0] === "call" && firstCallCommand === null) {
firstCallCommand = cmd;
}
if (args[0] === "call" && typeof cmd === "string" && cmd.toLowerCase().endsWith(".cmd")) {
const child = createMockChild({ autoClose: false });
queueMicrotask(() => {
@@ -1665,10 +1669,16 @@ describe("QmdMemoryManager", () => {
await expect(
manager.search("hello", { sessionKey: "agent:main:slack:dm:u123" }),
).resolves.toEqual([]);
expect(sawRetry).toBe(true);
expect(logWarnMock).toHaveBeenCalledWith(
expect.stringContaining("retrying with bare mcporter"),
);
const attemptedCmdShim = (firstCallCommand ?? "").toLowerCase().endsWith(".cmd");
if (attemptedCmdShim) {
expect(sawRetry).toBe(true);
expect(logWarnMock).toHaveBeenCalledWith(
expect.stringContaining("retrying with bare mcporter"),
);
} else {
// When wrapper resolution upgrades to a direct node/exe entrypoint, cmd-shim retry is unnecessary.
expect(sawRetry).toBe(false);
}
await manager.close();
} finally {
platformSpy.mockRestore();