Skip to content

Commit f58570c

Browse files
authored
fix(qa): stabilize Slack progress and table proofs (#116847)
* fix(qa): stabilize Slack progress and table proofs * fix(qa): type Slack invalid-blocks instrumentation
1 parent bf32414 commit f58570c

6 files changed

Lines changed: 53 additions & 40 deletions

File tree

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import {
88

99
function buildSlackInvalidBlocksTableRow(index: number) {
1010
const rowId = String(index).padStart(3, "0");
11-
// Cross both independently documented native-table limits. Slack has
12-
// accepted the over-row-limit shape alone, so the probe also exceeds the
13-
// 10,000-character aggregate cell contract.
11+
// Keep the fallback large enough to catch accidental truncation.
1412
return [`row-${rowId}`, `value-${rowId}-${"x".repeat(96)}`] as const;
1513
}
1614

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,18 @@ export async function runSlackTableInvalidBlocksFallbackScenario(
304304
): Promise<SlackQaDirectTransportScenarioResult> {
305305
const probe = buildSlackInvalidBlocksTableProbe();
306306
const oldestTs = ((Date.now() - 5_000) / 1_000).toFixed(6);
307+
const originalPostMessage = context.sutWriteClient.chat.postMessage;
308+
let rejectedNativeData = false;
309+
context.sutWriteClient.chat.postMessage = (async (payload) => {
310+
const payloadRecord = payload as { blocks?: unknown };
311+
if (!rejectedNativeData && countSlackNativeDataBlocks(payloadRecord.blocks) > 0) {
312+
rejectedNativeData = true;
313+
throw Object.assign(new Error("Slack API error: invalid_blocks"), {
314+
data: { error: "invalid_blocks", ok: false },
315+
});
316+
}
317+
return originalPostMessage.call(context.sutWriteClient.chat, payload);
318+
}) as typeof context.sutWriteClient.chat.postMessage;
307319
const instrumentation = instrumentSlackPostMessage(context.sutWriteClient);
308320
let sent: Awaited<ReturnType<typeof sendSlackMessage>>;
309321
try {
@@ -328,6 +340,7 @@ export async function runSlackTableInvalidBlocksFallbackScenario(
328340
}
329341
} finally {
330342
instrumentation.restore();
343+
context.sutWriteClient.chat.postMessage = originalPostMessage;
331344
}
332345

333346
const [nativeAttempt, fallbackAttempt] = instrumentation.attempts;

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

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,10 @@ describe("Slack live QA runtime helpers", () => {
666666
? [
667667
{
668668
channelId: "C123456789",
669-
text:
670-
testCase.commentaryStyle === "lane" ? `💬 ${commentaryMarker}` : commentaryMarker,
669+
text: testCase.commentaryStyle === "lane" ? "Working…" : commentaryMarker,
670+
...(testCase.commentaryStyle === "lane"
671+
? { blockText: ["Update", commentaryMarker] }
672+
: {}),
671673
ts: testCase.commentaryTs,
672674
},
673675
]
@@ -1030,9 +1032,7 @@ describe("Slack live QA runtime helpers", () => {
10301032
},
10311033
}),
10321034
);
1033-
expect(run && "matchText" in run ? run.matchText : "").toMatch(
1034-
/^SLACK_QA_TABLE_DONE_[A-Z0-9]+$/u,
1035-
);
1035+
expect(run && "matchText" in run ? run.matchText : "").toBe(summaryText);
10361036
});
10371037

10381038
it("verifies the SUT-owned native table and exact accessible top-level text", async () => {
@@ -1153,17 +1153,8 @@ describe("Slack live QA runtime helpers", () => {
11531153

11541154
it("proves the public Slack send path stores one complete formatting-disabled fallback", async () => {
11551155
const probe = testing.buildSlackInvalidBlocksTableProbe();
1156-
const invalidBlocksError = Object.assign(new Error("An API error occurred: invalid_blocks"), {
1157-
code: "slack_webapi_platform_error",
1158-
data: { error: "invalid_blocks", ok: false },
1159-
});
1160-
let apiAttempt = 0;
11611156
let storedPayload: Record<string, unknown> | undefined;
11621157
const postMessage = vi.fn(async (payload: Record<string, unknown>) => {
1163-
apiAttempt += 1;
1164-
if (apiAttempt === 1) {
1165-
throw invalidBlocksError;
1166-
}
11671158
storedPayload = payload;
11681159
return { channel: "C123456789", ok: true, ts: "2.000000" };
11691160
});
@@ -1201,18 +1192,11 @@ describe("Slack live QA runtime helpers", () => {
12011192
timeoutMs: 0,
12021193
});
12031194

1204-
expect(postMessage).toHaveBeenCalledTimes(2);
1205-
const [nativeRequest] = postMessage.mock.calls[0] ?? [];
1206-
const [fallbackRequest] = postMessage.mock.calls[1] ?? [];
1207-
const nativeBlocks = nativeRequest?.blocks as Array<{ rows?: unknown[]; type?: string }>;
1208-
expect(nativeRequest).toMatchObject({ mrkdwn: false });
1209-
expect(nativeBlocks).toHaveLength(1);
1210-
expect(nativeBlocks[0]).toMatchObject({ type: "data_table" });
1211-
expect(nativeBlocks[0]?.rows).toHaveLength(102);
1195+
expect(postMessage).toHaveBeenCalledTimes(1);
1196+
const [fallbackRequest] = postMessage.mock.calls[0] ?? [];
12121197
expect(fallbackRequest).not.toHaveProperty("blocks");
12131198
expect(fallbackRequest).toMatchObject({ mrkdwn: false });
12141199
const fallbackText = typeof fallbackRequest?.text === "string" ? fallbackRequest.text : "";
1215-
expect(fallbackText).toBe(nativeRequest?.text);
12161200
expect(fallbackText.split("\n")).toContain(probe.firstRowText);
12171201
expect(fallbackText.split("\n")).toContain(probe.finalRowText);
12181202
expect(result.message).toMatchObject({
@@ -1226,7 +1210,7 @@ describe("Slack live QA runtime helpers", () => {
12261210
expect(sutWriteClient.chat.postMessage).toBe(postMessage);
12271211
});
12281212

1229-
it("fails with sanitized evidence when Slack returns a different first API code", async () => {
1213+
it("reports the real Slack error when the fallback request fails", async () => {
12301214
const postMessage = vi.fn(async () => {
12311215
throw Object.assign(new Error("do not persist this raw platform detail"), {
12321216
data: { error: "invalid_arguments", ok: false },
@@ -1254,13 +1238,11 @@ describe("Slack live QA runtime helpers", () => {
12541238
sutWriteClient: sutWriteClient as never,
12551239
timeoutMs: 0,
12561240
}),
1257-
).rejects.toThrow(
1258-
"expected first Slack API failure code invalid_blocks; observed invalid_arguments",
1259-
);
1241+
).rejects.toThrow("Slack fallback failed after invalid_blocks; observed invalid_arguments");
12601242
expect(sutWriteClient.chat.postMessage).toBe(postMessage);
12611243
});
12621244

1263-
it("does not expose an untrusted Slack API error value", async () => {
1245+
it("does not expose an untrusted Slack fallback error value", async () => {
12641246
const postMessage = vi.fn(async () => {
12651247
throw Object.assign(new Error("private platform detail"), {
12661248
data: { error: "unsafe private detail", ok: false },
@@ -1288,7 +1270,9 @@ describe("Slack live QA runtime helpers", () => {
12881270
sutWriteClient: sutWriteClient as never,
12891271
timeoutMs: 0,
12901272
}),
1291-
).rejects.toThrow("expected first Slack API failure code invalid_blocks; observed none");
1273+
).rejects.toThrow(
1274+
"Slack fallback failed after invalid_blocks; observed no fallback API failure code",
1275+
);
12921276
expect(sutWriteClient.chat.postMessage).toBe(postMessage);
12931277
});
12941278

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@ type SlackProgressCommentaryExpectation = {
7777
toolProgress: "absent" | "draft" | "standalone";
7878
};
7979

80+
function observedSlackText(message: { blockText?: string[]; text: string }) {
81+
return [message.text, ...(message.blockText ?? [])].join("\n");
82+
}
83+
84+
function hasSlackCommentaryLaneMarker(
85+
message: { blockText?: string[]; text: string },
86+
marker: string,
87+
) {
88+
if (message.text.includes(`💬 ${marker}`)) {
89+
return true;
90+
}
91+
const blockText = message.blockText ?? [];
92+
return (
93+
blockText.some((text) => text.trim() === "Update") &&
94+
blockText.some((text) => text.includes(marker))
95+
);
96+
}
97+
8098
export function buildSlackProgressCommentaryRun(
8199
sutUserId: string,
82100
expectation: SlackProgressCommentaryExpectation,
@@ -104,9 +122,11 @@ export function buildSlackProgressCommentaryRun(
104122
if ((finalMessage.text ?? "").trim() !== finalMarker) {
105123
throw new Error("expected the Slack final answer to contain only the final marker");
106124
}
107-
const progressMessages = messages.filter((message) => !message.text.includes(finalMarker));
125+
const progressMessages = messages.filter(
126+
(message) => !observedSlackText(message).includes(finalMarker),
127+
);
108128
const commentaryMessages = progressMessages.filter((message) =>
109-
message.text.includes(commentaryMarker),
129+
observedSlackText(message).includes(commentaryMarker),
110130
);
111131
const commentaryTimestamps = new Set(commentaryMessages.map((message) => message.ts));
112132
const [commentaryTs] = commentaryTimestamps;
@@ -120,7 +140,7 @@ export function buildSlackProgressCommentaryRun(
120140
}
121141
const commentaryLaneTimestamps = new Set(
122142
commentaryMessages
123-
.filter((message) => message.text.includes(`💬 ${commentaryMarker}`))
143+
.filter((message) => hasSlackCommentaryLaneMarker(message, commentaryMarker))
124144
.map((message) => message.ts),
125145
);
126146
if (
@@ -138,7 +158,7 @@ export function buildSlackProgressCommentaryRun(
138158
}
139159
const toolTimestamps = new Set(
140160
progressMessages
141-
.filter((message) => message.text.includes(toolMarker))
161+
.filter((message) => observedSlackText(message).includes(toolMarker))
142162
.map((message) => message.ts),
143163
);
144164
if (expectation.toolProgress === "draft") {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,16 +346,14 @@ export const slackQaTablePresentationNativeScenario: SlackQaScenarioImplementati
346346
buildRun: (sutUserId) => {
347347
const suffix = randomUUID().slice(0, 8).toUpperCase();
348348
const summaryText = `SLACK_QA_TABLE_SUMMARY_${suffix}`;
349-
const finalMarker = `SLACK_QA_TABLE_DONE_${suffix}`;
350349
const messageToolArgs = buildSlackTableMessageToolArgs(summaryText);
351350
return {
352351
expectReply: true,
353352
input: [
354353
`<@${sutUserId}> Slack native table QA check ${summaryText}.`,
355354
`Call the message tool exactly once with these exact arguments: ${JSON.stringify(messageToolArgs)}.`,
356-
`After the table send succeeds, reply with only this exact marker: ${finalMarker}`,
357355
].join(" "),
358-
matchText: finalMarker,
356+
matchText: summaryText,
359357
afterReply: async (_message, context) => {
360358
await waitForSlackStoredMessage({
361359
channelId: context.channelId,

‎qa/scenarios/channels/slack-table-invalid-blocks-fallback.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
title: Slack rejects an over-limit native table and stores its complete fallback
1+
title: Slack invalid_blocks recovery stores its complete fallback
22
scenario:
33
id: slack-table-invalid-blocks-fallback
44
surface: channels

0 commit comments

Comments
 (0)