Text chat 20: devserver textchat scenario (#270) #305

Manually merged
charles merged 5 commits from textchat-20-devserver-textchat into textchat 2026-11-12 17:38:36 +00:00
Owner

Stacked on: origin/textchat-2-proto-chat-requests-events, origin/textchat-3-proto-expressions-threads-prefs

What this builds

The textchat scenario of fluxer-devserver (Text chat spec §12, plan Task 20):

  • Fixtures: fixtures/gateway/textchat_ready.json (guild with a still and an animated custom emoji, two stickers, the threads key with two threads (one archived), a read-only #announcements, the DM with ada and the group DM "Weekend plans", friends, a pending request and a block) and fixtures/textchat/history.json (1-10 image mosaics, alt text, spoiler, video, audio, files, an expired attachment, every embed type plus link, both stickers, a forward, a reply and a reply to a deleted message, pin/join/thread-created system messages, reactions, a thread starter, DM and group DM history). Everything is copied from the server-shaped Text chat 1-3 fixtures; the commit message cites the server files and lines.
  • REST for every endpoint of Text chat 5 and 6 with the server's validation, and the events the server sends: JSON and multipart sends (payload_json + files[n]), the presigned flow (PUT to a local URL that refuses an Authorization header, multipart parts, complete; presigned = true also flips the discovery feature), edit/delete, reactions (MESSAGE_REACTION_ADD; a scripted MESSAGE_REACTION_ADD_MANY via ChatScript::trigger("reaction-burst"), also timed at 5 s), pins (CHANNEL_PINS_UPDATE, type 6 system message, MESSAGE_UPDATE, in the server's order), search ({indexing: true} HTTP 200 on the first search of a scope, then substring results), bookmarks, mentions, group DMs and recipients (+ system messages), relationships, settings (USER_SETTINGS_UPDATE), saved media, guild emoji/stickers, GIFs from fixtures, threads, refresh-urls, and an unfurl MESSAGE_UPDATE (whole message) 1 s after a sent link. Errors use the fork's codes (CANNOT_SEND_EMPTY_MESSAGE, INVALID_FORM_BODY + errors[].code, FILE_SIZE_TOO_LARGE, MISSING_PERMISSIONS, MAX_REACTIONS, CANNOT_MODIFY_SYSTEM_WEBHOOK, NOT_FRIENDS_WITH_USER, FEATURE_TEMPORARILY_DISABLED, ...). Message events carry guild_id and member without user.
  • Media: /emoji/{cp}.svg and /media/emoji/{cp}.svg (drawn SVG), /media/emojis/{id}.webp and /media/stickers/{id}.webp (animated only when the expression is and animated=true), /media/attachments/{c}/{a}/{name} (uploaded bytes, else a picture of the attachment's aspect ratio encoded as its extension, a WAV tone for audio, filler for other types), /media/external/....
  • extends = "<scenario>" in scenario files; textchat_presigned.toml is textchat with presigned = true.

How it was tested

  • crates/fluxer-devserver/tests/textchat.rs (written first, seen failing, then passing): multipart_send_stores_attachments_and_echoes, presigned_flow_put_complete_send, presign_is_refused_when_the_instance_does_not_offer_it, attachment_limits_enforced, reaction_put_emits_event_and_add_many_script, pin_emits_three_events, search_indexing_then_results, unfurl_update_after_link, group_dm_recipient_events, twemoji_svg_served, scenario_fixtures_parse_with_proto_types, plus edit_delete_save_and_thread_endpoints and replies_forwards_stickers_and_saved_media. Every REST answer and gateway event is read through the fluxer-proto types.
  • Unit tests for the multipart parser, part sizes, the bucket, mention/link parsing, limits and host rewriting.
  • FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci green locally (Linux). Smoke-ran fluxer-devserver --scenario textchat_presigned. No desktop-only tests in this task.

Deviations from the plan

  • Files outside the list: fixtures/textchat/history.json (the showcase history; fixtures/rest is reserved for model round-trip fixtures), fixtures/scenarios/textchat_presigned.toml, src/voice.rs (the guild permission computation is now Voice::guild_permissions, shared by the chat checks; STREAM logic unchanged), Cargo.toml dev-dependency reqwest (already a workspace dependency; no new crate). The chat HTTP handlers are a chat_routes module inside http.rs.
  • Tests drive REST with plain reqwest, as fluxer-api does not have the Text chat 5/6 calls on this base yet.
  • The stacked merge of Text chat 2 and 3 needed real conflict resolution in fluxer-proto (dispatch name lists and counts 62/24, models/mod.rs, settings.rs accessors of both, README, models_roundtrip.rs lists); cargo xtask ci was green on that base before any code of this task.
  • Not modelled: chat rate limits, slowmode, guild channel settings, archived thread lists; there is no real video.

Closes #270

🤖 Generated with Claude Code

Stacked on: origin/textchat-2-proto-chat-requests-events, origin/textchat-3-proto-expressions-threads-prefs ## What this builds The `textchat` scenario of `fluxer-devserver` (Text chat spec §12, plan Task 20): - **Fixtures**: `fixtures/gateway/textchat_ready.json` (guild with a still and an animated custom emoji, two stickers, the `threads` key with two threads (one archived), a read-only #announcements, the DM with ada and the group DM "Weekend plans", friends, a pending request and a block) and `fixtures/textchat/history.json` (1-10 image mosaics, alt text, spoiler, video, audio, files, an expired attachment, every embed type plus link, both stickers, a forward, a reply and a reply to a deleted message, pin/join/thread-created system messages, reactions, a thread starter, DM and group DM history). Everything is copied from the server-shaped Text chat 1-3 fixtures; the commit message cites the server files and lines. - **REST** for every endpoint of Text chat 5 and 6 with the server's validation, and the events the server sends: JSON and multipart sends (`payload_json` + `files[n]`), the presigned flow (`PUT` to a local URL that refuses an `Authorization` header, multipart parts, complete; `presigned = true` also flips the discovery feature), edit/delete, reactions (`MESSAGE_REACTION_ADD`; a scripted `MESSAGE_REACTION_ADD_MANY` via `ChatScript::trigger("reaction-burst")`, also timed at 5 s), pins (`CHANNEL_PINS_UPDATE`, type 6 system message, `MESSAGE_UPDATE`, in the server's order), search (`{indexing: true}` HTTP 200 on the first search of a scope, then substring results), bookmarks, mentions, group DMs and recipients (+ system messages), relationships, settings (`USER_SETTINGS_UPDATE`), saved media, guild emoji/stickers, GIFs from fixtures, threads, refresh-urls, and an unfurl `MESSAGE_UPDATE` (whole message) 1 s after a sent link. Errors use the fork's codes (`CANNOT_SEND_EMPTY_MESSAGE`, `INVALID_FORM_BODY` + `errors[].code`, `FILE_SIZE_TOO_LARGE`, `MISSING_PERMISSIONS`, `MAX_REACTIONS`, `CANNOT_MODIFY_SYSTEM_WEBHOOK`, `NOT_FRIENDS_WITH_USER`, `FEATURE_TEMPORARILY_DISABLED`, ...). Message events carry `guild_id` and `member` without `user`. - **Media**: `/emoji/{cp}.svg` and `/media/emoji/{cp}.svg` (drawn SVG), `/media/emojis/{id}.webp` and `/media/stickers/{id}.webp` (animated only when the expression is and `animated=true`), `/media/attachments/{c}/{a}/{name}` (uploaded bytes, else a picture of the attachment's aspect ratio encoded as its extension, a WAV tone for audio, filler for other types), `/media/external/...`. - `extends = "<scenario>"` in scenario files; `textchat_presigned.toml` is `textchat` with `presigned = true`. ## How it was tested - `crates/fluxer-devserver/tests/textchat.rs` (written first, seen failing, then passing): `multipart_send_stores_attachments_and_echoes`, `presigned_flow_put_complete_send`, `presign_is_refused_when_the_instance_does_not_offer_it`, `attachment_limits_enforced`, `reaction_put_emits_event_and_add_many_script`, `pin_emits_three_events`, `search_indexing_then_results`, `unfurl_update_after_link`, `group_dm_recipient_events`, `twemoji_svg_served`, `scenario_fixtures_parse_with_proto_types`, plus `edit_delete_save_and_thread_endpoints` and `replies_forwards_stickers_and_saved_media`. Every REST answer and gateway event is read through the `fluxer-proto` types. - Unit tests for the multipart parser, part sizes, the bucket, mention/link parsing, limits and host rewriting. - `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` green locally (Linux). Smoke-ran `fluxer-devserver --scenario textchat_presigned`. No desktop-only tests in this task. ## Deviations from the plan - Files outside the list: `fixtures/textchat/history.json` (the showcase history; `fixtures/rest` is reserved for model round-trip fixtures), `fixtures/scenarios/textchat_presigned.toml`, `src/voice.rs` (the guild permission computation is now `Voice::guild_permissions`, shared by the chat checks; STREAM logic unchanged), `Cargo.toml` dev-dependency `reqwest` (already a workspace dependency; no new crate). The chat HTTP handlers are a `chat_routes` module inside `http.rs`. - Tests drive REST with plain `reqwest`, as `fluxer-api` does not have the Text chat 5/6 calls on this base yet. - The stacked merge of Text chat 2 and 3 needed real conflict resolution in `fluxer-proto` (dispatch name lists and counts 62/24, `models/mod.rs`, `settings.rs` accessors of both, README, `models_roundtrip.rs` lists); `cargo xtask ci` was green on that base before any code of this task. - Not modelled: chat rate limits, slowmode, guild channel settings, archived thread lists; there is no real video. Closes #270 🤖 Generated with [Claude Code](https://claude.com/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>
Typed guild emoji and stickers (REST, READY/GUILD_CREATE, GUILD_EMOJIS_UPDATE,
GUILD_STICKERS_UPDATE), thread channels, members and dispatches with the READY
`threads` key presence kept, thread-create requests, GIFs and the well-known gif
config, saved media and FAVORITE_MEME_*, and `prefs::SyncedPreferences`: a
field-preserving protobuf codec for user_settings.synced_preferences that rewrites
only changed top-level fields and keeps unknown fields byte for byte.

The unknown-dispatch example in fluxer-gateway's tests and fixtures/gateway/
unknown_event.json moves from FAVORITE_MEME_CREATE (now typed) to WEBHOOKS_UPDATE,
shaped from fluxer_api/src/api/webhook/WebhookService.ts:642-647 plus the guild_id
the gateway adds (guild_dispatch.erl:91).

Refs #253

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
# Conflicts:
#	crates/fluxer-proto/README.md
#	crates/fluxer-proto/src/gateway/events.rs
#	crates/fluxer-proto/src/gateway/ready.rs
#	crates/fluxer-proto/src/models/channel.rs
#	crates/fluxer-proto/src/models/mod.rs
#	crates/fluxer-proto/src/models/settings.rs
#	crates/fluxer-proto/tests/models_roundtrip.rs
READY and channel history of the `textchat` scenario, built from the
server-shaped fixtures of Text chat 1-3 (only ids, channels, authors and
hosts change):

- gateway/textchat_ready.json: fixtures/gateway/ready.json with the guild's
  emojis/stickers (rest/guild_emojis.json, rest/guild_stickers.json without
  the uploader), the `threads` key the gateway adds per guild
  (fluxer_gateway/src/guild/guild_data.erl:127) holding two
  ThreadChannelResponse objects (rest/thread_created.json;
  packages/schema/src/domains/channel/ThreadSchemas.ts:62), a group DM
  (rest/group_dm.json; ChannelSchemas.ts:51-105, `nicks`), and READY
  relationships with the user's id only (RelationshipResponse,
  packages/schema/src/domains/user/UserResponseSchemas.ts:492).
- textchat/history.json: MessageResponseSchema messages
  (packages/schema/src/domains/message/MessageResponseSchemas.ts:122-172;
  attachments :23-47, references :51, snapshots :90) copied from
  rest/message_{attachments,embeds,sticker,forward,reply,system_pin,
  reactions,thread}.json and gateway/message_update_unfurl.json.
- scenarios/textchat.toml, textchat_presigned.toml (extends textchat).

Refs #270

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The devserver serves text chat (Text chat spec §12): sending as JSON or
multipart (payload_json + files[n]) and the presigned upload flow (PUT to
a local URL without a token, parts, complete; switched by `presigned`,
which also sets the discovery feature), edits and deletes, reactions
(MESSAGE_REACTION_ADD, scripted MESSAGE_REACTION_ADD_MANY), pins
(CHANNEL_PINS_UPDATE + system message + MESSAGE_UPDATE), search
({indexing: true} on the first search of a scope, then substring
results), bookmarks, mentions, group DMs and recipients, relationships,
settings, saved media, guild emoji/stickers, GIFs, threads, and an unfurl
MESSAGE_UPDATE after a sent link; each with the server's validation
(limits, permissions, empty message, 30 reactions, pin types). Media:
Twemoji SVGs, custom emoji and sticker WebPs, attachments (uploaded bytes
or drawn by size and type) and proxied embed media.

Refs #270

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Author
Owner

Independent review: Text chat 20 (devserver textchat)

Scope: cb35156..f3f9e90 (commits 8609ab3 and f3f9e90). I also checked the stacked merge cb35156, as the implementer asked.

Plan tests (1). All ten tests the plan names are in tests/textchat.rs, along with 3 extra ones, and they assert the spec's values: 10 files max (FILE_INDEX_EXCEEDS_MAXIMUM); 25 MiB + 1 refused on both upload paths; empty message (CANNOT_SEND_EMPTY_MESSAGE); 2001 UTF-16 units (CONTENT_EXCEEDS_MAX_LENGTH); 30 distinct reactions (MAX_REACTIONS); a pin of a system message refused (CANNOT_MODIFY_SYSTEM_WEBHOOK, i.e. CannotEditSystemMessageError); the pin events in the order CHANNEL_PINS_UPDATE → type-6 MESSAGE_CREATE → MESSAGE_UPDATE pinned:true (matches MessagePinService.ts:144-146); {indexing:true} with HTTP 200 on the first search, then substring results; the unfurl arriving 900 ms or more later as a full MESSAGE_UPDATE with a link embed; a presigned PUT with auth refused; a multipart send refused before complete; presign answering 403 FEATURE_TEMPORARILY_DISABLED when the flag is off (matches AttachmentUploadService.ts:188); Twemoji SVG plus emoji/sticker WebPs (animated and still), attachments and external/ all served.

Interfaces (2). The scenario textchat (and textchat_presigned, presigned = true, which also flips the discovery feature) contains everything the plan lists: emoji (still and animated), 2 stickers, the threads key with 2 threads, 1–10 image mosaics, video, audio, file, spoiler, alt text, an expired attachment, every embed type, a sticker, a forward, a reply and a reply to a deleted message, pin, join and thread system messages, the scripted MESSAGE_REACTION_ADD_MANY, pins, a group DM, relationships, saved messages, memes and GIFs. The media paths match the spec.

Invariants (3). Only fluxer-devserver (plus fixtures) changed. No new non-dev dependency; reqwest is a dev-dependency that was already in the workspace. Fixtures contain no tokens, signed URLs or local paths; fluxer.forked.io hosts are rewritten to the devserver. The new code adds no logging of upload URLs; the only new log line is a warn on a failed scripted step. The ADD_MANY shape {channel_id, message_id, guild_id?, reactions:[{user_id, emoji, member?}]} and sending a lone entry as MESSAGE_REACTION_ADD both match session_dispatch_voice.erl:150-195. Guild message events carry member without user. The fixture commit names its server sources.

Review Focus #4. Multipart parsing (payload_json, files[n]/legacy file, id mapping) follows MessageRequestParser.ts. Presigned: singlepart up to 10 MiB, multipart part size from resolveAttachmentUploadPartSize, PUT without auth, completion required. Correct.

Stacked merge cb35156. Every line either parent added to the 7 conflicted files is in the result, apart from the expected count, import-list and doc-comment rewrites. The totals are consistent: 62 typed + 24 untyped = 86, as in each parent (51+35, 47+39). I found no lost hunks.

CI (5). cargo xtask ci in a fresh review worktree: green (EXIT 0; tests/textchat.rs 13/13 pass).

Findings

  • minor search.rs: "indexed" is tracked per sorted channel set rather than per channel, so a search over [A,B] after one over [A] answers {indexing:true} again. The scope-less search also covers channels the user cannot view (e.g. no VIEW_CHANNEL). Harmless for the client tests, but it differs a little from the spec's "first search per channel".
  • minor voice.rs: Voice::guild_permissions takes the voice lock while chat holds the World lock (World → Voice). This is safe today because no voice path takes the World lock. A comment on the lock order would keep it that way.

No blocking findings.

Verdict: APPROVE (0 blocking, 2 minor; local CI green; the remote runners are left to the integrator).

## Independent review: Text chat 20 (devserver textchat) Scope: `cb35156..f3f9e90` (commits 8609ab3 and f3f9e90). I also checked the stacked merge cb35156, as the implementer asked. **Plan tests (1).** All ten tests the plan names are in `tests/textchat.rs`, along with 3 extra ones, and they assert the spec's values: 10 files max (`FILE_INDEX_EXCEEDS_MAXIMUM`); 25 MiB + 1 refused on both upload paths; empty message (`CANNOT_SEND_EMPTY_MESSAGE`); 2001 UTF-16 units (`CONTENT_EXCEEDS_MAX_LENGTH`); 30 distinct reactions (`MAX_REACTIONS`); a pin of a system message refused (`CANNOT_MODIFY_SYSTEM_WEBHOOK`, i.e. `CannotEditSystemMessageError`); the pin events in the order CHANNEL_PINS_UPDATE → type-6 MESSAGE_CREATE → MESSAGE_UPDATE `pinned:true` (matches `MessagePinService.ts:144-146`); `{indexing:true}` with HTTP 200 on the first search, then substring results; the unfurl arriving 900 ms or more later as a full MESSAGE_UPDATE with a link embed; a presigned PUT with auth refused; a multipart send refused before `complete`; presign answering 403 `FEATURE_TEMPORARILY_DISABLED` when the flag is off (matches `AttachmentUploadService.ts:188`); Twemoji SVG plus emoji/sticker WebPs (animated and still), attachments and `external/` all served. **Interfaces (2).** The scenario `textchat` (and `textchat_presigned`, `presigned = true`, which also flips the discovery feature) contains everything the plan lists: emoji (still and animated), 2 stickers, the `threads` key with 2 threads, 1–10 image mosaics, video, audio, file, spoiler, alt text, an expired attachment, every embed type, a sticker, a forward, a reply and a reply to a deleted message, pin, join and thread system messages, the scripted `MESSAGE_REACTION_ADD_MANY`, pins, a group DM, relationships, saved messages, memes and GIFs. The media paths match the spec. **Invariants (3).** Only `fluxer-devserver` (plus fixtures) changed. No new non-dev dependency; `reqwest` is a dev-dependency that was already in the workspace. Fixtures contain no tokens, signed URLs or local paths; `fluxer.forked.io` hosts are rewritten to the devserver. The new code adds no logging of upload URLs; the only new log line is a warn on a failed scripted step. The ADD_MANY shape `{channel_id, message_id, guild_id?, reactions:[{user_id, emoji, member?}]}` and sending a lone entry as MESSAGE_REACTION_ADD both match `session_dispatch_voice.erl:150-195`. Guild message events carry `member` without `user`. The fixture commit names its server sources. **Review Focus #4.** Multipart parsing (`payload_json`, `files[n]`/legacy `file`, id mapping) follows `MessageRequestParser.ts`. Presigned: singlepart up to 10 MiB, multipart part size from `resolveAttachmentUploadPartSize`, PUT without auth, completion required. Correct. **Stacked merge cb35156.** Every line either parent added to the 7 conflicted files is in the result, apart from the expected count, import-list and doc-comment rewrites. The totals are consistent: 62 typed + 24 untyped = 86, as in each parent (51+35, 47+39). I found no lost hunks. **CI (5).** `cargo xtask ci` in a fresh review worktree: **green** (EXIT 0; `tests/textchat.rs` 13/13 pass). ### Findings - **minor** `search.rs`: "indexed" is tracked per sorted channel set rather than per channel, so a search over `[A,B]` after one over `[A]` answers `{indexing:true}` again. The scope-less search also covers channels the user cannot view (e.g. no VIEW_CHANNEL). Harmless for the client tests, but it differs a little from the spec's "first search per channel". - **minor** `voice.rs`: `Voice::guild_permissions` takes the voice lock while chat holds the World lock (World → Voice). This is safe today because no voice path takes the World lock. A comment on the lock order would keep it that way. No blocking findings. **Verdict: APPROVE** (0 blocking, 2 minor; local CI green; the remote runners are left to the integrator).
# Conflicts:
#	crates/fluxer-proto/README.md
#	crates/fluxer-proto/src/gateway/events.rs
#	crates/fluxer-proto/src/models/channel.rs
#	crates/fluxer-proto/src/models/mod.rs
#	crates/fluxer-proto/src/models/settings.rs
#	crates/fluxer-proto/tests/models_roundtrip.rs
charles manually merged commit 438468375f into textchat 2026-11-12 17:38:36 +00:00
Sign in to join this conversation.
No description provided.