Files
bare-operating-system/packages/bare-os-coreutils/test/pkg-swarm-index-pathcap.test.mjs
T
Raven Scott 071edccfb3 Expand bounded awk/expr/test toward Issue 7; refresh man, profile 1.0.18,
posix matrix/dashboard, and syscalls/process_table schema alignment (v8).

Booter: replication_operator_sketch/corestore hints, HRPC allowlist tests,
Protomux cap channel 65536-byte bound + export, Wasm posix_profile_peek,
swarm-disk and security_posture docs.

Coreutils/kernel: pkg-swarm-index pathCapabilityEnvelopeVerify on get;
pathcap-verify --trusted failure hint; rebuild bins and sync seeder.

Docs: KERNEL_CONTRACT, kernel-extensions, capabilities index, environment
appendix (warm-cache tuning, cap channel, Wasm env), handbook observability,
vault threat model (multisig), developer-guide ctx/HRPC/Wasm, DOCUMENTATION
release-checklist note, release-checklist optional tier1 drift.

Changelog maintenance in bare-os-booter and bare-os-protocol.
2026-04-05 23:01:54 -04:00

96 lines
2.5 KiB
JavaScript

/**
* pkg-swarm-index path-capability envelope verify on `get`.
*/
import { readFile } from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import test from 'brittle'
import b4a from 'b4a'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor
async function loadBin() {
const runtime = await readFile(
path.join(__dirname, '../lib/runtime.js'),
'utf8'
)
let body = await readFile(
path.join(__dirname, '../src/pkg-swarm-index.js'),
'utf8'
)
body = body.replace(/\nexport \{ run \}\s*$/m, '\n')
return new AsyncFunction(
'ctx',
'argv',
`${runtime}\n${body}\nif (typeof run === 'function') return await run(ctx, argv)\n`
)
}
const sampleIndex = {
packages: {
'[email protected]': {
driveKey: 'a'.repeat(64),
manifestHash: 'b'.repeat(64),
pathCapabilityEnvelope: { stub: true }
}
}
}
test('pkg-swarm-index get adds pathCapabilityEnvelopeVerify when ctx hook exists', async (t) => {
const run = await loadBin()
const logs = []
const ctx = {
b4a,
exitCode: 0,
env: {},
vfs: {
async readFile(p) {
t.is(p, '/etc/bare-os/pkg-index.json')
return b4a.from(JSON.stringify(sampleIndex))
}
},
bareOsVerifyPathCapabilityEnvelope(env) {
return { ok: true, envelope: env }
},
console: {
log: (m) => logs.push(String(m)),
error: (m) => logs.push(String(m))
}
}
await run(ctx, ['pkg-swarm-index', 'get', '[email protected]'])
t.is(ctx.exitCode, 0)
const out = JSON.parse(logs[0])
t.ok(out.pathCapabilityEnvelopeVerify)
t.is(out.pathCapabilityEnvelopeVerify.ok, true)
})
test('pkg-swarm-index get captures verify errors in pathCapabilityEnvelopeVerify', async (t) => {
const run = await loadBin()
const logs = []
const ctx = {
b4a,
exitCode: 0,
env: {},
vfs: {
async readFile() {
return b4a.from(JSON.stringify(sampleIndex))
}
},
bareOsVerifyPathCapabilityEnvelope() {
throw new Error('bad envelope')
},
console: {
log: (m) => logs.push(String(m)),
error: (m) => logs.push(String(m))
}
}
await run(ctx, ['pkg-swarm-index', 'get', '[email protected]'])
t.is(ctx.exitCode, 0)
const out = JSON.parse(logs[0])
t.ok(out.pathCapabilityEnvelopeVerify)
t.is(out.pathCapabilityEnvelopeVerify.ok, false)
t.ok(String(out.pathCapabilityEnvelopeVerify.error).includes('bad envelope'))
})