diff --git a/src/main/managed-server/host-state/orcad-state-snapshot-shell.test.ts b/src/main/managed-server/host-state/orcad-state-snapshot-shell.test.ts index 36898d2cec4..565804db789 100644 --- a/src/main/managed-server/host-state/orcad-state-snapshot-shell.test.ts +++ b/src/main/managed-server/host-state/orcad-state-snapshot-shell.test.ts @@ -33,8 +33,12 @@ const posix = getRemoteHostPlatform('linux-x64') // Linux hosts often run dash as /bin/sh; its builtins differ from bash's (`kill -- -pgid`). const SHELL = process.env.ORCA_TEST_POSIX_SHELL ?? '/bin/sh' -async function sh(command: string): Promise { - const result = await runProcess({ program: SHELL, args: ['-c', command] }) +async function sh(command: string, env?: NodeJS.ProcessEnv): Promise { + const result = await runProcess({ + program: SHELL, + args: ['-c', command], + ...(env ? { env: { ...process.env, ...env } } : {}) + }) return result.stdout } @@ -138,6 +142,28 @@ describe.skipIf(process.platform === 'win32')('snapshot commands on a real shell expect(readFileSync(join(root, 'profiles', 'p.json'), 'utf8')).toBe('old') }) + it('fails a restore whose member cannot move in, then reruns cleanly from the archive', async () => { + await sh(captureOrcadStateSnapshotCommand(posix, root, snapshot, remoteBase)) + writeFileSync(join(root, 'profiles', 'p.json'), 'migrated') + // A `mv` that refuses only the profiles member, so the restore stops part way through. + const bin = join(base, 'bin') + mkdirSync(bin) + const mvPath = (await runProcess({ program: SHELL, args: ['-c', 'command -v mv'] })).stdout + writeFileSync( + join(bin, 'mv'), + `#!/bin/sh\ncase "$1" in *profiles) exit 1;; esac\nexec ${mvPath.trim()} "$@"\n`, + { mode: 0o755 } + ) + const restore = restoreOrcadStateSnapshotCommand(posix, root, snapshot, remoteBase) + + const failed = await sh(restore, { PATH: `${bin}:${process.env.PATH ?? ''}` }) + expect(parseOrcadSnapshotRestore(failed)).toBe('failed') + expect(existsSync(join(root, '.orcad-state-restore-stage', 'profiles'))).toBe(true) + + expect(parseOrcadSnapshotRestore(await sh(restore))).toBe('restored') + expect(readFileSync(join(root, 'profiles', 'p.json'), 'utf8')).toBe('old') + }) + it('clears only the snapshot members for a root that started empty', async () => { expect( parseOrcadSnapshotRestore( diff --git a/src/main/managed-server/host-state/orcad-state-snapshot.test.ts b/src/main/managed-server/host-state/orcad-state-snapshot.test.ts index 82396c08968..05f820d0fb5 100644 --- a/src/main/managed-server/host-state/orcad-state-snapshot.test.ts +++ b/src/main/managed-server/host-state/orcad-state-snapshot.test.ts @@ -22,6 +22,11 @@ const ROOT = '/home/u/.orca' const SNAP = '/home/u/.orca-remote/orcad-state-snapshots/pre-0.2.0+bb01-1000' const BASE = '/home/u/.orca-remote' +/** Every `for m in ;` list a command walks. */ +function memberLists(command: string): string[] { + return [...command.matchAll(/for m in ([^;]+);/g)].map((match) => match[1]) +} + /** The work inside the lock-and-deadline wrapper, with its quoting undone. */ function innerScript(command: string): string { return command.replaceAll(`'\\''`, `'`) @@ -29,20 +34,23 @@ function innerScript(command: string): string { describe('capturing the pre-activation snapshot', () => { it('captures the profile state a rollback needs', () => { - const command = captureOrcadStateSnapshotCommand(posix, ROOT, SNAP, BASE) - for (const member of ORCAD_SNAPSHOT_MEMBERS) { - expect(command).toContain(`'${member}'`) - } + expect(memberLists(captureOrcadStateSnapshotCommand(posix, ROOT, SNAP, BASE))).toEqual([ + ORCAD_SNAPSHOT_MEMBERS.join(' ') + ]) }) // The live daemon owns /daemon and outlives every restart. Restoring a stale copy of // its socket, PID record and token would break the fence that keeps its terminals adoptable. - it.each(ORCAD_SNAPSHOT_EXCLUDED)('never captures %s', (excluded) => { - expect(captureOrcadStateSnapshotCommand(posix, ROOT, SNAP, BASE)).not.toContain(`'${excluded}'`) - }) - - it.each(ORCAD_SNAPSHOT_EXCLUDED)('never removes or restores over %s', (excluded) => { - expect(restoreOrcadStateSnapshotCommand(posix, ROOT, SNAP, BASE)).not.toContain(`'${excluded}'`) + it.each(ORCAD_SNAPSHOT_EXCLUDED)('never captures, removes or restores over %s', (excluded) => { + const commands = [ + captureOrcadStateSnapshotCommand(posix, ROOT, SNAP, BASE), + restoreOrcadStateSnapshotCommand(posix, ROOT, SNAP, BASE), + clearOrcadStateSnapshotMembersCommand(posix, ROOT, BASE), + compareOrcadStateSnapshotCommand(posix, ROOT, SNAP, BASE) + ] + for (const list of commands.flatMap(memberLists)) { + expect(list.split(' ')).not.toContain(excluded) + } }) it('writes the archive under a temp name and renames, so a killed deploy leaves no torn tar', () => { @@ -77,7 +85,10 @@ describe('the host-side guard around every state mutation', () => { ['clear', () => clearOrcadStateSnapshotMembersCommand(posix, ROOT, BASE)] ])('%s runs under the host lock and a host-enforced deadline', (_label, build) => { const command = build() - expect(command).toContain(`timeout -s KILL ${ORCAD_STATE_MUTATION_DEADLINE_SECONDS} sh -c`) + expect(command).toContain( + `orca_deadline="timeout -s KILL ${ORCAD_STATE_MUTATION_DEADLINE_SECONDS}"` + ) + expect(command).toContain('orca_state_group $orca_deadline sh -c') expect(innerScript(command)).toContain(`lock='${BASE}/orcad-state-mutation.lock'`) expect(command).toContain('echo STATE_MUTATION_DEADLINE') }) @@ -86,9 +97,9 @@ describe('the host-side guard around every state mutation', () => { describe('restoring the snapshot', () => { it('proves the archive extracts before clearing the live members', () => { const command = innerScript(restoreOrcadStateSnapshotCommand(posix, ROOT, SNAP, BASE)) - const extract = command.indexOf(`tar -C '${ROOT}/.orcad-state-restore-stage'`) + const extract = command.indexOf('tar -C "$stage" -xf "$archive"') expect(extract).toBeGreaterThan(-1) - expect(extract).toBeLessThan(command.indexOf(`rm -rf '${ROOT}'/'profiles'`)) + expect(extract).toBeLessThan(command.indexOf('rm -rf "$root/$m"')) }) it('reports a missing archive instead of extracting nothing and claiming success', () => { diff --git a/src/main/managed-server/host-state/orcad-state-snapshot.ts b/src/main/managed-server/host-state/orcad-state-snapshot.ts index a4893a0330c..f7ec816e289 100644 --- a/src/main/managed-server/host-state/orcad-state-snapshot.ts +++ b/src/main/managed-server/host-state/orcad-state-snapshot.ts @@ -47,15 +47,18 @@ import { } from './orcad-state-mutation-owner-record' /** - * The member names go into the command unquoted (see `captureOrcadStateSnapshotCommand`), so - * they must be inert. They are compile-time constants; this catches the edit that adds one - * with a space or a metacharacter in it. + * The member names go into the commands' `for` lists unquoted, so they must be inert. They are + * compile-time constants; this catches the edit that adds one with a space or a metacharacter. + * Why one loop over the names rather than a test per member: every path is then sent once, which + * keeps each op under the gateway exec limit (#30491). */ -function assertPlainMemberName(member: string): string { - if (!/^[A-Za-z0-9._-]+$/.test(member)) { - throw new Error(`Unsafe orcad snapshot member name: ${JSON.stringify(member)}`) +function plainMemberWords(): string { + for (const member of ORCAD_SNAPSHOT_MEMBERS) { + if (!/^[A-Za-z0-9._-]+$/.test(member)) { + throw new Error(`Unsafe orcad snapshot member name: ${JSON.stringify(member)}`) + } } - return member + return ORCAD_SNAPSHOT_MEMBERS.join(' ') } /** The Windows host-script op, or null on POSIX; `baseDir` is `~/.orca-remote`. */ @@ -131,15 +134,13 @@ export function serializedStateMutationCommand( `elif command -v perl >/dev/null 2>&1; then ORCA_STATE_MUTATION_GROUP=1 perl -e ${quotePosixShell('setpgrp(0, 0); exec { $ARGV[0] } @ARGV or exit 127')} "$@";`, 'else "$@"; fi; };', // Why timeout inside the group: KILL then reaches tar and rm, not only the shell. - `if command -v timeout >/dev/null 2>&1; then orca_state_group timeout -s KILL ${ORCAD_STATE_MUTATION_DEADLINE_SECONDS} ${run}; else orca_state_group ${run}; fi;`, + // The deadline is a word list, so the script is sent once, not once per branch. + `orca_deadline=; command -v timeout >/dev/null 2>&1 && orca_deadline="timeout -s KILL ${ORCAD_STATE_MUTATION_DEADLINE_SECONDS}";`, + `orca_state_group $orca_deadline ${run};`, `status=$?; ${owned ? `[ "$status" -eq ${ORCAD_FENCE_LOST_EXIT} ] && exit ${ORCAD_FENCE_LOST_EXIT}; ` : ''}if [ "$status" -eq 124 ] || [ "$status" -eq 137 ]; then echo ${ORCAD_STATE_MUTATION_DEADLINE}; fi` ].join(' ') } -function noSymlinkedStateCommand(path: string): string { - return `links=$(find ${path} -type l -print) && [ -z "$links" ]` -} - export function orcadSnapshotDirName(fullVersion: string, takenAtMs: number): string { // Why the version and the timestamp: two activations of one version (a re-deploy after a // rejected activation) must not overwrite each other's snapshot. @@ -171,38 +172,26 @@ export function captureOrcadStateSnapshotCommand( if (windows) { return windows } - const root = quotePosixShell(userDataDir) - const dir = quotePosixShell(snapshotDir) - const archive = quotePosixShell(joinRemotePath(host, snapshotDir, 'state.tar')) - const memberTests = ORCAD_SNAPSHOT_MEMBERS.map( - // Why the accumulated name is NOT quoted: `$members` is re-split by the shell before it - // reaches tar, so a quoted name arrives as a literal `'profiles'` that tar cannot stat. - // `assertPlainMemberName` is what makes leaving them bare safe. - (member) => { - const path = `${root}/${quotePosixShell(member)}` - const name = assertPlainMemberName(member) - return ( - `if [ -e ${path} ] || [ -L ${path} ]; then ` + - `links=$(find ${path} -type l -print 2>&1) && [ -z "$links" ] || ` + - `snapshot_fail "${name} holds a symbolic link or an entry Orca cannot read: $links"; ` + - `members="$members ${name}"; fi;` - ) - } - ).join(' ') return serializedStateMutationCommand( baseDir, [ + `root=${quotePosixShell(userDataDir)}; dir=${quotePosixShell(snapshotDir)};`, + `archive="$dir"/state.tar;`, `snapshot_fail() { printf '${ORCAD_SNAPSHOT_FAILURE} %s\\n' "$(printf %s "$1" | tr '\\n' ' ' | cut -c 1-400)"; echo FAILED; exit 0; };`, prune ? pruneOrcadSnapshotsScript(prune.snapshotsRoot, prune.keep) : '', - `members=;`, - memberTests, + // Why `$members` is re-split bare: a quoted name would reach tar as one literal word. + `members=; for m in ${plainMemberWords()}; do`, + 'if [ -e "$root/$m" ] || [ -L "$root/$m" ]; then', + 'links=$(find "$root/$m" -type l -print 2>&1) && [ -z "$links" ] ||', + 'snapshot_fail "$m holds a symbolic link or an entry Orca cannot read: $links";', + 'members="$members $m"; fi; done;', // Umask first so the snapshot dir, not just the archive, is owner-only. 'if [ -z "$members" ]; then echo EMPTY; else umask 077;', // Why a temp name then mv: a deploy killed mid-tar must not leave a truncated archive // that a later rollback would happily restore. - `if err=$( { mkdir -p ${dir} && tar -C ${root} -cf ${archive}.partial $members &&`, - `mv ${archive}.partial ${archive}; } 2>&1 ); then echo CAPTURED; else`, - `rm -f ${archive}.partial; rmdir ${dir} 2>/dev/null; snapshot_fail "$err"; fi; fi` + 'if err=$( { mkdir -p "$dir" && tar -C "$root" -cf "$archive.partial" $members &&', + 'mv "$archive.partial" "$archive"; } 2>&1 ); then echo CAPTURED; else', + 'rm -f "$archive.partial"; rmdir "$dir" 2>/dev/null; snapshot_fail "$err"; fi; fi' ].join(' ') ) } @@ -274,31 +263,26 @@ export function restoreOrcadStateSnapshotCommand( if (windows) { return windows } - const root = quotePosixShell(userDataDir) - const archive = quotePosixShell(joinRemotePath(host, snapshotDir, 'state.tar')) - const stage = quotePosixShell( - joinRemotePath(host, userDataDir, ORCAD_STATE_RESTORE_STAGE_DIRNAME) - ) - const removals = removeMembersCommand(root) - const replacements = ORCAD_SNAPSHOT_MEMBERS.map((member) => { - const name = quotePosixShell(member) - return `if [ -e ${stage}/${name} ]; then mv ${stage}/${name} ${root}/${name}; fi` - }).join(' && ') - const stagedMemberChecks = ORCAD_SNAPSHOT_MEMBERS.map( - (member) => `[ -e ${stage}/${quotePosixShell(member)} ]` - ).join(' || ') + const members = plainMemberWords() return serializedStateMutationCommand( baseDir, [ - `test -f ${archive} || { echo MISSING; exit 0; };`, + `root=${quotePosixShell(userDataDir)};`, + `archive=${quotePosixShell(joinRemotePath(host, snapshotDir, 'state.tar'))};`, + `stage="$root"/${ORCAD_STATE_RESTORE_STAGE_DIRNAME};`, + 'test -f "$archive" || { echo MISSING; exit 0; };', 'umask 077;', - `test -d ${root} || mkdir -p ${root};`, + 'test -d "$root" || mkdir -p "$root";', // Re-extracting from the intact archive makes an interrupted restore safe to rerun. - `rm -rf ${stage}; mkdir -p ${stage} || { echo FAILED; exit 0; };`, + 'rm -rf "$stage"; mkdir -p "$stage" || { echo FAILED; exit 0; };', // Extraction proves every archived byte is readable before live state is removed. - `tar -C ${stage} -xf ${archive} 2>/dev/null || { rm -rf ${stage}; echo FAILED; exit 0; };`, - `${stagedMemberChecks} || { rm -rf ${stage}; echo FAILED; exit 0; };`, - `if ${removals} && ${replacements}; then rm -rf ${stage}; echo RESTORED; else echo FAILED; fi` + 'tar -C "$stage" -xf "$archive" 2>/dev/null || { rm -rf "$stage"; echo FAILED; exit 0; };', + `ok=; for m in ${members}; do [ -e "$stage/$m" ] && ok=1; done;`, + '[ -n "$ok" ] || { rm -rf "$stage"; echo FAILED; exit 0; };', + removeMembersCommand(members), + `[ -n "$ok" ] && for m in ${members}; do`, + '[ ! -e "$stage/$m" ] || mv "$stage/$m" "$root/$m" || { ok=; break; }; done;', + 'if [ -n "$ok" ]; then rm -rf "$stage"; echo RESTORED; else echo FAILED; fi' ].join(' ') ) } @@ -313,17 +297,19 @@ export function clearOrcadStateSnapshotMembersCommand( if (windows) { return windows } - const root = quotePosixShell(userDataDir) return serializedStateMutationCommand( baseDir, - `test -d ${root} || mkdir -p ${root}; if ${removeMembersCommand(root)}; then echo RESTORED; else echo FAILED; fi` + [ + `root=${quotePosixShell(userDataDir)}; test -d "$root" || mkdir -p "$root"; ok=1;`, + removeMembersCommand(plainMemberWords()), + 'if [ -n "$ok" ]; then echo RESTORED; else echo FAILED; fi' + ].join(' ') ) } -function removeMembersCommand(root: string): string { - return ORCAD_SNAPSHOT_MEMBERS.map((member) => `rm -rf ${root}/${quotePosixShell(member)}`).join( - ' && ' - ) +/** Clears `ok` and stops at the first member it cannot remove, as an `&&` chain did. */ +function removeMembersCommand(members: string): string { + return `[ -n "$ok" ] && for m in ${members}; do rm -rf "$root/$m" || { ok=; break; }; done;` } export type OrcadSnapshotRestore = 'restored' | 'missing' | 'failed' @@ -347,27 +333,21 @@ export function compareOrcadStateSnapshotCommand( if (windows) { return windows } - const root = quotePosixShell(userDataDir) - const dir = quotePosixShell(snapshotDir) - const archive = quotePosixShell(joinRemotePath(host, snapshotDir, 'state.tar')) - const comparisons = ORCAD_SNAPSHOT_MEMBERS.map((member) => { - const name = quotePosixShell(member) - return [ - `if [ -e ${root}/${name} ] || [ -L ${root}/${name} ]; then`, - `${noSymlinkedStateCommand(`${root}/${name}`)} || { echo UNKNOWN; exit 0; };`, - `diff -r ${root}/${name} "$comparison"/${name} >/dev/null 2>&1 || verdict=CHANGED;`, - `elif [ -e "$comparison"/${name} ] || [ -L "$comparison"/${name} ]; then verdict=CHANGED; fi;` - ].join(' ') - }).join(' ') + const unknown = '{ echo UNKNOWN; exit 0; };' return [ - `test -d ${root} && test -r ${root} && test -x ${root} || { echo UNKNOWN; exit 0; };`, - `test -f ${archive} || { echo UNKNOWN; exit 0; };`, - `comparison=$(mktemp -d ${dir}/compare.XXXXXX) || { echo UNKNOWN; exit 0; };`, + `root=${quotePosixShell(userDataDir)}; dir=${quotePosixShell(snapshotDir)};`, + `archive="$dir"/state.tar;`, + `test -d "$root" && test -r "$root" && test -x "$root" || ${unknown}`, + `test -f "$archive" || ${unknown}`, + `comparison=$(mktemp -d "$dir"/compare.XXXXXX) || ${unknown}`, `trap 'rm -rf "$comparison"' EXIT HUP INT TERM;`, - `tar -C "$comparison" -xf ${archive} || { echo UNKNOWN; exit 0; };`, - `${noSymlinkedStateCommand('"$comparison"')} || { echo UNKNOWN; exit 0; };`, - 'verdict=UNCHANGED;', - comparisons, + `tar -C "$comparison" -xf "$archive" || ${unknown}`, + `links=$(find "$comparison" -type l -print) && [ -z "$links" ] || ${unknown}`, + `verdict=UNCHANGED; for m in ${plainMemberWords()}; do`, + 'if [ -e "$root/$m" ] || [ -L "$root/$m" ]; then', + `links=$(find "$root/$m" -type l -print) && [ -z "$links" ] || ${unknown}`, + 'diff -r "$root/$m" "$comparison/$m" >/dev/null 2>&1 || verdict=CHANGED;', + 'elif [ -e "$comparison/$m" ] || [ -L "$comparison/$m" ]; then verdict=CHANGED; fi; done;', 'echo "$verdict"' ].join(' ') } diff --git a/src/main/managed-server/install/orcad-remote-runtime.ts b/src/main/managed-server/install/orcad-remote-runtime.ts index 85fb82db72f..2f771ecc601 100644 --- a/src/main/managed-server/install/orcad-remote-runtime.ts +++ b/src/main/managed-server/install/orcad-remote-runtime.ts @@ -10,18 +10,19 @@ import { } from '../../../shared/orcad-artifacts' import { assertPosixOrcadHost } from './orcad-remote-host-support' import { quotePosixShell } from '../../../shared/shell-argument-quoting' -import { - joinRemotePath, - remoteDirname, - type RemoteHostPlatform -} from '../../ssh/ssh-remote-platform' +import { joinRemotePath, type RemoteHostPlatform } from '../../ssh/ssh-remote-platform' + +/** `orcad_slot=;`, so the selections below name the long slot path once on the wire. */ +function assignOrcadSlot(directory: string): string { + return `orcad_slot=${quotePosixShell(directory.replace(/\/+$/, ''))}; ` +} /** New slots start the server directly; rollback still accepts older single-entry slots. */ export function selectOrcadSlotEntryCommand(host: RemoteHostPlatform, directory: string): string { assertPosixOrcadHost(host) - const server = quotePosixShell(joinRemotePath(host, directory, ORCAD_SERVER_ENTRY_FILENAME)) - const launcher = quotePosixShell(joinRemotePath(host, directory, ORCAD_LAUNCHER_FILENAME)) - return `if [ -f ${server} ]; then orcad_entry=${server}; else orcad_entry=${launcher}; fi` + const server = `"$orcad_slot"/${quotePosixShell(ORCAD_SERVER_ENTRY_FILENAME)}` + const launcher = `"$orcad_slot"/${quotePosixShell(ORCAD_LAUNCHER_FILENAME)}` + return `${assignOrcadSlot(directory)}if [ -f ${server} ]; then orcad_entry=${server}; else orcad_entry=${launcher}; fi` } /** @@ -30,20 +31,13 @@ export function selectOrcadSlotEntryCommand(host: RemoteHostPlatform, directory: */ export function orcadNodeSlotRuntimeCommand(host: RemoteHostPlatform, directory: string): string { assertPosixOrcadHost(host) - const nodeMarker = quotePosixShell( - joinRemotePath(host, directory, ORCAD_NODE_RUNTIME_MARKER_FILENAME) - ) - const nodeRuntimePrefix = quotePosixShell( - joinRemotePath( - host, - remoteDirname(directory.replace(/\/+$/, ''), host), - ORCAD_RUNTIMES_DIRNAME, - ORCAD_NODE_RUNTIME_DIR_PREFIX - ) - ) + const nodeMarker = `"$orcad_slot"/${quotePosixShell(ORCAD_NODE_RUNTIME_MARKER_FILENAME)}` + const nodeRuntimePrefix = `"\${orcad_slot%/*}"/${quotePosixShell( + `${ORCAD_RUNTIMES_DIRNAME}/${ORCAD_NODE_RUNTIME_DIR_PREFIX}` + )}` const nodeExecutable = quotePosixShell(`/${ORCAD_NODE_RUNTIME_POSIX_EXECUTABLE}`) return ( - `orcad_node_sha=$(cat ${nodeMarker}) || exit 78; ` + + `${assignOrcadSlot(directory)}orcad_node_sha=$(cat ${nodeMarker}) || exit 78; ` + // Why validate: the digest becomes a path segment, so only a bare sha256 may reach it. // The leading `(` keeps the pattern parseable when stop embeds this in `$(...)`. 'case "$orcad_node_sha" in ("" | *[!0-9a-f]*) exit 78;; esac; ' + diff --git a/src/main/managed-server/posix-host-op-byte-budget.test.ts b/src/main/managed-server/posix-host-op-byte-budget.test.ts index d7a8d3a549f..efd3950dc38 100644 --- a/src/main/managed-server/posix-host-op-byte-budget.test.ts +++ b/src/main/managed-server/posix-host-op-byte-budget.test.ts @@ -94,18 +94,11 @@ import { orcadPosixStdioBridgeCommand } from './lifecycle/orcad-stdio-bridge-scr // fence-guarded command, wrapped uncompressed as a host without gzip/base64 receives it. const POSIX_HOST_OP_BYTE_BUDGET = 6 * 1024 -// Ops already past the budget, at their measured size. Ceilings may only shrink. The snapshot -// capture/restore/clear ops leave when they move onto the Node host script (R4-10b, decision D-J); -// install-lock steal and anything else that runs before a verified Node must shrink in shell. +// Ops already past the budget, at their measured size. Ceilings may only shrink. const OVER_BUDGET_CEILINGS: Readonly> = { - // #30618 added old-snapshot pruning and failure cleanup to the capture; R4-10b moves it to Node. - captureOrcadStateSnapshotCommand: 17_407, - restoreOrcadStateSnapshotCommand: 20_805, - clearOrcadStateSnapshotMembersCommand: 9_175, tryStealInstallLockCommand: 9_022, - serializedStateMutationCommand: 6_529, - orcadLaunchCommand: 8_181, - 'orcadLaunchCommand (WSL setsid)': 6_498, + orcadLaunchCommand: 8_122, + 'orcadLaunchCommand (WSL setsid)': 6_439, probeRemoteInstallCompleteCommand: 12_189 } @@ -159,8 +152,12 @@ function promoteArgs({ const BUILDERS: Readonly string>> = { serializedStateMutationCommand: () => serializedStateMutationCommand(baseDir, ':', 20, fence), + // As activation runs it: pruning every other capture but the recorded one. captureOrcadStateSnapshotCommand: ({ host }) => - captureOrcadStateSnapshotCommand(host, userDataDir, snapshotDir, baseDir), + captureOrcadStateSnapshotCommand(host, userDataDir, snapshotDir, baseDir, { + snapshotsRoot: `${baseDir}/orcad-snapshots`, + keep: [snapshotDir.slice(snapshotDir.lastIndexOf('/') + 1), 'pre-1.4.298-rc.3-1750000000000'] + }), probeOrcadStateSnapshotCommand: ({ host }) => probeOrcadStateSnapshotCommand(host, snapshotDir, baseDir), restoreOrcadStateSnapshotCommand: ({ host }) => diff --git a/src/main/ssh/ssh-exec-command-decoder-fallback.test.ts b/src/main/ssh/ssh-exec-command-decoder-fallback.test.ts index 791012befa9..e700b8cea7d 100644 --- a/src/main/ssh/ssh-exec-command-decoder-fallback.test.ts +++ b/src/main/ssh/ssh-exec-command-decoder-fallback.test.ts @@ -87,7 +87,7 @@ describe.skipIf(process.platform === 'win32')( expect(conn.exec).toHaveBeenCalledTimes(1) }) - it('captures a snapshot through a gateway that truncates the plain command and merges stderr', async () => { + it('captures a snapshot whole through a gateway that cuts exec requests at 6 KiB and merges stderr', async () => { const base = mkdtempSync(join(tmpdir(), 'orcad-gateway-capture-')) try { const root = join(base, '.orca') @@ -100,20 +100,11 @@ describe.skipIf(process.platform === 'win32')( snapshot, join(base, '.orca-remote') ) - // The command embeds the temp path ~40 times, so its size varies by OS; pick a cut the - // plain form always exceeds and the compressed form always fits. - const plainBytes = Buffer.byteLength( - wrapRemoteCommandForPosixShell(command, { compress: false }) - ) - const compressedBytes = Buffer.byteLength( - wrapRemoteCommandForPosixShell(command, { compress: true }) - ) - const gatewayLimitBytes = Math.min( - 10 * 1024, - Math.floor((plainBytes + compressedBytes) / 2) - ) - expect(plainBytes).toBeGreaterThan(gatewayLimitBytes) - expect(compressedBytes).toBeLessThan(gatewayLimitBytes) + // Under the byte budget, so even uncompressed nothing is cut. + const gatewayLimitBytes = 6 * 1024 + expect( + Buffer.byteLength(wrapRemoteCommandForPosixShell(command, { compress: false })) + ).toBeLessThan(gatewayLimitBytes) const output = await execCommand(host({ gatewayLimitBytes }), command)