Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: pre-landing review fixes (#7873)
garrytanac7f6aa99af0
diff --git a/src/core/persistence/page-prepare.ts b/src/core/persistence/page-prepare.tsindex 1cc8abe84e..d608e15a78 100644--- a/src/core/persistence/page-prepare.ts+++ b/src/core/persistence/page-prepare.ts@@ -126,7 +126,10 @@ function canonical(page: Pick<Page, 'type' | 'title' | 'compiled_truth' | 'timelfrontmatter: comparableFrontmatter(page.frontmatter), tags: [...new Set(tags)].sort() };}interface CanonicalProvenance { source_kind: string; ingested_via: string; ingested_at: string; }-/** Writes whose caller supplies the page text, and so could supply provenance stamps in its frontmatter. */+/**+ * Writes whose caller supplies the page text, and so could supply provenance stamps in its frontmatter. Unlike+ * trust/page-write.ts CONTENT_OPERATIONS, revert_version and restore_page are absent: they replay a stored version.+ */const CALLER_CONTENT_OPERATIONS = ['put_page', 'edit_page', 'append_page', 'capture'];/*** Canonical stamps belong to the first write, never to a later preparation attempt. #7873: they are server-owned ondiff --git a/test/large-pages/upload-provenance-7873.test.ts b/test/large-pages/upload-provenance-7873.test.tsindex 5c507a9a09..b51c5d015d 100644--- a/test/large-pages/upload-provenance-7873.test.ts+++ b/test/large-pages/upload-provenance-7873.test.ts@@ -3,8 +3,9 @@* cannot supply provenance stamps, as a remote put_page cannot.** 1. Protects: commit_page_upload of a 25 MiB page whose frontmatter carries source_kind / ingested_via /- * ingested_at stores none of the caller's values.- * 2. Fails when: a caller-written stamp reaches the stored frontmatter through the streamed path.+ * ingested_at stores none of the caller's values; a replace keeps the stamps of the page it replaces.+ * 2. Fails when: a caller-written stamp reaches the stored frontmatter through the streamed path, or a replace drops+ * the stored stamps.* 3. Runs on PGLite, and on Postgres when DATABASE_URL is set (no embedding, no model calls).*/import { afterAll, beforeAll, describe, expect, test } from 'bun:test';@@ -63,5 +64,31 @@ for (const kind of testBackends()) {expect({ source_kind: frontmatter.source_kind, ingested_via: frontmatter.ingested_via, ingested_at: frontmatter.ingested_at }).toEqual({ source_kind: undefined, ingested_via: undefined, ingested_at: undefined });}, 600_000);++ test('a 25 MiB remote replace keeps the stored stamps of the page it replaces', async () => {+ const slug = 'notes/huge-restamped';+ const stored = { source_kind: 'webhook', ingested_via: 'webhook', ingested_at: '2026-01-02T03:04:05.000Z' };+ await engine.putPage(slug, { type: 'note', title: 'Huge restamped', compiled_truth: 'Captured body', timeline: '', frontmatter: stored,+ source_kind: 'webhook', ingested_via: 'webhook' } as never);+ const revision = (await engine.readPageSnapshot(slug, { sourceId: 'default' }))!.revision;+ const line = 'We agreed to ship the review checklist first and revisit pricing next week.\n\n';+ const text = `---\ntitle: Huge restamped\nsource_kind: forged-kind\ningested_via: forged-channel\ningested_at: '2020-01-01T00:00:00.000Z'\n---\n\n${line.repeat(Math.ceil(25 * MiB / line.length))}End.`;+ const session = await call('begin_page_upload', { slug, mode: 'replace', expected_revision: revision, total_bytes: Buffer.byteLength(text), sha256: hex(text), request_id: randomUUID() });+ for (let part = 0, at = 0; at < text.length; part++, at += PART_CHARS) {+ const piece = text.slice(at, at + PART_CHARS);+ await call('upload_page_part', { upload_id: session.upload_id, part, text: piece, part_sha256: hex(piece) });+ }+ const streamed = stagedUploadWork.streamed;+ for (let attempt = 0; ; attempt++) {+ try { expect((await call('commit_page_upload', { upload_id: session.upload_id, wait_ms: 30_000 })).state).toBe('committed'); break; }+ catch (error) { if (!(error instanceof OperationError) || error.code !== 'write_pending' || attempt > 40) throw error; }+ }+ expect(stagedUploadWork.streamed).toBe(streamed + 1);+ const [row] = await engine.executeRaw<{ body_storage: string; frontmatter: Record<string, unknown> | string }>(+ 'SELECT body_storage, frontmatter FROM pages WHERE source_id = $1 AND slug = $2', ['default', slug]);+ expect(row!.body_storage).toBe('segmented');+ const frontmatter = typeof row!.frontmatter === 'string' ? JSON.parse(row!.frontmatter) : row!.frontmatter;+ expect({ source_kind: frontmatter.source_kind, ingested_via: frontmatter.ingested_via, ingested_at: frontmatter.ingested_at }).toEqual(stored);+ }, 600_000);});}diff --git a/test/provenance-stamps-7873.test.ts b/test/provenance-stamps-7873.test.tsindex 4f62633a32..a9114fcadd 100644--- a/test/provenance-stamps-7873.test.ts+++ b/test/provenance-stamps-7873.test.ts@@ -170,6 +170,27 @@ for (const kind of testBackends()) {if (repo) expect(stampsOf(fileFrontmatter(slug))).toEqual(STORED);});+ // Value: protects=remote append_page on an unclassified captured page keeps stored stamps and the lowering marker; fails_when=append re-derives the page higher or drops stamps; why_new=prior rows cover edit_page/put_page/capture only; seam=none; no_claim=segmented splice path (inline page only)+ test('a remote append_page keeps the stored stamps and does not raise an unclassified page', async () => {+ const slug = 'inbox/append-stamps';+ await seed(slug, STORED, 'unknown');+ await call('append_page', { slug, text: 'Appended line', request_id: crypto.randomUUID(), expected_revision: (await read(slug)).revision });+ const after = await page(slug);+ expect(after.page.compiled_truth).toContain('Appended line');+ expect(stampsOf(after.page.frontmatter)).toEqual(STORED);+ expect(lowest(after.page.frontmatter)).toBe('external_untrusted');+ if (repo) expect(stampsOf(fileFrontmatter(slug))).toEqual(STORED);+ });++ // Value: protects=a local (remote=false) edit_page can still change provenance stamps as before #7873; fails_when=the server-owned stamp rule is applied to local callers; why_new=every other row is remote=true; seam=none; no_claim=managed local put_page (put-page-provenance covers it)+ test.skipIf(repo)('a local edit_page keeps its old behaviour and can change stamps on a repo-less brain', async () => {+ const slug = 'inbox/local-edit';+ await seed(slug, STORED, 'external_untrusted');+ const current = await read(slug);+ await call('edit_page', { slug, expected_revision: current.revision, edits: forgeAll().map(([old_text, new_text]) => ({ old_text, new_text })) }, ctx(false));+ expect(stampsOf((await page(slug)).page.frontmatter)).toEqual(FORGED);+ });+test('a remote put_page and capture of a new page cannot supply stamps', async () => {const content = `---\ntitle: New page\nsource_kind: forged-kind\ningested_via: forged-channel\ningested_at: '${FORGED.ingested_at}'\n---\n\nFresh body`;await call('put_page', { slug: 'inbox/put-new', content });