@@ -532,6 +532,10 @@ function createArtifactVerificationHarness() {
532532 "printf '%s\\n' '<key>CFBundleShortVersionString</key><string>4.2.0</string>' '<key>CFBundleVersion</key><string>420</string>' '</dict></plist>' >>\"$app/Contents/Info.plist\"" ,
533533 "cat >\"$app/Contents/MacOS/OpenClaw\" <<'APP_HELPER'" ,
534534 "#!/bin/sh" ,
535+ 'if [ "${1:-}" = "--elevation-sync-file" ] && [ "${TEST_KILL_AFTER_PENDING_RECEIPT:-0}" = "1" ] && [ ! -e "$TEST_PENDING_KILL_MARKER" ] && echo "${2:-}" | grep -q \'elevation-host-install[.]pending[.]json$\'; then' ,
536+ ' : >"$TEST_PENDING_KILL_MARKER"' ,
537+ ' kill -KILL "$PPID"' ,
538+ "fi" ,
535539 'if [ "${1:-}" = "--elevation-rename-exclusive" ]; then' ,
536540 ' if [ "${TEST_DANGLING_ROLLBACK_DURING_MOVE:-0}" = "1" ] && echo "$3" | grep -q \'[.]rollback-elevation-host-\'; then' ,
537541 ' ln -s /missing/openclaw-rollback-target "$3"' ,
@@ -701,6 +705,7 @@ function createInstallRollbackHarness(
701705 killDuringMigrationRestoreBootstrapOnce ?: boolean ;
702706 killAfterMigrationRestoreBootstrapOnce ?: boolean ;
703707 killAfterInitialMigrationCustody ?: boolean ;
708+ killAfterPendingReceipt ?: boolean ;
704709 killAfterRollbackAppCustody ?: boolean ;
705710 migrationRestoreBootstrapFails ?: boolean ;
706711 raceMigrationCustodyDestination ?: boolean ;
@@ -1022,6 +1027,8 @@ function createInstallRollbackHarness(
10221027 TEST_KILL_AFTER_INITIAL_MIGRATION_CUSTODY : options . killAfterInitialMigrationCustody
10231028 ? "1"
10241029 : "0" ,
1030+ TEST_KILL_AFTER_PENDING_RECEIPT : options . killAfterPendingReceipt ? "1" : "0" ,
1031+ TEST_PENDING_KILL_MARKER : path . join ( tempRoot , "pending-kill-marker" ) ,
10251032 TEST_KILL_AFTER_ROLLBACK_APP_CUSTODY : options . killAfterRollbackAppCustody ? "1" : "0" ,
10261033 TEST_NODE_GENERATION_FILE : nodeGenerationFile ,
10271034 TEST_RECOVERY_KILL_MARKER : path . join ( tempRoot , "recovery-kill-marker" ) ,
@@ -1879,6 +1886,54 @@ describe("mac elevation host command contract", () => {
18791886 } ,
18801887 ) ;
18811888
1889+ it . skipIf ( process . platform !== "darwin" ) (
1890+ "recovers on the first attempt when killed immediately after publishing the prepared receipt" ,
1891+ ( ) => {
1892+ const harness = createInstallRollbackHarness ( { killAfterPendingReceipt : true } ) ;
1893+ const oldBinary = readFileSync ( path . join ( harness . appPath , "Contents" , "MacOS" , "OpenClaw" ) ) ;
1894+ const interrupted = runInstaller (
1895+ harness . installerPath ,
1896+ [
1897+ "install" ,
1898+ "--archive" ,
1899+ harness . archivePath ,
1900+ "--receipt" ,
1901+ harness . receiptPath ,
1902+ ...receiptDigestArgs ( harness . receiptPath ) ,
1903+ "--app" ,
1904+ harness . appPath ,
1905+ "--migrate-launch-agent" ,
1906+ harness . sourcePlist ,
1907+ ] ,
1908+ harness . env ,
1909+ ) ;
1910+ expect ( interrupted . signal ) . toBe ( "SIGKILL" ) ;
1911+ expect ( readFileSync ( harness . sourcePlist , "utf8" ) ) . toBe ( harness . sourceContents ) ;
1912+
1913+ const recovered = runInstaller (
1914+ harness . installerPath ,
1915+ [
1916+ "recover" ,
1917+ "--archive" ,
1918+ harness . archivePath ,
1919+ "--receipt" ,
1920+ harness . receiptPath ,
1921+ ...receiptDigestArgs ( harness . receiptPath ) ,
1922+ "--app" ,
1923+ harness . appPath ,
1924+ "--state-dir" ,
1925+ harness . stateDir ,
1926+ ] ,
1927+ harness . env ,
1928+ ) ;
1929+ expect ( recovered . status , recovered . stderr ) . toBe ( 0 ) ;
1930+ expect ( readFileSync ( path . join ( harness . appPath , "Contents" , "MacOS" , "OpenClaw" ) ) ) . toEqual (
1931+ oldBinary ,
1932+ ) ;
1933+ expect ( readFileSync ( harness . sourcePlist , "utf8" ) ) . toBe ( harness . sourceContents ) ;
1934+ } ,
1935+ ) ;
1936+
18821937 it . skipIf ( process . platform !== "darwin" ) (
18831938 "rejects a same-content migration source replacement after install process death" ,
18841939 ( ) => {
0 commit comments