test: verify CHRNX publication rollback
This commit is contained in:
2 files changed
+210
-19
No files matched your search
@@ -183,6 +183,9 @@ export async function publishReviewEvidence( {
|
||||
allowedParentDirectory,
|
||||
capturePlan,
|
||||
captureImage,
|
||||
renameEntry = rename,
|
||||
removeEntry = rm,
|
||||
reportCleanupFailure = ( message ) => process.stderr.write( `${ message }\n` ),
|
||||
} ) {
|
||||
const { outputPath, parentPath, outputExists } = await assertSafeOutput(
|
||||
outputDirectory,
|
||||
@@ -203,29 +206,42 @@ export async function publishReviewEvidence( {
|
||||
if ( await optionalLstat( backupPath ) ) {
|
||||
throw new Error( 'A previous review backup must be resolved before publication.' );
|
||||
}
|
||||
await rename( outputPath, backupPath );
|
||||
await renameEntry( outputPath, backupPath );
|
||||
backupCreated = true;
|
||||
}
|
||||
try {
|
||||
await rename( stagingPath, outputPath );
|
||||
await renameEntry( stagingPath, outputPath );
|
||||
published = true;
|
||||
} catch ( error ) {
|
||||
if ( backupCreated ) {
|
||||
await rename( backupPath, outputPath );
|
||||
await renameEntry( backupPath, outputPath );
|
||||
backupCreated = false;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
if ( backupCreated ) {
|
||||
await rm( backupPath, { recursive: true } );
|
||||
backupCreated = false;
|
||||
let cleanupError;
|
||||
for ( let attempt = 0; attempt < 2; attempt++ ) {
|
||||
try {
|
||||
await removeEntry( backupPath, { recursive: true } );
|
||||
backupCreated = false;
|
||||
break;
|
||||
} catch ( error ) {
|
||||
cleanupError = error;
|
||||
}
|
||||
}
|
||||
if ( backupCreated ) {
|
||||
const detail =
|
||||
cleanupError instanceof Error ? cleanupError.message : String( cleanupError );
|
||||
reportCleanupFailure( `Published review backup remains at ${ backupPath}: ${ detail }` );
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if ( ! published ) {
|
||||
await rm( stagingPath, { recursive: true, force: true } );
|
||||
}
|
||||
if ( backupCreated && ! await optionalLstat( outputPath ) ) {
|
||||
await rename( backupPath, outputPath );
|
||||
if ( backupCreated && ! ( await optionalLstat( outputPath ) ) ) {
|
||||
await renameEntry( backupPath, outputPath );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user