Skip to content

Commit 22fe6bd

Browse files
committed
feat(chaos): extend chaos support to handleVideoStatus
handleVideoStatus (GET /v1/videos/{id}) was the only handler missing chaos support. Wires applyChaos into the polling path so tests can inject drop / disconnect / malformed for video-status checks too. Since video status polling has no proxy path, it passes null for fixture and "fixture" for source. Widens ChaosJournalContext.body to accept null (matching JournalEntry.body) so handleVideoStatus can pass null without an unsafe cast.
1 parent abfa3e1 commit 22fe6bd

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/chaos.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ interface ChaosJournalContext {
131131
method: string;
132132
path: string;
133133
headers: Record<string, string>;
134-
body: ChatCompletionRequest;
134+
body: ChatCompletionRequest | null;
135135
}
136136

137137
/**

src/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ export async function createServer(
11961196
const videoStatusMatch = pathname.match(VIDEOS_STATUS_RE);
11971197
if (videoStatusMatch && req.method === "GET") {
11981198
const videoId = videoStatusMatch[1];
1199-
handleVideoStatus(req, res, videoId, journal, setCorsHeaders, videoStates);
1199+
handleVideoStatus(req, res, videoId, journal, defaults, setCorsHeaders, videoStates);
12001200
return;
12011201
}
12021202

src/video.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,29 @@ export function handleVideoStatus(
191191
res: http.ServerResponse,
192192
videoId: string,
193193
journal: Journal,
194+
defaults: HandlerDefaults,
194195
setCorsHeaders: (res: http.ServerResponse) => void,
195196
videoStates: VideoStateMap,
196197
): void {
197198
setCorsHeaders(res);
198199
const path = req.url ?? `/v1/videos/${videoId}`;
199200
const method = req.method ?? "GET";
200201

202+
if (
203+
applyChaos(
204+
res,
205+
null,
206+
defaults.chaos,
207+
req.headers,
208+
journal,
209+
{ method, path, headers: flattenHeaders(req.headers), body: null },
210+
"fixture",
211+
defaults.registry,
212+
defaults.logger,
213+
)
214+
)
215+
return;
216+
201217
const testId = getTestId(req);
202218
const stateKey = `${testId}:${videoId}`;
203219
const video = videoStates.get(stateKey);

0 commit comments

Comments
 (0)