(workspaceId: string)
| 343 | } |
| 344 | |
| 345 | async clear(workspaceId: string): Promise<void> { |
| 346 | assert(workspaceId.trim().length > 0, "DevToolsService.clear requires a workspaceId"); |
| 347 | |
| 348 | // Wait for any in-flight load to finish before clearing, otherwise the |
| 349 | // pending loadFromDisk can repopulate stale data after the clear. |
| 350 | const pendingLoad = this.loadingPromises.get(workspaceId); |
| 351 | if (pendingLoad) { |
| 352 | await pendingLoad; |
| 353 | } |
| 354 | |
| 355 | const data = this.getOrCreateWorkspaceData(workspaceId); |
| 356 | data.runs.clear(); |
| 357 | data.steps.clear(); |
| 358 | data.clearGeneration += 1; |
| 359 | data.loaded = true; |
| 360 | this.pendingRunMetadata.delete(workspaceId); |
| 361 | |
| 362 | // Enqueue truncation so clear() cannot race with pending appends. |
| 363 | await this.enqueueWrite(workspaceId, async () => { |
| 364 | const filePath = this.getSessionFilePath(workspaceId); |
| 365 | await fs.mkdir(path.dirname(filePath), { recursive: true }); |
| 366 | await fs.writeFile(filePath, "", "utf-8"); |
| 367 | }); |
| 368 | |
| 369 | this.emitWorkspaceEvent(workspaceId, { type: "cleared" }); |
| 370 | } |
| 371 | |
| 372 | private emitWorkspaceEvent(workspaceId: string, event: DevToolsEvent): void { |
| 373 | this.emit(`update:${workspaceId}`, event); |
nothing calls this directly
no test coverage detected