* feat(webui): add session-scoped model options Extend the composer preset menu with inherited reasoning effort and Codex Fast mode overrides. Persist choices with ordinary inputs, isolate captured runtimes, and restore browser preferences without changing shared presets. Add regression coverage for pending preset ordering, settings initialization, session and host isolation, queue edits, Codex request mapping, and narrow-screen controls. * feat(webui): refine session model options and add Codex Ultrafast Fit the composer options into a compact single row and preview reasoning effort only during a drag. Add Fast/Ultrafast controls for eligible Codex models, preserve explicit session choices across reloads, and document the speed tiers. * fix(webui): add Codex speed control to the component gallery * fix(webui): preserve saved model options after preset rename Use the session options for display when a browser preference no longer matches the preset. Omit model options from the next message unless the browser has a matching choice, so stale preferences cannot overwrite options the gateway already saved.
231 lines
14 KiB
TypeScript
231 lines
14 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
|
|
for (const width of [390, 1280]) {
|
|
test(`current-chat model options preserve the compact preset menu at ${width}px`, async ({ page }, testInfo) => {
|
|
await page.setViewportSize({ width, height: 900 });
|
|
await page.goto("/browser/fixture.html?case=model-options");
|
|
await page.getByRole("button", { name: "Default", exact: true }).click();
|
|
const dialog = page.getByRole("dialog", { name: "Switch model", exact: true });
|
|
const selected = dialog.getByRole("option", { name: "default", exact: true });
|
|
await expect(selected).toHaveAttribute("aria-selected", "true");
|
|
await dialog.evaluate((element) => Promise.all(element.getAnimations({ subtree: true }).map((animation) => animation.finished)));
|
|
const selectedBefore = await selected.boundingBox();
|
|
const effort = dialog.getByRole("slider", { name: "Reasoning effort" });
|
|
const fast = dialog.getByRole("button", { name: "Fast", exact: true });
|
|
await expect(effort).toHaveAttribute("aria-valuetext", "medium");
|
|
await expect(fast).toHaveAttribute("aria-pressed", "false");
|
|
await effort.press("ArrowRight");
|
|
await expect(effort).toHaveAttribute("aria-valuetext", "high");
|
|
await fast.click();
|
|
await expect(page.getByLabel("Sent model options")).toHaveText("No model options sent");
|
|
const selectedAfter = await selected.boundingBox();
|
|
expect(selectedAfter?.height).toBe(selectedBefore?.height);
|
|
expect(selectedAfter?.x).toBe(selectedBefore?.x);
|
|
const row = (await dialog.locator(".model-options-row").boundingBox())!;
|
|
const list = (await dialog.getByRole("listbox").boundingBox())!;
|
|
expect(Math.abs(row.x - selectedAfter!.x)).toBeLessThan(1);
|
|
expect(Math.abs(row.width - list.width)).toBeLessThan(1);
|
|
const track = (await dialog.locator(".reasoning-effort-track").boundingBox())!;
|
|
const thumb = (await dialog.locator(".reasoning-effort-thumb").boundingBox())!;
|
|
expect(track.height).toBe(20);
|
|
expect(thumb.height).toBe(24);
|
|
const stops = await dialog.locator(".reasoning-effort-tick").evaluateAll((elements) =>
|
|
elements.map((element) => element.getBoundingClientRect().x),
|
|
);
|
|
expect(stops).toHaveLength(5);
|
|
for (let i = 1; i < stops.length; i++) {
|
|
expect(stops[i] - stops[i - 1]).toBeCloseTo(thumb.width);
|
|
}
|
|
const label = (await dialog.getByText("Reasoning effort", { exact: true }).boundingBox())!;
|
|
const icon = (await fast.boundingBox())!;
|
|
const centerY = ({ y, height }: { y: number; height: number }) => y + height / 2;
|
|
expect(label.x + label.width).toBeLessThan(track.x);
|
|
const speedGap = icon.x - track.x - track.width;
|
|
expect(speedGap).toBeGreaterThan(0);
|
|
expect(speedGap).toBeLessThanOrEqual(6);
|
|
expect(row.x + row.width - icon.x - icon.width).toBeLessThanOrEqual(12);
|
|
for (const item of [label, thumb, icon]) {
|
|
expect(Math.abs(centerY(item) - centerY(track))).toBeLessThan(1);
|
|
}
|
|
if (width === 390) {
|
|
expect((await effort.boundingBox())!.height).toBeGreaterThanOrEqual(44);
|
|
expect((await fast.boundingBox())!.height).toBeGreaterThanOrEqual(44);
|
|
expect(selectedBefore!.height).toBeGreaterThanOrEqual(44);
|
|
}
|
|
expect(await dialog.evaluate((element) => element.scrollWidth <= element.clientWidth + 1)).toBe(true);
|
|
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true);
|
|
await page.mouse.move(0, 0);
|
|
await dialog.evaluate((element) => Promise.all(element.getAnimations({ subtree: true }).map((animation) => animation.finished)));
|
|
await page.screenshot({ path: testInfo.outputPath(`model-options-${width}.png`) });
|
|
await dialog.press("Escape");
|
|
await page.getByLabel("Message input").fill("Send with these options");
|
|
await page.getByRole("button", { name: "Send message", exact: true }).click();
|
|
await expect(page.getByLabel("Sent model options")).toHaveText("Reasoning: high; Codex Fast: on");
|
|
await page.reload();
|
|
await page.getByRole("button", { name: "Default", exact: true }).click();
|
|
await expect(effort).toHaveAttribute("aria-valuetext", "high");
|
|
await expect(fast).toHaveAttribute("aria-pressed", "true");
|
|
await dialog.getByRole("option", { name: "Review", exact: true }).click();
|
|
await page.getByRole("button", { name: "Review", exact: true }).click();
|
|
await expect(effort).toHaveAttribute("aria-valuetext", "medium");
|
|
await expect(fast).toHaveAttribute("aria-pressed", "false");
|
|
if (width === 1280) {
|
|
await fast.focus();
|
|
await expect(page.getByRole("tooltip")).toContainText("Faster responses, increased usage.");
|
|
}
|
|
});
|
|
}
|
|
|
|
test("Temporary Chats do not expose model option controls", async ({ page }) => {
|
|
await page.goto("/browser/fixture.html?case=model-options&temporary");
|
|
await page.getByRole("button", { name: "Default", exact: true }).click();
|
|
await expect(page.getByRole("dialog", { name: "Switch model", exact: true })).toBeVisible();
|
|
await expect(page.getByRole("slider", { name: "Reasoning effort" })).toHaveCount(0);
|
|
await expect(page.getByRole("button", { name: "Fast", exact: true })).toHaveCount(0);
|
|
});
|
|
|
|
test("reselecting medium and choosing Ultrafast sends and remembers both concrete values", async ({ page }) => {
|
|
await page.setViewportSize({ width: 320, height: 800 });
|
|
await page.goto("/browser/fixture.html?case=model-options&ultrafast");
|
|
const open = page.getByRole("button", { name: "Default", exact: true });
|
|
await open.click();
|
|
const dialog = page.getByRole("dialog", { name: "Switch model", exact: true });
|
|
const speeds = dialog.getByRole("group", { name: "Fast" });
|
|
const fast = speeds.getByRole("button", { name: "Fast", exact: true });
|
|
const effort = dialog.getByRole("slider", { name: "Reasoning effort" });
|
|
await expect(effort).toHaveAttribute("aria-valuetext", "medium");
|
|
await dialog.evaluate((element) => Promise.all(element.getAnimations({ subtree: true }).map((animation) => animation.finished)));
|
|
const ticks = dialog.locator(".reasoning-effort-tick");
|
|
const medium = (await ticks.nth(2).boundingBox())!;
|
|
const high = (await ticks.nth(3).boundingBox())!;
|
|
const sliderBefore = (await effort.boundingBox())!;
|
|
const speedBounds = (await speeds.boundingBox())!;
|
|
const speedGap = speedBounds.x - sliderBefore.x - sliderBefore.width;
|
|
expect(speedGap).toBeGreaterThan(0);
|
|
expect(speedGap).toBeLessThanOrEqual(6);
|
|
expect(Math.abs(speedBounds.y + speedBounds.height / 2 - sliderBefore.y - sliderBefore.height / 2)).toBeLessThan(1);
|
|
expect(await dialog.evaluate((element) => element.scrollWidth <= element.clientWidth + 1)).toBe(true);
|
|
const startX = medium.x + medium.width / 2;
|
|
const endX = high.x + high.width / 2;
|
|
const y = medium.y + medium.height / 2;
|
|
const hint = page.getByRole("tooltip");
|
|
await page.mouse.move(startX, y);
|
|
await expect(hint).toBeHidden();
|
|
await page.mouse.down();
|
|
await expect(hint).toHaveText("medium");
|
|
const pointerX = startX + 0.7 * (endX - startX);
|
|
await page.mouse.move(pointerX, y, { steps: 5 });
|
|
await expect(hint).toHaveText("high");
|
|
await expect(effort).toHaveAttribute("aria-valuetext", "medium");
|
|
expect(await effort.boundingBox()).toEqual(sliderBefore);
|
|
const thumbCenter = async () => {
|
|
const thumb = (await dialog.locator(".reasoning-effort-thumb").boundingBox())!;
|
|
return thumb.x + thumb.width / 2;
|
|
};
|
|
await expect.poll(async () => Math.abs(await thumbCenter() - pointerX)).toBeLessThan(2);
|
|
await page.mouse.up();
|
|
await expect(hint).toBeHidden();
|
|
await expect(effort).toHaveAttribute("aria-valuetext", "high");
|
|
await expect.poll(async () => Math.abs(await thumbCenter() - endX)).toBeLessThan(1);
|
|
await effort.press("ArrowLeft");
|
|
const ultrafast = speeds.getByRole("button", { name: "Ultrafast" });
|
|
await fast.press("Space");
|
|
await expect(fast).toHaveAttribute("aria-pressed", "true");
|
|
await ultrafast.click();
|
|
await expect(ultrafast).toHaveAttribute("aria-pressed", "true");
|
|
await expect(fast).toHaveAttribute("aria-pressed", "false");
|
|
expect(await speeds.evaluate((group) => [...group.querySelectorAll("button")].every((button) =>
|
|
button.scrollWidth <= button.clientWidth + 1 && button.offsetWidth >= 44 && button.offsetHeight >= 44,
|
|
))).toBe(true);
|
|
await dialog.press("Escape");
|
|
await page.getByLabel("Message input").fill("Test this speed");
|
|
await page.getByRole("button", { name: "Send message", exact: true }).click();
|
|
await expect(page.getByLabel("Sent model options")).toHaveText("Reasoning: medium; Codex Fast: ultrafast");
|
|
await page.reload();
|
|
await open.click();
|
|
await expect(effort).toHaveAttribute("aria-valuetext", "medium");
|
|
await expect(ultrafast).toHaveAttribute("aria-pressed", "true");
|
|
await ultrafast.click();
|
|
await expect(ultrafast).toHaveAttribute("aria-pressed", "false");
|
|
await dialog.press("Escape");
|
|
await page.getByLabel("Message input").fill("Turn fast mode off");
|
|
await page.getByRole("button", { name: "Send message", exact: true }).click();
|
|
await expect(page.getByLabel("Sent model options")).toHaveText("Reasoning: medium; Codex Fast: off");
|
|
});
|
|
|
|
test("provider examples switch from Codex to direct API and gateway capabilities", async ({ page }) => {
|
|
await page.goto("/browser/fixture.html?case=model-options&ultrafast");
|
|
const navigation = page.getByRole("navigation", { name: "Provider examples" });
|
|
await navigation.getByRole("link", { name: "Direct APIs" }).click();
|
|
await page.getByRole("button", { name: "Default", exact: true }).click();
|
|
const dialog = page.getByRole("dialog", { name: "Switch model", exact: true });
|
|
const reasoning = dialog.getByRole("slider", { name: "Reasoning effort" });
|
|
await expect(reasoning).toHaveAttribute("aria-valuetext", "high");
|
|
await expect(dialog.getByRole("button", { name: "Fast", exact: true })).toHaveCount(0);
|
|
await reasoning.press("End");
|
|
await expect(reasoning).toHaveAttribute("aria-valuetext", "max");
|
|
await dialog.evaluate((element) => Promise.all(element.getAnimations({ subtree: true }).map((animation) => animation.finished)));
|
|
const track = (await dialog.locator(".reasoning-effort-track").boundingBox())!;
|
|
const fill = (await dialog.locator(".reasoning-effort-fill").boundingBox())!;
|
|
const thumb = (await dialog.locator(".reasoning-effort-thumb").boundingBox())!;
|
|
expect(thumb.x + thumb.width).toBeGreaterThan(track.x + track.width);
|
|
expect(Math.abs(fill.x + fill.width - thumb.x - thumb.width / 2)).toBeLessThan(1);
|
|
await dialog.press("Escape");
|
|
await page.getByLabel("Message input").fill("Review direct API reasoning options");
|
|
await page.getByRole("button", { name: "Send message", exact: true }).click();
|
|
await expect(page.getByLabel("Sent model options")).toHaveText("Reasoning: max; Codex Fast: unchanged");
|
|
await navigation.getByRole("link", { name: "Gateways" }).click();
|
|
await page.getByRole("button", { name: "Default", exact: true }).click();
|
|
await expect(reasoning).toHaveAttribute("aria-valuetext", "Auto");
|
|
});
|
|
|
|
test("keeps the custom reasoning effort as a concrete value for a self-hosted preset", async ({ page }) => {
|
|
await page.goto("/browser/fixture.html?case=model-options&group=local");
|
|
await page.getByRole("button", { name: "Default", exact: true }).click();
|
|
const dialog = page.getByRole("dialog", { name: "Switch model", exact: true });
|
|
await dialog.getByRole("option", { name: "Custom API", exact: true }).click();
|
|
await page.getByRole("button", { name: "Custom API", exact: true }).click();
|
|
const effort = dialog.getByRole("combobox", { name: "Reasoning effort" });
|
|
await expect(effort.locator("option:checked")).toHaveText("extended");
|
|
await effort.selectOption({ label: "low" });
|
|
await dialog.press("Escape");
|
|
await page.getByLabel("Message input").fill("Review custom API reasoning options");
|
|
await page.getByRole("button", { name: "Send message", exact: true }).click();
|
|
await expect(page.getByLabel("Sent model options")).toHaveText("Reasoning: low; Codex Fast: unchanged");
|
|
});
|
|
|
|
test("touch drag previews the next effort without saving it until release", async ({ page }) => {
|
|
await page.setViewportSize({ width: 320, height: 800 });
|
|
const cdp = await page.context().newCDPSession(page);
|
|
await cdp.send("Emulation.setTouchEmulationEnabled", { enabled: true, maxTouchPoints: 1 });
|
|
await page.goto("/browser/fixture.html?case=model-options&ultrafast&dark");
|
|
await page.getByRole("button", { name: "Default", exact: true }).click();
|
|
const dialog = page.getByRole("dialog", { name: "Switch model", exact: true });
|
|
const effort = dialog.getByRole("slider", { name: "Reasoning effort" });
|
|
await expect(effort).toHaveAttribute("aria-valuetext", "medium");
|
|
await dialog.evaluate((element) => Promise.all(element.getAnimations({ subtree: true }).map((animation) => animation.finished)));
|
|
const ticks = dialog.locator(".reasoning-effort-tick");
|
|
const medium = (await ticks.nth(2).boundingBox())!;
|
|
const high = (await ticks.nth(3).boundingBox())!;
|
|
const startX = medium.x + medium.width / 2;
|
|
const endX = high.x + high.width / 2;
|
|
const y = medium.y + medium.height / 2;
|
|
const touch = (type: "touchStart" | "touchMove" | "touchCancel" | "touchEnd", x?: number) =>
|
|
cdp.send("Input.dispatchTouchEvent", { type, touchPoints: x === undefined ? [] : [{ x, y }] });
|
|
const hint = page.getByRole("tooltip");
|
|
const previewHigh = async () => {
|
|
await touch("touchStart", startX);
|
|
await touch("touchMove", startX + 0.75 * (endX - startX));
|
|
await expect(hint).toHaveText("high");
|
|
await expect(effort).toHaveAttribute("aria-valuetext", "medium");
|
|
};
|
|
await previewHigh();
|
|
await touch("touchCancel");
|
|
await expect(hint).toBeHidden();
|
|
await expect(effort).toHaveAttribute("aria-valuetext", "medium");
|
|
await previewHigh();
|
|
await touch("touchEnd");
|
|
await expect(hint).toBeHidden();
|
|
await expect(effort).toHaveAttribute("aria-valuetext", "high");
|
|
});
|