test(codex): observe completion through the typed spy (#159553)

This commit is contained in:
Peter Steinberger
2026-09-27 03:04:28 -07:00
committed by GitHub
parent f27997f86c
commit b8fa8dc525
@@ -125,26 +125,24 @@ export function captureNativeSubagentMonitorWork() {
export function observeCompletionAttempts() {
const attempts = new Map<Promise<void>, string>();
const started = new Set<{ runId: string; resolve: (attempt: Promise<void>) => void }>();
// oxlint-disable-next-line typescript/unbound-method -- Invoked below with .call(this, ...) to preserve the observed instance.
const original = CodexNativeSubagentCompletionDelivery.prototype.deliverPending;
const observer = vi
.spyOn(CodexNativeSubagentCompletionDelivery.prototype, "deliverPending")
.mockImplementation(function (
this: CodexNativeSubagentCompletionDelivery,
state,
child,
trigger,
) {
const attempt = original.call(this, state, child, trigger);
attempts.set(attempt, child.runId);
for (const waiter of started) {
if (waiter.runId === child.runId) {
started.delete(waiter);
waiter.resolve(attempt);
}
const prototype = CodexNativeSubagentCompletionDelivery.prototype;
const observer = vi.spyOn(prototype, "deliverPending");
prototype.deliverPending = function (
this: CodexNativeSubagentCompletionDelivery,
state,
child,
trigger,
) {
const attempt = observer.call(this, state, child, trigger);
attempts.set(attempt, child.runId);
for (const waiter of started) {
if (waiter.runId === child.runId) {
started.delete(waiter);
waiter.resolve(attempt);
}
return attempt;
});
}
return attempt;
};
onTestFinished(() => observer.mockRestore());
return {
next(runId: string) {