@blaxel/core 0.3.26-preview.314 → 0.3.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/common/settings.js +2 -2
- package/dist/cjs/image/image.js +63 -7
- package/dist/cjs/image/image.test.js +74 -0
- package/dist/cjs/types/image/image.browser.d.ts +2 -0
- package/dist/cjs/types/image/image.d.ts +10 -0
- package/dist/cjs-browser/.tsbuildinfo +1 -1
- package/dist/cjs-browser/common/settings.js +2 -2
- package/dist/cjs-browser/image/image.test.js +74 -0
- package/dist/cjs-browser/types/image/image.browser.d.ts +2 -0
- package/dist/cjs-browser/types/image/image.d.ts +10 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/common/settings.js +2 -2
- package/dist/esm/image/image.js +63 -7
- package/dist/esm/image/image.test.js +75 -1
- package/dist/esm-browser/.tsbuildinfo +1 -1
- package/dist/esm-browser/common/settings.js +2 -2
- package/dist/esm-browser/image/image.test.js +75 -1
- package/package.json +1 -1
|
@@ -24,8 +24,8 @@ function missingCredentialsMessage() {
|
|
|
24
24
|
return "No Blaxel credentials found. Set the BL_API_KEY and BL_WORKSPACE environment variables, or run `bl login`.";
|
|
25
25
|
}
|
|
26
26
|
// Build info - these placeholders are replaced at build time by build:replace-imports
|
|
27
|
-
const BUILD_VERSION = "0.3.26
|
|
28
|
-
const BUILD_COMMIT = "
|
|
27
|
+
const BUILD_VERSION = "0.3.26";
|
|
28
|
+
const BUILD_COMMIT = "18c2c73526c47b9ebc09aa3e16497b19854a02d0";
|
|
29
29
|
const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
|
|
30
30
|
const BLAXEL_API_VERSION = "2026-09-22";
|
|
31
31
|
// Bun < 1.3.11 never sends connection-level WINDOW_UPDATE: the pooled h2
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "fs";
|
|
5
5
|
import { tmpdir } from "os";
|
|
6
6
|
import { join } from "path";
|
|
7
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
7
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
8
|
+
import { settings } from "../common/settings.js";
|
|
8
9
|
import { ImageInstance } from "./image.js";
|
|
9
10
|
// Test fixtures
|
|
10
11
|
let tempDir;
|
|
@@ -541,3 +542,76 @@ describe("Dockerfile instruction order", () => {
|
|
|
541
542
|
expect(runIdx).toBeLessThan(thirdIdx);
|
|
542
543
|
});
|
|
543
544
|
});
|
|
545
|
+
describe("ImageInstance.build worker resources", () => {
|
|
546
|
+
async function buildWith(options, storedLabels) {
|
|
547
|
+
const calls = [];
|
|
548
|
+
vi.spyOn(settings, "authenticate").mockResolvedValue(undefined);
|
|
549
|
+
vi.spyOn(settings, "headers", "get").mockReturnValue({});
|
|
550
|
+
vi.spyOn(settings, "baseUrl", "get").mockReturnValue("https://api.test");
|
|
551
|
+
vi.stubGlobal("fetch", (url, init = {}) => {
|
|
552
|
+
const headers = init.headers;
|
|
553
|
+
const body = typeof init.body === "string" ? JSON.parse(init.body) : undefined;
|
|
554
|
+
calls.push({ url, method: init.method ?? "GET", headers, body });
|
|
555
|
+
if (url.includes("upload=true")) {
|
|
556
|
+
const sent = body.metadata?.labels;
|
|
557
|
+
return Promise.resolve(new Response(JSON.stringify({ metadata: { name: "img", labels: storedLabels ?? sent } }), {
|
|
558
|
+
status: 200,
|
|
559
|
+
headers: { "x-blaxel-upload-url": "https://upload.test/object" },
|
|
560
|
+
}));
|
|
561
|
+
}
|
|
562
|
+
if (url.startsWith("https://upload.test")) {
|
|
563
|
+
return Promise.resolve(new Response("", { status: 200 }));
|
|
564
|
+
}
|
|
565
|
+
return Promise.resolve(new Response(JSON.stringify({ metadata: { name: "img" }, status: "DEPLOYED" }), { status: 200 }));
|
|
566
|
+
});
|
|
567
|
+
const image = ImageInstance.fromRegistry("alpine:3.20");
|
|
568
|
+
// @ts-expect-error - private method
|
|
569
|
+
vi.spyOn(image, "_prepareForSandbox").mockReturnValue(image);
|
|
570
|
+
// @ts-expect-error - private method
|
|
571
|
+
vi.spyOn(image, "_waitForDeployment").mockResolvedValue("DEPLOYED");
|
|
572
|
+
await image.build({ name: "img", ...options });
|
|
573
|
+
return {
|
|
574
|
+
create: calls.find((call) => call.url.includes("upload=true")),
|
|
575
|
+
upload: calls.find((call) => call.url.startsWith("https://upload.test")),
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
afterEach(() => {
|
|
579
|
+
vi.restoreAllMocks();
|
|
580
|
+
vi.unstubAllGlobals();
|
|
581
|
+
});
|
|
582
|
+
it("sends build memory and volume as labels and signed upload headers", async () => {
|
|
583
|
+
const { create, upload } = await buildWith({ buildMemoryMb: 16384, buildVolumeMb: 32768 });
|
|
584
|
+
const labels = create.body.metadata?.labels;
|
|
585
|
+
expect(labels?.["x-blaxel-build-memory"]).toBe("16384");
|
|
586
|
+
expect(labels?.["x-blaxel-build-volume"]).toBe("32768");
|
|
587
|
+
expect(create.body.spec?.runtime?.memory).toBe(4096);
|
|
588
|
+
expect(upload.headers["x-amz-meta-x-blaxel-build-memory"]).toBe("16384");
|
|
589
|
+
expect(upload.headers["x-amz-meta-x-blaxel-build-volume"]).toBe("32768");
|
|
590
|
+
expect(upload.headers["x-amz-meta-x-blaxel-auto-generated"]).toBeUndefined();
|
|
591
|
+
});
|
|
592
|
+
it("keeps an explicit zero volume", async () => {
|
|
593
|
+
const { upload } = await buildWith({ buildVolumeMb: 0 });
|
|
594
|
+
expect(upload.headers["x-amz-meta-x-blaxel-build-volume"]).toBe("0");
|
|
595
|
+
expect(upload.headers["x-amz-meta-x-blaxel-build-memory"]).toBeUndefined();
|
|
596
|
+
});
|
|
597
|
+
it("sends no build headers by default", async () => {
|
|
598
|
+
const { upload } = await buildWith({});
|
|
599
|
+
expect(Object.keys(upload.headers).filter((name) => name.startsWith("x-amz-meta-"))).toEqual([]);
|
|
600
|
+
});
|
|
601
|
+
it("mirrors build labels the control plane already stored", async () => {
|
|
602
|
+
const { upload } = await buildWith({}, { "x-blaxel-auto-generated": "true", "x-blaxel-build-memory": "8192" });
|
|
603
|
+
expect(upload.headers["x-amz-meta-x-blaxel-build-memory"]).toBe("8192");
|
|
604
|
+
});
|
|
605
|
+
it.each([
|
|
606
|
+
[{ buildMemoryMb: 0 }, "buildMemoryMb"],
|
|
607
|
+
[{ buildMemoryMb: 32769 }, "buildMemoryMb"],
|
|
608
|
+
[{ buildMemoryMb: 1.5 }, "buildMemoryMb"],
|
|
609
|
+
[{ buildVolumeMb: -1 }, "buildVolumeMb"],
|
|
610
|
+
[{ buildVolumeMb: 131073 }, "buildVolumeMb"],
|
|
611
|
+
])("rejects out-of-range %o before any request", async (options, option) => {
|
|
612
|
+
const fetchSpy = vi.fn();
|
|
613
|
+
vi.stubGlobal("fetch", fetchSpy);
|
|
614
|
+
await expect(ImageInstance.fromRegistry("alpine:3.20").build({ name: "img", ...options })).rejects.toThrow(option);
|
|
615
|
+
expect(fetchSpy).not.toHaveBeenCalled();
|
|
616
|
+
});
|
|
617
|
+
});
|