Refactor model scene definitions

This commit is contained in:
Nicolas Mowen
2026-09-29 15:34:43 -06:00
parent 5e87d101da
commit 15bed3fb31
30 changed files with 617 additions and 228 deletions
@@ -0,0 +1,73 @@
/**
* Camera detect scene tests -- MEDIUM tier.
*
* Scenes are free-form names declared by the configured models, so a camera
* only needs to pick one when there is more than one model, and the choices
* are the default scene plus the scenes of those models.
*/
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 SETTINGS_URL = "/settings?page=cameraDetect&camera=front_door";
async function installRoutes(
page: Page,
models: { scene: string; devices: string[] }[],
) {
const config = configFactory({ models } as never);
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: {} }),
);
}
test.describe("camera detect scene @medium", () => {
test("is hidden when there is only one model", async ({ frigateApp }) => {
await installRoutes(frigateApp.page, [
{ scene: "default", devices: ["cpu"] },
]);
await frigateApp.goto(SETTINGS_URL);
const root = frigateApp.page.locator("#pageRoot");
await expect(root).toContainText("Detect FPS");
await expect(root).not.toContainText("Detect scene");
});
test("offers the default and configured model scenes", async ({
frigateApp,
}) => {
await installRoutes(frigateApp.page, [
{ scene: "default", devices: ["cpu"] },
{ scene: "thermal", devices: ["openvino:GPU.0"] },
]);
await frigateApp.goto(SETTINGS_URL);
const root = frigateApp.page.locator("#pageRoot");
await expect(root).toContainText("Detect scene");
await frigateApp.page.locator("#root_scene").click();
const options = frigateApp.page.getByRole("option");
await expect(options).toHaveText(["Default", "thermal"]);
});
});
+64 -28
View File
@@ -129,19 +129,19 @@ const openPage = async (frigateApp: {
test.describe("Detection models settings @high", () => {
test("renders a card per configured model", async ({ frigateApp }) => {
await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["cpu"] },
{ scene: "default", 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");
await expect(root).toContainText("Default");
await expect(root).toContainText("outdoor");
});
test("unlimited hardware offers a detector count", async ({ frigateApp }) => {
await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["openvino:GPU.0"] },
{ scene: "default", devices: ["openvino:GPU.0"] },
]);
await openPage(frigateApp);
@@ -169,7 +169,7 @@ test.describe("Detection models settings @high", () => {
frigateApp,
}) => {
await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["openvino:GPU.0", "openvino:GPU.0"] },
{ scene: "default", devices: ["openvino:GPU.0", "openvino:GPU.0"] },
]);
await openPage(frigateApp);
@@ -190,7 +190,7 @@ test.describe("Detection models settings @high", () => {
frigateApp,
}) => {
await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["edgetpu:pci:0"] },
{ scene: "default", devices: ["edgetpu:pci:0"] },
]);
await openPage(frigateApp);
@@ -206,7 +206,7 @@ test.describe("Detection models settings @high", () => {
frigateApp,
}) => {
await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["edgetpu:pci:0"] },
{ scene: "default", devices: ["edgetpu:pci:0"] },
{ scene: "outdoor", devices: ["edgetpu:pci:1"] },
]);
await openPage(frigateApp);
@@ -221,7 +221,7 @@ test.describe("Detection models settings @high", () => {
frigateApp,
}) => {
await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["openvino:GPU.0"] },
{ scene: "default", devices: ["openvino:GPU.0"] },
{ scene: "outdoor", devices: ["openvino:GPU.1"] },
]);
await openPage(frigateApp);
@@ -234,23 +234,51 @@ test.describe("Detection models settings @high", () => {
);
});
test("adding a model appends a card with an unused scene", async ({
test("adding a model appends a card with a scene to name", async ({
frigateApp,
}) => {
await installRoutes(frigateApp.page, [{ scene: "all", devices: ["cpu"] }]);
await installRoutes(frigateApp.page, [
{ scene: "default", 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");
// the new card's scene starts empty, and a scene is required to save
const scene = frigateApp.page.locator("#models-1-scene");
await expect(scene).toHaveValue("");
await expect(
frigateApp.page.getByRole("button", { name: /^Save$/ }),
).toBeDisabled();
// the card keeps focus while its scene is typed
await scene.fill("thermal");
await expect(scene).toHaveValue("thermal");
await expect(scene).toBeFocused();
});
test("two models cannot share a scene", async ({ frigateApp }) => {
await installRoutes(frigateApp.page, [
{ scene: "default", devices: ["cpu"] },
{ scene: "thermal", devices: ["edgetpu:pci:0"] },
]);
await openPage(frigateApp);
await frigateApp.page.locator("#models-1-scene").fill("default");
await expect(frigateApp.page.locator("#pageRoot")).toContainText(
"Each model must use a different scene",
);
await expect(
frigateApp.page.getByRole("button", { name: /^Save$/ }),
).toBeDisabled();
});
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"] },
{ scene: "default", devices: ["openvino:GPU.0", "openvino:GPU.0"] },
]);
await openPage(frigateApp);
@@ -269,7 +297,7 @@ test.describe("Detection models settings @high", () => {
frigateApp.page,
[
{
scene: "all",
scene: "default",
devices: ["openvino:GPU.0"],
path: "plus://abc123",
plus: PLUS_MODEL,
@@ -294,7 +322,7 @@ test.describe("Detection models settings @high", () => {
frigateApp.page,
[
{
scene: "all",
scene: "default",
devices: ["openvino:GPU.0"],
path: "/config/custom.onnx",
},
@@ -325,7 +353,7 @@ test.describe("Detection models settings @high", () => {
frigateApp.page,
[
{
scene: "all",
scene: "default",
devices: ["openvino:GPU.0"],
path: "plus://abc123",
plus: PLUS_MODEL,
@@ -359,7 +387,7 @@ test.describe("Detection models settings @high", () => {
}) => {
await installRoutes(frigateApp.page, [
{
scene: "all",
scene: "default",
devices: ["openvino:GPU.0"],
path: "plus://abc123",
width: 320,
@@ -383,7 +411,13 @@ test.describe("Detection models settings @high", () => {
// 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" }],
[
{
scene: "default",
devices: ["hailo:PCIe"],
path: "/config/custom.hef",
},
],
true,
HAILO_PLUS_MODELS,
true,
@@ -413,7 +447,7 @@ test.describe("Detection models settings @high", () => {
// that must not read as an edit.
await installRoutes(frigateApp.page, [
{
scene: "all",
scene: "default",
devices: ["openvino:GPU.0", "openvino:GPU.0"],
path: "/config/model_cache/abc123",
width: 320,
@@ -438,12 +472,14 @@ test.describe("Detection models settings @high", () => {
frigateApp,
}) => {
await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["openvino:GPU.0"] },
{ scene: "default", 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(
"A name for the cameras this model is for",
);
await expect(root).toContainText(
"The hardware this model runs its detection on",
);
@@ -454,7 +490,7 @@ test.describe("Detection models settings @high", () => {
frigateApp,
}) => {
await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["edgetpu:pci:0"] },
{ scene: "default", devices: ["edgetpu:pci:0"] },
]);
await openPage(frigateApp);
@@ -465,10 +501,10 @@ test.describe("Detection models settings @high", () => {
});
test("removing the default model blocks saving", async ({ frigateApp }) => {
// a camera that names no scene runs the "all" model, so deleting it would
// a camera that names no scene runs the default model, so deleting it would
// leave those cameras with nothing to fall back to
await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["cpu"] },
{ scene: "default", devices: ["cpu"] },
{ scene: "outdoor", devices: ["edgetpu:pci:0"] },
]);
await openPage(frigateApp);
@@ -479,7 +515,7 @@ test.describe("Detection models settings @high", () => {
.click();
await expect(frigateApp.page.locator("#pageRoot")).toContainText(
"One model must use a scene of 'All cameras'",
"One model must use the default scene",
);
await expect(
frigateApp.page.getByRole("button", { name: /^Save$/ }),
@@ -490,7 +526,7 @@ test.describe("Detection models settings @high", () => {
// 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"] },
{ scene: "default", devices: ["openvino:GPU.0"] },
]);
await openPage(frigateApp);
@@ -508,7 +544,7 @@ test.describe("Detection models settings @high", () => {
frigateApp,
}) => {
const saves = await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["openvino:GPU.0", "openvino:GPU.1"] },
{ scene: "default", devices: ["openvino:GPU.0", "openvino:GPU.1"] },
]);
await openPage(frigateApp);
@@ -531,7 +567,7 @@ test.describe("Detection models settings @high", () => {
frigateApp,
}) => {
const saves = await installRoutes(frigateApp.page, [
{ scene: "all", devices: ["edgetpu:pci:0"] },
{ scene: "default", devices: ["edgetpu:pci:0"] },
]);
await openPage(frigateApp);