Text chat 3: fluxer-proto expressions, threads and synced preferences (#253) #297
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "textchat-3-proto-expressions-threads-prefs"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Stacked on: textchat-1-proto-message-content
What this builds
fluxer-protogains the expression, thread and synced-preferences protocol of Text chat 3 (spec §3.1 "Threads", "Expressions", "GIFs", "Saved media", "Synced preferences"; §5prefs):models::expressions):GuildEmoji { id, name, animated },GuildSticker { id, name, description, tags, animated }.Guild.emojisis typed (wasVec<Value>),Guild.stickersis new,GuildReadyData.{emojis, stickers}are new; all lenient.GatewayEvent::{GuildEmojisUpdate, GuildStickersUpdate}.models::thread): thread fields onChannel(thread_metadata,message_count,total_message_sent,member_count, ownmember;owner_idexisted),ThreadMember,ThreadMuteConfig,ThreadListSync,ThreadMembersUpdate, requestsThreadCreateFromMessageandThreadCreate.GuildReadyData.threads: Option<Vec<Channel>>keeps the key's presence (absent = threads off; present,nullincluded, = on, asThreadGuilds.ts:63).GatewayEvent::{ThreadCreate, ThreadUpdate, ThreadDelete, ThreadListSync, ThreadMemberUpdate, ThreadMembersUpdate}.MessageThread.memberis now typed (Text chat 1 left it inIGNORED_FIELDSfor this task).models::gif):Gif,GifMedia,GifFeatured,GifCategory;WellKnown.gif: Option<GifConfig>.models::meme):FavoriteMeme(every field ofFavoriteMemeResponse),GatewayEvent::{FavoriteMemeCreate, FavoriteMemeUpdate, FavoriteMemeDelete}.prefs::{mod, wire, pickers}):SyncedPreferences::decode(&str) -> Result<Self, PrefsError>/encode(&self) -> Stringwithemoji_picker,sticker_picker,memes_picker,skin_tone,favorite_gifs,soundboard_favorites(#92) andsanitize_urls, field numbers frompreferences.proto/pickers.proto. The value keeps the decoded bytes;encodere-emits every top-level field whose value did not change byte for byte and in place, and rewrites only the changed ones (the same field-level merge the original does inSyncedPreferencesEngine.ts). Every parsed sub-message also keeps its unknown sub-fields. Hand-written protobuf (varint/LEN/I32/I64 only): no new crate.UserSettings::{synced_prefs(), sanitize_urls()}.TYPED_DISPATCH_NAMESgrows by 11 (47),UNTYPED_IN_FOUNDATIONshrinks to 39.How it was tested
tests/prefs.rs: decode reads every picker field of the golden snapshot;encode(decode(x)) == x; changing frecency rewrites field 20 only (every other top-level chunk identical, same order), and the unknown sub-field insideemoji_pickersurvives; each owned field changed alone touches only its field; unknown top-level fields 999 (from the fork's encoder) and 1000 (appended) survive a rewrite;""is the default and encodes to""; URL-safe unpadded input is accepted; malformed input isPrefsError; proptests over random bytes, random text and the fixture with a corrupted byte (no panic, and whatever decodes round-trips).fixtures/prefs/synced_preferences.b64was produced by running the fork's generated schema with its installed@bufbuild/protobuf2.16.0 under Node 22, read-only, output written outside the fork;fixtures/prefs/README.mdhas the script and steps. It sets every top-level field ofpreferences.protoand two unknown fields.tests/expressions.rs,tests/threads.rs: every new gateway fixture parses into its variant; old guild/READY fixtures still parse; READYthreadsabsent vs present vsnull; GIF featured/search, well-knowngif, memes; lenient entries.tests/models_roundtrip.rs: the six new REST fixtures round-trip strictly and tolerate unknown fields.FLUXER_SCREENSHOT_TESTS=1 cargo xtask cigreen locally (Linux).Fixtures are shaped from the server source; the fixture commit (
8be8a3d) names file and line for each.Deviations from the plan
ThreadCreate/ThreadUpdate/ThreadListSync/ThreadMemberUpdate/ThreadMembersUpdate/FavoriteMeme*variants hold aBox<…>(asChannelCreate(Box<Channel>)already does) to keepGatewayEventsmall; matchingGatewayEvent::ThreadCreate(channel)works the same.ThreadDelete.parent_idisOption<Snowflake>(lenient); the server always sends it.Channel.{total_message_sent, member},ThreadMember,ThreadMuteConfig,ThreadListSync.channel_ids,UserSettings::{synced_prefs, sanitize_urls}(spec §5 listssanitize_urlsas aUserSettingsaccessor; Text chat 2 ownssynced_preferences() -> Option<&str>, so the decoded accessor is namedsynced_prefsto avoid a clash),SyncedPreferences::{from_bytes, to_bytes},prefs::wire::fields(public so Text chat 14 can compare snapshots field by field),prefs::UnknownFields(anunknownfield on each picker message: construct with..Default::default()).models/instance.rs(WellKnown.gif, named by the Interfaces block),models/message.rs(MessageThread.member),lenient.rs(present_lenient_vec,lenient_map),Cargo.toml(base64.workspace = true: already a workspace dependency used by fluxer-api and fluxer-platform, so nothing new enters the graph orcargo deny),crates/fluxer-core/src/guilds.rs(one line:stickers: Vec::new()in aGuildliteral),crates/fluxer-gateway/tests/{machine,connection}.rsandfixtures/gateway/unknown_event.json(they usedFAVORITE_MEME_CREATEas the example of an untyped dispatch; it is typed now, so the example isWEBHOOKS_UPDATE, shaped fromWebhookService.ts:642-647plus the gateway'sguild_id).fixtures/gateway/thread_member_update.json(THREAD_MEMBER_UPDATE is a new typed event; the plan's list omits it).For the reviewer
prefs/mod.rsto_bytesis the clobber guard;tests/prefs.rsprefs_changing_*are the proof.synced_preferences_base_hashonPATCH /users/@me/settings(409 on mismatch,UserAccountSettingsService.ts:272-279); not modelled here, worth knowing for Text chat 2/14.Closes #253
🤖 Generated with Claude Code
Failing tests for Text chat 3 (expressions.rs, threads.rs, prefs.rs) and the fixtures they read, each shaped from the fork at ba98441b4: - gateway/guild_emojis_update.json, guild_stickers_update.json: fluxer_api/src/api/guild/services/content/EmojiService.ts:301-307 and StickerService.ts:342-348 ({emojis}/{stickers} via mapGuildEmojiToResponse / mapGuildStickerToResponse, guild/GuildModel.ts:98-118), guild_id added by fluxer_gateway/src/guild/guild_dispatch.erl:91. - gateway/thread_create.json, thread_update.json, thread_delete.json, thread_members_update.json, thread_member_update.json: fluxer_api/src/api/channel/services/thread/ThreadDispatch.ts:26-93 (thread object from ThreadMappers.ts:42-92); the internal _fluxer_* keys are stripped by guild_dispatch.erl:131-136 / guild_thread_payload.erl:139-146. - gateway/thread_list_sync.json: fluxer_gateway/src/guild/guild_thread_view.erl:100-123. - gateway/favorite_meme_create.json, favorite_meme_delete.json: fluxer_api/src/api/favorite_meme/FavoriteMemeService.ts:213-218, 454-458 and FavoriteMemeModel.ts:9-32. - gateway/user_settings_update_prefs.json: fluxer_api/src/api/user/services/UserAccountUpdatePropagator.ts:17-23, user/UserMappers.ts:296-375. - rest/guild_emojis.json, guild_stickers.json: GuildEmojiController.ts:111-133 (GuildEmojiWithUserResponse, packages/schema/src/domains/guild/GuildEmojiSchemas.ts:9-39). - rest/gifs_featured.json, gifs_search.json: packages/schema/src/domains/gif/GifSchemas.ts:36-88, fluxer_gifs/src/types.rs:70-100 (placeholder left out when absent). - rest/memes.json: FavoriteMemeModel.ts:9-32 (nullable fields written as null). - rest/thread_created.json: ThreadController.ts:134-169 (201 ThreadChannelResponse), ThreadMappers.ts:19-41 (own member: muted, mute_config null), 58-92. - prefs/synced_preferences.b64: encoded by the fork's own protobuf-es encoder (packages/schema/src/gen/fluxer/user/preferences/v1/*_pb.ts, packages/schema/src/domains/user/SyncedPreferencesCodec.ts), run read-only; how is in fixtures/prefs/README.md. Refs #253 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>Independent review: Text chat 3 (diff 6e2d2389..776fc2e)
Tests named in the plan: all 12 are there. The prefs tests assert against the fork-encoded golden fixture: the exact picker values, the byte-identical round trip, and that changing a field rewrites only that field (checked for each of 20–26 and 82). Unknown top-level fields 999 and 1000 and unknown field 9 inside
emoji_pickersurvive. Defaults are left out. There is a proptest over random bytes and over the fixture with one byte flipped.Interfaces: every name in the Task 3 Interfaces block exists. Field numbers match
preferences.protoandpickers.protoat ba98441b4.Invariants: fluxer-core changed by one line only (
stickers: Vec::new()). No new crate:base64was already a workspace dependency. Each fixture's shape matches the server file and line its commit names (ThreadDispatch.ts, ThreadSchemas.ts, FavoriteMemeModel.ts and FavoriteMemeService.ts checked by hand). Fixtures contain no real secrets or signed URLs (*.example.invalid,ex=0&is=0&hm=0). Bad input returnsErrand never panics. Bad list entries are dropped one at a time.Review Focus 3: met.
to_bytescompares each owned field's re-encoding before and after. Unchanged fields are copied fromrawas they were. A changed field is written where it first appeared, and repeated occurrences of it are merged. Unknown fields at every depth are kept.Local gate:
FLUXER_SCREENSHOT_TESTS=1 cargo xtask ciis green in the review worktree (exit 0, first run).Findings
ThreadCreate,ThreadUpdate,ThreadListSync,ThreadMember(s)UpdateandFavoriteMeme*areBox<..>, but the Interfaces block shows them unboxed. Consumers (Text chat 10, 14, 18) must deref them. This is not a break, but those tasks should know about it.UserSettings::synced_prefs()returns the empty snapshot whensynced_preferencesis present but not a string. A writer in Text chat 14 could then PATCH a fresh snapshot over the stored one. The server only ever sends a string ornull, so this is low risk. Text chat 14 should still sendsynced_preferences_base_hash(409 on mismatch) as the implementer noted.FAVORITE_MEME_UPDATEhas no fixture of its own. The test reuses the create payload, which is the same object on the server (FavoriteMemeService.ts:434-439).Verdict: approve. No blocking findings, and local CI is green.