Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
重构所有代码和文档中的项目名称,将OpenFang统一更新为ZCLAW。包括: - 配置文件中的项目名称 - 代码注释和文档引用 - 环境变量和路径 - 类型定义和接口名称 - 测试用例和模拟数据 同时优化部分代码结构,移除未使用的模块,并更新相关依赖项。
105 lines
3.1 KiB
JavaScript
105 lines
3.1 KiB
JavaScript
/**
|
|
* Test script to verify TOML parsing with actual config files
|
|
*/
|
|
|
|
import TOML from 'smol-toml';
|
|
|
|
// Use inline TOML strings for testing
|
|
const MAIN_CONFIG_TOML = `
|
|
[server]
|
|
host = "127.0.0.1"
|
|
port = 4200
|
|
websocket_port = 4200
|
|
websocket_path = "/ws"
|
|
|
|
[agent.defaults]
|
|
workspace = "~/.zclaw/workspace"
|
|
default_model = "gpt-4"
|
|
|
|
[llm]
|
|
default_provider = "openai"
|
|
default_model = "gpt-4"
|
|
`;
|
|
|
|
const CHINESE_PROVIDERS_TOML = `
|
|
[[llm.providers]]
|
|
name = "zhipu"
|
|
display_name = "Zhipu GLM"
|
|
api_key = "\${ZHIPU_API_KEY}"
|
|
base_url = "https://open.bigmodel.cn/api/paas/v4"
|
|
|
|
[[llm.providers.models]]
|
|
id = "glm-4-plus"
|
|
alias = "GLM-4-Plus"
|
|
context_window = 128000
|
|
|
|
[[llm.providers]]
|
|
name = "qwen"
|
|
display_name = "Qwen"
|
|
api_key = "\${QWEN_API_KEY}"
|
|
base_url = "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
|
|
|
[[llm.providers.models]]
|
|
id = "qwen-max"
|
|
alias = "Qwen-Max"
|
|
`;
|
|
|
|
console.log('=== Testing TOML Parsing ===\n');
|
|
|
|
// Test 1: Parse main config
|
|
try {
|
|
console.log('\n--- Test 1: Main config.toml ---');
|
|
const mainConfig = TOML.parse(MAIN_CONFIG_TOML);
|
|
console.log('Parsed successfully!');
|
|
console.log('Server config:', JSON.stringify(mainConfig.server, null, 2));
|
|
console.log('Agent defaults:', JSON.stringify(mainConfig.agent?.defaults, null, 2));
|
|
console.log('LLM config:', JSON.stringify(mainConfig.llm, null, 2));
|
|
|
|
// Check required fields
|
|
if (!mainConfig.server?.host) throw new Error('Missing server.host');
|
|
if (!mainConfig.server?.port) throw new Error('Missing server.port');
|
|
if (!mainConfig.agent?.defaults?.workspace) throw new Error('Missing agent.defaults.workspace');
|
|
if (!mainConfig.agent?.defaults?.default_model) throw new Error('Missing agent.defaults.default_model');
|
|
if (!mainConfig.llm?.default_provider) throw new Error('Missing llm.default_provider');
|
|
if (!mainConfig.llm?.default_model) throw new Error('Missing llm.default_model');
|
|
|
|
console.log('All required fields present!');
|
|
} catch (error) {
|
|
console.error('Failed to parse main config:', error.message);
|
|
process.exit(1);
|
|
}
|
|
|
|
// Test 2: Parse chinese-providers.toml
|
|
try {
|
|
console.log('\n--- Test 2: chinese-providers.toml ---');
|
|
const chineseProviders = TOML.parse(CHINESE_PROVIDERS_TOML);
|
|
console.log('Parsed successfully!');
|
|
console.log('Number of providers:', chineseProviders.llm?.providers?.length || 0);
|
|
|
|
// List providers
|
|
if (chineseProviders.llm?.providers) {
|
|
console.log('\nProviders found:');
|
|
chineseProviders.llm.providers.forEach((provider, index) => {
|
|
console.log(` ${index + 1}. ${provider.name} (${provider.display_name || 'N/A'})`);
|
|
if (provider.models) {
|
|
console.log(` Models: ${provider.models.length}`);
|
|
}
|
|
});
|
|
}
|
|
|
|
// Check for environment variable references
|
|
const envVarPattern = /\$\{([^}]+)\}/g;
|
|
const envVars = CHINESE_PROVIDERS_TOML.match(envVarPattern);
|
|
if (envVars) {
|
|
console.log('\nEnvironment variables referenced:');
|
|
const uniqueVars = [...new Set(envVars)];
|
|
uniqueVars.forEach(v => console.log(` - ${v}`));
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('Failed to parse chinese-providers:', error.message);
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log('\n=== All TOML parsing tests passed! ===\n');
|