Files
frigate/web/e2e/specs/settings/detection-models.spec.ts
T
Josh HawkinsandGitHub a1c8bf99a7 Miscellaneous fixes (#24498)
* fix auto quality recovery after a downswitch

The downswitch callback armed the upswitch probe, but `triggerDownswitch` reset the stall history right after the callback returned, which disarmed it again. Auto quality stayed on the sub stream until the next chunk boundary no matter how much the connection recovered. The governor now arms the probe itself after the reset.

The chunk boundary effect also ran on mount, so when coverage was already cached it immediately undid the low quality cold start the seed effect had just picked. It now only runs when the chunk actually changes.

* fix recording playback quality switches and silent codec failures

A quality switch changes `bufferLength` a commit before the new source arrives, and since it was a dependency of the hls.js setup effect, the player rebuilt once on the outgoing playlist (jumping back to its original `startPosition`) and again on the new one. The buffer length now updates the running instance's config instead.

A fatal codec error with no lower quality stream to fall back to did nothing at all, so playback just sat there with no message. It now shows the playback failure toast, which is also limited to once per source since hls.js and the video element can both report the same failure.

* retry failed WebRTC probes and skip offline streams

The connectivity probe only ever tried the first go2rtc stream and cached its result for the whole page session, so a single offline camera at the top of the go2rtc config marked WebRTC unreachable for every camera until a reload, as did any brief network hiccup. The probe now starts with the stream being viewed and moves on to the next one when go2rtc reports that it can't open the stream's source. A failed result is only reused for 30 seconds, and it's retried on the next mount or when the page becomes visible again.

* fix two-way talk on cameras with AAC audio

The mic button was enabled whenever WebRTC was globally available, but the live view only switched to the WebRTC player when the stream itself qualified for WebRTC, and AAC playback audio disqualifies it. On most cameras the mic showed as on while nothing was sent. Two-way talk only needs the stream's video to connect since the backchannel is sent, not received, so AAC playback audio no longer blocks it. The mic is also turned off when a stream switch makes talk unavailable.

* keep Frigate+ model references when saving the models section

`/api/config` served a Frigate+ model's path as the resolved `/config/model_cache/<id>` file, and since the models list is saved whole, editing any model in the settings UI wrote that cache path back to the config in place of `plus://<id>`. After a restart the model loaded as a custom model with the default labelmap. The config API now reports the `plus://<id>` reference the model was configured with, and the models section drops the fields the Frigate+ model info supplies (size, tensor, pixel format, dtype, and type) instead of pinning them in the config.

* allow models to share shareable detection hardware

The hardware picker treated every device another model listed as taken, so a second model couldn't pick an Intel GPU or the CPU that the first one already used. The backend only rejects reuse of devices that can't be shared (Coral, MemryX), so the picker now matches that and only marks exclusive units as claimed.

* fix model card state and camera counts in the models editor

Model cards were keyed by index, so deleting one handed its state (such as the selected model source tab) to the card after it. Cards are keyed by scene now, which is unique per model.

The camera count on each card also ignored the backend's fallback to the `all` model, so a camera whose detect scene had no model of its own wasn't counted anywhere. It's counted under `all` now, which also feeds the recommended detector count.

* share a unit's temperature across repeated detector devices

Detector temperatures were matched to units by counting detectors of each type, so a device listed twice to run a second inference process (`hailo:PCIe` and `hailo:PCIe#2`) showed the next unit's temperature, or none at all. Distinct devices are numbered now and repeats share their unit's reading.

* update monitored hardware after a runtime config swap

`swap_runtime_config` rebound the stats emitter to the new config but not its `HardwareStats`, which kept polling hardware for the old config and applied camera updates to the discarded object. It now follows the swap along with its camera update subscriber.

* time out model downloads that never respond

`download_from_url` had no timeout, so a proxy or server that accepted the connection and never answered hung the download forever, including runtime downloads during startup. Connect and read timeouts now fail it like any other download error. The read timeout applies per socket read, so large models still finish.

* resolve segment start times in segment order

A camera stream's cached segments are probed concurrently, and each one chained its start off `last_segment_end` as soon as its own probe finished. When segments backed up in the cache and a later probe finished first, it chained off the wrong segment and the earlier one then moved `last_segment_end` backwards, so rows lost their exact adjacency. Probes still run concurrently, but each segment now waits for the one before it to settle its start before resolving its own.

* plan exports from the same coverage the vod route serves

The vod manifest nulls video-only glitch rows on audio-bearing streams, but exports planned their stream runs from the raw coverage, so a glitch row could produce a mixed-stream file or a 404 that failed the export. `null_audio_glitches` now works out each stream's audio composition itself, and exports go through it like the manifest and its realized timelines do.

An unstaged auto export also paged its playlist and chapters over main whenever main had any rows in range, even when the manifest served the range from sub and main only contributed glitches or slivers at the edges. It now reads the rows of the stream its single run actually uses.

* keep staged export chapters aligned across stream hand-offs

Each staged run of a mixed-stream export is rendered from its own pinned vod playlist, and that playlist's first clip snaps back to the preceding keyframe, so every staged file runs up to a GOP longer than its slice of the merged timeline. Chapters were placed on the merged timeline, so they drifted further from the video at every hand-off. Chapter windows for staged exports are now planned the same way each run's playlist is, carrying that keyframe lead-in into the offsets.

* clarify which hardware units only one model can use

* add e2e tests for shareable hardware and Frigate+ model saves

* only show the path field for a Frigate+ model without an API key

Without `PLUS_API_KEY` the models editor has no Frigate+ tab, so a `plus://` model showed every custom model field. The size, format, type, and labelmap fields are all supplied by the Frigate+ model info and ignored for a Frigate+ model, so editing them did nothing. Only the path is shown now, which still lets the model be switched to a custom one.

* keep a configured input_dtype when saving a Frigate+ model

The backend only overwrites `input_dtype` when the Frigate+ model info supplies `inputDataType`, which older models don't, so a configured dtype still matters for them. Saving the models section was dropping it along with the fields the backend always overwrites.

* probe every go2rtc stream until one isn't refused

The probe stopped after three streams, so with three offline cameras ahead of a working one, WebRTC was marked unreachable everywhere. It only moves past a stream when go2rtc refuses it, which is quick, and a stream that hangs still ends the probe at its timeout, so the cap bought nothing.

* only reuse a failed WebRTC probe for the stream it started from

A failed probe was reused for 30 seconds by every caller, so a camera whose stream timed out kept WebRTC unavailable for the next camera viewed, including one opened while that probe was still running. A pass still counts for every stream since it proves the connection, but a failure is only reused by probes that start from the same stream.

* strip input_dtype from Frigate+ models again

A Frigate+ model's config comes entirely from its model info, and a missing `inputDataType` means the `int` default. Keeping `input_dtype` meant switching from a custom model with `input_dtype: float` to a Frigate+ model carried the stale dtype over, with the field hidden so it couldn't be corrected.
2026-09-28 13:45:05 -06:00

548 lines
17 KiB
TypeScript

/**
* Detection models settings page tests -- HIGH tier.
*
* Covers picking hardware per model: exclusive units (Corals) are checkboxes
* that can only be claimed by one model, unlimited hardware (a GPU) gets a
* detector-count dropdown, and the whole models list saves in one PUT.
*/
import { readFileSync } from "node:fs";
import { resolve, dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { test, expect } from "../../fixtures/frigate-test";
import type { Page } from "@playwright/test";
import { configFactory } from "../../fixtures/mock-data/config";
const __dirname = dirname(fileURLToPath(import.meta.url));
const CONFIG_SCHEMA = JSON.parse(
readFileSync(
resolve(__dirname, "../../fixtures/mock-data/config-schema.json"),
"utf-8",
),
);
const PAGE = "/settings?page=systemDetectorsAndModel";
type Model = {
scene: string;
devices: string[];
path?: string | null;
input_tensor?: string;
input_pixel_format?: string;
input_dtype?: string;
model_type?: string;
labelmap?: Record<string, string>;
attributes_map?: Record<string, string[]>;
plus?: { id: string; name: string } | null;
width?: number;
height?: number;
};
const PLUS_MODEL = {
id: "abc123",
name: "yolov9-s",
baseModel: "yolov9",
trainDate: "2026-01-02T03:04:05Z",
isBaseModel: true,
supportedDetectors: ["openvino"],
width: 320,
height: 320,
};
// Frigate+ builds a Hailo model per device and names the detector by its
// pre-rename key; /api/plus/models adds the current one before serving it
const HAILO_PLUS_MODELS = [
{
...PLUS_MODEL,
id: "hailo8l1",
supportedDetectors: ["hailo8l", "hailo"],
hailoDevice: "hailo8l",
},
{
...PLUS_MODEL,
id: "hailo8r1",
supportedDetectors: ["hailo8l", "hailo"],
hailoDevice: "hailo8r",
},
];
const HAILO_HARDWARE = [
{
key: "hailo",
detector: "hailo",
name: "Hailo",
units: [{ device: "hailo:PCIe", label: "hailo0" }],
count: 1,
unlimited: true,
},
];
type SavedConfig = { config_data?: { models?: Model[] } };
async function installRoutes(
page: Page,
models: Model[],
plusEnabled = false,
plusModels: unknown[] = [PLUS_MODEL],
hailoHardware = false,
) {
const config = configFactory({
models,
plus: { enabled: plusEnabled },
} as never);
const saves: SavedConfig[] = [];
await page.route("**/api/config/schema.json", (route) =>
route.fulfill({ json: CONFIG_SCHEMA }),
);
await page.route("**/api/config", (route) =>
route.request().method() === "GET"
? route.fulfill({ json: config })
: route.fulfill({ json: { success: true } }),
);
await page.route("**/api/config/raw_paths", (route) =>
route.fulfill({ json: { models } }),
);
await page.route("**/api/plus/models", (route) =>
route.fulfill({ json: plusModels }),
);
if (hailoHardware) {
await page.route("**/api/hardware/probe**", (route) =>
route.fulfill({ json: HAILO_HARDWARE }),
);
}
await page.route("**/api/config/set", async (route) => {
saves.push(route.request().postDataJSON() as SavedConfig);
await route.fulfill({ json: { success: true, require_restart: false } });
});
return saves;
}
const openPage = async (frigateApp: {
goto: (url: string) => Promise<void>;
}) => {
await frigateApp.goto(PAGE);
};
test.describe("Detection models settings @high", () => {
test("renders a card per configured model", async ({ frigateApp }) => {
await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["cpu"] },
{ scene: "outdoor", devices: ["edgetpu:pci:0"] },
]);
await openPage(frigateApp);
const root = frigateApp.page.locator("#pageRoot");
await expect(root).toContainText("All cameras");
await expect(root).toContainText("Outdoor");
});
test("unlimited hardware offers a detector count", async ({ frigateApp }) => {
await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["openvino:GPU.0"] },
]);
await openPage(frigateApp);
await expect(
frigateApp.page.getByText("Detectors", { exact: true }),
).toBeVisible();
// the trigger shows the bare count; the recommendation is a second line on
// the matching option, so the dropdown has to be open to see it
await expect(
frigateApp.page.locator("#models-0-detector-count"),
).toHaveText("1");
await frigateApp.page.locator("#models-0-detector-count").click();
// three cameras in the mock config, so one detector is recommended
await expect(
frigateApp.page.getByRole("option", {
name: /Recommended for 3 cameras/,
}),
).toHaveText(/^1/);
});
test("a detector count above the recommendation is unlabelled", async ({
frigateApp,
}) => {
await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["openvino:GPU.0", "openvino:GPU.0"] },
]);
await openPage(frigateApp);
// two detectors are configured while one is recommended, so neither the
// trigger nor the selected option carries a recommendation
await expect(
frigateApp.page.locator("#models-0-detector-count"),
).toHaveText("2");
await frigateApp.page.locator("#models-0-detector-count").click();
await expect(
frigateApp.page.getByRole("option", { name: /^2/ }),
).not.toContainText("Recommended");
});
test("exclusive hardware offers one checkbox per unit", async ({
frigateApp,
}) => {
await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["edgetpu:pci:0"] },
]);
await openPage(frigateApp);
await expect(
frigateApp.page.locator("#models-0-edgetpu\\:pci\\:0"),
).toBeChecked();
await expect(
frigateApp.page.locator("#models-0-edgetpu\\:pci\\:1"),
).not.toBeChecked();
});
test("a unit claimed by another model cannot be picked", async ({
frigateApp,
}) => {
await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["edgetpu:pci:0"] },
{ scene: "outdoor", devices: ["edgetpu:pci:1"] },
]);
await openPage(frigateApp);
// the first card's checkbox for the unit the second model holds
await expect(
frigateApp.page.locator("#models-0-edgetpu\\:pci\\:1").first(),
).toBeDisabled();
});
test("shareable hardware another model uses can still be picked", async ({
frigateApp,
}) => {
await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["openvino:GPU.0"] },
{ scene: "outdoor", devices: ["openvino:GPU.1"] },
]);
await openPage(frigateApp);
await expect(
frigateApp.page.locator("#models-0-openvino\\:GPU\\.1").first(),
).toBeEnabled();
await expect(frigateApp.page.locator("#pageRoot")).not.toContainText(
"used by outdoor",
);
});
test("adding a model appends a card with an unused scene", async ({
frigateApp,
}) => {
await installRoutes(frigateApp.page, [{ scene: "all", devices: ["cpu"] }]);
await openPage(frigateApp);
await frigateApp.page.getByRole("button", { name: "Add model" }).click();
// "all" is taken, so the new card takes the next available scene
await expect(frigateApp.page.locator("#pageRoot")).toContainText("Indoor");
});
test("hardware is summarized rather than listed device by device", async ({
frigateApp,
}) => {
await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["openvino:GPU.0", "openvino:GPU.0"] },
]);
await openPage(frigateApp);
await expect(frigateApp.page.locator("#pageRoot")).toContainText(
"Intel GPU (2) \u2022 3 cameras",
);
await expect(frigateApp.page.locator("#pageRoot")).not.toContainText(
"openvino:GPU, openvino:GPU",
);
});
test("a saved Frigate+ model opens on the Frigate+ tab", async ({
frigateApp,
}) => {
await installRoutes(
frigateApp.page,
[
{
scene: "all",
devices: ["openvino:GPU.0"],
path: "plus://abc123",
plus: PLUS_MODEL,
},
],
true,
);
await openPage(frigateApp);
await expect(
frigateApp.page.getByRole("tab", { name: "Frigate+" }),
).toHaveAttribute("data-state", "active");
await expect(frigateApp.page.locator("#pageRoot")).toContainText(
"yolov9-s",
);
});
test("picking a Frigate+ model stays on the tab and saves a plus path", async ({
frigateApp,
}) => {
const saves = await installRoutes(
frigateApp.page,
[
{
scene: "all",
devices: ["openvino:GPU.0"],
path: "/config/custom.onnx",
},
],
true,
);
await openPage(frigateApp);
await frigateApp.page.getByRole("tab", { name: "Frigate+" }).click();
await frigateApp.page.getByRole("combobox").last().click();
await frigateApp.page.getByRole("option").first().click();
await expect(
frigateApp.page.getByRole("tab", { name: "Frigate+" }),
).toHaveAttribute("data-state", "active");
await frigateApp.page.getByRole("button", { name: /^Save$/ }).click();
await expect.poll(() => saves.length).toBeGreaterThan(0);
expect(saves.at(-1)?.config_data?.models?.[0].path).toBe("plus://abc123");
});
test("saving a Frigate+ model keeps its reference without the Frigate+ fields", async ({
frigateApp,
}) => {
// the backend fills these in from the Frigate+ model info when it loads
const saves = await installRoutes(
frigateApp.page,
[
{
scene: "all",
devices: ["openvino:GPU.0"],
path: "plus://abc123",
plus: PLUS_MODEL,
width: 320,
height: 320,
input_tensor: "nchw",
input_dtype: "float",
model_type: "yolo-generic",
},
],
true,
);
await openPage(frigateApp);
await frigateApp.page.locator("#models-0-openvino\\:GPU\\.1").click();
await frigateApp.page.getByRole("button", { name: /^Save$/ }).click();
await expect.poll(() => saves.length).toBeGreaterThan(0);
const model = saves.at(-1)?.config_data?.models?.[0];
expect(model?.path).toBe("plus://abc123");
expect(model?.devices).toEqual(["openvino:GPU.0", "openvino:GPU.1"]);
expect(model).not.toHaveProperty("width");
expect(model).not.toHaveProperty("input_tensor");
expect(model).not.toHaveProperty("model_type");
// a leftover dtype from a custom model must not override the int default
expect(model).not.toHaveProperty("input_dtype");
});
test("a Frigate+ model only shows its path without a Frigate+ API key", async ({
frigateApp,
}) => {
await installRoutes(frigateApp.page, [
{
scene: "all",
devices: ["openvino:GPU.0"],
path: "plus://abc123",
width: 320,
height: 320,
},
]);
await openPage(frigateApp);
const root = frigateApp.page.locator("#pageRoot");
await expect(root).toContainText("Custom object detector model path");
await expect(root).not.toContainText("Object detection model input width");
await expect(root).not.toContainText(
"Label map for custom object detector",
);
});
test("a Frigate+ Hailo model is listed by the device it was built for", async ({
frigateApp,
}) => {
// every Hailo model supports the one hailo detector, so the detector name
// says nothing; which device it was built for is what the user picks on
await installRoutes(
frigateApp.page,
[{ scene: "all", devices: ["hailo:PCIe"], path: "/config/custom.hef" }],
true,
HAILO_PLUS_MODELS,
true,
);
await openPage(frigateApp);
await frigateApp.page.getByRole("tab", { name: "Frigate+" }).click();
await frigateApp.page.getByRole("combobox").last().click();
const options = frigateApp.page.getByRole("option");
await expect(options).toHaveCount(2);
await expect(options.first()).toContainText("hailo8l");
await expect(options.last()).toContainText("hailo8r");
// knowing which device is attached is left to the user, so neither is
// ruled out here
await expect(options.first()).not.toHaveAttribute("aria-disabled", "true");
await expect(options.last()).not.toHaveAttribute("aria-disabled", "true");
});
test("a freshly opened page is not reported as modified", async ({
frigateApp,
}) => {
// `/api/config` serializes with exclude_none, so a nullable field such as
// labelmap_path is absent rather than null. The form materializes it, and
// that must not read as an edit.
await installRoutes(frigateApp.page, [
{
scene: "all",
devices: ["openvino:GPU.0", "openvino:GPU.0"],
path: "/config/model_cache/abc123",
width: 320,
height: 320,
input_tensor: "nchw",
input_pixel_format: "rgb",
input_dtype: "float",
model_type: "yolo-generic",
labelmap: {},
attributes_map: {},
},
]);
await openPage(frigateApp);
await expect(
frigateApp.page.getByRole("button", { name: /^Save$/ }),
).toBeVisible();
await expect(frigateApp.page.getByText("Modified")).toHaveCount(0);
});
test("the scene, hardware and detector count fields are described", async ({
frigateApp,
}) => {
await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["openvino:GPU.0"] },
]);
await openPage(frigateApp);
const root = frigateApp.page.locator("#pageRoot");
await expect(root).toContainText("The environment this model is for");
await expect(root).toContainText(
"The hardware this model runs its detection on",
);
await expect(root).toContainText("How many detection processes to run");
});
test("per unit hardware explains why a claimed unit is unavailable", async ({
frigateApp,
}) => {
await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["edgetpu:pci:0"] },
]);
await openPage(frigateApp);
// the count dropdown is replaced by checkboxes, so it gets its own copy
await expect(frigateApp.page.locator("#pageRoot")).toContainText(
"Each unit runs its own detection process",
);
});
test("removing the default model blocks saving", async ({ frigateApp }) => {
// a camera that names no scene runs the "all" model, so deleting it would
// leave those cameras with nothing to fall back to
await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["cpu"] },
{ scene: "outdoor", devices: ["edgetpu:pci:0"] },
]);
await openPage(frigateApp);
await frigateApp.page
.getByRole("button", { name: "Delete" })
.first()
.click();
await expect(frigateApp.page.locator("#pageRoot")).toContainText(
"One model must use a scene of 'All cameras'",
);
await expect(
frigateApp.page.getByRole("button", { name: /^Save$/ }),
).toBeDisabled();
});
test("a second GPU can be assigned to a model", async ({ frigateApp }) => {
// shareable hardware can report several addressable units; every one of
// them must be reachable, not just the first
const saves = await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["openvino:GPU.0"] },
]);
await openPage(frigateApp);
await frigateApp.page.locator("#models-0-openvino\\:GPU\\.1").click();
await frigateApp.page.getByRole("button", { name: /^Save$/ }).click();
await expect.poll(() => saves.length).toBeGreaterThan(0);
expect(saves.at(-1)?.config_data?.models?.[0].devices).toEqual([
"openvino:GPU.0",
"openvino:GPU.1",
]);
});
test("detectors are spread across every selected GPU", async ({
frigateApp,
}) => {
const saves = await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["openvino:GPU.0", "openvino:GPU.1"] },
]);
await openPage(frigateApp);
await frigateApp.page.locator("#models-0-detector-count").click();
await frigateApp.page
.getByRole("option", { name: "4", exact: true })
.click();
await frigateApp.page.getByRole("button", { name: /^Save$/ }).click();
await expect.poll(() => saves.length).toBeGreaterThan(0);
expect(saves.at(-1)?.config_data?.models?.[0].devices).toEqual([
"openvino:GPU.0",
"openvino:GPU.1",
"openvino:GPU.0",
"openvino:GPU.1",
]);
});
test("saving writes the whole models list in one request", async ({
frigateApp,
}) => {
const saves = await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["edgetpu:pci:0"] },
]);
await openPage(frigateApp);
await frigateApp.page.locator("#models-0-edgetpu\\:pci\\:1").click();
await frigateApp.page.getByRole("button", { name: /^Save$/ }).click();
await expect.poll(() => saves.length).toBeGreaterThan(0);
const models = saves.at(-1)?.config_data?.models;
expect(models).toHaveLength(1);
expect(models?.[0].devices).toEqual(["edgetpu:pci:0", "edgetpu:pci:1"]);
});
});