Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(web): match renderer actions to themes (#1116)

Gener417cd6e92811
diff --git a/scripts/ci/e2e-shards.mjs b/scripts/ci/e2e-shards.mjs
index 71bd200a2..23d7b5e71 100644
--- a/scripts/ci/e2e-shards.mjs
+++ b/scripts/ci/e2e-shards.mjs
@@ -91,6 +91,7 @@ export const SPEC_SECONDS = {
"67-text-sidebar-threads.spec.ts": DEFAULT_SPEC_SECONDS,
"68-bot-memberships.spec.ts": DEFAULT_SPEC_SECONDS,
"69-table-fullscreen-scroll.spec.ts": DEFAULT_SPEC_SECONDS,
+ "70-renderer-action-themes.spec.ts": DEFAULT_SPEC_SECONDS,
}
function walk(directory) {
diff --git a/scripts/ci/e2e-shards.test.ts b/scripts/ci/e2e-shards.test.ts
index d20cf5b4e..763cefccd 100644
--- a/scripts/ci/e2e-shards.test.ts
+++ b/scripts/ci/e2e-shards.test.ts
@@ -75,7 +75,7 @@ describe("planE2eShards", () => {
expect(first).toEqual(second)
expect(Object.keys(SPEC_SECONDS).sort()).toEqual(specs)
- expect(first).toHaveLength(21)
+ expect(first).toHaveLength(22)
expect([...assigned].sort()).toEqual(specs)
expect(new Set(assigned).size).toBe(specs.length)
expect(SPEC_SECONDS["18-new-divider-scroll.spec.ts"]).toBe(DEFAULT_SPEC_SECONDS)
@@ -84,6 +84,9 @@ describe("planE2eShards", () => {
expect(SPEC_SECONDS["66-grouped-message-toolbar.spec.ts"]).toBe(DEFAULT_SPEC_SECONDS)
expect(SPEC_SECONDS["67-text-sidebar-threads.spec.ts"]).toBe(DEFAULT_SPEC_SECONDS)
expect(SPEC_SECONDS["68-bot-memberships.spec.ts"]).toBe(DEFAULT_SPEC_SECONDS)
+ expect(SPEC_SECONDS["70-renderer-action-themes.spec.ts"]).toBe(DEFAULT_SPEC_SECONDS)
+ expect(first.find((shard) => shard.files.includes("70-renderer-action-themes.spec.ts"))?.files)
+ .toEqual(["70-renderer-action-themes.spec.ts"])
expect(SPEC_SECONDS["69-table-fullscreen-scroll.spec.ts"]).toBe(DEFAULT_SPEC_SECONDS)
expect(first.find((shard) => shard.files.includes("69-table-fullscreen-scroll.spec.ts"))?.files)
.toEqual(["69-table-fullscreen-scroll.spec.ts"])
@@ -97,11 +100,11 @@ describe("planE2eShards", () => {
expect(first.find((shard) => shard.files.includes("67-text-sidebar-threads.spec.ts"))?.files)
.toEqual(["67-text-sidebar-threads.spec.ts"])
expect(specSeconds).toEqual([
- 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, 155.638, 154.234, 155.283,
+ 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, 155.638, 154.234, 155.283,
156.095, 155.905, 156.323, 155.711, 153.963, 154.488, 156.138,
])
expect(predictedSeconds).toEqual([
- 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 230.638, 229.234, 230.283,
+ 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 230.638, 229.234, 230.283,
231.095, 230.905, 231.323, 230.711, 228.963, 229.488, 231.138,
])
expect(first.every((shard) => (
diff --git a/src/web/src/app/globals.css b/src/web/src/app/globals.css
index 340d31b28..72318b67f 100644
--- a/src/web/src/app/globals.css
+++ b/src/web/src/app/globals.css
@@ -2431,7 +2431,7 @@ html.dark .blog-content [data-rehype-pretty-code-figure] span {
pointer-events: none !important;
}
-[data-streamdown="code-block"]:hover>div:has([data-streamdown="code-block-actions"]) {
+[data-streamdown="code-block"]:is(:hover, :focus-within)>div:has([data-streamdown="code-block-actions"]) {
pointer-events: auto !important;
}
@@ -2443,11 +2443,11 @@ html.dark .blog-content [data-rehype-pretty-code-figure] span {
opacity: 0;
pointer-events: none;
transition: opacity 150ms ease;
- background: oklch(0.2 0.01 60 / 80%) !important;
+ background: var(--popover) !important;
backdrop-filter: blur(4px);
- border: 1px solid oklch(1 0 0 / 10%) !important;
+ border: 1px solid var(--border) !important;
border-radius: 0.5rem !important;
- color: rgba(255, 255, 255, 0.7) !important;
+ color: var(--popover-foreground) !important;
padding: 0.125rem !important;
gap: 0.125rem !important;
}
@@ -2463,15 +2463,17 @@ html.dark .blog-content [data-rehype-pretty-code-figure] span {
align-items: center !important;
justify-content: center !important;
border-radius: 0.375rem !important;
- color: rgba(255, 255, 255, 0.7) !important;
- transition: color 150ms ease !important;
+ background: transparent !important;
+ color: var(--muted-foreground) !important;
+ transition: color 150ms ease, background-color 150ms ease !important;
}
-[data-streamdown="code-block-actions"] button:hover,
-[data-streamdown="mermaid-block-actions"] button:hover,
-[data-html-preview-actions] button:hover,
-[data-streamdown="table-wrapper"]>div:first-child:not(:has([data-streamdown="table"])) button:hover {
- color: #ffffff !important;
+[data-streamdown="code-block-actions"] button:not(:disabled):is(:hover, :focus-visible),
+[data-streamdown="mermaid-block-actions"] button:not(:disabled):is(:hover, :focus-visible),
+[data-html-preview-actions] button:not(:disabled):is(:hover, :focus-visible),
+[data-streamdown="table-wrapper"]>div:first-child:not(:has([data-streamdown="table"])) button:not(:disabled):is(:hover, :focus-visible) {
+ background: var(--muted) !important;
+ color: var(--foreground) !important;
}
[data-streamdown="code-block-actions"] button svg,
@@ -2502,7 +2504,7 @@ html.dark .blog-content [data-rehype-pretty-code-figure] span {
min-width: 8rem;
width: max-content !important;
overflow: visible !important;
- background: var(--background) !important;
+ background: var(--popover) !important;
border: 1px solid var(--border) !important;
border-radius: var(--radius-md) !important;
color: var(--foreground) !important;
@@ -2522,14 +2524,14 @@ html.dark .blog-content [data-rehype-pretty-code-figure] span {
cursor: pointer !important;
}
-[data-streamdown="code-block-actions"] .absolute button:hover,
-[data-streamdown="mermaid-block-actions"] .absolute button:hover,
-[data-streamdown="table-wrapper"]>div:first-child:not(:has([data-streamdown="table"])) .absolute button:hover {
- background: oklch(1 0 0 / 8%) !important;
+[data-streamdown="code-block-actions"] .absolute button:not(:disabled):is(:hover, :focus-visible),
+[data-streamdown="mermaid-block-actions"] .absolute button:not(:disabled):is(:hover, :focus-visible),
+[data-streamdown="table-wrapper"]>div:first-child:not(:has([data-streamdown="table"])) .absolute button:not(:disabled):is(:hover, :focus-visible) {
+ background: var(--muted) !important;
color: var(--foreground) !important;
}
-[data-streamdown="code-block"]:hover [data-streamdown="code-block-actions"] {
+[data-streamdown="code-block"]:is(:hover, :focus-within) [data-streamdown="code-block-actions"] {
opacity: 1;
pointer-events: auto;
}
@@ -2593,12 +2595,12 @@ html.dark .blog-content [data-rehype-pretty-code-figure] span {
}
/* On hover of the ENTIRE mermaid block: make actions interactive */
-[data-streamdown="mermaid-block"]:hover>div:has([data-streamdown="mermaid-block-actions"]) {
+[data-streamdown="mermaid-block"]:is(:hover, :focus-within)>div:has([data-streamdown="mermaid-block-actions"]) {
pointer-events: auto;
}
/* Mermaid actions: hover reveal */
-[data-streamdown="mermaid-block"]:hover [data-streamdown="mermaid-block-actions"] {
+[data-streamdown="mermaid-block"]:is(:hover, :focus-within) [data-streamdown="mermaid-block-actions"] {
opacity: 1;
pointer-events: auto;
}
@@ -2688,7 +2690,7 @@ html.dark .blog-content [data-rehype-pretty-code-figure] span {
margin: 0 !important;
}
-[data-streamdown="table-wrapper"]:hover>div:first-child:not(:has([data-streamdown="table"])) {
+[data-streamdown="table-wrapper"]:is(:hover, :focus-within)>div:first-child:not(:has([data-streamdown="table"])) {
opacity: 1;
pointer-events: auto;
}
diff --git a/src/web/src/test/e2e-ui/70-renderer-action-themes.spec.ts b/src/web/src/test/e2e-ui/70-renderer-action-themes.spec.ts
new file mode 100644
index 000000000..1b9a82bf4
--- /dev/null
+++ b/src/web/src/test/e2e-ui/70-renderer-action-themes.spec.ts
@@ -0,0 +1,192 @@
+import { readFile } from "node:fs/promises"
+import type { Locator, Page } from "@playwright/test"
+import { test, expect } from "./_fixtures/case-fixture"
+import { gotoAfterUserWsAuth } from "./_fixtures/actions"
+import { confirmCommunityFixtureApiResponse, CURRENT_COMMUNITY_FIXTURE_HEADERS } from "./_fixtures/business-contract"
+import { holdRoute } from "./_fixtures/held-route"
+import { tid } from "./_fixtures/testids"
+
+const HTML = "<!doctype html><html><body><p>Renderer action theme fixture</p></body></html>"
+const TABLE_ACTIONS = ':scope > div:first-child:not(:has([data-streamdown="table"]))'
+
+async function colors(control: Locator, group: Locator) {
+ const palette = await control.evaluate(() => {
+ const reference = document.createElement("span")
+ reference.style.display = "none"
+ document.body.appendChild(reference)
+ try {
+ const read = (name: string) => {
+ reference.style.color = `var(--${name})`
+ return getComputedStyle(reference).color
+ }
+ return { foreground: read("foreground"), mutedForeground: read("muted-foreground"), muted: read("muted"), popover: read("popover") }
+ } finally { reference.remove() }
+ })
+ const button = await control.evaluate(element => {
+ const style = getComputedStyle(element)
+ return { foreground: style.color, background: style.backgroundColor,
+ focused: document.activeElement === element, focusVisible: element.matches(":focus-visible") }
+ })
+ return { palette, button, background: await group.evaluate(element => getComputedStyle(element).backgroundColor) }
+}
+
+async function activeColors(control: Locator, group: Locator) {
+ await expect.poll(async () => {
+ const result = await colors(control, group)
+ return result.button.foreground === result.palette.foreground && result.button.background === result.palette.muted
+ && result.background === result.palette.popover
+ }).toBe(true)
+}
+
+async function inspectControl(page: Page, group: Locator, control: Locator, inline: boolean, block: Locator) {
+ await expect(control).toBeEnabled()
+ await control.scrollIntoViewIfNeeded()
+ await control.evaluate(element => (element as HTMLElement).blur())
+ await page.mouse.move(0, 0)
+ await expect.poll(async () => {
+ const result = await colors(control, group)
+ return result.button.foreground === (inline ? result.palette.mutedForeground : result.palette.foreground)
+ && result.button.background === "rgba(0, 0, 0, 0)"
+ }).toBe(true)
+ if (inline) {
+ await expect(control).toHaveCSS("width", "24px")
+ await expect(control).toHaveCSS("height", "24px")
+ await expect(control.locator("svg")).toHaveCSS("width", "14px")
+ await expect(control.locator("svg")).toHaveCSS("height", "14px")
+ }
+ await block.hover()
+ await control.hover()
+ await expect(group).toHaveCSS("opacity", "1")
+ await activeColors(control, group)
+ const hover = await colors(control, group)
+ await page.mouse.move(0, 0)
+ await page.keyboard.press("Tab")
+ await control.focus()
+ await expect(control).toBeFocused()
+ await expect.poll(() => control.evaluate(element => element.matches(":focus-visible"))).toBe(true)
+ await expect(group).toHaveCSS("opacity", "1")
+ await activeColors(control, group)
+ return { hover, focus: await colors(control, group) }
+}
+
+async function inspectGroup(page: Page, block: Locator, group: Locator, titles: string[]) {
+ await block.scrollIntoViewIfNeeded()
+ await block.hover()
+ await expect(group).toHaveCSS("opacity", "1")
+ await expect(group.getByRole("button")).toHaveCount(titles.length)
+ const results = []
+ for (const title of titles) results.push({ title, ...await inspectControl(page, group, group.getByRole("button", { name: title, exact: true }), true, block) })
+ return results
+}
+
+async function inspectMenu(page: Page, block: Locator, group: Locator, trigger: string, options: string[]) {
+ await group.getByTitle(trigger, { exact: true }).click()
+ const menu = group.locator(".absolute")
+ await expect(menu).toHaveCount(1)
+ await expect(menu.getByRole("button")).toHaveCount(options.length)
+ const results = []
+ for (const title of options) {
+ results.push({ title, ...await inspectControl(page, menu, menu.getByTitle(title, { exact: true }), false, block) })
+ await expect(group).toHaveCSS("opacity", "1")
+ }
+ await group.getByTitle(trigger, { exact: true }).click()
+ await expect(menu).toHaveCount(0)
+ return results
+}
+
+for (const viewport of [{ width: 390, height: 844 }, { width: 834, height: 1112 }, { width: 1280, height: 900 }]) {
+ test(`shared renderer actions use readable theme pairs on hover and focus at ${viewport.width}px`, async ({ caseActors, caseResources }, testInfo) => {
+ test.setTimeout(120_000)
+ const actors = await caseActors(["alice"])
+ const serverId = await actors.seed.seedServer("alice", `Action themes ${Date.now()}`)
+ const channelId = await actors.seed.seedChannel("alice", serverId, "action-themes")
+ const codeId = await actors.seed.seedMessage("alice", channelId, '```javascript\nconsole.log("theme");\n```')
+ const redactedId = await actors.seed.seedMessage("alice", channelId, '```text\nvalue=[REDACTED_SECRET]\n```')
+ const mermaidId = await actors.seed.seedMessage("alice", channelId, "```mermaid\nflowchart LR\nA[Start] --> B[End]\n```")
+ const tableId = await actors.seed.seedMessage("alice", channelId, "| Name | Value |\n| --- | --- |\n| Theme | Readable |")
+ const { page } = await actors.asUser("alice", { viewport, hasTouch: viewport.width < 1280,
+ isMobile: viewport.width === 390, reducedMotion: "reduce", colorScheme: "light" })
+ await gotoAfterUserWsAuth(page, `/c/channels/${serverId}/${channelId}`)
+ await expect.poll(() => page.evaluate(() => localStorage.getItem("theme") || "system")).toBe("system")
+ const upload = await confirmCommunityFixtureApiResponse(page.request.post(`/api/community/channels/${channelId}/attachments`, {
+ headers: CURRENT_COMMUNITY_FIXTURE_HEADERS,
+ multipart: { file: { name: "theme.html", mimeType: "text/html", buffer: Buffer.from(HTML) } },
+ }))
+ expect(upload.status()).toBe(200)
+ const attachmentId = (await upload.json() as { id: string }).id
+ const posted = await confirmCommunityFixtureApiResponse(page.request.post(`/api/community/channels/${channelId}/messages`, {
+ headers: CURRENT_COMMUNITY_FIXTURE_HEADERS,
+ data: { content: `[alook-html-preview](${attachmentId})`, attachments: [attachmentId] },
+ }))
+ expect(posted.status()).toBe(201)
+ const htmlMessageId = (await posted.json() as { message: { id: string } }).message.id
+ const preview = page.getByTestId(tid.message(htmlMessageId)).getByTestId(tid.htmlPreview(attachmentId))
+ await preview.scrollIntoViewIfNeeded()
+ await expect(preview).toHaveAttribute("data-html-preview-status", "ready")
+ const messageWrites: string[] = []
+ page.on("request", request => {
+ if (request.method() !== "GET" && /\/api\/community\/(?:channels\/[^/]+\/messages|messages\/[^/]+)$/.test(new URL(request.url()).pathname)) {
+ messageWrites.push(`${request.method()} ${new URL(request.url()).pathname}`)
+ }
+ })
+ const samples = []
+ for (const mode of ["light", "dark"] as const) {
+ await page.emulateMedia({ colorScheme: mode })
+ await expect.poll(() => page.evaluate(() => ({ media: matchMedia("(prefers-color-scheme: dark)").matches,
+ html: document.documentElement.classList.contains("dark") }))).toEqual({ media: mode === "dark", html: mode === "dark" })
+ for (const [consumer, id] of [["code", codeId], ["redacted", redactedId]] as const) {
+ const block = page.getByTestId(tid.message(id)).locator('[data-streamdown="code-block"]')
+ if (consumer === "redacted") await expect(block.locator("[data-redacted]")).toHaveCount(1)
+ samples.push({ mode, consumer, controls: await inspectGroup(page, block, block.locator('[data-streamdown="code-block-actions"]'), ["Copy Code"]) })
+ }
+ const mermaid = page.getByTestId(tid.message(mermaidId)).locator('[data-streamdown="mermaid-block"]')
+ await mermaid.scrollIntoViewIfNeeded()
+ await expect(mermaid.locator("svg .node")).toHaveCount(2)
+ const mermaidActions = mermaid.locator('[data-streamdown="mermaid-block-actions"]')
+ samples.push({ mode, consumer: "mermaid", controls: await inspectGroup(page, mermaid, mermaidActions, ["Download diagram", "Copy Code", "View fullscreen"]),
+ menu: await inspectMenu(page, mermaid, mermaidActions, "Download diagram", ["Download diagram as SVG", "Download diagram as PNG", "Download diagram as MMD"]) })
+ const table = page.getByTestId(tid.message(tableId)).locator('[data-streamdown="table-wrapper"]')
+ const tableActions = table.locator(TABLE_ACTIONS)
+ samples.push({ mode, consumer: "table", controls: await inspectGroup(page, table, tableActions, ["Copy table", "View fullscreen"]),
+ menu: await inspectMenu(page, table, tableActions, "Copy table", ["Copy table as Markdown", "Copy table as CSV", "Copy table as TSV"]) })
+ await tableActions.getByTitle("View fullscreen", { exact: true }).click()
+ const fullscreen = page.locator('[data-streamdown="table-fullscreen"]')
+ const fullscreenTable = fullscreen.locator('[data-streamdown="table-wrapper"]')
+ const fullscreenActions = fullscreenTable.locator(TABLE_ACTIONS)
+ samples.push({ mode, consumer: "fullscreen-table", controls: await inspectGroup(page, fullscreenTable, fullscreenActions, ["Copy table", "Exit fullscreen"]),
+ menu: await inspectMenu(page, fullscreenTable, fullscreenActions, "Copy table", ["Copy table as Markdown", "Copy table as CSV", "Copy table as TSV"]) })
+ await fullscreenActions.getByTitle("Exit fullscreen", { exact: true }).click()
+ await expect(fullscreen).toHaveCount(0)
+ const htmlActions = preview.getByRole("group", { name: "HTML preview actions" })
+ samples.push({ mode, consumer: "html", controls: await inspectGroup(page, preview, htmlActions, ["Download theme.html"]) })
+ const downloadButton = preview.getByTestId(tid.htmlPreviewDownload(attachmentId))
+ const started = page.waitForEvent("download")
+ await downloadButton.click()
+ const download = await started
+ expect(download.suggestedFilename()).toBe("theme.html")
+ const path = await download.path()
+ expect(path).not.toBeNull()
+ expect(await readFile(path!, "utf8")).toBe(HTML)
+ const originalUrl = new URL(`/api/community/channels/${channelId}/attachments/${attachmentId}`, page.url()).href
+ const held = await holdRoute(page, originalUrl, caseResources)
+ const aborted = page.waitForEvent("requestfailed", { predicate: request => request.url() === originalUrl })
+ try {
+ await downloadButton.click()
+ await expect.poll(held.held).toBe(1)
+ await expect(downloadButton).toHaveAccessibleName("Cancel download")
+ await expect(downloadButton).toHaveAttribute("aria-busy", "true")
+ samples.push({ mode, consumer: "html-cancel", controls: await inspectControl(page, htmlActions, downloadButton, true, preview) })
+ await downloadButton.click()
+ await expect(downloadButton).toHaveAccessibleName("Download theme.html")
+ await expect(downloadButton).toHaveAttribute("aria-busy", "false")
+ } finally { await held.release() }
+ expect((await aborted).failure()?.errorText).toContain("ERR_ABORTED")
+ expect(messageWrites).toEqual([])
+ expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true)
+ }
+ await testInfo.attach(`renderer-actions-${viewport.width}-themes.json`, { body: JSON.stringify({ viewport,
+ input: "mouse hover/click and scripted focus after keyboard Tab; not a complete Tab-entry or pure-touch journey",
+ media: await page.evaluate(() => ({ coarse: matchMedia("(pointer: coarse)").matches, hover: matchMedia("(hover: hover)").matches })),
+ serverId, channelId, codeId, redactedId, mermaidId, tableId, htmlMessageId, attachmentId, messageWrites, samples }), contentType: "application/json" })
+ })
+}