Skip to content

The agent that grows with you

fix(desktop): tag every line of a multi-line waiter script error

ethernet05d5d7e5370b
diff --git a/apps/desktop/electron/updater/relaunch-waiter-lifecycle.test.ts b/apps/desktop/electron/updater/relaunch-waiter-lifecycle.test.ts
index 47ffba13a51..9cb405fa317 100644
--- a/apps/desktop/electron/updater/relaunch-waiter-lifecycle.test.ts
+++ b/apps/desktop/electron/updater/relaunch-waiter-lifecycle.test.ts
@@ -276,6 +276,21 @@ test('the script log report keeps only this attempt, reads a bounded suffix, and
assert.match(report, /Jörg fehlgeschlagen/)
assert.doesNotMatch(report, /not mine|stale line|\[hermes-relaunch-old\]/)
assert.equal(waiterLogTail(file, 'hermes-relaunch-gone'), `${file}:\nno lines from this attempt`)
+ // Every physical line of a multi-line script error carries the tag, so none is dropped.
+ fs.writeFileSync(
+ file,
+ [
+ 't [hermes-relaunch-me] pid=3 failed: Exception: run.ps1:1',
+ 't [hermes-relaunch-me] pid=3 Line |',
+ 't [hermes-relaunch-me] pid=3 | first line second line third line',
+ 't [hermes-relaunch-other] pid=4 not mine'
+ ].join('\n'),
+ 'utf8'
+ )
+ const multi: string = waiterLogTail(file, 'hermes-relaunch-me')
+ assert.match(multi, /Line \|/)
+ assert.match(multi, /third line/)
+ assert.doesNotMatch(multi, /not mine/)
assert.match(waiterLogTail(path.join(dir, 'absent.log'), 'x'), /not written/)
} finally {
fs.rmSync(dir, { recursive: true, force: true })
diff --git a/apps/desktop/electron/updater/relaunch-waiter.windows-live.test.ts b/apps/desktop/electron/updater/relaunch-waiter.windows-live.test.ts
index c152ec3366b..94a6f448d46 100644
--- a/apps/desktop/electron/updater/relaunch-waiter.windows-live.test.ts
+++ b/apps/desktop/electron/updater/relaunch-waiter.windows-live.test.ts
@@ -73,4 +73,41 @@ exit $LASTEXITCODE
},
40_000
)
+
+ it('tags every line of a multi-line script error with its attempt', () => {
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'relaunch-log-'))
+ const wrapper = path.join(root, 'run.ps1')
+
+ fs.writeFileSync(
+ wrapper,
+ `
+function Get-AppxPackage { throw "first line\`nsecond line\`nthird line" }
+& ${quote(scriptPath)} -ProcessId $PID -ProcessStartTimeMs 1 -IdentityName audit-only -ReadyFile ${quote(path.join(root, 'ready.txt'))} -TimeoutSeconds 10
+exit $LASTEXITCODE
+`,
+ 'utf8'
+ )
+
+ try {
+ const result = spawnSync(POWERSHELL_PATH, ['-NoProfile', '-NonInteractive', '-File', wrapper], {
+ cwd: root,
+ encoding: 'utf8',
+ env: { ...process.env, TEMP: root, TMP: root },
+ windowsHide: true,
+ timeout: 30_000
+ })
+
+ expect(result.status, result.stdout + result.stderr).toBe(1)
+
+ const lines = fs
+ .readFileSync(path.join(root, 'hermes-relaunch-waiter.log'), 'utf8')
+ .split('\n')
+ .filter(line => line.trim())
+
+ expect(lines.some(line => line.includes('third line'))).toBe(true)
+ expect(lines.every(line => line.includes(`[${path.basename(root)}]`))).toBe(true)
+ } finally {
+ fs.rmSync(root, { recursive: true, force: true })
+ }
+ }, 40_000)
})
diff --git a/apps/desktop/scripts/update-relaunch-waiter.ps1 b/apps/desktop/scripts/update-relaunch-waiter.ps1
index 40b206ade6c..cc15dc791a0 100644
--- a/apps/desktop/scripts/update-relaunch-waiter.ps1
+++ b/apps/desktop/scripts/update-relaunch-waiter.ps1
@@ -16,7 +16,14 @@ $Attempt = Split-Path -Leaf (Split-Path -Parent $ReadyFile)
$Utf8NoBom = New-Object System.Text.UTF8Encoding($false)
try { if ((Test-Path -LiteralPath $LogFile) -and (Get-Item -LiteralPath $LogFile).Length -gt 65536) { Remove-Item -LiteralPath $LogFile -Force } } catch {}
function Write-WaiterLog([string]$Message) {
- try { [IO.File]::AppendAllText($LogFile, ('{0} [{1}] pid={2} {3}' -f (Get-Date -Format o), $Attempt, $PID, $Message) + "`n", $Utf8NoBom) } catch {}
+ # Tag every physical line: a multi-line error (message, location, details) must survive the parent's attempt filter.
+ try {
+ $stamp = Get-Date -Format o
+ $lines = @($Message -split '\r?\n' | Where-Object { $_.Trim() })
+ if (-not $lines) { return }
+ $text = ($lines | ForEach-Object { '{0} [{1}] pid={2} {3}' -f $stamp, $Attempt, $PID, $_ }) -join "`n"
+ [IO.File]::AppendAllText($LogFile, $text + "`n", $Utf8NoBom)
+ } catch {}
}
try {