mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 08:50:43 +00:00
test(gateway): consolidate archive import guards
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { importFreshModule } from "../../../test/helpers/import-fresh.ts";
|
||||
|
||||
describe("reply session module imports", () => {
|
||||
it("does not load archive runtime on module import", async () => {
|
||||
const archiveRuntimeLoads = vi.fn();
|
||||
vi.doMock("../../gateway/session-archive.runtime.js", async () => {
|
||||
archiveRuntimeLoads();
|
||||
return await vi.importActual<typeof import("../../gateway/session-archive.runtime.js")>(
|
||||
"../../gateway/session-archive.runtime.js",
|
||||
);
|
||||
});
|
||||
|
||||
await importFreshModule<typeof import("./session.js")>(
|
||||
import.meta.url,
|
||||
"./session.js?scope=no-archive-runtime-on-import",
|
||||
);
|
||||
|
||||
expect(archiveRuntimeLoads).not.toHaveBeenCalled();
|
||||
vi.doUnmock("../../gateway/session-archive.runtime.js");
|
||||
});
|
||||
});
|
||||
@@ -1,22 +0,0 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { importFreshModule } from "../../test/helpers/import-fresh.ts";
|
||||
|
||||
describe("session store module imports", () => {
|
||||
it("does not load archive runtime on module import", async () => {
|
||||
const archiveRuntimeLoads = vi.fn();
|
||||
vi.doMock("../gateway/session-archive.runtime.js", async () => {
|
||||
archiveRuntimeLoads();
|
||||
return await vi.importActual<typeof import("../gateway/session-archive.runtime.js")>(
|
||||
"../gateway/session-archive.runtime.js",
|
||||
);
|
||||
});
|
||||
|
||||
await importFreshModule<typeof import("./sessions/store.js")>(
|
||||
import.meta.url,
|
||||
"./sessions/store.js?scope=no-archive-runtime-on-import",
|
||||
);
|
||||
|
||||
expect(archiveRuntimeLoads).not.toHaveBeenCalled();
|
||||
vi.doUnmock("../gateway/session-archive.runtime.js");
|
||||
});
|
||||
});
|
||||
35
src/gateway/session-archive.imports.test.ts
Normal file
35
src/gateway/session-archive.imports.test.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { importFreshModule } from "../../test/helpers/import-fresh.ts";
|
||||
|
||||
describe("session archive runtime import guards", () => {
|
||||
it.each([
|
||||
{
|
||||
label: "reply session module",
|
||||
importPath: "../auto-reply/reply/session.js",
|
||||
scope: "reply-session",
|
||||
},
|
||||
{
|
||||
label: "session store module",
|
||||
importPath: "../config/sessions/store.js",
|
||||
scope: "session-store",
|
||||
},
|
||||
])("does not load archive runtime on module import for $label", async ({ importPath, scope }) => {
|
||||
const archiveRuntimeLoads = vi.fn();
|
||||
vi.doMock("./session-archive.runtime.js", async () => {
|
||||
archiveRuntimeLoads();
|
||||
return await vi.importActual<typeof import("./session-archive.runtime.js")>(
|
||||
"./session-archive.runtime.js",
|
||||
);
|
||||
});
|
||||
|
||||
try {
|
||||
await importFreshModule<typeof import("./session-archive.runtime.js")>(
|
||||
import.meta.url,
|
||||
`${importPath}?scope=no-archive-runtime-on-import-${scope}`,
|
||||
);
|
||||
expect(archiveRuntimeLoads).not.toHaveBeenCalled();
|
||||
} finally {
|
||||
vi.doUnmock("./session-archive.runtime.js");
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user