mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
test: trim embedded agents slow paths
This commit is contained in:
@@ -1,22 +1,15 @@
|
||||
import type { AgentMessage } from "@mariozechner/pi-agent-core";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { filterHeartbeatPairs } from "../../../auto-reply/heartbeat-filter.js";
|
||||
import { HEARTBEAT_PROMPT } from "../../../auto-reply/heartbeat.js";
|
||||
import { limitHistoryTurns } from "../history.js";
|
||||
import { buildEmbeddedMessageActionDiscoveryInput } from "../message-action-discovery-input.js";
|
||||
import {
|
||||
assembleAttemptContextEngine,
|
||||
type AttemptContextEngine,
|
||||
resolveAttemptBootstrapContext,
|
||||
} from "./attempt.context-engine-helpers.js";
|
||||
import {
|
||||
cleanupTempPaths,
|
||||
createContextEngineAttemptRunner,
|
||||
getHoisted,
|
||||
resetEmbeddedAttemptHarness,
|
||||
} from "./attempt.spawn-workspace.test-support.js";
|
||||
|
||||
const hoisted = getHoisted();
|
||||
const tempPaths: string[] = [];
|
||||
import { resetEmbeddedAttemptHarness } from "./attempt.spawn-workspace.test-support.js";
|
||||
|
||||
async function resolveBootstrapContext(params: {
|
||||
contextInjectionMode?: "always" | "continuation-skip";
|
||||
@@ -50,10 +43,6 @@ describe("embedded attempt context injection", () => {
|
||||
resetEmbeddedAttemptHarness();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await cleanupTempPaths(tempPaths);
|
||||
});
|
||||
|
||||
it("skips bootstrap reinjection on safe continuation turns when configured", async () => {
|
||||
const { result, hasCompletedBootstrapTurn, resolveBootstrapContextForRun } =
|
||||
await resolveBootstrapContext({
|
||||
@@ -87,25 +76,32 @@ describe("embedded attempt context injection", () => {
|
||||
});
|
||||
|
||||
it("forwards senderIsOwner into embedded message-action discovery", async () => {
|
||||
await createContextEngineAttemptRunner({
|
||||
contextEngine: {
|
||||
assemble: async ({ messages }) => ({ messages, estimatedTokens: 1 }),
|
||||
},
|
||||
attemptOverrides: {
|
||||
messageChannel: "matrix",
|
||||
messageProvider: "matrix",
|
||||
senderIsOwner: false,
|
||||
},
|
||||
const input = buildEmbeddedMessageActionDiscoveryInput({
|
||||
cfg: {},
|
||||
channel: "matrix",
|
||||
currentChannelId: "room",
|
||||
currentThreadTs: "thread",
|
||||
currentMessageId: 123,
|
||||
accountId: "work",
|
||||
sessionKey: "agent:main",
|
||||
tempPaths,
|
||||
sessionId: "session",
|
||||
agentId: "main",
|
||||
senderId: "@alice:example.org",
|
||||
senderIsOwner: false,
|
||||
});
|
||||
|
||||
expect(hoisted.buildEmbeddedMessageActionDiscoveryInputMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
channel: "matrix",
|
||||
senderIsOwner: false,
|
||||
}),
|
||||
);
|
||||
expect(input).toMatchObject({
|
||||
channel: "matrix",
|
||||
currentChannelId: "room",
|
||||
currentThreadTs: "thread",
|
||||
currentMessageId: 123,
|
||||
accountId: "work",
|
||||
sessionKey: "agent:main",
|
||||
sessionId: "session",
|
||||
agentId: "main",
|
||||
requesterSenderId: "@alice:example.org",
|
||||
senderIsOwner: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("never skips heartbeat bootstrap filtering", async () => {
|
||||
|
||||
@@ -115,7 +115,19 @@ describe("subagent registry persistence resume", () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
announceSpy.mockClear();
|
||||
mod.__testing.setDepsForTest();
|
||||
mod.__testing.setDepsForTest({
|
||||
cleanupBrowserSessionsForLifecycleEnd: vi.fn(async () => {}),
|
||||
ensureContextEnginesInitialized: vi.fn(),
|
||||
ensureRuntimePluginsLoaded: vi.fn(),
|
||||
loadConfig: vi.fn(() => ({})),
|
||||
resolveAgentTimeoutMs: vi.fn(() => 100),
|
||||
resolveContextEngine: vi.fn(async () => ({
|
||||
info: { id: "test", name: "Test", version: "0.0.1" },
|
||||
ingest: vi.fn(async () => ({ ingested: false })),
|
||||
assemble: vi.fn(async ({ messages }) => ({ messages, estimatedTokens: 0 })),
|
||||
compact: vi.fn(async () => ({ ok: false, compacted: false })),
|
||||
})),
|
||||
});
|
||||
mod.resetSubagentRegistryForTests({ persist: false });
|
||||
vi.mocked(callGatewayModule.callGateway).mockReset();
|
||||
vi.mocked(callGatewayModule.callGateway).mockResolvedValue({
|
||||
|
||||
Reference in New Issue
Block a user