Files
bare-operating-system/scripts/verify-posix-compliance-matrix.mjs
T
2026-08-18 18:11:34 -04:00

98 lines
3.0 KiB
JavaScript

#!/usr/bin/env node
/**
* CI: posix-compliance-matrix.json profileId matches protocol POSIX profile export;
* kernel syscalls.example.json ctxApiVersion matches bare-os-ctx-api.js.
*/
import fs from 'node:fs'
import path from 'node:path'
import process from 'node:process'
import { fileURLToPath } from 'node:url'
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
const matrixPath = path.join(root, 'docs/reference/posix-compliance-matrix.json')
const syscallEx = path.join(root, 'kernel/etc/bare-os/syscalls.example.json')
const ctxApiPath = path.join(
root,
'packages/bare-os-booter/lib/ctx/bare-os-ctx-api.js'
)
const protoPath = path.join(
root,
'packages/bare-os-protocol/lib/bare-os-posix-profile.js'
)
const syscallsProcSrc = path.join(
root,
'packages/bare-os-booter/lib/posix/bare-os-syscalls-proc-json.js'
)
const processTableSrc = path.join(
root,
'packages/bare-os-booter/lib/proc/bare-os-process-table.js'
)
function main() {
const matrix = JSON.parse(fs.readFileSync(matrixPath, 'utf8'))
const protoSrc = fs.readFileSync(protoPath, 'utf8')
const idM = protoSrc.match(/BARE_OS_POSIX_PROFILE_ID\s*=\s*['"]([^'"]+)['"]/)
const id = idM ? idM[1] : null
if (!id || matrix.profileId !== id) {
console.error(
'verify-posix-compliance-matrix: profileId mismatch matrix vs protocol',
matrix.profileId,
id
)
process.exit(1)
}
const sc = JSON.parse(fs.readFileSync(syscallEx, 'utf8'))
const ctxSrc = fs.readFileSync(ctxApiPath, 'utf8')
const verM = ctxSrc.match(
/BARE_OS_CTX_API_VERSION\s*=\s*['"]([0-9.]+)['"]/
)
const ver = verM ? verM[1] : null
if (!ver || sc.ctxApiVersion !== ver) {
console.error(
'verify-posix-compliance-matrix: syscalls.example ctxApiVersion mismatch',
sc.ctxApiVersion,
ver
)
process.exit(1)
}
if (
matrix.synthetic_proc?.syscalls_json_schema !== sc.schemaVersion
) {
console.error(
'verify-posix-compliance-matrix: matrix syscalls schema vs example',
matrix.synthetic_proc?.syscalls_json_schema,
sc.schemaVersion
)
process.exit(1)
}
const procJson = fs.readFileSync(syscallsProcSrc, 'utf8')
const procSch = procJson.match(/schemaVersion:\s*(\d+)/)
const procVer = procSch ? Number(procSch[1]) : null
if (procVer !== sc.schemaVersion) {
console.error(
'verify-posix-compliance-matrix: bare-os-syscalls-proc-json schemaVersion vs syscalls.example',
procVer,
sc.schemaVersion
)
process.exit(1)
}
const ptSrc = fs.readFileSync(processTableSrc, 'utf8')
const ptSch = ptSrc.match(/schemaVersion:\s*(\d+)/)
const ptVer = ptSch ? Number(ptSch[1]) : null
if (
ptVer != null &&
matrix.synthetic_proc?.process_table_schema != null &&
ptVer !== matrix.synthetic_proc.process_table_schema
) {
console.error(
'verify-posix-compliance-matrix: process_table schema vs matrix',
ptVer,
matrix.synthetic_proc.process_table_schema
)
process.exit(1)
}
console.log('verify-posix-compliance-matrix: OK')
}
main()