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

70 lines
2.4 KiB
TypeScript

/**
* Unit tests for `buildDefIndex` / `DefIndex` (RFC #909 Ring 2 SHARED #913).
*
* Covers: build-from-list, O(1) lookup contract, first-write-wins on
* duplicate `nodeId`, readonly surface.
*/
import { describe, it, expect } from 'vitest';
import { buildDefIndex, type SymbolDefinition } from 'gitnexus-shared';
const makeDef = (overrides: Partial<SymbolDefinition> = {}): SymbolDefinition => ({
nodeId: 'def:test',
filePath: 'src/test.ts',
type: 'Method',
...overrides,
});
describe('buildDefIndex', () => {
it('builds an empty index from an empty input', () => {
const idx = buildDefIndex([]);
expect(idx.size).toBe(0);
expect(idx.get('anything')).toBeUndefined();
expect(idx.has('anything')).toBe(false);
});
it('stores a single def and round-trips by nodeId', () => {
const def = makeDef({ nodeId: 'def:User.save' });
const idx = buildDefIndex([def]);
expect(idx.size).toBe(1);
expect(idx.has('def:User.save')).toBe(true);
expect(idx.get('def:User.save')).toBe(def); // reference identity
});
it('stores multiple defs under their distinct ids', () => {
const a = makeDef({ nodeId: 'def:A' });
const b = makeDef({ nodeId: 'def:B' });
const c = makeDef({ nodeId: 'def:C' });
const idx = buildDefIndex([a, b, c]);
expect(idx.size).toBe(3);
expect(idx.get('def:A')).toBe(a);
expect(idx.get('def:B')).toBe(b);
expect(idx.get('def:C')).toBe(c);
});
it('first-write-wins on duplicate nodeId', () => {
const first = makeDef({ nodeId: 'def:dup', returnType: 'Original' });
const second = makeDef({ nodeId: 'def:dup', returnType: 'Shadow' });
const idx = buildDefIndex([first, second]);
expect(idx.size).toBe(1);
expect(idx.get('def:dup')).toBe(first);
expect(idx.get('def:dup')?.returnType).toBe('Original');
});
it("returns undefined for a missing id (doesn't throw)", () => {
const idx = buildDefIndex([makeDef({ nodeId: 'def:A' })]);
expect(idx.get('def:missing')).toBeUndefined();
expect(idx.has('def:missing')).toBe(false);
});
it('exposes byId as the underlying read-only Map for direct iteration', () => {
const a = makeDef({ nodeId: 'def:A' });
const b = makeDef({ nodeId: 'def:B' });
const idx = buildDefIndex([a, b]);
const entries = Array.from(idx.byId.entries())
.map(([id]) => id)
.sort();
expect(entries).toEqual(['def:A', 'def:B']);
});
});