Files
archived-orca/config/scripts/desktop-distribution/runtime-verification/electron-builder-runtime-resources.test.mjs
T

76 lines
3.3 KiB
JavaScript

import { mkdir, mkdtemp, readFile, 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/file-write/windows-transient-lock-removal.ts'
const require = createRequire(import.meta.url)
const {
prunePackagedNodePty,
verifyPackagedMainRuntimeDeps
} = require('../../../packaged-runtime-node-modules.cjs')
describe('packaged runtime resources', () => {
it('verifies bare imports that rolldown hoisted into a shared main chunk', async () => {
const resourcesDir = await mkdtemp(join(tmpdir(), 'orca-runtime-chunk-imports-'))
try {
await writeFile(join(resourcesDir, 'app.asar'), '', 'utf8')
// The entry points themselves carry no specifier; only the shared chunk does.
const sources = new Map([
['out/main/index.js', ''],
['out/main/agent-hooks/installation/managed-agent-hook-controls.js', ''],
['out/main/chunks/managed-agent-hook-controls-CWf8D-KR.js', 'require(`jsonc-parser`)']
])
// listPackage includes directories that extractFile rejects; mock them to enforce the .js anchor.
const directories = ['/out', '/out/main', '/out/main/chunks']
const asar = {
listPackage: () => [...directories, ...[...sources.keys()].map((entry) => `/${entry}`)],
extractFile: (_asarPath, internalPath) => {
const source = sources.get(internalPath)
if (source === undefined) {
throw new Error(`Expected to find file at: ${internalPath} but found a directory`)
}
return Buffer.from(source, 'utf8')
}
}
expect(() => verifyPackagedMainRuntimeDeps(resourcesDir, asar)).toThrow(/jsonc-parser/)
await mkdir(join(resourcesDir, 'node_modules', 'jsonc-parser'), { recursive: true })
expect(() => verifyPackagedMainRuntimeDeps(resourcesDir, asar)).not.toThrow()
} finally {
await removeTree(resourcesDir)
}
})
it('copies the Windows node-pty ConPTY runtime beside the rebuilt addon', async () => {
const resourcesDir = await mkdtemp(join(tmpdir(), 'orca-node-pty-conpty-arm64-'))
try {
const nodePtyDir = join(resourcesDir, 'node_modules', 'node-pty')
const releaseDir = join(nodePtyDir, 'build', 'Release')
const conptyRoot = join(nodePtyDir, 'third_party', 'conpty', '0.1.0')
await mkdir(releaseDir, { recursive: true })
await writeFile(join(releaseDir, 'conpty.node'), 'native addon placeholder', 'utf8')
for (const sourceArch of ['x64', 'arm64']) {
const sourceDir = join(conptyRoot, `win10-${sourceArch}`)
await mkdir(sourceDir, { recursive: true })
await writeFile(join(sourceDir, 'conpty.dll'), `dll payload ${sourceArch}`, 'utf8')
await writeFile(join(sourceDir, 'OpenConsole.exe'), `console payload ${sourceArch}`, 'utf8')
}
prunePackagedNodePty(resourcesDir, 'win32', 3)
await expect(readFile(join(releaseDir, 'conpty', 'conpty.dll'), 'utf8')).resolves.toBe(
'dll payload arm64'
)
await expect(readFile(join(releaseDir, 'conpty', 'OpenConsole.exe'), 'utf8')).resolves.toBe(
'console payload arm64'
)
} finally {
await removeTree(resourcesDir)
}
})
})