test(gateway): KBN-101-02a RED — positive anchors, owned exit, classified readability

Second AMEND from the verifier. Five blockers, all inside the 16-path fence; no
new path taken and no GREEN implemented.

1. The run carried an out-of-band `process.exit unexpectedly called with "1"`,
   raised by main.ts:71 self-invoking on import and rejecting after the importing
   case had returned. Vitest attributes that to no case and warns it can produce
   false positives; it also falsified the document's "zero non-assertion
   failures". The import is now wrapped so `process.exit` is stubbed
   non-throwing and the case awaits a settle turn — the behavioral red is
   unchanged, the error is owned, and the run reports `Errors 0`.

2. Two inventory cases demanded the raw values 'standalone' and 'postgres',
   which the value-free classification unions cannot represent, so no compliant
   implementation could have turned them green. They assert 'non-local' and
   'non-pglite'.

3. SourceReadability gained `absent`. Without it an absent source has to be
   reported `readable` — the one value meaning "read, and clean" — collapsing
   the distinction the refusal path is built on. The invariant
   `present === false` iff `readability === 'absent'` is now asserted per state
   and across all seven rows at once.

4. Acceptance #6 had no positive anchor: an empty `bootstrap()` and an
   always-refusing `onModuleInit()` satisfied every case, so "safe" could have
   meant "does not work". Two cases now fail against that — bootstrap must reach
   NestFactory.create and listen under the frozen policy with zero independent
   read, and the sterile local lifecycle must actually run both migrations with
   no Postgres handle. Both in-process and substituted at their seams; no port
   is bound and nothing connects.

5. Every mkdtemp site in the six files now registers teardown at the point of
   creation, including the child route's root created inside the spawn
   arguments. The matrix leaves zero /tmp/kbn-02a-* residue, measured.

Focused matrix: 82 failing / 16 passing (98 cases, 6 files), Errors 0.
Typecheck, lint, Prettier, diff --check clean.
This commit is contained in:
shaggy committed 2026-08-12 21:39:20 -05:00
1 parent 1a77739410
commit bdcdff5e31
8 files changed
+388 -64

No files matched your search

+68 -25
View File
@@ -442,9 +442,25 @@ its stated reason is the same defect class as the span gap that created this ite
### RED phase result
Focused matrix, gateway package: **77 failing / 15 passing (92 cases, 6 files)**. Typecheck and
lint clean. Zero non-assertion failures — no module-resolution, mock-setup or masking errors, so
every red is a behavioral assertion that names its own guard.
Focused matrix, gateway package: **82 failing / 16 passing (98 cases, 6 files)**, terminal
`Errors 0`. Typecheck, lint and Prettier clean. Every failure is a behavioral assertion that names
its own guard — the matrix output was scanned specifically for `TypeError`, `ReferenceError`,
missing-export and module-resolution text, not merely counted.
**Correction to the previous report's error claim.** It said "zero non-assertion failures", and
that was wrong at the time it was written: the run also carried one out-of-band
`process.exit unexpectedly called with "1"`, raised by `main.ts:71` self-invoking on import and
rejecting after the importing case had already returned. Vitest attributes such an error to no
case and warns it can produce false positives. It is now captured inside the case that provokes
it — `process.exit` is stubbed non-throwing for the duration of the import and the case awaits a
settle turn — so the behavioral red is unchanged and the run reports `Errors 0`. The claim above
is a measurement, not an inference.
The matrix leaves **zero `/tmp/kbn-02a-*` residue**, measured by removing all matching roots
before the run and counting after it. Every `mkdtemp` site in the six files registers its root for
teardown at the point of creation, including the child-process route's root, which is created
inside the spawn arguments and was the one most easily missed. The earlier passes leaked one
directory per case.
Ten of the sixteen fenced paths are touched in RED. The six GREEN targets (`package.json`,
`env.ts`, `app.module.ts`, `config/config.module.ts`, `database/database.module.ts`, `main.ts`)
@@ -472,32 +488,59 @@ The bars are therefore proven through the actual entrypoint for the probe and ap
side effects, and through the real database lifecycle for the migration side effects. They are not
yet proven through a full boot, and this document does not claim they are.
The fifteen passing cases are itemized rather than counted as coverage, because a green that
**Positive anchors — added because a refusal-only matrix is satisfiable by dead code.** Every
other case in this item asserts an absence: no read, no probe, no migration, no application. A
`bootstrap()` with an empty body and an `onModuleInit()` that always refuses would satisfy all of
them, and "safe" would come to mean "does not work". Two cases fail against exactly that:
`main.spec.ts` requires the exported `bootstrap()` to reach `NestFactory.create` and `listen`
under an established frozen policy with zero independent read or probe (in-process, substituted at
the Nest seam — no port is bound), and `database.module.spec.ts` requires the sterile local
lifecycle to actually run both PGlite and adapter migrations with no Postgres handle constructed.
The second is green today and must stay green; it replaced a case that awaited
`onModuleInit().catch(() => undefined)` and asserted only an absence, which a total failure
satisfied.
The sixteen passing cases are itemized rather than counted as coverage, because a green that
cannot fail for its stated reason is the same defect class as the span gap that created this item:
| Passing case | Why it is green |
| ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------- |
| env: config read on import, no policy | legacy regression guard — expected green |
| env: planted dotenv loads, no policy | legacy regression guard — expected green |
| main: anchored config reaches `detectAndAssertTier` | current-contract regression guard; its import-time-exit premise is superseded and must migrate at GREEN |
| local-dev: production `dev` script untouched | regression guard — expected green |
| local-dev: no static import of `main.js` | structural, three forms (binding, side-effect, `require`); must stay green |
| local-dev: importing starts nothing | structural; green today only because nothing invokes `runLocalDev` |
| policy: refuses to serve when unestablished | scaffolding implements this correctly already |
| policy: no fallback read when unestablished | scaffolding implements this correctly already |
| inventory: retains no raw DSN text | **vacuous today** — the stub returns an empty inventory |
| inventory: retains no planted canary | **vacuous today** — same empty inventory |
| inventory: writes no planted canary to the console | **vacuous today** — the stub reads no source, so it can log none |
| policy: children beneath the state root | **vacuous today** — the stub concatenates the declared root |
| policy: unaffected by post-establish input mutation | **vacuous today** — the stub captured strings, it did not clone |
| policy: frozen policy survives a source file gaining a DSN | **vacuous today** — the stub re-serves the same object it built |
| policy: frozen policy survives the environment gaining a DSN | **vacuous today** — same |
| Passing case | Why it is green |
| ------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------- |
| env: config read on import, no policy | legacy regression guard — expected green |
| env: planted dotenv loads, no policy | legacy regression guard — expected green |
| main: anchored config reaches `detectAndAssertTier` | current-contract regression guard; its import-time-exit premise is superseded and must migrate at GREEN |
| local-dev: production `dev` script untouched | regression guard — expected green |
| local-dev: no static import of `main.js` | structural, three forms (binding, side-effect, `require`); must stay green |
| local-dev: importing starts nothing | structural; green today only because nothing invokes `runLocalDev` |
| policy: refuses to serve when unestablished | scaffolding implements this correctly already |
| policy: no fallback read when unestablished | scaffolding implements this correctly already |
| inventory: retains no raw DSN text | **vacuous today** — the stub returns an empty inventory |
| inventory: retains no planted canary | **vacuous today** — same empty inventory |
| inventory: writes no planted canary to the console | **vacuous today** — the stub reads no source, so it can log none |
| policy: children beneath the state root | **vacuous today** — the stub concatenates the declared root |
| policy: unaffected by post-establish input mutation | **vacuous today** — the stub captured strings, it did not clone |
| policy: frozen policy survives a source file gaining a DSN | **vacuous today** — the stub re-serves the same object it built |
| policy: frozen policy survives the environment gaining a DSN | **vacuous today** — same |
| database: sterile local lifecycle migrates, no Postgres seam | positive anchor — green today, must stay green; the one case that fails if GREEN makes "safe" mean "inert" |
Seven greens are vacuous until the implementation exists, up from three, because this pass added
retention and post-freeze-mutation cases that a stub satisfies trivially. They are evidence of
nothing today and are re-checked at GREEN. The count rising is the honest outcome of asserting
Seven greens are vacuous until the implementation exists, up from three, because an earlier pass
added retention and post-freeze-mutation cases that a stub satisfies trivially. They are evidence
of nothing today and are re-checked at GREEN. The count rising is the honest outcome of asserting
more about a module that does not exist yet — it is recorded here so it cannot later be read as
coverage.
coverage. Of the nine non-vacuous greens, seven are guards that must stay green (two legacy
continuity, the untouched `dev` script, the structural no-static-import, the two unestablished-
policy refusals, and the database positive anchor) and two are green for a weaker reason than they
read: `local-dev` "starts nothing on import" is green only because nothing yet invokes
`runLocalDev`, and the `main.ts` anchoring case guards a current contract whose import-time-exit
premise `-02a` inverts, so it must be migrated at GREEN rather than deleted.
**Classification is a type obligation, not only a wording one.** Two inventory cases demanded the
raw source values `'standalone'` and `'postgres'`, which the value-free classification unions
cannot represent — a compliant implementation could never have turned them green. They now assert
`'non-local'` and `'non-pglite'`. In the same vein `SourceReadability` gained `absent`: without
it an absent source has to be reported `readable`, which is the one value meaning "read, and
clean", collapsing the exact distinction the refusal path is built on. The invariant
`present === false` if and only if `readability === 'absent'` is asserted directly, per state and
across all seven rows at once.
### Scope discipline