VGSF CONSTITUTIONAL TECHNICAL ARCHITECTURE — BOOK II — PART E: VERIFICATION AND CERTIFICATION
Chapter 2 of 4 in this Part
V2 — Verification Architecture
Document record
| Field | Value |
|---|---|
| Constitutional Series | V — Verification and Certification |
| Primary Sources | FOUNDATION_INTEGRATION_VERIFICATION_STANDARD.md (VS-007) · MUTATION_AUTOMATION_STANDARD.md (VS-003) · REPLAY_AUTOMATION_STANDARD.md (VS-002) · VERIFICATION_ENVIRONMENT_ASSEMBLY_STANDARD.md (VS-008) |
| Constitutional Status | ADVISORY institutional standards (VS-002 FORWARDED to Primary Steward; VS-003, VS-007, VS-008 EMBEDDED) |
| Applies To | All REF domains entering Phase 3 (Verification Architecture) and Phase 5 (Verification Execution) |
| Position in Book | Part E, Chapter 2 of 4 |
V1 established the doctrine of verification: why it is constitutionally required, what categories of Verification Function the lifecycle demands, and what prohibitions govern all actors in the verification chain. V2 (Verification Architecture) establishes the technical architecture — how VFs are written, how mutations are injected and detected under the apply-detect-revert cycle, how the two-run replay obligation is satisfied through fresh-database isolation, and how the verification environment is assembled from Foundation Asset Registry contents to ensure reproducible, independent execution.
§1 — Foundation Integration Verification Standard (VS-007)
Identifier: VS-007 | Version: 1.0 | Date: 2026-06-14 | Authority: R-VARCH (advisory) | Originating Program: CAP028E-C | Status: INSTITUTIONAL STANDARD — Advisory | Classification: UNIVERSAL (applies when 2+ Foundation Stack members individually certified)
§1.1 — Purpose
Define what Foundation Stack Integration Verification means, when it is required, what categories of tests it must include, how its artifacts are structured in 40_FOUNDATION_ASSETS/INTEGRATION_TESTS/, and how it relates to individual domain certification.
This standard formalizes OBS-A-009 (Foundation Stack Integration Test Gap) from CAP028E-A. It does not prescribe a specific integration test program — that is the responsibility of the integration program (tentative CAP029A). It establishes what that program must produce and how future programs can inherit from it.
§1.2 — Definition of Foundation Stack Integration Verification
Foundation Stack Integration Verification is an independent verification program (distinct from any individual REF domain's Phase 5) that:
- Stands up two or more Foundation Stack member services simultaneously in a shared verification environment
- Executes cross-domain tests that cannot be performed by individual domain verification programs
- Produces a verdict of
INTEGRATION_VERIFIED,INTEGRATION_VERIFIED_WITH_FINDINGS, orINTEGRATION_FAIL - Promotes its artifacts to
40_FOUNDATION_ASSETS/INTEGRATION_TESTS/for future reuse
§1.3 — What Individual Certification Cannot Verify
Individual domain Phase 5 / Phase 6 programs verify one domain in isolation. They CANNOT verify:
| Cross-domain concern | Why individual certification is insufficient |
|---|---|
| JWT entity_id consistency | Each domain tests its own JWT middleware independently; consistency across services is untested |
| Cross-domain RLS scope | REF001 RLS applies to REF001 tables; REF003 RLS applies to REF003 tables; who verifies that the same JWT produces consistent scope in both? |
| Event UUID correlation | REF003 place.created event includes place_id; if REF004 consumes this event and creates a FK reference, the UUID chain must be consistent |
| Platform middleware uniformity | If auth middleware is shared code, a defect may pass REF001 tests and REF003 tests individually while failing in composition |
| Governance chain authorization | REF002 governs who can act; downstream domains trust REF002's governance routing; composition must be verified |
| Entity data presence | REF003 places are created by REF001 entity-scoped operations; if REF001 seed entities don't match REF003 entity_ids, integration environment is incoherent |
§1.4 — Integration Test Categories
Category IT — Integration Token Tests
Verify that a single JWT token produces consistent identity across all simultaneously-running Foundation Stack services.
Required IT tests:
- IT-001: Same JWT → same entity_id extracted from all Foundation Stack services
- IT-002: Same JWT → RLS scope consistent across all Foundation Stack services
- IT-003: Expired JWT → 401 from all Foundation Stack services simultaneously
- IT-004: Absent JWT → 401 from all Foundation Stack services simultaneously
Category IC — Integration Consistency Tests
Verify that data created in one Foundation Stack domain is correctly referenceable from another.
Required IC tests:
- IC-001: REF001 entity_id created → REF003 place created by same entity → place.entity_id matches REF001 entity record
- IC-002: REF002 governance relationship → REF003 address creation → same governing entity_id in both domains
- IC-003: Foundation Stack seed entity_ids present consistently across all three domain databases
Category IE — Integration Event Tests
Verify that integration events published by one domain carry UUIDs that are valid references in another domain.
Required IE tests:
- IE-001: REF003 place.created event includes place_id → place_id resolvable in REF003 GET /places/{id}
- IE-002: REF003 outbox event entity_id matches REF001 entity record
- IE-003: Event ordering is consistent for the same entity_id across all outbox channels
Category IP — Integration Platform Tests
Verify that platform middleware (auth, outbox, tracing) behaves consistently across Foundation Stack services.
Required IP tests:
- IP-001: shared JWT signing key → all services verify correctly
- IP-002: Outbox relay: events from all three services route to same relay infrastructure
- IP-003: Database connection pool exhaustion in one service → other services unaffected
§1.5 — Foundation Asset Contributions
§1.5.1 — Integration Test File Structure
40_FOUNDATION_ASSETS/INTEGRATION_TESTS/
FOUNDATION_STACK_V1/
test_integration_token.py # IT category
test_integration_consistency.py # IC category
test_integration_events.py # IE category
test_integration_platform.py # IP category
conftest.py # Shared fixtures (JWT tokens, entity_ids)
README.md # Usage and prerequisites§1.5.2 — Integration Test Prerequisites
Integration tests SHALL NOT run unless:
- All required Foundation Stack member services are healthy (health endpoint returns 200)
- Foundation Asset seeds are applied across all domain databases
- JWT fixture tokens are loaded from
40_FOUNDATION_ASSETS/JWT_FIXTURES/ - Integration environment is assembled per VS-008
If prerequisites are not met, integration tests SHALL SKIP with explicit skip reason, not FAIL.
§1.5.3 — JWT Fixture Requirements
Integration tests require JWT tokens with entity_ids that:
- Appear in REF001 seed data (entity exists)
- Are present in REF003 seed data (entity has place records)
- Are present in REF002 seed data (entity has governance relationships)
See 40_FOUNDATION_ASSETS/JWT_FIXTURES/README.md for generation instructions.
§1.6 — When Foundation Stack Integration Verification Is Required
| Trigger | Action |
|---|---|
| All Foundation Stack members reach Phase 6 certification | Constitute Foundation Stack Integration Program (tentative CAP029A); NOT OPTIONAL after all three certified |
| New domain is added to Foundation Stack definition | Constitute new integration verification with expanded scope |
| Platform middleware code changes | Re-run integration tests before any Phase 5 begins for the affected domains |
| Phase 6 certification of REF003 (CAP028G) | Prerequisite for CAP029A constitution; Primary Steward authorization required |
§1.7 — Relationship to Individual Domain Certification
Foundation Stack Integration Verification does NOT:
- Replace individual domain Phase 5 (R-VEXEC) verification
- Replace individual domain Phase 6 (R-CERT) certification
- Elevate individual domain certification verdicts (a CERTIFIED_WITH_OBSERVATIONS domain remains so)
Foundation Stack Integration Verification DOES:
- Add confidence above and beyond individual domain certification
- Identify defects visible only in composition
- Produce a distinct verdict for the Foundation Stack AS A UNIT (not for individual domains)
- Contribute integration test assets to
40_FOUNDATION_ASSETS/INTEGRATION_TESTS/for future reuse
Source: FOUNDATION_INTEGRATION_VERIFICATION_STANDARD.md (VS-007) | 2026-06-14 | CAP028E-C — R-VARCH
§2 — Mutation Automation Standard (VS-003)
Identifier: VS-003 | Version: 1.0 | Date: 2026-06-14 | Authority: R-VARCH (advisory) | Originating Program: CAP028E-B | Status: INSTITUTIONAL STANDARD — Advisory. Pending Primary Steward ratification for elevation to V2.x ratified doctrine.
§2.1 — Purpose
Define the principles and requirements for executing the constitutional mutation gate across VGSF verification programs. The mutation gate verifies that each constitutional protection is independently detectable — that no constraint can be silently removed without triggering specific test failures.
§2.2 — Mutation Gate Doctrine
§2.2.1 — Requirement (UNIVERSAL)
All constitutional verification programs (Phase 5) SHALL execute a mutation gate. The mutation gate passes only when every catalogued mutation is DETECTED by its designated test(s).
Classification: UNIVERSAL — Applies to all domains implementing Phase 5 verification under Methodology V2.0.
§2.2.2 — Definition of "Detected"
A mutation M is DETECTED when:
- The designated detection test(s) that were PASS in the baseline state produce FAIL after M is applied
- The detection failure is attributable to the mutation (not a pre-existing defect or environment issue)
- The baseline is restored after M is reverted and the detection test returns to PASS
A mutation that is NOT DETECTED indicates either:
- The mutation was not correctly applied (test the apply step)
- The detection test is insufficient to catch the defect
- The constitutional protection is redundant with another protection (investigate before concluding)
§2.3 — Apply-Detect-Revert Cycle
§2.3.1 — Core Protocol (UNIVERSAL)
For every mutation M:
Step 1 — BASELINE CHECK
Execute detection_tests(M) → assert all PASS
Step 2 — APPLY
Execute APPLY_SQL(M) against the verification database
Step 3 — DETECT
Execute detection_tests(M) → assert at least one FAILS
Step 4 — REVERT
Execute REVERT_SQL(M) against the verification database
Step 5 — VERIFY_REVERT
Execute detection_tests(M) → assert all PASS again
Step 6 — RECORD EVIDENCE
Write per-mutation evidence record (see §2.6)Critical invariant: Step 5 (VERIFY_REVERT) is mandatory. A failed revert leaves the schema in a mutated state, corrupting all subsequent mutations. If Step 4 fails or Step 5 does not return PASS, abort mutation testing and investigate before proceeding.
§2.3.2 — Isolation Invariant (UNIVERSAL)
Each mutation MUST be applied and reverted in isolation. Never run two mutations concurrently. This ensures:
- Attribution is unambiguous (only one mutation is active at any time)
- A failed revert does not compound with subsequent mutations
- Evidence is per-mutation and independent
§2.4 — Mutation Classification
§2.4.1 — Classification is Mandatory (UNIVERSAL)
Every mutation in the mutation catalogue SHALL be classified before Phase 5 execution. The classification determines the execution protocol.
§2.4.2 — Class A — Transactional Mutations
Definition: Mutations that use DDL executable within a PostgreSQL transaction (ENABLE/DISABLE TRIGGER, SET ROLE, SET LOCAL, grant/revoke within session).
Examples:
ALTER TABLE <t> DISABLE TRIGGER <name>;— disables a delete/truncate/bitemporal triggerALTER TABLE <t> ENABLE TRIGGER <name>;— reverts the above
Protocol: The Apply-Detect-Revert cycle can be executed with savepoints:
SAVEPOINT before_mutation;
<APPLY_SQL>;
-- Run detection test in same session
<REVERT_SQL>;
-- OR: ROLLBACK TO SAVEPOINT before_mutation; (reverts the DISABLE TRIGGER)
RELEASE SAVEPOINT before_mutation;Note: For clarity and evidence, the recommended approach is explicit APPLY + DETECT + REVERT rather than savepoint rollback, so the mutated state is observable and documented.
§2.4.3 — Class B — Non-Transactional Mutations
Definition: Mutations using DDL that cannot run inside a PostgreSQL transaction, or whose cleanup requires dropping data that constitutional triggers protect.
Examples:
ALTER TABLE <t> DROP CONSTRAINT <name>;— drops a CHECK or EXCLUSION constraint; requires index rebuild on ADDDROP POLICY <name> ON <t>;— drops an RLS policyALTER TABLE <t> ADD CONSTRAINT <name> ...;— rebuilds index after Class B drop
Protocol:
Option A (recommended for all Class B): Fresh verification database clone per mutation.
# Clone baseline database
pg_dump <domain>_verification | psql <domain>_mutation_MC{N}
# Apply mutation in clone
psql <domain>_mutation_MC{N} -c "<APPLY_SQL>"
# Run detection test against clone
# Verify detection
# Drop mutation database (cleanup is trivial)
psql -c "DROP DATABASE <domain>_mutation_MC{N};"Option B: Direct apply-revert with explicit cleanup. Use only when the mutation window data can be identified and cleaned before constraint re-add.
-- Apply mutation
<APPLY_SQL>;
-- Insert test data that bypasses removed constraint
INSERT INTO <table> ... (<invalid-under-constraint-data>);
-- Verify insertion succeeded (DETECTED)
-- Clean up mutation-window data before reverting
DELETE FROM <table> WHERE id = <mutation-window-id>;
-- Revert
<REVERT_SQL>;Note: On constitutionally-protected tables, DELETE in Option B is blocked by triggers. Use the fresh-DB clone (Option A) for all mutations on constitutionally-protected tables.
§2.5 — RLS Mutations
§2.5.1 — Superuser Bypass Requirement (UNIVERSAL for RLS-implementing domains)
PostgreSQL superusers bypass RLS by design. RLS mutation detection requires a non-superuser test role.
Setup requirement for any domain with RLS mutations:
CREATE ROLE <domain>_verifier WITH LOGIN PASSWORD '<secure>';
GRANT CONNECT ON DATABASE <domain>_verification TO <domain>_verifier;
GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA public TO <domain>_verifier;All RLS mutation detection tests MUST execute as this non-superuser role.
§2.5.2 — Session Configuration for RLS
RLS policies that depend on app.current_entity_id session configuration require that the configuration be set before the detection test:
SELECT set_config('app.current_entity_id', '<test-entity-id>', true);The test entity ID must match an entity that the verification environment's JWT fixtures are configured to present.
§2.6 — Evidence Requirements
§2.6.1 — Per-Mutation Evidence Record (UNIVERSAL)
For each mutation M, produce a structured evidence record:
Mutation: MC-<domain>-<N>
Description: <what is mutated>
Class: A (transactional) | B (non-transactional)
Target tests: <test-id-list>
Baseline check:
Tests: <test-ids>
Result: PASS
Apply SQL:
<SQL>
Detection:
Tests: <test-ids>
Result: DETECTED (expected failure observed)
Revert SQL:
<SQL>
Baseline restored:
Tests: <test-ids>
Result: PASS
Mutation verdict: DETECTED | NOT_DETECTED§2.6.2 — Mutation Gate Evidence Summary (UNIVERSAL)
After all mutations:
Total mutations: <N>
DETECTED: <count>
NOT_DETECTED: <count>
Gate verdict: PASS (if NOT_DETECTED = 0) | FAIL (if NOT_DETECTED > 0)§2.7 — Environment Cleanup Doctrine
§2.7.1 — Class A Mutations (UNIVERSAL)
Cleanup is the REVERT_SQL. No data cleanup required (no constraint-violating data was committed to the database — detection tests use savepoints or in-flight verification).
§2.7.2 — Class B Mutations — Protected Tables (UNIVERSAL)
When the mutation window inserts data into constitutionally-protected tables (TRUNCATE/DELETE blocked), cleanup requires one of:
- Fresh-DB clone (Option A above) — preferred; drop database after use
- Pre-cleanup before REVERT — requires that the mutation-window data is on non-protected tables or that the protection does not apply to the specific rows
Absolute rule: If cleanup of mutation-window data is not possible without violating constitutional protections, use the fresh-DB clone protocol. Do not attempt to work around constitutional protections to achieve cleanup.
§2.7.3 — Class B Mutations — Unprotected Tables (PRESUMPTIVE)
For tables without constitutional protection (e.g., ref003_event_outbox, address_type_registry), standard DELETE can be used for cleanup. Identify these tables in the mutation catalogue and note they allow standard cleanup.
§2.8 — Mutation Gate Failure Doctrine
§2.8.1 — NOT_DETECTED Failure Protocol (UNIVERSAL)
When a mutation returns NOT_DETECTED:
1. Verify the mutation was correctly applied (check pg_trigger, pg_constraint, pg_policies)
2. Verify the detection test is targeting the correct schema artifact
3. If mutation confirmed applied and test still passes: escalate
→ Test is insufficient to detect this defect
→ Trigger corrective cycle on the verification architecture (Phase 3 defect)
→ Constitute a verification architecture amendment before proceeding to certification
4. Mutation gate CANNOT be PASS until NOT_DETECTED = 0The existence of an undetected mutation means a constitutional protection can be silently removed without triggering test failures. This is a constitutional trustworthiness failure, not merely a test failure.
§2.9 — Mutation Catalogue Requirements (Phase 3 Obligation)
The Phase 3 verification architecture (R-VARCH) SHALL produce:
- A complete mutation catalogue for the domain
- Classification of each mutation (Class A or B)
- Detection test mapping (which test(s) detect each mutation)
- SQL for APPLY and REVERT
- Cleanup strategy for each Class B mutation
The mutation catalogue is a first-class Phase 3 deliverable and MUST be complete before Phase 5 execution begins.
§2.10 — Applicability
| Domain Characteristic | Requirement |
|---|---|
| Constitutional delete triggers | Include mutations for each trigger (Class A) |
| Constitutional truncate triggers | Include mutations for each trigger (Class A) |
| History immutability triggers | Include mutations for each trigger (Class A) |
| Bitemporal update triggers | Include mutations for each trigger (Class A) |
| CHECK constraints | Include mutations for each critical constraint (Class B) |
| EXCLUSION constraints | Include mutations for exclusion constraints (Class B, requires index rebuild) |
| RLS policies | Include mutations for critical policies (Class B, non-superuser role required) |
Source: MUTATION_AUTOMATION_STANDARD.md (VS-003) | 2026-06-14 | CAP028E-B
§3 — Replay Automation Standard (VS-002)
Identifier: VS-002 | Version: 1.0 | Date: 2026-06-14 | Authority: R-VARCH (advisory) | Originating Program: CAP028E-B | Status: INSTITUTIONAL STANDARD — Advisory. Pending Primary Steward ratification (FORWARDED — UP-008 candidate).
§3.1 — Purpose
Define the principles and requirements for deterministic replay verification across VGSF constitutional domains. Replay verification is the practice of executing the full verification suite twice and confirming that both runs produce identical results.
Without a replay standard, a passing verification could be an artifact of test ordering, accumulated database state, or environmental timing — not constitutional correctness.
OBS-A-002 embedded: This standard institutionalizes the two-domain observation (REF002 + REF003) that constitutional TRUNCATE/DELETE protection requires an explicit test environment reset philosophy incompatible with standard teardown patterns.
§3.2 — Two-Run Replay Doctrine
§3.2.1 — Requirement (UNIVERSAL)
All constitutional verification programs (Phase 5) SHALL execute the full test suite twice. The two runs SHALL produce identical verdicts on every test.
Classification: UNIVERSAL — Applies to all domains implementing Phase 5 verification under Methodology V2.0.
§3.2.2 — Definition of "Identical"
Two runs are identical when:
- Every test that PASS in Run 1 is PASS in Run 2
- Every test that FAIL in Run 1 is FAIL in Run 2 (expected zero failures at PASS gate)
- No test changes result between Run 1 and Run 2
A single test changing result between runs is a REPLAY_FAIL regardless of which direction it changed.
§3.2.3 — Rationale
The two-run requirement serves three constitutional purposes:
- State leak detection — Reveals tests that leave persistent state affecting downstream tests
- Ordering artifact detection — Reveals tests that pass only in specific sequences
- Environment noise elimination — Confirms results are not artifacts of connection pool state, timing, or first-run initialization
§3.3 — Evidence Requirements
§3.3.1 — Per-Run Evidence (UNIVERSAL)
Each replay run SHALL produce the following evidence artifacts:
| Artifact | Contents |
|---|---|
run{N}_summary.json | Test counts (total/pass/fail); P1 BLOCKER counts; verdict |
run{N}_test_log.txt | Complete test output with individual test names and results |
run{N}_db_state.sql | Table row counts; key column checksums (if applicable) |
run{N}_timestamp.txt | ISO-8601 start/end timestamps; service code git commit SHA |
§3.3.2 — Comparison Evidence (UNIVERSAL)
After both runs, produce a comparison artifact:
| Artifact | Contents |
|---|---|
replay_comparison.md | Side-by-side comparison of Run 1 vs Run 2 results; divergence list; overall verdict |
If zero divergences: REPLAY_GATE: PASS
If any divergence: REPLAY_GATE: FAIL — classify each divergence
§3.4 — Environment Reset Philosophy
§3.4.1 — The Constitutional Incompatibility Problem (UNIVERSAL)
Constitutional TRUNCATE triggers (trg_0_*_prevent_truncate) and DELETE triggers (trg_0_*_prevent_delete) block the operations that test frameworks conventionally use for teardown.
Standard teardown patterns that DO NOT WORK in constitutional schemas:
TRUNCATE TABLE place CASCADE;→ blocked by triggerDELETE FROM place;→ blocked by triggerTRUNCATE TABLE place, geometry, address RESTART IDENTITY CASCADE;→ blocked
This is not a defect. These triggers are correct constitutional enforcement. The implication is that test environment management requires explicit design in every constitutional domain's Phase 3 verification architecture.
§3.4.2 — Fresh Database Doctrine (UNIVERSAL, RECOMMENDED)
Classification: UNIVERSAL (recommended approach)
For replay verification runs, the recommended approach is a fresh database per run:
# Run N setup
DROP DATABASE IF EXISTS <domain>_verification_run{N};
CREATE DATABASE <domain>_verification_run{N} ...;
# Apply all DDL, workarounds, migrations, canonical seed
# Execute full test suite against <domain>_verification_run{N}
# Capture all evidence artifactsAdvantages:
- Guaranteed clean state — no possibility of state leak between runs
- Mutation window cleanup trivial (database is dropped at end of run)
- Supports parallel execution of runs (separate databases)
- Eliminates all trigger-induced cleanup complications
Disadvantages:
- Higher setup time (DDL application per run)
- Requires scripted setup (not a limitation in practice — required anyway)
§3.4.3 — Savepoint Doctrine (PRESUMPTIVE)
Classification: PRESUMPTIVE (acceptable for session-level verification, not full replay)
For individual test isolation within a single run, PostgreSQL savepoints provide rollback capability that IS compatible with constitutional DELETE/TRUNCATE protection:
SAVEPOINT test_start;
-- Execute test (including INSERTs)
ROLLBACK TO SAVEPOINT test_start;
-- INSERTs are reversed; database returns to pre-test state
RELEASE SAVEPOINT test_start;Critical confirmation: PostgreSQL savepoint ROLLBACK correctly reverses INSERTs, even on constitutionally-protected tables. The DELETE trigger fires only on DELETE FROM — it does not fire on savepoint rollback.
Applicability: Savepoints are the recommended intra-run isolation mechanism. They do NOT replace fresh-DB between replay runs (savepoints cannot reset the accumulated state from Run 1 before Run 2).
Limitation for AT (address type) category: The AT test category modifies address_type_registry.is_active. This modification cannot be rolled back via DELETE/TRUNCATE (blocked). AT tests MUST use per-test unique type IDs so modifications do not interfere with other tests.
§3.5 — Determinism Requirements
§3.5.1 — Sources of Non-Determinism (UNIVERSAL)
Known non-determinism sources in constitutional verification:
| Source | Mitigation |
|---|---|
| Runtime UUID generation in test inputs | Use canonical UUIDs from VS-001 seed standard |
| Timestamp comparisons (exact equality) | Use range bounds (> now() - interval '5 seconds') |
| Test execution ordering (implicit dependency) | Fix test order; document dependency chain in Phase 3 |
| JWT runtime generation | Use pre-generated fixed JWT fixtures with far-future exp |
| asyncpg infinity serialization (Python stack) | Explicit serialization test; document expected format |
| Connection pool state | Fresh DB per run eliminates this |
| Extension function behavior differences (PostGIS) | Pin extension version; document in verification DB setup |
§3.5.2 — JWT Fixture Requirements (UNIVERSAL for JWT-authenticated services)
JWT fixtures used in verification MUST be pre-generated with fixed values:
- Fixed
entity_idmatching the canonical seed's expected entity scope - Fixed
subclaim - Fixed
iat(issued-at) — use a historical value - Far-future
exp(expiry) — prevents fixture expiry during test execution - All JWT payloads stored in version-controlled fixture files, not generated at test runtime
§3.6 — Replay Failure Handling
§3.6.1 — Failure Classification
When a test changes result between Run 1 and Run 2, classify the divergence:
| Class | Definition | Resolution |
|---|---|---|
| ORDERING_ARTIFACT | Test passes/fails depending on what ran before it | Fix test isolation (savepoint per test); re-run both runs |
| STATE_LEAK | Run 1 leaves committed state that affects Run 2 | Fix with fresh-DB per run; identify leaking test |
| IMPLEMENTATION_DEFECT | Test reveals non-deterministic service behavior | Trigger corrective cycle (per CORRECTIVE_CYCLE_STANDARD.md) |
| ENVIRONMENT_DEFECT | Infrastructure timing/concurrency caused divergence | Fix environment; re-run both runs |
§3.6.2 — Re-Run Protocol
After fixing a classified failure:
- Execute Run 1 (fresh DB)
- Execute Run 2 (fresh DB)
- Compare — both runs must produce identical results
- Replay gate cannot be PASS until two consecutive runs produce identical results without any manual intervention between them
§3.7 — Recommended Test Runner Architecture
§3.7.1 — Technology Stack (DOMAIN-CONDITIONAL for Python/FastAPI services)
Recommended:
- pytest — test runner
- pytest-asyncio — async test support
- httpx.AsyncClient with
AsyncLifespanManager— ASGI test client (tests the actual application, not a mock) - pytest-ordering or explicit sequential marks — for fixed test order
§3.7.2 — Test Category Execution Order (DOMAIN-CONDITIONAL)
For domains with dependent test categories, document the required execution order in Phase 3 deliverables. Example ordering principle:
Registry/Type tests → Entity creation tests → Child creation tests →
Child update tests → History verification tests → Property tests →
Event tests → Middleware testsEach domain's Phase 3 verification architecture SHALL specify the ordering for that domain.
§3.8 — Applicability Matrix
| Domain Characteristic | Applies | Standard Section |
|---|---|---|
| Constitutional TRUNCATE protection | YES — all V2.0 domains | §3.4.1 (incompatibility), §3.4.2 (fresh DB) |
| Bitemporal schema | YES — all bitemporal domains | §3.3 (state evidence) |
| JWT-authenticated service | YES — all authenticated services | §3.5.2 (JWT fixtures) |
| Address type / registry mutations | YES — domains with is_active fields | §3.4.3 (AT category isolation) |
| asyncpg driver (Python) | YES — Python/asyncpg stack | §3.5.1 (serialization) |
| PostgreSQL savepoints | YES — all PostgreSQL-backed services | §3.4.3 (savepoint doctrine) |
Source: REPLAY_AUTOMATION_STANDARD.md (VS-002) | 2026-06-14 | CAP028E-B
§4 — Verification Environment Assembly Standard (VS-008)
Identifier: VS-008 | Version: 1.0 | Date: 2026-06-14 | Authority: R-VARCH (advisory) | Originating Program: CAP028E-C | Status: INSTITUTIONAL STANDARD — Advisory | Classification: UNIVERSAL (environment selection); DOMAIN-CONDITIONAL (multi-REF assembly)
§4.1 — Purpose
Extend VS-004 (VERIFICATION_ENVIRONMENT_STANDARD) to cover the assembly of multi-REF verification environments from Foundation Asset Registry contents. While VS-004 defines WHICH environment option to select (A/B/C), this standard defines HOW to assemble a verification environment from canonical foundation assets.
§4.2 — Assembly Principles
§4.2.1 — Single-Source Principle
Foundation seed data, JWT fixtures, and mutation SQL SHALL be sourced from 40_FOUNDATION_ASSETS/ when that registry is populated. Phase 5 programs SHALL NOT independently re-create foundation assets that are already registered.
Rationale: If each Phase 5 program independently creates its seed data, cross-domain collisions can arise and the accumulated wisdom from prior verifications is lost.
§4.2.2 — Extension Principle
Domain-specific test data (data required only for a specific domain's own tests, not shared with downstream) MAY be defined in the domain's own Phase 5 program. Foundation assets are the minimum-required shared layer; domain-specific extension is permitted and expected.
§4.2.3 — Dependency-Order Principle
Seeds MUST be applied in dependency order. If REF003 seeds reference REF001 entity_ids:
- Apply REF001 seeds first
- Apply REF002 seeds second (if REF002 governance relationships reference REF001 entities)
- Apply REF003 seeds third
The dependency order is declared in each seed file's header (per VS-005 §4.2).
§4.3 — Single-Domain Environment Assembly Protocol
For a Phase 5 program running Option A (per-domain isolated database):
Step 1 — Provision database:
createdb ref{nnn}_verificationStep 2 — Apply constitutional DDL:
psql ref{nnn}_verification < 02_DOMAIN/REF-{NNN}/03_engineering/ddl/001_*.sql
# ... all DDL files in orderStep 3 — Apply service migrations:
psql ref{nnn}_verification < 02_DOMAIN/REF-{NNN}/03_engineering/migrations/001_*.sqlStep 4 — Apply domain-conditional extension setup (where applicable):
For REF003 (PostGIS domains) — per VS-004 §5:
-- FINDING-R1-001 workaround
CREATE SCHEMA postgis_ext;
CREATE EXTENSION postgis SCHEMA postgis_ext;
ALTER DATABASE ref003_verification SET search_path = public, postgis_ext;
-- Reconnect after ALTER DATABASE
-- FINDING-R1-003 workaround (after DDL applied)
ALTER TABLE geometry_history ALTER COLUMN geom TYPE postgis_ext.geometry
USING NULL::postgis_ext.geometry;Step 5 — Apply foundation seeds (from Foundation Asset Registry):
psql ref{nnn}_verification < 40_FOUNDATION_ASSETS/SEEDS/REF{NNN}/{entity}_seeds_v1.sqlStep 6 — Apply domain-specific test data extensions (if any):
Domain Phase 5 seed SQL files not in the foundation registry.
Step 7 — Environment health check (mandatory):
-- Verify extension availability
SELECT COUNT(*) FROM pg_extension WHERE extname IN ('postgis', 'btree_gist'); -- domain-conditional
-- Verify seed row counts
SELECT COUNT(*) FROM {primary_entity_table}; -- expect N rows per seed file
-- Verify trigger inventory
SELECT tgname, tgenabled FROM pg_trigger WHERE tgname LIKE 'trg_%' ORDER BY tgname;
-- All triggers must show tgenabled = 'O'Step 8 — Record environment snapshot:
Per VS-009 (artifact packaging), record the health check output as environment_snapshot.md in the evidence folder.
§4.4 — Foundation Stack Environment Assembly Protocol (Option C — Hybrid)
For a Foundation Stack Integration Program (VS-007) assembling a multi-REF environment:
Step 1 — Provision per-domain databases:
createdb ref001_integration
createdb ref002_integration
createdb ref003_integrationStep 2 — Apply each domain's DDL and migrations in sequence.
Step 3 — Apply foundation seeds in dependency order:
# Apply upstream seeds first
psql ref001_integration < 40_FOUNDATION_ASSETS/SEEDS/REF001/entity_seeds_v1.sql
# Apply relationship seeds (depends on entity seeds)
psql ref002_integration < 40_FOUNDATION_ASSETS/SEEDS/REF002/relationship_seeds_v1.sql
psql ref002_integration < 40_FOUNDATION_ASSETS/SEEDS/REF002/governance_type_seeds_v1.sql
# Apply location seeds (depends on entity seeds for entity_id scope)
psql ref003_integration < 40_FOUNDATION_ASSETS/SEEDS/REF003/place_seeds_v1.sql
psql ref003_integration < 40_FOUNDATION_ASSETS/SEEDS/REF003/geometry_seeds_v1.sql
psql ref003_integration < 40_FOUNDATION_ASSETS/SEEDS/REF003/address_seeds_v1.sqlStep 4 — Load JWT fixtures:
# JWT fixtures must be configured per VS-009 §6
source 40_FOUNDATION_ASSETS/JWT_FIXTURES/integration_fixture_env.shStep 5 — Start services:
Start each domain service on its designated port (8001=REF001, 8002=REF002, 8003=REF003).
Step 6 — Verify all service health endpoints before running any tests:
curl -f http://localhost:8001/health
curl -f http://localhost:8002/health
curl -f http://localhost:8003/healthStep 7 — Run integration tests from Foundation Asset Registry:
pytest 40_FOUNDATION_ASSETS/INTEGRATION_TESTS/FOUNDATION_STACK_V1/§4.5 — Environment Reset Protocol
Per VS-002 (REPLAY_AUTOMATION_STANDARD), fresh-DB per replay run is the canonical reset protocol. For multi-domain environments:
- Drop all domain databases:
dropdb ref{NNN}_integration(each) - Re-apply Steps 1–6 above
- Do NOT use TRUNCATE — constitutional TRUNCATE protection is active on all foundation domains
§4.6 — Environment Health Check Standard
The following checks SHALL be performed before any test suite begins:
| Check | Query | Expected |
|---|---|---|
| DDL applied | SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'public' | ≥ constitutional table count |
| Triggers active | SELECT COUNT(*) FROM pg_trigger WHERE tgenabled = 'O' | All triggers enabled |
| Seed rows present | Count from primary entity table | ≥ seed file row count |
| PostGIS available | SELECT extname FROM pg_extension WHERE extname = 'postgis' | 1 row (PostGIS domains only) |
| btree_gist available | SELECT extname FROM pg_extension WHERE extname = 'btree_gist' | 1 row (exclusion constraint domains only) |
| RLS enabled | SELECT relname FROM pg_class WHERE relrowsecurity = true | All RLS-enabled tables |
If any health check fails: STOP. Do not proceed with verification. Fix environment before running tests.
§4.7 — Environment Assembly Evidence
As part of VS-009 (artifact packaging), the Phase 5 evidence package SHALL include:
environment_assembly.md— which protocol was used; SQL commands executed; versions appliedenvironment_snapshot.md— health check output at verification startenvironment_teardown.md— confirmation that environment was torn down after each run
Source: VERIFICATION_ENVIRONMENT_ASSEMBLY_STANDARD.md (VS-008) | 2026-06-14 | CAP028E-C — R-VARCH
§5 — Verification Standards Index
| Standard | Classification | Ratification Status | Key Obligation |
|---|---|---|---|
| VS-002 — Replay Automation | UNIVERSAL | FORWARDED (UP-008 candidate) | Two-run replay; fresh-DB per run; identical results |
| VS-003 — Mutation Automation | UNIVERSAL CANDIDATE | EMBEDDED (PP-009 candidate) | Apply-detect-revert; Class A/B; gate requires 0 NOT_DETECTED |
| VS-007 — Foundation Integration Verification | UNIVERSAL (2+ certified) | EMBEDDED (PP-012 candidate) | IT/IC/IE/IP test categories; CAP029A required when all three certified |
| VS-008 — Environment Assembly | UNIVERSAL | EMBEDDED | Single-source from foundation assets; dependency order; health check |
→ See: [V4.§2] — Canonical Seed Standard (VS-001) — the seed data that these assembly protocols load.
→ See: [V4.§3] — Foundation Seed Registry Standard (VS-005) — the registry that governs UUID namespace allocation across domains.
Constitutional Colophon — V2
This chapter establishes the complete verification architecture: the Foundation Stack Integration Verification categories (IT/IC/IE/IP) that address compositional risks invisible to individual certification; the Mutation Automation Standard's apply-detect-revert cycle with Class A (transactional) and Class B (non-transactional) classification; the Replay Automation Standard's two-run fresh-database doctrine and its constitutional necessity given the TRUNCATE/DELETE protection incompatibility with standard teardown; and the Environment Assembly Standard's single-source principle and step-by-step assembly protocol for both single-domain and multi-domain environments.
It operates within Part E under the governing principle that architectural elegance without independently verifiable evidence is constitutionally insufficient — V2's standards are what makes verification evidence reproducible and auditable rather than ad-hoc and ephemeral.
Readers proceeding to V3 (Certification Standards and Independence) should carry forward: the evidence produced under V2's standards — attack matrix, mutation gate results, replay comparison, environment snapshot — is the input corpus that the Phase 6 certifier evaluates. The eight-dimension scorecard in V3 scores the quality of that evidence chain.
