Skip to content

#249 PR3: extract pure logic from explorer.qmd to ES modules#12

Merged
rdhyee merged 1 commit into
mainfrom
feat/explorer-module-extraction
Jun 15, 2026
Merged

#249 PR3: extract pure logic from explorer.qmd to ES modules#12
rdhyee merged 1 commit into
mainfrom
feat/explorer-module-extraction

Conversation

@rdhyee

@rdhyee rdhyee commented Jun 15, 2026

Copy link
Copy Markdown
Owner

isamplesorg#249 PR3 — extract pure logic from explorer.qmd to ES modules

Third step of the strangler refactor (isamplesorg#249), behind the PR1 smoke gate (#9) and
PR2 characterization tests (#11). Extracts 10 closure-free functions out of the
explorer.qmd OJS god-block into two unit-testable ES modules. Behavior-neutral.

What moved

  • assets/js/sql-builders.jsescSql, escapeIlikePattern, textSearchWhere, textSearchScore
  • assets/js/explorer-utils.jsescapeHtml, searchTerms, parseNum, csvParamValues, sourceUrl, readHash

Same path-relative dynamic-import pattern as the existing source-palette.js.

Notable mechanics

  • OJS-safe swap (not the literal plan's "shadowing"). OJS forbids two cells of the same name, so an import-above / inline-below coexistence step is impossible. Each former function name(){...} cell is replaced in place by a single name = _module.name binding cell. Verified: no duplicate cells, no leftover inline defs.
  • Only intentional code change: readHash()readHash(hashStr = location.hash) so it's Node-testable. All 3 call sites are zero-arg; the default-param location reference is lazy (never hit in tests).
  • _quarto.yml: added both modules to the resources: allowlist — required for them to be copied into docs/ on render & deploy (same as source-palette.js; the deploy workflow ships docs/).

Tests / gate

  • tests/unit/{sql-builders,explorer-utils}.test.mjs — 13 node:test cases pinning exact outputs (esp. escapeIlikePattern metachar+quote escaping and readHash clamping/defaults).
  • explorer-e2e.yml: new fast node --test tests/unit/*.test.mjs step, ahead of the slow Quarto/Playwright steps. npm run test:unit for local use.

Verification (all green, local)

  • unit 13 ✓ · smoke 4 ✓ (incl. "loads without uncaught JS errors") · characterization 7
  • quarto render explorer.qmd ✓ → modules present under docs/assets/js/
  • Codex (gpt-5.5) review: no findings — independently byte-compared each extracted body against main:explorer.qmd (all executable-MATCH; sourceUrl only moved comments) and re-ran the gate.

Diff: explorer.qmd −79/+20; +2 modules, +2 unit specs.

🤖 Generated with Claude Code

Extract 10 closure-free functions out of the explorer.qmd OJS god-block
into two unit-testable ES modules, following the source-palette.js
dynamic-import precedent. No behavior change.

- assets/js/sql-builders.js: escSql, escapeIlikePattern, textSearchWhere,
  textSearchScore
- assets/js/explorer-utils.js: escapeHtml, searchTerms, parseNum,
  csvParamValues, sourceUrl, readHash. readHash gains a
  hashStr=location.hash default param so it is Node-testable; all 3 call
  sites are zero-arg and unchanged.

Wiring: each former `function name(){...}` OJS cell is replaced in place
by a single `name = _module.name` binding cell. OJS forbids two cells of
the same name, so the import block and the inline definitions cannot
coexist -- the swap is atomic rather than "import above, inline below".

- tests/unit/{sql-builders,explorer-utils}.test.mjs: 13 node:test cases
  pinning exact outputs (escapeIlikePattern metachar escaping +
  single-quote doubling; readHash clamping and defaults).
- .github/workflows/explorer-e2e.yml: add a `node --test` step as a fast
  PR gate ahead of the slow Quarto/Playwright steps.
- _quarto.yml: add the two modules to the resources allowlist so they are
  copied into docs/ on render and deploy (same treatment as
  source-palette.js).
- package.json: `npm run test:unit` convenience script.

Verified behavior-neutral locally: unit (13) + smoke (4) +
characterization (7) all green; explorer renders and boots with no
uncaught JS errors.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rdhyee rdhyee merged commit 3cdc39b into main Jun 15, 2026
3 checks passed
@rdhyee rdhyee deleted the feat/explorer-module-extraction branch June 15, 2026 15:48
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