test(elixir): gate embedding assertion on grammar install

This commit is contained in:
Benedikt Schnatterbeck 2026-09-23 15:44:22 +01:00
parent f6e81db0ae
commit 67df07ab7a
No known key found for this signature in database

View file

@ -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: [] });
},
);
});
// ────────────────────────────────────────────────────────────────────────────