Files
orca/config/scripts/zip-extractor-command.test.mjs
T
Neil 83cf7cf5e2 perf(ci): compile release JavaScript once for all packaging hosts (#25828)
* perf(ci): share release JavaScript across packaging hosts

* fix(ci): verify the projected web entry in release archives

* fix(ci): use the Windows system archive tool for release bundles

* test(ci): retain stylesheet evidence in release build comparisons

* test(ci): verify release parity across native color rounding

* test(ci): normalize manifest asset references without changing import order

* test(ci): compare portable outputs across Windows text and color formatting

* test(ci): preserve module identity across dependent asset hashes

* fix(ci): keep SVG build inputs identical across release hosts

* fix(ci): stabilize compiler inputs and projected web bindings

* fix(ci): retain vendor minification in projected web output

* test(ci): normalize platform-specific pnpm manifest source paths

* fix(packaging): exclude shared build staging from application files

* test: align thinking-state fixtures with the current source shape

* test(mobile): reuse message fixtures within the line limit
2026-10-06 13:22:04 -07:00

72 lines
2.8 KiB
JavaScript

import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { runProcessSync } from './script-child-process.mjs'
import { getTarProgram, getZipExtractorCommand } from './zip-extractor-command.mjs'
const directories = []
afterEach(() => {
vi.unstubAllEnvs()
vi.restoreAllMocks()
for (const directory of directories.splice(0)) {
rmSync(directory, { recursive: true, force: true })
}
})
function extract(bytes) {
const directory = mkdtempSync(join(tmpdir(), "orca archive '$ "))
directories.push(directory)
const archive = join(directory, "source '$.zip")
const destination = join(directory, "output '$")
writeFileSync(archive, bytes)
mkdirSync(destination)
const command = getZipExtractorCommand(archive, destination)
const result = runProcessSync({ program: command.file, args: command.args, timeoutMs: 120_000 })
return { result, destination }
}
describe('native archive extraction', () => {
it('pins Windows tar to the system tool even when Git Bash or an unzip override is present', () => {
vi.spyOn(process, 'platform', 'get').mockReturnValue('win32')
vi.stubEnv('SystemRoot', 'C:\\Windows')
vi.stubEnv('ORCA_UNZIP_BIN', 'custom-unzip')
expect(getTarProgram()).toBe(join('C:\\Windows', 'System32', 'tar.exe'))
vi.spyOn(process, 'platform', 'get').mockReturnValue('linux')
expect(getTarProgram()).toBe('tar')
})
it('uses the system archive reader on Windows unless an override is configured', () => {
vi.spyOn(process, 'platform', 'get').mockReturnValue('win32')
vi.stubEnv('SystemRoot', 'C:\\Windows')
vi.stubEnv('ORCA_UNZIP_BIN', '')
expect(getZipExtractorCommand('source.zip', 'output')).toEqual({
file: join('C:\\Windows', 'System32', 'tar.exe'),
args: ['-xf', 'source.zip', '-C', 'output'],
label: 'tar'
})
vi.stubEnv('ORCA_UNZIP_BIN', 'C:\\tools\\unzip.exe')
expect(getZipExtractorCommand("source '$.zip", "output '$")).toEqual({
file: 'C:\\tools\\unzip.exe',
args: ['-q', "source '$.zip", '-d', "output '$"],
label: 'unzip'
})
})
it('extracts through paths containing spaces, apostrophes and shell characters', () => {
const { result, destination } = extract(
Buffer.from(
'UEsDBBQAAAAAAI1iOF16rk6zGAAAABgAAAALAAAAcGF5bG9hZC50eHR2ZXJpZmllZCBhcmNoaXZlIHBheWxvYWRQSwECFAMUAAAAAACNYjhdeq5OsxgAAAAYAAAACwAAAAAAAAAAAAAAgAEAAAAAcGF5bG9hZC50eHRQSwUGAAAAAAEAAQA5AAAAQQAAAAAA',
'base64'
)
)
expect(result.code, result.stderr).toBe(0)
expect(readFileSync(join(destination, 'payload.txt'), 'utf8')).toBe('verified archive payload')
})
it('fails on a malformed archive', () => {
const { result } = extract('invalid archive')
expect(result.code).not.toBe(0)
})
})