Files
frigate/web/e2e/specs/explore.spec.ts
T
Blake BlackshearGitHubfrigate-agents[bot] <356735177+frigate-agents[bot]@users.noreply.github.com>Claude Opus 5.5
2b4b1fdb8e Plus rate limit handling (#25075)
* Raise a rate limit error when Frigate+ returns 429

The shared session's urllib3 Retry honored Retry-After by default, so a
429 on a GET or PUT blocked the calling thread for up to ten times the
requested wait (and fell back to exponential backoff for Retry-After: 0)
before failing with a generic error.

Stop honoring Retry-After in urllib3 and raise PlusRateLimitError with
the parsed wait instead. Retry-After is parsed as either delay-seconds or
an HTTP date per RFC 9110. While the wait is in effect, further requests
are refused locally rather than sent to Frigate+ again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Don't save a failed Frigate+ model download as the model

The model download never checked the response status, so an error body
(a 429 from the download host, for example) was written to the model
cache. Only the file's existence is checked on later starts, so the
error page was loaded as the model from then on.

Raise a config error instead of writing the file, and explain a Frigate+
rate limit at startup with how long to wait when it is known.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Report a rate limited Frigate+ key validation

A 429 while validating the API key was reported as "unreachable". Add a
rate_limited status that records the Retry-After wait, skip asking the
server again while that wait is in effect, and include the remaining
seconds in the /plus/validate response.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Return 429 from the API when Frigate+ is rate limiting

Submitting an event, frame, or false positive reported a rate limit as a
generic 400 upload error, and listing models failed with a 500. Return a
429 with the wait in retry_after and the Retry-After header so the UI can
tell the user how long to wait.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Show Frigate+ rate limits in the UI

Tell the user Frigate+ is rate limiting requests, and how long to wait
when the server said, instead of a generic failure:

- submitting a tracked object or false positive (explore and the review
  dialog), a frame from the player, or a frame from tracking details
- validating the API key in Frigate+ settings
- the Frigate+ model list in detection model settings and the setup
  wizard

The frame upload from the player also showed failures with a success
toast, and since axios rejects on error statuses it never reached that
branch at all, so failed uploads showed nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Let a failed Frigate+ annotation be retried

send_to_plus saved plus_id as soon as the image uploaded, so when the
annotation then failed (a rate limit, for example) every retry was
refused with "Already submitted to plus" and the image stayed without
its annotation.

Keep the uploaded image id in the event's data until the annotation
succeeds, and only then set plus_id. A retry reuses that image instead
of uploading it again, and since plus_id is still unset the UI already
offers the retry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Keep the longest Frigate+ wait when replies overlap

Requests to Frigate+ run on several threads. When two were refused at
once, a reply with a shorter Retry-After that was handled last replaced
the longer wait, so requests were sent again before Frigate+ allowed it.

Only move the deadline later, under a lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Include days in Frigate+ rate limit waits

formatSecondsToDuration only formats hours, minutes and seconds, so a
wait of a day or more lost its days: 90000 seconds read as "1 hour".
Format the wait from whole days down instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Keep the Frigate+ rate limit lock out of the client

The config holds the Frigate+ client and is pickled to start worker
processes from the forkserver. The lock added to PlusApi can't be
pickled, so worker startup failed with "cannot pickle '_thread.lock'
object", with or without a Frigate+ key.

Use a module level lock instead. Rate limit state is per process, so one
lock per process is all that's needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: frigate-agents[bot] <356735177+frigate-agents[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 07:12:34 -07:00

379 lines
15 KiB
TypeScript

/**
* Explore page tests -- HIGH tier.
*
* Search input, Enter submission, camera filter popover (desktop),
* event grid rendering with mocked events, mobile filter drawer.
*
* DEVIATION NOTES (from original plan):
*
* 1. Search input: InputWithTags is only rendered when
* config.semantic_search.enabled is true. Tests that exercise the search
* input override the config accordingly, using model:"genai" (not in the
* JINA_EMBEDDING_MODELS list) so the page skips local model-state checks
* and renders without waiting for model-download WS messages.
*
* 2. Filter buttons (Cameras, Labels, More Filters): SearchFilterGroup is
* only rendered when hasExistingSearch is true. Tests navigate with a URL
* param (?labels=person) to surface the filter bar.
*
* 3. Cameras button: accessible name is "Cameras Filter" (aria-label), not
* "All Cameras" (inner text). Use getByLabel("Cameras Filter").
*
* 4. Labels: button accessible name is "Labels" (aria-label). With
* ?labels=person, the text shows "Person" rather than "All Labels".
* Use getByLabel("Labels").
*
* 5. Sub-labels / Zones: These live inside the "More Filters" dialog
* (SearchFilterDialog), not as standalone top-level buttons. The Zones
* test opens "More Filters" and asserts zone content from config.
*
* 6. similarity_search_id URL param: This param does not exist in the app.
* The correct entrypoint for similarity search is
* ?search_type=similarity&event_id=<id>. The test uses this URL and
* polls for the resulting API request.
*/
import { test, expect } from "../fixtures/frigate-test";
// Semantic search config override used by multiple tests. Using model:
// "genai" (not in JINA_EMBEDDING_MODELS) sets isGenaiEmbeddings=true, which
// skips local model-state checks and lets the page render without waiting for
// individual model download WS messages. The WS mocker returns a completed
// reindexState so !reindexState is false and the loading gate clears.
const SEMANTIC_SEARCH_CONFIG = {
semantic_search: { enabled: true, model: "genai" },
} as const;
// ---------------------------------------------------------------------------
// Search input (semantic_search must be enabled)
// ---------------------------------------------------------------------------
test.describe("Explore — search @high", () => {
test("search input accepts text and clears", async ({ frigateApp }) => {
// Enable semantic search so InputWithTags renders.
await frigateApp.installDefaults({ config: SEMANTIC_SEARCH_CONFIG });
await frigateApp.goto("/explore");
const searchInput = frigateApp.page.locator("input").first();
await expect(searchInput).toBeVisible({ timeout: 10_000 });
await searchInput.fill("person");
await expect(searchInput).toHaveValue("person");
await searchInput.fill("");
await expect(searchInput).toHaveValue("");
});
test("Enter submission does not crash the page", async ({ frigateApp }) => {
await frigateApp.installDefaults({ config: SEMANTIC_SEARCH_CONFIG });
await frigateApp.goto("/explore");
const searchInput = frigateApp.page.locator("input").first();
await expect(searchInput).toBeVisible({ timeout: 10_000 });
await searchInput.fill("car in driveway");
await searchInput.press("Enter");
await expect(frigateApp.page.locator("#pageRoot")).toBeVisible();
});
});
// ---------------------------------------------------------------------------
// Filter bar — desktop only
// Filter buttons appear once hasExistingSearch is true (URL params present).
// ---------------------------------------------------------------------------
test.describe("Explore — filters (desktop) @high", () => {
test.skip(({ frigateApp }) => frigateApp.isMobile, "Desktop popovers");
test("Cameras popover lists configured cameras", async ({ frigateApp }) => {
// Navigate with a labels filter param so the filter bar renders.
await frigateApp.goto("/explore?labels=person");
// CamerasFilterButton has aria-label="Cameras Filter". Use getByLabel to
// match against the accessible name (not the inner "All Cameras" text).
const camerasBtn = frigateApp.page.getByLabel("Cameras Filter").first();
await expect(camerasBtn).toBeVisible({ timeout: 10_000 });
await camerasBtn.click();
// DropdownMenu on desktop wraps content in data-radix-popper-content-wrapper.
const popover = frigateApp.page.locator(
"[data-radix-popper-content-wrapper]",
);
await expect(popover.first()).toBeVisible({ timeout: 3_000 });
await expect(frigateApp.page.getByText("Front Door")).toBeVisible();
});
test("Labels filter lists labels from config", async ({ frigateApp }) => {
// Navigate with an existing search so the filter bar renders.
await frigateApp.goto("/explore?labels=person");
// GeneralFilterButton has aria-label="Labels". With ?labels=person the
// button text shows "Person" (the selected label), but the aria-label
// remains "Labels".
const labelsBtn = frigateApp.page.getByLabel("Labels").first();
await expect(labelsBtn).toBeVisible({ timeout: 10_000 });
await labelsBtn.click();
// PlatformAwareDialog renders on desktop as a dropdown/popover overlay.
const overlay = frigateApp.page.locator(
"[data-radix-popper-content-wrapper], [role='dialog'], [data-state='open']",
);
await expect(overlay.first()).toBeVisible({ timeout: 3_000 });
// "person" is already selected (it's in the URL); assert it appears in
// the overlay content.
await expect(overlay.first().getByText(/person/i)).toBeVisible();
await frigateApp.page.keyboard.press("Escape");
});
test("Sub-labels filter renders inside More Filters dialog", async ({
frigateApp,
}) => {
// Sub-labels live inside SearchFilterDialog ("More Filters" button).
// With sub_labels mocked as [], the section still renders its heading.
await frigateApp.page.route("**/api/sub_labels**", (route) =>
route.fulfill({ json: [] }),
);
await frigateApp.goto("/explore?labels=person");
const moreBtn = frigateApp.page.getByLabel("More Filters").first();
await expect(moreBtn).toBeVisible({ timeout: 10_000 });
await moreBtn.click();
const overlay = frigateApp.page.locator(
"[data-radix-popper-content-wrapper], [role='dialog'], [data-state='open']",
);
await expect(overlay.first()).toBeVisible({ timeout: 3_000 });
// "Sub Labels" section heading always renders inside the dialog.
await expect(
frigateApp.page.getByText(/sub.?label/i).first(),
).toBeVisible();
await frigateApp.page.keyboard.press("Escape");
});
test("Zones filter lists configured zones inside More Filters dialog", async ({
frigateApp,
}) => {
// Override config to guarantee a known zone on front_door.
await frigateApp.installDefaults({
config: {
cameras: {
front_door: {
zones: {
front_yard: { coordinates: "0.1,0.1,0.9,0.1,0.9,0.9,0.1,0.9" },
},
},
},
},
});
await frigateApp.goto("/explore?labels=person");
const moreBtn = frigateApp.page.getByLabel("More Filters").first();
await expect(moreBtn).toBeVisible({ timeout: 10_000 });
await moreBtn.click();
const overlay = frigateApp.page.locator(
"[data-radix-popper-content-wrapper], [role='dialog'], [data-state='open']",
);
await expect(overlay.first()).toBeVisible({ timeout: 3_000 });
await expect(frigateApp.page.getByText(/front.?yard/i)).toBeVisible();
await frigateApp.page.keyboard.press("Escape");
});
});
// ---------------------------------------------------------------------------
// Content
// ---------------------------------------------------------------------------
test.describe("Explore — content @high", () => {
test("page renders with mock events", async ({ frigateApp }) => {
await frigateApp.goto("/explore");
await expect(frigateApp.page.locator("#pageRoot")).toBeVisible({
timeout: 10_000,
});
await expect(
frigateApp.page.locator("#pageRoot button").first(),
).toBeVisible({ timeout: 10_000 });
});
test("empty events renders without crash", async ({ frigateApp }) => {
await frigateApp.installDefaults({ events: [] });
await frigateApp.goto("/explore");
await expect(frigateApp.page.locator("#pageRoot")).toBeVisible({
timeout: 10_000,
});
});
test("search fires a /api/events request with the query", async ({
frigateApp,
}) => {
await frigateApp.installDefaults({ config: SEMANTIC_SEARCH_CONFIG });
const eventsRequests: string[] = [];
frigateApp.page.on("request", (req) => {
const url = req.url();
if (/\/api\/events/.test(url)) eventsRequests.push(url);
});
await frigateApp.goto("/explore");
const searchInput = frigateApp.page.locator("input").first();
await expect(searchInput).toBeVisible({ timeout: 10_000 });
const before = eventsRequests.length;
await searchInput.fill("person in driveway");
await searchInput.press("Enter");
await expect
.poll(() => eventsRequests.length > before, { timeout: 5_000 })
.toBe(true);
});
});
// ---------------------------------------------------------------------------
// Similarity search URL param
// ---------------------------------------------------------------------------
test.describe("Explore: back button @high", () => {
test("direct visits do not show a back button", async ({ frigateApp }) => {
await frigateApp.goto("/explore?labels=person");
await expect(frigateApp.page.getByLabel("Labels").first()).toBeVisible({
timeout: 10_000,
});
await expect(
frigateApp.page.getByRole("button", { name: "Go back" }),
).toHaveCount(0);
});
});
test.describe("Explore — similarity search (desktop) @high", () => {
test.skip(
({ frigateApp }) => frigateApp.isMobile,
"Similarity trigger is hover-based; desktop-focused",
);
test("URL similarity search params fetch events", async ({ frigateApp }) => {
const eventsRequests: string[] = [];
frigateApp.page.on("request", (req) => {
const url = req.url();
if (/\/api\/events/.test(url)) eventsRequests.push(url);
});
// The app uses search_type=similarity&event_id=<id> (not
// similarity_search_id). This exercises the same similarity search code
// path as clicking "Find Similar" on a thumbnail.
// Use a valid event-id format (timestamp.fractional-alphanumeric).
await frigateApp.goto(
"/explore?search_type=similarity&event_id=1712412000.000000-abc123",
);
await expect(frigateApp.page.locator("#pageRoot")).toBeVisible({
timeout: 10_000,
});
// Poll to allow any pending SWR fetch to complete and be captured.
await expect
.poll(() => eventsRequests.length, { timeout: 5_000 })
.toBeGreaterThan(0);
});
});
// ---------------------------------------------------------------------------
// Mobile
// ---------------------------------------------------------------------------
test.describe("Explore — mobile @high @mobile", () => {
test.skip(({ frigateApp }) => !frigateApp.isMobile, "Mobile-only");
test("search input is focusable at mobile viewport", async ({
frigateApp,
}) => {
await frigateApp.installDefaults({ config: SEMANTIC_SEARCH_CONFIG });
await frigateApp.goto("/explore");
const searchInput = frigateApp.page.locator("input").first();
await expect(searchInput).toBeVisible({ timeout: 10_000 });
await searchInput.focus();
await expect(searchInput).toBeFocused();
});
});
// ---------------------------------------------------------------------------
// Frigate+ submission — desktop only
// The detail dialog's previous/next arrows only render on desktop.
// ---------------------------------------------------------------------------
test.describe("Explore — Frigate+ submission (desktop) @high", () => {
test.skip(
({ frigateApp }) => frigateApp.isMobile,
"Detail dialog navigation arrows are desktop-only",
);
test("in-flight submission does not mark the next tracked object as submitted", async ({
frigateApp,
}) => {
await frigateApp.installDefaults({ config: { plus: { enabled: true } } });
const page = frigateApp.page;
// Hold the submission open so it is still in flight while the user moves
// on to the next tracked object.
let releaseSubmission: () => void = () => {};
const submissionHeld = new Promise<void>((resolve) => {
releaseSubmission = resolve;
});
let submissions = 0;
await page.route("**/api/events/*/plus", async (route) => {
submissions += 1;
await submissionHeld;
await route.fulfill({ json: { success: true } });
});
await frigateApp.goto("/explore?labels=person");
const firstResult = page.locator("[data-start]").first();
await expect(firstResult).toBeVisible({ timeout: 10_000 });
await firstResult.click();
// The label being confirmed is rendered in a <code> tag inside the
// "Is this object a <label>?" question.
const dialog = page.getByRole("dialog");
await expect(dialog.locator("code")).toHaveText("person");
await dialog.getByRole("button", { name: "Yes", exact: true }).click();
await expect.poll(() => submissions, { timeout: 5_000 }).toBe(1);
await page.getByRole("button", { name: "Next tracked object" }).click();
await expect(dialog.locator("code")).toHaveText("car");
const submissionLanded = page.waitForResponse(/\/api\/events\/.*\/plus/);
releaseSubmission();
await submissionLanded;
// two frames is enough for React to flush the response handler's state
// updates, so the assertions below can't pass by racing ahead of them
await page.evaluate(
() =>
new Promise((resolve) =>
requestAnimationFrame(() => requestAnimationFrame(resolve)),
),
);
// The car was never submitted, so its question must be untouched.
expect(submissions).toBe(1);
await expect(dialog.getByText("Submitted")).toHaveCount(0);
await expect(
dialog.getByRole("button", { name: "Yes", exact: true }),
).toBeVisible();
});
test("a rate limited submission says how long to wait", async ({
frigateApp,
}) => {
await frigateApp.installDefaults({ config: { plus: { enabled: true } } });
const page = frigateApp.page;
await page.route("**/api/events/*/plus", (route) =>
route.fulfill({
status: 429,
headers: { "Retry-After": "90" },
json: { success: false, retry_after: 90 },
}),
);
await frigateApp.goto("/explore?labels=person");
const firstResult = page.locator("[data-start]").first();
await expect(firstResult).toBeVisible({ timeout: 10_000 });
await firstResult.click();
const dialog = page.getByRole("dialog");
await dialog.getByRole("button", { name: "Yes", exact: true }).click();
await expect(
page.getByText(
"Frigate+ is rate limiting requests. Try again in 1 minute, 30 seconds.",
),
).toBeVisible();
// the object can be submitted again once the wait is over
await expect(
dialog.getByRole("button", { name: "Yes", exact: true }),
).toBeVisible();
});
});