mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
* refactor(protocol): retire reserved voice_speakers and member_leave (S-15) Neither type was ever emitted by the server; B2-1 clears them from the schema before the epoch-1 wire fixtures are captured, so the frozen epoch does not carry two dead message types. Client: dropped the dead `ws.on(MEMBER_LEAVE)` / `ws.on(VOICE_SPEAKERS)` dispatcher handlers, the `MemberLeavePayload` type and both `ServerMessage` union members, and the tests that only exercised those WS paths. `removeMember` (member_ban) and `setSpeakers` (LiveKit ActiveSpeakers) stay live and keep their direct unit tests. * test(ws): capture the epoch-1 wire fixtures alpha.4 is the last client on the pre-epoch wire and B2-2 adds a protocol epoch to the auth handshake next, so record what epoch 1 actually looks like while it is still observable. TestEpoch1Fixtures drives eleven journeys through the ws package's in-process hub harness (full migrations, real hub, httptest WebSocket server) and compares each journey's per-connection frame sequence with a transcript under protocol/fixtures/epoch-1/: - fresh-connect, auth-failure, ping - chat-send-fanout, chat-edit-delete, reaction-add-remove - typing, mark-read, dm-send - resume-replay (last_seq + buffer-tier replay burst) - voice-join-e2ee-leave (join, both voice_state forms, announce and offer relay, leave) Volatile values are replaced by typed placeholders before both writing and comparison -- any key that is id/seq/last_seq, ends in _id (except channel_id and role_id) or _at, is timestamp/ts/last_seen, or contains token, becomes "<class:json-type>" so a field that changes type is still a diff, while everything else is compared verbatim. Regenerate with: go test ./ws -run TestEpoch1Fixtures -update Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * test(client): pin the epoch-1 auth frame contract Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * test(updater): pin the epoch-1 manifest and client-update shapes * test(ws): harden the epoch-1 fixtures against trailing frames and absent optionals Every journey now ends with the ping/pong barrier on each recorded connection, so a frame the server emits after the last read fails as `expected "pong", got "X"` instead of going unrecorded; auth-failure asserts the StatusPolicyViolation close instead, its socket being gone. alice carries a display name, avatar, about text, custom status, identity public key and an announce signature (bob carries none), so every optional field is frozen in its present form as well as its absent one — a rename or a retype of display_name or identity_public_key now moves a fixture. The typing journey focuses the channel on "a" before typing: without the subscription registerNow only makes for a focused client, its ping/pong proved nothing about excludeUserID. Comment fixes: the escaped placeholder form MarshalIndent would write, the real (headroom) reason for the raised read limit, a note that bare id and active_channel_id are normalised by design, and a .prettierignore line saying these fixtures are verified by the Go comparison, not by git diff. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * docs(protocol): document the epoch-1 fixtures * docs(protocol): match the epoch-1 wire where the fixtures contradicted the doc - voice_state: note the unsequenced relay-to-joiner form (table row + section) - auth_error: correct the example message and list the real rejection messages - member_join/presence connect example: add the seq both frames actually carry - chat_message.user: document display_name - voice_join reply order: state that the joiner's own voice_state broadcast is not ordered against the other three frames * test(ws): freeze the null forms of auth_ok and member_join user fields buildAuthOK emits display_name/about/custom_status/avatar as always-present nulls, but only alice — who has all four set — ever authenticated on a recorded connection, so the fixtures froze those fields in their populated form alone. A rename, a retype or a dropped null would have moved nothing, on the very frame B2-2 edits. fresh-connect now records bob's handshake too, on a second connection: his auth_ok carries the four nulls, his member_join carries avatar null with display_name and identity_public_key omitted, and alice — idle by then, so her reads stay in hub order — records the same pair as an already-connected observer sees it. In voice-join-e2ee-leave bob answers alice's signed announce with a legacy unsigned one, which freezes the absent form of signature next to her present one. The auth frames the test writes now carry the correlation id the real client stamps on every frame (ws.ts send()); normalisation renders it <id:string>. expectClosed also asserts the close reason ("authentication failed"), not just code 1008 — HP-2 asks for both. Comment precision, no behaviour change: the barrier guarantee now states that pong may overtake a pending LOW-priority frame (writePump) and that no journey is affected because every barrier is sent on an idle connection; the ping-budget ceiling is six connections, not four; the typing journey cites handleChannelFocusV2 rather than registerNow as the subscribe site; resume-replay's b barrier explains why moving it past the resume would be a flake, not a fix; and the header notes that normalisation hides that chat_send_ok.id echoes the request id. The client contract test's cited range for ws.ts's send() call is 441-453, not 441-454. Regenerate with: go test ./ws -run TestEpoch1Fixtures -update Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * docs(protocol): shape-not-value fixture rule, voice_max_video default, auth close code The fixture rule read "a fixture may only change with an epoch bump", which is false for the seeded values the transcripts record verbatim: role permission masks and colours, motd, server_name, voice_max_video, the voice_config preset. A migration that changes a default mask diffs fresh-connect.json, and the README told the author to revert a change that never touched the wire. Split the rule along shape versus value. A key set, a JSON type, a key appearing or disappearing, or per-connection frame order is a protocol change and earns fixtures/epoch-<n+1>/. A seeded default value is a seed change: regenerate in the same PR and read the diff frame by frame. Normalising those values is explicitly not the answer — a placeholder over a mask or over an enum such as voice_config.threshold_mode would hide the drift the fixtures exist to catch. Two wire facts corrected against the fixtures: - voice_max_video on an unconfigured channel is 25, not 0 (migration 004 is DEFAULT 25); the doc listed it among the zero values. - auth_error is followed by a close with code 1008 (policy violation) and reason "authentication failed" (serve.go:128), which the doc left as "closes the connection". Also: voice_speakers moves from discord-parity's "still dead" list to "came off the list" — it was retired earlier on this branch. And Kick says sessions are revoked and sockets drop on the next sweep, which is what ForceLogout does (moderation.go:236); it does not cut sockets. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * docs(protocol): fixture rule covers enum vocabularies; header comment precision Re-check minors from the whole-branch review: a fixed-vocabulary value the client switches on is shape, not a seeded value; drop the false 'new default channel' clause (the seed asserts channel ids); the low-priority frame is presence_update, not connect presence. * docs(plans): record B2-1 evidence for HP-2 (PR #1435, fixture commit SHAs) * docs(protocol): additive changes stay within an epoch; bump only for what old clients cannot process Codex review on #1435: B2-2 keeps protocol_epoch = 1 while adding auth/ready/auth_error fields, which the previous wording would have called a break to revert. An epoch is a compatibility boundary, not a snapshot: additive keys regenerate in the same PR and are documented; removals, renames, retypes, dropped frames and reordering bump the epoch. The plan's B2-1 evidence records the refinement and hands B2-2/B2-4 the open questions (additive-tolerant replay of the epoch-1 transcript; epoch 0 vs 1 naming). * test(client): compare auth-frame key sets order-independently Codex review on #1435: Object.keys preserves insertion order, so a harmless property reorder in ws.ts would fail the pin. Key order has no wire meaning; the Go fixtures already compare with sorted keys. Sort both sides. --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
361 lines
14 KiB
TypeScript
361 lines
14 KiB
TypeScript
/**
|
|
* Voice lifecycle E2E tests — tests the full voice join → widget → leave flow.
|
|
*
|
|
* These tests use the existing Tauri mock infrastructure to simulate:
|
|
* - WebSocket voice_state and voice_leave events
|
|
* - Voice channel UI (sidebar voice users, voice widget)
|
|
* - Connection quality, listen-only mode
|
|
*
|
|
* NOTE: These tests do NOT exercise real LiveKit/WebRTC connections.
|
|
* Real voice E2E requires the native test infrastructure (Tauri exe + LiveKit binary).
|
|
* These tests validate the UI layer's response to voice-related WS events.
|
|
*/
|
|
|
|
import { test, expect } from "@playwright/test";
|
|
import {
|
|
mockTauriFullSessionWithVoice,
|
|
mockTauriFullSessionWithVoiceFailure,
|
|
navigateToMainPageReady,
|
|
joinVoiceChannelByName,
|
|
emitWsMessage,
|
|
} from "./helpers";
|
|
|
|
test.describe("Voice lifecycle", () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await mockTauriFullSessionWithVoice(page);
|
|
await page.goto("/");
|
|
await navigateToMainPageReady(page);
|
|
});
|
|
|
|
test("shows voice users in voice channel sidebar", async ({ page }) => {
|
|
// MOCK_VOICE_STATE has remote users 2 and 3 in channel 10 ("Voice Chat")
|
|
const voiceChannel = page.locator(".channel-item", { hasText: "Voice Chat" });
|
|
await expect(voiceChannel).toBeVisible();
|
|
|
|
// Voice users should appear under the voice channel
|
|
const voiceUsers = page.locator(".voice-user-item");
|
|
await expect(voiceUsers).toHaveCount(2, { timeout: 5000 });
|
|
});
|
|
|
|
test("voice user shows muted indicator", async ({ page }) => {
|
|
// User 2 is muted in MOCK_VOICE_STATE
|
|
const mutedUser = page.locator(".voice-user-item .vu-muted");
|
|
await expect(mutedUser.first()).toBeVisible({ timeout: 5000 });
|
|
});
|
|
|
|
test("voice channel shows correct channel name", async ({ page }) => {
|
|
// The voice channel "Voice Chat" (id=10) should be visible in the sidebar
|
|
const voiceChannel = page.locator(".channel-item", { hasText: "Voice Chat" });
|
|
await expect(voiceChannel).toBeVisible({ timeout: 5000 });
|
|
// And "Music" (id=11) should also be visible
|
|
const musicChannel = page.locator(".channel-item", { hasText: "Music" });
|
|
await expect(musicChannel).toBeVisible({ timeout: 5000 });
|
|
});
|
|
|
|
test("voice_leave event removes user from voice channel", async ({ page }) => {
|
|
// Wait for initial voice users
|
|
await expect(page.locator(".voice-user-item")).toHaveCount(2, { timeout: 5000 });
|
|
|
|
// Emit voice_leave for user 2
|
|
await emitWsMessage(page, {
|
|
type: "voice_leave",
|
|
payload: {
|
|
user_id: 2,
|
|
channel_id: 10,
|
|
},
|
|
});
|
|
|
|
// Should now have 1 user
|
|
await expect(page.locator(".voice-user-item")).toHaveCount(1, { timeout: 5000 });
|
|
});
|
|
});
|
|
|
|
test.describe("Voice widget", () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await mockTauriFullSessionWithVoice(page);
|
|
await page.goto("/");
|
|
await navigateToMainPageReady(page);
|
|
});
|
|
|
|
test("voice widget exists in DOM", async ({ page }) => {
|
|
// The voice widget is always in the DOM but only visible when
|
|
// connected to a voice channel via LiveKit (not via WS mock alone).
|
|
// In mock mode, the widget exists but currentChannelId is null.
|
|
const widget = page.locator("[data-testid='voice-widget']");
|
|
await expect(widget).toBeAttached();
|
|
});
|
|
|
|
test("voice widget has correct control buttons", async ({ page }) => {
|
|
const widget = page.locator("[data-testid='voice-widget']");
|
|
// Even when hidden, the buttons should exist in the DOM
|
|
await expect(widget.locator("button[aria-label='Mute']")).toBeAttached();
|
|
await expect(widget.locator("button[aria-label='Deafen']")).toBeAttached();
|
|
await expect(widget.locator("button[aria-label='Camera']")).toBeAttached();
|
|
await expect(widget.locator("button[aria-label='Screenshare']")).toBeAttached();
|
|
await expect(widget.locator("button[aria-label='Disconnect']")).toBeAttached();
|
|
});
|
|
|
|
test("voice widget has grant mic button (hidden by default)", async ({ page }) => {
|
|
const grantMicBtn = page.locator(".vw-grant-mic");
|
|
// Should exist but be hidden (listenOnly is false)
|
|
await expect(grantMicBtn).toBeAttached();
|
|
await expect(grantMicBtn).toBeHidden();
|
|
});
|
|
|
|
test("voice widget has signal quality indicator", async ({ page }) => {
|
|
const signal = page.locator(".vw-signal");
|
|
await expect(signal).toBeAttached();
|
|
});
|
|
|
|
test("voice widget stats pane toggles on signal click", async ({ page }) => {
|
|
await joinVoiceChannelByName(page);
|
|
const signal = page.locator(".vw-signal");
|
|
const statsPane = page.locator(".vw-stats");
|
|
|
|
// Initially hidden
|
|
await expect(statsPane).not.toHaveClass(/visible/);
|
|
|
|
// Click signal to show
|
|
await signal.click();
|
|
await expect(statsPane).toHaveClass(/visible/);
|
|
|
|
// Click again to hide
|
|
await signal.click();
|
|
await expect(statsPane).not.toHaveClass(/visible/);
|
|
});
|
|
});
|
|
|
|
test.describe("Voice WS flow", () => {
|
|
// The local user starts OUTSIDE voice: pre-seeding ready.voice_states with
|
|
// user 1 no longer works — the dispatcher's stale-voice cleanup would send
|
|
// voice_leave and clear the store immediately. Tests join via the real
|
|
// click path (joinVoiceChannelByName) and the widget shows because
|
|
// joinVoiceChannel() sets currentChannelId synchronously on click.
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
await mockTauriFullSessionWithVoice(page);
|
|
await page.goto("/");
|
|
await navigateToMainPageReady(page);
|
|
});
|
|
|
|
// 1. Voice join flow — join, leave, then join a different channel.
|
|
test("joining a voice channel shows the widget", async ({ page }) => {
|
|
const widget = page.locator("[data-testid='voice-widget']");
|
|
|
|
// Not in voice at start
|
|
await expect(widget).not.toHaveClass(/visible/);
|
|
|
|
// Join "Voice Chat" (channel 10)
|
|
await joinVoiceChannelByName(page, "Voice Chat");
|
|
|
|
// Leave via Disconnect
|
|
const disconnectBtn = widget.locator("button[aria-label='Disconnect']");
|
|
await disconnectBtn.click();
|
|
await expect(widget).not.toHaveClass(/visible/, { timeout: 5_000 });
|
|
|
|
// Join "Music" (channel 11)
|
|
await joinVoiceChannelByName(page, "Music");
|
|
});
|
|
|
|
// 2. Voice leave flow — join, then clicking Disconnect hides the widget.
|
|
test("clicking disconnect hides voice widget", async ({ page }) => {
|
|
await joinVoiceChannelByName(page);
|
|
const widget = page.locator("[data-testid='voice-widget']");
|
|
|
|
const disconnectBtn = widget.locator("button[aria-label='Disconnect']");
|
|
await disconnectBtn.click();
|
|
|
|
await expect(widget).not.toHaveClass(/visible/, { timeout: 5_000 });
|
|
});
|
|
|
|
// 3. Permission recovery button — grant mic button appears when
|
|
// listenOnly is true (display toggled via voice store subscription).
|
|
test("grant mic button appears in listen-only mode", async ({ page }) => {
|
|
await joinVoiceChannelByName(page);
|
|
const widget = page.locator("[data-testid='voice-widget']");
|
|
|
|
// Set listen-only mode by manipulating the DOM directly (store isn't
|
|
// exposed on window; listenOnly is set by livekitSession on mic failure).
|
|
await page.evaluate(() => {
|
|
const grantBtn = document.querySelector(".vw-grant-mic") as HTMLElement | null;
|
|
if (grantBtn) grantBtn.style.display = "block";
|
|
});
|
|
|
|
const grantMicBtn = page.locator(".vw-grant-mic");
|
|
await expect(grantMicBtn).toBeVisible({ timeout: 5000 });
|
|
});
|
|
|
|
// 4. Device hot-swap toast — simulate a toast notification for device change.
|
|
test("device change shows toast notification", async ({ page }) => {
|
|
// Toast container is mounted by MainPage — inject a toast element.
|
|
await page.evaluate(() => {
|
|
const container = document.querySelector("[data-testid='toast-container']");
|
|
if (!container) return;
|
|
const toast = document.createElement("div");
|
|
toast.className = "toast toast-error";
|
|
toast.setAttribute("data-testid", "toast");
|
|
toast.textContent = "Audio device disconnected — switched to default";
|
|
container.appendChild(toast);
|
|
requestAnimationFrame(() => toast.classList.add("show"));
|
|
});
|
|
|
|
const toast = page.locator("[data-testid='toast']");
|
|
await expect(toast).toBeVisible({ timeout: 5000 });
|
|
});
|
|
|
|
// 5. Connection quality warning — stats pane auto-expands on quality degradation.
|
|
test("quality degradation auto-expands stats pane", async ({ page }) => {
|
|
await joinVoiceChannelByName(page);
|
|
const widget = page.locator("[data-testid='voice-widget']");
|
|
|
|
const statsPane = page.locator(".vw-stats");
|
|
await expect(statsPane).not.toHaveClass(/visible/);
|
|
|
|
// Simulate quality degradation by adding .visible class to stats pane
|
|
// (mirrors the onQualityChanged callback for "poor"/"bad" quality)
|
|
await page.evaluate(() => {
|
|
const pane = document.querySelector(".vw-stats");
|
|
if (pane) pane.classList.add("visible");
|
|
});
|
|
|
|
await expect(statsPane).toHaveClass(/visible/, { timeout: 5000 });
|
|
});
|
|
|
|
// 6. Mute/deafen toggle — buttons use aria-pressed and .active-ctrl class.
|
|
test("mute and deafen buttons toggle state", async ({ page }) => {
|
|
await joinVoiceChannelByName(page);
|
|
const widget = page.locator("[data-testid='voice-widget']");
|
|
|
|
const muteBtn = widget.locator("button[aria-label='Mute']");
|
|
await expect(muteBtn).toHaveAttribute("aria-pressed", "false", { timeout: 5000 });
|
|
|
|
await muteBtn.click();
|
|
await expect(muteBtn).toHaveAttribute("aria-pressed", "true", { timeout: 5000 });
|
|
await expect(muteBtn).toHaveClass(/active-ctrl/);
|
|
|
|
const deafenBtn = widget.locator("button[aria-label='Deafen']");
|
|
await deafenBtn.click();
|
|
await expect(deafenBtn).toHaveAttribute("aria-pressed", "true", { timeout: 5000 });
|
|
await expect(deafenBtn).toHaveClass(/active-ctrl/);
|
|
});
|
|
|
|
// 7. Voice timer — joinedAt is set by joinVoiceChannel() on click.
|
|
test("voice timer shows elapsed time", async ({ page }) => {
|
|
await joinVoiceChannelByName(page);
|
|
const widget = page.locator("[data-testid='voice-widget']");
|
|
|
|
const timer = widget.locator(".vw-timer");
|
|
await expect(timer).toBeVisible({ timeout: 5000 });
|
|
await expect(timer).toHaveText(/\d{2}:\d{2}/, { timeout: 5000 });
|
|
});
|
|
|
|
// 8. Token refresh — emitting a new voice_token doesn't disconnect.
|
|
test("token refresh does not disconnect session", async ({ page }) => {
|
|
await joinVoiceChannelByName(page);
|
|
const widget = page.locator("[data-testid='voice-widget']");
|
|
|
|
await emitWsMessage(page, {
|
|
type: "voice_token",
|
|
payload: {
|
|
token: "mock-livekit-token-refreshed",
|
|
url: "ws://localhost:7880",
|
|
channel_id: 10,
|
|
direct_url: "",
|
|
},
|
|
});
|
|
|
|
// Widget should still be visible
|
|
await expect(widget).toHaveClass(/visible/, { timeout: 3000 });
|
|
});
|
|
|
|
// 10. Camera indicator — voice_state with camera=true shows .vu-status.
|
|
test("voice_state with camera shows camera indicator on voice user", async ({ page }) => {
|
|
await expect(page.locator(".voice-user-item")).toHaveCount(2, { timeout: 5000 });
|
|
|
|
await emitWsMessage(page, {
|
|
type: "voice_state",
|
|
payload: {
|
|
user_id: 3,
|
|
channel_id: 10,
|
|
username: "member1",
|
|
muted: false,
|
|
deafened: false,
|
|
speaking: false,
|
|
camera: true,
|
|
screenshare: false,
|
|
},
|
|
});
|
|
|
|
const cameraIndicator = page.locator(".voice-user-item .vu-status");
|
|
await expect(cameraIndicator).toBeVisible({ timeout: 5000 });
|
|
});
|
|
|
|
// 11. Re-join after leave — join, leave via Disconnect, then re-join.
|
|
test("can rejoin voice channel after leaving", async ({ page }) => {
|
|
await joinVoiceChannelByName(page);
|
|
const widget = page.locator("[data-testid='voice-widget']");
|
|
|
|
// Leave voice
|
|
const disconnectBtn = widget.locator("button[aria-label='Disconnect']");
|
|
await disconnectBtn.click();
|
|
await expect(widget).not.toHaveClass(/visible/, { timeout: 5_000 });
|
|
|
|
// Wait for the mock's delayed voice_state/voice_leave echoes to be
|
|
// processed before re-joining: the hidden-widget assertion above passes
|
|
// on the synchronous store clear, but the join's voice_state echo briefly
|
|
// re-populates the store until the leave echo clears it again. Clicking
|
|
// the row inside that window toggles a LEAVE instead of a join. Our own
|
|
// roster entry disappearing is the settle signal for both echoes.
|
|
await expect(page.locator(".voice-user-item", { hasText: "testuser" })).toHaveCount(0, {
|
|
timeout: 5_000,
|
|
});
|
|
|
|
// Re-join
|
|
await joinVoiceChannelByName(page, "Voice Chat");
|
|
});
|
|
|
|
// 12. Channel switch — join Voice Chat, click Music to switch.
|
|
test("switching voice channels updates channel name", async ({ page }) => {
|
|
await joinVoiceChannelByName(page, "Voice Chat");
|
|
const widget = page.locator("[data-testid='voice-widget']");
|
|
|
|
// Verify initial channel name
|
|
await expect(widget.locator(".vw-channel")).toHaveText("Voice Chat", { timeout: 5000 });
|
|
|
|
// Click Music to switch channels
|
|
const musicChannel = page.locator(".channel-item.voice", { hasText: "Music" });
|
|
await musicChannel.click();
|
|
|
|
// Widget stays visible with updated channel name
|
|
await expect(widget).toHaveClass(/visible/, { timeout: 10_000 });
|
|
await expect(widget.locator(".vw-channel")).toHaveText("Music", { timeout: 5000 });
|
|
});
|
|
});
|
|
|
|
// Separate describe for failure scenarios (different mock setup)
|
|
test.describe("Voice WS flow — failure", () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await mockTauriFullSessionWithVoiceFailure(page);
|
|
await page.goto("/");
|
|
await navigateToMainPageReady(page);
|
|
});
|
|
|
|
// 13. Voice join failure — join Music, which triggers the failure handler.
|
|
test("voice join failure does not crash and disconnect still works", async ({ page }) => {
|
|
const widget = page.locator("[data-testid='voice-widget']");
|
|
await expect(widget).not.toHaveClass(/visible/);
|
|
|
|
// Join Music — the failure handler responds with a VOICE_JOIN_FAILED error
|
|
// event; joinVoiceChannel is called synchronously on click, so the widget
|
|
// shows immediately regardless.
|
|
await joinVoiceChannelByName(page, "Music");
|
|
|
|
// Wait for the error event to be processed — verify app is still functional
|
|
// by checking the disconnect button remains clickable
|
|
const disconnectBtn = widget.locator("button[aria-label='Disconnect']");
|
|
await expect(disconnectBtn).toBeEnabled({ timeout: 5_000 });
|
|
await disconnectBtn.click();
|
|
await expect(widget).not.toHaveClass(/visible/, { timeout: 5_000 });
|
|
});
|
|
});
|