Skip to content

chore: drop residual require('node:fs') calls in import-openneuro tests - #538

Merged
neuromechanist merged 1 commit into
devfrom
chore/drop-require-in-tests
May 18, 2026
Merged

neuromechanist merged 1 commit into
devfrom
chore/drop-require-in-tests

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Surfaced in the PR #537 release review (pr-review-toolkit code-reviewer, "Important" finding 1).

Commit f9c22b4 on the prior cycle fixed the same anti-pattern in `appendOpenNeuroProvenance`'s `readReadme()` helper but missed two other instances in the same file:

  • `test/import-openneuro.test.ts:224` (`seedMetadata`'s `readMeta()` helper)
  • `test/import-openneuro.test.ts:304` (the "metadata.json appears, config.json survives" test)

Both used `require("node:fs").readFileSync(...)` instead of the `readFileSync` already destructured from the top-level `import { ... } from "node:fs"`. `.rules/javascript.md` says ES modules only.

Pre-existing on dev, non-blocking for the v0.8.21 release, but bundling here keeps the test file consistent.

Test plan:

  • `bun test test/import-openneuro.test.ts`: 29/29 pass
  • `bun run typecheck` clean (root + backend)

Same anti-pattern that commit f9c22b4 fixed in appendOpenNeuroProvenance's
readReadme(). seedMetadata's readMeta() helper and the config.json read in
the 'metadata.json appears, config.json survives' test both still used a
dynamic require() instead of the readFileSync that's already destructured
at the top of the file. Flagged by the pr-review-toolkit code-reviewer
during the v0.8.21 release review; pre-existing on dev so non-blocking,
but bundling here keeps the file consistent and satisfies the
.rules/javascript.md 'ES modules only' rule.
@github-actions

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR538

Version: 0.8.21-PR538.260527d
Commit: 260527d


🤖 Updated on each push.

@neuromechanist
neuromechanist merged commit 51a5e1f into dev May 18, 2026
8 of 9 checks passed
@neuromechanist
neuromechanist deleted the chore/drop-require-in-tests branch May 18, 2026 10:37
neuromechanist added a commit that referenced this pull request May 18, 2026
…537)

* chore: bump version to 0.8.21-dev0

* Fix #535: stop seeding OpenNeuro placeholder description; route provenance to README

The OpenNeuro importer used to set the D1 datasets.description column to
'Imported from OpenNeuro <ds>' at import time. buildDatasetMetadata then
prioritized that catalog row over the LLM-enriched v2 description, so
the placeholder survived every successful enrichment cycle and the
public metadata.json endpoint kept returning it forever — defeating the
whole point of the enrichment pipeline that v0.8.20 unblocked.

Three coordinated changes:

src/lib/import-openneuro.ts: drop the description: 'Imported from
OpenNeuro <ds>' arg from importDataset(). Provenance is already
encoded by source: 'openneuro', source_id, and the on* dataset_id
prefix; the website renders the attribution badge from those fields.
Add a new appendOpenNeuroProvenance helper that writes a deterministic
'## Provenance' section to README.md at import time (idempotent;
re-running the importer is a no-op once the marker is present). The
README is the right place for human-readable provenance — it ships
with the GitHub repo, is visible without hitting any API, and stays
out of the LLM enrichment write path.

backend/src/services/data-router.ts: flip buildDatasetMetadata's
description-priority order so the LLM-enriched v2 (or v1) description
wins over row.description, with row.description as the fallback for
datasets that have not been enriched yet. The existing v2 fallback
test stays; new tests pin the placeholder→enrichment substitution and
the no-enrichment fallback.

test/import-openneuro.test.ts: new describe block for
appendOpenNeuroProvenance covering creation, append-to-existing,
idempotency, and the no-trailing-newline edge case.

The fix is forward-looking (new on* imports never get the placeholder)
and backward-compatible (existing on* datasets in D1 still have the
stale placeholder, but the metadata.json endpoint now correctly serves
the enrichment when present).

* fix(datasets): hide ds* catalog shadows when on* mirror exists (#534)

The list endpoint's catalog UNION used a single NOT IN clause comparing
nemar_catalog.id against datasets.dataset_id. That worked for the case
where a catalog row was "promoted" into the managed table under the
same id, but missed the ds -> on mirror case entirely: mirrored rows
have dataset_id = 'on002718' while the catalog shadow keeps
id = 'ds002718', so the NOT IN never matched.

Add a second NOT IN that joins on datasets.source_id where
source='openneuro'. Catalog rows whose id appears as a managed mirror's
source_id are now hidden.

Symptom (live before this change): GET /datasets?q=ds000117 returned
on000117 plus three ds* shadows (ds000117, ds002718, ds003645) all of
which had on counterparts in the catalog. After this change the list
returns only the canonical on* rows.

Adds a regression test asserting no on* row in /datasets has its
ds* counterpart alongside it.

Refs nemarOrg/website#1 (redesign epic discover-page dedup).

* chore: bump version to 0.8.21-dev1

* Address review finding: drop require('node:fs') in test helper

The pr-review-toolkit code-reviewer flagged that the readReadme() helper
in test/import-openneuro.test.ts used a dynamic require() call instead
of the ES module import already present at the top of the file. Add
readFileSync to the existing destructure and use it directly. No
behavior change; consistent with .rules/javascript.md (ES modules only).

* chore: bump version to 0.8.21-dev2

* Drop two remaining require('node:fs') calls in import-openneuro tests (#538)

Same anti-pattern that commit f9c22b4 fixed in appendOpenNeuroProvenance's
readReadme(). seedMetadata's readMeta() helper and the config.json read in
the 'metadata.json appears, config.json survives' test both still used a
dynamic require() instead of the readFileSync that's already destructured
at the top of the file. Flagged by the pr-review-toolkit code-reviewer
during the v0.8.21 release review; pre-existing on dev so non-blocking,
but bundling here keeps the file consistent and satisfies the
.rules/javascript.md 'ES modules only' rule.

* chore: bump version to 0.8.21-dev3

---------

Co-authored-by: nemar-bot <[email protected]>

This branch was previously deployed

1 inactive deployment
npm — 260527d6 Deployed May 18, 2026 by neuromechanist via publish #973
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