diff --git a/docs/session-seam.md b/docs/session-seam.md index 40b2668..7cd1764 100644 --- a/docs/session-seam.md +++ b/docs/session-seam.md @@ -1,8 +1,9 @@ # The session seam: the engine on `voelin_proto::link::Session` -Status: design (2026-10-20); slice 1 is implemented (section 13 says how it -differs from this text, sections 14 and 15 what the reviews changed); -section 10 has the slices. +Status: design (2026-10-20); slices 1 and 2 are implemented (section 13 says +how slice 1 differs from this text, sections 14 and 15 what its reviews +changed, section 16 what slice 2 built, found and corrected); section 10 has +the slices. Design for the first half of plan step 7 (Phase 4): the engine consumes `voelin_proto::link::Session`, `ServerLink` becomes an adapter over it, and @@ -705,6 +706,11 @@ half of `commands_reach_the_link`, `a_replaced_connection_is_ignored`) remain in `tests/link_fake.rs` in slice 2 and move into the crate in slice 3, when `ServerLink` is no longer public. +This table and the list above it are the design; section 16.4 lists where the +running code differs (the CHAT re-subscription is a full sync, not a delta; a +reconnect resumes nothing; the conformance run and the live TeamSpeak tests are +in-crate tests, not files of `tests/`). + ### 9.3 The conformance suite against the TeamSpeak `Session` `conformance::run_case` with a harness that opens a `LinkSession` @@ -742,6 +748,12 @@ one session's slot reaching the other's `MediaSink` (sequence, marker, end); a channel file written with `write_file` and read back from an offset with `read_file`. +The table above is the prediction. Section 16.2 has the verdicts the run +gave, on both servers, and what the run found on the way: the first version +of the harness ended its sessions by itself (16.5, F2), which made +`close_ends_the_session` pass for the wrong reason, and the reasons of the +cases that do not apply are what those cases did when they were run. + ## 10. Slices Every slice: `cargo fmt --all --check`; `cargo clippy $(scripts/own-crates.sh) @@ -806,6 +818,8 @@ against this record, not against an assumption. ### Slice 2: tests on FakeSession and FakeHost +Implemented; section 16 says how, what it found, and what ran. + - `tests/session_fake.rs` as in 9.2, the conformance run through `Backends` (17 of 17), the live TeamSpeak conformance subset of 9.3 with the expected verdicts asserted per case (2 pass, 4 skipped, the rest not run, each with @@ -1135,3 +1149,255 @@ again, the comparison with it is the table of section 13): `live` 6 of 6, `media_live` 2, `stream_live` 3, `voice_features` 3 and `voelin-stream`'s `live_ts6` 1 pass. + +## 16. Slice 2 as implemented + +Slice 2 (section 10: the tests on `FakeSession` and `FakeHost`, the conformance +suite, the TeamSpeak session tests) is in `phase4/session-seam`. It adds tests +and three small changes to the code under test, each found by a test, each in a +commit of its own (16.5). + +### 16.1 What was built + +| File | What | Tests | +|---|---|---| +| `tests/session_fake.rs` | The engine through `Engine::start_with_backends` with a `FakeConnector` (scheme `fake`) and a `FakeHost` filled with `put`; `FakeHandle` plays the backend of one session. Public API only. | 16 run, 1 ignored (F3) | +| `tests/link_fake.rs` | Trimmed to the three tests that need the inner link: the stream commands (`stream_commands_reach_a_link_with_streams`), the order of a reconnect's shutdown, a replaced connection that keeps talking. | 3 | +| `src/link/fake_tests.rs` | What needs the crate's private parts: our voice as RTP read from `sent_media`, the voice of other slots, our own voice coming back, the conformance suite through `Backends::connect`. | 4 | +| `src/link/tests.rs` | One more test: a session made outside an engine keeps its watches open (F2). | 1 | +| `src/ts_session/live_tests.rs` | The TeamSpeak `Session` on both development servers (`VOELIN_LIVE=1`): the conformance subset and the session scenarios of 9.3. | 12 live, 2 ignored | + +`scripts/it-smoke.sh` runs the live module before its engine stage. + +The scenarios of `link_fake.rs` that moved: + +| Was in `link_fake.rs` | Now | What is new in the version on the fake host | +|---|---|---| +| `presence_follows_the_link_until_it_disconnects` | `presence_follows_the_host_until_it_ends` | the server's name and backend from `Welcome`, the tree from `Channel`s with `position`, participants from `VoiceState`s and `User`s, talking from `inject_media`, the poke as a `Signal`, the notice as `Error`, the end as `kill(Network(..))` | +| `commands_reach_the_link` (minus streams) | `commands_reach_the_host_as_requests` | what the host received: `Put{Message}` (Markdown without `chat.bbcode`), `JoinVoice` with the password, the flags as notifications (id 0) patching one leaf path, `Signal{poke}`, `List{FILE}` (the fake refuses `List.path`, so the answer is scripted) | +| `a_sent_message_and_its_echo_are_one_message` | same name | the fake stores our `Put` and pushes its `Change` | +| `a_message_that_comes_twice_is_shown_once` | same name | four `FakeHost::put(Message)`, one with `MESSAGE_FLAG_RELAYED` | +| `history_is_kept_across_the_connection` | `history_is_kept_across_the_session` | a DM `Channel{server_id: 0}` in HOME, found through the other recipient's unique id | + +New in `session_fake.rs`: how a session ends and the text the user reads (a +kick with a reason, an idle timeout, a close with no reason, the user's own +close as `Local(Normal)`); what a host refuses in its own words (`message:`, +`poke:`, `PASSWORD`, `FULL`, other, and a private message to nobody without a +request); closed scopes (a CHAT scope says nothing, a LIVE scope is an error +and an empty presence); a `HostUpdate` that removes `files`, so that the engine +refuses a file list without asking, and adds it and `mailbox` again; offline +messages as scripted `Mail` and the `Put`/`Delete` the host received; a file +written with `write_file`, read back with `read_file`, a missing file, and a +resumed upload that continues where the host's copy ends (the copy is left by +another session of the host that dropped its upload); `CreateDirectory`, +`RenameFile` and `DeleteFiles` as `FileEntry` puts and deletes; media routed to +the talker of its slot (an unknown slot, a whisper, 400 ms of silence); a +reconnect (the host sees the first session closed, the second has another +participant, a message said while away arrives, the replay of a message seen +does not show again); a connect that fails, and a second that works. + +### 16.2 The conformance suite + +**Through the registry.** `the_conformance_suite_passes_on_a_session_of_the_registry` +runs the 17 cases of `c8e0e5a` against the `FakeSession` that +`Backends::connect(params, LocalCtx::standalone())` hands over: 17 of 17 +pass, none is skipped. The registry adds nothing to a plain connector's +session (`host_uid` is the connector's, there is no stream port), so the +request ids the host sees are the session's own (`shared_request_ids`). + +**Against TeamSpeak.** `ts3_conformance_subset` and `ts6_conformance_subset` +open a `TsConnector` session per case on the development servers, and give the +suite the `FakeHandle` of an unrelated fake host as its backend. The verdict of +every case is asserted (2 pass, 4 skipped, 11 not run), and a case the suite +gains fails until it is listed in `EXPECTED`. The verdicts are the same on +TeamSpeak 3.13.8 and 6.0.0-beta13.1: + +| Case | Verdict | Why (what the case did when it was run) | +|---|---|---| +| `welcome_matches_features` | passes | session only | +| `close_ends_the_session` | passes | session only: `closed()` is `Local(Normal)`, later requests, notifications and media are `Closed`, the push channel ends | +| `a_stale_rev_conflicts_and_a_patch_writes_only_its_paths` | skipped | no `chat.edit` | +| `requests_apply_in_the_order_they_were_issued` | skipped | no `chat.edit` | +| `list_pages_history` | skipped | no `chat.history` | +| `idempotency_keys_apply_a_put_once` | skipped | no `idempotency` | +| `subscribe_syncs_the_scope` | cannot pass | writes to channel 4001: rejected (`NotFound`) no such channel | +| `subscribe_resumes_from_a_cursor` | cannot pass | channel 4002, the same | +| `put_answers_entities_and_pushes_the_change_with_the_same_rev` | cannot pass | channel 4003, the same | +| `delete_answers_an_ack_and_pushes_the_removal` | cannot pass | channel 4004, the same; and TeamSpeak cannot delete a message, where the case needs `chat` only (P8) | +| `a_key_names_an_entity_without_its_server` | cannot pass | server 4020: rejected (`NotFound`) no such server; and it creates a `ScheduledEvent` and an `Emoji`, which TeamSpeak lacks, though it needs no feature (P8) | +| `files_round_trip` | cannot pass | writes an `AttachmentSlot`: rejected (`Unsupported`) "attachments are not offered by this connection"; TeamSpeak has channel files, and the case needs `files`, not `chat.attachments` (P8) | +| `media_loops_back` | cannot pass | a TeamSpeak server does not return a client's own voice: the packet never loops back | +| `cancel_before_apply_is_cancelled` | cannot run | holds the unrelated fake host, so the request is answered while it "holds" | +| `notifications_are_fire_and_forget` | cannot run | reads the request log of the unrelated fake host: the notification never arrives (and it types into channel 1) | +| `renew_account_follows_the_feature` | cannot run | pushes a `HostUpdate` into the unrelated fake session's push channel, which is closed | +| `the_backend_can_end_the_session` | cannot run | kills the unrelated fake session, so `closed()` of the TeamSpeak session never resolves; and a kick is `Network(text)`, not `Remote{KICKED}`, until H1 | + +The cases that cannot pass or cannot run are not part of the default run: the +two ignored tests `ts3_cases_that_do_not_apply_fail` and +`ts6_cases_that_do_not_apply_fail` run each of them (with a step of 3 s) and +assert that it fails, printing the first line of the failure, so that a case +that starts to pass (with the native session of H1) is noticed. The table above +is what they printed. + +### 16.3 The TeamSpeak session scenarios + +Six live tests per server, on sessions that `TsConnector` made through the +plain `Connector` interface and that were driven the way section 4.2 drives a +session (list the server, subscribe HOME, SERVER and LIVE, take the seat, wait +for the LIVE scope to show it): + +| Test | What it checks | +|---|---| +| `chat_in_the_own_channel` | `Put Message` in the channel both sessions are in is answered with the message as written; the other session gets the `Change` in its CHAT scope, ours gets the echo (the ids agree only with H1's native session, so only "not zero" is asserted) | +| `refused_moves` | with a Normal-group key and a locked and a full channel made through ServerQuery: `JoinVoice` without or with a wrong password is `Rejected(PASSWORD)`, with the right one it seats us in that channel, a full channel is `Rejected(FULL)` | +| `poke_between_sessions` | `Signal{poke}` to the other participant reaches it as a `Signal` from our participant with the words | +| `voice_between_sessions` | five Opus frames and an end sent on our slot reach the other session's `MediaSink` on our slot, the first with the marker, the sequence counting up by one (it is TeamSpeak's packet id), the last an empty payload; media on a slot that is not ours is refused before it leaves | +| `channel_file_from_an_offset` | with a Server Admin key (guests may not upload): `write_file` of 3,000 bytes, `read_file` from offset 1,000 gives the file's size in the head and the bytes from the offset; the file is deleted afterwards | +| `conformance_subset` | 16.2 | + +### 16.4 Where the code differs from sections 9.2 and 9.3 + +- **The CHAT re-subscription after moving back is a full sync**, not a delta + (13): `the_chat_of_a_channel_is_resubscribed_when_we_move_back` asserts two + `Subscribe`s of the channel without `since`, the missed message once, and the + message seen before not again. +- **A reconnect resumes nothing** (4.4): the second session is another session + of the same host. `a_reconnect_finds_the_state_the_first_session_left` asserts + what that gives (the state of the host, another participant, the first seat + gone from the host, the first session `Local(Normal)`), and F3 what it does + not give. +- **Our voice in `FakeHandle::sent_media()`** is a test of `SessionLink` + (`link/fake_tests.rs`): no `Command` of the engine sends voice, the audio + thread does. +- **The conformance run and the live TeamSpeak tests are in-crate**: + `Backends::connect`, `LocalCtx` and `TsConnector` are crate-private, and + nothing was made public for a test. The live module runs with + `VOELIN_LIVE=1 cargo test -p voelin-core --lib ts_session::live_tests -- --test-threads=1`. + Slice 3 makes `TsConnector` public as `voelin_core::ts` and can move them to + `tests/`. +- **The fake host does not model everything the scenarios use**: it refuses + `List.path` (a file list and the listing before a resumed upload are + scripted), stores no `Mail` and no `FileEntry` (scripted), and its scripts + take every request of their op, so a script is added after the connect, and + the one for `list` answers by the kind asked. A `HostUpdate` or a notice + has no event of its own: a test knows the engine has applied a push when the + notice it sent after it is reported. +- **`welcome_matches_features` and `close_ends_the_session` pass for the right + reason only since F2.** Before it, a session made outside an engine ended by + itself within a moment. + +### 16.5 What the tests found + +**F1 (fixed, `Drop the media that comes back on our own slot`).** A session +that loops our voice back made the engine hand our own packets to the audio +thread and show us as talking: the slot map holds every participant, ourselves +included. `FakeSession` loops media back by default, so that a test sees media +move; a Voelin host that did the same would have made the engine play us to +ourselves. `on_media` returns for the packets of our own slot. TeamSpeak never +sends a client its own voice, so nothing changes for the servers the engine +reaches. Test: `our_own_voice_coming_back_is_not_played_back` (it heard +`[1, 50]`, us and then alice, before the change). + +**F2 (fixed, `Keep the account watches of a session made outside an engine +open`).** `LocalCtx::standalone()` exists to hold the senders of the +myTeamSpeak watches for a connector called outside an engine, but +`connect_link` dropped it when it returned; the TeamSpeak link ends its +connection with "account source closed" when a watch has no sender, so every +session made through the plain `Connector` interface ended by itself a moment +after it was handed out. The engine's path was never affected. The context +now moves into the driver task. Found by the first live run of the suite +(`the_backend_can_end_the_session` saw that text; `close_ends_the_session` had +passed without the session being alive). Test: +`a_session_made_outside_an_engine_keeps_the_watches_of_its_link_open` (fails +with "the identity watch lost its sender" without the change). + +**F3 (open; `a_message_the_host_sends_again_after_a_reconnect_is_stored_once`, +ignored).** After a reconnect, a Voelin host sends the window of a CHAT scope +again (the full sync of 4.3), and the engine stores each message of it a second +time. The display is right: `seen` in `SessionLink` is per connection, so the +replay is reported again, and `Dedup` in `session.rs` drops the copy of the +event (same target, author, text and time) but only after `store_live`; the +store merges copies from different sources only, so a replay over the same +source is a second row, and `ChatMessage` does not carry the host's message id +that would let it merge them. TeamSpeak never replays, and no `voelin://` +connector is registered, so no host the engine reaches today meets this. Not +fixed here because the cure is the resume of H8, not a patch: a cursor kept per +CHAT scope and sent as `Subscribe.since` (a delta, or a full sync when the epoch +changed); the cheaper candidates each carry a risk (a time floor per channel +for the messages of a connect-time sync would hide a backlog of a host that +was restored with older clocks; keeping the reported ids across connections +would hide new messages of a host whose ids restart). The ignored test is the +acceptance test of whatever is chosen. + +**F4 (observation).** The first snapshot of the TeamSpeak link can come after +the session was handed out (the driver waits 250 ms for it, `FIRST_SNAPSHOT`), +so a consumer that subscribes at once gets an empty LIVE sync and the voice +states as changes after it, and the seat the first `JoinVoice` answers can +name channel 0. The engine's replica copes (it is built on changes); a +consumer that reads the seat's channel must wait for its `VoiceState` in LIVE, +as `Client::settle` in the live tests does. H1's native session should hold the +first sync back until it has the snapshot. + +### 16.6 Follow-ups from this slice + +For the protocol repository (workarounds as above): + +| # | What | Workaround meanwhile | +|---|---|---| +| P15 | The suite's `Fixture::backend` is a `FakeHandle` for every harness, so a session of a real backend hands it an unrelated fake host and the cases that touch the backend fail or wait instead of being skipped. Make it `Option` and let a case say that it needs the backend (extends P8). | `EXPECTED` in `live_tests.rs` names the cases to run. | +| P16 | Say whether a host sends a sender its own voice. `FakeSession` loops it back by default and `media_loops_back` pins that for the fake; a consumer cannot tell a rule of the protocol from a setting of the fake. | F1: the engine drops its own slot. | +| P17 | Say what a consumer that reconnects without a resume token does with the replay of a CHAT window (protocol 2.5, 5.4): the `Message` id is the key to merge on, and `Subscribe.since` of a previous connection's cursor is a delta only within an epoch. | F3: nothing yet. | + +For the second half: + +| # | What | +|---|---| +| H10 | CHAT cursors per session and address in `SessionLink` (or the SDK of H8), sent as `Subscribe.since` after a reconnect; then the ignored test of F3 runs. The host's message id also has to reach the store, or the store has to merge same-source copies by id. | +| H11 | The native TeamSpeak session of H1 holds the first sync back until it has the first snapshot (F4), and `ts_session/live_tests.rs` moves with `ts_session` to `voelin-gateway-ts`; its `EXPECTED` table is the conformance record of that crate. | + +### 16.7 The broken translation + +Acceptance asks for a deliberately broken translation that makes a +`session_fake` test fail. With the `self_mute` path dropped from +`LinkCmd::SetInputMuted` in `link/session_link.rs` (the line +`self.voice_flag("self_mute", |voice| voice.self_mute = muted);` removed, the +file restored afterwards), `commands_reach_the_host_as_requests` fails: + +``` +thread 'commands_reach_the_host_as_requests' panicked at .../voelin-proto/src/test_util/connector.rs:301:3: +timed out after 20s waiting for self_mute +``` + +### 16.8 What ran + +Environment: Rust 1.94 (`rust-toolchain.toml`) and nightly 2026-10-19, in a +`nix shell` with `gcc cmake gnumake pkg-config jq alsa-lib openssl libvpx dav1d +pipewire fontconfig libxkbcommon`. `nix shell` does not run the setup hooks, so +three things were added by hand: the `.dev` outputs of those libraries on +`PKG_CONFIG_PATH` (without them `alsa-sys` does not build), their `lib` +outputs on `LD_LIBRARY_PATH` (`voelinctl` needs `libvpx.so.12`), and +`LIBCLANG_PATH` with `BINDGEN_EXTRA_CLANG_ARGS` for `libspa-sys`. With that +`cargo check --workspace --all-targets --locked` passes on both toolchains. The +development servers were TeamSpeak 3.13.8 and 6.0.0-beta13.1 of +`dev/docker-compose.yml` (compose project `voelin-seam5`, reset with `down -v` +before each smoke run). + +| Check | Result | +|---|---| +| `cargo fmt $(scripts/own-crates.sh) -- --check` | clean on 1.94. Nightly: the six differences of the baseline (`history.rs`, `encoder.rs`, `discovery.rs`, `chat.rs`, `studio.rs`, `engine.rs`), none in a file of this slice. (`cargo fmt --all` on 1.94 rewrites the vendored `crates/proto`, so it is not the check.) | +| `cargo clippy $(scripts/own-crates.sh) --all-targets --locked --no-deps -- -D warnings` | clean on 1.94, `voelin-ui` and the binaries included. Nightly: the five lints of the baseline in code this slice did not touch (`chunks_exact` four times in `audio.rs`, `result_large_err` in `voice.rs`), none in the new code. Every commit of the slice was checked alone on 1.94 (fmt, clippy, its tests); the first from an archive of its tree. | +| `cargo check --workspace --all-targets --locked` | passes on 1.94 and on nightly | +| `cargo test -p voelin-core --locked` | 1.94 and nightly: 236 lib tests pass, 2 are ignored (the live "do not apply" tests), 2 fail; the integration tests pass (`session_fake` 16 and 1 ignored, `link_fake` 3, `session_backends` 2, `gateway` 8, ...). The two failures are the baseline's (`discover::tests::without_records_the_gateway_itself_is_asked`, `web::tests::pictures_go_through_the_proxy_named_for_each_hop`: both reach a server bound to `127.0.0.1` through `localhost`, which resolves to `::1` here); they fail on an unchanged copy of `bfc52e2` too. | +| `cargo test -p voelin-core --locked --features media-desktop` | the same, and a third failure, `media::tests::peer_config_follows_codecs`, which depends on the codecs of the machine and fails on the unchanged copy of `bfc52e2` as well. (`--features media` alone does not compile the crate's tests: `src/media.rs` names `voelin_media::ffmpeg`, which only the desktop backends have; that is the baseline's.) | +| `link_fake` and `session_fake`, 15 consecutive runs | 0 failures (load average about 4) | +| Mutation (16.7) | `commands_reach_the_host_as_requests` fails with the `self_mute` path dropped; the file was restored | +| `a_session_made_outside_an_engine_keeps_the_watches_of_its_link_open` without the change of F2 | fails ("the identity watch lost its sender") | +| `our_own_voice_coming_back_is_not_played_back` without the change of F1 | fails (`[1, 50]` heard) | +| Live module, `VOELIN_LIVE=1 cargo test -p voelin-core --lib ts_session::live_tests -- --test-threads=1` | 12 of 12 pass on both servers, in 16 s; three more serial runs and one parallel run the same; with `--include-ignored` the two ignored tests pass too, each non-applicable case failing as `EXPECTED` says (the output of 16.2) | +| `scripts/it-smoke.sh ts3 ts6` on an archive of `bfc52e2` (before) | every per-server scenario passes (connect and tree, server and channel chat, voice tone, invisible presence, relay chat, gateway, history, pins and reactions, the engine's voice features, and on TeamSpeak 6 the streams and the late and elsewhere streams); the last stage fails in `ts6_banners` (`live.rs:375`, "disabled policy must prevent HTTP requests"), as it does on `59fec5b` | +| `scripts/it-smoke.sh ts3 ts6` at the head of the slice (after) | the same output apart from ids and counters (compared line by line with the numbers and identifiers masked), plus the new stage of the live module (12 passed, 2 ignored); the last stage fails in `ts6_banners` at the same line | +| the live binaries by hand, serially, on the head (`--features media-desktop`) | `live` 6 of 6, `media_live` 2, `stream_live` 3, `voice_features` 3, `voelin-stream`'s `live_ts6` 1: those of the baseline | + +Not run: `cargo deny` (not installed in this environment; `Cargo.lock` and +`THIRD_PARTY_NOTICES.md` did not change, no dependency was added), the +Windows, Android and Flatpak builds.