Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions __tests__/foundation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import { CodeGraph } from '../src';
import { DEFAULT_CONFIG, Node, Edge } from '../src/types';
import { loadConfig, saveConfig } from '../src/config';
import { DEFAULT_CONFIG, LANGUAGES } from '../src/types';
import { loadConfig, saveConfig, validateConfig } from '../src/config';
import { isInitialized, getCodeGraphDir, validateDirectory } from '../src/directory';
import { DatabaseConnection, getDatabasePath } from '../src/db';

Expand Down Expand Up @@ -192,6 +192,28 @@ describe('CodeGraph Foundation', () => {
expect(config.rootDir).toBe(path.resolve(tempDir));
});

it('should validate every supported language from the shared registry', () => {
for (const language of LANGUAGES) {
expect(
validateConfig({
...DEFAULT_CONFIG,
rootDir: tempDir,
languages: [language],
})
).toBe(true);
}
});

it('should reject unknown languages', () => {
expect(
validateConfig({
...DEFAULT_CONFIG,
rootDir: tempDir,
languages: ['not-a-language'],
})
).toBe(false);
});

it('should update configuration', () => {
const cg = CodeGraph.initSync(tempDir);

Expand Down
15 changes: 2 additions & 13 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import * as fs from 'fs';
import * as path from 'path';
import picomatch from 'picomatch';
import { CodeGraphConfig, DEFAULT_CONFIG, Language, NodeKind } from './types';
import { CodeGraphConfig, DEFAULT_CONFIG, LANGUAGES, Language, NodeKind } from './types';
import { normalizePath } from './utils';

/**
Expand Down Expand Up @@ -72,18 +72,7 @@ export function validateConfig(config: unknown): config is CodeGraphConfig {
if (!c.include.every((p) => typeof p === 'string')) return false;
if (!c.exclude.every((p) => typeof p === 'string')) return false;

// Validate languages
const validLanguages: Language[] = [
'typescript',
'javascript',
'python',
'go',
'rust',
'java',
'svelte',
'unknown',
];
if (!c.languages.every((l) => validLanguages.includes(l as Language))) return false;
if (!c.languages.every((l) => LANGUAGES.includes(l as Language))) return false;

// Validate frameworks
for (const fw of c.frameworks) {
Expand Down