diff --git a/gitnexus/bench/import-target/baselines.json b/gitnexus/bench/import-target/baselines.json index 7b9a9932d..3752a9291 100644 --- a/gitnexus/bench/import-target/baselines.json +++ b/gitnexus/bench/import-target/baselines.json @@ -31,7 +31,8 @@ "c": 3.8, "cpp": 4, "objc": 1.8, - "zig": 1.8 + "zig": 1.8, + "elixir": 1.8 }, "depth_budget": { "go": 1.4, @@ -52,7 +53,8 @@ "c": 3, "cpp": 3, "objc": 3.6, - "zig": 2.4 + "zig": 2.4, + "elixir": 1.8 }, "small_ms_ceiling": { "go": 7, @@ -73,7 +75,8 @@ "c": 7, "cpp": 7, "objc": 8, - "zig": 4 + "zig": 4, + "elixir": 2 }, "collide_ms_ceiling": { "go": 28, @@ -94,7 +97,8 @@ "c": 11, "cpp": 12, "objc": 8, - "zig": 7 + "zig": 7, + "elixir": 2 }, "heap_ceiling_bytes": { "kotlin": 6800000, @@ -108,7 +112,8 @@ "php": 59410824, "java": 5600000, "python": 9541404, - "c": 15000000 + "c": 15000000, + "elixir": 75588 }, "_heap_reading_note": "heap_reading_bytes records each measured large-corpus reading so the 0.5x floor is independent of its ceiling. Ceilings use the standard 1.5x allowance for cross-platform and Node heap-accounting differences; re-baseline the reading and ceiling together.", "_kotlin_declared_package_gate": "#2960 replaces Kotlin\u0027s path-suffix cascade with one declared-package/module-binding index. The 32000-file arm measured 4516944 retained bytes (4.31 MiB), with a 6800000-byte ceiling. Correctness and reuse are pinned separately by kotlin-module-resolution.test.ts, external-import-conformance.test.ts, the shared index-reuse contract, and bench/kotlin-import-target.", @@ -124,7 +129,8 @@ "php": 39607216, "java": 3676984, "python": 6360936, - "c": 10018816 + "c": 10018816, + "elixir": 50392 }, "_heap_bound_note": "THE SECOND HEAP TIER. Every registered language is measured now; heap_bound_bytes gates the nine that are not BUDGETED above, and it gates them with one comparison and no floor. A ceiling says 'this index is not too big'. A bound says something narrower and it is the thing that was missing: 'the exclusion still holds' \u2014 this language has not grown an index since it was left out. measure.mjs's MEMORY section states the re-entry condition (if a language ever diverges in what it ASKS its index, it earns a budgeted arm) and until now nothing watched for the divergence; HEAP_LANGS was a hand-maintained list of eight whose two neighbours, LANG_REGISTRY and CONTEXT_LANGS, are both reconciled against a derived predicate in both directions. HEAP_BOUNDED is derived too \u2014 it is LANGS minus HEAP_BUDGETED \u2014 so the two tiers partition the languages and a new one cannot land outside both. WHAT RE-MEASURING FOUND, five runs each, maximum quoted, peak-to-peak in brackets. go 2998464 B [1.0021], dart 7834200 B [1.0006] and kotlin 42802456 B [1.0004] HAD NO STATED REASON AT ALL: the old prose opened 'SIX of the seventeen are deliberately NOT in HEAP_LANGS' against a list of eight of seventeen, and these three were the three nobody counted. All three retain a real per-pass structure (go's PackageDirIndex, dart's basename buckets, kotlin's suffixByStem cascade) and kotlin's 40.82 MiB is above ruby's 39.12 and java's 33.34, both of which carry a full budget. (It read 45.85 MiB when this was written, described here as 'the second-largest reading in this file' \u2014 it was third even then, behind csharp_csproj and php; #2881 later compacted its dirChildren buckets and took 11% off it. Same staleness this paragraph exists to document.) swift 3449216 B [1.0024] and cobol 2320456 B [1.0000] were excluded as 'below the measurement's own noise floor' on readings of 0.29 MB and 0 B at 32000 files; they now read 3.29 MB and 2.21 MB, growing with the corpus (969120 B and 536264 B at 8000). Those old numbers were not wrong when taken \u2014 the ARM changed under them, when #2903's follow-up made every probe resolve a real import and when measureHeap began flattening its corpus \u2014 which is the whole finding: a measurement written into prose is not re-taken, and this file had already gone stale against itself, quoting javascript at 46208832 B four paragraphs after quoting it at 25.51 MiB. rust is the one exclusion that survived unchanged: 16 B at 8000 files and 16 B at 32000, identical in all five runs. typescript 26745296 B, vue 28884016 B and cpp 10023344 B are duplicates of a builder AND of a read pattern: typescript is byte-identical to javascript's 26745296 in four runs of five, cpp is +0.05% of c's 10018816, vue is +8.0% of javascript. HOW THE BOUNDS WERE CHOSEN. Each takes 1.5x its measured maximum, rounded up to the next 100000 B: cobol 6200000 (1.508x of 4112464 B measured after copybook-dir preference; previously 3500000 based on 2320456 B before the behavior change), swift 5200000 (1.508x). (This sentence used to list eight, including go, dart, kotlin, typescript, vue and cpp. Those six were promoted to the budgeted tier and their bounds deleted; the numbers stayed here, unread by any gate, and #2881 dutifully updated kotlin's to 64300000 before anyone noticed heap_bound_bytes holds only cobol, swift and rust. A number nothing asserts is a number that rots \u2014 the finding this paragraph is otherwise about.) 1.5x is NOT copied from the ceilings out of habit \u2014 it is the same number for a stated reason, and the reason is not noise: measured peak-to-peak on this box is at most 1.0024, so noise alone would justify 1.05x. What a bound has to survive is a RUNNER change, since heapUsed accounting moves across platforms and Node majors, and this file already fixes that allowance at 50% for exactly this measurement on exactly this arm. Using a second allowance for the same uncertainty on the same number would be two conventions, not more rigour. At 1.5x the bound catches what the re-entry condition is about \u2014 a language growing an index, which costs +85% for one more suffix map and +100% for a duplicate \u2014 and it does NOT catch a duplicate diverging by 8%. That limit is real and is stated rather than hidden: the tight form is a same-process ratio against the arm each duplicate is a duplicate OF, which is the only form immune to the drift the absolute bound has to tolerate. RUST TAKES AN ABSOLUTE BOUND INSTEAD, 1048576 B (1 MiB), because 1.5 x 16 B is 24 B and would fail on the first byte of anything \u2014 a multiplier on a reading that is already nothing is a gate that flakes rather than a gate that bites. 1 MiB is ~65000x the reading and still 3.9x below the smallest real index measured here (cobol's 3.92 MB at the same file count after copybook-dir preference), so it separates 'builds nothing' from 'builds something' with room on both sides. NO FLOOR ON ANY OF THE NINE, and the reason differs by language rather than being uniform. For rust a floor would be a floor on noise. For the other eight the readings are stable enough to floor today, and for kotlin and dart \u2014 larger than budgeted arms \u2014 a floor would be worth having, since a lazily-built map going quiet is exactly how the four budgeted arms once read 0 B. Adding one is a PROMOTION to the budgeted tier, with a ceiling and a recorded reading beside it, not a line here: a floor whose companion ceiling does not exist asserts 'still measuring' against a number nothing else bounds. Recommended next, in order: kotlin, then dart, then go.", "heap_bound_bytes": { @@ -1085,6 +1091,62 @@ "small_ms": 1.844 } }, + "elixir": { + "small": { + "files": 400, + "imports": 3200, + "resolved": 1153, + "distinct_outcomes": 3154, + "fingerprint": "72e9eaa4893d907dbc144cfb3eef1782a2369ade13340dc23e662859e819db43" + }, + "large": { + "files": 1600, + "imports": 12800, + "resolved": 4681, + "distinct_outcomes": 12614, + "fingerprint": "c1c0002787ce3104e91eca446caffd307ba4bea3bd552210a35b491c6df9cbde" + }, + "deep": { + "files": 400, + "imports": 3200, + "resolved": 1153, + "distinct_outcomes": 3154, + "fingerprint": "aeac2c9721642f2ff21f6b3290bedca21283abd82c6eb65639b063c3601ce724" + }, + "collide": { + "files": 400, + "imports": 3200, + "resolved": 1153, + "distinct_outcomes": 3154, + "fingerprint": "eafdccb22fe9461b004a883d3e88d922d805d23c2049ca062d383925ae6bab49" + }, + "collide_large": { + "files": 1600, + "imports": 12800, + "resolved": 4681, + "distinct_outcomes": 12614, + "fingerprint": "b3050d1b36ebe1fde55836040b79870c975b46b36d1a52b1b1d851e0f2bf7eed" + }, + "fingerprint": "c1c0002787ce3104e91eca446caffd307ba4bea3bd552210a35b491c6df9cbde", + "heap": { + "files_small": 8000, + "files_large": 32000, + "path_segments": 11, + "probe": "Vendor0.Missing" + }, + "context": { + "target": "Demo.Target", + "with_context": "lib/Target.ex", + "without_context": "" + }, + "_measured": { + "collide_ms": 0.234, + "collide_scaling_ratio": 1.053, + "depth_ratio": 0.971, + "scaling_ratio": 0.983, + "small_ms": 0.243 + } + }, "zig": { "small": { "files": 400, diff --git a/gitnexus/bench/import-target/measure.mjs b/gitnexus/bench/import-target/measure.mjs index b66932d77..11ec68ad7 100644 --- a/gitnexus/bench/import-target/measure.mjs +++ b/gitnexus/bench/import-target/measure.mjs @@ -484,6 +484,7 @@ import { resolveSwiftImportTarget } from '../../src/core/ingestion/languages/swi import { resolveRustImportTarget } from '../../src/core/ingestion/languages/rust/import-target.ts'; import { resolveZigImportInternal } from '../../src/core/ingestion/import-resolvers/zig.ts'; import { resolvePythonImportTarget } from '../../src/core/ingestion/languages/python/import-target.ts'; +import { elixirScopeResolver } from '../../src/core/ingestion/languages/elixir/scope-resolver.ts'; import { makeJsResolveImportTarget } from '../../src/core/ingestion/languages/javascript/import-target.ts'; import { makeVueResolveImportTarget } from '../../src/core/ingestion/languages/vue/import-target.ts'; // The two `ScopeResolver`s, not their inner resolvers — see `RESOLVE_HOOK`. @@ -600,6 +601,7 @@ const HEAP_BUDGETED = [ 'go', 'cpp', 'objc', + 'elixir', ]; // javascript, typescript and vue were budgeted here until #2953 and are now // BOUNDED, which is a demotion in gate strength and a promotion in what the @@ -627,7 +629,7 @@ const HEAP_BUDGETED = [ * their hooks declare three or four parameters — so their numbers stay exactly * where they were. */ -const CONTEXT_LANGS = ['php', 'java', 'kotlin', 'python', 'swift']; +const CONTEXT_LANGS = ['php', 'java', 'kotlin', 'python', 'swift', 'elixir']; /** * Needs `node --expose-gc` to force collection for a clean delta; without it @@ -759,6 +761,7 @@ const EXTENSION = { c: '.c', cpp: '.cpp', objc: '.m', + elixir: '.ex', zig: '.zig', }; /** C and C++ resolve `#include` against HEADERS, which reach the resolver @@ -883,6 +886,7 @@ function uniqueDir(lang, d, i) { // `resolutionConfig` load-bearing. Odd `i` is the header. if (lang === 'c' || lang === 'cpp') return i % 2 === 1 ? `include/comp${d}` : `src/comp${d}`; if (lang === 'objc') return `src/comp${d}`; + if (lang === 'elixir') return `lib/App${d}`; if (lang === 'ruby') return `lib/mod${d}`; // One flat `src/mod{d}/` per index and NO nested slice, on purpose: a Zig // import is spelled RELATIVE TO THE IMPORTER, and `uniqueTarget` does not @@ -979,6 +983,7 @@ function collideDir(lang, d, i) { if (lang === 'vue') return `src/pkg${d}/components`; if (lang === 'c' || lang === 'cpp') return i % 2 === 1 ? `svc${d}/include` : `svc${d}/src`; if (lang === 'objc') return `svc${d}/src`; + if (lang === 'elixir') return `lib/Svc${d}/App`; if (lang === 'ruby') return `svc${d}/lib/models`; // Rust's reasoning, verbatim: the resolver walks path components and probes // `.has()`, never searches, so file count is not an axis its cost has and a @@ -1408,6 +1413,9 @@ function uniqueTarget(lang, { local, r, d, j, dirs }) { if (lang === 'objc') { return local ? `comp${j % dirs}/file${j}.m` : `vendor${(r >>> 4) % 97}/missing.m`; } + if (lang === 'elixir') { + return local ? `App${j % dirs}.file${j}` : `Vendor${(r >>> 4) % 97}.Missing`; + } if (lang === 'ruby') { return local ? `mod${d}/file${j}` @@ -1641,6 +1649,9 @@ function collideTarget(lang, { local, r, d, j, dirs }) { if (lang === 'objc') { return local ? `src/file${j}.m` : `vendor${(r >>> 4) % 97}/missing.m`; } + if (lang === 'elixir') { + return local ? `App.file${j}` : `Vendor${(r >>> 4) % 97}.Missing`; + } if (lang === 'ruby') { // `models/mod{n}.rb` in every package. Ruby answers `require` from a keyed // suffix map, so the repeated basename cannot grow a bucket: this arm @@ -1926,6 +1937,15 @@ function resolveOne(lang, from, target, pass) { if (lang === 'objc') { return objectiveCScopeResolver.resolveImportTarget(target, from, allFilePaths, pass.config); } + if (lang === 'elixir') { + return elixirScopeResolver.resolveImportTarget( + target, + from, + allFilePaths, + pass.config, + contextFor(pass, { kind: 'namespace', localName: 'X', importedName: 'X', targetRaw: target }), + ); + } if (lang === 'csharp' || lang === 'csharp_csproj') { return resolveCsharpImportTarget( { kind: 'namespace', localName: '_', importedName: '_', targetRaw: target }, @@ -2147,6 +2167,7 @@ const HEAP_PROBE_TARGET = { python: 'vendor0.deep.missing', c: 'vendor0/missing.h', objc: 'vendor0/missing.m', + elixir: 'Vendor0.Missing', // The entries below cover the BOUNDED tier — see `HEAP_BOUNDED`, which // derives to cobol, swift and rust; the rest were promoted. Same rule as the // budgeted ones above: a spelling `uniqueTarget` already mints for that language, and @@ -2346,6 +2367,14 @@ const CONTEXT_PROBE = { probeFile('Sources/Client/Main.swift', [['Class', 'Client.Main']]), ], }, + elixir: { + from: 'lib/Client.ex', + target: 'Demo.Target', + parsedFiles: [ + probeFile('lib/Client.ex', [['Class', 'Client']]), + probeFile('lib/Target.ex', [['Class', 'Demo.Target']]), + ], + }, }; /** Resolve the probe twice through `resolveOne` — once with the pass's parsed @@ -2430,6 +2459,7 @@ const LANG_REGISTRY = { c: SupportedLanguages.C, cpp: SupportedLanguages.CPlusPlus, objc: SupportedLanguages.ObjectiveC, + elixir: SupportedLanguages.Elixir, zig: SupportedLanguages.Zig, }; const LANGS = Object.keys(LANG_REGISTRY); diff --git a/gitnexus/src/core/embeddings/ast-utils.ts b/gitnexus/src/core/embeddings/ast-utils.ts index b29ca80fb..136e3bc60 100644 --- a/gitnexus/src/core/embeddings/ast-utils.ts +++ b/gitnexus/src/core/embeddings/ast-utils.ts @@ -111,6 +111,7 @@ export const findDeclarationNode = (root: any): any | null => { 'declaration', // Go: type X struct 'object_declaration', // Kotlin: object 'impl_item', // Rust: impl + 'call', // Elixir: defmodule ]); // Iterative DFS — avoids stack overflow on deeply nested ASTs. diff --git a/gitnexus/src/core/ingestion/cfg/visitors/elixir.ts b/gitnexus/src/core/ingestion/cfg/visitors/elixir.ts index 476c9355d..5baf5422a 100644 --- a/gitnexus/src/core/ingestion/cfg/visitors/elixir.ts +++ b/gitnexus/src/core/ingestion/cfg/visitors/elixir.ts @@ -298,6 +298,15 @@ class ElixirHarvester { visitCalls(node); for (let i = 0; i < memberNodes.length; i++) { const member = memberNodes[i]!; + const pipe = isPipe(member.parent) ? member.parent : undefined; + const pipedCall = pipe?.namedChildren[1]; + if (pipedCall?.type === 'call') { + const parentIndex = callSites.get(key(pipedCall)) ?? -1; + if (parentIndex >= 0) { + sites[i] = { ...sites[i]!, parent: [parentIndex, 0] }; + continue; + } + } for (let ancestor = member.parent; ancestor; ancestor = ancestor.parent) { if (ancestor.type !== 'call') continue; const args = ancestor.namedChildren.find((child) => child.type === 'arguments'); diff --git a/gitnexus/src/core/ingestion/languages/elixir.ts b/gitnexus/src/core/ingestion/languages/elixir.ts index c23ce5c04..67508a451 100644 --- a/gitnexus/src/core/ingestion/languages/elixir.ts +++ b/gitnexus/src/core/ingestion/languages/elixir.ts @@ -372,7 +372,16 @@ function extractElixirFrameworkFacts(tree: Parser.Tree): readonly ElixirFramewor const inPair = keywords?.namedChildren.find( (value) => value.type === 'pair' && value.namedChild(0)?.text.trim() === 'in:', ); - const model = alias(inPair?.namedChild(1) as SyntaxNode); + const inExpression = values.find( + (value) => + value.type === 'binary_operator' && + value.childForFieldName?.('left')?.type === 'identifier' && + value.childForFieldName?.('right')?.type === 'alias' && + /\bin\b/.test(value.text), + ); + const model = alias( + (inPair?.namedChild(1) ?? inExpression?.childForFieldName?.('right')) as SyntaxNode, + ); if (model) facts.push({ kind: 'query', model, method: 'from', line: node.startPosition.row + 1 }); } @@ -687,7 +696,13 @@ function emitElixirScopeCaptures( startCol: node.startPosition.column, }); } else if (target?.type === 'alias') { - add('@import.statement', node, { '@import.source': target, '@import.wildcard': target }); + // `bindingAugmentations` can only add references after wildcard imports + // are finalized, so an `except` import must not emit a wildcard here. + if (!except) + add('@import.statement', node, { + '@import.source': target, + '@import.wildcard': target, + }); if (except?.type === 'list') { const excluded = except.namedChildren .flatMap((entry) => (entry.type === 'keywords' ? entry.namedChildren : [entry])) diff --git a/gitnexus/src/core/ingestion/languages/elixir/scope-resolver.ts b/gitnexus/src/core/ingestion/languages/elixir/scope-resolver.ts index f1fbda955..7afd98e1e 100644 --- a/gitnexus/src/core/ingestion/languages/elixir/scope-resolver.ts +++ b/gitnexus/src/core/ingestion/languages/elixir/scope-resolver.ts @@ -104,7 +104,12 @@ function populateElixirImportFilters( const bucket = augmentations.get(scopeId) ?? new Map(); augmentations.set(scopeId, bucket); for (const def of targets[0]!.localDefs) { - if ((def.type !== 'Function' && def.type !== 'Macro') || def.isExported === false) continue; + if ( + (def.type !== 'Function' && def.type !== 'Macro') || + def.isExported === false || + def.qualifiedName !== `${fact.target}.${callableName(def)}` + ) + continue; if (fact.mode === 'only' && fact.category === 'functions' && def.type !== 'Function') continue; if (fact.mode === 'only' && fact.category === 'macros' && def.type !== 'Macro') continue; diff --git a/gitnexus/src/core/ingestion/languages/elixir/semantic-graph.ts b/gitnexus/src/core/ingestion/languages/elixir/semantic-graph.ts index 0fa5e4249..0ae9f478a 100644 --- a/gitnexus/src/core/ingestion/languages/elixir/semantic-graph.ts +++ b/gitnexus/src/core/ingestion/languages/elixir/semantic-graph.ts @@ -104,6 +104,7 @@ function isBehaviourModule(node: SyntaxNode): boolean { const visit = (child: SyntaxNode): void => { if (found || (child.type === 'call' && keyword(child) === 'defmodule' && child !== node)) return; + if (child.type === 'call' && keyword(child) === 'quote') return; if (child.type === 'unary_operator' && child.text.startsWith('@callback')) found = true; for (let i = 0; !found && i < child.namedChildCount; i++) { const next = child.namedChild(i); diff --git a/gitnexus/src/core/ingestion/utils/ast-helpers.ts b/gitnexus/src/core/ingestion/utils/ast-helpers.ts index 6d2c24779..8b017e29f 100644 --- a/gitnexus/src/core/ingestion/utils/ast-helpers.ts +++ b/gitnexus/src/core/ingestion/utils/ast-helpers.ts @@ -928,8 +928,9 @@ export const findEnclosingClassInfo = ( /** * Optional: the type a CONTAINER node declares * (`LanguageProvider.resolveContainerTypeOwner`). Consulted for every - * `CLASS_CONTAINER_TYPES` node the walk meets, before the generic name-child - * derivation, for languages whose containers are named from context (a + * ancestor the walk meets; it must return null for nodes it does not own. + * This supports languages whose containers are outside `CLASS_CONTAINER_TYPES` + * (for example, Elixir's `defmodule` call) or named from context (a * binding wrapper, an enclosing callable, an anonymous ordinal). Null falls * through to the generic derivation. */ @@ -1010,9 +1011,8 @@ export const findEnclosingClassInfo = ( }; } } - // Provider-owned containers may use grammar nodes outside the generic - // class list (Elixir's `defmodule` is a call). Returning null preserves - // every existing provider's fallback behavior. + // Provider-owned containers may use grammar nodes outside the generic class + // list (Elixir's `defmodule` is a call). Returning null preserves fallback. if (resolveContainerTypeOwner !== undefined) { const containerOwner = resolveContainerTypeOwner(current, filePath); if (containerOwner !== null) { diff --git a/gitnexus/test/integration/elixir-phoenix-ecto-pipeline.test.ts b/gitnexus/test/integration/elixir-phoenix-ecto-pipeline.test.ts index cd682a000..4b1f5d47b 100644 --- a/gitnexus/test/integration/elixir-phoenix-ecto-pipeline.test.ts +++ b/gitnexus/test/integration/elixir-phoenix-ecto-pipeline.test.ts @@ -537,40 +537,17 @@ describe('Elixir Phoenix/Ecto pipeline', () => { expect(callTargets('MyApp.AliasContainment.after_block')).not.toContain( 'MyApp.Tasks.ExampleTask.run', ); - expect(graph.relationships).not.toEqual( - expect.arrayContaining([ - expect.objectContaining({ - type: 'CALLS', - source: 'MyApp.Blog.wildcard_private', - target: 'MyApp.Helpers.private', - }), - expect.objectContaining({ - type: 'CALLS', - source: 'MyApp.Blog.wildcard_private_macro', - target: 'MyApp.Helpers.private_macro', - }), - expect.objectContaining({ - type: 'CALLS', - source: 'MyApp.Blog.except_private', - target: 'MyApp.Helpers.private', - }), - expect.objectContaining({ - type: 'CALLS', - source: 'MyApp.Blog.except_private_macro', - target: 'MyApp.Helpers.private_macro', - }), - expect.objectContaining({ - type: 'CALLS', - source: 'MyApp.Blog.callback_call', - target: 'MyApp.Behaviour.required', - }), - expect.objectContaining({ - type: 'CALLS', - source: 'MyApp.Behaviour.required', - target: 'MyApp.Behaviour.required', - }), - ]), - ); + for (const [source, target] of [ + ['MyApp.Blog.wildcard_private', 'MyApp.Helpers.private'], + ['MyApp.Blog.wildcard_private_macro', 'MyApp.Helpers.private_macro'], + ['MyApp.Blog.except_private', 'MyApp.Helpers.private'], + ['MyApp.Blog.except_private_macro', 'MyApp.Helpers.private_macro'], + ['MyApp.Blog.callback_call', 'MyApp.Behaviour.required'], + ['MyApp.Behaviour.required', 'MyApp.Behaviour.required'], + ]) + expect(graph.relationships).not.toContainEqual( + expect.objectContaining({ type: 'CALLS', source, target }), + ); expect(graph.relationships).toEqual( expect.arrayContaining([ expect.objectContaining({ @@ -580,18 +557,13 @@ describe('Elixir Phoenix/Ecto pipeline', () => { }), ]), ); - expect(graph.relationships).not.toEqual( - expect.arrayContaining([ - expect.objectContaining({ - type: 'METHOD_IMPLEMENTS', - source: 'MyApp.ArityImplementation.mismatch', - }), - expect.objectContaining({ - type: 'METHOD_IMPLEMENTS', - source: 'MyApp.AmbiguousImplementation.ambiguous', - }), - ]), - ); + for (const source of [ + 'MyApp.ArityImplementation.mismatch', + 'MyApp.AmbiguousImplementation.ambiguous', + ]) + expect(graph.relationships).not.toContainEqual( + expect.objectContaining({ type: 'METHOD_IMPLEMENTS', source }), + ); expect( graph.nodes.filter( (node) => node.label === 'Class' && node.qualifiedName === 'MyApp.Blog.Post', diff --git a/gitnexus/test/integration/filesystem-walker.test.ts b/gitnexus/test/integration/filesystem-walker.test.ts index 90052bf2c..be455cdfc 100644 --- a/gitnexus/test/integration/filesystem-walker.test.ts +++ b/gitnexus/test/integration/filesystem-walker.test.ts @@ -19,6 +19,7 @@ describe('filesystem-walker', () => { await fs.mkdir(path.join(tmpDir, 'src'), { recursive: true }); await fs.mkdir(path.join(tmpDir, 'src', 'components'), { recursive: true }); await fs.mkdir(path.join(tmpDir, 'src', 'deps', 'sample', 'lib'), { recursive: true }); + await fs.mkdir(path.join(tmpDir, 'deps', 'sample', 'lib'), { recursive: true }); await fs.mkdir(path.join(tmpDir, 'node_modules', 'lodash'), { recursive: true }); await fs.mkdir(path.join(tmpDir, '.git'), { recursive: true }); @@ -32,6 +33,11 @@ describe('filesystem-walker', () => { path.join(tmpDir, 'src', 'deps', 'sample', 'lib', 'sample.ex'), 'defmodule Sample do\nend\n', ); + await fs.writeFile( + path.join(tmpDir, 'deps', 'sample', 'lib', 'sample.ex'), + 'defmodule Dependency do\nend\n', + ); + await fs.writeFile(path.join(tmpDir, 'mix.exs'), 'defmodule Fixture.MixProject do\nend\n'); await fs.writeFile( path.join(tmpDir, 'node_modules', 'lodash', 'index.js'), 'module.exports = {}', @@ -72,10 +78,11 @@ describe('filesystem-walker', () => { expect(paths.every((p) => !p.includes('node_modules'))).toBe(true); }); - it('skips nested Mix dependency directories', async () => { + it('skips root Mix dependencies without excluding nested first-party deps directories', async () => { const files = await walkRepositoryPaths(tmpDir); const paths = files.map((f) => f.path.replace(/\\/g, '/')); - expect(paths.every((p) => !p.includes('/deps/') && !p.startsWith('deps/'))).toBe(true); + expect(paths).not.toContain('deps/sample/lib/sample.ex'); + expect(paths).toContain('src/deps/sample/lib/sample.ex'); }); it('skips .git directory', async () => { diff --git a/gitnexus/test/integration/tree-sitter-languages.test.ts b/gitnexus/test/integration/tree-sitter-languages.test.ts index ce976f89c..5ca4e6802 100644 --- a/gitnexus/test/integration/tree-sitter-languages.test.ts +++ b/gitnexus/test/integration/tree-sitter-languages.test.ts @@ -1010,7 +1010,7 @@ describe('Tree-sitter multi-language parsing', () => { }); }); - describe('Elixir', () => { + describe.skipIf(!isLanguageAvailable(SupportedLanguages.Elixir))('Elixir', () => { const elixirQueries = () => getProvider(SupportedLanguages.Elixir).treeSitterQueries; async function loadElixir(): Promise { diff --git a/gitnexus/test/unit/elixir-cfg.test.ts b/gitnexus/test/unit/elixir-cfg.test.ts index d4b4a6c16..0db571089 100644 --- a/gitnexus/test/unit/elixir-cfg.test.ts +++ b/gitnexus/test/unit/elixir-cfg.test.ts @@ -114,12 +114,20 @@ describe('Elixir CFG visitor', () => { expect(read).toBeGreaterThanOrEqual(0); expect(nested[wrapper]!.parent).toEqual([evalSite, 0]); expect(nested[read]!.parent).toEqual([wrapper, 0]); + const piped = cfg.blocks.find((block) => block.text.includes('|> Code.eval_string'))! + .statements![0]!.sites!; + const pipedRead = piped.findIndex((site) => site.kind === 'member-read'); + const pipedEval = piped.findIndex( + (site) => site.kind === 'call' && site.callee === 'Code.eval_string', + ); + expect(pipedRead).toBeGreaterThanOrEqual(0); + expect(piped[pipedRead]!.parent).toEqual([pipedEval, 0]); const findings = computeTaintFlows( cfg, computeReachingDefs(cfg), matchFunctionSites(cfg, ELIXIR_TAINT_MODEL, buildTaintImportIndex([])), ).findings.filter((finding) => finding.sink.entryName === 'eval_string'); - expect(findings).toHaveLength(2); + expect(findings).toHaveLength(3); }); it('uses source-range parents for repeated callees and shifted pipe arguments', async () => { diff --git a/gitnexus/test/unit/elixir-semantic-graph.test.ts b/gitnexus/test/unit/elixir-semantic-graph.test.ts index 928ad460c..f30244515 100644 --- a/gitnexus/test/unit/elixir-semantic-graph.test.ts +++ b/gitnexus/test/unit/elixir-semantic-graph.test.ts @@ -61,6 +61,23 @@ describe('Elixir semantic graph', () => { expect(graph.nodes.map((node) => node.properties.qualifiedName)).not.toContain(name); }); + it('does not classify a module as an interface from a quoted callback', async () => { + await loadLanguage(SupportedLanguages.Elixir, 'quoted-callback.ex'); + const parser = new Parser(); + parser.setLanguage( + getLanguageGrammar(SupportedLanguages.Elixir) as Parameters[0], + ); + const graph = extractElixirSemanticGraph( + parser.parse(`defmodule M do + quote do + @callback run(term()) :: term() + end + end`), + 'lib/quoted_callback.ex', + ); + expect(graph.nodes.find((node) => node.properties.qualifiedName === 'M')?.label).toBe('Class'); + }); + it('emits canonical zero-arity ordinary and guarded declarations', async () => { await loadLanguage(SupportedLanguages.Elixir, 'zero-arity.ex'); const parser = new Parser(); @@ -245,12 +262,10 @@ describe('Elixir semantic graph', () => { expect.objectContaining({ elixirKind: 'genserver-call', target: 'Worker' }), ]), ); - expect(evidence).not.toEqual( - expect.arrayContaining([ - expect.objectContaining({ elixirKind: 'supervisor-child', target: 'dynamic_child' }), - expect.objectContaining({ elixirKind: 'genserver-cast' }), - ]), + expect(evidence).not.toContainEqual( + expect.objectContaining({ elixirKind: 'supervisor-child', target: 'dynamic_child' }), ); + expect(evidence).not.toContainEqual(expect.objectContaining({ elixirKind: 'genserver-cast' })); expect(graph.relationships.filter((edge) => edge.type === 'DECLARES')).toHaveLength(4); }); }); diff --git a/gitnexus/test/unit/embedding-pipeline.test.ts b/gitnexus/test/unit/embedding-pipeline.test.ts index 51f6c011e..fe4447630 100644 --- a/gitnexus/test/unit/embedding-pipeline.test.ts +++ b/gitnexus/test/unit/embedding-pipeline.test.ts @@ -16,6 +16,7 @@ import { STRUCTURAL_LABELS, } from '../../src/core/embeddings/types.js'; import { STALE_HASH_SENTINEL } from '../../src/core/lbug/schema.js'; +import { extractStructuralNames } from '../../src/core/embeddings/structural-extractor.js'; const CLASS_CHUNK_SIZE = 90; const CLASS_OVERLAP = 10; @@ -32,6 +33,15 @@ describe('embedding schema column contracts', () => { expect(EMBEDDABLE_LABELS).toContain(LABEL_PROTOCOL); expect(EMBEDDABLE_LABELS).toContain(LABEL_CATEGORY); }); + + it('extracts method names from an Elixir defmodule snippet', async () => { + await expect( + extractStructuralNames( + 'defmodule Example do\n def run(value), do: value\nend', + 'example.ex', + ), + ).resolves.toMatchObject({ methodNames: ['run'] }); + }); }); // ──────────────────────────────────────────────────────────────────────────── diff --git a/gitnexus/test/unit/incremental-parse-cache.test.ts b/gitnexus/test/unit/incremental-parse-cache.test.ts index 27e9c43c5..45728efe8 100644 --- a/gitnexus/test/unit/incremental-parse-cache.test.ts +++ b/gitnexus/test/unit/incremental-parse-cache.test.ts @@ -300,8 +300,7 @@ describe('PARSE_CACHE_VERSION', () => { for (const taken of [ 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, - 104, 105, 106, 107, 108, - 109, + 104, 105, 106, 107, 108, 109, ]) { expect(Number(PARSE_CACHE_VERSION.split('+', 1)[0])).not.toBe(taken); } diff --git a/gitnexus/test/unit/scope-resolution/elixir/elixir-fixtures.test.ts b/gitnexus/test/unit/scope-resolution/elixir/elixir-fixtures.test.ts index ed3ab643a..3b7510c7f 100644 --- a/gitnexus/test/unit/scope-resolution/elixir/elixir-fixtures.test.ts +++ b/gitnexus/test/unit/scope-resolution/elixir/elixir-fixtures.test.ts @@ -56,12 +56,16 @@ describe('Elixir scope captures', () => { .filter((def) => def.qualifiedName === 'Actual.Name.same') .map((def) => def.type), ).toEqual(expect.arrayContaining(['Function', 'Macro'])); - expect(parsed?.parsedImports).toEqual( - expect.arrayContaining([ - expect.objectContaining({ kind: 'wildcard', targetRaw: 'Filtered' }), - ]), - ); + expect(parsed?.parsedImports.some((imp) => imp.targetRaw === 'Filtered')).toBe(false); expect(parsed?.parsedImports.some((imp) => imp.targetRaw === 'Helpers')).toBe(false); + expect( + elixirProvider.collectCaptureSideChannel?.('lib/filename_does_not_define_the_module.ex'), + ).toMatchObject({ + kind: 'elixir', + importExcepts: [ + expect.objectContaining({ target: 'Filtered', excluded: [{ name: 'hidden', arity: 1 }] }), + ], + }); const calls = parsed?.referenceSites ?? []; expect(calls.filter((site) => site.name === 'allowed').map((site) => site.arity)).toEqual([1]); expect( @@ -90,6 +94,21 @@ describe('Elixir scope captures', () => { }); }); + it('records a `from p in Schema` query fact without relying on Repo calls', async () => { + await loadLanguage(SupportedLanguages.Elixir, 'from-query.ex'); + extractParsedFile( + elixirProvider, + 'defmodule Queries do\n def all, do: from p in MyApp.Post\nend', + 'lib/from_query.ex', + ); + expect(elixirProvider.collectCaptureSideChannel?.('lib/from_query.ex')).toMatchObject({ + kind: 'elixir', + frameworkFacts: [ + expect.objectContaining({ kind: 'query', method: 'from', model: 'MyApp.Post' }), + ], + }); + }); + it('has identical cold and cached-tree ParsedFile output', async () => { await loadLanguage(SupportedLanguages.Elixir, 'cached.ex'); const source = diff --git a/gitnexus/test/unit/scope-resolution/elixir/elixir-import-excepts.test.ts b/gitnexus/test/unit/scope-resolution/elixir/elixir-import-excepts.test.ts index da5e4fe5d..cf7e22fe2 100644 --- a/gitnexus/test/unit/scope-resolution/elixir/elixir-import-excepts.test.ts +++ b/gitnexus/test/unit/scope-resolution/elixir/elixir-import-excepts.test.ts @@ -65,10 +65,10 @@ describe('Elixir import except augmentation', () => { const importer = { filePath: 'importer.ex', moduleScope: importerScope, - parsedImports: [{ kind: 'wildcard', targetRaw: 'Filtered', declaredAtScope: importerScope }], + parsedImports: [], localDefs: [], referenceSites: [], - scopes: [], + scopes: [{ id: importerScope, range: { startLine: 1, startCol: 0, endLine: 9, endCol: 0 } }], captureSideChannel: { kind: 'elixir', importExcepts: [ @@ -92,6 +92,7 @@ describe('Elixir import except augmentation', () => { callable('visible', 1), callable('hidden', 1), callable('hidden', 2), + { ...callable('nested', 0), qualifiedName: 'Filtered.Nested.nested' }, callable('private', 0, false), ], } as unknown as ParsedFile; @@ -110,6 +111,7 @@ describe('Elixir import except augmentation', () => { .get('hidden') .map((binding: { def: SymbolDefinition }) => binding.def.parameterCount), ).toEqual([2]); + expect(augmentations.get(importerScope)!.has('nested')).toBe(false); }); it('filters category-only imports by exported Function or Macro kind', () => {