()
| 560 | |
| 561 | let persistQueue = Promise.resolve(); |
| 562 | function persistState() { |
| 563 | if (!stateCache) { |
| 564 | return persistQueue; |
| 565 | } |
| 566 | // Snapshot synchronously and serialize writes so concurrent mutations |
| 567 | // persist in call order — a slow earlier write can't clobber a newer one. |
| 568 | const snapshot = JSON.stringify(stateCache, null, 2); |
| 569 | persistQueue = persistQueue |
| 570 | .catch(() => {}) |
| 571 | .then(async () => { |
| 572 | await mkdir(ARTIFACTS_DIR, { recursive: true }); |
| 573 | await writeFile(STATE_FILE, snapshot, "utf8"); |
| 574 | }); |
| 575 | return persistQueue; |
| 576 | } |
| 577 | |
| 578 | function normalizeState(raw) { |
| 579 | if (!raw || typeof raw !== "object") { |
no outgoing calls
no test coverage detected