mirror of
https://github.com/bitbaum/heidi.git
synced 2026-12-04 05:37:48 +01:00
batch-2
2
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
edf2cd32c5 |
release: informal address everywhere, engine clean-up, account limits, owner numbers (#358)
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T Co-authored-by: Claude <noreply@anthropic.com> |
||
|
|
f317425ec8 |
feat(groups): humans and Heidi in one thread, on a real database (#29)
* feat(db): heidi gets a database, the way the fleet already does it Study groups need two people to see one thread, which is the first thing in this app that cannot live in a browser tab. So: Postgres — and following the fleet's existing pattern rather than inventing a ninth one. WHAT WAS ALREADY DECIDED, AND REUSED fleetcrown's `apply-schema.sh` is a guarded, forward-only applier for DRIZZLE apps: it applies only migrations absent from the app's `_deploy_schema_history` ledger, refuses any migration carrying a destructive statement, and runs the batch in one transaction. It resolves the target database from apps.conf's `db` column — heidi's read `-`, which is why botsmann and printcraft shipped green for months while the pipeline never saw a migration file. That row is fixed in fleetcrown#682. So the layout is not a preference: `drizzle.config.ts` writes to `<app_dir>/drizzle` because that is one of the five paths the applier probes, and heidi's app_dir is the repo root. The client is vitareba's lazy-singleton-behind-a-Proxy, for its reason: `next build` imports every module and the build environment has no DATABASE_URL. PROVISIONING, AND THE BUG IT AVOIDS The box now has a heidi role, database, pg_hba rules and credentials. The schema step runs as the `postgres` superuser, so a table a migration creates is OWNED by postgres and the app role is granted nothing on it — the table exists, the connection works, every query says permission denied, and CI cannot see it because CI's test user owns everything. vitareba has 26 tables, 10 of them postgres-owned, and an empty `pg_default_acl`: those grants were repaired by hand afterwards. heidi sets ALTER DEFAULT PRIVILEGES FOR ROLE postgres before the first table exists. Verified on the box: the app role reads and writes a postgres-owned table. `lib/db/usable.ts` asserts the same property at runtime as the belt to that braces, since the deploy waits on health. NO USERS TABLE Identity stays federated; the OIDC `sub` is the actor id, stored as text with no foreign key, because the row it would point at lives in OrangeCat. The cost is a denormalised display name on the membership row — there is nothing to join to — which is accepted knowingly and is cheaper than mirroring an identity provider. Heidi is not a member row. She is in every group by construction, so a row for her could only ever say the same thing; she is composed into the threadkit participant list at read time. The rules are pure and tested without a database: a late joiner cannot read the back catalogue (threadkit's safe default, asserted), a departed member keeps their history and loses their voice, only the organiser hands out the link, and the invite token is 192 CSPRNG bits kept separate from the id because ids travel in URLs and logs. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FzYBD3sZroCAYeRgTYrpfT * feat(groups): the queries, and a CI that actually runs the tests The store is separate from the rules on purpose. The rules are decisions and are tested with no database at all; this is plumbing and is tested by using it, against a real Postgres — because every bug it can have is one the database has an opinion about. An upsert that would violate a primary key, a cascade that has to actually cascade, jsonb that must come back an object and not a string: a mocked `db` asserts only that the mock agrees with itself. CI DID NOT RUN THE TESTS Found while wiring the service container: the verify job ran type-check and lint as separate steps and never ran `pnpm run test`. Every unit test in this repository passed only on the machine of whoever remembered to run it — 200 of them, including the dialect gate over the Swiss German copy and the whole variety-pack suite. That is the single failure a CI floor exists to prevent, and it is why the house rule says CI calls the repo's own `verify` script verbatim instead of a hand-maintained list of what it is assumed to contain. The two had drifted, silently, in the direction that looks green. Now: postgres:17 as a service (matching the box), the deploy's own migrations applied to it rather than a schema written out by hand in the workflow, and one `Verify` step. WHAT THE STORE TESTS PIN - Re-joining does NOT reset `joinedAt`. threadkit gates visibility on it, so refreshing it would hand a returning member a blank thread. - Following an invite twice is an upsert, not a 500. (group, actor) is the primary key and a plain insert would break a thing that should just work. - The group list never carries the invite token. It renders for every member; only the organiser holds the key to the room. - Rotating the link kills the old one — the only way to un-invite a link already sitting in somebody's WhatsApp. - The app can use its own tables, which is the postgres-owns-the-table failure asserted directly rather than hoped about. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FzYBD3sZroCAYeRgTYrpfT * feat(groups): humans and Heidi in one thread The product ask was "invite humans, and humans and AI can be talked to together — a group chat with Heidi in it". This is that. WHAT THREADKIT ALREADY DECIDED Heidi does NOT answer every message in a group. With two participants she answers every turn because she IS the conversation; with three or more she waits to be addressed by name, because two humans talking to each other is not an invitation. That rule was already written months ago in `lib/domain/chat/thread.ts` for exactly this feature and needed no change — a group is the same object with a longer participant list, which is why the thread was modelled with threadkit rather than an array in the first place. The composer says so under the box, because a bot that silently declines to answer reads as broken rather than as polite. THE LINK IS THE CREDENTIAL A self-organised group has no approval step, so the invite token is treated as what it is: 192 CSPRNG bits, separate from the group id (ids travel in URLs and logs), shape-checked before any query so a hostile string never reaches Postgres, and rotatable — the only way to un-invite a link already sitting in somebody's WhatsApp. Only the organiser may see or rotate it. Narrow on purpose: if every member can re-share the key then "who can get in" is unknowable to the person responsible for the room. A non-organiser gets 404, and so does a stranger asking about a group — whether an id is real is not theirs to learn. WHAT THE ROUTE TESTS BUY The rules are pure and the queries hit real Postgres, but neither covers whether a route CALLS the right rule with the right arguments — which is exactly where an authorisation check goes missing. A route that forgets to ask `mayPost` passes every other test here. `caller()` is the seam, so the real handlers now run against the real database as any actor, including a stranger and a signed-out visitor. Three components were rewritten on the way. The React Compiler lint refused fetch-on-mount, and it was right to: the group thread, the group list and the invite token are all things the SERVER already has a session to query. Rendering them server-side removed three effects, three loading states and the empty flash before data arrives. The invite panel's own comment claimed a prop would leak the token into the page source — overstated, and now corrected: the page is dynamic, noindex, membership-checked and shows the token in an input on that very page. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FzYBD3sZroCAYeRgTYrpfT --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> |