Repository navigation
feat: browser BIDS validation on the upload page - #473
Merged
Merged
Conversation
validator-version.json is a copy of nemar-cli's pin (3.0.2). scripts/vendor-bids-validator.ts builds that release with deno bundle into one module worker, from scripts/bids-validator-worker.ts and the protocol the page shares with it, against a committed lock. The build is reproducible from a cold cache and from any directory. --relock resolves into a temporary lock and replaces the committed one only after every check has passed. Both Deno programs are excluded from tsconfig; typecheck and lint pass.
Output of: deno run -A scripts/vendor-bids-validator.ts public/vendor/bids-validator/3.0.2/ holds the bundle (10,267,556 bytes), SHA256SUMS, provenance.json and the license of each package built in (37 packages, and the Node.js shims the bundler adds). public/_headers gives the worker its own Content-Security-Policy: unsafe-eval (the validator uses the Function constructor) and a single connect-src host (HED schema downloads), and no Referer. The page policy is unchanged. Rebuilt from a cold cache in another directory: identical bytes.
bids-minimal is a byte-for-byte copy of nemar-cli's fixture of that name. annex-pointer is the participants.tsv pointer git-annex wrote for it. hed overlays two small HED files on it. The README names the origins.
report groups findings by code, errors first. gate decides what stops an upload the way the repository check does: errors block, warnings do not, errors on git-annex pointer files are not counted. A HED schema that could not be downloaded is listed with the warnings and not counted either, because that is a failure of the browser's request and not a fault in the dataset. wording holds the panel's sentences, privacy statement included. client runs the worker and never rejects; a run that has not answered in 15 minutes becomes "could not run". 84 unit tests on real-shape inputs and the real fixtures; no mocks.
Integrity: the bundle matches SHA256SUMS, carries the pinned release, and was built from the sources and lock in the tree. Drift: the pin equals nemar-cli's, strictly in CI (ci.yml now sparse-checks it out and sets NEMAR_CLI_VALIDATOR_PIN). Policy: the worker's header is the only static rule that allows eval and sends no Referer; the upload page's policy has no eval. Integration: the committed bytes validate the real fixtures, gate them, and make no request for a dataset whose HED schema ships. Full suite passes at this commit: 152 files, 4036 tests, with the pin variable pointing at nemar-cli dev. Lint clean, typecheck 0 errors.
The dropzone skipped every file whose name starts with a dot. .bidsignore is the one dotfile BIDS defines and the validator reads, so a dataset that lists its non-BIDS files there could pass neither the check on this page nor the repository check from the browser, with no way to fix it. It now travels with the upload, and the instant structure check no longer calls it a stray top-level file. Other dotfiles are still skipped. Two unit tests; suite passes (152 files, 4038 tests), lint clean.
After the instant structure check passes, the folder is validated in a module Web Worker, started on first use: /upload loads no new request until a folder is validated, and its own script grows from 13,783 to 22,672 bytes (stylesheet +3,952 bytes). The panel groups findings by code with file paths. Errors disable the upload button, warnings are advisory, and a HED schema that could not be downloaded is listed as a warning. A validator that cannot run (no worker, failed load, crash, no answer in 15 minutes) is its own amber state and lets the upload through. Cancel, a new drop and a reset drop a stale answer. The live region is always rendered, outside the panel that is hidden at rest, so a result set while the panel appears is heard; focus moves to the panel heading when a run starts. Run in Chrome against astro dev: valid, broken, git-annex pointer, HED (bundled and not), structure-error and 1,204-file datasets; cancel, re-drop, reset, Enter-submit while blocked; five ways for the worker to fail. Suite passes (153 files, 4052 tests), lint clean, typecheck 0 errors.
Records why the BIDS validator is built with Deno, committed, and run in a Web Worker under its own Content-Security-Policy: it needs unsafe-eval, which the page must not get. Also records the pin lockstep with nemar-cli, the gating rule (including the one place it is more lenient than the repository check), what the privacy sentence rests on, the .bidsignore change, and the npm.jsr.io route (installable with Bun, not taken here). Index updated.
CHANGELOG.md: the validator on /upload, the .bidsignore change, and the CI pin comparison. AGENTS.md: the architecture map entries, the Deno commands, and the lockstep note (re-vendor when nemar-cli moves the pin; never hand-edit public/vendor/; the worker's header is where its unsafe-eval lives).
Deploying nemar-website with
|
| Latest commit: |
285d0c2
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://9affba26.nemar-website.pages.dev |
| Branch Preview URL: | https://feature-browser-bids-validat.nemar-website.pages.dev |
5 tasks
The page exempted every HED_ERROR with sub-code SCHEMA_LOAD_FAILED, but that is seven conditions. A dataset with HED columns and no HEDVersion makes no request, passed the upload gate and failed the repository check, and the panel said "No BIDS errors found". Only a request that got no answer is exempt now. No specification, an invalid one, unmergeable library schemas, and any answer from GitHub, 404 for a version that does not exist included, stop the upload. The gate reads the validator's own wording, anchored at the start because the validator quotes the dataset's HEDVersion into other messages; an unknown wording stops the upload. When something is exempt the verdict says the HED annotations were not checked, in an amber tone. The wording of each case is copied from real runs (Chrome 155, Node 26 and Deno 2.9.7 with an unreachable proxy, a live 404) into the unit tests, and the real bundle is run offline for the rest: a real server that answers 404 or 503, and a closed port for no answer. The old broad rule fails 18 of the new tests. Suite 153 files, 4075 tests; lint clean; typecheck 0 errors.
Everything after the worker answered (the pointer lookup, the gate, drawing the panel) ran outside any try. A throw there left the state at "running" with the upload button disabled and Cancel doing nothing; in Chrome, with the panel's groups container made to throw, the page said "No BIDS errors found" and the button stayed disabled. startFullValidation now runs inside one try, and a throw becomes "could not run" like every other way the check can fail. validationCannotRun tells the person through the panel and, when there is none or it cannot draw, through the status line beside the button, so it is never only a console message. The worker's result is checked for the shape the page reads (isValidationReport) before anything uses it, and a failing progress callback no longer ends a run. The pointer lookup and the gate are one function, judge, which the page and the tests that run the real validator both call; every real report in those tests is held to the shape check after a structured clone. The test whose name claimed to check that the page says the check could not run only read the source; the tests that do are renamed for what they are, and cover the whole chain. Checked in Chrome: a result that is not a report, a throw while drawing, and no panel on the page. Suite 153 files, 4098 tests; lint clean; typecheck 0 errors.
The .bidsignore change was only tested at the unit level, with a FileList of stand-in names. Now the real bundle runs on real files: a stray foo.xyz is NOT_INCLUDED, an error on that file that stops the upload; with .bidsignore listing it the error is gone; and the same holds when the drop is what the dropzone keeps (hidden files and OS litter left out, .bidsignore kept), and fails again without it. The per-file decision that the drag-and-drop walk and the file input share is now one exported function, toDroppedFile, so real File objects test it for both. The walk's own plumbing (a browser's FileSystemEntry) cannot be built in Node and has no automated test; it was run in Chrome with a real folder dropped through CDP (Input.dispatchDragEvent): 9 files kept with .bidsignore, .DS_Store left out, and the check passed. Suite 153 files, 4110 tests; lint clean; typecheck 0 errors.
panel.ts sets text with textContent and nothing that parses HTML, because file names come from the person's disk and messages from the validator. That was a rule a reviewer had to remember. A source test now fails on innerHTML, outerHTML, insertAdjacentHTML, document.write or createContextualFragment in panel.ts, ignores comments that name them, and checks that the file does set text with textContent. Checked by putting innerHTML in the panel (fails) and in a comment (passes). Suite 153 files, 4116 tests; lint clean; typecheck 0 errors.
runValidation takes a deadlineMs option (the page still uses 15 minutes), so the give-up path can be run without waiting a quarter of an hour or faking the clock. Node has no Worker, so the test gives the client the browser's Worker surface over a real thread from node:worker_threads that never answers, with real timers: the run is settled as "could not run" at the deadline, the thread is really terminated (its exit event follows), the state lets the upload through, and Cancel ends the thread too with no later deadline. Checked by ignoring the parameter and by not terminating (both fail by timeout). Suite 153 files, 4119 tests; lint clean; typecheck 0 errors.
public/vendor/** is generated by scripts/vendor-bids-validator.ts, so it is marked linguist-generated (GitHub folds it in a pull request) and -diff (git does not print the 10 MB bundle or the licence text as a diff). The two small files a re-vendor is reviewed by, provenance.json and SHA256SUMS, stay diffable. Checked with git check-attr. Suite 153 files, 4119 tests; lint clean; typecheck 0 errors.
The vendor script's header now says identical bytes need network access (the packages come from jsr.io and npm, the shim licence from unpkg.com) and exactly the Deno that built the committed bundle, 2.9.7, and that the script prints a note when it is not that Deno. A re-vendor at the same version reuses the worker's URL. The client's comment on workerUrl and ADR 0028 now say so: the browser is corrected by revalidation, not by the name, because Pages answers a static file with an ETag and max-age=0, must-revalidate, and nothing may give the path a longer lifetime. The ADR's npm.jsr.io alternative links the follow-up issue (#474). Suite 153 files, 4119 tests; lint clean; typecheck 0 errors.
The list of findings in a group is capped at 18rem and scrolls, and a scrolling region that a keyboard cannot focus cannot be scrolled by one. It is now a tab stop (tabindex 0) with an accessible name, "Findings for <code>", and a visible focus ring. Checked in Chrome: Tab from a group's summary lands on the list, six ArrowDown presses scroll it 240 px, and the accessibility tree names it. A source test holds the pieces together. Suite 153 files, 4120 tests; lint clean; typecheck 0 errors.
The review fixes added code to the page's script (the shape check, the single try, judge, the deadline option, the HED copy), so the figures in the ADR and the changelog were stale. Measured on the build of this head against the unmodified base: the script goes from 13,783 to 25,031 bytes (4,841 to 8,927 gzipped, so +11.2 KB, +4.1 KB gzipped) and the site's one stylesheet grows by 4,077 bytes (891 gzipped). The ADR also says what the issue asked for and this is not: an unchanged initial payload for /upload, which holds for the validator and not for the code that drives it.
The state is set to "finished" before the panel draws the result. If showFinished or setStatus then threw, the catch called validationCannotRun, which set "unavailable" and let the upload through although the validator had found errors. The error count is now remembered when the gate answers. A throw after that keeps the verdict: the state stays "finished" with its errors, the upload button stays disabled, the line beside it says "Fix the BIDS errors above to enable the upload.", and the console has the error. A throw with no errors, or before the gate has answered, is still "could not run" and the upload is possible. A source test pins the order; in Chrome, with the panel's groups container made to throw, a verdict with 6 errors leaves the button disabled and one with none says the check could not run. Suite 153 files, 4121 tests; lint clean; typecheck 0 errors.
The cancel test said the deadline does not fire afterwards, and nothing asserted it. It now waits 250 ms, past the 200 ms deadline, and checks that the worker was terminated once (a deadline that fired would end it a second time) and that nothing was written to the console. Checked by removing clearTimeout from settle: the test fails with 2 terminations. Suite 153 files, 4121 tests; lint clean; typecheck 0 errors.
This was referenced Oct 21, 2026
Open
Merged
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.
Summary
The upload page now validates the dropped folder with the real BIDS validator (
@bids/validator3.0.2, the release nemar-cli pins and the repository check runs) in the browser, before any file is sent.The instant structure check is unchanged and runs first; the full check follows it, with a progress state and a panel of findings grouped by code, errors first, with file paths.
An error disables the upload button and a warning never does, which is the repository check's rule, including its exemption for git-annex pointer files.
The design and the alternatives are in ADR 0028.
A follow-up, #474, builds the validator from
npm.jsr.iowith Bun, so that it need not be committed.This PR targets
staging, so the issue is closed by hand after the merge.Where this differs from the issue text
The issue proposes importing it on the page.
Measured in Chrome 155, that fails: the validator evaluates code with the
Functionconstructor (the schema's expressions, and Ajv), and/upload's Content-Security-Policy has no'unsafe-eval', so the run throwsEvalError.A worker takes its policy from its own response, so the worker script gets a header rule in
public/_headers(default-src 'none'; script-src 'self' 'unsafe-eval'; connect-src https://raw.githubusercontent.com, withReferrer-Policy: no-referrer) and the page's policy is untouched.The alternative,
'unsafe-eval'on/uploadin the pattern of ADR 0009, is one line insrc/middleware.ts; the rest of this PR does not depend on the choice.@bids/validator/webdoes not exist in 3.0.2.The worker imports
@bids/validator/files/browser(fileListToTree) and@bids/validator/validate(validate).dev).Bun cannot install a
jsr:specifier, and Cloudflare's build has no Deno.JSR's npm registry (
npm.jsr.io) does serve the package, and Bun can install it with a scope entry;bun buildof the entry points gave a bundle that reported the same findings.That route was not built through Astro and Vite; ADR 0028 records it as the alternative a later change could take, with the protocol, gate, panel and tests unchanged, and Build the BIDS validator worker from npm.jsr.io with Bun #474 tracks it.
/upload's initial payload is not unchanged: its own script grows by 11.2 KB (4.1 KB gzipped).The issue asked to keep it unchanged.
The 10 MB validator is still fetched only when a folder is validated, but the code that drives it (the client, gate, report, panel and wording modules) is part of the page's script, which goes from 13,783 to 25,031 bytes (4,841 to 8,927 gzipped), and the site's one stylesheet grows by 4,077 bytes (891 gzipped).
What is in it
validator-version.json(copy of nemar-cli's pin),scripts/vendor-bids-validator.ts(Deno;--relockafter a pin move),scripts/bids-validator-worker.ts(the module it bundles),scripts/bids-validator-worker.lock.public/vendor/bids-validator/3.0.2/: the bundle,SHA256SUMS,provenance.json,THIRD_PARTY_LICENSES.txt(the 37 packages and the Node.js shims the bundler adds).The build is reproducible: the same bytes from a cold Deno cache and from another directory, given network access and the same Deno (2.9.7).
.gitattributesmarkspublic/vendor/**as generated, so GitHub folds it andgit diffdoes not print the bundle;provenance.jsonandSHA256SUMSstay diffable.src/lib/bids-validation/:protocol.ts(shared with the worker, imports nothing),gate.ts,report.ts,wording.ts,client.ts,panel.ts;src/components/BidsValidationPanel.astro; the wiring insrc/pages/upload.astro..bidsignorenow travels with a web upload (src/lib/upload-client.ts,src/lib/bids-precheck.ts): the dropzone skipped every dotfile, so a dataset that lists its non-BIDS files there could pass neither check from the browser.Other dotfiles are still skipped.
Fixtures are real files;
test/fixtures/bids-validation/README.mdnames the origins, including a pointer written by git-annex itself.ci.ymlsparse-checks out nemar-cli's pin.Gating rule
warningerrorerrorwhoselocationis a git-annex pointer fileHED_ERRORwithSCHEMA_LOAD_FAILED, where the browser's request for the schema got no answer at allSCHEMA_LOAD_FAILED: HED columns and noHEDVersion, an invalid or unmergeable specification, a version GitHub answers 404 for, any other answer from GitHub (a 503 included)The pointer rule is the repository check's (
run-bids-validation.yml): a file of fewer than 1024 bytes with a line that starts/annex/objects/, compared with the error'slocationas a whole string.A browser is never told about symlinks, so the check's other half, symlinks, has no counterpart here.
The options are the check's (
maxRows1000), except that warnings are kept, because the page lists them.The HED row is the one place the page is more lenient than the repository check, on purpose, and it is narrow.
SCHEMA_LOAD_FAILEDis one sub-code for seven conditions of the HED validator; only a request that got no answer (offline, a failed lookup, a blocker) is the browser's failure and not the dataset's, and an answer from GitHub, of any status, is the answer the check would get.The gate tells them apart by the validator's own wording, anchored at the start of the message because the validator quotes a dataset's
HEDVersioninto some of its other messages, and a wording it does not know stops the upload.The cost is that a page that cannot reach GitHub lets through a HED dataset naming a version that does not exist, which only the repository check catches.
Privacy
The panel says the check runs in the browser and nothing from the files is sent anywhere, with one stated exception: a HED schema version the validator does not ship is downloaded from
raw.githubusercontent.com, in a request that carries only its name and version and no Referer.Checked in Chrome with every request logged: no request at all for a dataset whose HED schema ships (and for datasets with none), one
GETfor one whose does not.The worker's own policy allows that one host and nothing else; a same-origin
fetch, another host, a WebSocket andimportScriptswere all refused, in Chrome 155 and in Firefox 158, underwrangler pages dev, which applies_headersas Pages does.Verification
bun install: no changes (package.jsonandbun.lockuntouched, no version bump).bun run test: 153 files, 4121 tests pass (the base had 144 files, 3917 tests), run as CI runs it: the fiveNEMAR_CLI_*variables against a snapshot of nemar-clidev.A sibling
../nemar-clithat is behindorigin/devfails the new pin test (a stale one pins 2.4.1); update it, or setNEMAR_CLI_VALIDATOR_PIN.bun run typecheck: 0 errors, 0 warnings (the 13 hints are the base's).bun run lint: clean.bun run build: succeeds, with the same five warnings as the base;dist/_routes.jsonexcludes/vendor/*, so the files are static assets, anddist/_headerscarries the worker rule.dev), build and the Cloudflare Pages deploy all pass.sha256sum -c SHA256SUMSpasses, and its ETag on the preview deployment did not change between the first head and this one.HEDVersion, an invalid one, unmergeable library schemas and a 404 was captured in Chrome 155 (the worker served by a preview deployment) and Node 26 (the library schemas in Node only), and for a request with no answer in Chrome (aborted) and in Node 26 and Deno 2.9.7 (HTTPS_PROXYat a closed port).The wording is copied into
gate.test.ts; the integration tests produce the ones that need no network again (a real local server that answers 404 or 503, a closed port for no answer), so a validator release that rewords one fails there.Against the old broad rule 18 of the new tests fail.
.bidsignore, ofpanel.tsusinginnerHTML, of the deadline parameter and of terminating the worker are all caught.astro devwith the dev sign-in: valid, broken-sidecar, git-annex-pointer, HED (bundled; noHEDVersion; a version GitHub answers 404 for; a request that gets no answer), structure-error and larger datasets (1,204 files and 10,404 findings in 0.8 s from the click; 20,003 files and 135,003 findings in 24 s); a.bidsignoreupload by the file input and by a real folder dropped through CDP, which runs the drag-and-drop walk (9 files kept with.bidsignore,.DS_Storeleft out); Cancel, a second drop while running, "Drop something else", Enter in a field while blocked; five ways for the worker to fail (offline, 404, a script that throws, the wrong content type, an answer offailure) and three more (a result that is not a report, a throw while the panel draws the result, with and without errors in it, no panel on the page); the 15-minute limit with a faked clock; Tab to a findings list and ArrowDown scrolling it; focus and the live-region announcements; light and dark; 390 px wide with no horizontal overflow.Firefox 158 ran the policy probe and the real validator through
wrangler pages devwith the same results.bun run dev:/uploadwithout a session answers 302 to the sign-in page, and with the dev session 200text/htmlwith no reference to the vendor file, no preload and no'unsafe-eval'in its policy; the asset URL answers 200text/javascript, 10,267,556 bytes.content-security-policyandreferrer-policyof the_headersrule andcache-control: public, max-age=0, must-revalidate,/upload's own policy is unchanged, and in Chrome 155 the module worker, started from that origin, validated thebids-minimalfixture (0 errors, 30 warnings, schema 1.2.7, about half a second with the download) with no request other than the asset./upload's own load: its script grows from 13,783 to 25,031 bytes (4,841 to 8,927 gzipped); the site-wide stylesheet grows by 4,077 bytes (891 gzipped).Nothing imports the bundle (the page script holds the worker's URL as a string), the HTML names no vendor file, the worker file is requested only when a folder is validated, and the server bundle lists the files as static assets and does not carry them.
Asset: 10,267,556 bytes (1,456,230 with
gzip -9, 872,874 withbrotli -q 9).Known limits
A few of the tests read the page's and the panel's source as text (the guard around the bind, the fallback line, the single
try, thetextContentrule, the list's tab stop), because there is no DOM to run them in; they are named for what they are.Safari was not run.
walkEntry) needs a browser'sFileSystemEntry, so its plumbing has no automated test.Its per-file decision, which
.bidsignoredepends on, is one function,toDroppedFile, shared with the file input and tested with real files, and the walk itself was run in Chrome on a real folder._headersis served.It was checked on this PR's preview deployments (above), not on
test.nemar.orgor production.After the merge to
staging,curl -sI https://test.nemar.org/vendor/bids-validator/3.0.2/bids-validator-worker.jsshould show the samecontent-security-policyandreferrer-policy; without them the worker still runs, but the privacy sentence no longer holds.max-age=0, must-revalidate); the path must never be given a longer lifetime.deno run -A scripts/vendor-bids-validator.ts --relockis run; that needs Deno on a maintainer's machine, not in CI.docs.nemar.org/web/uploadingdescribes BIDS validation as server-side only, so it needs a matching update in the documentation repository, which this PR does not touch.Refs #161