gitgram/aitimemachine/gitnexus/test/unit/stream-query-driver-guard.test.ts
caelum0x 49b183818c Unify gitgram + aitimemachine into the monorepo (de-submodule) and merge vendored engines
Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as
opaque submodule gitlinks on GitHub) into fully-tracked first-party content.

AITM now merges its 7 vendored repos as first-party engines:
- memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts
- git: vendored C git (bundled binary) + gitnexus (in-process code intelligence)
- agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess)

Includes the full session's product build: Gitgram web/mobile/backend features,
AITM website/CLI/MCP, the unified memory layer, engine build tooling
(scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md),
and extensive test suites.

Build artifacts, node_modules, external/, and gemini-cli are gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 14:14:09 +03:00

54 lines
2.1 KiB
TypeScript

/**
* Unit tests for the streamQuery WAL-driver guard (#2264). streamQuery is
* deliberately NOT wrapped in withConnLock (its per-row callback re-enters the
* adapter), so it must refuse to run while the WAL-checkpoint driver is live —
* otherwise its unlocked per-row reads could race a CHECKPOINT on the shared
* connection (the corruption window the lock serializes everything else against).
* Today the serve/read path never starts the driver; this guard fails loud if a
* future in-process analyze ever overlaps a stream.
*/
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { streamQuery } from '../../src/core/lbug/lbug-adapter.js';
import { markWalDriverActive } from '../../src/core/lbug/wal-driver-state.js';
import { startWalCheckpointDriver } from '../../src/core/lbug/wal-checkpoint-driver.js';
describe('streamQuery WAL-driver guard (#2264)', () => {
beforeEach(() => {
// Manual checkpoint defaults on; pin it so the driver path is deterministic.
vi.stubEnv('GITNEXUS_WAL_MANUAL_CHECKPOINT', '1');
});
afterEach(() => {
markWalDriverActive(false);
vi.unstubAllEnvs();
});
it('throws when the WAL-checkpoint driver is active', async () => {
markWalDriverActive(true);
await expect(streamQuery('RETURN 1 AS one', () => undefined)).rejects.toThrow(
/WAL-checkpoint driver is active/,
);
});
it('passes the guard when inactive (reaching the not-initialized check)', async () => {
markWalDriverActive(false);
await expect(streamQuery('RETURN 1 AS one', () => undefined)).rejects.toThrow(
/not initialized/,
);
});
it('startWalCheckpointDriver arms the guard; stop() disarms it', async () => {
const driver = startWalCheckpointDriver({ periodMs: 1_000_000 });
try {
await expect(streamQuery('RETURN 1 AS one', () => undefined)).rejects.toThrow(
/WAL-checkpoint driver is active/,
);
} finally {
await driver.stop();
}
await expect(streamQuery('RETURN 1 AS one', () => undefined)).rejects.toThrow(
/not initialized/,
);
});
});