# Phase 21 — Release Candidate Preparation and Defect Remediation

## 1. Defect remediation completed in source
- Added the missing SQLite connection definition to `config/database.php`, matching the in-memory SQLite test environment in `phpunit.xml`.
- Made the secure session cookie requirement explicit in `.env.example`.
- Configured Laravel to trust forwarded proxy headers; deployment must ensure only the trusted reverse proxy can reach the loopback-bound Nginx listener and that the proxy overwrites forwarded headers.
- Regenerate the authenticated session after successful password change.
- Compare clinician/user IDs as integers when authorising encounter signing.
- Restrict FHIR Encounter read/search to signed encounters only, preventing external FHIR consumers from seeing draft clinical notes.
- Added acceptance test source for FHIR draft-encounter isolation.
- Added password-change acceptance test source.

## 2. Release candidate gate
`scripts/phase21-release-candidate.sh` is a fail-closed staging gate. It checks:
1. Static source verification.
2. Reviewed Composer lock and installed vendor dependencies.
3. Production environment and HTTPS settings.
4. Required PHP extensions including PDO SQLite and PDO MySQL.
5. Composer strict validation and dependency audit.
6. Laravel bootstrap and route compilation.
7. Migration status (read-only; no automatic migration execution).
8. PHPUnit feature suite.
9. HTTPS staging smoke test.
10. Automated gate summary.

The gate intentionally does not apply migrations. Take a backup, review migration status and apply migrations explicitly under the approved change window.

## 3. Static checks in the current authoring environment
- PHP syntax lint.
- JavaScript syntax lint.
- Shell syntax lint.
- PHPUnit XML and Composer JSON parse.
- Docker Compose and workflow YAML parse.
- Static Blade named-route reference audit.
- Static route-controller action audit.
- Static database table reference audit.
- Migration duplicate table declaration audit.
- Project preflight script.

## 4. Current blockers
The authoring environment has no Composer, Docker, PDO SQLite, PDO MySQL, vendor dependencies or staging URL. Therefore:
- No Composer lock was resolved or audited.
- No Laravel runtime boot or route:list was executed.
- No PHPUnit tests were executed.
- No MySQL migrations were applied.
- No Docker image was built.
- No HTTP smoke test or external integration test was run.
- No production backup/restore drill or penetration test was run.

## 5. Required staging execution
1. Generate and review `composer.lock`.
2. Provision a staging host and HTTPS reverse proxy.
3. Configure unique secrets and a production-like `.env`.
4. Build the Docker image and start the five services.
5. Verify database readiness and take an encrypted pre-migration backup.
6. Review and apply migrations explicitly.
7. Run `scripts/phase21-release-candidate.sh` with `HMIS_BASE_URL`.
8. Resolve all test failures and critical/high severity defects.
9. Perform role-based UAT and cross-facility isolation testing.
10. Complete clinical safety, finance, privacy/DPIA, cybersecurity and interoperability approvals.
11. Conduct a restore drill and approve rollback.
12. Record signed go/no-go.

## 6. Release decision
**NOT RELEASED — release candidate preparation only.**

Static source validation is not runtime acceptance. Phase 21 can only be closed after the staging gate passes and all required human governance approvals are documented.
