Benjamin DiedrichsenandClaude Opus 5 bb8b1bfa5c [fix] nopy: detect a dependency cycle instead of overflowing the stack
Closes DOCS-AUDIT §6.5, and the substantive half of §1.5. `docs/API.md` has
documented a circular-dependency error since it was written; nothing raised it.
Two mutually dependent cubes recursed until V8 gave up, and a `RangeError`
names no cube — it reads as a nopy crash rather than as a manifest that says
something impossible.

`BuildContext` now carries a resolution stack: `resolveCube` pushes its
(cube, host) pair, delegates the body to `visitCube`, and pops in a `finally`.
A pair re-entered while it is still on the stack raises a `NopyUsageError`
naming the whole path — `Circular dependency on host1: a → b → c → a`. The
whole path, not just the repeated cube, because dependencies are declared
dynamically and a hook may `exec` anything at all, so the edge that closed the
loop is rarely the one you would guess from the two ends.

It has to be a structure of its own. `resolvedCubes` is written by
`buildDeployCall`, which runs *after* the descent, so a cycle never reaches it;
and it cannot be widened into a "seen" set, because re-entering a *finished*
cube with different `param` overrides is exactly what a dependency or a hook is
for. That distinction is what the diamond test pins: `shared` is entered twice
under `left` and `right` and must still resolve, while `a → b → a` must not.

There is still no topological sort and there does not need to be — emission is
post-order, so the order already is a topological one. Cycle detection was the
one thing a sort would have given that the recursion did not.

Six tests: self-dependency, a three-cube loop, the loop reported as usage
rather than as a stack overflow, a loop closed by a hook's `exec` rather than a
`dependencies()` entry, the diamond, and the same cube on two hosts.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DCzYTAm9QUhvLNr2EpdagJ
2026-09-01 12:48:06 +02:00
2026-07-27 13:09:00 +02:00
2026-07-29 13:21:04 +02:00
2026-07-29 13:21:04 +02:00
2026-07-29 13:21:04 +02:00

ansiblings

Infrastructure tooling monorepo: two published CLIs plus the pyinfra "cubes" they deploy.

Path Package Binary What it is
packages/nopy @bitsquare/nopy nopy interactive pyinfra script management and execution
packages/keyman @bitsquare/keyman keyman SSH key management with age encryption
packages/nopy-cubes @bitsquare/nopy-cubes — the authoring surface a cube's manifest.mjs imports
packages/nopy-cubes-core @bitsquare/nopy-cubes-core — the core bundle of deployment units nopy runs
npm install -g @bitsquare/nopy @bitsquare/keyman

See each package's README for usage, and README.PUBLISH.md for how they get published.

Development

Requires Node ≥ 22 (the repo pins 24 in .nvmrc) and pnpm — the version is pinned by packageManager, so corepack enable is enough.

pnpm install
Command Does
pnpm run build compiles both packages with tsc
pnpm run typecheck tsc --build across the workspace (see below)
pnpm run lint Biome check
pnpm run lint:fix Biome check with fixes applied
pnpm test vitest, both packages
pnpm run test:coverage vitest with the coverage gate
pnpm run coverage:summary renders the last coverage run as a Markdown table

typescript is on the 7.x native compiler, so tsc is the fast one — there is no separate tsgo binary to keep in sync. typecheck is plain tsc --build, not --noEmit: once a project has references, TypeScript rejects --noEmit outright (TS6310), because a composite project has to emit the declarations its dependents read. So the typecheck writes dist as a side effect — gitignored, and it means the gate also proves the build works. Each package also has a dev-run script (pnpm --filter @bitsquare/nopy run nopy) that executes the TypeScript sources directly through tsx.

Git hooks

Installed by simple-git-hooks on pnpm install, configured in the root package.json:

  • pre-commit — Biome check with fixes, on staged files only, re-staging what it fixed. Fast; blocks only on problems it cannot fix itself.
  • pre-push — lint:ci → typecheck → test:coverage. This is the same gate CI runs, so a push that survives it will not surprise you on the runner.

Set SKIP_SIMPLE_GIT_HOOKS=1 to bypass either one; re-install them after changing the config with pnpm exec simple-git-hooks.

Coverage

Both packages hold a hard 85 % branch floor, enforced by coverage.thresholds in their vitest.config.ts rather than by a CI-only flag — pnpm run test:coverage fails the same way locally, in the pre-push hook, and on the runner. Barrel files and CLI argv wiring are excluded; everything with behaviour in it is not.

S
Description
No description provided
Readme MIT
942 KiB
2026-09-02 14:03:39 +02:00
Languages
TypeScript 83.2%
JavaScript 12%
Python 4.5%
Dockerfile 0.2%