@elyracode/test-gen 0.9.58 → 1.0.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/CHANGELOG.md +11 -0
- package/extensions/index.ts +72 -38
- package/package.json +1 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [1.0.1] - 2026-11-22
|
|
4
|
+
|
|
5
|
+
## [1.0.0] - 2026-11-22
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- Fixed `generate_tests` and `find_untested` reporting failures (missing source file, scan errors) as normal results; they now raise a tool error
|
|
10
|
+
- Fixed shell injection through the `find_untested` `path` parameter: `find` now runs with an argv array instead of a shell pipeline, and a leading `-` can no longer be parsed as a `find` expression
|
|
11
|
+
- Fixed `find_untested` scanning the process working directory instead of the session `cwd`
|
package/extensions/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
1
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
3
|
import { basename, dirname, extname, join } from "node:path";
|
|
3
4
|
import type { AgentToolResult, ExtensionAPI } from "@elyracode/coding-agent";
|
|
@@ -38,14 +39,10 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
38
39
|
),
|
|
39
40
|
}),
|
|
40
41
|
execute: async (_toolCallId, params): Promise<AgentToolResult<GenerateTestsDetails>> => {
|
|
42
|
+
if (!existsSync(params.file_path)) {
|
|
43
|
+
throw new Error(`File not found: ${params.file_path}`);
|
|
44
|
+
}
|
|
41
45
|
try {
|
|
42
|
-
if (!existsSync(params.file_path)) {
|
|
43
|
-
return {
|
|
44
|
-
content: [{ type: "text", text: `File not found: ${params.file_path}` }],
|
|
45
|
-
details: {},
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
46
|
const content = readFileSync(params.file_path, "utf-8");
|
|
50
47
|
const ext = extname(params.file_path);
|
|
51
48
|
const dir = dirname(params.file_path);
|
|
@@ -128,10 +125,7 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
128
125
|
};
|
|
129
126
|
} catch (error) {
|
|
130
127
|
const msg = error instanceof Error ? error.message : String(error);
|
|
131
|
-
|
|
132
|
-
content: [{ type: "text", text: `Test generation failed: ${msg}` }],
|
|
133
|
-
details: {},
|
|
134
|
-
};
|
|
128
|
+
throw new Error(`Test generation failed: ${msg}`);
|
|
135
129
|
}
|
|
136
130
|
},
|
|
137
131
|
});
|
|
@@ -146,35 +140,57 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
146
140
|
parameters: Type.Object({
|
|
147
141
|
path: Type.Optional(Type.String({ description: "Directory to scan (default: current directory)" })),
|
|
148
142
|
}),
|
|
149
|
-
execute: async (_toolCallId, params): Promise<AgentToolResult<FindUntestedDetails>> => {
|
|
143
|
+
execute: async (_toolCallId, params, _signal, _onUpdate, ctx): Promise<AgentToolResult<FindUntestedDetails>> => {
|
|
150
144
|
try {
|
|
151
|
-
const
|
|
152
|
-
const cwd = process.cwd();
|
|
145
|
+
const cwd = ctx.cwd;
|
|
153
146
|
const scanPath = params.path ?? ".";
|
|
147
|
+
// A leading '-' would be parsed by find as an expression (e.g. -delete, -exec)
|
|
148
|
+
const findRoot = scanPath.startsWith("-") ? `./${scanPath}` : scanPath;
|
|
154
149
|
|
|
155
150
|
// Find PHP source files
|
|
156
|
-
const phpFiles
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
151
|
+
const phpFiles = findFiles(cwd, [
|
|
152
|
+
findRoot,
|
|
153
|
+
"-name",
|
|
154
|
+
"*.php",
|
|
155
|
+
"-not",
|
|
156
|
+
"-path",
|
|
157
|
+
"*/vendor/*",
|
|
158
|
+
"-not",
|
|
159
|
+
"-path",
|
|
160
|
+
"*/node_modules/*",
|
|
161
|
+
"-not",
|
|
162
|
+
"-path",
|
|
163
|
+
"*/test*",
|
|
164
|
+
"-not",
|
|
165
|
+
"-path",
|
|
166
|
+
"*/Test*",
|
|
167
|
+
"-not",
|
|
168
|
+
"-name",
|
|
169
|
+
"*Test.php",
|
|
170
|
+
"-not",
|
|
171
|
+
"-name",
|
|
172
|
+
"*test.php",
|
|
173
|
+
]).slice(0, 100);
|
|
166
174
|
|
|
167
175
|
// Find TS/JS source files
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
176
|
+
const tsExcludes = ["node_modules", "dist", ".test.", ".spec.", "__tests__"];
|
|
177
|
+
const tsFiles = findFiles(cwd, [
|
|
178
|
+
findRoot,
|
|
179
|
+
"-path",
|
|
180
|
+
"*/node_modules",
|
|
181
|
+
"-prune",
|
|
182
|
+
"-o",
|
|
183
|
+
"(",
|
|
184
|
+
"-name",
|
|
185
|
+
"*.ts",
|
|
186
|
+
"-o",
|
|
187
|
+
"-name",
|
|
188
|
+
"*.tsx",
|
|
189
|
+
")",
|
|
190
|
+
"-print",
|
|
191
|
+
])
|
|
192
|
+
.filter((file) => !tsExcludes.some((exclude) => file.includes(exclude)))
|
|
193
|
+
.slice(0, 100);
|
|
178
194
|
|
|
179
195
|
const untested: string[] = [];
|
|
180
196
|
for (const file of [...phpFiles, ...tsFiles]) {
|
|
@@ -207,10 +223,7 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
207
223
|
};
|
|
208
224
|
} catch (error) {
|
|
209
225
|
const msg = error instanceof Error ? error.message : String(error);
|
|
210
|
-
|
|
211
|
-
content: [{ type: "text", text: `Scan failed: ${msg}` }],
|
|
212
|
-
details: {},
|
|
213
|
-
};
|
|
226
|
+
throw new Error(`Scan failed: ${msg}`);
|
|
214
227
|
}
|
|
215
228
|
},
|
|
216
229
|
});
|
|
@@ -237,6 +250,27 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
237
250
|
});
|
|
238
251
|
}
|
|
239
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Run `find` with an argv array (no shell). Returns matched paths; when find exits
|
|
255
|
+
* non-zero (e.g. unreadable directories) the paths it did print are still returned.
|
|
256
|
+
*/
|
|
257
|
+
function findFiles(cwd: string, args: string[]): string[] {
|
|
258
|
+
let output: string;
|
|
259
|
+
try {
|
|
260
|
+
output = execFileSync("find", args, {
|
|
261
|
+
cwd,
|
|
262
|
+
timeout: 15000,
|
|
263
|
+
encoding: "utf-8",
|
|
264
|
+
maxBuffer: 32 * 1024 * 1024,
|
|
265
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
266
|
+
});
|
|
267
|
+
} catch (error) {
|
|
268
|
+
const stdout = error instanceof Error && "stdout" in error ? error.stdout : undefined;
|
|
269
|
+
output = typeof stdout === "string" ? stdout : "";
|
|
270
|
+
}
|
|
271
|
+
return output.split("\n").filter((l) => l.trim());
|
|
272
|
+
}
|
|
273
|
+
|
|
240
274
|
interface TestFramework {
|
|
241
275
|
type: "pest" | "vitest";
|
|
242
276
|
name: string;
|