| … | … | @@ -153,6 +153,104 @@ test('default tarTree (real async spawn) produces a valid tarball without blocki |
| 153 | 153 | rmSync(root, { recursive: true, force: true }) |
| 154 | 154 | }) |
| 155 | 155 | |
| 156 | // Cross-arch: hostLabel() only ever names the LOCAL arch, so an all-x64 fleet |
| 157 | // can never tar linux-arm64 and /bootstrap 404s for arm64 VPSes. Bootstrap apps |
| 158 | // vendor prebuilt cross-arch tarballs under node_modules/<pkg>/dist/ — reconcile |
| 159 | // promotes those into the served dir. |
| 160 | |
| 161 | // Drop a vendored cross-arch tarball into an app tree's node_modules/<pkg>/dist/. |
| 162 | function mkVendored (appDir, pkg, tarName, body = 'VENDORED') { |
| 163 | const dist = join(appDir, 'node_modules', pkg, 'dist') |
| 164 | mkdirSync(dist, { recursive: true }) |
| 165 | writeFileSync(join(dist, tarName), body) |
| 166 | return join(dist, tarName) |
| 167 | } |
| 168 | |
| 169 | test('reconcileBootstrapArtifacts promotes a vendored cross-arch tarball into the served dir', async (t) => { |
| 170 | const root = mkdtempSync(join(tmpdir(), 'pgh-ba-xarch-')) |
| 171 | const store = fakeStore(root); store.init() |
| 172 | const appDir = mkAppTree(store.appsDir, 'pgh', { label: 'linux-x64', treeHash: 'h1', installSh: true }) |
| 173 | const src = mkVendored(appDir, 'pgh', 'pgh-bootstrap-bare-linux-arm64.tar.gz', 'ARM64BYTES') |
| 174 | |
| 175 | const res = await reconcileBootstrapArtifacts(store, { tarTree: fakeTar([]), label: 'linux-x64' }) |
| 176 | |
| 177 | const dir = bootstrapDir(store) |
| 178 | const arm = join(dir, 'pgh-bootstrap-bare-linux-arm64.tar.gz') |
| 179 | t.ok(existsSync(arm), 'arm64 tarball now served') |
| 180 | t.is(readFileSync(arm, 'utf8'), 'ARM64BYTES', 'promoted the vendored bytes') |
| 181 | t.ok(res.tarred.includes('pgh-bootstrap-bare-linux-arm64.tar.gz'), 'reported as produced') |
| 182 | t.ok(existsSync(join(dir, 'pgh-bootstrap-bare-linux-x64.tar.gz')), 'host-arch tarball still tarred locally') |
| 183 | // hardlink, not copy — same inode means serving arm64 costs no extra bytes |
| 184 | t.is(lstatSync(arm).ino, lstatSync(src).ino, 'hardlinked to the vendored file (zero extra disk)') |
| 185 | }) |
| 186 | |
| 187 | test('a promoted cross-arch tarball survives the prune pass', async (t) => { |
| 188 | const root = mkdtempSync(join(tmpdir(), 'pgh-ba-xarch-p-')) |
| 189 | const store = fakeStore(root); store.init() |
| 190 | const appDir = mkAppTree(store.appsDir, 'pgh', { label: 'linux-x64', treeHash: 'h1', installSh: true }) |
| 191 | mkVendored(appDir, 'pgh', 'pgh-bootstrap-bare-linux-arm64.tar.gz') |
| 192 | |
| 193 | const dir = bootstrapDir(store) |
| 194 | await reconcileBootstrapArtifacts(store, { tarTree: fakeTar([]), label: 'linux-x64' }) |
| 195 | t.ok(existsSync(join(dir, 'pgh-bootstrap-bare-linux-arm64.tar.gz')), 'present after first reconcile') |
| 196 | |
| 197 | // Second pass is where a non-wanted artifact would get pruned. |
| 198 | const res = await reconcileBootstrapArtifacts(store, { tarTree: fakeTar([]), label: 'linux-x64' }) |
| 199 | t.absent(res.pruned.includes('pgh-bootstrap-bare-linux-arm64.tar.gz'), 'not pruned') |
| 200 | t.ok(existsSync(join(dir, 'pgh-bootstrap-bare-linux-arm64.tar.gz')), 'still served after re-reconcile') |
| 201 | }) |
| 202 | |
| 203 | test('local tar wins for the host arch — a vendored same-label tarball never overwrites it', async (t) => { |
| 204 | const root = mkdtempSync(join(tmpdir(), 'pgh-ba-xarch-w-')) |
| 205 | const store = fakeStore(root); store.init() |
| 206 | const appDir = mkAppTree(store.appsDir, 'pgh', { label: 'linux-x64', treeHash: 'h1', installSh: true }) |
| 207 | // a stale vendored tarball for OUR arch — must not shadow the fresh local tar |
| 208 | mkVendored(appDir, 'pgh', 'pgh-bootstrap-bare-linux-x64.tar.gz', 'STALE') |
| 209 | |
| 210 | await reconcileBootstrapArtifacts(store, { tarTree: fakeTar([]), label: 'linux-x64' }) |
| 211 | |
| 212 | const hostTb = join(bootstrapDir(store), 'pgh-bootstrap-bare-linux-x64.tar.gz') |
| 213 | t.not(readFileSync(hostTb, 'utf8'), 'STALE', 'host-arch tarball came from local tar, not the vendored copy') |
| 214 | }) |
| 215 | |
| 216 | // Measured on tabertron: pgh-sidecar-bootstrap-bare-linux-arm64.tar.gz lives ONLY |
| 217 | // in the pear-git-v3 tree, which is not a pgh.bootstrap app. install.sh fetches |
| 218 | // both pgh and pgh-sidecar under `set -e`, so missing the sidecar's arm64 tarball |
| 219 | // still breaks every arm64 install. |
| 220 | test('promotes a vendored tarball carried by a NON-bootstrap app tree', async (t) => { |
| 221 | const root = mkdtempSync(join(tmpdir(), 'pgh-ba-xarch-nb-')) |
| 222 | const store = fakeStore(root); store.init() |
| 223 | mkAppTree(store.appsDir, 'pgh', { label: 'linux-x64', treeHash: 'h1', installSh: true }) |
| 224 | // pear-git-v3 is NOT a bootstrap app, but it carries the sidecar's arm64 bytes |
| 225 | const pgv3 = mkAppTree(store.appsDir, 'pear-git-v3', { bootstrap: false, treeHash: 'h2' }) |
| 226 | mkVendored(pgv3, 'pgh-sidecar', 'pgh-sidecar-bootstrap-bare-linux-arm64.tar.gz', 'SIDECAR-ARM64') |
| 227 | |
| 228 | const res = await reconcileBootstrapArtifacts(store, { tarTree: fakeTar([]), label: 'linux-x64' }) |
| 229 | |
| 230 | const sc = join(bootstrapDir(store), 'pgh-sidecar-bootstrap-bare-linux-arm64.tar.gz') |
| 231 | t.ok(existsSync(sc), 'sidecar arm64 tarball served despite carrier not being a bootstrap app') |
| 232 | t.is(readFileSync(sc, 'utf8'), 'SIDECAR-ARM64', 'promoted the right bytes') |
| 233 | t.ok(res.tarred.includes('pgh-sidecar-bootstrap-bare-linux-arm64.tar.gz'), 'reported as produced') |
| 234 | t.absent(existsSync(join(bootstrapDir(store), 'pear-git-v3-bootstrap-bare-linux-x64.tar.gz')), |
| 235 | 'non-bootstrap carrier is still not tarred as a bootstrap app itself') |
| 236 | }) |
| 237 | |
| 238 | test('re-promotes when the vendored artifact is replaced underneath us', async (t) => { |
| 239 | const root = mkdtempSync(join(tmpdir(), 'pgh-ba-xarch-up-')) |
| 240 | const store = fakeStore(root); store.init() |
| 241 | const appDir = mkAppTree(store.appsDir, 'pgh', { label: 'linux-x64', treeHash: 'h1', installSh: true }) |
| 242 | mkVendored(appDir, 'pgh', 'pgh-bootstrap-bare-linux-arm64.tar.gz', 'V1') |
| 243 | |
| 244 | const dir = bootstrapDir(store) |
| 245 | await reconcileBootstrapArtifacts(store, { tarTree: fakeTar([]), label: 'linux-x64' }) |
| 246 | t.is(readFileSync(join(dir, 'pgh-bootstrap-bare-linux-arm64.tar.gz'), 'utf8'), 'V1', 'v1 served') |
| 247 | |
| 248 | // new upstream version replaces the vendored file (new inode) |
| 249 | mkVendored(appDir, 'pgh', 'pgh-bootstrap-bare-linux-arm64.tar.gz', 'V2') |
| 250 | await reconcileBootstrapArtifacts(store, { tarTree: fakeTar([]), label: 'linux-x64' }) |
| 251 | t.is(readFileSync(join(dir, 'pgh-bootstrap-bare-linux-arm64.tar.gz'), 'utf8'), 'V2', 're-promoted, not stale') |
| 252 | }) |
| 253 | |
| 156 | 254 | test('hostLabel returns os-arch', (t) => { |
| 157 | 255 | t.ok(/^[a-z0-9]+-[a-z0-9]+$/.test(hostLabel()), 'looks like <os>-<arch>') |
| 158 | 256 | }) |