↓Skip to main content
  1. My Blog Posts and Stories/

Making the HYSA Calculator explain itself

··1658 words·8 mins

The SG HYSA Calculator compares 17 savings accounts, and the numbers live in tables and short remarks. That is fine if you already know which buttons to press. For anyone else, the first few minutes are a rate table and a guess.

2 things pushed me to fix that.

The first was the questions. “How do I use this?” does not have an answer on the page you are looking at; the frequently asked questions (FAQ) page explains the accounts, not the clicks.

The second was the docs. The README lists 14 supported accounts. The app has 17: Trust Bank Flex, BOC SmartSaver and Citi Interest Booster are missing, because each shipped without anyone updating the table. Nobody notices, because nobody diffs a README against the code. Writing a guide is the easy part; knowing it still matches the app is the hard part.

A narrated tour kills 2 birds. It is the guide, and running the capture is also an end-to-end pass over the 3 main flows: it starts the real app, seeds a demo profile, clicks real selectors and fails if a step no longer works or the expected text has moved.

What I did not want was a screen recording: a recorded video is a screenshot with a longer shelf life. The user interface (UI) moves, the video does not, and nobody re-records a demo for a colour change.

So the walkthrough page plays 3 narrated tours, and every frame of them is generated from the same data structure that renders the page.

The walkthrough page #

The walkthrough page: a player, a chapter rail, and the written steps below it
Walkthrough page

3 tours: comparing effective interest rate (EIR) and yearly interest, tracking historical rates, and optimizing your accounts. They run 1:25, 1:16 and 1:37, with 9, 9 and 12 chapters, and each one starts on the page it is about.

The player is Remotion running in the browser, with a chapter rail next to it and the written steps below. Click a chapter and the video seeks to that moment, so the page works as a demo and as documentation at the same time.

Flows as data #

Each tour is a plain data structure in src/walkthrough/flows.ts: an id, a route, a fixed demo profile, the “what you’ll learn” bullets, tips, and a list of steps. A step has a caption, the narration, the Playwright actions to replay, a selector to spotlight, and optionally text the highlighted element must contain.

Nothing there is a function or a component, because 1 definition feeds every consumer in this picture:

CI

Runtime: the browser

Capture: manual, needs a browser

Authoring

flows.ts
captions, narration, actions, selectors

capture.mjs

Vite + Chromium

screenshot, spotlight rect, cursor

Edge TTS

Remotion player

/walkthrough page

docs/WALKTHROUGH.md + README block

docs:check

timelines/*.yaml

Capturing from the real app #

The step-by-step part is easier to read as a sequence than as prose. npm run walkthrough:capture does this for every step in every flow:

Edge TTSbrowser + appcapture scriptEdge TTSbrowser + appcapture scriptstart Vite, launch Chromiumloop[every step]usernpm run walkthrough:captureseed profile, open routeapp readyreplay the actionsactions donespotlight + screenshotrect + JPEGsynthesize narrationmp3read cursor targetcursor positiontimeline + mediauser

The output is 1 JPEG and 1 audio file per step, plus a YAML timeline for the flow.

The Optimize screenshot in the other post is 1 of those captures, copied straight out of the repo. That has a real cost: the media is committed, about 4.6MB across the 3 tours, because the production site must not run a browser at request time. The benefit: regenerating is the only way to change the demo, so a stale UI cannot survive more than 1 capture.

Narration broke twice #

The requirement was never a specific voice. It was: every step gets an audio track, generated at capture time, with no API key and no paid service, and the capture never fails because a voice is missing.

The first version used the text-to-speech (TTS) that ships with macOS: say, piped through afconvert to m4a. It works, it needs no network, and it sounds like a 2009 GPS unit. Good enough to ship a timeline, not good enough to listen to for a minute.

The second uses Edge’s neural TTS through @andresaya/edge-tts: no API key, mp3 output, and it sounds like a person. The default voice is en-SG-LunaNeural, which is a bonus rather than a requirement. It happens to be a Singapore English voice, so the Singlish the narration is written in lands the way it reads; any Edge voice works, and WALKTHROUGH_TTS_VOICE picks another one.

OptionVoiceOutputNeedsWhy not only this
Edge neuralen-SG-LunaNeuralmp3Network, no keyThe service or the voice can change
macOS saySamantham4aA MacLinux machines have no say
espeak-ngen-uswavThe packageUnderstandable, not pleasant
Silent tracknonewavNothingKeeps the timeline watchable

That fallback chain is the actual requirement: Edge, then macOS say, then espeak-ng, then a silent track of the estimated length, so a Linux box in continuous integration (CI) still produces a watchable timeline.

network fails

not on Linux

not installed

Edge neural TTS
en-SG-LunaNeural

macOS say
Samantha

espeak-ng

silent track
estimated length

Captions have 1 rule worth keeping: the subtitle burned into the video is the exact narration string, not the short chapter caption. 2 copies of the same sentence is exactly the drift this feature exists to avoid. The step’s duration comes from the audio that was actually generated, so a long sentence gets a long frame instead of a cut-off one.

A generated artifact needs a check #

npm run docs:check runs on every pull request and on pushes to main. It checks that the docs match the encoded flows and timelines, that every referenced screenshot, audio track and video exists, and that the sitemap has exactly the expected routes.

no

yes

flows.ts

generated docs
+ README block

committed media
+ timelines

docs:check

all match?

CI fails

merge

That is the answer to the 14-of-17 accounts problem: the README block and docs/WALKTHROUGH.md are generated between markers, so the guide cannot list a different set of flows than the ones that exist.

Refreshing the media is manual, because it needs Chromium and a speech engine; the regular CI job only checks that what is committed agrees with what the code says.

The first real bug in the generator was found by CodeQL, not by me: the markdown table writer did not escape backslashes, so a caption containing a backslash could break the generated table. The fix was 5 lines. The docs generator is code, it gets reviewed like code, and it can break the build like code.

Limitations #

The CI check proves that the docs, the timelines and the media agree with each other. It cannot prove that they still match the app: if the UI changes and nobody re-runs the capture, every check passes and the tour shows the old screen.

Every flow is scripted against data-walkthrough hooks and CSS selectors. A UI change that drops 1 breaks the capture, and you find out when you run it, not when you push.

The narration is generated audio committed as mp3, so editing a sentence means regenerating that step’s track, and the voice is whatever Edge TTS serves today, with a worse local fallback behind it.

Subtitles are burned into the frames. There is no transcript file to search, translate or hand to a screen reader.

And the media is ~4.6MB in the repository, served from the same host as the app.

Future work #

  1. Host the tours on YouTube and embed them. The committed media is ~4.6MB of frames and audio served from the same host on every visit. Uploading each tour once and embedding the player would move that bandwidth off the site, give the tours a shareable URL, and add captions and playback speed for free. The cost is a dependency on YouTube and an embed that is harder to style than the current player.
  2. Run the capture on a schedule in CI and fail when a screenshot changes beyond a threshold. That is the check that would catch UI drift.
  3. Emit the narration as a .vtt or transcript, for accessibility and for search.
  4. Add the obvious next tours: the FAQ and a bank detail page.

What I took away #

Generating the demo from the flow definition is what keeps it honest. A tour that is edited by hand drifts from the app within 1 release; a tour that is regenerated cannot, because the regeneration is the only way to change it.

But a generator is not self-maintaining either. Without docs:check in CI, the committed media and the encoded flows would still drift apart quietly, just more slowly. The check is the feature, the generator is the convenience.

The second bird was the one I did not plan for. The capture is the end-to-end test I never wrote: it drives the real app through the 3 flows that matter and fails on any step that no longer works, which is a kind of check the jsdom tests cannot make.

You can watch all 3 tours on hysa.jh123x.com/walkthrough. If you want the other half of that week’s work, the Optimize page that 1 of the tours walks through is in Making the HYSA Calculator suggest the next step.

↑