perf(test): slim raw-body directive integration

This commit is contained in:
Peter Steinberger
2026-02-14 20:07:53 +00:00
parent e1220c48f5
commit 5daaab3692
2 changed files with 42 additions and 62 deletions

View File

@@ -114,7 +114,7 @@ describe("RawBody directive parsing", () => {
vi.clearAllMocks();
});
it("handles directives, history, and non-default agent session files", async () => {
it("handles directives and history in the prompt", async () => {
await withTempHome(async (home) => {
agentMocks.runEmbeddedPiAgent.mockResolvedValue({
payloads: [{ text: "ok" }],
@@ -164,67 +164,6 @@ describe("RawBody directive parsing", () => {
expect(prompt).toContain('"body": "hello"');
expect(prompt).toContain("status please");
expect(prompt).not.toContain("/think:high");
const agentId = "worker1";
const sessionId = "sess-worker-1";
const sessionKey = `agent:${agentId}:telegram:12345`;
const sessionsDir = path.join(home, ".openclaw", "agents", agentId, "sessions");
const sessionFile = path.join(sessionsDir, `${sessionId}.jsonl`);
const storePath = path.join(sessionsDir, "sessions.json");
await fs.mkdir(sessionsDir, { recursive: true });
await fs.writeFile(sessionFile, "", "utf-8");
await fs.writeFile(
storePath,
JSON.stringify(
{
[sessionKey]: {
sessionId,
sessionFile,
updatedAt: Date.now(),
},
},
null,
2,
),
"utf-8",
);
agentMocks.runEmbeddedPiAgent.mockReset();
agentMocks.runEmbeddedPiAgent.mockResolvedValue({
payloads: [{ text: "ok" }],
meta: {
durationMs: 1,
agentMeta: { sessionId, provider: "anthropic", model: "claude-opus-4-5" },
},
});
const resWorker = await getReplyFromConfig(
{
Body: "hello",
From: "telegram:12345",
To: "telegram:12345",
SessionKey: sessionKey,
Provider: "telegram",
Surface: "telegram",
CommandAuthorized: true,
},
{},
{
agents: {
defaults: {
model: "anthropic/claude-opus-4-5",
workspace: path.join(home, "openclaw"),
},
},
},
);
const textWorker = Array.isArray(resWorker) ? resWorker[0]?.text : resWorker?.text;
expect(textWorker).toBe("ok");
expect(agentMocks.runEmbeddedPiAgent).toHaveBeenCalledOnce();
expect(
(agentMocks.runEmbeddedPiAgent.mock.calls[0]?.[0] as { sessionFile?: string } | undefined)
?.sessionFile,
).toBe(sessionFile);
});
});
});

View File

@@ -195,6 +195,47 @@ describe("initSessionState RawBody", () => {
expect(result.triggerBodyNormalized).toBe("/status");
});
it("uses the default per-agent sessions store when config store is unset", async () => {
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-session-store-default-"));
const stateDir = path.join(root, ".openclaw");
const agentId = "worker1";
const sessionKey = `agent:${agentId}:telegram:12345`;
const sessionId = "sess-worker-1";
const sessionFile = path.join(stateDir, "agents", agentId, "sessions", `${sessionId}.jsonl`);
const storePath = path.join(stateDir, "agents", agentId, "sessions", "sessions.json");
vi.stubEnv("OPENCLAW_STATE_DIR", stateDir);
try {
await fs.mkdir(path.dirname(storePath), { recursive: true });
await saveSessionStore(storePath, {
[sessionKey]: {
sessionId,
sessionFile,
updatedAt: Date.now(),
},
});
const cfg = {} as OpenClawConfig;
const result = await initSessionState({
ctx: {
Body: "hello",
ChatType: "direct",
Provider: "telegram",
Surface: "telegram",
SessionKey: sessionKey,
},
cfg,
commandAuthorized: true,
});
expect(result.sessionEntry.sessionId).toBe(sessionId);
expect(result.sessionEntry.sessionFile).toBe(sessionFile);
expect(result.storePath).toBe(storePath);
} finally {
vi.unstubAllEnvs();
}
});
});
describe("initSessionState reset policy", () => {