From e4655c9c1ccaff2ca5d62c132973c654b2a851a9 Mon Sep 17 00:00:00 2001 From: Alberto Minetti Date: Sun, 15 Nov 2026 18:23:39 +0000 Subject: [PATCH 1/2] test(nix): check dependency identity in the built install Cover the TUI startup crash from #56856: theme colors must survive spinner conversion, every OpenTUI consumer must resolve one runtime entrypoint, and the install must keep distinct Zod and OpenTelemetry peer contexts now that root dependencies participate in the filtered install (#56889). nix/scripts is not a workspace, so turbo never runs the test. The new checks..dependency-identity derivation overlays the node_modules output on the sources and runs the test there, and check-nix builds it, so an install-filter regression fails CI instead of the TUI. On the pre-#56889 filter the test reproduces the reported failure ('hex.replace is not a function') and two identity assertions. --- .github/workflows/check-nix.yml | 8 +++- flake.nix | 14 +++++++ nix/dependency-identity.nix | 53 ++++++++++++++++++++++++ nix/scripts/dependency-identity.test.ts | 54 +++++++++++++++++++++++++ 4 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 nix/dependency-identity.nix create mode 100644 nix/scripts/dependency-identity.test.ts diff --git a/.github/workflows/check-nix.yml b/.github/workflows/check-nix.yml index b52c03220e65..557dd70cee70 100644 --- a/.github/workflows/check-nix.yml +++ b/.github/workflows/check-nix.yml @@ -19,7 +19,7 @@ jobs: nix-eval: if: ${{ !github.event.pull_request.draft }} runs-on: blacksmith-4vcpu-ubuntu-2404 - timeout-minutes: 15 + timeout-minutes: 40 steps: - name: Checkout repository uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 @@ -95,3 +95,9 @@ jobs: echo "" echo "=== All evaluations passed ===" + + # Builds the Nix node_modules tree and runs the module identity test inside it, + # so a regression in the install filters fails here instead of at TUI startup. + - name: Check dependency identity + timeout-minutes: 20 + run: nix build .#checks.x86_64-linux.dependency-identity --print-build-logs diff --git a/flake.nix b/flake.nix index e96ac2344cbc..a8d4b835fb39 100644 --- a/flake.nix +++ b/flake.nix @@ -68,5 +68,19 @@ }; } ); + + checks = forEachSystem ( + pkgs: + let + node_modules = pkgs.callPackage ./nix/node_modules.nix { + inherit rev; + }; + in + { + dependency-identity = pkgs.callPackage ./nix/dependency-identity.nix { + inherit node_modules; + }; + } + ); }; } diff --git a/nix/dependency-identity.nix b/nix/dependency-identity.nix new file mode 100644 index 000000000000..6f62d9f25d6a --- /dev/null +++ b/nix/dependency-identity.nix @@ -0,0 +1,53 @@ +{ + lib, + stdenvNoCC, + bun, + node_modules, +}: +stdenvNoCC.mkDerivation { + pname = "opencode-dependency-identity"; + version = "1"; + + src = lib.fileset.toSource { + root = ../.; + fileset = lib.fileset.intersection (lib.fileset.fromSource (lib.sources.cleanSource ../.)) ( + lib.fileset.unions [ + ../packages + ../nix/scripts + ../bun.lock + ../bunfig.toml + ../package.json + ] + ); + }; + + nativeBuildInputs = [ bun ]; + + dontConfigure = true; + + buildPhase = '' + runHook preBuild + export HOME=$(mktemp -d) + export BUN_INSTALL_CACHE_DIR=$(mktemp -d) + # The test checks module identity, so it has to run against the install the + # derivation produces rather than a fresh install of its own. + cp -R ${node_modules}/. . + cd nix/scripts + bun test + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + mkdir -p $out + runHook postInstall + ''; + + dontFixup = true; + + meta.platforms = [ + "aarch64-linux" + "x86_64-linux" + "aarch64-darwin" + ]; +} diff --git a/nix/scripts/dependency-identity.test.ts b/nix/scripts/dependency-identity.test.ts new file mode 100644 index 000000000000..bc14354860ec --- /dev/null +++ b/nix/scripts/dependency-identity.test.ts @@ -0,0 +1,54 @@ +import { expect, test } from "bun:test" +import { readdir, realpath } from "node:fs/promises" +import { dirname, join } from "node:path" +import { migrateV1, resolveThemeDocument } from "../../packages/theme/src/tui/index.js" +import type { ThemeV1Json } from "../../packages/theme/src/tui/v1.js" +import { createColors, deriveInactiveColor, deriveTrailColors } from "../../packages/tui/src/ui/spinner.js" + +const root = join(import.meta.dir, "../..") +const source: ThemeV1Json = await Bun.file(join(root, "packages/tui/src/theme/assets/opencode.json")).json() + +test.each(["light", "dark"] as const)("theme colors survive spinner conversion in %s mode", (mode) => { + const color = resolveThemeDocument(migrateV1(source), mode).hue.accent[800] + const trail = deriveTrailColors(color) + expect([trail[0].r, trail[0].g, trail[0].b, trail[0].a]).toEqual([color.r, color.g, color.b, 1]) + const inactive = deriveInactiveColor(color, 0.2) + expect([inactive.r, inactive.g, inactive.b]).toEqual([color.r, color.g, color.b]) + expect(inactive.a).toBeCloseTo(0.2, 2) + expect(createColors({ colors: [color], defaultColor: color, enableFading: false })(0, 7, 54, 8)).toEqual(color) +}) + +test("OpenTUI consumers resolve one runtime entrypoint", async () => { + const consumers = ["theme", "tui", "cli", "merman", "latex", "plugin", "simulation"] + const paths = await Promise.all( + consumers.map((workspace) => realpath(Bun.resolveSync("@opentui/core", join(root, "packages", workspace)))), + ) + expect(new Set(paths).size).toBe(1) + + for (const dependency of ["@opentui/solid", "@opentui/keymap"]) { + const resolved = Bun.resolveSync(dependency, join(root, "packages/tui")) + expect(await realpath(Bun.resolveSync("@opentui/core", dirname(resolved)))).toBe(paths[0]) + } +}) + +test.each([ + ["@ai-sdk/provider-utils", "zod"], + ["@opentelemetry/core", "@opentelemetry/api"], +] as const)("%s keeps distinct %s peer contexts", async (name, peer) => { + const store = join(root, "node_modules/.bun") + const entries = (await readdir(store)).filter((entry) => entry.startsWith(name.replaceAll("/", "+") + "@")) + const contexts = new Map>() + + for (const entry of entries) { + const entryRoot = join(store, entry) + const packagePath = join(entryRoot, "node_modules", name) + const manifest = await Bun.file(join(packagePath, "package.json")).json() + const peerPath = await realpath(join(entryRoot, "node_modules", peer)) + const peerManifest = await Bun.file(join(peerPath, "package.json")).json() + const versions = contexts.get(manifest.version) ?? new Set() + versions.add(peerManifest.version) + contexts.set(manifest.version, versions) + } + + expect([...contexts.values()].some((versions) => versions.size > 1)).toBe(true) +}) From 20a2da4ec735a5e55cf80e3aa41c9bae4a8e8dd9 Mon Sep 17 00:00:00 2001 From: Alberto Minetti Date: Tue, 17 Nov 2026 23:18:28 +0000 Subject: [PATCH 2/2] test(nix): run the dependency identity check in bot-nix-hashes The check builds the fixed-output node_modules derivation, which is only pinned to the hash in nix/hashes.json. A pull request cannot update that hash (only bot/nix-hashes may), so check-nix would fail with a hash mismatch on any change to the install inputs - including a regression in the filters the test is meant to guard. Run it in bot-nix-hashes instead, right after the new hash is computed, building the check against that hash. Drop the two peer-context cases: they passed on the pre-#56889 layout too, and they only hold while the lockfile keeps multiple Zod and OpenTelemetry API versions. --- .github/workflows/bot-nix-hashes.yml | 20 ++++++++++++++++++++ .github/workflows/check-nix.yml | 8 +------- nix/scripts/dependency-identity.test.ts | 24 +----------------------- 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/.github/workflows/bot-nix-hashes.yml b/.github/workflows/bot-nix-hashes.yml index 039d8ee08874..43fe181058e3 100644 --- a/.github/workflows/bot-nix-hashes.yml +++ b/.github/workflows/bot-nix-hashes.yml @@ -90,8 +90,28 @@ jobs: fi echo "$HASH" > hash.txt + echo "hash=$HASH" >> "$GITHUB_OUTPUT" echo "Computed hash for ${SYSTEM}: $HASH" + # Dependency identity can only be checked against a tree built with its real + # hash, and this job is where that hash first exists. A pull request cannot + # carry the new hash (only bot/nix-hashes may), so check-nix cannot run this + # check: a filter or dependency change would make its pinned hash stale + # before the test ran. Running it here covers those changes after merge. + - name: Check dependency identity + env: + SYSTEM: ${{ matrix.system }} + HASH: ${{ steps.hash.outputs.hash }} + run: | + set -euo pipefail + + # node_modules.nix only reads the entry for the current system. + printf '{"nodeModules":{"%s":"%s"}}\n' "$SYSTEM" "$HASH" > nix/hashes.json + + # path: evaluates the working tree so the hash above is used instead of + # the one committed in nix/hashes.json. + nix build "path:$PWD#checks.${SYSTEM}.dependency-identity" --print-build-logs + - name: Upload hash uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: diff --git a/.github/workflows/check-nix.yml b/.github/workflows/check-nix.yml index 557dd70cee70..b52c03220e65 100644 --- a/.github/workflows/check-nix.yml +++ b/.github/workflows/check-nix.yml @@ -19,7 +19,7 @@ jobs: nix-eval: if: ${{ !github.event.pull_request.draft }} runs-on: blacksmith-4vcpu-ubuntu-2404 - timeout-minutes: 40 + timeout-minutes: 15 steps: - name: Checkout repository uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 @@ -95,9 +95,3 @@ jobs: echo "" echo "=== All evaluations passed ===" - - # Builds the Nix node_modules tree and runs the module identity test inside it, - # so a regression in the install filters fails here instead of at TUI startup. - - name: Check dependency identity - timeout-minutes: 20 - run: nix build .#checks.x86_64-linux.dependency-identity --print-build-logs diff --git a/nix/scripts/dependency-identity.test.ts b/nix/scripts/dependency-identity.test.ts index bc14354860ec..8b3b3e0dc999 100644 --- a/nix/scripts/dependency-identity.test.ts +++ b/nix/scripts/dependency-identity.test.ts @@ -1,5 +1,5 @@ import { expect, test } from "bun:test" -import { readdir, realpath } from "node:fs/promises" +import { realpath } from "node:fs/promises" import { dirname, join } from "node:path" import { migrateV1, resolveThemeDocument } from "../../packages/theme/src/tui/index.js" import type { ThemeV1Json } from "../../packages/theme/src/tui/v1.js" @@ -30,25 +30,3 @@ test("OpenTUI consumers resolve one runtime entrypoint", async () => { expect(await realpath(Bun.resolveSync("@opentui/core", dirname(resolved)))).toBe(paths[0]) } }) - -test.each([ - ["@ai-sdk/provider-utils", "zod"], - ["@opentelemetry/core", "@opentelemetry/api"], -] as const)("%s keeps distinct %s peer contexts", async (name, peer) => { - const store = join(root, "node_modules/.bun") - const entries = (await readdir(store)).filter((entry) => entry.startsWith(name.replaceAll("/", "+") + "@")) - const contexts = new Map>() - - for (const entry of entries) { - const entryRoot = join(store, entry) - const packagePath = join(entryRoot, "node_modules", name) - const manifest = await Bun.file(join(packagePath, "package.json")).json() - const peerPath = await realpath(join(entryRoot, "node_modules", peer)) - const peerManifest = await Bun.file(join(peerPath, "package.json")).json() - const versions = contexts.get(manifest.version) ?? new Set() - versions.add(peerManifest.version) - contexts.set(manifest.version, versions) - } - - expect([...contexts.values()].some((versions) => versions.size > 1)).toBe(true) -})