openpencil/tools/release/package-artifacts/tests/root.test.ts
Danila Poyarkov 1aa10a4fed
build(tools): group tools by role and gate them like the rest of the repo (#791)
Tools live under tools/<role>/<domain> (checks, generate, release, ci, dev), every tool is a workspace named @open-pencil/<domain>-tools, a shared tools/tsconfig.json backs the new check:tools gate that fixed 55 latent type errors, test:tools runs through bun --filter, the placement check is its own checks/test-homes package, and every tool resolves the repository through resolveWorkspaceRoot. Bun, Node, and mdast types live in a tools-root workspace so they never reach the app program.
2026-09-30 05:00:31 +04:00

27 lines
1.2 KiB
TypeScript

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'
import { resolveWorkspaceRoot } from '#package-artifacts/workspace/root'
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 })
}
})