Skip to content

Commit 65ae8a7

Browse files
committed
test(usage): give the rolling-file bound test room on Windows
The 325 appends this test needs cost ~1,954 synchronous fs calls (measured: mkdir 325, chmod 652, append 325, exists 325, read 325, write 2). On windows-latest under full-suite load that took 13.6s and tripped the 5s default, while ubuntu and macos stayed well under it. The cost is per-open rather than per-byte, so removing one of the six calls would not close a 2.7x overshoot. Reducing the append count would trade away coverage -- 325 is already the minimum that crosses the rotate threshold twice. Both assertions and the rotation contract are unchanged.
1 parent 2a3a0f8 commit 65ae8a7

2 files changed

Lines changed: 77 additions & 22 deletions

File tree

‎devlog/_plan/260728_pr_rebuild_unit/010_pr610_posix_launcher.md‎

Lines changed: 67 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -215,42 +215,88 @@ expect(undefined).toBe(false)
215215

216216
즉 이 테스트는 카탈로그 로드 실패를 **잡아낸다**. 조용히 통과하는 구조가 아니었다.
217217

218-
### 3. `PATH=""`가 자식 프로세스에 전달되지 않는다
218+
### 3. Bun이 시작 시점 환경을 스냅샷한다 — Node와 다르다
219219

220-
왜 런처가 죽지 않는가. `runCodexDebugModels`
220+
> **A 게이트 3라운드 정정.** 초안은 이를 "Node/Bun 공통 동작"이라고 적었다. 틀렸다.
221+
> 이건 **Bun 고유 동작**이고, 그 구분이 결론의 의미를 바꾼다.
222+
223+
`runCodexDebugModels`
221224
([src/codex/catalog/bundled.ts:137-143](/Users/jun/developer/new/700_projects/opencodex/src/codex/catalog/bundled.ts))는
222-
`execFile`에 `env` 옵션을 **넘기지 않는다**. Node/Bun이 `env`를 생략하면 자식은
223-
부모 환경을 상속하는데, 그 스냅샷은 프로세스 시작 시점 기준이라
224-
런타임에 `process.env.PATH = ""`로 바꾼 것이 반영되지 않는다.
225+
`execFile`에 `env` 옵션을 넘기지 않는다. 같은 스크립트를 두 런타임으로 돌린 결과:
226+
227+
```
228+
process.env.PATH = ""; execFileSync(bin, [], { encoding: "utf8" })
229+
230+
=== BUN === CHILD_PATH=[/Users/jun/.nvm/.../bin:/opt/homebrew/bin:...] ← 원본 PATH
231+
=== NODE === CHILD_PATH=[] ← 반영됨
232+
```
233+
234+
Bun은 자식 스폰용 환경을 프로세스 시작 시점에 스냅샷하고, 이후의
235+
`process.env` 변경을 관찰하지 않는다. Node는 반영한다.
225236

226-
동일 런처를 세 조건으로 실행한 결과:
237+
세 조건 비교:
227238

228239
```
229-
A: process.env.PATH='' , no env opt OK {"models":[{"slug":"x"}]}
240+
A: process.env.PATH='' , no env opt OK (Bun 한정)
230241
B: explicit env {...process.env} THREW 127
231242
C: explicit env {PATH:''} THREW 127
232243
```
233244

234-
A가 테스트의 실제 경로다. B/C는 `env`를 명시적으로 넘기는 경우 — 앞선 단독 재현이
235-
`env: { ...process.env, PATH: "" }`를 썼기 때문에 127이 났다. 코드가 실제로 타는
236-
경로가 아니었다.
245+
### 3-1. B는 가상이 아니라 실제 호출 지점이다
246+
247+
`src/codex/runtime.ts:261`이 정확히 조건 B다:
248+
249+
```ts
250+
env: { ...(deps.env ?? process.env), CODEX_HOME: probeHome },
251+
```
252+
253+
즉 한 테스트 실행 안에서 **두 프로브가 서로 다른 환경을 본다.**
254+
255+
| 프로브 | 호출 | 자식이 보는 PATH |
256+
| --- | --- | --- |
257+
| `--version` (`runtime.ts:261`) | `env` 명시 | `""` — 반영됨 |
258+
| `debug models` (`bundled.ts:137`) | `env` 생략 | 원본 — Bun 스냅샷 |
259+
260+
`--version` 쪽이 살아남는 건 `echo`가 셸 빌트인이라 PATH 조회가 필요 없기 때문이다.
261+
이 비대칭이 테스트가 초록인 진짜 이유다.
237262

238263
### 결론
239264

240-
리뷰 봇의 P1은 코드를 읽고 추론한 것이고, 그 추론은 `PATH=""`가 자식에게 전달된다는
241-
전제 위에 있다. 이 코드베이스에서는 그 전제가 성립하지 않는다.
265+
리뷰 봇의 P1은 **Node 의미론에서는 옳다.** 다만 이 저장소는 Bun 네이티브 런타임이고
266+
(AGENTS.md), Bun에서는 그 전제가 성립하지 않아 발화하지 않는다. 봇이 틀린 게 아니라
267+
런타임이 다르다.
268+
269+
주의할 점: 이 테스트의 통과가 **Bun 구현 세부에 의존한다.** Bun이 향후 Node와
270+
정렬되면 `tests/codex-runtime.test.ts:360`은 코드 변경 없이 실패하기 시작한다.
271+
272+
### 정정 — `PATH=""`는 장식이 아니다
273+
274+
> 3라운드에서 뒤집힌 두 번째 주장. 초안은 "격리 의도가 달성되지 않는다"고 적었는데
275+
> **틀렸다.**
276+
277+
`PATH`는 자식 프로세스만 쓰는 게 아니라 **in-process에서도 읽힌다.**
278+
`pathCandidates()`
279+
([src/codex/runtime.ts:308-312](/Users/jun/developer/new/700_projects/opencodex/src/codex/runtime.ts))가
280+
`deps.env ?? process.env`의 `PATH`를 분해해 후보 바이너리 목록을 만든다. in-process
281+
읽기는 Bun의 스폰 스냅샷과 무관하게 변경을 즉시 본다.
282+
283+
가짜 `codex`를 PATH에 심고 측정한 결과:
284+
285+
```
286+
PATH=<fakedir> -> source: path version: 9.9.9
287+
PATH='' -> source: fallback version: null
288+
```
289+
290+
`PATH=""`가 결과를 바꾼다. 즉 이 줄은 **머신에 설치된 진짜 `codex`가 후보 목록에
291+
들어오는 것을 실제로 막고 있다.** `CODEX_CLI_PATH` 고정은 두 번째 층이지 대체가 아니다.
242292

243-
**단, 테스트의 격리 의도는 실제로는 달성되지 않고 있다.** `PATH=""`를 설정하는 줄
244-
([tests/codex-runtime.test.ts:373](/Users/jun/developer/new/700_projects/opencodex/tests/codex-runtime.test.ts))은
245-
아무 효과가 없다. 머신에 진짜 `codex`가 PATH에 있으면 이 테스트가 그것을 집을
246-
가능성이 남아 있다는 뜻이다. 다만 테스트는 `CODEX_CLI_PATH`와 `persistCodexRuntime`으로
247-
절대 경로를 직접 지정하므로 현재 구조에서 오염이 실제로 발생하지는 않는다.
293+
이 줄을 "장식이니 지워도 된다"고 판단했다면 테스트를 머신 의존으로 만들 뻔했다.
248294

249-
이건 별개의 위생 문제이고, `src/codex/catalog/bundled.ts`의 `env` 전달 여부를
250-
바꾸는 일은 프로브 동작 변경이라 #610의 영역과 겹친다. **WP2는 NOOP으로 닫고**,
251-
관측 사실을 #610에 코멘트로 남겨 저자와 메인테이너가 판단하게 한다.
295+
### 최종 처분
252296

253-
터미널 판정: **NOOP** (코드 변경 없음, 관측 결과 코멘트로 전달).
297+
터미널 판정: **NOOP** (코드 변경 없음). NOOP 판정 자체는 유효하다 — P1이 이 런타임에서
298+
발화하지 않는다는 결론은 바뀌지 않았다. 바뀐 것은 그 이유의 설명이고, 잘못 전달한
299+
두 진술은 #610에 정정 코멘트로 바로잡는다.
254300

255301
`mihneaptu`의 포크 브랜치에는 push하지 않는다. 우리는 `dev` 대상 브랜치에 고치고,
256302
#610에 "P1은 네가 `056aa2d6e`에서 이미 고쳤다. 다만 같은 파일의 다른 테스트(head:514,

‎tests/usage-debug.test.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ describe("appendUsageDebug", () => {
152152
test("keeps file size bounded by MAX_LINES across long runs", () => {
153153
// Cross the rotate threshold twice — enough to prove the bound holds across
154154
// multiple rewrites without MAX*3 appends (that path times out under full-suite load).
155+
//
156+
// These 325 appends still cost ~1,950 synchronous fs calls: six per append
157+
// (mkdir + chmod from ensureUsageDebugDir, then append, chmod, exists, read),
158+
// plus a write/chmod pair on each of the two rotations. On windows-latest under
159+
// full-suite load that measured 13.6s — past the 5s default — while ubuntu and
160+
// macos stay well under it. The cost is per-open (Defender scans each handle),
161+
// not per-byte, so shaving one of the six calls would not move it enough to
162+
// matter. Give the test the time it needs instead of trading away coverage:
163+
// 325 is already the minimum that crosses the rotate threshold twice.
155164
const total = USAGE_DEBUG_MAX_LINES + USAGE_DEBUG_KEEP_LINES + 25;
156165
for (let i = 0; i < total; i++) {
157166
appendUsageDebug(sample({ requestId: `ocx-${i}`, ts: i }));
@@ -160,5 +169,5 @@ describe("appendUsageDebug", () => {
160169
const lines = readFileSync(path, "utf-8").split(/\r?\n/).filter(Boolean);
161170
expect(lines.length).toBeLessThanOrEqual(USAGE_DEBUG_MAX_LINES);
162171
expect(lines.length).toBeGreaterThanOrEqual(USAGE_DEBUG_KEEP_LINES);
163-
});
172+
}, 15_000);
164173
});

0 commit comments

Comments
 (0)