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/kotlin-scope-captures.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

100 lines
3.1 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { emitKotlinScopeCaptures } from '../../src/core/ingestion/languages/kotlin/captures.js';
function captureTexts(source: string): Array<Record<string, string>> {
return emitKotlinScopeCaptures(source, 'fixture.kt').map((match) =>
Object.fromEntries(Object.entries(match).map(([tag, capture]) => [tag, capture.text])),
);
}
describe('Kotlin scope captures', () => {
it('emits required arity equal to total arity when no parameters have defaults', () => {
const captures = captureTexts(`
fun greet(name: String, greeting: String) {}
`);
const declaration = captures.find((match) => match['@declaration.function'] !== undefined);
expect(declaration?.['@declaration.parameter-count']).toBe('2');
expect(declaration?.['@declaration.required-parameter-count']).toBe('2');
});
it('emits required arity excluding default parameters', () => {
const captures = captureTexts(`
fun greet(name: String, greeting: String = "Hello", punctuation: String = "!") {}
`);
const declaration = captures.find((match) => match['@declaration.function'] !== undefined);
expect(declaration?.['@declaration.parameter-count']).toBe('3');
expect(declaration?.['@declaration.required-parameter-count']).toBe('1');
});
it('counts trailing lambda call suffixes as call arguments', () => {
const captures = captureTexts(`
fun run(items: List<String>) {
items.forEach { println(it) }
}
`);
const forEach = captures.find(
(match) =>
match['@reference.call.member'] === 'items.forEach { println(it) }' &&
match['@reference.name'] === 'forEach',
);
expect(forEach?.['@reference.arity']).toBe('1');
});
it('does not synthesize extension free-call fallback for chained regular member calls', () => {
const captures = captureTexts(`
class Service {
fun current(): Service = this
fun save() {}
}
fun run(service: Service) {
service.current().save()
}
`);
const syntheticSaveFreeCalls = captures.filter(
(match) =>
match['@reference.call.free'] === 'service.current().save()' &&
match['@reference.name'] === 'save',
);
expect(syntheticSaveFreeCalls).toHaveLength(0);
});
it('keeps literal-receiver extension fallback for extension-call candidates', () => {
const captures = captureTexts(`
fun String.slug(): String = this
fun run() {
"hello".slug()
}
`);
const slugFreeCall = captures.find(
(match) =>
match['@reference.call.free'] === '"hello".slug()' && match['@reference.name'] === 'slug',
);
expect(slugFreeCall).toBeDefined();
});
it('does not emit a self type binding keyed by the extension function name', () => {
const captures = captureTexts(`
fun String.slug(): String = this
`);
const spuriousSelfBinding = captures.find(
(match) =>
match['@type-binding.self'] !== undefined &&
match['@type-binding.name'] === 'slug' &&
match['@type-binding.type'] === 'String',
);
expect(spuriousSelfBinding).toBeUndefined();
});
});