fix(hololake): harden immutable broadcast activation

This commit is contained in:
冰朔 2026-08-13 18:37:30 +08:00
commit aa3df05775
2 changed files with 47 additions and 6 deletions

View file

@ -5,7 +5,7 @@ import os from 'node:os'
import path from 'node:path'
import test from 'node:test'
import { createReleaseServer, loadRuntimeState } from '../server/release-broadcast/server.mjs'
import { createReleaseServer, isMainModule, loadRuntimeState } from '../server/release-broadcast/server.mjs'
const sha256 = (bytes) => crypto.createHash('sha256').update(bytes).digest('hex')
@ -32,10 +32,12 @@ function buildReleaseRoot() {
writeJson(path.join(releaseDirectory, 'HOLOLAKE-CODESIGN.json'), {
schema: 'hololake.platform-code-signature-receipt/v1',
state: 'DEVELOPER_ID_SIGNATURE_STRICT_AND_GATEKEEPER_ACCEPTED',
sourceCommit: '1'.repeat(40),
})
writeJson(path.join(releaseDirectory, 'HOLOLAKE-NOTARIZATION.json'), {
schema: 'hololake.apple-notarization-receipt/v1',
state: 'APPLE_NOTARIZATION_ACCEPTED_AND_STAPLED',
sourceCommit: '1'.repeat(40),
})
const broadcast = {
schema: 'hololake.release-broadcast/v1',
@ -67,6 +69,7 @@ function buildReleaseRoot() {
writeJson(path.join(releaseDirectory, 'pipeline-receipt.json'), {
schema: 'hololake.signed-release-pipeline-receipt/v1',
state: 'SIGNED_NOTARIZED_RELEASE_BROADCAST_READY_FOR_JD_CONTROLLER_UPLOAD',
sourceCommit: '1'.repeat(40),
broadcastSha256,
automaticUpload: false,
automaticActivation: false,
@ -80,6 +83,15 @@ function buildReleaseRoot() {
broadcastSha256,
pipelineReceiptRelativePath: 'releases/0.2.0/pipeline-receipt.json',
humanApprovalReceipt: 'GH-HUMAN-RELEASE-APPROVAL-001',
humanApprovalReceiptRelativePath: 'releases/0.2.0/human-approval.json',
})
writeJson(path.join(releaseDirectory, 'human-approval.json'), {
schema: 'hololake.release-broadcast-human-approval/v1',
state: 'HUMAN_APPROVED_EXACT_SIGNED_NOTARIZED_RELEASE',
approvalId: 'GH-HUMAN-RELEASE-APPROVAL-001',
releaseId: broadcast.releaseId,
version: broadcast.version,
broadcastSha256,
})
return { root, packageBytes }
}
@ -127,3 +139,15 @@ test('package tampering after pipeline output locks the whole release at startup
fs.appendFileSync(path.join(fixture.root, 'releases', '0.2.0', 'HoloLake.app.tar.gz'), 'tampered')
assert.equal(loadRuntimeState(fixture.root).state, 'LOCKED_INVALID_RELEASE_EVIDENCE')
})
test('a symlinked immutable current directory is recognized as the intended executable', () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'hololake-release-symlink-'))
const versionDirectory = path.join(root, 'immutable')
fs.mkdirSync(versionDirectory)
const source = fs.readFileSync(new URL('../server/release-broadcast/server.mjs', import.meta.url), 'utf8')
const copy = path.join(versionDirectory, 'server.mjs')
fs.writeFileSync(copy, source, { mode: 0o500 })
const current = path.join(root, 'current')
fs.symlinkSync(versionDirectory, current)
assert.equal(isMainModule(path.join(current, 'server.mjs'), new URL(`file://${copy}`)), true)
})