Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: storage updates keep access labels; finalize binds whole originals
garrytan194611e1c09f
diff --git a/changelog.d/capy-storage-manifest-adopt.md b/changelog.d/capy-storage-manifest-adopt.mdindex ffa65ccb0c..628fe30dbe 100644--- a/changelog.d/capy-storage-manifest-adopt.md+++ b/changelog.d/capy-storage-manifest-adopt.md@@ -1,10 +1,10 @@-**A storage manifest: agents can register what they archived to object storage and find it again later.** A new `storage` source holds one validated card per archived item: what it is, where every copy lives (store, bucket, path, restic repository and snapshot, size, file count, hash and its kind, when it was verified), where it came from and which skill restores it. `gbrain storage-register` adds a card (from stdin or `--card`) and never overwrites one; `gbrain storage-update <id> --expected-revision <rev>` patches a card bound to the revision it read and records restores newest first; `gbrain storage-find "<words>"` ranks the exact id, then an exact alias, then the cards holding most of the words, and a miss lists the closest cards; `gbrain storage-get` and `gbrain storage-list` read. On a brain with a Git checkout, `gbrain storage init` hosts the shelf in its own repository first (preview, then `--expect <plan_hash>`; it needs managed persistence), so each card is a commit before it is indexed. A repo-less brain gets a database-only shelf on the first register.+**A storage manifest: agents can register what they archived to object storage and find it again later.** A new `storage` source holds one validated card per archived item: what it is, where every copy lives (store, bucket, path, restic repository and snapshot, size, file count, hash and its kind, when it was verified), where it came from and which skill restores it. `gbrain storage-register` adds a card (from stdin or `--card`) and never overwrites one; `gbrain storage-update <id> --expected-revision <rev>` patches a card bound to the revision it read, keeps the page's access labels and records restores newest first; `gbrain storage-find "<words>"` ranks the exact id, then an exact alias, then the cards holding most of the words, and a miss lists the closest cards; `gbrain storage-get` and `gbrain storage-list` read. On a brain with a Git checkout, `gbrain storage init` hosts the shelf in its own repository first (preview, then `--expect <plan_hash>`; it needs managed persistence), so each card is a commit before it is indexed. A repo-less brain gets a database-only shelf on the first register.Cards never carry credentials or commands. A card is refused when any field looks like a secret, an environment assignment, a credential variable, a URL with user info or a presigned URL, or when any key is named `command`, `cmd`, `script`, `exec`, `shell` or `instructions`; object keys are checked too, and the refusal never echoes the value. A first shelf creation that stopped part way is finished by the next register or `storage init`, and an archived shelf refuses until it is restored. A restore is `{ skill, args }` with flat scalar arguments. gbrain stamps `registered_by` and `origin` itself, and holds no store credentials.The shelf is written only through the storage verbs. `put_page`, `remember` and every other page writer are refused `storage_source_managed` there, a request parameter cannot open the door, register and update run only from the trusted local CLI, and a dream cycle or enrichment run scoped to the shelf skips it. The source is not federated, so a remote connection reads cards only when its grant names `storage`.-**Agents find the shelf, and older archive records move onto it.** The brain-first lookup table every harness reads gains one row, "Find something archived to B2, Supabase or S3" (`gbrain storage-find` / `storage_find`), and a new `storage-manifest` skill says when to register, to find before restoring, to restore through the agent's own restore skill with the card's `restore.skill` and `restore.args`, and to record the restore with `gbrain storage-update`. `gbrain storage adopt` moves interim records (`stored-object` pages under `storage-manifest/` holding their record as JSON under `## Record`) onto the shelf: the preview shows each mapped card and every field a card refuses with its reason; `--apply --expect <plan_hash>` registers each card with `origin: adopt` and tags the original `storage-manifest-adopted`, deleting nothing, and refuses until each refused field is named with `--drop-field` (a credential-shaped value always refuses); `--finalize` previews, then soft-deletes the adopted originals only when every card matches its original (a restore recorded since is not a difference); the preview names any other section an original holds, and an original edited after the preview refuses. `gbrain storage export --jsonl` and `gbrain storage import --jsonl <file>` (preview per line, then `--apply --expect`) rebuild a shelf from a file, registering missing cards with `origin: import` and never overwriting a differing card; export leaves out and names a stored card that fails the card rules. Applies are idempotent and report `side_effects` and, when a run stops part way, the command that finishes it. The new doctor check `storage_manifest` warns about cards that fail the card schema, interim records not adopted yet and a hosted shelf whose directory is gone. On a brain with a Git checkout, adopt and import wait for `gbrain storage init`.+**Agents find the shelf, and older archive records move onto it.** The brain-first lookup table every harness reads gains one row, "Find something archived to B2, Supabase or S3" (`gbrain storage-find` / `storage_find`), and a new `storage-manifest` skill says when to register, to find before restoring, to restore through the agent's own restore skill with the card's `restore.skill` and `restore.args`, and to record the restore with `gbrain storage-update`. `gbrain storage adopt` moves interim records (`stored-object` pages under `storage-manifest/` holding their record as JSON under `## Record`) onto the shelf: the preview shows each mapped card and every field a card refuses with its reason; `--apply --expect <plan_hash>` registers each card with `origin: adopt` and tags the original `storage-manifest-adopted`, deleting nothing, and refuses until each refused field is named with `--drop-field` (a credential-shaped value always refuses); `--finalize` previews, then soft-deletes the adopted originals only when every card matches its original (a restore recorded since is not a difference); the preview names any other section an original holds and flags one longer than the 64 KiB it reads, and an original edited after the preview, even just before its delete, refuses. `gbrain storage export --jsonl` and `gbrain storage import --jsonl <file>` (preview per line, then `--apply --expect`) rebuild a shelf from a file, registering missing cards with `origin: import` and never overwriting a differing card; export leaves out and names a stored card that fails the card rules. Applies are idempotent and report `side_effects` and, when a run stops part way, the command that finishes it. The new doctor check `storage_manifest` warns about cards that fail the card schema, interim records not adopted yet and a hosted shelf whose directory is gone. On a brain with a Git checkout, adopt and import wait for `gbrain storage init`.### Itemized changesdiff --git a/docs/guides/storage-manifest.md b/docs/guides/storage-manifest.mdindex 40603d7f04..5528fc8753 100644--- a/docs/guides/storage-manifest.md+++ b/docs/guides/storage-manifest.md@@ -27,6 +27,7 @@ The skill behind these is `skills/storage-manifest/SKILL.md`.A restore runs through the agent's own restore skill: the card's `restore.skill` with `restore.args`. Cards nevercarry commands or credentials, and gbrain never contacts a store. After the restore, `storage-update` with`--restored-to` records where it landed (newest first); pass `--restored-verified` only when the checksums matched.+An update keeps the card page's access labels (`visibility`, `readable_by`), so a restricted card stays restricted.## Repo-less brains and brains with a Git checkout@@ -61,7 +62,8 @@ Agents that archived before the shelf existed often kept interim pages: `type: sthem (restorable for 72 hours with `gbrain restore`), only when every adopted card is on the shelf and matches itsoriginal's mapped card. A restore recorded with `storage-update` since adoption is not a difference. The previewnames any `##` section of an original other than `## Record` (notes the card does not carry, which go with the- page), and the plan_hash binds each original's content, so an original edited after the preview refuses+ page) and flags an original longer than the 64 KiB it reads, so you read the rest first. The plan_hash binds each+ original's whole content, checked again just before each delete, so an original edited after the preview refuses`preview_changed`.A rerun skips cards already on the shelf that match and originals already tagged. A card on the shelf that differs isdiff --git a/src/core/ops/storage-manifest.ts b/src/core/ops/storage-manifest.tsindex 2114f05e72..ff83b6cdbb 100644--- a/src/core/ops/storage-manifest.ts+++ b/src/core/ops/storage-manifest.ts@@ -7,6 +7,8 @@*/import { clampSearchLimit } from '../engine.ts';import { dataFrontmatter } from '../data-frontmatter.ts';+import { PROTECTED_FRONTMATTER_KEYS } from '../frontmatter-recovery.ts';+import { REVISION_BACKFILL_PENDING } from '../page-state/types.ts';import type { Operation, OperationContext } from './contract.ts';import { opError, OperationError } from './contract.ts';import { federatedSearchScope, readPolicyOpts } from './context.ts';@@ -58,21 +60,29 @@ function filtersOf(p: Record<string, unknown>): CardFilters {const NO_SHELF = 'This brain has no storage shelf yet: nothing has been registered. The archiving agent registers each item with gbrain storage-register after it verifies the archive.';-async function readCard(ctx: OperationContext, id: string): Promise<{ card: Card; revision: string; updated_at: string } | null> {+/** The card and its page frontmatter, read only when the caller may read that exact revision (a page that changes between the snapshot and the visibility check is read again). */+async function readCard(ctx: OperationContext, id: string): Promise<{ card: Card; revision: string; updated_at: string; frontmatter: Record<string, unknown> } | null> {if (!await shelfExists(ctx)) return null;const policy = await shelfPolicy(ctx);- const params: unknown[] = [STORAGE_SOURCE_ID, id];const { pageReadFilter } = await import('../search/read-policy-sql.ts');- const visible = await ctx.engine.executeRaw<{ ok: number }>(`SELECT 1 AS ok FROM pages p WHERE p.source_id = $1 AND p.slug = $2 AND ${pageReadFilter('p', policy, params, true)}`, params);- if (!visible.length) return null;- const snapshot = await ctx.engine.readPageSnapshot(id, { sourceId: STORAGE_SOURCE_ID });- if (!snapshot) return null;- const card = cardFromPage({ slug: snapshot.page.slug, title: snapshot.page.title, frontmatter: (snapshot.page.frontmatter ?? {}) as Record<string, unknown> });- return card ? { card, revision: snapshot.revision, updated_at: String(snapshot.page.updated_at ?? '') } : null;+ for (let attempt = 0; attempt < 3; attempt++) {+ const snapshot = await ctx.engine.readPageSnapshot(id, { sourceId: STORAGE_SOURCE_ID });+ if (!snapshot) return null;+ const params: unknown[] = [STORAGE_SOURCE_ID, id];+ const visible = await ctx.engine.executeRaw<{ revision: string | number | null }>(`SELECT p.knowledge_revision AS revision FROM pages p WHERE p.source_id = $1 AND p.slug = $2 AND ${pageReadFilter('p', policy, params, true)}`, params);+ if (!visible.length) return null;+ const revision = visible[0]!.revision == null ? REVISION_BACKFILL_PENDING : String(visible[0]!.revision);+ if (revision !== snapshot.revision) continue;+ const frontmatter = (snapshot.page.frontmatter ?? {}) as Record<string, unknown>;+ const card = cardFromPage({ slug: snapshot.page.slug, title: snapshot.page.title, frontmatter });+ return card ? { card, revision: snapshot.revision, updated_at: String(snapshot.page.updated_at ?? ''), frontmatter } : null;+ }+ throw opError('storage_revision_conflict', `Card ${id} kept changing while it was read; nothing was returned.`, 'Read the card again in a moment.', { fix: getFix(id) });}-async function writeCard(ctx: OperationContext, card: Card, opts: { expectedRevision?: string; requestId?: string }): Promise<Record<string, unknown>> {+async function writeCard(ctx: OperationContext, card: Card, opts: { expectedRevision?: string; requestId?: string; stored?: Record<string, unknown> }): Promise<Record<string, unknown>> {const { frontmatter, body } = cardPage(card);+ for (const key of PROTECTED_FRONTMATTER_KEYS) if (opts.stored && Object.hasOwn(opts.stored, key) && !Object.hasOwn(frontmatter, key)) frontmatter[key] = opts.stored[key];const content = dataFrontmatter.stringify(body, frontmatter);try {const response = await submitPageMutation(storageDoorContext(ctx), { operation: 'put_page', params: {@@ -253,7 +263,7 @@ const storage_update: Operation = {const { registered_by: _stampedBy, origin: _stampedOrigin, ...unstamped } = card;parseCardInput(unstamped);}- const response = await writeCard(ctx, card, { expectedRevision: expected });+ const response = await writeCard(ctx, card, { expectedRevision: expected, stored: found.frontmatter });return { id, source_id: STORAGE_SOURCE_ID, status: card.status, write: response };},cliHints: { name: 'storage-update', positional: ['id'] },diff --git a/src/core/storage-manifest/adopt.ts b/src/core/storage-manifest/adopt.tsindex 0d3240d013..3a08663d56 100644--- a/src/core/storage-manifest/adopt.ts+++ b/src/core/storage-manifest/adopt.ts@@ -13,8 +13,9 @@* finalize soft-deletes the tagged originals through the page door (restorable for 72 h), only when every adopted* card is on the shelf and matches its original's mapped card (a restore the card recorded since does not* count as a difference). The preview names each original's other sections (a `## Restore`, notes), which- * the card does not carry, and the plan_hash binds each original's content, so an original edited after- * the preview refuses preview_changed.+ * the card does not carry, and flags an original longer than the 64 KiB it reads. The plan_hash binds each+ * original's whole content (content_hash), checked again just before its delete, so an original edited+ * after the preview refuses preview_changed.** Idempotent: a card already on the shelf that matches is skipped, and so is an original already tagged. A card on* the shelf that differs is a conflict: reported, never overwritten, its original left untagged. The plan_hash covers@@ -26,6 +27,7 @@ import { opError, OperationError, type OperationContext } from '../ops/contract.import { readFix } from '../ops/op-fix.ts';import { registerCard } from '../ops/storage-manifest.ts';import { boundedBodyPrefixSql } from '../page-window/bounded-lead.ts';+import { BOUNDED_PREFIX_BYTES } from '../page-window/document.ts';import { submitPageMutation } from '../persistence/page-mutations.ts';import { readShelfCards } from './find.ts';import { CARD_KEYS, cardContent, cardDigest, credentialShape, isCommandKey, parseCardInput, STAMPED_KEYS, STORED_OBJECT_TYPE, type CardInput } from './schema.ts';@@ -52,14 +54,20 @@ export interface AdoptApplyResult {results: Array<{ slug: string; card_id: string | null; outcome: 'registered' | 'retagged' | 'skipped' | 'conflict' }>;conflicts: string[]; failure?: StepFailure; rerun?: string[]; finalize?: string[];}-export interface FinalizeEntry { slug: string; card_id: string | null; state: 'delete' | 'deleted' | 'unverified' | 'not_adopted'; other_sections?: string[]; content?: string }+export interface FinalizeEntry { slug: string; card_id: string | null; state: 'delete' | 'deleted' | 'unverified' | 'not_adopted'; other_sections?: string[]; unread_tail?: boolean; content?: string }export interface FinalizePlan { action: 'finalize'; dry_run: true; source_id: string; prefix: string; entries: FinalizeEntry[]; plan_hash: string; summary: string[]; apply?: string[] }export interface FinalizeApplyResult {action: 'finalize'; dry_run: false; source_id: string; prefix: string; plan_hash: string; side_effects: SideEffects;deleted: string[]; skipped: string[]; failure?: StepFailure; rerun?: string[];}-interface InterimRow { slug: string; title: string; frontmatter: unknown; body: string | null; tagged: boolean; deleted: boolean }+interface InterimRow { slug: string; title: string; frontmatter: unknown; body: string | null; content_hash: string | null; long_body: boolean; tagged: boolean; deleted: boolean }++const INTERIM_COLUMNS = `p.slug, p.title, p.frontmatter, ${boundedBodyPrefixSql('p')} AS body, p.content_hash,+ coalesce(p.body_bytes, 0) > ${BOUNDED_PREFIX_BYTES} AS long_body`;++/** What a finalize plan binds for one original: its title, frontmatter and whole content (content_hash), so any edit after the preview changes it. */+const originalDigest = (row: Pick<InterimRow, 'title' | 'frontmatter' | 'body' | 'content_hash'>) => sha256(JSON.stringify([row.title, row.frontmatter, row.content_hash ?? row.body]));const sha256 = (text: string) => createHash('sha256').update(text).digest('hex');const SECTION = /^##[ \t]+Record[ \t]*$/m;@@ -161,7 +169,7 @@ export function mapInterimPage(row: Pick<InterimRow, 'slug' | 'title' | 'frontmaasync function listInterim(ctx: OperationContext, opts: AdoptOptions, includeDeleted: boolean): Promise<InterimRow[]> {return ctx.engine.executeRaw<InterimRow>(`- SELECT p.slug, p.title, p.frontmatter, ${boundedBodyPrefixSql('p')} AS body, p.deleted_at IS NOT NULL AS deleted,+ SELECT ${INTERIM_COLUMNS}, p.deleted_at IS NOT NULL AS deleted,EXISTS (SELECT 1 FROM tags t WHERE t.page_id = p.id AND t.tag = $4) AS taggedFROM pages pWHERE p.source_id = $1 AND p.type = $2 AND left(p.slug, length($3)) = $3 AND p.slug <> $3 || 'index'${includeDeleted ? '' : ' AND p.deleted_at IS NULL'}@@ -275,13 +283,13 @@ export async function previewFinalize(ctx: OperationContext, opts: AdoptOptions)const entries: FinalizeEntry[] = (await listInterim(ctx, opts, true)).flatMap((row): FinalizeEntry[] => {if (!row.tagged) return row.deleted ? [] : [{ slug: row.slug, card_id: null, state: 'not_adopted' }];const { card } = mapInterimPage(row, opts.prefix);- const content = sha256(JSON.stringify([row.title, row.frontmatter, row.body]));+ const content = originalDigest(row);if (row.deleted) return [{ slug: row.slug, card_id: card?.id ?? null, state: 'deleted', content }];const onShelf = card ? shelf.get(card.id) : undefined;const existing = onShelf ? cardContent(onShelf) : null;const state = card && existing && matchesAdopted(existing, card) ? 'delete' : 'unverified';const other = otherSections(row.body ?? '');- return [{ slug: row.slug, card_id: card?.id ?? null, state, ...(other.length ? { other_sections: other } : {}), content }];+ return [{ slug: row.slug, card_id: card?.id ?? null, state, ...(other.length ? { other_sections: other } : {}), ...(row.long_body || (row.body?.length ?? 0) >= BOUNDED_PREFIX_BYTES ? { unread_tail: true } : {}), content }];});const count = (state: FinalizeEntry['state']) => entries.filter((e) => e.state === state).length;const plan_hash = sha256(JSON.stringify({ v: 1, kind: 'finalize', source_id: opts.sourceId, prefix: opts.prefix,@@ -289,12 +297,14 @@ export async function previewFinalize(ctx: OperationContext, opts: AdoptOptions)const summary = [`${count('delete')} adopted original(s) to soft-delete (restorable for 72 hours), ${count('deleted')} already deleted, ${count('unverified')} whose card is missing or differs, ${count('not_adopted')} not adopted yet (kept).`];const dropping = entries.filter((e) => e.state === 'delete' && e.other_sections);if (dropping.length) summary.push(`${dropping.length} original(s) to delete hold sections the card does not carry (${[...new Set(dropping.flatMap((e) => e.other_sections!))].join(', ')}): show the user, and move what matters into the card with gbrain storage-update before finalizing.`);+ const long = entries.filter((e) => e.state === 'delete' && e.unread_tail).map((e) => e.slug);+ if (long.length) summary.push(`${long.length} original(s) to delete are longer than 64 KiB, so sections past that point were not read (${long.slice(0, 5).join(', ')}): read each with gbrain get before finalizing.`);if (count('unverified')) summary.push('Finalize refuses while an adopted original has no matching card; compare it with gbrain storage-get and fix the card or the record first.');const apply = count('unverified') || !count('delete') ? undefined : [...adoptArgv(opts), '--finalize', '--expect', plan_hash];return { action: 'finalize', dry_run: true, source_id: opts.sourceId, prefix: opts.prefix, entries, plan_hash, summary, ...(apply ? { apply } : {}) };}-/** Soft-delete the adopted originals the preview listed, each bound to the revision read just before. */+/** Soft-delete the adopted originals the preview listed, each only while its content is still what the plan bound (deleted at the revision that matched). */export async function applyFinalize(ctx: OperationContext, opts: AdoptOptions & { expect: string }): Promise<FinalizeApplyResult> {const plan = await previewFinalize(ctx, opts);if (opts.expect !== plan.plan_hash) throw staleHash(opts, opts.expect, true);@@ -307,9 +317,12 @@ export async function applyFinalize(ctx: OperationContext, opts: AdoptOptions &let failure: StepFailure | undefined;for (const entry of plan.entries.filter((e) => e.state === 'delete')) {try {- const snapshot = await ctx.engine.readPageSnapshot(entry.slug, { sourceId: opts.sourceId });- if (!snapshot) continue;- await submitPageMutation(ctx, { operation: 'delete_page', params: { slug: entry.slug, source_id: opts.sourceId, expected_revision: snapshot.revision } });+ const [row] = await ctx.engine.executeRaw<InterimRow & { revision: string | number | null }>(+ `SELECT ${INTERIM_COLUMNS}, p.knowledge_revision AS revision FROM pages p WHERE p.source_id = $1 AND p.slug = $2 AND p.deleted_at IS NULL`, [opts.sourceId, entry.slug]);+ if (!row) continue;+ if (originalDigest(row) !== entry.content) throw opError('preview_changed', `${entry.slug} changed after the finalize preview; it was not deleted.`, 'Preview finalize again and show the user what changed.', { fix: previewFix(opts, true) });+ const expected = row.revision == null ? (await ctx.engine.readPageSnapshot(entry.slug, { sourceId: opts.sourceId }))?.revision : String(row.revision);+ await submitPageMutation(ctx, { operation: 'delete_page', params: { slug: entry.slug, source_id: opts.sourceId, ...(expected ? { expected_revision: expected } : {}) } });deleted.push(entry.slug);} catch (error) {if (!(error instanceof OperationError)) throw error;diff --git a/test/storage-manifest-adopt.test.ts b/test/storage-manifest-adopt.test.tsindex 2136bbb515..ebbdb2ae88 100644--- a/test/storage-manifest-adopt.test.ts+++ b/test/storage-manifest-adopt.test.ts@@ -207,6 +207,7 @@ describe('storage adopt on a repo-less brain', () => {test('finalize: a restore recorded on the card is no difference, other sections are named, and an original edited after the preview refuses', async () => {await interim('storage-manifest/dataset-a', record('dataset-a'));await interim('storage-manifest/dataset-b', record('dataset-b'));+ await call('put_page', { slug: 'storage-manifest/dataset-c', request_id: randomUUID(), content: `---\ntype: stored-object\ntitle: Interim long\n---\n## Record\n\n${FENCE}json\n${JSON.stringify(record('dataset-c'))}\n${FENCE}\n\n## Notes\n\n${'Long notes. '.repeat(6000)}\n\n## Late\n\nPast the read window.\n` });const plan = await previewAdopt(ctx(), opts);await applyAdopt(ctx(), { ...opts, expect: plan.plan_hash, dropFields: [] });await call('storage_update', { id: 'dataset-a', expected_revision: (await call('storage_get', { id: 'dataset-a' })).revision,@@ -214,15 +215,17 @@ describe('storage adopt on a repo-less brain', () => {expect((await call('storage_get', { id: 'dataset-a' })).card.status).toBe('restored');const preview = await previewFinalize(ctx(), opts);- expect(preview.entries.map((e) => [e.slug, e.state, e.other_sections])).toEqual([['storage-manifest/dataset-a', 'delete', ['Restore']], ['storage-manifest/dataset-b', 'delete', ['Restore']]]);- expect(preview.summary.join(' ')).toContain('hold sections the card does not carry (Restore)');+ expect(preview.entries.map((e) => [e.slug, e.state, e.other_sections, e.unread_tail ?? false])).toEqual([['storage-manifest/dataset-a', 'delete', ['Restore'], false],+ ['storage-manifest/dataset-b', 'delete', ['Restore'], false], ['storage-manifest/dataset-c', 'delete', ['Notes'], true]]);+ expect(preview.summary.join(' ')).toContain('hold sections the card does not carry (Restore, Notes)');+ expect(preview.summary.join(' ')).toContain('longer than 64 KiB, so sections past that point were not read (storage-manifest/dataset-c)');expect(preview.apply).toEqual(['gbrain', 'storage', 'adopt', '--finalize', '--expect', preview.plan_hash]);const original = await engine.readPageSnapshot('storage-manifest/dataset-b', { sourceId: 'default' });await call('put_page', { slug: 'storage-manifest/dataset-b', expected_revision: original!.revision, request_id: randomUUID(),content: (await call('get_page', { slug: 'storage-manifest/dataset-b', include_content: true })).content.replace('Ask the archive agent.', 'Ask the archive agent first.') });expect((await refusal(applyFinalize(ctx(), { ...opts, expect: preview.plan_hash })))?.code).toBe('preview_changed');- expect(await live()).toEqual(['storage-manifest/dataset-a', 'storage-manifest/dataset-b']);+ expect(await live()).toEqual(['storage-manifest/dataset-a', 'storage-manifest/dataset-b', 'storage-manifest/dataset-c']);}, 60_000);test('a brain with a Git checkout refuses storage_manifest_missing until storage init; the storage source is not an interim source', async () => {diff --git a/test/storage-manifest.test.ts b/test/storage-manifest.test.tsindex d37d344f58..b0a85a6a79 100644--- a/test/storage-manifest.test.ts+++ b/test/storage-manifest.test.ts@@ -7,6 +7,7 @@* - validation refuses a missing field, a command field, a stamped field, a scanner secret (in a value or an object* key) and every credential shape (env assignment, credential variable, URL userinfo, presigned URL), without* echoing the value;+ * - storage_update keeps the page's access frontmatter (visibility, readable_by) when it rewrites the card;* - the write guard: put_page, remember and forget_fact into the shelf are refused storage_source_managed, a forged* parameter does not open it, and the storage verbs still write;* - a shelf creation that stopped before marking its role (a crash, a concurrent first register) is finished by the@@ -220,6 +221,12 @@ describe('storage shelf on a repo-less brain', () => {expect(third.card.restores.map((r: { to: string }) => r.to)).toEqual(['/scratch/item-b-2', '/scratch/item-b']);expect((await refusal(call('storage_update', { id: 'item-b', expected_revision: third.revision, patch: { reason: 'TOKEN=abc123' } })))?.code).toBe('storage_record_secret');expect((await refusal(call('storage_update', { id: 'item-b', expected_revision: third.revision, patch: { origin: 'import' } })))?.code).toBe('storage_record_invalid');++ await engine.executeRaw(`UPDATE pages SET frontmatter = frontmatter || '{"visibility":"private","readable_by":["alice-example"]}'::jsonb WHERE source_id = 'storage' AND slug = 'item-b'`);+ await call('storage_update', { id: 'item-b', expected_revision: (await call('storage_get', { id: 'item-b' })).revision, patch: { status: 'retired' } });+ const [kept] = await engine.executeRaw<{ visibility: string | null; readers: unknown }>("SELECT frontmatter->>'visibility' AS visibility, frontmatter->'readable_by' AS readers FROM pages WHERE source_id = 'storage' AND slug = 'item-b'");+ expect(kept).toEqual({ visibility: 'private', readers: ['alice-example'] });+ expect((await call('storage_get', { id: 'item-b' })).card.status).toBe('retired');}, 30_000);test('remote callers cannot write; a bound client without the storage grant reads nothing; only a grant naming the shelf reads it', async () => {