Files
wehub-resource-sync cb15c5e0d8
CI / Rust (windows-latest - x86_64-pc-windows-msvc) (push) Waiting to run
CI / Native E2E Tests (push) Blocked by required conditions
CI / Windows Integration Test (push) Blocked by required conditions
CI / Version Sync Check (push) Waiting to run
CI / Rust (push) Waiting to run
CI / Dashboard (push) Waiting to run
CI / Sandbox Package (push) Waiting to run
CI / Rust (macos-latest - aarch64-apple-darwin) (push) Waiting to run
CI / Rust (macos-latest - x86_64-apple-darwin) (push) Waiting to run
CI / Global Install (macos-latest) (push) Blocked by required conditions
CI / Global Install (ubuntu-latest) (push) Blocked by required conditions
CI / Global Install (windows-latest) (push) Blocked by required conditions
Release / Check for new version (push) Has been cancelled
Release / Build macOS ARM64 (push) Has been cancelled
Release / Build macOS x64 (push) Has been cancelled
Release / Build Linux ARM64 (push) Has been cancelled
Release / Build Linux musl ARM64 (push) Has been cancelled
Release / Build Linux musl x64 (push) Has been cancelled
Release / Build Linux x64 (push) Has been cancelled
Release / Build Windows x64 (push) Has been cancelled
Release / Publish to npm (push) Has been cancelled
Release / Publish sandbox package to npm (push) Has been cancelled
Release / Create GitHub Release (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:35:58 +08:00

71 lines
2.2 KiB
JavaScript

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
import {
AGENT_BROWSER_SANDBOX_VERSION,
DEFAULT_AGENT_BROWSER_INSTALL_SPEC,
buildAgentBrowserArgv,
buildShellCommand,
defaultSessionName,
quoteShellArg,
resolveAgentBrowserInstallSpec,
} from "../dist/index.js";
test("defaults install spec to the package version", () => {
const packageJson = JSON.parse(
readFileSync(new URL("../package.json", import.meta.url), "utf-8"),
);
const expectedInstallSpec = `agent-browser@${packageJson.version}`;
assert.equal(AGENT_BROWSER_SANDBOX_VERSION, packageJson.version);
assert.equal(DEFAULT_AGENT_BROWSER_INSTALL_SPEC, expectedInstallSpec);
assert.equal(resolveAgentBrowserInstallSpec(), expectedInstallSpec);
assert.equal(resolveAgentBrowserInstallSpec({ installSpec: "latest" }), "latest");
});
test("builds argv with session and json by default", () => {
assert.deepEqual(buildAgentBrowserArgv(["open", "https://example.com"], { session: "s1" }), [
"--session",
"s1",
"open",
"https://example.com",
"--json",
]);
assert.deepEqual(buildAgentBrowserArgv(["snapshot", "--json"], { session: "s1" }), [
"--session",
"s1",
"snapshot",
"--json",
]);
});
test("quotes shell args and builds commands", () => {
assert.equal(quoteShellArg("simple"), "simple");
assert.equal(quoteShellArg("hello world"), "'hello world'");
assert.equal(quoteShellArg("can't"), "'can'\\''t'");
assert.equal(
buildShellCommand(["open", "https://example.com/a b"], {
env: { AGENT_BROWSER_HOME: "/tmp/agent browser" },
session: "s1",
}),
"AGENT_BROWSER_HOME='/tmp/agent browser' agent-browser --session s1 open 'https://example.com/a b' --json",
);
});
test("sanitizes default session names", () => {
assert.equal(defaultSessionName("eve", "sandbox/id 1"), "eve-sandbox-id-1");
});
test("keeps generated default session names short", () => {
const session = defaultSessionName(
"eve",
"eve-sbx-ses-vercel-1d940340bdba4563-wrun_01KVKDK1Z3GC3XEC86DGWRWRMH-__root__",
);
assert.equal(session.length <= 48, true);
assert.match(session, /^eve-eve-sbx-ses-vercel-.+-[a-f0-9]{8}$/);
});