test(realtime): 조합 transport의 OFFLINE 재시도 규칙을 테스트로 다시 막는다

문제: 0929/04-01 규칙은 "환경이 online이면 transport가 낸 OFFLINE도
online 이벤트를 기다리지 않고 backoff로 재시도한다"이다
(reconnect-coordinator.ts의 RealtimeReconnectEnvironment 주석, 설계 5.3).
이 규칙을 막던 두 테스트는 SSE fetch·reader 거절이 OFFLINE이던 것을
이용했다. af00067(1103/04-04)이 SSE 거절을 PROVIDER_UNAVAILABLE로 바꾼 뒤
두 테스트는 그 kind의 재시도만 본다. 4d27b20이 지운 requireOnline() 두
줄을 되살리는 변이(MR1)에서 realtime 테스트가 모두 통과했다(리뷰 04-R4).

고른 방법: 조합 코드가 만든 transport로 그 경로를 직접 지나는 테스트
둘을 더한다. 환경은 계속 online이다.
- attempt가 OFFLINE/CONNECT/retryable로 실패한다 → 3회 시도, backoff
  [50, 100], OFFLINE retryable로 끝난다. 관측 순서도 고정한다.
- 세션이 열린 뒤 OFFLINE/RECEIVE/retryable로 닫힌다 → 3회 시도,
  OFFLINE retryable로 끝난다.
리뷰 대조 C1·C2와 같은 입력이고, `as never` 없이 파일의 도우미를 쓴다.
버린 대안: SSE 테스트 기대값을 OFFLINE으로 되돌리기. 템플릿 SSE는 이제
OFFLINE을 내지 않으므로 실제 동작과 다른 테스트가 된다.

위험·한계: 테스트만 더했다. 동작은 바뀌지 않는다. 그래서 RED(부모
코드)에서도 이 테스트는 통과한다. 결함을 보이는 방법은 변이 MR1이다.

검증: desktop batch에서 확인.
- GREEN: node scripts/run-vitest.ts run tests/unit/realtime/
- 변이 MR1(reconnect-coordinator.ts의 두 retry 분기 뒤 OFFLINE이면
  requireOnline()): 새 두 테스트가 attempts 1, result null로 실패해야 한다

Refs: 1105/04-01
This commit is contained in:
DongHyeonka
2026-11-05 22:01:01 +09:00
parent e85c8361b6
commit bde7fa4609
@@ -2198,6 +2198,93 @@ describe("transport failures through the reconnect coordinator", () => {
]);
});
// 1105/04-01. No template transport reports OFFLINE any more (1103/04-04),
// so the two SSE tests above no longer reach the 0929/04-01 rule. A
// composer's transport (a STOMP one, say) still may. While the environment
// stays online, its OFFLINE is retried with backoff; waiting for an online
// event that never comes would park the run with no retry and no result.
it("retries a composer transport's OFFLINE attempt failure while the browser stays online", async () => {
const clock = new ManualClock();
const offline = realtimeFailure("OFFLINE", "CONNECT", true);
const observed: string[] = [];
let attempts = 0;
const coordinator = createRealtimeReconnectCoordinator({
policy: policy(),
environment: new MutableOnlineEnvironment(true),
clock,
random: () => 0.5,
confirmTransportBarrier: confirmationSucceeded,
attempt: () => {
attempts += 1;
return failed(offline);
},
observe: (observation) => observed.push(observationLabel(observation)),
});
let result: RealtimeResult<void> | null = null;
void coordinator.run().then((value) => {
result = value;
});
await advanceUntil(clock, () => result !== null);
expect(attempts).toBe(3);
expect(clock.sleepCalls).toEqual([50, 100]);
expect(result).toEqual({
ok: false,
error: { kind: "OFFLINE", operation: "CONNECT", retryable: true },
});
expect(observed).toEqual([
"ATTEMPT_STARTED",
"RETRY_SCHEDULED:OFFLINE",
"ATTEMPT_STARTED",
"RETRY_SCHEDULED:OFFLINE",
"ATTEMPT_STARTED",
"RUN_ENDED:OFFLINE:EXHAUSTED",
]);
});
it("reconnects after a composer session closes with OFFLINE while the browser stays online", async () => {
const clock = new ManualClock();
const offline = realtimeFailure("OFFLINE", "RECEIVE", true);
const observed: string[] = [];
let attempts = 0;
const coordinator = createRealtimeReconnectCoordinator({
policy: policy(),
environment: new MutableOnlineEnvironment(true),
clock,
random: () => 0.5,
confirmTransportBarrier: confirmationSucceeded,
attempt: () => {
attempts += 1;
return opened(
Object.freeze({
classifyClosed: (
receipt: RealtimeReconnectOutcome<void>,
) => receipt,
close: vi.fn(),
waitClosed: () => failed(offline),
}),
);
},
observe: (observation) => observed.push(observationLabel(observation)),
});
let result: RealtimeResult<void> | null = null;
void coordinator.run().then((value) => {
result = value;
});
await advanceUntil(clock, () => result !== null);
expect(attempts).toBe(3);
expect(result).toEqual({
ok: false,
error: { kind: "OFFLINE", operation: "RECEIVE", retryable: true },
});
expect(
observed.filter((label) => label === "RETRY_SCHEDULED:OFFLINE"),
).toHaveLength(2);
});
it.each(["before", "after"] as const)(
"waits for the online event when the browser goes offline %s the SSE fetch rejects",
async (order) => {