Skip to content

Add the first test coverage for the Sheets add-on - #73

Merged
Divide-By-0 merged 2 commits into
masterfrom
codex/sheets-test-coverage
Sep 20, 2026
Merged

Divide-By-0 merged 2 commits into
masterfrom
codex/sheets-test-coverage

Conversation

@Divide-By-0

@Divide-By-0 Divide-By-0 commented Sep 19, 2026 •

Copy link
Copy Markdown
Owner

Sheets had zero test coverage, so its correctness was only ever asserted by hand. This adds the missing coverage — and the first live run it enabled immediately surfaced a real bug, which this PR also fixes.

Human intent

Rephrased from the request: finish the Sheets add-on and actually verify it works, without releasing it and without changing OAuth scopes on the shared production project that serves every Docs/Slides user.

The bug the live run found

Server renderers return the equation at \dpi{900}. insertRenderedImage only resized when an explicit pixel size was chosen:

if (preferredSize > 0) { /* scale */ }

Automatic and Inline both arrive as size 0 (Common.getSize("smart") === 0), so they skipped the resize entirely and the native image went in as-is. A single $$1+1=2$$ covered roughly 14 rows and overlapped the equation beneath it. Both the server path and the client path funnel through this call, so both were affected. This is the add-on's default setting — the first thing any user would hit.

Fix: scaling is now unconditional. An explicit size keeps its historical 4x multiplier; Automatic/Inline target one default row (~21px) so consecutive equations in a column don't collide. Width scales by the same factor, since setHeight alone stretches an OverGridImage.

Verified live in a bound test spreadsheet — before: several hundred px tall; after: 22px, sitting on its own row, with the round trip still exact.

What the tests cover

tests/helpers/sheets-harness.js doubles only the SpreadsheetApp boundary (a grid of cells plus an OverGridImage list). Cell scanning, delimiter parsing, renderer routing, base64 round-trip storage and de-rendering all run the real Sheets/Code.ts against the real Common library. The harness deliberately models a native 900dpi render size, so the sizing test fails against the old code instead of passing vacuously.

Test What it pins
render + anchor equation becomes an image anchored to its own cell
alt-text round trip ALE-Latex: + base64 reconstructs the authored cell exactly
de-render removeAll restores text character for character, removes the image
mixed cell before $$x^2$$ after is left alone — the whole-cell-only limitation
Automatic / MathJax both defer to the client; zero server fetches
retired renderer no request reaches sciweavers.org
multi-row three equations across four rows render once each
image sizing Automatic fits ~one row and preserves aspect ratio

Validation

  • npm test: 152 passing (was 144).
  • Negative controls: flipping ALE_ALT_TEXT_PREFIX fails only the round-trip test; the sizing test fails against the pre-fix code.
  • Live end-to-end in Google Sheets via the Apps Script editor: successCount: 2, failureCount: 0; alt text decoded back to $$1+1=2$$ and $$\frac{a}{b}$$; removeAll restored both cells exactly and removed both images.
  • Picked up by CI automatically via the tests/*.test.js glob.

Scope boundaries

No production OAuth scope was changed — the shared consent screen behind the published Docs/Slides add-ons is untouched. Live testing ran through a separate throwaway GCP project and a container-bound script, so nothing about the Marketplace listing changed. Docs v96 and Slides v16 are unaffected.

Known remaining rough edge, not addressed here: a tall equation like \frac{a}{b} scaled to one row height becomes small, because aspect ratio is preserved. That is a design question about Automatic sizing rather than a defect.

🤖 Generated with Claude Code

Divide-By-0 and others added 2 commits September 19, 2026 11:42
Sheets had no tests at all, which is why its behaviour was only ever checked by
hand in a live spreadsheet — and why it is the one surface whose correctness we
could not state. These run the real Sheets/Code.ts against the real Common
library; only the SpreadsheetApp boundary is doubled, so cell scanning, delimiter
parsing, renderer routing, base64 round-trip storage and de-rendering are all
production code.

Covers: whole-cell equations render and anchor to their source cell; the authored
text survives base64 round-trip in the image alt text; De-render All restores it
character for character and removes the image; a cell mixing prose with an
equation is deliberately left alone (the documented Sheets limitation); Automatic
and MathJax defer to the client instead of fetching; the retired Sciweavers host
is never requested; and every equation in a multi-row sheet renders exactly once.

Verified these bite: flipping ALE_ALT_TEXT_PREFIX fails the round-trip test.
They join CI automatically via the tests/*.test.js glob in `npm test`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Found by running the add-on live for the first time: server renderers return the
equation at \dpi{900}, and insertRenderedImage only resized when an explicit
pixel size was chosen. Automatic and Inline both arrive as size 0, so they skipped
the resize entirely and the native image was inserted as-is — a single "1+1=2"
covered roughly 14 rows and overlapped the equation beneath it.

Scaling is now unconditional. An explicit size keeps its historical 4x multiplier;
Automatic/Inline target one default row (~21px) so consecutive equations in a
column do not collide. Width is scaled by the same factor, since setHeight alone
stretches an OverGridImage.

Verified live in a bound test spreadsheet: before the fix the image was several
hundred pixels tall, after it is 22px and sits on its own row, and the
render -> alt-text -> de-render round trip still restores the source exactly.

The regression test models a real 900dpi render in the harness, so it fails
against the previous code rather than passing vacuously.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Divide-By-0
Divide-By-0 merged commit c989025 into master Sep 20, 2026
3 checks passed
@Divide-By-0
Divide-By-0 deleted the codex/sheets-test-coverage branch September 20, 2026 00:15
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