This repository has been archived on 2026-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
gitgram-ai/aitimemachine/gitnexus/test/unit/local-backend-maxbuffer.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

49 lines
2.0 KiB
TypeScript

/**
* Source-code regression: ENOBUFS on large git/rg output.
*
* Node's default maxBuffer for execFileSync is 1 MB, which is easily exceeded
* by `git diff` on repos with large unstaged changes (e.g. unignored build
* folders) — see the original bug report:
*
* "spawnSync git ENOBUFS in gitnexus_detect_changes(scope=\"unstaged\")
* due to missing maxBuffer".
*
* Every `execFileSync` call in `local-backend.ts` that captures stdout
* (i.e. sets `encoding`) MUST pass an explicit `maxBuffer`. This test is a
* lightweight static guard so the regression cannot silently come back.
*
* Kept as a standalone file (no LocalBackend import) so it does not depend
* on the LadybugDB native binding being available in the test environment.
*/
import { describe, it, expect } from 'vitest';
import fs from 'fs';
import path from 'path';
const SOURCE_PATH = path.join(__dirname, '../../src/mcp/local/local-backend.ts');
describe('local-backend: execFileSync maxBuffer regression', () => {
const source = fs.readFileSync(SOURCE_PATH, 'utf-8');
it('every stdout-capturing execFileSync call passes maxBuffer', () => {
// Match each `execFileSync(...)` call. The local-backend.ts call sites use
// a single trailing options object literal, so a non-greedy match up to the
// closing `)` of the statement is sufficient.
const callRe = /execFileSync\s*\(([\s\S]*?)\)\s*;/g;
const offenders: string[] = [];
let match: RegExpExecArray | null;
while ((match = callRe.exec(source)) !== null) {
const args = match[1];
// Only stdout-capturing calls (encoding set) are at risk of ENOBUFS.
if (!/encoding\s*:/.test(args)) continue;
if (!/maxBuffer\s*:/.test(args)) {
const lineNo = source.slice(0, match.index).split('\n').length;
offenders.push(`line ${lineNo}: ${args.replace(/\s+/g, ' ').slice(0, 160)}`);
}
}
expect(
offenders,
`execFileSync calls missing explicit maxBuffer (ENOBUFS risk):\n${offenders.join('\n')}`,
).toEqual([]);
});
});