From 67df07ab7aadae16d38edeb47070c06ed31264cd Mon Sep 17 00:00:00 2001 From: Benedikt Schnatterbeck Date: Wed, 23 Sep 2026 15:44:22 +0100 Subject: [PATCH] test(elixir): gate embedding assertion on grammar install --- gitnexus/test/unit/embedding-pipeline.test.ts | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/gitnexus/test/unit/embedding-pipeline.test.ts b/gitnexus/test/unit/embedding-pipeline.test.ts index 7c7ab0a33..30c95cfc3 100644 --- a/gitnexus/test/unit/embedding-pipeline.test.ts +++ b/gitnexus/test/unit/embedding-pipeline.test.ts @@ -1,5 +1,7 @@ -import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { createRequire } from 'node:module'; import { createHash } from 'crypto'; +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { SupportedLanguages } from 'gitnexus-shared'; import { contentHashForNode, EMBEDDING_TEXT_VERSION, @@ -17,10 +19,21 @@ import { } 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'; +import { isLanguageAvailable } from '../../src/core/tree-sitter/parser-loader.js'; const CLASS_CHUNK_SIZE = 90; const CLASS_OVERLAP = 10; +const _require = createRequire(import.meta.url); +const elixirPackageInstalled = (() => { + try { + _require.resolve('tree-sitter-elixir'); + return true; + } catch { + return false; + } +})(); + describe('embedding schema column contracts', () => { it('does not query Objective-C protocol/category tables for an isExported column', () => { expect(LABELS_WITH_EXPORTED.has(LABEL_PROTOCOL)).toBe(false); @@ -34,18 +47,23 @@ describe('embedding schema column contracts', () => { expect(EMBEDDABLE_LABELS).toContain(LABEL_CATEGORY); }); - it('extracts defmodule methods without treating ordinary calls as declarations', async () => { - await expect( - extractStructuralNames( - 'defmodule Example do\n def run(value), do: value\nend', - 'example.ex', - ), - ).resolves.toMatchObject({ methodNames: ['run'] }); + it.skipIf(!elixirPackageInstalled)( + 'extracts defmodule methods without treating ordinary calls as declarations', + async () => { + expect(isLanguageAvailable(SupportedLanguages.Elixir)).toBe(true); - await expect( - extractStructuralNames('configure do\n def leaked(value), do: value\nend', 'example.ex'), - ).resolves.toMatchObject({ methodNames: [] }); - }); + await expect( + extractStructuralNames( + 'defmodule Example do\n def run(value), do: value\nend', + 'example.ex', + ), + ).resolves.toMatchObject({ methodNames: ['run'] }); + + await expect( + extractStructuralNames('configure do\n def leaked(value), do: value\nend', 'example.ex'), + ).resolves.toMatchObject({ methodNames: [] }); + }, + ); }); // ────────────────────────────────────────────────────────────────────────────