mirror of
https://github.com/stablyai/orca.git
synced 2026-11-13 17:37:40 +00:00
* refactor(tooling): organize test runtime and maintenance owners * test(tooling): preserve relocated runtime fixture dependency edges * refactor(tooling): preserve xterm routing owner checks * ci(tooling): include routing owner in sparse checkout * test(tooling): preserve copied workflow dependency closures * fix(tooling): normalize hashed JSON assets in release parity * fix(tooling): distinguish asset aliases from literal references * fix(tooling): frame normalized asset reference payloads * fix(tooling): normalize decoded JSON asset references * refactor(tooling): organize build, CI and release owners * fix(tooling): align moved generator and workflow path contracts * fix(tooling): update generated plugin bundle owner banners * test(tooling): create relocated mobile verifier fixture directories * test(tooling): copy headless detector dependency closure * test(tooling): align native batch policy fixtures with owner path * fix(tooling): link moved reliability command to historical evidence * fix(tooling): preserve nested sandbox owners and canonical guide source * fix(tooling): target release version owners in checkout fixture
75 lines
2.9 KiB
JavaScript
75 lines
2.9 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 '@orca/process-host'
|
|
import {
|
|
getTarProgram,
|
|
getZipExtractorCommand
|
|
} from '../../../../src/shared/zip-extractor-command.ts'
|
|
|
|
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)
|
|
})
|
|
})
|