






















@@ -1895,6 +1895,7 @@ async function waitForScenarioObservedMessage(
18951895label: string;
18961896match: (message: WhatsAppQaDriverObservedMessage) => boolean;
18971897}>;
1898+expectedSender?: (message: WhatsAppQaDriverObservedMessage) => boolean;
18981899match: (message: WhatsAppQaDriverObservedMessage) => boolean;
18991900observedAfter?: Date;
19001901timeoutMs?: number;
@@ -1906,7 +1907,8 @@ async function waitForScenarioObservedMessage(
19061907observedAfter: params.observedAfter,
19071908timeoutMs: params.timeoutMs ?? 45_000,
19081909match: (candidate) =>
1909-candidate.fromPhoneE164 === context.sutPhoneE164 && params.match(candidate),
1910+(params.expectedSender?.(candidate) ?? candidate.fromPhoneE164 === context.sutPhoneE164) &&
1911+params.match(candidate),
19101912});
19111913} catch (error) {
19121914if (/\btimed out waiting for WhatsApp QA driver message\b/iu.test(formatErrorMessage(error))) {
@@ -2522,6 +2524,8 @@ async function runWhatsAppScenario(params: {
25222524sutAuthDir: string;
25232525sutPhoneE164: string;
25242526groupJid?: string;
2527+onGatewayDebugPreserveFailure?: (error: unknown) => void;
2528+onGatewayDebugPreserved?: () => void;
25252529}): Promise<WhatsAppQaScenarioResult> {
25262530const scenarioRun = params.scenario.buildRun();
25272531if (scenarioRun.kind !== "approval" && scenarioRun.target === "group" && !params.groupJid) {
@@ -2709,26 +2713,19 @@ async function runWhatsAppScenario(params: {
27092713details: "no reply",
27102714};
27112715}
2712-const reply = await params.driver.waitForMessage({
2716+const reply = await waitForScenarioObservedMessage(scenarioContext, {
27132717observedAfter: requestStartedAt,
27142718timeoutMs: params.scenario.timeoutMs,
2715-match: (message) =>
2716-(scenarioRun.target === "group"
2719+expectedSender: (message) =>
2720+scenarioRun.target === "group"
27172721 ? message.fromJid === params.groupJid
2718- : message.fromPhoneE164 === params.sutPhoneE164) &&
2719- messageMatches(message as WhatsAppObservedMessage, scenarioRun.matchText),
2722+ : message.fromPhoneE164 === params.sutPhoneE164,
2723+match: (message) => messageMatches(message as WhatsAppObservedMessage, scenarioRun.matchText),
27202724});
2721-const observed: WhatsAppObservedMessage = {
2722- ...reply,
2723-matchedScenario: true,
2724-scenarioId: params.scenario.id,
2725-scenarioTitle: params.scenario.title,
2726-};
27272725scenarioRun.verify?.(reply, scenarioContext);
2728-params.observedMessages.push(observed);
27292726const afterReplyDetails = await scenarioRun.afterReply?.(reply, scenarioContext);
27302727const batchDetails = await assertWhatsAppScenarioMessageBatch({
2731-alreadyRecordedMessageIds: new Set(observed.messageId ? [observed.messageId] : []),
2728+alreadyRecordedMessageIds: new Set(reply.messageId ? [reply.messageId] : []),
27322729context: scenarioContext,
27332730observedAfter: requestStartedAt,
27342731run: scenarioRun,
@@ -2754,8 +2751,13 @@ async function runWhatsAppScenario(params: {
27542751},
27552752};
27562753} catch (error) {
2757-preservedGatewayDebug = true;
2758-await gatewayHarness.stop({ preserveToDir: params.gatewayDebugDirPath }).catch(() => {});
2754+try {
2755+await gatewayHarness.stop({ preserveToDir: params.gatewayDebugDirPath });
2756+preservedGatewayDebug = true;
2757+params.onGatewayDebugPreserved?.();
2758+} catch (preserveError) {
2759+params.onGatewayDebugPreserveFailure?.(preserveError);
2760+}
27592761throw error;
27602762} finally {
27612763if (!preservedGatewayDebug) {
@@ -3074,6 +3076,8 @@ export async function runWhatsAppQaLive(params: {
30743076}
30753077let driverAttempt = 1;
30763078while (true) {
3079+let scenarioGatewayDebugPreserved = false;
3080+const scenarioGatewayDebugPreserveFailures: unknown[] = [];
30773081try {
30783082const result = await runWhatsAppScenario({
30793083driver: activeDriver,
@@ -3090,6 +3094,12 @@ export async function runWhatsAppQaLive(params: {
30903094 sutAccountId,
30913095 sutAuthDir,
30923096sutPhoneE164: runtimeEnv.sutPhoneE164,
3097+onGatewayDebugPreserved: () => {
3098+scenarioGatewayDebugPreserved = true;
3099+},
3100+onGatewayDebugPreserveFailure: (error) => {
3101+scenarioGatewayDebugPreserveFailures.push(error);
3102+},
30933103});
30943104const recordedResult =
30953105driverAttempt > 1
@@ -3126,7 +3136,12 @@ export async function runWhatsAppQaLive(params: {
31263136closeDriverSession = () => activeDriver.close();
31273137continue;
31283138}
3129-preservedGatewayDebugArtifacts = true;
3139+if (scenarioGatewayDebugPreserved) {
3140+preservedGatewayDebugArtifacts = true;
3141+}
3142+for (const preserveError of scenarioGatewayDebugPreserveFailures) {
3143+appendLiveLaneIssue(cleanupIssues, "gateway debug preserve failed", preserveError);
3144+}
31303145const result: WhatsAppQaScenarioResult = {
31313146id: scenario.id,
31323147title: scenario.title,
@@ -3286,6 +3301,7 @@ export const testing = {
32863301 parseWhatsAppQaCredentialPayload,
32873302 renderWhatsAppQaMarkdown,
32883303 runWhatsAppStructuredInboundChecks,
3304+ waitForScenarioObservedMessage,
32893305 redactWhatsAppQaScenarioResults,
32903306 resolveWhatsAppQaMessageTargets,
32913307 resolveWhatsAppQaRuntimeEnv,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。