Add poorbird seed so the gallery has volume to be built against

The recorded TODO 3.0 decision: generated, not downloaded. No image licensing
question, no binary blobs in git, and it can produce the volume a virtualised
grid actually has to be tested against, which no set of real photos on hand
would.

Frames are written to disk for real, and thumbnails with them. A gallery whose
rows point at files that do not exist tests nothing about the delivery path,
which is the half most likely to be wrong. --no-thumbnails leaves thumb_path
NULL instead, which is how to exercise the queue at volume.

The data imitates what the firmware sends rather than being uniformly random:
bursts of frames around one radar trigger, the first one or two out of the
PSRAM pre-trigger ring, timestamps weighted toward daylight because birds are
diurnal and a gallery grouped by day looks wrong otherwise. Frames within a
burst land milliseconds apart on purpose - that is the received_at collision
the gallery cursor has to survive, and a seed that spread a burst over minutes
would never reproduce the paging bug it causes.

--clear is scoped by device_uid prefix, and that is the whole reason the prefix
exists. This command holds a DELETE over the same tables a real camera writes
to, so the property worth having is not that it removes seeded rows but that it
removes nothing else. The test for that is the one to keep: it puts a non-seed
device with a capture alongside the seeded ones and asserts both survive.

That test was mutation-checked against a scratch database rather than the dev
one, deliberately - a widened clear() would have taken the six real captures
with it, and verifying a safety property is not worth risking the thing it
protects. Against the scratch database, removing the scoping failed exactly
that test and nothing else.

The seed device is issued no token. It is a row for the gallery to point at,
not a camera, and giving it a working credential would be creating a real way
in for the sake of test data.

One flaky test found and fixed rather than re-run. test_every_burst_has_
pre_trigger_frames failed about one run in fifteen, because a count that is
not a multiple of the burst size left a truncated final burst - sometimes of
one frame, which is necessarily all pre-trigger, so "not all frames are
pre-trigger" did not hold. Both sides were wrong: a one-frame burst with
burst_count=1 is not something a camera sends, so the generator now absorbs a
short tail into the previous burst (bursts are 3-7 rather than 3-5), and the
test states its precondition instead of assuming it. Verified by running the
randomised tests fifteen times with the fix (0 failures) and fifteen times
without it (1 failure), rather than by one green run.

Tests: 293 -> 308.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Thomas KarnerandClaude Opus 5 committed 2026-09-21 19:27:27 +02:00
1 parent 735cbcc5a0
commit 51750e1644
3 files changed
+604

No files matched your search

+45
View File
@@ -214,6 +214,30 @@ def cmd_user_passwd(args: argparse.Namespace) -> int:
return 0
def cmd_seed(args: argparse.Namespace) -> int:
from .db import SessionLocal
from .seed import clear, generate
with SessionLocal() as session:
if args.clear:
captures, devices = clear(session)
print(f"removed {captures} seeded capture(s) and {devices} seed device(s)")
return 0
print(f"generating {args.captures} capture(s) over {args.days} day(s)...")
made = generate(
session,
count=args.captures,
days=args.days,
device_name=args.device_name,
thumbnails=not args.no_thumbnails,
)
print(f"\ndone: {made} capture(s) on device {args.device_name!r}")
print("Remove them again with: poorbird seed --clear")
return 0
def cmd_check(_args: argparse.Namespace) -> int:
settings = get_settings()
problems: list[str] = []
@@ -327,6 +351,27 @@ def main(argv: list[str] | None = None) -> int:
p.add_argument("payload", nargs="?", help="JSON object")
p.set_defaults(func=cmd_enqueue)
p = sub.add_parser(
"seed",
help="generate synthetic captures for gallery development",
description=(
"Creates captures on a dedicated seed device, with real JPEGs on disk. "
"--clear removes them again, and is scoped to seed devices only, so a "
"real camera's captures are never in scope."
),
)
p.add_argument("--captures", type=int, default=500, help="how many frames (default 500)")
p.add_argument("--days", type=int, default=14, help="spread them over this many days")
p.add_argument("--device-name", default="seed-cam")
p.add_argument(
"--no-thumbnails",
action="store_true",
help="leave thumb_path NULL so the worker generates them, which is how to "
"exercise the queue at volume",
)
p.add_argument("--clear", action="store_true", help="delete all seeded data instead")
p.set_defaults(func=cmd_seed)
p = sub.add_parser("user", help="manage UI accounts (there is no web signup)")
usersub = p.add_subparsers(dest="user_command", required=True)