@oalacea/daemon 0.5.1 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/cli.d.ts +42 -0
- package/dist/cli/cli.d.ts.map +1 -0
- package/dist/cli/cli.js +89 -0
- package/dist/cli/cli.js.map +1 -0
- package/dist/cli/commands/detect.command.d.ts +39 -0
- package/dist/cli/commands/detect.command.d.ts.map +1 -0
- package/dist/cli/commands/detect.command.js +111 -0
- package/dist/cli/commands/detect.command.js.map +1 -0
- package/dist/cli/commands/index.d.ts +14 -0
- package/dist/cli/commands/index.d.ts.map +1 -0
- package/dist/cli/commands/index.js +11 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/commands/init.command.d.ts +41 -0
- package/dist/cli/commands/init.command.d.ts.map +1 -0
- package/dist/cli/commands/init.command.js +111 -0
- package/dist/cli/commands/init.command.js.map +1 -0
- package/dist/cli/commands/test.command.d.ts +58 -0
- package/dist/cli/commands/test.command.d.ts.map +1 -0
- package/dist/cli/commands/test.command.js +180 -0
- package/dist/cli/commands/test.command.js.map +1 -0
- package/dist/cli/index.d.ts +8 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +10 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/config/daemon.config.d.ts +32 -0
- package/dist/core/config/daemon.config.d.ts.map +1 -0
- package/dist/core/config/daemon.config.js +83 -0
- package/dist/core/config/daemon.config.js.map +1 -0
- package/dist/core/config/index.d.ts +5 -0
- package/dist/core/config/index.d.ts.map +1 -0
- package/dist/core/config/index.js +5 -0
- package/dist/core/config/index.js.map +1 -0
- package/dist/core/constants.d.ts +36 -0
- package/dist/core/constants.d.ts.map +1 -0
- package/dist/core/constants.js +56 -0
- package/dist/core/constants.js.map +1 -0
- package/dist/core/types/common.types.d.ts +250 -0
- package/dist/core/types/common.types.d.ts.map +1 -0
- package/dist/core/types/common.types.js +7 -0
- package/dist/core/types/common.types.js.map +1 -0
- package/dist/core/types/detection.types.d.ts +232 -0
- package/dist/core/types/detection.types.d.ts.map +1 -0
- package/dist/core/types/detection.types.js +22 -0
- package/dist/core/types/detection.types.js.map +1 -0
- package/dist/core/types/docker.types.d.ts +322 -0
- package/dist/core/types/docker.types.d.ts.map +1 -0
- package/dist/core/types/docker.types.js +7 -0
- package/dist/core/types/docker.types.js.map +1 -0
- package/dist/core/types/index.d.ts +11 -0
- package/dist/core/types/index.d.ts.map +1 -0
- package/dist/core/types/index.js +7 -0
- package/dist/core/types/index.js.map +1 -0
- package/dist/core/types/project.types.d.ts +74 -0
- package/dist/core/types/project.types.d.ts.map +1 -0
- package/dist/core/types/project.types.js +7 -0
- package/dist/core/types/project.types.js.map +1 -0
- package/dist/core/types/shared.types.d.ts +118 -0
- package/dist/core/types/shared.types.d.ts.map +1 -0
- package/dist/core/types/shared.types.js +7 -0
- package/dist/core/types/shared.types.js.map +1 -0
- package/dist/core/types/test.types.d.ts +230 -0
- package/dist/core/types/test.types.d.ts.map +1 -0
- package/dist/core/types/test.types.js +7 -0
- package/dist/core/types/test.types.js.map +1 -0
- package/dist/services/detection/__tests__/framework-detector.test.d.ts +5 -0
- package/dist/services/detection/__tests__/framework-detector.test.d.ts.map +1 -0
- package/dist/services/detection/__tests__/framework-detector.test.js +52 -0
- package/dist/services/detection/__tests__/framework-detector.test.js.map +1 -0
- package/dist/services/detection/framework-detector.d.ts +179 -0
- package/dist/services/detection/framework-detector.d.ts.map +1 -0
- package/dist/services/detection/framework-detector.js +636 -0
- package/dist/services/detection/framework-detector.js.map +1 -0
- package/dist/services/detection/index.d.ts +10 -0
- package/dist/services/detection/index.d.ts.map +1 -0
- package/dist/services/detection/index.js +7 -0
- package/dist/services/detection/index.js.map +1 -0
- package/dist/services/docker/__tests__/docker-manager.test.d.ts +5 -0
- package/dist/services/docker/__tests__/docker-manager.test.d.ts.map +1 -0
- package/dist/services/docker/__tests__/docker-manager.test.js +67 -0
- package/dist/services/docker/__tests__/docker-manager.test.js.map +1 -0
- package/dist/services/docker/docker-manager.d.ts +157 -0
- package/dist/services/docker/docker-manager.d.ts.map +1 -0
- package/dist/services/docker/docker-manager.js +516 -0
- package/dist/services/docker/docker-manager.js.map +1 -0
- package/dist/services/docker/index.d.ts +9 -0
- package/dist/services/docker/index.d.ts.map +1 -0
- package/dist/services/docker/index.js +9 -0
- package/dist/services/docker/index.js.map +1 -0
- package/dist/services/index.d.ts +10 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +8 -0
- package/dist/services/index.js.map +1 -0
- package/dist/shared/errors/__tests__/base.error.test.d.ts +5 -0
- package/dist/shared/errors/__tests__/base.error.test.d.ts.map +1 -0
- package/dist/shared/errors/__tests__/base.error.test.js +61 -0
- package/dist/shared/errors/__tests__/base.error.test.js.map +1 -0
- package/dist/shared/errors/__tests__/command.error.test.d.ts +5 -0
- package/dist/shared/errors/__tests__/command.error.test.d.ts.map +1 -0
- package/dist/shared/errors/__tests__/command.error.test.js +62 -0
- package/dist/shared/errors/__tests__/command.error.test.js.map +1 -0
- package/dist/shared/errors/__tests__/file.error.test.d.ts +5 -0
- package/dist/shared/errors/__tests__/file.error.test.d.ts.map +1 -0
- package/dist/shared/errors/__tests__/file.error.test.js +75 -0
- package/dist/shared/errors/__tests__/file.error.test.js.map +1 -0
- package/dist/shared/errors/__tests__/index.test.d.ts +5 -0
- package/dist/shared/errors/__tests__/index.test.d.ts.map +1 -0
- package/dist/shared/errors/__tests__/index.test.js +62 -0
- package/dist/shared/errors/__tests__/index.test.js.map +1 -0
- package/dist/shared/errors/__tests__/validation.error.test.d.ts +5 -0
- package/dist/shared/errors/__tests__/validation.error.test.d.ts.map +1 -0
- package/dist/shared/errors/__tests__/validation.error.test.js +79 -0
- package/dist/shared/errors/__tests__/validation.error.test.js.map +1 -0
- package/dist/shared/errors/base.error.d.ts +54 -0
- package/dist/shared/errors/base.error.d.ts.map +1 -0
- package/dist/shared/errors/base.error.js +85 -0
- package/dist/shared/errors/base.error.js.map +1 -0
- package/dist/shared/errors/command.error.d.ts +58 -0
- package/dist/shared/errors/command.error.d.ts.map +1 -0
- package/dist/shared/errors/command.error.js +102 -0
- package/dist/shared/errors/command.error.js.map +1 -0
- package/dist/shared/errors/detection.error.d.ts +42 -0
- package/dist/shared/errors/detection.error.d.ts.map +1 -0
- package/dist/shared/errors/detection.error.js +82 -0
- package/dist/shared/errors/detection.error.js.map +1 -0
- package/dist/shared/errors/docker.error.d.ts +142 -0
- package/dist/shared/errors/docker.error.d.ts.map +1 -0
- package/dist/shared/errors/docker.error.js +172 -0
- package/dist/shared/errors/docker.error.js.map +1 -0
- package/dist/shared/errors/file.error.d.ts +66 -0
- package/dist/shared/errors/file.error.d.ts.map +1 -0
- package/dist/shared/errors/file.error.js +93 -0
- package/dist/shared/errors/file.error.js.map +1 -0
- package/dist/shared/errors/index.d.ts +56 -0
- package/dist/shared/errors/index.d.ts.map +1 -0
- package/dist/shared/errors/index.js +86 -0
- package/dist/shared/errors/index.js.map +1 -0
- package/dist/shared/errors/validation.error.d.ts +67 -0
- package/dist/shared/errors/validation.error.d.ts.map +1 -0
- package/dist/shared/errors/validation.error.js +97 -0
- package/dist/shared/errors/validation.error.js.map +1 -0
- package/dist/shared/templates/index.d.ts +2 -0
- package/dist/shared/templates/index.d.ts.map +1 -0
- package/dist/shared/templates/index.js +2 -0
- package/dist/shared/templates/index.js.map +1 -0
- package/dist/shared/templates/prompt-builder.d.ts +2 -0
- package/dist/shared/templates/prompt-builder.d.ts.map +1 -0
- package/dist/shared/templates/prompt-builder.js +2 -0
- package/dist/shared/templates/prompt-builder.js.map +1 -0
- package/dist/shared/templates/template-engine.d.ts +2 -0
- package/dist/shared/templates/template-engine.d.ts.map +1 -0
- package/dist/shared/templates/template-engine.js +2 -0
- package/dist/shared/templates/template-engine.js.map +1 -0
- package/dist/shared/utils/__tests__/command-executor.test.d.ts +5 -0
- package/dist/shared/utils/__tests__/command-executor.test.d.ts.map +1 -0
- package/dist/shared/utils/__tests__/command-executor.test.js +45 -0
- package/dist/shared/utils/__tests__/command-executor.test.js.map +1 -0
- package/dist/shared/utils/__tests__/file-helper.test.d.ts +5 -0
- package/dist/shared/utils/__tests__/file-helper.test.d.ts.map +1 -0
- package/dist/shared/utils/__tests__/file-helper.test.js +71 -0
- package/dist/shared/utils/__tests__/file-helper.test.js.map +1 -0
- package/dist/shared/utils/__tests__/logger.test.d.ts +5 -0
- package/dist/shared/utils/__tests__/logger.test.d.ts.map +1 -0
- package/dist/shared/utils/__tests__/logger.test.js +83 -0
- package/dist/shared/utils/__tests__/logger.test.js.map +1 -0
- package/dist/shared/utils/command-executer.d.ts +2 -0
- package/dist/shared/utils/command-executer.d.ts.map +1 -0
- package/dist/shared/utils/command-executer.js +2 -0
- package/dist/shared/utils/command-executer.js.map +1 -0
- package/dist/shared/utils/command-executor.d.ts +255 -0
- package/dist/shared/utils/command-executor.d.ts.map +1 -0
- package/dist/shared/utils/command-executor.js +287 -0
- package/dist/shared/utils/command-executor.js.map +1 -0
- package/dist/shared/utils/file-helper.d.ts +86 -0
- package/dist/shared/utils/file-helper.d.ts.map +1 -0
- package/dist/shared/utils/file-helper.js +323 -0
- package/dist/shared/utils/file-helper.js.map +1 -0
- package/dist/shared/utils/index.d.ts +9 -0
- package/dist/shared/utils/index.d.ts.map +1 -0
- package/dist/shared/utils/index.js +9 -0
- package/dist/shared/utils/index.js.map +1 -0
- package/dist/shared/utils/logger.d.ts +163 -0
- package/dist/shared/utils/logger.d.ts.map +1 -0
- package/dist/shared/utils/logger.js +389 -0
- package/dist/shared/utils/logger.js.map +1 -0
- package/package.json +25 -6
- package/CHANGELOG.md +0 -46
- package/agents/deps-analyzer.js +0 -366
- package/agents/detector.js +0 -570
- package/agents/fix-engine.js +0 -305
- package/agents/lighthouse-scanner.js +0 -405
- package/agents/perf-analyzer.js +0 -294
- package/agents/perf-front-analyzer.js +0 -229
- package/agents/test-generator.js +0 -387
- package/agents/test-runner.js +0 -318
- package/bin/cli.js +0 -449
- package/lib/config.js +0 -250
- package/lib/docker.js +0 -207
- package/lib/reporter.js +0 -297
- package/scripts/dev.js +0 -106
package/agents/fix-engine.js
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Daemon - Fix Engine
|
|
3
|
-
*
|
|
4
|
-
* Analyzes test failures and applies fixes.
|
|
5
|
-
* Handles common test issues automatically.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const fs = require('fs');
|
|
9
|
-
const path = require('path');
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Analyze test failure and categorize
|
|
13
|
-
*/
|
|
14
|
-
function categorizeFailure(errorOutput, testPath) {
|
|
15
|
-
if (!errorOutput) return { category: 'unknown' };
|
|
16
|
-
|
|
17
|
-
if (errorOutput.includes('Cannot find module')) {
|
|
18
|
-
return { category: 'import', message: 'Module import issue' };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (errorOutput.includes('is not defined') || errorOutput.includes('is not a function')) {
|
|
22
|
-
return { category: 'mock', message: 'Missing mock' };
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (errorOutput.includes('timeout')) {
|
|
26
|
-
return { category: 'timeout', message: 'Test timeout' };
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (errorOutput.includes('Expected') && errorOutput.includes('Received')) {
|
|
30
|
-
return { category: 'assertion', message: 'Assertion failed' };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (errorOutput.includes('Cannot read property')) {
|
|
34
|
-
return { category: 'null', message: 'Null/undefined access' };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (errorOutput.includes('ECONNREFUSED') || errorOutput.includes('connect')) {
|
|
38
|
-
return { category: 'connection', message: 'Connection refused' };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return { category: 'unknown', message: 'Unknown error' };
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Fix import issues
|
|
46
|
-
*/
|
|
47
|
-
function fixImportIssue(testPath, error) {
|
|
48
|
-
const content = fs.readFileSync(testPath, 'utf-8');
|
|
49
|
-
const missingModule = error.match(/Cannot find module ['"](.+)['"]/)?.[1];
|
|
50
|
-
|
|
51
|
-
if (!missingModule) return false;
|
|
52
|
-
|
|
53
|
-
// Check if it's a relative import issue
|
|
54
|
-
if (missingModule.startsWith('@/')) {
|
|
55
|
-
// Check if vitest.config.ts has the alias
|
|
56
|
-
const vitestConfig = path.join(process.cwd(), 'vitest.config.ts');
|
|
57
|
-
if (fs.existsSync(vitestConfig)) {
|
|
58
|
-
const config = fs.readFileSync(vitestConfig, 'utf-8');
|
|
59
|
-
if (!config.includes('resolve:') || !config.includes('alias:')) {
|
|
60
|
-
return {
|
|
61
|
-
fixType: 'config',
|
|
62
|
-
message: 'Add path alias to vitest.config.ts',
|
|
63
|
-
configFix: `
|
|
64
|
-
export default defineConfig({
|
|
65
|
-
resolve: {
|
|
66
|
-
alias: {
|
|
67
|
-
'@': path.resolve(__dirname, './src'),
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
});`,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
fixType: 'import',
|
|
78
|
-
message: `Create or update import for ${missingModule}`,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Fix mock issues
|
|
84
|
-
*/
|
|
85
|
-
function fixMockIssue(testPath, error) {
|
|
86
|
-
const content = fs.readFileSync(testPath, 'utf-8');
|
|
87
|
-
const missingVar = error.match(/(.+) is not defined/)?.[1];
|
|
88
|
-
|
|
89
|
-
if (!missingVar) return false;
|
|
90
|
-
|
|
91
|
-
// Check if it's a hook/function that needs mocking
|
|
92
|
-
if (missingVar.startsWith('use')) {
|
|
93
|
-
return {
|
|
94
|
-
fixType: 'mock',
|
|
95
|
-
message: `Add mock for ${missingVar}`,
|
|
96
|
-
mock: `vi.mock('@/hooks/${missingVar}', () => ({
|
|
97
|
-
${missingVar}: vi.fn(() => ({/* default return */})),
|
|
98
|
-
}));`,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return {
|
|
103
|
-
fixType: 'mock',
|
|
104
|
-
message: `Add mock for ${missingVar}`,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Fix assertion issues
|
|
110
|
-
*/
|
|
111
|
-
function fixAssertionIssue(testPath, error) {
|
|
112
|
-
const content = fs.readFileSync(testPath, 'utf-8');
|
|
113
|
-
|
|
114
|
-
// Check for common issues
|
|
115
|
-
if (error.includes('querySelector returned null')) {
|
|
116
|
-
return {
|
|
117
|
-
fixType: 'selector',
|
|
118
|
-
message: 'Element not found - use queryBy or add waitFor',
|
|
119
|
-
suggestion: 'Replace getBy with queryBy for optional elements, or add waitFor',
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (error.includes('received null') || error.includes('received undefined')) {
|
|
124
|
-
return {
|
|
125
|
-
fixType: 'assertion',
|
|
126
|
-
message: 'Element/property is null/undefined',
|
|
127
|
-
suggestion: 'Check if component renders with required props',
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return {
|
|
132
|
-
fixType: 'manual',
|
|
133
|
-
message: 'Manual fix required',
|
|
134
|
-
error,
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Fix timeout issues
|
|
140
|
-
*/
|
|
141
|
-
function fixTimeoutIssue(testPath, error) {
|
|
142
|
-
return {
|
|
143
|
-
fixType: 'timeout',
|
|
144
|
-
message: 'Increase test timeout or fix async operation',
|
|
145
|
-
suggestion: `Add timeout to test: it('test name', async () => { ... }, { timeout: 10000 })`,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Fix connection issues
|
|
151
|
-
*/
|
|
152
|
-
function fixConnectionIssue(testPath, error) {
|
|
153
|
-
return {
|
|
154
|
-
fixType: 'mock',
|
|
155
|
-
message: 'Mock external API calls',
|
|
156
|
-
suggestion: 'Use vi.mock or MSW to mock fetch/axios calls',
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Generate fix for a failing test
|
|
162
|
-
*/
|
|
163
|
-
function generateFix(testPath, error) {
|
|
164
|
-
const failure = categorizeFailure(error, testPath);
|
|
165
|
-
|
|
166
|
-
switch (failure.category) {
|
|
167
|
-
case 'import':
|
|
168
|
-
return fixImportIssue(testPath, error);
|
|
169
|
-
case 'mock':
|
|
170
|
-
return fixMockIssue(testPath, error);
|
|
171
|
-
case 'timeout':
|
|
172
|
-
return fixTimeoutIssue(testPath, error);
|
|
173
|
-
case 'assertion':
|
|
174
|
-
return fixAssertionIssue(testPath, error);
|
|
175
|
-
case 'connection':
|
|
176
|
-
return fixConnectionIssue(testPath, error);
|
|
177
|
-
default:
|
|
178
|
-
return {
|
|
179
|
-
fixType: 'manual',
|
|
180
|
-
message: 'Manual analysis required',
|
|
181
|
-
error,
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Apply fix to file
|
|
188
|
-
*/
|
|
189
|
-
function applyFix(testPath, fix) {
|
|
190
|
-
if (!fix) return false;
|
|
191
|
-
|
|
192
|
-
const content = fs.readFileSync(testPath, 'utf-8');
|
|
193
|
-
let newContent = content;
|
|
194
|
-
|
|
195
|
-
switch (fix.fixType) {
|
|
196
|
-
case 'mock':
|
|
197
|
-
// Add mock at top of file after imports
|
|
198
|
-
const importsEnd = content.indexOf(');', content.indexOf('import '));
|
|
199
|
-
if (importsEnd > -1) {
|
|
200
|
-
newContent = content.slice(0, importsEnd + 2) +
|
|
201
|
-
'\n\n' + fix.mock +
|
|
202
|
-
content.slice(importsEnd + 2);
|
|
203
|
-
}
|
|
204
|
-
break;
|
|
205
|
-
|
|
206
|
-
case 'timeout':
|
|
207
|
-
// Add timeout option to it() call
|
|
208
|
-
newContent = content.replace(
|
|
209
|
-
/it\('([^']+)',\s*(async\s*)?\(([^)]*)\)\s*=>/g,
|
|
210
|
-
"it('$1', async ($2) => { ... }, { timeout: 10000 })"
|
|
211
|
-
);
|
|
212
|
-
break;
|
|
213
|
-
|
|
214
|
-
case 'selector':
|
|
215
|
-
// Suggest using queryBy instead of getBy
|
|
216
|
-
newContent = content.replace(
|
|
217
|
-
/getBy\(([^)]+)\)/g,
|
|
218
|
-
'queryBy($1) || getBy($1)'
|
|
219
|
-
);
|
|
220
|
-
break;
|
|
221
|
-
|
|
222
|
-
default:
|
|
223
|
-
return false;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (newContent !== content) {
|
|
227
|
-
fs.writeFileSync(testPath, newContent);
|
|
228
|
-
return true;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return false;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Fix all failing tests
|
|
236
|
-
*/
|
|
237
|
-
function fixFailures(testResults) {
|
|
238
|
-
const fixes = [];
|
|
239
|
-
|
|
240
|
-
for (const result of testResults) {
|
|
241
|
-
if (result.status === 'failed') {
|
|
242
|
-
const fix = generateFix(result.file, result.error);
|
|
243
|
-
fixes.push({
|
|
244
|
-
file: result.file,
|
|
245
|
-
error: result.error,
|
|
246
|
-
fix,
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
return fixes;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Create fix summary
|
|
256
|
-
*/
|
|
257
|
-
function createFixSummary(fixes) {
|
|
258
|
-
const summary = {
|
|
259
|
-
total: fixes.length,
|
|
260
|
-
applied: 0,
|
|
261
|
-
manual: 0,
|
|
262
|
-
failed: 0,
|
|
263
|
-
details: [],
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
for (const fix of fixes) {
|
|
267
|
-
const detail = {
|
|
268
|
-
file: fix.file,
|
|
269
|
-
type: fix.fix?.fixType || 'unknown',
|
|
270
|
-
message: fix.fix?.message || 'No fix available',
|
|
271
|
-
applied: false,
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
if (fix.fix?.fixType === 'manual') {
|
|
275
|
-
summary.manual++;
|
|
276
|
-
detail.applied = false;
|
|
277
|
-
} else if (fix.fix) {
|
|
278
|
-
// Try to apply fix
|
|
279
|
-
// const applied = applyFix(fix.file, fix.fix);
|
|
280
|
-
// if (applied) summary.applied++;
|
|
281
|
-
// else summary.failed++;
|
|
282
|
-
summary.manual++; // For safety, mark as manual
|
|
283
|
-
detail.applied = false;
|
|
284
|
-
} else {
|
|
285
|
-
summary.failed++;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
summary.details.push(detail);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
return summary;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
module.exports = {
|
|
295
|
-
categorizeFailure,
|
|
296
|
-
fixImportIssue,
|
|
297
|
-
fixMockIssue,
|
|
298
|
-
fixAssertionIssue,
|
|
299
|
-
fixTimeoutIssue,
|
|
300
|
-
fixConnectionIssue,
|
|
301
|
-
generateFix,
|
|
302
|
-
applyFix,
|
|
303
|
-
fixFailures,
|
|
304
|
-
createFixSummary,
|
|
305
|
-
};
|
|
@@ -1,405 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Daemon - Lighthouse Page Scanner
|
|
3
|
-
*
|
|
4
|
-
* Automatically discovers and tests all pages with Lighthouse:
|
|
5
|
-
* 1. Scans project for routes/pages
|
|
6
|
-
* 2. Generates page list
|
|
7
|
-
* 3. Runs Lighthouse on each page
|
|
8
|
-
* 4. Aggregates results
|
|
9
|
-
* 5. Generates recommendations
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
const fs = require('fs');
|
|
13
|
-
const path = require('path');
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Discover pages based on framework
|
|
17
|
-
*/
|
|
18
|
-
function discoverPages(projectDir, framework) {
|
|
19
|
-
const pages = [];
|
|
20
|
-
|
|
21
|
-
switch (framework) {
|
|
22
|
-
case 'Next.js':
|
|
23
|
-
// App Router
|
|
24
|
-
const appDir = path.join(projectDir, 'app');
|
|
25
|
-
if (fs.existsSync(appDir)) {
|
|
26
|
-
pages.push(...scanNextjsAppDir(appDir));
|
|
27
|
-
}
|
|
28
|
-
// Pages Router
|
|
29
|
-
const pagesDir = path.join(projectDir, 'pages');
|
|
30
|
-
if (fs.existsSync(pagesDir)) {
|
|
31
|
-
pages.push(...scanNextjsPagesDir(pagesDir));
|
|
32
|
-
}
|
|
33
|
-
break;
|
|
34
|
-
|
|
35
|
-
case 'Remix':
|
|
36
|
-
const remixRoutesDir = path.join(projectDir, 'app', 'routes');
|
|
37
|
-
if (fs.existsSync(remixRoutesDir)) {
|
|
38
|
-
pages.push(...scanRemixRoutes(remixRoutesDir));
|
|
39
|
-
}
|
|
40
|
-
break;
|
|
41
|
-
|
|
42
|
-
case 'SvelteKit':
|
|
43
|
-
const svelteRoutesDir = path.join(projectDir, 'src', 'routes');
|
|
44
|
-
if (fs.existsSync(svelteRoutesDir)) {
|
|
45
|
-
pages.push(...scanSvelteKitRoutes(svelteRoutesDir));
|
|
46
|
-
}
|
|
47
|
-
break;
|
|
48
|
-
|
|
49
|
-
case 'Nuxt':
|
|
50
|
-
const nuxtPagesDir = path.join(projectDir, 'pages');
|
|
51
|
-
if (fs.existsSync(nuxtPagesDir)) {
|
|
52
|
-
pages.push(...scanNuxtPages(nuxtPagesDir));
|
|
53
|
-
}
|
|
54
|
-
break;
|
|
55
|
-
|
|
56
|
-
case 'Vite':
|
|
57
|
-
case 'React':
|
|
58
|
-
case 'Vue':
|
|
59
|
-
case 'Solid':
|
|
60
|
-
case 'Svelte':
|
|
61
|
-
const srcIndex = path.join(projectDir, 'src', 'App.tsx');
|
|
62
|
-
const srcIndexVue = path.join(projectDir, 'src', 'App.vue');
|
|
63
|
-
const mainJsx = path.join(projectDir, 'src', 'main.jsx');
|
|
64
|
-
|
|
65
|
-
if (fs.existsSync(srcIndex) || fs.existsSync(srcIndexVue) || fs.existsSync(mainJsx)) {
|
|
66
|
-
pages.push({
|
|
67
|
-
path: '/',
|
|
68
|
-
name: 'Home',
|
|
69
|
-
priority: 'critical',
|
|
70
|
-
source: 'SPA entry point'
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
break;
|
|
74
|
-
|
|
75
|
-
case 'Angular':
|
|
76
|
-
const angularRoutes = path.join(projectDir, 'src', 'app', 'app-routing.module.ts');
|
|
77
|
-
if (fs.existsSync(angularRoutes)) {
|
|
78
|
-
pages.push(...scanAngularRoutes(angularRoutes));
|
|
79
|
-
}
|
|
80
|
-
break;
|
|
81
|
-
|
|
82
|
-
case 'Express':
|
|
83
|
-
case 'NestJS':
|
|
84
|
-
pages.push(
|
|
85
|
-
...scanExpressRoutes(projectDir)
|
|
86
|
-
);
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Always add common routes for web apps
|
|
91
|
-
const commonRoutes = [
|
|
92
|
-
{ path: '/', name: 'Home', priority: 'critical' },
|
|
93
|
-
{ path: '/login', name: 'Login', priority: 'high' },
|
|
94
|
-
{ path: '/register', name: 'Register', priority: 'medium' },
|
|
95
|
-
{ path: '/dashboard', name: 'Dashboard', priority: 'high' },
|
|
96
|
-
];
|
|
97
|
-
|
|
98
|
-
// Merge without duplicates
|
|
99
|
-
const existingPaths = new Set(pages.map(p => p.path));
|
|
100
|
-
for (const route of commonRoutes) {
|
|
101
|
-
if (!existingPaths.has(route.path)) {
|
|
102
|
-
pages.push({ ...route, source: 'common route' });
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return pages.sort((a, b) => {
|
|
107
|
-
const priorityOrder = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
108
|
-
return priorityOrder[a.priority] - priorityOrder[b.priority];
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Scan Next.js App Router
|
|
114
|
-
*/
|
|
115
|
-
function scanNextjsAppDir(appDir, basePath = '') {
|
|
116
|
-
const pages = [];
|
|
117
|
-
const items = fs.readdirSync(appDir, { withFileTypes: true });
|
|
118
|
-
|
|
119
|
-
for (const item of items) {
|
|
120
|
-
if (item.name.startsWith('_')) continue; // Ignore _layout, _error, etc.
|
|
121
|
-
|
|
122
|
-
const fullPath = path.join(appDir, item.name);
|
|
123
|
-
const routePath = basePath + (item.name === 'page.tsx' || item.name === 'page.ts'
|
|
124
|
-
? '/'
|
|
125
|
-
: `/${item.name.replace(/\.tsx?$/, '').replace(/\[\.{3}.+\]/, '*').replace(/\[(.+)\]/, ':$1')}`);
|
|
126
|
-
|
|
127
|
-
if (item.isDirectory()) {
|
|
128
|
-
pages.push(...scanNextjsAppDir(fullPath, routePath));
|
|
129
|
-
} else if (item.name.startsWith('page.')) {
|
|
130
|
-
pages.push({
|
|
131
|
-
path: routePath === '' ? '/' : routePath,
|
|
132
|
-
name: getPageName(routePath),
|
|
133
|
-
priority: routePath === '/' ? 'critical' : 'medium',
|
|
134
|
-
source: fullPath
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return pages;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Scan Next.js Pages Router
|
|
144
|
-
*/
|
|
145
|
-
function scanNextjsPagesDir(pagesDir, basePath = '') {
|
|
146
|
-
const pages = [];
|
|
147
|
-
const items = fs.readdirSync(pagesDir, { withFileTypes: true });
|
|
148
|
-
|
|
149
|
-
for (const item of items) {
|
|
150
|
-
if (item.name.startsWith('_')) continue;
|
|
151
|
-
|
|
152
|
-
const fullPath = path.join(pagesDir, item.name);
|
|
153
|
-
const routePath = basePath + (item.name === 'index.tsx' || item.name === 'index.ts'
|
|
154
|
-
? '/'
|
|
155
|
-
: `/${item.name.replace(/\.tsx?$/, '')}`);
|
|
156
|
-
|
|
157
|
-
if (item.isDirectory()) {
|
|
158
|
-
pages.push(...scanNextjsPagesDir(fullPath, routePath));
|
|
159
|
-
} else if (item.name.endsWith('.tsx') || item.name.endsWith('.ts')) {
|
|
160
|
-
pages.push({
|
|
161
|
-
path: routePath,
|
|
162
|
-
name: getPageName(routePath),
|
|
163
|
-
priority: routePath === '/' || routePath.includes('dashboard') ? 'high' : 'medium',
|
|
164
|
-
source: fullPath
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return pages;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Scan Remix routes
|
|
174
|
-
*/
|
|
175
|
-
function scanRemixRoutes(routesDir, basePath = '') {
|
|
176
|
-
const pages = [];
|
|
177
|
-
const items = fs.readdirSync(routesDir, { withFileTypes: true });
|
|
178
|
-
|
|
179
|
-
for (const item of items) {
|
|
180
|
-
if (item.name.startsWith('_')) continue;
|
|
181
|
-
|
|
182
|
-
const fullPath = path.join(routesDir, item.name);
|
|
183
|
-
const routePath = basePath + (item.name === 'root.tsx' || item.name === 'root.ts'
|
|
184
|
-
? '/'
|
|
185
|
-
: `/${item.name.replace(/\.tsx?$/, '').replace(/\[\.{3}.+\]/, '*').replace(/\[(.+)\]/, ':$1')}`);
|
|
186
|
-
|
|
187
|
-
if (item.isDirectory()) {
|
|
188
|
-
pages.push(...scanRemixRoutes(fullPath, routePath));
|
|
189
|
-
} else if (!item.name.startsWith('_')) {
|
|
190
|
-
pages.push({
|
|
191
|
-
path: routePath === '' ? '/' : routePath,
|
|
192
|
-
name: getPageName(routePath),
|
|
193
|
-
priority: routePath === '/' ? 'critical' : 'medium',
|
|
194
|
-
source: fullPath
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return pages;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Scan SvelteKit routes
|
|
204
|
-
*/
|
|
205
|
-
function scanSvelteKitRoutes(routesDir, basePath = '') {
|
|
206
|
-
const pages = [];
|
|
207
|
-
const items = fs.readdirSync(routesDir, { withFileTypes: true });
|
|
208
|
-
|
|
209
|
-
for (const item of items) {
|
|
210
|
-
if (item.name.startsWith('_')) continue;
|
|
211
|
-
|
|
212
|
-
const fullPath = path.join(routesDir, item.name);
|
|
213
|
-
const routePath = basePath + (item.name === '+page.svelte'
|
|
214
|
-
? '/'
|
|
215
|
-
: `/${item.name.replace(/\+\w+\./, '').replace(/\[\.{3}.+\]/, '*').replace(/\[(.+)\]/, ':$1')}`);
|
|
216
|
-
|
|
217
|
-
if (item.isDirectory()) {
|
|
218
|
-
pages.push(...scanSvelteKitRoutes(fullPath, routePath));
|
|
219
|
-
} else if (item.name.includes('+page')) {
|
|
220
|
-
pages.push({
|
|
221
|
-
path: routePath === '' ? '/' : routePath,
|
|
222
|
-
name: getPageName(routePath),
|
|
223
|
-
priority: routePath === '/' ? 'critical' : 'medium',
|
|
224
|
-
source: fullPath
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return pages;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Scan Nuxt pages
|
|
234
|
-
*/
|
|
235
|
-
function scanNuxtPages(pagesDir, basePath = '') {
|
|
236
|
-
const pages = [];
|
|
237
|
-
const items = fs.readdirSync(pagesDir, { withFileTypes: true });
|
|
238
|
-
|
|
239
|
-
for (const item of items) {
|
|
240
|
-
const fullPath = path.join(pagesDir, item.name);
|
|
241
|
-
const routePath = basePath + (item.name === 'index.vue'
|
|
242
|
-
? '/'
|
|
243
|
-
: `/${item.name.replace(/\.vue$/, '').replace(/\[\.{3}.+\]/, '*').replace(/\[(.+)\]/, ':$1')}`);
|
|
244
|
-
|
|
245
|
-
if (item.isDirectory()) {
|
|
246
|
-
pages.push(...scanNuxtPages(fullPath, routePath));
|
|
247
|
-
} else if (item.name.endsWith('.vue')) {
|
|
248
|
-
pages.push({
|
|
249
|
-
path: routePath,
|
|
250
|
-
name: getPageName(routePath),
|
|
251
|
-
priority: routePath === '/' ? 'critical' : 'medium',
|
|
252
|
-
source: fullPath
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
return pages;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Scan Angular routes (basic)
|
|
262
|
-
*/
|
|
263
|
-
function scanAngularRoutes(routingFile) {
|
|
264
|
-
const content = fs.readFileSync(routingFile, 'utf-8');
|
|
265
|
-
const pages = [
|
|
266
|
-
{ path: '/', name: 'Home', priority: 'critical', source: routingFile }
|
|
267
|
-
];
|
|
268
|
-
|
|
269
|
-
// Extract path definitions from RouterModule
|
|
270
|
-
const pathMatches = content.matchAll(/path:\s*['"`]([^'"`]+)['"`]/g);
|
|
271
|
-
for (const match of pathMatches) {
|
|
272
|
-
const routePath = match[1];
|
|
273
|
-
if (routePath !== '' && routePath !== '**') {
|
|
274
|
-
pages.push({
|
|
275
|
-
path: `/${routePath}`,
|
|
276
|
-
name: getPageName(`/${routePath}`),
|
|
277
|
-
priority: 'medium',
|
|
278
|
-
source: routingFile
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
return pages;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Scan Express/NestJS routes (basic API routes)
|
|
288
|
-
*/
|
|
289
|
-
function scanExpressRoutes(projectDir) {
|
|
290
|
-
const pages = [];
|
|
291
|
-
|
|
292
|
-
// For API routes, we typically test the API documentation or main endpoints
|
|
293
|
-
const commonApiRoutes = [
|
|
294
|
-
{ path: '/api', name: 'API Root', priority: 'low', source: 'API routes' },
|
|
295
|
-
{ path: '/api/health', name: 'Health Check', priority: 'low', source: 'API routes' },
|
|
296
|
-
];
|
|
297
|
-
|
|
298
|
-
// Try to find route definitions
|
|
299
|
-
const srcFiles = findFiles(projectDir, ['.ts', '.js'], ['routes', 'controllers']);
|
|
300
|
-
|
|
301
|
-
for (const file of srcFiles) {
|
|
302
|
-
const content = fs.readFileSync(file, 'utf-8');
|
|
303
|
-
|
|
304
|
-
// Look for route definitions like app.get(), router.get(), @Get(), etc.
|
|
305
|
-
const getRoutes = content.matchAll(/(?:app|router)\.get\(['"`]([^'"`]+)['"`]/g);
|
|
306
|
-
for (const match of getRoutes) {
|
|
307
|
-
pages.push({
|
|
308
|
-
path: `/api${match[1]}`,
|
|
309
|
-
name: `API: ${match[1]}`,
|
|
310
|
-
priority: 'low',
|
|
311
|
-
source: file
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
return pages.length > 0 ? pages : commonApiRoutes;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* Helper: Find files recursively
|
|
321
|
-
*/
|
|
322
|
-
function findFiles(dir, extensions, keywords = []) {
|
|
323
|
-
const results = [];
|
|
324
|
-
|
|
325
|
-
if (!fs.existsSync(dir)) return results;
|
|
326
|
-
|
|
327
|
-
const items = fs.readdirSync(dir, { withFileTypes: true });
|
|
328
|
-
|
|
329
|
-
for (const item of items) {
|
|
330
|
-
const fullPath = path.join(dir, item.name);
|
|
331
|
-
|
|
332
|
-
if (item.isDirectory()) {
|
|
333
|
-
if (item.name !== 'node_modules' && !item.name.startsWith('.')) {
|
|
334
|
-
results.push(...findFiles(fullPath, extensions, keywords));
|
|
335
|
-
}
|
|
336
|
-
} else if (extensions.some(ext => item.name.endsWith(ext))) {
|
|
337
|
-
if (keywords.length === 0 || keywords.some(kw => fullPath.includes(kw))) {
|
|
338
|
-
results.push(fullPath);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
return results;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Helper: Get readable page name
|
|
348
|
-
*/
|
|
349
|
-
function getPageName(routePath) {
|
|
350
|
-
if (routePath === '/') return 'Home';
|
|
351
|
-
|
|
352
|
-
const parts = routePath.split('/').filter(Boolean);
|
|
353
|
-
return parts
|
|
354
|
-
.map(p => p.replace(/[:-]/g, ' ').replace(/\*/g, 'wildcard'))
|
|
355
|
-
.map(p => p.charAt(0).toUpperCase() + p.slice(1))
|
|
356
|
-
.join(' / ');
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* Generate Lighthouse commands for all pages
|
|
361
|
-
*/
|
|
362
|
-
function generateLighthouseCommands(pages, baseUrl) {
|
|
363
|
-
return pages.map((page, index) => ({
|
|
364
|
-
...page,
|
|
365
|
-
command: `npx lighthouse "${baseUrl}${page.path}" --output=json --output=html --chrome-flags="--headless --no-sandbox" --quiet`,
|
|
366
|
-
outputPath: path.join(process.cwd(), 'reports', `lighthouse-${index}-${page.path.replace(/\//g, '-')}.json`)
|
|
367
|
-
}));
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Create page scanner summary
|
|
372
|
-
*/
|
|
373
|
-
function createPageSummary(pages) {
|
|
374
|
-
const byPriority = {
|
|
375
|
-
critical: pages.filter(p => p.priority === 'critical'),
|
|
376
|
-
high: pages.filter(p => p.priority === 'high'),
|
|
377
|
-
medium: pages.filter(p => p.priority === 'medium'),
|
|
378
|
-
low: pages.filter(p => p.priority === 'low'),
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
return {
|
|
382
|
-
total: pages.length,
|
|
383
|
-
byPriority,
|
|
384
|
-
pages: pages.map(p => ({
|
|
385
|
-
path: p.path,
|
|
386
|
-
name: p.name,
|
|
387
|
-
priority: p.priority,
|
|
388
|
-
source: p.source
|
|
389
|
-
}))
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
module.exports = {
|
|
394
|
-
discoverPages,
|
|
395
|
-
generateLighthouseCommands,
|
|
396
|
-
createPageSummary,
|
|
397
|
-
// Export scanner functions for testing
|
|
398
|
-
scanNextjsAppDir,
|
|
399
|
-
scanNextjsPagesDir,
|
|
400
|
-
scanRemixRoutes,
|
|
401
|
-
scanSvelteKitRoutes,
|
|
402
|
-
scanNuxtPages,
|
|
403
|
-
scanAngularRoutes,
|
|
404
|
-
scanExpressRoutes,
|
|
405
|
-
};
|