Repository navigation
fix(longitudinal): reject reused Commons observation identities #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2fc3a36
test(longitudinal): reject reused Commons observation identity
seonghobae a2fe87d
fix(longitudinal): keep Commons observation IDs unique
seonghobae cf251b5
test(longitudinal): prove rejected identity reuse preserves original
seonghobae b9680ed
docs(longitudinal): explain record identity rejection plainly
seonghobae d759ece
merge(main): reconcile longitudinal identity guard after publisher merge
seonghobae 64d88c7
style: format longitudinal identity regression
seonghobae 31df209
docs(longitudinal): trace observation identity invariant
seonghobae 8cd3ae2
merge(main): reconcile longitudinal identity guard after #258
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| //! Regression contract for unique Commons longitudinal observation identities. | ||
|
|
||
| use psychometrics_commons_runtime::longitudinal_observation::{ | ||
| LongitudinalObservationError, LongitudinalObservationInput, LongitudinalObservationSet, | ||
| MembershipShareInput, ObservationTimeInput, | ||
| }; | ||
|
|
||
| static MEMBERSHIPS: [MembershipShareInput<'static>; 1] = [MembershipShareInput { | ||
| membership_context_ref: "seoul_clinic_ward_a", | ||
| weight_parts_per_10_000: 10_000, | ||
| }]; | ||
|
|
||
| fn observation<'a>( | ||
| observation_record_ref: &'a str, | ||
| source_observation_ref: &'a str, | ||
| received_at_unix_ms: u64, | ||
| ingested_at_unix_ms: u64, | ||
| ) -> LongitudinalObservationInput<'a> { | ||
| LongitudinalObservationInput { | ||
| observation_record_ref, | ||
| enrollment_ref: "enrollment_seoul_clinic_2026q3", | ||
| source_system_ref: "gyeot_ema_android", | ||
| source_observation_ref, | ||
| construct_ref: "construct_anxious_mood", | ||
| measure_ref: "measure_anxious_mood_ema_v3", | ||
| membership_shares: &MEMBERSHIPS, | ||
| time: ObservationTimeInput { | ||
| validity_start_at_unix_ms: 1_776_297_000_000, | ||
| validity_end_at_unix_ms: 1_776_297_000_000, | ||
| recorded_at_unix_ms: received_at_unix_ms - 1_000, | ||
| received_at_unix_ms, | ||
| ingested_at_unix_ms, | ||
| timezone_name: "Asia/Seoul", | ||
| utc_offset_minutes: 540, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn distinct_source_observations_cannot_reuse_one_commons_record_identity() { | ||
| let mut observations = LongitudinalObservationSet::new(); | ||
| observations | ||
| .ingest(observation( | ||
| "observation_record_shared_identity", | ||
| "gyeot_obs_first", | ||
| 1_776_336_120_000, | ||
| 1_776_336_180_000, | ||
| )) | ||
| .expect("first source observation owns the Commons record identity"); | ||
|
|
||
| let conflict = observations | ||
| .ingest(observation( | ||
| "observation_record_shared_identity", | ||
| "gyeot_obs_second", | ||
| 1_776_336_240_000, | ||
| 1_776_336_300_000, | ||
| )) | ||
| .expect_err("a distinct source observation must not reuse the Commons record identity"); | ||
|
|
||
| assert_eq!( | ||
| conflict, | ||
| LongitudinalObservationError::ObservationIdentityConflict | ||
| ); | ||
| assert!(conflict | ||
| .to_string() | ||
| .contains("observation-record identity")); | ||
| assert_eq!(observations.len(), 1); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.