Stage 2 Certification
Purpose
Certify Stage 2 onboarding, policy/RBAC, and PEPM assignment behavior as a sealed baseline.When to run this
- At Stage 2 seal decision
- After Stage 2 hotfixes touching onboarding/policy/PEPM paths
Prerequisites
- Stage 1 gate remains green
- Access to Stage 2 test suites and certification tag history
Inputs
- Candidate commit SHA/tag
- Stage 2 test outputs
- Stage 1 regression gate outputs
Procedure
Certification Date: 2026-01-28Certified Commit:
14ce86050c736c1ee63d8a2014fd6356015be22dTag:
stage2-certified-2026-01-28
1) Scope statement
Stage 2 certifies the following capabilities:- Business onboarding readiness: Discovery, classification, and preflight validation
- Policy + RBAC enforcement: Platform-scope vs org-scope policy management, super-admin enforcement
- PEPM assignment writes: Idempotent SCD2 writes with safe-group handling
- Wizard continuation readiness: Preflight → discovery → mapping → processing flow readiness
2) Explicit exclusions
Stage 2 does NOT include:- Commission math / calculation logic
- Allocation / reconciliation logic
- Stage 3 snapshot generation
- Rollups / aggregation / totals
- Dashboard / analytics endpoints
- AI decision-making in business logic
3) Evidence
Stage 2 Test Results
9 passed, 115 warnings in 0.10s
12 passed, 119 warnings in 0.13s
Total Stage 2 tests: 21 passed
Stage 1 Gate Verification
23 passed, 136 warnings in 0.20s
Stage 1 gate remains green and untouched.
4) Notable fixes included in Stage 2 closure
Production Bugfix
assignment_ids→pepm_assignment_idsinapi/bigquery/business_onboarding_queries.py:1612- Prevents
NameErrorin non-idempotent PEPM write path - Regression test added in
test_pepm_write_non_idempotent_when_active_set_differs
- Prevents
Test Stabilization
-
Function-boundary patching for
find_business_ids_in_safe_groupin idempotent test- Avoids brittle SQL string matching
- Patches at
api.bigquery.business_onboarding_queries.find_business_ids_in_safe_group
-
Correct patch targets for preflight discovered businesses
- Changed from
api.bigquery.discovery_queries.get_discovered_businessestoapi.routes.intake_preflight.get_discovered_businesses - Matches actual import:
from api.bigquery.discovery_queries import get_discovered_businesses
- Changed from
-
Removed brittle
call_countassertions- Replaced with
script_calledflag guard for idempotent case - Focuses on contract checks (idempotent result structure) rather than exact query counts
- Replaced with
-
Idempotency normalization fix
- Updated
idempotency_rowsto use non-normalizedpepm_ratevalues ("2.50","1.00") to match production’sstr(Decimal(...))behavior - Ensures idempotency check matches correctly and script is NOT executed for idempotent cases
- Updated
-
Import safety for optional dependencies
- Made
api/routes/ai_query.pyimport-safe by wrappingvertexaiimports intry/except ImportError - Prevents pytest crashes when optional AI dependencies are not installed
- Made
5) Known non-blocking warnings
- PydanticDeprecatedSince20 warnings about
Field(..., example=...)usage- Not test failures
- Deferred to future Pydantic migration work
- Does not affect functionality
Verification
Stage 2 is now SEALED as of 2026-01-28. Any future changes to Stage 2 code paths require:- Explicit hotfix justification
- Re-run of Stage 2 test suite
- Re-run of Stage 1 gate (must remain green)
- Updated certification if scope changes
stage2-certified-2026-01-28 for the certified baseline.
Failure modes & fixes
- Stage 2 suite failures
- Fix failing onboarding/policy/PEPM code paths and rerun targeted tests.
- Stage 1 gate regression
- Block seal; restore Stage 1 green before proceeding.
- Optional dependency import crashes in tests
- Keep optional integrations import-safe using guarded imports.
- Idempotency path mismatch
- Validate PEPM idempotency normalization assumptions and test fixtures.
Artifacts produced
- Certification metadata (date/commit/tag)
- Stage 2 and Stage 1 test results
- Notable fix list captured in certification evidence
- Seal decision and re-certification criteria
Related docs
docs/runbooks/STAGE1_CERTIFICATION.mddocs/runbooks/STAGE3_KICKOFF.mddocs/reference/RBAC_AUDIT_SUMMARY.md