fix(packages): make packed exports runtime-safe (#665)
* fix(packages): make packed exports runtime-safe
Make checked-in package manifests truthful for ordinary npm and Bun packing, and verify installed artifacts under both runtimes. Centralize package discovery, artifact inspection, and bounded process execution so CI and release publication share the same contracts.
* ci: build package dependencies before checks
Keep workspace jobs independent of ignored dist output now that public package exports consistently resolve built artifacts.
* ci: preserve source-first engine tests
Keep the broader dependency build for package and repository validation, but retain Core-only setup for engine shards so workspace tests continue exercising source modules.
* ci: build engine shard dependencies
Build the seven workspace packages imported by engine tests in dependency order. This preserves a single module instance per package and keeps each clean CI shard independent of ignored dist output.
* ci: restore established package build boundaries
Keep the original repository and engine job setup, and add installed artifact verification only after the existing package build. Avoid changing which module copies unrelated tests execute.
* fix(packages): preserve Bun source identity in tarballs
Retain source-first workspace resolution and ship complete source trees for Bun conditions. Verify clean installed consumers without overlaying archives, reuse consumer validation before release publication, and repair Bun 1.3.10 private source alias resolution.
* refactor(tooling): reuse package and process utilities
Use pkg-types for manifest I/O and types, tinyexec for subprocess lifecycle, and npm's pack listing for release staging. Preserve archive verification and project release invariants rather than reimplementing package-manager file selection.
* refactor(tooling): resolve workspace roots at CLI boundaries
Discover and validate the nearest workspace once, support explicit roots, and pass roots to reusable checks. Replace subprocess entrypoint dispatch with direct calls and preserve aggregate package diagnostics without adding arbitrary test timeout increases.
* fix(release): enforce publication boundaries
Use root version alignment and shared validated npm output parsing. Enforce the public npm registry policy and test verification-before-publication, mismatched artifacts, and partial retries without registry writes.
* refactor(tooling): validate package responses with Valibot
Express npm pack and manifest identity contracts as schemas, infer parsed output types, and preserve contextual failures and relative-path safety. Document Valibot as the first-party validation convention while retaining Zod at SDK boundaries.
* refactor(tooling): validate manifests at input boundaries
Share Valibot schemas for consumed manifest fields, recursive exports, supported workspace declarations, and npm registry responses. Infer domain types and reject malformed metadata instead of silently skipping it downstream.
* refactor(tooling): group package helpers by ownership
Colocate manifest and workspace contracts, separate npm response parsing from generic JSON handling, and split smoke packing, installation, and runtime checks. Remove the release tarball forwarding shim and consolidate its coverage in package-artifacts. Preserve public tooling exports and CLI commands.
2026-09-09 15:25:22 +00:00
|
|
|
import { expect, test } from 'bun:test'
|
|
|
|
|
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
|
|
|
|
|
import { tmpdir } from 'node:os'
|
|
|
|
|
import { join } from 'node:path'
|
|
|
|
|
|
fix(tools): run npm packaging guards in package verification
* fix(tools): run npm packaging guards in package verification
The packed-resolution unit tests spawned npm pack, npm init and npm
install under Bun's default 5 s test timeout, and npm's cold start on a
fresh CI runner exceeded it. Package-manager work is not bounded by a
test budget, so the fixture chain becomes a packaging-guard phase of
test:packages: fixture manifests packed with the release's npm pack,
inspected, installed through the real consumer install and imported
under Node and Bun, each with the outcome it must produce.
The tarball inspector reads archives in-process with @publint/pack
instead of a tar executable. Its bun test coverage is now pure unit
tests plus in-process tarball fixtures.
* fix(tools): bound npm init and build tarball fixtures in-process
The consumer install helper gave npm install a deadline but not npm
init, so a stalled init could hold the packaging-guard phase open. The
inspector tests built their archives with a tar executable, which
contradicted what they claim to prove; nanotar now writes them
in-process.
* refactor(tools): alias package tool tests and compare guards with isEqual
package-artifacts and package-quality were the only tools without a
#domain/* subpath alias, so their tests reached into ../src. Both now
declare the alias like the other tools and the tests use it. The guard
diagnostic comparison uses es-toolkit's isEqual instead of joined
strings.
* fix(tools): match the expected runtime failure in packaging guards
A guard that expected Bun to fail accepted any non-zero exit, so an
unrelated error would have satisfied it. Failing expectations now carry
the resolution error Bun must report, and observations keep the actual
output so a mismatch names what happened instead.
2026-09-25 21:40:24 +00:00
|
|
|
import { resolveWorkspaceRoot } from '#package-artifacts/workspace/root'
|
fix(packages): make packed exports runtime-safe (#665)
* fix(packages): make packed exports runtime-safe
Make checked-in package manifests truthful for ordinary npm and Bun packing, and verify installed artifacts under both runtimes. Centralize package discovery, artifact inspection, and bounded process execution so CI and release publication share the same contracts.
* ci: build package dependencies before checks
Keep workspace jobs independent of ignored dist output now that public package exports consistently resolve built artifacts.
* ci: preserve source-first engine tests
Keep the broader dependency build for package and repository validation, but retain Core-only setup for engine shards so workspace tests continue exercising source modules.
* ci: build engine shard dependencies
Build the seven workspace packages imported by engine tests in dependency order. This preserves a single module instance per package and keeps each clean CI shard independent of ignored dist output.
* ci: restore established package build boundaries
Keep the original repository and engine job setup, and add installed artifact verification only after the existing package build. Avoid changing which module copies unrelated tests execute.
* fix(packages): preserve Bun source identity in tarballs
Retain source-first workspace resolution and ship complete source trees for Bun conditions. Verify clean installed consumers without overlaying archives, reuse consumer validation before release publication, and repair Bun 1.3.10 private source alias resolution.
* refactor(tooling): reuse package and process utilities
Use pkg-types for manifest I/O and types, tinyexec for subprocess lifecycle, and npm's pack listing for release staging. Preserve archive verification and project release invariants rather than reimplementing package-manager file selection.
* refactor(tooling): resolve workspace roots at CLI boundaries
Discover and validate the nearest workspace once, support explicit roots, and pass roots to reusable checks. Replace subprocess entrypoint dispatch with direct calls and preserve aggregate package diagnostics without adding arbitrary test timeout increases.
* fix(release): enforce publication boundaries
Use root version alignment and shared validated npm output parsing. Enforce the public npm registry policy and test verification-before-publication, mismatched artifacts, and partial retries without registry writes.
* refactor(tooling): validate package responses with Valibot
Express npm pack and manifest identity contracts as schemas, infer parsed output types, and preserve contextual failures and relative-path safety. Document Valibot as the first-party validation convention while retaining Zod at SDK boundaries.
* refactor(tooling): validate manifests at input boundaries
Share Valibot schemas for consumed manifest fields, recursive exports, supported workspace declarations, and npm registry responses. Infer domain types and reject malformed metadata instead of silently skipping it downstream.
* refactor(tooling): group package helpers by ownership
Colocate manifest and workspace contracts, separate npm response parsing from generic JSON handling, and split smoke packing, installation, and runtime checks. Remove the release tarball forwarding shim and consolidate its coverage in package-artifacts. Preserve public tooling exports and CLI commands.
2026-09-09 15:25:22 +00:00
|
|
|
|
|
|
|
|
test('nearest workspace lockfile isolates nested worktrees from the parent checkout', async () => {
|
|
|
|
|
const parent = await mkdtemp(join(tmpdir(), 'workspace-root-'))
|
|
|
|
|
try {
|
|
|
|
|
const worktree = join(parent, '.worktrees', 'feature')
|
|
|
|
|
const nested = join(worktree, 'tools', 'release')
|
|
|
|
|
await mkdir(nested, { recursive: true })
|
|
|
|
|
for (const root of [parent, worktree]) {
|
|
|
|
|
await writeFile(join(root, 'bun.lock'), '{}')
|
|
|
|
|
await writeFile(join(root, 'package.json'), JSON.stringify({ workspaces: ['tools/release'] }))
|
|
|
|
|
}
|
|
|
|
|
await writeFile(join(worktree, '.git'), 'gitdir: /not-needed-for-discovery')
|
|
|
|
|
expect(await resolveWorkspaceRoot(nested)).toBe(worktree)
|
|
|
|
|
expect(await resolveWorkspaceRoot(nested, parent)).toBe(parent)
|
|
|
|
|
await writeFile(join(nested, 'package.json'), JSON.stringify({ private: true }))
|
|
|
|
|
await expect(resolveWorkspaceRoot(nested, '.')).rejects.toThrow('expected a workspace manifest')
|
|
|
|
|
} finally {
|
|
|
|
|
await rm(parent, { recursive: true, force: true })
|
|
|
|
|
}
|
|
|
|
|
})
|