chore(memory): V1-2.1 evidence update, M7 rehearsal scripts, TODO, journal
This commit is contained in:
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
@@ -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"
|
||||
Reference in new issue
Block a user