mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-25 17:14:57 +02:00
P2 — Non-finite ttlSeconds/maxStaleMin bypassed validation.
`typeof NaN === 'number'` and `NaN > 0 === false` meant a NaN duration
passed the old typeof+<=0 checks and would have poisoned TTLs once
validateDescriptor is wired into runSeed. Now gated by Number.isFinite,
which rejects NaN and ±Infinity. Tests added for NaN/Infinity on both
fields.
P2 — Empty/whitespace-only strings for domain/resource/canonicalKey/sourceVersion
bypassed validation. Added .trim() === '' rejection + tests per field.
This mattered because canonicalKey='' would have landed writes at the
empty key and seed-meta under a blank resource namespace.
P3 — SeedContractError silently dropped the Error v2 cause option.
Constructor now forwards { cause } through super() so err.cause works
with standard tooling (Node's default stack printer, Sentry chained-cause
serialization). resolveRecordCount's manual err.cause = err assignment
was replaced with the options-bag form. Test added for both constructor
direct-use and the resolveRecordCount wrap path.
P3 — Parity verifier was not on an automated path. Added
tests/seed-envelope-parity.test.mjs which spawns scripts/verify-seed-envelope-parity.mjs
via execFile; non-zero exit (drift) → test fails. Now runs as part of
`npm run test:data` (tsx --test tests/*.test.mjs). Drift injection
confirmed: sed -i modifying api/_seed-envelope.js makes the test fail
with 'Command failed' from execFile.
51 tests total (was 39). All green on clean tree.
36 lines
1.6 KiB
JavaScript
36 lines
1.6 KiB
JavaScript
// Drift check for the seed-envelope helpers.
|
|
//
|
|
// `scripts/verify-seed-envelope-parity.mjs` diffs function bodies between:
|
|
// - scripts/_seed-envelope-source.mjs (source of truth)
|
|
// - api/_seed-envelope.js (edge-safe mirror)
|
|
//
|
|
// This test runs the verifier as a child process during `npm run test:data`
|
|
// so drift between the two JS copies fails CI. Without this, someone could
|
|
// hand-edit api/_seed-envelope.js and the parity guarantee — which is the
|
|
// central invariant PR #3095 introduced — would silently erode.
|
|
//
|
|
// The TS mirror at server/_shared/seed-envelope.ts is validated by
|
|
// `npm run typecheck` and reviewed manually (see header comment in that file).
|
|
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { execFile } from 'node:child_process';
|
|
import { promisify } from 'node:util';
|
|
import { dirname, resolve } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const execFileP = promisify(execFile);
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
const verifier = resolve(here, '..', 'scripts', 'verify-seed-envelope-parity.mjs');
|
|
|
|
test('seed-envelope parity: source ↔ edge mirror stay in sync', async () => {
|
|
const { stdout, stderr } = await execFileP(process.execPath, [verifier], {
|
|
timeout: 10_000,
|
|
});
|
|
// Verifier prints a one-line OK on success. Any drift would exit non-zero,
|
|
// which execFile surfaces as a thrown error rejecting the promise, so
|
|
// reaching this line means the verifier succeeded.
|
|
assert.match(stdout, /parity: OK/);
|
|
assert.equal(stderr.trim(), '');
|
|
});
|