---
title: Testing and Change Safety
summary: Layered tests and schema checks protect BookWorm behavior, service boundaries, and contract compatibility.
owners:
  - architecture-enabling-team
badges:
  - content: Cross-cutting Concept
    backgroundColor: purple
    textColor: purple
---

## Purpose and Scope

Testing and change safety establish evidence that code, contracts, policies, data effects, and user journeys remain acceptable from development through release. These rules apply to shared foundations and every frontend, API, worker, event, integration, and AI boundary.

## Visual Reference

**Verification and Release Gates**

<MermaidFileLoader file="mermaids/006-testing-and-change-safety-diagram-1.mmd" />

## Core Rules and Standards

1. **Test at the lowest useful boundary.** Use fast unit and component tests for local behavior and raise the test level only for interaction or deployment evidence.
2. **Verify contracts independently.** Providers and consumers must prove compatibility for APIs and event schemas before deployment.
3. **Protect architectural boundaries.** Automated checks must prevent forbidden dependencies and preserve capability ownership.
4. **Test behavior, not implementation.** Assert domain outcomes, observable API effects, access decisions, and recoverable failure behavior.
5. **Require quality gates.** Formatting, static analysis, tests, security checks, contract checks, and documentation checks must pass before promotion.
6. **Make releases reversible.** Deploy behind feature or traffic controls when rollback or staged observation is useful.
7. **Use explicit rollback criteria.** A release halts or rolls back for health, error, latency, security, privacy, contract, or business-signal breaches agreed by the owner.

<Admonition type="warning">
	A green build proves only the evidence it exercises. Critical compatibility, privacy, migration,
	and rollout risks require targeted tests or a documented human release gate.
</Admonition>

## Mechanism / How It Works

| Layer        | Primary Evidence                                                                                 |
| :----------- | :----------------------------------------------------------------------------------------------- |
| Unit         | Domain rules, validation, state transitions, pure transformations, and failure classification    |
| Component    | UI behavior, endpoint behavior, handler behavior, policy decisions, and data access boundaries   |
| Integration  | Real interactions among a host and its database, broker, cache, identity, or external dependency |
| Contract     | Consumer/provider compatibility for HTTP, RPC, events, AI tools, and message envelopes           |
| End-to-end   | Critical journeys across frontends, gateways, capabilities, and asynchronous completion          |
| Architecture | Dependency direction, domain isolation, forbidden references, and infrastructure conventions     |

## Verification and Release Gates

<Steps>
	<Step title="Local evidence">
		Run focused tests and formatting or static checks while code is still under development.
	</Step>
	<Step title="Change evidence">
		Run the relevant unit, contract, architecture, integration, and user-flow checks for the changed
		boundary.
	</Step>
	<Step title="Promotion gate">
		Require security, privacy, schema, coverage, migration, and quality checks to pass before
		deployment.
	</Step>
	<Step title="Controlled rollout">
		Deploy incrementally, observe health and business signals, and retain the previous reversible
		artifact.
	</Step>
	<Step title="Decision and rollback">
		Promote when agreed criteria hold; halt or roll back when a breach is detected or the outcome
		cannot be verified.
	</Step>
</Steps>

## Rollout and Rollback Criteria

| Concern              | Promote When                                                   | Roll Back or Halt When                                                    |
| :------------------- | :------------------------------------------------------------- | :------------------------------------------------------------------------ |
| Availability         | Readiness and liveness remain stable at the approved threshold | Health probes fail or traffic sheds unexpectedly                          |
| Latency and errors   | Error and latency budgets remain within release limits         | Sustained breaches correlate with the change                              |
| Contracts            | Consumers pass compatibility checks and replay remains safe    | Additive or breaking incompatibility appears                              |
| Privacy and security | Policy tests pass and no secrets or PII leak is detected       | Unauthorized access, PII exposure, or policy bypass occurs                |
| Business outcome     | Authoritative state and key journeys complete correctly        | Reconciliation gaps, duplicate side effects, or incorrect outcomes appear |

## Verification and Governance

- Map each shared library or boundary change to its owning test layer and contract.
- Keep known gaps explicit and prioritize them with release risk.
- Review failed, flaky, or skipped tests as release evidence, not merely CI noise.
- Retain rollback evidence and operational criteria with every promoted release.

## Related Documentation

- [[doc|development/005-testing]] — Test commands and focused execution.
- [[doc|development/008-testing-matrix]] — Framework and coverage details.
- [[doc|development/006-pull-request-process]] — Pull-request and review requirements.
