Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

propose_takes / extract_atoms: todo tests for the #5211 atom stamp and atom candidate filter

garrytandcf941572eaa
diff --git a/test/extract-atoms-dream-generated-stamp.test.ts b/test/extract-atoms-dream-generated-stamp.test.ts
new file mode 100644
index 0000000000..5eb15aa5d7
--- /dev/null
+++ b/test/extract-atoms-dream-generated-stamp.test.ts
@@ -0,0 +1,64 @@
+// #5211 (wave 14 PR3 row P3.8): an atom extract_atoms writes carries
+// `dream_generated: true`, so the anti-loop guards that key on that flag
+// (extract_atoms' own input exclusion, facts and chronicle eligibility,
+// transcript discovery, propose_takes' candidate filter) see the phase's own
+// output. Atoms carried `extracted_by` only.
+//
+// The stamp is one additive line in `src/core/cycle/extract-atoms.ts`, a wave
+// 13 hot file: the hunk lives in `~/.capy/work/w14/pr3/stack-hunks/` and
+// stacks behind wave 13 PR3 (#6446). Flip `test.todo` to `test` when it lands.
+//
+// Protects: the written atom's frontmatter. Fails when: the write site drops
+// the flag. Why not existing coverage: no test reads `dream_generated` off an
+// atom. Seams: `_transcripts`, `_pages`, `_chat` already exist.
+
+import { describe, test, expect, beforeAll, afterAll, beforeEach } from 'bun:test';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { runPhaseExtractAtoms } from '../src/core/cycle/extract-atoms.ts';
+import { resetPgliteState } from './helpers/reset-pglite.ts';
+import type { ChatResult, ChatOpts } from '../src/core/ai/gateway.ts';
+
+let engine: PGLiteEngine;
+beforeAll(async () => {
+ engine = new PGLiteEngine();
+ await engine.connect({});
+ await engine.initSchema();
+}, 120_000);
+afterAll(async () => { await engine.disconnect(); });
+beforeEach(async () => { await resetPgliteState(engine); });
+
+function chatReturning(atoms: unknown[]): (o: ChatOpts) => Promise<ChatResult> {
+ const text = JSON.stringify(atoms);
+ return async () => ({
+ text,
+ blocks: [{ type: 'text', text }],
+ stopReason: 'end',
+ usage: { input_tokens: 100, output_tokens: 10, cache_read_tokens: 0, cache_creation_tokens: 0 },
+ model: 'anthropic:claude-haiku-4-5',
+ providerId: 'anthropic',
+ });
+}
+
+const SOURCE = ['Meeting notes, 12 March.', 'The budget is a ceiling and not a target.', 'We agreed to revisit in April.']
+ .join('\n').padEnd(600, ' .');
+
+describe('extract_atoms stamps its atoms dream_generated (#5211, P3.8)', () => {
+ test.todo('P3.8: a written atom carries dream_generated: true next to extracted_by', async () => {
+ await runPhaseExtractAtoms(engine, {
+ sourceId: 'default',
+ _transcripts: [{ filePath: '/tmp/dg1.txt', content: SOURCE, contentHash: 'c3'.repeat(8) }],
+ _pages: [],
+ _chat: chatReturning([{
+ title: 'Budgets are ceilings',
+ atom_type: 'insight',
+ body: 'A budget caps spend; it is not a goal to reach.',
+ source_quote: 'The budget is a ceiling and not a target.',
+ }]),
+ });
+ const pages = await engine.listPages({ type: 'atom', limit: 10 });
+ expect(pages.length).toBe(1);
+ const atom = (await engine.getPage(pages[0]!.slug, { sourceId: 'default' }))!;
+ expect(atom.frontmatter.dream_generated).toBe(true);
+ expect(String(atom.frontmatter.extracted_by)).toStartWith('extract_atoms');
+ });
+});
diff --git a/test/propose-takes-atom-candidates.test.ts b/test/propose-takes-atom-candidates.test.ts
new file mode 100644
index 0000000000..374b8908f5
--- /dev/null
+++ b/test/propose-takes-atom-candidates.test.ts
@@ -0,0 +1,49 @@
+// #5211 (wave 14 PR3 row P3.8): propose_takes never proposes from atoms. Wave
+// 13 PR3 (#6446, its #5212 row) excludes the writer-stamped dream output
+// (`dream_generated`, `extracted_by: extract_atoms…`, `synthesized_by:
+// synthesize_concepts…`); the remaining gap is a legacy `type = 'atom'` page
+// that carries neither stamp. The one-line `type IS DISTINCT FROM 'atom'` arm
+// is a stack hunk on `src/core/cycle/propose-takes.ts` (wave 13 hot file) in
+// `~/.capy/work/w14/pr3/stack-hunks/`. Flip `test.todo` to `test` when both
+// #6446 and the hunk land.
+//
+// Protects: the candidate list of `listCandidatePages`. Fails when: an atom,
+// a page stamped `dream_generated` or an unstamped legacy atom reaches the
+// extractor, or when the ordinary note stops reaching it. Why not existing
+// coverage: #6446's test covers stamped atoms only. Seam: the `extractor`
+// option already exists.
+
+import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { resetPgliteState } from './helpers/reset-pglite.ts';
+import { runPhaseProposeTakes } from '../src/core/cycle/propose-takes.ts';
+import type { OperationContext } from '../src/core/operations.ts';
+
+let engine: PGLiteEngine;
+beforeAll(async () => {
+ engine = new PGLiteEngine();
+ await engine.connect({});
+ await engine.initSchema();
+});
+afterAll(async () => { await engine.disconnect(); });
+beforeEach(async () => { await resetPgliteState(engine); });
+
+const context = (): OperationContext => ({
+ engine, config: {} as never, logger: { info() {}, warn() {}, error() {} } as never, dryRun: false, remote: false, sourceId: 'default',
+});
+const put = (slug: string, type: string, frontmatter: Record<string, unknown>) => engine.putPage(slug, {
+ title: slug, type: type as never, compiled_truth: 'A strong claim lives in this page.', frontmatter, timeline: '',
+});
+
+describe('propose_takes candidate filter excludes atoms and dream output (#5211, P3.8)', () => {
+ test.todo('P3.8: a stamped atom, a legacy unstamped atom and a dream_generated page are not candidates; a note is', async () => {
+ await put('wiki/essays/thesis', 'analysis', {});
+ await put('atoms/stamped-claim', 'atom', { dream_generated: true, extracted_by: 'extract_atoms-v0.41.2.1' });
+ await put('atoms/legacy-claim', 'atom', {});
+ await put('wiki/personal/reflections/2026-10-01-dream', 'note', { dream_generated: true });
+ const scanned: string[] = [];
+ const result = await runPhaseProposeTakes(context(), { extractor: async ({ pagePath }) => { scanned.push(pagePath); return []; } });
+ expect(scanned).toEqual(['wiki/essays/thesis']);
+ expect((result.details as Record<string, unknown>).pages_scanned).toBe(1);
+ });
+});