test: trim duplicate embedded runner setup cases

This commit is contained in:
Peter Steinberger
2026-02-22 17:33:55 +00:00
parent 924455edb8
commit 1437f371fc

View File

@@ -243,119 +243,6 @@ const runDefaultEmbeddedTurn = async (sessionFile: string, prompt: string) => {
};
describe("runEmbeddedPiAgent", () => {
it("writes models.json into the provided agentDir", async () => {
const sessionFile = nextSessionFile();
const cfg = {
models: {
providers: {
minimax: {
baseUrl: "https://api.minimax.io/anthropic",
api: "anthropic-messages",
apiKey: "sk-minimax-test",
models: [
{
id: "MiniMax-M2.1",
name: "MiniMax M2.1",
reasoning: false,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 200000,
maxTokens: 8192,
},
],
},
},
},
} satisfies OpenClawConfig;
await expect(
runEmbeddedPiAgent({
sessionId: "session:test",
sessionKey: testSessionKey,
sessionFile,
workspaceDir,
config: cfg,
prompt: "hi",
provider: "definitely-not-a-provider",
model: "definitely-not-a-model",
timeoutMs: 1,
agentDir,
runId: nextRunId("unknown-model"),
enqueue: immediateEnqueue,
}),
).rejects.toThrow(/Unknown model:/);
await expect(fs.stat(path.join(agentDir, "models.json"))).resolves.toBeTruthy();
});
it("falls back to per-agent workspace when runtime workspaceDir is missing", async () => {
const sessionFile = nextSessionFile();
const fallbackWorkspace = path.join(tempRoot ?? os.tmpdir(), "workspace-fallback-main");
const cfg = {
...makeOpenAiConfig(["mock-1"]),
agents: {
defaults: {
workspace: fallbackWorkspace,
},
},
} satisfies OpenClawConfig;
const result = await runEmbeddedPiAgent({
sessionId: "session:test-fallback",
sessionKey: "agent:main:subagent:fallback-workspace",
sessionFile,
workspaceDir: undefined as unknown as string,
config: cfg,
prompt: "hello",
provider: "openai",
model: "mock-1",
timeoutMs: 5_000,
agentDir,
runId: "run-fallback-workspace",
enqueue: immediateEnqueue,
});
expect(result.payloads?.[0]?.text).toBe("ok");
await expect(fs.stat(fallbackWorkspace)).resolves.toBeTruthy();
});
it("throws when sessionKey is malformed", async () => {
const sessionFile = nextSessionFile();
const cfg = {
...makeOpenAiConfig(["mock-1"]),
agents: {
defaults: {
workspace: path.join(tempRoot ?? os.tmpdir(), "workspace-fallback-main"),
},
list: [
{
id: "research",
workspace: path.join(tempRoot ?? os.tmpdir(), "workspace-fallback-research"),
},
],
},
} satisfies OpenClawConfig;
await expect(
runEmbeddedPiAgent({
sessionId: "session:test-fallback-malformed",
sessionKey: "agent::broken",
agentId: "research",
sessionFile,
workspaceDir: undefined as unknown as string,
config: cfg,
prompt: "hello",
provider: "openai",
model: "mock-1",
timeoutMs: 5_000,
agentDir,
runId: "run-fallback-workspace-malformed",
enqueue: immediateEnqueue,
}),
).rejects.toThrow("Malformed agent session key");
});
it("persists the user message when prompt fails before assistant output", async () => {
const sessionFile = nextSessionFile();
const cfg = makeOpenAiConfig(["mock-error"]);