mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 16:41:36 +00:00
refactor(test): reuse state-dir helper in agent runner suite
This commit is contained in:
@@ -5,6 +5,7 @@ import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vites
|
|||||||
import type { SessionEntry } from "../../config/sessions.js";
|
import type { SessionEntry } from "../../config/sessions.js";
|
||||||
import * as sessions from "../../config/sessions.js";
|
import * as sessions from "../../config/sessions.js";
|
||||||
import type { TypingMode } from "../../config/types.js";
|
import type { TypingMode } from "../../config/types.js";
|
||||||
|
import { withStateDirEnv } from "../../test-helpers/state-dir-env.js";
|
||||||
import type { TemplateContext } from "../templating.js";
|
import type { TemplateContext } from "../templating.js";
|
||||||
import type { GetReplyOptions } from "../types.js";
|
import type { GetReplyOptions } from "../types.js";
|
||||||
import type { FollowupRun, QueueSettings } from "./queue.js";
|
import type { FollowupRun, QueueSettings } from "./queue.js";
|
||||||
@@ -269,35 +270,11 @@ async function runReplyAgentWithBase(params: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("runReplyAgent typing (heartbeat)", () => {
|
describe("runReplyAgent typing (heartbeat)", () => {
|
||||||
let fixtureRoot = "";
|
|
||||||
let caseId = 0;
|
|
||||||
|
|
||||||
type StateEnvSnapshot = {
|
|
||||||
OPENCLAW_STATE_DIR: string | undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
function snapshotStateEnv(): StateEnvSnapshot {
|
|
||||||
return { OPENCLAW_STATE_DIR: process.env.OPENCLAW_STATE_DIR };
|
|
||||||
}
|
|
||||||
|
|
||||||
function restoreStateEnv(snapshot: StateEnvSnapshot) {
|
|
||||||
if (snapshot.OPENCLAW_STATE_DIR === undefined) {
|
|
||||||
delete process.env.OPENCLAW_STATE_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.OPENCLAW_STATE_DIR = snapshot.OPENCLAW_STATE_DIR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function withTempStateDir<T>(fn: (stateDir: string) => Promise<T>): Promise<T> {
|
async function withTempStateDir<T>(fn: (stateDir: string) => Promise<T>): Promise<T> {
|
||||||
const stateDir = path.join(fixtureRoot, `case-${++caseId}`);
|
return await withStateDirEnv(
|
||||||
await fs.mkdir(stateDir, { recursive: true });
|
"openclaw-typing-heartbeat-",
|
||||||
const envSnapshot = snapshotStateEnv();
|
async ({ stateDir }) => await fn(stateDir),
|
||||||
process.env.OPENCLAW_STATE_DIR = stateDir;
|
);
|
||||||
try {
|
|
||||||
return await fn(stateDir);
|
|
||||||
} finally {
|
|
||||||
restoreStateEnv(envSnapshot);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function writeCorruptGeminiSessionFixture(params: {
|
async function writeCorruptGeminiSessionFixture(params: {
|
||||||
@@ -321,16 +298,6 @@ describe("runReplyAgent typing (heartbeat)", () => {
|
|||||||
return { storePath, sessionEntry, sessionStore, transcriptPath };
|
return { storePath, sessionEntry, sessionStore, transcriptPath };
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
fixtureRoot = await fs.mkdtemp(path.join(tmpdir(), "openclaw-typing-heartbeat-"));
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
if (fixtureRoot) {
|
|
||||||
await fs.rm(fixtureRoot, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it("signals typing for normal runs", async () => {
|
it("signals typing for normal runs", async () => {
|
||||||
const onPartialReply = vi.fn();
|
const onPartialReply = vi.fn();
|
||||||
state.runEmbeddedPiAgentMock.mockImplementationOnce(async (params: AgentRunParams) => {
|
state.runEmbeddedPiAgentMock.mockImplementationOnce(async (params: AgentRunParams) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user