Skip to content

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.
@Test
void 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");
});
}
@Test
void 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");
}
  • 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.
@Test
void 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");
}

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.
@Test
void 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"));
}
@Test
void 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);
}
@Test
void 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();
}
  • 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.
@Test
void 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);
}

Written and edited by Abhinav Taduka, enterprise software architect.