Skip to content

Development setup ​

This page is for working on SparkForensics itself. To run the dashboard as a user, see Run it locally.

You need Node 22.18+ (CI uses the version in .nvmrc) and git on your PATH: the first test or build run fetches the tuning reference with it. Clone the repo, then:

bash
git submodule update --init dev/log-corpus   # or: git clone --recurse-submodules
npm install
npm test              # vitest run: the root suite (site app and dev tooling)
npm run test:watch    # vitest, watch mode
npm run test:core     # packages/core's suite: detectors, analyzer, parser, MCP tools
npm run test:cli      # packages/cli's suite (packs and spawns the real tarball)
npm run test:mcp      # packages/mcp's suite (packs and spawns the real tarball)
npm run dev           # Vite dev server for the app itself
npm run build         # production build, outputs dist/ (plus dist/export-template.html, the HTML download's template)
npm run preview       # serves dist/ locally
npx tsc --noEmit      # typecheck (strict TypeScript across src/, tests/view/ and packages/core/src/)
npx tsc --noEmit -p tsconfig.check.json   # typecheck the Node entry points and tests outside src/ (scope: testing.md)
npm run lint          # eslint over the repo's JS, oxlint over its .ts/.tsx
npm run lint:structure  # ast-grep structure rules over src/, packages/core/src/ and the tests (rules/, tested by rule-tests/)
node packages/cli/bin/sparkforensics-analyze.mjs <file|rolling-log-dir>   # run the CLI analyzer against a log, outside the browser

npm run test:coverage, at the root or inside packages/core, cli, mcp or server, runs that suite with --coverage (v8 provider, lcov and text reporters, plus html at the root; written to <pkg>/coverage/lcov.info). CI's build, core, cli, mcp and server jobs all run through it and upload to Coveralls, merged by a final finish job.

The dashboard's Download HTML dashboard fetches export-template.html from beside the app, so under npm run dev it fails with an error toast; use npm run build && npm run preview to try it.

npm install also runs the prepare script, which points git at .githooks/. After that, a pre-commit hook lints staged JS and TS files on every commit, and runs npm run lint:structure when staged files are under src/ or are structure rules. Fix what it reports, or skip it with git commit --no-verify.

The tuning reference under packages/core/src/docs-content/{chapters,tuning,diagrams} isn't committed. It's generated from the shuffle-works/spark-tuning-reference commit pinned in packages/core/src/docs-content/upstream.json: the first npm test, npm run docs:dev or npm run build fetches it over HTTPS (about 2s, no credentials) and later runs reuse the gitignored copy while it matches the pin. npm run docs:fetch does the same step on its own. Never edit those folders: fix the content upstream, then npm run docs:bump to move the pin. Running the MCP or CLI bins from source (node packages/*/bin/...) doesn't fetch it, so run npm run docs:fetch first: without it the MCP's tuning-reference lookups come back empty. npm run docs:bump [-- <sha>] moves the pin (default: upstream head), regenerates the docs and writes the changeset; put the compare link it prints in the PR body. npm run docs:bump -- --check [<sha>] runs the anchor gate and writes nothing; .github/workflows/tuning-reference-drift.yml runs it with test:core every week.

Offline, a cached copy keeps working. If the pin has moved since, npm test and docs:dev warn and use the older copy, while docs:build, npm pack and anything with CI set fail. npm run docs:fetch -- --allow-stale keeps a stale cached copy with a warning when the fetch fails; docs:dev uses it. To build from a local upstream checkout instead (offline, or to preview upstream edits in this docs site before they merge), set SPARK_TUNING_REFERENCE_DIR:

bash
SPARK_TUNING_REFERENCE_DIR=../spark-tuning-reference npm run docs:dev

The same checks apply to that checkout. npm pack and CI accept it only when it sits at the pinned commit with no uncommitted content/ changes.

dev/log-corpus is a git submodule pointing at the public spark-event-corpus-data repo. It's optional locally: if you skip the git submodule update step above, the corpus-backed tests (such as packages/server/test/shs-proxy-fixture.test.js) report as skipped rather than failed, which is expected, not a bug. CI's core and server jobs check it out and run them (plus the corpus regression snapshot in core); the build, cli and mcp jobs don't, so a corpus-backed test belongs in packages/core or packages/server.

The packages/server/ package (the optional local-server deploy mode) keeps its own dependencies and test suite. Run it from the repo root: a second npm install inside packages/server prunes the shared root node_modules's workspace symlinks.

bash
npm run test:server   # runs packages/server's own suite, not part of `npm test`

Packing or releasing packages/server/ builds the docs site for you: its prepack runs packages/server/scripts/copy-frontend.js, which runs the root npm run build (docs:build included), so the packed artifact always ships /sparkforensics/docs/.

This docs site has its own dev loop:

bash
npm run docs:dev       # VitePress dev server for docs-site/
npm run docs:build     # production build; flags links to missing pages (anchors: `node scripts/check-doc-anchors.mjs`)
npm run docs:preview   # serves the built docs site locally

Generated and vendored files ​

  • packages/core/src/docs-content/detection/*.md (gitignored) is split from docs-site/user-guide/understanding-findings.md, one file per finding tag. docs:dev, docs:build, the vitest globalSetup and prepack regenerate it when it differs from the guide, so nothing is committed or run by hand. To regenerate on demand: npm run split-detection-docs.
  • docs-site/detectors/ and docs-site/.vitepress/detectors-data.json (gitignored) are the detector catalog pages and the data the Vue components render, written by scripts/build-detector-pages.mjs from the catalog in packages/core, dev/detector-examples.json and dev/detector-example-runs.json. The script also writes each page's example data to docs-site/public/detector-widget/data/. docs:dev and docs:build run it; to regenerate on demand: node scripts/build-detector-pages.mjs.
  • docs-site/public/detector-widget/app/ (gitignored) is the example app each detector page frames, built from docs-widget.html by npm run build:docs-widget, which docs:dev and docs:build run.
  • packages/{cli,mcp,server}/vendor-core/ (gitignored) is rebuilt only at prepack. In the monorepo the bins load packages/core/src/load-node-core.js, which resolves through load-vendored.js and uses a leftover vendor-core/ only while its core-source-hash.txt matches packages/core/src; otherwise it warns on stderr and runs the source. load-node-core.js is the one module a bin locates by hand (vendor-core/load-node-core.js in a packed install). It loads packages/core/src/node.ts once, and the bin reads every core name it uses from that module. packages/core/test/node-entry.test.js runs each bin with --help and fails when it does not start.
  • The CLI's export-template/ has no such check. Without it, --export-html from source uses the repo-root dist-export/ from npm run build:export (not produced by npm run build); a leftover export-template/ wins over that, so rebuild it with node scripts/vendor-export-template.mjs or delete it before trusting a local --export-html.

Core entry points ​

@sparkforensics/core lists its entry points in the exports map of packages/core/package.json, with no wildcard. Each is a plain re-export file in packages/core/src/:

  • analysis: the analysis the app and the tools share (analyze, auditConfig, the detector catalog and docs, thresholds, run interpretation and comparison, evidence report, ingest).
  • view-model: what src/view renders (formatting, finding names, presentation and filters, the plan graph model, evidence availability).
  • export: the HTML export data, run payload and session snapshot, plus the vendored gzip codec that decodes them.
  • types: the model and finding types (export type only).
  • browser: core services that need a real browser (the IndexedDB recent-files list); scripts/vendor-core.mjs leaves it out of the vendor tree.
  • cli and mcp: the cli/ modules, and the MCP server factory with its tools and error shape.
  • node: every name the CLI and MCP bins read.

src/ imports core through analysis, browser, export, types and view-model only (the core-entry-points-only rule of npm run lint:structure). The export build reaches view-model and export, so they re-export only modules on ALLOWED_EXPORT_CORE_MODULES in scripts/export-analysis-guard.mjs; a new analysis import for the export goes through interpretRun, not through a new re-export there. Specs that mock or load one core module by file import it through the @core-src/ alias (vitest.config.js and tsconfig.json), which points at packages/core/src/; packages/cli/test imports load-vendored.js by relative path.

The docs site's anchor clicks ​

VitePress installs a window-level, capture-phase click listener (node_modules/vitepress/dist/client/app/router.js) that catches clicks on any <a href="#..."> pointing at the current page and scrolls to the target itself, before a handler the theme adds on that element runs, so preventDefault() there is too late. An interactive control built over in-page anchors, such as the footnote-marker popovers in docs-site/.vitepress/theme/citation-chips.ts, must drop the element's href and restore role, tabindex and keyboard handling by hand.

That router scrolls with its own offset, while a deep link, and every click on the published tuning reference (which ships without hydration), is a native fragment jump that follows scroll-padding-top. Both read one measured value: docs-site/.vitepress/anchor-offset.js, inlined into every page's head, sizes it from the pinned chrome on screen, which includes the Shuffle Works product bar on the published site. Never write that bar's marker attribute literally in the docs source, prose included: the hub skips injecting its bar into any built page that contains it.

The app side of that contract is three DOM markers, all read in src/view/shuffle-hub.ts (PRODUCT_BAR_SELECTOR, HUB_FOOTER_SELECTOR) and set on the dashboard, plan graph and run comparison routes. Their exact attribute names live in that file, not here, for the reason above.

  • The product-bar marker (a data-shuffle- attribute ending in product-bar) is present when the host site injected its shared bar into the published shell. ProductBarPortal portals the page's header controls into it; without it they render in place.
  • The footer marker (a data-shuffle- attribute ending in footer) is present when the host site injected its footer.
  • The dashboard test id (data-testid="dashboard") is the signal the host site's chrome-toggle script uses to hide the shared nav and footer while a dashboard is on screen. Each of those routes carries it, and App renders only one at a time, so it stays present across route changes.

Lists, counts and default thresholds of the detectors come from the detector catalog, not from hand-written prose. In a contributor page, use <DetectorTypeList family="plan" /> (or region="reference") for a list of finding types and <DetectorThresholds /> for the default-threshold table, and name no count of detectors, widgets or tools (tests/docs-contributor-counts.test.js rejects one). The header markup the shared bar and assistive technology read (the page-controls marker, the switch's aria-label, the home page's main landmark) is rendered by copies of five default-theme components in docs-site/.vitepress/theme/overrides/, which config.ts aliases over the originals. After a VitePress upgrade, diff those copies against node_modules/vitepress/dist/client/theme-default/components/.

Driving the app in a browser ​

  • Sample logs: download one from a Spark History Server with curl -o app.zip "<baseUrl>/api/v1/applications/<appId>/logs" and drop the zip in as-is (single-file and rolling logs both unwrap), or the .zstd event log inside it. Private logs follow the naming rule in Testing.
  • Loading a file under Playwright: the drop zone prefers showOpenFilePicker, a native dialog that localhost Chromium can't drive. Run await page.evaluate(() => delete window.showOpenFilePicker) before clicking Choose file, then setInputFiles on [data-testid=file-input] or handle the filechooser event.
  • Run comparison: on the landing page, click Compare two runs, fill the Baseline and Candidate slots the same way (each has its own [data-testid=file-input]), then click Compare. Both runs parse one after the other through the one worker. From a run's dashboard, the topbar's Compare with another run opens the same view with that run in the baseline slot (a cached RunSource, not parsed again). View baseline/candidate dashboard drills into one run, and ← Back to comparison returns.
  • The landing page's Try a sample run (src/view/DropZone.tsx) loads a gzip-compressed corpus log from public/sample-runs/: the corpus candidate with the most findings under sparkforensics-analyze --format json. Rerun that scan over every candidate, against the current corpus, before swapping the bundled sample.
  • Screenshots on a PR: the gh token can't use GitHub's browser-only attachment uploader. Commit the PNGs to a throwaway asset branch and embed them by commit SHA as https://raw.githubusercontent.com/<owner>/<repo>/<sha>/<path>.png. The repo is public, so every reader's browser loads them, and the binaries stay out of the feature diff.