refactor: share qa runtime helpers

This commit is contained in:
Peter Steinberger
2026-04-20 20:58:21 +01:00
parent 26fdff9e03
commit 0882b85d5a
2 changed files with 16 additions and 39 deletions

View File

@@ -98,7 +98,7 @@ type QaSuiteScenarioResult = {
details?: string;
};
function createQaSuiteScenarioDeps(params: {
type QaSuiteScenarioDepsParams = {
env: QaSuiteScenarioFlowEnv;
runScenario: (name: string, steps: QaSuiteStep[]) => Promise<QaSuiteScenarioResult>;
splitModelRef: (ref: string) => { provider: string; model: string } | null;
@@ -111,7 +111,18 @@ function createQaSuiteScenarioDeps(params: {
env: Pick<QaSuiteRuntimeEnv, "providerMode" | "primaryModel" | "alternateModel">,
fallbackMs: number,
) => number;
}) {
};
type QaSuiteScenarioFlowApiParams = QaSuiteScenarioDepsParams & {
scenario: QaSeedScenarioWithSource;
constants: {
imageUnderstandingPngBase64: string;
imageUnderstandingLargePngBase64: string;
imageUnderstandingValidPngBase64: string;
};
};
function createQaSuiteScenarioDeps(params: QaSuiteScenarioDepsParams) {
return {
fs,
path,
@@ -185,26 +196,7 @@ function createQaSuiteScenarioDeps(params: {
};
}
export function createQaSuiteScenarioFlowApi(params: {
env: QaSuiteScenarioFlowEnv;
scenario: QaSeedScenarioWithSource;
runScenario: (name: string, steps: QaSuiteStep[]) => Promise<QaSuiteScenarioResult>;
splitModelRef: (ref: string) => { provider: string; model: string } | null;
formatErrorMessage: (error: unknown) => string;
liveTurnTimeoutMs: (
env: Pick<QaSuiteRuntimeEnv, "providerMode" | "primaryModel" | "alternateModel">,
fallbackMs: number,
) => number;
resolveQaLiveTurnTimeoutMs: (
env: Pick<QaSuiteRuntimeEnv, "providerMode" | "primaryModel" | "alternateModel">,
fallbackMs: number,
) => number;
constants: {
imageUnderstandingPngBase64: string;
imageUnderstandingLargePngBase64: string;
imageUnderstandingValidPngBase64: string;
};
}) {
export function createQaSuiteScenarioFlowApi(params: QaSuiteScenarioFlowApiParams) {
return createQaScenarioRuntimeApi({
env: params.env,
scenario: params.scenario,

View File

@@ -2,27 +2,12 @@ import { setTimeout as sleep } from "node:timers/promises";
import {
createFailureAwareTransportWaitForCondition,
findFailureOutboundMessage as findTransportFailureOutboundMessage,
waitForQaTransportCondition,
type QaTransportState,
} from "./qa-transport.js";
import { extractQaFailureReplyText } from "./reply-failure.js";
import type { QaBusMessage } from "./runtime-api.js";
async function waitForCondition<T>(
check: () => T | Promise<T | null | undefined> | null | undefined,
timeoutMs = 15_000,
intervalMs = 100,
): Promise<T> {
const startedAt = Date.now();
while (Date.now() - startedAt < timeoutMs) {
const value = await check();
if (value !== null && value !== undefined) {
return value;
}
await sleep(intervalMs);
}
throw new Error(`timed out after ${timeoutMs}ms`);
}
function findFailureOutboundMessage(
state: QaTransportState,
options?: { sinceIndex?: number; cursorSpace?: "all" | "outbound" },
@@ -40,7 +25,7 @@ async function waitForOutboundMessage(
timeoutMs = 15_000,
options?: { sinceIndex?: number },
) {
return await waitForCondition(() => {
return await waitForQaTransportCondition(() => {
const failureMessage = findFailureOutboundMessage(state, options);
if (failureMessage) {
throw new Error(extractQaFailureReplyText(failureMessage.text) ?? failureMessage.text);