fix: 重构 资源的注册,发现,解析架构,解决兼容性问题

This commit is contained in:
sean
2025-06-12 12:28:53 +08:00
parent 88874ff7ec
commit 5d6e678bd2
15 changed files with 2029 additions and 1354 deletions

View File

@ -124,7 +124,8 @@ describe('协议路径警告问题 - E2E Tests', () => {
}
} catch (error) {
// 验证错误信息是否与问题描述匹配
expect(error.message).toMatch(/协议|路径|@packages/)
// 在新架构中,错误消息应该是 "Resource 'prompt' not found"
expect(error.message).toMatch(/Resource.*not found|协议|路径|@packages/)
}
} finally {
@ -265,23 +266,24 @@ describe('协议路径警告问题 - E2E Tests', () => {
})
describe('协议注册表验证测试', () => {
test('应该验证prompt协议注册表配置', () => {
test('应该验证prompt协议注册表配置', async () => {
const ResourceRegistry = require('../../lib/core/resource/resourceRegistry')
const registry = new ResourceRegistry()
// 检查prompt协议是否正确注册
const promptProtocol = registry.getProtocolInfo('prompt')
expect(promptProtocol).toBeDefined()
expect(promptProtocol.name).toBe('prompt')
// 在新架构中,注册表是基于索引的,检查是否正确加载
await registry.loadFromFile('src/resource.registry.json')
expect(registry.index.size).toBeGreaterThan(0)
// 检查protocols资源是否在注册表中
const protocolRegistry = registry.getProtocolRegistry('prompt')
expect(protocolRegistry).toBeDefined()
expect(protocolRegistry.has('protocols')).toBe(true)
// 检查一些基础资源是否正确注册
const hasRoleResource = Array.from(registry.index.keys()).some(key => key.startsWith('role:'))
const hasExecutionResource = Array.from(registry.index.keys()).some(key => key.startsWith('execution:'))
expect(hasRoleResource).toBe(true)
expect(hasExecutionResource).toBe(true)
// 获取protocols的路径配置
const protocolsPath = protocolRegistry.get('protocols')
expect(protocolsPath).toBe('@package://prompt/protocol/**/*.md')
// 检查注册表是否包含协议引用格式
const registryEntries = Array.from(registry.index.values())
const hasPackageProtocol = registryEntries.some(ref => ref.startsWith('@package://'))
expect(hasPackageProtocol).toBe(true)
console.log('✅ 协议注册表配置验证通过')
})