Skip to content

Commit 4c94d9f

Browse files
authored
fix(qa): reject silent and out-of-character persona conversations (#119497)
* fix(qa): reject unanswered and unsafe character conversations * fix(qa): propagate classified persona delivery failures * fix(qa): keep qualitative persona evaluations on live providers * test(qa): avoid inefficient persona failure table spread
1 parent 85fd4c9 commit 4c94d9f

3 files changed

Lines changed: 255 additions & 10 deletions

File tree

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
import { join } from "node:path";
2+
import { describe, expect, it } from "vitest";
3+
import { createQaBusState } from "./bus-state.js";
4+
import { readQaScenarioById } from "./scenario-catalog.js";
5+
import { runLoadedScenarioFlow } from "./scenario-flow-runner.test-support.js";
6+
import { selectQaFlowSuiteScenarios } from "./suite-planning.js";
7+
import { waitForOutboundMessage } from "./suite-runtime-transport.js";
8+
9+
const characterScenarioIds = ["character-vibes-gollum", "character-vibes-c3po"] as const;
10+
const classifiedFailureReplies = [
11+
{
12+
failureName: "provider failure",
13+
failureText: '⚠️ No API key found for provider "openai".',
14+
},
15+
{
16+
failureName: "delivery failure",
17+
failureText: "⚠️ ✉️ Message failed",
18+
},
19+
{
20+
failureName: "missing tool failure",
21+
failureText: "Read: AGENT.md\nEvidence snippet: Tool read not found\nStatus: blocked",
22+
},
23+
{
24+
failureName: "internal coordination leak",
25+
failureText: "checking thread context; then post a tight progress reply here.",
26+
},
27+
] as const;
28+
29+
function createCharacterScenarioApi(
30+
onWaitForOutboundMessage?: (state: ReturnType<typeof createQaBusState>) => void,
31+
) {
32+
return {
33+
env: {
34+
providerMode: "live-frontier",
35+
gateway: {
36+
workspaceDir: "/qa-character-workspace",
37+
},
38+
},
39+
fs: {
40+
writeFile: async () => undefined,
41+
},
42+
path: { join },
43+
normalizeLowercaseStringOrEmpty: (value: unknown) =>
44+
typeof value === "string" ? value.trim().toLowerCase() : "",
45+
resolveQaLiveTurnTimeoutMs: () => 10,
46+
waitForOutboundMessage: async (
47+
state: ReturnType<typeof createQaBusState>,
48+
predicate: Parameters<typeof waitForOutboundMessage>[1],
49+
timeoutMs: number,
50+
options?: Parameters<typeof waitForOutboundMessage>[3],
51+
) => {
52+
onWaitForOutboundMessage?.(state);
53+
return await waitForOutboundMessage(state, predicate, timeoutMs, options);
54+
},
55+
formatConversationTranscript: (state: ReturnType<typeof createQaBusState>) =>
56+
state
57+
.getSnapshot()
58+
.messages.map((message) => `${message.direction}:${message.text}`)
59+
.join("\n"),
60+
};
61+
}
62+
63+
describe("character scenario transcript safety", () => {
64+
it.each(characterScenarioIds)("requires a live provider for %s", (scenarioId) => {
65+
const scenario = readQaScenarioById(scenarioId);
66+
67+
expect(scenario.execution.config?.requiredProviderMode).toBe("live-frontier");
68+
expect(() =>
69+
selectQaFlowSuiteScenarios({
70+
scenarios: [scenario],
71+
scenarioIds: [scenarioId],
72+
providerMode: "mock-openai",
73+
primaryModel: "mock-openai/gpt-5.6-luna",
74+
}),
75+
).toThrow(`${scenarioId} (providerMode=live-frontier)`);
76+
expect(
77+
selectQaFlowSuiteScenarios({
78+
scenarios: [scenario],
79+
providerMode: "mock-openai",
80+
primaryModel: "mock-openai/gpt-5.6-luna",
81+
}),
82+
).toEqual([]);
83+
expect(
84+
selectQaFlowSuiteScenarios({
85+
scenarios: [scenario],
86+
scenarioIds: [scenarioId],
87+
providerMode: "live-frontier",
88+
primaryModel: "openai/gpt-5.6-luna",
89+
}),
90+
).toEqual([scenario]);
91+
});
92+
93+
it.each(characterScenarioIds)("rejects forbidden model internals in %s", async (scenarioId) => {
94+
const state = createQaBusState();
95+
96+
await expect(
97+
runLoadedScenarioFlow(scenarioId, {
98+
state,
99+
api: createCharacterScenarioApi((currentState) => {
100+
currentState.addOutboundMessage({
101+
accountId: "qa-channel",
102+
to: "dm:alice",
103+
text: "As an AI, I cannot stay in character.",
104+
});
105+
}),
106+
}),
107+
).rejects.toThrow("hit fallback/error text: As an AI, I cannot stay in character.");
108+
109+
expect(state.getSnapshot().messages.some((message) => message.direction === "outbound")).toBe(
110+
true,
111+
);
112+
});
113+
114+
it.each(
115+
characterScenarioIds.flatMap((scenarioId) =>
116+
classifiedFailureReplies.map(({ failureName, failureText }) => ({
117+
scenarioId,
118+
failureName,
119+
failureText,
120+
})),
121+
),
122+
)(
123+
"rejects a $failureName after an actual reply in $scenarioId",
124+
async ({ scenarioId, failureText }) => {
125+
const state = createQaBusState();
126+
const firstReply = "The build is green, and I am here.";
127+
let waitCount = 0;
128+
129+
await expect(
130+
runLoadedScenarioFlow(scenarioId, {
131+
state,
132+
api: createCharacterScenarioApi((currentState) => {
133+
currentState.addOutboundMessage({
134+
accountId: "qa-channel",
135+
to: "dm:alice",
136+
text: waitCount++ === 0 ? firstReply : failureText,
137+
});
138+
}),
139+
}),
140+
).rejects.toThrow(failureText);
141+
142+
expect(
143+
state
144+
.getSnapshot()
145+
.messages.filter((message) => message.direction === "outbound")
146+
.map((message) => message.text),
147+
).toEqual([firstReply, failureText]);
148+
},
149+
);
150+
151+
it.each(characterScenarioIds)(
152+
"rejects an entirely unanswered character conversation in %s",
153+
async (scenarioId) => {
154+
const state = createQaBusState();
155+
156+
await expect(
157+
runLoadedScenarioFlow(scenarioId, {
158+
state,
159+
api: createCharacterScenarioApi(),
160+
}),
161+
).rejects.toThrow("no assistant replies");
162+
163+
expect(state.getSnapshot().messages).toHaveLength(4);
164+
expect(state.getSnapshot().messages.every((message) => message.direction === "inbound")).toBe(
165+
true,
166+
);
167+
},
168+
);
169+
170+
it.each(characterScenarioIds)(
171+
"keeps partially missing replies visible without aborting %s",
172+
async (scenarioId) => {
173+
const state = createQaBusState();
174+
const reply = "The build is green, and I am here.";
175+
const result = await runLoadedScenarioFlow(scenarioId, {
176+
state,
177+
api: createCharacterScenarioApi((currentState) => {
178+
if (
179+
currentState.getSnapshot().messages.some((message) => message.direction === "outbound")
180+
) {
181+
return;
182+
}
183+
currentState.addOutboundMessage({
184+
accountId: "qa-channel",
185+
to: "dm:alice",
186+
text: reply,
187+
});
188+
}),
189+
});
190+
191+
expect(result.status).toBe("pass");
192+
expect(result.steps[0]?.details).toContain("inbound:");
193+
expect(result.steps[0]?.details).toContain(`outbound:${reply}`);
194+
const messages = state.getSnapshot().messages;
195+
expect(messages.filter((message) => message.direction === "inbound")).toHaveLength(4);
196+
expect(messages.filter((message) => message.direction === "outbound")).toHaveLength(1);
197+
},
198+
);
199+
});

‎qa/scenarios/character/character-vibes-c3po.yaml‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ scenario:
2525
kind: flow
2626
summary: Capture a raw natural C-3PO character transcript for later quality grading.
2727
config:
28+
requiredProviderMode: live-frontier
2829
conversationId: alice
2930
senderName: Alice
3031
workspaceFiles:
@@ -81,6 +82,8 @@ flow:
8182
- expr: "path.join(env.gateway.workspaceDir, String(workspaceFile[0]))"
8283
- expr: "`${String(workspaceFile[1] ?? '').trimEnd()}\\n`"
8384
- utf8
85+
- set: assistantReplyCount
86+
value: 0
8487
- forEach:
8588
items:
8689
ref: config.turns
@@ -100,6 +103,8 @@ flow:
100103
ref: config.senderName
101104
text:
102105
expr: turn.text
106+
- set: latestOutbound
107+
value: null
103108
- try:
104109
actions:
105110
- call: waitForOutboundMessage
@@ -112,13 +117,31 @@ flow:
112117
- expr: resolveQaLiveTurnTimeoutMs(env, 45000)
113118
- sinceIndex:
114119
ref: beforeOutboundCount
115-
- assert:
116-
expr: "!config.forbiddenNeedles.some((needle) => normalizeLowercaseStringOrEmpty(latestOutbound.text).includes(needle))"
117-
message:
118-
expr: "`C-3PO natural chat turn ${String(turnIndex)} hit fallback/error text: ${latestOutbound.text}`"
119120
catchAs: turnError
120121
catch:
122+
- if:
123+
expr: "!(turnError instanceof Error) || turnError.message !== `timed out after ${resolveQaLiveTurnTimeoutMs(env, 45000)}ms`"
124+
then:
125+
- throw:
126+
expr: turnError
121127
- set: latestTurnError
122128
value:
123129
ref: turnError
124-
detailsExpr: "formatConversationTranscript(state, { conversationId: config.conversationId })"
130+
- if:
131+
expr: latestOutbound != null
132+
then:
133+
- assert:
134+
expr: "!config.forbiddenNeedles.some((needle) => normalizeLowercaseStringOrEmpty(latestOutbound.text).includes(needle))"
135+
message:
136+
expr: "`C-3PO natural chat turn ${String(turnIndex)} hit fallback/error text: ${latestOutbound.text}`"
137+
- set: assistantReplyCount
138+
value:
139+
expr: assistantReplyCount + 1
140+
- set: conversationTranscript
141+
value:
142+
expr: "formatConversationTranscript(state, { conversationId: config.conversationId })"
143+
- assert:
144+
expr: assistantReplyCount >= 1
145+
message:
146+
expr: "`C-3PO natural chat produced no assistant replies; transcript: ${conversationTranscript}`"
147+
detailsExpr: conversationTranscript

‎qa/scenarios/character/character-vibes-gollum.yaml‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ scenario:
2424
kind: flow
2525
summary: Capture a raw natural character transcript for later quality grading.
2626
config:
27+
requiredProviderMode: live-frontier
2728
conversationId: alice
2829
senderName: Alice
2930
workspaceFiles:
@@ -101,6 +102,8 @@ flow:
101102
- expr: "path.join(env.gateway.workspaceDir, String(workspaceFile[0]))"
102103
- expr: "`${String(workspaceFile[1] ?? '').trimEnd()}\\n`"
103104
- utf8
105+
- set: assistantReplyCount
106+
value: 0
104107
- forEach:
105108
items:
106109
ref: config.turns
@@ -120,6 +123,8 @@ flow:
120123
ref: config.senderName
121124
text:
122125
expr: turn.text
126+
- set: latestOutbound
127+
value: null
123128
- try:
124129
actions:
125130
- call: waitForOutboundMessage
@@ -132,13 +137,31 @@ flow:
132137
- expr: resolveQaLiveTurnTimeoutMs(env, 45000)
133138
- sinceIndex:
134139
ref: beforeOutboundCount
135-
- assert:
136-
expr: "!config.forbiddenNeedles.some((needle) => normalizeLowercaseStringOrEmpty(latestOutbound.text).includes(needle))"
137-
message:
138-
expr: "`gollum natural chat turn ${String(turnIndex)} hit fallback/error text: ${latestOutbound.text}`"
139140
catchAs: turnError
140141
catch:
142+
- if:
143+
expr: "!(turnError instanceof Error) || turnError.message !== `timed out after ${resolveQaLiveTurnTimeoutMs(env, 45000)}ms`"
144+
then:
145+
- throw:
146+
expr: turnError
141147
- set: latestTurnError
142148
value:
143149
ref: turnError
144-
detailsExpr: "formatConversationTranscript(state, { conversationId: config.conversationId })"
150+
- if:
151+
expr: latestOutbound != null
152+
then:
153+
- assert:
154+
expr: "!config.forbiddenNeedles.some((needle) => normalizeLowercaseStringOrEmpty(latestOutbound.text).includes(needle))"
155+
message:
156+
expr: "`gollum natural chat turn ${String(turnIndex)} hit fallback/error text: ${latestOutbound.text}`"
157+
- set: assistantReplyCount
158+
value:
159+
expr: assistantReplyCount + 1
160+
- set: conversationTranscript
161+
value:
162+
expr: "formatConversationTranscript(state, { conversationId: config.conversationId })"
163+
- assert:
164+
expr: assistantReplyCount >= 1
165+
message:
166+
expr: "`gollum natural chat produced no assistant replies; transcript: ${conversationTranscript}`"
167+
detailsExpr: conversationTranscript

0 commit comments

Comments
 (0)