opencode-config/docs/decisions/081-pr-186-beforeall-output-tmp-race.md
Sergey 72caab4097
fix(draw-image): per-process output TMP in beforeAll for parallel vitest (#186)
* fix(draw-image): per-process output TMP in integration tests

* fix(draw-image): per-process output TMP in e2e tests

* fix(draw-image): per-process output TMP in cleanup test

* docs(handoff): add handoff and ADR for beforeAll output TMP fix

* docs(handoff): set PR number

* docs(handoff): set PR number 186

---------

Co-authored-by: opencode-agent <agent@opencode.local>
2026-07-31 22:39:58 +03:00

14 lines
No EOL
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ADR-081: Per-process output TMP dirs in draw-image test beforeAll
## Статус
Accepted (2026-07-31)
## Контекст
Тестовые файлы draw-image использовали общий output-каталог на тест-файл (`/tmp/draw-image-<name>`), создаваемый/очищаемый в `beforeAll`. При параллельном запуске нескольких процессов vitest concurrently (внешняя параллель, не intra-pool) процессы с одинаковым набором тест-файлов конкурировали за один каталог: `rmSync(TMP, recursive)` процесса A удалял PNG + `meta.json`, только что написанные процессом B → падение assertions (`existsSync`, `skipped vs rendered`, `unable to open for write`). Аналогично race на `input.svg` (#177, test helper), но для output-каталогов `beforeAll`. Issue #183.
## Решение
Уникализировать output-каталог на процесс через `process.pid` suffix: `TMP = path.join(os.tmpdir(), \`draw-image-<name>-\${process.pid}\`)`. Добавить `afterAll` cleanup где отсутствовал. `process.pid` уникален на каждый параллельный vitest-процесс → каталоги не коллизируют. Не использован `mkdtempSync` — детерминированный suffixed path проще для assertions и достаточно уникален для внешней параллельности (intra-pool workers у vitest по умолчанию forks → разные PID).
## Альтернативы
- `fs.mkdtempSync(path.join(os.tmpdir(), "draw-image-<name>-"))` — гарантированная уникальность даже при одинаковом PID (threads pool), но nondeterministic path усложняет дебаг. PID-suffix достаточен для текущего pool-режима vitest.
- Vitest `--no-parallel` / `--pool=threads --poolOptions.threads.singleThread: true` — подавляет параллель, но не устраняет root cause и замедляет CI.