mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-17 20:21:13 +00:00
67 lines
1.3 KiB
TypeScript
67 lines
1.3 KiB
TypeScript
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
|
import type { QaBusState } from "./bus-state.js";
|
|
|
|
export type QaScenarioStepContext = {
|
|
state: QaBusState;
|
|
};
|
|
|
|
export type QaScenarioStep = {
|
|
name: string;
|
|
run: (ctx: QaScenarioStepContext) => Promise<string | void>;
|
|
};
|
|
|
|
export type QaScenarioDefinition = {
|
|
name: string;
|
|
steps: QaScenarioStep[];
|
|
};
|
|
|
|
export type QaScenarioStepResult = {
|
|
name: string;
|
|
status: "pass" | "fail";
|
|
details?: string;
|
|
};
|
|
|
|
export type QaScenarioResult = {
|
|
name: string;
|
|
status: "pass" | "fail";
|
|
steps: QaScenarioStepResult[];
|
|
details?: string;
|
|
};
|
|
|
|
export async function runQaScenario(
|
|
definition: QaScenarioDefinition,
|
|
ctx: QaScenarioStepContext,
|
|
): Promise<QaScenarioResult> {
|
|
const steps: QaScenarioStepResult[] = [];
|
|
|
|
for (const step of definition.steps) {
|
|
try {
|
|
const details = await step.run(ctx);
|
|
steps.push({
|
|
name: step.name,
|
|
status: "pass",
|
|
...(details ? { details } : {}),
|
|
});
|
|
} catch (error) {
|
|
const details = formatErrorMessage(error);
|
|
steps.push({
|
|
name: step.name,
|
|
status: "fail",
|
|
details,
|
|
});
|
|
return {
|
|
name: definition.name,
|
|
status: "fail",
|
|
steps,
|
|
details,
|
|
};
|
|
}
|
|
}
|
|
|
|
return {
|
|
name: definition.name,
|
|
status: "pass",
|
|
steps,
|
|
};
|
|
}
|