mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
fix: tests fail on Windows
This commit is contained in:
@@ -108,6 +108,12 @@ describe('SubagentManager', () => {
|
||||
if (yamlString.includes('name: agent3')) {
|
||||
return { name: 'agent3', description: 'Third agent' };
|
||||
}
|
||||
if (yamlString.includes('name: 11')) {
|
||||
return { name: 11, description: 333 }; // Numeric values test case
|
||||
}
|
||||
if (yamlString.includes('name: true')) {
|
||||
return { name: true, description: false }; // Boolean values test case
|
||||
}
|
||||
if (!yamlString.includes('name:')) {
|
||||
return { description: 'A test subagent' }; // Missing name case
|
||||
}
|
||||
@@ -248,6 +254,46 @@ You are a helpful assistant.
|
||||
expect(config.runConfig).toEqual({ max_time_minutes: 5, max_turns: 10 });
|
||||
});
|
||||
|
||||
it('should handle numeric name and description values', () => {
|
||||
const markdownWithNumeric = `---
|
||||
name: 11
|
||||
description: 333
|
||||
---
|
||||
|
||||
You are a helpful assistant.
|
||||
`;
|
||||
|
||||
const config = manager.parseSubagentContent(
|
||||
markdownWithNumeric,
|
||||
validConfig.filePath,
|
||||
);
|
||||
|
||||
expect(config.name).toBe('11');
|
||||
expect(config.description).toBe('333');
|
||||
expect(typeof config.name).toBe('string');
|
||||
expect(typeof config.description).toBe('string');
|
||||
});
|
||||
|
||||
it('should handle boolean name and description values', () => {
|
||||
const markdownWithBoolean = `---
|
||||
name: true
|
||||
description: false
|
||||
---
|
||||
|
||||
You are a helpful assistant.
|
||||
`;
|
||||
|
||||
const config = manager.parseSubagentContent(
|
||||
markdownWithBoolean,
|
||||
validConfig.filePath,
|
||||
);
|
||||
|
||||
expect(config.name).toBe('true');
|
||||
expect(config.description).toBe('false');
|
||||
expect(typeof config.name).toBe('string');
|
||||
expect(typeof config.description).toBe('string');
|
||||
});
|
||||
|
||||
it('should determine level from file path', () => {
|
||||
const projectPath = '/test/project/.qwen/agents/test-agent.md';
|
||||
const userPath = '/home/user/.qwen/agents/test-agent.md';
|
||||
@@ -358,7 +404,7 @@ You are a helpful assistant.
|
||||
await manager.createSubagent(validConfig, { level: 'project' });
|
||||
|
||||
expect(fs.mkdir).toHaveBeenCalledWith(
|
||||
path.dirname(validConfig.filePath),
|
||||
path.normalize(path.dirname(validConfig.filePath)),
|
||||
{ recursive: true },
|
||||
);
|
||||
expect(fs.writeFile).toHaveBeenCalledWith(
|
||||
@@ -428,7 +474,7 @@ You are a helpful assistant.
|
||||
expect(config).toBeDefined();
|
||||
expect(config!.name).toBe('test-agent');
|
||||
expect(fs.readFile).toHaveBeenCalledWith(
|
||||
'/test/project/.qwen/agents/test-agent.md',
|
||||
path.normalize('/test/project/.qwen/agents/test-agent.md'),
|
||||
'utf8',
|
||||
);
|
||||
});
|
||||
@@ -443,7 +489,7 @@ You are a helpful assistant.
|
||||
expect(config).toBeDefined();
|
||||
expect(config!.name).toBe('test-agent');
|
||||
expect(fs.readFile).toHaveBeenCalledWith(
|
||||
'/home/user/.qwen/agents/test-agent.md',
|
||||
path.normalize('/home/user/.qwen/agents/test-agent.md'),
|
||||
'utf8',
|
||||
);
|
||||
});
|
||||
@@ -507,7 +553,7 @@ You are a helpful assistant.
|
||||
await manager.deleteSubagent('test-agent', 'project');
|
||||
|
||||
expect(fs.unlink).toHaveBeenCalledWith(
|
||||
'/test/project/.qwen/agents/test-agent.md',
|
||||
path.normalize('/test/project/.qwen/agents/test-agent.md'),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -518,10 +564,10 @@ You are a helpful assistant.
|
||||
|
||||
expect(fs.unlink).toHaveBeenCalledTimes(2);
|
||||
expect(fs.unlink).toHaveBeenCalledWith(
|
||||
'/test/project/.qwen/agents/test-agent.md',
|
||||
path.normalize('/test/project/.qwen/agents/test-agent.md'),
|
||||
);
|
||||
expect(fs.unlink).toHaveBeenCalledWith(
|
||||
'/home/user/.qwen/agents/test-agent.md',
|
||||
path.normalize('/home/user/.qwen/agents/test-agent.md'),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -121,9 +121,9 @@ export class SubagentManager {
|
||||
return BuiltinAgentRegistry.getBuiltinAgent(name);
|
||||
}
|
||||
|
||||
const path = this.getSubagentPath(name, level);
|
||||
const filePath = this.getSubagentPath(name, level);
|
||||
try {
|
||||
const config = await this.parseSubagentFile(path);
|
||||
const config = await this.parseSubagentFile(filePath);
|
||||
return config;
|
||||
} catch (_error) {
|
||||
return null;
|
||||
@@ -378,18 +378,22 @@ export class SubagentManager {
|
||||
// Parse YAML frontmatter
|
||||
const frontmatter = parseYaml(frontmatterYaml) as Record<string, unknown>;
|
||||
|
||||
// Extract required fields
|
||||
const name = frontmatter['name'] as string;
|
||||
const description = frontmatter['description'] as string;
|
||||
// Extract required fields and convert to strings
|
||||
const nameRaw = frontmatter['name'];
|
||||
const descriptionRaw = frontmatter['description'];
|
||||
|
||||
if (!name || typeof name !== 'string') {
|
||||
throw new Error('Missing or invalid "name" in frontmatter');
|
||||
if (nameRaw == null || nameRaw === '') {
|
||||
throw new Error('Missing "name" in frontmatter');
|
||||
}
|
||||
|
||||
if (!description || typeof description !== 'string') {
|
||||
throw new Error('Missing or invalid "description" in frontmatter');
|
||||
if (descriptionRaw == null || descriptionRaw === '') {
|
||||
throw new Error('Missing "description" in frontmatter');
|
||||
}
|
||||
|
||||
// Convert to strings (handles numbers, booleans, etc.)
|
||||
const name = String(nameRaw);
|
||||
const description = String(descriptionRaw);
|
||||
|
||||
// Extract optional fields
|
||||
const tools = frontmatter['tools'] as string[] | undefined;
|
||||
const modelConfig = frontmatter['modelConfig'] as
|
||||
@@ -400,11 +404,19 @@ export class SubagentManager {
|
||||
| undefined;
|
||||
const color = frontmatter['color'] as string | undefined;
|
||||
|
||||
// Determine level from file path
|
||||
// Project level paths contain the project root, user level paths are in home directory
|
||||
// Determine level from file path using robust, cross-platform check
|
||||
// A project-level agent lives under <projectRoot>/.qwen/agents
|
||||
const projectAgentsDir = path.join(
|
||||
this.config.getProjectRoot(),
|
||||
QWEN_CONFIG_DIR,
|
||||
AGENT_CONFIG_DIR,
|
||||
);
|
||||
const rel = path.relative(
|
||||
path.normalize(projectAgentsDir),
|
||||
path.normalize(filePath),
|
||||
);
|
||||
const isProjectLevel =
|
||||
filePath.includes(this.config.getProjectRoot()) &&
|
||||
filePath.includes(`/${QWEN_CONFIG_DIR}/${AGENT_CONFIG_DIR}/`);
|
||||
rel !== '' && !rel.startsWith('..') && !path.isAbsolute(rel);
|
||||
const level: SubagentLevel = isProjectLevel ? 'project' : 'user';
|
||||
|
||||
const config: SubagentConfig = {
|
||||
|
||||
Reference in New Issue
Block a user