Files
openclaw/extensions/anthropic/lazy-import.test.ts
WhatsSkiLL 632581477f fix(session-catalog): preserve explicit agent ownership across UI and CLI (#123899)
* fix(session-catalog): preserve explicit agent ownership across UI and CLI

* fix(session-catalog): repair owner routing regressions

* Fix-session-catalog-CI-checks

* test(ui): split chat catalog pane coverage

Co-authored-by: IWhatsskill <284122573+IWhatsskill@users.noreply.github.com>

* refactor(session-catalog): bind Codex homes per request

Co-authored-by: IWhatsskill <284122573+IWhatsskill@users.noreply.github.com>

* refactor(session-catalog): centralize owner resolution

Co-authored-by: IWhatsskill <284122573+IWhatsskill@users.noreply.github.com>

* fix(codex): resolve session fork against the adopted home

Co-authored-by: IWhatsskill <284122573+IWhatsskill@users.noreply.github.com>

* refactor(ui): extract chat session discussion

* test(sessions): stabilize archive worker responsiveness check

---------

Co-authored-by: IWhatsskill <284122573+IWhatsskill@users.noreply.github.com>
Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-08-15 04:47:28 -07:00

73 lines
2.8 KiB
TypeScript

import type {
OpenClawPluginNodeHostCommand,
OpenClawPluginNodeInvokePolicy,
} from "openclaw/plugin-sdk/plugin-entry";
import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api";
import { createPluginRuntimeMock } from "openclaw/plugin-sdk/plugin-test-runtime";
import type { SessionCatalogProvider } from "openclaw/plugin-sdk/session-catalog";
import { afterEach, describe, expect, it, vi } from "vitest";
describe("anthropic session catalog lazy imports", () => {
afterEach(() => {
vi.doUnmock("./session-catalog.js");
vi.doUnmock("./session-catalog-node-commands.js");
vi.resetModules();
});
it("loads catalog and node handlers only on first use", async () => {
let catalogImports = 0;
let nodeCommandImports = 0;
vi.doMock("./session-catalog.js", () => {
catalogImports += 1;
return {
createClaudeSessionCatalogRuntime: () => ({
list: async () => [],
read: async () => ({ hostId: "gateway:local", label: "Local", threadId: "", items: [] }),
continueSession: async () => ({ sessionKey: "agent:main:test" }),
startTerminalSession: async () => ({ kind: "local", argv: ["claude"] }),
openTerminal: async () => ({ kind: "local", argv: ["claude"] }),
checkUpstreamActivity: async () => [],
}),
};
});
vi.doMock("./session-catalog-node-commands.js", () => {
nodeCommandImports += 1;
return {
listClaudeSessions: async () => "[]",
readClaudeSession: async () => "{}",
resumeClaudeSession: async () => "{}",
};
});
const { default: anthropicPlugin } = await import("./index.js");
const catalogs: SessionCatalogProvider[] = [];
const nodeCommands: OpenClawPluginNodeHostCommand[] = [];
const nodePolicies: OpenClawPluginNodeInvokePolicy[] = [];
anthropicPlugin.register(
createTestPluginApi({
id: "anthropic",
name: "Anthropic",
source: "test",
config: {},
runtime: createPluginRuntimeMock(),
registerSessionCatalog: (provider) => catalogs.push(provider),
registerNodeHostCommand: (command) => nodeCommands.push(command),
registerNodeInvokePolicy: (policy) => nodePolicies.push(policy),
}),
);
expect(catalogImports).toBe(0);
expect(nodeCommandImports).toBe(0);
expect(catalogs).toHaveLength(1);
expect(nodeCommands).toHaveLength(3);
expect(nodePolicies).toHaveLength(1);
await expect(catalogs[0]?.list({ agentId: "main" })).resolves.toEqual([]);
await expect(catalogs[0]?.list({ agentId: "main" })).resolves.toEqual([]);
await expect(nodeCommands[0]?.handle()).resolves.toBe("[]");
await expect(nodeCommands[0]?.handle()).resolves.toBe("[]");
expect(catalogImports).toBe(1);
expect(nodeCommandImports).toBe(1);
});
});