Files
Piik/tests/browser-encoding-output.test.ts
T
AAA 04cbb2c9f4 fix(media): recover sharing from initialization failures
## Problem and outcome / ?????

Windows Auto could reject startup because it benchmarked the only remaining VP8 path after hardware encoding failed. Start that ordinary fallback directly; keep comparison only when it can choose between usable encoders. Browser peer construction failures now reach their existing preparation/recovery owners, while constructors release tracks they acquired before throwing. Native event timeout text no longer assumes which encoder event was missing.

## Release notes

### ??

??????????????????

- ?? Windows ?????????????????????????????????????
- ?????????????????????????????????????
- ??????????????????????????????

????????????????????????????????????

### English

This patch improves sharing startup and connection recovery.

- Fixes Windows automatic codec selection failing to start when an unnecessary software benchmark fails after hardware encoding is unavailable.
- Fixes some browser media-connection initialization failures not reaching the existing failure or recovery flow.
- Releases video tracks left behind by failed initialization and clarifies native encoder timeout diagnostics.

These fixes passed local validation. Device- or network-specific sharing failures still require evidence from the affected environment.

## Verification / ??

- npm run check: 76 test files / 1,115 tests, TypeScript and production Web build passed.
- Windows capture build and deterministic native checks passed, including proved-H264 retention and software-only fallback under a failed/expired optional comparison. The old implementation fails the new fallback check.
- Fault-injected hardware-unavailable and exhausted-probe-budget paths both captured a synthetic window and produced decoded 1920?1080 VP8 frames, followed by clean process/port/profile retirement.
- Browser regressions cover construction failures, exact connection identity, existing recovery budgets, prepared-candidate replacement and owned-track cleanup. Ordinary Host rebuild keeps the existing Viewer recovery owner.
- Documentation and repository hygiene checks passed. npm run check:go-core passed; Darwin cgo remains assigned to the native macOS packaging runner. CI also verifies race checks and all platform packages.

## Impact / ??

Compatible patch release v1.6.5; no wire, storage, room authority, retry-policy or quality-adaptation change. Source diagnostics stay ignored and private. The complete v1.6.3 reporter exports narrow failure stages but do not establish the affected machine's root cause. No interaction or room-voice feature is included. A matching Server restart interrupts process-owned media; routine atomic deployment keeps the pre-cutover binary through bounded postflight.
2026-09-25 17:08:42 +08:00

22 lines
1.0 KiB
TypeScript

import { afterEach, expect, it, vi } from "vitest";
import { BrowserEncodingOutput } from "../src/client/media/browser-encoding-output";
afterEach(() => vi.unstubAllGlobals());
it.each(["streams", "writer"])("releases its carrier when %s initialization fails", (stage) => {
const track = { stop: vi.fn(), contentHint: "" };
vi.stubGlobal("document", { createElement: () => ({
getContext: () => ({}), captureStream: () => ({ getVideoTracks: () => [track] }),
}) });
const failure = new DOMException("Already acquired", "InvalidStateError");
const sender = { createEncodedStreams: () => {
if (stage === "streams") throw failure;
return { writable: { getWriter: () => { throw failure; } } };
} } as unknown as RTCRtpSender;
const onFailure = vi.fn();
expect(() => new BrowserEncodingOutput(sender, onFailure, {})).toThrow(failure);
expect(track.stop).toHaveBeenCalledOnce();
// Construction has no live owner yet; start()'s caller handles its rejection.
expect(onFailure).not.toHaveBeenCalled();
});