chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,53 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { test } from 'node:test'
|
||||
|
||||
import { ConfigError, normalizeBaseUrl, resolveConfig } from '../dist/config.js'
|
||||
|
||||
test('base URLs are normalized to an API root', () => {
|
||||
assert.equal(normalizeBaseUrl('https://kb.example.com'), 'https://kb.example.com/api/v1')
|
||||
assert.equal(normalizeBaseUrl('https://kb.example.com/'), 'https://kb.example.com/api/v1')
|
||||
assert.equal(normalizeBaseUrl('https://kb.example.com/api/v1'), 'https://kb.example.com/api/v1')
|
||||
assert.equal(normalizeBaseUrl('https://kb.example.com/api/v2/'), 'https://kb.example.com/api/v2')
|
||||
})
|
||||
|
||||
test('an empty config resolves to documented defaults', () => {
|
||||
const config = resolveConfig(undefined)
|
||||
assert.equal(config.baseUrl, 'http://localhost:8080/api/v1')
|
||||
assert.equal(config.maxResults, 8)
|
||||
assert.equal(config.toolPrefix, 'academy')
|
||||
assert.equal(config.resourceUrls, 'public')
|
||||
assert.deepEqual(config.knowledgeBaseIds, [])
|
||||
assert.deepEqual(config.tools, { listKnowledgeBases: true, search: true, readDocument: true, ask: true })
|
||||
})
|
||||
|
||||
test('resourceUrls handle remains an explicit opt-out', () => {
|
||||
assert.equal(resolveConfig({ resourceUrls: 'handle' }).resourceUrls, 'handle')
|
||||
})
|
||||
|
||||
test('a bad row fails the load and names every violation', () => {
|
||||
assert.throws(
|
||||
() => resolveConfig({ baseUrl: 'not-a-url', maxResults: -1, resourceUrls: 'nope', toolPrefix: '9bad' }),
|
||||
error => {
|
||||
assert.ok(error instanceof ConfigError)
|
||||
assert.match(error.message, /baseUrl must be an absolute URL/)
|
||||
assert.match(error.message, /maxResults must be a positive number/)
|
||||
assert.match(error.message, /resourceUrls must be "handle" or "public"/)
|
||||
assert.match(error.message, /toolPrefix must match/)
|
||||
return true
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
test('disabling every tool is refused', () => {
|
||||
assert.throws(
|
||||
() => resolveConfig({ tools: { listKnowledgeBases: false, search: false, readDocument: false, ask: false } }),
|
||||
/at least one tool must stay enabled/,
|
||||
)
|
||||
})
|
||||
|
||||
test('blank strings collapse to unset rather than empty headers', () => {
|
||||
const config = resolveConfig({ apiKey: ' ', tenantId: '', agentId: 'agent-7' })
|
||||
assert.equal(config.apiKey, undefined)
|
||||
assert.equal(config.tenantId, undefined)
|
||||
assert.equal(config.agentId, 'agent-7')
|
||||
})
|
||||
Reference in new issue
Block a user