@@ -5,15 +5,14 @@ import {
55 resolveControlUiDistIndexPathForRoot ,
66} from "./control-ui-assets.js" ;
77import { readPackageVersion } from "./package-json.js" ;
8- import { trimLogTail } from "./restart-sentinel.js" ;
98import { resolveStableNodePath } from "./stable-node-path.js" ;
109import { DEV_BRANCH , type UpdateChannel } from "./update-channels.js" ;
1110import {
1211 managerInstallArgs ,
1312 managerScriptArgs ,
1413 resolveUpdateBuildManager ,
1514} from "./update-package-manager.js" ;
16- import { MAX_LOG_CHARS , normalizeFallbackFailureReason , runStep } from "./update-runner-command.js" ;
15+ import { normalizeFallbackFailureReason , runStep } from "./update-runner-command.js" ;
1716import {
1817 buildUpdateDoctorEnv ,
1918 resolveUpdateDoctorExecutionPolicy ,
@@ -89,6 +88,7 @@ export async function runGitUpdate(params: {
8988 progress : opts . progress ,
9089 stepIndex : stepIndex ++ ,
9190 totalSteps,
91+ results : steps ,
9292 } ) ;
9393
9494 let allowGatewayServiceRepair = opts . allowGatewayServiceRepair !== false ;
@@ -128,44 +128,40 @@ export async function runGitUpdate(params: {
128128 } ) ;
129129 const runRequiredStep = async ( name : string , argv : string [ ] , reason : string ) => {
130130 const result = await runStep ( step ( name , argv , gitRoot ) ) ;
131- steps . push ( result ) ;
132131 return result . exitCode === 0 ? null : buildError ( reason ) ;
133132 } ;
134133 const appendRecoveryStep = async ( name : string , argv : string [ ] ) => {
135- const started = Date . now ( ) ;
136- const result = await runCommand ( argv , { cwd : gitRoot , timeoutMs } ) ;
137- steps . push ( {
134+ const result = await runStep ( {
135+ runCommand,
138136 name,
139- command : argv . join ( " " ) ,
137+ argv,
140138 cwd : gitRoot ,
141- durationMs : Date . now ( ) - started ,
142- exitCode : result . code ,
143- stdoutTail : trimLogTail ( result . stdout , MAX_LOG_CHARS ) ,
144- stderrTail : trimLogTail ( result . stderr , MAX_LOG_CHARS ) ,
139+ timeoutMs ,
140+ stepIndex : 0 ,
141+ totalSteps : 1 ,
142+ results : steps ,
145143 } ) ;
146- return result . code === 0 ;
144+ return result . exitCode === 0 ;
147145 } ;
148146 const verifyRollbackHead = async ( ) => {
149147 if ( ! beforeSha ) {
150148 return false ;
151149 }
152- const started = Date . now ( ) ;
153- const result = await runCommand ( [ "git" , "-C" , gitRoot , "rev-parse" , "HEAD" ] , {
154- cwd : gitRoot ,
155- timeoutMs,
156- } ) ;
157- const verified = result . code === 0 && result . stdout . trim ( ) === beforeSha ;
158- steps . push ( {
150+ const result = await runStep ( {
151+ runCommand,
159152 name : "git rollback verify HEAD" ,
160- command : ` git -C ${ gitRoot } rev-parse HEAD` ,
153+ argv : [ " git" , "-C" , gitRoot , " rev-parse" , " HEAD" ] ,
161154 cwd : gitRoot ,
162- durationMs : Date . now ( ) - started ,
163- exitCode : verified ? 0 : 1 ,
164- stdoutTail : trimLogTail ( result . stdout , MAX_LOG_CHARS ) ,
165- stderrTail : verified
166- ? trimLogTail ( result . stderr , MAX_LOG_CHARS )
167- : `expected ${ beforeSha } , found ${ result . stdout . trim ( ) || "unreadable HEAD" } ` ,
155+ timeoutMs,
156+ stepIndex : 0 ,
157+ totalSteps : 1 ,
158+ results : steps ,
168159 } ) ;
160+ const verified = result . exitCode === 0 && result . stdoutTail ?. trim ( ) === beforeSha ;
161+ result . exitCode = verified ? 0 : 1 ;
162+ if ( ! verified ) {
163+ result . stderrTail = `expected ${ beforeSha } , found ${ result . stdoutTail ?. trim ( ) || "unreadable HEAD" } ` ;
164+ }
169165 return verified ;
170166 } ;
171167 const rollback = async ( ) => {
@@ -274,7 +270,6 @@ export async function runGitUpdate(params: {
274270 gitRoot ,
275271 ) ,
276272 ) ;
277- steps . push ( statusCheck ) ;
278273 if ( statusCheck . stdoutTail ?. trim ( ) ) {
279274 return buildError ( "dirty" , "skipped" ) ;
280275 }
@@ -361,20 +356,16 @@ export async function runGitUpdate(params: {
361356 const rebaseStep = await runStep (
362357 step ( "git rebase" , [ "git" , "-C" , gitRoot , "rebase" , preflight . selectedSha ] , gitRoot ) ,
363358 ) ;
364- steps . push ( rebaseStep ) ;
365359 if ( rebaseStep . exitCode !== 0 ) {
366- const abort = await runCommand ( [ "git" , "-C" , gitRoot , "rebase" , "--abort" ] , {
367- cwd : gitRoot ,
368- timeoutMs,
369- } ) ;
370- steps . push ( {
360+ await runStep ( {
361+ runCommand,
371362 name : "git rebase --abort" ,
372- command : "git rebase --abort" ,
363+ argv : [ "git" , "-C" , gitRoot , " rebase" , " --abort"] ,
373364 cwd : gitRoot ,
374- durationMs : 0 ,
375- exitCode : abort . code ,
376- stdoutTail : trimLogTail ( abort . stdout , MAX_LOG_CHARS ) ,
377- stderrTail : trimLogTail ( abort . stderr , MAX_LOG_CHARS ) ,
365+ timeoutMs ,
366+ stepIndex : 0 ,
367+ totalSteps : 1 ,
368+ results : steps ,
378369 } ) ;
379370 return buildError ( "rebase-failed" ) ;
380371 }
@@ -426,14 +417,12 @@ export async function runGitUpdate(params: {
426417 installEnv ,
427418 ) ,
428419 ) ;
429- steps . push ( installStep ) ;
430420 if ( installStep . exitCode !== 0 && shouldRetryWindowsInstallIgnoringScripts ( manager . manager ) ) {
431421 const retryArgv = resolveRetryInstallArgs ( manager . manager ) ;
432422 if ( retryArgv ) {
433423 installStep = await runStep (
434424 step ( "deps install (ignore scripts)" , retryArgv , gitRoot , installEnv ) ,
435425 ) ;
436- steps . push ( installStep ) ;
437426 }
438427 }
439428 if ( installStep . exitCode !== 0 ) {
@@ -451,7 +440,6 @@ export async function runGitUpdate(params: {
451440 ) ,
452441 ) ,
453442 ) ;
454- steps . push ( buildStep ) ;
455443 if ( buildStep . exitCode !== 0 ) {
456444 return await rollbackError ( "build-failed" ) ;
457445 }
@@ -462,7 +450,6 @@ export async function runGitUpdate(params: {
462450 gitRoot ,
463451 ) ,
464452 ) ;
465- steps . push ( buildCleanCheck ) ;
466453 if ( buildCleanCheck . exitCode !== 0 ) {
467454 return await rollbackError ( "build-failed" ) ;
468455 }
@@ -479,7 +466,6 @@ export async function runGitUpdate(params: {
479466 manager . env ,
480467 ) ,
481468 ) ;
482- steps . push ( uiBuildStep ) ;
483469 if ( uiBuildStep . exitCode !== 0 ) {
484470 return await rollbackError ( "ui-build-failed" ) ;
485471 }
@@ -526,30 +512,25 @@ export async function runGitUpdate(params: {
526512 } ) ,
527513 ) ,
528514 ) ;
529- steps . push ( doctorStep ) ;
530515 if ( doctorStep . exitCode !== 0 ) {
531516 return await rollbackError ( "doctor-failed" ) ;
532517 }
533518
534519 const uiIndexHealth = await resolveControlUiDistIndexHealth ( { root : gitRoot } ) ;
535520 if ( ! uiIndexHealth . exists ) {
536521 const repairArgv = managerScriptArgs ( manager . manager , "ui:build" ) ;
537- const repairStarted = Date . now ( ) ;
538- const repairResult = await runCommand ( repairArgv , {
522+ const repairStep = await runStep ( {
523+ runCommand,
524+ name : "ui:build (post-doctor repair)" ,
525+ argv : repairArgv ,
539526 cwd : gitRoot ,
540527 timeoutMs,
541528 env : manager . env ,
529+ stepIndex : 0 ,
530+ totalSteps : 1 ,
531+ results : steps ,
542532 } ) ;
543- steps . push ( {
544- name : "ui:build (post-doctor repair)" ,
545- command : repairArgv . join ( " " ) ,
546- cwd : gitRoot ,
547- durationMs : Date . now ( ) - repairStarted ,
548- exitCode : repairResult . code ,
549- stdoutTail : trimLogTail ( repairResult . stdout , MAX_LOG_CHARS ) ,
550- stderrTail : trimLogTail ( repairResult . stderr , MAX_LOG_CHARS ) ,
551- } ) ;
552- if ( repairResult . code !== 0 ) {
533+ if ( repairStep . exitCode !== 0 ) {
553534 return await rollbackError ( "ui-build-failed" ) ;
554535 }
555536 const repairedHealth = await resolveControlUiDistIndexHealth ( { root : gitRoot } ) ;
@@ -572,7 +553,6 @@ export async function runGitUpdate(params: {
572553 const afterShaStep = await runStep (
573554 step ( "git rev-parse HEAD (after)" , [ "git" , "-C" , gitRoot , "rev-parse" , "HEAD" ] , gitRoot ) ,
574555 ) ;
575- steps . push ( afterShaStep ) ;
576556 return {
577557 status : failedStep ? "error" : "ok" ,
578558 mode : "git" ,
0 commit comments