Files
HealthAppRepository/suggestions/test-requirements-architecture-alignment-review-2026-10-05.md
T

17 KiB
Raw Blame History

Test alignment review — 2026-10-05

Reviewed baseline: b6342af, including the renamed non-persistence ER illustrations. Scope: all test classes/support/fixtures in both test projects; US-01–US-15 and common requirements; current architecture diagrams/correction; authentication design; relevant gateway/client/DTO behaviour needed to interpret what a test actually exercises.

Fresh verification: dotnet test HealthApp.slnx -c Release --no-restore against isolated real PostgreSQL: 265 passed, zero failed, zero skipped (29 PatientProfile, 236 Observation project). The projects also built as part of that run. The temporary database container was removed afterwards. No implementation, requirements or test expectations were changed by this review.

Conclusion

The suite broadly agrees with the specified product and its logical service/data boundaries. There is useful automated evidence for every story. However, passing 265 tests does not demonstrate complete acceptance or deployment coverage. There are misleading/mismatched test fixtures and coverage gaps below. These are primarily test-evidence findings, not proof that the corresponding production operation is broken. Earlier claims that every acceptance criterion was covered were too broad, especially for all-route authentication and process isolation.

Keep the existing behavioural expectations; strengthen coverage rather than weakening tests or changing the requirements. This report replaces the earlier coverage review's remaining-work conclusions for test alignment only; that older review remains a historical pre-implementation snapshot.

F1 — High: authentication coverage is incomplete for the current route set

References:

  • tests/Observation.AcceptanceTests/PatientAuthenticationTests.cs:63
  • tests/Observation.AcceptanceTests/PatientAuthenticationTests.cs:200
  • tests/Observation.AcceptanceTests/ProfessionalAccessTests.cs:197
  • tests/Observation.AcceptanceTests/PatchObservationTests.cs:182
  • tests/Observation.AcceptanceTests/HealthTrendTests.cs:383
  • tests/Observation.AcceptanceTests/HealthOverviewTests.cs:196

US-13 explicitly applies missing, invalid and expired authentication behaviour to every applicable operation. The test named Missing_and_invalid_tokens_reject_every_existing_patient_operation omits PATCH, trends and overview. PATCH separately checks missing/invalid tokens, and trend/ overview tests separately check missing tokens and owner/assignment rejection. Expired-token testing is concentrated on profile retrieval and assignment-list access; invalid/expired-token rejection is not explicitly exercised for trends and overview. The additional shared middleware makes rejection plausible, but is not equivalent to an assertion on each endpoint (an accidental endpoint exception could escape).

Recommendation: a route/method table using real login, existing protected resources, valid request bodies/periods, and explicit actors. Cover missing/invalid/expired tokens, patient-owner/other-patient and assigned/unassigned professional reads. Verify no protected body and unchanged state on rejected writes. Include PATCH and both newer GET routes. This extends documented scenarios, not product functionality.

F2 — Medium: several missing-resource tests pass before reaching the intended service

References:

  • tests/Support/AuthenticatedTestClient.cs:76
  • tests/PatientProfile.AcceptanceTests/CreatePatientTests.cs:94
  • tests/PatientProfile.AcceptanceTests/UpdatePatientTests.cs:36
  • tests/Observation.AcceptanceTests/RecordObservationTests.cs:113
  • tests/Observation.AcceptanceTests/UpdateObservationTests.cs:112
  • tests/Observation.AcceptanceTests/PatchObservationTests.cs:169
  • tests/Observation.AcceptanceTests/DeleteObservationTests.cs:79
  • src/ApiGateway/Security/PatientAccessMiddleware.cs

For an unknown identifier the automatic authenticated client falls back to its last account. An account without a profile, or an account whose own profile differs from the random patient ID, gets an empty gateway 404 before the requested profile/record operation is called. Observation-ID operations resolve the observation during access checking and return 404 there before forwarding update/patch/delete to the operation.

Those tests validly establish public rejection/non-disclosure/no mutation. They do not separately prove the downstream controller/application/repository missing-resource handling suggested by their names. Common requirements assume authorised callers for ordinary missing-resource scenarios; the distinction should be explicit.

There is already a genuinely assigned missing-profile GET test under US-14 and an assigned missing-profile Overview test, so missing profile reads are not entirely uncovered. Unknown observation ownership cannot simply be assigned to a caller.

Recommendation: retain the public security tests and label them accurately. Add service-component tests or authenticated internal-service HTTP tests for the remaining missing-resource branches, using the actual service protection mechanism. Do not relax public ownership checks or invent a public route that bypasses authorization.

F3 — Medium: trend calculator fixtures declare selections inconsistent with their data

References:

  • tests/Observation.AcceptanceTests/HealthTrendTests.cs:20
  • tests/Observation.AcceptanceTests/HealthTrendTests.cs:113
  • tests/Observation.AcceptanceTests/HealthTrendTests.cs:137
  • tests/Observation.AcceptanceTests/HealthTrendTests.cs:187

The calculator helper always supplies Home and AtRest. Some callers supply Clinic, Unknown or AfterActivity observations. In the architecture the calculator consumes already-selected observations; the HTTP history client performs selection. These fixtures therefore describe an impossible selected-input/result-metadata combination for those cases. Their numerical/context assertions are still useful unit assertions, but they cannot demonstrate a valid selected-series assessment.

Recommendation: let the helper accept an explicit selection. Use unrestricted selection for mixed/unknown series and the matching Clinic selection for Clinic-only series. Assert selection metadata as well as the relevant numerical/context behaviour. Keep actual selection/exclusion assertions in the existing HTTP tests.

F4 — Medium: the suite does not verify independent OS-process deployment

References:

  • tests/Observation.AcceptanceTests/ObservationApiFixture.cs:66
  • tests/PatientProfile.AcceptanceTests/PatientApiFixture.cs:49
  • the microservice process boundary in AGENTS.md
  • Docs/Architecture/02_microservice_architecture.jpg

The main fixture creates real Kestrel endpoints and real HTTP calls, but all five WebApplicationFactory hosts live inside the test process. The profile fixture uses Kestrel for the profile and a gateway test server. Restart methods recreate hosts; they do not restart separate operating-system processes. Development uses loopback HTTP and a common fixture gateway-key value for multiple services.

This is an acceptable integration-test arrangement, not itself a production architecture violation. It cannot certify separate deployment, separate-machine networking, production HTTPS/certificate configuration, independently surviving process failure, systemd behaviour, or per-service credentials in an actual deployment. Test-only project references and fixture DB inspection/seeding are not production cross-service coupling; common requirements explicitly allow independent scenario setup.

Recommendation: add a small separate-process acceptance/smoke test that starts the published five executables with external configuration, distinct service credentials, and independent patient/observation databases. Exercise representative reads/writes and stop/restart an individual process. A deployment check should additionally verify production HTTPS and systemd on the intended Linux hosts. Separate-machine operation requires deployment evidence or equivalent network separation, not a claim based on localhost tests alone. These checks need not replace fast existing integration tests.

F5 — Medium: US-11 clinical/context edge cases are mostly calculator-level evidence

References:

  • tests/Observation.AcceptanceTests/HealthTrendTests.cs:12
  • tests/Observation.AcceptanceTests/HealthTrendTests.cs:149
  • tests/Observation.AcceptanceTests/HealthTrendTests.cs:173
  • tests/Observation.AcceptanceTests/HealthTrendTests.cs:237
  • tests/Observation.AcceptanceTests/HealthTrendTests.cs:341
  • US-11 context scenarios and AC-11-A through AC-11-N

Separate metric interpretations, reversals, equal-timestamp handling and exercise- narrative conflict are checked directly against InsightCalculator. HTTP tests cover scope, filters, counts, invalid requests, context correction, deletion and access. The layers together provide substantial evidence, but there is no full HTTP conflict scenario proving original text travels from PostgreSQL through both gateway calls into the trend calculation, nor an HTTP all-tied-timestamps scenario or a HTTP storage/insertion-order equivalence check. Context clearing affecting clinical interpretation is not directly checked by the trend API tests.

Recommendation: add representative end-to-end cases for conflicting recorded text, all-tied timestamps, context clearing and order independence. For clearing, preserve numerical description but check withdrawn references/changed comparability and correct Unknown-only selection. Verify all three metrics' relevant fields, not just systolic.

The current missing-optional-details tests use either fully populated preparation fields except additional circumstances, or all preparation fields missing. Add individual omitted-detail cases to test US-11's narrower rule that a missing optional detail only limits claims that depend on it. Distinguish reference comparison from stronger trajectory/comparability claims; do not add invented clinical thresholds.

F6 — Lower priority: Overview's unknown-context case is not a fully absent-context fixture

Reference: tests/Observation.AcceptanceTests/HealthOverviewTests.cs:110.

That case submits null setting/activity but still supplies rest, posture, arm, device and cuff through the record helper. It correctly verifies unknown categories. It does not prove all preparation details remain absent when the latest reading truly has no context while an older reading has complete context.

Recommendation: add an older complete reading and a newest submission omitting the entire context object, then assert Unknown categories and null optional fields in latest. Assert that the insight's own context explanation is retained independently.

Additional evidence limits

  • Tests asserting clinical boundaries, a source-domain substring or words such as "favourable" are regression evidence for the chosen implementation. They do not independently validate the medical applicability of each inference. The US-11 source-to-claim mapping in src/TRENDS.md remains part of the evidence and needs explicit review when rules or sources change. This audit is not a clinical validation.
  • The documented OLS slope has sign checks, but no exact irregular-spacing slope fixture. A deterministic example with a hand-calculated slope would strengthen evidence for the documented mathematical method without prescribing a new method.
  • The suite verifies offset equivalence but does not rerun equivalent requests under different service time zones. That would strengthen the machine-independent offset-free UTC contract.
  • HTTP failure tests usually stop a dependency to provoke a connection failure. Invalid upstream JSON, upstream timeouts and client-disconnect cancellation are not comprehensively tested. These are robustness/implementation-contract coverage suggestions, not new user-story acceptance criteria.
  • Many tests assert exact HTTP status, DTO equality, headers and explanation wording. These are compatible implementation contracts, but common requirements do not make every exact string/status a product requirement. Keep essential behaviour checks distinct from presentation-contract regression tests.

Story-to-test traceability

This table identifies existing evidence and qualifications, not an assertion that all possible cases or every deployment property have been proven.

Story Existing automated evidence Qualification
US-01 CreatePatientTests; PatientAuthenticationTests login/create/retry/concurrency/restart/database-trigger rollback Atomic association and recovery tested; F1 applies to cross-cutting authentication.
US-02 CreatePatientTests retrieval after restart; ProfessionalAccessTests assigned/missing profile reads Legacy random-ID test is gateway rejection (F2); assigned missing read is genuine evidence.
US-03 UpdatePatientTests update/restart/no-mutation validation; ProfessionalAccessTests forbidden writes Missing update is gateway rejection, not independent service behaviour (F2).
US-04 RecordObservationTests; RecordMeasurementContextTests; MeasurementContextMigrationTests Values, partial/absent/conflicting context, validation, migration and access covered; missing-patient recording needs F2 qualification.
US-05 ViewObservationContextTests; RecordObservationTests; professional/ownership tests Complete/partial/historical text and protected context have strong evidence; missing ID often stops at ownership lookup.
US-06 LatestObservationTests Actual deterministic seeded measurement/recording/ID ties and edits/restart covered. DB seeding is explicitly allowed.
US-07 ObservationHistoryTests; ContextFilteredHistoryTests Independent/combined/unknown filters, metadata, chronology, inclusive/equal/offset bounds and access covered.
US-08 UpdateObservationTests; PatchObservationTests; selected-insight/trend/overview freshness tests Partial correction/clearing/atomic rejection covered; F2 for missing operation and F5 for cleared trend interpretation.
US-09 DeleteObservationTests; DeleteContextualisedObservationTests; trend/overview deletion tests Persisted removal and exclusion are covered; missing delete component path is F2.
US-10 HealthInsightTests; ContextSelectedInsightTests Arithmetic means/extrema, exact rounding fixtures, selection metadata, pooled context and freshness covered.
US-11 HealthTrendCalculationTests and HealthTrendTests (both in HealthTrendTests.cs) Explicit AC-A–N numerical/interpretation evidence is divided between unit and HTTP tests; F3/F5 and source-validation limits apply.
US-12 HealthOverviewTests Profile/latest/selected insight/empty insight/limits/freshness/access/failure covered; F1/F4/F6 remain.
US-13 PatientAuthenticationTests; AuthenticationIntegrationTests; story-level access tests Real credentials/bearer validation/expiration/tampering/association tested; complete operation matrix missing (F1).
US-14 ProfessionalAccessTests; story-level assigned/unassigned/write-rejection tests Multiple/shared/empty assignments, spoofing, ownership and non-disclosure covered; newer-route invalid/expired authentication still F1.
US-15 MeasurementGuidanceTests; RecordObservationTests valid submissions without guidance Public, labelled, sourced, ordered/static guidance and no upstream access covered; source accuracy is not established by string assertions alone.

Architecture alignment

  • Main interservice flows are actual HTTP through the API Gateway, consistent with Observation, Insights and Overview class models. Production projects do not contain references to other service implementations.
  • Patient and observation fixture databases are separate. Migration/persistence tests inspect only controlled test databases. This does not authorize production services to access another service's database.
  • Insights and Overview have no DB/repository registration; freshness is tested with current corrections and deletions. The explicitly renamed ER illustrations do not require persisted calculated results.
  • The real authentication implementation is used for main functional/security tests. A replacement handler is used only in specifically labelled replaceability tests; it is not evidence for bearer cryptography and is not a measured workload.
  • Fixtures replace the clock for deterministic expiry and load synthetic accounts; deployment/measurement must use recorded production settings and real service processes. The current test harness is not an energy-measurement workload.
  • Production HTTPS is tested narrowly for the gateway login/guidance entry point. Main service integration uses Development HTTP. Production transport protection for every service and systemd deployment remains a separate verification task.
  1. Complete the current route/method authentication matrix (F1).
  2. Correct the inconsistent trend unit-fixture selections (F3) and clarify/add missing-resource component evidence (F2).
  3. Add the small number of end-to-end trend and absent-context overview cases (F5/F6).
  4. Verify the separate-process deployed baseline (F4), before architectural/energy comparison.

No architecture redesign or requirement rewrite is needed to improve these tests. The review does not approve changed clinical rules or new product behaviour.