mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 03:27:26 +00:00
perf(test): trim embedded/bash runtime fixture overhead
This commit is contained in:
@@ -13,7 +13,7 @@ const defaultShell = isWin
|
||||
// PowerShell: Start-Sleep for delays, ; for command separation, $null for null device
|
||||
const shortDelayCmd = isWin ? "Start-Sleep -Milliseconds 4" : "sleep 0.004";
|
||||
const yieldDelayCmd = isWin ? "Start-Sleep -Milliseconds 16" : "sleep 0.016";
|
||||
const longDelayCmd = isWin ? "Start-Sleep -Milliseconds 96" : "sleep 0.096";
|
||||
const longDelayCmd = isWin ? "Start-Sleep -Milliseconds 72" : "sleep 0.072";
|
||||
const POLL_INTERVAL_MS = 15;
|
||||
const TEST_EXEC_DEFAULTS = { security: "full" as const, ask: "off" as const };
|
||||
const createTestExecTool = (
|
||||
@@ -164,7 +164,7 @@ describe("exec tool backgrounding", () => {
|
||||
});
|
||||
|
||||
it("uses default timeout when timeout is omitted", async () => {
|
||||
const customBash = createTestExecTool({ timeoutSec: 0.08, backgroundMs: 10 });
|
||||
const customBash = createTestExecTool({ timeoutSec: 0.05, backgroundMs: 10 });
|
||||
const customProcess = createProcessTool();
|
||||
|
||||
const result = await customBash.execute("call1", {
|
||||
@@ -182,7 +182,7 @@ describe("exec tool backgrounding", () => {
|
||||
});
|
||||
return (poll.details as { status: string }).status;
|
||||
},
|
||||
{ timeout: 1500, interval: POLL_INTERVAL_MS },
|
||||
{ timeout: 1000, interval: POLL_INTERVAL_MS },
|
||||
)
|
||||
.toBe("failed");
|
||||
});
|
||||
|
||||
@@ -169,11 +169,10 @@ const nextSessionFile = () => {
|
||||
return path.join(workspaceDir, `session-${sessionCounter}.jsonl`);
|
||||
};
|
||||
const nextRunId = (prefix = "run-embedded-test") => `${prefix}-${++runCounter}`;
|
||||
|
||||
const testSessionKey = "agent:test:embedded";
|
||||
const nextSessionKey = () => `agent:test:embedded:${nextRunId("session-key")}`;
|
||||
const immediateEnqueue = async <T>(task: () => Promise<T>) => task();
|
||||
|
||||
const runWithOrphanedSingleUserMessage = async (text: string) => {
|
||||
const runWithOrphanedSingleUserMessage = async (text: string, sessionKey: string) => {
|
||||
const sessionFile = nextSessionFile();
|
||||
const sessionManager = SessionManager.open(sessionFile);
|
||||
sessionManager.appendMessage({
|
||||
@@ -185,7 +184,7 @@ const runWithOrphanedSingleUserMessage = async (text: string) => {
|
||||
const cfg = makeOpenAiConfig(["mock-1"]);
|
||||
return await runEmbeddedPiAgent({
|
||||
sessionId: "session:test",
|
||||
sessionKey: testSessionKey,
|
||||
sessionKey,
|
||||
sessionFile,
|
||||
workspaceDir,
|
||||
config: cfg,
|
||||
@@ -226,11 +225,11 @@ const readSessionMessages = async (sessionFile: string) => {
|
||||
) as Array<{ role?: string; content?: unknown }>;
|
||||
};
|
||||
|
||||
const runDefaultEmbeddedTurn = async (sessionFile: string, prompt: string) => {
|
||||
const runDefaultEmbeddedTurn = async (sessionFile: string, prompt: string, sessionKey: string) => {
|
||||
const cfg = makeOpenAiConfig(["mock-1"]);
|
||||
await runEmbeddedPiAgent({
|
||||
sessionId: "session:test",
|
||||
sessionKey: testSessionKey,
|
||||
sessionKey,
|
||||
sessionFile,
|
||||
workspaceDir,
|
||||
config: cfg,
|
||||
@@ -244,7 +243,7 @@ const runDefaultEmbeddedTurn = async (sessionFile: string, prompt: string) => {
|
||||
});
|
||||
};
|
||||
|
||||
describe("runEmbeddedPiAgent", () => {
|
||||
describe.concurrent("runEmbeddedPiAgent", () => {
|
||||
it("handles prompt error paths without dropping user state", async () => {
|
||||
for (const testCase of [
|
||||
{
|
||||
@@ -264,9 +263,10 @@ describe("runEmbeddedPiAgent", () => {
|
||||
] as const) {
|
||||
const sessionFile = nextSessionFile();
|
||||
const cfg = makeOpenAiConfig([testCase.model]);
|
||||
const sessionKey = nextSessionKey();
|
||||
const execution = runEmbeddedPiAgent({
|
||||
sessionId: "session:test",
|
||||
sessionKey: testSessionKey,
|
||||
sessionKey,
|
||||
sessionFile,
|
||||
workspaceDir,
|
||||
config: cfg,
|
||||
@@ -300,6 +300,7 @@ describe("runEmbeddedPiAgent", () => {
|
||||
{ timeout: 90_000 },
|
||||
async () => {
|
||||
const sessionFile = nextSessionFile();
|
||||
const sessionKey = nextSessionKey();
|
||||
|
||||
const sessionManager = SessionManager.open(sessionFile);
|
||||
sessionManager.appendMessage({
|
||||
@@ -331,7 +332,7 @@ describe("runEmbeddedPiAgent", () => {
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
|
||||
await runDefaultEmbeddedTurn(sessionFile, "hello");
|
||||
await runDefaultEmbeddedTurn(sessionFile, "hello", sessionKey);
|
||||
|
||||
const messages = await readSessionMessages(sessionFile);
|
||||
const seedUserIndex = messages.findIndex(
|
||||
@@ -355,7 +356,7 @@ describe("runEmbeddedPiAgent", () => {
|
||||
);
|
||||
|
||||
it("repairs orphaned user messages and continues", async () => {
|
||||
const result = await runWithOrphanedSingleUserMessage("orphaned user");
|
||||
const result = await runWithOrphanedSingleUserMessage("orphaned user", nextSessionKey());
|
||||
|
||||
expect(result.meta.error).toBeUndefined();
|
||||
expect(result.payloads?.length ?? 0).toBeGreaterThan(0);
|
||||
|
||||
Reference in New Issue
Block a user