gentle-pi 4.7.0 → 4.8.0

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 (365) hide show
  1. package/README.md +55 -44
  2. package/assets/agents/gentle-ai-explore.md +3 -3
  3. package/assets/agents/gentle-ai-verify.md +20 -6
  4. package/assets/agents/gentle-ai-worker.md +6 -6
  5. package/assets/agents/jd-judge-a.md +1 -3
  6. package/assets/agents/jd-judge-b.md +1 -3
  7. package/assets/agents/review-readability.md +1 -5
  8. package/assets/agents/review-reliability.md +1 -5
  9. package/assets/agents/review-resilience.md +1 -5
  10. package/assets/agents/review-risk.md +1 -5
  11. package/assets/design-canvas/canvas-api.js +45 -0
  12. package/assets/design-canvas/canvas-boards.js +456 -0
  13. package/assets/design-canvas/canvas-boot.js +217 -0
  14. package/assets/design-canvas/canvas-checks.js +491 -0
  15. package/assets/design-canvas/canvas-comments.js +315 -0
  16. package/assets/design-canvas/canvas-compare.js +159 -0
  17. package/assets/design-canvas/canvas-events.js +75 -0
  18. package/assets/design-canvas/canvas-export.js +393 -0
  19. package/assets/design-canvas/canvas-focus.js +203 -0
  20. package/assets/design-canvas/canvas-handoffs.js +150 -0
  21. package/assets/design-canvas/canvas-i18n-es.js +392 -0
  22. package/assets/design-canvas/canvas-i18n.js +108 -0
  23. package/assets/design-canvas/canvas-layout.js +526 -0
  24. package/assets/design-canvas/canvas-menu.js +213 -0
  25. package/assets/design-canvas/canvas-messages.js +86 -0
  26. package/assets/design-canvas/canvas-minimap.js +163 -0
  27. package/assets/design-canvas/canvas-parts.js +401 -0
  28. package/assets/design-canvas/canvas-popover.js +234 -0
  29. package/assets/design-canvas/canvas-rail.js +348 -0
  30. package/assets/design-canvas/canvas-sizes.js +524 -0
  31. package/assets/design-canvas/canvas-store.js +164 -0
  32. package/assets/design-canvas/canvas-tokens.js +674 -0
  33. package/assets/design-canvas/canvas-ui.js +24 -0
  34. package/assets/design-canvas/canvas-view.js +184 -0
  35. package/assets/design-canvas/canvas.css +746 -15
  36. package/assets/design-canvas/canvas.js +2 -1506
  37. package/assets/design-canvas/index.html +117 -36
  38. package/assets/design-canvas/inspector.js +546 -16
  39. package/assets/install-wizard/wizard.js +5 -1
  40. package/assets/migrations/agent-body-history.json +24 -0
  41. package/assets/orchestrator-delegation-reference.md +8 -14
  42. package/assets/orchestrator-delegation.md +4 -4
  43. package/assets/orchestrator-full-delegation-card.md +4 -5
  44. package/assets/orchestrator-full-delegation.md +8 -8
  45. package/assets/orchestrator-memory.md +2 -2
  46. package/assets/orchestrator-prompts.md +1 -1
  47. package/assets/orchestrator-quota-recovery.md +5 -0
  48. package/assets/orchestrator-skills.md +13 -12
  49. package/assets/orchestrator-tracking.md +10 -14
  50. package/assets/orchestrator-verification.md +10 -8
  51. package/assets/orchestrator-writer.md +4 -4
  52. package/assets/orchestrator.md +18 -22
  53. package/bin/gentle-shell.mjs +128 -9
  54. package/contracts/review-provider-contract-mirror/provider-contract.lock.json +8 -9
  55. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/manifest.json +3 -3
  56. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/orchestration/pi.md +1 -0
  57. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/routing/pi.md +6 -6
  58. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/generated/provider-capabilities.baseline.json +3 -3
  59. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/generated/provider-roles.baseline.json +1 -1
  60. package/docs/assets/brand/sponsor-banner.svg +60 -0
  61. package/docs/bundled-install.md +14 -6
  62. package/docs/delegated-verification.md +18 -2
  63. package/docs/desktop-rpc.md +1253 -0
  64. package/docs/gentle-agents-activity.md +26 -0
  65. package/docs/gentle-shell.md +39 -16
  66. package/docs/install-wizard.md +30 -21
  67. package/docs/odd-preparation-continuity.md +24 -0
  68. package/docs/permission-modes.md +9 -1
  69. package/docs/prompt-budget.md +12 -0
  70. package/docs/rdd-odd-friction-triage-2026-11-07.md +57 -0
  71. package/docs/readme-reference.md +76 -24
  72. package/docs/review-coordinator.md +29 -9
  73. package/docs/review-delivery-preflight.md +22 -0
  74. package/docs/work-continuity.md +11 -1
  75. package/extensions/ask-user-question.ts +2 -2
  76. package/extensions/child-context.ts +21 -7
  77. package/extensions/gentle-agents.ts +234 -33
  78. package/extensions/gentle-ai.ts +576 -135
  79. package/extensions/gentle-design.ts +69 -3
  80. package/extensions/gentle-desktop-rpc.ts +143 -0
  81. package/extensions/gentle-guide.ts +3 -0
  82. package/extensions/gentle-shell.ts +105 -52
  83. package/extensions/gentle-todo.ts +48 -25
  84. package/extensions/skill-registry.ts +248 -223
  85. package/lib/agent-assets.ts +30 -6
  86. package/lib/agent-tool-overlay.ts +117 -0
  87. package/lib/agents-config.ts +47 -6
  88. package/lib/agents-message-delivery.ts +17 -0
  89. package/lib/agents-messaging.ts +8 -2
  90. package/lib/agents-protocol.ts +15 -0
  91. package/lib/agents-report-cap.ts +115 -0
  92. package/lib/agents-runner.ts +91 -6
  93. package/lib/agents-session-transport.ts +17 -1
  94. package/lib/background-jobs-tools.ts +9 -4
  95. package/lib/bounded-writer-admission.ts +184 -31
  96. package/lib/child-context-files.ts +21 -6
  97. package/lib/codemode-renderer.ts +1 -0
  98. package/lib/delivery-conflict-markers.ts +349 -0
  99. package/lib/design-canvas-assets.ts +36 -0
  100. package/lib/design-canvas-server.ts +241 -23
  101. package/lib/design-comments.ts +94 -4
  102. package/lib/design-handoffs.ts +2 -1
  103. package/lib/design-layout.ts +125 -0
  104. package/lib/design-parts.ts +281 -0
  105. package/lib/design-system-tokens.ts +111 -0
  106. package/lib/desktop-agents-service.ts +294 -0
  107. package/lib/desktop-design-service.ts +233 -0
  108. package/lib/desktop-jobs-service.ts +263 -0
  109. package/lib/desktop-rpc-agents.ts +294 -0
  110. package/lib/desktop-rpc-config.ts +731 -0
  111. package/lib/desktop-rpc-design.ts +138 -0
  112. package/lib/desktop-rpc-jobs.ts +181 -0
  113. package/lib/desktop-rpc-permissions.ts +177 -0
  114. package/lib/desktop-rpc-profiles.ts +196 -0
  115. package/lib/desktop-rpc-usage.ts +229 -0
  116. package/lib/desktop-rpc.ts +225 -0
  117. package/lib/desktop-usage-service.ts +310 -0
  118. package/lib/destructive-command-guard.ts +188 -13
  119. package/lib/gentle-ai-renderer.ts +13 -1
  120. package/lib/gentle-design.ts +201 -14
  121. package/lib/gentle-shell-bundled.ts +100 -9
  122. package/lib/hidden-tools.ts +35 -0
  123. package/lib/inprocess-reviewer.ts +96 -12
  124. package/lib/model-fallback-policy.ts +9 -0
  125. package/lib/model-routing-authority.ts +9 -0
  126. package/lib/nan-provider.ts +42 -28
  127. package/lib/native-review-cli.ts +79 -4
  128. package/lib/orchestrator-discovery.ts +39 -2
  129. package/lib/reply-language-anchor.ts +27 -2
  130. package/lib/request-context-placement.ts +53 -0
  131. package/lib/review-candidate-view.ts +11 -1
  132. package/lib/review-continuation-registry.ts +17 -0
  133. package/lib/review-coordinator.ts +252 -8
  134. package/lib/review-delivery-preflight.ts +85 -0
  135. package/lib/review-host-relay.ts +5 -1
  136. package/lib/review-integration-v2.ts +56 -3
  137. package/lib/reviewer-stream.ts +87 -0
  138. package/lib/shell-prompt.ts +16 -3
  139. package/lib/shell-usage.ts +10 -0
  140. package/lib/vim-editor-adapter.ts +9 -2
  141. package/lib/writer-batch-admission.ts +55 -0
  142. package/lib/yolo-session-policy.ts +6 -1
  143. package/package.json +2 -2
  144. package/prompts/skill-creation.md +1 -10
  145. package/runtime/design-canvas-assets.mjs +37 -0
  146. package/runtime/gentle-shell-bundled.mjs +100 -9
  147. package/runtime/native-review-cli.mjs +79 -4
  148. package/runtime/review-integration-v2.mjs +56 -3
  149. package/scripts/bootstrap.cmd +2 -2
  150. package/scripts/bootstrap.sh +41 -4
  151. package/scripts/build-full-delegation-card.mjs +4 -0
  152. package/scripts/build-runtime-modules.mjs +1 -0
  153. package/scripts/gentle-ai-installer.mjs +10 -10
  154. package/scripts/gentle-ai-proxy.mjs +1 -1
  155. package/scripts/installer-downloads.mjs +34 -8
  156. package/scripts/installer-preflight.mjs +28 -17
  157. package/scripts/installer-probes.mjs +25 -5
  158. package/scripts/installer-server.mjs +38 -9
  159. package/scripts/installer-windows.mjs +2 -2
  160. package/scripts/pi-update.mjs +166 -27
  161. package/scripts/prepare-verifier.mjs +107 -0
  162. package/scripts/update-agent-body-history.mjs +55 -8
  163. package/scripts/verify-package-files.mjs +40 -19
  164. package/skills/branch-pr/SKILL.md +16 -16
  165. package/skills/comment-writer/SKILL.md +1 -1
  166. package/skills/design/SKILL.md +6 -6
  167. package/skills/gentle-ai/SKILL.md +5 -5
  168. package/skills/judgment-day/SKILL.md +2 -2
  169. package/skills/judgment-day/references/prompts-and-formats.md +1 -1
  170. package/skills/rdd-defect-workflow/SKILL.md +6 -6
  171. package/skills/skill-improver/SKILL.md +2 -2
  172. package/skills/skill-registry/SKILL.md +11 -13
  173. package/skills/tui-design/SKILL.md +1 -1
  174. package/skills/work-unit-commits/SKILL.md +5 -5
  175. package/tests/agent-prompt-diet-contract.test.ts +101 -0
  176. package/tests/agent-tool-overlay-acceptance.test.ts +158 -0
  177. package/tests/agent-tool-overlay.test.ts +89 -0
  178. package/tests/agents-config.test.ts +10 -1
  179. package/tests/agents-message-delivery.test.ts +36 -0
  180. package/tests/agents-queries.test.ts +144 -4
  181. package/tests/agents-report-cap.test.ts +126 -0
  182. package/tests/agents-runner.test.ts +37 -1
  183. package/tests/agents-session-transport.test.ts +34 -0
  184. package/tests/always-on-prompt-verdicts-contract.test.ts +188 -0
  185. package/tests/append-system-prompt-route.test.ts +10 -2
  186. package/tests/approved-text-leftovers-contract.test.ts +136 -0
  187. package/tests/artifact-language.test.ts +1 -1
  188. package/tests/ask-user-question.test.ts +2 -1
  189. package/tests/audit-leftovers-contract.test.ts +51 -0
  190. package/tests/bounded-stop-contract.test.ts +9 -1
  191. package/tests/branch-pr-skill.test.ts +10 -1
  192. package/tests/bundled-install.test.ts +1 -1
  193. package/tests/child-context-files.test.ts +64 -8
  194. package/tests/child-skills-catalog.test.ts +56 -0
  195. package/tests/codemode-rendering.test.ts +4 -1
  196. package/tests/delegate-for-reason-contract.test.ts +30 -8
  197. package/tests/delivery-conflict-markers.test.ts +348 -0
  198. package/tests/design-canvas-all-sizes.test.ts +631 -0
  199. package/tests/design-canvas-allowlist.test.ts +32 -0
  200. package/tests/design-canvas-assets.test.ts +11 -878
  201. package/tests/design-canvas-boards.test.ts +77 -0
  202. package/tests/design-canvas-checks.test.ts +655 -0
  203. package/tests/design-canvas-compare.test.ts +79 -0
  204. package/tests/design-canvas-events.test.ts +59 -0
  205. package/tests/design-canvas-export.test.ts +1168 -0
  206. package/tests/design-canvas-focus.test.ts +113 -0
  207. package/tests/design-canvas-handoffs.test.ts +59 -0
  208. package/tests/design-canvas-i18n-review.test.ts +513 -0
  209. package/tests/design-canvas-i18n-views.test.ts +259 -0
  210. package/tests/design-canvas-i18n.test.ts +526 -0
  211. package/tests/design-canvas-inspector.test.ts +937 -0
  212. package/tests/design-canvas-layout.test.ts +1222 -0
  213. package/tests/design-canvas-minimap.test.ts +413 -0
  214. package/tests/design-canvas-modules.test.ts +90 -0
  215. package/tests/design-canvas-parts.test.ts +721 -0
  216. package/tests/design-canvas-rail.test.ts +799 -0
  217. package/tests/design-canvas-server.test.ts +855 -17
  218. package/tests/design-canvas-sizes.test.ts +548 -0
  219. package/tests/design-canvas-store.test.ts +180 -0
  220. package/tests/design-canvas-tokens.test.ts +965 -0
  221. package/tests/design-canvas-view.test.ts +299 -0
  222. package/tests/design-comments.test.ts +201 -1
  223. package/tests/design-handoffs.test.ts +20 -0
  224. package/tests/design-layout.test.ts +100 -0
  225. package/tests/design-parts.test.ts +260 -0
  226. package/tests/design-system-tokens.test.ts +215 -0
  227. package/tests/desktop-rpc-agents.test.ts +893 -0
  228. package/tests/desktop-rpc-config.test.ts +1452 -0
  229. package/tests/desktop-rpc-design.test.ts +662 -0
  230. package/tests/desktop-rpc-jobs.test.ts +796 -0
  231. package/tests/desktop-rpc-permissions.test.ts +311 -0
  232. package/tests/desktop-rpc-profiles.test.ts +140 -0
  233. package/tests/desktop-rpc-safety.test.ts +119 -0
  234. package/tests/desktop-rpc-usage.test.ts +697 -0
  235. package/tests/desktop-rpc.test.ts +252 -0
  236. package/tests/devbinary/pi-host-relay.devtest.ts +149 -80
  237. package/tests/devbinary/review-session-consent.devtest.ts +84 -0
  238. package/tests/engram-safety.test.ts +111 -0
  239. package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.captured.json +92 -0
  240. package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.provenance.md +3 -0
  241. package/tests/fixtures/primary-session-prompt/gentleman.golden.md +20 -29
  242. package/tests/fixtures/refusal-identity.probe.mjs +139 -0
  243. package/tests/full-delegation-closure.test.ts +29 -0
  244. package/tests/gentle-agents.test.ts +329 -4
  245. package/tests/gentle-ai-binary.test.ts +1 -1
  246. package/tests/gentle-ai-child-guards.test.ts +1 -0
  247. package/tests/gentle-ai-installer.test.ts +52 -51
  248. package/tests/gentle-ai-renderer.test.ts +36 -2
  249. package/tests/gentle-ai.test.ts +121 -6
  250. package/tests/gentle-design.test.ts +365 -1
  251. package/tests/gentle-shell-bundled.test.ts +91 -5
  252. package/tests/gentle-shell-launcher.test.ts +1 -1
  253. package/tests/gentle-shell.test.ts +118 -87
  254. package/tests/gentle-todo.test.ts +32 -9
  255. package/tests/hidden-tools.test.ts +188 -0
  256. package/tests/independent-recovery-delivery.test.ts +19 -5
  257. package/tests/inprocess-reviewer.test.ts +73 -0
  258. package/tests/install-wizard.test.ts +27 -1
  259. package/tests/installer-downloads.test.ts +30 -1
  260. package/tests/installer-posix-bootstrap.test.ts +114 -13
  261. package/tests/installer-preflight.test.ts +49 -1
  262. package/tests/installer-probes.test.ts +146 -0
  263. package/tests/installer-server.test.ts +203 -4
  264. package/tests/installer-windows-bootstrap.test.ts +19 -1
  265. package/tests/judgment-day-severity-admission.test.ts +46 -0
  266. package/tests/lazy-module-contradictions-contract.test.ts +158 -0
  267. package/tests/maintainer/desktop-rpc.maintest.ts +632 -0
  268. package/tests/maintainer/pi-update-source.maintest.ts +48 -18
  269. package/tests/model-fallback-policy.test.ts +26 -7
  270. package/tests/nan-provider-runtime.test.ts +17 -3
  271. package/tests/nan-provider.test.ts +111 -56
  272. package/tests/native-review-capability-contract.test.ts +11 -1
  273. package/tests/native-review-cli-nonblocking-findings.test.ts +165 -0
  274. package/tests/native-review-parity.test.ts +24 -5
  275. package/tests/native-review-refusal-identity.test.ts +25 -0
  276. package/tests/no-self-pause-contract.test.ts +11 -3
  277. package/tests/odd-integration.test.ts +11 -3
  278. package/tests/odd-routing-contract.test.ts +80 -28
  279. package/tests/orchestrator-budget.test.ts +30 -5
  280. package/tests/orchestrator-consultation-sdk.test.ts +32 -6
  281. package/tests/orchestrator-delegation-mode.test.ts +2 -1
  282. package/tests/orchestrator-discovery.test.ts +28 -0
  283. package/tests/orchestrator-prompt-budget.test.ts +11 -2
  284. package/tests/orchestrator-prompt-diet-contract.test.ts +221 -0
  285. package/tests/orchestrator-rdd-ownership.test.ts +2 -1
  286. package/tests/orchestrator-work-search.test.ts +4 -2
  287. package/tests/package-files.test.ts +25 -1
  288. package/tests/package-manifest.test.ts +11 -10
  289. package/tests/parallel-reason-contract.test.ts +6 -3
  290. package/tests/permission-allowlist.test.ts +200 -30
  291. package/tests/persona-neutral-voseo.test.ts +4 -4
  292. package/tests/persona-reply-language.test.ts +1 -1
  293. package/tests/persona-single-channel.test.ts +13 -5
  294. package/tests/pi-update-launcher.test.ts +17 -7
  295. package/tests/pi-update-source.test.ts +113 -6
  296. package/tests/pi-update.test.ts +294 -19
  297. package/tests/pnpm-workspace-policy.test.ts +47 -0
  298. package/tests/primary-context-files.test.ts +233 -0
  299. package/tests/primary-context-three-files.test.ts +174 -0
  300. package/tests/provider-defect-handoff.test.ts +9 -2
  301. package/tests/rdd-aware-verification-contract.test.ts +1 -1
  302. package/tests/rdd-status-line.test.ts +94 -1
  303. package/tests/reply-language-anchor-placement.test.ts +184 -0
  304. package/tests/reply-language-anchor.test.ts +17 -1
  305. package/tests/request-context-append-only.test.ts +218 -0
  306. package/tests/request-context-placement.test.ts +148 -0
  307. package/tests/review-agent-end-preflight.test.ts +79 -1
  308. package/tests/review-candidate-view.test.ts +65 -0
  309. package/tests/review-continuation-registry.test.ts +31 -0
  310. package/tests/review-contract-prompt.test.ts +1 -1
  311. package/tests/review-controller.test.ts +2 -1
  312. package/tests/review-coordinator-correction-gate.test.ts +105 -0
  313. package/tests/review-coordinator-findings.test.ts +206 -0
  314. package/tests/review-coordinator-nonblocking-scope.test.ts +169 -0
  315. package/tests/review-coordinator.test.ts +271 -4
  316. package/tests/review-delivery-preflight.test.ts +462 -0
  317. package/tests/review-due-compaction.test.ts +31 -0
  318. package/tests/review-due-public-boundary.test.ts +26 -0
  319. package/tests/review-integration-nonblocking-findings.test.ts +108 -0
  320. package/tests/review-json-arguments.test.ts +41 -2
  321. package/tests/review-ledger-contract.test.ts +19 -40
  322. package/tests/review-loadout-rdd-off-sdk.test.ts +30 -1
  323. package/tests/review-one-call-findings.test.ts +131 -0
  324. package/tests/review-one-call-followups.test.ts +308 -0
  325. package/tests/review-one-call-reviewer-requests.test.ts +207 -0
  326. package/tests/review-one-call.test.ts +452 -0
  327. package/tests/review-relay-transport-agent.test.ts +28 -1
  328. package/tests/review-reviewer-evidence.test.ts +41 -1
  329. package/tests/review-risk-assessment.test.ts +52 -5
  330. package/tests/review-run-statement-guidance-independent.test.ts +54 -0
  331. package/tests/review-session-standing-permission-controller.test.ts +32 -2
  332. package/tests/review-tool-prose-budget.test.ts +1 -0
  333. package/tests/reviewer-stream.test.ts +149 -0
  334. package/tests/session-profile-extension.test.ts +2 -2
  335. package/tests/shell-prompt.test.ts +17 -0
  336. package/tests/shell-usage.test.ts +59 -10
  337. package/tests/skill-contradictions-contract.test.ts +122 -0
  338. package/tests/skill-registry-watcher.test.ts +216 -2
  339. package/tests/skill-registry.test.ts +929 -306
  340. package/tests/support/design-canvas-dom.ts +369 -0
  341. package/tests/support/review-coordinator-runtime.ts +212 -17
  342. package/tests/task-size-routing-contract.test.ts +42 -11
  343. package/tests/test-strength-contract.test.ts +2 -1
  344. package/tests/todo-request-append-only.test.ts +214 -0
  345. package/tests/tool-batching-contract.test.ts +3 -1
  346. package/tests/update-agent-body-history.test.ts +138 -0
  347. package/tests/verification-tiers-contract.test.ts +229 -0
  348. package/tests/verifier-preparation.test.ts +229 -0
  349. package/tests/verify-agent-contract.test.ts +20 -2
  350. package/tests/verify-first-launch-contract.test.ts +87 -11
  351. package/tests/vim-editor-adapter.test.ts +2 -2
  352. package/tests/work-continuity-contract.test.ts +54 -11
  353. package/tests/writer-admission-messages.test.ts +232 -0
  354. package/tests/writer-batch-admission.test.ts +66 -0
  355. package/tests/writer-edit-surface-scope.test.ts +52 -20
  356. package/tests/writer-feature-document-admission.test.ts +184 -0
  357. package/tests/yolo-mode.test.ts +39 -0
  358. package/skills/_shared/review-ledger-contract.md +0 -106
  359. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/README.md +0 -0
  360. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/lens.schema.json +0 -0
  361. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/refuter.schema.json +0 -0
  362. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/targeted-validator.schema.json +0 -0
  363. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/lens.json +0 -0
  364. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/refuter.json +0 -0
  365. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/targeted-validator.json +0 -0
@@ -0,0 +1,548 @@
1
+ import assert from "node:assert/strict";
2
+ import { readFileSync } from "node:fs";
3
+ import test from "node:test";
4
+ import { fileURLToPath } from "node:url";
5
+ import { click, findAll, inspectorPick, loadCanvas, read, texts, withClass, type FakeElement } from "./support/design-canvas-dom.ts";
6
+
7
+ // Screen sizes in focus mode (canvas-sizes.js): the top bar's device button and its menu
8
+ // (Phone, Tablet, Desktop and a custom width), the focused artboard's frame at that size,
9
+ // and the focus geometry it needs (canvas-focus.js): 8 px margins, a 48 px band for Back to
10
+ // canvas, Desktop as wide as the window. Every assertion compares strings, numbers or
11
+ // booleans, never fake elements, which node:assert would walk whole on a failure.
12
+
13
+ /** First artboard 1200 x 800 so Desktop is wider than the 1000 px test viewport. */
14
+ const WIDE_ALPHA = { "/t/api/designs/alpha": { slug: "alpha", title: "Alpha", brief: "", artboards: [
15
+ { file: "01-a.html", title: "First", tradeoff: "", width: 1200, height: 800 },
16
+ { file: "02-b.html", title: "Second", tradeoff: "", width: 400, height: 300 },
17
+ ] } };
18
+
19
+ async function loadSizes(replies: Record<string, unknown> = {}, firstHeight = 300) {
20
+ const canvas = await loadCanvas(firstHeight, replies);
21
+ // The fake DOM starts every element visible; index.html starts these hidden.
22
+ for (const id of ["gd-popover", "gd-menu", "gd-device-menu"]) canvas.document.getElementById(id).hidden = true;
23
+ return canvas;
24
+ }
25
+ type Canvas = Awaited<ReturnType<typeof loadSizes>>;
26
+
27
+ const $ = (canvas: Canvas, id: string) => canvas.document.getElementById(id);
28
+ const focusOn = (canvas: Canvas, index = 0) => click(canvas.boards[index].shield!, 200, 200);
29
+ const back = (canvas: Canvas) => $(canvas, "gd-back").dispatch("click");
30
+ const tallViewport = (canvas: Canvas) => { canvas.viewport.rect = { left: 0, top: 50, width: 1000, height: 1400 }; };
31
+ const keyOn = (target: FakeElement, key: string) => target.dispatch("keydown", { key, shiftKey: false });
32
+ const isActive = (canvas: Canvas, element: FakeElement | undefined) => canvas.document.activeElement === element;
33
+
34
+ const deviceButton = (canvas: Canvas) => $(canvas, "gd-device");
35
+ const deviceMenu = (canvas: Canvas) => $(canvas, "gd-device-menu");
36
+ const deviceItems = (canvas: Canvas) => findAll(deviceMenu(canvas), (element) => element.getAttribute("role") === "menuitemradio");
37
+ const openDevices = (canvas: Canvas) => { if (deviceMenu(canvas).hidden) deviceButton(canvas).dispatch("click"); };
38
+ const chooseSize = (canvas: Canvas, size: string) => {
39
+ openDevices(canvas);
40
+ deviceItems(canvas).find((item) => item.dataset.size === size)!.dispatch("click");
41
+ };
42
+ /** The checked items of the device menu, read with the menu open, then closed again when it was closed. */
43
+ const pressedSizes = (canvas: Canvas) => {
44
+ const closed = deviceMenu(canvas).hidden;
45
+ openDevices(canvas);
46
+ const sizes = deviceItems(canvas).filter((item) => item.getAttribute("aria-checked") === "true").map((item) => item.dataset.size);
47
+ if (closed) deviceButton(canvas).dispatch("click");
48
+ return sizes;
49
+ };
50
+ /** What the device button reads: the size's short name and, in focus mode, its width × height. */
51
+ const readout = (canvas: Canvas) => [$(canvas, "gd-device-name").textContent, $(canvas, "gd-device-size").textContent].filter(Boolean).join(" ");
52
+ const deviceIcon = (canvas: Canvas) => $(canvas, "gd-device-icon").getAttribute("href");
53
+ const customInput = (canvas: Canvas) => {
54
+ openDevices(canvas);
55
+ return withClass(deviceMenu(canvas), "gd-device-input")[0];
56
+ };
57
+ const customRow = (canvas: Canvas) => withClass(deviceMenu(canvas), "gd-device-custom")[0];
58
+ const sizeError = (canvas: Canvas) => withClass(deviceMenu(canvas), "gd-device-error")[0];
59
+ /** Types a width in the custom field and presses Enter, the only key that applies it. */
60
+ const setCustom = (canvas: Canvas, value: string) => {
61
+ const input = customInput(canvas);
62
+ input.value = value;
63
+ input.dispatch("keydown", { key: "Enter" });
64
+ return input;
65
+ };
66
+ const frameSize = (canvas: Canvas, index = 0) => [canvas.boards[index].frame.style.width, canvas.boards[index].frame.style.height];
67
+
68
+ // ---- focus geometry (canvas-layout S5 and S8)
69
+
70
+ test("canvas-layout S8: Desktop fills the viewport's width at 100% in focus, the fixed sizes keep theirs, and the other artboards are hidden", async () => {
71
+ const canvas = await loadSizes();
72
+ focusOn(canvas);
73
+ // A 400 px artboard in the 1000 px viewport: Desktop is 1000 - 2 * 8 wide, at 100%, from the left margin.
74
+ assert.deepEqual(frameSize(canvas), ["984px", "300px"]);
75
+ assert.equal(canvas.zoomLevel.textContent, "100%");
76
+ assert.equal(canvas.world.style.transform, "translate(8px, 200px) scale(1)");
77
+ assert.equal(readout(canvas), "Desktop 984 × 300");
78
+ chooseSize(canvas, "phone");
79
+ assert.deepEqual(frameSize(canvas), ["390px", "644px"], "844 px is clipped to the 700 px viewport less its 8 px margin and the 48 px band");
80
+ chooseSize(canvas, "desktop");
81
+ assert.deepEqual(frameSize(canvas), ["984px", "300px"]);
82
+ // A wider window widens Desktop with it.
83
+ canvas.viewport.rect = { left: 0, top: 50, width: 1600, height: 700 };
84
+ canvas.windowEvent("resize");
85
+ assert.equal(canvas.boards[0].frame.style.width, "1584px");
86
+ assert.equal(readout(canvas), "Desktop 1584 × 300", "the button follows the window");
87
+ back(canvas);
88
+ assert.deepEqual(frameSize(canvas), ["400px", "300px"], "leaving focus restores the artboard's own size");
89
+ assert.match(read("canvas.css"), /\.gd-focused \.gd-world > :not\(\.gd-focus-board\) \{ visibility: hidden; \}/);
90
+ });
91
+
92
+ test("canvas-layout S5: a tall artboard keeps 8 px margins and a 48 px band for Back to canvas, idempotently", async () => {
93
+ const canvas = await loadSizes({}, 1600);
94
+ const [first] = canvas.boards;
95
+ first.frame.parentElement!.offsetLeft = 480;
96
+ first.frame.parentElement!.offsetTop = 20;
97
+ focusOn(canvas);
98
+ // 700 - (8 + 20) - 48 = 624 px of frame; x puts Desktop at the left margin: 8 - 480; y its top 8 + 20 px down: 28 - 20.
99
+ assert.deepEqual(frameSize(canvas), ["984px", "624px"]);
100
+ assert.equal(canvas.world.style.transform, "translate(-472px, 8px) scale(1)");
101
+ canvas.windowEvent("resize");
102
+ assert.equal(canvas.world.style.transform, "translate(-472px, 8px) scale(1)");
103
+ back(canvas);
104
+ assert.deepEqual(frameSize(canvas), ["400px", "1600px"]);
105
+ });
106
+
107
+ test("canvas-layout S5: an artboard wider than the window is drawn smaller to fit from the 8 px margin, and centered when it fits", async () => {
108
+ const canvas = await loadSizes({ "/t/api/designs/alpha": { slug: "alpha", title: "Alpha", brief: "", artboards: [
109
+ { file: "01-a.html", title: "First", tradeoff: "", width: 1440, height: 900 },
110
+ { file: "02-b.html", title: "Second", tradeoff: "", width: 400, height: 300 },
111
+ ] } });
112
+ const [first] = canvas.boards;
113
+ first.frame.parentElement!.offsetTop = 32;
114
+ focusOn(canvas);
115
+ // 1440 px drawn into 1000 - 2 * 8: 68%; 900 * 0.68 = 615 px fits under the 8 px margin and the 32 px label (22 px on screen), above the 48 px band.
116
+ const zoom = 984 / 1440;
117
+ assert.equal(canvas.zoomLevel.textContent, "68%");
118
+ assert.deepEqual(frameSize(canvas), ["1440px", "900px"], "the design still renders at its real width");
119
+ assert.equal(canvas.world.style.transform, `translate(8px, ${Math.round((700 - 900 * zoom) / 2 - 32 * zoom)}px) scale(${zoom})`);
120
+ assert.equal(readout(canvas), "Desktop 1440 × 900");
121
+ });
122
+
123
+ test("canvas-layout S5: the label above the frame is measured at the focused width, so one that wraps narrower keeps its space", async () => {
124
+ const canvas = await loadSizes();
125
+ const [first] = canvas.boards;
126
+ const box = first.frame.parentElement!;
127
+ // The label wraps to two lines once the frame is narrower than 400 px: 40 px above the frame instead of 20.
128
+ Object.defineProperty(box, "offsetTop", { configurable: true, get: () => (Number.parseInt(String(first.frame.style.width), 10) < 400 ? 40 : 20) });
129
+ focusOn(canvas);
130
+ chooseSize(canvas, "phone");
131
+ // 700 - (8 + 40) - 48 = 604 px of frame, the frame's top 8 + 40 px down: 48 - 40.
132
+ assert.deepEqual(frameSize(canvas), ["390px", "604px"]);
133
+ assert.equal(canvas.world.style.transform, "translate(305px, 8px) scale(1)");
134
+ });
135
+
136
+ // ---- the device button and its menu (canvas-layout S6)
137
+
138
+ test("canvas-layout S6: the top bar's device button opens a menu of Phone, Tablet, Desktop, All sizes and a custom width, Desktop checked", async () => {
139
+ const canvas = await loadSizes();
140
+ const button = deviceButton(canvas);
141
+ assert.equal(button.disabled, true, "outside an open artboard the button does nothing");
142
+ assert.equal(button.title, "Open an artboard to choose its preview size");
143
+ assert.equal(button.getAttribute("aria-label"), "Preview size: Desktop");
144
+ button.dispatch("click");
145
+ assert.equal(deviceMenu(canvas).hidden, true, "and opens nothing");
146
+ focusOn(canvas);
147
+ assert.equal(button.disabled, false);
148
+ assert.equal(button.title, "Preview size of the open artboard");
149
+ assert.equal(button.getAttribute("aria-label"), "Preview size: Desktop 984 × 300");
150
+ assert.equal(readout(canvas), "Desktop 984 × 300", "the button reads the current size");
151
+ assert.equal(deviceIcon(canvas), "#i-monitor");
152
+ button.dispatch("click");
153
+ const menu = deviceMenu(canvas);
154
+ assert.equal(menu.hidden, false);
155
+ assert.equal(button.getAttribute("aria-expanded"), "true");
156
+ assert.equal(menu.getAttribute("aria-label"), "Preview size");
157
+ const items = deviceItems(canvas);
158
+ assert.deepEqual(items.map((item) => item.dataset.size), ["phone", "tablet", "desktop", "all"]);
159
+ assert.deepEqual(items.map((item) => texts(item, "gd-menu-label")[0]), ["Phone", "Tablet", "Desktop", "All sizes"]);
160
+ assert.deepEqual(items.map((item) => texts(item, "gd-device-dim")[0] ?? ""), ["390 × 844", "820 × 1180", "984 × 300", ""]);
161
+ assert.deepEqual(items.map((item) => item.title), ["Phone 390 × 844", "Tablet 820 × 1180", "Desktop 984 × 300", "All sizes: Phone, Tablet and the artboard as designed, side by side"]);
162
+ assert.deepEqual(items.map((item) => item.getAttribute("aria-checked")), ["false", "false", "true", "false"], "Desktop is checked when focus mode starts");
163
+ assert.deepEqual(items.map((item) => (item as FakeElement & { type?: string }).type), ["button", "button", "button", "button"]);
164
+ for (const item of items) assert.equal(withClass(item, "gd-i")[0].getAttribute("aria-hidden"), "true", "icons are decoration");
165
+ assert.deepEqual(items.map((item) => withClass(item, "gd-i")[0].children[0].getAttribute("href")), ["#i-phone", "#i-tablet", "#i-monitor", "#i-devices"]);
166
+ assert.ok(isActive(canvas, items[0]), "focus moves to the first item");
167
+ const input = customInput(canvas);
168
+ assert.equal(input.getAttribute("aria-label"), "Custom width in pixels");
169
+ assert.deepEqual([(input as FakeElement & { type?: string }).type, (input as FakeElement & { name?: string }).name, input.getAttribute("min"), input.getAttribute("max"), input.getAttribute("step")], ["number", "gd-custom-width", "240", "2560", "1"]);
170
+ assert.deepEqual(texts(menu, "gd-device-custom-label"), ["Custom"]);
171
+ assert.equal(input.value, "");
172
+ assert.equal(sizeError(canvas).hidden, true);
173
+ assert.equal(sizeError(canvas).getAttribute("role"), "alert");
174
+ });
175
+
176
+ test("the custom width field and its error sit in a group named Custom width, the only kind of non-item a menu may own", async () => {
177
+ const canvas = await loadSizes();
178
+ tallViewport(canvas);
179
+ focusOn(canvas);
180
+ $(canvas, "gd-device").dispatch("click");
181
+ const roles = deviceMenu(canvas).children.map((child) => child.getAttribute("role"));
182
+ assert.deepEqual(roles.filter((role) => role !== "menuitemradio"), ["separator", "group"], "besides its items, the menu owns only a separator and a group");
183
+ const group = deviceMenu(canvas).children[roles.indexOf("group")];
184
+ assert.equal(group.getAttribute("aria-label"), "Custom width");
185
+ assert.deepEqual(group.children.map((child) => child.className), ["gd-device-custom", "gd-device-error"], "the field's row and its error are inside the group");
186
+ });
187
+
188
+ test("canvas-layout S6: choosing a size closes the menu, gives focus back to the button and shows the size's icon and name on it", async () => {
189
+ const canvas = await loadSizes();
190
+ tallViewport(canvas);
191
+ focusOn(canvas);
192
+ const shown: Array<Array<string | null>> = [];
193
+ for (const size of ["phone", "tablet", "desktop"]) {
194
+ chooseSize(canvas, size);
195
+ assert.equal(deviceMenu(canvas).hidden, true, size);
196
+ assert.equal(deviceButton(canvas).getAttribute("aria-expanded"), "false");
197
+ assert.ok(isActive(canvas, deviceButton(canvas)), `${size}: focus is back on the button`);
198
+ shown.push([deviceIcon(canvas), readout(canvas), deviceButton(canvas).getAttribute("aria-label")]);
199
+ }
200
+ setCustom(canvas, "600");
201
+ shown.push([deviceIcon(canvas), readout(canvas), deviceButton(canvas).getAttribute("aria-label")]);
202
+ assert.deepEqual(shown, [
203
+ ["#i-phone", "Phone 390 × 844", "Preview size: Phone 390 × 844"],
204
+ ["#i-tablet", "Tablet 820 × 1180", "Preview size: Tablet 820 × 1180"],
205
+ ["#i-monitor", "Desktop 984 × 300", "Preview size: Desktop 984 × 300"],
206
+ ["#i-width", "Custom 600 × 300", "Preview size: Custom 600 × 300"],
207
+ ]);
208
+ back(canvas);
209
+ assert.equal(deviceButton(canvas).disabled, true, "back on the canvas it is off again");
210
+ assert.equal(readout(canvas), "Desktop", "naming no size of its own");
211
+ assert.equal(deviceIcon(canvas), "#i-monitor");
212
+ });
213
+
214
+ test("canvas-layout S6: the device menu keeps the shared menu's keys, and the width field keeps its own", async () => {
215
+ const canvas = await loadSizes();
216
+ tallViewport(canvas);
217
+ focusOn(canvas);
218
+ const button = deviceButton(canvas);
219
+ assert.equal(keyOn(button, "ArrowDown").defaultPrevented, true);
220
+ assert.equal(deviceMenu(canvas).hidden, false);
221
+ assert.ok(isActive(canvas, deviceItems(canvas)[0]), "ArrowDown opens on the first item");
222
+ assert.equal(keyOn(button, "Escape").defaultPrevented, true);
223
+ assert.equal(deviceMenu(canvas).hidden, true);
224
+ assert.equal(button.getAttribute("aria-expanded"), "false");
225
+ keyOn(button, "ArrowUp");
226
+ const items = deviceItems(canvas);
227
+ const input = withClass(deviceMenu(canvas), "gd-device-input")[0];
228
+ assert.ok(isActive(canvas, input), "ArrowUp opens on the last entry, the width field");
229
+ keyOn(input, "ArrowDown");
230
+ assert.ok(isActive(canvas, items[0]), "ArrowDown wraps to the first");
231
+ keyOn(items[0], "ArrowUp");
232
+ assert.ok(isActive(canvas, input), "ArrowUp wraps to the field");
233
+ keyOn(input, "ArrowUp");
234
+ assert.ok(isActive(canvas, items[3]), "All sizes is the last item before the field");
235
+ keyOn(items[3], "Home");
236
+ assert.ok(isActive(canvas, items[0]));
237
+ keyOn(items[0], "End");
238
+ assert.ok(isActive(canvas, input));
239
+ for (const key of ["Home", "End", "5", " "]) assert.equal(keyOn(input, key).defaultPrevented, false, `${JSON.stringify(key)} stays with the field`);
240
+ assert.ok(isActive(canvas, input));
241
+ assert.equal(deviceMenu(canvas).hidden, false, "moving never closes it");
242
+ assert.equal(keyOn(input, "Escape").defaultPrevented, true);
243
+ assert.equal(deviceMenu(canvas).hidden, true);
244
+ assert.ok(isActive(canvas, button), "Esc returns focus to the button");
245
+
246
+ for (const key of ["Enter", " "]) {
247
+ button.dispatch("click");
248
+ const chosen = keyOn(deviceItems(canvas)[0], key);
249
+ assert.equal(chosen.defaultPrevented, true, key);
250
+ assert.equal(readout(canvas), "Phone 390 × 844", key);
251
+ assert.equal(deviceMenu(canvas).hidden, true, key);
252
+ chooseSize(canvas, "desktop");
253
+ }
254
+
255
+ button.dispatch("click");
256
+ assert.equal(keyOn(deviceItems(canvas)[1], "Tab").defaultPrevented, false, "Tab keeps its move");
257
+ assert.equal(deviceMenu(canvas).hidden, true);
258
+
259
+ button.dispatch("click");
260
+ const pointerdown = (target: FakeElement) => (canvas.document.listeners.get("pointerdown") ?? []).forEach((listener) => listener({ target, button: 0 }));
261
+ pointerdown(deviceMenu(canvas));
262
+ pointerdown(withClass(deviceMenu(canvas), "gd-device-input")[0]);
263
+ assert.equal(deviceMenu(canvas).hidden, false, "a press inside does not close it");
264
+ pointerdown(button);
265
+ assert.equal(deviceMenu(canvas).hidden, false, "the button toggles on its own click");
266
+ pointerdown(canvas.viewport);
267
+ assert.equal(deviceMenu(canvas).hidden, true, "a press outside closes it");
268
+ assert.equal(button.getAttribute("aria-expanded"), "false");
269
+ button.dispatch("click");
270
+ button.dispatch("click");
271
+ assert.equal(deviceMenu(canvas).hidden, true, "the button closes it again");
272
+ assert.equal(readout(canvas), "Desktop 984 × 300", "closing chose nothing");
273
+ });
274
+
275
+ test("canvas-layout S6: the device and Settings menus close each other, and leaving the artboard closes the device menu", async () => {
276
+ const canvas = await loadSizes();
277
+ focusOn(canvas);
278
+ const settings = $(canvas, "gd-rail-settings");
279
+ const menu = $(canvas, "gd-menu");
280
+ deviceButton(canvas).dispatch("click");
281
+ settings.dispatch("click");
282
+ assert.equal(deviceMenu(canvas).hidden, true);
283
+ assert.equal(deviceButton(canvas).getAttribute("aria-expanded"), "false");
284
+ assert.equal(menu.hidden, false);
285
+ deviceButton(canvas).dispatch("click");
286
+ assert.equal(menu.hidden, true);
287
+ assert.equal(settings.getAttribute("aria-expanded"), "false");
288
+ assert.equal(deviceMenu(canvas).hidden, false);
289
+ canvas.message(canvas.boards[0].frame.contentWindow, { type: "gd:exit-focus" });
290
+ assert.equal(deviceMenu(canvas).hidden, true);
291
+ assert.equal(deviceButton(canvas).getAttribute("aria-expanded"), "false");
292
+ assert.equal(deviceButton(canvas).disabled, true);
293
+ assert.equal(deviceMenu(canvas).children.length, 0, "the menu is emptied when it closes");
294
+ });
295
+
296
+ // ---- one size at a time (S1, S2)
297
+
298
+ test("S1: Desktop is the artboard's own manifest size when it is wider than the window (canvas-layout S8), and each focus session starts at Desktop", async () => {
299
+ const canvas = await loadSizes(WIDE_ALPHA);
300
+ focusOn(canvas);
301
+ assert.equal(readout(canvas), "Desktop 1200 × 800");
302
+ openDevices(canvas);
303
+ assert.equal(deviceItems(canvas)[2].title, "Desktop 1200 × 800");
304
+ chooseSize(canvas, "phone");
305
+ back(canvas);
306
+ focusOn(canvas);
307
+ assert.deepEqual(pressedSizes(canvas), ["desktop"]);
308
+ assert.equal(readout(canvas), "Desktop 1200 × 800");
309
+ });
310
+
311
+ test("S2: Phone, Tablet and Desktop resize the focused iframe in place, centered at 100%", async () => {
312
+ const canvas = await loadSizes();
313
+ tallViewport(canvas);
314
+ const [first] = canvas.boards;
315
+ const src = first.frame.src;
316
+ focusOn(canvas);
317
+ chooseSize(canvas, "phone");
318
+ assert.deepEqual(frameSize(canvas), ["390px", "844px"]);
319
+ assert.equal(canvas.world.style.transform, "translate(305px, 278px) scale(1)");
320
+ assert.equal(canvas.zoomLevel.textContent, "100%");
321
+ assert.deepEqual(pressedSizes(canvas), ["phone"]);
322
+ assert.equal(readout(canvas), "Phone 390 × 844");
323
+
324
+ chooseSize(canvas, "tablet");
325
+ assert.deepEqual(frameSize(canvas), ["820px", "1180px"]);
326
+ assert.equal(canvas.world.style.transform, "translate(90px, 110px) scale(1)");
327
+ assert.deepEqual(pressedSizes(canvas), ["tablet"]);
328
+ assert.equal(readout(canvas), "Tablet 820 × 1180");
329
+
330
+ chooseSize(canvas, "desktop");
331
+ assert.deepEqual(frameSize(canvas), ["984px", "300px"]);
332
+ assert.equal(canvas.world.style.transform, "translate(8px, 550px) scale(1)");
333
+ assert.deepEqual(pressedSizes(canvas), ["desktop"]);
334
+ assert.equal(first.frame.src, src, "the artboard is not reloaded");
335
+ assert.ok(canvas.frames()[0] === first.frame, "and keeps its iframe");
336
+ });
337
+
338
+ test("S2: a size taller than the viewport keeps the clip, and one wider than it is drawn smaller to fit", async () => {
339
+ const canvas = await loadSizes(WIDE_ALPHA);
340
+ const [first] = canvas.boards;
341
+ first.frame.parentElement!.offsetLeft = 480;
342
+ first.frame.parentElement!.offsetTop = 20;
343
+ focusOn(canvas);
344
+ // Desktop is 1200 wide in a 1000 px viewport: it keeps its 1200 px width, drawn at (1000 - 2 * 8) / 1200, from the left margin.
345
+ const scale = 984 / 1200;
346
+ assert.equal(first.frame.style.width, "1200px", "the design still renders at its real width");
347
+ assert.equal(canvas.world.style.transform, `translate(${Math.round(8 - 480 * scale)}px, 8px) scale(${scale})`);
348
+ assert.equal(canvas.zoomLevel.textContent, "82%", "the zoom says how much smaller it is drawn");
349
+ chooseSize(canvas, "phone");
350
+ assert.equal(first.frame.style.height, "624px", "844 px does not fit the 700 px viewport (less the 8 px margin, the 20 px label and the 48 px band)");
351
+ assert.equal(readout(canvas), "Phone 390 × 844", "the readout keeps the preset height");
352
+ assert.equal(canvas.world.style.transform, "translate(-175px, 8px) scale(1)");
353
+ });
354
+
355
+ test("S2: a custom width resizes the iframe with the manifest height; the field accepts whole px from 240 to 2560 only", async () => {
356
+ const canvas = await loadSizes();
357
+ tallViewport(canvas);
358
+ focusOn(canvas);
359
+ setCustom(canvas, "600");
360
+ assert.deepEqual(frameSize(canvas), ["600px", "300px"], "height keeps the artboard's manifest height");
361
+ assert.equal(deviceMenu(canvas).hidden, true, "a valid width closes the menu");
362
+ assert.equal(readout(canvas), "Custom 600 × 300");
363
+ assert.equal(canvas.world.style.transform, "translate(200px, 550px) scale(1)");
364
+ assert.deepEqual(pressedSizes(canvas), [], "no preset is checked");
365
+ assert.equal(customInput(canvas).value, "600", "the field shows the width when the menu opens again");
366
+ assert.ok(customRow(canvas).classes.has("gd-selected"));
367
+
368
+ for (const bad of ["239", "2561", "abc", "500.5", "", "-300", "1e3"]) {
369
+ const input = setCustom(canvas, bad);
370
+ assert.equal(canvas.boards[0].frame.style.width, "600px", `${JSON.stringify(bad)} is refused`);
371
+ assert.equal(readout(canvas), "Custom 600 × 300");
372
+ assert.equal(input.getAttribute("aria-invalid"), "true");
373
+ assert.equal(sizeError(canvas).hidden, false);
374
+ assert.equal(sizeError(canvas).textContent, "Enter a whole number from 240 to 2560 (px).");
375
+ assert.equal(deviceMenu(canvas).hidden, false, "the menu stays open to correct it");
376
+ }
377
+ for (const edge of ["240", "2560"]) {
378
+ setCustom(canvas, edge);
379
+ assert.equal(canvas.boards[0].frame.style.width, `${edge}px`, `${edge} is accepted with Enter`);
380
+ assert.equal(deviceMenu(canvas).hidden, true);
381
+ assert.ok(isActive(canvas, deviceButton(canvas)));
382
+ assert.equal(customInput(canvas).getAttribute("aria-invalid"), null, "the menu is built again, without the error, when it opens");
383
+ assert.equal(sizeError(canvas).hidden, true);
384
+ deviceButton(canvas).dispatch("click");
385
+ }
386
+ // A size wider than the viewport starts at the left margin, like a wide artboard.
387
+ assert.match(canvas.world.style.transform, /^translate\(8px, /);
388
+ chooseSize(canvas, "phone");
389
+ assert.equal(customInput(canvas).value, "", "a preset clears the custom field");
390
+ assert.ok(!customRow(canvas).classes.has("gd-selected"));
391
+ });
392
+
393
+ test("S2: the custom width applies on Enter only: leaving the field (change) applies nothing, so Phone chosen next is Phone", async () => {
394
+ const canvas = await loadSizes();
395
+ tallViewport(canvas);
396
+ focusOn(canvas);
397
+ const input = customInput(canvas);
398
+ input.value = "600";
399
+ input.dispatch("change");
400
+ assert.equal(deviceMenu(canvas).hidden, false, "a change event (blur, spinner step) keeps the menu open");
401
+ assert.equal(readout(canvas), "Desktop 984 × 300", "and applies no width");
402
+ deviceItems(canvas).find((item) => item.dataset.size === "phone")?.dispatch("click");
403
+ assert.equal(readout(canvas), "Phone 390 × 844");
404
+ assert.deepEqual(frameSize(canvas), ["390px", "844px"]);
405
+ assert.equal(deviceMenu(canvas).hidden, true);
406
+ });
407
+
408
+ test("S2: leaving focus mode, or focusing another artboard, restores the manifest size", async () => {
409
+ const canvas = await loadSizes({ "/t/api/system": { exists: true, file: "system.html", width: 800, height: 600 } });
410
+ tallViewport(canvas);
411
+ // The system board comes first.
412
+ focusOn(canvas, 1);
413
+ chooseSize(canvas, "tablet");
414
+ back(canvas);
415
+ assert.deepEqual(frameSize(canvas, 1), ["400px", "300px"]);
416
+
417
+ focusOn(canvas, 1);
418
+ chooseSize(canvas, "phone");
419
+ // Settings > Design system board focuses another artboard.
420
+ $(canvas, "gd-rail-settings").dispatch("click");
421
+ findAll($(canvas, "gd-menu"), (element) => element.getAttribute("role") === "menuitem" && texts(element, "gd-menu-label")[0] === "Design system board")[0].dispatch("click");
422
+ assert.deepEqual(frameSize(canvas, 1), ["400px", "300px"], "the artboard left behind is restored");
423
+ assert.deepEqual(pressedSizes(canvas), ["desktop"], "the new focus starts at Desktop");
424
+ assert.deepEqual(frameSize(canvas, 0), ["984px", "600px"], "Desktop is the viewport's width (canvas-layout S8)");
425
+ canvas.message(canvas.boards[0].frame.contentWindow, { type: "gd:exit-focus" });
426
+ assert.deepEqual(frameSize(canvas, 0), ["800px", "600px"]);
427
+ });
428
+
429
+ test("S2: the size survives a manifest refresh of the focused artboard", async () => {
430
+ const canvas = await loadSizes();
431
+ tallViewport(canvas);
432
+ focusOn(canvas);
433
+ chooseSize(canvas, "phone");
434
+ await canvas.serverEvent("change", { slug: "alpha", file: "design.json" });
435
+ assert.equal(canvas.frames()[0].style.width, "390px");
436
+ assert.deepEqual(pressedSizes(canvas), ["phone"]);
437
+ assert.equal(readout(canvas), "Phone 390 × 844");
438
+ });
439
+
440
+ test("S2: pins and the comment box measure the frame at its focused width, not the manifest's", async () => {
441
+ const comment = { id: "abc123", file: "01-a.html", selector: "h1", excerpt: "First", comment: "Update", status: "open", sentAt: null };
442
+ const canvas = await loadSizes({ "/t/api/designs/alpha/comments": { comments: [comment] } });
443
+ tallViewport(canvas);
444
+ const [first] = canvas.boards;
445
+ focusOn(canvas);
446
+ chooseSize(canvas, "phone");
447
+ const pins = withClass(first.frame.parentElement!, "gd-pins")[0];
448
+ canvas.message(first.frame.contentWindow, { type: "gd:pin-rects", rects: [{ id: comment.id, rect: { x: 395, y: 10, width: 4, height: 4 } }] });
449
+ assert.equal(pins.children.length, 0, "beyond the 390 px frame (inside the 400 px manifest width) the pin is hidden");
450
+ canvas.message(first.frame.contentWindow, { type: "gd:pin-rects", rects: [{ id: comment.id, rect: { x: 380, y: 10, width: 4, height: 4 } }] });
451
+ assert.equal(pins.children.length, 1);
452
+ // The frame is 390 px wide on screen at 100%: a pick 100 px in is 100 px right of its left edge.
453
+ $(canvas, "gd-comment").dispatch("click");
454
+ first.frame.rect = { left: 305, top: 50, width: 390, height: 844 };
455
+ canvas.message(first.frame.contentWindow, inspectorPick(first.frame, { type: "gd:pick", selector: "h1", excerpt: "First", rect: { x: 100, y: 20, width: 30, height: 40 } }));
456
+ assert.equal($(canvas, "gd-popover").hidden, false);
457
+ assert.equal($(canvas, "gd-popover").style.left, "405px");
458
+ });
459
+
460
+ // ---- All sizes in a narrow viewport
461
+
462
+ test("All sizes fits a narrow viewport: each frame is as wide as its scaled iframe, the row fits the room, and a cut label keeps its full text in a title", async () => {
463
+ const canvas = await loadSizes({ "/t/api/designs/alpha": { slug: "alpha", title: "Alpha", brief: "", artboards: [
464
+ { file: "01-a.html", title: "First", tradeoff: "", width: 4000, height: 800 },
465
+ { file: "02-b.html", title: "Second", tradeoff: "", width: 400, height: 300 },
466
+ ] } });
467
+ focusOn(canvas);
468
+ chooseSize(canvas, "all");
469
+ const px = (value: unknown) => Number.parseFloat(String(value));
470
+ const view = withClass(canvas.viewport, "gd-sizes-all")[0];
471
+ const sections = withClass(canvas.viewport, "gd-size-frame");
472
+ const scaled = sections.map((section) => withClass(section, "gd-size-scaled")[0]);
473
+ const widths = scaled.map((box) => px(box.style.width));
474
+ // The label cannot widen its frame: the section is exactly as wide as the scaled iframe.
475
+ assert.deepEqual(sections.map((section) => px(section.style.width)), widths);
476
+ // The 1000 px viewport less the side margins and the two 20 px gaps.
477
+ const room = 1000 - px(view.style.left) - px(view.style.right) - 20 * 2;
478
+ const total = widths.reduce((sum, width) => sum + width, 0);
479
+ assert.ok(total <= room, `${total} px of frames fit the ${room} px room`);
480
+ const tallest = Math.max(...scaled.map((box) => px(box.style.height)));
481
+ assert.ok(tallest <= 700 - px(view.style.top) - px(view.style.bottom) - 28, `${tallest} px fit under the 28 px labels`);
482
+ const percent = texts(sections[0], "gd-size-scale")[0];
483
+ assert.deepEqual(sections.map((section) => withClass(section, "gd-size-head")[0].title), [`Phone 390 × 844 ${percent}`, `Tablet 820 × 1180 ${percent}`, `As designed 4000 × 800 ${percent}`]);
484
+
485
+ const css = read("canvas.css");
486
+ const block = (selector: string) => {
487
+ const start = css.indexOf(`\n${selector} {`);
488
+ assert.ok(start >= 0, `${selector} is styled`);
489
+ return css.slice(start, css.indexOf("}", start) + 1);
490
+ };
491
+ const head = block(".gd-size-head");
492
+ for (const rule of [/overflow: hidden;/, /text-overflow: ellipsis;/, /white-space: nowrap;/]) assert.match(head, rule, "a label longer than its frame ends in an ellipsis");
493
+ const row = block(".gd-sizes-all");
494
+ assert.match(row, /justify-content: safe center;/, "a row wider than the viewport starts at its left edge, never cut on both sides");
495
+ assert.match(row, /overflow-x: auto;/, "and scrolls sideways at the smallest scale");
496
+ });
497
+
498
+ // ---- markup, styles, store and docs
499
+
500
+ test("canvas-layout S6: the device selector's markup sits after the arrangements in English, and its styles use --gd-* tokens, a focus ring and no motion", () => {
501
+ const html = read("index.html");
502
+ const bar = html.slice(html.indexOf('<header class="gd-bar"'), html.indexOf("</header>"));
503
+ assert.match(bar, /<button type="button" id="gd-device" class="gd-device-button" aria-haspopup="menu" aria-expanded="false" aria-controls="gd-device-menu" aria-label="Preview size: Desktop" title="Open an artboard to choose its preview size" data-i18n-aria-label="previewDesktop" data-i18n-title="previewOff" disabled><svg class="gd-i gd-i-s" aria-hidden="true"><use id="gd-device-icon" href="#i-monitor"\/><\/svg><span id="gd-device-name" data-i18n="desktop">Desktop<\/span><span id="gd-device-size" class="gd-device-size"><\/span><\/button>/);
504
+ assert.ok(bar.indexOf('id="gd-arrange-grid"') < bar.indexOf('id="gd-device"') && bar.indexOf('id="gd-device"') < bar.indexOf('id="gd-nav-mode"'), "after the arrangements, before the mode label");
505
+ assert.match(html, /<div id="gd-device-menu" class="gd-menu gd-device-menu" role="menu" aria-label="Preview size" data-i18n-aria-label="previewSize" hidden><\/div>/);
506
+ for (const icon of ["i-phone", "i-tablet", "i-monitor", "i-devices", "i-width", "i-check"]) assert.match(html, new RegExp(`<symbol id="${icon}" viewBox="0 0 24 24">`));
507
+ // The English stays in the markup, keyed for the language (ES.html, tests/design-canvas-i18n.test.ts); renderDevice rewrites it.
508
+ const css = read("canvas.css");
509
+ const block = (selector: string) => {
510
+ const start = css.indexOf(`\n${selector} {`);
511
+ assert.ok(start >= 0, `${selector} is styled`);
512
+ return css.slice(start, css.indexOf("}", start) + 1);
513
+ };
514
+ for (const selector of [".gd-device-button", ".gd-device-menu", ".gd-device-item", ".gd-device-dim", ".gd-device-custom", ".gd-device-input", ".gd-device-error"]) {
515
+ const text = block(selector);
516
+ assert.ok(!/#[0-9a-fA-F]{3,8}\b|rgba?\(/.test(text), `${selector}: tokens only`);
517
+ assert.ok(!/var\(--(?!gd-)/.test(text), `${selector}: only --gd-* tokens`);
518
+ assert.ok(!/transition|animation/.test(text), `${selector}: no motion`);
519
+ }
520
+ assert.match(css, /\.gd-device-item\[aria-checked="true"\][^{]*{[^}]*background:\s*var\(--gd-stage\)/);
521
+ assert.match(css, /\.gd-device-item\[aria-checked="true"\] \.gd-device-check[^{]*{[^}]*visibility:\s*visible/);
522
+ assert.match(css, /\.gd-device-button:focus-visible[^{]*{[^}]*outline:\s*2px solid var\(--gd-focus\)/);
523
+ assert.match(css, /\.gd-device-input\[aria-invalid="true"\][^{]*{[^}]*border-color:\s*var\(--gd-danger\)/);
524
+ assert.match(css, /\.gd-bar > \.gd-device-button \{ flex: none; \}/, "it never shrinks under its text");
525
+ assert.match(block(".gd-back"), /bottom: 8px;/, "Back to canvas floats in the 48 px band");
526
+ });
527
+
528
+ test("the focus margins live in canvas-focus.js, and the size changes only through the store's setFocus", () => {
529
+ const focus = read("canvas-focus.js");
530
+ assert.match(focus, /const FOCUS_MARGIN = 8;/);
531
+ assert.match(focus, /const BACK_SPACE = 48;/);
532
+ assert.ok(!/setFrameHeight/.test(focus), "the frame is sized whole: setFrameSize");
533
+ const sizes = read("canvas-sizes.js");
534
+ assert.match(sizes, /store\.setFocus\(\{ size/);
535
+ assert.ok(!/\bstate\.size\s*=(?!=)/.test(sizes), "never assigned in place");
536
+ });
537
+
538
+ test("the docs describe the preview size in the top bar, All sizes, the Overflows chip, the comment's size and focus mode as wide as the window", () => {
539
+ const docs = readFileSync(fileURLToPath(new URL("../docs/gentle-shell.md", import.meta.url)), "utf8");
540
+ const section = docs.slice(docs.indexOf("### Gentle Design"), docs.indexOf("### Gentle Music"));
541
+ const start = section.indexOf("- **Sizes**");
542
+ assert.ok(start >= 0, "a Sizes entry");
543
+ const sizes = section.slice(start, section.indexOf("\n", start));
544
+ for (const part of ["**Preview size**", "top bar", "disabled", "**Phone** (390 × 844)", "**Tablet** (820 × 1180)", "**Desktop**", "**Custom**", "240", "2560", "8 px", "drawn smaller", "Leaving focus mode"]) assert.ok(sizes.includes(part), `the Sizes entry mentions ${part}`);
545
+ for (const part of ["**All sizes**", "side by side", "its own iframe", "Comment mode", "**Overflows**", "wider than", "the size it was made at", "**As designed**", "Desktop records none"]) assert.ok(sizes.includes(part), `the Sizes entry mentions ${part}`);
546
+ assert.ok(!section.includes("at its designed width at 100%"), "focus mode is no longer the designed width");
547
+ assert.ok(!section.includes("the rest of the canvas is dimmed"), "the other artboards are hidden now");
548
+ });