Repository navigation
Add the first test coverage for the Sheets add-on - #73
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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}.insertRenderedImageonly resized when an explicit pixel size was chosen: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
4xmultiplier; Automatic/Inline target one default row (~21px) so consecutive equations in a column don't collide. Width scales by the same factor, sincesetHeightalone stretches anOverGridImage.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.jsdoubles only the SpreadsheetApp boundary (a grid of cells plus anOverGridImagelist). Cell scanning, delimiter parsing, renderer routing, base64 round-trip storage and de-rendering all run the realSheets/Code.tsagainst the realCommonlibrary. The harness deliberately models a native 900dpi render size, so the sizing test fails against the old code instead of passing vacuously.ALE-Latex:+ base64 reconstructs the authored cell exactlyremoveAllrestores text character for character, removes the imagebefore $$x^2$$ afteris left alone — the whole-cell-only limitationsciweavers.orgValidation
npm test: 152 passing (was 144).ALE_ALT_TEXT_PREFIXfails only the round-trip test; the sizing test fails against the pre-fix code.successCount: 2, failureCount: 0; alt text decoded back to$$1+1=2$$and$$\frac{a}{b}$$;removeAllrestored both cells exactly and removed both images.tests/*.test.jsglob.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