Files
ycode/scripts/runtime-bundle.test.mjs
T

41 lines
2.1 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import fs from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import { createRequire } from 'node:module'
import { digest, inventory, manifest, verifyRuntimeBundle } from './runtime-bundle.mjs'
import { transformRuntime } from './runtime-transform.mjs'
const require = createRequire(import.meta.url)
test('source lock uses reviewed official HTTPS endpoints and fixed digests', () => {
for (const r of manifest.runtimes) {
assert.ok(['nodejs.org','api.nuget.org','github.com'].includes(new URL(r.url).hostname))
assert.equal(new URL(r.url).protocol, 'https:')
assert.match(r.treeSha256, /^[a-f0-9]{64}$/)
assert.equal(Buffer.from(r.digest, r.digestEncoding).length, r.algorithm === 'sha512' ? 64 : 32)
}
})
test('inventory is deterministic and notices content changes', async () => {
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'ycode-inventory-'))
try {
await fs.writeFile(path.join(root, 'a'), 'one')
const first = digest(JSON.stringify(await inventory(root)))
assert.equal(first, digest(JSON.stringify(await inventory(root))))
await fs.writeFile(path.join(root, 'a'), 'two')
assert.notEqual(first, digest(JSON.stringify(await inventory(root))))
await assert.rejects(verifyRuntimeBundle(root), /Missing bundled/)
} finally { await fs.rm(root, { recursive:true, force:true }) }
})
test('Python convenience launcher is relocatable and uses module pip', async () => {
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'ycode-python-'))
try {
await transformRuntime('python', root)
assert.equal(await fs.readFile(path.join(root,'Scripts/pip.cmd'),'utf8'), '@echo off\r\n"%~dp0..\\python.exe" -m pip %*\r\n')
} finally { await fs.rm(root,{recursive:true,force:true}) }
})
test('packaging rejects wrong platform and wrong arch', async () => {
const beforePack = require('./runtime-before-pack.cjs')
await assert.rejects(beforePack({electronPlatformName:'win32',arch:3}), /Windows x64 only/)
await assert.rejects(beforePack({electronPlatformName:'linux',arch:1}), /Windows x64 only/)
})