[CLI] Add a seed-demo command for quick test environments #5
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
We need a one-shot way to populate the database with believable dummy data so a fresh test environment (or a fresh prod you just stood up) has something to look at. Today there is no
seedcommand —app/cli.pyonly manages users. Without seed data you stare at an empty Library and cannot tell if the UI works.This is also a precondition for properly exercising infinite-scroll tests against a real-looking dataset.
Desired behaviour
A new subcommand
python -m app.cli seed-demothat:items, do nothing (refuse to clobber). Prints a one-line hint pointing at--reset.--reset: wipeitems,sources,services(in that order, FK-safe) and re-seed. Must require both--resetand--yes, and print a red warning before running.--count N: how many items to seed (default 200 so infinite scroll is genuinely exercised).--source-count N: how many sources to spread items across (default 2).--with-failures/--no-failures: include a couple offailedstatus rows (default true).--allow-production: allow running against a non-localhost database. Off by default; the command refuses to run ifDATABASE_URLis apostgres://to a non-localhost host, to prevent foot-guns.Seeded content:
Sourcerows with realistictelegram_chathandles (@sample_channel_books, etc.).Servicerow of typelocal_folder(no real network calls).Itemrows spread acrosscontent_type∈ {image, audio, video, text} andstatus∈ {discovered, queued, imported, failed} so badges, filters, and progress states all render.Sample(e.g.Sample Photo 0042,Sample Audiobook Demo — Chapter 7) so nobody confuses them with real media.media_path(if used) points to a non-existent path so the UI shows the existingfile-placeholder/file-glyphperAGENTS.md.Goals
app/seed.seed_demo(db, *, count, source_count, with_failures)function, importable from tests.app/cli.pythat wraps it, reuses the existing argparse style.seeded_library(count=…)intests/conftest.pythat calls the same function.--allow-production.Out of scope
Acceptance
python -m app.cli seed-demoon an empty DB seeds the expected number of items + sources + services, prints a summary line.python -m app.cli seed-demoon a populated DB exits 0 and prints a no-op hint.python -m app.cli seed-demo --reset --yeswipes and re-seeds; without--yesit prompts and refuses onn.python -m app.cli seed-demoagainst apostgres://prod-host/...DB exits non-zero with a clear error unless--allow-productionis passed.app/seed.seed_demois importable fromtests/conftest.pyand used by aseeded_libraryfixture.test_seed_demo_idempotent,test_seed_demo_reset_wipes_and_reseeds,test_seed_demo_default_count_is_200,test_seed_demo_refuses_production_db,test_seed_demo_allow_production_runs.Closed by #7