Skip to content

A three-icon capsule launcher for NEMAR's widget - #468

Merged
neuromechanist merged 23 commits into
developfrom
feature/issue-436-capsule
Sep 24, 2026
Merged

neuromechanist merged 23 commits into
developfrom
feature/issue-436-capsule

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Builds the three-icon capsule launcher the maintainer decided on in #436, opt-in per community, and turns it on for NEMAR. Every other community keeps today's single chat bubble, markup and styles unchanged.

What it does

  • Collapsed, the launcher is today's chat bubble. Opening the chat expands it into one capsule of three circular buttons, chat at the bottom (it never moves), a notebook above it, and high-performance computing (HPC) at the top; the chat panel opens to the left of the capsule. At 600 px wide or less the icons lay out in a row beside the bubble and the panel opens above, as today.
  • The notebook button has four states, each with its reason in a tooltip shown on hover and on keyboard focus: no dataset on this page; checking whether the dataset has a Zarr copy; no Zarr copy yet; and active, which opens https://notebook.osc.earth/osa/open.html?community=<id>&dataset=<id> in a new tab with noopener (the notebook site is Host a JupyterLite notebook site at notebook.osc.earth/osa #465). An unavailable button uses aria-disabled, not disabled, so its reason stays reachable by keyboard and screen reader. HPC is "coming soon" everywhere, with a "Soon" badge so it reads differently from an inactive button.
  • The page says which dataset is on screen through OSAChatWidget.setDataset(null | {id, zarr}), callable before or after init(); nemar.org's dataset page calls it (Tell the assistant which dataset is on screen, for its notebook button nemarOrg/website#351). setConfig({notebookUrl}) sets the notebook site per environment (default https://notebook.osc.earth/osa/).
  • Configuration: widget.launcher: bubble | capsule (default bubble) and widget.launcher_label, the collapsed tooltip's text (Widget launcher: a three-icon capsule for chat, notebook and HPC #436's comment asked for a minimal "Explore NEMAR"). NEMAR sets both.
  • Found and fixed along the way: the chat window, a later fixed-position sibling, painted over the icons' tooltips despite their higher z-index, which only applied inside the capsule's own stacking context.

Docs: a Launcher section in docs/community-widget.md.

Tests

  • Python: field validation, resolve() omission, and only NEMAR sets launcher or launcher_label (every real community config).
  • frontend/test-widget-capsule.js (90, real widget in happy-dom), in both workflow suites: capsule markup only under capsule; each notebook state; setDataset before init(); invalid setDataset and notebookUrl ignored; the exact opened URL, encoded; an inactive button opens nothing; labels and aria-disabled per state; bubble mode renders today's markup; the capsule's active and neutral surfaces in the table-driven color audit.
  • Mutations of the click guard, the URL validation, the setDataset validation, the before-init render and the bubble default are each caught; two exposed weak tests, which were strengthened.
  • Chrome (widget_e2e.py --nemar, with a ?dataset=&zarr= hook): screenshots of each state and a 390 px phone, no console errors or Content Security Policy violations, and the clicked URL recorded. The phone-width overflow of the panel's header and footer predates this and affects every community (Widget header and footer overflow on phone widths #466).
  • Full suite: 2,754 passed; the one failure is the pre-existing color-terminal test (test_version_shows_version fails locally and passes in CI, because rich colorizes on a TTY #434).

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Preview Deployment

Name Link
Preview URL https://feature-issue-436-capsule-demo.osc.earth
Branch feature/issue-436-capsule
Commit b0336e9

This preview will be updated automatically when you push new commits.

Widget config gains launcher (bubble default, capsule opt-in) and
launcher_label (a short collapsed-launcher tooltip, replacing the
hardcoded "Ask me about <title>"), following the pattern theme_color
and user_bubble_color already use: resolve() omits both when unset,
so a community that never sets them is unaffected. NEMAR is the first
community on the capsule (#436), with the label "Explore NEMAR".
launcher: capsule converts the DOM in place (applyLauncherMode), moving
the existing chat button into a new capsule wrapper alongside a
notebook and an HPC placeholder icon, rather than branching the whole
markup template: a bubble-mode widget never builds this wrapper, so its
markup and computed styles stay exactly what they were before this
feature existed.

setDataset({id, zarr}) drives the notebook icon through four states (no
dataset, Zarr unknown, no Zarr copy, active); the active state opens
${notebookUrl}open.html?community=...&dataset=... in a new tab.
notebookUrl is validated and normalized in setConfig, defaulting to
https://notebook.osc.earth/osa/. Each icon carries aria-disabled (never
the disabled attribute) and a hover/keyboard-focus tooltip; "coming
soon" (HPC, always) additionally carries a small badge so it reads
differently from "inactive" (no dataset, or no Zarr copy).

Layout: a vertical stack above the bubble past 601px wide, with the
chat panel opening to its left; a row to the bubble's left at or below
600px, with the chat panel opening above as today. Both directions rely
on the capsule being anchored by bottom+right alone, so it grows away
from that corner and the chat button never moves.

Fixed along the way: two fixed-position siblings with equal z-index
stack by DOM order, so the capsule's own z-index has to beat the chat
window's for an icon tooltip to paint above it, not just the tooltip's
own (which is scoped to the capsule's stacking context).
Runs the real widget source in a happy-dom window, the same technique
test-widget-tools.js uses: the capsule exists only under launcher:
capsule; a bubble-mode widget's markup and className are byte-for-byte
unchanged; all four notebook states from setDataset, including a call
made before init(); invalid setDataset and notebookUrl inputs leave the
prior state alone (checked via the full rendered state, not just the
active/inactive flag, since a malformed id that is still "active"
would otherwise pass by coincidence); the exact, encoded contract URL a
click opens, and that an inactive or coming-soon icon's click opens
nothing; aria-disabled as its own guard, forced out of sync with
currentDataset directly on the DOM; the capsule's z-index beating the
chat window's; and launcher_label overriding the collapsed tooltip,
with the community-config and setConfig precedence both covered.

Registered in both CI workflows alongside test-widget-tools.js.
widget-e2e-dataset.js reads ?dataset=<id>&zarr=true|false&notebookUrl=
from the page's own URL and calls OSAChatWidget.setDataset/setConfig
accordingly, so a manual or scripted Chrome run against --nemar can
exercise a given notebook state without a devtools console. An
external file, not inline script, since the harness serves this page
under a real Content-Security-Policy with no 'unsafe-inline'.
docs/community-widget-launcher.md is a self-contained section (its own
level-2 heading) rather than a page of its own: it is meant to be
folded into docs/community-widget.md, the WidgetConfig reference page
a sibling PR is adding, once that PR merges.
setupResize only ever reads chatWindow's own offsetWidth/offsetHeight
and mouse deltas; nothing about it changes when the chat button (and
so the window's neighbor) moves into the capsule wrapper, but that was
reasoning rather than a test. Drags the real handle via MouseEvent and
checks the resulting inline width/height.
Mirrors #463's table-driven surface/foreground probe against the real
stylesheet, kept here rather than in test-widget-tools.js so all
capsule classification lives in one file. The active notebook icon is
a themed surface (theme_color/theme_text_color, same pair the launcher
button already is); the neutral icon (inactive OR coming-soon, which
share a look per #436) is proven NOT themed: identical whether or not
a community sets any color, which is what keeps a disabled button from
ever reading as active. Mutation-checked: swapping the active icon's
foreground to --osa-accent is caught by both the NEMAR-styled and
unset cases.
The base PR (#463) added docs/community-widget.md, "one section per
area", explicitly anticipating a section like this one being added
without disturbing the others. Moves the standalone
community-widget-launcher.md content in as its own "Launcher" section,
between Color roles (the active icon's theme_color/theme_text_color
pair) and the setConfig key table; adds launcher/launcher_label to
that table, and notebookUrl to the embedder-only settings note
alongside disclaimerColor/disclaimerBackground. Deletes the standalone
file and repoints the CHANGELOG's reference.
A base URL is meant to carry neither: handleNotebookClick appends its
own '?community=...&dataset=...' after it, so a query would produce a
URL with two '?', and the trailing-slash fix would land the slash
inside the query or fragment instead of at the end of the path.
Reject rather than silently mangle it, in both normalizeNotebookUrl
and the notebookUrl validation test's invalid cases.
launcher: capsule can arrive from the community config after the
reader has already opened the chat, and the conversion previously
moved the open panel's right/bottom/max-height instantly. Add a short
CSS transition scoped to capsule mode alone (bubble mode is untouched),
and test that opening the chat before the config resolves ends with
the transitioned position and a declared transition on those properties.
The new icon tooltips' spans repeat the button's own aria-label
verbatim, so a screen reader read each one twice. Mark the two new
capsule tooltips aria-hidden (the pre-existing .osa-chat-tooltip has
no button-owning aria-label to duplicate, so it is left alone), and
assert both the hiding and that the pre-existing tooltip is untouched.
The three appendChild calls already order the icons hpc/notebook/chat
for the anchoring trick; that same order is Tab order (Tab follows DOM
order, not visual position) and it matches the visual order in both
the desktop (top-to-bottom) and narrow (left-to-right) layouts. Say so
in a comment so the order reads as deliberate, not incidental.
happy-dom defaults to a 1024px desktop viewport, so nothing exercised
the narrow (<=600px) branch, and no test checked computed style for
bubble mode at all: dropping the ".osa-launcher-capsule " prefix from
the chat-button override (widening it to every community) passed
every existing test. Let loadWidget size the happy-dom viewport, and
add two tests: bubble mode's exact computed position (today's values,
since outside sites embed it unpinned), and the capsule's
flex-direction and chat-window position at explicit narrow and
desktop widths either side of the 601px breakpoint.
The four notebook states and the HPC icon only checked that
aria-label was non-empty; hard-coding 'Notebook' for every state
passed. Assert the exact label per state instead.
applyLauncherMode's "&& !CONFIG.fullscreen" exclusion was untested;
removing it passed every existing test since the pop-out's chat
button is already hidden. Assert directly that fullscreen with
launcher: capsule builds no capsule wrapper.
"guarded by aria-disabled ALONE" read as if the handler had only one
guard; it has two (aria-disabled and a currentDataset re-check). Reword
to describe what the test actually isolates: this scenario keeps
currentDataset.zarr true so the OTHER guard would let the click
through on its own, proving the aria-disabled check does real work.
isValidCommunityId and isValidDatasetId only ever admit unreserved
characters, so nothing that reaches handleNotebookClick ever needs
escaping; removing both encodeURIComponent calls still passed this
test. Rename it and explain what it actually proves (the literal
contract string for punctuation the format allows), and note that
encodeURIComponent stays in the source as defense in depth for a
future, less-gated caller, not because this test exercises it.
happy-dom does not turn a trusted Enter or Space keypress into a click
on a focused <button>, so the aria-disabled/currentDataset guard could
not be exercised through the keyboard in the Bun suite. Add a script
that reuses chrome.js's own findChrome/launch/connect to drive real
Chrome over CDP, Tab-focuses the notebook button, and dispatches real
Input.dispatchKeyEvent presses for Enter and Space, asserting each
opens the contract URL when the dataset is active and opens nothing
when it is not.

Run against a live widget_e2e.py --nemar server on 2026-09-23: all 7
checks passed. Mutation-tested by removing both of
handleNotebookClick's guards, which the inactive-dataset checks caught
(both opened the URL that should have been refused); reverted and
reconfirmed green.
The Launcher section described only the desktop (vertical stack,
opening above) layout. Add the 600px breakpoint: at 600px and
narrower, the capsule is a row beside the chat button and the panel
opens above it exactly as it always has, matching a bubble widget's
panel. Also spell out high-performance computing (HPC) on its first
use, in the section heading.
"What happens with a malformed value" covers only the color fields; a
reader could easily assume it also covers notebookUrl or launcher,
described just above it. Add a one-line pointer to where each is
actually described instead.
Break at sentence end and at clause punctuation, roughly one sentence
per line, matching the project's line-break convention. No content
change.
@neuromechanist
neuromechanist force-pushed the feature/issue-436-capsule branch from a623e57 to ba5ffd7 Compare September 24, 2026 06:44
@neuromechanist

Copy link
Copy Markdown
Member Author

Review response

Three Sonnet reviewers ran (code and accessibility, tests, docs). The code reviewer proved the hard requirement by tracing every path: with launcher unset, bubble mode's DOM, classes, styles, handlers and requests are unchanged, so the outside sites that embed the widget unpinned with communityId: 'hed' see no difference. Every finding is addressed in the 15 commits after the rebase onto develop (which now includes #467):

Tests

  • Bubble mode's computed layout had no test: unscoping the capsule's chat-button override (which would move every community's button) passed all 402 tests. The chat button's position, bottom, right and z-index, and the chat window's bottom, right and max-height, are now asserted for bubble mode; the capsule's layout is asserted at two explicit widths, catching the breakpoint mutation (e4edcc6).
  • The pop-out never gets a capsule (0b7002a); each state's exact aria-label (9f21f0b); the URL test no longer claims to prove encoding, which the validators make unreachable (b7a7351).
  • Keyboard activation in real Chrome: frontend/browser-harness/keyboard-activation-check.mjs sends trusted Enter and Space to the focused notebook button, which open the exact URL when active and nothing when inactive; removing the click guards fails both inactive checks (005c0a9).

Code

  • A notebookUrl with a query or fragment is rejected with a warning; it used to produce a URL with two ? (1556c3b).
  • A panel already open when the capsule config arrives now eases into position in capsule mode only (26d2115).
  • The capsule's tooltip text is hidden from the accessibility tree, since the aria-label carries it (9f9133f); tab order follows the DOM, which matches the visual order in both layouts (fdcad56).

Docs: the Launcher section describes both breakpoints, high-performance computing (HPC) is spelled out on first use, a pointer separates notebookUrl and launcher from the color-validation section, a test comment no longer overclaims, and the section uses semantic line breaks (d50e8b8, 1f5b571, 72ff14d, a4bf77b, ba5ffd7, 33aa3f2).

Gates: test-widget-capsule.js 119, test-widget-tools.js 312, every other Bun suite and chrome.js passed; pytest 2,802 passed (the one failure is #434); the embed-snippet test from #467 still passes; the keyboard check passed 7 of 7.

@neuromechanist
neuromechanist merged commit ab9628f into develop Sep 24, 2026
16 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-436-capsule branch September 24, 2026 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant