修复日登录埋点构造器缺失
Project CI / Repository checks (pull_request) Has been cancelled
Project CI / Frontend tests (pull_request) Has been cancelled
Project CI / Backend tests (pull_request) Has been cancelled
Project CI / Native shell tests (pull_request) Has been cancelled

恢复 TrackingEventDraft::user 用户态构造器

补充用户 scope 与主体字段的回归测试
This commit is contained in:
2026-09-02 10:41:21 +00:00
parent c5170669ef
commit 0a06b49880
@@ -61,6 +61,16 @@ impl TrackingEventDraft {
client_marker: None,
}
}
pub fn user(event_key: &'static str, module_key: &'static str, user_id: &str) -> Self {
let normalized_user_id = user_id.trim().to_string();
let mut draft = Self::new(event_key, module_key);
draft.scope_kind = RuntimeTrackingScopeKind::User;
draft.scope_id = normalized_user_id.clone();
draft.user_id = Some(normalized_user_id.clone());
draft.owner_user_id = Some(normalized_user_id);
draft
}
}
#[derive(Clone, Debug)]
@@ -1271,6 +1281,21 @@ mod tests {
assert_eq!(resolve_tracking_scope_id(&spec, &identity), "user-225");
}
#[test]
fn user_tracking_draft_sets_user_scope_and_subject_fields() {
let draft = TrackingEventDraft::user("daily_login", "profile", " user-225 ");
assert_eq!(
draft.scope_kind,
module_runtime::RuntimeTrackingScopeKind::User
);
assert_eq!(draft.scope_id, "user-225");
assert_eq!(draft.user_id.as_deref(), Some("user-225"));
assert_eq!(draft.owner_user_id.as_deref(), Some("user-225"));
assert_eq!(draft.module_key, Some("profile"));
assert_eq!(draft.event_key, "daily_login");
}
#[test]
fn tracking_identity_uses_external_api_owner_and_does_not_forge_user() {
let authenticated = build_test_authenticated("login-user");