@zyro-sec/session-ui 0.0.0-stage → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/AGENTS.md +25 -0
  2. package/bunfig.toml +2 -0
  3. package/component-tests/basic-tool.fixture.tsx +46 -0
  4. package/component-tests/basic-tool.spec.ts +63 -0
  5. package/component-tests/file-media.fixture.tsx +39 -0
  6. package/component-tests/file-media.spec.ts +13 -0
  7. package/component-tests/file-tool.spec.ts +62 -0
  8. package/component-tests/file-viewer.fixture.tsx +109 -0
  9. package/component-tests/file-viewer.spec.ts +134 -0
  10. package/component-tests/file.spec.ts +33 -0
  11. package/component-tests/line-comment-v2.spec.ts +15 -0
  12. package/component-tests/markdown-code-wrap.spec.ts +94 -0
  13. package/component-tests/markdown-readiness.spec.ts +95 -0
  14. package/component-tests/markdown.fixture.tsx +104 -0
  15. package/component-tests/markdown.spec.ts +1564 -0
  16. package/component-tests/mermaid-preview.spec.ts +43 -0
  17. package/component-tests/patch-group.spec.ts +79 -0
  18. package/component-tests/read-group.spec.ts +72 -0
  19. package/component-tests/read-image.fixture.tsx +66 -0
  20. package/component-tests/read-image.spec.ts +154 -0
  21. package/component-tests/session-compaction.spec.ts +254 -0
  22. package/component-tests/session-lifecycle.spec.ts +190 -0
  23. package/component-tests/session-message-projection.spec.ts +639 -0
  24. package/component-tests/session-notice-projection.spec.ts +20 -0
  25. package/component-tests/session-review-comments.spec.ts +179 -0
  26. package/component-tests/session-shell.spec.ts +93 -0
  27. package/component-tests/session-timeline-mobile.spec.ts +201 -0
  28. package/component-tests/session-timeline-notices.spec.ts +38 -0
  29. package/component-tests/session-timeline-reasoning.spec.ts +107 -0
  30. package/component-tests/session-timeline.spec.ts +157 -0
  31. package/component-tests/session-tool-projection.spec.ts +323 -0
  32. package/component-tests/text-lifecycle.fixture.tsx +26 -0
  33. package/component-tests/text-lifecycle.spec.ts +42 -0
  34. package/component-tests/timeline-subagent-rows.spec.ts +33 -0
  35. package/component-tests/tool-disclosure.spec.ts +48 -0
  36. package/component-tests/tool-group-sticky.spec.ts +37 -0
  37. package/component-tests/tool-group.spec.ts +290 -0
  38. package/component-tests/tool-status-title.fixture.tsx +22 -0
  39. package/component-tests/tool-status-title.spec.ts +30 -0
  40. package/component-tests/user-message-quotes.spec.ts +111 -0
  41. package/package.json +91 -4
  42. package/playwright.components.config.ts +4 -0
  43. package/playwright.local.config.ts +2 -0
  44. package/src/actions.ts +54 -0
  45. package/src/components/apply-patch-file.ts +122 -0
  46. package/src/components/basic-tool.css +487 -0
  47. package/src/components/basic-tool.tsx +258 -0
  48. package/src/components/copy-machine.ts +78 -0
  49. package/src/components/copy.ts +85 -0
  50. package/src/components/diagram-preview.tsx +28 -0
  51. package/src/components/disclosure-machine.ts +188 -0
  52. package/src/components/disclosure.ts +129 -0
  53. package/src/components/dock-prompt.stories.tsx +73 -0
  54. package/src/components/dock-prompt.tsx +29 -0
  55. package/src/components/file-comment-selection.tsx +146 -0
  56. package/src/components/file-media-machine.ts +165 -0
  57. package/src/components/file-media.stories.tsx +112 -0
  58. package/src/components/file-media.tsx +323 -0
  59. package/src/components/file-search.tsx +73 -0
  60. package/src/components/file.css +59 -0
  61. package/src/components/file.tsx +1300 -0
  62. package/src/components/image-preview.tsx +35 -0
  63. package/src/components/line-comment-annotations.tsx +580 -0
  64. package/src/components/line-comment-machine.ts +262 -0
  65. package/src/components/line-comment-styles.ts +293 -0
  66. package/src/components/line-comment.stories.tsx +152 -0
  67. package/src/components/line-comment.tsx +448 -0
  68. package/src/components/link-segments.ts +20 -0
  69. package/src/components/linked-text.tsx +21 -0
  70. package/src/components/markdown-cache-machine.ts +257 -0
  71. package/src/components/markdown-cache.tsx +556 -0
  72. package/src/components/markdown-clipboard.ts +101 -0
  73. package/src/components/markdown-code-machine.ts +200 -0
  74. package/src/components/markdown-code-state.ts +22 -0
  75. package/src/components/markdown-fragment-links.ts +74 -0
  76. package/src/components/markdown-github.svg +3 -0
  77. package/src/components/markdown-globe.svg +5 -0
  78. package/src/components/markdown-image-machine.ts +170 -0
  79. package/src/components/markdown-image.ts +156 -0
  80. package/src/components/markdown-inline-code-kind.ts +39 -0
  81. package/src/components/markdown-mermaid.ts +18 -0
  82. package/src/components/markdown-phase-machine.ts +102 -0
  83. package/src/components/markdown-projection.ts +13 -0
  84. package/src/components/markdown-session-links.ts +183 -0
  85. package/src/components/markdown-solid.test.tsx +92 -0
  86. package/src/components/markdown-solid.tsx +113 -0
  87. package/src/components/markdown-stream.ts +95 -0
  88. package/src/components/markdown-worker-machine.ts +516 -0
  89. package/src/components/markdown-worker-protocol.ts +73 -0
  90. package/src/components/markdown-worker.ts +250 -0
  91. package/src/components/markdown.css +672 -0
  92. package/src/components/markdown.stories.tsx +199 -0
  93. package/src/components/markdown.tsx +1612 -0
  94. package/src/components/markdown.worker.ts +188 -0
  95. package/src/components/message-file.ts +102 -0
  96. package/src/components/message-nav.css +134 -0
  97. package/src/components/message-nav.tsx +159 -0
  98. package/src/components/message-part.css +2109 -0
  99. package/src/components/message-part.tsx +3 -0
  100. package/src/components/question-prompt-experimental.css +576 -0
  101. package/src/components/question-prompt.css +527 -0
  102. package/src/components/quote-highlight.css +59 -0
  103. package/src/components/review-focus-driver.ts +142 -0
  104. package/src/components/review-focus-machine.ts +95 -0
  105. package/src/components/session-compaction.css +270 -0
  106. package/src/components/session-diff.ts +358 -0
  107. package/src/components/session-error.tsx +41 -0
  108. package/src/components/session-retry.tsx +92 -0
  109. package/src/components/session-review-machine.ts +241 -0
  110. package/src/components/session-review.css +264 -0
  111. package/src/components/session-review.stories.tsx +232 -0
  112. package/src/components/session-review.tsx +733 -0
  113. package/src/components/session-turn.css +282 -0
  114. package/src/components/shell-submessage.css +24 -0
  115. package/src/components/timeline-separator.tsx +69 -0
  116. package/src/components/tool-count-label.css +57 -0
  117. package/src/components/tool-count-label.tsx +76 -0
  118. package/src/components/tool-count-summary.css +102 -0
  119. package/src/components/tool-count-summary.stories.tsx +99 -0
  120. package/src/components/tool-count-summary.tsx +44 -0
  121. package/src/components/tool-error-card.css +178 -0
  122. package/src/components/tool-error-card.stories.tsx +113 -0
  123. package/src/components/tool-error-card.tsx +202 -0
  124. package/src/components/tool-status-title-machine.ts +128 -0
  125. package/src/components/tool-status-title.css +89 -0
  126. package/src/components/tool-status-title.tsx +163 -0
  127. package/src/context/data.tsx +107 -0
  128. package/src/context/index.ts +1 -0
  129. package/src/context/markdown.tsx +129 -0
  130. package/src/context/sources.tsx +34 -0
  131. package/src/document.ts +8 -0
  132. package/src/file-presentation.ts +34 -0
  133. package/src/message/action-machine.ts +72 -0
  134. package/src/message/agent-label.ts +3 -0
  135. package/src/message/attachment-card.css +119 -0
  136. package/src/message/attachment-card.tsx +40 -0
  137. package/src/message/attachment-media-machine.ts +213 -0
  138. package/src/message/comment-card.tsx +155 -0
  139. package/src/message/compaction-entrance-machine.ts +93 -0
  140. package/src/message/current-message.tsx +157 -0
  141. package/src/message/current-tool-state.ts +161 -0
  142. package/src/message/message-content.tsx +1391 -0
  143. package/src/message/paced-text-machine.ts +73 -0
  144. package/src/message/prompt-message.stories.tsx +149 -0
  145. package/src/message/relative-time.ts +45 -0
  146. package/src/message/user-message-quote-parts.ts +16 -0
  147. package/src/message/user-message-quotes.stories.tsx +797 -0
  148. package/src/message/user-message-quotes.tsx +135 -0
  149. package/src/pierre/comment-hover-machine.ts +53 -0
  150. package/src/pierre/comment-hover.ts +131 -0
  151. package/src/pierre/comment-selection-machine.ts +257 -0
  152. package/src/pierre/commented-lines.ts +106 -0
  153. package/src/pierre/diff-selection.ts +91 -0
  154. package/src/pierre/file-find-machine.ts +323 -0
  155. package/src/pierre/file-find.ts +537 -0
  156. package/src/pierre/file-runtime.ts +42 -0
  157. package/src/pierre/file-selection.ts +140 -0
  158. package/src/pierre/index.ts +344 -0
  159. package/src/pierre/media.ts +140 -0
  160. package/src/pierre/render-machine.ts +381 -0
  161. package/src/pierre/selection-bridge.ts +82 -0
  162. package/src/pierre/selection-machine.ts +198 -0
  163. package/src/pierre/virtualizer.ts +114 -0
  164. package/src/pierre/worker.ts +46 -0
  165. package/src/sources/experiment.ts +59 -0
  166. package/src/sources/site-icon.tsx +53 -0
  167. package/src/sources/sources-chip.tsx +57 -0
  168. package/src/sources/sources-expand-machine.ts +101 -0
  169. package/src/sources/sources-panel.tsx +249 -0
  170. package/src/sources/sources-title.tsx +21 -0
  171. package/src/sources/sources.css +266 -0
  172. package/src/sources/sources.ts +141 -0
  173. package/src/storybook/current-session-fixtures.ts +1492 -0
  174. package/src/storybook/current-session-scenarios.ts +76 -0
  175. package/src/storybook/current-session-story.tsx +154 -0
  176. package/src/storybook/index.ts +43 -0
  177. package/src/styles/index.css +19 -0
  178. package/src/timeline/__snapshots__/group-labels.test.ts.snap +110 -0
  179. package/src/timeline/__snapshots__/placement.test.ts.snap +1041 -0
  180. package/src/timeline/code-blocks.stories.tsx +105 -0
  181. package/src/timeline/commentary.stories.tsx +70 -0
  182. package/src/timeline/commentary.ts +38 -0
  183. package/src/timeline/detail.ts +111 -0
  184. package/src/timeline/error-card.stories.tsx +134 -0
  185. package/src/timeline/error-spacing.stories.tsx +71 -0
  186. package/src/timeline/facts.ts +493 -0
  187. package/src/timeline/file-changes.stories.tsx +436 -0
  188. package/src/timeline/group-label-fixtures.ts +97 -0
  189. package/src/timeline/mermaid.stories.tsx +131 -0
  190. package/src/timeline/place.ts +280 -0
  191. package/src/timeline/placement-fixtures.ts +365 -0
  192. package/src/timeline/placement-reactivity.ts +133 -0
  193. package/src/timeline/projection.ts +1261 -0
  194. package/src/timeline/research-and-agents.stories.tsx +461 -0
  195. package/src/timeline/session-timeline-row.tsx +1675 -0
  196. package/src/timeline/session-timeline.tsx +68 -0
  197. package/src/timeline/steer-arrival-machine.ts +134 -0
  198. package/src/timeline/terminal-work.stories.tsx +464 -0
  199. package/src/timeline/timeline-row.stories.tsx +1069 -0
  200. package/src/timeline/timeline-row.ts +238 -0
  201. package/src/timeline/turn-phase-machine.ts +112 -0
  202. package/src/timeline/user-message-fold.stories.tsx +194 -0
  203. package/src/timeline/user-runs.ts +87 -0
  204. package/src/timeline-next/__snapshots__/placement.test.ts.snap +990 -0
  205. package/src/timeline-next/compaction.tsx +236 -0
  206. package/src/timeline-next/errors.ts +101 -0
  207. package/src/timeline-next/event-row.tsx +168 -0
  208. package/src/timeline-next/events.ts +103 -0
  209. package/src/timeline-next/index.ts +10 -0
  210. package/src/timeline-next/nested-rail.ts +125 -0
  211. package/src/timeline-next/projection.ts +1028 -0
  212. package/src/timeline-next/row.tsx +1728 -0
  213. package/src/timeline-next/rules.ts +89 -0
  214. package/src/timeline-next/separator.tsx +73 -0
  215. package/src/timeline-next/spacing.ts +127 -0
  216. package/src/timeline-next/status-line.tsx +41 -0
  217. package/src/timeline-next/status.ts +33 -0
  218. package/src/timeline-next/stories/compare-renderer.stories.tsx +190 -0
  219. package/src/timeline-next/stories/compare-sessions/.gitignore +3 -0
  220. package/src/timeline-next/stories/compare.stories.tsx +486 -0
  221. package/src/timeline-next/stories/playground.stories.tsx +297 -0
  222. package/src/timeline-next/stories/session-replay.ts +1156 -0
  223. package/src/timeline-next/stories/session-timeline.tsx +50 -0
  224. package/src/timeline-next/stories/subagent-status.stories.tsx +132 -0
  225. package/src/timeline-next/timeline-next.css +649 -0
  226. package/src/timeline-next/tools/__snapshots__/activity-label.test.ts.snap +39 -0
  227. package/src/timeline-next/tools/activity-label.ts +166 -0
  228. package/src/timeline-next/tools/assistant-content.tsx +84 -0
  229. package/src/timeline-next/tools/context-group.tsx +619 -0
  230. package/src/timeline-next/tools/error-card.tsx +147 -0
  231. package/src/timeline-next/tools/explore.tsx +119 -0
  232. package/src/timeline-next/tools/file-group.tsx +128 -0
  233. package/src/timeline-next/tools/patch.tsx +174 -0
  234. package/src/timeline-next/tools/shell.tsx +186 -0
  235. package/src/timeline-next/tools/thought.tsx +87 -0
  236. package/src/timeline-next/tools/tool-display.tsx +119 -0
  237. package/src/tools/ansi.ts +8 -0
  238. package/src/tools/context-group-label.ts +123 -0
  239. package/src/tools/file-runs.ts +35 -0
  240. package/src/tools/project-path.ts +18 -0
  241. package/src/tools/read-group.stories.tsx +159 -0
  242. package/src/tools/run-machine.ts +185 -0
  243. package/src/tools/shell-output-machine.ts +233 -0
  244. package/src/tools/shell-output.ts +91 -0
  245. package/src/tools/subagent-row-variants.stories.tsx +129 -0
  246. package/src/tools/tool-group.stories.tsx +345 -0
  247. package/src/tools/tool-renderer.tsx +2876 -0
  248. package/src/v2/components/line-comment-annotations-v2.tsx +215 -0
  249. package/src/v2/components/session-file-panel-v2.tsx +149 -0
  250. package/src/v2/components/session-progress-indicator-v2.css +5 -0
  251. package/src/v2/components/session-progress-indicator-v2.stories.tsx +86 -0
  252. package/src/v2/components/session-progress-indicator-v2.tsx +16 -0
  253. package/src/v2/components/session-review-empty-changes-v2.tsx +17 -0
  254. package/src/v2/components/session-review-empty-no-git-v2.tsx +28 -0
  255. package/src/v2/components/session-review-file-preview-v2-virtualize.ts +5 -0
  256. package/src/v2/components/session-review-file-preview-v2.tsx +266 -0
  257. package/src/v2/components/session-review-v2.css +653 -0
  258. package/src/v2/components/session-review-v2.tsx +422 -0
  259. package/src/v2/components/sidebar-presence-machine.ts +69 -0
  260. package/tsconfig.json +20 -0
  261. package/README.md +0 -3
package/AGENTS.md ADDED
@@ -0,0 +1,25 @@
1
+ ## Localization
2
+
3
+ - NEVER hardcode user-visible English strings in production code. ALWAYS use an i18n key for visible copy, placeholders, accessible labels, tooltips, menus, dialogs, empty states, and displayed errors.
4
+ - Feature work adds English source strings only. Leave non-English keys absent so the runtime English fallback applies; translations land separately after language review.
5
+ - Render count-sensitive copy through `i18n.plural(baseKey, count, params)`. Never select or pass `.zero`, `.one`, `.two`, `.few`, `.many`, or `.other` variants to `i18n.t(...)`; `pluralForm(...)` is reserved for components that animate individual grammatical forms.
6
+ - When migrating existing copy to i18n, preserve the English text byte-for-byte unless the task explicitly requests a copy change.
7
+ - NEVER change existing English text or English keys to facilitate translation. English is intentional, designer-written source copy; adapt locale-specific translations and i18n mechanics around it.
8
+ - Do not translate from model knowledge alone. Verify terminology and grammar with Unicode CLDR locale/plural data, Microsoft Localization Style Guides and terminology, Apple localization/style guidance and localized platform UI, Mozilla localization style guides, Mozilla Pontoon, and the Firefox localization corpus at `github.com/mozilla-l10n/firefox-l10n`.
9
+ - Also use the relevant language authority or official dictionary for the locale (for example RAE/Fundéu, FranceTerme, Duden, TDK, Kotus/Kielitoimiston sanakirja, Språkrådet/Bokmålsordboka, Rada Języka Polskiego/PWN, the Russian and Arabic language academies, the Ukrainian Orthography, Taiwan MOE dictionaries, or the Royal Society of Thailand). Treat the English dictionary as the semantic source of truth and preserve placeholders, code identifiers, product names, and keyboard labels.
10
+
11
+ ## State
12
+
13
+ - Lifecycles follow the State Machines section of `packages/app/AGENTS.md`: one union, a pure `transition`, buttons and panels derived from selectors, and every action settling its attempt whether the host call returns, rejects or throws. Precedent: `src/message/action-machine.ts`.
14
+
15
+ ## Timeline stability
16
+
17
+ - Everything here renders in timeline rows. Follow the Timeline stability section of `packages/app/AGENTS.md`: a `:has()` selector on anything that can contain rows ends at the `:has()` element, `:has()` never selects on `style`, and code that moves focus in a row passes `preventScroll: true` unless the reader must see that control next.
18
+
19
+ ## Typography
20
+
21
+ - Use `--line-height-compact` (`16px`) for `13px` transcript, tool, notice, and truncation text. Use `--line-height-base` (`20px`) for body text.
22
+ - Never copy Figma's generated `leading-none` onto text. Inter descenders clip when a solid `13px` line box meets `overflow: hidden`, `overflow: clip`, or truncation.
23
+ - Keep fixed row dimensions explicit; correct inner line metrics do not require transforms, negative margins, or paint-space compensation.
24
+ - `TextShimmer` inherits font metrics, so put typography overrides on its parent.
25
+ - Fonts follow the Fonts section of `packages/app/AGENTS.md`. Commands, code and paths shown as code use the code font with the timeline shell metrics; never write a literal family or add font files here.
package/bunfig.toml ADDED
@@ -0,0 +1,2 @@
1
+ [test]
2
+ preload = ["../ui/test/solid-jsx.ts"]
@@ -0,0 +1,46 @@
1
+ import { render } from "solid-js/web"
2
+ import { createStore } from "solid-js/store"
3
+ import { BasicTool } from "../src/components/basic-tool"
4
+
5
+ export { getCachedMarkdown } from "../src/components/markdown-cache"
6
+
7
+ export function mountBasicTool() {
8
+ const host = document.createElement("div")
9
+ host.dataset.testid = "basic-tool-fixture"
10
+ document.body.appendChild(host)
11
+ render(() => {
12
+ const [state, setState] = createStore({ label: "Initial title", titles: 0, details: 0 })
13
+
14
+ function Title() {
15
+ // Count construction, including JSX created by unused trigger getter reads.
16
+ setState("titles", (value) => value + 1)
17
+
18
+ return <span title={state.label}>{state.label}</span>
19
+ }
20
+
21
+ function Details() {
22
+ setState("details", (value) => value + 1)
23
+
24
+ return <p>Tool details</p>
25
+ }
26
+
27
+ return (
28
+ <>
29
+ <output data-testid="trigger-constructions">{state.titles}</output>
30
+ <output data-testid="detail-mounts">{state.details}</output>
31
+ <input
32
+ aria-label="Trigger label"
33
+ value={state.label}
34
+ onInput={(event) => setState("label", event.currentTarget.value)}
35
+ />
36
+ <BasicTool icon="glasses" hasContent trigger={<Title />}>
37
+ <Details />
38
+ </BasicTool>
39
+ <BasicTool icon="glasses" trigger={{ title: state.label, subtitle: "Tool subtitle", args: ["path=src"] }} />
40
+ <BasicTool icon="glasses" trigger={(open) => <span>Function: {open() ? "open" : "closed"}</span>}>
41
+ <p>Function details</p>
42
+ </BasicTool>
43
+ </>
44
+ )
45
+ }, host)
46
+ }
@@ -0,0 +1,63 @@
1
+ import { expect, sourceURL, story } from "../../stories/playwright/story"
2
+
3
+ const fixture = sourceURL(new URL("./basic-tool.fixture.tsx", import.meta.url))
4
+
5
+ story("does not render completed reasoning until it is opened", async ({ mount, page }) => {
6
+ const root = await mount("current-session-timeline-rows--conversation", {
7
+ args: { scenario: "reasoning", mode: "compact", text: "Response after reasoning" },
8
+ })
9
+
10
+ const reasoning = root.locator('[data-timeline-part-id="msg_projection_assistant:reasoning:0"]')
11
+ const trigger = reasoning.locator('[data-slot="collapsible-trigger"]')
12
+ await expect(trigger).toHaveAttribute("aria-expanded", "false")
13
+ await expect(reasoning.locator('[data-component="markdown"]')).toHaveCount(0)
14
+
15
+ const cached = () =>
16
+ page.evaluate(async (fixture) => {
17
+ const { getCachedMarkdown } = await import(fixture)
18
+
19
+ return !!getCachedMarkdown("msg_projection_assistant:reasoning:0:0:full")
20
+ }, fixture)
21
+
22
+ expect(await cached()).toBe(false)
23
+ await trigger.click()
24
+ await expect(
25
+ reasoning.getByText("I will inspect the timeline before changing its state.", { exact: true }),
26
+ ).toBeVisible()
27
+ expect(await cached()).toBe(true)
28
+ })
29
+
30
+ story("constructs declared tool details lazily and keeps trigger contracts reactive", async ({ mount, page }) => {
31
+ await mount("components-markdown--compact-result")
32
+ await page.evaluate(async (fixture) => {
33
+ const { mountBasicTool } = await import(fixture)
34
+ mountBasicTool()
35
+ }, fixture)
36
+ const root = page.getByTestId("basic-tool-fixture")
37
+ await expect(root.getByRole("button", { name: "Initial title", exact: true })).toHaveAttribute(
38
+ "aria-expanded",
39
+ "false",
40
+ )
41
+ await expect(root.getByTestId("detail-mounts")).toHaveText("0")
42
+ await expect(root.getByTestId("trigger-constructions")).toHaveText("1")
43
+
44
+ await root.getByLabel("Trigger label").fill("Updated title")
45
+ await expect(root.getByTitle("Updated title", { exact: true })).toHaveText("Updated title")
46
+ await expect(root.getByTestId("trigger-constructions")).toHaveText("1")
47
+ await expect(root.getByRole("button", { name: /Tool subtitle/ })).toHaveAccessibleName(
48
+ /Updated title\s*Tool subtitle\s*path=src/,
49
+ )
50
+ await root.getByRole("button", { name: "Updated title", exact: true }).click()
51
+ await expect(root.getByText("Tool details", { exact: true })).toBeVisible()
52
+ await expect(root.getByTestId("detail-mounts")).toHaveText("1")
53
+
54
+ await root.getByRole("button", { name: "Function: closed", exact: true }).click()
55
+ await expect(root.getByText("Function details", { exact: true })).toBeVisible()
56
+ await root.getByRole("button", { name: "Function: open", exact: true }).click()
57
+ await expect(root.getByText("Function details", { exact: true })).toBeHidden()
58
+ await expect(root.getByRole("button", { name: "Function: closed", exact: true })).toHaveAttribute(
59
+ "aria-expanded",
60
+ "false",
61
+ )
62
+ await expect(root.getByTestId("trigger-constructions")).toHaveText("1")
63
+ })
@@ -0,0 +1,39 @@
1
+ import { createSignal } from "solid-js"
2
+ import { render } from "solid-js/web"
3
+ import { FileMedia } from "../src/components/file-media"
4
+ import type { PresentationFileContent } from "../src/file-presentation"
5
+
6
+ // A 160x96 picture, large enough to see in a screenshot.
7
+ const png =
8
+ "iVBORw0KGgoAAAANSUhEUgAAAKAAAABgCAYAAACaJ3mZAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAMuSURBVHhe7dK7jRwxEADRC0y5KhOFI1u2nD1AwMqo/Q3ZJJufMp6zd9NsztTX7z9/b1KWL/4gjWSASmWASmWASmWASmWASmWASmWASmWASmWASmWASmWASmWAh7r9+vERn+nBAA/E0N7hs60Z4EEYVwnOasUAD8KoSnBWKwZ4CAZVgzNbMMADMKQIzo4ywAMwogjOjjLAAzCiCM6OMsADMKIIzo4ywM0xoCjOjzLAAzCiCM6OMsADMKIIzo4ywAMwogjOjjLAAzCiCM6OMsBDMKQanNmCAR6EQZXgrFYM8CCMqgRntWKAB2Jc7/DZ1gzwUAztGT7TgwEqlQEqlQEqlQEqlQEqlQEqlQEqlQEqlQEq1TYBfv28/cPfNbctArzHZ4TrWT5AxmeEa1k6QEb3DJ/RXJYNkKG9w2c1jyUDZGBXcIbmsFyADKsU5ynXUgEyplqcqzzLBMiIojhfOY4N8I7naKwlAmQ0rfG8Xaxwv+kDZCy98NyV8W4z32/qAPkSR+AOq+F9Zr/btAHy5Y3EXVbAO7zC57JNGSBfWgbuNDPu/gmfzzRdgHxZ2bjfTLhrCc7KMlWAfEmz4J4z4I41ODPDNAHy5cyG+2bhXhGcncEAC3HvkbhLCzxjtCkC5EuZHffvjee3xvNGSg+QL2MVvEcvPLcXnjtKaoB8CSvinVrhOSNwhxHSAuTlV8a7RXH+SNylt5QAeekd8I41ODML9+ppeIC87G5436s4Jxv362VogLzkrnjvd/jsLLhnL8MC5AV3x/s/w2dmw317GBIgL3YSvovV3gd3b80AB1j9XfB7ttQ9QF5Ga+J3baVrgLyE1sbv20K3ALm89sDvHNUlQC6tffBbRzUPkAtrP/zmEU0D5KLaF799rWYBckHtjw3UaBIgF9M52EIpA1QYeygRDpDL6Ezs4qpQgFxCZ2MfV1QHyMMlNnJFVYA8WLpjK58UB8gDJWIz7xQFyIOkV9jOK5cD5AHSJ2zomUsBcrB0FVsiA1R37KkoQA6TarCrSwFyiFSLbX0MkAOkKDb2MkA+KLXy0NrDD08eklp6GSD/UerlIUD+g9Tb/wD5B2mUb+KUZjdSnrb+AAAAAElFTkSuQmCC"
9
+
10
+ const [read, setRead] = createSignal<() => Promise<PresentationFileContent | undefined>>(() =>
11
+ Promise.resolve({ type: "binary", content: png, encoding: "base64", mimeType: "image/png" }),
12
+ )
13
+
14
+ export const controls = {
15
+ /** New media options re-read the same file, as a diff or comment refresh does. Settles once the read has failed. */
16
+ refreshFailing: () =>
17
+ new Promise<void>((settled) =>
18
+ setRead(() => () => {
19
+ const failed = Promise.reject(new Error("read failed"))
20
+ // The viewer handles the rejection in microtasks; the next task runs after it.
21
+ failed.catch(() => setTimeout(settled))
22
+
23
+ return failed
24
+ }),
25
+ ),
26
+ }
27
+
28
+ /** A remote image whose first read succeeds. */
29
+ export function mountFileMedia() {
30
+ const host = document.createElement("div")
31
+ host.dataset.testid = "file-media-fixture"
32
+ document.body.appendChild(host)
33
+ render(
34
+ () => (
35
+ <FileMedia media={{ mode: "auto", path: "diagram.png", readFile: read() }} fallback={() => <div>fallback</div>} />
36
+ ),
37
+ host,
38
+ )
39
+ }
@@ -0,0 +1,13 @@
1
+ import { expect, sourceURL, story } from "../../stories/playwright/story"
2
+
3
+ const fixture = sourceURL(new URL("./file-media.fixture.tsx", import.meta.url))
4
+
5
+ story("keeps a loaded image when re-reading the same file fails", async ({ mount, page }) => {
6
+ await mount("components-markdown--compact-result")
7
+ await page.evaluate(async (fixture) => (await import(fixture)).mountFileMedia(), fixture)
8
+ const root = page.getByTestId("file-media-fixture")
9
+ await expect(root.getByRole("img", { name: "diagram.png" })).toBeVisible()
10
+
11
+ await page.evaluate(async (fixture) => (await import(fixture)).controls.refreshFailing(), fixture)
12
+ await expect(root.getByRole("img", { name: "diagram.png" })).toBeVisible()
13
+ })
@@ -0,0 +1,62 @@
1
+ import { expect, story } from "../../stories/playwright/story"
2
+
3
+ story("keeps grouped file choices when the Used group reopens", async ({ mount }) => {
4
+ const root = await mount("current-session-research-agents--agent-research", { args: { scenario: "workflow" } })
5
+ const group = root.locator('[data-component="collapsed-tool-group"]').filter({ hasText: "Patch" })
6
+ const disclosure = group.getByRole("button", { name: /^Used \d+ .*Edit.*Write.*Patch$/ })
7
+ await disclosure.click()
8
+
9
+ const files = group.locator(
10
+ '[data-timeline-part-ids="tool_family_edit,tool_family_write,tool_family_write_extra,tool_family_patch"] [data-slot="accordion-item"]',
11
+ )
12
+
13
+ await expect(files).toHaveCount(3)
14
+
15
+ for (const file of await files.all()) {
16
+ const trigger = file.locator('[data-slot="accordion-trigger"]')
17
+ await expect(trigger).toHaveAttribute("aria-expanded", "false")
18
+ await expect(file.locator('[data-component="file"]')).toHaveCount(0)
19
+ await trigger.click()
20
+ await expect(file.getByRole("region")).toBeVisible()
21
+ }
22
+
23
+ await disclosure.click()
24
+ await disclosure.click()
25
+ await expect(files).toHaveCount(3)
26
+
27
+ for (const file of await files.all()) {
28
+ await expect(file.locator('[data-slot="accordion-trigger"]')).toHaveAttribute("aria-expanded", "true")
29
+ await expect(file.getByRole("region")).toBeVisible()
30
+ }
31
+ })
32
+
33
+ for (const tool of ["edit", "write"]) {
34
+ story(`${tool} preserves input fallback and disclosure through completion`, async ({ mount }) => {
35
+ const root = await mount("current-session-file-changes--file-tool-fallbacks", { args: { tool } })
36
+ const file = root.getByRole("button", { name: /example\.ts/ })
37
+ await expect(file).toHaveAttribute("aria-expanded", "false")
38
+ await file.click()
39
+ await expect(root.locator('[data-component="file"]')).toContainText(tool === "edit" ? "after" : "written")
40
+ await root.getByRole("button", { name: "Complete file tool" }).click()
41
+ await expect(root.getByText("Example diagnostic")).toBeVisible()
42
+ await expect(file).toHaveAttribute("aria-expanded", "true")
43
+ await file.click()
44
+ await expect(file).toHaveAttribute("aria-expanded", "false")
45
+ await expect(root.getByText("Example diagnostic")).toBeVisible()
46
+ })
47
+ }
48
+
49
+ // Product regression from 010cd6131e: an empty write renders no file row. Remove `fail` once it is fixed.
50
+ story.fail("empty writes still show a file row", async ({ mount }) => {
51
+ const root = await mount("current-session-file-changes--file-tool-fallbacks", {
52
+ args: { tool: "write", empty: true },
53
+ })
54
+
55
+ await root.getByRole("button", { name: "Complete file tool" }).click()
56
+ const file = root.getByRole("button", { name: /example\.ts/ })
57
+ await expect(file).toHaveAttribute("aria-expanded", "false")
58
+ await file.click()
59
+ await expect(file).toHaveAttribute("aria-expanded", "true")
60
+ await expect(root.locator('[data-component="file"]')).toBeAttached()
61
+ await expect(file).toBeVisible()
62
+ })
@@ -0,0 +1,109 @@
1
+ import { render } from "solid-js/web"
2
+ import { createSignal } from "solid-js"
3
+ import type { SelectedLineRange } from "@pierre/diffs"
4
+ import { File } from "../src/components/file"
5
+ import { normalize } from "../src/components/session-diff"
6
+
7
+ const source = (lines: number, revision = 0) =>
8
+ Array.from(
9
+ { length: lines },
10
+ (_, index) => `const value${index} = ${index % 10 === 0 ? index + revision : index}\n`,
11
+ ).join("")
12
+
13
+ const [overflow, setOverflow] = createSignal<"wrap" | "scroll">("wrap")
14
+
15
+ const [contents, setContents] = createSignal("")
16
+
17
+ const [selected, setSelected] = createSignal<SelectedLineRange | null>(null)
18
+
19
+ const [commented, setCommented] = createSignal<SelectedLineRange[]>([])
20
+
21
+ let first: Element | null = null
22
+
23
+ const ends: (SelectedLineRange | null)[] = []
24
+
25
+ const comments: SelectedLineRange[] = []
26
+
27
+ export const controls = {
28
+ setOverflow,
29
+ setSelected,
30
+ setCommented,
31
+ /** Every range `onLineSelectionEnd` reported, in order. */
32
+ ends: () => ends.map((range) => (range ? { start: range.start, end: range.end } : null)),
33
+ /** Every range the Add comment toolbar reported, in order. */
34
+ comments: () => comments.map((range) => ({ start: range.start, end: range.end })),
35
+ append: (line: string) => setContents((value) => value + line),
36
+ // Keep the first Pierre host so a later check can tell an in-place update from a rebuild.
37
+ keepHost: () => (first = document.querySelector("[data-testid='file-viewer-fixture'] diffs-container")),
38
+ sameHost: () =>
39
+ first !== null && first === document.querySelector("[data-testid='file-viewer-fixture'] diffs-container"),
40
+ clearDiff: () => {},
41
+ /** The inline min-height the viewer pins on its container while a draw replaces rows. */
42
+ pinnedHeight: () =>
43
+ document.querySelector<HTMLElement>("[data-testid='file-viewer-fixture'] div:has(> diffs-container)")?.style
44
+ .minHeight,
45
+ }
46
+
47
+ function host() {
48
+ const element = document.createElement("div")
49
+ element.dataset.testid = "file-viewer-fixture"
50
+ element.style.cssText =
51
+ "position: fixed; inset: 0 auto auto 0; z-index: 1; width: 800px; height: 400px; overflow: auto"
52
+ document.body.appendChild(element)
53
+
54
+ return element
55
+ }
56
+
57
+ export function mountTextViewer(lines: number) {
58
+ setContents(source(lines))
59
+ render(
60
+ () => (
61
+ <File
62
+ mode="text"
63
+ file={{ name: "a.ts", contents: contents() }}
64
+ overflow={overflow()}
65
+ enableLineSelection
66
+ selectedLines={selected()}
67
+ commentedLines={commented()}
68
+ onLineSelectionEnd={(range) => ends.push(range)}
69
+ onCommentSelection={(range) => comments.push(range)}
70
+ />
71
+ ),
72
+ host(),
73
+ )
74
+ }
75
+
76
+ /** A plain diff of `lines` lines; `controls.clearDiff()` then makes both sides identical, which draws no rows. */
77
+ export function mountChangingDiff(lines: number) {
78
+ const [after, setAfter] = createSignal(source(lines, 1))
79
+ controls.clearDiff = () => setAfter(source(lines))
80
+ render(
81
+ () => (
82
+ <File
83
+ mode="diff"
84
+ fileDiff={
85
+ normalize({ file: "a.ts", before: source(lines), after: after(), additions: 0, deletions: 0 }).fileDiff
86
+ }
87
+ diffStyle="unified"
88
+ />
89
+ ),
90
+ host(),
91
+ )
92
+ }
93
+
94
+ export function mountDiffViewer(lines: number) {
95
+ const view = normalize({ file: "a.ts", before: source(lines), after: source(lines, 1), additions: 0, deletions: 0 })
96
+ render(
97
+ () => (
98
+ <File
99
+ mode="diff"
100
+ fileDiff={view.fileDiff}
101
+ diffStyle="unified"
102
+ expandUnchanged
103
+ enableLineSelection
104
+ selectedLines={selected()}
105
+ />
106
+ ),
107
+ host(),
108
+ )
109
+ }
@@ -0,0 +1,134 @@
1
+ import { expect, sourceURL, story } from "../../stories/playwright/story"
2
+
3
+ const fixture = sourceURL(new URL("./file-viewer.fixture.tsx", import.meta.url))
4
+
5
+ story("updates a text file in place when its props change", async ({ mount, page }) => {
6
+ await mount("components-markdown--compact-result")
7
+ await page.evaluate(async (fixture) => (await import(fixture)).mountTextViewer(40), fixture)
8
+ const root = page.getByTestId("file-viewer-fixture")
9
+ await expect(root.locator('[data-line="40"]')).toHaveCount(1)
10
+ await page.evaluate(async (fixture) => (await import(fixture)).controls.keepHost(), fixture)
11
+
12
+ await page.evaluate(async (fixture) => (await import(fixture)).controls.setOverflow("scroll"), fixture)
13
+ await expect(root.locator('pre[data-overflow="scroll"]')).toHaveCount(1)
14
+ await page.evaluate(async (fixture) => (await import(fixture)).controls.append("const appended = true\n"), fixture)
15
+ await expect(root.locator('[data-line="41"]')).toContainText("appended")
16
+
17
+ expect(await page.evaluate(async (fixture) => (await import(fixture)).controls.sameHost(), fixture)).toBe(true)
18
+ })
19
+
20
+ story("windows a medium text file and keeps selection and comment marks", async ({ mount, page }) => {
21
+ await mount("components-markdown--compact-result")
22
+ await page.evaluate(async (fixture) => (await import(fixture)).mountTextViewer(480), fixture)
23
+ const root = page.getByTestId("file-viewer-fixture")
24
+ await expect(root.locator('[data-line="1"]')).toBeInViewport()
25
+ expect(await root.locator("[data-line]").count()).toBeLessThan(200)
26
+
27
+ await page.evaluate(async (fixture) => {
28
+ const { controls } = await import(fixture)
29
+ controls.setSelected({ start: 3, end: 5 })
30
+ controls.setCommented([{ start: 8, end: 8 }])
31
+ }, fixture)
32
+ await expect(root.locator("[data-line][data-selected-line]")).toHaveCount(3)
33
+ await expect(root.locator('[data-line="8"][data-comment-selected]')).toHaveCount(1)
34
+
35
+ // File links jump by setting the scroll offset from the line number; the window must follow it.
36
+ await root.evaluate((element) => (element.scrollTop = (400 - 4) * 24))
37
+ await expect(root.locator('[data-line="400"]')).toBeInViewport()
38
+ })
39
+
40
+ story(
41
+ "selects text when dragging over the code and lines when dragging over the line numbers",
42
+ async ({ mount, page }) => {
43
+ await mount("components-markdown--compact-result")
44
+ await page.evaluate(async (fixture) => (await import(fixture)).mountTextViewer(40), fixture)
45
+ const root = page.getByTestId("file-viewer-fixture")
46
+ await expect(root.locator('[data-line="40"]')).toHaveCount(1)
47
+ const ends = () => page.evaluate(async (fixture) => (await import(fixture)).controls.ends(), fixture)
48
+
49
+ const from = await root.locator('[data-line="3"]').boundingBox()
50
+ const to = await root.locator('[data-line="6"]').boundingBox()
51
+
52
+ if (!from || !to) throw new Error("lines 3 and 6 have no layout")
53
+ await page.mouse.move(from.x + 8, from.y + from.height / 2)
54
+ await page.mouse.down()
55
+ await page.mouse.move(to.x + 40, to.y + to.height / 2, { steps: 6 })
56
+ await page.mouse.up()
57
+ await expect(page.getByRole("toolbar", { name: "Selection actions" })).toBeVisible()
58
+
59
+ const first = await root.locator('[data-column-number="8"]').boundingBox()
60
+ const last = await root.locator('[data-column-number="10"]').boundingBox()
61
+
62
+ if (!first || !last) throw new Error("line numbers 8 and 10 have no layout")
63
+ await page.mouse.move(first.x + first.width / 2, first.y + first.height / 2)
64
+ await page.mouse.down()
65
+ await page.mouse.move(last.x + last.width / 2, last.y + last.height / 2, { steps: 4 })
66
+ await page.mouse.up()
67
+ await expect(root.locator("[data-line][data-selected-line]")).toHaveCount(3)
68
+ // The text drag ended no line selection.
69
+ await expect.poll(ends).toEqual([{ start: 8, end: 10 }])
70
+ },
71
+ )
72
+
73
+ story("comments on the lines a selection covers, not the next one it ends at", async ({ mount, page }) => {
74
+ await mount("components-markdown--compact-result")
75
+ await page.evaluate(async (fixture) => (await import(fixture)).mountTextViewer(40), fixture)
76
+ const root = page.getByTestId("file-viewer-fixture")
77
+ const add = page.getByRole("toolbar", { name: "Selection actions" }).getByRole("button", { name: "Add comment" })
78
+ await expect(root.locator('[data-line="40"]')).toHaveCount(1)
79
+
80
+ // A triple click selects line 3 up to the start of line 4.
81
+ await root.locator('[data-line="3"]').click({ clickCount: 3 })
82
+ await expect(add).toBeVisible()
83
+ const line = await root.locator('[data-line="3"]').boundingBox()
84
+ const toolbar = await page.getByRole("toolbar", { name: "Selection actions" }).boundingBox()
85
+
86
+ if (!line || !toolbar) throw new Error("line 3 or the toolbar has no layout")
87
+ // A one-line selection gets the toolbar above it, not below the next line.
88
+ expect(toolbar.y + toolbar.height).toBeLessThanOrEqual(line.y)
89
+ await add.click()
90
+
91
+ // A drag that starts past the end of line 7 selects only its line break, so it comments from line 8.
92
+ const from = await root.locator('[data-line="7"]').boundingBox()
93
+ const to = await root.locator('[data-line="9"]').boundingBox()
94
+
95
+ if (!from || !to) throw new Error("lines 7 and 9 have no layout")
96
+ await page.mouse.move(from.x + from.width - 4, from.y + from.height / 2)
97
+ await page.mouse.down()
98
+ await page.mouse.move(to.x + 40, to.y + to.height / 2, { steps: 6 })
99
+ await page.mouse.up()
100
+ await add.click()
101
+ await expect
102
+ .poll(() => page.evaluate(async (fixture) => (await import(fixture)).controls.comments(), fixture))
103
+ .toEqual([
104
+ { start: 3, end: 3 },
105
+ { start: 8, end: 9 },
106
+ ])
107
+ })
108
+
109
+ story("releases the pinned height when a diff becomes empty", async ({ mount, page }) => {
110
+ await mount("components-markdown--compact-result")
111
+ await page.evaluate(async (fixture) => (await import(fixture)).mountChangingDiff(40), fixture)
112
+ const root = page.getByTestId("file-viewer-fixture")
113
+ await expect(root.locator('[data-line-type="change-addition"]').first()).toBeVisible()
114
+ const pinned = () => page.evaluate(async (fixture) => (await import(fixture)).controls.pinnedHeight(), fixture)
115
+ await expect.poll(pinned).toBe("")
116
+
117
+ await page.evaluate(async (fixture) => (await import(fixture)).controls.clearDiff(), fixture)
118
+ await expect(root.locator('[data-line-type="change-addition"]')).toHaveCount(0)
119
+ await expect.poll(pinned).toBe("")
120
+ })
121
+
122
+ story("scrolls a virtualized diff to an off-screen selection", async ({ mount, page }) => {
123
+ await mount("components-markdown--compact-result")
124
+ await page.evaluate(async (fixture) => (await import(fixture)).mountDiffViewer(480), fixture)
125
+ const root = page.getByTestId("file-viewer-fixture")
126
+ await expect(root.locator('[data-line="1"]').first()).toBeVisible()
127
+ await expect(root.locator('[data-line="400"]')).toHaveCount(0)
128
+
129
+ await page.evaluate(
130
+ async (fixture) => (await import(fixture)).controls.setSelected({ start: 400, end: 400, side: "additions" }),
131
+ fixture,
132
+ )
133
+ await expect(root.locator('[data-line="400"][data-selected-line]').first()).toBeInViewport()
134
+ })
@@ -0,0 +1,33 @@
1
+ import { expect, story } from "../../stories/playwright/story"
2
+
3
+ for (const split of [false, true]) {
4
+ for (const theme of ["light", "dark"]) {
5
+ story(`highlights changed words in ${split ? "split" : "unified"} ${theme} diffs`, async ({ mount }) => {
6
+ const root = await mount("components-session-review--inline-changes", { args: { split }, globals: { theme } })
7
+ const diffs = root.locator("diffs-container")
8
+ await expect(diffs).toHaveCount(2)
9
+
10
+ for (const diff of await diffs.all()) {
11
+ await expect(diff.locator('[data-line] [style*="--syntax-"]')).not.toHaveCount(0)
12
+ }
13
+
14
+ const additions = root.locator('[data-line-type="change-addition"] [data-diff-span]')
15
+ await expect(additions).toHaveText(["select-text"])
16
+ await expect(root.locator('[data-line-type="context"] [data-diff-span]')).toHaveCount(0)
17
+ await expect(root.locator('[data-line-type="change-deletion"] [data-diff-span]')).toHaveText([
18
+ '"http" in error.reason ? error.reason.http?.response?.headers["x-should-retry"] : undefined',
19
+ ])
20
+ await expect(additions).not.toHaveCSS("background-color", "rgba(0, 0, 0, 0)")
21
+ })
22
+ }
23
+
24
+ for (const source of ["files", "metadata"]) {
25
+ story(`skips word diffs for large ${split ? "split" : "unified"} ${source}`, async ({ mount }) => {
26
+ const root = await mount("components-session-review--large-file", { args: { split, source } })
27
+ const line = root.locator('[data-line][data-line-type="change-addition"]')
28
+ await expect(line).toHaveText("export const value = 'after'")
29
+ await expect(line.locator('[style*="--syntax-"]')).toHaveCount(0)
30
+ await expect(root.locator("[data-diff-span]")).toHaveCount(0)
31
+ })
32
+ }
33
+ }
@@ -0,0 +1,15 @@
1
+ import { expect, story } from "../../stories/playwright/story"
2
+
3
+ story("renders the line comment cancel action as a ghost button", async ({ mount }) => {
4
+ const root = await mount("ui-line-comment--editor-filled")
5
+ await expect(root.getByRole("button", { name: "Cancel" })).toHaveAttribute("data-variant", "ghost")
6
+ })
7
+
8
+ story("keeps the line breaks of a submitted comment", async ({ mount }) => {
9
+ const root = await mount("ui-line-comment--display-multiline")
10
+ // toHaveText collapses whitespace, so compare the rendered text exactly.
11
+ await expect(root.locator('[data-slot="line-comment-v2-text"]')).toHaveJSProperty(
12
+ "innerText",
13
+ "Consider guarding against empty arrays.\n\nAn early return keeps the happy path flat.",
14
+ )
15
+ })
@@ -0,0 +1,94 @@
1
+ import type { Locator } from "@playwright/test"
2
+ import { expect, story } from "../../stories/playwright/story"
3
+
4
+ story(
5
+ "code blocks offer Wrap only when a line overflows, and a block's choice overrides the setting",
6
+ async ({ mount, page }) => {
7
+ const root = await mount("components-markdown--long-code-lines")
8
+ await expect(root.locator('[data-component="markdown"]')).toHaveAttribute("data-markdown-ready", "")
9
+ const blocks = root.locator('[data-component="markdown-code"]')
10
+ const [shell, ts, short] = [blocks.nth(0), blocks.nth(1), blocks.nth(2)]
11
+ const pre = (block: Locator) => block.locator(":scope > pre")
12
+ const wrapButton = (block: Locator) => block.locator('[data-slot="markdown-wrap-button"] button')
13
+
14
+ await expect(shell).toHaveAttribute("data-code-overflow", "")
15
+ await expect(ts).toHaveAttribute("data-code-overflow", "")
16
+ await expect(short).not.toHaveAttribute("data-code-overflow", "")
17
+ await short.hover()
18
+ await expect(wrapButton(short)).toBeHidden()
19
+
20
+ await shell.hover()
21
+ await wrapButton(shell).click()
22
+ await expect(pre(shell)).toHaveCSS("white-space", "pre-wrap")
23
+ await expect(pre(ts)).toHaveCSS("white-space", "pre")
24
+ // A wrapped block still measures its unwrapped lines, so it keeps the button to unwrap.
25
+ await expect(shell).toHaveAttribute("data-code-overflow", "")
26
+ await expect(wrapButton(shell)).toHaveAccessibleName("Don't wrap lines")
27
+
28
+ await page.getByLabel("Wrap code blocks setting").check()
29
+ await expect(pre(ts)).toHaveCSS("white-space", "pre-wrap")
30
+ await ts.hover()
31
+ await wrapButton(ts).click()
32
+ await expect(pre(ts)).toHaveCSS("white-space", "pre")
33
+ await expect(pre(shell)).toHaveCSS("white-space", "pre-wrap")
34
+
35
+ // Choosing the default again follows the setting from then on.
36
+ await wrapButton(ts).click()
37
+ await page.getByLabel("Wrap code blocks setting").uncheck()
38
+ await expect(pre(ts)).toHaveCSS("white-space", "pre")
39
+ },
40
+ )
41
+
42
+ story("code block actions sit in the block's top corner over the block's own background", async ({ mount, page }) => {
43
+ const root = await mount("components-markdown--long-code-lines")
44
+ await expect(root.locator('[data-component="markdown"]')).toHaveAttribute("data-markdown-ready", "")
45
+ const blocks = root.locator('[data-component="markdown-code"]')
46
+ const toolbar = (block: Locator) => block.locator('[data-slot="markdown-code-toolbar"]')
47
+
48
+ const fill = (block: Locator) =>
49
+ toolbar(block).evaluate((element) => getComputedStyle(element, "::before").backgroundColor)
50
+
51
+ const background = (block: Locator) =>
52
+ block.locator(":scope > pre").evaluate((element) => getComputedStyle(element).backgroundColor)
53
+
54
+ // A shell block and a TypeScript block have different backgrounds; each fill matches its own.
55
+ for (const block of [blocks.nth(0), blocks.nth(1)]) {
56
+ const code = (await block.locator(":scope > pre").boundingBox())!
57
+ await expect(toolbar(block)).toHaveCSS("opacity", "0")
58
+ await page.mouse.move(code.x + 40, code.y + code.height / 2)
59
+ await expect(toolbar(block)).toHaveCSS("opacity", "1")
60
+ const box = (await toolbar(block).boundingBox())!
61
+ expect(box.y).toBeLessThan(code.y + 8)
62
+ expect(code.x + code.width - (box.x + box.width)).toBeLessThan(8)
63
+ expect(await fill(block)).toBe(await background(block))
64
+ }
65
+
66
+ // A clicked button keeps focus, which must not keep the actions shown once the pointer leaves.
67
+ const block = blocks.nth(1)
68
+ await block.getByRole("button", { name: "Copy", exact: true }).click()
69
+ await page.mouse.move(4, 4)
70
+ await expect(toolbar(block)).toHaveCSS("opacity", "0")
71
+
72
+ await page.keyboard.press("Shift+Tab")
73
+ await expect(toolbar(block)).toHaveCSS("opacity", "1")
74
+ })
75
+
76
+ // The fill sits over the block's 0.5px border, and one that reaches the hairline paints over it while hovered.
77
+ story("the fill behind code block actions stays inside the block's border", async ({ mount, page }) => {
78
+ const root = await mount("current-session-code-blocks--long-lines")
79
+ const block = root.locator('[data-component="markdown-code"]').nth(2)
80
+ const toolbar = block.locator('[data-slot="markdown-code-toolbar"]')
81
+ const box = (await block.boundingBox())!
82
+ await page.mouse.move(box.x + 40, box.y + box.height / 2)
83
+ await expect(toolbar).toHaveCSS("opacity", "1")
84
+
85
+ const fill = await toolbar.evaluate((element) => {
86
+ const bar = element.getBoundingClientRect()
87
+ const style = getComputedStyle(element, "::before")
88
+
89
+ return { top: bar.top + parseFloat(style.top), right: bar.right - parseFloat(style.right) }
90
+ })
91
+
92
+ expect(fill.top - box.y).toBeGreaterThanOrEqual(1)
93
+ expect(box.x + box.width - fill.right).toBeGreaterThanOrEqual(1)
94
+ })