Skip to content

Phase 5a: share the standard edits - #1925

Merged
neuromechanist merged 15 commits into
feature/issue-1046-epic-upstream-freshnessfrom
feature/issue-1911-phase5a-shared-edits
Oct 24, 2026
Merged

neuromechanist merged 15 commits into
feature/issue-1046-epic-upstream-freshnessfrom
feature/issue-1911-phase5a-shared-edits

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Phase 5a of epic #1046 (ADR 0111): move the NEMAR standard edits to shared/ so the future re-pull planner (Phase 5b) and the Worker use the very functions the importer and the publisher use. No behavior change.

New shared/standard-edits/{description,readme,bidsignore}.ts hold applyConceptDoiToDescription, the README badge pair and decision rule (decideReadme, readmeProvenanceStub, selectPublishReadmes) and the .bidsignore rule; doi.ts and ensureReadmeMd re-export or wrap them so every old path still works unedited. The orchestrator's update_readme now calls selectPublishReadmes instead of keeping a second copy (a source check guards that wiring because nothing drives update_readme end to end). importHeaderPatch moves into shared/identifier-scrub.ts with patchHeader as a thin wrapper, the scrub path regexes are exported as RECORDING_PATH, JSON_PATH and SCANS_TABLE_PATH, and git-lib.ts exports presentIn and a new readLocationLogsAt (resolves a ref to one commit, refuses a missing ref, escapes key file names the way git-annex does, checked against real git-annex 10.20261006 with a URL key).

Filed while building: #1918 (three copies of the .bidsignore rule) and #1919 (locationLogs misses escaped keys, so a dead URL key could be copied; predates this branch). Known and unchanged: applyConceptDoiToDescription throws on SourceDatasets: [null], a lowercase bare readme rename is followed by git add README, and an upstream Readme.md is kept on import but not found on publish. Phase 5b will account for each.

Test plan

  • Root bun test: 18695 pass, 231 skip, 2 fail across 736 files; neither failure comes from this branch (website parity against a stale sibling checkout; admin-pr-reviews-cli crashed under load and passes alone, 168 pass)
  • bun run test:scrub: 871 pass, 0 fail
  • Typecheck, lint and lint:scrub clean; the old-path suites pass unedited
  • Worker bundle dry run (wrangler deploy --dry-run, dev env) succeeds at 5399.67 KiB; nothing in shared/standard-edits or identifier-scrub.ts imports node:
  • 29 one-line mutations, each caught by a test (two unreachable branches are documented in the test file)

First half of #1911; Phase 5b (the plan command) completes it.

Part of epic #1046

applyConceptDoiToDescription moves unchanged to shared/standard-edits/description.ts so the re-pull planner (ADR 0111, #1911) can recognize the edit publish makes. services/doi.ts re-exports it; the orchestrator and the #1386 repair keep their imports.

Tested: concept-doi-description, repair-doi-metadata and doi-provider suites pass unedited; a new suite proves the two paths are one function and pins the non-array SourceDatasets cases; three one-line mutations of the shared body fail the old-path suite.
shared/standard-edits/readme.ts now holds buildDoiBadge and planReadmeBadgeCommit (moved unchanged; services/doi.ts re-exports them), decideReadme and readmeProvenanceStub (ensureReadmeMd's #642 rule, which ensureReadmeMd now applies), and selectPublishReadmes (the update_readme step's content-source and deletion rule), for the re-pull planner (ADR 0111, #1911).

Tested: readme-badge-plan, import-openneuro and repair-doi-metadata pass unedited; a new suite proves the badge pair is the same functions, pins the stub's bytes, and checks ensureReadmeMd against decideReadme on nine real directory layouts; seven one-line mutations each fail a suite.
The orchestrator's update_readme step takes its content source and the files it deletes from selectPublishReadmes instead of an inline copy of the same loop, so the re-pull planner models the rule publish actually follows. Same order, same entries, same deletions.

Tested: a source check pins the call and the absence of a README list in the orchestrator (no test drives the step itself, it reads GitHub); mutating the delete loop to readmes.found fails it; the orchestrator source-scan suites still pass.
withBidsignoreEntry in shared/standard-edits/bidsignore.ts is the .nemar/ line rule the backend's enrichment commit and the upload's metadata step each carry a copy of, for the re-pull planner (ADR 0111, #1911). Both callers are left unchanged.

Tested: a parity suite runs the real writeNemarMetadata for eleven starting files (absent, empty, CRLF, trailing blanks, already present, non-ASCII) and compares bytes; mutating the shared rule or the upload's copy fails it.
importHeaderPatch(before, dates) in shared/identifier-scrub.ts is the importer's scrub-then-dates patch with both proofs, returning ok/not-edf/scrub-unverified instead of throwing, for the re-pull planner (ADR 0111, #1911). patchHeader in import-scrub.ts is now a thin wrapper: not-edf is null and scrub-unverified throws the same ImportScrubRefused as before.

Tested: import-scrub, import-normalize, identifier-scrub and identifier-dates pass unedited; a new unit suite pins the result shapes; a new end-to-end case (no existing one reads a non-EDF header) drives prepareImportedTreeForCopy over two non-EDF recordings. Mutations of the shared body and of the wrapper each fail a suite.
RECORDING, JSON_FILE and SCANS_TABLE in import-scrub.ts become exported RECORDING_PATH, JSON_PATH and SCANS_TABLE_PATH, unchanged, so the re-pull planner (ADR 0111, #1911) forecasts the scrub over the same paths it runs on.

Tested: import-scrub passes unedited (50/50); a new unit suite pins what each matches and that none is stateful; three one-line mutations of the patterns fail it, and dropping .bdf also fails the not-EDF end-to-end case.
git-lib.ts exports presentIn and adds readLocationLogsAt(repo, ref, keys): the location logs at one resolved commit of a git-annex branch, read with rev-parse and cat-file only, so the re-pull planner (ADR 0111, #1911) can read dead marks and nemar-s3 presence from a bare clone. It applies git-annex's keyFile escaping (& % : /), refuses a ref that does not resolve instead of answering no log, and refuses a ref or key that would break the batch read.

Tested against real git-annex (add, copy to a directory remote, drop, dead, registerurl, bare clone): logs match git-annex's own, presence matches whereis, a URL key is found under its escaped name. Six one-line mutations each fail it; annex-registry still passes.
The suite's git-annex probe goes through toolOrFail, so NEMAR_REQUIRE_SCRUB_TOOLS=1 fails it instead of skipping, and the header says it drives the git-held header read, not the upstream ranged read (review round 1, #1925).

Tested: passes with git-annex; skips without it; fails with the requirement set and no git-annex on PATH.
Review round 1 (#1925) found a header the scrub rewrites but cannot prove: a recording field leading with Startdate 99-ZZZ-9999. import-header-patch pins importHeaderPatch's scrub-unverified result for it with dates on and off and corrects the comment that called the branch unreachable (datesUnproven stays documented as unreached: 400,000 fuzzed patches found none). The not-EDF end-to-end file becomes import-scrub-header-outcomes and adds the same header through prepareImportedTreeForCopy: it refuses with scrub-unverified in patchHeader, before any write or commit.

Tested: both files pass; flipping patchHeader's not-edf test fails both end-to-end cases, and dropping importHeaderPatch's verifyScrub guard fails the unit and end-to-end cases.
The orchestrator's update_metadata comment and repair-doi-metadata's header named services/doi.ts as where the rules live; they now name shared/standard-edits/, which doi.ts re-exports, so nobody adds a copy back in doi.ts. The readme.ts header also says doi.ts re-exports applyConceptDoiToDescription (review round 1, #1925). Comments only.

Tested: the orchestrator source-scan suites, standard-edits-readme and repair-doi-metadata pass.
The orchestrator wiring check now parses publication-orchestrator.ts with the TypeScript compiler and compares comment-free code: the selectPublishReadmes import, readmes = selectPublishReadmes(tree) over main's tree, getBlobContent of contentSource.sha, contentSourcePath: contentSource?.path, and one deleteRepoFile inside the loop over readmes.remove. Any string literal in the file that spells a README name in any case, other than the README.md it writes, fails (review round 1, #1925).

Tested: re-inlining a list (readme.md, Readme.md, README.rst), filtering the tree by an inline list, hard-coding contentSourcePath, deleting readmes.found and reading tree[0] each fail it; the expected text written only in a comment does not satisfy it.
readLocationLogsAt no longer reads "no log" for a reason other than the branch having none (review round 1, #1925). A ref whose tree has no uuid.log (HEAD, main, any non-git-annex branch) refuses with annex-ref-not-git-annex, and a log the tree names that this clone lacks (a partial or blobless clone), or a log path that is a directory, refuses with annex-log-unreadable. Paths are looked up with ls-tree and read by object id; a key named twice gets the same answer twice. A valid git-annex ref reads exactly as before.

Tested against real git-annex plus branches built with git mktree --missing: HEAD, main and a branch without uuid.log refuse, the missing object and the directory refuse, absent logs stay empty, duplicates agree. Removing each guard, or returning one answer per unique path, fails a test; annex-registry and fresh-clone still pass.
The bidsignore parity suite now also runs the backend's own rule: the loop over bidsignoreEntriesToIgnore in commitEnrichmentWithBidsignore is taken from the parsed contents.ts without comments, compiled and run over the same eleven starting files, with one entry and with the admin route's two, and compared with withBidsignoreEntry byte for byte. It also reads the .nemar/ entry the enrichment pipeline and the admin route's v2 branch pass. The backend copy is unchanged; #1918 owns folding it in (review round 1, #1925).

Tested: dropping trimEnd, matching by endsWith, never setting the updated flag in contents.ts, and changing either caller's entry each fail it.
The ensureReadmeMd parity block is retitled to say it proves the file I/O (decideReadme's own tests pin the rules), the lowercase bare readme case says from: "README" is the preserved legacy outcome, and ReadmeOutcome's doc says so too, with its consequence: on a case-sensitive filesystem the caller's git add README names an untracked path and the import fails at staging (checked: fatal, exit 128). No code changes (review round 1, #1925).

Tested: standard-edits-readme and import-openneuro pass.
@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR1925

Version: 0.10.24-PR1925.26db727
Commit: 26db727


🤖 Updated on each push.

Tested: location-logs-at suite passes.
@neuromechanist
neuromechanist merged commit 8a54cfc into feature/issue-1046-epic-upstream-freshness Oct 24, 2026
18 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-1911-phase5a-shared-edits branch October 24, 2026 10:05

This branch was previously deployed

1 inactive deployment
npm — 26db7278 Deployed Oct 24, 2026 by neuromechanist via publish #3861
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