test(core): dedupe auth rotation and credential injection specs

This commit is contained in:
Peter Steinberger
2026-02-22 08:44:35 +00:00
parent c2c7114ed3
commit cfb3cee7aa
2 changed files with 58 additions and 74 deletions

View File

@@ -272,45 +272,40 @@ async function runTurnWithCooldownSeed(params: {
}
describe("runEmbeddedPiAgent auth profile rotation", () => {
it("rotates for auto-pinned profiles", async () => {
const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-agent-"));
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-workspace-"));
try {
await writeAuthStore(agentDir);
mockFailedThenSuccessfulAttempt("rate limit");
await runAutoPinnedOpenAiTurn({
agentDir,
workspaceDir,
it("rotates for auto-pinned profiles across retryable stream failures", async () => {
const cases = [
{
errorMessage: "rate limit",
sessionKey: "agent:test:auto",
runId: "run:auto",
});
expect(runEmbeddedAttemptMock).toHaveBeenCalledTimes(2);
await expectProfileP2UsageUpdated(agentDir);
} finally {
await fs.rm(agentDir, { recursive: true, force: true });
await fs.rm(workspaceDir, { recursive: true, force: true });
}
});
it("rotates when stream ends without sending chunks", async () => {
const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-agent-"));
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-workspace-"));
try {
await writeAuthStore(agentDir);
mockFailedThenSuccessfulAttempt("request ended without sending any chunks");
await runAutoPinnedOpenAiTurn({
agentDir,
workspaceDir,
},
{
errorMessage: "request ended without sending any chunks",
sessionKey: "agent:test:empty-chunk-stream",
runId: "run:empty-chunk-stream",
});
},
] as const;
expect(runEmbeddedAttemptMock).toHaveBeenCalledTimes(2);
await expectProfileP2UsageUpdated(agentDir);
} finally {
await fs.rm(agentDir, { recursive: true, force: true });
await fs.rm(workspaceDir, { recursive: true, force: true });
for (const testCase of cases) {
runEmbeddedAttemptMock.mockClear();
const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-agent-"));
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-workspace-"));
try {
await writeAuthStore(agentDir);
mockFailedThenSuccessfulAttempt(testCase.errorMessage);
await runAutoPinnedOpenAiTurn({
agentDir,
workspaceDir,
sessionKey: testCase.sessionKey,
runId: testCase.runId,
});
expect(runEmbeddedAttemptMock).toHaveBeenCalledTimes(2);
await expectProfileP2UsageUpdated(agentDir);
} finally {
await fs.rm(agentDir, { recursive: true, force: true });
await fs.rm(workspaceDir, { recursive: true, force: true });
}
}
});