Files
ChatLab/scripts/run-tests.mjs
T
diguaandClaude Sonnet 4.6 f5e83748ff fix(ai): register execute_sql tool in Electron tool registry
sqlQueryTool (execute_sql) was listed in BUILTIN_TOOL_CATALOG and
available in the CLI AGENT_TOOL_REGISTRY, but was never imported or
registered in the Electron-specific TOOL_REGISTRY. Users who enabled
the tool via the assistant config panel would trigger a missing-tool
error at inference time.

Add sqlQueryTool to the Electron registry following the same
adaptSharedTool pattern used by all other analysis tools. Add a
catalog/registry drift guard test (name + category) covering all
BUILTIN_TOOL_CATALOG entries, enabled via
--experimental-test-module-mocks to mock Electron runtime deps.
Document the general-over-specific assertion rule in AGENTS.md.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-10 00:15:25 +08:00

94 lines
2.3 KiB
JavaScript

#!/usr/bin/env node
import { readdirSync, statSync } from 'node:fs'
import { join, relative, sep } from 'node:path'
import { spawnSync } from 'node:child_process'
import { fileURLToPath } from 'node:url'
const SKIP_DIRS = new Set([
'.git',
'.docs',
'node_modules',
'dist',
'dist-web',
'out',
'build',
'coverage',
'.vitepress',
])
const TEST_FILE_RE = /\.(?:test|spec)\.(?:ts|tsx|js|jsx|mjs|mts|cjs|cts)$/
function normalizePath(filePath) {
return filePath.split(sep).join('/')
}
export function filterDefaultTestFiles(files) {
return files
.map(normalizePath)
.filter((file) => TEST_FILE_RE.test(file))
.filter((file) => !file.startsWith('tests/e2e/'))
.filter((file) => !file.includes('/smoke/'))
.filter((file) => !file.includes('.smoke.test.'))
.filter((file) => !file.includes('.e2e.test.'))
}
function collectFiles(rootDir, dir = rootDir) {
const entries = readdirSync(dir, { withFileTypes: true })
const files = []
for (const entry of entries) {
if (entry.isDirectory()) {
if (SKIP_DIRS.has(entry.name)) continue
files.push(...collectFiles(rootDir, join(dir, entry.name)))
continue
}
if (!entry.isFile()) continue
const filePath = join(dir, entry.name)
files.push(normalizePath(relative(rootDir, filePath)))
}
return files
}
export function collectDefaultTestFiles(rootDir = process.cwd()) {
if (!statSync(rootDir).isDirectory()) {
throw new Error(`Test root is not a directory: ${rootDir}`)
}
return filterDefaultTestFiles(collectFiles(rootDir)).sort()
}
export function buildNodeTestArgs(testArgs) {
return ['--experimental-test-module-mocks', '--import', 'tsx', '--test', ...testArgs]
}
function run() {
const explicitArgs = process.argv.slice(2)
const testArgs = explicitArgs.length > 0 ? explicitArgs : collectDefaultTestFiles()
if (testArgs.length === 0) {
console.error('No test files found.')
process.exit(1)
}
if (explicitArgs.length === 0) {
console.log(`Running ${testArgs.length} default test files.`)
}
const result = spawnSync(process.execPath, buildNodeTestArgs(testArgs), {
stdio: 'inherit',
})
if (result.error) {
throw result.error
}
process.exit(result.status ?? 1)
}
if (process.argv[1] === fileURLToPath(import.meta.url)) {
run()
}