KB-2C20

110000x · 03 — Điều 30 Regression Suite

12 min read Revision 1
iu-core110000xdieu-30regressionalias-equivalencemanifest-digestno-regression

110000x · 03 — Điều 30 Regression Protection Suite

Law: knowledge/dev/laws/dieu30-regression-protection-law.md — "every change that touches a working surface must PROVE the old behavior still works."

Scope of touched surface: new fn_iu_op_* wrappers + 5 dot_iu_command_catalog rows. Untouched: all core pipeline functions, all live information_unit / iu_vector_sync_point / iu_core.iu_staging_* data, production_documents, Qdrant, Nuxt.

Browser/UI test: N/A. 110000x does not touch UI. Required surface is operator / API / SQL only.

Run all tests post-apply against directus DB as workflow_admin.

T0 — Pre-flight state capture

SELECT
  (SELECT count(*) FROM information_unit) AS iu_count_pre,
  (SELECT count(*) FROM information_unit WHERE doc_code='DIEU-28') AS d28,
  (SELECT count(*) FROM information_unit WHERE doc_code='DIEU-32') AS d32,
  (SELECT count(*) FROM information_unit WHERE doc_code='DIEU-35') AS d35,
  (SELECT count(*) FROM iu_vector_sync_point) AS vsp,
  (SELECT count(*) FROM iu_core.iu_staging_record) AS stg_rec,
  (SELECT count(*) FROM iu_core.iu_staging_payload) AS stg_pay,
  (SELECT count(*) FROM dot_iu_command_catalog) AS dot_cat,
  (SELECT count(*) FROM dot_iu_command_run) AS dot_run;

Expected (entry): iu=175, d28=27, d32=23, d35=36, vsp=152, stg_rec=3, stg_pay=4, dot_cat=41 (after apply), dot_run=21.

T1 — 100000x fixture still passes (alias path)

Re-run the 100000x FIXTURE-NVSZ-PROOF fixture through the alias surface in BEGIN/ROLLBACK and verify every assertion from 100000x report 04 still holds.

BEGIN;

-- Step 1: MARK via alias
WITH r AS (
  SELECT public.fn_iu_op_mark_file(
    p_source_text  := E'## fixture intro\n\nbody1\n\nbody2\n',
    p_source_ref   := 'FIXTURE-NVSZ-PROOF-110000x-T1',
    p_pieces       := '[
      {"local_piece_id":"p1","parent_local_id":null,"unit_kind":"design_doc_section","content_text":"## fixture intro","section_type":"heading","section_code":"k1","piece_role":"title","canonical_address":"FIXTURE-T1#k1","source_position":1,"sort_order":1},
      {"local_piece_id":"p2","parent_local_id":"p1","unit_kind":"design_doc_section","content_text":"body1","section_type":"paragraph","section_code":"k2","piece_role":"body","canonical_address":"FIXTURE-T1#k2","source_position":2,"sort_order":2},
      {"local_piece_id":"p3","parent_local_id":"p1","unit_kind":"design_doc_section","content_text":"body2","section_type":"paragraph","section_code":"k3","piece_role":"body","canonical_address":"FIXTURE-T1#k3","source_position":3,"sort_order":3}
    ]'::jsonb,
    p_actor        := 'd30-regression-t1',
    p_source_kind  := 'system'
  ) AS res
)
SELECT res->>'staging_record_id' AS sid,
       res->>'manifest_digest'   AS digest,
       res->>'lifecycle_status'  AS lifecycle
FROM r \gset

-- Assert lifecycle = pending_review
\if :{?lifecycle}
  \echo 'sid:' :sid
\endif

-- Step 2: VERIFY-MARK (dry-run)
SELECT public.fn_iu_op_verify_mark(:'sid'::uuid, false) -> 'verdict';

-- Step 3: APPROVE (verify-mark apply=true)
SELECT public.fn_iu_op_verify_mark(
  :'sid'::uuid, true,
  'knowledge/dev/laws/dieu44-trien-khai/v0.6-iu-core-110000x-operator-alias-surface-d30-d31-protection/',
  'd30-regression-approver',
  'd30-regression-t1'
) -> 'verdict';

-- Step 4: CUT (apply=true, open composer in-TX)
WITH cut AS (
  SELECT public.fn_iu_op_cut(:'sid'::uuid, true, 'd30-regression-t1', true) AS r
)
SELECT r->>'applied' AS applied,
       r->>'pieces_created_count' AS pieces,
       r->>'run_id' AS rid
FROM cut \gset

-- Step 5: VERIFY-CUT
SELECT public.fn_iu_op_verify_cut(:'rid'::uuid, 'd30-regression-t1') -> 'verdict';

-- Step 6: cleanup dry-run
SELECT public.fn_iu_op_cleanup_dry_run(15, 'd30-regression-t1');

ROLLBACK;

Pass criteria (matches 100000x report 04):

  • MARK → lifecycle pending_review, manifest_digest 32-hex
  • VERIFY-MARK dry-run → verdict approved
  • APPROVE → verdict approved, lifecycle approved
  • CUT → applied true, pieces_created_count = 3
  • VERIFY-CUT → verdict verified, all axes ok, no_vector_ok true, problems []
  • Cleanup dry-run → eligible_count >= 0 (3 existing rows may match age threshold)
  • Post-ROLLBACK: state identical to pre-T1 (iu=175, dot_run=21)

T2 — Alias MARK ≡ Direct MARK (manifest_digest equivalence)

Critical equivalence test: same input → same staging row (via idempotency_key).

BEGIN;
-- Direct call
WITH d AS (
  SELECT public.fn_iu_mark_create_manifest(
    p_manifest := jsonb_build_object(
      'manifest_version','v0.6',
      'source_id','EQUIV-T2',
      'source_hash', md5('hello world'),
      'source_bytes', octet_length('hello world'),
      'manifest_digest', md5(md5('hello world')||'|'||octet_length('hello world')::text||'|'||'[{"local_piece_id":"p1","unit_kind":"design_doc_section","content_text":"hello world","section_type":"paragraph","canonical_address":"EQUIV-T2#k1","piece_role":"body","source_position":1,"sort_order":1}]'),
      'pieces', '[{"local_piece_id":"p1","unit_kind":"design_doc_section","content_text":"hello world","section_type":"paragraph","canonical_address":"EQUIV-T2#k1","piece_role":"body","source_position":1,"sort_order":1}]'::jsonb
    ),
    p_mark_report_md := '# direct',
    p_coverage_proof := jsonb_build_object('covered_bytes', octet_length('hello world')),
    p_determinism_digest := md5(md5('hello world')||'|'||octet_length('hello world')::text||'|'||'[{"local_piece_id":"p1","unit_kind":"design_doc_section","content_text":"hello world","section_type":"paragraph","canonical_address":"EQUIV-T2#k1","piece_role":"body","source_position":1,"sort_order":1}]'),
    p_source_kind := 'system',
    p_source_ref := 'EQUIV-T2-direct',
    p_idempotency_key := 'equiv-t2-direct',
    p_actor := 'd30-t2'
  ) AS res
) SELECT res->>'staging_record_id' AS sid_direct, res->>'manifest_digest' AS dig_direct FROM d \gset

-- Alias call with equivalent inputs
WITH a AS (
  SELECT public.fn_iu_op_mark_file(
    p_source_text := 'hello world',
    p_source_ref  := 'EQUIV-T2-alias',
    p_pieces      := '[{"local_piece_id":"p1","unit_kind":"design_doc_section","content_text":"hello world","section_type":"paragraph","canonical_address":"EQUIV-T2#k1","piece_role":"body","source_position":1,"sort_order":1}]'::jsonb,
    p_actor       := 'd30-t2',
    p_source_kind := 'system'
  ) AS res
) SELECT res->>'staging_record_id' AS sid_alias, res->>'manifest_digest' AS dig_alias FROM a \gset

-- Pass criterion: same manifest_digest (deterministic formula), same payload-shape (3 parts)
SELECT
  :'dig_direct' AS dig_direct,
  :'dig_alias'  AS dig_alias,
  (:'dig_direct' = :'dig_alias') AS digest_equal,
  (SELECT count(*) FROM iu_core.iu_staging_payload WHERE staging_record_id = :'sid_direct'::uuid) AS parts_direct,
  (SELECT count(*) FROM iu_core.iu_staging_payload WHERE staging_record_id = :'sid_alias'::uuid)  AS parts_alias;

ROLLBACK;

Pass criteria:

  • dig_direct = dig_alias (manifest_digest computation matches)
  • parts_direct = parts_alias = 3 (cut_manifest, mark_report, coverage_proof — same staging shape)
  • source_hash recorded on both records equals md5('hello world')

T3 — Alias CUT ≡ Direct CUT (same output shape)

BEGIN;
-- Setup: MARK + APPROVE via alias to get an approved staging row
SELECT public.fn_iu_op_mark_file(
  p_source_text := 'line1', p_source_ref := 'EQUIV-T3', p_actor := 'd30-t3',
  p_pieces := '[{"local_piece_id":"p1","unit_kind":"design_doc_section","content_text":"line1","section_type":"paragraph","canonical_address":"EQUIV-T3#k1","piece_role":"body","source_position":1,"sort_order":1}]'::jsonb,
  p_source_kind := 'system'
) -> 'staging_record_id' \gset sid_

SELECT public.fn_iu_op_verify_mark(:'sid_?column?'::uuid, true,
  'knowledge/.../approval-d30-t3.md', 'd30-t3', 'd30-t3');

-- Open composer
UPDATE dot_config SET value='true' WHERE key='iu_core.composer_enabled';

-- Direct cut
SELECT public.fn_iu_cut_from_manifest(
  :'sid_?column?'::uuid, true, md5('line1'), 'd30-t3-direct'
) AS direct_result;

ROLLBACK;

-- Repeat with alias-cut for comparison
BEGIN;
SELECT public.fn_iu_op_mark_file(
  p_source_text := 'line1', p_source_ref := 'EQUIV-T3', p_actor := 'd30-t3',
  p_pieces := '[{"local_piece_id":"p1","unit_kind":"design_doc_section","content_text":"line1","section_type":"paragraph","canonical_address":"EQUIV-T3#k1","piece_role":"body","source_position":1,"sort_order":1}]'::jsonb,
  p_source_kind := 'system'
) -> 'staging_record_id' \gset sid_

SELECT public.fn_iu_op_verify_mark(:'sid_?column?'::uuid, true,
  'knowledge/.../approval-d30-t3.md', 'd30-t3', 'd30-t3');

-- Alias cut (auto-opens composer)
SELECT public.fn_iu_op_cut(:'sid_?column?'::uuid, true, 'd30-t3-alias', true) AS alias_result;

ROLLBACK;

Pass criteria: Both runs return JSON with applied=true, pieces_created_count=1, valid run_id, no refusal_code. Same inner_result shape modulo run_id/uuid generation.

T4 — No regression on baseline surfaces

After full T1+T2+T3 + ROLLBACK, re-run the T0 query. Every count must match exactly.

-- Re-run T0 query; expect identical numbers.

T5 — dot_iu_command_catalog count delta is exactly +5

SELECT count(*) FROM dot_iu_command_catalog;            -- expect 41
SELECT count(*) FROM dot_iu_command_catalog
WHERE command_name LIKE 'dot_iu_operator_%';            -- expect 5
SELECT count(*) FROM pg_proc p JOIN pg_namespace n ON n.oid=p.pronamespace
WHERE n.nspname='public' AND p.proname LIKE 'fn_iu_op_%';  -- expect 5

T6 — iu_vector_sync_point unchanged

SELECT count(*) FROM iu_vector_sync_point;   -- expect 152
-- Same value as 100000x baseline. Alias touches NO vector surface.

T7 — production_documents untouched

SELECT to_regclass('public.production_documents') IS NULL AS still_absent;  -- expect true

T8 — Qdrant unchanged

Not asserted from SQL — verified at operator level by absence of any Qdrant client call from 042R. Confirmed by code inspection: fn_iu_op_* bodies contain zero dblink, http, or external-call constructs.

Regression matrix summary

Surface Pre 110000x Post 110000x apply + T1-T8 Δ allowed?
information_unit count 175 175 0 (proof BEGIN/ROLLBACK)
DIEU-28/32/35 counts 27/23/36 27/23/36 0
iu_vector_sync_point 152 152 0
iu_core.iu_staging_record 3 3 0 (BEGIN/ROLLBACK)
iu_core.iu_staging_payload 4 4 0 (BEGIN/ROLLBACK)
dot_iu_command_catalog 36 41 +5 (alias DOT entries)
public fns 502 507 +5 (fn_iu_op_*)
dot_iu_command_run 21 21 (BEGIN/ROLLBACK) or +N +N audit only when apply path executes
dot_config composer/retention false/false false/false gates closed at exit
production_documents absent absent 0
Qdrant iu_core_iu_chunks (untouched) (untouched) 0

Verdict template (post-apply)

When all eight tests PASS in sequence:

IU_CORE_110000X_DIEU30_REGRESSION_PASS
- T1 alias-fixture: PASS
- T2 alias≡direct MARK digest: PASS
- T3 alias≡direct CUT shape: PASS
- T4 baseline-unchanged: PASS
- T5 +5 fn, +5 DOT: PASS
- T6 vsp=152 unchanged: PASS
- T7 production_documents absent: PASS
- T8 Qdrant untouched: PASS (inspection)
Back to Knowledge Hub knowledge/dev/laws/dieu44-trien-khai/v0.6-iu-core-110000x-operator-alias-surface-d30-d31-protection/03-dieu30-regression-suite.md