Skip to content

Drive the mirror chip from the API's mirror flag - #489

Merged
neuromechanist merged 5 commits into
stagingfrom
feature/phase8c-mirror-flag
Oct 27, 2026
Merged

neuromechanist merged 5 commits into
stagingfrom
feature/phase8c-mirror-flag

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Drives the mirror chip in the version switcher and the "View as-imported mirror" action in the source toggle from the mirror flag the API puts on each landing version (true, false or null), instead of guessing from vN.0.0. This is PR 8c of nemarOrg/nemar-cli#1914 (epic nemarOrg/nemar-cli#1046), following nemar-cli Architecture Decision Record (ADR) 0111, decision 5. It refs #478 rather than closing it, because staging is not the default branch.

What changes

  • LandingVersion gains mirror?: boolean | null, with a comment naming the three values and that an older backend omits the key.
  • listMirrorVersions lists only mirror === true, newest first, as soon as any version carries the key. A null N.0.0 (snapshot unknown or not examined yet) gets no chip and is never the toggle's mirror version.
  • When no version carries the key, the old vN.0.0 rule stays as a documented temporary fallback. PR 8c2 deletes it later; this PR keeps it.
  • VersionSwitcher.astro and ProvenanceToggle.astro are unchanged. I read both: the page passes the switcher provenance.allMirrorVersions and the toggle reads provenance.mirrorVersion, and both come from detectProvenance, so the one change in provenance.ts reaches them. Nothing else under src derives a mirror from a version number.
  • A [Unreleased] entry in CHANGELOG.md (the file's convention for feature PRs), the one sentence in .context/research.md that stated the old rule, and the release gate in .context/handoff.md, where this repo records them.

Behavior by backend

  • A backend that omits the key: nothing changes. Production is in this state today (checked 2026-10-27 UTC): https://data.nemar.org/on005506/ carries no mirror on its version, and https://api.nemar.org/health reports 0.10.25.
  • A backend that sends the key: the chip and the toggle follow it.

Ordering note for the release sequence

The fallback only covers a payload with no key at all. Once production sends the key, an on N.0.0 whose snapshot is not recorded yet is null and shows no chip, with or without the fallback, until nemar admin upstream-backfill --execute has run. In a read-only sample of 27 production on datasets (spread over the catalog by name, 2026-10-27 UTC), 26 are a lone v1.0.0, one has v1.0.2 and v1.0.0, and none carries the key yet, so a lone null N.0.0 is the common case. The plan promotes the website after the backfill, which avoids a chip-less window; an unrelated website release between the nemar-cli release and the backfill would not.

Differences from the plan

  • The plan says 'mirror' in v to detect the key. I used v.mirror !== undefined, which is the same on parsed JSON (it has no undefined) and also treats an explicit undefined as absent. The one mutant that swaps them survives the tests for that reason.
  • The plan asks for one recorded fixture. I recorded three from the same route, because the all-null payload is the common pre-backfill shape, and a payload with a false in it hides an implementation that treats null as an absent key.

Tests

  • Three landing payloads are recorded from nemar-cli's real data-plane route over a real SQLite database built from its migrations, seeded the way backend/test/landing-mirror-flag.test.ts seeds it (commit 1abf9286 of the epic branch): landing-mirror-flag-on000001.json (v4.0.0 true, v3.0.0 null, v2.0.0 null, v1.0.1 false, v1.0.0 true), landing-mirror-flag-on000001-unexamined.json (nothing but null) and landing-mirror-flag-nm000200.json (nothing but false). They are not captures of production, which does not send the key. One seed differs from that test: the DOI of its stored-v4.0.0 row reads ...v4.0.0 here, where the test builds ...vv4.0.0. The existing jsonld-landing-on007753.json, a real production capture from before the flag, covers the fallback.
  • Cases: true, false, null and absent per version; a null N.0.0 has no chip and is not the toggle's mirror version, including when it is the newest; the mixed list (v2.0.0 true, v2.0.1 false, v1.0.0 null); pickMirrorVersion with one version, whatever its flag; an nm dataset (all false); one key anywhere turns the number rule off, wherever the bare entry sits; the flag path still sorts by version number. The cases assert on what detectProvenance hands the switcher and the toggle.
  • Eleven wrong implementations of listMirrorVersions fail these tests: a per-version ?? fallback, a fallback whenever nothing is true, no fallback, the number only, null treated as a mirror, false listed as well, no sort on the flag path, every for some, only the first entry checked for the key, null treated as an absent key, and only booleans counted as the key. Each was applied one at a time, confirmed applied, and reverted.

Gates

Each of the first two commits passes all four gates with exit code 0: bun run lint; bun run typecheck (0 errors, 0 warnings, the same 14 hints as before); bun run test (161 files, 4381 tests, 18 more than before); bun run build. The test gate was run the way ci.yml runs it, with the six nemar-cli dev contract files in the environment variables, because the local sibling nemar-cli checkout is stale (it pins validator 2.4.1, dev pins 3.0.2) and fails validator-pin-drift on any branch. The three review-fix commits after them change only comments and .context/handoff.md; on the final head lint and typecheck exit 0, and the test gate, run the same way, exits 0 with all 4381 tests.

The GitHub Actions run on the pull request head (5091a7f) also passed all four jobs (lint, typecheck, test, build) and the Cloudflare Pages preview built, so no check is red for lack of Actions minutes.

Checking it

  • test.nemar.org runs against the nemar-cli dev backend, whose catalog holds only xx fixtures, so no true or null chip can be looked at there. The recorded-payload tests prove them. After the release and the backfill, curl -s -H 'Accept: application/json' https://data.nemar.org/<on id>/ | jq '[.versions[].mirror]' shows the real values.
  • Merging to staging deploys to test.nemar.org only and auto-bumps -devN. Check that runs started (website#374).
  • After merging, close Drive the mirror chip from the API's mirror flag #478 by hand with a comment that the fallback removal is 8c2.

LandingVersion gains mirror?: boolean | null. Once any version
carries the key, listMirrorVersions lists only the versions flagged
true, so a null N.0.0 (snapshot unknown) gets no chip and is not the
toggle's mirror version. A payload with no key at all keeps the old
vN.0.0 rule as a temporary fallback.

VersionSwitcher and ProvenanceToggle already read allMirrorVersions
through detectProvenance, so neither changes.

Refs #478. Lint, typecheck, test and build pass; the existing tests
pass unchanged and the new cases follow in the next commit.
Cases for true, false, null and an absent key on each version,
driven by landing payloads recorded from nemar-cli's real route: a
mirror with every value, a mirror with nothing but null, and a
NEMAR dataset with nothing but false. A real production capture
from before the flag covers the fallback.

A null N.0.0 gets no chip and is not the toggle's mirror version,
and one key anywhere in a payload turns the version-number rule off.
Eleven wrong implementations of listMirrorVersions fail these tests;
the one that survives (an in check for !== undefined) is equivalent
on parsed JSON.

Refs #478. Lint, typecheck, test and build pass.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Deploying nemar-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5091a7f
Status: ✅  Deploy successful!
Preview URL: https://5462a481.nemar-website.pages.dev
Branch Preview URL: https://feature-phase8c-mirror-flag.nemar-website.pages.dev

View logs

Adds the hold to .context/handoff.md, where this repo records
release gates: no staging to main promotion until the production
upstream-backfill has run, because once the API sends the flag a
mirror whose snapshot is not recorded reads null and has no chip.

Docs only.
The fallback comment named "PR 8c2", a plan label the issue does not
define. It now points at website#478, whose checklist states when
the fallback is deleted.

Comment only.
The comment said four recorded payloads drive the cases below, but
several cases build their payloads by hand with flaggedLanding and
versionEntry. It now says the four recordings drive the main flag
cases and names the shapes the hand-built ones cover.

Comment only.
@neuromechanist
neuromechanist merged commit 11773da into staging Oct 27, 2026
5 checks passed
@neuromechanist
neuromechanist deleted the feature/phase8c-mirror-flag branch October 27, 2026 07:26
neuromechanist added a commit that referenced this pull request Nov 2, 2026
The toggle copy predates the mirror flag (#489); a null N.0.0 is no longer
shown as a mirror. Say what the flag says instead. Lint and unit suite pass.
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