mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
116 lines
4.4 KiB
JavaScript
116 lines
4.4 KiB
JavaScript
import { spawnSync } from 'node:child_process'
|
||
import { existsSync, mkdirSync, mkdtempSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
||
import { tmpdir } from 'node:os'
|
||
import { join, resolve } from 'node:path'
|
||
import { describe, expect, it } from 'vitest'
|
||
import { resolve7zaPath } from './resolve-7za-path.mjs'
|
||
|
||
const projectRoot = resolve(import.meta.dirname, '../../../..')
|
||
|
||
describe('7za path resolution for the Windows signing gates (#6487)', () => {
|
||
// Match upstream mac/win/linux architecture dirs; darwin/ or collapsed-arch guesses silently fail to resolve.
|
||
|
||
it('resolves an executable 7za that can extract an archive', async () => {
|
||
const path7za = await resolve7zaPath(projectRoot)
|
||
expect(existsSync(path7za)).toBe(true)
|
||
|
||
const scratch = mkdtempSync(join(tmpdir(), 'orca 7za resolve '))
|
||
try {
|
||
const payloadDir = join(scratch, 'payload')
|
||
mkdirSync(payloadDir, { recursive: true })
|
||
writeFileSync(join(payloadDir, 'Orca.exe'), 'not-a-real-pe')
|
||
|
||
const archive = join(scratch, 'bundle.7z')
|
||
const created = spawnSync(path7za, ['a', archive, payloadDir], { encoding: 'utf8' })
|
||
expect(created.status).toBe(0)
|
||
|
||
const outDir = join(scratch, 'out')
|
||
const extracted = spawnSync(path7za, ['x', archive, `-o${outDir}`, '-y'], {
|
||
encoding: 'utf8'
|
||
})
|
||
expect(extracted.status).toBe(0)
|
||
expect(existsSync(join(outDir, 'payload', 'Orca.exe'))).toBe(true)
|
||
} finally {
|
||
rmSync(scratch, { recursive: true, force: true })
|
||
}
|
||
}, 120_000)
|
||
|
||
it('prefers an explicit ELECTRON_BUILDER_7ZIP_PATH override', async () => {
|
||
const scratch = mkdtempSync(join(tmpdir(), 'orca 7za override '))
|
||
const previous = process.env.ELECTRON_BUILDER_7ZIP_PATH
|
||
try {
|
||
const fake = join(scratch, 'my7za')
|
||
writeFileSync(fake, '#!/bin/sh\n')
|
||
process.env.ELECTRON_BUILDER_7ZIP_PATH = fake
|
||
await expect(resolve7zaPath(projectRoot)).resolves.toBe(fake)
|
||
} finally {
|
||
if (previous === undefined) {
|
||
delete process.env.ELECTRON_BUILDER_7ZIP_PATH
|
||
} else {
|
||
process.env.ELECTRON_BUILDER_7ZIP_PATH = previous
|
||
}
|
||
rmSync(scratch, { recursive: true, force: true })
|
||
}
|
||
})
|
||
|
||
// Use directory override: Test-Path accepts it, masking bad resolver validation until extraction fails.
|
||
it('ignores an override that points at a directory', async () => {
|
||
const scratch = mkdtempSync(join(tmpdir(), 'orca 7za dir override '))
|
||
const previous = process.env.ELECTRON_BUILDER_7ZIP_PATH
|
||
try {
|
||
process.env.ELECTRON_BUILDER_7ZIP_PATH = scratch
|
||
const resolved = await resolve7zaPath(projectRoot)
|
||
expect(resolved).not.toBe(scratch)
|
||
expect(statSync(resolved).isFile()).toBe(true)
|
||
} finally {
|
||
if (previous === undefined) {
|
||
delete process.env.ELECTRON_BUILDER_7ZIP_PATH
|
||
} else {
|
||
process.env.ELECTRON_BUILDER_7ZIP_PATH = previous
|
||
}
|
||
rmSync(scratch, { recursive: true, force: true })
|
||
}
|
||
}, 120_000)
|
||
|
||
// Overlap calls to global stdout patch; naive save/restore can permanently restore another caller’s diverting stub.
|
||
|
||
// Use fresh subprocess: app-builder-lib memoizes toolset, hiding dangling-override failures in warm process.
|
||
it('ignores an override that points at a missing file, in a cold process', () => {
|
||
const dangling = join(tmpdir(), 'orca-7za-does-not-exist')
|
||
const result = spawnSync(
|
||
process.execPath,
|
||
['config/scripts/archives/seven-zip/resolve-7za-path.mjs'],
|
||
{
|
||
cwd: projectRoot,
|
||
encoding: 'utf8',
|
||
env: { ...process.env, ELECTRON_BUILDER_7ZIP_PATH: dangling },
|
||
timeout: 120_000
|
||
}
|
||
)
|
||
|
||
expect(result.stderr ?? '').not.toContain('does not exist')
|
||
expect(result.status).toBe(0)
|
||
const resolved = result.stdout.trim()
|
||
expect(resolved).not.toBe(dangling)
|
||
expect(existsSync(resolved)).toBe(true)
|
||
}, 120_000)
|
||
|
||
it('prints exactly one clean line the PowerShell gate can consume', () => {
|
||
const result = spawnSync(
|
||
process.execPath,
|
||
['config/scripts/archives/seven-zip/resolve-7za-path.mjs'],
|
||
{
|
||
cwd: projectRoot,
|
||
encoding: 'utf8',
|
||
timeout: 120_000
|
||
}
|
||
)
|
||
|
||
expect(result.status).toBe(0)
|
||
expect(result.stdout.trimEnd().split('\n')).toHaveLength(1)
|
||
expect(existsSync(result.stdout.trim())).toBe(true)
|
||
}, 120_000)
|
||
|
||
// Unset VITEST with cold cache: builder-util suppresses download logs in tests, hiding multiline stdout that breaks PowerShell path capture.
|
||
})
|