mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 03:15:01 +00:00
test: remove low-value build and packaging test inventories (#38593)
* test: remove low-value build and packaging test inventories * ci: retire removed dependency resolution suite invocation --------- Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
@@ -1528,11 +1528,10 @@ jobs:
|
||||
pnpm rebuild bun
|
||||
fi
|
||||
|
||||
- name: Typecheck and check undeclared dependency resolution
|
||||
- name: Typecheck under isolated dependency resolution
|
||||
run: |
|
||||
set -euo pipefail
|
||||
pnpm tc
|
||||
pnpm exec vitest run --config config/vitest.config.ts config/scripts/dependency-security/runtime-resolution/undeclared-dependency-resolution.test.ts
|
||||
# Pointless if any pnpm command above fell back to the hoisted layout or another store.
|
||||
case "$(realpath node_modules/zod)" in
|
||||
"$(realpath "$pnpm_config_store_dir")"/*) ;;
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,95 +1,7 @@
|
||||
import { join, resolve } from 'node:path'
|
||||
import { runProcessSync } from '@orca/process-host'
|
||||
import { DEFAULT_MAX_OUTPUT_BYTES } from '@orca/process-host/process-spec'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { auditToolEntry, runAuditTool } from './run-audit-tool.mjs'
|
||||
|
||||
const root = resolve(import.meta.dirname, '../../../..')
|
||||
const success = { code: 0, signal: null, timedOut: false }
|
||||
import { runAuditTool } from './run-audit-tool.mjs'
|
||||
|
||||
describe('locked audit tool execution', () => {
|
||||
it('installs frozen without scripts before forwarding tool arguments directly to Node', () => {
|
||||
const calls = []
|
||||
const args = ['.', '--scope', 'lines', '--base', 'branch with & shell $characters']
|
||||
const failed = { code: 7, signal: null, timedOut: false }
|
||||
const result = runAuditTool('react-doctor', args, {
|
||||
root,
|
||||
run: (spec) => {
|
||||
calls.push(spec)
|
||||
return calls.length === 1 ? success : failed
|
||||
}
|
||||
})
|
||||
expect(calls).toHaveLength(2)
|
||||
expect(calls[0].args.slice(-5)).toEqual([
|
||||
'--dir',
|
||||
join(root, 'config', 'audit-tools'),
|
||||
'install',
|
||||
'--frozen-lockfile',
|
||||
'--ignore-scripts'
|
||||
])
|
||||
expect(calls[1]).toEqual({
|
||||
program: process.execPath,
|
||||
args: [auditToolEntry('react-doctor', root), ...args],
|
||||
cwd: root,
|
||||
stdio: 'inherit',
|
||||
maxOutputBytes: 64 * 1024 * 1024,
|
||||
timeoutMs: null
|
||||
})
|
||||
expect(result).toBe(failed)
|
||||
})
|
||||
|
||||
it('captures structured tool output without hiding the installation log', () => {
|
||||
const calls = []
|
||||
const output = { ...success, stdout: '{"ok":true}' }
|
||||
expect(
|
||||
runAuditTool('react-doctor', ['.', '--json'], {
|
||||
stdio: 'pipe',
|
||||
run: (spec) => {
|
||||
calls.push(spec)
|
||||
return calls.length === 1 ? success : output
|
||||
}
|
||||
})
|
||||
).toBe(output)
|
||||
expect(calls[0].stdio).toBe('inherit')
|
||||
expect(calls[1].stdio).toBe('pipe')
|
||||
})
|
||||
|
||||
it('captures reports larger than the default subprocess output limit', () => {
|
||||
const reportSize = DEFAULT_MAX_OUTPUT_BYTES + 1024
|
||||
const result = runAuditTool('react-doctor', ['.', '--json'], {
|
||||
stdio: 'pipe',
|
||||
run: (spec) =>
|
||||
spec.stdio === 'inherit'
|
||||
? success
|
||||
: runProcessSync({
|
||||
...spec,
|
||||
args: ['-e', `process.stdout.write('x'.repeat(${reportSize}))`]
|
||||
})
|
||||
})
|
||||
|
||||
expect(result.code).toBe(0)
|
||||
expect(result.outputTruncated).toBe(false)
|
||||
expect(result.stdout).toHaveLength(reportSize)
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ code: 1, signal: null, timedOut: false },
|
||||
{ code: null, signal: 'SIGTERM', timedOut: false },
|
||||
{ code: null, signal: null, timedOut: true }
|
||||
])('does not execute a tool after install failure: %j', (failure) => {
|
||||
let count = 0
|
||||
expect(
|
||||
runAuditTool('knip', [], {
|
||||
run: () => {
|
||||
count += 1
|
||||
return failure
|
||||
}
|
||||
})
|
||||
).toBe(failure)
|
||||
expect(count).toBe(1)
|
||||
})
|
||||
|
||||
it('rejects an unknown executable before installing anything', () => {
|
||||
const run = vi.fn()
|
||||
expect(() => runAuditTool('../arbitrary-package', [], { run })).toThrow('Unknown audit tool')
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
import { mkdtemp, rm } from 'node:fs/promises'
|
||||
import { createRequire } from 'node:module'
|
||||
import { join, resolve } from 'node:path'
|
||||
import { build } from 'vite'
|
||||
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
||||
import { electronViteConfig } from '../../../../electron.vite.config'
|
||||
import { runProcess } from '@orca/process-host'
|
||||
|
||||
const projectDir = resolve(import.meta.dirname, '../../../..')
|
||||
const require = createRequire(import.meta.url)
|
||||
let outputDir
|
||||
|
||||
const smokeScript = `
|
||||
const assert = require('node:assert/strict')
|
||||
const { createRequire } = require('node:module')
|
||||
const loaderPath = process.argv[1]
|
||||
const requireFromLoader = createRequire(loaderPath)
|
||||
const sdkEntry = requireFromLoader.resolve('@linear/sdk')
|
||||
const { loadLinearSdk } = require(loaderPath)
|
||||
assert.equal(require.cache[sdkEntry], undefined, 'SDK must remain lazy')
|
||||
|
||||
const sdk = loadLinearSdk()
|
||||
assert.equal(sdk, requireFromLoader('@linear/sdk'))
|
||||
assert.equal(loadLinearSdk(), sdk, 'repeat loads must reuse the SDK')
|
||||
const client = new sdk.LinearClient({ apiKey: 'orca-offline-smoke-test' })
|
||||
assert.equal(typeof client.issues, 'function')
|
||||
assert.equal(typeof client.teams, 'function')
|
||||
assert.ok(sdk.AuthenticationLinearError.prototype instanceof Error)
|
||||
console.log('Linear SDK loaded')
|
||||
`
|
||||
|
||||
beforeAll(async () => {
|
||||
// Keep normal dependency resolution while executing outside Vitest's module loader.
|
||||
outputDir = await mkdtemp(join(projectDir, 'node_modules', 'orca-linear-sdk-runtime-'))
|
||||
const mainBuild = electronViteConfig.main.build
|
||||
await build({
|
||||
configFile: false,
|
||||
publicDir: false,
|
||||
logLevel: 'silent',
|
||||
build: {
|
||||
ssr: true,
|
||||
minify: mainBuild.minify,
|
||||
outDir: outputDir,
|
||||
rollupOptions: {
|
||||
external: mainBuild.rollupOptions.external,
|
||||
input: join(projectDir, 'src/main/linear/linear-sdk.ts'),
|
||||
output: { format: 'cjs', entryFileNames: 'linear-sdk.cjs' }
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
if (outputDir) {
|
||||
await rm(outputDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 })
|
||||
}
|
||||
})
|
||||
|
||||
describe('resolved Linear SDK through the production CommonJS loader', () => {
|
||||
it.each([
|
||||
{ name: 'Node', program: process.execPath },
|
||||
{ name: 'Electron', program: require('electron') }
|
||||
])(
|
||||
'loads and constructs the real SDK under $name without network access',
|
||||
async ({ program }) => {
|
||||
const result = await runProcess({
|
||||
program,
|
||||
args: ['-e', smokeScript, join(outputDir, 'linear-sdk.cjs')],
|
||||
cwd: projectDir,
|
||||
env: { ...process.env, ORCA_BACKGROUND_LAUNCH: '1', ELECTRON_RUN_AS_NODE: '1' },
|
||||
timeoutMs: 20000
|
||||
})
|
||||
expect(result.code, result.stderr).toBe(0)
|
||||
expect(result.timedOut).toBe(false)
|
||||
expect(result.stdout.trim()).toBe('Linear SDK loaded')
|
||||
}
|
||||
)
|
||||
})
|
||||
-80
@@ -1,80 +0,0 @@
|
||||
import { existsSync, readFileSync, realpathSync } from 'node:fs'
|
||||
import { createRequire } from 'node:module'
|
||||
import { join } from 'node:path'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { parse } from 'yaml'
|
||||
import { z } from 'zod'
|
||||
import { markdownParserAliases } from '../../../build-plugins/markdown-parser-exports'
|
||||
|
||||
const repoRoot = join(import.meta.dirname, '../../../..')
|
||||
const repoNodeModules = join(repoRoot, 'node_modules')
|
||||
|
||||
const dependencyMap = z.record(z.string(), z.string()).optional()
|
||||
const workspace = z
|
||||
.object({
|
||||
packageExtensions: z
|
||||
.record(
|
||||
z.string(),
|
||||
z.object({ dependencies: dependencyMap, peerDependencies: dependencyMap })
|
||||
)
|
||||
.optional(),
|
||||
addMissingPeerTypes: z.boolean().optional()
|
||||
})
|
||||
.parse(parse(readFileSync(join(repoRoot, 'pnpm-workspace.yaml'), 'utf8')))
|
||||
|
||||
// Every dependency pnpm-workspace.yaml adds, so a new entry is covered without editing this file.
|
||||
const extensionPairs = Object.entries(workspace.packageExtensions ?? {}).flatMap(
|
||||
([owner, extension]) =>
|
||||
[
|
||||
...Object.keys(extension.dependencies ?? {}),
|
||||
...Object.keys(extension.peerDependencies ?? {})
|
||||
].map((dependency) => [owner, dependency] as const)
|
||||
)
|
||||
|
||||
// These peer on react and ship .d.ts that import it; addMissingPeerTypes supplies @types/react.
|
||||
const peerTypePairs = [
|
||||
'@dnd-kit/core',
|
||||
'@dnd-kit/sortable',
|
||||
'@dnd-kit/utilities',
|
||||
'@monaco-editor/react',
|
||||
'cmdk',
|
||||
'emoji-picker-react',
|
||||
'lucide-react',
|
||||
'react-colorful',
|
||||
'react-i18next',
|
||||
'sonner'
|
||||
].map((owner) => [owner, '@types/react'] as const)
|
||||
|
||||
// Node's own lookup from the package's real location, without tripping over "exports" maps.
|
||||
function isVisibleFrom(owner: string, dependency: string): boolean {
|
||||
const ownerDir = realpathSync(join(repoNodeModules, owner))
|
||||
const lookupDirs = createRequire(join(ownerDir, 'package.json')).resolve.paths(dependency) ?? []
|
||||
return lookupDirs.some((dir) => existsSync(join(dir, dependency, 'package.json')))
|
||||
}
|
||||
|
||||
describe('undeclared dependency resolution', () => {
|
||||
it('covers every packageExtensions entry', () => {
|
||||
const owners = new Set(extensionPairs.map(([owner]) => owner))
|
||||
expect([...owners].sort()).toEqual(Object.keys(workspace.packageExtensions ?? {}).sort())
|
||||
expect(workspace.addMissingPeerTypes).toBe(true)
|
||||
})
|
||||
|
||||
// Why: the global virtual store links only declared deps; pnpm-workspace.yaml supplies these.
|
||||
it.each([...extensionPairs, ...peerTypePairs])(
|
||||
'%s sees %s from its own install location',
|
||||
(owner, dependency) => {
|
||||
expect(isVisibleFrom(owner, dependency)).toBe(true)
|
||||
}
|
||||
)
|
||||
|
||||
it('decodes named references through the DOM-free parser alias', async () => {
|
||||
const decoder = await import(
|
||||
pathToFileURL(markdownParserAliases['decode-named-character-reference']).href
|
||||
)
|
||||
expect(typeof decoder.decodeNamedCharacterReference).toBe('function')
|
||||
expect(decoder.decodeNamedCharacterReference('amp')).toBe('&')
|
||||
expect(decoder.decodeNamedCharacterReference('NotEqualTilde')).toBe('≂̸')
|
||||
expect(decoder.decodeNamedCharacterReference('not-an-entity')).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -4,13 +4,9 @@ import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
|
||||
const {
|
||||
assertNoDarkOutputOfOffSwitches,
|
||||
assertNotDarkBuild,
|
||||
darkBuildDefines,
|
||||
darkBuildMarkers,
|
||||
turnedOnDarkBuildDefines
|
||||
} = createRequire(import.meta.url)('../../../dark-build-switches.cjs')
|
||||
const { assertNoDarkOutputOfOffSwitches, assertNotDarkBuild, darkBuildMarkers } = createRequire(
|
||||
import.meta.url
|
||||
)('../../../dark-build-switches.cjs')
|
||||
|
||||
const scratch = []
|
||||
afterEach(async () => {
|
||||
@@ -18,27 +14,6 @@ afterEach(async () => {
|
||||
})
|
||||
|
||||
describe('dark build switches', () => {
|
||||
it.each(['ORCA_LAYOUT_OWNER', 'ORCA_SIDEBAR_INPUTS'])(
|
||||
'compiles the dark path in only when %s=main asks',
|
||||
(variable) => {
|
||||
expect(darkBuildDefines({ [variable]: 'main' })[variable]).toBe('"main"')
|
||||
expect(darkBuildDefines({ [variable]: 'window' })[variable]).toBe('"window"')
|
||||
expect(darkBuildDefines({})[variable]).toBe('"window"')
|
||||
expect(turnedOnDarkBuildDefines({ [variable]: 'main' })).toEqual({ [variable]: '"main"' })
|
||||
expect(turnedOnDarkBuildDefines({})).toEqual({})
|
||||
}
|
||||
)
|
||||
|
||||
it('keeps the layout-owner marker name packaging already refuses', () => {
|
||||
expect(darkBuildMarkers({ ORCA_LAYOUT_OWNER: 'main' })).toEqual([
|
||||
{
|
||||
fileName: 'ORCA_LAYOUT_OWNER_MAIN',
|
||||
text: 'Built with ORCA_LAYOUT_OWNER=main, for dark testing only.\n'
|
||||
}
|
||||
])
|
||||
expect(darkBuildMarkers({})).toEqual([])
|
||||
})
|
||||
|
||||
it.each(['ORCA_LAYOUT_OWNER', 'ORCA_SIDEBAR_INPUTS'])(
|
||||
'refuses %s at packaging time, and any output its dark build marked',
|
||||
async (variable) => {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { verifyPreloadSource, verifyPreloadOutput } from './preload-output-contract.mjs'
|
||||
import { preloadRuntimeImports } from './sandbox-preload-imports.mjs'
|
||||
import * as nodeFs from 'node:fs'
|
||||
import { mkdtempSync, readFileSync, rmSync } from 'node:fs'
|
||||
import * as nodePath from 'node:path'
|
||||
@@ -8,17 +6,11 @@ import { tmpdir } from 'node:os'
|
||||
import { EventEmitter } from 'node:events'
|
||||
import { runInNewContext } from 'node:vm'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { PreloadConfigFactory } from 'electron-vite'
|
||||
import { build, resolveConfig } from 'vite'
|
||||
import { electronViteConfig } from '../../../../electron.vite.config'
|
||||
import {
|
||||
BOOTSTRAP_FATAL_LOG_ENV_VAR,
|
||||
BOOTSTRAP_FATAL_LOG_FILE_NAME,
|
||||
createBootstrapFatalExitBanner
|
||||
} from '../../../build-plugins/bootstrap-fatal-exit-banner'
|
||||
import { BOOTSTRAP_FATAL_EXIT_GUARD_KEY } from '../../../../src/main/startup/bootstrap-fatal-exit-guard'
|
||||
import { createSandboxedScriptBundlesPlugin } from '../../../build-plugins/sandboxed-script-bundles'
|
||||
import { MAIN_BUILD_ENTRY_POINTS } from '../../../build-plugins/main-build-entry-points'
|
||||
|
||||
type BootstrapProcessMock = EventEmitter & {
|
||||
env: Record<string, string>
|
||||
@@ -71,141 +63,6 @@ function failBootstrapWithBanner(options: {
|
||||
}
|
||||
|
||||
describe('Electron Vite output contract', () => {
|
||||
it('builds browser and document guest preloads without sandbox-inaccessible chunks', async () => {
|
||||
const fixtureId = '\0sandbox-bundle-fixture'
|
||||
const result = await build({
|
||||
configFile: false,
|
||||
logLevel: 'silent',
|
||||
plugins: [
|
||||
createSandboxedScriptBundlesPlugin(),
|
||||
{
|
||||
name: 'sandbox-bundle-fixture',
|
||||
resolveId: (id) => (id === fixtureId ? fixtureId : null),
|
||||
load: (id) => (id === fixtureId ? 'export default 0' : null)
|
||||
}
|
||||
],
|
||||
build: { write: false, rollupOptions: { input: fixtureId } }
|
||||
})
|
||||
const emitted = new Map<string, string>()
|
||||
for (const bundle of Array.isArray(result) ? result : [result]) {
|
||||
if ('output' in bundle) {
|
||||
for (const asset of bundle.output) {
|
||||
if (asset.type === 'asset' && typeof asset.source === 'string') {
|
||||
emitted.set(asset.fileName, asset.source)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const name of ['browser-guest-preload', 'doc-preview-link-preload']) {
|
||||
expect(MAIN_BUILD_ENTRY_POINTS).not.toHaveProperty(name)
|
||||
const source = emitted.get(`${name}.js`)
|
||||
if (!source) {
|
||||
throw new Error(`Missing guest preload ${name}`)
|
||||
}
|
||||
expect(await preloadRuntimeImports(source)).toEqual(['electron'])
|
||||
}
|
||||
})
|
||||
|
||||
it('bundles ordinary preload dependencies while retaining sandbox builtins', async () => {
|
||||
expect(electronViteConfig.preload?.build?.externalizeDeps).toBe(false)
|
||||
const preload = await new PreloadConfigFactory(electronViteConfig.preload ?? {}, {}, {}).build()
|
||||
const resolved = await resolveConfig({ ...preload, configFile: false }, 'build')
|
||||
const patterns = resolved.build.rolldownOptions.external
|
||||
if (!Array.isArray(patterns)) {
|
||||
throw new Error('Expected preload externals')
|
||||
}
|
||||
const external = (source: string) =>
|
||||
patterns.some((pattern) =>
|
||||
typeof pattern === 'string' ? pattern === source : pattern.test(source)
|
||||
)
|
||||
expect(external('electron')).toBe(true)
|
||||
expect(external('node:fs')).toBe(true)
|
||||
for (const name of ['smol-toml', 'smol-toml/package.json', 'zod']) {
|
||||
expect(external(name)).toBe(false)
|
||||
}
|
||||
})
|
||||
|
||||
it('rejects unsupported lazy, dynamic, indirect and chunked sandbox output', async () => {
|
||||
for (const source of [
|
||||
'require("smol-toml")',
|
||||
'require("./chunks/native-chat-visual-guest-theme.js")',
|
||||
'function later(){ return require("node:fs") }',
|
||||
'require(name)',
|
||||
'const load = require; load("smol-toml")',
|
||||
'import("smol-toml")',
|
||||
'module.require("smol-toml")',
|
||||
'const load = process.getBuiltinModule; load("fs")'
|
||||
]) {
|
||||
await expect(verifyPreloadSource(source)).rejects.toThrow()
|
||||
}
|
||||
await expect(verifyPreloadSource('require("electron")')).rejects.toThrow('executable')
|
||||
const root = mkdtempSync(join(tmpdir(), 'orca-preload-contract-'))
|
||||
try {
|
||||
nodeFs.mkdirSync(join(root, 'out', 'preload'), { recursive: true })
|
||||
nodeFs.writeFileSync(join(root, 'out', 'preload', 'index.js'), '')
|
||||
nodeFs.writeFileSync(join(root, 'out', 'preload', 'lazy.js'), '')
|
||||
await expect(verifyPreloadOutput(root)).rejects.toThrow('one complete artifact')
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
it('executes multibyte encoding and the restricted bridge with checked IPC results', async () => {
|
||||
const source = `const {contextBridge, ipcRenderer} = require('electron');
|
||||
const text = 'A🌊é中';
|
||||
const encoded = new TextEncoder().encode(text);
|
||||
if (Array.from(encoded).join(',') !== '65,240,159,140,138,195,169,228,184,173') {
|
||||
throw new Error('Incorrect multibyte UTF-8 encoding');
|
||||
}
|
||||
if (new TextDecoder('utf-8', {fatal: true}).decode(encoded) !== text) {
|
||||
throw new Error('Incorrect multibyte UTF-8 decoding');
|
||||
}
|
||||
contextBridge.exposeInMainWorld('api', {
|
||||
app: {getIdentity: () => ipcRenderer.invoke('app:getIdentity')},
|
||||
orcaProfiles: {list: () => ipcRenderer.invoke('orcaProfiles:list')}
|
||||
});`
|
||||
await expect(verifyPreloadSource(source)).resolves.toEqual({ imports: ['electron'] })
|
||||
await expect(verifyPreloadSource(source.replace('app:getIdentity', 'wrong'))).rejects.toThrow(
|
||||
'bridge result'
|
||||
)
|
||||
})
|
||||
|
||||
it('exits when a static import fails before source error guards load', () => {
|
||||
const processMock = new EventEmitter() as EventEmitter & {
|
||||
exit: (code: number) => void
|
||||
exitCode?: number
|
||||
stderr: { write: (chunk: string) => boolean }
|
||||
}
|
||||
let scheduledExit: (() => void) | null = null
|
||||
let exitedWith: number | null = null
|
||||
const stderrWrites: string[] = []
|
||||
processMock.exit = (code) => {
|
||||
exitedWith = code
|
||||
}
|
||||
processMock.stderr = {
|
||||
write: (chunk) => {
|
||||
stderrWrites.push(chunk)
|
||||
return true
|
||||
}
|
||||
}
|
||||
const context = {
|
||||
process: processMock,
|
||||
setImmediate: (callback: () => void) => {
|
||||
scheduledExit = callback
|
||||
}
|
||||
}
|
||||
|
||||
runInNewContext(createBootstrapFatalExitBanner(), context)
|
||||
processMock.emit('uncaughtException', new Error("Cannot find module 'zod'"))
|
||||
|
||||
expect(processMock.exitCode).toBe(1)
|
||||
expect(scheduledExit).not.toBeNull()
|
||||
scheduledExit?.()
|
||||
expect(exitedWith).toBe(1)
|
||||
expect(context).toHaveProperty(BOOTSTRAP_FATAL_EXIT_GUARD_KEY)
|
||||
expect(stderrWrites.join('')).toContain("Cannot find module 'zod'")
|
||||
})
|
||||
|
||||
it('records the bootstrap failure it exits on, since the guard hides Electron dialog', () => {
|
||||
const logDirectory = mkdtempSync(join(tmpdir(), 'orca-bootstrap-fatal-'))
|
||||
const logPath = join(logDirectory, 'fatal.log')
|
||||
|
||||
@@ -2,12 +2,8 @@ import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import type { Plugin, Rollup } from 'vite'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
CLI_MAIN_ENTRY_NAMES,
|
||||
createPlainNodeEntryGuardPlugin,
|
||||
GUARDED_ENTRY_NAMES
|
||||
} from '../../../build-plugins/plain-node-entry-guard'
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { createPlainNodeEntryGuardPlugin } from '../../../build-plugins/plain-node-entry-guard'
|
||||
|
||||
let outputDir: string | undefined
|
||||
|
||||
@@ -123,48 +119,6 @@ describe('plain Node entry guard', () => {
|
||||
})
|
||||
|
||||
// daemon-entry traps SIGTERM; smoke timeout must escalate to SIGKILL or spawnSync can wait forever.
|
||||
it('kills a daemon that traps SIGTERM and never exits', async () => {
|
||||
const dir = createOutputDir()
|
||||
const plugin = createPlainNodeEntryGuardPlugin({ timeoutMs: 250, killGraceMs: 250 })
|
||||
|
||||
runWriteBundle(plugin, dir)
|
||||
writeFileSync(
|
||||
join(dir, 'daemon-entry.js'),
|
||||
"process.on('SIGTERM', () => {}); setInterval(() => {}, 1000)\n"
|
||||
)
|
||||
|
||||
await expect(runCloseBundle(plugin)).rejects.toThrow('did not exit within 250ms')
|
||||
}, 10_000)
|
||||
})
|
||||
|
||||
// Fail if entry is renamed: writeBundle otherwise skips missing input and silently drops its guard.
|
||||
describe('guarded entry names', () => {
|
||||
function runBuildStart(plugin: Plugin, input: unknown): void {
|
||||
const hook = plugin.buildStart
|
||||
if (typeof hook !== 'function') {
|
||||
throw new Error('Expected buildStart hook')
|
||||
}
|
||||
hook.call({} as never, { input } as Rollup.NormalizedInputOptions)
|
||||
}
|
||||
|
||||
it('rejects a guarded name that is no longer a rollup input', () => {
|
||||
const plugin = createPlainNodeEntryGuardPlugin()
|
||||
const input = Object.fromEntries(
|
||||
GUARDED_ENTRY_NAMES.filter((name) => name !== 'stt-worker').map((name) => [
|
||||
name,
|
||||
`${name}.ts`
|
||||
])
|
||||
)
|
||||
|
||||
expect(() => runBuildStart(plugin, input)).toThrow('"stt-worker"')
|
||||
})
|
||||
|
||||
it('passes when every guarded name is a rollup input', () => {
|
||||
const plugin = createPlainNodeEntryGuardPlugin()
|
||||
const input = Object.fromEntries(GUARDED_ENTRY_NAMES.map((name) => [name, `${name}.ts`]))
|
||||
|
||||
expect(() => runBuildStart(plugin, input)).not.toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
// Electron is unavailable in main-process workers too (#11161); transitive imports can kill startup despite entry-local electron-free comments.
|
||||
@@ -199,114 +153,6 @@ describe('CLI and worker thread entry guard', () => {
|
||||
} as Rollup.OutputChunk
|
||||
}
|
||||
|
||||
function countElectronRequireScans(run: () => void): number {
|
||||
const pattern = /require\(\s*["'`]electron(?:\/[^"'`]+)?["'`]\s*\)/
|
||||
const originalTest = RegExp.prototype.test
|
||||
let scans = 0
|
||||
const spy = vi.spyOn(RegExp.prototype, 'test').mockImplementation(function (
|
||||
this: RegExp,
|
||||
value: string
|
||||
) {
|
||||
if (this.source === pattern.source) {
|
||||
scans += 1
|
||||
}
|
||||
return originalTest.call(this, value)
|
||||
})
|
||||
try {
|
||||
run()
|
||||
} finally {
|
||||
spy.mockRestore()
|
||||
}
|
||||
return scans
|
||||
}
|
||||
|
||||
it('scans shared code once across every guarded entry', () => {
|
||||
const shared = entryChunk('shared', 'require("node:fs")')
|
||||
shared.isEntry = false
|
||||
const bundle: Rollup.OutputBundle = { [shared.fileName]: shared }
|
||||
for (const name of GUARDED_ENTRY_NAMES) {
|
||||
const entry = entryChunk(name, `require("./shared.js"); // ${name}`, [shared.fileName])
|
||||
bundle[entry.fileName] = entry
|
||||
}
|
||||
const snapshot = structuredClone(bundle)
|
||||
|
||||
const scans = countElectronRequireScans(() => {
|
||||
runEntryWriteBundle(createPlainNodeEntryGuardPlugin(), bundle)
|
||||
})
|
||||
|
||||
expect(bundle).toEqual(snapshot)
|
||||
expect(scans).toBe(GUARDED_ENTRY_NAMES.length + 1)
|
||||
})
|
||||
|
||||
it('does not retain a successful scan across output bundles', () => {
|
||||
const plugin = createPlainNodeEntryGuardPlugin()
|
||||
const entry = entryChunk('stt-worker', 'require("node:fs")')
|
||||
const bundle: Rollup.OutputBundle = { [entry.fileName]: entry }
|
||||
const scans = countElectronRequireScans(() => {
|
||||
runEntryWriteBundle(plugin, bundle)
|
||||
runEntryWriteBundle(plugin, bundle)
|
||||
})
|
||||
expect(scans).toBe(2)
|
||||
|
||||
entry.code = 'require("electron/main")'
|
||||
expect(() => runEntryWriteBundle(plugin, bundle)).toThrow(
|
||||
'[plain-node-entry-guard] "stt-worker" reaches chunk "stt-worker.js" that requires electron. '
|
||||
)
|
||||
})
|
||||
|
||||
it('still reads changed code on the same chunk within one bundle scan', () => {
|
||||
const first = entryChunk('stt-worker', 'require("node:fs")')
|
||||
const second = entryChunk('warp-theme-parser-worker', 'require("node:fs")')
|
||||
const shared = entryChunk('shared', '')
|
||||
shared.isEntry = false
|
||||
let reads = 0
|
||||
Object.defineProperty(shared, 'code', {
|
||||
get: () => (++reads === 1 ? 'require("node:fs")' : 'require("electron")')
|
||||
})
|
||||
first.imports = [shared.fileName]
|
||||
second.dynamicImports = [shared.fileName]
|
||||
const bundle: Rollup.OutputBundle = {
|
||||
[first.fileName]: first,
|
||||
[second.fileName]: second,
|
||||
[shared.fileName]: shared
|
||||
}
|
||||
|
||||
expect(() => runEntryWriteBundle(createPlainNodeEntryGuardPlugin(), bundle)).toThrow(
|
||||
'[plain-node-entry-guard] "warp-theme-parser-worker" reaches chunk "shared.js"'
|
||||
)
|
||||
expect(reads).toBe(2)
|
||||
})
|
||||
|
||||
it('keeps watch mode free of entry scanning', () => {
|
||||
const entry = entryChunk('stt-worker', 'require("electron")')
|
||||
const bundle: Rollup.OutputBundle = { [entry.fileName]: entry }
|
||||
const scans = countElectronRequireScans(() => {
|
||||
runEntryWriteBundle(createPlainNodeEntryGuardPlugin(), bundle, true)
|
||||
})
|
||||
expect(scans).toBe(0)
|
||||
})
|
||||
|
||||
it.each(CLI_MAIN_ENTRY_NAMES)('rejects direct and transitive Electron imports in %s', (name) => {
|
||||
const plugin = createPlainNodeEntryGuardPlugin()
|
||||
const entry = entryChunk(name, 'require("electron")')
|
||||
const bundle: Rollup.OutputBundle = { [entry.fileName]: entry }
|
||||
expect(() => runEntryWriteBundle(plugin, bundle)).toThrow('requires electron')
|
||||
|
||||
entry.code = ''
|
||||
const shared = entryChunk('shared', 'require("electron/main")')
|
||||
shared.isEntry = false
|
||||
bundle[shared.fileName] = shared
|
||||
for (const edge of ['imports', 'dynamicImports'] as const) {
|
||||
entry[edge] = [shared.fileName]
|
||||
expect(() => runEntryWriteBundle(plugin, bundle)).toThrow('requires electron')
|
||||
entry[edge] = []
|
||||
}
|
||||
|
||||
shared.code = 'require("node:fs")'
|
||||
entry.imports = [shared.fileName]
|
||||
expect(() => runEntryWriteBundle(plugin, bundle)).not.toThrow()
|
||||
})
|
||||
|
||||
it('rejects an Electron require reachable from a worker entry', () => {
|
||||
const plugin = createPlainNodeEntryGuardPlugin()
|
||||
const bundle: Rollup.OutputBundle = {
|
||||
@@ -319,15 +165,6 @@ describe('CLI and worker thread entry guard', () => {
|
||||
expect(() => runEntryWriteBundle(plugin, bundle)).toThrow('requires electron')
|
||||
})
|
||||
|
||||
it('names the worker-thread runtime so the failure is actionable', () => {
|
||||
const plugin = createPlainNodeEntryGuardPlugin()
|
||||
const bundle: Rollup.OutputBundle = {
|
||||
'stt-worker.js': entryChunk('stt-worker', 'require("electron")')
|
||||
}
|
||||
|
||||
expect(() => runEntryWriteBundle(plugin, bundle)).toThrow('runs as a worker thread')
|
||||
})
|
||||
|
||||
// Exercise transitive shared-chunk imports into the electron client, where direct-import checks miss startup failures.
|
||||
it('follows shared chunks out of a worker entry', () => {
|
||||
const plugin = createPlainNodeEntryGuardPlugin()
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { resolveSucraseUnusedTransformer } from '../../../build-plugins/sucrase-unused-transformers'
|
||||
|
||||
const ROOT_TRANSFORMER =
|
||||
'/Users/me/pnpm/store/v11/links/@/sucrase/3.35.1/abc/node_modules/sucrase/dist/esm/transformers/RootTransformer.js'
|
||||
const CJS_ROOT_TRANSFORMER = ROOT_TRANSFORMER.replace('/esm', '')
|
||||
|
||||
describe('sucrase unused transformers stub', () => {
|
||||
it('stubs only the flow and react-hot-loader transformers sucrase itself imports', () => {
|
||||
expect(resolveSucraseUnusedTransformer('./FlowTransformer', ROOT_TRANSFORMER)).not.toBeNull()
|
||||
expect(
|
||||
resolveSucraseUnusedTransformer('./ReactHotLoaderTransformer.js', CJS_ROOT_TRANSFORMER)
|
||||
).not.toBeNull()
|
||||
expect(
|
||||
resolveSucraseUnusedTransformer(
|
||||
'./ReactHotLoaderTransformer',
|
||||
'C:\\x\\node_modules\\sucrase\\dist\\transformers\\RootTransformer.js'
|
||||
)
|
||||
).not.toBeNull()
|
||||
expect(resolveSucraseUnusedTransformer('./JSXTransformer', ROOT_TRANSFORMER)).toBeNull()
|
||||
expect(
|
||||
resolveSucraseUnusedTransformer('./FlowTransformer', '/repo/src/main/flow.ts')
|
||||
).toBeNull()
|
||||
})
|
||||
})
|
||||
-79
@@ -23,56 +23,6 @@ async function runScript(script, { cwd = directory, env = {} } = {}) {
|
||||
}
|
||||
|
||||
describe('Windows dev-channel artifact staging', () => {
|
||||
it('keeps existing callers publishing by default', () => {
|
||||
expect(build.on.workflow_call.inputs.stage_only).toMatchObject({
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
required: false
|
||||
})
|
||||
expect(build.on.workflow_dispatch.inputs.stage_only).toBeUndefined()
|
||||
const normalPackage = buildSteps.find((step) => step.name === 'Publish Windows artifacts')
|
||||
expect(normalPackage.with.command).toContain('--publish always')
|
||||
expect(normalPackage.if).toBe('${{ !inputs.stage_only }}')
|
||||
})
|
||||
|
||||
it('never mints or consumes release-write credentials while staging', () => {
|
||||
for (const step of buildSteps) {
|
||||
const credentialed = JSON.stringify(step).includes('secrets.') || step.env?.GH_TOKEN
|
||||
if (credentialed) {
|
||||
expect(step.if, step.name).toBe('${{ !inputs.stage_only }}')
|
||||
}
|
||||
}
|
||||
const stagePackage = buildSteps.find(
|
||||
(step) => step.name === 'Package Windows artifacts without publishing'
|
||||
)
|
||||
expect(stagePackage.if).toBe('inputs.stage_only')
|
||||
expect(stagePackage.with.command).toContain('--publish never')
|
||||
expect(stagePackage.env.GH_TOKEN).toBeUndefined()
|
||||
for (const workflow of [build, publish]) {
|
||||
const contents = JSON.stringify(workflow.jobs)
|
||||
expect(contents).not.toMatch(/SignPath|SIGNPATH|signpath/)
|
||||
}
|
||||
})
|
||||
|
||||
it('passes exactly the installer, blockmap, and update manifest within the same run', () => {
|
||||
const upload = buildSteps.find((step) => step.uses?.startsWith('actions/upload-artifact@'))
|
||||
const download = publishSteps.find((step) =>
|
||||
step.uses?.startsWith('actions/download-artifact@')
|
||||
)
|
||||
expect(upload.if).toBe('inputs.stage_only')
|
||||
expect(upload.with.path.trim().split('\n')).toEqual([
|
||||
'dist/orca-windows-setup.exe',
|
||||
'dist/orca-windows-setup.exe.blockmap',
|
||||
'dist/latest.yml'
|
||||
])
|
||||
expect(upload.with['if-no-files-found']).toBe('error')
|
||||
expect(download.with).toEqual({
|
||||
name: upload.with.name,
|
||||
path: 'staged-windows'
|
||||
})
|
||||
expect(build.concurrency.group).not.toBe(publish.concurrency.group)
|
||||
})
|
||||
|
||||
it.each([
|
||||
['build', buildSteps, 'dist'],
|
||||
['publish', publishSteps, 'staged-windows']
|
||||
@@ -107,33 +57,4 @@ describe('Windows dev-channel artifact staging', () => {
|
||||
expect((await runScript(step.run, { env: { CHANNEL: channel, TAG: tag } })).code).toBe(code)
|
||||
}
|
||||
})
|
||||
|
||||
it('requires a live existing release and never creates one', async () => {
|
||||
const guard = publishSteps.find((step) => step.name === 'Confirm the target release is live')
|
||||
for (const [response, code] of [
|
||||
['false', 0],
|
||||
['true', 1],
|
||||
['', 1]
|
||||
]) {
|
||||
const stub = 'gh() { printf "%s" "$STUB_RESPONSE"; }; export -f gh;\n'
|
||||
expect(
|
||||
(
|
||||
await runScript(`${stub}${guard.run}`, {
|
||||
env: { STUB_RESPONSE: response, CHANNEL: 'adhoc', TAG: 'v1.4.232-adhoc.1' }
|
||||
})
|
||||
).code
|
||||
).toBe(code)
|
||||
}
|
||||
expect(
|
||||
(
|
||||
await runScript(`gh() { return 1; };\n${guard.run}`, {
|
||||
env: { CHANNEL: 'adhoc', TAG: 'v1.4.232-adhoc.1' }
|
||||
})
|
||||
).code
|
||||
).toBe(1)
|
||||
const upload = publishSteps.find((step) => step.name === 'Publish Windows artifacts')
|
||||
expect(upload.with.command).toContain('gh release upload')
|
||||
expect(JSON.stringify(publish)).not.toContain('gh release create')
|
||||
expect(publishSteps.indexOf(guard)).toBeLessThan(publishSteps.indexOf(upload))
|
||||
})
|
||||
})
|
||||
|
||||
-174
@@ -1,174 +0,0 @@
|
||||
import { createRequire } from 'node:module'
|
||||
import { resolve } from 'node:path'
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { collectDevChannelPackagingProblems } from './verify-dev-channel-packaging.mjs'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const CONFIG_PATH = resolve(import.meta.dirname, '../../../electron-builder.config.cjs')
|
||||
|
||||
/** The config reads process.env at require time, so each identity needs a fresh load. */
|
||||
function loadConfigWithEnv(env) {
|
||||
const saved = { ...process.env }
|
||||
for (const key of Object.keys(process.env)) {
|
||||
if (key.startsWith('ORCA_')) {
|
||||
delete process.env[key]
|
||||
}
|
||||
}
|
||||
Object.assign(process.env, env)
|
||||
try {
|
||||
delete require.cache[require.resolve(CONFIG_PATH)]
|
||||
return require(CONFIG_PATH)
|
||||
} finally {
|
||||
process.env = saved
|
||||
delete require.cache[require.resolve(CONFIG_PATH)]
|
||||
}
|
||||
}
|
||||
|
||||
const WIN_ADHOC_ENV = {
|
||||
ORCA_WIN_ADHOC: '1',
|
||||
ORCA_ADHOC_BUILD_VERSION: '1.4.178-adhoc.20260819010203'
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
delete require.cache[require.resolve(CONFIG_PATH)]
|
||||
})
|
||||
|
||||
describe('electron-builder dev-channel identity', () => {
|
||||
it('keeps the SignPath publisherName on stable Windows builds', () => {
|
||||
const config = loadConfigWithEnv({})
|
||||
|
||||
expect(config.win.signtoolOptions.publisherName).toBe('SignPath Foundation')
|
||||
expect(config.win.verifyUpdateCodeSignature).toBeUndefined()
|
||||
expect(config.publish.repo).toBe('orca')
|
||||
expect(config.publish.releaseType).toBe('draft')
|
||||
})
|
||||
|
||||
// The whole point of the change: an unsigned build that advertised a
|
||||
// publisherName would Authenticode-verify — and reject — every installer it
|
||||
// ever downloaded, including its own way back to stable.
|
||||
it('drops the publisherName and disables update signature checks on Windows dev builds', () => {
|
||||
const config = loadConfigWithEnv(WIN_ADHOC_ENV)
|
||||
|
||||
expect(config.win.signtoolOptions?.publisherName).toBeUndefined()
|
||||
expect(config.win.verifyUpdateCodeSignature).toBe(false)
|
||||
})
|
||||
|
||||
it.each([
|
||||
['hourly', { ORCA_WIN_HOURLY: '1' }, 'orca-hourly'],
|
||||
['daily', { ORCA_WIN_DAILY: '1' }, 'orca-daily'],
|
||||
['adhoc', { ORCA_WIN_ADHOC: '1' }, 'orca-adhoc']
|
||||
])('publishes %s Windows builds to its own repo as a prerelease', (_channel, env, repo) => {
|
||||
const config = loadConfigWithEnv(env)
|
||||
|
||||
expect(config.publish.repo).toBe(repo)
|
||||
expect(config.publish.releaseType).toBe('prerelease')
|
||||
})
|
||||
|
||||
// Why: ORCA_MAC_* gates hardened runtime, notarization, and root-level
|
||||
// forceCodeSigning. If the Windows variables leaked into that, the Windows job
|
||||
// would fail packaging for want of a cert it deliberately does not use.
|
||||
it('leaves mac release signing off for Windows dev builds', () => {
|
||||
const config = loadConfigWithEnv(WIN_ADHOC_ENV)
|
||||
|
||||
expect(config.forceCodeSigning).toBe(false)
|
||||
expect(config.mac.notarize).toBe(false)
|
||||
expect(config.mac.hardenedRuntime).toBe(false)
|
||||
})
|
||||
|
||||
it('still notarizes mac dev builds', () => {
|
||||
const config = loadConfigWithEnv({
|
||||
ORCA_MAC_ADHOC: '1',
|
||||
ORCA_ADHOC_BUILD_VERSION: '1.4.178-adhoc.20260819010203'
|
||||
})
|
||||
|
||||
expect(config.mac.notarize).toBe(true)
|
||||
expect(config.publish.repo).toBe('orca-adhoc')
|
||||
})
|
||||
})
|
||||
|
||||
describe('collectDevChannelPackagingProblems', () => {
|
||||
const goodWinConfig = {
|
||||
publish: { repo: 'orca-adhoc', releaseType: 'prerelease' },
|
||||
extraMetadata: { version: '1.4.178-adhoc.20260819010203' },
|
||||
win: { verifyUpdateCodeSignature: false }
|
||||
}
|
||||
const env = { ORCA_ADHOC_BUILD_VERSION: '1.4.178-adhoc.20260819010203' }
|
||||
|
||||
it('accepts a correctly configured Windows dev build', () => {
|
||||
expect(
|
||||
collectDevChannelPackagingProblems({
|
||||
channel: 'adhoc',
|
||||
platform: 'win32',
|
||||
config: goodWinConfig,
|
||||
env
|
||||
})
|
||||
).toEqual([])
|
||||
})
|
||||
|
||||
// The failure this script exists for: a branch predating Windows dev builds
|
||||
// resolves publish.repo to the main repo.
|
||||
it('rejects a config that resolved the main repo', () => {
|
||||
const problems = collectDevChannelPackagingProblems({
|
||||
channel: 'adhoc',
|
||||
platform: 'win32',
|
||||
config: { ...goodWinConfig, publish: { repo: 'orca', releaseType: 'release' } },
|
||||
env
|
||||
})
|
||||
|
||||
expect(problems.join('\n')).toContain('must publish to "orca-adhoc"')
|
||||
expect(problems.join('\n')).toContain('rebase it onto a main that does')
|
||||
})
|
||||
|
||||
it('rejects a Windows dev build that still advertises a publisherName', () => {
|
||||
const problems = collectDevChannelPackagingProblems({
|
||||
channel: 'adhoc',
|
||||
platform: 'win32',
|
||||
config: {
|
||||
...goodWinConfig,
|
||||
win: { signtoolOptions: { publisherName: 'SignPath Foundation' } }
|
||||
},
|
||||
env
|
||||
})
|
||||
|
||||
expect(problems.join('\n')).toContain('verifyUpdateCodeSignature must be false')
|
||||
expect(problems.join('\n')).toContain('publisherName is set to "SignPath Foundation"')
|
||||
})
|
||||
|
||||
it('rejects a build packaging a version other than the tag the workflow created', () => {
|
||||
const problems = collectDevChannelPackagingProblems({
|
||||
channel: 'adhoc',
|
||||
platform: 'win32',
|
||||
config: { ...goodWinConfig, extraMetadata: { version: '1.4.178' } },
|
||||
env
|
||||
})
|
||||
|
||||
expect(problems.join('\n')).toContain('but the workflow computed')
|
||||
})
|
||||
|
||||
// macOS builds are signed, so the Windows-only assertions must not fire there.
|
||||
it('does not apply Windows signature rules to a mac dev build', () => {
|
||||
expect(
|
||||
collectDevChannelPackagingProblems({
|
||||
channel: 'adhoc',
|
||||
platform: 'darwin',
|
||||
config: {
|
||||
publish: { repo: 'orca-adhoc', releaseType: 'prerelease' },
|
||||
extraMetadata: { version: '1.4.178-adhoc.20260819010203' },
|
||||
win: { signtoolOptions: { publisherName: 'SignPath Foundation' } }
|
||||
},
|
||||
env
|
||||
})
|
||||
).toEqual([])
|
||||
})
|
||||
|
||||
it('rejects an unknown channel', () => {
|
||||
expect(
|
||||
collectDevChannelPackagingProblems({
|
||||
channel: 'nightly',
|
||||
platform: 'win32',
|
||||
config: goodWinConfig,
|
||||
env
|
||||
})
|
||||
).toEqual(['Unknown dev channel "nightly"; expected one of hourly, daily, adhoc.'])
|
||||
})
|
||||
})
|
||||
@@ -1,67 +0,0 @@
|
||||
import { mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
||||
import { createRequire } from 'node:module'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const {
|
||||
appImageNodeRuntimeFpmArgs,
|
||||
placeAppImageNodeRuntime
|
||||
} = require('./appimage-node-runtime.cjs')
|
||||
const releaseConfig = require('../../../electron-builder.config.cjs')
|
||||
const prLinuxConfig = require('../../../electron-builder-pr-linux.config.cjs')
|
||||
|
||||
let root = ''
|
||||
|
||||
beforeEach(() => {
|
||||
root = mkdtempSync(join(tmpdir(), 'orca-appimage-node-pack-'))
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
/** Ruby's File.fnmatch without flags, which is how fpm applies --exclude: `*` crosses `/`. */
|
||||
function fpmExcludes(pattern, stagedPath) {
|
||||
const source = pattern.replace(/[.+^${}()|[\]\\]/g, '\\$&').replaceAll('*', '.*')
|
||||
return new RegExp(`^${source}$`).test(stagedPath)
|
||||
}
|
||||
|
||||
describe('the pinned Node in Linux packages', () => {
|
||||
it('is placed under resources as an executable bin/node for the slice arch', async () => {
|
||||
const pinned = join(root, 'pinned-node')
|
||||
writeFileSync(pinned, 'node bytes')
|
||||
const requested = []
|
||||
const destination = await placeAppImageNodeRuntime(join(root, 'resources'), 'arm64', (t) => {
|
||||
requested.push(t)
|
||||
return pinned
|
||||
})
|
||||
expect(requested).toEqual(['linux-arm64-glibc'])
|
||||
expect(destination).toBe(join(root, 'resources', 'node-runtime', 'bin', 'node'))
|
||||
expect(readFileSync(destination, 'utf8')).toBe('node bytes')
|
||||
expect(statSync(destination).mode & 0o777).toBe(0o755)
|
||||
})
|
||||
|
||||
it('fails packaging for a slice the pin has no glibc build for', async () => {
|
||||
await expect(
|
||||
placeAppImageNodeRuntime(join(root, 'resources'), 'ia32', () => '')
|
||||
).rejects.toThrow('no glibc build for Linux ia32')
|
||||
})
|
||||
|
||||
it('ships only in the AppImage: deb and rpm exclude it, release and PR builds alike', () => {
|
||||
for (const config of [releaseConfig, prLinuxConfig]) {
|
||||
for (const target of ['deb', 'rpm']) {
|
||||
const fpm = config[target].fpm.join('\0')
|
||||
expect(fpm).toContain(appImageNodeRuntimeFpmArgs.join('\0'))
|
||||
}
|
||||
expect(config.appImage.fpm).toBeUndefined()
|
||||
}
|
||||
const [, pattern] = appImageNodeRuntimeFpmArgs
|
||||
expect(fpmExcludes(pattern, 'opt/Orca/resources/node-runtime')).toBe(true)
|
||||
expect(fpmExcludes(pattern, 'opt/Orca/resources/node_modules')).toBe(false)
|
||||
expect(fpmExcludes(pattern, 'opt/Orca/resources/app.asar.unpacked/out/node-runtime')).toBe(
|
||||
false
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -1,85 +0,0 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
buildLinuxElectronBuilderArgs,
|
||||
resolveLinuxBuildArch,
|
||||
runLocalLinuxBuild
|
||||
} from './build-linux-local.mjs'
|
||||
|
||||
describe('local Linux build target', () => {
|
||||
it('is the package script used by the local Linux build', () => {
|
||||
const packageJson = JSON.parse(
|
||||
readFileSync(resolve(import.meta.dirname, '../../../../package.json'), 'utf8')
|
||||
)
|
||||
expect(packageJson.scripts['build:linux']).toContain(
|
||||
'node config/scripts/desktop-distribution/linux/build-linux-local.mjs'
|
||||
)
|
||||
})
|
||||
|
||||
it('follows a native Linux host architecture', () => {
|
||||
expect(resolveLinuxBuildArch({ platform: 'linux', hostArch: 'arm64' })).toBe('arm64')
|
||||
expect(resolveLinuxBuildArch({ platform: 'linux', hostArch: 'x64' })).toBe('x64')
|
||||
})
|
||||
|
||||
it('defaults cross-platform Linux builds to x64 and allows an explicit override', () => {
|
||||
expect(resolveLinuxBuildArch({ platform: 'darwin', hostArch: 'arm64' })).toBe('x64')
|
||||
expect(
|
||||
resolveLinuxBuildArch({ platform: 'darwin', hostArch: 'arm64', requestedArch: 'arm64' })
|
||||
).toBe('arm64')
|
||||
})
|
||||
|
||||
it('rejects unsupported architectures', () => {
|
||||
expect(() => resolveLinuxBuildArch({ platform: 'linux', hostArch: 'ia32' })).toThrow(
|
||||
'Unsupported Linux build architecture'
|
||||
)
|
||||
expect(() => buildLinuxElectronBuilderArgs('ia32')).toThrow(
|
||||
'Unsupported Linux build architecture'
|
||||
)
|
||||
})
|
||||
|
||||
it('passes an explicit target and matching artifact-name environment', () => {
|
||||
const execFile = vi.fn()
|
||||
runLocalLinuxBuild({
|
||||
arch: 'arm64',
|
||||
environment: { PATH: '/bin', ORCA_LINUX_ARM64_RELEASE: undefined },
|
||||
execFile,
|
||||
platform: 'linux',
|
||||
cwd: '/workspace'
|
||||
})
|
||||
expect(execFile).toHaveBeenCalledWith(
|
||||
'pnpm',
|
||||
buildLinuxElectronBuilderArgs('arm64'),
|
||||
expect.objectContaining({
|
||||
cwd: '/workspace',
|
||||
env: expect.objectContaining({ ORCA_LINUX_ARM64_RELEASE: '1' }),
|
||||
stdio: 'inherit'
|
||||
})
|
||||
)
|
||||
|
||||
expect(buildLinuxElectronBuilderArgs('x64')).toEqual(
|
||||
expect.arrayContaining(['--linux', 'AppImage', 'deb', 'rpm', '--x64'])
|
||||
)
|
||||
|
||||
runLocalLinuxBuild({
|
||||
arch: 'x64',
|
||||
environment: { PATH: '/bin', ORCA_LINUX_ARM64_RELEASE: '1' },
|
||||
execFile,
|
||||
platform: 'linux',
|
||||
cwd: '/workspace'
|
||||
})
|
||||
expect(execFile).toHaveBeenLastCalledWith(
|
||||
'pnpm',
|
||||
buildLinuxElectronBuilderArgs('x64'),
|
||||
expect.objectContaining({
|
||||
env: expect.not.objectContaining({ ORCA_LINUX_ARM64_RELEASE: expect.anything() })
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('uses the Windows pnpm command name when cross-host packaging', () => {
|
||||
const execFile = vi.fn()
|
||||
runLocalLinuxBuild({ arch: 'x64', execFile, platform: 'win32', cwd: 'C:\\workspace' })
|
||||
expect(execFile.mock.calls[0]?.[0]).toBe('pnpm.cmd')
|
||||
})
|
||||
})
|
||||
@@ -11,11 +11,10 @@ import {
|
||||
symlinkSync,
|
||||
writeFileSync
|
||||
} from 'node:fs'
|
||||
import { createRequire } from 'node:module'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
import { linuxFormatArguments, packageLinuxFormats } from './package-linux-formats.mjs'
|
||||
import { packageLinuxFormats } from './package-linux-formats.mjs'
|
||||
|
||||
let root
|
||||
let preparedDirectory
|
||||
@@ -48,30 +47,6 @@ function emitPackage(args) {
|
||||
return { format, app, output }
|
||||
}
|
||||
|
||||
it('preserves configured hooks, architecture, names, and PR compression with exact argv', () => {
|
||||
const args = linuxFormatArguments({
|
||||
format: 'deb',
|
||||
appDirectory: '/app with spaces',
|
||||
outputDirectory: '/out with spaces'
|
||||
})
|
||||
expect(args).toEqual([
|
||||
'--config',
|
||||
'config/electron-builder-pr-linux.config.cjs',
|
||||
'--linux',
|
||||
'deb',
|
||||
'--x64',
|
||||
'--publish',
|
||||
'never',
|
||||
'--prepackaged',
|
||||
'/app with spaces',
|
||||
'--config.directories.output',
|
||||
'/out with spaces',
|
||||
'--config.deb.compression=gz',
|
||||
'--config.rpm.compression=gzip'
|
||||
])
|
||||
expect(() => linuxFormatArguments({ format: 'zip' })).toThrow('Unsupported Linux package format')
|
||||
})
|
||||
|
||||
describe('independent Linux package formats', () => {
|
||||
it('starts all formats before awaiting completion and isolates metadata writes', async () => {
|
||||
if (process.platform !== 'win32') {
|
||||
@@ -188,35 +163,6 @@ describe('independent Linux package formats', () => {
|
||||
}
|
||||
)
|
||||
|
||||
it('passes its private tool environment only to AppImage and removes it after success', async () => {
|
||||
const originalToolsPath = process.env.APPIMAGE_TOOLS_PATH
|
||||
let overlay
|
||||
const calls = []
|
||||
await packageLinuxFormats({
|
||||
preparedDirectory,
|
||||
outputDirectory,
|
||||
prepareAppImageTools: async ({ directory }) => {
|
||||
overlay = directory
|
||||
mkdirSync(directory)
|
||||
return { APPIMAGE_TOOLS_PATH: directory, ORCA_PR_APPIMAGE_MKSQUASHFS: 'original tool' }
|
||||
},
|
||||
runBuilder: async (args, environment) => {
|
||||
const format = valueAfter(args, '--linux')
|
||||
calls.push(format)
|
||||
expect(environment).toEqual(
|
||||
format === 'AppImage'
|
||||
? { APPIMAGE_TOOLS_PATH: overlay, ORCA_PR_APPIMAGE_MKSQUASHFS: 'original tool' }
|
||||
: {}
|
||||
)
|
||||
expect(process.env.APPIMAGE_TOOLS_PATH).toBe(originalToolsPath)
|
||||
emitPackage(args)
|
||||
}
|
||||
})
|
||||
expect(calls.sort()).toEqual(targets.slice().sort())
|
||||
expect(existsSync(overlay)).toBe(false)
|
||||
expect(process.env.APPIMAGE_TOOLS_PATH).toBe(originalToolsPath)
|
||||
})
|
||||
|
||||
it('rejects missing artifacts even when the builder reports success', async () => {
|
||||
await expect(
|
||||
packageLinuxFormats({
|
||||
@@ -265,17 +211,3 @@ describe('independent Linux package formats', () => {
|
||||
expect(readdirSync(outputDirectory)).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
it('changes only CI deb/rpm compression levels without mutating release settings or hooks', () => {
|
||||
const require = createRequire(import.meta.url)
|
||||
const release = require('../../../electron-builder.config.cjs')
|
||||
const before = { deb: { ...release.deb }, rpm: { ...release.rpm } }
|
||||
const ci = require('../../../electron-builder-pr-linux.config.cjs')
|
||||
expect(release.deb).toEqual(before.deb)
|
||||
expect(release.rpm).toEqual(before.rpm)
|
||||
expect(ci).toEqual({
|
||||
...release,
|
||||
deb: { ...release.deb, fpm: [...(release.deb.fpm ?? []), '--deb-compression-level=1'] },
|
||||
rpm: { ...release.rpm, fpm: [...(release.rpm.fpm ?? []), '--rpm-compression-level=1'] }
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { createRequire } from 'node:module'
|
||||
import { expect, it, vi } from 'vitest'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const {
|
||||
MACOS_FOLDER_USAGE_DESCRIPTIONS,
|
||||
applyMacHelperFolderUsageDescriptions
|
||||
} = require('./macos-folder-usage-descriptions.cjs')
|
||||
const config = require('../../../electron-builder.config.cjs')
|
||||
|
||||
it('uses the same three folder descriptions for the app and every packaged Electron Helper', () => {
|
||||
expect(config.mac.extendInfo).toMatchObject(MACOS_FOLDER_USAGE_DESCRIPTIONS)
|
||||
expect(Object.keys(MACOS_FOLDER_USAGE_DESCRIPTIONS)).toHaveLength(3)
|
||||
const root = mkdtempSync(join(tmpdir(), 'orca-helper-privacy-'))
|
||||
try {
|
||||
const names = [
|
||||
'Orca Dev Helper.app',
|
||||
'Orca Dev Helper (GPU).app',
|
||||
'Orca Dev Helper (Renderer).app',
|
||||
'Orca Dev Helper (Plugin).app',
|
||||
'Orca Computer.app'
|
||||
]
|
||||
for (const name of names) {
|
||||
const contents = join(root, 'Contents', 'Frameworks', name, 'Contents')
|
||||
mkdirSync(contents, { recursive: true })
|
||||
writeFileSync(
|
||||
join(contents, 'Info.plist'),
|
||||
JSON.stringify({ CFBundleIdentifier: name, preserved: true })
|
||||
)
|
||||
}
|
||||
const run = vi.fn((_program, args) =>
|
||||
args.includes('json') ? readFileSync(args.at(-1), 'utf8') : ''
|
||||
)
|
||||
applyMacHelperFolderUsageDescriptions(root, 'Orca Dev', run)
|
||||
for (const name of names.slice(0, 4)) {
|
||||
expect(
|
||||
JSON.parse(
|
||||
readFileSync(join(root, 'Contents', 'Frameworks', name, 'Contents', 'Info.plist'), 'utf8')
|
||||
)
|
||||
).toEqual({ CFBundleIdentifier: name, preserved: true, ...MACOS_FOLDER_USAGE_DESCRIPTIONS })
|
||||
}
|
||||
expect(run).toHaveBeenCalledTimes(8)
|
||||
expect(
|
||||
JSON.parse(
|
||||
readFileSync(
|
||||
join(root, 'Contents', 'Frameworks', names[4], 'Contents', 'Info.plist'),
|
||||
'utf8'
|
||||
)
|
||||
)
|
||||
).not.toHaveProperty('NSDesktopFolderUsageDescription')
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
@@ -1,120 +0,0 @@
|
||||
import { createRequire } from 'node:module'
|
||||
import { resolve } from 'node:path'
|
||||
import { expect, it } from 'vitest'
|
||||
import { signMacApp } from './sign-mac-app.mjs'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const builderRequire = createRequire(require.resolve('electron-builder'))
|
||||
const appBuilderRequire = createRequire(builderRequire.resolve('app-builder-lib'))
|
||||
const { resolveFunction } = appBuilderRequire('app-builder-lib/out/util/resolve')
|
||||
|
||||
it('preserves file-specific signing policy and retries with fresh options', async () => {
|
||||
const calls = []
|
||||
const failure = new Error('timestamp service unavailable')
|
||||
const options = {
|
||||
app: '/fixture/Orca.app',
|
||||
platform: 'darwin',
|
||||
type: 'distribution',
|
||||
identity: 'SIGNING_IDENTITY',
|
||||
identityValidation: false,
|
||||
keychain: '/fixture/signing.keychain',
|
||||
binaries: ['/fixture/extra-helper'],
|
||||
optionsForFile: (path) => ({ entitlements: `${path}.plist`, hardenedRuntime: true }),
|
||||
ignore: [(path) => path.includes('/orcad-template/')],
|
||||
preAutoEntitlements: false
|
||||
}
|
||||
let policy
|
||||
const result = await signMacApp(options, {
|
||||
async retry(task, retryOptions) {
|
||||
policy = retryOptions
|
||||
try {
|
||||
return await task()
|
||||
} catch (error) {
|
||||
expect(error).toBe(failure)
|
||||
return task()
|
||||
}
|
||||
},
|
||||
async sign(received) {
|
||||
calls.push(received)
|
||||
if (calls.length === 1) {
|
||||
throw failure
|
||||
}
|
||||
return 'signed'
|
||||
}
|
||||
})
|
||||
expect(result).toBe('signed')
|
||||
expect(policy).toEqual({ retries: 3, interval: 5000, backoff: 5000 })
|
||||
expect(calls).toHaveLength(2)
|
||||
expect(calls[0]).not.toBe(calls[1])
|
||||
for (const received of calls) {
|
||||
expect(received).toEqual({ ...options, batchCodesignCalls: true })
|
||||
expect(received.optionsForFile).toBe(options.optionsForFile)
|
||||
expect(received.optionsForFile('/fixture/helper')).toEqual({
|
||||
entitlements: '/fixture/helper.plist',
|
||||
hardenedRuntime: true
|
||||
})
|
||||
expect(received.ignore[0]('/fixture/orcad-template/helper')).toBe(true)
|
||||
}
|
||||
expect(options).not.toHaveProperty('batchCodesignCalls')
|
||||
})
|
||||
|
||||
it('propagates signing failure after the retry policy is exhausted', async () => {
|
||||
const failure = new Error('signature verification failed')
|
||||
await expect(
|
||||
signMacApp(
|
||||
{},
|
||||
{
|
||||
retry: (task) => task(),
|
||||
sign: async () => {
|
||||
throw failure
|
||||
}
|
||||
}
|
||||
)
|
||||
).rejects.toBe(failure)
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ ORCA_MAC_ADHOC: '1' },
|
||||
{},
|
||||
{ ORCA_MAC_RELEASE: '1' },
|
||||
{ ORCA_MAC_HOURLY: '1' },
|
||||
{ ORCA_MAC_DAILY: '1' },
|
||||
{ ORCA_WIN_ADHOC: '1' }
|
||||
])(
|
||||
'uses batched signing and strict verification for every macOS release channel: %j',
|
||||
async (env) => {
|
||||
const configPath = resolve('config/electron-builder.config.cjs')
|
||||
const saved = { ...process.env }
|
||||
try {
|
||||
for (const name of Object.keys(process.env)) {
|
||||
if (name.startsWith('ORCA_')) {
|
||||
delete process.env[name]
|
||||
}
|
||||
}
|
||||
Object.assign(process.env, env)
|
||||
delete require.cache[configPath]
|
||||
const config = require(configPath)
|
||||
if (
|
||||
['ORCA_MAC_ADHOC', 'ORCA_MAC_RELEASE', 'ORCA_MAC_HOURLY', 'ORCA_MAC_DAILY'].some(
|
||||
(name) => env[name] === '1'
|
||||
)
|
||||
) {
|
||||
expect(config.mac.sign).toBe(
|
||||
resolve('config/scripts/desktop-distribution/macos/sign-mac-app.mjs')
|
||||
)
|
||||
const hook = await resolveFunction(undefined, config.mac.sign, 'sign', process.cwd())
|
||||
expect(typeof hook).toBe('function')
|
||||
expect(hook.name).toBe('sign')
|
||||
expect(config.mac.signIgnore).toContain('/orcad-template/')
|
||||
expect(config.forceCodeSigning).toBe(true)
|
||||
expect(config.mac.hardenedRuntime).toBe(true)
|
||||
expect(config.mac.notarize).toBe(true)
|
||||
} else {
|
||||
expect(config.mac.sign).toBeUndefined()
|
||||
}
|
||||
} finally {
|
||||
process.env = saved
|
||||
delete require.cache[configPath]
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -1,26 +1,11 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { createRequire } from 'node:module'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { join } from 'node:path'
|
||||
import { beforeAll, describe, expect, it } from 'vitest'
|
||||
import { runProcessSync } from '@orca/process-host'
|
||||
|
||||
const hooks = readFileSync(
|
||||
new URL('../../../nsis/orca-installer-hooks.nsh', import.meta.url),
|
||||
'utf8'
|
||||
)
|
||||
const processCheck = readFileSync(
|
||||
new URL('../../../nsis/orca-process-check.nsh', import.meta.url),
|
||||
'utf8'
|
||||
)
|
||||
const require = createRequire(import.meta.url)
|
||||
const builderRequire = createRequire(require.resolve('electron-builder/package.json'))
|
||||
const upstreamChecks = readFileSync(
|
||||
join(
|
||||
dirname(builderRequire.resolve('app-builder-lib/package.json')),
|
||||
'templates/nsis/include/allowOnlyOneInstallerInstance.nsh'
|
||||
),
|
||||
'utf8'
|
||||
)
|
||||
|
||||
function readPowerShellProbe(source = processCheck) {
|
||||
const match = source.match(/nsExec::Exec `"\$PowerShellPath"(.*?) -(?:C|Command) "([^"\n]+)"`/)
|
||||
@@ -30,27 +15,6 @@ function readPowerShellProbe(source = processCheck) {
|
||||
return { args: match[1].trim().split(/\s+/).filter(Boolean), command: match[2] }
|
||||
}
|
||||
|
||||
describe('NSIS process-check integration', () => {
|
||||
it('loads the capability hook through the installer and uninstaller include', () => {
|
||||
expect(hooks).toContain('!include "${__FILEDIR__}\\orca-process-check.nsh"')
|
||||
expect(processCheck).toMatch(/!macro customCheckAppRunning\b/)
|
||||
expect(processCheck).toContain('!include "getProcessInfo.nsh"')
|
||||
expect(processCheck).toMatch(/^Var pid$/m)
|
||||
expect(processCheck).toMatch(/^Var \/GLOBAL IsPowerShellAvailable$/m)
|
||||
})
|
||||
|
||||
it('keeps upstream process selection, retries, and installation-mode handling', () => {
|
||||
expect(processCheck).toContain('!insertmacro _CHECK_APP_RUNNING')
|
||||
expect(processCheck).not.toMatch(/!macro (?:FIND_PROCESS|KILL_PROCESS|_CHECK_APP_RUNNING)\b/)
|
||||
expect(processCheck).not.toMatch(/\b(?:Stop-Process|taskkill|Set-ExecutionPolicy)\b/)
|
||||
const findProcess = upstreamChecks.match(/!macro FIND_PROCESS\b[\s\S]*?!macroend/)?.[0]
|
||||
if (!findProcess) {
|
||||
throw new Error('The upstream process finder was not found')
|
||||
}
|
||||
expect(readPowerShellProbe().args).toEqual(readPowerShellProbe(findProcess).args)
|
||||
})
|
||||
})
|
||||
|
||||
describe.runIf(process.platform === 'win32')(
|
||||
'NSIS capability probe under Restricted policy',
|
||||
() => {
|
||||
|
||||
@@ -43,39 +43,8 @@ function makeCache(...relativeFiles) {
|
||||
|
||||
describe('cached elevate.exe swap covers the real electron-builder layouts', () => {
|
||||
// Model real <releaseName>/<archive>-<url hash> legacy/unified layouts; old <cache>/nsis matched neither. Custom layout is covered by probe tests.
|
||||
it.each([
|
||||
['legacy bundle', 'nsis-3.0.4.1/nsis-3.0.4.1-1mx3n/elevate.exe'],
|
||||
['unified bundle', 'nsis@1.2.1/nsis-bundle-3.12-k4d9x/elevate.exe'],
|
||||
['bare nsis release dir', 'nsis/nsis-3.0.4.1/elevate.exe']
|
||||
])('finds the cached helper in the %s layout', (_label, relative) => {
|
||||
const cacheDir = makeCache(relative)
|
||||
expect(findCachedElevatePaths(cacheDir, { env: {} })).toEqual([
|
||||
join(cacheDir, ...relative.split('/'))
|
||||
])
|
||||
})
|
||||
|
||||
it('leaves other toolsets and the raw download dir alone', () => {
|
||||
const cacheDir = makeCache(
|
||||
'winCodeSign/winCodeSign-2.6.0-abc12/elevate.exe',
|
||||
'downloads/nsis/elevate.exe'
|
||||
)
|
||||
expect(findCachedElevatePaths(cacheDir, { env: {} })).toEqual([])
|
||||
})
|
||||
|
||||
// Allow nsis-resources overmatch: it ships plugins without elevate.exe and costs one cheap read; guessing narrower upstream naming is brittle.
|
||||
it('scans the resources bundle too, which ships no helper to find', () => {
|
||||
expect(
|
||||
findCachedElevatePaths(makeCache('nsis-resources-3.4.1/plugins/x86-unicode/nsProcess.dll'), {
|
||||
env: {}
|
||||
})
|
||||
).toEqual([])
|
||||
|
||||
const planted = 'nsis-resources-3.4.1/nsis-resources-3.4.1-p8w1z/elevate.exe'
|
||||
const cacheDir = makeCache(planted)
|
||||
expect(findCachedElevatePaths(cacheDir, { env: {} })).toEqual([
|
||||
join(cacheDir, ...planted.split('/'))
|
||||
])
|
||||
})
|
||||
|
||||
// Replace all cached copies because only app-builder-lib knows which one repack chooses.
|
||||
it('replaces every cached copy when several bundles are present', async () => {
|
||||
@@ -99,17 +68,6 @@ describe('cached elevate.exe swap covers the real electron-builder layouts', ()
|
||||
}
|
||||
})
|
||||
|
||||
it('covers the ELECTRON_BUILDER_NSIS_DIR override copy', () => {
|
||||
const overrideDir = join(scratch, 'nsis-override')
|
||||
mkdirSync(overrideDir, { recursive: true })
|
||||
writeFileSync(join(overrideDir, 'elevate.exe'), 'unsigned-elevate')
|
||||
const cacheDir = makeCache()
|
||||
|
||||
expect(
|
||||
findCachedElevatePaths(cacheDir, { env: { ELECTRON_BUILDER_NSIS_DIR: overrideDir } })
|
||||
).toEqual([join(overrideDir, 'elevate.exe')])
|
||||
})
|
||||
|
||||
// Compare real cache scan against independent unbounded walk to catch vacuous empty matches; skip only if no bundle is cached.
|
||||
})
|
||||
|
||||
@@ -137,57 +95,6 @@ describe('the probe, not the scan, decides whether the swap worked', () => {
|
||||
})
|
||||
|
||||
// Prefix-restored stale release can satisfy replaced.length while authoritative packed bundle sits outside scan; model both copies.
|
||||
it('does not call a stale directory a success when the packed bundle is unmatched', async () => {
|
||||
const stale = 'nsis-3.0.4.1/nsis-3.0.4.1-1mx3n/elevate.exe'
|
||||
const packed = 'builder-nsis@4.0.0/nsis-bundle-4.0-k4d9x/elevate.exe'
|
||||
const cacheDir = makeCache(stale, packed)
|
||||
const signed = join(scratch, 'signed-elevate.exe')
|
||||
writeFileSync(signed, 'signpath-signed-elevate')
|
||||
|
||||
const result = await replaceCachedElevateHelpers({
|
||||
signedPath: signed,
|
||||
cacheDir,
|
||||
env: {},
|
||||
probe: probeUnavailable
|
||||
})
|
||||
|
||||
expect(result.replaced).toEqual([join(cacheDir, ...stale.split('/'))])
|
||||
expect(readFileSync(join(cacheDir, ...packed.split('/')), 'utf8')).toBe('unsigned-elevate')
|
||||
|
||||
const { annotations, exitCode } = summarizeSwap(result)
|
||||
expect(exitCode).toBe(0)
|
||||
expect(annotations).toHaveLength(1)
|
||||
expect(annotations[0].level).toBe('warning')
|
||||
expect(annotations[0].message).toContain('Could not ask app-builder-lib')
|
||||
})
|
||||
|
||||
it('fails when the probe names a copy that could not be replaced', () => {
|
||||
const summary = summarizeSwap({
|
||||
replaced: ['C:/cache/nsis-3.0.4.1/nsis-3.0.4.1-1mx3n/elevate.exe'],
|
||||
cacheDir: 'C:/cache',
|
||||
toolsetPath: 'C:/cache/nsis@2.0.0/nsis-bundle-4.0-k4d9x/elevate.exe',
|
||||
toolsetError: null,
|
||||
toolsetReplaced: false
|
||||
})
|
||||
|
||||
expect(summary.exitCode).toBe(1)
|
||||
expect(summary.annotations[0].level).toBe('error')
|
||||
expect(summary.annotations[0].message).toContain('will pack')
|
||||
})
|
||||
|
||||
it('fails when nothing at all was replaced', () => {
|
||||
const summary = summarizeSwap({
|
||||
replaced: [],
|
||||
cacheDir: 'C:/cache',
|
||||
toolsetPath: null,
|
||||
toolsetError: 'app-builder-lib not loadable',
|
||||
toolsetReplaced: false
|
||||
})
|
||||
|
||||
expect(summary.exitCode).toBe(1)
|
||||
expect(summary.annotations[0].level).toBe('error')
|
||||
expect(summary.annotations[0].message).toContain('No cached elevate.exe found')
|
||||
})
|
||||
})
|
||||
|
||||
describe('a cached elevate.exe miss is not silent', () => {
|
||||
|
||||
+1
-227
@@ -1,6 +1,6 @@
|
||||
import { execFile } from 'node:child_process'
|
||||
import { existsSync } from 'node:fs'
|
||||
import { chmod, lstat, mkdir, mkdtemp, readFile, realpath, rm, writeFile } from 'node:fs/promises'
|
||||
import { chmod, lstat, mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
||||
import { createRequire } from 'node:module'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { dirname, join } from 'node:path'
|
||||
@@ -72,69 +72,10 @@ describe('electron-builder config', () => {
|
||||
})
|
||||
|
||||
// All-negation lists implicitly include **/*; missing examples exclusion shipped hostile-panel in 1.4.160-rc.3. Exercise real matcher, not pattern spelling.
|
||||
it('keeps plugin authoring examples out of app.asar', () => {
|
||||
const matcher = new FileMatcher('/app', '/dest', (value) => value, electronBuilderConfig.files)
|
||||
// copyFiles() prepends this itself once the pattern list is all-negation.
|
||||
matcher.prependPattern('**/*')
|
||||
const isPacked = matcher.createFilter()
|
||||
const packs = (repoPath) => isPacked(join('/app', repoPath), { isDirectory: () => false })
|
||||
|
||||
for (const authoringOnly of [
|
||||
'examples/plugins/test-fixtures/hostile-panel/panel.html',
|
||||
'examples/plugins/test-fixtures/hostile-panel/orca-plugin.json',
|
||||
'examples/plugins/hello-orca/main.mjs',
|
||||
'examples/plugins/hello-orca/orca-plugin.json'
|
||||
]) {
|
||||
expect(packs(authoringOnly)).toBe(false)
|
||||
}
|
||||
// The negation stays anchored at the app root, so nested `examples` segments still ship.
|
||||
expect(packs('out/main/examples/index.js')).toBe(true)
|
||||
})
|
||||
|
||||
// CI never creates ~270MB/branch out/electron-dev caches; only local packages exposed this bloat.
|
||||
it('keeps cached dev Electron bundles and Vite dependencies out of app.asar', () => {
|
||||
const matcher = new FileMatcher('/app', '/dest', (value) => value, electronBuilderConfig.files)
|
||||
matcher.prependPattern('**/*')
|
||||
const isPacked = matcher.createFilter()
|
||||
const packs = (repoPath) => isPacked(join('/app', repoPath), { isDirectory: () => false })
|
||||
|
||||
for (const devBundlePath of [
|
||||
'out/electron-dev/1a2b3c4d5e6f/Orca: dev.app/Contents/MacOS/Electron',
|
||||
'out/electron-dev/1a2b3c4d5e6f/orca-dev-electron-app.json',
|
||||
'.cache/vite/renderer/deps/react.js',
|
||||
'.cache/vite/web/deps/react.js',
|
||||
'.cache/vite.lock/owner'
|
||||
]) {
|
||||
expect(packs(devBundlePath)).toBe(false)
|
||||
}
|
||||
// The real build outputs sit beside it under out/ and must still ship.
|
||||
expect(packs('out/main/index.js')).toBe(true)
|
||||
expect(packs('out/renderer/index.html')).toBe(true)
|
||||
})
|
||||
|
||||
// Duplicated relay.js added 14MB to asar and AV quarantine gutted the entire archive (#20966); packaged app uses resources/relay.
|
||||
it('keeps the relay bundles out of app.asar and ships them only through extraResources', () => {
|
||||
const matcher = new FileMatcher('/app', '/dest', (value) => value, electronBuilderConfig.files)
|
||||
matcher.prependPattern('**/*')
|
||||
const isPacked = matcher.createFilter()
|
||||
const packs = (repoPath) => isPacked(join('/app', repoPath), { isDirectory: () => false })
|
||||
|
||||
for (const relayPath of [
|
||||
'out/relay/linux-x64/relay.js',
|
||||
'out/relay/win32-x64/relay.js',
|
||||
'out/relay/darwin-arm64/relay-watcher.js',
|
||||
'out/relay/wsl/wsl-agent-hook-relay.js'
|
||||
]) {
|
||||
expect(packs(relayPath)).toBe(false)
|
||||
}
|
||||
|
||||
for (const platform of ['mac', 'linux', 'win']) {
|
||||
expect(electronBuilderConfig[platform].extraResources).toContainEqual({
|
||||
from: 'out/relay',
|
||||
to: 'relay'
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
// Bundled agent-browser answered "No skills found" because only its binary shipped (#17705).
|
||||
const hostBuilderPlatform = { darwin: 'mac', linux: 'linux', win32: 'win' }[process.platform]
|
||||
@@ -174,77 +115,9 @@ describe('electron-builder config', () => {
|
||||
}
|
||||
)
|
||||
|
||||
it.each(['mac', 'linux'])(
|
||||
'loads Codex TOML parsing after %s runtime pruning',
|
||||
async (platform) => {
|
||||
const resourcesDir = await mkdtemp(join(tmpdir(), 'orca-packaged-codex-toml-'))
|
||||
try {
|
||||
const resource = electronBuilderConfig[platform].extraResources.find(
|
||||
(entry) => entry.to === join('node_modules', 'smol-toml')
|
||||
)
|
||||
expect(resource).toBeDefined()
|
||||
await copyFiles([
|
||||
new FileMatcher(resource.from, join(resourcesDir, resource.to), (value) => value)
|
||||
])
|
||||
require('../../../packaged-runtime-node-modules.cjs').prunePackagedRuntimeNodeModules(
|
||||
resourcesDir,
|
||||
platform === 'mac' ? 'darwin' : 'linux',
|
||||
process.arch
|
||||
)
|
||||
const stagedRequire = createRequire(join(resourcesDir, 'out', 'main', 'codex', 'trust.cjs'))
|
||||
expect(await realpath(stagedRequire.resolve('smol-toml'))).toBe(
|
||||
await realpath(join(resourcesDir, resource.to, 'dist', 'index.cjs'))
|
||||
)
|
||||
const { parse } = stagedRequire('smol-toml')
|
||||
expect(parse('[projects."/workspace"]\ntrust_level = "trusted"\n')).toEqual({
|
||||
projects: { '/workspace': { trust_level: 'trusted' } }
|
||||
})
|
||||
} finally {
|
||||
await rm(resourcesDir, { recursive: true, force: true })
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// CLI Node mode cannot read asar; packed entry sends orca serve to Electron (#27307).
|
||||
it('unpacks the orcad serve-selection entry the CLI runs', async () => {
|
||||
const sharedSource = await readFile(
|
||||
join(REPO_ROOT, 'src', 'shared', 'orcad-local-serve-selection.ts'),
|
||||
'utf8'
|
||||
)
|
||||
const entryName = sharedSource.match(/ORCAD_LOCAL_SERVE_SELECTION_ENTRY = '([^']+)'/)?.[1]
|
||||
expect(entryName).toBeDefined()
|
||||
|
||||
const matcher = new FileMatcher(
|
||||
'/app',
|
||||
'/dest',
|
||||
(value) => value,
|
||||
electronBuilderConfig.asarUnpack
|
||||
)
|
||||
const isUnpacked = matcher.createFilter()
|
||||
expect(
|
||||
isUnpacked(join('/app', 'out', 'main', `${entryName}.js`), { isDirectory: () => false })
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
// Swept one-time /tmp asar extracts cause web-client 500s and phone bundle failures until restart (#27976).
|
||||
it('unpacks the web and mobile bundles a host serves by opening their files', () => {
|
||||
const matcher = new FileMatcher(
|
||||
'/app',
|
||||
'/dest',
|
||||
(value) => value,
|
||||
electronBuilderConfig.asarUnpack
|
||||
)
|
||||
const isUnpacked = matcher.createFilter()
|
||||
for (const webPath of [
|
||||
'out/renderer/web-index.html',
|
||||
'out/renderer/assets/index-abc123.js',
|
||||
'out/renderer/.orca-web-client-files.json',
|
||||
'out/mobile-web/manifest.json',
|
||||
'out/mobile-web/assets/index-abc123.js'
|
||||
]) {
|
||||
expect(isUnpacked(join('/app', webPath), { isDirectory: () => false })).toBe(true)
|
||||
}
|
||||
})
|
||||
|
||||
it('validates each AppImage before electron-builder publishes it', async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), 'orca-electron-builder-appimage-'))
|
||||
@@ -263,67 +136,11 @@ describe('electron-builder config', () => {
|
||||
await rm(root, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
it('overrides packaged semver only for local macOS builds', () => {
|
||||
const configPath = require.resolve('../../../electron-builder.config.cjs')
|
||||
const original = process.env.ORCA_LOCAL_BUILD_VERSION
|
||||
const originalMacRelease = process.env.ORCA_MAC_RELEASE
|
||||
try {
|
||||
delete require.cache[configPath]
|
||||
delete process.env.ORCA_MAC_RELEASE
|
||||
process.env.ORCA_LOCAL_BUILD_VERSION = '1.4.159-rc.0.local.123.abc'
|
||||
expect(require('../../../electron-builder.config.cjs').extraMetadata).toEqual({
|
||||
version: '1.4.159-rc.0.local.123.abc'
|
||||
})
|
||||
} finally {
|
||||
if (originalMacRelease === undefined) {
|
||||
delete process.env.ORCA_MAC_RELEASE
|
||||
} else {
|
||||
process.env.ORCA_MAC_RELEASE = originalMacRelease
|
||||
}
|
||||
if (original === undefined) {
|
||||
delete process.env.ORCA_LOCAL_BUILD_VERSION
|
||||
} else {
|
||||
process.env.ORCA_LOCAL_BUILD_VERSION = original
|
||||
}
|
||||
delete require.cache[configPath]
|
||||
require('../../../electron-builder.config.cjs')
|
||||
}
|
||||
})
|
||||
|
||||
it('never applies local semver to release packaging', () => {
|
||||
const configPath = require.resolve('../../../electron-builder.config.cjs')
|
||||
const originalLocalVersion = process.env.ORCA_LOCAL_BUILD_VERSION
|
||||
const originalMacRelease = process.env.ORCA_MAC_RELEASE
|
||||
try {
|
||||
delete require.cache[configPath]
|
||||
process.env.ORCA_LOCAL_BUILD_VERSION = '1.4.159-local.123.abc'
|
||||
process.env.ORCA_MAC_RELEASE = '1'
|
||||
expect(require('../../../electron-builder.config.cjs').extraMetadata).toBeUndefined()
|
||||
} finally {
|
||||
if (originalLocalVersion === undefined) {
|
||||
delete process.env.ORCA_LOCAL_BUILD_VERSION
|
||||
} else {
|
||||
process.env.ORCA_LOCAL_BUILD_VERSION = originalLocalVersion
|
||||
}
|
||||
if (originalMacRelease === undefined) {
|
||||
delete process.env.ORCA_MAC_RELEASE
|
||||
} else {
|
||||
process.env.ORCA_MAC_RELEASE = originalMacRelease
|
||||
}
|
||||
delete require.cache[configPath]
|
||||
require('../../../electron-builder.config.cjs')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('arch-aware packaging guard', () => {
|
||||
// electron-builder Arch enum: ia32=0, x64=1, armv7l=2, arm64=3.
|
||||
const HOST_ARCH = process.arch === 'arm64' ? 3 : 1
|
||||
const OTHER_ARCH = process.arch === 'arm64' ? 1 : 3
|
||||
const OTHER_ARCH_NAME = process.arch === 'arm64' ? 'x64' : 'arm64'
|
||||
const SHERPA_PLATFORM = process.platform === 'win32' ? 'win' : process.platform
|
||||
const otherSherpa = `sherpa-onnx-${SHERPA_PLATFORM}-${OTHER_ARCH_NAME}`
|
||||
|
||||
// Native tests need valid mobile bundle for beforePack; use temp build, leaving bundle verification to its own suite.
|
||||
let scratch
|
||||
@@ -376,48 +193,5 @@ describe('arch-aware packaging guard', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it.skipIf(process.platform === 'win32')(
|
||||
'requires the other architecture natives to be installed',
|
||||
() => {
|
||||
const otherSherpaInstalled = existsSync(
|
||||
join(REPO_ROOT, 'node_modules', otherSherpa, 'package.json')
|
||||
)
|
||||
const otherSherpaExpected = Object.hasOwn(
|
||||
require('../../../../package.json').optionalDependencies,
|
||||
otherSherpa
|
||||
)
|
||||
if (otherSherpaExpected && !otherSherpaInstalled) {
|
||||
expect(() => packHost(OTHER_ARCH)).toThrow(otherSherpa)
|
||||
expect(() => packHost(OTHER_ARCH)).toThrow('pnpm install:release')
|
||||
} else {
|
||||
expect(() => packHost(OTHER_ARCH)).not.toThrow()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// The host's own build is the foreign-arch case: a Windows checkout compiles these for its CPU only.
|
||||
it.runIf(process.platform === 'win32')(
|
||||
'refuses a Windows workspace addon built for another architecture',
|
||||
() => {
|
||||
for (const binary of ['orca_windows_registry.node', 'orca_windows_security.node']) {
|
||||
expect(() => packHost(OTHER_ARCH)).toThrow(`${binary} for ${OTHER_ARCH_NAME}`)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
it('requires installed Windows addons for Windows packaging', () => {
|
||||
const windowsAddon = electronBuilderConfig.win.extraResources.some(
|
||||
(resource) => resource.to === join('node_modules', '@vscode', 'windows-process-tree')
|
||||
)
|
||||
const packWindows = () =>
|
||||
electronBuilderConfig.beforePack({ electronPlatformName: 'win32', arch: 1 }, bundleDir)
|
||||
if (process.platform === 'win32' || windowsAddon) {
|
||||
expect(packWindows).not.toThrow()
|
||||
} else {
|
||||
expect(packWindows).toThrow('@vscode/windows-process-tree')
|
||||
expect(packWindows).toThrow('Windows packaging requires a Windows host')
|
||||
// A workspace link exists everywhere; only its compiled binary proves the addon will load.
|
||||
expect(packWindows).toThrow('@orca/windows-security')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
-126
@@ -1,126 +0,0 @@
|
||||
import { createRequire } from 'node:module'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const electronBuilderConfig = require('../../../electron-builder.config.cjs')
|
||||
|
||||
const MUTABLE_BUILD_ENV = [
|
||||
'ORCA_MAC_HOURLY',
|
||||
'ORCA_MAC_DAILY',
|
||||
'ORCA_MAC_ADHOC',
|
||||
'ORCA_MAC_RELEASE',
|
||||
'ORCA_HOURLY_BUILD_VERSION',
|
||||
'ORCA_DAILY_BUILD_VERSION',
|
||||
'ORCA_ADHOC_BUILD_VERSION',
|
||||
'ORCA_LOCAL_BUILD_VERSION'
|
||||
]
|
||||
|
||||
/** Re-requires the config under a temporary env, then restores env and module cache. */
|
||||
function withEnv(env, assert) {
|
||||
const configPath = require.resolve('../../../electron-builder.config.cjs')
|
||||
const original = Object.fromEntries(MUTABLE_BUILD_ENV.map((key) => [key, process.env[key]]))
|
||||
try {
|
||||
for (const key of MUTABLE_BUILD_ENV) {
|
||||
delete process.env[key]
|
||||
}
|
||||
Object.assign(process.env, env)
|
||||
delete require.cache[configPath]
|
||||
assert(require('../../../electron-builder.config.cjs'))
|
||||
} finally {
|
||||
for (const [key, value] of Object.entries(original)) {
|
||||
if (value === undefined) {
|
||||
delete process.env[key]
|
||||
} else {
|
||||
process.env[key] = value
|
||||
}
|
||||
}
|
||||
delete require.cache[configPath]
|
||||
require('../../../electron-builder.config.cjs')
|
||||
}
|
||||
}
|
||||
|
||||
const withHourlyEnv = (assert) => withEnv({ ORCA_MAC_HOURLY: '1' }, assert)
|
||||
const withDailyEnv = (assert) => withEnv({ ORCA_MAC_DAILY: '1' }, assert)
|
||||
const withAdhocEnv = (assert) => withEnv({ ORCA_MAC_ADHOC: '1' }, assert)
|
||||
|
||||
describe('electron-builder mac channel config', () => {
|
||||
// Squirrel.Mac requires release bundle ID and Developer ID signature; local ad-hoc hourly identity cannot update real Orca.
|
||||
it('builds hourly artifacts with the release signing identity', () => {
|
||||
withHourlyEnv((config) => {
|
||||
expect(config.mac.appId).toBeUndefined()
|
||||
expect(config.appId).toBe('com.stablyai.orca')
|
||||
expect(config.mac.hardenedRuntime).toBe(true)
|
||||
expect(config.forceCodeSigning).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
// Notarization anchors TCC to identifier/team across updates; unnotarized hourlies lose folder grants without re-prompt.
|
||||
it('notarizes hourly builds like releases, and neither locally', () => {
|
||||
withHourlyEnv((config) => {
|
||||
expect(config.mac.notarize).toBe(true)
|
||||
})
|
||||
withEnv({ ORCA_MAC_RELEASE: '1' }, (config) => {
|
||||
expect(config.mac.notarize).toBe(true)
|
||||
})
|
||||
expect(electronBuilderConfig.mac.notarize).toBe(false)
|
||||
})
|
||||
|
||||
// Twenty-four hourly releases would evict stable/RC from main repo’s ten-entry feed.
|
||||
it('publishes hourly builds to the separate hourly repo', () => {
|
||||
withHourlyEnv((config) => {
|
||||
expect(config.publish).toMatchObject({ repo: 'orca-hourly', releaseType: 'prerelease' })
|
||||
})
|
||||
expect(electronBuilderConfig.publish).toMatchObject({
|
||||
repo: 'orca',
|
||||
releaseType: 'draft'
|
||||
})
|
||||
})
|
||||
|
||||
it('stamps hourly packages with the hourly version', () => {
|
||||
withEnv(
|
||||
{ ORCA_MAC_HOURLY: '1', ORCA_HOURLY_BUILD_VERSION: '1.4.160-hourly.202607281400' },
|
||||
(config) => {
|
||||
expect(config.extraMetadata).toEqual({ version: '1.4.160-hourly.202607281400' })
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
// Adhoc uses same updater, signing and TCC identity as hourly; only destination repo differs.
|
||||
it('builds adhoc artifacts with the release identity and its own repo', () => {
|
||||
withAdhocEnv((config) => {
|
||||
expect(config.appId).toBe('com.stablyai.orca')
|
||||
expect(config.mac.hardenedRuntime).toBe(true)
|
||||
expect(config.mac.notarize).toBe(true)
|
||||
expect(config.forceCodeSigning).toBe(true)
|
||||
expect(config.publish).toMatchObject({ repo: 'orca-adhoc', releaseType: 'prerelease' })
|
||||
})
|
||||
})
|
||||
|
||||
it('stamps adhoc packages with the adhoc version', () => {
|
||||
withEnv(
|
||||
{ ORCA_MAC_ADHOC: '1', ORCA_ADHOC_BUILD_VERSION: '1.4.160-adhoc.20260728140533' },
|
||||
(config) => {
|
||||
expect(config.extraMetadata).toEqual({ version: '1.4.160-adhoc.20260728140533' })
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('builds daily artifacts with the release identity and its own repo', () => {
|
||||
withDailyEnv((config) => {
|
||||
expect(config.appId).toBe('com.stablyai.orca')
|
||||
expect(config.mac.hardenedRuntime).toBe(true)
|
||||
expect(config.mac.notarize).toBe(true)
|
||||
expect(config.forceCodeSigning).toBe(true)
|
||||
expect(config.publish).toMatchObject({ repo: 'orca-daily', releaseType: 'prerelease' })
|
||||
})
|
||||
})
|
||||
|
||||
it('stamps daily packages with the daily version', () => {
|
||||
withEnv(
|
||||
{ ORCA_MAC_DAILY: '1', ORCA_DAILY_BUILD_VERSION: '1.4.160-daily.202607281300' },
|
||||
(config) => {
|
||||
expect(config.extraMetadata).toEqual({ version: '1.4.160-daily.202607281300' })
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
+1
-109
@@ -2,117 +2,9 @@ import { createRequire } from 'node:module'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const {
|
||||
buildNativeRebuildArgs,
|
||||
runElectronBuilderNativeRebuild
|
||||
} = require('./electron-builder-native-rebuild.cjs')
|
||||
const { buildNativeRebuildArgs } = require('./electron-builder-native-rebuild.cjs')
|
||||
|
||||
describe('electron-builder native rebuild hook', () => {
|
||||
it('passes the target platform and arch to Orca native rebuild script', () => {
|
||||
expect(
|
||||
buildNativeRebuildArgs({
|
||||
platform: { nodeName: 'darwin' },
|
||||
arch: 'x64'
|
||||
})
|
||||
).toEqual([
|
||||
'config/scripts/native-build/node-addons/rebuild-native-deps.mjs',
|
||||
'--platform=darwin',
|
||||
'--arch=x64',
|
||||
'--force'
|
||||
])
|
||||
})
|
||||
|
||||
it('returns false so electron-builder skips its optional module rebuild pass', () => {
|
||||
const calls = []
|
||||
const result = runElectronBuilderNativeRebuild(
|
||||
{
|
||||
platform: { nodeName: 'linux' },
|
||||
arch: 'arm64'
|
||||
},
|
||||
(...args) => calls.push(args)
|
||||
)
|
||||
|
||||
expect(result).toBe(false)
|
||||
expect(calls).toEqual([
|
||||
[
|
||||
process.execPath,
|
||||
[
|
||||
'config/scripts/native-build/node-addons/rebuild-native-deps.mjs',
|
||||
'--platform=linux',
|
||||
'--arch=arm64',
|
||||
'--force'
|
||||
],
|
||||
expect.objectContaining({ stdio: 'inherit' })
|
||||
]
|
||||
])
|
||||
})
|
||||
|
||||
it('reuses a prepared native runtime only for the host target', () => {
|
||||
const runtime = {
|
||||
environment: { ORCA_REUSE_PREPARED_NATIVE_RUNTIME: '1' },
|
||||
hostPlatform: 'linux',
|
||||
hostArch: 'x64'
|
||||
}
|
||||
|
||||
expect(
|
||||
buildNativeRebuildArgs(
|
||||
{
|
||||
platform: { nodeName: 'linux' },
|
||||
arch: 'x64'
|
||||
},
|
||||
runtime
|
||||
)
|
||||
).toEqual([
|
||||
'config/scripts/native-build/node-addons/rebuild-native-deps.mjs',
|
||||
'--platform=linux',
|
||||
'--arch=x64'
|
||||
])
|
||||
expect(
|
||||
buildNativeRebuildArgs(
|
||||
{
|
||||
platform: { nodeName: 'linux' },
|
||||
arch: 'arm64'
|
||||
},
|
||||
runtime
|
||||
)
|
||||
).toContain('--force')
|
||||
})
|
||||
|
||||
it('builds the native CLI launcher before packaging Windows resources', () => {
|
||||
const calls = []
|
||||
const result = runElectronBuilderNativeRebuild(
|
||||
{
|
||||
platform: { nodeName: 'win32' },
|
||||
arch: 'x64'
|
||||
},
|
||||
(...args) => calls.push(args)
|
||||
)
|
||||
|
||||
expect(result).toBe(false)
|
||||
expect(calls).toEqual([
|
||||
[
|
||||
process.execPath,
|
||||
['config/scripts/native-build/windows/build-windows-cli-launcher.mjs'],
|
||||
expect.objectContaining({ stdio: 'inherit' })
|
||||
],
|
||||
[
|
||||
process.execPath,
|
||||
['config/scripts/native-build/windows/build-windows-agent-hook.mjs', '--arch', 'x64'],
|
||||
expect.objectContaining({ stdio: 'inherit' })
|
||||
],
|
||||
[
|
||||
process.execPath,
|
||||
[
|
||||
'config/scripts/native-build/node-addons/rebuild-native-deps.mjs',
|
||||
'--platform=win32',
|
||||
'--arch=x64',
|
||||
'--force'
|
||||
],
|
||||
expect.objectContaining({ stdio: 'inherit' })
|
||||
]
|
||||
])
|
||||
})
|
||||
|
||||
it('rejects incomplete electron-builder contexts', () => {
|
||||
expect(() => buildNativeRebuildArgs({ arch: 'x64' })).toThrow(/platform/)
|
||||
expect(() => buildNativeRebuildArgs({ platform: { nodeName: 'linux' } })).toThrow(/arch/)
|
||||
|
||||
-71
@@ -356,77 +356,6 @@ describe('packaged runtime resources', () => {
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
it.skipIf(process.platform === 'win32')(
|
||||
'marks packaged Unix CLI launchers executable',
|
||||
async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), 'orca-electron-builder-config-'))
|
||||
const previousPath = process.env.PATH
|
||||
try {
|
||||
const resourcesDir = join(root, 'linux-unpacked', 'resources')
|
||||
const launcherPath = join(resourcesDir, 'bin', 'orca-ide')
|
||||
await mkdir(join(resourcesDir, 'bin'), { recursive: true })
|
||||
await cp(
|
||||
join(process.cwd(), 'resources', 'plugins', 'launch'),
|
||||
join(resourcesDir, 'plugins', 'launch'),
|
||||
{ recursive: true }
|
||||
)
|
||||
await seedBundledRipgrep(resourcesDir)
|
||||
await seedPackagedServePayload(resourcesDir)
|
||||
// Layout fixtures use a cross-arch slice; native PTY probes need real packaged binaries.
|
||||
const target =
|
||||
process.arch === 'x64'
|
||||
? { electronArch: 3, machine: 0xb7 }
|
||||
: { electronArch: 1, machine: 0x3e }
|
||||
await seedClipboardPublisher(resourcesDir, target.machine)
|
||||
await stubObjdump(root)
|
||||
await mkdir(join(resourcesDir, 'node_modules', 'zod', 'src'), { recursive: true })
|
||||
// afterPack rejects missing unpacked daemon entry; model real package layout.
|
||||
const unpackedMainDir = join(resourcesDir, 'app.asar.unpacked', 'out', 'main')
|
||||
await mkdir(unpackedMainDir, { recursive: true })
|
||||
await writeFile(
|
||||
join(unpackedMainDir, 'daemon-entry.js'),
|
||||
'console.error("Usage: daemon-entry <socket>"); process.exit(1)\n',
|
||||
'utf8'
|
||||
)
|
||||
await writeFile(
|
||||
join(resourcesDir, 'app.asar.unpacked', 'out', 'package.json'),
|
||||
`${JSON.stringify({ name: 'orca-compiled-output', type: 'commonjs', private: true })}\n`,
|
||||
'utf8'
|
||||
)
|
||||
const unpackedCliDir = join(resourcesDir, 'app.asar.unpacked', 'out', 'cli')
|
||||
await mkdir(join(unpackedCliDir, 'handlers'), { recursive: true })
|
||||
await writeFile(join(unpackedCliDir, 'handlers', 'skills.js'), '', 'utf8')
|
||||
await writeFile(
|
||||
join(unpackedCliDir, 'index.js'),
|
||||
[
|
||||
'const args = process.argv.slice(2)',
|
||||
"if (args[1] === 'list') console.log(JSON.stringify({ topics: [{ name: 'orca-cli' }, { name: 'orca-computer-use' }] }))",
|
||||
"else if (args[1] === 'get') console.log(`---\\nname: ${args[2]}\\n---`)",
|
||||
'else console.log(JSON.stringify({ executed: false }))'
|
||||
].join('\n'),
|
||||
'utf8'
|
||||
)
|
||||
await writeFile(launcherPath, '#!/usr/bin/env bash\n', { encoding: 'utf8', mode: 0o644 })
|
||||
|
||||
await electronBuilderConfig.afterPack({
|
||||
appOutDir: join(root, 'linux-unpacked'),
|
||||
electronPlatformName: 'linux',
|
||||
arch: target.electronArch,
|
||||
packager: { appInfo: { version: '9.9.9' } }
|
||||
})
|
||||
|
||||
expect((await stat(launcherPath)).mode & 0o111).not.toBe(0)
|
||||
await expect(
|
||||
readFile(join(resourcesDir, 'app.asar.unpacked', 'out', 'package.json'), 'utf8')
|
||||
).resolves.toContain('"version": "9.9.9"')
|
||||
await expect(readFile(join(resourcesDir, 'package-type'), 'utf8')).resolves.toBe('AppImage')
|
||||
} finally {
|
||||
process.env.PATH = previousPath
|
||||
await removeTree(root)
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
// Headers model architecture; objdump is stubbed for these packaging-layout tests.
|
||||
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
import { createRequire } from 'node:module'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const electronBuilderConfig = require('../../../electron-builder.config.cjs')
|
||||
const { FileMatcher } = require('app-builder-lib/out/fileMatcher')
|
||||
|
||||
describe('electron-builder speech resources', () => {
|
||||
it('excludes bundled variants and keeps one target resource per platform', () => {
|
||||
expect(electronBuilderConfig.files).toContain('!node_modules/sherpa-onnx*{,/**/*}')
|
||||
expect(electronBuilderConfig.asarUnpack).not.toContain('node_modules/sherpa-onnx*/**')
|
||||
|
||||
for (const [platform, packagePath] of [
|
||||
['mac', 'node_modules/sherpa-onnx-darwin-${arch}'],
|
||||
['linux', 'node_modules/sherpa-onnx-linux-${arch}'],
|
||||
['win', 'node_modules/sherpa-onnx-win-x64']
|
||||
]) {
|
||||
const speechResources = electronBuilderConfig[platform].extraResources.filter(
|
||||
(resource) =>
|
||||
typeof resource.to === 'string' && resource.to.startsWith('node_modules/sherpa-onnx')
|
||||
)
|
||||
expect(speechResources).toEqual([{ from: packagePath, to: packagePath }])
|
||||
}
|
||||
|
||||
const matcher = new FileMatcher('/app', '/dest', (value) => value, electronBuilderConfig.files)
|
||||
matcher.prependPattern('**/*')
|
||||
const isPacked = matcher.createFilter()
|
||||
const stat = { isDirectory: () => false }
|
||||
for (const packageName of [
|
||||
'sherpa-onnx',
|
||||
'sherpa-onnx-darwin-arm64',
|
||||
'sherpa-onnx-darwin-x64',
|
||||
'sherpa-onnx-linux-arm64',
|
||||
'sherpa-onnx-linux-x64',
|
||||
'sherpa-onnx-win-x64'
|
||||
]) {
|
||||
expect(isPacked(`/app/node_modules/${packageName}/index.js`, stat)).toBe(false)
|
||||
}
|
||||
expect(isPacked('/app/node_modules/ws/index.js', stat)).toBe(true)
|
||||
})
|
||||
})
|
||||
-67
@@ -1,67 +0,0 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { join, resolve } from 'node:path'
|
||||
import { runInNewContext } from 'node:vm'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { parse } from 'yaml'
|
||||
|
||||
const projectDir = resolve(import.meta.dirname, '../../../..')
|
||||
const readProject = (file) => readFileSync(join(projectDir, file), 'utf8')
|
||||
|
||||
describe('Electron runtime package contract', () => {
|
||||
it('qualifies macOS after failed sibling builds and publishes only complete successful builds', () => {
|
||||
const { jobs } = parse(readProject('.github/workflows/release-cut.yml'))
|
||||
const evaluate = (source, needs, cancelled) =>
|
||||
runInNewContext(source.replace(/needs\.([a-z][a-z0-9-]*)/g, 'needs["$1"]'), {
|
||||
needs,
|
||||
cancelled: () => cancelled,
|
||||
contains: (value, part) => value.includes(part)
|
||||
})
|
||||
const results = ['success', 'failure', 'skipped', 'cancelled']
|
||||
for (const matrix of results) {
|
||||
for (const dispatch of results) {
|
||||
for (const verification of results) {
|
||||
for (const cancelled of [false, true]) {
|
||||
const needs = {
|
||||
cut: { result: 'success', outputs: { should_release: 'true', tag: 'v1.5.0' } },
|
||||
build: { result: matrix },
|
||||
'build-mac': { result: dispatch },
|
||||
'verify-mac-build': { result: verification },
|
||||
'skill-sharing-linux-floor-release-gate': { result: 'success' },
|
||||
'skill-sharing-release-gate': { result: 'success' },
|
||||
'terminal-rendering-golden': { result: 'success' }
|
||||
}
|
||||
expect(evaluate(jobs['verify-mac-build'].if, needs, cancelled)).toBe(
|
||||
!cancelled && dispatch === 'success'
|
||||
)
|
||||
expect(evaluate(jobs['publish-release'].if, needs, cancelled)).toBe(
|
||||
!cancelled &&
|
||||
matrix === 'success' &&
|
||||
dispatch === 'success' &&
|
||||
verification === 'success'
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const prerequisite of [
|
||||
'cut',
|
||||
'skill-sharing-linux-floor-release-gate',
|
||||
'skill-sharing-release-gate',
|
||||
'terminal-rendering-golden'
|
||||
]) {
|
||||
const needs = Object.fromEntries([
|
||||
['cut', { result: 'success', outputs: { should_release: 'true', tag: 'v1.5.0' } }],
|
||||
...[
|
||||
'build',
|
||||
'build-mac',
|
||||
'verify-mac-build',
|
||||
'skill-sharing-linux-floor-release-gate',
|
||||
'skill-sharing-release-gate',
|
||||
'terminal-rendering-golden'
|
||||
].map((name) => [name, { result: 'success' }])
|
||||
])
|
||||
needs[prerequisite].result = 'failure'
|
||||
expect(evaluate(jobs['publish-release'].if, needs, false)).toBe(false)
|
||||
}
|
||||
})
|
||||
})
|
||||
-39
@@ -1,46 +1,11 @@
|
||||
import { existsSync, realpathSync } from 'node:fs'
|
||||
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
|
||||
import { createRequire } from 'node:module'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { removeTree } from '../../../../src/shared/windows-transient-lock-removal.ts'
|
||||
import {
|
||||
runPackagedProcessHostConsumer,
|
||||
stagePackagedProcessHost,
|
||||
writePackagedProcessHostConsumer
|
||||
} from './packaged-process-host-fixture.mjs'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const {
|
||||
createPackagedRuntimeNodeModuleResources
|
||||
} = require('../../../packaged-runtime-node-modules.cjs')
|
||||
const {
|
||||
collectRuntimeClosure
|
||||
} = require('../../runtime-verification/skills-cli/verify-skills-cli-runtime.cjs')
|
||||
const nodeExecutable = process.env.ORCA_TEST_NODE_EXECUTABLE ?? process.execPath
|
||||
|
||||
it('loads the copied process package from an unpacked CLI without checkout dependencies', async () => {
|
||||
const resourcesDir = await mkdtemp(join(tmpdir(), 'orca-packaged-process-host-'))
|
||||
try {
|
||||
const resource = createPackagedRuntimeNodeModuleResources().find(
|
||||
(entry) => entry.to === join('node_modules', '@orca', 'process-host')
|
||||
)
|
||||
expect(resource).toBeDefined()
|
||||
expect(resource.filter).toEqual(['package.json', 'dist/**/*'])
|
||||
const packageDir = await stagePackagedProcessHost(resourcesDir)
|
||||
expect(existsSync(join(packageDir, 'src'))).toBe(false)
|
||||
|
||||
const { outDir, entry } = await writePackagedProcessHostConsumer(resourcesDir)
|
||||
const closure = collectRuntimeClosure(outDir, resourcesDir)
|
||||
expect(closure).toContain(realpathSync(join(packageDir, 'dist', 'run-process.js')))
|
||||
const result = runPackagedProcessHostConsumer(nodeExecutable, resourcesDir, entry)
|
||||
expect(result.code, result.stderr).toBe(0)
|
||||
expect(result.stdout).toBe('copied-runtime')
|
||||
} finally {
|
||||
await removeTree(resourcesDir)
|
||||
}
|
||||
})
|
||||
|
||||
describe('process-host output packaging guard', () => {
|
||||
const { assertProcessHostOutputBuilt } = require('../../../packaged-runtime-node-modules.cjs')
|
||||
@@ -77,10 +42,6 @@ describe('process-host output packaging guard', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('accepts the checkout package', () => {
|
||||
expect(() => assertProcessHostOutputBuilt()).not.toThrow()
|
||||
})
|
||||
|
||||
it.each([
|
||||
['a public export target', 'feature.js', /missing: \.\/dist\/feature\.js/],
|
||||
['an internal module', 'internal.js', /missing: \.\/dist\/internal\.js/]
|
||||
|
||||
-65
@@ -1,65 +0,0 @@
|
||||
import { existsSync } from 'node:fs'
|
||||
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
||||
import { createRequire } from 'node:module'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const electronBuilderConfig = require('../../../electron-builder.config.cjs')
|
||||
const { copyFiles, FileMatcher } = require('app-builder-lib/out/fileMatcher')
|
||||
|
||||
describe('packaged repository input exclusion', () => {
|
||||
it('omits repository build inputs while preserving runtime files', async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), 'orca-packaging-inputs-'))
|
||||
const source = join(root, 'app')
|
||||
const destination = join(root, 'selected')
|
||||
const cloudPaths = [
|
||||
'cloud/apps/relay/src/index.ts',
|
||||
'cloud/apps/push/src/app.test.ts',
|
||||
'cloud/infra/main.tf',
|
||||
'cloud/dev/scripts/deploy.mjs',
|
||||
'cloud/.env',
|
||||
'cloud/packages/push-contract/src/push-host-proof-vector.json'
|
||||
]
|
||||
const rootConfigs = [
|
||||
'.oxlintrc.json',
|
||||
'.oxfmtrc.json',
|
||||
'components.json',
|
||||
'opencode.json',
|
||||
'orca.yaml',
|
||||
'pnpm-workspace.yaml',
|
||||
'vite.web.config.ts'
|
||||
]
|
||||
const runtimePaths = [
|
||||
'LICENSE',
|
||||
'package.json',
|
||||
'out/main/index.js',
|
||||
'out/cli/index.js',
|
||||
'out/main/runtime/mobile-cloud-relay/index.js',
|
||||
'out/main/runtime/push/push-host-proof.js',
|
||||
'out/shared/mobile-push-contract.js',
|
||||
'out/renderer/index.html',
|
||||
'out/renderer/assets/cloud/client.js',
|
||||
'resources/configs/orca.yaml',
|
||||
'resources/cloud/icon.png'
|
||||
]
|
||||
try {
|
||||
for (const fixturePath of [...cloudPaths, ...rootConfigs, ...runtimePaths]) {
|
||||
const file = join(source, fixturePath)
|
||||
await mkdir(dirname(file), { recursive: true })
|
||||
await writeFile(file, fixturePath)
|
||||
}
|
||||
await copyFiles([
|
||||
new FileMatcher(source, destination, (value) => value, electronBuilderConfig.files)
|
||||
])
|
||||
expect(existsSync(join(destination, 'cloud'))).toBe(false)
|
||||
expect(rootConfigs.filter((file) => existsSync(join(destination, file)))).toEqual([])
|
||||
for (const runtimePath of runtimePaths) {
|
||||
expect(await readFile(join(destination, runtimePath), 'utf8')).toBe(runtimePath)
|
||||
}
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
})
|
||||
+1
-51
@@ -6,8 +6,7 @@ import { describe, expect, it } from 'vitest'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const {
|
||||
prunePackagedRuntimeTypeAndSourceMapArtifacts,
|
||||
prunePackagedRuntimeNodeModules
|
||||
prunePackagedRuntimeTypeAndSourceMapArtifacts
|
||||
} = require('../../../packaged-runtime-node-modules.cjs')
|
||||
|
||||
const LINEAR_SDK_PACKAGE_JSON =
|
||||
@@ -85,53 +84,4 @@ describe('packaged runtime type-declaration and source-map pruning', () => {
|
||||
await rm(resourcesDir, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
it('removes source maps from every packaged dependency, not just @linear/sdk', async () => {
|
||||
const resourcesDir = await mkdtemp(join(tmpdir(), 'orca-source-map-prune-all-'))
|
||||
try {
|
||||
const { jsYamlDir, nodePtyDir } = await createPackagedNodeModulesFixture(resourcesDir)
|
||||
|
||||
prunePackagedRuntimeTypeAndSourceMapArtifacts(resourcesDir)
|
||||
|
||||
await expect(readdir(jsYamlDir)).resolves.toEqual(['js-yaml.min.js'])
|
||||
await expect(readdir(nodePtyDir)).resolves.toEqual(['index.js'])
|
||||
} finally {
|
||||
await rm(resourcesDir, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
it('removes type declarations and declaration maps in the same walk', async () => {
|
||||
const resourcesDir = await mkdtemp(join(tmpdir(), 'orca-source-map-prune-dts-'))
|
||||
try {
|
||||
const { updaterDir } = await createPackagedNodeModulesFixture(resourcesDir)
|
||||
|
||||
prunePackagedRuntimeTypeAndSourceMapArtifacts(resourcesDir)
|
||||
|
||||
await expect(readdir(updaterDir)).resolves.toEqual(['main.js'])
|
||||
} finally {
|
||||
await rm(resourcesDir, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
it('runs the artifact prune through aggregate runtime cleanup', async () => {
|
||||
const resourcesDir = await mkdtemp(join(tmpdir(), 'orca-source-map-aggregate-prune-'))
|
||||
try {
|
||||
const { distDir, updaterDir, packageDir } =
|
||||
await createPackagedNodeModulesFixture(resourcesDir)
|
||||
|
||||
prunePackagedRuntimeNodeModules(resourcesDir, 'darwin', 'arm64')
|
||||
|
||||
await expect(readdir(distDir).then((entries) => entries.sort())).resolves.toEqual([
|
||||
'index.cjs',
|
||||
'index.mjs',
|
||||
'runtime-helper.cjs'
|
||||
])
|
||||
await expect(readdir(updaterDir)).resolves.toEqual(['main.js'])
|
||||
await expect(readFile(join(packageDir, 'metadata.json.map'), 'utf8')).resolves.toBe(
|
||||
'{"keep":true}'
|
||||
)
|
||||
} finally {
|
||||
await rm(resourcesDir, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
+1
-44
@@ -1,4 +1,3 @@
|
||||
import { existsSync } from 'node:fs'
|
||||
import { mkdir, mkdtemp, writeFile } from 'node:fs/promises'
|
||||
import { createRequire } from 'node:module'
|
||||
import { tmpdir } from 'node:os'
|
||||
@@ -7,19 +6,10 @@ import { describe, expect, it } from 'vitest'
|
||||
import { removeTree } from '../../../../src/shared/windows-transient-lock-removal.ts'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const { copyFiles, FileMatcher } = require('app-builder-lib/out/fileMatcher')
|
||||
const {
|
||||
createPackagedRuntimeNodeModuleResources
|
||||
} = require('../../../packaged-runtime-node-modules.cjs')
|
||||
const {
|
||||
RUNTIME_PACKAGE_EXCLUDED_FILES,
|
||||
assertNoWindowsExecutablesInRuntimeNodeModules,
|
||||
runtimePackageExcludeFilter
|
||||
assertNoWindowsExecutablesInRuntimeNodeModules
|
||||
} = require('../../../packaged-windows-only-runtime-files.cjs')
|
||||
|
||||
const ssh2Target = join('node_modules', 'ssh2')
|
||||
const { everyPlatform, nonWindows } = RUNTIME_PACKAGE_EXCLUDED_FILES.ssh2
|
||||
|
||||
async function withTempDir(prefix, run) {
|
||||
const dir = await mkdtemp(join(tmpdir(), prefix))
|
||||
try {
|
||||
@@ -29,13 +19,6 @@ async function withTempDir(prefix, run) {
|
||||
}
|
||||
}
|
||||
|
||||
// Apply electron-builder’s extraResources filter to real installed ssh2 and report surviving excluded files.
|
||||
async function copiedSsh2ExcludedFiles(resource, destinationRoot) {
|
||||
const destination = join(destinationRoot, resource.to)
|
||||
await copyFiles([new FileMatcher(resource.from, destination, (value) => value, resource.filter)])
|
||||
return [...everyPlatform, ...nonWindows].filter((file) => existsSync(join(destination, file)))
|
||||
}
|
||||
|
||||
function peImage() {
|
||||
const image = Buffer.alloc(0x80)
|
||||
image.write('MZ', 0, 'latin1')
|
||||
@@ -46,32 +29,6 @@ function peImage() {
|
||||
}
|
||||
|
||||
describe('Windows-only runtime files', () => {
|
||||
it.each(['darwin', 'linux'])('keeps ssh2 Pageant files out of the %s copy', async (platform) => {
|
||||
const resource = createPackagedRuntimeNodeModuleResources(platform).find(
|
||||
(entry) => entry.to === ssh2Target
|
||||
)
|
||||
// Why: the fixture must be the real package, so a bump that moves these files is noticed here.
|
||||
for (const file of [...everyPlatform, ...nonWindows]) {
|
||||
expect(existsSync(join(resource.from, file)), file).toBe(true)
|
||||
}
|
||||
expect(nonWindows).toContain('util/pagent.exe')
|
||||
await withTempDir('orca-ssh2-copy-', async (dir) => {
|
||||
expect(await copiedSsh2ExcludedFiles(resource, dir)).toEqual([])
|
||||
expect(existsSync(join(dir, ssh2Target, 'lib', 'agent.js'))).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps pagent.exe for Pageant on Windows but drops its build inputs', async () => {
|
||||
// Why the linux entry: the win32 plan resolves Windows-only addons absent on other hosts.
|
||||
const { from } = createPackagedRuntimeNodeModuleResources('linux').find(
|
||||
(entry) => entry.to === ssh2Target
|
||||
)
|
||||
const resource = { from, to: ssh2Target, filter: runtimePackageExcludeFilter('ssh2', 'win32') }
|
||||
await withTempDir('orca-ssh2-copy-win-', async (dir) => {
|
||||
expect(await copiedSsh2ExcludedFiles(resource, dir)).toEqual(nonWindows)
|
||||
})
|
||||
})
|
||||
|
||||
it('fails a non-Windows package that ships a Windows executable under any name', async () => {
|
||||
await withTempDir('orca-windows-exe-', async (resourcesDir) => {
|
||||
const nested = join(resourcesDir, 'node_modules', 'some-dep', 'bin')
|
||||
|
||||
-49
@@ -162,32 +162,6 @@ describe('External process-host development rebuilds', () => {
|
||||
await expect.poll(() => versions.at(-1), { timeout: 15_000 }).toBe(7)
|
||||
})
|
||||
|
||||
it('recompiles when a nested package manifest is created or removed', async () => {
|
||||
const { root, packageDir, main } = fixture()
|
||||
writeFileSync(join(packageDir, 'src', 'entry.ts'), 'export const version = 1\n')
|
||||
const watcher = watch({
|
||||
input: main,
|
||||
external: ['@orca/process-host'],
|
||||
plugins: [createProcessHostDevRebuildPlugin(root)],
|
||||
output: { file: join(root, 'out', 'main.cjs'), format: 'cjs' }
|
||||
})
|
||||
watchers.push(watcher)
|
||||
closeSuccessfulBundles(watcher)
|
||||
await nextEvent(watcher, 'END')
|
||||
const output = join(packageDir, 'dist', 'entry.js')
|
||||
expect(readFileSync(output, 'utf8')).toContain('exports.version')
|
||||
|
||||
const manifest = join(packageDir, 'src', 'package.json')
|
||||
writeFileSync(manifest, JSON.stringify({ type: 'module' }))
|
||||
await expect
|
||||
.poll(() => readFileSync(output, 'utf8'), { timeout: 15_000 })
|
||||
.toContain('export const')
|
||||
rmSync(manifest)
|
||||
await expect
|
||||
.poll(() => readFileSync(output, 'utf8'), { timeout: 15_000 })
|
||||
.toContain('exports.version')
|
||||
})
|
||||
|
||||
it('emits private source edits and new imports before the Electron reload hook', async () => {
|
||||
const { root, packageDir, main } = fixture()
|
||||
const loadedVersions: number[] = []
|
||||
@@ -224,29 +198,6 @@ describe('External process-host development rebuilds', () => {
|
||||
expect(readFileSync(join(packageDir, 'dist', 'new-feature.js'), 'utf8')).toContain('added = 3')
|
||||
})
|
||||
|
||||
it('rebuilds when an inherited compiler configuration changes', async () => {
|
||||
const { root, packageDir, main } = fixture()
|
||||
const watcher = watch({
|
||||
input: main,
|
||||
external: ['@orca/process-host'],
|
||||
plugins: [createProcessHostDevRebuildPlugin(root)],
|
||||
output: { file: join(root, 'out', 'main.cjs'), format: 'cjs' }
|
||||
})
|
||||
watchers.push(watcher)
|
||||
closeSuccessfulBundles(watcher)
|
||||
await nextEvent(watcher, 'END')
|
||||
const emittedSource = join(packageDir, 'dist', 'internal.js')
|
||||
expect(readFileSync(emittedSource, 'utf8')).toContain('preserved comment')
|
||||
|
||||
writeFileSync(
|
||||
join(root, 'tsconfig.base.json'),
|
||||
JSON.stringify({ compilerOptions: { strict: true, removeComments: true } })
|
||||
)
|
||||
await expect
|
||||
.poll(() => readFileSync(emittedSource, 'utf8'), { timeout: 15_000 })
|
||||
.not.toContain('preserved comment')
|
||||
})
|
||||
|
||||
it('reports a failed compilation, preserves prior output, and recovers after a fix', async () => {
|
||||
const { root, packageDir, main } = fixture()
|
||||
const loadedVersions: number[] = []
|
||||
|
||||
-103
@@ -36,17 +36,6 @@ describe('assertMobileWebBundleBuilt', () => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('accepts a freshly built bundle', async () => {
|
||||
await withBundle(({ bundleDir, manifest }) => {
|
||||
expect(() => assertMobileWebBundleBuilt(bundleDir)).not.toThrow()
|
||||
expect(manifest.entrypoint).toBe('index.html')
|
||||
expect(manifest.assets.length).toBeGreaterThanOrEqual(3)
|
||||
expect(
|
||||
new Set(manifest.assets.map((asset) => asset.contentType)).size
|
||||
).toBeGreaterThanOrEqual(2)
|
||||
})
|
||||
})
|
||||
|
||||
it('fails on a file the manifest does not list, so no stale asset ships inside asar', async () => {
|
||||
await withBundle(async ({ bundleDir }) => {
|
||||
// Dropped content-addressed assets never overwrite themselves; reject leftovers rather than pack unverified unreachable bytes.
|
||||
@@ -57,22 +46,6 @@ describe('assertMobileWebBundleBuilt', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('fails when the manifest is missing', async () => {
|
||||
const scratch = await mkdtemp(join(tmpdir(), 'orca-mobile-web-guard-'))
|
||||
try {
|
||||
expect(() => assertMobileWebBundleBuilt(scratch)).toThrow(/no bundle manifest/)
|
||||
} finally {
|
||||
await rm(scratch, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
it('fails when the manifest is not JSON', async () => {
|
||||
await withBundle(async ({ bundleDir }) => {
|
||||
await writeFile(join(bundleDir, 'manifest.json'), 'not json', 'utf8')
|
||||
expect(() => assertMobileWebBundleBuilt(bundleDir)).toThrow(/not valid JSON/)
|
||||
})
|
||||
})
|
||||
|
||||
it('fails when an asset is tampered with on disk', async () => {
|
||||
await withBundle(async ({ bundleDir, manifest }) => {
|
||||
const asset = manifest.assets.find((entry) => entry.path.endsWith('.js'))
|
||||
@@ -84,14 +57,6 @@ describe('assertMobileWebBundleBuilt', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('fails when an asset is truncated', async () => {
|
||||
await withBundle(async ({ bundleDir, manifest }) => {
|
||||
const asset = manifest.assets.find((entry) => entry.path.endsWith('.css'))
|
||||
await writeFile(join(bundleDir, asset.path), 'truncated', 'utf8')
|
||||
expect(() => assertMobileWebBundleBuilt(bundleDir)).toThrow(/bytes on disk, manifest says/)
|
||||
})
|
||||
})
|
||||
|
||||
it('fails when a listed asset was never written', async () => {
|
||||
await withBundle(async ({ bundleDir, manifest }) => {
|
||||
const asset = manifest.assets.find((entry) => entry.path.endsWith('.png'))
|
||||
@@ -100,44 +65,6 @@ describe('assertMobileWebBundleBuilt', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('fails when the manifest buildId no longer matches its asset list', async () => {
|
||||
await withBundle(async ({ bundleDir }) => {
|
||||
await rewriteManifest(bundleDir, (manifest) => {
|
||||
manifest.buildId = 'f'.repeat(64)
|
||||
})
|
||||
expect(() => assertMobileWebBundleBuilt(bundleDir)).toThrow(/does not match its asset list/)
|
||||
})
|
||||
})
|
||||
|
||||
it('fails on an unknown schemaVersion', async () => {
|
||||
await withBundle(async ({ bundleDir }) => {
|
||||
await rewriteManifest(bundleDir, (manifest) => {
|
||||
manifest.schemaVersion = 2
|
||||
})
|
||||
expect(() => assertMobileWebBundleBuilt(bundleDir)).toThrow(
|
||||
/unsupported manifest schemaVersion/
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it('fails when a required field is dropped', async () => {
|
||||
await withBundle(async ({ bundleDir }) => {
|
||||
await rewriteManifest(bundleDir, (manifest) => {
|
||||
delete manifest.desktopVersion
|
||||
})
|
||||
expect(() => assertMobileWebBundleBuilt(bundleDir)).toThrow(/desktopVersion is missing/)
|
||||
})
|
||||
})
|
||||
|
||||
it('fails when totalBytes disagrees with the asset list', async () => {
|
||||
await withBundle(async ({ bundleDir }) => {
|
||||
await rewriteManifest(bundleDir, (manifest) => {
|
||||
manifest.totalBytes += 1
|
||||
})
|
||||
expect(() => assertMobileWebBundleBuilt(bundleDir)).toThrow(/its assets sum to/)
|
||||
})
|
||||
})
|
||||
|
||||
it('refuses an asset path that escapes the bundle directory', async () => {
|
||||
await withBundle(async ({ bundleDir }) => {
|
||||
await rewriteManifest(bundleDir, (manifest) => {
|
||||
@@ -146,26 +73,9 @@ describe('assertMobileWebBundleBuilt', () => {
|
||||
expect(() => assertMobileWebBundleBuilt(bundleDir)).toThrow(/not a safe relative path/)
|
||||
})
|
||||
})
|
||||
|
||||
it('refuses a manifest whose entrypoint is not one of its assets', async () => {
|
||||
await withBundle(async ({ bundleDir }) => {
|
||||
await rewriteManifest(bundleDir, (manifest) => {
|
||||
manifest.entrypoint = 'index.html'
|
||||
manifest.assets = manifest.assets.filter((asset) => asset.path !== 'index.html')
|
||||
})
|
||||
expect(() => assertMobileWebBundleBuilt(bundleDir)).toThrow(/is not one of its assets/)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('electron-builder packaging wiring', () => {
|
||||
it('does not exclude the built bundle, so out/mobile-web ships like out/web', () => {
|
||||
const excludesBuiltBundle = electronBuilderConfig.files.some(
|
||||
(entry) => typeof entry === 'string' && entry.startsWith('!out/mobile-web')
|
||||
)
|
||||
expect(excludesBuiltBundle).toBe(false)
|
||||
})
|
||||
|
||||
it('verifies a dark page build, and refuses to package it', async () => {
|
||||
await withBundle(async ({ bundleDir }) => {
|
||||
const [marker] = darkBuildMarkers({ ORCA_SIDEBAR_INPUTS: 'main' })
|
||||
@@ -179,17 +89,4 @@ describe('electron-builder packaging wiring', () => {
|
||||
).toThrow(`${bundleDir} holds an ORCA_SIDEBAR_INPUTS=main build`)
|
||||
})
|
||||
})
|
||||
|
||||
it('verifies the bundle root it is given, not the repo one', async () => {
|
||||
// Injected root must reach verifier so unit tests can use scratch build without real out/.
|
||||
await withBundle(async ({ bundleDir }) => {
|
||||
await rm(join(bundleDir, 'manifest.json'))
|
||||
expect(() =>
|
||||
electronBuilderConfig.beforePack(
|
||||
{ electronPlatformName: process.platform, arch: process.arch === 'arm64' ? 3 : 1 },
|
||||
bundleDir
|
||||
)
|
||||
).toThrow(/no bundle manifest/)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
-312
@@ -1,312 +0,0 @@
|
||||
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'
|
||||
import { createRequire } from 'node:module'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { peImage } from '../../native-build/windows/windows-pe-image-fixture.mjs'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const {
|
||||
verifyPackagedConptyBreakawayMarker,
|
||||
verifyPackagedNodePtyJobOwnership,
|
||||
verifyPackagedWindowsNodePty
|
||||
} = require('./verify-packaged-node-pty-job-ownership.cjs')
|
||||
const {
|
||||
CYGWIN_BREAKAWAY_MARKER,
|
||||
NATIVE_HOST_JOB_MARKER
|
||||
} = require('../../native-build/node-addons/node-pty-job-ownership.cjs')
|
||||
|
||||
const fixtureDir = mkdtempSync(join(tmpdir(), 'packaged-node-pty-job-'))
|
||||
|
||||
/** A real enough addon: a machine field the arch check reads, and the marker. */
|
||||
function conptyImage({
|
||||
arch = 'x64',
|
||||
cygwinBreakawayDenied = true,
|
||||
nativeHostJobOwned = true
|
||||
} = {}) {
|
||||
return Buffer.concat([
|
||||
peImage({ arch }),
|
||||
cygwinBreakawayDenied ? CYGWIN_BREAKAWAY_MARKER : Buffer.alloc(0),
|
||||
nativeHostJobOwned ? NATIVE_HOST_JOB_MARKER : Buffer.alloc(0)
|
||||
])
|
||||
}
|
||||
|
||||
function writeAddon(name, options) {
|
||||
const path = join(fixtureDir, name)
|
||||
writeFileSync(path, conptyImage(options))
|
||||
return path
|
||||
}
|
||||
|
||||
/** A packaged resources tree carrying exactly the conpty.node files named. */
|
||||
function packagedResources(addons) {
|
||||
const resourcesDir = mkdtempSync(join(fixtureDir, 'resources-'))
|
||||
const nodePtyDir = join(resourcesDir, 'node_modules', 'node-pty')
|
||||
for (const [relativePath, options] of Object.entries(addons)) {
|
||||
const addonPath = join(nodePtyDir, ...relativePath.split('/'))
|
||||
mkdirSync(dirname(addonPath), { recursive: true })
|
||||
writeFileSync(addonPath, conptyImage(options))
|
||||
}
|
||||
return resourcesDir
|
||||
}
|
||||
|
||||
const CURRENT_ADDON = writeAddon('current.node', { cygwinBreakawayDenied: true })
|
||||
const PRE_MSYS_ADDON = writeAddon('pre-msys.node', { cygwinBreakawayDenied: false })
|
||||
|
||||
const PATCHED = {
|
||||
dir: '../build/Release/',
|
||||
module: {
|
||||
listJobProcessIds: () => [],
|
||||
terminateJob: () => true,
|
||||
assignCurrentProcessToJob: () => true,
|
||||
assignCurrentProcessToStrictJob: () => true
|
||||
}
|
||||
}
|
||||
|
||||
const packaged = (native, addonPath = CURRENT_ADDON) => ({
|
||||
platform: 'win32',
|
||||
loadNative: () => ({ native, addonPath })
|
||||
})
|
||||
|
||||
it('rejects a cross-host package whose addon predates strict native-host ownership', () => {
|
||||
const resourcesDir = packagedResources({
|
||||
'build/Release/conpty.node': { nativeHostJobOwned: false }
|
||||
})
|
||||
expect(() =>
|
||||
verifyPackagedWindowsNodePty(resourcesDir, 'x64', { hostPlatform: 'darwin' })
|
||||
).toThrow(/lacks strict native-host process ownership/)
|
||||
})
|
||||
|
||||
describe('verifyPackagedNodePtyJobOwnership', () => {
|
||||
it('accepts the packaged patched ConPTY binding', () => {
|
||||
expect(() => verifyPackagedNodePtyJobOwnership('resources', packaged(PATCHED))).not.toThrow()
|
||||
})
|
||||
|
||||
it('rejects a packaged upstream prebuild', () => {
|
||||
expect(() =>
|
||||
verifyPackagedNodePtyJobOwnership(
|
||||
'resources',
|
||||
packaged({ dir: '../prebuilds/win32-x64/', module: {} })
|
||||
)
|
||||
).toThrow(/missing listJobProcessIds, terminateJob, assignCurrentProcessToJob/)
|
||||
})
|
||||
|
||||
// Stale native cache can export all job functions while leaking MSYS children; packaging must inspect marker bytes.
|
||||
it('rejects a packaged build that predates the Cygwin/MSYS breakaway denial', () => {
|
||||
expect(() =>
|
||||
verifyPackagedNodePtyJobOwnership('resources', packaged(PATCHED, PRE_MSYS_ADDON))
|
||||
).toThrow(/predates the Cygwin\/MSYS job-breakaway denial/)
|
||||
})
|
||||
|
||||
it('requires the patched source-build directory', () => {
|
||||
expect(() =>
|
||||
verifyPackagedNodePtyJobOwnership(
|
||||
'resources',
|
||||
packaged({ ...PATCHED, dir: '../prebuilds/win32-x64/' })
|
||||
)
|
||||
).toThrow(/expected patched build\/Release/)
|
||||
})
|
||||
|
||||
it('does not load Windows natives for other targets', () => {
|
||||
const loadNative = vi.fn()
|
||||
verifyPackagedNodePtyJobOwnership('resources', { platform: 'linux', loadNative })
|
||||
expect(loadNative).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('verifyPackagedConptyBreakawayMarker', () => {
|
||||
// Normal same-arch source rebuild replaces prebuild, which pruning already removed.
|
||||
it('passes a package whose only ConPTY load path carries the denial', () => {
|
||||
const resourcesDir = packagedResources({ 'build/Release/conpty.node': {} })
|
||||
expect(() => verifyPackagedConptyBreakawayMarker(resourcesDir, 'x64')).not.toThrow()
|
||||
})
|
||||
|
||||
// Cross-host package may have only upstream prebuild because non-Windows cannot compile conpty; this is the MSYS-leaking candidate gate must reject.
|
||||
it('rejects an unpatched published prebuild and explains both host remedies', () => {
|
||||
const resourcesDir = packagedResources({
|
||||
'prebuilds/win32-x64/conpty.node': { cygwinBreakawayDenied: false }
|
||||
})
|
||||
const verify = () => verifyPackagedConptyBreakawayMarker(resourcesDir, 'x64')
|
||||
expect(verify).toThrow(/predates the Cygwin\/MSYS job-breakaway denial/)
|
||||
expect(verify).toThrow(
|
||||
/this package holds no node-pty source build at all[\s\S]*Otherwise package this Windows slice on a host that can/
|
||||
)
|
||||
expect(verify).toThrow(/If this IS a Windows x64 host, the rebuild did not leave one/)
|
||||
})
|
||||
|
||||
// Correct target-arch source build wins even if unused prebuild survives; blaming host would reject valid package.
|
||||
it('passes a cross-arch package whose build/Release really is the target arch', () => {
|
||||
const resourcesDir = packagedResources({
|
||||
'build/Release/conpty.node': { arch: 'arm64' },
|
||||
'prebuilds/win32-arm64/conpty.node': { arch: 'arm64', cygwinBreakawayDenied: false }
|
||||
})
|
||||
expect(() => verifyPackagedConptyBreakawayMarker(resourcesDir, 'arm64')).not.toThrow()
|
||||
})
|
||||
|
||||
// Wrong-arch source rebuild falls through to unpatched target prebuild.
|
||||
it('rejects a wrong-arch source build with the target rebuild command', () => {
|
||||
const resourcesDir = packagedResources({
|
||||
'build/Release/conpty.node': { arch: 'x64' },
|
||||
'prebuilds/win32-arm64/conpty.node': { arch: 'arm64', cygwinBreakawayDenied: false }
|
||||
})
|
||||
const verify = () => verifyPackagedConptyBreakawayMarker(resourcesDir, 'arm64')
|
||||
expect(verify).toThrow(/prebuilds[\\/]win32-arm64/)
|
||||
expect(verify).toThrow(
|
||||
/the source build beside it is the wrong architecture[\s\S]*machine 0x8664/
|
||||
)
|
||||
expect(verify).toThrow(/rebuild-native-deps\.mjs --platform=win32 --arch=arm64/)
|
||||
expect(verify).toThrow(/^(?![\s\S]*Package this Windows slice on such a host)[\s\S]*$/)
|
||||
})
|
||||
|
||||
it('rejects unloadable architectures and reports their machine values', () => {
|
||||
const resourcesDir = packagedResources({ 'build/Release/conpty.node': { arch: 'x64' } })
|
||||
const verify = () => verifyPackagedConptyBreakawayMarker(resourcesDir, 'arm64')
|
||||
expect(verify).toThrow(/the app can load none of them/)
|
||||
expect(verify).toThrow(/machine 0x8664[\s\S]*0xaa64/)
|
||||
})
|
||||
|
||||
it('calls a candidate that is not a PE image what it is', () => {
|
||||
const resourcesDir = packagedResources({})
|
||||
const addonPath = join(
|
||||
resourcesDir,
|
||||
'node_modules',
|
||||
'node-pty',
|
||||
'build',
|
||||
'Release',
|
||||
'conpty.node'
|
||||
)
|
||||
mkdirSync(dirname(addonPath), { recursive: true })
|
||||
writeFileSync(addonPath, Buffer.alloc(0x200))
|
||||
expect(() => verifyPackagedConptyBreakawayMarker(resourcesDir, 'x64')).toThrow(/not a PE image/)
|
||||
})
|
||||
|
||||
// Truncated/quarantined image resembles cross-arch build but re-running --arch is wrong remedy.
|
||||
it('does not blame --arch for a source build that is not a PE image', () => {
|
||||
const resourcesDir = packagedResources({
|
||||
'prebuilds/win32-x64/conpty.node': { cygwinBreakawayDenied: false }
|
||||
})
|
||||
const addonPath = join(
|
||||
resourcesDir,
|
||||
'node_modules',
|
||||
'node-pty',
|
||||
'build',
|
||||
'Release',
|
||||
'conpty.node'
|
||||
)
|
||||
mkdirSync(dirname(addonPath), { recursive: true })
|
||||
writeFileSync(addonPath, Buffer.alloc(0x200))
|
||||
expect(() => verifyPackagedConptyBreakawayMarker(resourcesDir, 'x64')).toThrow(
|
||||
/is not a PE image at all[\s\S]*truncated, empty or quarantined/
|
||||
)
|
||||
})
|
||||
|
||||
it('ignores a prebuild for an arch this slice will never load', () => {
|
||||
const resourcesDir = packagedResources({
|
||||
'build/Release/conpty.node': {},
|
||||
'prebuilds/win32-arm64/conpty.node': { arch: 'arm64', cygwinBreakawayDenied: false }
|
||||
})
|
||||
expect(() => verifyPackagedConptyBreakawayMarker(resourcesDir, 'x64')).not.toThrow()
|
||||
})
|
||||
|
||||
// Debug wins after unloadable Release and before prebuild; it is never pruned.
|
||||
it('resolves past a Release build the target cannot load', () => {
|
||||
const resourcesDir = packagedResources({
|
||||
'build/Release/conpty.node': { arch: 'x64' },
|
||||
'build/Debug/conpty.node': { arch: 'arm64', cygwinBreakawayDenied: false }
|
||||
})
|
||||
expect(() => verifyPackagedConptyBreakawayMarker(resourcesDir, 'arm64')).toThrow(
|
||||
/build[\\/]Debug/
|
||||
)
|
||||
})
|
||||
|
||||
// Stale source output needs local rebuild advice, distinct from cross-host upstream prebuild.
|
||||
it('tells a stale source build to rebuild, not to change hosts', () => {
|
||||
const resourcesDir = packagedResources({
|
||||
'build/Release/conpty.node': { cygwinBreakawayDenied: false }
|
||||
})
|
||||
expect(() => verifyPackagedConptyBreakawayMarker(resourcesDir, 'x64')).toThrow(
|
||||
/Rebuild node-pty from source/
|
||||
)
|
||||
})
|
||||
|
||||
// No loadable candidate means package has no ConPTY backend; gate must fail.
|
||||
it('rejects a package with no ConPTY backend and lists the searched paths', () => {
|
||||
const resourcesDir = packagedResources({})
|
||||
const verify = () => verifyPackagedConptyBreakawayMarker(resourcesDir, 'x64')
|
||||
expect(verify).toThrow(/no conpty\.node on any path its loader tries/)
|
||||
expect(verify).toThrow(/build[\\/]Release[\s\S]*build[\\/]Debug[\s\S]*prebuilds[\\/]win32-x64/)
|
||||
})
|
||||
|
||||
// Unreadable candidate used to pass; propagate read error instead of warning.
|
||||
it('fails rather than pass a candidate it cannot read', () => {
|
||||
const resourcesDir = packagedResources({})
|
||||
mkdirSync(join(resourcesDir, 'node_modules', 'node-pty', 'build', 'Release', 'conpty.node'), {
|
||||
recursive: true
|
||||
})
|
||||
expect(() => verifyPackagedConptyBreakawayMarker(resourcesDir, 'x64')).toThrow()
|
||||
})
|
||||
|
||||
it('accepts the electron-builder Arch enum the afterPack hook passes', () => {
|
||||
const resourcesDir = packagedResources({
|
||||
'prebuilds/win32-arm64/conpty.node': { arch: 'arm64' }
|
||||
})
|
||||
expect(() => verifyPackagedConptyBreakawayMarker(resourcesDir, 3)).not.toThrow()
|
||||
})
|
||||
|
||||
it('refuses a target arch no Windows slice ships', () => {
|
||||
const resourcesDir = packagedResources({ 'build/Release/conpty.node': {} })
|
||||
expect(() => verifyPackagedConptyBreakawayMarker(resourcesDir, 'ia32')).toThrow(
|
||||
/Unsupported packaged node-pty Windows architecture/
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('verifyPackagedWindowsNodePty', () => {
|
||||
const spies = () => ({ verifyMarker: vi.fn(), verifyExports: vi.fn() })
|
||||
|
||||
// Marker check must survive host gate: old else nesting skipped the very cross-host packages it protects.
|
||||
it.each([
|
||||
['a cross-platform host', { hostPlatform: 'darwin', canExecuteTargetArch: true }],
|
||||
['a cross-arch slice', { hostPlatform: 'win32', canExecuteTargetArch: false }],
|
||||
['both', { hostPlatform: 'linux', canExecuteTargetArch: false }],
|
||||
['neither', { hostPlatform: 'win32', canExecuteTargetArch: true }]
|
||||
])('checks the marker on %s', (_case, host) => {
|
||||
const { verifyMarker, verifyExports } = spies()
|
||||
verifyPackagedWindowsNodePty('resources', 'x64', { ...host, verifyMarker, verifyExports })
|
||||
expect(verifyMarker).toHaveBeenCalledWith('resources', 'x64')
|
||||
})
|
||||
|
||||
it('loads the addon for the export check only where that can work', () => {
|
||||
const { verifyMarker, verifyExports } = spies()
|
||||
verifyPackagedWindowsNodePty('resources', 'x64', {
|
||||
hostPlatform: 'win32',
|
||||
canExecuteTargetArch: true,
|
||||
verifyMarker,
|
||||
verifyExports
|
||||
})
|
||||
expect(verifyExports).toHaveBeenCalledWith('resources')
|
||||
})
|
||||
|
||||
it.each([
|
||||
['a cross-platform host', { hostPlatform: 'darwin', canExecuteTargetArch: true }],
|
||||
['a cross-arch slice', { hostPlatform: 'win32', canExecuteTargetArch: false }]
|
||||
])('skips the export check on %s', (_case, host) => {
|
||||
const { verifyMarker, verifyExports } = spies()
|
||||
verifyPackagedWindowsNodePty('resources', 'x64', { ...host, verifyMarker, verifyExports })
|
||||
expect(verifyExports).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
// Propagate marker verdict; swallowing it leaves gate running without enforcing anything.
|
||||
it('lets the marker verdict fail the package', () => {
|
||||
const verifyMarker = vi.fn(() => {
|
||||
throw new Error('predates the Cygwin/MSYS job-breakaway denial')
|
||||
})
|
||||
expect(() =>
|
||||
verifyPackagedWindowsNodePty('resources', 'x64', {
|
||||
hostPlatform: 'win32',
|
||||
canExecuteTargetArch: true,
|
||||
verifyMarker,
|
||||
verifyExports: vi.fn()
|
||||
})
|
||||
).toThrow(/predates the Cygwin\/MSYS job-breakaway denial/)
|
||||
})
|
||||
})
|
||||
-68
@@ -3,7 +3,6 @@ import { createRequire } from 'node:module'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { ORCAD_LOCAL_SERVE_SELECTION_ENTRY } from '../../../../src/shared/orcad-local-serve-selection'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const {
|
||||
@@ -47,54 +46,11 @@ const INDEX =
|
||||
'<link rel="stylesheet" href="./assets/web.css">'
|
||||
|
||||
describe('assertPackagedWebClient', () => {
|
||||
it('passes a package whose unpacked web client loads every file it names', () => {
|
||||
const resourcesDir = packagedResources({
|
||||
index: INDEX,
|
||||
assets: ['assets/web.js', 'assets/web.css']
|
||||
})
|
||||
expect(() => assertPackagedWebClient(resourcesDir)).not.toThrow()
|
||||
})
|
||||
|
||||
it('fails a package with no unpacked web-index.html', () => {
|
||||
expect(() => assertPackagedWebClient(packagedResources({}))).toThrow(/missing unpacked/)
|
||||
})
|
||||
|
||||
it('fails a package whose page loads a file that was not shipped', () => {
|
||||
const resourcesDir = packagedResources({ index: INDEX, assets: ['assets/web.js'] })
|
||||
expect(() => assertPackagedWebClient(resourcesDir)).toThrow(/assets\/web\.css/)
|
||||
})
|
||||
|
||||
it('fails a page that loads nothing, which is not a real build', () => {
|
||||
expect(() => assertPackagedWebClient(packagedResources({ index: '<html></html>' }))).toThrow(
|
||||
/references no/
|
||||
)
|
||||
})
|
||||
|
||||
it.each([
|
||||
null,
|
||||
{},
|
||||
['assets/web.js'],
|
||||
['web-index.html', 'index.html'],
|
||||
['web-index.html', 'assets/../private'],
|
||||
['web-index.html', 'assets//private'],
|
||||
['web-index.html', 'assets/./private'],
|
||||
['web-index.html', 'assets/a\\private'],
|
||||
['web-index.html', 'assets/private.js.map'],
|
||||
['web-index.html', '/assets/a'],
|
||||
['web-index.html', 'assets/a\0.js'],
|
||||
['web-index.html', 3]
|
||||
])('rejects malformed shared web manifests: %j', (files) => {
|
||||
const resourcesDir = packagedResources({
|
||||
index: INDEX,
|
||||
assets: ['assets/web.js', 'assets/web.css']
|
||||
})
|
||||
writeFileSync(
|
||||
join(resourcesDir, 'app.asar.unpacked/out/renderer/.orca-web-client-files.json'),
|
||||
JSON.stringify(files)
|
||||
)
|
||||
expect(() => assertPackagedWebClient(resourcesDir)).toThrow(/invalid web file manifest/)
|
||||
})
|
||||
|
||||
it('fails when a transitive worker is missing even though HTML assets exist', () => {
|
||||
const resourcesDir = packagedResources({
|
||||
index: INDEX,
|
||||
@@ -111,15 +67,6 @@ describe('assertPackagedWebClient', () => {
|
||||
)
|
||||
expect(() => assertPackagedWebClient(resourcesDir)).toThrow(/editor.worker.js/)
|
||||
})
|
||||
|
||||
it('fails when the CLI the web root resolves from is not unpacked', () => {
|
||||
const resourcesDir = packagedResources({
|
||||
index: INDEX,
|
||||
assets: ['assets/web.js', 'assets/web.css'],
|
||||
cli: false
|
||||
})
|
||||
expect(() => assertPackagedWebClient(resourcesDir)).toThrow(/no unpacked CLI/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('assertPackagedServeSelectionEntry', () => {
|
||||
@@ -134,21 +81,6 @@ describe('assertPackagedServeSelectionEntry', () => {
|
||||
return resourcesDir
|
||||
}
|
||||
|
||||
it('passes an unpacked entry whose relative requires are all unpacked', () => {
|
||||
const resourcesDir = packagedEntry({
|
||||
[`main/${ORCAD_LOCAL_SERVE_SELECTION_ENTRY}.js`]:
|
||||
'require("../chunks/a.js"); require("node:fs")',
|
||||
'main/chunks/a.js': 'require("./b"); require("../persistence")',
|
||||
'main/chunks/b.js': '',
|
||||
'main/persistence/index.js': ''
|
||||
})
|
||||
expect(() => assertPackagedServeSelectionEntry(resourcesDir)).not.toThrow()
|
||||
})
|
||||
|
||||
it('fails a package that left the entry inside app.asar (#27404)', () => {
|
||||
expect(() => assertPackagedServeSelectionEntry(packagedEntry({}))).toThrow(/missing unpacked/)
|
||||
})
|
||||
|
||||
it('fails when a chunk the entry reaches was not unpacked', () => {
|
||||
const resourcesDir = packagedEntry({
|
||||
[SERVE_SELECTION_ENTRY]: 'require("../chunks/a.js")',
|
||||
|
||||
-54
@@ -1,54 +0,0 @@
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { createRequire } from 'node:module'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { peImage } from '../../native-build/windows/windows-pe-image-fixture.mjs'
|
||||
|
||||
const { verifyPackagedWindowsAgentHook } = createRequire(import.meta.url)(
|
||||
'./verify-packaged-windows-agent-hook.cjs'
|
||||
)
|
||||
|
||||
const roots = []
|
||||
|
||||
function resourcesWith(image) {
|
||||
const resourcesDir = mkdtempSync(join(tmpdir(), 'orca-agent-hook-package-'))
|
||||
roots.push(resourcesDir)
|
||||
if (image) {
|
||||
mkdirSync(join(resourcesDir, 'bin'))
|
||||
writeFileSync(join(resourcesDir, 'bin', 'orca-agent-hook.exe'), image)
|
||||
}
|
||||
return resourcesDir
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
for (const root of roots.splice(0)) {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
describe('verifyPackagedWindowsAgentHook', () => {
|
||||
it('accepts a hook built for the packaged slice', () => {
|
||||
expect(() =>
|
||||
verifyPackagedWindowsAgentHook(resourcesWith(peImage({ arch: 'x64' })), 1)
|
||||
).not.toThrow()
|
||||
expect(() =>
|
||||
verifyPackagedWindowsAgentHook(resourcesWith(peImage({ arch: 'arm64' })), 3)
|
||||
).not.toThrow()
|
||||
})
|
||||
|
||||
it('refuses a missing hook instead of shipping the .cmd fallback silently', () => {
|
||||
expect(() => verifyPackagedWindowsAgentHook(resourcesWith(null), 1)).toThrow(
|
||||
'Missing packaged agent hook'
|
||||
)
|
||||
})
|
||||
|
||||
it('refuses a host-arch hook in a cross-built slice', () => {
|
||||
expect(() =>
|
||||
verifyPackagedWindowsAgentHook(resourcesWith(peImage({ arch: 'x64' })), 3)
|
||||
).toThrow('machine 0x8664')
|
||||
expect(() => verifyPackagedWindowsAgentHook(resourcesWith(Buffer.from('not a PE')), 1)).toThrow(
|
||||
'not a PE image'
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -1,51 +1,11 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { PNG } from 'pngjs'
|
||||
import {
|
||||
buildWindowsIcoFromPng,
|
||||
cropImage,
|
||||
findOpaqueBounds,
|
||||
resizeImage,
|
||||
squareWithMargin
|
||||
} from './trim-windows-icon-source.mjs'
|
||||
|
||||
const scriptDir = import.meta.dirname
|
||||
const projectDir = dirname(dirname(dirname(dirname(scriptDir))))
|
||||
const buildDir = join(projectDir, 'resources', 'build')
|
||||
|
||||
// Windows downscales largest frame, so match native fill rather than macOS safe-area’s ~83% (#5357).
|
||||
const MIN_GLYPH_FILL_FRACTION = 0.92
|
||||
|
||||
function largestIcoFrame(icoBuffer) {
|
||||
const count = icoBuffer.readUInt16LE(4)
|
||||
let best = null
|
||||
for (let i = 0; i < count; i++) {
|
||||
const entry = 6 + i * 16
|
||||
let width = icoBuffer.readUInt8(entry)
|
||||
if (width === 0) {
|
||||
width = 256
|
||||
}
|
||||
const byteLength = icoBuffer.readUInt32LE(entry + 8)
|
||||
const imageOffset = icoBuffer.readUInt32LE(entry + 12)
|
||||
if (!best || width > best.width) {
|
||||
best = { width, byteLength, imageOffset }
|
||||
}
|
||||
}
|
||||
return best
|
||||
}
|
||||
|
||||
function decodeIcoFrame(icoBuffer, frame) {
|
||||
const payload = icoBuffer.subarray(frame.imageOffset, frame.imageOffset + frame.byteLength)
|
||||
const isPng =
|
||||
payload[0] === 0x89 && payload[1] === 0x50 && payload[2] === 0x4e && payload[3] === 0x47
|
||||
if (!isPng) {
|
||||
throw new Error('Expected PNG-compressed ICO frame')
|
||||
}
|
||||
const png = PNG.sync.read(Buffer.from(payload))
|
||||
return { width: png.width, height: png.height, data: png.data }
|
||||
}
|
||||
|
||||
function glyphFillFraction(image) {
|
||||
const bounds = findOpaqueBounds(image)
|
||||
if (!bounds) {
|
||||
@@ -54,21 +14,6 @@ function glyphFillFraction(image) {
|
||||
return Math.max(bounds.width, bounds.height) / Math.max(image.width, image.height)
|
||||
}
|
||||
|
||||
describe('Windows ICO glyph fill', () => {
|
||||
it('committed resources/build/icon.ico fills the canvas', () => {
|
||||
const ico = readFileSync(join(buildDir, 'icon.ico'))
|
||||
const frame = decodeIcoFrame(ico, largestIcoFrame(ico))
|
||||
expect(glyphFillFraction(frame)).toBeGreaterThanOrEqual(MIN_GLYPH_FILL_FRACTION)
|
||||
})
|
||||
|
||||
it('regenerating from the macOS render fills the canvas', () => {
|
||||
const sourcePng = readFileSync(join(buildDir, 'icon.png'))
|
||||
const ico = buildWindowsIcoFromPng(sourcePng)
|
||||
const frame = decodeIcoFrame(ico, largestIcoFrame(ico))
|
||||
expect(glyphFillFraction(frame)).toBeGreaterThanOrEqual(MIN_GLYPH_FILL_FRACTION)
|
||||
})
|
||||
})
|
||||
|
||||
describe('trim pipeline', () => {
|
||||
function solidSquareWithInset(canvas, glyph) {
|
||||
const data = Buffer.alloc(canvas * canvas * 4)
|
||||
@@ -91,18 +36,6 @@ describe('trim pipeline', () => {
|
||||
expect(bounds).toEqual({ minX: 20, minY: 20, maxX: 79, maxY: 79, width: 60, height: 60 })
|
||||
})
|
||||
|
||||
it('crops to the glyph then re-squares with a small margin', () => {
|
||||
const image = solidSquareWithInset(100, 60)
|
||||
const cropped = cropImage(image, findOpaqueBounds(image))
|
||||
expect(cropped.width).toBe(60)
|
||||
expect(cropped.height).toBe(60)
|
||||
expect(cropped.data).toEqual(solidSquareWithInset(60, 60).data)
|
||||
const squared = squareWithMargin(cropped, 0.04)
|
||||
// Glyph (60) plus ~4% margin per side keeps it near-full-bleed.
|
||||
expect(glyphFillFraction(squared)).toBeGreaterThanOrEqual(0.9)
|
||||
expect(squared.width).toBe(squared.height)
|
||||
})
|
||||
|
||||
it('downscales without leaving the glyph undersized', () => {
|
||||
const image = solidSquareWithInset(256, 200)
|
||||
const filled = squareWithMargin(cropImage(image, findOpaqueBounds(image)))
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { getDevInstanceIdentity } from '../../../../src/main/startup/dev-instance-identity'
|
||||
import {
|
||||
DEV_BUNDLE_DISPLAY_NAME,
|
||||
getDevBundlePlistPatches,
|
||||
getDevHelperPlistPatches
|
||||
} from './dev-electron-bundle-identity.mjs'
|
||||
|
||||
const BRANCH_ENV_KEYS = [
|
||||
'ORCA_DEV_DOCK_TITLE',
|
||||
'ORCA_DEV_BRANCH',
|
||||
'ORCA_DEV_INSTANCE_LABEL',
|
||||
'ORCA_DEV_WORKTREE_NAME'
|
||||
] as const
|
||||
|
||||
/** Collect the patch set as it would be computed on a given branch. */
|
||||
function patchesUnder(dockTitle: string, branch: string) {
|
||||
// Restore env keys individually: replacing process.env loses Node’s string coercion and leaks a plain object into later worker tests.
|
||||
const saved = BRANCH_ENV_KEYS.map((key) => [key, process.env[key]] as const)
|
||||
Object.assign(process.env, {
|
||||
ORCA_DEV_DOCK_TITLE: dockTitle,
|
||||
ORCA_DEV_BRANCH: branch,
|
||||
ORCA_DEV_INSTANCE_LABEL: branch,
|
||||
ORCA_DEV_WORKTREE_NAME: branch
|
||||
})
|
||||
try {
|
||||
return [...getDevBundlePlistPatches(), ...getDevHelperPlistPatches()]
|
||||
} finally {
|
||||
for (const [key, value] of saved) {
|
||||
if (value === undefined) {
|
||||
delete process.env[key]
|
||||
} else {
|
||||
process.env[key] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describe('dev-electron-bundle-identity', () => {
|
||||
it('gives the dev app a legible display name so notifications are not just "Electron"', () => {
|
||||
const byKey = Object.fromEntries(
|
||||
getDevBundlePlistPatches().map((patch) => [patch.key, patch.value])
|
||||
)
|
||||
expect(byKey.CFBundleName).toBe(DEV_BUNDLE_DISPLAY_NAME)
|
||||
expect(byKey.CFBundleDisplayName).toBe(DEV_BUNDLE_DISPLAY_NAME)
|
||||
expect(DEV_BUNDLE_DISPLAY_NAME).not.toBe('Electron')
|
||||
})
|
||||
|
||||
it('keeps the bundle display name in step with the name safeStorage keys off', () => {
|
||||
// Keep fixed bundle name aligned with app.setName’s Keychain service identity.
|
||||
expect(DEV_BUNDLE_DISPLAY_NAME).toBe(getDevInstanceIdentity(true, {}).appName)
|
||||
})
|
||||
|
||||
it('produces byte-identical patches on two different branches', () => {
|
||||
// Compare full patches across branches: any signed Info.plist drift changes cdhash/Keychain ACL; substring denylists miss ordinary branch names.
|
||||
expect(patchesUnder('Orca: fix-login-crash', 'fix-login-crash')).toEqual(
|
||||
patchesUnder('Orca: perf-2', 'perf-2')
|
||||
)
|
||||
expect(patchesUnder('Orca: dev', 'main')).toEqual(
|
||||
patchesUnder('Orca: some-worktree @ feature/x', 'feature/x')
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -74,24 +74,6 @@ afterEach(() => {
|
||||
})
|
||||
|
||||
describe('renderer web client projection', () => {
|
||||
it('preserves existing minified bindings while producing runnable compact code', async () => {
|
||||
const root = createRendererFixture()
|
||||
writeFixtureFile(
|
||||
root,
|
||||
'out/renderer/assets/web-shared.js',
|
||||
'const Zq = [1, 2, 3]; export function nM() { return Zq.length; }'
|
||||
)
|
||||
const result = await projectFixture(root)
|
||||
expect(result.code, result.stderr).toBe(0)
|
||||
const code = readFileSync(join(root, 'out/web/assets/web-shared.js'), 'utf8')
|
||||
expect(code).toContain('function nM(')
|
||||
expect(code).not.toContain('[1, 2, 3]')
|
||||
const output = await import(
|
||||
`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`
|
||||
)
|
||||
expect(output.nM()).toBe(3)
|
||||
})
|
||||
|
||||
it('copies and minifies only the web dependency closure', async () => {
|
||||
const root = createRendererFixture()
|
||||
const result = await projectFixture(root)
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
redactTranscript,
|
||||
scanTranscriptForSecrets
|
||||
} from './pty-transcript-secret-scan.mjs'
|
||||
import { parseArgs, resizeMarker, resolveSpawn } from './capture-agent-pty-transcript.mjs'
|
||||
|
||||
describe('pty transcript secret scan', () => {
|
||||
it('finds the account row of a ready screen', () => {
|
||||
@@ -47,12 +46,6 @@ describe('pty transcript secret scan', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('claims a span once, so a token inside an email is not double-reported', () => {
|
||||
const email = 'longlivedaccountnamefortycharacterslongenough@corp.internal'
|
||||
const findings = scanTranscriptForSecrets(email)
|
||||
expect(findings).toMatchObject([{ kind: 'email', match: email, index: 0 }])
|
||||
})
|
||||
|
||||
it('passes a fixture that is already scrubbed, so "prove it is gone" can succeed', () => {
|
||||
const scrubbed = `uuuu@example.com\n${'X'.repeat(44)}`
|
||||
expect(scanTranscriptForSecrets(scrubbed)).toEqual([])
|
||||
@@ -95,63 +88,3 @@ describe('committed transcripts', () => {
|
||||
expect(findings, formatFindings(name, findings)).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('capture argv', () => {
|
||||
it('splits recorder options from the agent command', () => {
|
||||
const { options, command } = parseArgs([
|
||||
'--name',
|
||||
'antigravity-ready-personal-non-gemini',
|
||||
'--cols',
|
||||
'120',
|
||||
'--',
|
||||
'agy',
|
||||
'--model',
|
||||
'sonnet'
|
||||
])
|
||||
expect(options.name).toBe('antigravity-ready-personal-non-gemini')
|
||||
expect(options.cols).toBe(120)
|
||||
expect(command).toEqual(['agy', '--model', 'sonnet'])
|
||||
})
|
||||
|
||||
it('collects a multi-file scan list', () => {
|
||||
const { options } = parseArgs(['--scan', 'a.txt', 'b.txt', '--redact'])
|
||||
expect(options.scan).toEqual(['a.txt', 'b.txt'])
|
||||
expect(options.redact).toBe(true)
|
||||
})
|
||||
|
||||
it('collects repeatable mid-capture resizes', () => {
|
||||
const { options } = parseArgs([
|
||||
'--name',
|
||||
'codex-conpty-resize',
|
||||
'--resize-at',
|
||||
'3000:80x24',
|
||||
'--resize-at',
|
||||
'6000:140x40',
|
||||
'--',
|
||||
'codex'
|
||||
])
|
||||
expect(options.resizes).toEqual([
|
||||
{ atMs: 3000, cols: 80, rows: 24 },
|
||||
{ atMs: 6000, cols: 140, rows: 40 }
|
||||
])
|
||||
})
|
||||
|
||||
it('rejects a malformed resize', () => {
|
||||
expect(() => parseArgs(['--resize-at', '3000:80'])).toThrow(/--resize-at expects/)
|
||||
expect(() => parseArgs(['--resize-at', '3000:0x24'])).toThrow(/--resize-at expects/)
|
||||
})
|
||||
|
||||
it('marks a resize with XTWINOPS rows;cols, which the secret scan ignores', () => {
|
||||
const marker = resizeMarker(80, 24)
|
||||
expect(marker).toBe(`${String.fromCharCode(27)}[8;24;80t`)
|
||||
expect(scanTranscriptForSecrets(`before${marker}after`)).toEqual([])
|
||||
})
|
||||
|
||||
it('routes a Windows shim through cmd.exe, which node-pty cannot spawn directly', () => {
|
||||
expect(resolveSpawn(['agy.cmd', '--model', 'sonnet'])).toEqual(
|
||||
process.platform === 'win32'
|
||||
? { file: 'cmd.exe', args: ['/c', '"agy.cmd"', '--model', 'sonnet'] }
|
||||
: { file: 'agy.cmd', args: ['--model', 'sonnet'] }
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user