fix(tests): iteration 13

This commit is contained in:
Mohamed Boudra
2026-03-13 13:42:51 +07:00
parent 4a01b9ec90
commit f3036ad2c9
2 changed files with 37 additions and 19 deletions
+7 -1
View File
@@ -21,6 +21,10 @@ async function openWorkspaceAgentTab(page: Page, agentId: string) {
await tab.click(); await tab.click();
} }
function buildWorkspaceDraftUrl(workspaceUrl: string) {
return `${workspaceUrl}?open=${encodeURIComponent("draft:new")}`;
}
test("direct load and refresh land at the bottom for history-backed chats", async ({ test("direct load and refresh land at the bottom for history-backed chats", async ({
page, page,
}) => { }) => {
@@ -69,7 +73,9 @@ test("revisiting a loaded chat restores bottom anchoring", async ({
await waitForAgentReady(page, agent.expectedTailText); await waitForAgentReady(page, agent.expectedTailText);
await expectNearBottom(page); await expectNearBottom(page);
await page.getByTestId("sidebar-new-agent").first().click(); await page.goto(buildWorkspaceDraftUrl(agent.workspaceUrl), {
waitUntil: "domcontentloaded",
});
await expect(page.getByRole("textbox", { name: "Message agent..." }).first()).toBeVisible({ await expect(page.getByRole("textbox", { name: "Message agent..." }).first()).toBeVisible({
timeout: 30000, timeout: 30000,
}); });
@@ -93,31 +93,36 @@ async function waitForTimelineToolCall(
async function waitForPathExists( async function waitForPathExists(
options: { targetPath: string; timeoutMs: number; label: string } options: { targetPath: string; timeoutMs: number; label: string }
): Promise<void> { ): Promise<void> {
const start = Date.now(); await waitForCondition({
while (Date.now() - start < options.timeoutMs) { timeoutMs: options.timeoutMs,
if (existsSync(options.targetPath)) { label: `${options.label}: ${options.targetPath}`,
return; predicate: () => existsSync(options.targetPath),
} });
await new Promise((resolve) => setTimeout(resolve, 50));
}
throw new Error(
`Timed out after ${options.timeoutMs}ms waiting for ${options.label}: ${options.targetPath}`
);
} }
async function waitForPathRemoved( async function waitForPathRemoved(
options: { targetPath: string; timeoutMs: number; label: string } options: { targetPath: string; timeoutMs: number; label: string }
): Promise<void> { ): Promise<void> {
await waitForCondition({
timeoutMs: options.timeoutMs,
label: `removal of ${options.label}: ${options.targetPath}`,
predicate: () => !existsSync(options.targetPath),
});
}
async function waitForCondition(options: {
timeoutMs: number;
label: string;
predicate: () => boolean | Promise<boolean>;
}): Promise<void> {
const start = Date.now(); const start = Date.now();
while (Date.now() - start < options.timeoutMs) { while (Date.now() - start < options.timeoutMs) {
if (!existsSync(options.targetPath)) { if (await options.predicate()) {
return; return;
} }
await new Promise((resolve) => setTimeout(resolve, 50)); await new Promise((resolve) => setTimeout(resolve, 50));
} }
throw new Error( throw new Error(`Timed out after ${options.timeoutMs}ms waiting for ${options.label}`);
`Timed out after ${options.timeoutMs}ms waiting for removal of ${options.label}: ${options.targetPath}`
);
} }
async function withShell<T>(shell: string, run: () => Promise<T>): Promise<T> { async function withShell<T>(shell: string, run: () => Promise<T>): Promise<T> {
@@ -818,10 +823,17 @@ describe("daemon E2E", () => {
label: "createAgent should not block on setup", label: "createAgent should not block on setup",
}); });
await waitForPathExists({ await waitForCondition({
targetPath: path.join(agent.cwd, "dev-terminal.txt"), timeoutMs: 30000,
timeoutMs: 15000, label: `worktree terminal bootstrap for ${agent.cwd}`,
label: "worktree terminal marker", predicate: async () => {
const directories = ctx.daemon.daemon.terminalManager.listDirectories();
if (!directories.includes(agent.cwd)) {
return false;
}
const terminals = await ctx.client.listTerminals(agent.cwd);
return terminals.terminals.some((terminal) => terminal.name === "Dev Server");
},
}); });
const beforeArchiveDirectories = ctx.daemon.daemon.terminalManager.listDirectories(); const beforeArchiveDirectories = ctx.daemon.daemon.terminalManager.listDirectories();