Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

store: Remotion, Marp, CircuitJS and Yosys install and run on a fresh machine

dee19ccba19eb92
diff --git a/store/agents/autonomous-circuit/toolchain/runtimes.sh b/store/agents/autonomous-circuit/toolchain/runtimes.sh
index 51fefe3f9..7223c78dc 100644
--- a/store/agents/autonomous-circuit/toolchain/runtimes.sh
+++ b/store/agents/autonomous-circuit/toolchain/runtimes.sh
@@ -77,6 +77,8 @@ harness_node() {
# A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
_harness_node_at_least "$min" && return 0
diff --git a/store/agents/autonomous-workshop/toolchain/runtimes.sh b/store/agents/autonomous-workshop/toolchain/runtimes.sh
index 51fefe3f9..7223c78dc 100644
--- a/store/agents/autonomous-workshop/toolchain/runtimes.sh
+++ b/store/agents/autonomous-workshop/toolchain/runtimes.sh
@@ -77,6 +77,8 @@ harness_node() {
# A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
_harness_node_at_least "$min" && return 0
diff --git a/store/agents/blender/toolchain/runtimes.sh b/store/agents/blender/toolchain/runtimes.sh
index 51fefe3f9..7223c78dc 100644
--- a/store/agents/blender/toolchain/runtimes.sh
+++ b/store/agents/blender/toolchain/runtimes.sh
@@ -77,6 +77,8 @@ harness_node() {
# A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
_harness_node_at_least "$min" && return 0
diff --git a/store/agents/circuitjs/toolchain/doctor.sh b/store/agents/circuitjs/toolchain/doctor.sh
index dffe4e49f..6cc6e451b 100755
--- a/store/agents/circuitjs/toolchain/doctor.sh
+++ b/store/agents/circuitjs/toolchain/doctor.sh
@@ -2,6 +2,8 @@
# Exit 0 = this machine can run the harness. One line per check; Harness shows them.
set -u
cd "$(dirname "$0")/.."
+# shellcheck source=runtimes.sh
+. toolchain/runtimes.sh
bad=0
war=upstream/war
if [ -s "$war/circuitjs.html" ] && [ -s "$war/circuitjs1/circuitjs1.nocache.js" ] && ls "$war"/circuitjs1/*.cache.js >/dev/null 2>&1; then
@@ -18,6 +20,6 @@ else
echo "miss upstream/war/circuitjs1/circuits — run toolchain/setup.sh"
bad=1
fi
-if command -v node >/dev/null 2>&1; then echo "ok node $(node -v) (the pane)"; else echo "miss node >= 18 (the pane is a node server)"; bad=1; fi
+if harness_node 18 >/dev/null; then echo "ok node $(node -v) (the pane)"; else harness_node 18; bad=1; fi
if command -v python3 >/dev/null 2>&1; then echo "ok $(python3 --version) (the verdict)"; else echo "miss python3 (the verdict)"; bad=1; fi
exit $bad
diff --git a/store/agents/circuitjs/toolchain/runtimes.sh b/store/agents/circuitjs/toolchain/runtimes.sh
new file mode 100644
index 000000000..7223c78dc
--- /dev/null
+++ b/store/agents/circuitjs/toolchain/runtimes.sh
@@ -0,0 +1,192 @@
+# shellcheck shell=bash
+# runtimes.sh — the interpreters a store package runs on, found on this machine or fetched, never
+# asked of the person who pressed Get.
+#
+# Sourced (not run) by a package's setup, doctor and viewer scripts. A new Mac has Apple's Python 3.9,
+# no Homebrew and, for most people, no Node on PATH; a package that answers "brew install [email protected]"
+# has failed its install. So:
+#
+# harness_node 18 node >= 18 on PATH, with npm: the machine's own, else the Node Harness
+# itself runs on (~/.harness/runtime/current-node, laid down with the CLI)
+# harness_uv uv on PATH: the machine's own, else a pinned, checksummed release
+# fetched into ~/.harness/runtime
+# harness_venv DIR 3.12 [MIN [BELOW]]
+# DIR is a venv on CPython 3.12, which uv downloads when the machine
+# has none. A venv already there on a Python in [MIN, BELOW) is kept.
+# harness_pip DIR PKG… install into that venv, through uv
+# harness_micromamba micromamba, pinned and checksummed, for native libraries PyPI has
+# no wheel for (pycairo on macOS)
+# harness_conda_env DIR SPEC… DIR is a conda-forge environment with those packages
+#
+# Every function prints `miss …` and returns 1 when it cannot deliver, so `harness_node 18 || exit 1`
+# reads like the rest of a setup script. Nothing here touches the user's shell profile; what it
+# installs lands in ~/.harness/runtime or the package's own directory (uv keeps its download cache
+# where it always does, which a venv does not depend on).
+#
+# ONE copy is written by hand: store/tools/runtimes.sh in the OpenHarness repository. Each package
+# carries an identical copy (a package installs alone, so it cannot reach this one);
+# `node store/tools/sync-runtimes.mjs` rewrites them and the CLI's store spec fails when one drifts.
+
+HARNESS_RUNTIME="${ADAPTER_RUNTIME_DIR:-${HOME:-}/.harness/runtime}"
+# The Pythons uv downloads live with Harness's other runtimes, not in uv's own ~/.local/share/uv:
+# a package's venv points at its interpreter, and `uv python uninstall` there must not break it.
+UV_PYTHON_INSTALL_DIR="${UV_PYTHON_INSTALL_DIR:-$HARNESS_RUNTIME/python}"
+export UV_PYTHON_INSTALL_DIR
+HARNESS_UV_VERSION=0.12.15
+HARNESS_MICROMAMBA_VERSION=2.9.0-0
+
+_harness_platform() {
+ case "$(uname -s)-$(uname -m)" in
+ Darwin-arm64) echo darwin-arm64 ;;
+ Darwin-x86_64) echo darwin-x64 ;;
+ Linux-x86_64) echo linux-x64 ;;
+ Linux-aarch64 | Linux-arm64) echo linux-arm64 ;;
+ *) return 1 ;;
+ esac
+}
+
+_harness_sha256() {
+ if command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" | cut -d' ' -f1
+ else sha256sum "$1" | cut -d' ' -f1; fi
+}
+
+# _harness_fetch URL DEST SHA256 — DEST exists only if what arrived matches the pinned checksum.
+_harness_fetch() {
+ local part="$2.part.$$"
+ if ! curl -fsSL --retry 3 --connect-timeout 20 --max-time 900 -o "$part" "$1"; then
+ rm -f "$part"; echo "miss could not download $1 — check this machine's internet connection"; return 1
+ fi
+ if [ "$(_harness_sha256 "$part")" != "$3" ]; then
+ rm -f "$part"; echo "miss $1 did not match its pinned checksum; nothing was installed"; return 1
+ fi
+ mv -f "$part" "$2"
+}
+
+_harness_node_at_least() {
+ command -v node >/dev/null 2>&1 || return 1
+ node -e '
+ const [a, b = 0] = process.argv[1].split(".").map(Number)
+ const [x, y] = process.versions.node.split(".").map(Number)
+ process.exit(x > a || (x === a && y >= b) ? 0 : 1)
+ ' "$1" >/dev/null 2>&1
+}
+
+harness_node() {
+ local min="${1:-18}" recorded saved="$PATH" own=0
+ _harness_node_at_least "$min" && own=1
+ # A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
+ if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
+ recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
+ if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
+ PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
+ _harness_node_at_least "$min" && return 0
+ PATH="$saved"; export PATH; hash -r 2>/dev/null || true
+ [ "$own" = 1 ] && return 0
+ echo "miss node >= $min — this machine's newest is $("${recorded%/*}/node" -v), Harness's own; update Harness"
+ return 1
+ fi
+ [ "$own" = 1 ] && return 0
+ echo "miss node >= $min, and Harness's own Node is not in $HARNESS_RUNTIME — run \`harness start\` once to lay it down"
+ return 1
+}
+
+harness_uv() {
+ local dir asset sum tmp
+ command -v uv >/dev/null 2>&1 && return 0
+ for dir in "${HOME:-}/.local/bin" "${HOME:-}/.cargo/bin"; do
+ [ -n "${HOME:-}" ] || break
+ if [ -x "$dir/uv" ]; then PATH="$dir:$PATH"; export PATH; return 0; fi
+ done
+ dir="$HARNESS_RUNTIME/uv-$HARNESS_UV_VERSION"
+ if [ ! -x "$dir/uv" ]; then
+ case "$(_harness_platform)" in
+ darwin-arm64) asset=uv-aarch64-apple-darwin sum=dc304b9ed1b24174572290fba60ac3f6fe63c73a671f0439e62a91375841964d ;;
+ darwin-x64) asset=uv-x86_64-apple-darwin sum=e9ca61775532368fe518ab03e7a354c7ecab8ccb3c7d941c775fcc4a362b801b ;;
+ linux-x64) asset=uv-x86_64-unknown-linux-gnu sum=f97935763c04be3e692460a7aaeaaab8fc3b78fcf8b389da820b38ae7423a638 ;;
+ linux-arm64) asset=uv-aarch64-unknown-linux-gnu sum=0e9a3499b0587d449c9ff684c0160da607826e4af1cee220bc87f378702d3e08 ;;
+ *) echo "miss uv — there is no uv release for $(uname -s) $(uname -m); install it from https://docs.astral.sh/uv/"; return 1 ;;
+ esac
+ echo " fetching uv $HARNESS_UV_VERSION into $HARNESS_RUNTIME (it brings Python and the packages)"
+ mkdir -p "$HARNESS_RUNTIME" || { echo "miss cannot write $HARNESS_RUNTIME"; return 1; }
+ tmp="$(mktemp -d "$HARNESS_RUNTIME/.uv.XXXXXX")" || { echo "miss cannot write $HARNESS_RUNTIME"; return 1; }
+ if ! _harness_fetch "https://github.com/astral-sh/uv/releases/download/$HARNESS_UV_VERSION/$asset.tar.gz" "$tmp/uv.tar.gz" "$sum"; then
+ rm -rf "$tmp"; return 1
+ fi
+ tar -xzf "$tmp/uv.tar.gz" -C "$tmp" && chmod +x "$tmp/$asset/uv" "$tmp/$asset/uvx" \
+ || { rm -rf "$tmp"; echo "miss the uv archive would not unpack"; return 1; }
+ # Two installs at once both get here; whichever renames first wins and the other's copy goes.
+ # (mv onto a directory that exists would nest the copy inside it, hence the test.)
+ [ -e "$dir" ] || mv "$tmp/$asset" "$dir" 2>/dev/null || true
+ rm -rf "$tmp"
+ [ -x "$dir/uv" ] || { echo "miss uv did not land in $dir"; return 1; }
+ fi
+ PATH="$dir:$PATH"; export PATH
+}
+
+# harness_venv DIR VERSION [MIN [BELOW]] — MIN defaults to VERSION; BELOW is exclusive and optional.
+harness_venv() {
+ local dir="${1:?harness_venv needs a directory}" want="${2:?harness_venv needs a Python version}"
+ local min="${3:-$2}" below="${4:-}"
+ if [ -x "$dir/bin/python" ] && "$dir/bin/python" -c '
+import sys
+at = lambda s: tuple(int(p) for p in s.split("."))
+v = sys.version_info[:2]
+sys.exit(0 if v >= at(sys.argv[1]) and (not sys.argv[2] or v < at(sys.argv[2])) else 1)
+' "$min" "$below" 2>/dev/null; then
+ echo "ok $("$dir/bin/python" --version) in $dir"
+ return 0
+ fi
+ harness_uv || return 1
+ echo " python $want in $dir (uv downloads it when this machine has none)"
+ rm -rf "$dir"
+ # only-managed: the same python-build-standalone interpreter on every machine, so a package tested
+ # once is tested everywhere — not whichever Homebrew or pyenv Python happened to be first on PATH.
+ uv venv --quiet --seed --python "$want" --python-preference only-managed "$dir" \
+ || { echo "miss could not make a Python $want environment in $dir"; return 1; }
+ echo "ok $("$dir/bin/python" --version) in $dir"
+}
+
+harness_pip() {
+ local dir="${1:?harness_pip needs a venv}"
+ shift
+ harness_uv || return 1
+ # uv's own error comes first; the miss line is last, so it is the line the store shows.
+ uv pip install --quiet --python "$dir/bin/python" "$@" \
+ || { echo "miss could not install $* into $dir"; return 1; }
+}
+
+harness_micromamba() {
+ local dir asset sum
+ dir="$HARNESS_RUNTIME/micromamba-$HARNESS_MICROMAMBA_VERSION"
+ if [ ! -x "$dir/micromamba" ]; then
+ case "$(_harness_platform)" in
+ darwin-arm64) asset=micromamba-osx-arm64 sum=ec2a072f028e1a7cf20f3e2e74d5a8127cf5a5f27636375b5359811565f4e5be ;;
+ darwin-x64) asset=micromamba-osx-64 sum=1e71054bb3ac9a076e21f7ec48acfef536f9b3f1408f371a942784bf5ef83d8a ;;
+ linux-x64) asset=micromamba-linux-64 sum=366cd9cd8be14df1ab8ed50352a82111082a36686b2d389fdb79a92c3fafb3e3 ;;
+ linux-arm64) asset=micromamba-linux-aarch64 sum=9f93b974adcb4d166996af969b6cd371287d1a3e52733704727884d9b74cb7a7 ;;
+ *) echo "miss micromamba — there is no release for $(uname -s) $(uname -m)"; return 1 ;;
+ esac
+ echo " fetching micromamba $HARNESS_MICROMAMBA_VERSION into $HARNESS_RUNTIME (native libraries PyPI has no wheel for)"
+ mkdir -p "$dir" || { echo "miss cannot write $dir"; return 1; }
+ _harness_fetch "https://github.com/mamba-org/micromamba-releases/releases/download/$HARNESS_MICROMAMBA_VERSION/$asset" "$dir/micromamba.$$" "$sum" || return 1
+ chmod +x "$dir/micromamba.$$" && mv -f "$dir/micromamba.$$" "$dir/micromamba" \
+ || { rm -f "$dir/micromamba.$$"; echo "miss micromamba would not install into $dir"; return 1; }
+ fi
+ HARNESS_MICROMAMBA="$dir/micromamba"
+ export HARNESS_MICROMAMBA
+}
+
+# harness_conda_env DIR SPEC… — conda-forge only, packages cached under ~/.harness/runtime/mamba.
+harness_conda_env() {
+ local dir="${1:?harness_conda_env needs a directory}"
+ shift
+ # micromamba takes a relative --prefix as a name under its root prefix and "succeeds" there.
+ case "$dir" in /*) ;; *) dir="$PWD/$dir" ;; esac
+ harness_micromamba || return 1
+ MAMBA_ROOT_PREFIX="$HARNESS_RUNTIME/mamba" "$HARNESS_MICROMAMBA" create --yes --quiet \
+ --prefix "$dir" --override-channels --channel conda-forge "$@" >/dev/null \
+ && [ -d "$dir/conda-meta" ] \
+ || { echo "miss could not make the conda-forge environment in $dir ($*)"; return 1; }
+}
diff --git a/store/agents/circuitjs/toolchain/setup.sh b/store/agents/circuitjs/toolchain/setup.sh
index c45875590..95cc40f76 100755
--- a/store/agents/circuitjs/toolchain/setup.sh
+++ b/store/agents/circuitjs/toolchain/setup.sh
@@ -7,9 +7,14 @@ cd "$(dirname "$0")/.."
root=$PWD
# shellcheck disable=SC1091
. ./VERSIONS
+# shellcheck source=runtimes.sh
+. toolchain/runtimes.sh
command -v curl >/dev/null 2>&1 || { echo "miss curl on PATH"; exit 1; }
-command -v node >/dev/null 2>&1 || { echo "miss node >= 18 on PATH (the pane is a node server)"; exit 1; }
+# node reads the permutations out of the build here, and the pane is a node server: this machine's
+# own when it has one, else the Node Harness itself runs on.
+harness_node 18 || exit 1
+# The verdict is written for any python3 from 3.9 on, Apple's own included.
command -v python3 >/dev/null 2>&1 || { echo "miss python3 (the verdict)"; exit 1; }
command -v tar >/dev/null 2>&1 || { echo "miss tar on PATH"; exit 1; }
diff --git a/store/agents/circuitjs/toolchain/test_scripts.py b/store/agents/circuitjs/toolchain/test_scripts.py
index bf53a7c6d..4e445eafb 100644
--- a/store/agents/circuitjs/toolchain/test_scripts.py
+++ b/store/agents/circuitjs/toolchain/test_scripts.py
@@ -4,7 +4,8 @@ Each test builds a package root in a temp dir with this checkout's scripts (and
file by file, and runs them with PATH set to a bin dir holding only the tools the test grants: real
ones (bash, node, python3, tar, …) linked in, or stubs. `curl` is always a stub that serves a local
stand-in for the pinned source tarball and the project's CI build, so setup.sh runs end to end with
-no network, and a "miss node" branch is simply a PATH without node.
+no network, and a "miss node" branch is simply a PATH without node. Harness's own Node (runtimes.sh's
+fallback) is looked for in a runtime dir of the sandbox's, never the real ~/.harness.
"""
from __future__ import annotations
@@ -27,7 +28,7 @@ COMMIT = PINS["CIRCUITJS1_COMMIT"]
TARBALL_URL = PINS["CIRCUITJS1_TARBALL"].replace("${CIRCUITJS1_COMMIT}", COMMIT)
BUILD_URL = PINS["CIRCUITJS1_BUILD"]
PERMS = ["0123456789ABCDEF0123456789ABCDEF", "FEDCBA9876543210FEDCBA9876543210"]
-BASE_TOOLS = ("bash", "dirname", "mkdir", "rm", "mktemp", "find", "head", "cp", "ls", "wc", "tr",
+BASE_TOOLS = ("bash", "cat", "dirname", "mkdir", "rm", "mktemp", "find", "head", "cp", "ls", "wc", "tr",
"xargs", "shasum", "sort", "date", "du", "cut", "sed", "mv")
CURL = """#!/bin/bash
@@ -56,7 +57,9 @@ class Sandbox:
self.root = self.dir / "circuitjs"
self.bin = self.dir / "bin"
self.bin.mkdir()
+ self.runtime = self.dir / "runtime"
(self.root / "toolchain").mkdir(parents=True)
+ (self.root / "toolchain" / "runtimes.sh").symlink_to(PKG / "toolchain" / "runtimes.sh")
for tool in BASE_TOOLS + tools:
self.grant(tool)
@@ -70,13 +73,28 @@ class Sandbox:
def stub(self, name: str, body: str) -> None:
path = self.bin / name
+ path.unlink(missing_ok=True) # never write through a link to a real command
path.write_text(body)
path.chmod(0o755)
+ def harness_node(self) -> None:
+ """Harness's own Node, recorded where runtimes.sh looks when node is not on PATH."""
+ found = shutil.which("node")
+ assert found, "node is needed on this machine to run the test"
+ (self.dir / "harness-node").mkdir()
+ (self.dir / "harness-node" / "node").symlink_to(found)
+ self.runtime.mkdir()
+ (self.runtime / "current-node").write_text(f"{self.dir}/harness-node/node\n")
+
def run(self, rel: str, cwd: Path | None = None, **env: str) -> subprocess.CompletedProcess:
clean = {k: v for k, v in os.environ.items() if not k.startswith("HARNESS_")}
return subprocess.run([str(self.root / rel)], cwd=cwd or self.dir, capture_output=True, text=True,
- env={**clean, "PATH": str(self.bin), **env}, timeout=120)
+ env={**clean, "PATH": str(self.bin), "ADAPTER_RUNTIME_DIR": str(self.runtime), **env},
+ timeout=120)
+
+
+def no_node(box: Sandbox) -> str:
+ return f"miss node >= 18, and Harness's own Node is not in {box.runtime} — run `harness start` once to lay it down"
def lines(done: subprocess.CompletedProcess) -> list[str]:
@@ -142,10 +160,10 @@ class Setup(unittest.TestCase):
def test_each_tool_it_needs_is_named_when_missing(self) -> None:
for curl, have, missing in ((False, ("node", "python3", "tar"), "miss curl on PATH"),
- (True, ("python3", "tar"), "miss node >= 18 on PATH (the pane is a node server)"),
+ (True, ("python3", "tar"), None),
(True, ("node", "tar"), "miss python3 (the verdict)"),
(True, ("node", "python3"), "miss tar on PATH")):
- with self.subTest(missing=missing):
+ with self.subTest(missing=missing or "node"):
box = Sandbox(self, have)
box.link("toolchain/setup.sh")
box.link("VERSIONS")
@@ -153,7 +171,16 @@ class Setup(unittest.TestCase):
box.stub("curl", CURL)
done = box.run("toolchain/setup.sh")
self.assertEqual(done.returncode, 1)
- self.assertEqual(lines(done), [missing])
+ self.assertEqual(lines(done), [missing or no_node(box)])
+
+ def test_without_node_on_path_it_runs_on_harnesss_own(self) -> None:
+ box = self.sandbox("python3", "tar")
+ box.harness_node()
+ self.upstream()
+ done = self.setup(box)
+ self.assertEqual(done.returncode, 0, done.stdout + done.stderr)
+ self.assertEqual(lines(done)[1], " 2 compiled permutation(s), 2 theme images, 2 example circuits")
+ self.assertRegex(lines(done)[-1], r"^ok node v\d+\S* · Python 3\.\d+\.\d+$")
def test_it_installs_the_static_half_and_the_compiled_module(self) -> None:
box = self.sandbox("node", "python3", "tar")
@@ -275,15 +302,24 @@ class Doctor(unittest.TestCase):
self.assertEqual(len(out), 4)
def test_an_empty_machine(self) -> None:
- done = self.sandbox().run("toolchain/doctor.sh")
+ box = self.sandbox()
+ done = box.run("toolchain/doctor.sh")
self.assertEqual(done.returncode, 1)
self.assertEqual(lines(done), [
"miss upstream/ — run toolchain/setup.sh (it downloads CircuitJS1)",
"miss upstream/war/circuitjs1/circuits — run toolchain/setup.sh",
- "miss node >= 18 (the pane is a node server)",
+ no_node(box),
"miss python3 (the verdict)",
])
+ def test_harnesss_own_node_serves_the_pane(self) -> None:
+ box = self.sandbox("python3")
+ box.harness_node()
+ self.install(box)
+ done = box.run("toolchain/doctor.sh")
+ self.assertEqual(done.returncode, 0, done.stdout + done.stderr)
+ self.assertRegex(lines(done)[2], r"^ok node v\d+\S* \(the pane\)$")
+
def test_a_static_half_without_the_compiled_module(self) -> None:
box = self.sandbox("node", "python3")
self.install(box, perms=False)
@@ -350,6 +386,12 @@ class ViewerLauncher(unittest.TestCase):
self.assertEqual(done.returncode, 0, done.stderr)
self.assertEqual(done.stdout, f"node {box.root}/viewer.mjs in {box.dir} port=4100 ws=/Users/example/circuit\n")
+ def test_no_node_anywhere_is_a_miss_not_a_crash(self) -> None:
+ box = Sandbox(self, ("pwd",))
+ box.link("viewer.sh")
+ done = box.run("viewer.sh", HARNESS_VIEWER_PORT="4100", HARNESS_WORKSPACE="/Users/example/circuit")
+ self.assertEqual((done.returncode, done.stdout), (1, no_node(box) + "\n"))
+
if __name__ == "__main__":
unittest.main()
diff --git a/store/agents/circuitjs/viewer.sh b/store/agents/circuitjs/viewer.sh
index 9a40a19cc..375f83b6b 100755
--- a/store/agents/circuitjs/viewer.sh
+++ b/store/agents/circuitjs/viewer.sh
@@ -1,5 +1,10 @@
#!/usr/bin/env bash
# The pane. Harness runs this here with HARNESS_VIEWER_PORT and HARNESS_WORKSPACE.
+# The daemon starts it through a login shell whose PATH may hold no node at all.
set -euo pipefail
: "${HARNESS_VIEWER_PORT:?}"; : "${HARNESS_WORKSPACE:?}"
-exec node "$(cd "$(dirname "$0")" && pwd)/viewer.mjs"
+here="$(cd "$(dirname "$0")" && pwd)"
+# shellcheck source=toolchain/runtimes.sh
+. "$here/toolchain/runtimes.sh"
+harness_node 18 || exit 1
+exec node "$here/viewer.mjs"
diff --git a/store/agents/excalidraw/toolchain/runtimes.sh b/store/agents/excalidraw/toolchain/runtimes.sh
index 51fefe3f9..7223c78dc 100644
--- a/store/agents/excalidraw/toolchain/runtimes.sh
+++ b/store/agents/excalidraw/toolchain/runtimes.sh
@@ -77,6 +77,8 @@ harness_node() {
# A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
_harness_node_at_least "$min" && return 0
diff --git a/store/agents/manim/toolchain/runtimes.sh b/store/agents/manim/toolchain/runtimes.sh
index 51fefe3f9..7223c78dc 100644
--- a/store/agents/manim/toolchain/runtimes.sh
+++ b/store/agents/manim/toolchain/runtimes.sh
@@ -77,6 +77,8 @@ harness_node() {
# A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
_harness_node_at_least "$min" && return 0
diff --git a/store/agents/marimo/toolchain/runtimes.sh b/store/agents/marimo/toolchain/runtimes.sh
index 51fefe3f9..7223c78dc 100644
--- a/store/agents/marimo/toolchain/runtimes.sh
+++ b/store/agents/marimo/toolchain/runtimes.sh
@@ -77,6 +77,8 @@ harness_node() {
# A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
_harness_node_at_least "$min" && return 0
diff --git a/store/agents/marp/.gitignore b/store/agents/marp/.gitignore
index 7f365015b..b8a4359c7 100644
--- a/store/agents/marp/.gitignore
+++ b/store/agents/marp/.gitignore
@@ -1,3 +1,5 @@
node_modules/
toolchain/node_modules/
+toolchain/browser/
+toolchain/browser.partial/
.DS_Store
diff --git a/store/agents/marp/AGENTS.md b/store/agents/marp/AGENTS.md
index a2549ec61..74268c1e1 100644
--- a/store/agents/marp/AGENTS.md
+++ b/store/agents/marp/AGENTS.md
@@ -17,10 +17,11 @@ print a URL, never open a browser.
- **The skill** is linked into `.claude/skills/marp-deck`. Read it before the first save: it is
the arc of a keynote, the copy rules, the two themes and their slide classes, the art generator,
the check, the export. Everything below assumes you have.
-- **The toolchain** is `$MARP_TOOLCHAIN` (pinned `marp-core`, `marp-cli`, `art.mjs`, `check.mjs`)
- and the themes are `$MARP_THEMES`. Use them through the skill's commands; install nothing.
+- **The toolchain** is `$MARP_TOOLCHAIN` (pinned `marp-core`, `marp-cli`, `art.mjs`, `check.mjs`,
+ run as `art`, `check` and `marp` beside them) and the themes are `$MARP_THEMES`. Use them through
+ the skill's commands, never with a bare `node`; install nothing.
- **The verdict.** `.harness/verdict.json` is written by the check — by the viewer on every save
- and by you when you run `node "$MARP_TOOLCHAIN/check.mjs"`. Never edit it by hand.
+ and by you when you run `"$MARP_TOOLCHAIN/check"`. Never edit it by hand.
## How to work: the deck takes shape in the pane
@@ -36,7 +37,7 @@ early and often — not in your head and then all at once.
Reference each from its slide and save. The pane goes from words to a keynote in one step.
3. **Then fill, slide by slide, in order.** Headline, one line, speaker notes. Save after every
slide or two; every save redraws the pane.
-4. **Run the check after each pass**: `node "$MARP_TOOLCHAIN/check.mjs"`. Fix errors at once;
+4. **Run the check after each pass**: `"$MARP_TOOLCHAIN/check"`. Fix errors at once;
clear warnings before you call it done. The header reads *Ready* when it is a deck and the
Polish phase completes when the check has nothing left to say.
5. **Ask only what you cannot infer, and only after the outline is up.** Audience, length and
diff --git a/store/agents/marp/THIRD_PARTY_NOTICES.md b/store/agents/marp/THIRD_PARTY_NOTICES.md
index 48d4b4499..0f8606fe7 100644
--- a/store/agents/marp/THIRD_PARTY_NOTICES.md
+++ b/store/agents/marp/THIRD_PARTY_NOTICES.md
@@ -7,5 +7,11 @@ from npm by `toolchain/setup.sh` at the versions pinned in `toolchain/package.js
The `marp-browser.js` the viewer serves is marp-core's own browser bundle, served from that install.
The Marp mark on the Harness tile is the Marp team's, used to name their project.
+**Chrome for Testing headless shell** — Google, BSD-3-Clause with the third-party licences listed in the
+download's own `LICENSE.headless_shell`. Only on a machine with no Chromium-family browser of its own:
+`toolchain/setup.sh` downloads it from Google's Chrome for Testing bucket at the version marp-cli's
+puppeteer-core is pinned to, checks it against a pinned SHA-256, and marp-cli renders PDF and PPTX
+through it, unmodified. Not vendored.
+
Everything else here — the keynote themes, the art generator, the viewer page, the check, the
workspace template — is Autonomous's under `LICENSE`.
diff --git a/store/agents/marp/skills/marp-deck/SKILL.md b/store/agents/marp/skills/marp-deck/SKILL.md
index 5b2800e91..1c7bfd83d 100644
--- a/store/agents/marp/skills/marp-deck/SKILL.md
+++ b/store/agents/marp/skills/marp-deck/SKILL.md
@@ -149,14 +149,14 @@ seed, no network, no accounts:
```sh
# wallpapers: gradient light on black (or --light). Palettes: aurora sunset ocean graphite spectrum
-node "$MARP_TOOLCHAIN/art.mjs" wallpaper -o assets/hero.svg --palette aurora --seed 7
-node "$MARP_TOOLCHAIN/art.mjs" wallpaper -o assets/reveal.svg --palette aurora --seed 12
+"$MARP_TOOLCHAIN/art" wallpaper -o assets/hero.svg --palette aurora --seed 7
+"$MARP_TOOLCHAIN/art" wallpaper -o assets/reveal.svg --palette aurora --seed 12
# a chart from the talk's real numbers: bar (default) or line, in the accent colour
-node "$MARP_TOOLCHAIN/art.mjs" chart -o assets/growth.svg --data "2023:12,2024:31,2025:64" --label "Teams on it" --type bar
+"$MARP_TOOLCHAIN/art" chart -o assets/growth.svg --data "2023:12,2024:31,2025:64" --label "Teams on it" --type bar
# a screenshot or photo in a device, on a wallpaper: phone (default), laptop, window
-node "$MARP_TOOLCHAIN/art.mjs" frame -o assets/demo.svg --image assets/screen.png --kind laptop --palette ocean
+"$MARP_TOOLCHAIN/art" frame -o assets/demo.svg --image assets/screen.png --kind laptop --palette ocean
```
- Same palette across the deck; vary `--seed` so slides differ. Seeds 1–99 all look good.
@@ -169,8 +169,8 @@ node "$MARP_TOOLCHAIN/art.mjs" frame -o assets/demo.svg --image assets/screen.pn
## 5. The check
```sh
-node "$MARP_TOOLCHAIN/check.mjs" # deck.md
-node "$MARP_TOOLCHAIN/check.mjs" other.md # another file
+"$MARP_TOOLCHAIN/check" # deck.md
+"$MARP_TOOLCHAIN/check" other.md # another file
```
Writes `.harness/verdict.json` (what the pane header shows) and prints every finding. Errors: the
@@ -182,12 +182,12 @@ check on every save; run it yourself to read the list.
## 6. Export
```sh
-"$MARP_TOOLCHAIN/node_modules/.bin/marp" deck.md --theme-set "$MARP_THEMES" --allow-local-files --no-stdin -o dist/deck.pdf
-"$MARP_TOOLCHAIN/node_modules/.bin/marp" deck.md --theme-set "$MARP_THEMES" --allow-local-files --no-stdin -o dist/deck.pptx
-"$MARP_TOOLCHAIN/node_modules/.bin/marp" deck.md --theme-set "$MARP_THEMES" --allow-local-files --no-stdin -o dist/deck.html
+"$MARP_TOOLCHAIN/marp" deck.md --theme-set "$MARP_THEMES" --allow-local-files --no-stdin -o dist/deck.pdf
+"$MARP_TOOLCHAIN/marp" deck.md --theme-set "$MARP_THEMES" --allow-local-files --no-stdin -o dist/deck.pptx
+"$MARP_TOOLCHAIN/marp" deck.md --theme-set "$MARP_THEMES" --allow-local-files --no-stdin -o dist/deck.html
```
`--theme-set` is what makes the keynote themes real outside the viewer; without it the export falls
-back to the default theme. PDF and PPTX render through a Chromium-family browser on the machine;
-`toolchain/doctor.sh` says whether one is there. HTML needs nothing. `--no-stdin` matters in a tool
+back to the default theme. PDF and PPTX render through a Chromium-family browser — the machine's, or
+the headless one setup fetched when it had none; `toolchain/doctor.sh` says which. HTML needs nothing. `--no-stdin` matters in a tool
shell. Keynote (the app) opens the PPTX.
diff --git a/store/agents/marp/toolchain/art b/store/agents/marp/toolchain/art
new file mode 100755
index 000000000..8241432b2
--- /dev/null
+++ b/store/agents/marp/toolchain/art
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+# `"$MARP_TOOLCHAIN/art" …` — art.mjs on this machine's node, or on the Node Harness itself runs on when
+# the agent's shell has none on PATH.
+here="$(cd "$(dirname "$0")" && pwd)"
+# shellcheck source=runtimes.sh
+. "$here/runtimes.sh"
+harness_node 18 || exit 1
+exec node "$here/art.mjs" "$@"
diff --git a/store/agents/marp/toolchain/browser.sh b/store/agents/marp/toolchain/browser.sh
new file mode 100644
index 000000000..5bf7dde41
--- /dev/null
+++ b/store/agents/marp/toolchain/browser.sh
@@ -0,0 +1,26 @@
+# shellcheck shell=bash
+# browser.sh — sourced by setup.sh, doctor.sh and marp: the Chromium-family browser marp-cli renders PDF
+# and PPTX through. `marp_browser` prints this machine's (an app in /Applications, or a Chromium or
+# Chrome on PATH under a Linux package's name), else the headless shell setup.sh fetched into
+# toolchain/browser/, and fails when there is neither. MARP_APPLICATIONS_DIR stands in for
+# /Applications in the tests.
+#
+# The headless shell is Chrome for Testing's, at the version marp-cli's puppeteer-core is pinned to; one
+# fetched for another version does not count, so a bump here fetches again.
+MARP_HEADLESS_SHELL_VERSION=148.0.7778.97
+
+marp_browser() {
+ local apps="${MARP_APPLICATIONS_DIR:-/Applications}" app shell here
+ here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+ for app in "Google Chrome" Chromium "Microsoft Edge" "Brave Browser"; do
+ if [ -d "$apps/$app.app" ]; then echo "$apps/$app.app"; return 0; fi
+ done
+ for app in chromium chromium-browser google-chrome google-chrome-stable; do
+ command -v "$app" 2>/dev/null && return 0
+ done
+ [ "$(cat "$here/browser/.version" 2>/dev/null)" = "$MARP_HEADLESS_SHELL_VERSION" ] || return 1
+ for shell in "$here"/browser/chrome-headless-shell-*/chrome-headless-shell; do
+ if [ -x "$shell" ]; then echo "$shell"; return 0; fi
+ done
+ return 1
+}
diff --git a/store/agents/marp/toolchain/check b/store/agents/marp/toolchain/check
new file mode 100755
index 000000000..820c8f192
--- /dev/null
+++ b/store/agents/marp/toolchain/check
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+# `"$MARP_TOOLCHAIN/check" …` — check.mjs on this machine's node, or on the Node Harness itself runs on when
+# the agent's shell has none on PATH.
+here="$(cd "$(dirname "$0")" && pwd)"
+# shellcheck source=runtimes.sh
+. "$here/runtimes.sh"
+harness_node 18 || exit 1
+exec node "$here/check.mjs" "$@"
diff --git a/store/agents/marp/toolchain/doctor.sh b/store/agents/marp/toolchain/doctor.sh
index fcaa9dda9..48fe6a97e 100755
--- a/store/agents/marp/toolchain/doctor.sh
+++ b/store/agents/marp/toolchain/doctor.sh
@@ -3,23 +3,21 @@
# One line per check: `ok <what>` / `warn <what>` / `miss <what>`. Exit 1 only on a miss.
set -uo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
+# shellcheck source=runtimes.sh
+. "$ROOT/toolchain/runtimes.sh"
+# shellcheck source=browser.sh
+. "$ROOT/toolchain/browser.sh"
status=0
ok() { echo "ok $*"; }
warn() { echo "warn $*"; }
miss() { echo "miss $*"; status=1; }
-if command -v claude >/dev/null 2>&1 || [ -x "$HOME/.local/bin/claude" ]; then
- ok "claude on PATH"
+# The engine (claude) is Harness's to find, like every other package's; this checks what setup provides.
+# node: this machine's when it is new enough, else the Node Harness itself runs on.
+if harness_node 18 >/dev/null; then
+ ok "node $(node --version | sed 's/^v//')"
else
- miss "claude not found — install Claude Code: https://claude.ai/install"
-fi
-
-if command -v node >/dev/null 2>&1; then
- v="$(node --version | sed 's/^v//')"; major="${v%%.*}"
- case "$major" in (*[!0-9]*|"") major=0;; esac
- if [ "$major" -ge 18 ]; then ok "node $v"; else miss "node $v is older than 18 (brew install node)"; fi
-else
- miss "node not found (brew install node)"
+ harness_node 18; status=1
fi
if [ -d "$ROOT/toolchain/node_modules/@marp-team/marp-core" ]; then
@@ -39,15 +37,8 @@ else
miss "toolchain/viewer/ is incomplete — reinstall the harness"
fi
-# Export to PDF/PPTX renders through a Chromium-family browser marp-cli finds on its own.
-# MARP_APPLICATIONS_DIR is where to look instead of /Applications (the tests point it at a scratch folder).
-apps="${MARP_APPLICATIONS_DIR:-/Applications}"
-found=""
-for app in "$apps/Google Chrome.app" "$apps/Chromium.app" "$apps/Microsoft Edge.app" "$apps/Brave Browser.app"; do
- [ -d "$app" ] && { found="$app"; break; }
-done
-[ -z "$found" ] && command -v chromium >/dev/null 2>&1 && found="$(command -v chromium)"
-[ -z "$found" ] && command -v google-chrome >/dev/null 2>&1 && found="$(command -v google-chrome)"
-if [ -n "$found" ]; then ok "browser for PDF/PPTX export: $(basename "$found")"; else warn "no Chrome/Chromium/Edge — HTML export only, no PDF or PPTX"; fi
+# Export to PDF/PPTX renders through a Chromium-family browser: this machine's, or the headless shell
+# setup.sh fetched when it had none.
+if found="$(marp_browser)"; then ok "browser for PDF/PPTX export: $(basename "$found")"; else warn "no Chrome/Chromium/Edge — HTML export only until toolchain/setup.sh fetches a headless one"; fi
exit $status
diff --git a/store/agents/marp/toolchain/init-workspace.sh b/store/agents/marp/toolchain/init-workspace.sh
index b2c8c64c6..51528daab 100755
--- a/store/agents/marp/toolchain/init-workspace.sh
+++ b/store/agents/marp/toolchain/init-workspace.sh
@@ -4,4 +4,5 @@
set -euo pipefail
: "${HARNESS_DSH_DIR:?HARNESS_DSH_DIR is required}"
mkdir -p .harness assets
-node "$HARNESS_DSH_DIR/toolchain/check.mjs" deck.md >/dev/null 2>&1 || true
+# Through the wrapper, which finds a node when the daemon's PATH has none.
+"$HARNESS_DSH_DIR/toolchain/check" deck.md >/dev/null 2>&1 || true
diff --git a/store/agents/marp/toolchain/marp b/store/agents/marp/toolchain/marp
new file mode 100755
index 000000000..232432a7c
--- /dev/null
+++ b/store/agents/marp/toolchain/marp
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+# `"$MARP_TOOLCHAIN/marp" deck.md … -o dist/deck.pdf` — the pinned marp-cli, whose own launcher is a
+# node script: node on PATH first (this machine's, or the Node Harness itself runs on).
+here="$(cd "$(dirname "$0")" && pwd)"
+# shellcheck source=runtimes.sh
+. "$here/runtimes.sh"
+harness_node 18 || exit 1
+[ -x "$here/node_modules/.bin/marp" ] || { echo "miss marp-cli — run toolchain/setup.sh"; exit 1; }
+# A machine with no browser of its own renders PDF and PPTX through the headless shell setup.sh fetched.
+# shellcheck source=browser.sh
+. "$here/browser.sh"
+if [ -z "${CHROME_PATH:-}" ] && browser="$(marp_browser)"; then
+ case "$browser" in */chrome-headless-shell) export CHROME_PATH="$browser" ;; esac
+fi
+exec "$here/node_modules/.bin/marp" "$@"
diff --git a/store/agents/marp/toolchain/runtimes.sh b/store/agents/marp/toolchain/runtimes.sh
new file mode 100644
index 000000000..7223c78dc
--- /dev/null
+++ b/store/agents/marp/toolchain/runtimes.sh
@@ -0,0 +1,192 @@
+# shellcheck shell=bash
+# runtimes.sh — the interpreters a store package runs on, found on this machine or fetched, never
+# asked of the person who pressed Get.
+#
+# Sourced (not run) by a package's setup, doctor and viewer scripts. A new Mac has Apple's Python 3.9,
+# no Homebrew and, for most people, no Node on PATH; a package that answers "brew install [email protected]"
+# has failed its install. So:
+#
+# harness_node 18 node >= 18 on PATH, with npm: the machine's own, else the Node Harness
+# itself runs on (~/.harness/runtime/current-node, laid down with the CLI)
+# harness_uv uv on PATH: the machine's own, else a pinned, checksummed release
+# fetched into ~/.harness/runtime
+# harness_venv DIR 3.12 [MIN [BELOW]]
+# DIR is a venv on CPython 3.12, which uv downloads when the machine
+# has none. A venv already there on a Python in [MIN, BELOW) is kept.
+# harness_pip DIR PKG… install into that venv, through uv
+# harness_micromamba micromamba, pinned and checksummed, for native libraries PyPI has
+# no wheel for (pycairo on macOS)
+# harness_conda_env DIR SPEC… DIR is a conda-forge environment with those packages
+#
+# Every function prints `miss …` and returns 1 when it cannot deliver, so `harness_node 18 || exit 1`
+# reads like the rest of a setup script. Nothing here touches the user's shell profile; what it
+# installs lands in ~/.harness/runtime or the package's own directory (uv keeps its download cache
+# where it always does, which a venv does not depend on).
+#
+# ONE copy is written by hand: store/tools/runtimes.sh in the OpenHarness repository. Each package
+# carries an identical copy (a package installs alone, so it cannot reach this one);
+# `node store/tools/sync-runtimes.mjs` rewrites them and the CLI's store spec fails when one drifts.
+
+HARNESS_RUNTIME="${ADAPTER_RUNTIME_DIR:-${HOME:-}/.harness/runtime}"
+# The Pythons uv downloads live with Harness's other runtimes, not in uv's own ~/.local/share/uv:
+# a package's venv points at its interpreter, and `uv python uninstall` there must not break it.
+UV_PYTHON_INSTALL_DIR="${UV_PYTHON_INSTALL_DIR:-$HARNESS_RUNTIME/python}"
+export UV_PYTHON_INSTALL_DIR
+HARNESS_UV_VERSION=0.12.15
+HARNESS_MICROMAMBA_VERSION=2.9.0-0
+
+_harness_platform() {
+ case "$(uname -s)-$(uname -m)" in
+ Darwin-arm64) echo darwin-arm64 ;;
+ Darwin-x86_64) echo darwin-x64 ;;
+ Linux-x86_64) echo linux-x64 ;;
+ Linux-aarch64 | Linux-arm64) echo linux-arm64 ;;
+ *) return 1 ;;
+ esac
+}
+
+_harness_sha256() {
+ if command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" | cut -d' ' -f1
+ else sha256sum "$1" | cut -d' ' -f1; fi
+}
+
+# _harness_fetch URL DEST SHA256 — DEST exists only if what arrived matches the pinned checksum.
+_harness_fetch() {
+ local part="$2.part.$$"
+ if ! curl -fsSL --retry 3 --connect-timeout 20 --max-time 900 -o "$part" "$1"; then
+ rm -f "$part"; echo "miss could not download $1 — check this machine's internet connection"; return 1
+ fi
+ if [ "$(_harness_sha256 "$part")" != "$3" ]; then
+ rm -f "$part"; echo "miss $1 did not match its pinned checksum; nothing was installed"; return 1
+ fi
+ mv -f "$part" "$2"
+}
+
+_harness_node_at_least() {
+ command -v node >/dev/null 2>&1 || return 1
+ node -e '
+ const [a, b = 0] = process.argv[1].split(".").map(Number)
+ const [x, y] = process.versions.node.split(".").map(Number)
+ process.exit(x > a || (x === a && y >= b) ? 0 : 1)
+ ' "$1" >/dev/null 2>&1
+}
+
+harness_node() {
+ local min="${1:-18}" recorded saved="$PATH" own=0
+ _harness_node_at_least "$min" && own=1
+ # A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
+ if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
+ recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
+ if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
+ PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
+ _harness_node_at_least "$min" && return 0
+ PATH="$saved"; export PATH; hash -r 2>/dev/null || true
+ [ "$own" = 1 ] && return 0
+ echo "miss node >= $min — this machine's newest is $("${recorded%/*}/node" -v), Harness's own; update Harness"
+ return 1
+ fi
+ [ "$own" = 1 ] && return 0
+ echo "miss node >= $min, and Harness's own Node is not in $HARNESS_RUNTIME — run \`harness start\` once to lay it down"
+ return 1
+}
+
+harness_uv() {
+ local dir asset sum tmp
+ command -v uv >/dev/null 2>&1 && return 0
+ for dir in "${HOME:-}/.local/bin" "${HOME:-}/.cargo/bin"; do
+ [ -n "${HOME:-}" ] || break
+ if [ -x "$dir/uv" ]; then PATH="$dir:$PATH"; export PATH; return 0; fi
+ done
+ dir="$HARNESS_RUNTIME/uv-$HARNESS_UV_VERSION"
+ if [ ! -x "$dir/uv" ]; then
+ case "$(_harness_platform)" in
+ darwin-arm64) asset=uv-aarch64-apple-darwin sum=dc304b9ed1b24174572290fba60ac3f6fe63c73a671f0439e62a91375841964d ;;
+ darwin-x64) asset=uv-x86_64-apple-darwin sum=e9ca61775532368fe518ab03e7a354c7ecab8ccb3c7d941c775fcc4a362b801b ;;
+ linux-x64) asset=uv-x86_64-unknown-linux-gnu sum=f97935763c04be3e692460a7aaeaaab8fc3b78fcf8b389da820b38ae7423a638 ;;
+ linux-arm64) asset=uv-aarch64-unknown-linux-gnu sum=0e9a3499b0587d449c9ff684c0160da607826e4af1cee220bc87f378702d3e08 ;;
+ *) echo "miss uv — there is no uv release for $(uname -s) $(uname -m); install it from https://docs.astral.sh/uv/"; return 1 ;;
+ esac
+ echo " fetching uv $HARNESS_UV_VERSION into $HARNESS_RUNTIME (it brings Python and the packages)"
+ mkdir -p "$HARNESS_RUNTIME" || { echo "miss cannot write $HARNESS_RUNTIME"; return 1; }
+ tmp="$(mktemp -d "$HARNESS_RUNTIME/.uv.XXXXXX")" || { echo "miss cannot write $HARNESS_RUNTIME"; return 1; }
+ if ! _harness_fetch "https://github.com/astral-sh/uv/releases/download/$HARNESS_UV_VERSION/$asset.tar.gz" "$tmp/uv.tar.gz" "$sum"; then
+ rm -rf "$tmp"; return 1
+ fi
+ tar -xzf "$tmp/uv.tar.gz" -C "$tmp" && chmod +x "$tmp/$asset/uv" "$tmp/$asset/uvx" \
+ || { rm -rf "$tmp"; echo "miss the uv archive would not unpack"; return 1; }
+ # Two installs at once both get here; whichever renames first wins and the other's copy goes.
+ # (mv onto a directory that exists would nest the copy inside it, hence the test.)
+ [ -e "$dir" ] || mv "$tmp/$asset" "$dir" 2>/dev/null || true
+ rm -rf "$tmp"
+ [ -x "$dir/uv" ] || { echo "miss uv did not land in $dir"; return 1; }
+ fi
+ PATH="$dir:$PATH"; export PATH
+}
+
+# harness_venv DIR VERSION [MIN [BELOW]] — MIN defaults to VERSION; BELOW is exclusive and optional.
+harness_venv() {
+ local dir="${1:?harness_venv needs a directory}" want="${2:?harness_venv needs a Python version}"
+ local min="${3:-$2}" below="${4:-}"
+ if [ -x "$dir/bin/python" ] && "$dir/bin/python" -c '
+import sys
+at = lambda s: tuple(int(p) for p in s.split("."))
+v = sys.version_info[:2]
+sys.exit(0 if v >= at(sys.argv[1]) and (not sys.argv[2] or v < at(sys.argv[2])) else 1)
+' "$min" "$below" 2>/dev/null; then
+ echo "ok $("$dir/bin/python" --version) in $dir"
+ return 0
+ fi
+ harness_uv || return 1
+ echo " python $want in $dir (uv downloads it when this machine has none)"
+ rm -rf "$dir"
+ # only-managed: the same python-build-standalone interpreter on every machine, so a package tested
+ # once is tested everywhere — not whichever Homebrew or pyenv Python happened to be first on PATH.
+ uv venv --quiet --seed --python "$want" --python-preference only-managed "$dir" \
+ || { echo "miss could not make a Python $want environment in $dir"; return 1; }
+ echo "ok $("$dir/bin/python" --version) in $dir"
+}
+
+harness_pip() {
+ local dir="${1:?harness_pip needs a venv}"
+ shift
+ harness_uv || return 1
+ # uv's own error comes first; the miss line is last, so it is the line the store shows.
+ uv pip install --quiet --python "$dir/bin/python" "$@" \
+ || { echo "miss could not install $* into $dir"; return 1; }
+}
+
+harness_micromamba() {
+ local dir asset sum
+ dir="$HARNESS_RUNTIME/micromamba-$HARNESS_MICROMAMBA_VERSION"
+ if [ ! -x "$dir/micromamba" ]; then
+ case "$(_harness_platform)" in
+ darwin-arm64) asset=micromamba-osx-arm64 sum=ec2a072f028e1a7cf20f3e2e74d5a8127cf5a5f27636375b5359811565f4e5be ;;
+ darwin-x64) asset=micromamba-osx-64 sum=1e71054bb3ac9a076e21f7ec48acfef536f9b3f1408f371a942784bf5ef83d8a ;;
+ linux-x64) asset=micromamba-linux-64 sum=366cd9cd8be14df1ab8ed50352a82111082a36686b2d389fdb79a92c3fafb3e3 ;;
+ linux-arm64) asset=micromamba-linux-aarch64 sum=9f93b974adcb4d166996af969b6cd371287d1a3e52733704727884d9b74cb7a7 ;;
+ *) echo "miss micromamba — there is no release for $(uname -s) $(uname -m)"; return 1 ;;
+ esac
+ echo " fetching micromamba $HARNESS_MICROMAMBA_VERSION into $HARNESS_RUNTIME (native libraries PyPI has no wheel for)"
+ mkdir -p "$dir" || { echo "miss cannot write $dir"; return 1; }
+ _harness_fetch "https://github.com/mamba-org/micromamba-releases/releases/download/$HARNESS_MICROMAMBA_VERSION/$asset" "$dir/micromamba.$$" "$sum" || return 1
+ chmod +x "$dir/micromamba.$$" && mv -f "$dir/micromamba.$$" "$dir/micromamba" \
+ || { rm -f "$dir/micromamba.$$"; echo "miss micromamba would not install into $dir"; return 1; }
+ fi
+ HARNESS_MICROMAMBA="$dir/micromamba"
+ export HARNESS_MICROMAMBA
+}
+
+# harness_conda_env DIR SPEC… — conda-forge only, packages cached under ~/.harness/runtime/mamba.
+harness_conda_env() {
+ local dir="${1:?harness_conda_env needs a directory}"
+ shift
+ # micromamba takes a relative --prefix as a name under its root prefix and "succeeds" there.
+ case "$dir" in /*) ;; *) dir="$PWD/$dir" ;; esac
+ harness_micromamba || return 1
+ MAMBA_ROOT_PREFIX="$HARNESS_RUNTIME/mamba" "$HARNESS_MICROMAMBA" create --yes --quiet \
+ --prefix "$dir" --override-channels --channel conda-forge "$@" >/dev/null \
+ && [ -d "$dir/conda-meta" ] \
+ || { echo "miss could not make the conda-forge environment in $dir ($*)"; return 1; }
+}
diff --git a/store/agents/marp/toolchain/setup.sh b/store/agents/marp/toolchain/setup.sh
index 158151108..3a7075a5e 100755
--- a/store/agents/marp/toolchain/setup.sh
+++ b/store/agents/marp/toolchain/setup.sh
@@ -1,13 +1,60 @@
#!/usr/bin/env bash
# Harness DSH setup — install the pinned Marp toolchain into ./toolchain/node_modules. cwd = the
# install dir. Idempotent: a second run with the same lockfile is a no-op.
+#
+# PDF and PPTX export render through a Chromium-family browser. A machine with none (a new Mac has only
+# Safari) gets Chrome for Testing's headless shell in toolchain/browser/, pinned and checksummed; the
+# `marp` wrapper points marp-cli at it. Without it the deck still shows live and exports to HTML, so a
+# failed fetch is a warning, not a failed install.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT/toolchain"
-command -v node >/dev/null 2>&1 || { echo "miss node — install Node 18 or newer (brew install node)"; exit 1; }
+# shellcheck source=runtimes.sh
+. ./runtimes.sh
+# shellcheck source=browser.sh
+. ./browser.sh
+# This machine's node when it has one, else the Node Harness itself runs on (npm is beside it).
+harness_node 18 || exit 1
if [ -f package-lock.json ]; then
- npm ci --no-audit --no-fund
+ npm ci --no-audit --no-fund --no-update-notifier --loglevel=error
else
- npm install --no-audit --no-fund
+ npm install --no-audit --no-fund --no-update-notifier --loglevel=error
fi
echo "ok marp toolchain $(node -p "require('@marp-team/marp-core/package.json').version")"
+
+# fetch_headless_shell — toolchain/browser/chrome-headless-shell-<platform>/, or a warn line and no change.
+fetch_headless_shell() {
+ local platform sum url
+ case "$(uname -s)-$(uname -m)" in
+ Darwin-arm64) platform=mac-arm64 sum=f3747ddcb6caba3972ea064878f338ea5a9a2505c7595e68506d394d44baacc8 ;;
+ Darwin-x86_64) platform=mac-x64 sum=1f547b3f4e3cad27366871be2bc22f93e433535ed924638d8a72367bccab6560 ;;
+ Linux-x86_64) platform=linux64 sum=e122f8722a0cbd15c954fb02220db761eb2fda0a466618b03e3e31406f2b0167 ;;
+ *) echo "warn no Chrome/Chromium/Edge, and Chrome has no headless build for $(uname -s) $(uname -m) — HTML export only"; return 0 ;;
+ esac
+ url="https://storage.googleapis.com/chrome-for-testing-public/$MARP_HEADLESS_SHELL_VERSION/$platform/chrome-headless-shell-$platform.zip"
+ echo " no Chrome/Chromium/Edge here: fetching Chrome's headless shell $MARP_HEADLESS_SHELL_VERSION for PDF and PPTX (~100 MB)"
+ rm -rf browser.partial
+ mkdir browser.partial
+ if ! curl -fsSL --retry 3 --connect-timeout 20 --max-time 900 -o browser.partial/shell.zip "$url"; then
+ rm -rf browser.partial; echo "warn could not download $url — HTML export only until toolchain/setup.sh runs again"; return 0
+ fi
+ if [ "$(shasum -a 256 browser.partial/shell.zip 2>/dev/null || sha256sum browser.partial/shell.zip)" != "$sum browser.partial/shell.zip" ]; then
+ rm -rf browser.partial; echo "warn $url did not match its pinned checksum — HTML export only"; return 0
+ fi
+ # extract-zip (marp-cli's own dependency, pinned by the lockfile) keeps the executable bit, and not
+ # every Linux has unzip. It wants an absolute destination.
+ if ! node_modules/.bin/extract-zip browser.partial/shell.zip "$PWD/browser.partial"; then
+ rm -rf browser.partial; echo "warn the headless shell would not unpack — HTML export only until toolchain/setup.sh runs again"; return 0
+ fi
+ rm -f browser.partial/shell.zip
+ echo "$MARP_HEADLESS_SHELL_VERSION" > browser.partial/.version
+ rm -rf browser
+ mv browser.partial browser
+ echo "ok browser for PDF/PPTX export: chrome-headless-shell $MARP_HEADLESS_SHELL_VERSION"
+}
+
+if browser="$(marp_browser)"; then
+ echo "ok browser for PDF/PPTX export: $(basename "$browser")"
+else
+ fetch_headless_shell
+fi
diff --git a/store/agents/marp/toolchain/test/scripts.test.mjs b/store/agents/marp/toolchain/test/scripts.test.mjs
index 723d07b79..1ed7d0347 100644
--- a/store/agents/marp/toolchain/test/scripts.test.mjs
+++ b/store/agents/marp/toolchain/test/scripts.test.mjs
@@ -1,6 +1,7 @@
-// setup.sh, doctor.sh, init-workspace.sh and viewer.sh, run for real by /bin/bash against a scratch
-// install whose PATH is only stub commands and the few coreutils the scripts use: every ok, warn and
-// miss line is reached without npm, a browser or a network.
+// setup.sh, doctor.sh, init-workspace.sh, viewer.sh and the art/check/marp wrappers, run for real by
+// /bin/bash against a scratch install whose PATH is only stub commands and the few coreutils the scripts
+// use: every ok, warn and miss line is reached without npm, a browser or a network. runtimes.sh looks for
+// Harness's own Node in a runtime dir of the sandbox's (ADAPTER_RUNTIME_DIR), never the real ~/.harness.
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { spawnSync } from 'node:child_process'
@@ -10,7 +11,12 @@ import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
const TOOLCHAIN = fileURLToPath(new URL('..', import.meta.url))
-const COREUTILS = ['dirname', 'sed', 'basename', 'mkdir']
+const COREUTILS = ['dirname', 'sed', 'basename', 'mkdir', 'cat', 'bash', 'rm', 'mv']
+const SHELL_VERSION = readFileSync(join(TOOLCHAIN, 'browser.sh'), 'utf8').match(/^MARP_HEADLESS_SHELL_VERSION=(\S+)$/m)[1]
+const SHELL_SUMS = Object.fromEntries([...readFileSync(join(TOOLCHAIN, 'setup.sh'), 'utf8').matchAll(/platform=(\S+) sum=([0-9a-f]{64})/g)].map((m) => [m[1], m[2]]))
+const shellUrl = (platform) => `https://storage.googleapis.com/chrome-for-testing-public/${SHELL_VERSION}/${platform}/chrome-headless-shell-${platform}.zip`
+// node as runtimes.sh probes it: `node -e <script> 18` exits 0 when new enough.
+const NODE = 'case "$1" in -e) exit "${NODE_OLD:-0}" ;; --version) echo v22.11.0 ;; -p) echo 4.1.0 ;; *) exit "${NODE_EXIT:-0}" ;; esac'
// A bash line tracer's hooks (BASH_ENV sourcing a DEBUG trap that appends to SHCOV_OUT), passed through when set.
const TRACER = Object.fromEntries(['BASH_ENV', 'SHCOV_OUT'].filter((k) => process.env[k]).map((k) => [k, process.env[k]]))
@@ -20,41 +26,66 @@ function sandbox(t) {
const install = join(root, 'install')
mkdirSync(join(install, 'toolchain'), { recursive: true })
// Linked, not copied: $0 still names the scratch install, and a line tracer can map back to the source.
- for (const script of ['doctor.sh', 'setup.sh', 'init-workspace.sh', 'viewer.sh']) symlinkSync(join(TOOLCHAIN, script), join(install, 'toolchain', script))
+ for (const script of ['doctor.sh', 'setup.sh', 'init-workspace.sh', 'viewer.sh', 'runtimes.sh', 'browser.sh', 'art', 'check', 'marp']) symlinkSync(join(TOOLCHAIN, script), join(install, 'toolchain', script))
const bin = join(root, 'bin')
const home = join(root, 'home')
const apps = join(root, 'Applications')
+ const runtime = join(root, 'runtime')
for (const dir of [bin, home, apps]) mkdirSync(dir)
for (const name of COREUTILS) symlinkSync(['/bin', '/usr/bin'].map((d) => join(d, name)).find((p) => existsSync(p)), join(bin, name))
const calls = join(root, 'calls.log')
writeFileSync(calls, '')
const box = {
- root, install, bin, home, apps,
+ root, install, bin, home, apps, runtime,
file(rel, body = '') { const full = join(install, rel); mkdirSync(dirname(full), { recursive: true }); writeFileSync(full, body); return full },
stub(name, body = '', where = bin) {
const full = join(where, name)
mkdirSync(where, { recursive: true })
+ rmSync(full, { force: true }) // never write through a link to a real command
writeFileSync(full, `#!/bin/bash\necho "${name} $*" >> "$CALLS"\n${body}\n`)
chmodSync(full, 0o755)
return full
},
- run(script, { cwd = install, env = {} } = {}) {
- const r = spawnSync('/bin/bash', [join(install, 'toolchain', script)], {
+ run(script, { cwd = install, env = {}, args = [] } = {}) {
+ const r = spawnSync('/bin/bash', [join(install, 'toolchain', script), ...args], {
cwd, encoding: 'utf8', timeout: 30_000,
- env: { PATH: bin, HOME: home, CALLS: calls, MARP_APPLICATIONS_DIR: apps, ...TRACER, ...env },
+ env: { PATH: bin, HOME: home, CALLS: calls, MARP_APPLICATIONS_DIR: apps, ADAPTER_RUNTIME_DIR: runtime, ...TRACER, ...env },
})
return { code: r.status, lines: r.stdout.split('\n').filter(Boolean), stderr: r.stderr }
},
logged: () => readFileSync(calls, 'utf8').split('\n').filter(Boolean),
+ /** The calls, minus runtimes.sh's `node -e` version probe (its script spans several lines). */
+ ran: () => readFileSync(calls, 'utf8').split('\n').filter((c) => /^(node \/|npm |marp )/.test(c)),
+ /** No node on PATH, Harness's own recorded where the CLI lays it down. */
+ harnessNode() {
+ const node = box.stub('node', NODE, join(root, 'harness-node'))
+ mkdirSync(runtime, { recursive: true })
+ writeFileSync(join(runtime, 'current-node'), `${node}\n`)
+ },
+ noNode: () => `miss node >= 18, and Harness's own Node is not in ${runtime} — run \`harness start\` once to lay it down`,
+ /** The headless shell as setup.sh leaves it, for `version` (the pinned one by default). */
+ headlessShell(version = SHELL_VERSION) {
+ const shell = box.stub('chrome-headless-shell', '', join(install, 'toolchain', 'browser', 'chrome-headless-shell-mac-arm64'))
+ writeFileSync(join(install, 'toolchain', 'browser', '.version'), `${version}\n`)
+ return shell
+ },
+ /** No browser here: uname says `platform`, curl hands over a zip unless CURL_FAIL, shasum answers `sum`,
+ * and extract-zip lays out the shell unless UNZIP_FAIL. */
+ shellDownload({ uname = 'case "$1" in -s) echo Darwin ;; -m) echo arm64 ;; esac', sum = SHELL_SUMS['mac-arm64'] } = {}) {
+ box.stub('uname', uname)
+ box.stub('curl', 'for a in "$@"; do [ "$prev" = -o ] && out="$a"; prev="$a"; done\n[ -n "$CURL_FAIL" ] && exit 22\necho zip > "$out"')
+ box.stub('shasum', `echo "${sum} $3"`)
+ box.stub('extract-zip', '[ -n "$UNZIP_FAIL" ] && exit 1\nmkdir -p "$2/chrome-headless-shell-mac-arm64" && printf "#!/bin/sh\\n" > "$2/chrome-headless-shell-mac-arm64/chrome-headless-shell" && /bin/chmod +x "$2/chrome-headless-shell-mac-arm64/chrome-headless-shell"',
+ join(install, 'toolchain', 'node_modules', '.bin'))
+ },
}
return box
}
-/** A machine with everything: claude, node 22, the installed toolchain, the pane, Chrome. */
+/** A machine with everything: node 22, the installed toolchain, the pane, Chrome. */
function healthy(t) {
const box = sandbox(t)
- box.stub('claude')
- box.stub('node', 'case "$1" in --version) echo v22.11.0 ;; -p) echo 4.1.0 ;; esac')
+ box.stub('node', NODE)
mkdirSync(join(box.install, 'toolchain/node_modules/@marp-team/marp-core'), { recursive: true })
chmodSync(box.file('toolchain/node_modules/.bin/marp'), 0o755)
for (const f of ['toolchain/viewer.mjs', 'toolchain/viewer/index.html', 'toolchain/viewer/app.js']) box.file(f)
@@ -63,7 +94,6 @@ function healthy(t) {
}
const OK = [
- 'ok claude on PATH',
'ok node 22.11.0',
'ok marp-core 4.1.0',
'ok marp-cli (PDF, PPTX and HTML export)',
@@ -77,28 +107,20 @@ test('doctor: a machine with everything is ready', (t) => {
assert.equal(r.code, 0)
})
-test('doctor: claude from the installer, outside PATH, counts', (t) => {
+test('doctor: without node on PATH, Harness\'s own serves', (t) => {
const box = healthy(t)
- rmSync(join(box.bin, 'claude'))
- box.stub('claude', '', join(box.home, '.local', 'bin'))
- assert.deepEqual(box.run('doctor.sh').lines[0], 'ok claude on PATH')
- rmSync(join(box.home, '.local'), { recursive: true })
- const r = box.run('doctor.sh')
- assert.equal(r.lines[0], 'miss claude not found — install Claude Code: https://claude.ai/install')
- assert.equal(r.code, 1)
+ rmSync(join(box.bin, 'node'))
+ box.harnessNode()
+ assert.deepEqual(box.run('doctor.sh').lines, OK)
})
-test('doctor: node missing, too old, or saying something that is not a version', (t) => {
+test('doctor: node missing, or older than 18 with no Harness Node to fall back on', (t) => {
const box = healthy(t)
- for (const [version, line] of [['v16.20.2', 'miss node 16.20.2 is older than 18 (brew install node)'], ['nightly', 'miss node nightly is older than 18 (brew install node)']]) {
- box.stub('node', `case "$1" in --version) echo ${version} ;; -p) echo 4.1.0 ;; esac`)
- const r = box.run('doctor.sh')
- assert.equal(r.lines[1], line)
- assert.equal(r.code, 1)
- }
+ let r = box.run('doctor.sh', { env: { NODE_OLD: '1' } })
+ assert.deepEqual([r.code, r.lines[0]], [1, box.noNode()])
rmSync(join(box.bin, 'node'))
- const r = box.run('doctor.sh')
- assert.deepEqual(r.lines.slice(1, 3), ['miss node not found (brew install node)', 'ok marp-core present'], 'the version needs node; the install is still there')
+ r = box.run('doctor.sh')
+ assert.deepEqual(r.lines.slice(0, 2), [box.noNode(), 'ok marp-core present'], 'the version needs node; the install is still there')
assert.equal(r.code, 1)
})
@@ -106,17 +128,17 @@ test('doctor: no toolchain is a miss, no marp-cli only a warning, an incomplete
const box = healthy(t)
rmSync(join(box.install, 'toolchain/node_modules/.bin/marp'))
let r = box.run('doctor.sh')
- assert.equal(r.lines[3], 'warn marp-cli missing — decks show live but do not export')
+ assert.equal(r.lines[2], 'warn marp-cli missing — decks show live but do not export')
assert.equal(r.code, 0)
rmSync(join(box.install, 'toolchain/node_modules'), { recursive: true })
r = box.run('doctor.sh')
- assert.equal(r.lines[2], 'miss marp toolchain not installed — run toolchain/setup.sh')
+ assert.equal(r.lines[1], 'miss marp toolchain not installed — run toolchain/setup.sh')
assert.equal(r.code, 1)
for (const f of ['toolchain/viewer/app.js', 'toolchain/viewer/index.html', 'toolchain/viewer.mjs']) {
const box2 = healthy(t)
rmSync(join(box2.install, f))
const r2 = box2.run('doctor.sh')
- assert.equal(r2.lines[4], 'miss toolchain/viewer/ is incomplete — reinstall the harness', f)
+ assert.equal(r2.lines[3], 'miss toolchain/viewer/ is incomplete — reinstall the harness', f)
assert.equal(r2.code, 1)
}
})
@@ -126,17 +148,30 @@ test('doctor: each browser marp-cli can export with, or a warning when there is
const box = healthy(t)
rmSync(join(box.apps, 'Google Chrome.app'), { recursive: true })
mkdirSync(join(box.apps, app))
- assert.equal(box.run('doctor.sh').lines[5], `ok browser for PDF/PPTX export: ${app}`)
+ assert.equal(box.run('doctor.sh').lines[4], `ok browser for PDF/PPTX export: ${app}`)
}
const box = healthy(t)
rmSync(join(box.apps, 'Google Chrome.app'), { recursive: true })
let r = box.run('doctor.sh')
- assert.equal(r.lines[5], 'warn no Chrome/Chromium/Edge — HTML export only, no PDF or PPTX')
+ assert.equal(r.lines[4], 'warn no Chrome/Chromium/Edge — HTML export only until toolchain/setup.sh fetches a headless one')
assert.equal(r.code, 0, 'a warning is not a miss')
- box.stub('google-chrome')
- assert.equal(box.run('doctor.sh').lines[5], 'ok browser for PDF/PPTX export: google-chrome')
+ box.stub('google-chrome-stable')
+ assert.equal(box.run('doctor.sh').lines[4], 'ok browser for PDF/PPTX export: google-chrome-stable')
+ box.stub('chromium-browser')
+ assert.equal(box.run('doctor.sh').lines[4], 'ok browser for PDF/PPTX export: chromium-browser')
box.stub('chromium')
- assert.equal(box.run('doctor.sh').lines[5], 'ok browser for PDF/PPTX export: chromium')
+ assert.equal(box.run('doctor.sh').lines[4], 'ok browser for PDF/PPTX export: chromium')
+})
+
+test('doctor: the headless shell setup.sh fetched counts, at the pinned version only', (t) => {
+ const box = healthy(t)
+ rmSync(join(box.apps, 'Google Chrome.app'), { recursive: true })
+ box.headlessShell('120.0.0.0')
+ assert.equal(box.run('doctor.sh').lines[4], 'warn no Chrome/Chromium/Edge — HTML export only until toolchain/setup.sh fetches a headless one')
+ box.headlessShell()
+ assert.equal(box.run('doctor.sh').lines[4], 'ok browser for PDF/PPTX export: chrome-headless-shell')
+ rmSync(join(box.install, 'toolchain', 'browser', 'chrome-headless-shell-mac-arm64', 'chrome-headless-shell'))
+ assert.equal(box.run('doctor.sh').lines[4], 'warn no Chrome/Chromium/Edge — HTML export only until toolchain/setup.sh fetches a headless one')
})
test('setup: npm ci from the lockfile, npm install without one, and the version it got', (t) => {
@@ -144,18 +179,97 @@ test('setup: npm ci from the lockfile, npm install without one, and the version
box.stub('node', 'echo 4.1.0')
box.stub('npm')
box.file('toolchain/package-lock.json', '{}')
+ mkdirSync(join(box.apps, 'Google Chrome.app'))
let r = box.run('setup.sh')
- assert.deepEqual([r.code, r.lines], [0, ['ok marp toolchain 4.1.0']])
+ assert.deepEqual([r.code, r.lines], [0, ['ok marp toolchain 4.1.0', 'ok browser for PDF/PPTX export: Google Chrome.app']])
rmSync(join(box.install, 'toolchain/package-lock.json'))
r = box.run('setup.sh')
assert.equal(r.code, 0)
- assert.deepEqual(box.logged().filter((c) => c.startsWith('npm')), ['npm ci --no-audit --no-fund', 'npm install --no-audit --no-fund'])
+ assert.deepEqual(box.logged().filter((c) => c.startsWith('npm')), ['npm ci --no-audit --no-fund --no-update-notifier --loglevel=error', 'npm install --no-audit --no-fund --no-update-notifier --loglevel=error'])
+})
+
+test('setup: without node on PATH, npm runs on Harness\'s own Node', (t) => {
+ const box = sandbox(t)
+ box.harnessNode()
+ box.stub('npm', 'echo "npm sees $(command -v node)" >> "$CALLS"')
+ box.file('toolchain/package-lock.json', '{}')
+ box.stub('chromium')
+ const r = box.run('setup.sh')
+ assert.deepEqual([r.code, r.lines], [0, ['ok marp toolchain 4.1.0', 'ok browser for PDF/PPTX export: chromium']])
+ assert.ok(box.logged().includes(`npm sees ${join(box.root, 'harness-node', 'node')}`))
+})
+
+test('setup: a machine with no browser gets Chrome\'s headless shell, once', (t) => {
+ const box = sandbox(t)
+ box.stub('node', 'echo 4.1.0')
+ box.stub('npm')
+ box.shellDownload()
+ mkdirSync(join(box.install, 'toolchain', 'browser.partial', 'from-a-killed-run'), { recursive: true })
+ let r = box.run('setup.sh')
+ assert.deepEqual([r.code, r.lines], [0, [
+ 'ok marp toolchain 4.1.0',
+ ` no Chrome/Chromium/Edge here: fetching Chrome's headless shell ${SHELL_VERSION} for PDF and PPTX (~100 MB)`,
+ `ok browser for PDF/PPTX export: chrome-headless-shell ${SHELL_VERSION}`,
+ ]], r.stderr)
+ const browser = join(box.install, 'toolchain', 'browser')
+ assert.equal(readFileSync(join(browser, '.version'), 'utf8'), `${SHELL_VERSION}\n`)
+ assert.ok(existsSync(join(browser, 'chrome-headless-shell-mac-arm64', 'chrome-headless-shell')))
+ assert.ok(!existsSync(join(browser, 'shell.zip')) && !existsSync(join(box.install, 'toolchain', 'browser.partial')))
+ assert.ok(box.logged().includes(`curl -fsSL --retry 3 --connect-timeout 20 --max-time 900 -o browser.partial/shell.zip ${shellUrl('mac-arm64')}`))
+ assert.ok(box.logged().includes(`extract-zip browser.partial/shell.zip ${box.install}/toolchain/browser.partial`))
+ r = box.run('setup.sh')
+ assert.deepEqual(r.lines, ['ok marp toolchain 4.1.0', 'ok browser for PDF/PPTX export: chrome-headless-shell'])
+ assert.equal(box.logged().filter((c) => c.startsWith('curl')).length, 1, 'the second run keeps it')
+ writeFileSync(join(browser, '.version'), '120.0.0.0\n')
+ r = box.run('setup.sh')
+ assert.equal(r.lines[2], `ok browser for PDF/PPTX export: chrome-headless-shell ${SHELL_VERSION}`, 'one for another version is fetched again')
+})
+
+test('setup: each platform Chrome builds a headless shell for, and the ones it does not', (t) => {
+ for (const [s, m, platform] of [['Darwin', 'x86_64', 'mac-x64'], ['Linux', 'x86_64', 'linux64']]) {
+ const box = sandbox(t)
+ box.stub('node', 'echo 4.1.0')
+ box.stub('npm')
+ box.shellDownload({ uname: `case "$1" in -s) echo ${s} ;; -m) echo ${m} ;; esac`, sum: SHELL_SUMS[platform] })
+ const r = box.run('setup.sh')
+ assert.equal(r.lines[2], `ok browser for PDF/PPTX export: chrome-headless-shell ${SHELL_VERSION}`, platform)
+ assert.ok(box.logged().some((c) => c.endsWith(shellUrl(platform))), platform)
+ }
+ const box = sandbox(t)
+ box.stub('node', 'echo 4.1.0')
+ box.stub('npm')
+ box.shellDownload({ uname: 'case "$1" in -s) echo Linux ;; -m) echo aarch64 ;; esac' })
+ const r = box.run('setup.sh')
+ assert.deepEqual([r.code, r.lines.at(-1)], [0, 'warn no Chrome/Chromium/Edge, and Chrome has no headless build for Linux aarch64 — HTML export only'])
+ assert.ok(!box.logged().some((c) => c.startsWith('curl')))
+})
+
+test('setup: a headless shell that does not arrive is a warning, and leaves nothing behind', (t) => {
+ const cases = [
+ [{ CURL_FAIL: '1' }, {}, `warn could not download ${shellUrl('mac-arm64')} — HTML export only until toolchain/setup.sh runs again`],
+ [{}, { sum: '0'.repeat(64) }, `warn ${shellUrl('mac-arm64')} did not match its pinned checksum — HTML export only`],
+ [{ UNZIP_FAIL: '1' }, {}, 'warn the headless shell would not unpack — HTML export only until toolchain/setup.sh runs again'],
+ [{ NO_SHASUM: '1' }, {}, `warn ${shellUrl('mac-arm64')} did not match its pinned checksum — HTML export only`],
+ ]
+ for (const [env, download, line] of cases) {
+ const box = sandbox(t)
+ box.stub('node', 'echo 4.1.0')
+ box.stub('npm')
+ box.shellDownload(download)
+ if (env.NO_SHASUM) { // no shasum on this machine: coreutils' sha256sum answers instead
+ rmSync(join(box.bin, 'shasum'))
+ box.stub('sha256sum', 'echo "1111 $1"')
+ }
+ const r = box.run('setup.sh', { env })
+ assert.deepEqual([r.code, r.lines.at(-1)], [0, line])
+ assert.ok(!existsSync(join(box.install, 'toolchain', 'browser.partial')) && !existsSync(join(box.install, 'toolchain', 'browser')))
+ }
})
test('setup: no node is a miss, and a failed install fails setup', (t) => {
const box = sandbox(t)
let r = box.run('setup.sh')
- assert.deepEqual([r.code, r.lines], [1, ['miss node — install Node 18 or newer (brew install node)']])
+ assert.deepEqual([r.code, r.lines], [1, [box.noNode()]])
box.stub('node', 'echo 4.1.0')
box.stub('npm', 'exit 1')
r = box.run('setup.sh')
@@ -167,11 +281,20 @@ test('init-workspace: makes the folders and seeds the verdict, even when the che
const box = sandbox(t)
const ws = join(box.root, 'ws')
mkdirSync(ws)
- box.stub('node', 'exit 1')
+ box.stub('node', 'case "$1" in -e) exit 0 ;; *) exit 1 ;; esac')
const r = box.run('init-workspace.sh', { cwd: ws, env: { HARNESS_DSH_DIR: box.install } })
assert.equal(r.code, 0, r.stderr)
assert.ok(existsSync(join(ws, '.harness')) && existsSync(join(ws, 'assets')))
- assert.deepEqual(box.logged(), [`node ${box.install}/toolchain/check.mjs deck.md`])
+ assert.deepEqual(box.ran(), [`node ${box.install}/toolchain/check.mjs deck.md`])
+})
+
+test('init-workspace: no node anywhere still makes the folders', (t) => {
+ const box = sandbox(t)
+ const ws = join(box.root, 'ws')
+ mkdirSync(ws)
+ const r = box.run('init-workspace.sh', { cwd: ws, env: { HARNESS_DSH_DIR: box.install } })
+ assert.deepEqual([r.code, r.lines, box.logged()], [0, [], []])
+ assert.ok(existsSync(join(ws, '.harness')) && existsSync(join(ws, 'assets')))
})
test('init-workspace: needs the install dir', (t) => {
@@ -192,5 +315,58 @@ test('viewer.sh: needs a port and a workspace, then becomes the node server', (t
assert.match(r.stderr, /HARNESS_WORKSPACE is required/)
r = box.run('viewer.sh', { env: { HARNESS_VIEWER_PORT: '4100', HARNESS_WORKSPACE: '/Users/example/deck' } })
assert.deepEqual([r.code, r.lines], [0, ['server 4100 /Users/example/deck']])
- assert.deepEqual(box.logged(), [`node ${box.install}/toolchain/viewer.mjs`])
+ assert.deepEqual(box.ran(), [`node ${box.install}/toolchain/viewer.mjs`])
+})
+
+test('viewer.sh: no node anywhere is a miss', (t) => {
+ const box = sandbox(t)
+ const r = box.run('viewer.sh', { env: { HARNESS_VIEWER_PORT: '4100', HARNESS_WORKSPACE: '/Users/example/deck' } })
+ assert.deepEqual([r.code, r.lines], [1, [box.noNode()]])
+})
+
+test('art and check: the .mjs beside them, on Harness\'s own Node when PATH has none, with the exit code', (t) => {
+ const box = sandbox(t)
+ box.harnessNode()
+ const ws = join(box.root, 'ws')
+ mkdirSync(ws)
+ let r = box.run('art', { cwd: ws, args: ['wallpaper', '-o', 'assets/hero.svg', '--seed', '7'] })
+ assert.equal(r.code, 0, r.stderr)
+ r = box.run('check', { cwd: ws, args: ['talk.md'], env: { NODE_EXIT: '1' } })
+ assert.equal(r.code, 1, 'a deck that is not ready exits 1 through the wrapper')
+ assert.deepEqual(box.ran(), [
+ `node ${box.install}/toolchain/art.mjs wallpaper -o assets/hero.svg --seed 7`,
+ `node ${box.install}/toolchain/check.mjs talk.md`,
+ ])
+})
+
+test('art, check and marp: no node anywhere is a miss', (t) => {
+ const box = sandbox(t)
+ for (const wrapper of ['art', 'check', 'marp']) {
+ const r = box.run(wrapper, { args: ['deck.md'] })
+ assert.deepEqual([r.code, r.lines], [1, [box.noNode()]], wrapper)
+ }
+ assert.deepEqual(box.logged(), [])
+})
+
+test('marp: the pinned marp-cli, with node on PATH for its own launcher, or a miss before setup', (t) => {
+ const box = sandbox(t)
+ box.harnessNode()
+ let r = box.run('marp', { args: ['deck.md', '-o', 'dist/deck.pdf'] })
+ assert.deepEqual([r.code, r.lines], [1, ['miss marp-cli — run toolchain/setup.sh']])
+ box.stub('marp', 'echo "node is $(command -v node)"; exit 3', join(box.install, 'toolchain', 'node_modules', '.bin'))
+ r = box.run('marp', { args: ['deck.md', '-o', 'dist/deck.pdf'] })
+ assert.deepEqual([r.code, r.lines], [3, [`node is ${join(box.root, 'harness-node', 'node')}`]])
+ assert.deepEqual(box.ran(), ['marp deck.md -o dist/deck.pdf'])
+})
+
+test('marp: renders through the headless shell only when the machine has no browser of its own', (t) => {
+ const box = sandbox(t)
+ box.stub('node', NODE)
+ box.stub('marp', 'echo "CHROME_PATH=${CHROME_PATH:-}"', join(box.install, 'toolchain', 'node_modules', '.bin'))
+ assert.deepEqual(box.run('marp').lines, ['CHROME_PATH='], 'no browser at all: marp-cli says so itself')
+ const shell = box.headlessShell()
+ assert.deepEqual(box.run('marp').lines, [`CHROME_PATH=${shell}`])
+ assert.deepEqual(box.run('marp', { env: { CHROME_PATH: '/Users/example/chrome' } }).lines, ['CHROME_PATH=/Users/example/chrome'], 'one the user chose wins')
+ mkdirSync(join(box.apps, 'Microsoft Edge.app'))
+ assert.deepEqual(box.run('marp').lines, ['CHROME_PATH='], 'a browser of its own: marp-cli finds it')
})
diff --git a/store/agents/marp/toolchain/viewer.sh b/store/agents/marp/toolchain/viewer.sh
index 8c178d105..bd868cb6a 100755
--- a/store/agents/marp/toolchain/viewer.sh
+++ b/store/agents/marp/toolchain/viewer.sh
@@ -6,8 +6,13 @@
# HARNESS_VIEWER_PORT the loopback port to listen on
# HARNESS_WORKSPACE the workspace folder (the agent's cwd)
# HARNESS_DSH_DIR this install dir (also the cwd)
+#
+# The daemon starts it through a login shell whose PATH may hold no node at all.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
: "${HARNESS_VIEWER_PORT:?HARNESS_VIEWER_PORT is required}"
: "${HARNESS_WORKSPACE:?HARNESS_WORKSPACE is required}"
+# shellcheck source=runtimes.sh
+. "$ROOT/toolchain/runtimes.sh"
+harness_node 18 || exit 1
exec node "$ROOT/toolchain/viewer.mjs"
diff --git a/store/agents/mujoco/toolchain/runtimes.sh b/store/agents/mujoco/toolchain/runtimes.sh
index 51fefe3f9..7223c78dc 100644
--- a/store/agents/mujoco/toolchain/runtimes.sh
+++ b/store/agents/mujoco/toolchain/runtimes.sh
@@ -77,6 +77,8 @@ harness_node() {
# A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
_harness_node_at_least "$min" && return 0
diff --git a/store/agents/phaser/toolchain/runtimes.sh b/store/agents/phaser/toolchain/runtimes.sh
index 51fefe3f9..7223c78dc 100644
--- a/store/agents/phaser/toolchain/runtimes.sh
+++ b/store/agents/phaser/toolchain/runtimes.sh
@@ -77,6 +77,8 @@ harness_node() {
# A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
_harness_node_at_least "$min" && return 0
diff --git a/store/agents/rdkit/toolchain/runtimes.sh b/store/agents/rdkit/toolchain/runtimes.sh
index 51fefe3f9..7223c78dc 100644
--- a/store/agents/rdkit/toolchain/runtimes.sh
+++ b/store/agents/rdkit/toolchain/runtimes.sh
@@ -77,6 +77,8 @@ harness_node() {
# A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
_harness_node_at_least "$min" && return 0
diff --git a/store/agents/remotion/toolchain/doctor.sh b/store/agents/remotion/toolchain/doctor.sh
index e2344e1d6..614544bbf 100755
--- a/store/agents/remotion/toolchain/doctor.sh
+++ b/store/agents/remotion/toolchain/doctor.sh
@@ -1,7 +1,11 @@
#!/usr/bin/env bash
set -u; cd "$(dirname "$0")/.."; bad=0
+# shellcheck source=runtimes.sh
+. toolchain/runtimes.sh
+harness_node 18 >/dev/null; node_ok=$? # PATH now names Harness's own Node when this machine has none
if [ -x node_modules/.bin/remotion ]; then echo "ok remotion $(node -p "require('remotion/package.json').version")"; else echo "miss node_modules — run toolchain/setup.sh"; bad=1; fi
if [ -f upstream/skills/remotion-best-practices/SKILL.md ]; then echo "ok skills @ $(cat upstream/.harness-commit 2>/dev/null)"; else echo "miss upstream skills — run toolchain/setup.sh"; bad=1; fi
-if [ -x toolchain/remotion ] && node -e 'process.exit(Number(process.versions.node.split(".")[0]) >= 18 ? 0 : 1)' 2>/dev/null; then echo "ok \$REMOTION (render progress for the pane) · node $(node -v)"; else echo "miss node >= 18 or an executable toolchain/remotion"; bad=1; fi
+if [ "$node_ok" != 0 ]; then harness_node 18; bad=1
+elif [ -x toolchain/remotion ]; then echo "ok \$REMOTION (render progress for the pane) · node $(node -v)"; else echo "miss an executable toolchain/remotion"; bad=1; fi
command -v python3 >/dev/null 2>&1 && echo "ok $(python3 --version)" || { echo "miss python3"; bad=1; }
exit $bad
diff --git a/store/agents/remotion/toolchain/init-workspace.sh b/store/agents/remotion/toolchain/init-workspace.sh
index 2d6d66d7f..f79391443 100755
--- a/store/agents/remotion/toolchain/init-workspace.sh
+++ b/store/agents/remotion/toolchain/init-workspace.sh
@@ -5,4 +5,8 @@ set -euo pipefail
: "${HARNESS_DSH_DIR:?}"
mkdir -p .harness out public
[ -e node_modules ] || ln -s "$HARNESS_DSH_DIR/node_modules" node_modules
+# The verdict bundles through Remotion's CLI, a node script: node on PATH for it (the seed is best-effort).
+# shellcheck source=runtimes.sh
+. "$HARNESS_DSH_DIR/toolchain/runtimes.sh"
+harness_node 18 >/dev/null || true
python3 "$HARNESS_DSH_DIR/toolchain/verdict.py" >/dev/null 2>&1 || true
diff --git a/store/agents/remotion/toolchain/remotion b/store/agents/remotion/toolchain/remotion
index 48e3a4120..9e826343d 100755
--- a/store/agents/remotion/toolchain/remotion
+++ b/store/agents/remotion/toolchain/remotion
@@ -1,3 +1,8 @@
#!/usr/bin/env bash
# `$REMOTION`: Remotion's CLI, with render progress written to .harness/render.json for the pane.
-exec node "$(cd "$(dirname "$0")" && pwd)/remotion.mjs" "$@"
+# The agent's shell may have no node on PATH: Harness's own serves, and the CLI it spawns inherits it.
+here="$(cd "$(dirname "$0")" && pwd)"
+# shellcheck source=runtimes.sh
+. "$here/runtimes.sh"
+harness_node 18 || exit 1
+exec node "$here/remotion.mjs" "$@"
diff --git a/store/agents/remotion/toolchain/runtimes.sh b/store/agents/remotion/toolchain/runtimes.sh
new file mode 100644
index 000000000..7223c78dc
--- /dev/null
+++ b/store/agents/remotion/toolchain/runtimes.sh
@@ -0,0 +1,192 @@
+# shellcheck shell=bash
+# runtimes.sh — the interpreters a store package runs on, found on this machine or fetched, never
+# asked of the person who pressed Get.
+#
+# Sourced (not run) by a package's setup, doctor and viewer scripts. A new Mac has Apple's Python 3.9,
+# no Homebrew and, for most people, no Node on PATH; a package that answers "brew install [email protected]"
+# has failed its install. So:
+#
+# harness_node 18 node >= 18 on PATH, with npm: the machine's own, else the Node Harness
+# itself runs on (~/.harness/runtime/current-node, laid down with the CLI)
+# harness_uv uv on PATH: the machine's own, else a pinned, checksummed release
+# fetched into ~/.harness/runtime
+# harness_venv DIR 3.12 [MIN [BELOW]]
+# DIR is a venv on CPython 3.12, which uv downloads when the machine
+# has none. A venv already there on a Python in [MIN, BELOW) is kept.
+# harness_pip DIR PKG… install into that venv, through uv
+# harness_micromamba micromamba, pinned and checksummed, for native libraries PyPI has
+# no wheel for (pycairo on macOS)
+# harness_conda_env DIR SPEC… DIR is a conda-forge environment with those packages
+#
+# Every function prints `miss …` and returns 1 when it cannot deliver, so `harness_node 18 || exit 1`
+# reads like the rest of a setup script. Nothing here touches the user's shell profile; what it
+# installs lands in ~/.harness/runtime or the package's own directory (uv keeps its download cache
+# where it always does, which a venv does not depend on).
+#
+# ONE copy is written by hand: store/tools/runtimes.sh in the OpenHarness repository. Each package
+# carries an identical copy (a package installs alone, so it cannot reach this one);
+# `node store/tools/sync-runtimes.mjs` rewrites them and the CLI's store spec fails when one drifts.
+
+HARNESS_RUNTIME="${ADAPTER_RUNTIME_DIR:-${HOME:-}/.harness/runtime}"
+# The Pythons uv downloads live with Harness's other runtimes, not in uv's own ~/.local/share/uv:
+# a package's venv points at its interpreter, and `uv python uninstall` there must not break it.
+UV_PYTHON_INSTALL_DIR="${UV_PYTHON_INSTALL_DIR:-$HARNESS_RUNTIME/python}"
+export UV_PYTHON_INSTALL_DIR
+HARNESS_UV_VERSION=0.12.15
+HARNESS_MICROMAMBA_VERSION=2.9.0-0
+
+_harness_platform() {
+ case "$(uname -s)-$(uname -m)" in
+ Darwin-arm64) echo darwin-arm64 ;;
+ Darwin-x86_64) echo darwin-x64 ;;
+ Linux-x86_64) echo linux-x64 ;;
+ Linux-aarch64 | Linux-arm64) echo linux-arm64 ;;
+ *) return 1 ;;
+ esac
+}
+
+_harness_sha256() {
+ if command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" | cut -d' ' -f1
+ else sha256sum "$1" | cut -d' ' -f1; fi
+}
+
+# _harness_fetch URL DEST SHA256 — DEST exists only if what arrived matches the pinned checksum.
+_harness_fetch() {
+ local part="$2.part.$$"
+ if ! curl -fsSL --retry 3 --connect-timeout 20 --max-time 900 -o "$part" "$1"; then
+ rm -f "$part"; echo "miss could not download $1 — check this machine's internet connection"; return 1
+ fi
+ if [ "$(_harness_sha256 "$part")" != "$3" ]; then
+ rm -f "$part"; echo "miss $1 did not match its pinned checksum; nothing was installed"; return 1
+ fi
+ mv -f "$part" "$2"
+}
+
+_harness_node_at_least() {
+ command -v node >/dev/null 2>&1 || return 1
+ node -e '
+ const [a, b = 0] = process.argv[1].split(".").map(Number)
+ const [x, y] = process.versions.node.split(".").map(Number)
+ process.exit(x > a || (x === a && y >= b) ? 0 : 1)
+ ' "$1" >/dev/null 2>&1
+}
+
+harness_node() {
+ local min="${1:-18}" recorded saved="$PATH" own=0
+ _harness_node_at_least "$min" && own=1
+ # A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
+ if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
+ recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
+ if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
+ PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
+ _harness_node_at_least "$min" && return 0
+ PATH="$saved"; export PATH; hash -r 2>/dev/null || true
+ [ "$own" = 1 ] && return 0
+ echo "miss node >= $min — this machine's newest is $("${recorded%/*}/node" -v), Harness's own; update Harness"
+ return 1
+ fi
+ [ "$own" = 1 ] && return 0
+ echo "miss node >= $min, and Harness's own Node is not in $HARNESS_RUNTIME — run \`harness start\` once to lay it down"
+ return 1
+}
+
+harness_uv() {
+ local dir asset sum tmp
+ command -v uv >/dev/null 2>&1 && return 0
+ for dir in "${HOME:-}/.local/bin" "${HOME:-}/.cargo/bin"; do
+ [ -n "${HOME:-}" ] || break
+ if [ -x "$dir/uv" ]; then PATH="$dir:$PATH"; export PATH; return 0; fi
+ done
+ dir="$HARNESS_RUNTIME/uv-$HARNESS_UV_VERSION"
+ if [ ! -x "$dir/uv" ]; then
+ case "$(_harness_platform)" in
+ darwin-arm64) asset=uv-aarch64-apple-darwin sum=dc304b9ed1b24174572290fba60ac3f6fe63c73a671f0439e62a91375841964d ;;
+ darwin-x64) asset=uv-x86_64-apple-darwin sum=e9ca61775532368fe518ab03e7a354c7ecab8ccb3c7d941c775fcc4a362b801b ;;
+ linux-x64) asset=uv-x86_64-unknown-linux-gnu sum=f97935763c04be3e692460a7aaeaaab8fc3b78fcf8b389da820b38ae7423a638 ;;
+ linux-arm64) asset=uv-aarch64-unknown-linux-gnu sum=0e9a3499b0587d449c9ff684c0160da607826e4af1cee220bc87f378702d3e08 ;;
+ *) echo "miss uv — there is no uv release for $(uname -s) $(uname -m); install it from https://docs.astral.sh/uv/"; return 1 ;;
+ esac
+ echo " fetching uv $HARNESS_UV_VERSION into $HARNESS_RUNTIME (it brings Python and the packages)"
+ mkdir -p "$HARNESS_RUNTIME" || { echo "miss cannot write $HARNESS_RUNTIME"; return 1; }
+ tmp="$(mktemp -d "$HARNESS_RUNTIME/.uv.XXXXXX")" || { echo "miss cannot write $HARNESS_RUNTIME"; return 1; }
+ if ! _harness_fetch "https://github.com/astral-sh/uv/releases/download/$HARNESS_UV_VERSION/$asset.tar.gz" "$tmp/uv.tar.gz" "$sum"; then
+ rm -rf "$tmp"; return 1
+ fi
+ tar -xzf "$tmp/uv.tar.gz" -C "$tmp" && chmod +x "$tmp/$asset/uv" "$tmp/$asset/uvx" \
+ || { rm -rf "$tmp"; echo "miss the uv archive would not unpack"; return 1; }
+ # Two installs at once both get here; whichever renames first wins and the other's copy goes.
+ # (mv onto a directory that exists would nest the copy inside it, hence the test.)
+ [ -e "$dir" ] || mv "$tmp/$asset" "$dir" 2>/dev/null || true
+ rm -rf "$tmp"
+ [ -x "$dir/uv" ] || { echo "miss uv did not land in $dir"; return 1; }
+ fi
+ PATH="$dir:$PATH"; export PATH
+}
+
+# harness_venv DIR VERSION [MIN [BELOW]] — MIN defaults to VERSION; BELOW is exclusive and optional.
+harness_venv() {
+ local dir="${1:?harness_venv needs a directory}" want="${2:?harness_venv needs a Python version}"
+ local min="${3:-$2}" below="${4:-}"
+ if [ -x "$dir/bin/python" ] && "$dir/bin/python" -c '
+import sys
+at = lambda s: tuple(int(p) for p in s.split("."))
+v = sys.version_info[:2]
+sys.exit(0 if v >= at(sys.argv[1]) and (not sys.argv[2] or v < at(sys.argv[2])) else 1)
+' "$min" "$below" 2>/dev/null; then
+ echo "ok $("$dir/bin/python" --version) in $dir"
+ return 0
+ fi
+ harness_uv || return 1
+ echo " python $want in $dir (uv downloads it when this machine has none)"
+ rm -rf "$dir"
+ # only-managed: the same python-build-standalone interpreter on every machine, so a package tested
+ # once is tested everywhere — not whichever Homebrew or pyenv Python happened to be first on PATH.
+ uv venv --quiet --seed --python "$want" --python-preference only-managed "$dir" \
+ || { echo "miss could not make a Python $want environment in $dir"; return 1; }
+ echo "ok $("$dir/bin/python" --version) in $dir"
+}
+
+harness_pip() {
+ local dir="${1:?harness_pip needs a venv}"
+ shift
+ harness_uv || return 1
+ # uv's own error comes first; the miss line is last, so it is the line the store shows.
+ uv pip install --quiet --python "$dir/bin/python" "$@" \
+ || { echo "miss could not install $* into $dir"; return 1; }
+}
+
+harness_micromamba() {
+ local dir asset sum
+ dir="$HARNESS_RUNTIME/micromamba-$HARNESS_MICROMAMBA_VERSION"
+ if [ ! -x "$dir/micromamba" ]; then
+ case "$(_harness_platform)" in
+ darwin-arm64) asset=micromamba-osx-arm64 sum=ec2a072f028e1a7cf20f3e2e74d5a8127cf5a5f27636375b5359811565f4e5be ;;
+ darwin-x64) asset=micromamba-osx-64 sum=1e71054bb3ac9a076e21f7ec48acfef536f9b3f1408f371a942784bf5ef83d8a ;;
+ linux-x64) asset=micromamba-linux-64 sum=366cd9cd8be14df1ab8ed50352a82111082a36686b2d389fdb79a92c3fafb3e3 ;;
+ linux-arm64) asset=micromamba-linux-aarch64 sum=9f93b974adcb4d166996af969b6cd371287d1a3e52733704727884d9b74cb7a7 ;;
+ *) echo "miss micromamba — there is no release for $(uname -s) $(uname -m)"; return 1 ;;
+ esac
+ echo " fetching micromamba $HARNESS_MICROMAMBA_VERSION into $HARNESS_RUNTIME (native libraries PyPI has no wheel for)"
+ mkdir -p "$dir" || { echo "miss cannot write $dir"; return 1; }
+ _harness_fetch "https://github.com/mamba-org/micromamba-releases/releases/download/$HARNESS_MICROMAMBA_VERSION/$asset" "$dir/micromamba.$$" "$sum" || return 1
+ chmod +x "$dir/micromamba.$$" && mv -f "$dir/micromamba.$$" "$dir/micromamba" \
+ || { rm -f "$dir/micromamba.$$"; echo "miss micromamba would not install into $dir"; return 1; }
+ fi
+ HARNESS_MICROMAMBA="$dir/micromamba"
+ export HARNESS_MICROMAMBA
+}
+
+# harness_conda_env DIR SPEC… — conda-forge only, packages cached under ~/.harness/runtime/mamba.
+harness_conda_env() {
+ local dir="${1:?harness_conda_env needs a directory}"
+ shift
+ # micromamba takes a relative --prefix as a name under its root prefix and "succeeds" there.
+ case "$dir" in /*) ;; *) dir="$PWD/$dir" ;; esac
+ harness_micromamba || return 1
+ MAMBA_ROOT_PREFIX="$HARNESS_RUNTIME/mamba" "$HARNESS_MICROMAMBA" create --yes --quiet \
+ --prefix "$dir" --override-channels --channel conda-forge "$@" >/dev/null \
+ && [ -d "$dir/conda-meta" ] \
+ || { echo "miss could not make the conda-forge environment in $dir ($*)"; return 1; }
+}
diff --git a/store/agents/remotion/toolchain/setup.sh b/store/agents/remotion/toolchain/setup.sh
index ac86d6a46..2b1f93e8c 100755
--- a/store/agents/remotion/toolchain/setup.sh
+++ b/store/agents/remotion/toolchain/setup.sh
@@ -7,7 +7,10 @@ set -euo pipefail
cd "$(dirname "$0")/.."
# shellcheck disable=SC1091
. ./VERSIONS
-command -v node >/dev/null 2>&1 && node -e 'process.exit(Number(process.versions.node.split(".")[0]) >= 18 ? 0 : 1)' || { echo "miss node >= 18 on PATH"; exit 1; }
+# shellcheck source=runtimes.sh
+. toolchain/runtimes.sh
+# This machine's node when it has one, else the Node Harness itself runs on — npm is beside it.
+harness_node 18 || exit 1
command -v npm >/dev/null 2>&1 || { echo "miss npm on PATH"; exit 1; }
command -v python3 >/dev/null 2>&1 || { echo "miss python3 (the verdict)"; exit 1; }
echo " npm ci (remotion ${REMOTION}, a few minutes the first time)"
diff --git a/store/agents/remotion/toolchain/test_scripts.py b/store/agents/remotion/toolchain/test_scripts.py
index 29c2650ca..5ed4df27e 100644
--- a/store/agents/remotion/toolchain/test_scripts.py
+++ b/store/agents/remotion/toolchain/test_scripts.py
@@ -1,7 +1,8 @@
"""setup.sh, doctor.sh, init-workspace.sh and the two wrappers ($REMOTION, viewer.sh), run for real
against a scratch install whose PATH holds only stub commands (node, npm, python3, git) and the few
coreutils the scripts use, so every ok / warn / miss line is reached without a network, npm or
-Remotion on the machine:
+Remotion on the machine. runtimes.sh's fallback to Harness's own Node reads a runtime dir of the
+sandbox's (ADAPTER_RUNTIME_DIR), never the real ~/.harness:
python3 -m unittest toolchain/test_scripts.py
"""
@@ -16,7 +17,7 @@ COREUTILS = ("dirname", "cat", "mkdir", "rm", "ls", "tr", "ln")
VERSIONS = dict(line.split("=", 1) for line in (PACKAGE / "VERSIONS").read_text().split())
COMMIT = VERSIONS["SKILLS_COMMIT"]
-# node as the scripts use it: -e is the version check (NODE_OK), -p reads a package version, -v.
+# node as the scripts use it: -e is runtimes.sh's version check (NODE_OK), -p reads a package version, -v.
NODE = """case "$1" in
-e) exit "${NODE_OK:-0}" ;;
-p) case "$2" in *remotion/package.json*) echo 4.0.525 ;; *react/package.json*) echo 19.3.0 ;; esac ;;
@@ -43,12 +44,13 @@ class Sandbox:
self.install = self.root / "install"
(self.install / "toolchain").mkdir(parents=True)
# Linked, not copied, so a line tracer maps back to the source. Never chmod or write these.
- for name in ("setup.sh", "doctor.sh", "init-workspace.sh", "remotion"):
+ for name in ("setup.sh", "doctor.sh", "init-workspace.sh", "remotion", "runtimes.sh"):
(self.install / "toolchain" / name).symlink_to(PACKAGE / "toolchain" / name)
(self.install / "viewer.sh").symlink_to(PACKAGE / "viewer.sh")
shutil.copy(PACKAGE / "VERSIONS", self.install / "VERSIONS")
self.bin = self.root / "bin"
self.bin.mkdir()
+ self.runtime = self.root / "runtime"
self.calls = self.root / "calls.log"
self.calls.touch()
for name in COREUTILS:
@@ -69,6 +71,15 @@ class Sandbox:
self.stub(name, bodies[name])
return self
+ def harness_node(self) -> None:
+ """No node on PATH, but Harness's own recorded in the runtime dir, as the CLI lays it down."""
+ node = self.stub("node", NODE, where=self.root / "harness-node")
+ self.runtime.mkdir()
+ (self.runtime / "current-node").write_text(f"{node}\n")
+
+ def no_node(self) -> str:
+ return f"miss node >= 18, and Harness's own Node is not in {self.runtime} — run `harness start` once to lay it down"
+
def skills(self, commit: str | None = COMMIT) -> None:
skill = self.install / "upstream" / "skills" / "remotion-best-practices" / "SKILL.md"
skill.parent.mkdir(parents=True, exist_ok=True)
@@ -78,12 +89,17 @@ class Sandbox:
def run(self, script: str, *args: str, cwd: Path | None = None, **env: str) -> subprocess.CompletedProcess:
return subprocess.run([BASH, str(self.install / script), *args], cwd=cwd or self.install,
- env={"PATH": str(self.bin), "CALLS": str(self.calls), **TRACER, **env},
+ env={"PATH": str(self.bin), "CALLS": str(self.calls), "ADAPTER_RUNTIME_DIR": str(self.runtime),
+ **TRACER, **env},
capture_output=True, text=True, timeout=60)
def logged(self) -> list[str]:
return self.calls.read_text().splitlines()
+ def ran(self) -> list[str]:
+ """The calls, minus runtimes.sh's `node -e` version probe (whose script spans several lines)."""
+ return [c for c in self.logged() if c.startswith(("node /", "python3 ", "npm ", "git ", "remotion "))]
+
class Setup(unittest.TestCase):
def sandbox(self) -> Sandbox:
@@ -141,15 +157,23 @@ class Setup(unittest.TestCase):
self.assertFalse(r.stdout.splitlines()[-1].startswith("ok skills"))
def test_missing_tools_are_misses(self):
- cases = (((), {}, "miss node >= 18 on PATH"),
- (("node",), {"NODE_OK": "1"}, "miss node >= 18 on PATH"),
+ cases = (((), {}, None),
+ (("node",), {"NODE_OK": "1"}, None),
(("node",), {}, "miss npm on PATH"),
(("node", "npm"), {}, "miss python3 (the verdict)"))
for tools, env, line in cases:
with self.subTest(line=line, tools=tools):
box = Sandbox(self).tools(*tools)
r = box.run("toolchain/setup.sh", **env)
- self.assertEqual((r.returncode, r.stdout.strip()), (1, line))
+ self.assertEqual((r.returncode, r.stdout.strip()), (1, line or box.no_node()))
+
+ def test_without_node_on_path_harnesss_own_serves(self):
+ box = Sandbox(self).tools("npm", "python3", "git")
+ box.stub("remotion", where=box.install / "node_modules" / ".bin")
+ box.harness_node()
+ r = box.run("toolchain/setup.sh")
+ self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
+ self.assertEqual(r.stdout.splitlines()[1], "ok remotion 4.0.525 · react 19.3.0")
class Doctor(unittest.TestCase):
@@ -173,10 +197,19 @@ class Doctor(unittest.TestCase):
self.assertEqual(r.stdout.splitlines(), [
"miss node_modules — run toolchain/setup.sh",
"miss upstream skills — run toolchain/setup.sh",
- "miss node >= 18 or an executable toolchain/remotion",
+ box.no_node(),
"miss python3",
])
+ def test_harnesss_own_node_is_found_without_node_on_path(self):
+ box = Sandbox(self).tools("python3")
+ box.harness_node()
+ box.stub("remotion", where=box.install / "node_modules" / ".bin")
+ box.skills()
+ r = box.run("toolchain/doctor.sh")
+ self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
+ self.assertEqual(r.stdout.splitlines()[::2], ["ok remotion 4.0.525", "ok $REMOTION (render progress for the pane) · node v22.1.0"])
+
def test_no_executable_wrapper_and_no_commit_file(self):
box = Sandbox(self).tools("node", "python3")
box.stub("remotion", where=box.install / "node_modules" / ".bin")
@@ -184,7 +217,7 @@ class Doctor(unittest.TestCase):
(box.install / "toolchain" / "remotion").unlink()
r = box.run("toolchain/doctor.sh")
self.assertEqual(r.returncode, 1)
- self.assertEqual(r.stdout.splitlines()[1:3], ["ok skills @ ", "miss node >= 18 or an executable toolchain/remotion"])
+ self.assertEqual(r.stdout.splitlines()[1:3], ["ok skills @ ", "miss an executable toolchain/remotion"])
class InitWorkspace(unittest.TestCase):
@@ -198,6 +231,16 @@ class InitWorkspace(unittest.TestCase):
self.assertEqual(os.readlink(ws / "node_modules"), f"{box.install}/node_modules")
self.assertEqual(box.logged(), [f"python3 {box.install}/toolchain/verdict.py"])
+ def test_the_verdict_runs_with_harnesss_own_node_on_path(self):
+ box = Sandbox(self).tools("python3")
+ box.harness_node()
+ box.stub("python3", 'echo "PATH=$PATH" >> "$CALLS"')
+ ws = box.root / "ws"
+ ws.mkdir()
+ r = box.run("toolchain/init-workspace.sh", cwd=ws, HARNESS_DSH_DIR=str(box.install))
+ self.assertEqual(r.returncode, 0, r.stderr)
+ self.assertEqual(box.logged()[-1], f"PATH={box.root / 'harness-node'}:{box.bin}")
+
def test_a_node_modules_already_there_is_kept(self):
box = Sandbox(self).tools("python3")
ws = box.root / "ws"
@@ -218,13 +261,27 @@ class Wrappers(unittest.TestCase):
box = Sandbox(self).tools("node")
r = box.run("toolchain/remotion", "render", "Main", "out/main.mp4", NODE_CODE="7")
self.assertEqual(r.returncode, 7)
- self.assertEqual(box.logged(), [f"node {box.install}/toolchain/remotion.mjs render Main out/main.mp4"])
+ self.assertEqual(box.ran(), [f"node {box.install}/toolchain/remotion.mjs render Main out/main.mp4"])
def test_viewer_sh_runs_the_pane_server(self):
box = Sandbox(self).tools("node")
r = box.run("viewer.sh", HARNESS_VIEWER_PORT="4321", HARNESS_WORKSPACE=str(box.root))
self.assertEqual(r.returncode, 0, r.stderr)
- self.assertEqual(box.logged(), [f"node {box.install}/viewer.mjs"])
+ self.assertEqual(box.ran(), [f"node {box.install}/viewer.mjs"])
+
+ def test_without_node_on_path_the_wrappers_run_on_harnesss_own(self):
+ box = Sandbox(self)
+ box.harness_node()
+ self.assertEqual(box.run("toolchain/remotion", "still", "Main").returncode, 0)
+ self.assertEqual(box.run("viewer.sh", HARNESS_VIEWER_PORT="4321", HARNESS_WORKSPACE=str(box.root)).returncode, 0)
+ self.assertEqual(box.ran(), [f"node {box.install}/toolchain/remotion.mjs still Main", f"node {box.install}/viewer.mjs"])
+
+ def test_no_node_at_all_is_a_miss_from_either_wrapper(self):
+ box = Sandbox(self)
+ for argv, env in ((("toolchain/remotion", "render"), {}), (("viewer.sh",), {"HARNESS_VIEWER_PORT": "1", "HARNESS_WORKSPACE": "/tmp"})):
+ with self.subTest(argv[0]):
+ r = box.run(*argv, **env)
+ self.assertEqual((r.returncode, r.stdout.strip()), (1, box.no_node()))
def test_viewer_sh_needs_its_port_and_workspace(self):
box = Sandbox(self).tools("node")
diff --git a/store/agents/remotion/viewer.sh b/store/agents/remotion/viewer.sh
index 26c7c3637..b5dfe527e 100755
--- a/store/agents/remotion/viewer.sh
+++ b/store/agents/remotion/viewer.sh
@@ -2,6 +2,11 @@
# The pane. Harness runs this here with HARNESS_VIEWER_PORT and HARNESS_WORKSPACE. viewer.mjs starts
# Remotion Studio on the workspace (on a private loopback port, BROWSER=none) and serves the pane on
# HARNESS_VIEWER_PORT: Studio itself, plus the renders in out/ and the render in progress.
+# The daemon starts it through a login shell whose PATH may hold no node at all; Studio inherits ours.
set -euo pipefail
: "${HARNESS_VIEWER_PORT:?}"; : "${HARNESS_WORKSPACE:?}"
-exec node "$(cd "$(dirname "$0")" && pwd)/viewer.mjs"
+here="$(cd "$(dirname "$0")" && pwd)"
+# shellcheck source=toolchain/runtimes.sh
+. "$here/toolchain/runtimes.sh"
+harness_node 18 || exit 1
+exec node "$here/viewer.mjs"
diff --git a/store/agents/strudel/toolchain/runtimes.sh b/store/agents/strudel/toolchain/runtimes.sh
index 51fefe3f9..7223c78dc 100644
--- a/store/agents/strudel/toolchain/runtimes.sh
+++ b/store/agents/strudel/toolchain/runtimes.sh
@@ -77,6 +77,8 @@ harness_node() {
# A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
_harness_node_at_least "$min" && return 0
diff --git a/store/agents/text-to-cad/toolchain/runtimes.sh b/store/agents/text-to-cad/toolchain/runtimes.sh
index 51fefe3f9..7223c78dc 100644
--- a/store/agents/text-to-cad/toolchain/runtimes.sh
+++ b/store/agents/text-to-cad/toolchain/runtimes.sh
@@ -77,6 +77,8 @@ harness_node() {
# A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
_harness_node_at_least "$min" && return 0
diff --git a/store/agents/yosys/.gitignore b/store/agents/yosys/.gitignore
index 4609b50ca..9b1d38f9d 100644
--- a/store/agents/yosys/.gitignore
+++ b/store/agents/yosys/.gitignore
@@ -1,3 +1,5 @@
node_modules/
__pycache__/
tmp/
+oss-cad-suite/
+.oss-cad-suite.*/
diff --git a/store/agents/yosys/AGENTS.md b/store/agents/yosys/AGENTS.md
index f245a887e..a03b13a57 100644
--- a/store/agents/yosys/AGENTS.md
+++ b/store/agents/yosys/AGENTS.md
@@ -23,7 +23,8 @@ never print a URL, never open a browser.
board's pinout and the mistakes to avoid. **Read it before you write your first module.**
- **The target is an iCEBreaker** — a Lattice iCE40UP5K in the SG48 package, 5280 logic cells, a
12 MHz clock on pin 35. Change it only if the user names a different board.
-- **The tools are installed**: `iverilog`, `yosys`, `nextpnr-ice40`, `icepack`. Install nothing.
+- **The tools are installed**: `iverilog`, `yosys`, `nextpnr-ice40`, `icepack`, `iceprog` — not
+ necessarily on your PATH, so run one alone as `"$YOSYS_TOOLCHAIN/run" <tool> …`. Install nothing.
## The one command
@@ -56,5 +57,5 @@ or those JSON files yourself: the pane reads them.
the whole DUT with `$dumpvars(0, dut)` so the user can browse its internals.
6. **Ask only what you cannot infer**: the board, the clock rate, the protocol's baud or width.
Otherwise decide, say so in one line, and build.
-7. **Deliver**: `out/<top>.bin`, and the line that flashes it — `iceprog out/<top>.bin`. Say where
- it is and what the design costs.
+7. **Deliver**: `out/<top>.bin`, and the line that flashes it —
+ `"$YOSYS_TOOLCHAIN/run" iceprog out/<top>.bin`. Say where it is and what the design costs.
diff --git a/store/agents/yosys/README.md b/store/agents/yosys/README.md
index fa384fa59..62bb666da 100644
--- a/store/agents/yosys/README.md
+++ b/store/agents/yosys/README.md
@@ -27,8 +27,11 @@ how the pane shows the step that is running *now*.
- `skills/yosys/` — the skill (ours): the synthesisable Verilog-2005 subset, the testbench shape,
the iCEBreaker pinout, how to read utilisation and Fmax, the pitfalls, and ready-made
UART / PWM / debounce blocks. Every code block in it compiles and synthesises.
-- `toolchain/setup.sh` installs the four tools from Homebrew (idempotent — it skips what is already
- on PATH) and netlistsvg into `node_modules`; `doctor.sh` checks all of them;
+- `toolchain/setup.sh` keeps the machine's own four tools when it has them all (Homebrew's, a
+ distro's) and otherwise fetches YosysHQ's OSS CAD Suite — one dated release, checksummed per
+ platform — into `oss-cad-suite/`, cut down to those four; then netlistsvg into `node_modules` and a
+ smoke run of the flow. `path.sh` finds the tools (and a node) the same way for `flow.sh`,
+ `doctor.sh`, `viewer.sh` and `run` (one tool alone, for the agent); `doctor.sh` checks all of them;
`flow.sh <top>` is the whole flow; `vcd2json.py` turns the VCD into a summary for the verdict;
`verdict.py` writes `out/<top>.report.json` and `.harness/verdict.json` **before and after every
step**, so the pane fills in while the flow runs.
@@ -76,8 +79,8 @@ numbers in the template's PCF are the
[iCEBreaker project's](https://codeberg.org/icebreaker-fpga/icebreaker-verilog-examples), cited in
the file itself.
-Nothing of any of them is changed or redistributed here: `setup.sh` installs them from Homebrew and
-npm as their authors publish them. This folder is the Harness wrapper — the manifest, a skill,
+Nothing of any of them is changed or redistributed here: `setup.sh` uses the machine's own, or
+downloads YosysHQ's OSS CAD Suite build and npm packages as their authors publish them. This folder is the Harness wrapper — the manifest, a skill,
the template, the toolchain, the verdict and the viewer — written by Autonomous to bring the
open-source FPGA flow into Harness. We did that work on the projects' behalf, to bootstrap the
catalogue.
@@ -85,7 +88,8 @@ catalogue.
If you maintain any of these projects and want to own this Harness package, it is yours: open an
issue on [OpenHarness](https://github.com/autonomous-ai/openharness/issues) and we
transfer this package and point the registry entry at it. Until then: bugs in the tools belong
-upstream, bugs in the wrapper belong here, and a newer toolchain is a `brew upgrade`.
+upstream, bugs in the wrapper belong here, and a newer toolchain is a new `SUITE_RELEASE` (and its
+four checksums) in `toolchain/setup.sh`.
```sh
harness dsh check . # conformance
diff --git a/store/agents/yosys/THIRD_PARTY_NOTICES.md b/store/agents/yosys/THIRD_PARTY_NOTICES.md
index fffb7dad0..07fae4060 100644
--- a/store/agents/yosys/THIRD_PARTY_NOTICES.md
+++ b/store/agents/yosys/THIRD_PARTY_NOTICES.md
@@ -18,7 +18,8 @@ EPL-1.0, [kieler/elkjs](https://github.com/kieler/elkjs). netlistsvg's own depen
**Project IceStorm chip database** — Claire Xenia Wolf and contributors, ISC (`LICENSE-icestorm`),
[YosysHQ/icestorm](https://github.com/YosysHQ/icestorm). The Board and Chip tabs read the
-package-pin table (`.pins <package>`) from the installed `share/icestorm/chipdb/chipdb-*.txt`.
+package-pin table (`.pins <package>`) from the installed `chipdb-*.txt` beside icepack
+(`share/icestorm/chipdb/` in Homebrew's IceStorm, `share/icebox/` in the OSS CAD Suite).
`viewer/lib/chip.mjs` carries the 39-row iCE40UP5K-SG48 table from `chipdb-5k.txt` as a fallback for
a machine where the chipdb cannot be found.
diff --git a/store/agents/yosys/skills/yosys/SKILL.md b/store/agents/yosys/skills/yosys/SKILL.md
index aceb59449..1d6385414 100644
--- a/store/agents/yosys/skills/yosys/SKILL.md
+++ b/store/agents/yosys/skills/yosys/SKILL.md
@@ -29,11 +29,14 @@ Each step's full output is at `out/logs/<step>.log`, with `<step>.start`, `<step
which step is running. The flow does not stop the world on a failure: synthesis still runs when
simulation fails, so you see every problem at once.
-Single steps, when you are iterating on one thing:
+Single steps, when you are iterating on one thing — through `"$YOSYS_TOOLCHAIN/run"`, which finds
+the tools the way the flow does (they need not be on your PATH):
```sh
-iverilog -g2012 -o out/sim.vvp rtl/*.v tb/blink_tb.v && vvp out/sim.vvp # just the simulation
-yosys -p "read_verilog rtl/*.v; synth_ice40 -top blink; stat" # just the cell count
+# just the simulation
+"$YOSYS_TOOLCHAIN/run" iverilog -g2012 -o out/sim.vvp rtl/*.v tb/blink_tb.v && "$YOSYS_TOOLCHAIN/run" vvp out/sim.vvp
+# just the cell count
+"$YOSYS_TOOLCHAIN/run" yosys -p "read_verilog rtl/*.v; synth_ice40 -top blink; stat"
```
Then always finish with the full `"$YOSYS_FLOW" <top>` so the pane and the verdict are current.
@@ -200,8 +203,8 @@ Another board: change `constraints/<top>.pcf` and set `YOSYS_DEVICE` / `YOSYS_PA
is to break it with a pipeline register, not to lower the clock, unless lowering it is honest.
The path itself, hop by hop with the RTL line of each net, is `critical_paths` in
`out/<top>_pnr.json` — and drawn on the floorplan in the pane's Chip tab.
-- **`bitstream.path`** — `out/<top>.bin`, and `iceprog out/<top>.bin` flashes a board over USB
- (install `icestorm`'s `iceprog`; the user needs the board plugged in).
+- **`bitstream.path`** — `out/<top>.bin`, and `"$YOSYS_TOOLCHAIN/run" iceprog out/<top>.bin` flashes
+ a board over USB (the user needs the board plugged in).
## Pitfalls that cost a day
diff --git a/store/agents/yosys/toolchain/doctor.sh b/store/agents/yosys/toolchain/doctor.sh
index 0442f6765..03ddfeb2a 100755
--- a/store/agents/yosys/toolchain/doctor.sh
+++ b/store/agents/yosys/toolchain/doctor.sh
@@ -1,7 +1,9 @@
#!/usr/bin/env bash
# One line per check; exit 0 when this machine can take a Verilog file all the way to a bitstream.
set -u; cd "$(dirname "$0")/.."; bad=0
-command -v yosys >/dev/null 2>&1 || export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"
+# The tools and node found the way flow.sh finds them: the package's OSS CAD Suite first.
+# shellcheck source=path.sh
+. toolchain/path.sh
line() { # line <label> <command...> — ok with the command's first line only when the command succeeds
local label="$1" out; shift
@@ -17,12 +19,15 @@ if command -v iverilog >/dev/null 2>&1; then line "iverilog, the simulator" iver
if command -v iceprog >/dev/null 2>&1; then echo "ok iceprog, to flash a board over USB"; else echo "info iceprog not found — synthesis works, flashing a real board does not"; fi
if [ -x node_modules/.bin/netlistsvg ]; then echo "ok netlistsvg $(node -p "require('netlistsvg/package.json').version" 2>/dev/null), the schematic"; else echo "miss node_modules — run toolchain/setup.sh"; bad=1; fi
-if command -v node >/dev/null 2>&1 && v="$(node -v 2>/dev/null)"; then echo "ok node $v for the viewer"; else echo "miss node for the viewer"; bad=1; fi
+if harness_node 18 >/dev/null; then echo "ok node $(node -v) for the viewer"; else harness_node 18; bad=1; fi
# The pane's Board and Chip tabs map package pins to the die with IceStorm's chip database.
chipdb=""
if command -v icepack >/dev/null 2>&1; then
real="$(python3 -c 'import os,sys; print(os.path.realpath(sys.argv[1]))' "$(command -v icepack)" 2>/dev/null)"
- [ -n "$real" ] && [ -f "$(dirname "$real")/../share/icestorm/chipdb/chipdb-5k.txt" ] && chipdb=yes
+ # Homebrew's IceStorm keeps it in share/icestorm/chipdb, the OSS CAD Suite in share/icebox.
+ for db in share/icestorm/chipdb share/icebox; do
+ [ -n "$real" ] && [ -f "$(dirname "$real")/../$db/chipdb-5k.txt" ] && chipdb=yes
+ done
fi
if [ -n "$chipdb" ]; then echo "ok IceStorm chipdb, for the pane's pin maps"; else echo "info IceStorm chipdb not found — the pane falls back to its built-in iCE40UP5K-SG48 pin table"; fi
if command -v python3 >/dev/null 2>&1; then echo "ok $(python3 --version) for the waveforms and the verdict"; else echo "miss python3"; bad=1; fi
diff --git a/store/agents/yosys/toolchain/flow.sh b/store/agents/yosys/toolchain/flow.sh
index a1443137e..bcf33f1cd 100755
--- a/store/agents/yosys/toolchain/flow.sh
+++ b/store/agents/yosys/toolchain/flow.sh
@@ -28,6 +28,9 @@
# YOSYS_PACKAGE nextpnr package, default sg48
# YOSYS_TOOLCHAIN this directory; set by the harness
# HARNESS_DSH_DIR the install dir (netlistsvg lives in its node_modules)
+#
+# The tools come from path.sh: the package's own OSS CAD Suite when setup.sh fetched it, else the
+# machine's (Homebrew's bin included), and node for netlistsvg even when PATH has none.
set -uo pipefail
@@ -36,9 +39,8 @@ DSH_DIR="${HARNESS_DSH_DIR:-$(cd "$HERE/.." && pwd)}"
WS="${HARNESS_WORKSPACE:-$PWD}"
cd "$WS" || { echo "no workspace at $WS" >&2; exit 2; }
-# Homebrew's bin is not always on the PATH of a process the daemon spawned; put it there when the
-# tools are not visible, rather than making every caller remember to.
-command -v yosys >/dev/null 2>&1 || export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"
+# shellcheck source=path.sh
+. "$HERE/path.sh"
TOP="${1:-${YOSYS_TOP:-}}"
if [ -z "$TOP" ]; then
diff --git a/store/agents/yosys/toolchain/init-workspace.sh b/store/agents/yosys/toolchain/init-workspace.sh
index cd3a3ce77..180d4ca82 100755
--- a/store/agents/yosys/toolchain/init-workspace.sh
+++ b/store/agents/yosys/toolchain/init-workspace.sh
@@ -8,9 +8,7 @@ set -uo pipefail
: "${HARNESS_DSH_DIR:?}"
mkdir -p .harness out
-# Homebrew's bin is not always on the PATH of a process the daemon spawned.
-command -v yosys >/dev/null 2>&1 || export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"
-
+# flow.sh finds the tools and node itself (toolchain/path.sh), whatever PATH the daemon gave us.
HARNESS_WORKSPACE="$PWD" bash "$HARNESS_DSH_DIR/toolchain/flow.sh" blink >out/logs-init.txt 2>&1 || true
# flow.sh always leaves a verdict; if it could not run at all, seed one so the header is not empty.
[ -f .harness/verdict.json ] || python3 "$HARNESS_DSH_DIR/toolchain/verdict.py" blink >/dev/null 2>&1 || true
diff --git a/store/agents/yosys/toolchain/path.sh b/store/agents/yosys/toolchain/path.sh
new file mode 100644
index 000000000..f8b448b67
--- /dev/null
+++ b/store/agents/yosys/toolchain/path.sh
@@ -0,0 +1,18 @@
+# shellcheck shell=bash
+# path.sh — sourced by flow.sh, doctor.sh and run: the FPGA tools and node on PATH, however this
+# process started (the daemon's PATH and the agent's shell may have neither Homebrew's bin nor a node).
+#
+# 1. oss-cad-suite/bin in this install, when setup.sh fetched the suite because the machine lacked
+# a tool — first, so the flow never mixes the suite's tools with the machine's
+# 2. otherwise the machine's own, with Homebrew's bin added when yosys is not already visible
+# 3. node for netlistsvg: this machine's when it is new enough, else the Node Harness itself runs on
+_yosys_install="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
+if [ -x "$_yosys_install/oss-cad-suite/bin/yosys" ]; then
+ PATH="$_yosys_install/oss-cad-suite/bin:$PATH"
+elif ! command -v yosys >/dev/null 2>&1; then
+ PATH="$PATH:/opt/homebrew/bin:/usr/local/bin"
+fi
+export PATH
+# shellcheck source=runtimes.sh
+. "$_yosys_install/toolchain/runtimes.sh"
+harness_node 18 >/dev/null || true
diff --git a/store/agents/yosys/toolchain/run b/store/agents/yosys/toolchain/run
new file mode 100755
index 000000000..f1a586b96
--- /dev/null
+++ b/store/agents/yosys/toolchain/run
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+# `"$YOSYS_TOOLCHAIN/run" <tool> …` — one tool of the flow on its own (iverilog, vvp, yosys,
+# nextpnr-ice40, icepack, iceprog), found the way flow.sh finds it: the agent's shell may have the
+# package's OSS CAD Suite, Homebrew's bin or a node on PATH, or none of them.
+# shellcheck source=path.sh
+. "$(cd "$(dirname "$0")" && pwd)/path.sh"
+[ $# -gt 0 ] || { echo "usage: \"\$YOSYS_TOOLCHAIN/run\" <tool> [arguments…]" >&2; exit 2; }
+command -v "$1" >/dev/null 2>&1 || { echo "miss $1 — run toolchain/setup.sh"; exit 127; }
+exec "$@"
diff --git a/store/agents/yosys/toolchain/runtimes.sh b/store/agents/yosys/toolchain/runtimes.sh
new file mode 100644
index 000000000..7223c78dc
--- /dev/null
+++ b/store/agents/yosys/toolchain/runtimes.sh
@@ -0,0 +1,192 @@
+# shellcheck shell=bash
+# runtimes.sh — the interpreters a store package runs on, found on this machine or fetched, never
+# asked of the person who pressed Get.
+#
+# Sourced (not run) by a package's setup, doctor and viewer scripts. A new Mac has Apple's Python 3.9,
+# no Homebrew and, for most people, no Node on PATH; a package that answers "brew install [email protected]"
+# has failed its install. So:
+#
+# harness_node 18 node >= 18 on PATH, with npm: the machine's own, else the Node Harness
+# itself runs on (~/.harness/runtime/current-node, laid down with the CLI)
+# harness_uv uv on PATH: the machine's own, else a pinned, checksummed release
+# fetched into ~/.harness/runtime
+# harness_venv DIR 3.12 [MIN [BELOW]]
+# DIR is a venv on CPython 3.12, which uv downloads when the machine
+# has none. A venv already there on a Python in [MIN, BELOW) is kept.
+# harness_pip DIR PKG… install into that venv, through uv
+# harness_micromamba micromamba, pinned and checksummed, for native libraries PyPI has
+# no wheel for (pycairo on macOS)
+# harness_conda_env DIR SPEC… DIR is a conda-forge environment with those packages
+#
+# Every function prints `miss …` and returns 1 when it cannot deliver, so `harness_node 18 || exit 1`
+# reads like the rest of a setup script. Nothing here touches the user's shell profile; what it
+# installs lands in ~/.harness/runtime or the package's own directory (uv keeps its download cache
+# where it always does, which a venv does not depend on).
+#
+# ONE copy is written by hand: store/tools/runtimes.sh in the OpenHarness repository. Each package
+# carries an identical copy (a package installs alone, so it cannot reach this one);
+# `node store/tools/sync-runtimes.mjs` rewrites them and the CLI's store spec fails when one drifts.
+
+HARNESS_RUNTIME="${ADAPTER_RUNTIME_DIR:-${HOME:-}/.harness/runtime}"
+# The Pythons uv downloads live with Harness's other runtimes, not in uv's own ~/.local/share/uv:
+# a package's venv points at its interpreter, and `uv python uninstall` there must not break it.
+UV_PYTHON_INSTALL_DIR="${UV_PYTHON_INSTALL_DIR:-$HARNESS_RUNTIME/python}"
+export UV_PYTHON_INSTALL_DIR
+HARNESS_UV_VERSION=0.12.15
+HARNESS_MICROMAMBA_VERSION=2.9.0-0
+
+_harness_platform() {
+ case "$(uname -s)-$(uname -m)" in
+ Darwin-arm64) echo darwin-arm64 ;;
+ Darwin-x86_64) echo darwin-x64 ;;
+ Linux-x86_64) echo linux-x64 ;;
+ Linux-aarch64 | Linux-arm64) echo linux-arm64 ;;
+ *) return 1 ;;
+ esac
+}
+
+_harness_sha256() {
+ if command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" | cut -d' ' -f1
+ else sha256sum "$1" | cut -d' ' -f1; fi
+}
+
+# _harness_fetch URL DEST SHA256 — DEST exists only if what arrived matches the pinned checksum.
+_harness_fetch() {
+ local part="$2.part.$$"
+ if ! curl -fsSL --retry 3 --connect-timeout 20 --max-time 900 -o "$part" "$1"; then
+ rm -f "$part"; echo "miss could not download $1 — check this machine's internet connection"; return 1
+ fi
+ if [ "$(_harness_sha256 "$part")" != "$3" ]; then
+ rm -f "$part"; echo "miss $1 did not match its pinned checksum; nothing was installed"; return 1
+ fi
+ mv -f "$part" "$2"
+}
+
+_harness_node_at_least() {
+ command -v node >/dev/null 2>&1 || return 1
+ node -e '
+ const [a, b = 0] = process.argv[1].split(".").map(Number)
+ const [x, y] = process.versions.node.split(".").map(Number)
+ process.exit(x > a || (x === a && y >= b) ? 0 : 1)
+ ' "$1" >/dev/null 2>&1
+}
+
+harness_node() {
+ local min="${1:-18}" recorded saved="$PATH" own=0
+ _harness_node_at_least "$min" && own=1
+ # A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
+ if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
+ recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
+ if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
+ PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
+ _harness_node_at_least "$min" && return 0
+ PATH="$saved"; export PATH; hash -r 2>/dev/null || true
+ [ "$own" = 1 ] && return 0
+ echo "miss node >= $min — this machine's newest is $("${recorded%/*}/node" -v), Harness's own; update Harness"
+ return 1
+ fi
+ [ "$own" = 1 ] && return 0
+ echo "miss node >= $min, and Harness's own Node is not in $HARNESS_RUNTIME — run \`harness start\` once to lay it down"
+ return 1
+}
+
+harness_uv() {
+ local dir asset sum tmp
+ command -v uv >/dev/null 2>&1 && return 0
+ for dir in "${HOME:-}/.local/bin" "${HOME:-}/.cargo/bin"; do
+ [ -n "${HOME:-}" ] || break
+ if [ -x "$dir/uv" ]; then PATH="$dir:$PATH"; export PATH; return 0; fi
+ done
+ dir="$HARNESS_RUNTIME/uv-$HARNESS_UV_VERSION"
+ if [ ! -x "$dir/uv" ]; then
+ case "$(_harness_platform)" in
+ darwin-arm64) asset=uv-aarch64-apple-darwin sum=dc304b9ed1b24174572290fba60ac3f6fe63c73a671f0439e62a91375841964d ;;
+ darwin-x64) asset=uv-x86_64-apple-darwin sum=e9ca61775532368fe518ab03e7a354c7ecab8ccb3c7d941c775fcc4a362b801b ;;
+ linux-x64) asset=uv-x86_64-unknown-linux-gnu sum=f97935763c04be3e692460a7aaeaaab8fc3b78fcf8b389da820b38ae7423a638 ;;
+ linux-arm64) asset=uv-aarch64-unknown-linux-gnu sum=0e9a3499b0587d449c9ff684c0160da607826e4af1cee220bc87f378702d3e08 ;;
+ *) echo "miss uv — there is no uv release for $(uname -s) $(uname -m); install it from https://docs.astral.sh/uv/"; return 1 ;;
+ esac
+ echo " fetching uv $HARNESS_UV_VERSION into $HARNESS_RUNTIME (it brings Python and the packages)"
+ mkdir -p "$HARNESS_RUNTIME" || { echo "miss cannot write $HARNESS_RUNTIME"; return 1; }
+ tmp="$(mktemp -d "$HARNESS_RUNTIME/.uv.XXXXXX")" || { echo "miss cannot write $HARNESS_RUNTIME"; return 1; }
+ if ! _harness_fetch "https://github.com/astral-sh/uv/releases/download/$HARNESS_UV_VERSION/$asset.tar.gz" "$tmp/uv.tar.gz" "$sum"; then
+ rm -rf "$tmp"; return 1
+ fi
+ tar -xzf "$tmp/uv.tar.gz" -C "$tmp" && chmod +x "$tmp/$asset/uv" "$tmp/$asset/uvx" \
+ || { rm -rf "$tmp"; echo "miss the uv archive would not unpack"; return 1; }
+ # Two installs at once both get here; whichever renames first wins and the other's copy goes.
+ # (mv onto a directory that exists would nest the copy inside it, hence the test.)
+ [ -e "$dir" ] || mv "$tmp/$asset" "$dir" 2>/dev/null || true
+ rm -rf "$tmp"
+ [ -x "$dir/uv" ] || { echo "miss uv did not land in $dir"; return 1; }
+ fi
+ PATH="$dir:$PATH"; export PATH
+}
+
+# harness_venv DIR VERSION [MIN [BELOW]] — MIN defaults to VERSION; BELOW is exclusive and optional.
+harness_venv() {
+ local dir="${1:?harness_venv needs a directory}" want="${2:?harness_venv needs a Python version}"
+ local min="${3:-$2}" below="${4:-}"
+ if [ -x "$dir/bin/python" ] && "$dir/bin/python" -c '
+import sys
+at = lambda s: tuple(int(p) for p in s.split("."))
+v = sys.version_info[:2]
+sys.exit(0 if v >= at(sys.argv[1]) and (not sys.argv[2] or v < at(sys.argv[2])) else 1)
+' "$min" "$below" 2>/dev/null; then
+ echo "ok $("$dir/bin/python" --version) in $dir"
+ return 0
+ fi
+ harness_uv || return 1
+ echo " python $want in $dir (uv downloads it when this machine has none)"
+ rm -rf "$dir"
+ # only-managed: the same python-build-standalone interpreter on every machine, so a package tested
+ # once is tested everywhere — not whichever Homebrew or pyenv Python happened to be first on PATH.
+ uv venv --quiet --seed --python "$want" --python-preference only-managed "$dir" \
+ || { echo "miss could not make a Python $want environment in $dir"; return 1; }
+ echo "ok $("$dir/bin/python" --version) in $dir"
+}
+
+harness_pip() {
+ local dir="${1:?harness_pip needs a venv}"
+ shift
+ harness_uv || return 1
+ # uv's own error comes first; the miss line is last, so it is the line the store shows.
+ uv pip install --quiet --python "$dir/bin/python" "$@" \
+ || { echo "miss could not install $* into $dir"; return 1; }
+}
+
+harness_micromamba() {
+ local dir asset sum
+ dir="$HARNESS_RUNTIME/micromamba-$HARNESS_MICROMAMBA_VERSION"
+ if [ ! -x "$dir/micromamba" ]; then
+ case "$(_harness_platform)" in
+ darwin-arm64) asset=micromamba-osx-arm64 sum=ec2a072f028e1a7cf20f3e2e74d5a8127cf5a5f27636375b5359811565f4e5be ;;
+ darwin-x64) asset=micromamba-osx-64 sum=1e71054bb3ac9a076e21f7ec48acfef536f9b3f1408f371a942784bf5ef83d8a ;;
+ linux-x64) asset=micromamba-linux-64 sum=366cd9cd8be14df1ab8ed50352a82111082a36686b2d389fdb79a92c3fafb3e3 ;;
+ linux-arm64) asset=micromamba-linux-aarch64 sum=9f93b974adcb4d166996af969b6cd371287d1a3e52733704727884d9b74cb7a7 ;;
+ *) echo "miss micromamba — there is no release for $(uname -s) $(uname -m)"; return 1 ;;
+ esac
+ echo " fetching micromamba $HARNESS_MICROMAMBA_VERSION into $HARNESS_RUNTIME (native libraries PyPI has no wheel for)"
+ mkdir -p "$dir" || { echo "miss cannot write $dir"; return 1; }
+ _harness_fetch "https://github.com/mamba-org/micromamba-releases/releases/download/$HARNESS_MICROMAMBA_VERSION/$asset" "$dir/micromamba.$$" "$sum" || return 1
+ chmod +x "$dir/micromamba.$$" && mv -f "$dir/micromamba.$$" "$dir/micromamba" \
+ || { rm -f "$dir/micromamba.$$"; echo "miss micromamba would not install into $dir"; return 1; }
+ fi
+ HARNESS_MICROMAMBA="$dir/micromamba"
+ export HARNESS_MICROMAMBA
+}
+
+# harness_conda_env DIR SPEC… — conda-forge only, packages cached under ~/.harness/runtime/mamba.
+harness_conda_env() {
+ local dir="${1:?harness_conda_env needs a directory}"
+ shift
+ # micromamba takes a relative --prefix as a name under its root prefix and "succeeds" there.
+ case "$dir" in /*) ;; *) dir="$PWD/$dir" ;; esac
+ harness_micromamba || return 1
+ MAMBA_ROOT_PREFIX="$HARNESS_RUNTIME/mamba" "$HARNESS_MICROMAMBA" create --yes --quiet \
+ --prefix "$dir" --override-channels --channel conda-forge "$@" >/dev/null \
+ && [ -d "$dir/conda-meta" ] \
+ || { echo "miss could not make the conda-forge environment in $dir ($*)"; return 1; }
+}
diff --git a/store/agents/yosys/toolchain/setup.sh b/store/agents/yosys/toolchain/setup.sh
index 902f3e50e..f7b1f3d38 100755
--- a/store/agents/yosys/toolchain/setup.sh
+++ b/store/agents/yosys/toolchain/setup.sh
@@ -1,55 +1,139 @@
#!/usr/bin/env bash
# Runs once at install, cwd = the install dir. Two halves:
#
-# 1. The open-source FPGA flow — yosys, nextpnr-ice40, icestorm, icarus-verilog — from Homebrew.
-# These are compilers and a bitstream packer; they belong on PATH, not vendored in this folder,
-# and Homebrew is how they are published for macOS. Already-installed formulas are left alone,
-# so running this twice costs nothing.
-# 2. netlistsvg (and its elkjs layout engine) into this directory's node_modules, from the
-# lockfile. Nothing global.
+# 1. The open-source FPGA flow — yosys, nextpnr-ice40, icepack (IceStorm), iverilog (Icarus). A
+# machine that already has all four (Homebrew's, a distro's) keeps them. Otherwise YosysHQ's own
+# OSS CAD Suite build is fetched into oss-cad-suite/ here: one dated release, pinned and
+# checksummed per platform, relocatable, the same four tools on macOS and Linux, arm64 and x64.
+# No Homebrew, no sudo, nothing outside this folder. It unpacks to ~2 GB of every open-source EDA
+# tool there is; only the four tools and what they load are kept (~720 MB on macOS).
+# 2. netlistsvg (and its elkjs layout engine) into this directory's node_modules, from the lockfile.
#
-# On a machine without Homebrew, or on Linux, this says exactly which tools are missing and where to
-# get them; it never installs a package manager.
+# Then a smoke run of the whole flow on a two-bit counter, so a tool that cannot run here is a miss at
+# install rather than a failed step in the first workspace — and macOS's once-per-binary check of a new
+# executable (most of a minute, for nextpnr's libraries) is paid here too, not in the user's first run.
+#
+# Why a dated suite release and not YoWASP wheels or conda-forge: YoWASP has no Icarus Verilog, and
+# conda-forge has no nextpnr or IceStorm at all and no arm64 macOS build of yosys or iverilog. The
+# suite's dated releases stay downloadable (2021's still are), so the pin does not rot.
set -euo pipefail
cd "$(dirname "$0")/.."
+# shellcheck source=runtimes.sh
+. toolchain/runtimes.sh
-FORMULAS=(yosys nextpnr-ice40 icestorm icarus-verilog)
-# formula:binary — the binary is how we know the formula is really there.
-BINARIES=(yosys nextpnr-ice40 icepack iverilog)
+SUITE_RELEASE=2026-09-16
+TOOLS=(yosys nextpnr-ice40 icepack iverilog)
+# What the flow runs, what those load, and the chip databases the pane's pin maps read. Relative to
+# the suite's root; a path one platform's build does not have (Frameworks/ on Linux) is skipped.
+KEEP=(VERSION license etc lib Frameworks share/yosys share/icebox \
+ bin/yosys bin/yosys-abc bin/nextpnr-ice40 bin/icepack bin/iceprog bin/iverilog bin/vvp \
+ libexec/realpath libexec/yosys libexec/yosys-abc libexec/nextpnr-ice40 libexec/icepack \
+ libexec/iceprog libexec/iverilog libexec/vvp libexec/ivl libexec/ivlpp)
+# Inside lib/: Python's own tests and packages (nextpnr embeds the interpreter, not its packages), and
+# GHDL, Python 2, LLVM and Mesa, which none of the four load.
+DROP=(lib/python3*/test lib/python3*/site-packages lib/python2* lib/ghdl lib/libghdl* lib/libLLVM* lib/libgallium* lib/dri)
have() { command -v "$1" >/dev/null 2>&1; }
-have yosys || export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"
+suite_tmp=""; work=""
+trap 'rm -rf ${suite_tmp:+"$suite_tmp"} ${work:+"$work"}' EXIT
+sha256() { if have shasum; then shasum -a 256 "$1" | cut -d' ' -f1; else sha256sum "$1" | cut -d' ' -f1; fi; }
+
+harness_node 18 || exit 1
+have npm || { echo "miss npm on PATH"; exit 1; }
+have python3 || { echo "miss python3 (the VCD reader and the verdict)"; exit 1; }
+
+# fetch_suite — oss-cad-suite/ at SUITE_RELEASE, or a miss line and nothing changed.
+fetch_suite() {
+ local platform sum mb asset url p
+ case "$(uname -s)-$(uname -m)" in
+ Darwin-arm64) platform=darwin-arm64 mb=521 sum=827b4d55246eab8146d5d508b9dd6c50924388516e961c92a01fe4cafe22edfb ;;
+ Darwin-x86_64) platform=darwin-x64 mb=504 sum=d6c52a4cf8c051223e00e386a377b95353bf50622427f19e3feca088e010724f ;;
+ Linux-x86_64) platform=linux-x64 mb=742 sum=88b3d97cffabe85c9491625318f86797f35573904df276a505ebd6963b0f75b3 ;;
+ Linux-aarch64 | Linux-arm64) platform=linux-arm64 mb=680 sum=20e8d8058d62d829d71acc67540a2b1ad7b3acef2097f0f717e0be4fd4c82d17 ;;
+ *) echo "miss ${missing[*]} — and the OSS CAD Suite has no build for $(uname -s) $(uname -m)"; return 1 ;;
+ esac
+ asset="oss-cad-suite-$platform-${SUITE_RELEASE//-/}.tgz"
+ url="https://github.com/YosysHQ/oss-cad-suite-build/releases/download/$SUITE_RELEASE/$asset"
+ echo " fetching the OSS CAD Suite $SUITE_RELEASE for $platform (${mb} MB, a few minutes the first time)"
+ # Unpacked beside the install, not in TMPDIR: the final move is then a rename, not a 2 GB copy. An
+ # interrupted run's leftovers go first; the EXIT trap removes this run's, whatever happens.
+ rm -rf .oss-cad-suite.*
+ suite_tmp="$(mktemp -d "$PWD/.oss-cad-suite.XXXXXX")"
+ if ! curl -fsSL --retry 3 --connect-timeout 20 --max-time 3600 -o "$suite_tmp/$asset" "$url"; then
+ echo "miss could not download $url — check this machine's internet connection"; return 1
+ fi
+ if [ "$(sha256 "$suite_tmp/$asset")" != "$sum" ]; then
+ echo "miss $url did not match its pinned checksum; nothing was installed"; return 1
+ fi
+ tar -xzf "$suite_tmp/$asset" -C "$suite_tmp" || { echo "miss the OSS CAD Suite archive would not unpack (is the disk full?)"; return 1; }
+ mkdir "$suite_tmp/keep"
+ for p in "${KEEP[@]}"; do
+ [ -e "$suite_tmp/oss-cad-suite/$p" ] || continue
+ mkdir -p "$suite_tmp/keep/$(dirname "$p")"
+ mv "$suite_tmp/oss-cad-suite/$p" "$suite_tmp/keep/$p"
+ done
+ for p in "${DROP[@]}"; do rm -rf "$suite_tmp/keep/"$p; done
+ echo "$SUITE_RELEASE" > "$suite_tmp/keep/.release"
+ rm -rf oss-cad-suite
+ mv "$suite_tmp/keep" oss-cad-suite
+ echo "ok OSS CAD Suite $SUITE_RELEASE in oss-cad-suite/ ($(du -sh oss-cad-suite | cut -f1 | tr -d ' '))"
+}
missing=()
-for i in "${!FORMULAS[@]}"; do
- have "${BINARIES[$i]}" || missing+=("${FORMULAS[$i]}")
-done
-
-if [ ${#missing[@]} -eq 0 ]; then
- echo "ok yosys, nextpnr-ice40, icestorm, icarus-verilog already on PATH"
-elif have brew; then
- echo " brew install ${missing[*]} (the open-source FPGA flow; a few minutes the first time)"
- HOMEBREW_NO_AUTO_UPDATE=1 brew install "${missing[@]}"
+if [ -x oss-cad-suite/bin/yosys ] && [ "$(cat oss-cad-suite/.release 2>/dev/null)" = "$SUITE_RELEASE" ]; then
+ echo "ok OSS CAD Suite $SUITE_RELEASE already in oss-cad-suite/"
else
- echo "miss ${missing[*]} and no brew to install them with."
- echo " macOS: /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\" then re-run this"
- echo " Linux: apt install yosys nextpnr-ice40 fpga-icestorm iverilog"
- echo " Either: the YosysHQ oss-cad-suite tarball, https://github.com/YosysHQ/oss-cad-suite-build/releases"
- exit 1
+ # Homebrew's bin is not always on the PATH of a process the daemon spawned.
+ have yosys || export PATH="$PATH:/opt/homebrew/bin:/usr/local/bin"
+ for t in "${TOOLS[@]}"; do have "$t" || missing+=("$t"); done
+ if [ ${#missing[@]} -eq 0 ] && [ ! -d oss-cad-suite ]; then
+ echo "ok yosys, nextpnr-ice40, icepack, iverilog already on this machine"
+ else
+ # flow.sh prefers oss-cad-suite/ whenever it is there, so a stale one is replaced, not kept.
+ [ ${#missing[@]} -eq 0 ] || echo " this machine has no ${missing[*]}"
+ fetch_suite || exit 1
+ fi
fi
-
-for i in "${!BINARIES[@]}"; do
- have "${BINARIES[$i]}" || { echo "miss ${BINARIES[$i]} even after installing ${FORMULAS[$i]}"; exit 1; }
-done
-
-have node >/dev/null || { echo "miss node >= 18 on PATH (the viewer and netlistsvg)"; exit 1; }
-have npm >/dev/null || { echo "miss npm on PATH"; exit 1; }
-have python3 >/dev/null || { echo "miss python3 (the VCD reader and the verdict)"; exit 1; }
+[ -x oss-cad-suite/bin/yosys ] && export PATH="$PWD/oss-cad-suite/bin:$PATH"
echo " npm ci (netlistsvg $(node -p "require('./package.json').dependencies.netlistsvg"), for the schematic)"
npm ci --silent --no-audit --no-fund
[ -x node_modules/.bin/netlistsvg ] || { echo "miss node_modules/.bin/netlistsvg after npm ci"; exit 1; }
+# smoke — simulate, synthesise, place and route, and pack a counter too small to take a second. Prints
+# the tool that failed, if one did; its output is in $1/log.
+smoke() {
+ local d="$1"
+ cat > "$d/c.v" <<'EOF'
+module c(input clk, output led);
+ reg [1:0] n = 0;
+ always @(posedge clk) n <= n + 1;
+ assign led = n[1];
+endmodule
+EOF
+ cat > "$d/tb.v" <<'EOF'
+module tb;
+ reg clk = 0;
+ wire led;
+ c dut(.clk(clk), .led(led));
+ initial begin repeat (8) #1 clk = !clk; $display("led %b", led); $finish; end
+endmodule
+EOF
+ printf 'set_io clk 35\nset_io led 39\n' > "$d/c.pcf"
+ iverilog -g2012 -o "$d/sim.vvp" "$d/c.v" "$d/tb.v" >"$d/log" 2>&1 || { echo iverilog; return 1; }
+ vvp -n "$d/sim.vvp" >>"$d/log" 2>&1 || { echo vvp; return 1; }
+ yosys -q -p "read_verilog $d/c.v; synth_ice40 -top c -json $d/c.json" >>"$d/log" 2>&1 || { echo yosys; return 1; }
+ nextpnr-ice40 -q --up5k --package sg48 --json "$d/c.json" --pcf "$d/c.pcf" --asc "$d/c.asc" >>"$d/log" 2>&1 || { echo nextpnr-ice40; return 1; }
+ icepack "$d/c.asc" "$d/c.bin" >>"$d/log" 2>&1 && [ -s "$d/c.bin" ] || { echo icepack; return 1; }
+}
+
+echo " smoke run: a counter simulated, synthesised, placed, routed and packed (slow only the first time)"
+work="$(mktemp -d "${TMPDIR:-/tmp}/yosys-smoke.XXXXXX")"
+if ! failed="$(smoke "$work")"; then
+ echo "miss $failed does not run on this machine: $(grep -v '^[[:space:]]*$' "$work/log" | tail -1)"
+ exit 1
+fi
+
echo "ok $(yosys -V 2>&1 | head -1)"
echo "ok nextpnr-ice40 · icepack · $(iverilog -V 2>&1 | head -1)"
echo "ok netlistsvg $(node -p "require('netlistsvg/package.json').version") · node $(node -v)"
diff --git a/store/agents/yosys/toolchain/test_scripts.py b/store/agents/yosys/toolchain/test_scripts.py
index 2011437d4..ddd9986dd 100644
--- a/store/agents/yosys/toolchain/test_scripts.py
+++ b/store/agents/yosys/toolchain/test_scripts.py
@@ -1,26 +1,33 @@
-"""The shell half of the toolchain — flow.sh, setup.sh, doctor.sh, init-workspace.sh, viewer.sh — on
-stub tools: `python3 -m unittest toolchain/test_scripts.py`.
+"""The shell half of the toolchain — flow.sh, setup.sh, doctor.sh, init-workspace.sh, viewer.sh, path.sh
+and run — on stub tools: `python3 -m unittest toolchain/test_scripts.py`.
Each test builds a throwaway install (the real scripts symlinked in, file by file), a workspace, a
directory of stub tools that log how they were called, and a PATH made of those stubs plus links to
the few system tools the scripts use, so a tool is missing exactly when a test leaves it out. The
scripts fall back to Homebrew's bin when yosys is not on PATH; a test that needs a tool to stay
-missing after that hides it with a `command -v` wrapper exported into bash. One test at the end runs
-the real flow on the starter design, when yosys, nextpnr, icestorm and icarus are installed.
+missing after that hides it with a `command -v` wrapper exported into bash. setup.sh's OSS CAD Suite
+download is a stub curl handing over a small tarball of stub tools laid out like the suite, and
+runtimes.sh's fallback to Harness's own Node reads a runtime dir of the sandbox's, never ~/.harness.
+One test at the end runs the real flow on the starter design, when yosys, nextpnr, icestorm and icarus
+are installed.
"""
import atexit
import hashlib
+import io
import json
import os
+import re
import shutil
import subprocess
+import tarfile
import tempfile
import time
import unittest
from pathlib import Path
PKG = Path(__file__).resolve().parent.parent
-SYSTEM = ["bash", "basename", "cat", "chmod", "date", "dirname", "head", "ln", "mkdir", "perl", "rm", "sed", "tail"]
+SYSTEM = ["bash", "basename", "cat", "chmod", "cut", "date", "dirname", "du", "grep", "gzip", "head", "ln", "mkdir",
+ "mktemp", "mv", "perl", "rm", "sed", "tail", "tar", "tr"]
# `command -v <tool>` fails for every tool named in $STUB_HIDE, wherever it is installed.
HIDE = '() { if [ "$1" = -v ]; then case " $STUB_HIDE " in *" $2 "*) return 1;; esac; fi; builtin command "$@"; }'
SCRUB = ("HARNESS_WORKSPACE", "HARNESS_DSH_DIR", "HARNESS_VIEWER_PORT", "YOSYS_TOP", "YOSYS_DEVICE",
@@ -51,6 +58,30 @@ STUBS = {
"npm": 'mkdir -p node_modules/.bin && printf "#!/bin/sh\\n" > node_modules/.bin/netlistsvg && chmod +x node_modules/.bin/netlistsvg\n',
}
+# The same tools as setup.sh's smoke run calls them: every output lands where its argument says.
+SMOKE = {
+ "iverilog": 'case "$1" in -V) echo "Icarus Verilog version 13.0 (stable)"; exit 0;; esac\n'
+ 'while [ $# -gt 0 ]; do [ "$1" = -o ] && : > "$2"; shift; done\n',
+ "vvp": 'echo "led 1"\n',
+ "yosys": 'case "$1" in -V) echo "Yosys 0.99 (stub)"; exit 0;; esac\n'
+ 'all="$*"; echo "{}" > "${all##*-json }"\n',
+ "nextpnr-ice40": 'case "$1" in --version) echo "nextpnr-ice40 (stub)"; exit 0;; esac\n'
+ 'while [ $# -gt 0 ]; do [ "$1" = --asc ] && : > "$2"; shift; done\n',
+ "icepack": 'printf bits > "$2"\n',
+ "node": 'case "$1" in -v) echo v22.0.0;; -p) echo 1.0.2;; esac\n',
+ "npm": STUBS["npm"],
+}
+ALL_TOOLS_OF_THE_SUITE = ("yosys", "nextpnr-ice40", "icepack", "iceprog", "iverilog", "vvp")
+SETUP_TEXT = (PKG / "toolchain" / "setup.sh").read_text()
+RELEASE = re.search(r"^SUITE_RELEASE=(\S+)$", SETUP_TEXT, re.M).group(1)
+PINS = {m.group(1): (int(m.group(2)), m.group(3)) for m in
+ re.finditer(r"platform=(\S+) mb=(\d+) sum=([0-9a-f]{64})", SETUP_TEXT)}
+SUITE_URL = "https://github.com/YosysHQ/oss-cad-suite-build/releases/download/{release}/oss-cad-suite-{platform}-{date}.tgz"
+
+
+def suite_url(platform):
+ return SUITE_URL.format(release=RELEASE, platform=platform, date=RELEASE.replace("-", ""))
+
_STUB_DIR = None
@@ -84,9 +115,11 @@ class Sandbox:
self.bin = self.root / "stubs"
self.sys = self.root / "system"
self.calls = self.root / "calls.log"
+ self.runtime = self.root / "runtime"
for d in (self.pkg / "toolchain", self.ws, self.bin, self.sys):
d.mkdir(parents=True)
- for name in ("flow.sh", "setup.sh", "doctor.sh", "init-workspace.sh", "verdict.py", "vcd2json.py"):
+ for name in ("flow.sh", "setup.sh", "doctor.sh", "init-workspace.sh", "verdict.py", "vcd2json.py",
+ "path.sh", "runtimes.sh", "run"):
(self.pkg / "toolchain" / name).symlink_to(PKG / "toolchain" / name)
(self.pkg / "viewer.sh").symlink_to(PKG / "viewer.sh")
for name in system:
@@ -107,7 +140,8 @@ class Sandbox:
def run(self, argv, cwd=None, hide=(), **env):
full = {k: v for k, v in os.environ.items() if k not in SCRUB}
- full.update(PATH=f"{self.bin}:{self.sys}", STUB_CALLS=str(self.calls), STUB_BIN=str(self.bin), LC_ALL="C")
+ full.update(PATH=f"{self.bin}:{self.sys}", STUB_CALLS=str(self.calls), STUB_BIN=str(self.bin), LC_ALL="C",
+ ADAPTER_RUNTIME_DIR=str(self.runtime))
if hide:
full["BASH_FUNC_command%%"] = HIDE
full["STUB_HIDE"] = " ".join(hide)
@@ -118,6 +152,31 @@ class Sandbox:
def called(self):
return self.calls.read_text().splitlines() if self.calls.exists() else []
+ def tools(self):
+ """The calls, minus runtimes.sh's `node -e` version probe (whose script spans several lines)."""
+ return [c for c in self.called() if re.match(r"(iverilog|vvp|yosys|nextpnr-ice40|icepack|iceprog|netlistsvg|npm|curl|suite-\S+) |node /", c)]
+
+ def harness_node(self, body=None):
+ """No node on PATH, but Harness's own recorded where the CLI lays it down."""
+ node = self.stub("node", body, where=self.root / "harness-node")
+ self.runtime.mkdir(exist_ok=True)
+ (self.runtime / "current-node").write_text(f"{node}\n")
+ return node
+
+ def no_node(self):
+ return f"miss node >= 18, and Harness's own Node is not in {self.runtime} — run `harness start` once to lay it down"
+
+ def suite(self, release=None, tools=ALL_TOOLS_OF_THE_SUITE, chipdb=False):
+ """oss-cad-suite/ in the install, as setup.sh leaves it: stub tools that log as suite-<tool>."""
+ for name in tools:
+ self.stub(name, body=f'echo "suite-{name} $*" >> "$STUB_CALLS"\n' + SMOKE.get(name, STUBS.get(name, "")),
+ where=self.pkg / "oss-cad-suite" / "bin")
+ if release:
+ (self.pkg / "oss-cad-suite" / ".release").write_text(release + "\n")
+ if chipdb:
+ (self.pkg / "oss-cad-suite" / "share" / "icebox").mkdir(parents=True)
+ (self.pkg / "oss-cad-suite" / "share" / "icebox" / "chipdb-5k.txt").write_text(".device 5k\n")
+
def design(self, rtl=True, tb=True, pcf=True, top="blink"):
for sub, name, ok in (("rtl", f"{top}.v", rtl), ("tb", f"{top}_tb.v", tb), ("constraints", f"{top}.pcf", pcf)):
if ok:
@@ -307,76 +366,230 @@ class Flow(unittest.TestCase):
class Setup(unittest.TestCase):
- TOOLS = ("yosys", "nextpnr-ice40", "icepack", "iverilog", "node", "npm")
+ TOOLS = ("yosys", "nextpnr-ice40", "icepack", "iverilog")
+ HIDDEN = TOOLS + ("brew",) # wherever they are installed, so a machine with Homebrew's answers the same
- def setup_sh(self, sb, **kw):
- return sb.run([sb.pkg / "toolchain" / "setup.sh"], **kw)
+ def sandbox(self, machine_tools=True, **kw):
+ sb = Sandbox(self, **kw)
+ for name in ("node", "npm", "vvp") + (self.TOOLS if machine_tools else ()):
+ sb.stub(name, body=SMOKE[name])
+ sb.stub("uname", body='case "$1" in -s) echo Darwin;; -m) echo arm64;; esac\n')
+ return sb
- def test_everything_already_there(self):
- sb = Sandbox(self, stubs=self.TOOLS)
- r = self.setup_sh(sb)
- self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
- self.assertEqual(r.stdout.splitlines(), [
- "ok yosys, nextpnr-ice40, icestorm, icarus-verilog already on PATH",
- " npm ci (netlistsvg 1.0.2, for the schematic)",
+ def setup_sh(self, sb, **kw):
+ return sb.run([sb.pkg / "toolchain" / "setup.sh"], cwd=sb.root, **kw)
+
+ def serve(self, sb, archive=None, sha=None):
+ """curl hands over `archive` (a tarball of the suite's layout by default) whatever the URL; shasum
+ answers the pinned checksum of the platform uname names, unless `sha` says otherwise."""
+ tgz = sb.root / "suite.tgz"
+ tgz.write_bytes(archive if archive is not None else suite_tarball())
+ sb.stub("curl", body='for a in "$@"; do case "$prev" in -o) out="$a";; esac; prev="$a"; done\n'
+ f'[ -n "$CURL_FAIL" ] && exit 22\n/bin/cp "{tgz}" "$out"\n')
+ sb.stub("shasum", body=f'echo "{sha or PINS["darwin-arm64"][1]} $3"\n')
+
+ def assert_smoke_and_versions(self, lines, node="v22.0.0"):
+ self.assertEqual(lines[-4:], [
+ " smoke run: a counter simulated, synthesised, placed, routed and packed (slow only the first time)",
"ok Yosys 0.99 (stub)",
"ok nextpnr-ice40 · icepack · Icarus Verilog version 13.0 (stable)",
- "ok netlistsvg 1.0.2 · node v22.0.0",
+ f"ok netlistsvg 1.0.2 · node {node}",
])
- self.assertIn("npm ci --silent --no-audit --no-fund", sb.called())
- self.assertTrue((sb.pkg / "node_modules" / ".bin" / "netlistsvg").exists()) # in the install, not the cwd
- def test_brew_installs_what_is_missing(self):
- sb = Sandbox(self, stubs=("yosys", "iverilog", "node", "npm"))
- sb.stub("brew", body=f'echo "HOMEBREW_NO_AUTO_UPDATE=$HOMEBREW_NO_AUTO_UPDATE" >> "$STUB_CALLS"\n'
- f'ln "{stub_file("nextpnr-ice40", "")}" "{stub_file("icepack", "")}" "$STUB_BIN"\n')
+ def test_the_machines_own_tools_are_kept_and_smoke_tested(self):
+ sb = self.sandbox()
r = self.setup_sh(sb)
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
- self.assertIn(" brew install nextpnr-ice40 icestorm (the open-source FPGA flow; a few minutes the first time)", r.stdout)
- self.assertIn("brew install nextpnr-ice40 icestorm", sb.called())
- self.assertIn("HOMEBREW_NO_AUTO_UPDATE=1", sb.called())
-
- def test_a_formula_that_installs_without_its_binary(self):
- sb = Sandbox(self, stubs=("yosys", "nextpnr-ice40", "iverilog", "brew", "node", "npm"))
- r = self.setup_sh(sb)
- self.assertEqual(r.returncode, 1)
- self.assertEqual(r.stdout.splitlines()[-1], "miss icepack even after installing icestorm")
-
- def test_no_brew_says_where_to_get_the_tools(self):
- sb = Sandbox(self, stubs=("yosys",))
- r = self.setup_sh(sb)
- self.assertEqual(r.returncode, 1)
lines = r.stdout.splitlines()
- self.assertEqual(lines[0], "miss nextpnr-ice40 icestorm icarus-verilog and no brew to install them with.")
- self.assertTrue(lines[1].startswith(" macOS: /bin/bash -c "))
- self.assertEqual(lines[2], " Linux: apt install yosys nextpnr-ice40 fpga-icestorm iverilog")
- self.assertIn("oss-cad-suite", lines[3])
-
- def test_without_yosys_on_path_it_looks_in_homebrew_first(self):
- # Hidden everywhere, so the answer is the same on a machine that has them in /opt/homebrew.
- sb = Sandbox(self)
- r = self.setup_sh(sb, hide=("yosys", "nextpnr-ice40", "icepack", "iverilog", "brew"))
+ self.assertEqual(lines[:2], ["ok yosys, nextpnr-ice40, icepack, iverilog already on this machine",
+ " npm ci (netlistsvg 1.0.2, for the schematic)"])
+ self.assert_smoke_and_versions(lines)
+ self.assertEqual(len(lines), 6)
+ tools = [c.split()[0] for c in sb.tools()]
+ self.assertEqual(tools[:6], ["npm", "iverilog", "vvp", "yosys", "nextpnr-ice40", "icepack"])
+ self.assertIn("npm ci --silent --no-audit --no-fund", sb.called())
+ self.assertNotIn("curl", tools)
+ self.assertTrue((sb.pkg / "node_modules" / ".bin" / "netlistsvg").exists()) # in the install, not the cwd
+ self.assertFalse((sb.pkg / "oss-cad-suite").exists())
+ self.assertEqual(list(Path(sb.root).glob("tmp/yosys-smoke.*")), [])
+
+ def test_a_machine_without_the_tools_gets_the_oss_cad_suite(self):
+ sb = self.sandbox(machine_tools=False)
+ self.serve(sb)
+ (sb.pkg / ".oss-cad-suite.interrupted").mkdir() # a run killed mid-download left this
+ tmp = sb.root / "tmp"
+ tmp.mkdir()
+ r = self.setup_sh(sb, hide=self.HIDDEN, TMPDIR=tmp)
+ self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
+ lines = r.stdout.splitlines()
+ self.assertEqual(lines[:2], [" this machine has no yosys nextpnr-ice40 icepack iverilog",
+ f" fetching the OSS CAD Suite {RELEASE} for darwin-arm64 ({PINS['darwin-arm64'][0]} MB, a few minutes the first time)"])
+ self.assertRegex(lines[2], rf"^ok OSS CAD Suite {RELEASE} in oss-cad-suite/ \(\d+(\.\d+)?[BKMG]\)$")
+ self.assert_smoke_and_versions(lines)
+ self.assertIn(f"curl -fsSL --retry 3 --connect-timeout 20 --max-time 3600 -o {sb.pkg}/.oss-cad-suite.", "\n".join(sb.called()))
+ self.assertIn(suite_url("darwin-arm64"), "\n".join(sb.called()))
+ # the smoke run and the version lines ran the suite's tools, not anything else on PATH
+ self.assertEqual([c.split()[0] for c in sb.called() if c.startswith("suite-")],
+ ["suite-iverilog", "suite-vvp", "suite-yosys", "suite-nextpnr-ice40", "suite-icepack",
+ "suite-yosys", "suite-iverilog"])
+ suite = sb.pkg / "oss-cad-suite"
+ kept = sorted(str(f.relative_to(suite)) for f in suite.rglob("*") if f.is_file())
+ self.assertEqual(kept, sorted([
+ ".release", "VERSION", "license/COPYING", "etc/cacert.pem", "Frameworks/QtCore.framework/QtCore",
+ "bin/yosys", "bin/yosys-abc", "bin/nextpnr-ice40", "bin/icepack", "bin/iceprog", "bin/iverilog", "bin/vvp",
+ "libexec/yosys", "libexec/nextpnr-ice40", "libexec/ivl",
+ "lib/libz.1.dylib", "lib/ivl/system.vpi", "lib/python3.11/os.py", "lib/python3.11/lib-dynload/_json.so",
+ "share/yosys/ice40/cells_sim.v", "share/icebox/chipdb-5k.txt",
+ ]))
+ self.assertEqual((suite / ".release").read_text(), f"{RELEASE}\n")
+ self.assertEqual(sorted(p.name for p in sb.pkg.iterdir() if p.name.startswith(".oss-cad-suite")), [])
+ self.assertEqual(list(tmp.iterdir()), [], "the smoke run's scratch dir is removed")
+
+ def test_a_suite_at_the_pinned_release_is_used_as_it_is(self):
+ sb = self.sandbox(machine_tools=False)
+ sb.suite(release=RELEASE)
+ r = self.setup_sh(sb, hide=self.HIDDEN)
+ self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
+ self.assertEqual(r.stdout.splitlines()[0], f"ok OSS CAD Suite {RELEASE} already in oss-cad-suite/")
+ self.assertFalse(any(c.startswith("curl") for c in sb.called()))
+ self.assertIn("suite-nextpnr-ice40", "\n".join(sb.called()))
+
+ def test_a_suite_from_another_release_is_replaced_even_on_a_machine_with_the_tools(self):
+ # flow.sh would prefer the stale suite over the machine's tools, so it cannot be left there.
+ sb = self.sandbox()
+ sb.suite(release="2020-01-01")
+ (sb.pkg / "oss-cad-suite" / "bin" / "stale").write_text("")
+ self.serve(sb)
+ r = self.setup_sh(sb)
+ self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
+ self.assertTrue(r.stdout.splitlines()[0].startswith(f" fetching the OSS CAD Suite {RELEASE} for darwin-arm64"))
+ self.assertFalse((sb.pkg / "oss-cad-suite" / "bin" / "stale").exists())
+ self.assertEqual((sb.pkg / "oss-cad-suite" / ".release").read_text(), f"{RELEASE}\n")
+
+ def test_each_platform_fetches_its_own_build(self):
+ for system, machine, platform in (("Darwin", "x86_64", "darwin-x64"), ("Linux", "x86_64", "linux-x64"),
+ ("Linux", "aarch64", "linux-arm64"), ("Linux", "arm64", "linux-arm64")):
+ with self.subTest(platform=platform, machine=machine):
+ sb = self.sandbox(machine_tools=False)
+ sb.stub("uname", body=f'case "$1" in -s) echo {system};; -m) echo {machine};; esac\n')
+ self.serve(sb, sha=PINS[platform][1])
+ r = self.setup_sh(sb, hide=self.HIDDEN)
+ self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
+ self.assertIn(f" fetching the OSS CAD Suite {RELEASE} for {platform} ({PINS[platform][0]} MB, a few minutes the first time)",
+ r.stdout.splitlines())
+ self.assertIn(suite_url(platform), "\n".join(sb.called()))
+
+ def test_a_platform_the_suite_is_not_built_for(self):
+ sb = self.sandbox(machine_tools=False)
+ sb.stub("uname", body='case "$1" in -s) echo FreeBSD;; -m) echo amd64;; esac\n')
+ r = self.setup_sh(sb, hide=self.HIDDEN)
self.assertEqual(r.returncode, 1)
- self.assertEqual(r.stdout.splitlines()[0],
- "miss yosys nextpnr-ice40 icestorm icarus-verilog and no brew to install them with.")
-
- def test_node_npm_and_python_are_required(self):
- for missing, message in (("node", "miss node >= 18 on PATH (the viewer and netlistsvg)"),
- ("npm", "miss npm on PATH"),
- ("python3", "miss python3 (the VCD reader and the verdict)")):
+ self.assertEqual(r.stdout.splitlines()[-1],
+ "miss yosys nextpnr-ice40 icepack iverilog — and the OSS CAD Suite has no build for FreeBSD amd64")
+ self.assertFalse(any(c.startswith(("curl", "npm")) for c in sb.called()))
+
+ def test_a_download_that_fails_or_does_not_match_changes_nothing(self):
+ for case in ("offline", "checksum", "sha256sum", "not a tarball"):
+ with self.subTest(case):
+ sb = self.sandbox(machine_tools=False)
+ sb.suite(release="2020-01-01")
+ if case == "sha256sum": # no shasum on this machine (a Linux without perl's): coreutils' answers
+ self.serve(sb)
+ (sb.bin / "shasum").unlink()
+ sb.stub("sha256sum", body='echo "0000 $1"\n')
+ else:
+ self.serve(sb, archive=b"<html>rate limited</html>" if case == "not a tarball" else None,
+ sha="f" * 64 if case == "checksum" else None)
+ r = self.setup_sh(sb, hide=self.HIDDEN, CURL_FAIL="1" if case == "offline" else "")
+ self.assertEqual(r.returncode, 1)
+ last = r.stdout.splitlines()[-1]
+ if case == "offline":
+ self.assertEqual(last, f"miss could not download {suite_url('darwin-arm64')} — check this machine's internet connection")
+ elif case == "not a tarball":
+ self.assertEqual(last, "miss the OSS CAD Suite archive would not unpack (is the disk full?)")
+ else:
+ self.assertEqual(last, f"miss {suite_url('darwin-arm64')} did not match its pinned checksum; nothing was installed")
+ self.assertEqual((sb.pkg / "oss-cad-suite" / ".release").read_text(), "2020-01-01\n")
+ self.assertEqual(sorted(p.name for p in sb.pkg.iterdir() if p.name.startswith(".oss-cad-suite")), [])
+
+ def test_node_npm_and_python_come_before_any_download(self):
+ for missing in ("node", "npm", "python3"):
with self.subTest(missing):
- sb = Sandbox(self, stubs=[t for t in self.TOOLS if t != missing], python=missing != "python3")
- r = self.setup_sh(sb)
+ sb = self.sandbox(machine_tools=False, python=missing != "python3")
+ if missing != "python3":
+ (sb.bin / missing).unlink()
+ self.serve(sb)
+ r = self.setup_sh(sb, hide=self.HIDDEN)
self.assertEqual(r.returncode, 1)
- self.assertEqual(r.stdout.splitlines()[-1], message)
- self.assertNotIn("npm ci --silent --no-audit --no-fund", sb.called())
+ self.assertEqual(r.stdout.splitlines(), [{"node": sb.no_node(), "npm": "miss npm on PATH",
+ "python3": "miss python3 (the VCD reader and the verdict)"}[missing]])
+ self.assertFalse(any(c.startswith("curl") for c in sb.called()))
+
+ def test_without_node_on_path_harnesss_own_runs_npm_and_netlistsvg(self):
+ sb = self.sandbox()
+ (sb.bin / "node").unlink()
+ (sb.bin / "npm").unlink()
+ sb.harness_node(SMOKE["node"])
+ sb.stub("npm", body=SMOKE["npm"], where=sb.root / "harness-node")
+ r = self.setup_sh(sb)
+ self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
+ self.assert_smoke_and_versions(r.stdout.splitlines())
def test_npm_ci_that_leaves_no_netlistsvg(self):
- sb = Sandbox(self, stubs=self.TOOLS)
+ sb = self.sandbox()
sb.stub("npm", body="")
r = self.setup_sh(sb)
self.assertEqual(r.returncode, 1)
self.assertEqual(r.stdout.splitlines()[-1], "miss node_modules/.bin/netlistsvg after npm ci")
+ self.assertFalse(any(c.startswith("iverilog") for c in sb.called()))
+
+ def test_a_tool_that_does_not_run_is_named(self):
+ for tool in ("iverilog", "vvp", "yosys", "nextpnr-ice40", "icepack"):
+ with self.subTest(tool):
+ sb = self.sandbox()
+ r = self.setup_sh(sb, STUB_FAIL=tool)
+ self.assertEqual(r.returncode, 1)
+ self.assertEqual(r.stdout.splitlines()[-1], f"miss {tool} does not run on this machine: {tool}: stub failure")
+ sb = self.sandbox()
+ sb.stub("icepack", body="") # exits 0 and packs nothing
+ r = self.setup_sh(sb)
+ self.assertEqual((r.returncode, r.stdout.splitlines()[-1]), (1, "miss icepack does not run on this machine: led 1"))
+
+ def test_without_yosys_on_path_it_looks_in_homebrew_too(self):
+ # after the rest of PATH, so Homebrew's node never replaces the one runtimes.sh chose
+ sb = self.sandbox(machine_tools=False)
+ sb.stub("curl", body='echo "PATH=$PATH" >> "$STUB_CALLS"; exit 22\n')
+ r = self.setup_sh(sb, hide=self.HIDDEN)
+ self.assertEqual(r.returncode, 1)
+ [path] = [c for c in sb.called() if c.startswith("PATH=")]
+ self.assertTrue(path.endswith(":/opt/homebrew/bin:/usr/local/bin"), path)
+
+
+def suite_tarball():
+ """The OSS CAD Suite's layout in miniature: the tools setup.sh keeps (as smoke-run stubs), and some of
+ what it leaves behind — other tools, Python's tests and packages, GHDL, LLVM."""
+ files = {
+ "VERSION": "20260916\n", "README": "", "license/COPYING": "", "etc/cacert.pem": "",
+ "Frameworks/QtCore.framework/QtCore": "", "examples/ice40/blink.v": "",
+ "libexec/yosys": "", "libexec/nextpnr-ice40": "", "libexec/ivl": "", "libexec/ghdl": "", "libexec/nextpnr-ecp5": "",
+ "lib/libz.1.dylib": "", "lib/ivl/system.vpi": "", "lib/python3.11/os.py": "", "lib/python3.11/lib-dynload/_json.so": "",
+ "lib/python3.11/test/test_os.py": "", "lib/python3.11/site-packages/pip/__init__.py": "", "lib/python2.7/os.py": "",
+ "lib/ghdl/std.cf": "", "lib/libghdl-5.dylib": "", "lib/libLLVM.so.21": "", "lib/libgallium-26.so": "", "lib/dri/swrast.so": "",
+ "share/yosys/ice40/cells_sim.v": "", "share/icebox/chipdb-5k.txt": "", "share/trellis/database.json": "",
+ "bin/ghdl": "",
+ }
+ for name in ("yosys", "yosys-abc", "nextpnr-ice40", "icepack", "iceprog", "iverilog", "vvp"):
+ files[f"bin/{name}"] = ("#!/bin/sh\n" f'echo "suite-{name} $*" >> "$STUB_CALLS"\n'
+ f'case " $STUB_FAIL " in *" {name} "*) echo "{name}: stub failure"; exit 1;; esac\n'
+ + SMOKE.get(name, ""))
+ buf = io.BytesIO()
+ with tarfile.open(fileobj=buf, mode="w:gz") as tar:
+ for rel, text in files.items():
+ data = text.encode()
+ info = tarfile.TarInfo(f"oss-cad-suite/{rel}")
+ info.size, info.mode = len(data), 0o755
+ tar.addfile(info, io.BytesIO(data))
+ return buf.getvalue()
class Doctor(unittest.TestCase):
@@ -405,6 +618,31 @@ class Doctor(unittest.TestCase):
])
self.assertTrue(r.stdout.splitlines()[8].startswith("ok Python 3."))
+ def test_the_oss_cad_suite_setup_fetched_comes_first(self):
+ sb = Sandbox(self, stubs=("yosys", "nextpnr-ice40", "icepack", "iverilog", "node")) # the machine's too
+ sb.suite(release=RELEASE, chipdb=True)
+ sb.stub("netlistsvg", where=sb.pkg / "node_modules" / ".bin")
+ r = self.doctor(sb)
+ self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
+ self.assertEqual(r.stdout.splitlines()[:8], [
+ "ok yosys, the synthesiser — Yosys 0.99 (stub)",
+ "ok nextpnr-ice40, place and route — nextpnr-ice40 (stub)",
+ "ok icepack, the bitstream packer (icestorm)",
+ "ok iverilog, the simulator — Icarus Verilog version 13.0 (stable)",
+ "ok iceprog, to flash a board over USB",
+ "ok netlistsvg 1.0.2, the schematic",
+ "ok node v22.0.0 for the viewer",
+ "ok IceStorm chipdb, for the pane's pin maps",
+ ])
+ self.assertEqual([c.split()[0] for c in sb.called() if c.startswith("suite-")],
+ ["suite-yosys", "suite-nextpnr-ice40", "suite-iverilog"])
+
+ def test_harnesss_own_node_serves_the_viewer(self):
+ sb = Sandbox(self, stubs=("yosys", "nextpnr-ice40", "icepack", "iverilog"))
+ sb.harness_node(SMOKE["node"])
+ r = self.doctor(sb, hide=("iceprog",))
+ self.assertIn("ok node v22.0.0 for the viewer", r.stdout.splitlines())
+
def test_a_bare_machine(self):
sb = Sandbox(self)
r = self.doctor(sb, hide=("yosys", "nextpnr-ice40", "icepack", "iverilog", "iceprog", "node", "python3"))
@@ -416,7 +654,7 @@ class Doctor(unittest.TestCase):
"miss iverilog — run toolchain/setup.sh",
"info iceprog not found — synthesis works, flashing a real board does not",
"miss node_modules — run toolchain/setup.sh",
- "miss node for the viewer",
+ sb.no_node(),
"info IceStorm chipdb not found — the pane falls back to its built-in iCE40UP5K-SG48 pin table",
"miss python3",
])
@@ -431,7 +669,7 @@ class Doctor(unittest.TestCase):
lines = r.stdout.splitlines()
self.assertIn("miss yosys, the synthesiser", lines)
self.assertIn("miss iverilog, the simulator", lines)
- self.assertIn("miss node for the viewer", lines)
+ self.assertIn(sb.no_node(), lines)
self.assertIn("info IceStorm chipdb not found — the pane falls back to its built-in iCE40UP5K-SG48 pin table", lines)
@@ -475,14 +713,73 @@ class ViewerSh(unittest.TestCase):
self.assertEqual(sb.called(), [])
def test_runs_the_server_beside_it_from_anywhere(self):
- sb = Sandbox(self, stubs=("node",))
+ sb = Sandbox(self, stubs=("node", "yosys")) # yosys visible: path.sh leaves Homebrew's bin out
r = sb.run(["../install/viewer.sh"], HARNESS_VIEWER_PORT=4100, HARNESS_WORKSPACE=sb.ws)
self.assertEqual(r.returncode, 0, r.stderr)
- [call] = sb.called()
+ [call] = sb.tools()
node, server = call.split(" ", 1)
self.assertEqual((node, os.path.realpath(server)), ("node", os.path.realpath(sb.pkg / "viewer.mjs")))
self.assertTrue(os.path.isabs(server))
+ def test_the_server_runs_with_the_suite_and_harnesss_own_node_on_path(self):
+ sb = Sandbox(self)
+ sb.harness_node('echo "PATH=$PATH" >> "$STUB_CALLS"\n')
+ sb.suite(release=RELEASE, tools=("yosys", "icepack"))
+ r = sb.run([sb.pkg / "viewer.sh"], HARNESS_VIEWER_PORT=4100, HARNESS_WORKSPACE=sb.ws)
+ self.assertEqual(r.returncode, 0, r.stderr)
+ path = sb.called()[-1].removeprefix("PATH=").split(":")
+ # (runtimes.sh may put Harness's node dir in front more than once: once is what matters)
+ self.assertEqual(list(dict.fromkeys(path)), [str(sb.root / "harness-node"), str(sb.pkg / "oss-cad-suite" / "bin"), str(sb.bin), str(sb.sys)])
+
+ def test_no_node_anywhere_is_a_miss(self):
+ sb = Sandbox(self)
+ r = sb.run([sb.pkg / "viewer.sh"], HARNESS_VIEWER_PORT=4100, HARNESS_WORKSPACE=sb.ws, hide=("node",))
+ self.assertEqual((r.returncode, r.stdout), (1, sb.no_node() + "\n"))
+
+
+class Run(unittest.TestCase):
+ """toolchain/run and path.sh, which flow.sh and doctor.sh share: the order the tools are found in."""
+
+ def run_(self, sb, *argv, **kw):
+ return sb.run([sb.pkg / "toolchain" / "run", *argv], **kw)
+
+ def test_a_tool_with_its_arguments_and_exit_code(self):
+ sb = Sandbox(self, stubs=("yosys",))
+ sb.stub("iverilog", body='exit 3\n')
+ r = self.run_(sb, "yosys", "-p", "read_verilog rtl/*.v; stat")
+ self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
+ self.assertEqual(self.run_(sb, "iverilog", "-o", "out/sim.vvp").returncode, 3)
+ self.assertEqual(sb.tools(), ["yosys -p read_verilog rtl/*.v; stat", "iverilog -o out/sim.vvp"])
+
+ def test_the_suite_first_then_the_machines_then_homebrews(self):
+ sb = Sandbox(self, stubs=("yosys",))
+ sb.suite(release=RELEASE, tools=("yosys",))
+ self.run_(sb, "yosys", "-V")
+ self.assertEqual(sb.called()[:2], ["yosys -V", "suite-yosys -V"])
+ shutil.rmtree(sb.pkg / "oss-cad-suite")
+ sb.stub("show-path", body='echo "PATH=$PATH" >> "$STUB_CALLS"\n')
+ self.run_(sb, "show-path")
+ self.assertEqual(sb.called()[-1], f"PATH={sb.bin}:{sb.sys}", "yosys is visible: PATH is left alone")
+ self.run_(sb, "show-path", hide=("yosys",))
+ self.assertEqual(sb.called()[-1], f"PATH={sb.bin}:{sb.sys}:/opt/homebrew/bin:/usr/local/bin", "after, so it shadows no node")
+
+ def test_a_tool_that_is_not_there_or_no_tool_at_all(self):
+ sb = Sandbox(self)
+ r = self.run_(sb, "iceprog", "out/blink.bin", hide=("iceprog",))
+ self.assertEqual((r.returncode, r.stdout), (127, "miss iceprog — run toolchain/setup.sh\n"))
+ r = self.run_(sb)
+ self.assertEqual(r.returncode, 2)
+ self.assertIn('usage: "$YOSYS_TOOLCHAIN/run" <tool> [arguments…]', r.stderr)
+
+ def test_the_flow_draws_with_harnesss_own_node_when_path_has_none(self):
+ sb = Sandbox(self, stubs=ALL_FLOW)
+ sb.design()
+ sb.harness_node()
+ sb.stub("netlistsvg", body='echo "node=$(command -v node)" >> "$STUB_CALLS"\necho "<svg/>" > "$3"\n',
+ where=sb.pkg / "node_modules" / ".bin")
+ sb.run([sb.pkg / "toolchain" / "flow.sh", "blink"])
+ self.assertIn(f"node={sb.root / 'harness-node' / 'node'}", sb.called())
+
REAL = ("iverilog", "vvp", "yosys", "nextpnr-ice40", "icepack")
REAL_PATH = f"{os.environ.get('PATH', '')}:/opt/homebrew/bin:/usr/local/bin"
diff --git a/store/agents/yosys/viewer.sh b/store/agents/yosys/viewer.sh
index 9a40a19cc..6107290b9 100755
--- a/store/agents/yosys/viewer.sh
+++ b/store/agents/yosys/viewer.sh
@@ -1,5 +1,11 @@
#!/usr/bin/env bash
# The pane. Harness runs this here with HARNESS_VIEWER_PORT and HARNESS_WORKSPACE.
+# The daemon starts it through a login shell whose PATH may hold no node at all; path.sh also puts the
+# package's OSS CAD Suite on PATH, where the pane finds IceStorm's chip database beside icepack.
set -euo pipefail
: "${HARNESS_VIEWER_PORT:?}"; : "${HARNESS_WORKSPACE:?}"
-exec node "$(cd "$(dirname "$0")" && pwd)/viewer.mjs"
+here="$(cd "$(dirname "$0")" && pwd)"
+# shellcheck source=toolchain/path.sh
+. "$here/toolchain/path.sh"
+harness_node 18 || exit 1
+exec node "$here/viewer.mjs"
diff --git a/store/agents/yosys/viewer/lib/chip.mjs b/store/agents/yosys/viewer/lib/chip.mjs
index da9267665..300aa92cb 100644
--- a/store/agents/yosys/viewer/lib/chip.mjs
+++ b/store/agents/yosys/viewer/lib/chip.mjs
@@ -48,7 +48,10 @@ const CHIPDB_FOR = {
}
let chipdbDirCache
-/** IceStorm's chipdb directory, found next to icepack; null when IceStorm is not installed. */
+/**
+ * IceStorm's chipdb directory, found next to icepack — share/icestorm/chipdb in Homebrew's IceStorm,
+ * share/icebox in the OSS CAD Suite setup.sh fetches — or null when IceStorm is not installed.
+ */
export function chipdbDir() {
if (chipdbDirCache !== undefined) return chipdbDirCache
chipdbDirCache = null
@@ -57,7 +60,10 @@ export function chipdbDir() {
const bin = execFileSync('/bin/sh', ['-c', 'command -v icepack'], {
encoding: 'utf8', env: { ...process.env, PATH: `${process.env.PATH ?? ''}:/opt/homebrew/bin:/usr/local/bin:/usr/bin` },
}).trim()
- if (bin) candidates.push(join(dirname(realpathSync(bin)), '..', 'share', 'icestorm', 'chipdb'))
+ if (bin) {
+ const prefix = join(dirname(realpathSync(bin)), '..')
+ candidates.push(join(prefix, 'share', 'icestorm', 'chipdb'), join(prefix, 'share', 'icebox'))
+ }
} catch { /* not on PATH */ }
candidates.push('/opt/homebrew/share/icestorm/chipdb', '/usr/local/share/icestorm/chipdb', '/usr/share/icestorm/chipdb')
chipdbDirCache = candidates.find((d) => existsSync(join(d, 'chipdb-5k.txt'))) ?? null
diff --git a/store/agents/yosys/viewer/test/viewer.test.mjs b/store/agents/yosys/viewer/test/viewer.test.mjs
index 2300e73e7..ccdd29945 100644
--- a/store/agents/yosys/viewer/test/viewer.test.mjs
+++ b/store/agents/yosys/viewer/test/viewer.test.mjs
@@ -368,6 +368,15 @@ test('chipdb: found beside icepack and read from its head, or the built-in UP5K
])
assert.equal(found.pinsCached, true)
+ // The OSS CAD Suite setup.sh fetches keeps the chipdb in share/icebox, beside the same bin/.
+ mkdirSync(join(root, 'suite', 'bin'), { recursive: true })
+ writeFileSync(join(root, 'suite', 'bin', 'icepack'), '')
+ mkdirSync(join(root, 'suite', 'share', 'icebox'), { recursive: true })
+ writeFileSync(join(root, 'suite', 'share', 'icebox', 'chipdb-5k.txt'), '.device 5k\n.pins sg48\n35 12 31 1\n')
+ const suite = probe({ PROBE_ICEPACK: join(root, 'suite', 'bin', 'icepack') }, [['up5k', 'sg48']])
+ assert.equal(realpathSync(suite.dir), realpathSync(join(root, 'suite', 'share', 'icebox')))
+ assert.deepEqual(suite.pins, [[{ pin: '35', x: 12, y: 31, z: 1 }]])
+
const none = probe({ PROBE_ICEPACK: '', PROBE_NO_PATH: '1' }, [['up5k', 'sg48'], ['hx8k', 'ct256']])
assert.equal(none.dir, null)
assert.equal(none.lookupPath, ':/opt/homebrew/bin:/usr/local/bin:/usr/bin')
diff --git a/store/tools/runtimes.sh b/store/tools/runtimes.sh
index 51fefe3f9..7223c78dc 100644
--- a/store/tools/runtimes.sh
+++ b/store/tools/runtimes.sh
@@ -77,6 +77,8 @@ harness_node() {
# A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
_harness_node_at_least "$min" && return 0
diff --git a/store/tools/test_runtimes.py b/store/tools/test_runtimes.py
index 52266cda6..320b44b61 100644
--- a/store/tools/test_runtimes.py
+++ b/store/tools/test_runtimes.py
@@ -179,6 +179,12 @@ class Node(unittest.TestCase):
r = box.run('harness_node 18 && command -v node && command -v npm', NODE_VERSION="20.1.0")
self.assertEqual(lines(r), [str(node), str(node.parent / "npm")], r.stderr)
+ def test_asking_twice_adds_harness_node_to_path_once(self):
+ box = Box(self)
+ self.runtime_node(box, "22.23.2") # no npm beside it, as in a sandbox
+ r = box.run('harness_node 18 && harness_node 18 && harness_node 20 && echo "$PATH"')
+ self.assertEqual(lines(r), [f"{box.root}/harness-node/bin:{box.bin}"], r.stderr)
+
def test_a_node_without_npm_is_kept_when_harness_node_is_older(self):
box = Box(self)
box.stub("node", NODE)
diff --git a/store/viewers/cad-viewer/runtimes.sh b/store/viewers/cad-viewer/runtimes.sh
index 51fefe3f9..7223c78dc 100644
--- a/store/viewers/cad-viewer/runtimes.sh
+++ b/store/viewers/cad-viewer/runtimes.sh
@@ -77,6 +77,8 @@ harness_node() {
# A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
_harness_node_at_least "$min" && return 0
diff --git a/store/viewers/doc-viewer/runtimes.sh b/store/viewers/doc-viewer/runtimes.sh
index 51fefe3f9..7223c78dc 100644
--- a/store/viewers/doc-viewer/runtimes.sh
+++ b/store/viewers/doc-viewer/runtimes.sh
@@ -77,6 +77,8 @@ harness_node() {
# A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
_harness_node_at_least "$min" && return 0
diff --git a/store/viewers/model-viewer/runtimes.sh b/store/viewers/model-viewer/runtimes.sh
index 51fefe3f9..7223c78dc 100644
--- a/store/viewers/model-viewer/runtimes.sh
+++ b/store/viewers/model-viewer/runtimes.sh
@@ -77,6 +77,8 @@ harness_node() {
# A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
_harness_node_at_least "$min" && return 0
diff --git a/store/viewers/mujoco-viewer/runtimes.sh b/store/viewers/mujoco-viewer/runtimes.sh
index 51fefe3f9..7223c78dc 100644
--- a/store/viewers/mujoco-viewer/runtimes.sh
+++ b/store/viewers/mujoco-viewer/runtimes.sh
@@ -77,6 +77,8 @@ harness_node() {
# A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
_harness_node_at_least "$min" && return 0
diff --git a/store/viewers/video-viewer/runtimes.sh b/store/viewers/video-viewer/runtimes.sh
index 51fefe3f9..7223c78dc 100644
--- a/store/viewers/video-viewer/runtimes.sh
+++ b/store/viewers/video-viewer/runtimes.sh
@@ -77,6 +77,8 @@ harness_node() {
# A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
_harness_node_at_least "$min" && return 0
diff --git a/store/viewers/web-viewer/runtimes.sh b/store/viewers/web-viewer/runtimes.sh
index 51fefe3f9..7223c78dc 100644
--- a/store/viewers/web-viewer/runtimes.sh
+++ b/store/viewers/web-viewer/runtimes.sh
@@ -77,6 +77,8 @@ harness_node() {
# A node without npm beside it (a distro's nodejs package) cannot run a setup's `npm ci`.
if [ "$own" = 1 ] && command -v npm >/dev/null 2>&1; then return 0; fi
recorded="$(cat "$HARNESS_RUNTIME/current-node" 2>/dev/null || true)"
+ # Already Harness's own (a second call, or a wrapper calling a script that asks again): nothing to add.
+ if [ "$own" = 1 ] && [ -n "$recorded" ] && [ "$(command -v node)" = "${recorded%/*}/node" ]; then return 0; fi
if [ -n "$recorded" ] && [ -x "${recorded%/*}/node" ]; then
PATH="${recorded%/*}:$PATH"; export PATH; hash -r 2>/dev/null || true
_harness_node_at_least "$min" && return 0