test(opencode): guard patched dependency versions (#46673)

This commit is contained in:
Aiden Cline 2026-09-01 14:59:45 -05:00 committed by GitHub
parent 1542195217
commit c066339d80
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 32 deletions

View file

@ -146,7 +146,6 @@
},
"patchedDependencies": {
"@dnd-kit/dom@0.5.0": "patches/@dnd-kit%2Fdom@0.5.0.patch",
"@ff-labs/fff-bun@0.9.3": "patches/@ff-labs%2Ffff-bun@0.9.3.patch",
"@npmcli/agent@4.0.2": "patches/@npmcli%2Fagent@4.0.2.patch",
"@silvia-odwyer/photon-node@0.3.4": "patches/@silvia-odwyer%2Fphoton-node@0.3.4.patch",
"@standard-community/standard-openapi@0.2.9": "patches/@standard-community%2Fstandard-openapi@0.2.9.patch",

View file

@ -0,0 +1,29 @@
import { describe, expect, test } from "bun:test"
import path from "path"
// Bun applies a patch only to the exact `name@version` named in
// `patchedDependencies`. Bumping the dependency without regenerating the patch
// does not fail `bun install`; the patch just stops applying and the runtime
// silently loses whatever the patch fixed. This pins the two together for the
// packages that ship in the CLI.
const root = path.resolve(import.meta.dir, "../../..")
const workspaces = ["packages/opencode", "packages/core"]
const patched = (await Bun.file(path.join(root, "package.json")).json()).patchedDependencies as Record<string, string>
describe("patched dependencies", () => {
for (const key of Object.keys(patched)) {
const at = key.lastIndexOf("@")
const name = key.slice(0, at)
const version = key.slice(at + 1)
test(`${key} matches the installed version`, async () => {
expect(await Bun.file(path.join(root, patched[key])).exists()).toBe(true)
for (const workspace of workspaces) {
const file = Bun.file(path.join(root, workspace, "node_modules", name, "package.json"))
if (!(await file.exists())) continue
const installed = (await file.json()).version as string
expect(installed, `${workspace} resolves ${name}@${installed}; patch is for ${version}`).toBe(version)
}
})
}
})

View file

@ -1,31 +0,0 @@
diff --git a/src/download.ts b/src/download.ts
index 3454256..6dca25a 100644
--- a/src/download.ts
+++ b/src/download.ts
@@ -7,7 +7,7 @@
*/
+declare const FFF_LIBC: "gnu" | "musl";
import { existsSync } from "node:fs";
-import { createRequire } from "node:module";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { getLibFilename, getNpmPackageName } from "./platform";
@@ -54,14 +54,10 @@ export function binaryExists(): boolean {
* in the same directory.
*/
function resolveFromNpmPackage(): string | null {
- const packageName = getNpmPackageName();
-
try {
- // Use createRequire to resolve the platform package's location
- const require = createRequire(join(getPackageDir(), "package.json"));
- const packageJsonPath = require.resolve(`${packageName}/package.json`);
- const packageDir = dirname(packageJsonPath);
- const binaryPath = join(packageDir, getLibFilename());
+ const binaryPath = require(
+ `@ff-labs/fff-bin-${process.platform === "linux" ? `linux-${process.arch}-${typeof FFF_LIBC === "string" ? FFF_LIBC : getNpmPackageName().endsWith("musl") ? "musl" : "gnu"}` : `${process.platform}-${process.arch}`}/${process.platform === "win32" ? "fff_c.dll" : process.platform === "darwin" ? "libfff_c.dylib" : "libfff_c.so"}`,
+ );
if (existsSync(binaryPath)) {
return binaryPath;