Skip to content
Merged
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
14 changes: 14 additions & 0 deletions apps/web/src/features/sandbox/deployment-specification.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { defaultSandboxResources, distributionRuntime, savedSpecification, validSandboxResources } from "./deployment-specification";
import { isRuntimeReleaseField } from "./runtime-release";
import standardSizes from "./standard-sizes.json";
import type { SandboxSpecification } from "@agents-core-web/agents-client";

Expand Down Expand Up @@ -48,6 +49,19 @@ describe("deployment resources and Runtime", () => {
expect(validSandboxResources("e2b", { cpus: 2, memory_mib: 2048, root_disk_mib: 1024 })).toBe(false);
expect(validSandboxResources("microsandbox", { cpus: 2, memory_mib: 2048, root_disk_mib: 1023, environment_disk_mib: 8192 })).toBe(false);
});
it("accepts any well-formed Runtime image name in the Runtime reference", async () => {
const digest = "b".repeat(64);
for (const runtime_ref of [`parsar-core-runtime@sha256:${digest}`, `oac-runtime@sha256:${digest}`]) {
vi.stubGlobal("fetch", vi.fn().mockResolvedValue(new Response(JSON.stringify({ ...manifest, runtime_ref }))));
expect((await distributionRuntime(new AbortController().signal)).microsandbox_ref).toBe(runtime_ref);
expect(isRuntimeReleaseField("microsandbox_ref", runtime_ref)).toBe(true);
}
for (const runtime_ref of [`oac-runtime:${digest}`, `oac-runtime@sha256:${"b".repeat(63)}`, `oac-runtime@sha256:${"B".repeat(64)}`, `@sha256:${digest}`]) {
vi.stubGlobal("fetch", vi.fn().mockResolvedValue(new Response(JSON.stringify({ ...manifest, runtime_ref }))));
await expect(distributionRuntime(new AbortController().signal)).rejects.toThrow();
expect(isRuntimeReleaseField("microsandbox_ref", runtime_ref)).toBe(false);
}
});
it("rejects unavailable, mutable or incomplete release identities", async () => {
vi.stubGlobal("fetch", vi.fn().mockResolvedValue(new Response("{}", { status: 404 })));
await expect(distributionRuntime(new AbortController().signal)).rejects.toThrow();
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/features/sandbox/deployment-specification.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { SandboxDeployment, SandboxE2BTemplateBuild, SandboxProvider, SandboxResources, SandboxRuntimeRelease, SandboxSpecification } from "@agents-core-web/agents-client";
import { RUNTIME_REF_PATTERN } from "./runtime-release";
import standardSizes from "./standard-sizes.json";

interface Manifest {
Expand Down Expand Up @@ -53,7 +54,7 @@ export async function distributionRuntime(signal: AbortSignal): Promise<SandboxR
const image = /^sha256:[a-f0-9]{64}$/;
if (manifest.platform !== "linux/amd64" || !/^[a-f0-9]{40}$/.test(manifest.source_commit ?? "")
|| !image.test(manifest.images?.runtime ?? "") || !image.test(manifest.image_manifest_digests?.runtime ?? "")
|| !/^parsar-core-runtime@sha256:[a-f0-9]{64}$/.test(manifest.runtime_ref ?? "")
|| !RUNTIME_REF_PATTERN.test(manifest.runtime_ref ?? "")
|| !hash.test(manifest.microsandbox?.runtime_sha256 ?? "") || !hash.test(manifest.microsandbox?.firmware_sha256 ?? "")) throw new Error("invalid distribution");
return { source_commit: manifest.source_commit!, image_id: manifest.images!.runtime!, image_manifest_digest: manifest.image_manifest_digests!.runtime!,
microsandbox_ref: manifest.runtime_ref!, runtime_sha256: manifest.microsandbox!.runtime_sha256!, firmware_sha256: manifest.microsandbox!.firmware_sha256! };
Expand Down
5 changes: 4 additions & 1 deletion apps/web/src/features/sandbox/runtime-release.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import type { SandboxRuntimeRelease } from "@agents-core-web/agents-client";

/** Core owns the Runtime image name, so the Web checks only the `<name>@sha256:<digest>` shape. */
export const RUNTIME_REF_PATTERN = /^[a-z0-9][a-z0-9._-]*@sha256:[0-9a-f]{64}$/;

const patterns: Record<keyof SandboxRuntimeRelease, RegExp> = {
source_commit: /^[0-9a-f]{40}$/,
image_id: /^sha256:[0-9a-f]{64}$/,
image_manifest_digest: /^sha256:[0-9a-f]{64}$/,
microsandbox_ref: /^parsar-core-runtime@sha256:[0-9a-f]{64}$/,
microsandbox_ref: RUNTIME_REF_PATTERN,
runtime_sha256: /^[0-9a-f]{64}$/,
firmware_sha256: /^[0-9a-f]{64}$/,
};
Expand Down