Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(trust): provenance stamps are server-owned on every remote page write (#7873)
garrytanb0b9a15e8fe7
diff --git a/src/core/persistence/page-append.ts b/src/core/persistence/page-append.tsindex 5aa99d7d4d..682ac1a67e 100644--- a/src/core/persistence/page-append.ts+++ b/src/core/persistence/page-append.ts@@ -319,7 +319,7 @@ export async function prepareSegmentedSpliceMutation(engine: BrainEngine, row: W`Page ${row.slug} is near the configured page ceiling, so this write refuses on every retry. Start a new page for further text, or ask the owner to raise pages.max_bytes.`,{ fix: pageFix(row.source_id, row.slug) });}- stampPageTrustMarker(row, frontmatter, trust, storedTier);+ stampPageTrustMarker(row, frontmatter, trust, storedTier, stored.page.frontmatter);// As put_page's gate (import-screen.ts settleContentDisposition), over the new text only: the stored text was assessed when it was written.const gate = gateTrust && writeGateApplies(gateTrust.tier, gateConfig) ? await applyTrustAllowRules(engine, assessWriteGate([['title', stored.page.title],['body', stripManagedFenceRows(built.replacements.map(r => Buffer.from(r.bytes).toString('utf8')).join('\n'))], ['frontmatter', frontmatterText(frontmatter)]],diff --git a/src/core/persistence/page-prepare.ts b/src/core/persistence/page-prepare.tsindex c63a70de7d..1cc8abe84e 100644--- a/src/core/persistence/page-prepare.ts+++ b/src/core/persistence/page-prepare.ts@@ -126,14 +126,18 @@ 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; }-/** Canonical stamps belong to the first write, never to a later preparation attempt. */+/** Writes whose caller supplies the page text, and so could supply provenance stamps in its frontmatter. */+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 on+ * every caller-content write a remote caller makes, with or without a repository: the caller's values are dropped and+ * the stored page's kept. A managed put_page (local too) also stamps the first write's provenance.+ */function putProvenance(row: WriteRequest, snapshot: PageSnapshot | null, parsed: ParsedPage): CanonicalProvenance | undefined {- if (row.operation !== 'put_page' || !row.worktree_id) return undefined;- const keys = ['source_kind', 'ingested_via', 'ingested_at'] as const;- for (const key of keys) {- delete parsed.frontmatter[key];- if (snapshot?.page.frontmatter[key] !== undefined) parsed.frontmatter[key] = snapshot.page.frontmatter[key];- }+ const managedPut = row.operation === 'put_page' && !!row.worktree_id;+ if (!managedPut && !(row.authority.remote && CALLER_CONTENT_OPERATIONS.includes(row.operation))) return undefined;+ keepStoredProvenance(parsed.frontmatter, snapshot?.page.frontmatter);+ if (!managedPut) return undefined;const tags = [...new Set([...(snapshot?.tags ?? []), ...parsed.tags])].sort();if (snapshot && !snapshot.page.deleted_at && digest(canonical(snapshot.page, snapshot.tags)) === digest(canonical(parsed, tags))) {return undefined;@@ -151,6 +155,13 @@ function putProvenance(row: WriteRequest, snapshot: PageSnapshot | null, parsed:Object.assign(parsed.frontmatter, stamp);return stamp;}+/** The provenance stamps of `stored` replace whatever `frontmatter` carries for them (removed when the stored page has none). */+export function keepStoredProvenance(frontmatter: Record<string, unknown>, stored: Record<string, unknown> | null | undefined): void {+ for (const key of ['source_kind', 'ingested_via', 'ingested_at'] as const) {+ delete frontmatter[key];+ if (stored?.[key] !== undefined) frontmatter[key] = stored[key];+ }+}export { isNeverFiledDerivedPage };/*** A live page whose canonical file is absent publishes to the database only@@ -890,7 +901,7 @@ async function prepareInlineOrSegmentedMutation(unbounded: BrainEngine, row: WriprepareFrontmatter: page => {provenance = putProvenance(row, snapshot, page);suppliedTrustMarker = page.frontmatter.trust_tier;- stampPageTrustMarker(row, page.frontmatter, trust, storedTier);+ stampPageTrustMarker(row, page.frontmatter, trust, storedTier, snapshot?.page.frontmatter);if (privateRequest) assertPrivateRequestKept(row, page.frontmatter);},prepare: async value => { prepared = value; return value.result; },diff --git a/src/core/persistence/upload-streamed.ts b/src/core/persistence/upload-streamed.tsindex f8428163aa..9b16cfef83 100644--- a/src/core/persistence/upload-streamed.ts+++ b/src/core/persistence/upload-streamed.ts@@ -34,7 +34,7 @@ import type { PageSnapshot } from '../page-state/types.ts';import { PAGE_MAX_BYTES } from '../page-size-policy.ts';import { bodyStagingGoneError } from '../engine-sql/page-body.ts';import { ownerSourceGateInput, writeTrustOfGate } from './attribution.ts';-import { pageDatabaseOnlyPublication } from './page-prepare.ts';+import { keepStoredProvenance, pageDatabaseOnlyPublication } from './page-prepare.ts';import { pageIdentityError } from './page-identity.ts';import { remoteLinkHint } from './page-advisories.ts';import { stagedUploadParts, stagedUploadWork, type StagingBodyRef } from './page-upload.ts';@@ -116,7 +116,10 @@ export async function prepareStreamedUpload(engine: BrainEngine, row: WriteRequeconst gate = pageGateTrust(row, trust, storedTier);return gate ? { tier: gate.tier, origin: { channel: gate.origin?.channel ?? row.operation }, requestId: null } : ownerSourceGateInput(engine, row.source_id, frontmatter);},- stamp: (frontmatter: Record<string, unknown>) => stampPageTrustMarker(row, frontmatter, trust, storedTier),+ stamp: (frontmatter: Record<string, unknown>) => {+ keepStoredProvenance(frontmatter, snapshot?.page.frontmatter);+ stampPageTrustMarker(row, frontmatter, trust, storedTier, snapshot?.page.frontmatter);+ },} } : {}) },coordinated: { snapshot, sha256: ref.sha256, slug: row.slug, prepare: async value => { ready = value; return value.result; },owner: { kind: 'put', principalKind: row.principal_kind, principalId: row.principal_id, baseRevision: snapshot?.revision ?? null } } }, stat, policy)diff --git a/src/core/trust/page-write.ts b/src/core/trust/page-write.tsindex eb1f454deb..91e3574a8c 100644--- a/src/core/trust/page-write.ts+++ b/src/core/trust/page-write.ts@@ -67,10 +67,14 @@ export async function storedPageTier(engine: BrainEngine, sourceId: string, slug* #6550: a stored `unknown` means "not classified yet", not "known unverified", so it does not lower the* marker: the marker names the writer's tier and the row keeps min(writer, stored) until the backfill* classifies it. An explicit `trust_tier: unknown` already in the frontmatter still caps (stampTrustMarker).+ * #7873: an unclassified page's own lowering markers (`storedFrontmatter`, the page before the write) still cap the+ * marker, so a write that removes one (a `ingested_via: webhook` stamp) cannot raise the page when it is re-derived.*/-export function stampPageTrustMarker(row: Pick<WriteRequest, 'operation'>, frontmatter: Record<string, unknown>, trust: WriteTrust | undefined, stored: TrustTier | null): void {+export function stampPageTrustMarker(row: Pick<WriteRequest, 'operation'>, frontmatter: Record<string, unknown>, trust: WriteTrust | undefined, stored: TrustTier | null,+ storedFrontmatter?: Record<string, unknown> | null): void {if (!trust || !CONTENT_OPERATIONS.includes(row.operation)) return;- const tier = stored && stored !== 'unknown' ? minTrust(trust.tier, stored) : trust.tier;+ const prior = stored && stored !== 'unknown' ? [stored] : frontmatterTrustCaps(storedFrontmatter);+ const tier = minTrust(trust.tier, ...prior);const stamped = stampTrustMarker(frontmatter, tier);if (stamped !== frontmatter) frontmatter.trust_tier = stamped.trust_tier;}diff --git a/test/large-pages/upload-provenance-7873.test.ts b/test/large-pages/upload-provenance-7873.test.tsnew file mode 100644index 0000000000..5c507a9a09--- /dev/null+++ b/test/large-pages/upload-provenance-7873.test.ts@@ -0,0 +1,67 @@+/**+ * #7873: a remote upload over the single-string ceiling (the segmented streamed preparation, upload-streamed.ts)+ * 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.+ * 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';+import { createHash, randomUUID } from 'node:crypto';+import type { BrainEngine } from '../../src/core/engine.ts';+import type { GBrainConfig } from '../../src/core/config.ts';+import { PGLiteEngine } from '../../src/core/pglite-engine.ts';+import { operations, OperationError, type OperationContext } from '../../src/core/operations.ts';+import { stagedUploadWork } from '../../src/core/persistence/page-upload.ts';+import { isolatedPersistencePostgres } from '../helpers/persistence-postgres.ts';+import { testBackends } from '../helpers/test-backends.ts';++const MiB = 1024 ** 2;+const PART_CHARS = 3_900_000;+const op = (name: string) => operations.find(o => o.name === name)!;+const hex = (text: string) => createHash('sha256').update(Buffer.from(text, 'utf8')).digest('hex');++for (const kind of testBackends()) {+ describe(`#7873 streamed upload provenance stamps (${kind})`, () => {+ let engine: BrainEngine;+ let close: () => Promise<void>;+ const ctx = (): OperationContext => ({+ engine, config: {} as GBrainConfig, logger: { info() {}, warn() {}, error() {} }, dryRun: false, remote: true, sourceId: 'default',+ transport: 'http', inboundFrameBytes: 4 * MiB, auth: { token: 'fixture', clientId: 'upload-stamps', principal: { kind: 'oauth_client', id: 'upload-stamps' },+ scopes: ['read', 'write'], sourceId: 'default', allowedSources: ['default'] } } as unknown as OperationContext);+ const call = async (name: string, params: Record<string, unknown>) => await op(name).handler(ctx(), params) as Record<string, any>;++ beforeAll(async () => {+ if (kind === 'postgres') ({ engine, close } = await isolatedPersistencePostgres(process.env.DATABASE_URL!));+ else { engine = new PGLiteEngine(); await engine.connect({}); await engine.initSchema(); close = () => engine.disconnect(); }+ await engine.executeRaw(`INSERT INTO oauth_clients(client_id,client_secret_hash,client_name,scope,source_id)+ VALUES('upload-stamps','fixture-hash','upload-client','read write','default') ON CONFLICT (client_id) DO NOTHING`);+ await engine.executeRaw("INSERT INTO config (key, value) VALUES ('write_gate.agent_mode', 'off') ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value");+ }, 120_000);+ afterAll(async () => { await close(); });++ test('a 25 MiB remote upload stores none of the caller\'s stamps', async () => {+ const slug = 'notes/huge-stamped';+ const line = 'We agreed to ship the review checklist first and revisit pricing next week.\n\n';+ const text = `---\ntitle: Huge stamped\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: 'create', 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({ source_kind: undefined, ingested_via: undefined, ingested_at: undefined });+ }, 600_000);+ });+}diff --git a/test/provenance-stamps-7873.test.ts b/test/provenance-stamps-7873.test.tsnew file mode 100644index 0000000000..4f62633a32--- /dev/null+++ b/test/provenance-stamps-7873.test.ts@@ -0,0 +1,186 @@+/**+ * #7873: provenance stamps (source_kind / ingested_via / ingested_at) are server-owned on every caller-content+ * write a remote caller makes, and removing a page's own lowering marker never raises it when it is re-derived.+ *+ * 1. Protects: a remote edit_page, put_page (with or without a repository) and capture cannot write, change or drop+ * provenance stamps in the page file or the stored frontmatter; an edit that only forges stamps is a no-op; on an+ * unclassified page (stored tier unknown) a remote edit that strips a lowering marker (an ingested_via: webhook+ * stamp, a third-party transcript_import) stamps the trust marker at the stripped marker's tier, so a later sync+ * (ownerPageTrust over the file) or the trust backfill (frontmatter caps) does not raise the page.+ * 2. Fails when: a remote caller's stamp reaches the file or the database, or a re-derive after a remote edit+ * yields a higher tier than the page's own markers allowed before the edit.+ * 3. Runs on PGLite, and on Postgres when DATABASE_URL is set; repository and repo-less brains (no embedding, no+ * model calls).+ */+import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';+import * as fs from 'node:fs';+import * as os from 'node:os';+import * as path from 'node:path';+import type { BrainEngine } from '../src/core/engine.ts';+import type { OperationContext } from '../src/core/operations.ts';+import { operations } from '../src/core/operations.ts';+import { PGLiteEngine } from '../src/core/pglite-engine.ts';+import { parseMarkdown, serializePageToMarkdown } from '../src/core/markdown.ts';+import { resetGateway } from '../src/core/ai/gateway.ts';+import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';+import { claimWorktree } from '../src/core/persistence/ownership.ts';+import { registerLocalWriter, withVerifiedLocalRegistration, type LocalRegistration } from '../src/core/persistence/identity.ts';+import { frontmatterTrustCaps, ownerPageTrust } from '../src/core/trust/channel.ts';+import { minTrust } from '../src/core/trust/tier.ts';+import { withEnv } from './helpers/with-env.ts';+import { withManagedFixtureWrite } from './helpers/managed-e2e-fixture-write.ts';+import { resetPgliteState } from './helpers/reset-pglite.ts';+import { isolatedPersistencePostgres } from './helpers/persistence-postgres.ts';+import { testBackends } from './helpers/test-backends.ts';++const STORED = { source_kind: 'webhook', ingested_via: 'webhook', ingested_at: '2026-01-02T03:04:05.000Z' };+const FORGED = { source_kind: 'put_page', ingested_via: 'put_page', ingested_at: '2020-01-01T00:00:00.000Z' };+const stampsOf = (fm: Record<string, unknown>) => ({ source_kind: fm.source_kind, ingested_via: fm.ingested_via, ingested_at: fm.ingested_at });+const lowest = (fm: Record<string, unknown>) => { const caps = frontmatterTrustCaps(fm); return caps.length ? minTrust(caps[0]!, ...caps.slice(1)) : null; };++for (const kind of testBackends()) {+ for (const repo of [true, false]) {+ describe(`#7873 provenance stamps (${kind}, ${repo ? 'repository' : 'repo-less'} brain)`, () => {+ let engine: BrainEngine;+ let close: () => Promise<void>;+ let tmpRoot: string;+ let brainDir: string;+ let registration: LocalRegistration | null = null;++ beforeAll(async () => {+ if (kind === 'pglite') { engine = new PGLiteEngine(); await engine.connect({}); await engine.initSchema(); }+ }, 120_000);+ afterAll(async () => { if (kind === 'pglite') { await disposePersistenceConsumer(engine); await engine.disconnect(); } resetGateway(); });+ beforeEach(async () => {+ if (kind === 'postgres') ({ engine, close } = await isolatedPersistencePostgres(process.env.DATABASE_URL!));+ else { await disposePersistenceConsumer(engine); await resetPgliteState(engine as PGLiteEngine); }+ resetGateway();+ tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'gbrain-7873-'));+ brainDir = path.join(tmpRoot, 'brain');+ fs.mkdirSync(brainDir, { recursive: true });+ if (repo) await engine.setConfig('sync.repo_path', brainDir);+ else await engine.executeRaw("DELETE FROM config WHERE key = 'sync.repo_path'");+ // Postgres writes through to a repository only from a bound source, through a verified local writer.+ registration = null;+ if (repo && kind === 'postgres') {+ registration = await withEnv({ GBRAIN_HOME: path.join(tmpRoot, 'home') }, async () => {+ await claimWorktree(engine, 'default', brainDir);+ return registerLocalWriter(engine, 'stdio', { sourceIds: ['default'], operations: null, scopes: ['read', 'write'], slugPrefixes: ['inbox'] });+ });+ }+ }, 120_000);+ afterEach(async () => {+ await disposePersistenceConsumer(engine);+ if (kind === 'postgres') await close();+ fs.rmSync(tmpRoot, { recursive: true, force: true });+ });++ const ctx = (remote = true) => ({ engine, config: { engine: kind, embedding_disabled: true }, logger: { info() {}, warn() {}, error() {} },+ dryRun: false, remote, sourceId: 'default' }) as unknown as OperationContext;+ const call = (name: string, params: Record<string, unknown>, c = ctx()) =>+ withEnv({ GBRAIN_HOME: path.join(tmpRoot, 'home') }, () => {+ const run = () => operations.find(o => o.name === name)!.handler(c, params);+ return registration ? withVerifiedLocalRegistration(engine, registration, run) : run();+ }) as Promise<Record<string, any>>;+ const fileFrontmatter = (slug: string) => parseMarkdown(fs.readFileSync(path.join(brainDir, `${slug}.md`), 'utf8'), slug).frontmatter;+ const page = async (slug: string) => (await engine.readPageSnapshot(slug, { sourceId: 'default' }))!;+ /** A page as an ingestion capture left it: stamped external, and unclassified (stored tier unknown) or classified. */+ const seed = async (slug: string, frontmatter: Record<string, unknown>, tier: string) => {+ const write = async (tx: BrainEngine) => {+ await tx.putPage(slug, { type: 'note', title: 'Seeded', compiled_truth: 'Captured body', timeline: '', frontmatter,+ source_kind: 'webhook', ingested_via: 'webhook' } as never);+ await tx.executeRaw('UPDATE pages SET trust_tier = $1, ingested_at = $4::timestamptz WHERE source_id = $2 AND slug = $3', [tier, 'default', slug, STORED.ingested_at]);+ };+ await (repo && kind === 'postgres' ? withManagedFixtureWrite(engine, ['default'], write) : write(engine));+ const snapshot = await page(slug);+ if (repo) {+ fs.mkdirSync(path.dirname(path.join(brainDir, slug)), { recursive: true });+ fs.writeFileSync(path.join(brainDir, `${slug}.md`), serializePageToMarkdown(snapshot.page, snapshot.tags));+ }+ return snapshot;+ };+ const read = (slug: string) => call('get_page', { slug, include_content: true }) as Promise<{ content: string; revision: string }>;+ const edit = async (slug: string, pairs: Array<[string, string]>) => {+ const current = await read(slug);+ return call('edit_page', { slug, expected_revision: current.revision, edits: pairs.map(([old_text, new_text]) => ({ old_text, new_text })) });+ };+ const forgeAll = (): Array<[string, string]> => [['source_kind: webhook', `source_kind: ${FORGED.source_kind}`],+ ['ingested_via: webhook', `ingested_via: ${FORGED.ingested_via}`], [`ingested_at: '${STORED.ingested_at}'`, `ingested_at: '${FORGED.ingested_at}'`]];++ test('a remote edit_page keeps the stored stamps in the file and the database, and the page does not re-derive higher', async () => {+ const slug = 'inbox/edit-stamps';+ const before = await seed(slug, STORED, 'unknown');+ const prior = ownerPageTrust({ frontmatter: before.page.frontmatter, channel: 'sync' }).tier;+ expect(prior).toBe('external_untrusted');+ expect((await read(slug)).content).toContain(`ingested_at: '${STORED.ingested_at}'`);+ const result = await edit(slug, [...forgeAll(), ['Captured body', 'Captured body, edited']]);+ expect(result.noop).toBe(false);+ const after = await page(slug);+ expect(after.page.compiled_truth).toContain('edited');+ expect(stampsOf(after.page.frontmatter)).toEqual(STORED);+ expect(lowest(after.page.frontmatter)).toBe('external_untrusted');+ if (repo) {+ const file = fileFrontmatter(slug);+ expect(stampsOf(file)).toEqual(STORED);+ expect(ownerPageTrust({ frontmatter: file, channel: 'sync' }).tier).toBe(prior);+ }+ });++ test('a remote edit_page that only forges stamps is a no-op', async () => {+ const slug = 'inbox/edit-noop';+ const before = await seed(slug, STORED, 'external_untrusted');+ const result = await edit(slug, forgeAll());+ expect(result.noop).toBe(true);+ expect((await page(slug)).revision).toBe(before.revision);+ if (repo) expect(stampsOf(fileFrontmatter(slug))).toEqual(STORED);+ });++ test('a remote edit_page that drops a stamp from an unclassified page stamps the marker at the dropped stamp\'s tier', async () => {+ const slug = 'inbox/edit-drop';+ await seed(slug, { ingested_via: 'webhook' }, 'unknown');+ await edit(slug, [['ingested_via: webhook\n', ''], ['Captured body', 'Captured body, edited']]);+ const after = await page(slug);+ expect(after.page.frontmatter.ingested_via).toBe('webhook');+ expect(after.page.frontmatter.trust_tier).toBe('external_untrusted');+ if (repo) expect(ownerPageTrust({ frontmatter: fileFrontmatter(slug), channel: 'sync' }).tier).toBe('external_untrusted');+ });++ test('a remote edit_page that strips another lowering marker from an unclassified page does not raise it on re-derive', async () => {+ const slug = 'inbox/edit-transcript';+ const before = await seed(slug, { transcript_import: { harness: 'third-party-example' } }, 'unknown');+ expect(lowest(before.page.frontmatter)).toBe('external_untrusted');+ const current = await read(slug);+ const stripped = serializePageToMarkdown({ ...before.page, frontmatter: {}, compiled_truth: 'Captured body, edited' }, before.tags);+ await call('put_page', { slug, content: stripped, expected_revision: current.revision });+ const after = await page(slug);+ expect(after.page.frontmatter.trust_tier).toBe('external_untrusted');+ expect(lowest(after.page.frontmatter)).toBe('external_untrusted');+ if (repo) expect(ownerPageTrust({ frontmatter: fileFrontmatter(slug), channel: 'sync' }).tier).toBe('external_untrusted');+ });++ test('a remote put_page cannot change the stamps of an existing page', async () => {+ const slug = 'inbox/put-existing';+ const before = await seed(slug, STORED, 'external_untrusted');+ const current = await read(slug);+ const forged = serializePageToMarkdown({ ...before.page, frontmatter: FORGED, compiled_truth: 'Captured body, replaced' }, before.tags);+ await call('put_page', { slug, content: forged, expected_revision: current.revision });+ const after = await page(slug);+ expect(after.page.compiled_truth).toContain('replaced');+ expect(stampsOf(after.page.frontmatter)).toEqual(STORED);+ if (repo) expect(stampsOf(fileFrontmatter(slug))).toEqual(STORED);+ });++ 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 });+ await call('capture', { slug: 'inbox/capture-new', content });+ for (const slug of ['inbox/put-new', 'inbox/capture-new']) {+ const stored = (await page(slug)).page.frontmatter;+ expect(JSON.stringify(stampsOf(stored))).not.toContain('forged');+ expect(stored.ingested_at).not.toBe(FORGED.ingested_at);+ if (repo) expect(JSON.stringify(stampsOf(fileFrontmatter(slug)))).not.toContain('forged');+ }+ });+ });+ }+}