mirror of
https://github.com/openclaw/openclaw.git
synced 2026-09-28 14:12:28 +08:00
test(codex): observe completion through the typed spy (#159553)
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user