test(protocol): add deterministic MBR failover-key coverage docs(protocol): align package-bare-os-protocol version to 0.9.1 test(booter): add MBR corruption and wrong-topic smoke fixtures test(peer-seed): add strict pre-MBR bare_os.capabilities negotiation check feat(seeder): validate BARE_OS_SEED_REQUIRE_MBR_LABELS feat(seeder): validate BARE_OS_SEED_CAPABILITY_ATTESTATION_JSON schema docs(boot-policy): add requireProtocolPackageMin 0.9.1 example test(kernel): cover boot.policy denySeedRpcMethods behavior test(protocol): add app/cap/chat/meshdrop channel compatibility fixture test(swarm-disk): cover duplicate Protomux channel null-return path test(protocol): add 11-word kernelCapabilityWords round-trip fixture docs(schema): add mbr-layout schema and validate seeder examples test(protocol): add topicKey() golden hash fixture docs(trust): document block-0 trust assumptions in boot docs feat(seeder): add discovery.flushed readiness logging feat(booter): record peer discovery timings in boot-perf.json feat(integration): add local testnet mode to integration lab smoke test(booter): add Hyperswarm connection-budget env regression coverage test(booter): add swarm plus Corestore suspend/resume integration coverage feat(booter): mirror swarm ban events into host audit logs feat(booter): add direct-peer boot via BARE_OS_BOOT_JOIN_PEER_HEX feat(seeder): pass BARE_OS_SEED_MAX_PEERS to Hyperswarm feat(seeder): log drive.version and discoveryKey at startup test(booter): add Hyperdrive.checkout read-only boot probe coverage feat(booter): prefetch /boot/init.js before kernel handoff feat(booter): add optional /bin warm replication via downloadDiff feat(seeder): add manifestPaths SHA-256 generation in stage-kernel-tree test(peer-seed): cover helper-served block-0 after seeder exit feat(protocol): add Protomux cork batching for initial channel sends test(boot-graph): compare kernel/init labels with booter graph proc docs(boot-policy): add v9-v11 schema examples feat(release): add requireInitJsSha256 fixture generation step test(vfs): add BARE_OS_VFS_SYSTEM_RO_ALIAS coverage test(vfs): strengthen system-drive write-deny path coverage feat(identity): add personal-drive namespace export/import docs and tests test(booter): add guest-to-login warm cache invalidation regression test(vfs): add guest deny coverage for /.bare sensitive paths test(coreutils): add cross-drive mv failure injection coverage test(vfs): add .bareos_empty round-trip coverage across mkdir/rmdir/cp/git-fs test(vfs): add /dev/shm quota enforcement coverage test(proc): add /proc/bare_os/index.json sortedness and schema checks test(vfs): add warm read cache invalidation on replication growth docs(ctx): document bareOsInvalidateWarmReadCaches(reason) test(kernel): add BARE_OS_BOOT_DRY_RUN behavior coverage docs(posix): add dashboard rows for all COREUTILS_COMMANDS feat(curl): expand -w variables beyond http_code/url_effective/size_download feat(wget): mark -N timestamping as explicit unsupported error feat(curl): plumb mutual TLS cert/key intent to ctx.httpFetch metadata feat(shuf): add deterministic seed mode via BARE_OS_SHUF_SEED docs(sort): document -M month-sort as unsupported feat(grep): add explicit -E and -G mode handling test(sed): add Open Group Issue 7 golden fixtures test(awk): add getline VFS regressions for missing/repeat/boundary cases test(shell): add non-interactive here-doc coverage test(shell): add trap delivery coverage for synthetic PIDs/job IDs test(shell): add set -e compound-body behavior coverage docs(shell): strengthen read builtin opt-in guidance test(env): add Bare-runtime coverage for -S and --env-file docs(man): add examples for pathcap-verify pkg-swarm-index corestorectl test(identity): add account/vault backup-restore smoke coverage feat(audit): add tamper detection verification for audit chain rows test(peer-admission): cover strict empty allowlist deny behavior test(peer-admission): add denylist precedence over allowlist coverage test(peer-admission): add BARE_OS_PEER_REQUIRE_CAPS_JSON metadata checks docs(identity): add trusted-key rotation example for path capabilities feat(schema): tighten extensionSignerPinsV2-V4 hash validation test(delegate): add allowlist negative cases for curl/wget/git/hrpc/systemctl test(proc): extend /proc/self/environ redaction key coverage docs(security): add peer-assisted block-0 mirroring threat-model notes feat(bench): add boot budget trend output from real booter phases test(baretop): align fixture coverage with /proc snapshot key set test(metrics): validate /proc/bare_os/metrics.prom OpenMetrics shape docs(ops): add structured seeder NDJSON examples test(replication): add live stall-hint coverage for no_peers/length_unavailable/ok docs(release): add corestore-snapshot workflow to checklist docs(ops): add mirror-drive experiment utility to maintainer workflow test(booter): add monitor progress coverage for replication live sketch feat(seeder): validate DHT bootstrap address class JSON inputs docs(network): add HYPERSWARM_BOOTSTRAP testnet operator guidance chore(root): add deterministic test:integration script docs(ci): add local CI runbook for no-.github environments docs(release): add npm run test:bare after npm test feat(verify): add protocol docs/package version parity checker feat(verify): enforce feature-roadmap canonical path consistency feat(lockfile-drift): add tier-1 strict fail option for mismatches docs(lockfile-drift): add udx-native and blind-peering upgrade workflow notes docs(cli-parity): add bare-fetch upstream issue tracking row feat(bundle-health): generate per-tier bundle size regression thresholds feat(doc-contracts): verify handbook references to current proc schema versions feat(pretest): add validate-mermaid-syntax gate feat(probe): add bare-runtime top-25 critical command lane docs(protocol): update capability-word prose from bits..bits5 to current words docs(two-drive): document /tmp /var/log and account-prefix routing docs(security): add concise boot trust model page and links docs(dev-guide): add P2P lab cookbook section docs(dev-guide): add how-to for adding seed RPCs docs(dev-guide): add how-to for adding /proc/bare_os nodes docs(dev-guide): add /bin utility checklist for man/posix/build/parity/tests docs(user-manual): add short What BareOS is not section
210 lines
6.9 KiB
JavaScript
210 lines
6.9 KiB
JavaScript
import test from 'brittle'
|
|
import { readFile } from 'node:fs/promises'
|
|
import { dirname, join } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { createContext, runInContext } from 'node:vm'
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
const fixturePath = join(__dirname, 'fixtures/baretop-sample-metrics.json')
|
|
const processTableFixture = join(__dirname, 'fixtures/baretop-process-table.json')
|
|
const largeProcessTableFixture = join(
|
|
__dirname,
|
|
'fixtures/baretop-large-process-table.json'
|
|
)
|
|
const helpersPath = join(__dirname, '../lib/baretop-ui-helpers.js')
|
|
const snapPath = join(__dirname, '../lib/baretop-snapshot.js')
|
|
|
|
test('fixture metrics_live-shaped JSON parses with expected keys', async (t) => {
|
|
const raw = await readFile(fixturePath, 'utf8')
|
|
const o = JSON.parse(raw)
|
|
t.ok(o && typeof o.session === 'object')
|
|
t.is(Number(o.schema), 4)
|
|
t.is(Number(o.session.execLineCount), 42)
|
|
t.ok(typeof o.delegateInflight === 'object')
|
|
t.ok(o.replicationLive && typeof o.replicationLive === 'object')
|
|
t.ok(o.kernelCounters && typeof o.kernelCounters === 'object')
|
|
t.ok(
|
|
o.netSummaryNestedExample &&
|
|
typeof o.netSummaryNestedExample.replicationQueue === 'object'
|
|
)
|
|
})
|
|
|
|
test('baretop-snapshot preamble lists batch proc entries', async (t) => {
|
|
const src = await readFile(snapPath, 'utf8')
|
|
t.ok(src.includes('BARE_TOP_SNAPSHOT_PROC_ENTRIES'))
|
|
t.ok(src.includes("'/proc/bare_os/index.json'"))
|
|
t.ok(src.includes('bareOsReadBareTopSnapshot'))
|
|
t.ok(src.includes('bareTopHealthScore'))
|
|
t.ok(src.includes('BARE_TOP_SNAPSHOT_LITE_ENTRIES'))
|
|
t.ok(src.includes('bootBudgetSummary'))
|
|
t.ok(src.includes('security_posture.json'))
|
|
})
|
|
|
|
test('bareTopHealthScore penalizes stall and inflight cardinality', async (t) => {
|
|
const src = await readFile(snapPath, 'utf8')
|
|
const ctx = createContext({})
|
|
runInContext(src, ctx)
|
|
const m = {
|
|
delegateInflight: { a: 2, b: 3 },
|
|
replicationLive: { stallHint: 'yes' }
|
|
}
|
|
const s = ctx.bareTopHealthScore(m, 3)
|
|
t.ok(s < 80)
|
|
const good = {
|
|
peers: 2,
|
|
delegateInflight: {},
|
|
replicationLive: { peerCount: 2, stallHint: '' }
|
|
}
|
|
t.is(ctx.bareTopHealthScore(good, 2), 100)
|
|
})
|
|
|
|
test('bareTopHealthScore: no_peers + idle delegates is not stuck at 73', async (t) => {
|
|
const src = await readFile(snapPath, 'utf8')
|
|
const ctx = createContext({})
|
|
runInContext(src, ctx)
|
|
const idle = {
|
|
peers: 0,
|
|
delegateInflight: {},
|
|
replicationLive: { peerCount: 0, stallHint: 'no_peers' }
|
|
}
|
|
t.is(ctx.bareTopHealthScore(idle, 0), 100)
|
|
const lightInflight = {
|
|
peers: 0,
|
|
delegateInflight: { http: 1, dns: 0 },
|
|
replicationLive: { peerCount: 0, stallHint: 'no_peers' }
|
|
}
|
|
const s2 = ctx.bareTopHealthScore(lightInflight, 0)
|
|
t.ok(s2 >= 90)
|
|
t.not(s2, 73)
|
|
})
|
|
|
|
test('bareTopHealthScoreDetail: benign stall hints and replicationStall flag', async (t) => {
|
|
const src = await readFile(snapPath, 'utf8')
|
|
const ctx = createContext({})
|
|
runInContext(src, ctx)
|
|
const lenOk = {
|
|
peers: 0,
|
|
replicationLive: { stallHint: 'length_unavailable', peerCount: 0 }
|
|
}
|
|
t.is(ctx.bareTopHealthScore(lenOk, 0), 100)
|
|
const explicit = {
|
|
peers: 1,
|
|
replicationLive: { stallHint: 'ok', peerCount: 1, replicationStall: true }
|
|
}
|
|
t.is(ctx.bareTopHealthScore(explicit, 1), 80)
|
|
const d = ctx.bareTopHealthScoreDetail(explicit, 1, null)
|
|
t.ok(String(d.breakdown).includes('replication_stall_flag'))
|
|
})
|
|
|
|
test('process_table fixture maps to sorted PID rows via helpers', async (t) => {
|
|
const raw = await readFile(processTableFixture, 'utf8')
|
|
const pt = JSON.parse(raw)
|
|
const code = await readFile(helpersPath, 'utf8')
|
|
const ctx = createContext({})
|
|
runInContext(code, ctx)
|
|
const rows = ctx.bareTopProcessRowsFromTable(pt)
|
|
t.is(rows.length, 2)
|
|
const sorted = ctx.bareTopSortProcessRows(rows, 'pid', true)
|
|
t.is(ctx.bareTopProcessPid(sorted[0]), 2)
|
|
const line = ctx.bareTopFormatFixedColumns(
|
|
[
|
|
String(sorted[1].pid),
|
|
String(sorted[1].ppid),
|
|
String(sorted[1].name)
|
|
],
|
|
[4, 4, 20],
|
|
['r', 'r', 'l'],
|
|
80
|
|
)
|
|
t.ok(line.includes('3'))
|
|
t.ok(line.toLowerCase().includes('shell'))
|
|
})
|
|
|
|
test('large process table fixture benchmark stays within budget', async (t) => {
|
|
const raw = await readFile(largeProcessTableFixture, 'utf8')
|
|
const pt = JSON.parse(raw)
|
|
const code = await readFile(helpersPath, 'utf8')
|
|
const ctx = createContext({})
|
|
runInContext(code, ctx)
|
|
const started = Date.now()
|
|
let rows = []
|
|
for (let i = 0; i < 200; i++) {
|
|
rows = ctx.bareTopProcessRowsFromTable(pt)
|
|
rows = ctx.bareTopSortProcessRows(rows, 'cpu', false, { sortWallMs: 1000 })
|
|
}
|
|
const elapsed = Date.now() - started
|
|
t.ok(rows.length >= 20)
|
|
t.ok(elapsed < 250, 'process fixture benchmark elapsed=' + elapsed + 'ms')
|
|
})
|
|
|
|
test('snapshot source includes profile/requested key support', async (t) => {
|
|
const booter = await readFile(
|
|
join(__dirname, '../../bare-os-booter/index.js'),
|
|
'utf8'
|
|
)
|
|
t.ok(booter.includes('requestedKeys'), 'booter supports requested key hints')
|
|
t.ok(booter.includes('const profile ='), 'booter supports profile selection')
|
|
const snap = await readFile(snapPath, 'utf8')
|
|
t.ok(snap.includes('snapshotProfile'), 'coreutils tracks snapshot profile')
|
|
t.ok(snap.includes('sectionTtl'), 'coreutils emits per-section ttl metadata')
|
|
})
|
|
|
|
test('baretop snapshot proc entry list stays in sync with booter', async (t) => {
|
|
const snap = await readFile(snapPath, 'utf8')
|
|
const booter = await readFile(
|
|
join(__dirname, '../../bare-os-booter/index.js'),
|
|
'utf8'
|
|
)
|
|
const procPaths = (s) =>
|
|
[...s.matchAll(/'\/proc\/bare_os\/[^']+'/g)].map((m) => m[0].slice(1, -1))
|
|
const a = new Set(procPaths(snap))
|
|
const b = new Set(procPaths(booter))
|
|
const optionalCoreutilsOnly = new Set([
|
|
'/proc/bare_os/metrics_live.json',
|
|
'/proc/bare_os/features',
|
|
'/proc/bare_os/initd_graph.json'
|
|
])
|
|
for (const p of a) {
|
|
if (optionalCoreutilsOnly.has(p)) continue
|
|
t.ok(b.has(p), 'booter includes ' + p)
|
|
}
|
|
t.ok(a.has('/proc/bare_os/metrics.prom'))
|
|
t.ok(a.has('/proc/bare_os/process_table.json'))
|
|
})
|
|
|
|
test('bareTopFetchSnapshot tolerates sparse file maps and missing fields', async (t) => {
|
|
const src = await readFile(snapPath, 'utf8')
|
|
const ctx = createContext({
|
|
TextDecoder,
|
|
Uint8Array,
|
|
Date,
|
|
JSON,
|
|
Object,
|
|
Math,
|
|
String,
|
|
Number,
|
|
Set,
|
|
Map,
|
|
Array
|
|
})
|
|
runInContext(src, ctx)
|
|
const fakeCtx = {
|
|
env: {},
|
|
b4a: { toString: (v) => String(v || '') },
|
|
vfs: { readFile: async () => '' },
|
|
bareOsReadBareTopSnapshot: async () => ({
|
|
atMs: Date.now(),
|
|
files: {
|
|
index: '{"ok":true}',
|
|
swarm: '{"peerCount":1}',
|
|
processTable: '{"processes":[]}'
|
|
},
|
|
metricsLiveText: '{"peers":1}'
|
|
})
|
|
}
|
|
const snap = await ctx.bareTopFetchSnapshot(fakeCtx, { activeTab: 'network' })
|
|
t.ok(snap && typeof snap === 'object')
|
|
t.ok(snap.fileTexts && typeof snap.fileTexts === 'object')
|
|
t.ok(snap.extra && typeof snap.extra === 'object')
|
|
})
|