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>
126 lines
4.9 KiB
TypeScript
126 lines
4.9 KiB
TypeScript
/**
|
|
* Unit tests for `buildQualifiedNameIndex` / `QualifiedNameIndex`
|
|
* (RFC #909 Ring 2 SHARED #913).
|
|
*
|
|
* Covers: per-kind accumulation, multi-def-per-qname (partial classes /
|
|
* overloads), skipping defs without a qualifiedName, duplicate-pair dedup,
|
|
* and empty-bucket iteration guarantee.
|
|
*/
|
|
|
|
import { describe, it, expect } from 'vitest';
|
|
import { buildQualifiedNameIndex, type SymbolDefinition } from 'gitnexus-shared';
|
|
|
|
const makeDef = (overrides: Partial<SymbolDefinition> = {}): SymbolDefinition => ({
|
|
nodeId: 'def:test',
|
|
filePath: 'src/test.ts',
|
|
type: 'Class',
|
|
...overrides,
|
|
});
|
|
|
|
describe('buildQualifiedNameIndex', () => {
|
|
it('builds an empty index from no defs', () => {
|
|
const idx = buildQualifiedNameIndex([]);
|
|
expect(idx.size).toBe(0);
|
|
expect(idx.get('anything')).toEqual([]);
|
|
expect(idx.has('anything')).toBe(false);
|
|
});
|
|
|
|
it('indexes a single qualified-named def', () => {
|
|
const def = makeDef({ nodeId: 'def:app.User', qualifiedName: 'app.User' });
|
|
const idx = buildQualifiedNameIndex([def]);
|
|
expect(idx.size).toBe(1);
|
|
expect(idx.has('app.User')).toBe(true);
|
|
expect(idx.get('app.User')).toEqual(['def:app.User']);
|
|
});
|
|
|
|
it('accumulates distinct DefIds under the same qualified name (partial classes)', () => {
|
|
// C# partial classes: same qname, different files/nodeIds
|
|
const a = makeDef({
|
|
nodeId: 'def:app.User:Core',
|
|
qualifiedName: 'app.User',
|
|
filePath: 'src/User.Core.cs',
|
|
});
|
|
const b = makeDef({
|
|
nodeId: 'def:app.User:Api',
|
|
qualifiedName: 'app.User',
|
|
filePath: 'src/User.Api.cs',
|
|
});
|
|
const idx = buildQualifiedNameIndex([a, b]);
|
|
expect(idx.get('app.User')).toEqual(['def:app.User:Core', 'def:app.User:Api']);
|
|
// Hit-path bucket is frozen just like the miss path — consumers cannot
|
|
// mutate the returned array.
|
|
expect(() => (idx.get('app.User') as unknown as string[]).push('x')).toThrow();
|
|
});
|
|
|
|
it('preserves input order in the bucket', () => {
|
|
const a = makeDef({ nodeId: 'def:a', qualifiedName: 'app.Foo' });
|
|
const b = makeDef({ nodeId: 'def:b', qualifiedName: 'app.Foo' });
|
|
const c = makeDef({ nodeId: 'def:c', qualifiedName: 'app.Foo' });
|
|
const idx = buildQualifiedNameIndex([c, a, b]);
|
|
expect(idx.get('app.Foo')).toEqual(['def:c', 'def:a', 'def:b']);
|
|
});
|
|
|
|
it('separates defs that share a simple name but differ in qualifiedName', () => {
|
|
const appUser = makeDef({ nodeId: 'def:app.User', qualifiedName: 'app.User' });
|
|
const adminUser = makeDef({ nodeId: 'def:admin.User', qualifiedName: 'admin.User' });
|
|
const idx = buildQualifiedNameIndex([appUser, adminUser]);
|
|
expect(idx.get('app.User')).toEqual(['def:app.User']);
|
|
expect(idx.get('admin.User')).toEqual(['def:admin.User']);
|
|
});
|
|
|
|
it('skips defs that have no qualifiedName', () => {
|
|
const qnamed = makeDef({ nodeId: 'def:app.Foo', qualifiedName: 'app.Foo' });
|
|
const anon = makeDef({ nodeId: 'def:anon', qualifiedName: undefined });
|
|
const idx = buildQualifiedNameIndex([qnamed, anon]);
|
|
expect(idx.size).toBe(1);
|
|
expect(idx.get('app.Foo')).toEqual(['def:app.Foo']);
|
|
expect(idx.has('')).toBe(false);
|
|
});
|
|
|
|
it('skips defs with an empty-string qualifiedName', () => {
|
|
const empty = makeDef({ nodeId: 'def:empty', qualifiedName: '' });
|
|
const idx = buildQualifiedNameIndex([empty]);
|
|
expect(idx.size).toBe(0);
|
|
expect(idx.has('')).toBe(false);
|
|
});
|
|
|
|
it('deduplicates exact (qname, DefId) pairs when the same def appears twice in input', () => {
|
|
const def = makeDef({ nodeId: 'def:app.Foo', qualifiedName: 'app.Foo' });
|
|
const idx = buildQualifiedNameIndex([def, def]);
|
|
expect(idx.get('app.Foo')).toEqual(['def:app.Foo']); // not duplicated
|
|
});
|
|
|
|
it('indexes across heterogeneous kinds (Class + Method + Field may share qname convention)', () => {
|
|
const klass = makeDef({
|
|
nodeId: 'def:class:app.User',
|
|
type: 'Class',
|
|
qualifiedName: 'app.User',
|
|
});
|
|
const method = makeDef({
|
|
nodeId: 'def:method:app.User.save',
|
|
type: 'Method',
|
|
qualifiedName: 'app.User.save',
|
|
});
|
|
const idx = buildQualifiedNameIndex([klass, method]);
|
|
expect(idx.size).toBe(2);
|
|
expect(idx.get('app.User')).toEqual(['def:class:app.User']);
|
|
expect(idx.get('app.User.save')).toEqual(['def:method:app.User.save']);
|
|
});
|
|
|
|
it('returns a frozen empty array (not undefined) for misses so callers can iterate safely', () => {
|
|
const idx = buildQualifiedNameIndex([makeDef({ qualifiedName: 'app.Foo' })]);
|
|
const miss = idx.get('app.Missing');
|
|
expect(miss).toEqual([]);
|
|
expect(() => (miss as unknown as string[]).push('x')).toThrow();
|
|
});
|
|
|
|
it('exposes byQualifiedName as a read-only Map for direct iteration', () => {
|
|
const idx = buildQualifiedNameIndex([
|
|
makeDef({ nodeId: 'def:A', qualifiedName: 'app.A' }),
|
|
makeDef({ nodeId: 'def:B', qualifiedName: 'app.B' }),
|
|
]);
|
|
const names = Array.from(idx.byQualifiedName.keys()).sort();
|
|
expect(names).toEqual(['app.A', 'app.B']);
|
|
});
|
|
});
|