Skip to content

fix(instrument-bundler): bundle files with upper-case extensions - #1806

Open
dyk1454683243-sudo wants to merge 2 commits into
DouglasNeuroInformatics:mainfrom
dyk1454683243-sudo:cursor/fix-uppercase-file-extension-977a
Open

dyk1454683243-sudo wants to merge 2 commits into
DouglasNeuroInformatics:mainfrom
dyk1454683243-sudo:cursor/fix-uppercase-file-extension-977a

Conversation

@dyk1454683243-sudo

Copy link
Copy Markdown

Instrument files whose extensions are upper case, such as IMG_0001.JPG or stim.PNG, crash every tool that reads them with Pattern matching error: no pattern matches value ".PNG".

BUNDLER_FILE_EXT_REGEX is case-insensitive, so those files are accepted as inputs. extractInputFileExtension returned the match in its original case while typed as the lower-case BundlerInputFileExtension union, and inferLoader's exhaustive match then threw. That path is shared by bundle(), the instrument-bundler CLI, serve-instrument, InstrumentReposService.readInstrumentInputs, and the playground's inferFileType.

extractInputFileExtension now lower-cases the matched extension, so the value really is a BundlerInputFileExtension and every consumer treats .PNG like .png.

Tests: packages/instrument-bundler/src/__tests__/utils.test.ts asserts extractInputFileExtension('a.PNG') is .png and that inferLoader('IMG_0001.JPG') is dataurl. The instrument-repositories Playwright spec cannot carry a fixture asset: importing a repository clones from GitHub, which the test environment deliberately does not do.

Fixes #1798

Co-Authored-By: Grok 4.7

BUNDLER_FILE_EXT_REGEX accepts any case, but extractInputFileExtension
returned the match unchanged, so inferLoader's exhaustive match threw on
values like ".PNG". Lower-case the extracted extension so every consumer
sees a BundlerInputFileExtension.

Co-Authored-By: Grok 4.7

@gdevenyi gdevenyi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this fix. The diagnosis is correct, and I confirmed that the bundle() repro from #1798 fails on main and passes with your change.

The maintainers accept case-insensitive extension handling in the bundler. Upper-case module declarations in runtime/v1/env.d.ts will come in a separate follow-up, so you do not need to add them here.

One item before this can merge:

  1. Please add an end-to-end test in testing/src/specs/playground.spec.ts. The instrument-repositories spec cannot carry a fixture, but the playground spec can. It already loads multi-file instruments from a share link with generatePlaygroundURL({ files: [...] }) (see the test at around line 135). Use an index.ts that imports ./stim.PNG and a stim.PNG file whose content is base64-encoded PNG data (the playground decodes asset files in editorFileToInput). Then assert that the preview renders the instrument. This goes through the same path that crashed in #1798, and the repository requires an e2e test for every change.

If you hand this to Claude Code, Fable 5 is the right size — the change is in the instrument pipeline, where we use the strongest model.

Reviewed at commit b6f4077.

…ase PNG

The preview loads index.ts plus a base64 stim.PNG through the same
editor-to-bundler path that crashed on upper-case extensions.

Co-Authored-By: Grok 4.7
@dyk1454683243-sudo

Copy link
Copy Markdown
Author

Added the playground end-to-end test should render a share link that imports an upper-case PNG, so the preview shows the stimulus in testing/src/specs/playground.spec.ts. It opens a share link whose index.ts imports ./stim.PNG, with the PNG carried as base64, and asserts the preview renders that stimulus. Locally, pnpm --filter @opendatacapture/testing lint passed, pnpm exec vitest --project instrument-bundler --run passed (106 tests), and pnpm exec env-cmd -f ../.env playwright test src/specs/playground.spec.ts -g "upper-case PNG" --project=chromium passed. Upper-case module declarations in runtime/v1/env.d.ts are left for the maintainer follow-up, as requested.

This branch has not been deployed

No deployments
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.

Instrument files with an upper-case extension such as .PNG or .JPG crash the bundler, its CLI and serve-instrument with a pattern-matching error

3 participants