Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(concepts): run the W9F item 3 file-recheck cases on Postgres too
time-attackd38b2416a75f
diff --git a/test/cycle/concept-publication-file-recheck.test.ts b/test/cycle/concept-publication-file-recheck.test.tsindex 70f5ce9d07..4c6bbad186 100644--- a/test/cycle/concept-publication-file-recheck.test.ts+++ b/test/cycle/concept-publication-file-recheck.test.ts@@ -17,50 +17,50 @@ import { execFileSync } from 'node:child_process';import { chmodSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';-import { PGLiteEngine } from '../../src/core/pglite-engine.ts';+import type { BrainEngine } from '../../src/core/engine.ts';+import { isolatedSharedSkillsEngine } from '../helpers/shared-skills-engine.ts';+import { requirePostgresTestDatabase, testBackends } from '../helpers/test-backends.ts';import { importFromContent } from '../../src/core/import-file.ts';import { serializeMarkdown } from '../../src/core/markdown.ts';import { publishClassicConcept } from '../../src/core/cycle/concept-publication.ts';import { _resetWriteThroughCacheForTest, writePageThrough } from '../../src/core/write-through.ts';-import { resetPgliteState } from '../helpers/reset-pglite.ts';const SLUG = 'concepts/launch-dates';const BASELINE = 'Launch dates slip when nobody owns them.';const SYNTHESIZED = 'SYNTHESIZED: launch dates need a single owner.';-let engine: PGLiteEngine;-let repo: string;-let file: string;+const frontmatter = { synthesized_by: 'synthesize_concepts-v0.41', tier: 2, member_hash: 'h1', visibility: 'world' };-beforeAll(async () => {- engine = new PGLiteEngine();- await engine.connect({});- await engine.initSchema();-}, 60000);+for (const backend of testBackends()) describe(`publishClassicConcept file recheck (W9F item 3, ${backend})`, () => {+ let engine: BrainEngine;+ let close: () => Promise<void>;+ let repo: string;+ let file: string;-afterAll(async () => {- await engine.disconnect();-});+ beforeAll(async () => {+ ({ engine, close } = await isolatedSharedSkillsEngine(backend === 'postgres' ? requirePostgresTestDatabase() : undefined));+ }, 120000);-const frontmatter = { synthesized_by: 'synthesize_concepts-v0.41', tier: 2, member_hash: 'h1', visibility: 'world' };+ afterAll(async () => {+ await close();+ });-beforeEach(async () => {- await resetPgliteState(engine);- _resetWriteThroughCacheForTest();- repo = mkdtempSync(join(tmpdir(), 'gbrain-concept-recheck-'));- execFileSync('git', ['init', '-q'], { cwd: repo });- await engine.executeRaw("UPDATE sources SET local_path = $1 WHERE id = 'default'", [repo]);- await importFromContent(engine, SLUG, serializeMarkdown(frontmatter, BASELINE, '', { type: 'concept', title: 'launch dates', tags: ['ops'] }), { noEmbed: true });- const written = await writePageThrough(engine, SLUG, { sourceId: 'default' });- expect(written.written).toBe(true);- file = written.path!;-});+ beforeEach(async () => {+ await engine.executeRaw('DELETE FROM pages');+ _resetWriteThroughCacheForTest();+ repo = mkdtempSync(join(tmpdir(), 'gbrain-concept-recheck-'));+ execFileSync('git', ['init', '-q'], { cwd: repo });+ await engine.executeRaw("UPDATE sources SET local_path = $1 WHERE id = 'default'", [repo]);+ await importFromContent(engine, SLUG, serializeMarkdown(frontmatter, BASELINE, '', { type: 'concept', title: 'launch dates', tags: ['ops'] }), { noEmbed: true });+ const written = await writePageThrough(engine, SLUG, { sourceId: 'default' });+ expect(written.written).toBe(true);+ file = written.path!;+ });-const importPage = (markdown: string) => importFromContent(engine, SLUG, markdown, { noEmbed: true });-const publish = (opts: { importPage?: (markdown: string) => Promise<unknown> } = {}) => publishClassicConcept(engine, SLUG, 'default',- { ...frontmatter, member_hash: 'h2' }, SYNTHESIZED, BASELINE, { writeThrough: false, importPage: opts.importPage ?? importPage });-const codeOf = async (p: Promise<unknown>) => p.then(() => 'published', (err: { code?: string }) => err.code ?? String(err));+ const importPage = (markdown: string) => importFromContent(engine, SLUG, markdown, { noEmbed: true });+ const publish = (opts: { importPage?: (markdown: string) => Promise<unknown> } = {}) => publishClassicConcept(engine, SLUG, 'default',+ { ...frontmatter, member_hash: 'h2' }, SYNTHESIZED, BASELINE, { writeThrough: false, importPage: opts.importPage ?? importPage });+ const codeOf = async (p: Promise<unknown>) => p.then(() => 'published', (err: { code?: string }) => err.code ?? String(err));-describe('publishClassicConcept file recheck (W9F item 3)', () => {test('a narrative edit made only to the file defers and survives', async () => {writeFileSync(file, readFileSync(file, 'utf-8').replace(BASELINE, `${BASELINE}\n\nUSER EDIT: the board owns launch dates.`));expect(await codeOf(publish())).toBe('revision_conflict');diff --git a/test/e2e/concept-publication-file-recheck-postgres.test.ts b/test/e2e/concept-publication-file-recheck-postgres.test.tsnew file mode 100644index 0000000000..ba1d02ef76--- /dev/null+++ b/test/e2e/concept-publication-file-recheck-postgres.test.ts@@ -0,0 +1,3 @@+import { registerPostgresTests } from '../helpers/test-backends.ts';++await registerPostgresTests(() => import('../cycle/concept-publication-file-recheck.test.ts'));