Files
windmill/cli/test/esbuild_loader_unit.test.ts
Ruben Fiszel 86d1d160f0 fix(cli): fall back to esbuild-wasm on native host/binary mismatch (#9629)
* fix(cli): fall back to esbuild-wasm on native host/binary mismatch

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(cli): guard tarball extraction, extend esbuild-wasm fallback to script bundling

Address CI review: prevent tar-slip in esbuild-wasm package extraction, route codebase/script and inline-rawscript bundling through getEsbuild() too, and move the loader to utils. Add a unit test for the tar-slip guard.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(cli): make esbuild-wasm fallback concurrency-safe

Address CI review (P1): memoize getEsbuild() on an in-flight promise so concurrent first callers (parallel wmill sync push) share one probe/download instead of racing, and give each extraction a unique temp dir so concurrent extractions can't clobber each other.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 02:33:18 +02:00

32 lines
1.1 KiB
TypeScript

/**
* Unit tests for esbuild_loader pure logic (no backend, no network).
*/
import { expect, test, describe } from "bun:test";
import { resolveTarEntryPath } from "../src/utils/esbuild_loader.ts";
import { sep, resolve } from "node:path";
describe("resolveTarEntryPath", () => {
const dest = resolve("/tmp/cache/esbuild-wasm-0.28.0");
test("strips the leading package/ component and resolves inside dest", () => {
expect(resolveTarEntryPath(dest, "package/lib/main.js")).toBe(
dest + sep + "lib" + sep + "main.js"
);
expect(resolveTarEntryPath(dest, "package/esbuild.wasm")).toBe(
dest + sep + "esbuild.wasm"
);
});
test("rejects tar-slip entries that escape the dest dir", () => {
expect(resolveTarEntryPath(dest, "package/../../etc/passwd")).toBeNull();
expect(resolveTarEntryPath(dest, "package/../../../outside")).toBeNull();
});
test("rejects entries that only share a prefix with dest", () => {
// ".../esbuild-wasm-0.28.0-evil" must not be treated as inside dest
expect(resolveTarEntryPath(dest, "evil/../../esbuild-wasm-0.28.0-evil/x"))
.toBeNull();
});
});