Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test: sync gate tests read the chunker stamp

garrytandcf1eb506d17
diff --git a/test/doctor.test.ts b/test/doctor.test.ts
index 0aa98934fb..4792125e62 100644
--- a/test/doctor.test.ts
+++ b/test/doctor.test.ts
@@ -1008,8 +1008,8 @@ describe('v0.41.27.0 — sync_freshness git short-circuit', () => {
beforeEach(async () => {
const { _setGitHeadProbeForTests, _setGitCleanProbeForTests } =
await import('../src/core/git-head.ts');
- const { CHUNKER_VERSION } = await import('../src/core/chunkers/code.ts');
- currentChunkerVersion = String(CHUNKER_VERSION);
+ const { chunkerStamp } = await import('../src/core/chunkers/code.ts');
+ currentChunkerVersion = chunkerStamp();
_setGitHeadProbeForTests(null);
_setGitCleanProbeForTests(null);
});
@@ -1260,8 +1260,8 @@ describe('v0.41.32.0 — commit-relative staleness', () => {
beforeEach(async () => {
const { _setGitHeadProbeForTests, _setGitCleanProbeForTests } =
await import('../src/core/git-head.ts');
- const { CHUNKER_VERSION } = await import('../src/core/chunkers/code.ts');
- currentChunkerVersion = String(CHUNKER_VERSION);
+ const { chunkerStamp } = await import('../src/core/chunkers/code.ts');
+ currentChunkerVersion = chunkerStamp();
_setGitHeadProbeForTests(null);
_setGitCleanProbeForTests(null);
});
@@ -1931,8 +1931,8 @@ describe('sync_freshness — clone-unavailable content-lag fallback', () => {
beforeEach(async () => {
const { _setGitHeadProbeForTests, _setGitCleanProbeForTests } =
await import('../src/core/git-head.ts');
- const { CHUNKER_VERSION } = await import('../src/core/chunkers/code.ts');
- currentChunkerVersion = String(CHUNKER_VERSION);
+ const { chunkerStamp } = await import('../src/core/chunkers/code.ts');
+ currentChunkerVersion = chunkerStamp();
_setGitHeadProbeForTests(null);
_setGitCleanProbeForTests(null);
});
diff --git a/test/managed-sync-chunker-version.test.ts b/test/managed-sync-chunker-version.test.ts
index 159945284b..c9ecefaae9 100644
--- a/test/managed-sync-chunker-version.test.ts
+++ b/test/managed-sync-chunker-version.test.ts
@@ -14,7 +14,7 @@ import type { BrainEngine } from '../src/core/engine.ts';
import { PGLiteEngine } from '../src/core/pglite-engine.ts';
import { performSync } from '../src/commands/sync.ts';
import { checkSyncFreshness } from '../src/commands/doctor.ts';
-import { CHUNKER_VERSION } from '../src/core/chunkers/code.ts';
+import { chunkerStamp } from '../src/core/chunkers/code.ts';
import { claimWorktree } from '../src/core/persistence/ownership.ts';
import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';
import { isolatedPersistencePostgres } from './helpers/persistence-postgres.ts';
@@ -65,7 +65,7 @@ for (const backend of backends) {
try {
const stamp = async () => (await engine.executeRaw<{ v: string | null }>('SELECT chunker_version AS v FROM sources WHERE id=$1', [sourceId]))[0].v;
await performSync(engine, { repoPath: root, sourceId, noPull: true, noEmbed: true });
- expect(await stamp()).toBe(String(CHUNKER_VERSION));
+ expect(await stamp()).toBe(chunkerStamp());
await engine.executeRaw("UPDATE sources SET chunker_version='6' WHERE id=$1", [sourceId]);
commit(root, 'notes/second.md', 'An incremental change.');
@@ -74,7 +74,7 @@ for (const backend of backends) {
const full = await performSync(engine, { repoPath: root, sourceId, noPull: true, noEmbed: true, full: true });
expect(full.status).not.toBe('blocked_by_failures');
- expect(await stamp()).toBe(String(CHUNKER_VERSION));
+ expect(await stamp()).toBe(chunkerStamp());
// The reporter's symptom: 80 h after a successful sync of an unchanged repo, doctor stays ok.
const later = Date.now() + 80 * 3_600_000;
diff --git a/test/sync-cost-estimate.test.ts b/test/sync-cost-estimate.test.ts
index cc53947ce5..ac67d907b1 100644
--- a/test/sync-cost-estimate.test.ts
+++ b/test/sync-cost-estimate.test.ts
@@ -4,7 +4,7 @@
* The inline cost estimator now MIRRORS EXECUTION (delta, not full-tree
* ceiling) so the gate's dollar figure stops being a ~400x phantom on a busy
* brain. Real temp git repos, no PGLite. estimateInlineNewTokens is exported
- * from commands/sync.ts; CHUNKER_VERSION is the live chunker version.
+ * from commands/sync.ts; chunkerStamp() is the live chunker stamp (version plus grammar revisions).
*/
import { describe, test, expect, beforeEach, afterEach } from 'bun:test';
import { mkdtempSync, writeFileSync, rmSync, mkdirSync } from 'fs';
@@ -12,9 +12,9 @@ import { execSync } from 'child_process';
import { tmpdir } from 'os';
import { join } from 'path';
import { estimateInlineNewTokens } from '../src/commands/sync.ts';
-import { CHUNKER_VERSION } from '../src/core/chunkers/code.ts';
+import { chunkerStamp } from '../src/core/chunkers/code.ts';
-const CURRENT = String(CHUNKER_VERSION);
+const CURRENT = chunkerStamp();
let repo: string;
function commitAll(msg: string): string {
diff --git a/test/sync-cost-gate.serial.test.ts b/test/sync-cost-gate.serial.test.ts
index 190919df37..f9fb4c6611 100644
--- a/test/sync-cost-gate.serial.test.ts
+++ b/test/sync-cost-gate.serial.test.ts
@@ -30,7 +30,7 @@ import {
} from '../src/core/sync-embed-backfill.ts';
import { resetPgliteState } from './helpers/reset-pglite.ts';
import { configureGateway, resetGateway, __setEmbedTransportForTests } from '../src/core/ai/gateway.ts';
-import { CHUNKER_VERSION } from '../src/core/chunkers/code.ts';
+import { chunkerStamp } from '../src/core/chunkers/code.ts';
import type { ChunkInput } from '../src/core/types.ts';
/** Offline embed stub so inline-proceed paths (posture tokenmax) don't network. */
@@ -180,7 +180,7 @@ describe('v0.41.31 — sync --all cost gate wiring', () => {
await runSources(workerBackedEngine, ['add', 'vault', '--path', repoPath, '--no-federated']);
await engine.executeRaw(
`UPDATE sources SET last_commit = $1, chunker_version = $2 WHERE id = 'vault'`,
- [headSha, String(CHUNKER_VERSION)],
+ [headSha, chunkerStamp()],
);
const [source] = await engine.executeRaw<{
@@ -197,11 +197,11 @@ describe('v0.41.31 — sync --all cost gate wiring', () => {
source,
{
id: 'disabled', local_path: repoPathTwo, config: { syncEnabled: false },
- last_commit: repoTwoHead, chunker_version: String(CHUNKER_VERSION),
+ last_commit: repoTwoHead, chunker_version: chunkerStamp(),
},
{
id: 'missing', local_path: join(repoPath, 'definitely-missing'), config: {},
- last_commit: null, chunker_version: String(CHUNKER_VERSION),
+ last_commit: null, chunker_version: chunkerStamp(),
},
];
const active = candidates.filter((candidate) => candidate.config.syncEnabled !== false);
@@ -243,7 +243,7 @@ describe('v0.41.31 — sync --all cost gate wiring', () => {
await runSources(workerBackedEngine, ['add', 'vault', '--path', repoPath, '--no-federated']);
await engine.executeRaw(
`UPDATE sources SET last_commit = $1, chunker_version = $2 WHERE id = 'vault'`,
- [headSha, String(CHUNKER_VERSION)],
+ [headSha, chunkerStamp()],
);
await engine.setConfig('sync.federated_v2', 'true');
await engine.setConfig('sync.cost_gate_min_usd', '1000');
@@ -281,7 +281,7 @@ describe('v0.41.31 — sync --all cost gate wiring', () => {
await runSources(workerBackedEngine, ['add', 'vault', '--path', repoPath, '--no-federated']);
await engine.executeRaw(
`UPDATE sources SET last_commit = $1, chunker_version = $2 WHERE id = 'vault'`,
- [headSha, String(CHUNKER_VERSION)],
+ [headSha, chunkerStamp()],
);
await engine.setConfig('sync.federated_v2', 'true');
await engine.setConfig('sync.cost_gate_min_usd', '1000');
@@ -317,7 +317,7 @@ describe('v0.41.31 — sync --all cost gate wiring', () => {
await runSources(workerBackedEngine, ['add', 'vault', '--path', repoPath, '--no-federated']);
await engine.executeRaw(
`UPDATE sources SET last_commit = $1, chunker_version = $2 WHERE id = 'vault'`,
- [headSha, String(CHUNKER_VERSION)],
+ [headSha, chunkerStamp()],
);
await engine.setConfig('sync.federated_v2', 'false');
await engine.setConfig('sync.cost_gate_min_usd', '1000');
@@ -411,11 +411,11 @@ describe('v0.41.31 — sync --all cost gate wiring', () => {
const headShaTwo = execSync('git rev-parse HEAD', { cwd: repoPathTwo, stdio: 'pipe' }).toString().trim();
await engine.executeRaw(
`UPDATE sources SET last_commit = $1, chunker_version = $2 WHERE id = 'vault'`,
- [headSha, String(CHUNKER_VERSION)],
+ [headSha, chunkerStamp()],
);
await engine.executeRaw(
`UPDATE sources SET last_commit = $1, chunker_version = $2 WHERE id = 'vault-two'`,
- [headShaTwo, String(CHUNKER_VERSION)],
+ [headShaTwo, chunkerStamp()],
);
// Seed a stale backlog so the deferred notice has a non-zero figure.
await engine.putPage('vault/note', { type: 'note', title: 'note', compiled_truth: '# note' }, { sourceId: 'vault' });
@@ -482,7 +482,7 @@ describe('v0.41.31 — sync --all cost gate wiring', () => {
// Mirrors the executor's up_to_date predicate: HEAD==last_commit AND chunker
// matches → 0 new tokens → below floor → proceeds without deferring.
await runSources(engine, ['add', 'vault', '--path', repoPath, '--no-federated']);
- await engine.executeRaw(`UPDATE sources SET last_commit = $1, chunker_version = $2 WHERE id = 'vault'`, [headSha, String(CHUNKER_VERSION)]);
+ await engine.executeRaw(`UPDATE sources SET last_commit = $1, chunker_version = $2 WHERE id = 'vault'`, [headSha, chunkerStamp()]);
await engine.setConfig('sync.cost_gate_min_usd', '0');
const { exitCode, stdout } = await runSyncCaptured(['--all', '--serial', '--json', '--no-pull']);
@@ -497,7 +497,7 @@ describe('v0.41.31 — sync --all cost gate wiring', () => {
// git-clean, but the commits are caught up. The OLD estimator priced the
// whole tree (158M-token phantom); the new one mirrors execution → $0.
await runSources(engine, ['add', 'vault', '--path', repoPath, '--no-federated']);
- await engine.executeRaw(`UPDATE sources SET last_commit = $1, chunker_version = $2 WHERE id = 'vault'`, [headSha, String(CHUNKER_VERSION)]);
+ await engine.executeRaw(`UPDATE sources SET last_commit = $1, chunker_version = $2 WHERE id = 'vault'`, [headSha, chunkerStamp()]);
// Dirty the tree with an untracked non-syncable scratch file (agents/crons
// write constantly) — attached-HEAD sync never imports it.
writeFileSync(join(repoPath, 'scratch.tmp'), 'uncommitted agent scratch');
@@ -575,7 +575,7 @@ describe('v0.41.31 — sync --all cost gate wiring', () => {
await runSources(engine, ['add', 'vault', '--path', repoPath, '--no-federated']);
await engine.executeRaw(
`UPDATE sources SET last_commit = $1, chunker_version = $2 WHERE id = 'vault'`,
- [headSha, String(CHUNKER_VERSION)],
+ [headSha, chunkerStamp()],
);
await engine.setConfig('sync.cost_gate_min_usd', '1000');
commitLargeIncrementalDrop();
@@ -607,7 +607,7 @@ describe('v0.41.31 — sync --all cost gate wiring', () => {
await runSources(workerBackedEngine, ['add', 'vault', '--path', repoPath, '--no-federated']);
await engine.executeRaw(
`UPDATE sources SET last_commit = $1, chunker_version = $2 WHERE id = 'vault'`,
- [headSha, String(CHUNKER_VERSION)],
+ [headSha, chunkerStamp()],
);
await engine.setConfig('sync.cost_gate_min_usd', '1000');
commitLargeIncrementalDrop();
@@ -627,7 +627,7 @@ describe('v0.41.31 — sync --all cost gate wiring', () => {
await runSources(workerBackedEngine, ['add', 'vault', '--path', repoPath, '--no-federated']);
await engine.executeRaw(
`UPDATE sources SET last_commit = $1, chunker_version = $2 WHERE id = 'vault'`,
- [headSha, String(CHUNKER_VERSION)],
+ [headSha, chunkerStamp()],
);
commitLargeIncrementalDrop();
@@ -644,7 +644,7 @@ describe('v0.41.31 — sync --all cost gate wiring', () => {
await runSources(engine, ['add', 'vault', '--path', repoPath, '--no-federated']);
await engine.executeRaw(
`UPDATE sources SET last_commit = $1, chunker_version = $2 WHERE id = 'vault'`,
- [headSha, String(CHUNKER_VERSION)],
+ [headSha, chunkerStamp()],
);
await engine.setConfig('sync.cost_gate_min_usd', '1000');
commitLargeIncrementalDrop();
diff --git a/test/sync-rename-reconcile.serial.test.ts b/test/sync-rename-reconcile.serial.test.ts
index 569e54e025..0707dd3e30 100644
--- a/test/sync-rename-reconcile.serial.test.ts
+++ b/test/sync-rename-reconcile.serial.test.ts
@@ -2273,7 +2273,7 @@ describe('#3583 review: GATE13 — chunker_version is acknowledged only by a com
});
test('a BLOCKED forced re-chunk keeps the version stale, so the retry actually re-runs', async () => {
- const { CHUNKER_VERSION } = await import('../src/core/chunkers/code.ts');
+ const { chunkerStamp } = await import('../src/core/chunkers/code.ts');
const { performSync } = await import('../src/commands/sync.ts');
const goodAlpha = personMd('Alpha', 'Alpha is a person.');
const repo = mkRepo({ 'people/alpha.md': goodAlpha });
@@ -2303,7 +2303,7 @@ describe('#3583 review: GATE13 — chunker_version is acknowledged only by a com
const ackedVersion = await engine.executeRaw<{ chunker_version: string | null }>(
`SELECT chunker_version FROM sources WHERE id = 'default'`,
);
- expect(ackedVersion[0]?.chunker_version).toBe(String(CHUNKER_VERSION));
+ expect(ackedVersion[0]?.chunker_version).toBe(chunkerStamp());
expect(await engine.getPage('people/alpha')).not.toBeNull();
await engine.setConfig('sync.holds', 'hold');
});