feat(supabase): db:trial accounts, grants, equine drawings, app

account: confirmed account through GoTrue's admin API, hidden password typed
twice. grant: owner/admin by the operator path (factors counted in SQL and again
in the transaction, names sanitised); catalogue rights mirror grant_catalog_right
(admin first for sheet_editor), audit row, no implicit admin. Every grant typed
at a terminal. assets: R5.5 tool through the gateway. app: Vite stopped and
waited on exit. 323 stub-only harness cases.
This commit is contained in:
bchanot committed 2026-11-10 22:33:49 +01:00
1 parent b85614aa09
commit 3b687a218e
3 files changed
+649 -7

No files matched your search

@@ -3363,6 +3363,24 @@ fresh_log; trial stop; fresh_log; trial app
check "app: refused while the stack is stopped" refused "is not running"
```
#### Lot B3 review fixes (2026-11-10)
Already made by the B3 executor, kept: the lock is taken first (`require_state; take_lock` before `require_running`); `account` refuses a piped stdin; `app_stop` prints its message once; `grant` and `assets` die with a message when the factor read or the upload tool fails.
1. Factor gate: `factor_count` (SQL `count(*)` of verified TOTP factors, never output lines) and `factor_list`, whose names are sanitised in SQL (`left(regexp_replace(..., '[^[:alnum:] ._-]', '?', 'g'), 40)`): no newline, CR or escape reaches the terminal.
2. `grant_platform_role`: the grant transaction counts the factors again (`select assign_platform_role(...) where (count) >= :need \gset`, `need` 2 for owner, 1 for admin): fewer rows nothing, `\gset` fails under ON_ERROR_STOP, the unfinished transaction rolls back, the operator reads "nothing was granted".
3. Catalogue rights mirror `public.grant_catalog_right` in operator SQL (the RPC needs an owner JWT at aal2): `catalog_grant_status` answers no_account, inactive, no_totp, not_admin, already or ok (confirmed active account; verified TOTP except catalog_reader; admin for sheet_editor and sheet_publisher; no active row), each refused with its own message and nothing written. The practitioner procedure is admin first (`pnpm db:trial grant <email> admin`), then sheet_editor; the "granted but inactive under O1" note is gone. The write (insert, then `private.log_event(null, 'catalog_grant.operator_bootstrap', ...)`) is one `begin; ... commit;` that re-checks the rules; `granted_by` is the account's own id (NOT NULL column, the operator has no profile). An already active right stays exit 0, nothing written.
4. Every grant, catalogue included, asks the exact typed phrase `grant <right>` after the checks and the factor list, before any write.
5. Grant SQL (role and catalogue): explicit `begin;` ... `commit;` instead of `--single-transaction` (which commits a truncated script), ON_ERROR_STOP kept.
6. `read_new_password`: `IFS= read -rsp`, blanks kept and counted in the 12-character minimum.
7. `cmd_account` and `cmd_grant` lowercase the address (`${1,,}`, GoTrue stores it lowercased) before any use.
8. `read_new_password`: locals renamed `_rnp_typed` and `_rnp_again`, so a caller's variable cannot collide with the nameref.
9. `app_stop` finds Vite through `jobs -p` (no window between `&` and the pid assignment leaves an orphan) and `wait`s for it, so port 5194 is free on return; `cmd_app` ends with `wait $!`.
10. `require_terminal` in `check_arguments` for account, grant, restore, destroy: a non-terminal stdin is refused before any Docker call ("needs a terminal ... nothing was changed"). Moved assertions: B2 "restore/destroy with the phrase piped" now `refused_early` (no docker call); "restore refuses an incomplete backup" and the B3 lock case for `grant` now run at a terminal (`trial_tty`).
11. Known limit, no code: `app` takes no lock, so a `rotate-keys` can pass `refuse_while_app_runs` just before Vite binds; the app then keeps the previous anon key until its expiry. Holding the lock for the whole app session would block backup and migrate with a misleading message. Noted as a `shortcut:` comment in `cmd_app`.
12. Harness: one case per fix (stub hooks `answers/grant-factor-count`, `answers/txn-factors`, `vite-hold` with `vite-hold-sig`, `int-trial.sh`); the changed assertions are those of fix 10, the O1 cases (now the not_admin refusal), the grant cases that now run at a terminal, and the `-v need=` argument of the role grant.
13. Re-review (2026-11-10): the `shortcut:` above `cmd_app` now states the whole unlocked window and its upgrade path; harness comment on SIGINT corrected; the two-line factor name case now runs `factor_list` (indented lines, nothing written before the confirmation) with the SQL sanitisation kept as a named text check; the failing grant session case is named for the script's handling; the `granted_by` case asserts the bash comment; new case `fail/grant-catalog-write` (catalogue write failing after a passing check).
---
### Lot C: documentation, comments, TODO