mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 10:20:42 +00:00
test: trim more hotspot overhead
This commit is contained in:
@@ -144,9 +144,9 @@ describe("serveAcpGateway startup", () => {
|
||||
async function emitHelloAndWaitForAgentSideConnection() {
|
||||
const gateway = getMockGateway();
|
||||
gateway.emitHello();
|
||||
await vi.waitFor(() => {
|
||||
expect(mockState.agentSideConnectionCtor).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
await Promise.resolve();
|
||||
await Promise.resolve();
|
||||
expect(mockState.agentSideConnectionCtor).toHaveBeenCalledTimes(1);
|
||||
}
|
||||
|
||||
async function stopServeWithSigint(
|
||||
|
||||
@@ -1006,12 +1006,15 @@ describe("Initialization guard", () => {
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
describe("Bundle chunk isolation (#40096)", () => {
|
||||
it("shares registrations and resolves engines across independently loaded chunks", async () => {
|
||||
it("shares registrations and keeps concurrent chunk registration visible", async () => {
|
||||
const ts = Date.now().toString(36);
|
||||
const registryUrl = new URL("./registry.ts", import.meta.url).href;
|
||||
|
||||
const chunkA = await import(/* @vite-ignore */ `${registryUrl}?chunk=a-${ts}`);
|
||||
const chunkB = await import(/* @vite-ignore */ `${registryUrl}?chunk=b-${ts}`);
|
||||
const chunks = await Promise.all(
|
||||
Array.from(
|
||||
{ length: 5 },
|
||||
(_, i) => import(/* @vite-ignore */ `${registryUrl}?chunk=${ts}-${i}`),
|
||||
),
|
||||
);
|
||||
|
||||
const engineId = `cross-chunk-${ts}`;
|
||||
const factory = () => ({
|
||||
@@ -1026,40 +1029,22 @@ describe("Bundle chunk isolation (#40096)", () => {
|
||||
return { ok: true, compacted: false };
|
||||
},
|
||||
});
|
||||
chunkA.registerContextEngine(engineId, factory);
|
||||
chunks[0].registerContextEngine(engineId, factory);
|
||||
|
||||
expect(chunkB.getContextEngineFactory(engineId)).toBe(factory);
|
||||
expect(chunkB.listContextEngineIds()).toContain(engineId);
|
||||
const engine = await chunkB.resolveContextEngine(configWithSlot(engineId));
|
||||
expect(chunks[1].getContextEngineFactory(engineId)).toBe(factory);
|
||||
expect(chunks[1].listContextEngineIds()).toContain(engineId);
|
||||
const engine = await chunks[1].resolveContextEngine(configWithSlot(engineId));
|
||||
expect(engine.info.id).toBe(engineId);
|
||||
});
|
||||
|
||||
it("concurrent registration from multiple chunks does not lose entries", async () => {
|
||||
const ts = Date.now().toString(36);
|
||||
const registryUrl = new URL("./registry.ts", import.meta.url).href;
|
||||
let releaseRegistrations: (() => void) | undefined;
|
||||
const registrationStart = new Promise<void>((resolve) => {
|
||||
releaseRegistrations = resolve;
|
||||
});
|
||||
|
||||
// Load 5 "chunks" in parallel
|
||||
const chunks = await Promise.all(
|
||||
Array.from(
|
||||
{ length: 5 },
|
||||
(_, i) => import(/* @vite-ignore */ `${registryUrl}?concurrent-${ts}-${i}`),
|
||||
),
|
||||
);
|
||||
|
||||
const ids = chunks.map((_, i) => `concurrent-${ts}-${i}`);
|
||||
const registrationTasks = chunks.map(async (chunk, i) => {
|
||||
const id = `concurrent-${ts}-${i}`;
|
||||
await registrationStart;
|
||||
chunk.registerContextEngine(id, () => new MockContextEngine());
|
||||
});
|
||||
releaseRegistrations?.();
|
||||
const registrationTasks = chunks.map((chunk, i) =>
|
||||
Promise.resolve().then(() => {
|
||||
const id = `concurrent-${ts}-${i}`;
|
||||
chunk.registerContextEngine(id, () => new MockContextEngine());
|
||||
}),
|
||||
);
|
||||
await Promise.all(registrationTasks);
|
||||
|
||||
// All 5 engines must be visible from any chunk
|
||||
const allIds = chunks[0].listContextEngineIds();
|
||||
for (const id of ids) {
|
||||
expect(allIds).toContain(id);
|
||||
|
||||
@@ -187,11 +187,12 @@ describe("plugin activation boundary", () => {
|
||||
}),
|
||||
).toBe(true);
|
||||
expect(isStaticallyChannelConfigured({}, "whatsapp", {})).toBe(false);
|
||||
expect(normalizeModelRef("google", "gemini-3.1-pro")).toEqual({
|
||||
const staticNormalize = { allowPluginNormalization: false };
|
||||
expect(normalizeModelRef("google", "gemini-3.1-pro", staticNormalize)).toEqual({
|
||||
provider: "google",
|
||||
model: "gemini-3.1-pro-preview",
|
||||
});
|
||||
expect(normalizeModelRef("xai", "grok-4-fast-reasoning")).toEqual({
|
||||
expect(normalizeModelRef("xai", "grok-4-fast-reasoning", staticNormalize)).toEqual({
|
||||
provider: "xai",
|
||||
model: "grok-4-fast",
|
||||
});
|
||||
|
||||
@@ -1000,44 +1000,6 @@ describe("chat view", () => {
|
||||
expect(container.textContent).not.toContain("Opened page");
|
||||
});
|
||||
|
||||
it("auto-expands new tool cards inline when the preference is enabled", () => {
|
||||
const container = document.createElement("div");
|
||||
render(
|
||||
renderChat(
|
||||
createProps({
|
||||
autoExpandToolCalls: true,
|
||||
messages: [
|
||||
{
|
||||
id: "assistant-2",
|
||||
role: "assistant",
|
||||
toolCallId: "call-2",
|
||||
content: [
|
||||
{
|
||||
type: "toolcall",
|
||||
id: "call-2",
|
||||
name: "browser.open",
|
||||
arguments: { url: "https://example.com" },
|
||||
},
|
||||
{
|
||||
type: "toolresult",
|
||||
id: "call-2",
|
||||
name: "browser.open",
|
||||
text: "Opened page",
|
||||
},
|
||||
],
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
],
|
||||
}),
|
||||
),
|
||||
container,
|
||||
);
|
||||
|
||||
expect(container.textContent).toContain("Tool input");
|
||||
expect(container.textContent).toContain("Tool output");
|
||||
expect(container.textContent).toContain("https://example.com");
|
||||
});
|
||||
|
||||
it("expands already-visible tool cards when auto-expand is turned on", () => {
|
||||
const container = document.createElement("div");
|
||||
const baseProps = createProps({
|
||||
@@ -1073,84 +1035,6 @@ describe("chat view", () => {
|
||||
expect(container.textContent).toContain("Tool output");
|
||||
});
|
||||
|
||||
it("lets an auto-expanded tool call collapse again from the summary row", async () => {
|
||||
const container = document.createElement("div");
|
||||
const props = createProps({
|
||||
autoExpandToolCalls: true,
|
||||
messages: [
|
||||
{
|
||||
id: "assistant-3b",
|
||||
role: "assistant",
|
||||
toolCallId: "call-3b",
|
||||
content: [
|
||||
{
|
||||
type: "toolcall",
|
||||
id: "call-3b",
|
||||
name: "browser.open",
|
||||
arguments: { url: "https://example.com" },
|
||||
},
|
||||
{
|
||||
type: "toolresult",
|
||||
id: "call-3b",
|
||||
name: "browser.open",
|
||||
text: "Opened page",
|
||||
},
|
||||
],
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const rerender = () => {
|
||||
render(renderChat({ ...props, onRequestUpdate: rerender }), container);
|
||||
};
|
||||
rerender();
|
||||
|
||||
expect(container.textContent).toContain("Tool input");
|
||||
expect(container.textContent).toContain("Opened page");
|
||||
|
||||
container
|
||||
.querySelector<HTMLElement>(".chat-tool-msg-summary")
|
||||
?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
||||
await flushTasks();
|
||||
|
||||
expect(container.textContent).not.toContain("Tool input");
|
||||
expect(container.textContent).not.toContain("Opened page");
|
||||
});
|
||||
|
||||
it("keeps expanded input-only tool calls from rendering a redundant output block", () => {
|
||||
const container = document.createElement("div");
|
||||
render(
|
||||
renderChat(
|
||||
createProps({
|
||||
autoExpandToolCalls: true,
|
||||
messages: [
|
||||
{
|
||||
id: "assistant-4",
|
||||
role: "assistant",
|
||||
toolCallId: "call-4",
|
||||
content: [
|
||||
{
|
||||
type: "toolcall",
|
||||
id: "call-4",
|
||||
name: "sessions_spawn",
|
||||
arguments: { mode: "session", thread: true },
|
||||
},
|
||||
],
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
],
|
||||
}),
|
||||
),
|
||||
container,
|
||||
);
|
||||
|
||||
expect(container.textContent).toContain("Tool input");
|
||||
expect(container.textContent).toContain('"thread": true');
|
||||
expect(container.textContent).not.toContain("Tool output");
|
||||
expect(container.textContent).not.toContain("No output");
|
||||
});
|
||||
|
||||
it("routes standalone tool-call rows through the same top-level disclosure as tool output", async () => {
|
||||
const container = document.createElement("div");
|
||||
const props = createProps({
|
||||
@@ -1244,42 +1128,6 @@ describe("chat view", () => {
|
||||
expect(container.textContent).toContain('"childSessionKey": "agent:test:subagent:abc123"');
|
||||
});
|
||||
|
||||
it("does not render tool-row canvas previews", () => {
|
||||
const container = document.createElement("div");
|
||||
render(
|
||||
renderChat(
|
||||
createProps({
|
||||
autoExpandToolCalls: true,
|
||||
messages: [
|
||||
{
|
||||
id: "tool-anki-1",
|
||||
role: "tool",
|
||||
toolCallId: "call-anki-1",
|
||||
toolName: "canvas_render",
|
||||
content: JSON.stringify({
|
||||
kind: "canvas",
|
||||
source: {
|
||||
type: "html",
|
||||
content: "<div>Front card</div>",
|
||||
},
|
||||
presentation: {
|
||||
target: "tool_card",
|
||||
title: "Status view",
|
||||
},
|
||||
}),
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
],
|
||||
}),
|
||||
),
|
||||
container,
|
||||
);
|
||||
|
||||
expect(container.querySelector(".chat-tool-card__preview-frame")).toBeNull();
|
||||
expect(container.textContent).toContain("Status view");
|
||||
expect(container.textContent).toContain("Tool output");
|
||||
});
|
||||
|
||||
it("renders [embed] shortcodes inside the assistant bubble", () => {
|
||||
const container = document.createElement("div");
|
||||
render(
|
||||
|
||||
Reference in New Issue
Block a user