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.
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

124 lines
3.6 KiB
TypeScript

/**
* Unit Tests: CLI trace command wiring
*
* Tests that traceCommand forwards CLI flags to callTool('trace', ...)
* with correct parameter names. Mocked LocalBackend — no graph/DB.
*/
import { describe, it, expect, vi, beforeEach } from 'vitest';
const { callTool, init } = vi.hoisted(() => ({
callTool: vi.fn(),
init: vi.fn().mockResolvedValue(true),
}));
vi.mock('../../src/mcp/local/local-backend.js', () => ({
LocalBackend: class {
init = init;
callTool = callTool;
},
VALID_NODE_LABELS: new Set(['Function', 'Class', 'Interface', 'Method', 'Constructor']),
}));
vi.mock('node:fs', () => ({ writeSync: vi.fn() }));
import { traceCommand } from '../../src/cli/tool.js';
describe('CLI trace command', () => {
beforeEach(() => {
callTool.mockReset();
callTool.mockResolvedValue({ status: 'ok', hopCount: 1 });
});
it('forwards from/to as positional args', async () => {
await traceCommand('validateUser', 'executeQuery', {});
expect(callTool).toHaveBeenCalledTimes(1);
expect(callTool).toHaveBeenCalledWith(
'trace',
expect.objectContaining({
from: 'validateUser',
to: 'executeQuery',
}),
);
});
it('forwards --from-uid/--to-uid as from_uid/to_uid', async () => {
await traceCommand('A', 'B', {
fromUid: 'uid:A',
toUid: 'uid:B',
});
expect(callTool).toHaveBeenCalledWith(
'trace',
expect.objectContaining({
from_uid: 'uid:A',
to_uid: 'uid:B',
}),
);
});
it('forwards --from-file/--to-file as from_file/to_file', async () => {
await traceCommand('A', 'B', {
fromFile: 'src/a.ts',
toFile: 'src/b.ts',
});
expect(callTool).toHaveBeenCalledWith(
'trace',
expect.objectContaining({
from_file: 'src/a.ts',
to_file: 'src/b.ts',
}),
);
});
it('forwards --depth as maxDepth', async () => {
await traceCommand('A', 'B', { depth: '5' });
expect(callTool).toHaveBeenCalledWith(
'trace',
expect.objectContaining({
maxDepth: 5,
}),
);
});
it('exits with usage when from is missing and no from_uid', async () => {
const exitSpy = vi.spyOn(process, 'exit').mockImplementation(() => {
throw new Error('process.exit');
});
await expect(traceCommand(undefined, 'B', {})).rejects.toThrow('process.exit');
expect(exitSpy).toHaveBeenCalledWith(1);
exitSpy.mockRestore();
});
it('exits with usage when --depth is non-numeric instead of forwarding NaN', async () => {
const exitSpy = vi.spyOn(process, 'exit').mockImplementation(() => {
throw new Error('process.exit');
});
await expect(traceCommand('A', 'B', { depth: 'abc' })).rejects.toThrow('process.exit');
expect(exitSpy).toHaveBeenCalledWith(1);
expect(callTool).not.toHaveBeenCalled();
exitSpy.mockRestore();
});
it('exits with usage when --from-uid or --to-uid is a swallowed flag value', async () => {
for (const opts of [{ fromUid: '--oops' }, { toUid: '--oops' }]) {
callTool.mockReset();
const exitSpy = vi.spyOn(process, 'exit').mockImplementation(() => {
throw new Error('process.exit');
});
await expect(traceCommand('A', 'B', opts)).rejects.toThrow('process.exit');
expect(exitSpy).toHaveBeenCalledWith(1);
expect(callTool).not.toHaveBeenCalled();
exitSpy.mockRestore();
}
});
it('forwards --include-tests as includeTests', async () => {
await traceCommand('A', 'B', { includeTests: true });
expect(callTool).toHaveBeenCalledWith('trace', expect.objectContaining({ includeTests: true }));
});
});