Upgrade @huggingface/transformers to 4.3.2 and carry the sequential-session patch
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9607c8558f
commit
753ea03979
8 files changed
+136
-67
No files matched your search
@@ -0,0 +1,50 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
/**
|
||||
* Tripwires for the patched, pinned Transformers.js runtime (D-WS1a).
|
||||
* `@huggingface/transformers` carries a `bun patch` (D-027/D-028) keyed by
|
||||
* its exact version; a bump that forgets to regenerate the patch would leave
|
||||
* the app working but silently bring back the mobile OOM. These checks fail
|
||||
* the fast suite instead.
|
||||
*/
|
||||
|
||||
const ROOT = join(import.meta.dir, "..");
|
||||
const PKG_DIR = join(ROOT, "node_modules/@huggingface/transformers");
|
||||
const PINNED_VERSION = "4.3.2";
|
||||
|
||||
function read(path: string): string {
|
||||
return readFileSync(path, "utf8");
|
||||
}
|
||||
|
||||
/** Source text of `async function <name>(…) { … }` in a bundled file. */
|
||||
function functionSource(source: string, name: string): string {
|
||||
const start = source.indexOf(`async function ${name}(`);
|
||||
if (start < 0) throw new Error(`${name} not found`);
|
||||
const end = source.indexOf("\nfunction ", start + 1);
|
||||
const endAsync = source.indexOf("\nasync function ", start + 1);
|
||||
const stops = [end, endAsync].filter((i) => i > 0);
|
||||
return source.slice(start, stops.length ? Math.min(...stops) : undefined);
|
||||
}
|
||||
|
||||
describe("@huggingface/transformers runtime", () => {
|
||||
test("installed version is the pinned 4.3.2", () => {
|
||||
const installed = JSON.parse(read(join(PKG_DIR, "package.json"))).version;
|
||||
expect(installed).toBe(PINNED_VERSION);
|
||||
});
|
||||
|
||||
test("patchedDependencies points at an existing patch for the installed version", () => {
|
||||
const rootPkg = JSON.parse(read(join(ROOT, "package.json")));
|
||||
const patchPath = rootPkg.patchedDependencies?.[`@huggingface/transformers@${PINNED_VERSION}`];
|
||||
expect(typeof patchPath).toBe("string");
|
||||
expect(existsSync(join(ROOT, patchPath))).toBe(true);
|
||||
});
|
||||
|
||||
test("web bundle's constructSessions carries the sequential-load patch (D-027/D-028)", () => {
|
||||
const body = functionSource(read(join(PKG_DIR, "dist/transformers.web.js")), "constructSessions");
|
||||
expect(body).toContain("options?.sequentialSessionLoad");
|
||||
expect(body).toContain("Promise.all(");
|
||||
expect(body).toContain("for (const name of Object.keys(names))");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user