hololake-system-architecture/product-source/hololake-platform/scripts/internal-release-provenance.test.mjs

77 lines
2.4 KiB
JavaScript

import assert from 'node:assert/strict'
import test from 'node:test'
import {
buildInternalReleaseProvenance,
validateInternalReleaseProvenance,
} from './internal-release-provenance.mjs'
const sourceCommit = '1'.repeat(40)
const sourceTree = '2'.repeat(40)
function input(overrides = {}) {
return {
sourceCommit,
sourceTree,
sourceBranch: 'main',
sourceRepository: 'repo://guanghulab.com/code/bingshuo/hololake-system-architecture',
sourceRepositoryId: 'REPO-014',
sourcePath: 'product-source/hololake-platform',
architectureId: 'HLP-CURRENT-ARCH-001',
architectureVersion: '2026-08-12.16',
applicationVersion: '0.4.6',
developmentId: 'DEV-20260811-010',
distribution: 'local-candidate',
targetTriple: 'aarch64-apple-darwin',
recordedAt: '2026-08-12T07:00:00+08:00',
worktreeClean: true,
...overrides,
}
}
test('builds a source-bound local candidate provenance record', () => {
assert.deepEqual(buildInternalReleaseProvenance(input()), {
schema: 'hololake.internal-release-provenance/v1',
architecture: {
id: 'HLP-CURRENT-ARCH-001',
version: '2026-08-12.16',
},
build: {
application_version: '0.4.6',
development_id: 'DEV-20260811-010',
distribution: 'local-candidate',
recorded_at: '2026-08-12T07:00:00+08:00',
target_triple: 'aarch64-apple-darwin',
},
source: {
branch: 'main',
commit: sourceCommit,
path: 'product-source/hololake-platform',
repository: 'repo://guanghulab.com/code/bingshuo/hololake-system-architecture',
repository_id: 'REPO-014',
tree: sourceTree,
worktree_clean: true,
},
})
})
test('refuses to issue provenance for a dirty source tree', () => {
assert.throws(
() => buildInternalReleaseProvenance(input({ worktreeClean: false })),
/clean source worktree/,
)
})
test('validates exact source, architecture, application and development bindings', () => {
const provenance = buildInternalReleaseProvenance(input())
assert.equal(validateInternalReleaseProvenance(provenance, input()), true)
assert.throws(
() => validateInternalReleaseProvenance(provenance, input({ sourceCommit: '3'.repeat(40) })),
/source commit mismatch/,
)
assert.throws(
() => validateInternalReleaseProvenance(provenance, input({ architectureVersion: '2026-08-12.17' })),
/architecture version mismatch/,
)
})