Checks: time, ownership and inter-agency data
Templates for the four time, ownership and inter-agency data stories. These guarantees are business rules as much as technical ones, so the test names are written to be read by the agency staff who own the rules.
C-09: the owner’s value wins over a newer timestamp
Section titled “C-09: the owner’s value wins over a newer timestamp”- Proves: a verified value from the owning agency survives a partner record with an older value and a newer export time; the partner’s value stays visible; the owner can still change it.
- Fails for: last-write-wins on arrival or export time. The newest timestamp came from the least authoritative source.
- Harness needs: submit records to the hub as each source.
@Testvoid aVerifiedAddressSurvivesAnOlderPartnerAddressWithAFresherExport() { hub.receive(fromOwner("P-1", "48 Oak Ave", revision(12), verifiedAt("2026-11-20T14:00:00Z"))); hub.receive(fromPartner("LICENSING", "P-1", "12 Elm St", sourceChangedAt("2026-01-15"), exportedAt("2026-11-21T01:00:00Z")));
var person = hub.person("P-1"); assertThat(person.mailingAddress()).isEqualTo("48 Oak Ave"); assertThat(person.observations()).anySatisfy(o -> { assertThat(o.source()).isEqualTo("LICENSING"); assertThat(o.value()).isEqualTo("12 Elm St"); });}
@Testvoid theOwnerCanStillChangeTheAddress() { hub.receive(fromOwner("P-2", "48 Oak Ave", revision(12), verifiedAt("2026-11-20T14:00:00Z"))); hub.receive(fromOwner("P-2", "9 Pine Rd", revision(13), verifiedAt("2026-11-25T09:00:00Z"))); assertThat(hub.person("P-2").mailingAddress()).isEqualTo("9 Pine Rd");}def test_a_verified_address_survives_an_older_partner_address_with_a_fresher_export(hub): hub.receive(from_owner("P-1", "48 Oak Ave", revision=12, verified_at="2026-11-20T14:00:00Z")) hub.receive(from_partner("LICENSING", "P-1", "12 Elm St", source_changed_at="2026-01-15", exported_at="2026-11-21T01:00:00Z"))
person = hub.person("P-1") assert person.mailing_address == "48 Oak Ave" assert any(o.source == "LICENSING" and o.value == "12 Elm St" for o in person.observations)C-10: both questions about the past
Section titled “C-10: both questions about the past”- Proves: after a retroactive correction, the history answers what was true then, using today’s knowledge and what did we believe when we decided, and the notice keeps its actual destination.
- Fails for: effective dates only. The address correction that rewrote history.
- Harness needs: a controllable clock.
@Testvoid aRetroactiveCorrectionKeepsWhatWeKnewAtTheTime() { clock.set("2026-01-02T09:00:00Z"); addresses.record("P-1", "A", effectiveFrom("2026-01-01")); clock.set("2026-03-15T15:00:00Z"); var notice = notices.send("P-1", "Benefit change"); clock.set("2026-04-10T10:00:00Z"); addresses.record("P-1", "B", effectiveFrom("2026-03-01"));
var march15 = LocalDate.parse("2026-03-15"); var decisionTime = Instant.parse("2026-03-15T17:00:00Z"); assertThat(addresses.asOf("P-1", march15, knownAt(clock.now()))).isEqualTo("B"); assertThat(addresses.asOf("P-1", march15, knownAt(decisionTime))).isEqualTo("A"); assertThat(notices.get(notice.id()).sentTo()).isEqualTo("A");}def test_a_retroactive_correction_keeps_what_we_knew_at_the_time(clock, addresses, notices): clock.set("2026-01-02T09:00:00Z") addresses.record("P-1", "A", effective_from=date(2026, 1, 1)) clock.set("2026-03-15T15:00:00Z") notice = notices.send("P-1", "Benefit change") clock.set("2026-04-10T10:00:00Z") addresses.record("P-1", "B", effective_from=date(2026, 3, 1))
march_15 = date(2026, 3, 15) assert addresses.as_of("P-1", march_15, known_at=clock.now()) == "B" assert addresses.as_of("P-1", march_15, known_at="2026-03-15T17:00:00Z") == "A" assert notices.get(notice.id).sent_to == "A"-- History rows are closed, never edited: for each person and effective period,-- the currently-believed rows must not overlap in effective time.SELECT a.person_id, a.address, b.addressFROM address_history aJOIN address_history b ON a.person_id = b.person_id AND a.id < b.id AND a.recorded_to IS NULL AND b.recorded_to IS NULL AND a.effective_from < COALESCE(b.effective_to, 'infinity') AND b.effective_from < COALESCE(a.effective_to, 'infinity');C-11: an incomplete snapshot closes nothing
Section titled “C-11: an incomplete snapshot closes nothing”- Proves: a truncated file closes zero cases, a complete file still closes a case that’s legitimately gone, and an unusually large closure waits for approval.
- Fails for: absence means closed. The missing record that closed a valid case.
- Harness needs: write snapshot files and manifests into the importer’s inbox.
@Testvoid aTruncatedSnapshotClosesNothing() { var cases = activeCases(52_118); inbox.write(snapshot(cases.subList(0, 48_000)), manifest(rowCount(52_118), sha256Of(cases)));
var result = importer.runNightly();
assertThat(result.status()).isEqualTo(REJECTED); assertThat(caseStore.closedSince(result.startedAt())).isEmpty(); assertThat(alerts.raised()).anyMatch(a -> a.contains("incomplete snapshot"));}
@Testvoid aCompleteSnapshotStillClosesARemovedCase() { var cases = activeCases(52_118); var tonight = without(cases, "C-77"); inbox.write(snapshot(tonight), manifest(rowCount(tonight.size()), sha256Of(tonight)));
importer.runNightly();
assertThat(caseStore.status("C-77")).isEqualTo(CLOSED);}
@Testvoid anUnusuallyLargeClosureWaitsForApproval() { var cases = activeCases(52_118); var tonight = cases.subList(0, (int) (cases.size() * 0.97)); inbox.write(snapshot(tonight), manifest(rowCount(tonight.size()), sha256Of(tonight)));
var result = importer.runNightly();
assertThat(result.status()).isEqualTo(AWAITING_APPROVAL); assertThat(caseStore.closedSince(result.startedAt())).isEmpty();}def test_a_truncated_snapshot_closes_nothing(inbox, importer, case_store, alerts): cases = active_cases(52_118) inbox.write(snapshot(cases[:48_000]), manifest(row_count=52_118, sha256=sha256_of(cases)))
result = importer.run_nightly()
assert result.status == "rejected" assert case_store.closed_since(result.started_at) == [] assert any("incomplete snapshot" in a for a in alerts.raised())
def test_a_complete_snapshot_still_closes_a_removed_case(inbox, importer, case_store): tonight = [c for c in active_cases(52_118) if c.id != "C-77"] inbox.write(snapshot(tonight), manifest(row_count=len(tonight), sha256=sha256_of(tonight)))
importer.run_nightly()
assert case_store.status("C-77") == "closed"C-12: merges can be undone
Section titled “C-12: merges can be undone”- Proves: splitting a wrongly merged person returns every attributable update to the right resident, lists the ambiguous ones, and loses nothing.
- Fails for: destructive merges. The records that could be merged but never separated.
- Harness needs: submit updates through each agency’s source record and directly to the person.
@Testvoid splittingAWrongMergeReturnsEveryAttributableUpdate() { var a = registry.ingest(sourceRecord("AGENCY_A", "5531", "Maria Garcia", "1980-04-02")); var b = registry.ingest(sourceRecord("AGENCY_B", "8820", "Maria Garcia", "1980-04-02")); var person = registry.match(a, b); // the wrong merge
registry.update(viaSource("AGENCY_A", "5531"), income("2,400")); registry.update(viaSource("AGENCY_B", "8820"), dependent("child, 2019")); registry.update(directlyOn(person, "caseworker-17"), address("9 Pine Rd")); var before = registry.updateCount(person);
var split = registry.split(person, a, b);
assertThat(registry.updatesFor(split.personOf(a))).extracting("field").containsExactly("income"); assertThat(registry.updatesFor(split.personOf(b))).extracting("field").containsExactly("dependent"); assertThat(split.needsReview()).extracting("field").containsExactly("address"); assertThat(registry.updateCount(split.personOf(a)) + registry.updateCount(split.personOf(b)) + split.needsReview().size()).isEqualTo(before);}def test_splitting_a_wrong_merge_returns_every_attributable_update(registry): a = registry.ingest(source_record("AGENCY_A", "5531", "Maria Garcia", "1980-04-02")) b = registry.ingest(source_record("AGENCY_B", "8820", "Maria Garcia", "1980-04-02")) person = registry.match(a, b) # the wrong merge
registry.update(via_source("AGENCY_A", "5531"), income="2,400") registry.update(via_source("AGENCY_B", "8820"), dependent="child, 2019") registry.update(directly_on(person, user="caseworker-17"), address="9 Pine Rd") before = registry.update_count(person)
split = registry.split(person, a, b)
assert [u.field for u in registry.updates_for(split.person_of(a))] == ["income"] assert [u.field for u in registry.updates_for(split.person_of(b))] == ["dependent"] assert [u.field for u in split.needs_review] == ["address"] assert (registry.update_count(split.person_of(a)) + registry.update_count(split.person_of(b)) + len(split.needs_review)) == beforeRelated pages
Section titled “Related pages”Written and edited by Abhinav Taduka, enterprise software architect.
New pages are added regularly. Follow Abhinav on LinkedIn to see them first.