Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/bot-nix-hashes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
);
};
}
53 changes: 53 additions & 0 deletions nix/dependency-identity.nix
Original file line number Diff line number Diff line change
@@ -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"
];
}
32 changes: 32 additions & 0 deletions nix/scripts/dependency-identity.test.ts
Original file line number Diff line number Diff line change
@@ -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])
}
})
Loading