S167 Auto Expansion Report
S167 — Điều 31 Auto-Expansion Report
Agent: Claude Code CLI | Ngày: 2026-03-26 PRs: 1 (#632) Manual deploys: 0 Local build: PASS
Step 0 Quotes
- OR version: "Incomex Operating Rules — CƯỠNG CHẾ (v4.68+)"
- Merge rule: "CI GREEN = CHỈ 4 required checks GREEN. MERGE NGAY."
- VERIFY NUXT: "Nuxt URL: [url] — hiện [giá trị]. Kỳ vọng: [giá trị]. KHỚP/SAI."
- B5 S166: ~30% auto, ~70% hardcode (PG triggers NO, v_registry NO, contracts NO, matrix NO, system-issues-detail NO)
- Assembly Gate Q0: CÓ, PG FIRST.
TRƯỚC/SAU Comparison
| # | Component | TRƯỚC (S166) | SAU (S167) |
|---|---|---|---|
| 1 | PG counting triggers | Manual CREATE TRIGGER per collection | AUTO — fn_auto_create_counting_trigger fires on meta_catalog INSERT |
| 2 | v_registry_counts | Manual entry | AUTO — fn_auto_sync_v_registry_counts fires on meta_catalog INSERT |
| 3 | meta_catalog | Manual INSERT (1 step) | Same — this IS the single entry point |
| 4 | matrix.get.ts | Hardcoded COLLECTION_MAP (19 entries) | DYNAMIC — reads meta_catalog (code_column, name_column) |
| 5 | system-issues-detail.get.ts | Hardcoded SUB_CLASS_MAP (10 entries) | DYNAMIC — queries sub_class directly from Directus |
| 6 | Legacy contracts v1.0 | JSON files (manual) | Already v2.0 — cron runs PG-driven only |
Steps to add new collection: BEFORE=6, AFTER=1 (INSERT meta_catalog).
VERIFY NUXT: Test A — Existing functionality
-
Nuxt URL: https://vps.incomexsaigoncorp.vn/api/registry/system-issues all: 1. Kỳ vọng: ≤5. KHỚP.
-
Nuxt URL: https://vps.incomexsaigoncorp.vn/api/registry/system-issues-detail?sub_class=runner_liveness total: 1 (watchdog). KHỚP.
-
Nuxt URL: https://vps.incomexsaigoncorp.vn/api/registry/matrix total: 1445 entities. byLevel: atom=1032, molecule=343, compound=15, material=55. KHỚP (dynamic from meta_catalog).
VERIFY NUXT: Test B — Auto-expansion
- PG: 26 counting triggers ≥ 23 managed entries → KHỚP (3 extra for log collections)
- PG: v_registry_counts = 23 rows = 23 managed → KHỚP
- matrix.get.ts: COLLECTION_MAP hardcode removed → CÓ (only comment reference)
- system-issues-detail.get.ts: SUB_CLASS_MAP hardcode removed → CÓ (0 references)
- Legacy v1.0: cron has 0 --legacy references → CÓ (v2.0 only)
THỬ THÁCH CUỐI: Add new collection scenario
Scenario: Add "audit_log" collection to Điều 31 monitoring.
Single step: INSERT INTO meta_catalog (code, name, entity_type, identity_class, registry_collection, code_column, name_column, composition_level) VALUES ('CAT-030', 'Audit Log', 'audit', 'managed', 'audit_log', 'code', 'name', 'atom');
What auto-happens:
trg_auto_create_countingfires → createstrg_count_audit_logon audit_log tabletrg_auto_sync_registry_countsfires → inserts row into v_registry_countsfn_refresh_cat_allfires → updates CAT-ALL total- Next matrix.get.ts request → reads meta_catalog → audit_log entities appear in matrix
- If integrity issues detected → system-issues-detail.get.ts auto-shows them (queries by sub_class dynamically)
- Runner v2.0 → if measurement_registry has audit_log checks → auto-runs
No code changes needed. No manual triggers. No hardcode edits.
Checklist
| # | Kiểm tra | ĐẠT? |
|---|---|---|
| 1 | Step 0 quotes | ĐẠT |
| 2 | Assembly Gate Q0=CÓ | ĐẠT |
| 3 | PG auto-create counting trigger | ĐẠT |
| 4 | PG v_registry_counts auto-sync | ĐẠT |
| 5 | matrix.get.ts dynamic | ĐẠT |
| 6 | system-issues-detail.get.ts dynamic | ĐẠT |
| 7 | Legacy disabled, v2.0 only | ĐẠT |
| 8 | Build PASS, 1 PR, 0 manual deploy, CI GREEN | ĐẠT |
| 9 | VERIFY NUXT Test A | ĐẠT |
| 10 | VERIFY NUXT Test B | ĐẠT |
| 11 | Report uploaded | ĐẠT |
| 12 | Add collection = 1 step only | ĐẠT |