Files
aiturk-hermes-ide/apps/desktop/scripts/build-native-watch-launcher.test.mjs
T

37 lines
2.0 KiB
JavaScript

import { test } from 'node:test'
import assert from 'node:assert/strict'
import { mkdtempSync, copyFileSync, readFileSync, writeFileSync, existsSync, rmSync } from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { compilerCommand, buildNativeWatchLauncher } from './build-native-watch-launcher.mjs'
const desktop = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
test('Windows and Linux hosts build the same Windows source with the required assembly', () => {
const input = { source: 'source with spaces.cs', output: 'output with spaces.exe' }
const win = compilerCommand({ ...input, platform: 'win32', env: { SystemRoot: 'D:/Windows' } })
const linux = compilerCommand({ ...input, platform: 'linux' })
assert.equal(win.command, 'D:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\csc.exe')
assert.equal(linux.command, 'mcs')
assert.deepEqual(win.args, linux.args)
assert.ok(linux.args.includes('/reference:System.Web.Extensions.dll'))
assert.equal(linux.args.at(-1), input.source)
assert.throws(() => compilerCommand({ ...input, platform: 'darwin' }), /not configured/)
})
test('real host compiler builds PE from source, and broken source fails without stale artifact', () => {
// Inside the source workspace, including on the mounted Linux CI fixture.
const home = mkdtempSync(path.join(desktop, '.native-watch-test-'))
try {
copyFileSync(path.join(desktop, 'assets/codex-bridge/NativeWatchBootstrap.cs'), path.join(home, 'NativeWatchBootstrap.cs'))
const exe = buildNativeWatchLauncher({ home })
const first = readFileSync(exe)
assert.equal(first.toString('ascii', 0, 2), 'MZ')
writeFileSync(exe, 'stale artifact')
buildNativeWatchLauncher({ home })
assert.equal(readFileSync(exe).toString('ascii', 0, 2), 'MZ')
writeFileSync(path.join(home, 'NativeWatchBootstrap.cs'), 'invalid C# source')
assert.throws(() => buildNativeWatchLauncher({ home }))
assert.equal(existsSync(exe), false)
} finally { rmSync(home, { recursive: true, force: true }) }
})