mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
The e2e TypeScript project was never type checked: its tsconfig didn't inherit the app's settings, so @/ imports didn't resolve and hundreds of diagnostics went unnoticed. e2e/tsconfig.json now extends the root config (plus Node/Vite types and ES2024), pnpm typecheck runs tsrs -p e2e, and the remaining real type errors in the specs and fixtures are fixed; the code-style docs list the new project. Co-authored-by: Mr0Bread <55754540+Mr0Bread@users.noreply.github.com>
244 lines
10 KiB
TypeScript
244 lines
10 KiB
TypeScript
import { expect, test } from "./fixtures";
|
|
import type { AgentQuestion, AgentTask } from "../src/bindings";
|
|
import type * as AgentStore from "../src/features/agents/store";
|
|
import type * as Ipc from "../src/platform/ipc";
|
|
|
|
const task: AgentTask = {
|
|
id: "questions",
|
|
title: "Plan the change",
|
|
status: "needsInput",
|
|
isolation: "local",
|
|
provider: "codex",
|
|
model: null,
|
|
cwd: "/dev/acme-api",
|
|
branch: null,
|
|
base: null,
|
|
baseCommit: null,
|
|
error: null,
|
|
createdMs: 0,
|
|
updatedMs: 0,
|
|
config: [],
|
|
commands: [],
|
|
usage: null,
|
|
queue: [],
|
|
};
|
|
const questions: AgentQuestion[] = [
|
|
{
|
|
header: "Layout",
|
|
question: "Which layout should we use?",
|
|
multiSelect: false,
|
|
options: [{ label: "Table", description: "One row per check", preview: "| check | result |" }],
|
|
},
|
|
{
|
|
header: "Checks",
|
|
question: "Which checks should we include? " + "Explain the checks and their expected results. ".repeat(8),
|
|
multiSelect: true,
|
|
options: [
|
|
{ label: "LongOption".repeat(20), description: "Description ".repeat(25), preview: null },
|
|
{ label: "Updates", description: "Check for updates", preview: null },
|
|
],
|
|
},
|
|
{
|
|
header: "Delivery",
|
|
question: "When should the change ship?",
|
|
multiSelect: false,
|
|
options: [{ label: "Today", description: "After the checks pass", preview: null }],
|
|
},
|
|
];
|
|
|
|
for (const status of ["running", "ready"] as const) {
|
|
test(`answers an asynchronous Codex question when ${status}`, async ({ workbench: page }) => {
|
|
const key = JSON.stringify(["request_user_input_async", "call-1", 0]);
|
|
await page.evaluate(
|
|
async ({ task, status, key }) => {
|
|
// Keep the workbench imports in the browser's Vite realm.
|
|
const storePath = "/src/features/agents/store.ts";
|
|
const ipcPath = "/src/platform/ipc.ts";
|
|
const store: typeof AgentStore = await import(storePath);
|
|
const { commands }: typeof Ipc = await import(ipcPath);
|
|
commands.agentAnswerQuestion = async (id, question, answer) => {
|
|
document.documentElement.dataset.asyncAnswer = JSON.stringify({ id, question, answer });
|
|
const entries = store.useAgents.getState().entries.get(id)!;
|
|
store.useAgents.setState({
|
|
entries: new Map([
|
|
[
|
|
id,
|
|
entries.map((entry) =>
|
|
entry.type === "question" ? { ...entry, chosen: "Read latest content" } : entry,
|
|
),
|
|
],
|
|
]),
|
|
});
|
|
return { status: "ok", data: null };
|
|
};
|
|
store.useAgents.setState({
|
|
loaded: true,
|
|
tasks: new Map([[task.id, { ...task, status }]]),
|
|
entries: new Map([
|
|
[
|
|
task.id,
|
|
[
|
|
{ type: "agent", text: "I can keep working while you decide." },
|
|
{
|
|
type: "question",
|
|
id: "call-1",
|
|
title: "Should Retry read the latest content?",
|
|
chosen: null,
|
|
questions: [
|
|
{
|
|
answerKey: key,
|
|
header: "",
|
|
question: "Should Retry read the latest content?",
|
|
multiSelect: false,
|
|
options: [
|
|
{ label: "Read latest content (Recommended)", description: "", preview: null },
|
|
{ label: "Keep the original snapshot", description: "", preview: null },
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
],
|
|
]),
|
|
});
|
|
store.openTaskInEditorLocation(task.id);
|
|
},
|
|
{ task, status, key },
|
|
);
|
|
const card = page.getByRole("form", { name: "Should Retry read the latest content?" });
|
|
await expect(card).toBeVisible();
|
|
await card.getByRole("radio", { name: /^Read latest content/ }).check();
|
|
if (status === "running") {
|
|
await page.evaluate(async (id) => {
|
|
const storePath = "/src/features/agents/store.ts";
|
|
const { useAgents }: typeof AgentStore = await import(storePath);
|
|
useAgents.setState((s) => ({ tasks: new Map(s.tasks).set(id, { ...s.tasks.get(id)!, status: "ready" }) }));
|
|
}, task.id);
|
|
await expect(card.getByRole("radio", { name: /^Read latest content/ })).toBeChecked();
|
|
}
|
|
await card.getByRole("button", { name: "Submit", exact: true }).click();
|
|
await expect(page.locator("html")).toHaveAttribute(
|
|
"data-async-answer",
|
|
JSON.stringify({
|
|
id: task.id,
|
|
question: "call-1",
|
|
answer: JSON.stringify({ [key]: ["Read latest content (Recommended)"] }),
|
|
}),
|
|
);
|
|
await expect(card).toHaveCount(0);
|
|
});
|
|
}
|
|
|
|
for (const theme of ["dark", "light"] as const) {
|
|
for (const width of [760, 1400]) {
|
|
for (const count of [1, 3]) {
|
|
test(`${count} questions at ${width}px in ${theme}`, async ({ workbench: page }) => {
|
|
await page.setViewportSize({ width, height: 900 });
|
|
await page.evaluate(
|
|
async ({ task, questions, theme }) => {
|
|
const storePath = "/src/features/agents/store.ts";
|
|
const themePath = "/src/workbench/theme.ts";
|
|
const ipcPath = "/src/platform/ipc.ts";
|
|
const store = await import(storePath);
|
|
(await import(themePath)).previewTheme(theme);
|
|
// Keep this fixture entirely local, including submission.
|
|
(await import(ipcPath)).commands.agentRespond = async (
|
|
_task: string,
|
|
_permission: number,
|
|
answer: string,
|
|
) => {
|
|
document.documentElement.dataset.questionAnswer = answer;
|
|
return { status: "ok", data: null };
|
|
};
|
|
store.useAgents.setState({
|
|
loaded: true,
|
|
tasks: new Map([[task.id, task]]),
|
|
entries: new Map([
|
|
[
|
|
task.id,
|
|
[{ type: "permission", id: 1, title: "Plan the change", options: [], chosen: null, questions }],
|
|
],
|
|
]),
|
|
});
|
|
store.openTaskInEditorLocation(task.id);
|
|
},
|
|
{ task, questions: questions.slice(0, count), theme },
|
|
);
|
|
const card = page.getByRole("form", { name: "Plan the change" });
|
|
await expect(card).toBeVisible();
|
|
const submit = card.getByRole("button", { name: "Submit", exact: true });
|
|
await expect(submit).toBeDisabled();
|
|
if (count === 1) {
|
|
await expect(card.getByRole("tablist")).toHaveCount(0);
|
|
await expect(card.getByRole("button", { name: "Next", exact: true })).toHaveCount(0);
|
|
await card.getByRole("radio", { name: /^Table/ }).check();
|
|
await expect(submit).toBeEnabled();
|
|
await card.getByRole("radio", { name: /^Other/ }).check();
|
|
await card.getByPlaceholder("Type your answer").fill("Custom layout");
|
|
await page.keyboard.press("Enter");
|
|
await expect(page.locator("html")).toHaveAttribute(
|
|
"data-question-answer",
|
|
JSON.stringify({ [questions[0]!.question]: ["Custom layout"] }),
|
|
);
|
|
return;
|
|
}
|
|
const tabs = card.getByRole("tab");
|
|
await expect(tabs).toHaveCount(3);
|
|
await expect(card.getByRole("button", { name: "Next", exact: true })).toBeInViewport({ ratio: 1 });
|
|
const initial = await card.boundingBox();
|
|
await tabs.first().focus();
|
|
await page.keyboard.press("ArrowRight");
|
|
await expect(tabs.nth(1)).toBeFocused();
|
|
await expect(tabs.nth(1)).toHaveAttribute("aria-selected", "true");
|
|
await page.keyboard.press("Tab");
|
|
await expect(card.getByRole("tabpanel", { name: "Checks" })).toBeFocused();
|
|
await expect(card.getByRole("tabpanel")).toHaveCount(1);
|
|
await expect(card.getByText("| check | result |", { exact: true })).toBeHidden();
|
|
const geometry = await card.evaluate((el) => ({
|
|
width: el.clientWidth,
|
|
scroll: el.scrollWidth,
|
|
panelWidth: el.querySelector('[role="tabpanel"][aria-hidden="false"]')!.clientWidth,
|
|
panelScroll: el.querySelector('[role="tabpanel"][aria-hidden="false"]')!.scrollWidth,
|
|
}));
|
|
expect(geometry.scroll).toBe(geometry.width);
|
|
expect(geometry.panelScroll).toBe(geometry.panelWidth);
|
|
await card.getByRole("checkbox", { name: /^LongOption/ }).check();
|
|
const panels = card.getByRole("tabpanel", { name: "Checks" }).locator("..");
|
|
await panels.evaluate((el) => (el.scrollTop = el.scrollHeight));
|
|
await expect(tabs.nth(1)).toBeInViewport({ ratio: 1 });
|
|
await card.getByRole("button", { name: "Next", exact: true }).click();
|
|
await expect(card.getByRole("tabpanel", { name: "Delivery" })).toBeFocused();
|
|
expect(
|
|
await card
|
|
.getByRole("tabpanel", { name: "Delivery" })
|
|
.locator("..")
|
|
.evaluate((el) => el.scrollTop),
|
|
).toBe(0);
|
|
await card.getByRole("radio", { name: /^Today/ }).check();
|
|
await card.getByRole("button", { name: "Previous", exact: true }).click();
|
|
await expect(card.getByRole("tabpanel", { name: "Checks" })).toBeFocused();
|
|
await expect(card.getByRole("checkbox", { name: /^LongOption/ })).toBeChecked();
|
|
await tabs.nth(1).focus();
|
|
await page.keyboard.press("Home");
|
|
await expect(tabs.first()).toBeFocused();
|
|
await page.keyboard.press("Tab");
|
|
await expect(card.getByRole("tabpanel", { name: "Layout" })).toBeFocused();
|
|
await page.keyboard.press("1");
|
|
await expect(card.getByRole("radio", { name: /^Table/ })).toBeChecked();
|
|
await expect(submit).toBeEnabled();
|
|
expect((await card.boundingBox())!.height).toBeCloseTo(initial!.height, 0);
|
|
await submit.focus();
|
|
await page.keyboard.press("Enter");
|
|
await expect(page.locator("html")).toHaveAttribute(
|
|
"data-question-answer",
|
|
JSON.stringify({
|
|
[questions[0]!.question]: ["Table"],
|
|
[questions[1]!.question]: [questions[1]!.options[0]!.label],
|
|
[questions[2]!.question]: ["Today"],
|
|
}),
|
|
);
|
|
});
|
|
}
|
|
}
|
|
}
|