chore(memory): V1-2.1 evidence update, M7 rehearsal scripts, TODO, journal

This commit is contained in:
bchanot committed 2026-10-28 18:44:00 +01:00
1 parent 961995804a
commit f80f325fd6
5 files changed
+168 -10

No files matched your search

@@ -49,7 +49,7 @@ files of this pass:
|---|---|---|
| 006 | 2 not ok: another editor uploads a pending key it did not register (L5) | 16/16 |
| 016 | 1 not ok: a draft from a deprecated version takes it as base (M2) | 50/50 |
| 017 | M1 approval on an archived sheet succeeds; M2 base from a deprecated version; the file aborts there | 78/78 |
| 017 | M1 approval on an archived sheet succeeds; M2 base from a deprecated version; the file aborts there | 85/85 |
| 018 | 93 not ok of 337: capability holders at aal1 get `rights.capability` instead of `rights.mfa` (§6.7); `delete_sheet_asset` answers a raw code | 337/337 |
| 019 | 38/38 (lost coverage of behaviour that was already correct) | 38/38 |
| sheets-concurrency | 5 failed of 15: publish against withdraw (no version lock), two deprecations (no sheet lock), archive against approve (no sheet lock) | 15/15 |
@@ -58,13 +58,13 @@ files of this pass:
| Run | Fresh stack | Upgraded stack (M3 + drawing object, then M4+M5) |
|---|---|---|
| pgTAP (`test-db`) | 1 325/1 325 | 1 325/1 325 |
| pgTAP (`test-db`) | 1 333/1 333 (final HEAD; 1 325 at 4a82941) | 1 325/1 325 (at 4a82941) |
| sandbox suite, run 1 | 86/86 | 86/86 |
| sandbox suite, run 2 (same stack) | 86/86 | 86/86 |
| pgTAP again after both suite runs | 1 325/1 325 | 1 325/1 325 |
| pgTAP again after both suite runs | 1 333/1 333 | 1 325/1 325 |
| `types --check` | | types match |
PGlite: 125/125 (packages/supabase), the 17 pgTAP files included.
PGlite: 127/127 (packages/supabase: the 17 pgTAP files and the closed-code census).
## 5. Timing at the caps (§15, budget 2 000 ms for save, submit, publish)
@@ -99,3 +99,7 @@ drawing placed as the operator tool placed it on DEV (the Git file
- After M4+M5, through the Storage API with real tokens: an editor at aal2 reads the 132 997
bytes (sha256 equal to the key); the same editor at aal1, a catalogue reader and an anonymous
caller are refused (the historical sheet has no published version).
The rehearsal is reproducible: `2026-10-28-v1-2-1-m7/m7-rehearsal.sh` (sandbox only; it applies
M4+M5 with `supabase migration up --db-url` on the sandbox port, a step `scripts/db-sandbox.sh`
has no subcommand for) and `m7-read.mjs` (the reads with real tokens).
@@ -0,0 +1,66 @@
// M7 rehearsal, after M4+M5: reads the historical drawing object through the
// Storage API with real GoTrue tokens (sandbox only, ports 57xxx). An editor at
// aal2 must get the exact bytes; a catalogue reader and an anonymous caller get
// nothing (the historical sheet has no published version). Prints one JSON line.
// Keys come from the environment (the sandbox secrets file), never argv.
import { createHash, createHmac } from 'node:crypto'
import { execFileSync } from 'node:child_process'
const AUTH = 'http://127.0.0.1:57999'
const STORAGE = 'http://127.0.0.1:57500'
const KEY = process.argv[2]
const anon = process.env.SB_ANON_KEY
const service = process.env.SB_SERVICE_KEY
const psql = (script) => execFileSync('docker', ['exec', '-i', '-e', 'PGPASSWORD', 'faunosteo_dbsandbox_db', 'psql', '-X', '-q', '-t', '-A',
'-h', '127.0.0.1', '-U', 'postgres', '-d', 'postgres', '-v', 'ON_ERROR_STOP=1'],
{ input: script, env: { ...process.env, PGPASSWORD: process.env.SB_PW } }).toString().trim()
const json = async (res) => { const t = await res.text(); try { return JSON.parse(t) } catch { return t } }
const auth = (path, body, bearer = anon) => fetch(AUTH + path, { method: 'POST',
headers: { apikey: anon, Authorization: `Bearer ${bearer}`, 'Content-Type': 'application/json' }, body: JSON.stringify(body) })
function base32(text) {
const A = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'; const out = []; let buf = 0; let bits = 0
for (const c of text.replace(/=+$/, '').toUpperCase()) { buf = (buf << 5) | A.indexOf(c); bits += 5; if (bits >= 8) { bits -= 8; out.push((buf >> bits) & 0xff) } }
return Buffer.from(out)
}
function totp(secret) {
const counter = Buffer.alloc(8); counter.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 30000)))
const mac = createHmac('sha1', base32(secret)).update(counter).digest(); const o = mac[mac.length - 1] & 0x0f
return ((mac.readUInt32BE(o) & 0x7fffffff) % 1_000_000).toString().padStart(6, '0')
}
async function account(tag) {
const email = `m7-${tag}-${Date.now()}@sandbox.local`
const user = await json(await auth('/admin/users', { email, password: 'Sandbox-only-pw-1', email_confirm: true }, service))
const session = await json(await auth('/token?grant_type=password', { email, password: 'Sandbox-only-pw-1' }))
return { id: user.id, token: session.access_token }
}
async function stepUp(token) {
const call = (method, path, body) => fetch(AUTH + path, { method, headers: { apikey: anon, Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' }, body: JSON.stringify(body) }).then(json)
const factor = await call('POST', '/factors', { factor_type: 'totp', friendly_name: 'm7' })
const challenge = await call('POST', `/factors/${factor.id}/challenge`, {})
const verified = await call('POST', `/factors/${factor.id}/verify`, { challenge_id: challenge.id, code: totp(factor.totp.secret) })
return verified.access_token
}
const read = async (token) => {
const res = await fetch(`${STORAGE}/object/authenticated/anatomical-sheet-assets/${KEY}`, { headers: token ? { Authorization: `Bearer ${token}` } : {} })
const bytes = Buffer.from(await res.arrayBuffer())
return { status: res.status, bytes: res.ok ? bytes.length : 0, sha256: res.ok ? createHash('sha256').update(bytes).digest('hex') : null }
}
const editor = await account('editor')
const editorAal2 = await stepUp(editor.token)
psql(`select private.assign_platform_role(null, '${editor.id}', 'admin');
insert into public.anatomical_catalog_grants (user_id, grant_kind, reason, verification_note, granted_by)
values ('${editor.id}', 'sheet_editor', 'm7 rehearsal', 'sandbox', '${editor.id}');`)
const reader = await account('reader')
psql(`insert into public.anatomical_catalog_grants (user_id, grant_kind, reason, granted_by)
values ('${reader.id}', 'catalog_reader', 'm7 rehearsal', '${editor.id}');`)
const result = {
editor_aal2: await read(editorAal2),
editor_aal1: await read(editor.token),
reader: await read(reader.token),
anonymous: await read(null),
}
console.log(JSON.stringify(result))
+87
View File
@@ -0,0 +1,87 @@
#!/usr/bin/env bash
# M7 rehearsal on the isolated db:sandbox stack only (containers faunosteo_dbsandbox_*,
# ports 57xxx; never the DEV stack). Builds the DEV state (migrations up to M3 through
# `up upgrade`, seeds, GoTrue accounts), places the historical drawing object the way the
# operator tool did on DEV (Git bytes, service-key upload, pre-M4 confirmation RPC),
# snapshots bytes and metadata, applies M4+M5 with the CLI, snapshots again, compares.
set -uo pipefail
S=/tmp/claude-1000/-home-bchanot-Documents-faunosteo/57f363af-09e1-44d4-88b0-b4d55155b08e/scratchpad
WT=/tmp/claude-1000/-home-bchanot-Documents-faunosteo/e641af9a-743e-46d0-9804-99667836040e/scratchpad/v1-2
BASE=$S/m7/base-$(date +%s)
OUT=$S/logs/m7
STATE="$HOME/.cache/faunosteo-db-sandbox"
mkdir -p "$OUT"
# 1. A scratch copy of the repository pieces db-sandbox.sh reads, migrations stopped at M3.
mkdir "$BASE" # a new directory per run: nothing is ever deleted
mkdir -p "$BASE/scripts" "$BASE/supabase/migrations"
cp "$WT/scripts/db-sandbox.sh" "$WT/scripts/dev-env.sh" "$BASE/scripts/"
cp "$WT/supabase/config.toml" "$WT/supabase/seed.sql" "$BASE/supabase/"
ln -s "$WT/supabase/seed" "$BASE/supabase/seed"
ln -s "$WT/node_modules" "$BASE/node_modules"
for f in "$WT"/supabase/migrations/*.sql; do
[ "$(basename "$f" | cut -d_ -f1)" \< 20261028100000 ] && cp "$f" "$BASE/supabase/migrations/"
done
ls "$BASE/supabase/migrations" > "$OUT/base-migrations.txt"
# 2. The DEV state: base migrations, seeds, the two GoTrue accounts.
(cd "$WT" && bash scripts/db-sandbox.sh down >/dev/null)
(cd "$BASE" && bash scripts/db-sandbox.sh up upgrade 20261028100000) > "$OUT/up-base.log" 2>&1
set -a; . "$STATE/secrets.sh"; set +a
export PGPASSWORD="$SB_PW"
q() { docker exec -i -e PGPASSWORD faunosteo_dbsandbox_db psql -X -q -t -A -h 127.0.0.1 -U postgres -d postgres -v ON_ERROR_STOP=1; }
ASSET=7f767f74-3b36-51a7-8465-52dd7e2ead4a
SVG="$WT/supabase/seed/anatomical-sheets/equine/draft/assets/horse.svg"
SHA=$(sha256sum "$SVG" | cut -d' ' -f1)
KEY="$SHA.svg"
echo "git file: $(stat -c %s "$SVG") bytes, sha256 $SHA" > "$OUT/fixture.txt"
echo "row sha256: $(echo "select sha256 || ' ' || byte_size from public.anatomical_sheet_assets where id = '$ASSET'" | q)" >> "$OUT/fixture.txt"
# 3. The operator path of R5.5 on DEV: object written with the service key, row confirmed by the pre-M4 RPC.
curl -sS -o "$OUT/upload.json" -w '%{http_code}\n' -X POST -H @"$STATE/service-header" -H 'Content-Type: image/svg+xml' \
--data-binary @"$SVG" "http://127.0.0.1:57500/object/anatomical-sheet-assets/$KEY" > "$OUT/upload.status"
curl -sS -o "$OUT/confirm.json" -w '%{http_code}\n' -X POST -H @"$STATE/service-header" -H 'Content-Type: application/json' \
-d "{\"asset_id\":\"$ASSET\"}" "http://127.0.0.1:57300/rpc/confirm_sheet_asset_upload" > "$OUT/confirm.status"
snapshot() { # label
{
echo "== object row"
echo "select row_to_json(o) from (select id, bucket_id, name, owner, owner_id, metadata, user_metadata, version, created_at, updated_at, last_accessed_at, path_tokens from storage.objects where bucket_id = 'anatomical-sheet-assets' and name = '$KEY') o" | q
echo "== bucket"
echo "select row_to_json(b) from (select id, public, file_size_limit, allowed_mime_types from storage.buckets where id = 'anatomical-sheet-assets') b" | q
echo "== asset row"
echo "select row_to_json(a) from (select * from public.anatomical_sheet_assets where id = '$ASSET') a" | q
echo "== historical sheet and version"
echo "select row_to_json(s) from (select id, status, current_version_id, last_version_number, updated_at, slug from public.anatomical_sheets where id = '503dc301-a8b1-50d4-9e44-0919b2fc2916') s" | q
echo "select id || ' ' || status || ' ' || version_number || ' ' || md5(content::text) || ' ' || updated_at from public.anatomical_sheet_versions where sheet_id = '503dc301-a8b1-50d4-9e44-0919b2fc2916'" | q
echo "== service_role table privileges on the catalogue tables"
echo "select coalesce(string_agg(table_name || ':' || privilege_type, ',' order by table_name, privilege_type), 'none') from information_schema.role_table_grants where grantee = 'service_role' and table_schema = 'public' and table_name in ('species', 'anatomical_sheets', 'anatomical_sheet_versions', 'anatomical_sheet_assets', 'profiles', 'profile_roles')" | q
echo "== bytes through the Storage API (service key)"
curl -sS -H @"$STATE/service-header" "http://127.0.0.1:57500/object/anatomical-sheet-assets/$KEY" | tee "$OUT/bytes-$1.svg" | sha256sum
stat -c '%s bytes' "$OUT/bytes-$1.svg"
} > "$OUT/snapshot-$1.txt"
}
snapshot before
# 4. M4 + M5 with the CLI, as the owner will apply them on DEV (migration up).
(cd "$WT" && node_modules/.bin/supabase --workdir . migration up \
--db-url "postgresql://postgres@127.0.0.1:57432/postgres?sslmode=disable") > "$OUT/migrate.log" 2>&1
echo "notify pgrst, 'reload schema'" | q
sleep 2
snapshot after
# 5. Reads through the migrated policies with real tokens.
node "$S/m7/m7-read.mjs" "$KEY" > "$OUT/reads.json"
# 6. The comparison: everything but the bucket limit identical.
diff "$OUT/snapshot-before.txt" "$OUT/snapshot-after.txt" > "$OUT/snapshot.diff" || true
cmp "$OUT/bytes-before.svg" "$SVG" && cmp "$OUT/bytes-after.svg" "$SVG" && echo "bytes identical to the Git file before and after" > "$OUT/bytes.result"
echo "m7 done"
# 7. The upgraded stack under the whole test set: pgTAP, the sandbox suite twice, the types.
cd "$WT"
bash scripts/db-sandbox.sh test-db > "$OUT/testdb.log" 2>&1; echo "test-db exit $?" >> "$OUT/testdb.log"
bash scripts/db-sandbox.sh test > "$OUT/sandbox-run1.log" 2>&1; echo "run1 exit $?" >> "$OUT/sandbox-run1.log"
bash scripts/db-sandbox.sh test > "$OUT/sandbox-run2.log" 2>&1; echo "run2 exit $?" >> "$OUT/sandbox-run2.log"
bash scripts/db-sandbox.sh test-db > "$OUT/testdb-after.log" 2>&1; echo "test-db-after exit $?" >> "$OUT/testdb-after.log"
bash scripts/db-sandbox.sh types --check > "$OUT/types.log" 2>&1; echo "types exit $?" >> "$OUT/types.log"
echo "m7 all done"
+1
View File
@@ -476,3 +476,4 @@ R5.4: `draft/{labels,changelog,review_report,drawing,overlay,app_review,svg_comp
## 2026-10-28
- V1-2.1 M4/M5 built+tested on sandbox (DEV untouched): M4 20261028100000 sheet_access_hardening (rights table + RPCs, has_mfa/has_aal2_session, catalogue reader predicate, can_edit_sheet on capability, AR-1 B role RPCs + F17/F18/F19, F1-F16), M5 20261028110000 sheet_review_workflow (version/sheet cols, freeze/revision/author triggers, rounds/comments/acks, lifecycle+review+publish RPCs, species, working copy, uploads+INSERT policy, mirror removed + status check). Defects F1-F19 reproduced on old schema; pgTAP 001/003/004/005/006/007/010/015/016 green (850 real-stack, 122 PGlite); sandbox real-GoTrue AR-1 B + F18 race green; fresh install + M3->M5 upgrade green; sheets.ts closed kinds, client gate deleted, types regen no drift; rust:check + typecheck + lint + build green. 011 + SQL-mirror generator deleted, ledger retargeted. BDR + LRN-095. check:all Docker image/worker stages not re-run (no app/worker/Dockerfile change). STOP at checkpoint.
- V1-2.1 fresh security+verifier gates run on commit 77e5fa4: security PASS (no blocker; lease-token whole-row grant narrowed to omit attempts/lease_token/locked_at). Verifier ECARTS(10) → fixed the real gaps: publish re-checks the approver's reviewer grant (publish.approval.invalid), scope disclaimer enforced at approve+publish (publish.disclaimer.missing, O6), to_confirm split from inherited (publish.to_confirm.open), save requires an active sheet, delete_sheet_asset revoked from service_role, species table comment updated, working-copy 2 MiB check, lock order sheet→version→round in decide/publish, conflict_retry kind (40001/40P01) in sheets.ts. Tests added (pgTAP 016 now 50, 001 census no-other-writer): omitted review_status, separation author-reviewer, revoked-reviewer approval + renewal, ack carry, inactive-species publish refusal, deprecated-delete, schema_version 1 refused, content-write-without-actor, working-copy positive. 871 real-stack pgTAP / 122 PGlite / 4 sandbox green; typecheck+lint+types drift clean. Deferred (noted): at-caps timing (V1-2.2 doc), fuller MFA factor mgmt (V1-2.5), low residuals (existence oracle, write-budget on some admin RPCs).
- V1-2.1 corrections after audit (3914eaa CHANGES REQUIRED): M1 approve needs active sheet, M2 base only from published round version, LOW fixes (rights.mfa first, closed codes, budgets, view.asset.unknown at submit, upload policy = registrant, append-only acks, deprecate/working-copy locks). Found+fixed: published round withdrawable, approver-author not refused at publish. Found: jsonb pg_column_size > text size (CHECK binds before contract measure) → closed code; owner decision. pgTAP 1325 fresh+upgraded, sandbox 86/86 x2 both stacks, caps timing max 374 ms, M7 rehearsal object+metadata identical, check:all green. Commits d05f75d..4a82941 pushed. M6 + M7 criterion + size measure → owner. Fresh verifier + security gates dispatched.
+6 -6
View File
@@ -549,12 +549,12 @@ Order (BDR-071): P0 docs + decisions → V1-1 clients and animals → V1-2 sheet
- [x] G2 M2 `create_sheet_draft`: base only from a `published` version with `published_review_id`; pgTAP: deprecated and pre-M5 sources give no base, every group to cover
- [x] G3 M3 pgTAP coverage from the verifier list (§5.3 matrix, F14 per RPC and policy + capability at aal1, F2, F8/D8, submit conflict, `review.uncoverable`, `publish.drawing.changed`, no carry for an author, removal group, `verdict.*`, species refusals, working copy slot / unchanged / verbatim, historical triggers, table-owner immutability + deprecation freeze, document guards at save, 2 MiB asset, species mismatch, one draft, number never reused, deactivated, Storage key variants, service_role confirm, SVG mime); no SQL-mirror test restored. Done: 017 rules (77), 018 access matrix (337), 019 immutability + Storage (38); 006/016 adapted; PGlite 125/125
- [x] G3b found while testing: withdrawal of a published version's round (now `draft.not_a_draft`, lock version → round); approver in the author set refused at publication too (§6.7); working-copy slot race (historical row lock) and restore while another copy is active
- [ ] G4 LOW: stale refs (`mfa.sandbox.ts`, LEDGER 011 note, sheet-model rule) + shim-vs-image column test; write budget on the 10 unmetered RPCs; `rights.mfa` before `rights.capability`; slug collision closed code; `view.asset.unknown` at submit; INSERT policy = registering caller; acknowledgments append-only; deprecate locks the sheet first (two-deprecation race); `delete_sheet_asset` closed codes + historical; red-on-old evidence + service_role grants record versioned
- [ ] G5 M5 sandbox suite re-runnable (F18 restores the other owners, workspaces uses its own owner); full suite twice on one stack
- [ ] G6 M4 the six two-session scenarios of §15 + archive vs approve + revoke vs grant; at-caps timing (synthetic document: 1 024 annotations, 8 192 nodes, 64 views, depth 8)
- [ ] G7 M7 upgrade rehearsal from the M3 state with a drawing-object fixture (Git bytes, sha256 = DEV row), bytes and metadata before/after; DEV-copy criterion → owner decision
- [ ] G8 AR-1 on the upgraded stack: seed owner with two factors works at aal2, refused at aal1; without a factor usable at aal1 except roles and rights
- [ ] G9 gates: pgTAP fresh + upgraded, PGlite, unit, sandbox ×2, types, check:all; fresh verifier + security audit
- [x] G4 LOW: stale refs (`mfa.sandbox.ts`, LEDGER 011 note, sheet-model rule) + shim-vs-image column test; write budget on the 10 unmetered RPCs; `rights.mfa` before `rights.capability`; slug collision closed code; `view.asset.unknown` at submit; INSERT policy = registering caller; acknowledgments append-only; deprecate locks the sheet first (two-deprecation race); `delete_sheet_asset` closed codes + historical; red-on-old evidence + service_role grants record versioned
- [x] G5 M5 sandbox suite re-runnable (F18 restores the other owners, workspaces uses its own owner); full suite twice on one stack
- [x] G6 M4 the six two-session scenarios of §15 + archive vs approve + revoke vs grant; at-caps timing (synthetic document: 1 024 annotations, 8 192 nodes, 64 views, depth 8)
- [x] G7 M7 upgrade rehearsal from the M3 state with a drawing-object fixture (Git bytes, sha256 = DEV row), bytes and metadata before/after; DEV-copy criterion → owner decision
- [x] G8 AR-1 on the upgraded stack: seed owner with two factors works at aal2, refused at aal1; without a factor usable at aal1 except roles and rights
- [x] G9 gates: pgTAP fresh + upgraded, PGlite, unit, sandbox ×2, types, check:all; fresh verifier + security audit
- [ ] M6 `grant.self_review`: divergence and proposal presented; owner decision pending, rule unchanged
- [ ] V1-2.2 core verdict, preview, change list, edit primitives, SVG cleaning · V1-2.3 drawings and worker verification (M6) · V1-2.4 wireframes (editor, review, admin entry) · V1-2.5 catalogue, admin space, rights, species, MFA · V1-2.6 editor level 1 · V1-2.7 preview, review, publication UI · V1-2.8 equine working copy and review preparation · V1-2.9 FR/EN acceptance and closure (owner checkpoints V1-2.3, V1-2.4, V1-2.6, V1-2.7, V1-2.8, V1-2.9 + each DEV operation of contract §16.11)