import { readFileSync } from "node:fs"; import { join } from "node:path"; import { describe, expect, it } from "vitest"; import { HARDWARE_PREFERENCE, retainsHardwarePreference, } from "../native/sender/internal/app/ui/hardware-status.js"; const senderUI = readFileSync( join(import.meta.dirname, "../native/sender/internal/app/ui/app.js"), "utf8", ); const senderHTML = readFileSync( join(import.meta.dirname, "../native/sender/internal/app/ui/index.html"), "utf8", ); const senderServer = readFileSync( join(import.meta.dirname, "../native/sender/internal/app/server.go"), "utf8", ); describe("native sender hardware preference contract", () => { it("accepts only a retained prefer-hardware capability result", () => { expect(retainsHardwarePreference({ supported: true, config: { hardwareAcceleration: HARDWARE_PREFERENCE }, })).toBe(true); expect(retainsHardwarePreference({ supported: true, config: {} })).toBe(false); expect(retainsHardwarePreference({ supported: false, config: { hardwareAcceleration: HARDWARE_PREFERENCE, } })).toBe(false); expect(retainsHardwarePreference(null)).toBe(false); }); it("keeps VP8 default, maps browser/native H.264, and retains one encoder", () => { expect(senderHTML).toContain(''); expect(senderHTML).toContain(''); expect(senderHTML).toContain(''); expect(senderUI).toContain('elements.codec?.value === "h264" || elements.codec?.value === "native-h264" ? "h264" : "vp8"'); expect(senderUI).toContain('elements.codec?.value === "native-h264" ? "native-window-h264" : "browser"'); expect(senderUI).toContain('codec: codec === "h264" ? "avc1.42c01f" : "vp8"'); expect(senderUI).toContain("metrics.codec = codec"); expect(senderUI).toContain("codecLabel(metrics.codec)"); expect(senderUI).toContain("codecLabel(codec)"); expect(senderUI).not.toContain("此设备不支持 VP8 720p30 编码"); expect(senderUI).not.toContain("`VP8 · 3 Mbps 上限"); expect(senderUI).toContain("encoderInstances: 1"); expect(senderUI).toContain("HARDWARE_STATUS.PREFERENCE_ACCEPTED"); expect(senderUI).toContain("HARDWARE_STATUS.FALLBACK"); expect(senderUI).toContain("HARDWARE_STATUS.UNVERIFIED"); expect(senderUI).toContain("delete fallback.hardwareAcceleration"); expect(senderUI).not.toContain('hardwareAcceleration: "prefer-software"'); expect(senderServer).toContain("ui/hardware-status.js"); expect(senderServer).toContain("/hardware-status.js"); }); });