@@ -4,8 +4,10 @@ import path from "node:path";
44import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
55import { QaSuiteInfraError } from "./errors.js" ;
66import type { QaLabServerHandle } from "./lab-server.types.js" ;
7+ import type { QaTransportAdapter } from "./qa-transport.js" ;
8+ import { makeQaSuiteTestScenario } from "./suite-test-helpers.js" ;
79import type { QaSuiteScenarioResult } from "./suite.js" ;
8- import { throwQaSuiteCleanupErrors } from "./suite.js" ;
10+ import { qaSuiteProgressTesting , throwQaSuiteCleanupErrors } from "./suite.js" ;
911import type {
1012 QaTestFileScenario ,
1113 QaTestFileScenarioRunResult ,
@@ -14,11 +16,13 @@ import type {
1416const {
1517 crablineRuntimeLoads,
1618 prepareDockerE2eEnvironment,
19+ replaceFileAtomicMock,
1720 runQaFlowSuite,
1821 runQaTestFileScenarios,
1922} = vi . hoisted ( ( ) => ( {
2023 crablineRuntimeLoads : vi . fn ( ) ,
2124 prepareDockerE2eEnvironment : vi . fn ( ) ,
25+ replaceFileAtomicMock : vi . fn ( ) ,
2226 runQaFlowSuite : vi . fn ( ) ,
2327 runQaTestFileScenarios : vi . fn ( ) ,
2428} ) ) ;
@@ -43,6 +47,12 @@ vi.mock("./test-file-scenario-docker-batch.js", async (importOriginal) => ({
4347 prepareDockerE2eEnvironment,
4448} ) ) ;
4549
50+ vi . mock ( "openclaw/plugin-sdk/security-runtime" , async ( importOriginal ) => {
51+ const actual = await importOriginal < typeof import ( "openclaw/plugin-sdk/security-runtime" ) > ( ) ;
52+ replaceFileAtomicMock . mockImplementation ( actual . replaceFileAtomic ) ;
53+ return { ...actual , replaceFileAtomic : replaceFileAtomicMock } ;
54+ } ) ;
55+
4656import { runQaSuite , runQaSuiteWithInfraRetry } from "./suite-launch.runtime.js" ;
4757
4858const tempRoots : string [ ] = [ ] ;
@@ -120,8 +130,67 @@ function mockFlowPartitionFailures(failuresByScenarioId: ReadonlyMap<string, rea
120130 return attempts ;
121131}
122132
133+ async function expectArtifactPublicationFailurePreservesPrior ( params : {
134+ canonicalFileNames : readonly string [ ] ;
135+ failedFileName : string ;
136+ outputDir : string ;
137+ publish : ( ) => Promise < unknown > ;
138+ } ) {
139+ const sentinels = new Map (
140+ params . canonicalFileNames . map ( ( fileName ) => [ fileName , `prior ${ fileName } \n` ] ) ,
141+ ) ;
142+ await fs . mkdir ( params . outputDir , { recursive : true , mode : 0o750 } ) ;
143+ await fs . chmod ( params . outputDir , 0o750 ) ;
144+ for ( const [ fileName , sentinel ] of sentinels ) {
145+ const finalPath = path . join ( params . outputDir , fileName ) ;
146+ await fs . writeFile ( finalPath , sentinel , { encoding : "utf8" , mode : 0o640 } ) ;
147+ await fs . chmod ( finalPath , 0o640 ) ;
148+ }
149+ const actualSecurityRuntime = await vi . importActual <
150+ typeof import ( "openclaw/plugin-sdk/security-runtime" )
151+ > ( "openclaw/plugin-sdk/security-runtime" ) ;
152+ const publicationOrder : string [ ] = [ ] ;
153+ const failSelectedArtifact = async ( options : Parameters < typeof replaceFileAtomicMock > [ 0 ] ) => {
154+ publicationOrder . push ( path . basename ( options . filePath ) ) ;
155+ return await actualSecurityRuntime . replaceFileAtomic ( {
156+ ...options ,
157+ ...( path . basename ( options . filePath ) === params . failedFileName
158+ ? {
159+ beforeRename : async ( { tempPath } : { tempPath : string } ) => {
160+ await fs . writeFile ( tempPath , "partial replacement\n" , "utf8" ) ;
161+ throw Object . assign ( new Error ( "injected QA artifact publication failure" ) , {
162+ code : "EIO" ,
163+ } ) ;
164+ } ,
165+ }
166+ : { } ) ,
167+ } ) ;
168+ } ;
169+
170+ await replaceFileAtomicMock . withImplementation ( failSelectedArtifact , async ( ) => {
171+ await expect ( params . publish ( ) ) . rejects . toMatchObject ( { code : "EIO" } ) ;
172+ } ) ;
173+
174+ const selectedPath = path . join ( params . outputDir , params . failedFileName ) ;
175+ await expect ( fs . readFile ( selectedPath , "utf8" ) ) . resolves . toBe (
176+ sentinels . get ( params . failedFileName ) ,
177+ ) ;
178+ if ( process . platform !== "win32" ) {
179+ expect ( ( await fs . stat ( selectedPath ) ) . mode & 0o777 ) . toBe ( 0o640 ) ;
180+ expect ( ( await fs . stat ( params . outputDir ) ) . mode & 0o7777 ) . toBe ( 0o750 ) ;
181+ }
182+ const selectedIndex = params . canonicalFileNames . indexOf ( params . failedFileName ) ;
183+ expect ( publicationOrder ) . toEqual ( params . canonicalFileNames . slice ( 0 , selectedIndex + 1 ) ) ;
184+ expect (
185+ ( await fs . readdir ( params . outputDir ) ) . filter ( ( entry ) =>
186+ entry . startsWith ( `${ params . failedFileName } .qa-artifact.` ) ,
187+ ) ,
188+ ) . toEqual ( [ ] ) ;
189+ }
190+
123191describe ( "qa suite runtime launcher" , ( ) => {
124192 beforeEach ( ( ) => {
193+ replaceFileAtomicMock . mockClear ( ) ;
125194 runQaFlowSuite . mockReset ( ) ;
126195 runQaTestFileScenarios . mockReset ( ) ;
127196 prepareDockerE2eEnvironment . mockReset ( ) ;
@@ -1225,6 +1294,62 @@ describe("qa suite runtime launcher", () => {
12251294 ) ;
12261295 } ) ;
12271296
1297+ it . each ( [
1298+ { kind : "report" , fileName : "qa-suite-report.md" } ,
1299+ { kind : "evidence" , fileName : "qa-evidence.json" } ,
1300+ { kind : "summary" , fileName : "qa-suite-summary.json" } ,
1301+ ] ) (
1302+ "preserves the prior standard $kind artifact when atomic publication fails" ,
1303+ async ( { fileName } ) => {
1304+ const outputDir = await makeTempRepo ( "qa-suite-standard-artifact-atomic-" ) ;
1305+ await expectArtifactPublicationFailurePreservesPrior ( {
1306+ canonicalFileNames : [ "qa-suite-report.md" , "qa-evidence.json" , "qa-suite-summary.json" ] ,
1307+ failedFileName : fileName ,
1308+ outputDir,
1309+ publish : async ( ) =>
1310+ await qaSuiteProgressTesting . writeQaSuiteArtifacts ( {
1311+ outputDir,
1312+ startedAt : new Date ( "2026-08-12T00:00:00.000Z" ) ,
1313+ finishedAt : new Date ( "2026-08-12T00:01:00.000Z" ) ,
1314+ scenarios : [ { name : "Atomic publication" , status : "pass" , steps : [ ] } ] ,
1315+ scenarioDefinitions : [ makeQaSuiteTestScenario ( "channel-chat-baseline" ) ] ,
1316+ transport : {
1317+ id : "qa-channel" ,
1318+ createReportNotes : ( ) => [ ] ,
1319+ } as unknown as QaTransportAdapter ,
1320+ providerMode : "mock-openai" ,
1321+ primaryModel : "mock-openai/gpt-5.6-luna" ,
1322+ alternateModel : "mock-openai/gpt-5.6-luna-alt" ,
1323+ fastMode : true ,
1324+ concurrency : 1 ,
1325+ } ) ,
1326+ } ) ;
1327+ } ,
1328+ ) ;
1329+
1330+ it . each ( [
1331+ { kind : "evidence" , fileName : "qa-evidence.json" } ,
1332+ { kind : "report" , fileName : "qa-suite-report.md" } ,
1333+ { kind : "summary" , fileName : "qa-suite-summary.json" } ,
1334+ ] ) (
1335+ "preserves the prior unified $kind artifact when atomic publication fails" ,
1336+ async ( { fileName } ) => {
1337+ const repoRoot = await makeTempRepo ( "qa-suite-unified-artifact-atomic-" ) ;
1338+ const outputDir = path . join ( repoRoot , ".artifacts" , "qa-e2e" , "artifact-atomic" ) ;
1339+ await expectArtifactPublicationFailurePreservesPrior ( {
1340+ canonicalFileNames : [ "qa-evidence.json" , "qa-suite-report.md" , "qa-suite-summary.json" ] ,
1341+ failedFileName : fileName ,
1342+ outputDir,
1343+ publish : async ( ) =>
1344+ await runQaSuite ( {
1345+ repoRoot,
1346+ outputDir : ".artifacts/qa-e2e/artifact-atomic" ,
1347+ scenarioIds : [ "control-ui-chat-flow-playwright" ] ,
1348+ } ) ,
1349+ } ) ;
1350+ } ,
1351+ ) ;
1352+
12281353 it ( "aggregates mixed-kind progress through the parent lab" , async ( ) => {
12291354 const repoRoot = await makeTempRepo ( "qa-suite-mixed-progress-" ) ;
12301355 const scenarioRuns : Array < Parameters < QaLabServerHandle [ "setScenarioRun" ] > [ 0 ] > = [ ] ;
0 commit comments