Files
entity/tests/profile_refresh_test.zi
T
waozi 7649b7b922 Build with Ziran 768495fc and Kryon 0dea8bc2
Pin the pushed Ziran 768495fc toolchain and Kryon 0dea8bc2, the same set
the apps that depend on Entity use, so they share one Kryon.

The runtime artifact and the web build no longer use a BOOTSTRAP=1 Ziran
runtime: with one-format ZX it has no instruction engine and cannot open
the profile's bundle. The canvas profile host imports
kryon/test_driver_frame in test builds, since Kryon's canvas host now
takes the test driver's input only when a host registers it.

The refresh test's identity constant is renamed: Ziran 768495fc emits a
module string constant as an unprefixed C macro that rewrote DaochiClient's
identity fields (reported to Ziran).
2026-11-16 03:13:15 -03:00

131 lines
5.6 KiB
Ziran

// A completed profile read must not undo a picture selected after it began.
#import "account_store"
#import "picture_publish"
#import "model"
#import "native_files"
#import "native_host"
#import "profile_appearance"
#import "entity_records"
#import "recovery"
#import "std/c_string"
#import "std/text_buffer"
#import "daochi_client/async_client"
Auth :: #import "daochi_client/auth";
account_identity :: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
CompletedRead :: (icon: s32) {
alias_active = true
alias_pending = .{}
alias_pending.done = true
alias_pending.result = cast(Auth.AuthResult)Auth.AuthResult.AUTH_OK
alias_session = .{}
alias_session.profile_icon_known = true
alias_session.profile_icon = cast(s64)icon
}
#program_export
main :: () -> s32 {
directory := NativeEnvironment("ENTITY_PROFILE_REFRESH_DATA")
if directory == "" || !NativeDirectory(directory) || !CopyCString(directory, account_root[:]) { return 1 }
account_profile = EntityDefault()
unused CopyCString(account_identity, account_recovery.keys.public_id[:])
unused CopyCString(account_identity, account_profile.owner_id[:])
account_profile.picture = 1
alias_owner = account_recovery.keys.public_id
unused CopyCString(TextUntilNul(account_profile.nodes[account_profile.preferred][:]), alias_node[:])
account_standalone_ready = true
old_icon := EntityPublicIcon(account_profile)
AccountStoreAliasReadStarted()
selected := account_profile
selected.picture = 7
selected.appearance_changed = 200
if !AccountStoreSaveProfile(selected) { return 2 }
// A second host with this identity reads the first host's choice and clock.
second := EntityDefault()
if !SharedProfileLoad(account_identity, *second) || second.picture != 7 || second.appearance_changed != 200 { return 8 }
second.picture = 9
second.appearance_changed = 300
if !SharedProfileSave(account_identity, second) { return 9 }
reopened := EntityDefault()
if !SharedProfileLoad(account_identity, *reopened) || reopened.picture != 9 || reopened.appearance_changed != 300 { return 10 }
// Its authenticated upload finished before the older read arrived.
picture_dirty = false
picture_publisher.active = false
CompletedRead(old_icon)
AccountStoreAliasPump()
if account_profile.picture != 7 { return 3 }
// A read begun while the new picture was still uploading is stale too,
// even if the upload finishes before its response reaches the app.
selected = account_profile
selected.picture = 8
if !AccountStoreSaveProfile(selected) { return 4 }
AccountStoreAliasReadStarted()
picture_dirty = false
picture_publisher.active = false
CompletedRead(old_icon)
AccountStoreAliasPump()
if account_profile.picture != 8 { return 5 }
// Legacy profiles still restore from the unversioned public icon.
account_profile.appearance_changed = 0
AccountStoreAliasReadStarted()
CompletedRead(old_icon)
AccountStoreAliasPump()
if account_profile.picture != 1 { return 6 }
account_recovery.keys.public_id[0] = #char "b"
account_profile.owner_id = account_recovery.keys.public_id
account_profile.picture = 7
account_standalone_ready = false
CompletedRead(old_icon)
AccountStoreAliasPump()
if account_profile.picture != 7 || alias_active { return 7 }
// Two independent host stores share the same account profile. The second
// host starts with an older cached record and then receives a newer one.
unused CopyCString(account_identity, account_recovery.keys.public_id[:])
account_profile = EntityDefault()
unused CopyCString(account_identity, account_profile.owner_id[:])
account_standalone_ready = true
chosen := account_profile
chosen.picture = 12
if !EntityHostSaveProfile(chosen) { return 12 }
second_root: [4096]u8
if !CopyCString(NativeJoin(second_root[:], directory, "second-host"), account_root[:]) || !NativeDirectory(TextUntilNul(account_root[:])) { return 13 }
records_owner = .{}
stale := EntityDefault()
stale.picture = 1
stale.appearance_changed = 1
put := ProfileAppearancePut(stale)
unused EntityRecordsAnswer(put)
EntityFree(put)
account_profile = EntityDefault()
unused CopyCString(account_identity, account_profile.owner_id[:])
loaded := EntityHostReadProfile()
if loaded.picture != 12 || loaded.appearance_changed <= 1 { return 14 }
alias_owner = account_recovery.keys.public_id
unused CopyCString(TextUntilNul(account_profile.nodes[account_profile.preferred][:]), alias_node[:])
picture_dirty = false
picture_publisher.active = false
AccountStoreAliasReadStarted()
CompletedRead(old_icon)
AccountStoreAliasPump()
if account_profile.picture != 12 { return 18 }
// Reopening this host must keep the shared selection despite its older record.
records_owner = .{}
account_profile = EntityDefault()
unused CopyCString(account_identity, account_profile.owner_id[:])
loaded = EntityHostReadProfile()
if loaded.picture != 12 { return 15 }
remote := loaded
remote.picture = 15
remote.appearance_changed = loaded.appearance_changed + 1
put = ProfileAppearancePut(remote)
unused EntityRecordsAnswer(put)
EntityFree(put)
loaded = EntityHostReadProfile()
if loaded.picture != 15 || loaded.appearance_changed != remote.appearance_changed { return 16 }
reopened_remote := EntityDefault()
if !SharedProfileLoad(account_identity, *reopened_remote) || reopened_remote.picture != 15 { return 17 }
print("Profile picture local tests: stale reads, pending uploads, fresh restore and owner change passed.\n")
return 0
}