mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-08-28 05:25:25 +00:00
* refactor(ingestion): delete legacy call-resolution DAG + heritage processor (#942) RING4-1: all 16 production languages (incl. Vue #940) are registry-primary, so the legacy resolution legs only ran under the now-removed CI parity gate. Calls and inheritance now resolve exclusively through scope-resolution (Registry.lookup, preEmitInheritanceEdges, emitHeritageEdges, buildMro → MethodDispatchIndex). Removed: - Call-resolution DAG: call-processor.ts legacy body (processCalls, processCallsFromExtracted, resolveCallTarget + all resolver/dispatch/chain helpers), model/resolve.ts MRO-via-HeritageMap, model/heritage-map.ts, type-env DAG types; inferImplicitReceiver/selectDispatch LanguageProvider hooks + Ruby impls; DispatchDecision/ImplicitReceiverOverride/ReceiverEnriched. - Legacy heritage path: heritage-processor.ts, heritage-types.ts, heritage-extractors/, @heritage.* tree-sitter queries, heritageExtractor/ heritageDefaultEdge/interfaceNamePattern wiring, worker + parse-impl heritage passes (parse-worker/parsing-processor lockstep), cross-file-impl DAG pass. - Scope-parity infrastructure entirely (no legacy↔registry parity left to run): scripts/run-parity.ts, scripts/ci-list-migrated-languages.ts, ci-scope-parity.yml, test:parity, and the scope-parity ci.yml gate. Resolver integration tests still run via the normal tests job. Kept (shared infra, NOT call-DAG-only): type-env.ts buildTypeEnv (field extraction / structure phase / embeddings), model/resolve.ts c3Linearize + gatherAncestors (mro-processor mroPhase), route/fetch/exported-type-map helpers in call-processor.ts, preEmitInheritanceEdges (legacy-edge dedup simplified). Acceptance: grep for resolveCallTarget/inferImplicitReceiver/selectDispatch/ buildHeritageMap/HeritageMap/processHeritage/heritageExtractor/@heritage. is zero across src + test. tsc clean (both packages); resolver integration suite green (bit-compatible EXTENDS/IMPLEMENTS/CALLS); scope-capture fingerprints unchanged (python re-baselined: removed redundant ignored captures). ARCHITECTURE.md updated to scope-resolution-only. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(review): apply autofix feedback (#942) ce-code-review autofix pass on the RING4-1 deletion: - parse-cache.ts: bump SCHEMA_BUMP 2→3 — ParseWorkerResult lost its `heritage` field, so stale on-disk caches must invalidate (prevents a rollback replaying a heritage-less cache into legacy code) [api-contract P2]. - parse-impl.ts: drop 3 now-unused type imports (ExtractedCall, ExtractedAssignment, FileConstructorBindings) left by the deferred-block removal — would fail the eslint CI gate [correctness+maintainability P1]. - AGENTS.md / CLAUDE.md / scope-resolver.ts contract doc: fix stale pointers to the deleted "§ Call-Resolution DAG" section + removed hooks; preserve the language-neutrality rule [project-standards P1]. - registry-primary-flag.ts / cross-file.ts / parse-impl.ts: refresh stale comments referencing deleted symbols (legacy DAG, runCrossFileBindingPropagation). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * refactor(ingestion): remove the vestigial isRegistryPrimary flag (#942) With the legacy call-resolution DAG deleted, the per-language `REGISTRY_PRIMARY_<LANG>` / `isRegistryPrimary` / `MIGRATED_LANGUAGES` flag had only one meaningful state — every production language resolves via scope-resolution — and an explicit `=0` override could only *disable* resolution with no fallback (a footgun the review flagged). Removing it. - Delete `registry-primary-flag.ts` and the now-dead `shadow-harness.ts` (legacy↔registry shadow-parity tool) + its test. - Collapse the three flag gates to their behavior-preserving outcome (`SCOPE_RESOLVERS == MIGRATED_LANGUAGES`, so this is a no-op): - scope-resolution phase now runs for every registered `SCOPE_RESOLVERS` entry (was `∩ MIGRATED_LANGUAGES`). - import-processor `addImportGraphEdge` + parse-impl `shouldAccumulate`: the legacy emit/accumulate paths were already inert for migrated languages (scope-resolution owns IMPORTS via the imports-to-edges bridge); drop the flag term. - Collapse flag-branching tests to the scope-resolution path and delete the csharp legacy-`=0`-leg describe blocks; remove the ruby/rust-scope env-forcing hooks (no-ops now). - Refresh docs/comments (ARCHITECTURE.md "one registration", scope-resolver cookbook, phase deps) — adding a language is now a single `SCOPE_RESOLVERS` registration. Verified: tsc clean (both packages); resolver integration tests green (747 assertions across cobol/csharp/ruby/rust/typescript/go, IMPORTS edges intact); grep for the flag symbols is zero across src + test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * style(format): prettier formatting on #942 changes Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(ci): drop legacy heritage-capture tests + re-baseline scope-capture fingerprints (#942) Two CI failures from the #942 cleanup, surfaced by the tri-review + CI: - tree-sitter-languages.test.ts: two tests asserted `@heritage.*` captures (Rust trait-impl, Dart extends/implements/with) that this PR removed. The acceptance grep used `@heritage\.` (with `@`); these reference the runtime capture name `heritage.trait` (no `@`), so they slipped the earlier sweep. Inheritance is now covered by the resolver integration suite. (fixed macos-latest) - Re-baselined the scope-capture bench fingerprints for csharp/rust/ruby/java/ javascript/kotlin (baselines.json) + python (python-scope/baseline-fingerprint.txt). The earlier test-cleanup reworded comments inside the lang-resolution fixture files (Shapes.cs, child.rs, derived.rb, IA.java/Plain.java, Service.js, F.kt, app.py) to scrub deleted-symbol references for the acceptance grep; those are the bench corpus, so capture node positions shifted. Capture LOGIC is unchanged — verified `--check` passes for all 14 langs + python. (fixed benchmarks) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs/chore: scrub remaining REGISTRY_PRIMARY + deleted-symbol references (#942) Tri-review P3 follow-ups (verified): - TESTING.md: rewrite the "Scope-resolution parity" section — the legacy dual-leg (REGISTRY_PRIMARY_<LANG>=0/1) and `npm run test:parity` no longer exist; resolver tests run once on the sole scope-resolution path in the normal tests job. - scripts/bench-scope-resolution.ts: drop the inert `REGISTRY_PRIMARY_PYTHON=1` env set + usage hint (the flag is gone). - ruby/scope-resolver.ts, php/captures.ts: re-point doc-comments off the deleted heritage-map.ts / heritage-processor.ts to the current behavior. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(ci): prettier format + regenerate scope-capture goldens (#942) Two more CI failures, same root cause as the bench re-baseline (the test-cleanup reworded comments in lang-resolution bench/golden-corpus fixtures): - quality/format: prettier on tree-sitter-languages.test.ts (blank line left by the deleted heritage-capture tests) + TESTING.md (the rewritten section). - tests/ubuntu/coverage: `csharp-captures-golden` (and python/ruby/rust) drifted because the edited fixtures feed the per-language capture-golden snapshots too (not just the bench). Regenerated via UPDATE_GOLDEN=1. Verified safe: only the edited-fixture entries changed; csharp `captureGroups` unchanged (38) — digest shifted from comment-position only; capture LOGIC untouched. 1168 scope- resolution tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test(resolvers): drop createResolverParityIt wrapper, use vitest it directly The parity-aware `it` wrapper became a no-op when #942 removed the legacy call-resolution DAG (it just returned vitest's `it`). Remove it entirely so the resolver tests call vitest's `it` directly instead of shadowing it with a local `const it` (or `pit`/`rustParityIt`): - helpers.ts: delete createResolverParityIt + its now-unused vitestIt import and VitestIt type. - 16 files: drop `const it = createResolverParityIt('x')` and import `it` from vitest instead. - ruby.test.ts (pit) + rust.test.ts (rustParityIt): rename calls to `it`. - Scrub every comment that described the removed wrapper / dual-mode parity skip / legacy_skip gate (vue-scope, js/ts/dart/php/python headers, rust x2, cpp, swift x4, rust-coverage). Genuine test rationale is kept; only the vestigial two-leg framing is dropped. Accurate "legacy DAG (removed in #942)" historical notes are retained. No fixtures touched (no bench/golden re-baseline). tsc clean; rust+ruby resolver suites green (323 tests, incl. #1992 worker-path parity after a local dist build). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
513 lines
20 KiB
TypeScript
513 lines
20 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { routeRubyCall } from '../../../src/core/ingestion/call-routing.js';
|
|
|
|
// ── Mock AST node helpers ────────────────────────────────────────────────────
|
|
|
|
/**
|
|
* Build a minimal mock tree-sitter node. Only the fields actually accessed
|
|
* by routeRubyCall are populated; everything else is left undefined so that
|
|
* accidental property reads surface as undefined (the same as a real node
|
|
* that lacks the field) rather than silently returning a wrong value.
|
|
*/
|
|
|
|
interface MockNode {
|
|
type: string;
|
|
text: string;
|
|
isNamed?: boolean;
|
|
startPosition?: { row: number; col?: number };
|
|
endPosition?: { row: number; col?: number };
|
|
children?: MockNode[];
|
|
parent?: MockNode | null;
|
|
previousSibling?: MockNode | null;
|
|
childForFieldName?: (name: string) => MockNode | undefined;
|
|
}
|
|
|
|
/** Build a string node as tree-sitter-ruby emits it: string → string_content */
|
|
function makeStringNode(content: string): MockNode {
|
|
const contentNode: MockNode = { type: 'string_content', text: content };
|
|
return {
|
|
type: 'string',
|
|
text: `"${content}"`,
|
|
children: [contentNode],
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Build a mock `call` node for require/require_relative with a single string
|
|
* argument.
|
|
*/
|
|
function makeRequireCallNode(path: string | null): MockNode {
|
|
const argChildren: MockNode[] = path !== null ? [makeStringNode(path)] : [];
|
|
const argList: MockNode = { type: 'argument_list', text: '', children: argChildren };
|
|
const node: MockNode = {
|
|
type: 'call',
|
|
text: '',
|
|
childForFieldName: (name: string) => (name === 'arguments' ? argList : undefined),
|
|
};
|
|
return node;
|
|
}
|
|
|
|
/**
|
|
* Build a call node where the argument list contains a string node whose
|
|
* string_content child is absent (simulates a non-literal string argument).
|
|
*/
|
|
function makeRequireCallNodeNoContent(): MockNode {
|
|
const stringNodeNoContent: MockNode = { type: 'string', text: '""', children: [] };
|
|
const argList: MockNode = { type: 'argument_list', text: '', children: [stringNodeNoContent] };
|
|
return {
|
|
type: 'call',
|
|
text: '',
|
|
childForFieldName: (name: string) => (name === 'arguments' ? argList : undefined),
|
|
};
|
|
}
|
|
|
|
/** Build a mock call node for include/extend/prepend with a chain of parents. */
|
|
function makeHeritageCallNode(
|
|
argNodes: MockNode[],
|
|
enclosingType: 'class' | 'module' | null,
|
|
enclosingName: string | null,
|
|
extraDepth = 0,
|
|
): MockNode {
|
|
const argList: MockNode = { type: 'argument_list', text: '', children: argNodes };
|
|
const callNode: MockNode = {
|
|
type: 'call',
|
|
text: '',
|
|
parent: null,
|
|
childForFieldName: (name: string) => (name === 'arguments' ? argList : undefined),
|
|
};
|
|
|
|
if (enclosingType === null) {
|
|
// No enclosing class at all — parent chain ends without a class/module node
|
|
const intermediate: MockNode = { type: 'body', text: '', parent: null };
|
|
callNode.parent = intermediate;
|
|
return callNode;
|
|
}
|
|
|
|
// Build extra intermediate nodes to test deep parent walking
|
|
let leaf: MockNode = callNode;
|
|
for (let i = 0; i < extraDepth; i++) {
|
|
const wrapper: MockNode = { type: 'body_statement', text: '', parent: null };
|
|
leaf.parent = wrapper;
|
|
leaf = wrapper;
|
|
}
|
|
|
|
const nameNode: MockNode | undefined = enclosingName
|
|
? { type: 'constant', text: enclosingName }
|
|
: undefined;
|
|
|
|
const classNode: MockNode = {
|
|
type: enclosingType,
|
|
text: '',
|
|
parent: null,
|
|
childForFieldName: (name: string) => (name === 'name' ? nameNode : undefined),
|
|
};
|
|
leaf.parent = classNode;
|
|
|
|
return callNode;
|
|
}
|
|
|
|
/** Build a constant arg node (used as mixin name) */
|
|
function makeConstantArg(text: string): MockNode {
|
|
return { type: 'constant', text };
|
|
}
|
|
|
|
/** Build a scope_resolution arg node (e.g. Foo::Bar) */
|
|
function makeScopeResolutionArg(text: string): MockNode {
|
|
return { type: 'scope_resolution', text };
|
|
}
|
|
|
|
/** Build an identifier arg that is neither constant nor scope_resolution */
|
|
function makeIdentifierArg(text: string): MockNode {
|
|
return { type: 'identifier', text };
|
|
}
|
|
|
|
/** Build a simple_symbol arg (used in attr_accessor etc.) */
|
|
function makeSimpleSymbol(name: string, row = 0): MockNode {
|
|
return {
|
|
type: 'simple_symbol',
|
|
text: `:${name}`,
|
|
startPosition: { row },
|
|
endPosition: { row },
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Build a call node for attr_accessor/attr_reader/attr_writer with optional
|
|
* preceding comment siblings.
|
|
*/
|
|
function makeAccessorCallNode(symbolArgs: MockNode[], previousSiblings: MockNode[] = []): MockNode {
|
|
const argList: MockNode = { type: 'argument_list', text: '', children: symbolArgs };
|
|
|
|
// Link previousSiblings as a chain (last element is the direct previousSibling)
|
|
let prevSibling: MockNode | null = null;
|
|
for (const s of previousSiblings) {
|
|
s.previousSibling = prevSibling;
|
|
prevSibling = s;
|
|
}
|
|
|
|
const callNode: MockNode = {
|
|
type: 'call',
|
|
text: '',
|
|
previousSibling: prevSibling,
|
|
childForFieldName: (name: string) => (name === 'arguments' ? argList : undefined),
|
|
};
|
|
return callNode;
|
|
}
|
|
|
|
/** Build a comment node (isNamed = false by default, matching real tree-sitter Ruby) */
|
|
function makeCommentNode(text: string, named = false): MockNode {
|
|
return { type: 'comment', text, isNamed: named };
|
|
}
|
|
|
|
/** Build a named non-comment sibling (causes yard-scan loop to stop) */
|
|
function makeNamedSibling(type = 'expression_statement'): MockNode {
|
|
return { type, text: '', isNamed: true };
|
|
}
|
|
|
|
// ── require / require_relative ───────────────────────────────────────────────
|
|
|
|
describe('routeRubyCall — require / require_relative', () => {
|
|
it('require with a valid string path returns import with isRelative=false', () => {
|
|
const node = makeRequireCallNode('net/http');
|
|
const result = routeRubyCall('require', node);
|
|
|
|
expect(result).toEqual({ kind: 'import', importPath: 'net/http', isRelative: false });
|
|
});
|
|
|
|
it('require_relative without leading dot prepends "./"', () => {
|
|
const node = makeRequireCallNode('models/user');
|
|
const result = routeRubyCall('require_relative', node);
|
|
|
|
expect(result).toEqual({ kind: 'import', importPath: './models/user', isRelative: true });
|
|
});
|
|
|
|
it('require_relative with path already starting with "." does not double-prepend', () => {
|
|
const node = makeRequireCallNode('./helpers/formatter');
|
|
const result = routeRubyCall('require_relative', node);
|
|
|
|
expect(result).toEqual({ kind: 'import', importPath: './helpers/formatter', isRelative: true });
|
|
});
|
|
|
|
it('require_relative with "../" prefix is left unchanged', () => {
|
|
const node = makeRequireCallNode('../shared/utils');
|
|
const result = routeRubyCall('require_relative', node);
|
|
|
|
expect(result).toEqual({ kind: 'import', importPath: '../shared/utils', isRelative: true });
|
|
});
|
|
|
|
it('returns skip when there is no string_content node (non-literal argument)', () => {
|
|
const node = makeRequireCallNodeNoContent();
|
|
expect(routeRubyCall('require', node)).toEqual({ kind: 'skip' });
|
|
});
|
|
|
|
it('returns skip when import path is an empty string', () => {
|
|
const node = makeRequireCallNode('');
|
|
expect(routeRubyCall('require', node)).toEqual({ kind: 'skip' });
|
|
});
|
|
|
|
it('returns skip when import path contains a control character (\\x00)', () => {
|
|
const node = makeRequireCallNode('some\x00path');
|
|
expect(routeRubyCall('require', node)).toEqual({ kind: 'skip' });
|
|
});
|
|
|
|
it('returns skip when import path contains a newline control character (\\n)', () => {
|
|
const node = makeRequireCallNode('path\ninjection');
|
|
expect(routeRubyCall('require', node)).toEqual({ kind: 'skip' });
|
|
});
|
|
|
|
it('returns skip when import path exceeds 1024 characters', () => {
|
|
const longPath = 'a'.repeat(1025);
|
|
const node = makeRequireCallNode(longPath);
|
|
expect(routeRubyCall('require', node)).toEqual({ kind: 'skip' });
|
|
});
|
|
|
|
it('accepts import path of exactly 1024 characters', () => {
|
|
const maxPath = 'a'.repeat(1024);
|
|
const node = makeRequireCallNode(maxPath);
|
|
const result = routeRubyCall('require', node);
|
|
expect(result).toEqual({ kind: 'import', importPath: maxPath, isRelative: false });
|
|
});
|
|
|
|
it('returns skip when argument list has no string child at all', () => {
|
|
// argList has only a non-string child
|
|
const argList: MockNode = {
|
|
type: 'argument_list',
|
|
text: '',
|
|
children: [{ type: 'identifier', text: 'MY_CONST' }],
|
|
};
|
|
const node: MockNode = {
|
|
type: 'call',
|
|
text: '',
|
|
childForFieldName: (name: string) => (name === 'arguments' ? argList : undefined),
|
|
};
|
|
expect(routeRubyCall('require', node)).toEqual({ kind: 'skip' });
|
|
});
|
|
|
|
it('returns skip when childForFieldName is absent (undefined callNode fields)', () => {
|
|
// callNode has no childForFieldName method at all
|
|
const node: MockNode = { type: 'call', text: '' };
|
|
expect(routeRubyCall('require', node)).toEqual({ kind: 'skip' });
|
|
});
|
|
});
|
|
|
|
// ── include / extend / prepend ───────────────────────────────────────────────
|
|
// Heritage edges for include/extend/prepend are emitted by the scope-resolution
|
|
// pipeline, not by the call router. routeRubyCall returns 'skip' for these so
|
|
// they don't become spurious call edges or fall through to normal call
|
|
// processing.
|
|
|
|
describe('routeRubyCall — include / extend / prepend (heritage owned by scope-resolution)', () => {
|
|
it('include returns skip (heritage emitted by scope-resolution, not a call edge)', () => {
|
|
const node = makeHeritageCallNode([makeConstantArg('Serializable')], 'class', 'User');
|
|
expect(routeRubyCall('include', node)).toEqual({ kind: 'skip' });
|
|
});
|
|
|
|
it('extend returns skip (heritage emitted by scope-resolution, not a call edge)', () => {
|
|
const node = makeHeritageCallNode(
|
|
[makeScopeResolutionArg('ActiveSupport::Concern')],
|
|
'class',
|
|
'Post',
|
|
);
|
|
expect(routeRubyCall('extend', node)).toEqual({ kind: 'skip' });
|
|
});
|
|
|
|
it('prepend returns skip (heritage emitted by scope-resolution, not a call edge)', () => {
|
|
const node = makeHeritageCallNode([makeConstantArg('Instrumented')], 'class', 'Service');
|
|
expect(routeRubyCall('prepend', node)).toEqual({ kind: 'skip' });
|
|
});
|
|
});
|
|
|
|
// ── attr_accessor / attr_reader / attr_writer ────────────────────────────────
|
|
|
|
describe('routeRubyCall — attr_accessor / attr_reader / attr_writer', () => {
|
|
it('attr_accessor with a single symbol returns a property item', () => {
|
|
const node = makeAccessorCallNode([makeSimpleSymbol('name', 5)]);
|
|
const result = routeRubyCall('attr_accessor', node);
|
|
|
|
expect(result).toEqual({
|
|
kind: 'properties',
|
|
items: [{ propName: 'name', accessorType: 'attr_accessor', startLine: 5, endLine: 5 }],
|
|
});
|
|
});
|
|
|
|
it('attr_reader sets accessorType to "attr_reader"', () => {
|
|
const node = makeAccessorCallNode([makeSimpleSymbol('age', 3)]);
|
|
const result = routeRubyCall('attr_reader', node);
|
|
|
|
expect(result).toEqual({
|
|
kind: 'properties',
|
|
items: [{ propName: 'age', accessorType: 'attr_reader', startLine: 3, endLine: 3 }],
|
|
});
|
|
});
|
|
|
|
it('attr_writer sets accessorType to "attr_writer"', () => {
|
|
const node = makeAccessorCallNode([makeSimpleSymbol('email', 7)]);
|
|
const result = routeRubyCall('attr_writer', node);
|
|
|
|
expect(result).toEqual({
|
|
kind: 'properties',
|
|
items: [{ propName: 'email', accessorType: 'attr_writer', startLine: 7, endLine: 7 }],
|
|
});
|
|
});
|
|
|
|
it('strips leading colon from symbol text', () => {
|
|
// makeSimpleSymbol already prefixes with ':', this validates the slice(1) branch
|
|
const symNode: MockNode = {
|
|
type: 'simple_symbol',
|
|
text: ':title',
|
|
startPosition: { row: 2 },
|
|
endPosition: { row: 2 },
|
|
};
|
|
const node = makeAccessorCallNode([symNode]);
|
|
const result = routeRubyCall('attr_accessor', node);
|
|
|
|
expect(result).toMatchObject({ kind: 'properties', items: [{ propName: 'title' }] });
|
|
});
|
|
|
|
it('handles symbol text without colon prefix (no double-strip)', () => {
|
|
// Simulate a symbol whose text does NOT start with ':'
|
|
const symNode: MockNode = {
|
|
type: 'simple_symbol',
|
|
text: 'status',
|
|
startPosition: { row: 1 },
|
|
endPosition: { row: 1 },
|
|
};
|
|
const node = makeAccessorCallNode([symNode]);
|
|
const result = routeRubyCall('attr_accessor', node);
|
|
|
|
expect(result).toMatchObject({ kind: 'properties', items: [{ propName: 'status' }] });
|
|
});
|
|
|
|
it('multiple symbols produce one item each', () => {
|
|
const args = [
|
|
makeSimpleSymbol('first_name', 10),
|
|
makeSimpleSymbol('last_name', 10),
|
|
makeSimpleSymbol('dob', 10),
|
|
];
|
|
const node = makeAccessorCallNode(args);
|
|
const result = routeRubyCall('attr_accessor', node);
|
|
|
|
expect(result).toEqual({
|
|
kind: 'properties',
|
|
items: [
|
|
{ propName: 'first_name', accessorType: 'attr_accessor', startLine: 10, endLine: 10 },
|
|
{ propName: 'last_name', accessorType: 'attr_accessor', startLine: 10, endLine: 10 },
|
|
{ propName: 'dob', accessorType: 'attr_accessor', startLine: 10, endLine: 10 },
|
|
],
|
|
});
|
|
});
|
|
|
|
it('extracts simple YARD @return [Type] from preceding comment', () => {
|
|
const comment = makeCommentNode('# @return [Address]');
|
|
const node = makeAccessorCallNode([makeSimpleSymbol('address', 20)], [comment]);
|
|
const result = routeRubyCall('attr_accessor', node);
|
|
|
|
expect(result).toMatchObject({
|
|
kind: 'properties',
|
|
items: [{ propName: 'address', declaredType: 'Address' }],
|
|
});
|
|
});
|
|
|
|
it('extracts only the leading type name from compound YARD type (Array<User> → "Array")', () => {
|
|
// The regex captures "Array<User>"; the simple match grabs the first uppercase word "Array"
|
|
const comment = makeCommentNode('# @return [Array<User>]');
|
|
const node = makeAccessorCallNode([makeSimpleSymbol('users', 15)], [comment]);
|
|
const result = routeRubyCall('attr_accessor', node);
|
|
|
|
expect(result).toMatchObject({
|
|
kind: 'properties',
|
|
items: [{ declaredType: 'Array' }],
|
|
});
|
|
});
|
|
|
|
it('extracts type from YARD comment with extra whitespace inside brackets', () => {
|
|
const comment = makeCommentNode('# @return [ Integer ]');
|
|
const node = makeAccessorCallNode([makeSimpleSymbol('count', 8)], [comment]);
|
|
const result = routeRubyCall('attr_accessor', node);
|
|
|
|
expect(result).toMatchObject({
|
|
kind: 'properties',
|
|
items: [{ declaredType: 'Integer' }],
|
|
});
|
|
});
|
|
|
|
it('does not set declaredType when no YARD comment precedes the call', () => {
|
|
const node = makeAccessorCallNode([makeSimpleSymbol('score', 12)]);
|
|
const result = routeRubyCall('attr_accessor', node);
|
|
|
|
expect(result).toMatchObject({ kind: 'properties', items: [{ propName: 'score' }] });
|
|
const item = (result as any).items[0];
|
|
expect(item.declaredType).toBeUndefined();
|
|
});
|
|
|
|
it('does not set declaredType when comment has no @return annotation', () => {
|
|
const comment = makeCommentNode('# This accessor stores the user name');
|
|
const node = makeAccessorCallNode([makeSimpleSymbol('user_name', 9)], [comment]);
|
|
const result = routeRubyCall('attr_accessor', node);
|
|
|
|
const item = (result as any).items[0];
|
|
expect(item.declaredType).toBeUndefined();
|
|
});
|
|
|
|
it('does not set declaredType when YARD type starts with lowercase (not ^[A-Z])', () => {
|
|
// e.g. "@return [string]" — lowercase first char fails the simple = raw.match(/^([A-Z]\w*)/)
|
|
const comment = makeCommentNode('# @return [string]');
|
|
const node = makeAccessorCallNode([makeSimpleSymbol('label', 4)], [comment]);
|
|
const result = routeRubyCall('attr_accessor', node);
|
|
|
|
const item = (result as any).items[0];
|
|
expect(item.declaredType).toBeUndefined();
|
|
});
|
|
|
|
it('stops sibling scan at a non-comment named sibling before reaching a comment', () => {
|
|
// Ordered as [comment, namedSibling] — namedSibling is the direct previousSibling,
|
|
// so the scan hits it first and stops before reading the comment
|
|
const yardComment = makeCommentNode('# @return [User]');
|
|
const named = makeNamedSibling();
|
|
const node = makeAccessorCallNode([makeSimpleSymbol('owner', 6)], [yardComment, named]);
|
|
// named is last in the array → becomes direct previousSibling
|
|
const result = routeRubyCall('attr_accessor', node);
|
|
|
|
const item = (result as any).items[0];
|
|
expect(item.declaredType).toBeUndefined();
|
|
});
|
|
|
|
it('continues past unnamed (non-named) siblings to find a YARD comment', () => {
|
|
// An unnamed whitespace/punctuation node between the comment and the call
|
|
const unnamedNode: MockNode = { type: 'newline', text: '\n', isNamed: false };
|
|
const comment = makeCommentNode('# @return [Order]');
|
|
// siblings in order oldest→newest; the last becomes the direct previousSibling
|
|
const node = makeAccessorCallNode([makeSimpleSymbol('order', 30)], [comment, unnamedNode]);
|
|
const result = routeRubyCall('attr_accessor', node);
|
|
|
|
expect(result).toMatchObject({
|
|
kind: 'properties',
|
|
items: [{ declaredType: 'Order' }],
|
|
});
|
|
});
|
|
|
|
it('returns skip when arg list contains no simple_symbol nodes', () => {
|
|
// Only an identifier node — not a symbol
|
|
const identArg: MockNode = { type: 'identifier', text: 'some_var' };
|
|
const node = makeAccessorCallNode([identArg]);
|
|
expect(routeRubyCall('attr_accessor', node)).toEqual({ kind: 'skip' });
|
|
});
|
|
|
|
it('returns skip when arg list is empty', () => {
|
|
const node = makeAccessorCallNode([]);
|
|
expect(routeRubyCall('attr_accessor', node)).toEqual({ kind: 'skip' });
|
|
});
|
|
|
|
it('records correct startLine and endLine from symbol node positions', () => {
|
|
const sym: MockNode = {
|
|
type: 'simple_symbol',
|
|
text: ':created_at',
|
|
startPosition: { row: 42 },
|
|
endPosition: { row: 42 },
|
|
};
|
|
const node = makeAccessorCallNode([sym]);
|
|
const result = routeRubyCall('attr_accessor', node);
|
|
|
|
expect(result).toMatchObject({
|
|
kind: 'properties',
|
|
items: [{ startLine: 42, endLine: 42 }],
|
|
});
|
|
});
|
|
});
|
|
|
|
// ── default case ─────────────────────────────────────────────────────────────
|
|
|
|
describe('routeRubyCall — default (unknown method name)', () => {
|
|
it('returns {kind: "call"} for an arbitrary method name', () => {
|
|
const node: MockNode = { type: 'call', text: '' };
|
|
expect(routeRubyCall('some_method', node)).toEqual({ kind: 'call' });
|
|
});
|
|
|
|
it('returns {kind: "call"} for an empty method name string', () => {
|
|
const node: MockNode = { type: 'call', text: '' };
|
|
expect(routeRubyCall('', node)).toEqual({ kind: 'call' });
|
|
});
|
|
|
|
it('returns {kind: "call"} for a realistic method name (save, render, etc.)', () => {
|
|
const node: MockNode = { type: 'call', text: '' };
|
|
expect(routeRubyCall('render', node)).toEqual({ kind: 'call' });
|
|
expect(routeRubyCall('save', node)).toEqual({ kind: 'call' });
|
|
expect(routeRubyCall('destroy', node)).toEqual({ kind: 'call' });
|
|
});
|
|
});
|
|
|
|
// ── routeRubyCall passthrough ────────────────────────────────────────────────
|
|
|
|
describe('routeRubyCall passthrough', () => {
|
|
it('routeRubyCall delegates correctly for require', () => {
|
|
const node = makeRequireCallNode('json');
|
|
const result = routeRubyCall('require', node);
|
|
expect(result).toEqual({ kind: 'import', importPath: 'json', isRelative: false });
|
|
});
|
|
|
|
it('routeRubyCall returns {kind: "call"} for an unknown method name', () => {
|
|
const node: MockNode = { type: 'call', text: '' };
|
|
const result = routeRubyCall('render', node);
|
|
expect(result).toEqual({ kind: 'call' });
|
|
});
|
|
});
|