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/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..8b3b3e0dc999 --- /dev/null +++ b/nix/scripts/dependency-identity.test.ts @@ -0,0 +1,32 @@ +import { expect, test } from "bun:test" +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" +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]) + } +})