@@ -39,6 +39,15 @@ function runProfileExtensionMemory(args: string[], cwd = process.cwd()) {
|
39 | 39 | }); |
40 | 40 | } |
41 | 41 | |
| 42 | +function extractReportPath(stdout: string) { |
| 43 | +const match = stdout.match(/^\[extension-memory\] report: (.+)$/mu); |
| 44 | +const reportPath = match?.[1]; |
| 45 | +if (!reportPath) { |
| 46 | +throw new Error(`missing report path in stdout:\n${stdout}`); |
| 47 | +} |
| 48 | +return reportPath; |
| 49 | +} |
| 50 | + |
42 | 51 | async function waitForChildExit( |
43 | 52 | child: ReturnType<typeof spawn>, |
44 | 53 | timeoutMs = 8_000, |
@@ -176,6 +185,44 @@ describe("scripts/profile-extension-memory", () => {
|
176 | 185 | } |
177 | 186 | }); |
178 | 187 | |
| 188 | +it("uses distinct default JSON report paths for separate runs", () => { |
| 189 | +const root = mkdtempSync(path.join(tmpdir(), "openclaw-extension-memory-test-")); |
| 190 | +const reportPaths: string[] = []; |
| 191 | +try { |
| 192 | +const extensionDir = path.join(root, "dist", "extensions", "simple"); |
| 193 | +mkdirSync(extensionDir, { recursive: true }); |
| 194 | +writeFileSync(path.join(extensionDir, "index.js"), `export default {};\n`, "utf8"); |
| 195 | + |
| 196 | +for (let index = 0; index < 2; index += 1) { |
| 197 | +const result = runProfileExtensionMemory( |
| 198 | +["--extension", "simple", "--skip-combined", "--concurrency", "1"], |
| 199 | +root, |
| 200 | +); |
| 201 | + |
| 202 | +expect(result.status, result.stderr).toBe(0); |
| 203 | +const reportPath = extractReportPath(result.stdout); |
| 204 | +reportPaths.push(reportPath); |
| 205 | +expect(path.dirname(reportPath)).toBe(tmpdir()); |
| 206 | +expect(path.basename(reportPath)).toMatch( |
| 207 | +/^openclaw-extension-memory-\d+-\d+-[0-9a-f-]+\.json$/u, |
| 208 | +); |
| 209 | +expect(JSON.parse(readFileSync(reportPath, "utf8")).counts).toMatchObject({ |
| 210 | +totalEntries: 1, |
| 211 | +ok: 1, |
| 212 | +fail: 0, |
| 213 | +timeout: 0, |
| 214 | +}); |
| 215 | +} |
| 216 | + |
| 217 | +expect(reportPaths[0]).not.toBe(reportPaths[1]); |
| 218 | +} finally { |
| 219 | +for (const reportPath of reportPaths) { |
| 220 | +rmSync(reportPath, { force: true }); |
| 221 | +} |
| 222 | +rmSync(root, { recursive: true, force: true }); |
| 223 | +} |
| 224 | +}); |
| 225 | + |
179 | 226 | it("fails when a profiled plugin import fails", () => { |
180 | 227 | const root = mkdtempSync(path.join(tmpdir(), "openclaw-extension-memory-test-")); |
181 | 228 | try { |
|