@elyracode/test-gen 0.9.56 → 0.9.58
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/extensions/index.ts +29 -13
- package/package.json +1 -1
package/extensions/index.ts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { basename, dirname, extname, join } from "node:path";
|
|
3
|
-
import type { ExtensionAPI } from "@elyracode/coding-agent";
|
|
3
|
+
import type { AgentToolResult, ExtensionAPI } from "@elyracode/coding-agent";
|
|
4
4
|
import { Type } from "typebox";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/** Details reported by generate_tests. */
|
|
7
|
+
interface GenerateTestsDetails {
|
|
8
|
+
framework?: string;
|
|
9
|
+
testPath?: string;
|
|
10
|
+
functions?: number;
|
|
11
|
+
classes?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Details reported by find_untested. */
|
|
15
|
+
interface FindUntestedDetails {
|
|
16
|
+
untestedCount?: number;
|
|
17
|
+
}
|
|
7
18
|
|
|
19
|
+
export default function (elyra: ExtensionAPI): void {
|
|
8
20
|
// ── Tool: generate_tests ──
|
|
9
21
|
elyra.registerTool({
|
|
10
22
|
name: "generate_tests",
|
|
@@ -20,11 +32,12 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
20
32
|
}),
|
|
21
33
|
focus: Type.Optional(
|
|
22
34
|
Type.String({
|
|
23
|
-
description:
|
|
35
|
+
description:
|
|
36
|
+
"Focus on specific methods or functionality (e.g., 'validation', 'edge cases', 'error handling')",
|
|
24
37
|
}),
|
|
25
38
|
),
|
|
26
39
|
}),
|
|
27
|
-
execute: async (_toolCallId, params) => {
|
|
40
|
+
execute: async (_toolCallId, params): Promise<AgentToolResult<GenerateTestsDetails>> => {
|
|
28
41
|
try {
|
|
29
42
|
if (!existsSync(params.file_path)) {
|
|
30
43
|
return {
|
|
@@ -35,7 +48,6 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
35
48
|
|
|
36
49
|
const content = readFileSync(params.file_path, "utf-8");
|
|
37
50
|
const ext = extname(params.file_path);
|
|
38
|
-
const fileName = basename(params.file_path, ext);
|
|
39
51
|
const dir = dirname(params.file_path);
|
|
40
52
|
|
|
41
53
|
const framework = detectTestFramework(ext, dir);
|
|
@@ -132,11 +144,9 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
132
144
|
"Scan the project for source files that don't have corresponding test files. " +
|
|
133
145
|
"Returns a list of files that need tests, prioritized by importance.",
|
|
134
146
|
parameters: Type.Object({
|
|
135
|
-
path: Type.Optional(
|
|
136
|
-
Type.String({ description: "Directory to scan (default: current directory)" }),
|
|
137
|
-
),
|
|
147
|
+
path: Type.Optional(Type.String({ description: "Directory to scan (default: current directory)" })),
|
|
138
148
|
}),
|
|
139
|
-
execute: async (_toolCallId, params) => {
|
|
149
|
+
execute: async (_toolCallId, params): Promise<AgentToolResult<FindUntestedDetails>> => {
|
|
140
150
|
try {
|
|
141
151
|
const { execSync } = await import("node:child_process");
|
|
142
152
|
const cwd = process.cwd();
|
|
@@ -150,7 +160,9 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
150
160
|
{ cwd, timeout: 15000, encoding: "utf-8" },
|
|
151
161
|
);
|
|
152
162
|
phpFiles.push(...result.split("\n").filter((l) => l.trim()));
|
|
153
|
-
} catch {
|
|
163
|
+
} catch {
|
|
164
|
+
/* ignore */
|
|
165
|
+
}
|
|
154
166
|
|
|
155
167
|
// Find TS/JS source files
|
|
156
168
|
const tsFiles: string[] = [];
|
|
@@ -160,7 +172,9 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
160
172
|
{ cwd, timeout: 15000, encoding: "utf-8" },
|
|
161
173
|
);
|
|
162
174
|
tsFiles.push(...result.split("\n").filter((l) => l.trim()));
|
|
163
|
-
} catch {
|
|
175
|
+
} catch {
|
|
176
|
+
/* ignore */
|
|
177
|
+
}
|
|
164
178
|
|
|
165
179
|
const untested: string[] = [];
|
|
166
180
|
for (const file of [...phpFiles, ...tsFiles]) {
|
|
@@ -206,7 +220,9 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
206
220
|
description: "Generate tests for a file: /test-gen <path>",
|
|
207
221
|
handler: async (args, _ctx) => {
|
|
208
222
|
if (!args.trim()) {
|
|
209
|
-
elyra.sendUserMessage(
|
|
223
|
+
elyra.sendUserMessage(
|
|
224
|
+
"Usage: /test-gen <file-path>\n\nExample: /test-gen app/Http/Controllers/ProductController.php",
|
|
225
|
+
);
|
|
210
226
|
return;
|
|
211
227
|
}
|
|
212
228
|
elyra.sendUserMessage(`Generate comprehensive tests for ${args.trim()}`);
|
|
@@ -226,7 +242,7 @@ interface TestFramework {
|
|
|
226
242
|
name: string;
|
|
227
243
|
}
|
|
228
244
|
|
|
229
|
-
function detectTestFramework(ext: string,
|
|
245
|
+
function detectTestFramework(ext: string, _dir: string): TestFramework {
|
|
230
246
|
if (ext === ".php") {
|
|
231
247
|
return { type: "pest", name: "Pest (Laravel)" };
|
|
232
248
|
}
|