gitgram/aitimemachine/gitnexus/test/integration/analyze-heap-oom-e2e.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

75 lines
2.8 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { spawnSync } from 'node:child_process';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const testDir = path.dirname(fileURLToPath(import.meta.url));
const repoRoot = path.resolve(testDir, '../..');
const distCli = path.join(repoRoot, 'dist', 'cli', 'index.js');
const fixtureSource = path.resolve(testDir, '..', 'fixtures', 'mini-repo');
const runAnalyzeWithForcedOom = (cwd: string, gitnexusHome: string) =>
spawnSync(process.execPath, [distCli, 'analyze'], {
cwd,
encoding: 'utf8',
timeout: process.env.CI ? 40_000 : 20_000,
stdio: ['pipe', 'pipe', 'pipe'],
env: {
...process.env,
GITNEXUS_HOME: gitnexusHome,
NODE_OPTIONS: '',
GITNEXUS_TEST_RESPAWN_HEAP_MB: '32',
GITNEXUS_TEST_FORCE_HEAP_OOM: '1',
CI: '1',
},
});
describe('analyze OOM guidance (real child-process OOM)', () => {
it('prints OOM guidance with Unix and Windows commands when respawned child truly OOMs', () => {
if (!fs.existsSync(distCli)) {
throw new Error(
'dist/cli/index.js missing — run `npm run build` first (or use `npm run test:integration`, which builds via pretest:integration).',
);
}
const oomTestRepoParent = fs.mkdtempSync(path.join(os.tmpdir(), 'gn-oom-e2e-repo-'));
const oomTestGitnexusHome = fs.mkdtempSync(path.join(os.tmpdir(), 'gn-oom-e2e-home-'));
const repoPath = path.join(oomTestRepoParent, 'mini-repo');
fs.cpSync(fixtureSource, repoPath, { recursive: true });
spawnSync('git', ['init'], { cwd: repoPath, stdio: 'pipe' });
spawnSync('git', ['add', '-A'], { cwd: repoPath, stdio: 'pipe' });
spawnSync('git', ['commit', '-m', 'initial commit'], {
cwd: repoPath,
stdio: 'pipe',
env: {
...process.env,
GIT_AUTHOR_NAME: 'test',
GIT_AUTHOR_EMAIL: 'test@test',
GIT_COMMITTER_NAME: 'test',
GIT_COMMITTER_EMAIL: 'test@test',
},
});
try {
const result = runAnalyzeWithForcedOom(repoPath, oomTestGitnexusHome);
const combinedOutput = `${result.stderr}\n${result.stdout}`;
expect(result.status).not.toBeNull();
expect(result.status).not.toBe(0);
expect(combinedOutput).toContain('Analysis likely ran out of memory (heap cap auto-sized to');
expect(combinedOutput).toContain(
'NODE_OPTIONS="--max-old-space-size=<MB>" gitnexus analyze [your-args]',
);
expect(combinedOutput).toContain(
'(Windows: set NODE_OPTIONS=--max-old-space-size=<MB> && gitnexus analyze [your-args])',
);
} finally {
fs.rmSync(oomTestRepoParent, { recursive: true, force: true });
fs.rmSync(oomTestGitnexusHome, { recursive: true, force: true });
}
}, 60_000);
});