KB-5438

08 — No-Hardcode Tests (Labels / Layers / Pins) + Every-Count-Pivot-Backed

4 min read Revision 1
architectureno-hardcodetestspivot-backedpivot-missingdieu-28hardcode-violation2026-05-31

title: 08 — No-Hardcode Tests + Every-Count-Pivot-Backed date: 2026-05-31

08 — No-Hardcode Tests

Enforces: no frontend hardcode or disguised hardcode; every count pivot-backed or PIVOT_MISSING; labels/layers/pins are PG data. Reuses the live hardcode_violation / hc_finding_sql|builtin|function issue types (Đ28) — the enforcement channel already exists.

Principle

The surface is a reflection of PG. Nuxt holds no numbers, thresholds, label arrays, layer depths, or pin state. Anything that looks like a value baked into web/ is a violation.

Test catalogue (design — to run as governed checks, not this session)

id asserts fail ⇒
T-COUNT-1 every displayed count = a pivot_count/pivot_query result, or is explicitly rendered PIVOT_MISSING hardcode_violation
T-COUNT-2 no client-side arithmetic on counts (no reduce(Σ), no Math.abs(gap) injection) — the health.get.ts totalGap/orphan_count=21,823 pattern is the canonical anti-example hardcode_violation (Đ28)
T-COUNT-3 the accounting invariant is computed over the leaf set, never a blind SUM over all meta_catalog rows (doc 02) count_integrity_failed (false-clean risk)
T-LABEL-1 every label_ref resolves to a live taxonomy/label_rules row hardcode_violation
T-LABEL-2 max_ungrouped_threshold read from PG per species; literal 50 in web/ is itself a violation hardcode_violation
T-LABEL-3 no literal label/category arrays in web/ (grep CAT-PHA, CAT-ORP, CAT-UNM, CAT-SPE, phantom/unmapped string lists) hardcode_violation
T-DRILL-1 every node with children_count > 1 resolves a next_pivot_code or a final_substrate_ref (no dead-end mid-tree) structural
T-DRILL-2 no Nuxt depth/level branching (level === N, fixed layer arrays) — depth is data hardcode_violation
T-PIN-1 pin_state derives from registry_pin (PG); no localStorage/in-memory pin arrays hardcode_violation
T-SELF-1 every NEW registry (registry_pin, label dims) is itself in meta_catalog + has a pivot, else it is an orphan by Đ23/Đ26 thiếu_mã_định_danh

Every-count-pivot-backed — the PIVOT_MISSING ledger (verified)

Counts the surface needs that have no live pivot today → must be added as pivot_definitions rows (INSERT), never computed in Nuxt:

  • PIV-500 grand-total total_system_objects (cross-check anchor; today only PIV-019 birth=980,221 exists).
  • PIV-30x orphan-total + orphan-by-dimension (orphan_count lives per-row in meta_catalog but has no rollup pivot).
  • PIV-30x phantom-total (record_count − actual_count where >0; needs phantom_count column first — doc 02).
  • PIV-30x count-integrity / drift total (drift_rows, net_gap).
  • PIV-31x label-by-facet (labels are not yet a pivot dimension; entity_labels=718,744 uncounted by pivot).
  • PIV-32x registry_pin count (after the NEW table is born).
  • IU 219 / KG totals (noted PIVOT_MISSING in prior sessions; still absent).

Until each exists, the surface renders that cell as PIVOT_MISSING with next_action = propose_pivot — it does not invent the number.

Anti-pattern of record (Đ28 violation to be retired)

web/server/api/registry/health.get.ts: totalGap = collections.reduce((s,c)=>s+Math.abs(c.gap),0)orphan_count = 21,823 injected into index.vue; CAT-PHA=7 / CAT-UNM=122 computed in the API. This is disguised hardcode (frontend math masquerading as a count) and is the exact thing T-COUNT-2/T-LABEL-3 catch. The convergence target replaces these with pivot reads + PIVOT_MISSING.

Back to Knowledge Hub knowledge/dev/reports/architecture/registries-pivot-os-agency-count-integrity-orphan-phantom-label-pin-rehearsal-2026-05-31/08-no-hardcode-tests-and-pivot-backed.md