skill-task-manager.test.js
4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* Unit Tests — skill-task-manager.js
*/
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import fs from 'fs';
import path from 'path';
const taskManager = require('../../services/skill-task-manager');
describe('skill-task-manager', () => {
const TMP = '/tmp/test-skill-tasks';
const SKILL_DIR = path.join(TMP, 'test-skill');
beforeAll(() => fs.mkdirSync(TMP, { recursive: true }));
afterAll(() => { try { fs.rmSync(TMP, { recursive: true }); } catch {} });
describe('initTask', () => {
it('should create a task file with create pipeline', () => {
const task = taskManager.initTask(SKILL_DIR, {
skillName: 'test-skill', domain: 'test', scope: 'unit',
});
expect(task.skillName).toBe('test-skill');
expect(task.pipelineType).toBe('create');
expect(task.pipeline).toHaveLength(3);
expect(task.pipeline.map(p => p.step)).toEqual(taskManager.PIPELINE_STEPS);
expect(task.pipeline.every(p => p.status === 'pending')).toBe(true);
});
it('should create a feedback pipeline', () => {
const fbDir = path.join(TMP, 'feedback-skill');
const task = taskManager.initTask(fbDir, {
skillName: 'fb-skill', pipelineType: 'feedback', feedback: 'Needs improvement',
});
expect(task.pipelineType).toBe('feedback');
expect(task.pipeline).toHaveLength(4);
expect(task.pipeline.map(p => p.step)).toEqual(taskManager.FEEDBACK_PIPELINE_STEPS);
expect(task.feedback).toBe('Needs improvement');
});
});
describe('getTask', () => {
it('should retrieve an existing task', () => {
const task = taskManager.getTask(SKILL_DIR);
expect(task).not.toBeNull();
expect(task.skillName).toBe('test-skill');
});
it('should return null for non-existent task', () => {
expect(taskManager.getTask('/tmp/no-such-dir-xyz')).toBeNull();
});
});
describe('updateStep', () => {
it('should update step to running', () => {
const task = taskManager.updateStep(SKILL_DIR, 'hunt', 'running');
expect(task.pipeline[0].status).toBe('running');
});
it('should update step to done with completedAt', () => {
const task = taskManager.updateStep(SKILL_DIR, 'hunt', 'done');
expect(task.pipeline[0].status).toBe('done');
expect(task.pipeline[0].completedAt).toBeDefined();
});
it('should update step to failed with error', () => {
const task = taskManager.updateStep(SKILL_DIR, 'digest', 'failed', 'API error');
expect(task.pipeline[1].status).toBe('failed');
expect(task.pipeline[1].error).toBe('API error');
});
it('should return null for non-existent step', () => {
expect(taskManager.updateStep(SKILL_DIR, 'nonexistent', 'done')).toBeNull();
});
});
describe('getNextPendingStep', () => {
it('should return next pending step', () => {
// hunt=done, digest=failed, skill_create=pending
const next = taskManager.getNextPendingStep(SKILL_DIR);
expect(next).toBe('skill_create');
});
});
describe('isCompleted', () => {
it('should return false when steps are pending', () => {
expect(taskManager.isCompleted(SKILL_DIR)).toBe(false);
});
it('should return true when all steps are done', () => {
taskManager.updateStep(SKILL_DIR, 'digest', 'done');
taskManager.updateStep(SKILL_DIR, 'skill_create', 'done');
expect(taskManager.isCompleted(SKILL_DIR)).toBe(true);
});
});
describe('findIncompleteTasks', () => {
it('should find incomplete tasks in a directory', () => {
// Create another incomplete task
const incDir = path.join(TMP, 'incomplete-skill');
taskManager.initTask(incDir, { skillName: 'incomplete' });
const results = taskManager.findIncompleteTasks(TMP);
expect(results.some(r => r.skillName === 'incomplete')).toBe(true);
});
});
describe('constants', () => {
it('should export PIPELINE_STEPS', () => {
expect(taskManager.PIPELINE_STEPS).toEqual(['hunt', 'digest', 'skill_create']);
});
it('should export FEEDBACK_PIPELINE_STEPS', () => {
expect(taskManager.FEEDBACK_PIPELINE_STEPS).toEqual(['re_hunt', 're_digest', 'evolve', 'publish']);
});
it('should export TASK_FILE', () => {
expect(taskManager.TASK_FILE).toBe('.innovator_task.json');
});
});
});