From f724e790e0a10adb3caf42005838877ab075e976 Mon Sep 17 00:00:00 2001 From: okbexx Date: Thu, 21 May 2026 19:48:26 +0800 Subject: [PATCH] fix(config): validate languages from shared registry --- __tests__/foundation.test.ts | 26 ++++++++++++++++++++++++-- src/config.ts | 15 ++------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/__tests__/foundation.test.ts b/__tests__/foundation.test.ts index 4e8f204a..3a93efac 100644 --- a/__tests__/foundation.test.ts +++ b/__tests__/foundation.test.ts @@ -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'; @@ -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); diff --git a/src/config.ts b/src/config.ts index 9ab1032a..6b7bc1ba 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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'; /** @@ -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) {