Skip to content

Commit ae54355

Browse files
authored
fix(qa): preserve profile execution contracts (#119519)
Punchcard-Session: silver-valley-valley-dt
1 parent db8e95f commit ae54355

15 files changed

Lines changed: 215 additions & 58 deletions

‎extensions/qa-lab/src/cli.runtime.test.ts‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,64 @@ describe("qa cli runtime", () => {
787787
expectWriteContains(stdoutWrite, "QA run profile: all; categories: 1; scenarios:");
788788
});
789789

790+
it.each([
791+
{
792+
label: "implicit profile membership",
793+
scenarioIds: undefined,
794+
expectedExitCode: undefined,
795+
explicitScenarioSelection: false,
796+
},
797+
{
798+
label: "explicit profile selection",
799+
scenarioIds: ["runtime-tool-image-generate"],
800+
expectedExitCode: 1,
801+
explicitScenarioSelection: true,
802+
},
803+
])(
804+
"keeps optional skips $label blocking semantics",
805+
async ({ scenarioIds, expectedExitCode, explicitScenarioSelection }) => {
806+
const priorExitCode = process.exitCode;
807+
process.exitCode = undefined;
808+
const optionalScenario = {
809+
name: "Runtime tool fixture — image_generate",
810+
status: "skip" as const,
811+
details: "image_generate mock provider report-only: tool unavailable",
812+
};
813+
await fs.writeFile(
814+
suiteSummaryPath,
815+
JSON.stringify({
816+
counts: { total: 2, passed: 1, failed: 0, skipped: 1 },
817+
scenarios: [QA_PASSING_SUITE_SCENARIO, optionalScenario],
818+
}),
819+
"utf8",
820+
);
821+
runQaSuite.mockResolvedValueOnce(
822+
flowSuiteRuntimeResult({
823+
reportPath: suiteReportPath,
824+
summaryPath: suiteSummaryPath,
825+
scenarios: [QA_PASSING_SUITE_SCENARIO, optionalScenario],
826+
}),
827+
);
828+
829+
try {
830+
await runQaProfileCommand({
831+
repoRoot: "/tmp/openclaw-repo",
832+
profile: "all",
833+
surface: "media",
834+
category: "media.media-generation",
835+
providerMode: "mock-openai",
836+
scenarioIds,
837+
});
838+
expect(process.exitCode).toBe(expectedExitCode);
839+
expect(mockFirstObjectArg(runQaSuite).adapterOptions).toMatchObject({
840+
explicitScenarioSelection,
841+
});
842+
} finally {
843+
process.exitCode = priorExitCode;
844+
}
845+
},
846+
);
847+
790848
it("filters QA-channel-pinned scenarios from an implicit Crabline smoke profile", async () => {
791849
runQaSuite.mockImplementationOnce(async () => {
792850
await fs.writeFile(suiteEvidencePath, JSON.stringify(makeQaEvidence()), "utf8");

‎extensions/qa-lab/src/cli.runtime.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ export async function runQaProfileCommand(opts: QaProfileCommandOptions) {
713713
fastMode: opts.fastMode,
714714
failFast: opts.failFast,
715715
scenarioIds: scenarios.map((scenario) => scenario.id),
716+
explicitScenarioSelection: requestedScenarioIds.length > 0,
716717
concurrency: opts.concurrency,
717718
allowFailures: opts.allowFailures,
718719
channelDriver: profileReport.channelDriver,
@@ -815,7 +816,9 @@ function resolveQaReportOnlyOptionalScenarioNames(params: {
815816
scenarioIds: readonly string[];
816817
explicitScenarioSelection?: boolean;
817818
}): ReadonlySet<string> | undefined {
818-
if (params.explicitScenarioSelection || params.scenarioIds.length > 0) {
819+
const explicitScenarioSelection =
820+
params.explicitScenarioSelection ?? params.scenarioIds.length > 0;
821+
if (explicitScenarioSelection) {
819822
return undefined;
820823
}
821824
return resolveQaReportOnlyOptionalScenarioNamesFromCatalog(readQaScenarioPack().scenarios);

‎extensions/qa-lab/src/providers/mock-openai/server.test.ts‎

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,25 @@ const QA_COMPACTION_RETRY_CODE_MODE_WRITE_RESULT = {
6464
const QA_COMPACTION_RETRY_PROMPT =
6565
"Compaction retry mutating tool check. Current durable context marker: QA-COMPACTION-DURABLE-MARKER. Create compaction-retry-summary.txt.";
6666
const QA_COMPACTION_RETRY_OVERFLOW_PADDING = "x".repeat(300_000);
67+
const QA_COMPACTION_RETRY_HISTORICAL_PHRASE = "post-marker historical user block";
6768
const QA_COMPACTION_EMPTY_RECOVERY_SUMMARY_MARKER = "QA-COMPACTION-EMPTY-RECOVERED-SUMMARY";
6869
const QA_COMPACTION_REASONING_RECOVERY_SUMMARY_MARKER = "QA-COMPACTION-REASONING-RECOVERED-SUMMARY";
70+
const QA_COMPACTION_SUMMARY_HEADINGS = [
71+
"## Decisions",
72+
"## Open TODOs",
73+
"## Constraints/Rules",
74+
"## Pending user asks",
75+
"## Exact identifiers",
76+
] as const;
6977
const QA_COMPACTION_SUMMARY_INSTRUCTIONS = `You are a context summarization assistant. Your task is to read a conversation between a user and an AI assistant, then produce a structured summary following the exact format specified.
7078
7179
Do NOT continue the conversation. Do NOT respond to any questions in the conversation. ONLY output the structured summary.`;
7280

81+
function expectCurrentCompactionSummaryHeadings(summary: string) {
82+
expect(summary.match(/^## .+$/gmu)).toEqual(QA_COMPACTION_SUMMARY_HEADINGS);
83+
expect(summary).not.toContain("## Goal");
84+
}
85+
7386
afterEach(async () => {
7487
while (cleanups.length > 0) {
7588
await cleanups.pop()?.();
@@ -2395,7 +2408,7 @@ describe("qa mock openai server", () => {
23952408

23962409
expect(response.status).toBe(200);
23972410
const summary = outputText(await response.json());
2398-
expect(summary).toContain("## Goal");
2411+
expectCurrentCompactionSummaryHeadings(summary);
23992412
expect(summary).not.toContain("QA-COMPACTION-DURABLE-MARKER");
24002413
expect(summary).not.toContain("QA-COMPACTION-BULKY-HISTORICAL-MARKER");
24012414
const requests = requireArray(
@@ -2570,9 +2583,16 @@ describe("qa mock openai server", () => {
25702583

25712584
expect(response.status).toBe(200);
25722585
const body = requireRecord(await response.json(), "Anthropic summary response");
2573-
expect(requireArray(body.content, "content")).toContainEqual(
2574-
expect.objectContaining({ type: "text", text: expect.stringContaining("## Goal") }),
2586+
const content = requireArray(body.content, "content");
2587+
expect(content).toContainEqual(
2588+
expect.objectContaining({ type: "text", text: expect.stringContaining("## Decisions") }),
25752589
);
2590+
const summaryText = requireRecord(content[0], "summary content").text;
2591+
expect(typeof summaryText).toBe("string");
2592+
if (typeof summaryText !== "string") {
2593+
throw new TypeError("Anthropic summary content text must be a string");
2594+
}
2595+
expectCurrentCompactionSummaryHeadings(summaryText);
25762596
expect(await getJson(server, "/debug/last-request")).toMatchObject({
25772597
requestKind: "compaction-summary",
25782598
outcome: "success",
@@ -2588,20 +2608,43 @@ describe("qa mock openai server", () => {
25882608
"<conversation>\n[Chunk 1 - oldest messages]\nunrelated historical context\n</conversation>\n\nAdditional focus: preserve exact identifiers.",
25892609
});
25902610
const genericChunkSummary = outputText(genericChunkPayload);
2591-
expect(genericChunkSummary).toContain("## Goal");
2611+
expectCurrentCompactionSummaryHeadings(genericChunkSummary);
25922612
expect(genericChunkSummary).not.toContain("QA-COMPACTION-DURABLE-MARKER");
25932613

25942614
const scenarioChunkPayload = await expectOpenAiNonStreamingResponsesJson(server, {
25952615
model: "gpt-5.6-luna",
25962616
instructions: QA_COMPACTION_SUMMARY_INSTRUCTIONS,
2597-
input:
2598-
"<conversation>\n[Chunk 2 - most recent messages]\nQA-COMPACTION-BULKY-HISTORICAL-MARKER\n</conversation>\n\nAdditional focus: preserve exact identifiers.",
2617+
input: `<conversation>
2618+
[Chunk 2 - most recent messages]
2619+
QA-COMPACTION-BULKY-HISTORICAL-MARKER ${QA_COMPACTION_RETRY_HISTORICAL_PHRASE} 10
2620+
</conversation>
2621+
2622+
Additional focus: preserve exact identifiers.`,
25992623
});
26002624
const scenarioChunkSummary = outputText(scenarioChunkPayload);
2601-
expect(scenarioChunkSummary).toContain("## Goal");
2625+
expectCurrentCompactionSummaryHeadings(scenarioChunkSummary);
2626+
expect(scenarioChunkSummary).toContain(QA_COMPACTION_RETRY_HISTORICAL_PHRASE);
26022627
expect(scenarioChunkSummary).not.toContain("QA-COMPACTION-DURABLE-MARKER");
26032628
expect(scenarioChunkSummary).not.toContain("QA-COMPACTION-BULKY-HISTORICAL-MARKER");
26042629

2630+
const historyMergePayload = await expectOpenAiNonStreamingResponsesJson(server, {
2631+
model: "gpt-5.6-luna",
2632+
instructions: QA_COMPACTION_SUMMARY_INSTRUCTIONS,
2633+
input: `<conversation>
2634+
[Chunk 1 - oldest messages]
2635+
${genericChunkSummary}
2636+
[Chunk 2 - most recent messages]
2637+
${scenarioChunkSummary}
2638+
</conversation>
2639+
2640+
Update and merge these partial structured summaries.`,
2641+
});
2642+
const historyMergedSummary = outputText(historyMergePayload);
2643+
expectCurrentCompactionSummaryHeadings(historyMergedSummary);
2644+
expect(historyMergedSummary).toContain(QA_COMPACTION_RETRY_HISTORICAL_PHRASE);
2645+
expect(historyMergedSummary).not.toContain("QA-COMPACTION-DURABLE-MARKER");
2646+
expect(historyMergedSummary).not.toContain("QA-COMPACTION-BULKY-HISTORICAL-MARKER");
2647+
26052648
const durableChunkPayload = await expectOpenAiNonStreamingResponsesJson(server, {
26062649
model: "gpt-5.6-luna",
26072650
instructions: QA_COMPACTION_SUMMARY_INSTRUCTIONS,
@@ -2612,6 +2655,7 @@ Retain QA-COMPACTION-DURABLE-MARKER for the active task.
26122655
Additional focus: preserve QA-COMPACTION-DURABLE-MARKER.`,
26132656
});
26142657
const durableChunkSummary = outputText(durableChunkPayload);
2658+
expectCurrentCompactionSummaryHeadings(durableChunkSummary);
26152659
expect(durableChunkSummary).toContain("QA-COMPACTION-DURABLE-MARKER");
26162660

26172661
const promptOnlyChunkPayload = await expectOpenAiNonStreamingResponsesJson(server, {
@@ -2624,6 +2668,7 @@ Compaction retry mutating tool check. Create compaction-retry-summary.txt.
26242668
Additional focus: preserve current work.`,
26252669
});
26262670
const promptOnlyChunkSummary = outputText(promptOnlyChunkPayload);
2671+
expectCurrentCompactionSummaryHeadings(promptOnlyChunkSummary);
26272672
expect(promptOnlyChunkSummary).not.toContain("QA-COMPACTION-DURABLE-MARKER");
26282673

26292674
const currentChunkPayload = await expectOpenAiNonStreamingResponsesJson(server, {
@@ -2637,6 +2682,7 @@ Create compaction-retry-summary.txt.
26372682
Additional focus: preserve current work.`,
26382683
});
26392684
const currentChunkSummary = outputText(currentChunkPayload);
2685+
expectCurrentCompactionSummaryHeadings(currentChunkSummary);
26402686
expect(currentChunkSummary).toContain("QA-COMPACTION-DURABLE-MARKER");
26412687

26422688
const mergePayload = await expectOpenAiNonStreamingResponsesJson(server, {
@@ -2657,22 +2703,25 @@ ${durableChunkSummary}
26572703
26582704
Update and merge these partial structured summaries.`,
26592705
});
2660-
expect(outputText(mergePayload)).toContain("QA-COMPACTION-DURABLE-MARKER");
2706+
const mergedSummary = outputText(mergePayload);
2707+
expectCurrentCompactionSummaryHeadings(mergedSummary);
2708+
expect(mergedSummary).toContain("QA-COMPACTION-DURABLE-MARKER");
26612709

26622710
const unrelatedPayload = await expectOpenAiNonStreamingResponsesJson(server, {
26632711
model: "gpt-5.6-luna",
26642712
instructions: QA_COMPACTION_SUMMARY_INSTRUCTIONS,
26652713
input:
26662714
"<conversation>\na later unrelated scenario\n</conversation>\n\nCreate a structured summary.",
26672715
});
2668-
expect(outputText(unrelatedPayload)).toContain("## Goal");
2669-
expect(outputText(unrelatedPayload)).not.toContain("QA-COMPACTION-DURABLE-MARKER");
2716+
const unrelatedSummary = outputText(unrelatedPayload);
2717+
expectCurrentCompactionSummaryHeadings(unrelatedSummary);
2718+
expect(unrelatedSummary).not.toContain("QA-COMPACTION-DURABLE-MARKER");
26702719

26712720
const requests = requireArray(
26722721
await getJson(server, "/debug/requests"),
26732722
"compaction requests",
26742723
).map((request) => requireRecord(request, "compaction request"));
2675-
expect(requests).toHaveLength(7);
2724+
expect(requests).toHaveLength(8);
26762725
expect(
26772726
requests.every(
26782727
(request) =>
@@ -2705,6 +2754,7 @@ Update and merge these partial structured summaries.`,
27052754
],
27062755
});
27072756
const compactedSummary = outputText(summaryPayload);
2757+
expectCurrentCompactionSummaryHeadings(compactedSummary);
27082758
expect(compactedSummary).toContain("QA-COMPACTION-DURABLE-MARKER");
27092759

27102760
const writePlan = await expectOpenAiStreamingResponsesText(server, {

‎extensions/qa-lab/src/providers/mock-openai/server.ts‎

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -186,61 +186,59 @@ const QA_COMPACTION_RETRY_OVERFLOW_THRESHOLD_BYTES = 256 * 1024;
186186
const QA_COMPACTION_OUTPUT_RECOVERY_OVERFLOW_THRESHOLD_BYTES = 96 * 1024;
187187
const QA_COMPACTION_RETRY_DURABLE_MARKER = "QA-COMPACTION-DURABLE-MARKER";
188188
const QA_COMPACTION_RETRY_BULKY_MARKER = "QA-COMPACTION-BULKY-HISTORICAL-MARKER";
189+
const QA_COMPACTION_RETRY_HISTORICAL_PHRASE = "post-marker historical user block";
189190
const QA_COMPACTION_EMPTY_OUTPUT_ONCE_MARKER_RE =
190191
/\bQA-COMPACTION-EMPTY-OUTPUT-ONCE-[A-Za-z0-9_-]+\b/u;
191192
const QA_COMPACTION_REASONING_ONLY_OUTPUT_ONCE_MARKER_RE =
192193
/\bQA-COMPACTION-REASONING-ONLY-OUTPUT-ONCE-[A-Za-z0-9_-]+\b/u;
193194
const QA_COMPACTION_EMPTY_RECOVERY_SUMMARY_MARKER = "QA-COMPACTION-EMPTY-RECOVERED-SUMMARY";
194195
const QA_COMPACTION_REASONING_RECOVERY_SUMMARY_MARKER = "QA-COMPACTION-REASONING-RECOVERED-SUMMARY";
195-
const QA_COMPACTION_RETRY_SUMMARY = `## Goal
196-
Complete the compaction retry mutating tool check.
196+
const QA_COMPACTION_RETRY_SUMMARY = `## Decisions
197+
- Continue the compaction retry from durable context without replaying a completed mutation.
197198
198-
## Constraints & Preferences
199-
- Preserve ${QA_COMPACTION_RETRY_DURABLE_MARKER}.
200-
201-
## Progress
202-
### Done
203-
- [x] Historical context compacted after overflow.
204-
205-
### In Progress
206-
- [ ] Write compaction-retry-summary.txt exactly once.
199+
## Open TODOs
200+
- Write compaction-retry-summary.txt exactly once.
201+
- Return the final replay-safety marker.
207202
208-
### Blocked
209-
- (none)
203+
## Constraints/Rules
204+
- Preserve ${QA_COMPACTION_RETRY_DURABLE_MARKER}.
205+
- Write exactly: Replay safety: unsafe after write.
210206
211-
## Key Decisions
212-
- **Retry once**: Continue from compacted context without replaying a completed mutation.
207+
## Pending user asks
208+
- Create compaction-retry-summary.txt, then reply exactly: Protocol note: replay unsafe after write.
213209
214-
## Next Steps
215-
1. Write the required file.
216-
2. Return the final replay-safety marker.
210+
## Exact identifiers
211+
- ${QA_COMPACTION_RETRY_DURABLE_MARKER}
212+
- compaction-retry-summary.txt`;
213+
const QA_COMPACTION_RETRY_HISTORICAL_SUMMARY = `## Decisions
214+
- Preserve the latest ${QA_COMPACTION_RETRY_HISTORICAL_PHRASE} context through staged compaction.
217215
218-
## Critical Context
219-
- ${QA_COMPACTION_RETRY_DURABLE_MARKER}`;
220-
const QA_GENERIC_COMPACTION_SUMMARY = `## Goal
221-
Preserve the active conversation context.
216+
## Open TODOs
217+
- Continue summarizing the ${QA_COMPACTION_RETRY_HISTORICAL_PHRASE} sequence.
222218
223-
## Constraints & Preferences
224-
- Keep current requirements and identifiers.
219+
## Constraints/Rules
220+
- Keep historical content distinct from live task state.
221+
- Do not invent durable context absent from the summarized history.
225222
226-
## Progress
227-
### Done
228-
- [x] Historical context summarized.
223+
## Pending user asks
224+
- Retain the ${QA_COMPACTION_RETRY_HISTORICAL_PHRASE} details.
229225
230-
### In Progress
231-
- [ ] Continue the active task.
226+
## Exact identifiers
227+
- None captured.`;
228+
const QA_GENERIC_COMPACTION_SUMMARY = `## Decisions
229+
- Continue from the summary without restarting completed work.
232230
233-
### Blocked
234-
- (none)
231+
## Open TODOs
232+
- Continue the active task.
235233
236-
## Key Decisions
237-
- **Continue from summary**: Do not restart completed work.
234+
## Constraints/Rules
235+
- Keep current requirements and identifiers.
238236
239-
## Next Steps
240-
1. Continue the active task from the retained context.
237+
## Pending user asks
238+
- Continue the active task from the retained context.
241239
242-
## Critical Context
243-
- Refer to the retained recent turns for current task details.`;
240+
## Exact identifiers
241+
- None captured.`;
244242
const QA_COMPACTION_OUTPUT_RECOVERY_SUMMARY = `## Decisions
245243
- Retry the typed compaction-summary fault at the compaction owner.
246244
@@ -834,7 +832,10 @@ async function buildResponsesPayload(
834832
return buildAssistantEvents(
835833
hasCompactionRetryDurableContext
836834
? QA_COMPACTION_RETRY_SUMMARY
837-
: resolveCompactionRecoverySummary(allInputText),
835+
: allInputText.includes(QA_COMPACTION_RETRY_BULKY_MARKER) ||
836+
allInputText.includes(QA_COMPACTION_RETRY_HISTORICAL_PHRASE)
837+
? QA_COMPACTION_RETRY_HISTORICAL_SUMMARY
838+
: resolveCompactionRecoverySummary(allInputText),
838839
);
839840
}
840841
if (

0 commit comments

Comments
 (0)