OverviewFilesCommitsIssuesDocsReleasesPeers

favela-surface-android commits / d85c5a3

test the seam: the directory the store writes is the one the bundle derives
Two halves that never speak. bundleStore WRITES the addon directory, inside the worklet, from the marker. lib/bootstrap.js DERIVES it, inside the staged bundle, from import.meta.url — with no marker, no shell, no argument. They agree only by convention, and a convention held in two places is one rename away from a phone that stages addons nothing ever loads. That failure is silent and indistinguishable from a release that simply carried none. So it is asserted against real store output rather than a restatement of the rule: materialize a tree through the real pgh-runtime installTree, then check addonsDirFor('file://' + store.pathFor(hash) + '/lib/bootstrap.js') against store.addonsFor(hash), and that every addon is on disk where the bootstrap will look. Plus the property that makes it work at all — the staged file is named by CONTENT hash and the directory after that file, so the pairing holds whatever the hash turns out to be, which is why the bundle never needs to be told the tree hash it was published under. Suite 82/82, 278/278. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
d85c5a376f50af84f4469e0cce1d0fe57e19ade5
by plankatron <fleeky@gmail.com> · 2026-09-11T01:04:14.000Z

Changed files (1) +48 -0

test/ota.test.js +48 -0
……@@ -455,3 +455,51 @@ test('a bundle whose header cannot be read is UNKNOWN, not empty', async (t) =>
455455 t.is(marker.demands, null, 'unknown')
456456 t.ok(store.hasTree(treeHash), 'and the bundle is still staged — an unreadable header is not a bad bundle')
457457})
458
459// ── the seam ──────────────────────────────────────────────────────────────────────────────────────
460//
461// ⛔ TWO HALVES THAT NEVER SPEAK. bundleStore WRITES the addon directory, inside the worklet, from the
462// marker. lib/bootstrap.js DERIVES it, inside the staged bundle, from import.meta.url — with no marker,
463// no shell and no argument. They agree only by convention, and a convention held in two places is one
464// rename away from a phone that stages addons nothing ever loads: silent, and indistinguishable from a
465// release that simply had none.
466//
467// So it is asserted against the real store output rather than against a restatement of the rule.
468import { addonsDirFor } from '../lib/host/loader-core.js'
469
470test('the directory the store writes is the one the bundle derives', async (t) => {
471 const dir = tmpdir('seam')
472 const { entries, treeHash, sub, subHash } = treeWithAddons(BUNDLE, ADDONS)
473 const contents = { [hashOf(BUNDLE)]: BUNDLE }
474 for (const [, bytes] of Object.entries(ADDONS)) contents[hashOf(bytes)] = bytes
475
476 const store = bundleStore({ dir })
477 await installTree(store, treeHash, treeFetcher({ trees: { [treeHash]: entries, [subHash]: sub }, contents }))
478
479 // What the shell hands bare-kit, and therefore what import.meta.url is rooted at inside the bundle.
480 const staged = store.pathFor(treeHash)
481 const derived = addonsDirFor('file://' + staged + '/lib/bootstrap.js')
482
483 t.is(derived, store.addonsFor(treeHash), 'store and bundle agree on the path')
484 for (const name of Object.keys(ADDONS)) {
485 t.ok(fs.existsSync(path.join(derived, name)), name + ' is where the bootstrap will look')
486 }
487})
488
489test('the seam survives the bundle being renamed by content hash', async (t) => {
490 // The store names the staged file by CONTENT hash and the directory after that file, so the pairing
491 // holds whatever the hash turns out to be — which is the property that lets the bundle derive it
492 // without being told the tree hash it was published under.
493 const dir = tmpdir('seam2')
494 const other = Buffer.from('#!/bare\n// a different bundle entirely\n')
495 const { entries, treeHash, sub, subHash } = treeWithAddons(other, ADDONS)
496 const contents = { [hashOf(other)]: other }
497 for (const [, bytes] of Object.entries(ADDONS)) contents[hashOf(bytes)] = bytes
498
499 const store = bundleStore({ dir })
500 await installTree(store, treeHash, treeFetcher({ trees: { [treeHash]: entries, [subHash]: sub }, contents }))
501
502 const staged = store.pathFor(treeHash)
503 t.ok(staged.endsWith(hashOf(other) + '.bundle'), 'named by content hash')
504 t.is(addonsDirFor('file://' + staged + '/x.js'), store.addonsFor(treeHash), 'and the pairing still holds')
505})