Skip to content

Commit 56ffa2b

Browse files
authored
fix(qa): preserve Slack fallback evidence (#117420)
1 parent 40e1ce6 commit 56ffa2b

3 files changed

Lines changed: 79 additions & 14 deletions

File tree

‎extensions/qa-lab/src/live-transports/slack/slack-live.config.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type SlackQaPostMessageAttempt = {
6262
formattingDisabled: boolean;
6363
nativeDataBlockCount: number;
6464
status: "failed" | "sent";
65+
text: string;
6566
};
6667

6768
export function countSlackNativeDataBlocks(value: unknown) {
@@ -85,10 +86,11 @@ export function instrumentSlackPostMessage(client: WebClient) {
8586
const originalPostMessage = client.chat.postMessage;
8687
const attempts: SlackQaPostMessageAttempt[] = [];
8788
client.chat.postMessage = (async (payload) => {
88-
const payloadRecord = payload as { blocks?: unknown; mrkdwn?: boolean };
89+
const payloadRecord = payload as { blocks?: unknown; mrkdwn?: boolean; text?: unknown };
8990
const attempt = {
9091
formattingDisabled: payloadRecord.mrkdwn === false,
9192
nativeDataBlockCount: countSlackNativeDataBlocks(payloadRecord.blocks),
93+
text: typeof payloadRecord.text === "string" ? payloadRecord.text : "",
9294
};
9395
try {
9496
const response = await originalPostMessage.call(client.chat, payload);

‎extensions/qa-lab/src/live-transports/slack/slack-live.observations.ts‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,15 @@ function normalizeSlackAccessibleText(value: string) {
220220
return value.trim().replace(/\s+/gu, " ");
221221
}
222222

223+
const SLACK_QA_TEXT_DIAGNOSTIC_MAX_CHARS = 500;
224+
225+
function describeSlackObservedText(value: string) {
226+
const preview = value.slice(0, SLACK_QA_TEXT_DIAGNOSTIC_MAX_CHARS);
227+
return `${value.length} characters; actual=${JSON.stringify(preview)}${
228+
preview.length < value.length ? "…" : ""
229+
}`;
230+
}
231+
223232
export function isExpectedSlackNativeChartMessage(
224233
message: SlackMessage,
225234
expectedAccessibleText: string,
@@ -365,6 +374,11 @@ export async function runSlackTableInvalidBlocksFallbackScenario(
365374
) {
366375
throw new Error("Slack fallback did not use one formatting-disabled blockless API request");
367376
}
377+
if (fallbackAttempt.text !== probe.fallbackText) {
378+
throw new Error(
379+
`Slack fallback API request was incomplete: expected ${probe.fallbackText.length} characters, observed ${describeSlackObservedText(fallbackAttempt.text)}`,
380+
);
381+
}
368382

369383
const message = await waitForSlackStoredMessage({
370384
channelId: context.channelId,
@@ -379,16 +393,20 @@ export async function runSlackTableInvalidBlocksFallbackScenario(
379393
if (countSlackNativeDataBlocks(message.blocks) !== 0) {
380394
throw new Error("stored Slack fallback retained a native data block");
381395
}
382-
const storedLines = storedText.split("\n");
383-
if (!storedLines.includes(probe.firstRowText)) {
384-
throw new Error("stored Slack fallback omitted the exact first data row");
396+
const normalizedStoredText = normalizeSlackAccessibleText(storedText);
397+
if (!normalizedStoredText.includes(normalizeSlackAccessibleText(probe.firstRowText))) {
398+
throw new Error(
399+
`stored Slack fallback omitted the first data row: ${describeSlackObservedText(storedText)}`,
400+
);
385401
}
386-
if (!storedLines.includes(probe.finalRowText)) {
387-
throw new Error("stored Slack fallback omitted the exact final data row");
402+
if (!normalizedStoredText.includes(normalizeSlackAccessibleText(probe.finalRowText))) {
403+
throw new Error(
404+
`stored Slack fallback omitted the final data row: ${describeSlackObservedText(storedText)}`,
405+
);
388406
}
389-
if (storedText !== probe.fallbackText) {
407+
if (normalizedStoredText !== normalizeSlackAccessibleText(probe.fallbackText)) {
390408
throw new Error(
391-
`stored Slack fallback was incomplete: expected ${probe.fallbackText.length} characters, observed ${storedText.length}`,
409+
`stored Slack fallback was incomplete: expected ${probe.fallbackText.length} characters, observed ${describeSlackObservedText(storedText)}`,
392410
);
393411
}
394412
return {

‎extensions/qa-lab/src/live-transports/slack/slack-live.runtime.test.ts‎

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,10 @@ describe("Slack live QA runtime helpers", () => {
11671167
? [
11681168
{
11691169
blocks: storedPayload.blocks,
1170-
text: storedPayload.text,
1170+
text:
1171+
typeof storedPayload.text === "string"
1172+
? storedPayload.text.replace(/\s+/gu, " ")
1173+
: storedPayload.text,
11711174
ts: "2.000000",
11721175
user: "U999999999",
11731176
},
@@ -1203,17 +1206,59 @@ describe("Slack live QA runtime helpers", () => {
12031206
const fallbackText = typeof fallbackRequest?.text === "string" ? fallbackRequest.text : "";
12041207
expect(fallbackText.split("\n")).toContain(probe.firstRowText);
12051208
expect(fallbackText.split("\n")).toContain(probe.finalRowText);
1206-
expect(result.message).toMatchObject({
1207-
text: fallbackText,
1208-
ts: "2.000000",
1209-
user: "U999999999",
1210-
});
1209+
expect(result.message).toMatchObject({ ts: "2.000000", user: "U999999999" });
1210+
expect(result.message.text).toBe(fallbackText.replace(/\s+/gu, " "));
12111211
expect(result.details).toContain("first API failure=invalid_blocks");
12121212
expect(result.details).toContain("fallback formatting disabled=true");
12131213
expect(result.details).toContain("complete delivery=true");
12141214
expect(sutWriteClient.chat.postMessage).toBe(postMessage);
12151215
});
12161216

1217+
it("bounds invalid_blocks readback diagnostics while showing the observed text", async () => {
1218+
const malformedReadback = `BROKEN-${"x".repeat(2_000)}`;
1219+
const postMessage = vi.fn(async () => ({
1220+
channel: "C123456789",
1221+
ok: true,
1222+
ts: "2.000000",
1223+
}));
1224+
const sutWriteClient = { chat: { postMessage } };
1225+
const cfg = testing.buildSlackQaConfig(
1226+
{},
1227+
{
1228+
channelId: "C123456789",
1229+
driverBotUserId: "U111111111",
1230+
sutAccountId: "sut",
1231+
sutAppToken: "xapp-sut",
1232+
sutBotToken: "xoxb-sut",
1233+
},
1234+
);
1235+
1236+
const error = await testing
1237+
.runSlackTableInvalidBlocksFallbackScenario({
1238+
cfg,
1239+
channelId: "C123456789",
1240+
sutAccountId: "sut",
1241+
sutIdentity: { userId: "U999999999" },
1242+
sutReadClient: {
1243+
conversations: {
1244+
history: vi.fn(async () => ({
1245+
messages: [{ text: malformedReadback, ts: "2.000000", user: "U999999999" }],
1246+
})),
1247+
},
1248+
} as never,
1249+
sutWriteClient: sutWriteClient as never,
1250+
timeoutMs: 0,
1251+
})
1252+
.catch((caught: unknown) => caught);
1253+
1254+
expect(error).toBeInstanceOf(Error);
1255+
const message = (error as Error).message;
1256+
expect(message).toContain(`${malformedReadback.length} characters`);
1257+
expect(message).toContain('actual="BROKEN-');
1258+
expect(message).toContain("…");
1259+
expect(message.length).toBeLessThan(700);
1260+
});
1261+
12171262
it("reports the real Slack error when the fallback request fails", async () => {
12181263
const postMessage = vi.fn(async () => {
12191264
throw Object.assign(new Error("do not persist this raw platform detail"), {

0 commit comments

Comments
 (0)