Stabilize tests after merge

This commit is contained in:
Mohamed Boudra
2026-01-23 14:01:29 +07:00
parent 2b27b71467
commit 3459faabc4
2 changed files with 32 additions and 6 deletions

View File

@@ -14,7 +14,10 @@ import { ClaudeAgentClient } from "./claude-agent.js";
import type { AgentSession, AgentSessionConfig, AgentSlashCommand } from "../agent-sdk-types.js";
import { createTestLogger } from "../../../test-utils/test-logger.js";
describe("ClaudeAgentSession Commands", () => {
const hasClaudeCredentials =
!!process.env.CLAUDE_SESSION_TOKEN || !!process.env.ANTHROPIC_API_KEY;
(hasClaudeCredentials ? describe : describe.skip)("ClaudeAgentSession Commands", () => {
let client: ClaudeAgentClient;
let session: AgentSession;

View File

@@ -20,6 +20,30 @@ async function waitForFile(filepath: string, timeoutMs = 5000): Promise<void> {
}
}
async function waitForJsonFile<T>(
filepath: string,
timeoutMs = 5000
): Promise<T> {
const start = Date.now();
// eslint-disable-next-line no-constant-condition
while (true) {
if (existsSync(filepath)) {
try {
const raw = readFileSync(filepath, "utf8");
if (raw.trim().length > 0) {
return JSON.parse(raw) as T;
}
} catch {
// File may exist but still be mid-write; retry.
}
}
if (Date.now() - start > timeoutMs) {
throw new Error(`Timed out waiting for valid JSON: ${filepath}`);
}
await new Promise((r) => setTimeout(r, 50));
}
}
describe("voice conversations - daemon E2E", () => {
test(
"two concurrent clients persist independently under paseoHome/voice-conversations",
@@ -57,16 +81,16 @@ describe("voice conversations - daemon E2E", () => {
await waitForFile(fileA);
await waitForFile(fileB);
const dataA = JSON.parse(readFileSync(fileA, "utf8")) as {
const dataA = await waitForJsonFile<{
voiceConversationId: string;
messageCount: number;
messages: unknown[];
};
const dataB = JSON.parse(readFileSync(fileB, "utf8")) as {
}>(fileA);
const dataB = await waitForJsonFile<{
voiceConversationId: string;
messageCount: number;
messages: unknown[];
};
}>(fileB);
expect(dataA.voiceConversationId).toBe(voiceConversationIdA);
expect(dataB.voiceConversationId).toBe(voiceConversationIdB);
@@ -121,4 +145,3 @@ describe("voice conversations - daemon E2E", () => {
30000
);
});