Skip to content

Commit 1a9d79b

Browse files
committed
Updating the unit tests (now all linting works with 100% unit test coverage and working integration tests).
1 parent f9b0adc commit 1a9d79b

5 files changed

Lines changed: 35 additions & 17 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@
5151
"nunjucks": "^3.2.4",
5252
"zod": "^4.1.12"
5353
}
54-
}
54+
}

src/services/SkillRunner.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,30 @@ export class SkillRunner implements ISkillRunner {
2323
private driverRegistry: DriverRegistry,
2424
private promptEngine: PromptEngine,
2525
private host: IRuntimeHost,
26-
) { }
26+
) {}
2727

28-
async init(): Promise<void> {
29-
await this.loadYamlSkills();
28+
init(): Promise<void> {
29+
this.loadYamlSkills();
30+
return Promise.resolve();
3031
}
3132

32-
private async loadYamlSkills(): Promise<void> {
33-
if (!(await this.project.fileSystem.isDirectory(this.project.paths.skills))) {
33+
private loadYamlSkills(): void {
34+
if (!this.project.fileSystem.isDirectory(this.project.paths.skills)) {
3435
return;
3536
}
3637

37-
const files = await this.project.fileSystem.listFiles(this.project.paths.skills);
38+
const files = this.project.fileSystem.listFiles(this.project.paths.skills);
3839

3940
for (const filename of files) {
4041
if (filename.endsWith('.skill.yml') || filename.endsWith('.skill.yaml') || filename.endsWith('.yml')) {
4142
const filePath = path.join(this.project.paths.skills, filename);
4243
try {
43-
const content = await this.project.fileSystem.readFile(filePath);
44+
const content = this.project.fileSystem.readFile(filePath);
4445
const profile = yaml.load(content);
4546
const parsed = SkillSchema.parse(profile);
4647
this.skills[parsed.name] = parsed as ISkill;
47-
} catch (e: any) {
48-
this.host.log('error', `Error loading skill profile ${filename}: ${e.message}`);
48+
} catch (e: unknown) {
49+
this.host.log('error', `Error loading skill profile ${filename}: ${(e as Error).message}`);
4950
}
5051
}
5152
}

tests/unit/agents/PlannerAgent.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ describe('PlannerAgent', () => {
176176
mockDriver.execute.mockResolvedValue(mockResult);
177177

178178
const spy = jest.spyOn(Plan, 'fromYaml').mockImplementation(() => {
179+
// eslint-disable-next-line @typescript-eslint/only-throw-error
179180
throw 'String Error';
180181
});
181182

tests/unit/services/SkillRunner.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ describe('SkillRunner', () => {
187187
it('should fail if default driver missing for provider-less skill', async () => {
188188
// Force skill to have no provider
189189
const skillNoProvider = { name: 'test-skill' };
190-
// @ts-ignore - reaching into private/protected or public property
191-
runner.skills['test-skill'] = skillNoProvider as any;
190+
// @ts-expect-error - reaching into private/protected or public property
191+
(runner.skills as Record<string, unknown>)['test-skill'] = skillNoProvider;
192192

193193
mockRegistryGetDefault.mockReturnValue(undefined);
194194
await expect(runner.validateAvailableSkills()).rejects.toThrow('needs a default driver but none is available.');
@@ -197,7 +197,7 @@ describe('SkillRunner', () => {
197197

198198
it('should fail if driver not supported', async () => {
199199
// Manually populate skills to bypass init/fs complexity since we are outside the describe block that calls init
200-
(runner as any).skills = {
200+
(runner as unknown as { skills: Record<string, unknown> }).skills = {
201201
'test-skill': { name: 'test-skill', provider: 'mock-driver' },
202202
};
203203

@@ -211,7 +211,7 @@ describe('SkillRunner', () => {
211211
});
212212

213213
it('should handle driver errors during validation', async () => {
214-
(runner as any).skills = {
214+
(runner as unknown as { skills: Record<string, unknown> }).skills = {
215215
'test-skill': { name: 'test-skill', provider: 'mock-driver' },
216216
};
217217

tests/unit/workflow/Workflow.test.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,27 @@ jest.unstable_mockModule('../../../src/workflow/WorkflowGraph.js', () => ({
4747
DefaultWorkflowConfig: {},
4848
}));
4949

50-
let Workflow: any;
50+
// Define the shape of the Workflow class constructor
51+
type WorkflowConstructor = new (
52+
brain: Brain,
53+
project: IProject,
54+
workspace: IWorkspace,
55+
host: IRuntimeHost,
56+
) => {
57+
start(state: EngineState, onStateChange?: () => Promise<void>): Promise<void>;
58+
registerState(state: State): void;
59+
currentState?: State;
60+
// Access private property for testing if needed, though strictly not allowed
61+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
62+
states: Map<string, any>;
63+
};
64+
65+
let Workflow: WorkflowConstructor;
5166
try {
5267
const mod = await import('../../../src/workflow/Workflow.js');
53-
Workflow = mod.Workflow;
68+
Workflow = mod.Workflow as unknown as WorkflowConstructor;
5469
} catch (e) {
70+
// eslint-disable-next-line no-console
5571
console.error('Error importing Workflow module:', e);
5672
}
5773

@@ -256,7 +272,7 @@ describe('Workflow Unit Tests', () => {
256272
setupMockState('PLANNING', planningRun);
257273

258274
// Mock graph to return undefined for subsequent states to finish loop if needed
259-
mockGraph.getNextState.mockImplementation((state, signal) => {
275+
mockGraph.getNextState.mockImplementation((state, _signal) => {
260276
if (state === 'ARCHITECTING') return 'PLANNING';
261277
return undefined;
262278
});

0 commit comments

Comments
 (0)