test: stabilize matrix block streaming prompt

This commit is contained in:
Peter Steinberger
2026-04-27 07:25:49 +01:00
parent edf43dfc88
commit 9313554a8d
2 changed files with 15 additions and 12 deletions

View File

@@ -87,12 +87,10 @@ export function buildMatrixBlockStreamingPrompt(
secondText: string,
) {
return [
sutUserId,
"Block streaming QA check:",
"emit exactly two assistant message blocks in order.",
`First exact marker: \`${firstText}\`.`,
`Second exact marker: \`${secondText}\`.`,
].join(" ");
`${sutUserId} Block streaming QA check: reply with exactly this two-line body and no extra text:`,
firstText,
secondText,
].join("\n");
}
export function isMatrixQaMessageLikeKind(kind: MatrixQaObservedEvent["kind"]) {

View File

@@ -2246,10 +2246,11 @@ describe("matrix live qa scenarios", () => {
it("preserves separate finalized block events when Matrix block streaming is enabled", async () => {
const primeRoom = vi.fn().mockResolvedValue("driver-sync-start");
const sendTextMessage = vi.fn().mockResolvedValue("$block-stream-trigger");
const readBlockText = (label: "First" | "Second") =>
new RegExp(`${label} exact marker: \`([^\\\`]+)\``).exec(
String(sendTextMessage.mock.calls[0]?.[0]?.body),
)?.[1] ?? `MATRIX_QA_BLOCK_${label.toUpperCase()}_FIXED`;
const readBlockText = (label: "ONE" | "TWO") =>
String(sendTextMessage.mock.calls[0]?.[0]?.body)
.split("\n")
.find((line) => line.startsWith(`MATRIX_QA_BLOCK_${label}_`)) ??
`MATRIX_QA_BLOCK_${label}_FIXED`;
const waitForRoomEvent = vi
.fn()
.mockImplementationOnce(async () => ({
@@ -2259,7 +2260,7 @@ describe("matrix live qa scenarios", () => {
eventId: "$block-one",
sender: "@sut:matrix-qa.test",
type: "m.room.message",
body: readBlockText("First"),
body: readBlockText("ONE"),
},
since: "driver-sync-block-one",
}))
@@ -2270,7 +2271,7 @@ describe("matrix live qa scenarios", () => {
eventId: "$block-two",
sender: "@sut:matrix-qa.test",
type: "m.room.message",
body: readBlockText("Second"),
body: readBlockText("TWO"),
},
since: "driver-sync-next",
}));
@@ -2333,6 +2334,10 @@ describe("matrix live qa scenarios", () => {
mentionUserIds: ["@sut:matrix-qa.test"],
roomId: "!block:matrix-qa.test",
});
const body = String(sendTextMessage.mock.calls[0]?.[0]?.body);
expect(body).toMatch(
/reply with exactly this two-line body and no extra text:\nMATRIX_QA_BLOCK_ONE_[A-F0-9]{8}\nMATRIX_QA_BLOCK_TWO_[A-F0-9]{8}$/,
);
expect(waitForRoomEvent).toHaveBeenNthCalledWith(
2,
expect.objectContaining({