Files
Reims-Go/scripts/test.mjs
T
千川白浪 e0ff794b0e feat: add experimental macOS desktop support on Apple Silicon (#207)
* feat: add experimental Apple Silicon support with Nivfold

Integrate the standalone Nivfold protocol 1 runner; tested against Nivfold f436fb6. The Windows Reims vGPU runtime remains independent.

* fix: open QQ invites and VM SSH on macOS

* fix: move VM, View and Help to the macOS menu bar

* feat(macos): add resumable Apple restore image downloads

Expose the compatible restore image in the VM wizard and Images page, validate downloads before caching, and fix macOS memory reporting and plugin SVG rendering.

* fix(macos): localize the native application menu

* fix(macos): address native desktop review findings
2026-12-06 00:47:07 +08:00

136 lines
5.7 KiB
JavaScript

#!/usr/bin/env node
import { spawn } from 'node:child_process'
import fs from 'node:fs'
import { availableParallelism } from 'node:os'
import path from 'node:path'
import { cachePath, REPO_ROOT, resolveStorageRoot } from './debug/paths.mjs'
import { createTemporaryFiles } from './debug/temporary-files.mjs'
const frontend = path.join(REPO_ROOT, 'frontend')
const goTrees = ['./internal/...', './pkg/...', './scripts/...']
const ciTests = fs.readdirSync(path.join(REPO_ROOT, 'scripts', 'ci'))
.filter((name) => name.endsWith('.test.mjs'))
.sort()
.map((name) => path.join('scripts', 'ci', name))
const hostInputs = [
'REIMS_GO_TEST_CTL', 'REIMS_GO_TEST_QEMU_IMG', 'REIMS_GO_TEST_OPENCORE', 'REIMS_GO_TEST_OFFLINE_IMG',
]
const usage = `Usage: node scripts/test.mjs <profile>
quick go ./internal/<package> [./pkg/<package> ...]
quick frontend | storage | tooling | automation
ci
release
webview2 <windows-executable>
applevz <macos-helper>
Set REIMS_TEST_JOBS to cap Go package concurrency (default: at most 4).`
function run(label, command, args, env, cwd = REPO_ROOT) {
console.log(`[test] ${label}`)
return new Promise((resolve, reject) => {
const child = spawn(command, args, { cwd, env, stdio: 'inherit' })
child.once('error', reject)
child.once('close', (code, signal) => {
if (code === 0) resolve()
else reject(new Error(`${label} failed (${signal ?? `exit ${code}`})`))
})
})
}
function select(args) {
const [profile, area, ...packages] = args
if ((profile === 'ci' || profile === 'release') && args.length === 1) return { profile }
if ((profile === 'webview2' || profile === 'applevz') && args.length === 2) return { profile, executable: path.resolve(area) }
if (profile !== 'quick') throw new Error(usage)
if (area === 'go' && packages.length > 0) {
for (const pkg of packages) {
if (!/^\.\/(?:[\w-]+\/)*[\w-]+$/.test(pkg)) {
throw new Error(`Invalid Go package ${pkg}. Use a path such as ./internal/config.`)
}
const directory = path.join(REPO_ROOT, pkg)
if (!fs.statSync(directory, { throwIfNoEntry: false })?.isDirectory()) {
throw new Error(`Go package directory does not exist: ${pkg}`)
}
}
return { profile, area, packages }
}
if (['frontend', 'storage', 'tooling', 'automation'].includes(area) && packages.length === 0) return { profile, area }
throw new Error(usage)
}
async function main(args) {
if (args[0] === '--help' || args[0] === '-h') return console.log(usage)
const { profile, area, packages, executable } = select(args)
const jobs = Number(process.env.REIMS_TEST_JOBS ?? Math.min(4, availableParallelism()))
if (!Number.isSafeInteger(jobs) || jobs < 1) throw new Error('REIMS_TEST_JOBS must be a positive integer')
const root = resolveStorageRoot()
const files = createTemporaryFiles(root)
const directory = files.create('test', process.pid)
const started = performance.now()
console.log(`[test] ${profile}${area ? ` ${area}` : ''} in ${directory}`)
try {
const env = {
...process.env,
TEMP: directory,
TMP: directory,
TMPDIR: directory,
GOTMPDIR: directory,
GOCACHE: cachePath(root, 'go-build'),
GOMAXPROCS: String(jobs),
REIMS_TMP_DIR: directory,
REIMS_GO_DATA_ROOT: path.join(directory, 'data'),
REIMS_GO_LOCATION_FILE: path.join(directory, 'location.json'),
REIMS_GO_FIRST_RUN: '',
REIMS_CTL_CONFIG_DIR: path.join(directory, 'ctl-config'),
REIMS_CTL_DATA_DIR: path.join(directory, 'ctl-data'),
}
for (const key of hostInputs) env[key] = ''
const go = (targets, flags = []) => run('Go', 'go', ['test', '-timeout=5m', `-p=${jobs}`, ...flags, ...targets], env)
const front = (script) => run(`Frontend ${script}`, process.execPath, ['--run', script], env, frontend)
const tooling = () => run('Tooling', process.execPath, ['--test', 'scripts/debug/debug.test.mjs'], env)
const automation = () => run('GitHub automation', process.execPath, ['--test', ...ciTests], env)
if (profile === 'webview2') {
if (process.platform !== 'win32') throw new Error('WebView2 smoke requires Windows')
await run('WebView2 first launch', 'powershell.exe', [
'-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-File', 'scripts/smoke-webview2.ps1', executable,
], env)
} else if (profile === 'applevz') {
if (process.platform !== 'darwin' || process.arch !== 'arm64') throw new Error('Apple Virtualization smoke requires Apple silicon')
await run('Apple Virtualization signature', 'codesign', ['--verify', '--strict', executable], env)
await run('Nivfold runtime protocol', process.execPath, ['scripts/check-nivfold.mjs', executable], env)
} else if (profile === 'quick') {
if (area === 'go') await go(packages)
if (area === 'storage') {
await go(['./internal/config', './internal/dataroot', './internal/datamigrate'])
await go(['./internal/plugin'], ['-run=^TestStateStore'])
}
if (area === 'frontend') await front('test')
if (area === 'tooling') await tooling()
if (area === 'automation') await automation()
} else {
await front('test')
await front('typecheck')
const flags = profile === 'release' ? ['-count=1', '-shuffle=on', '-tags=desktop,production'] : []
await go(goTrees, ['-vet=all', ...flags])
await tooling()
await automation()
}
files.close(directory)
console.log(`[test] PASS in ${((performance.now() - started) / 1000).toFixed(2)}s`)
} catch (error) {
console.error(`[test] Evidence kept in ${directory}`)
throw error
}
}
try {
await main(process.argv.slice(2))
} catch (error) {
console.error(`[test] ${error.message}`)
process.exitCode = 1
}