diff --git a/README.md b/README.md index 18605dc28..31c7f8b58 100644 --- a/README.md +++ b/README.md @@ -235,9 +235,8 @@ How each command uses it: with that instruction when `box` is not on your PATH. Container agents need no local box. Each box runtime names its release in `agentcore.json` with `"box": { "version": "" }`, -which `agentcore create` writes. The pinned version keeps the checksums in `boxRelease.json`; -another version takes them from its release's `SHA256SUMS.txt`. To try an unreleased box build, -publish it as a pre-release with the same file names and set `box.version` to it. +which `agentcore create` writes. It must be the pinned version, whose checksums `boxRelease.json` +keeps; build, deploy and container `dev` stop on any other version and say to set the pinned one. On AgentCore Runtime, box signs the agent's Bedrock and Memory calls with the execution role: the profile's bare `aws://` resolves the AWS default credential chain, which box reads and refreshes diff --git a/docs/box-local-testing.md b/docs/box-local-testing.md index 7c657034a..374a0312c 100644 --- a/docs/box-local-testing.md +++ b/docs/box-local-testing.md @@ -32,9 +32,10 @@ only for the box templates. The runtime's entry point and Dockerfile never decid `start.py` runs the usual way. A runtime with `box.version` in a project without `"projectType": "box"` stops dev with `agentcore.json has no "projectType": "box"`. -To try an unreleased box build, publish it as a pre-release with the same file names and set -`box.version` to it: a version the CLI does not pin takes its checksums from the release's -`SHA256SUMS.txt`. +`box.version` must be the box version the CLI pins in +`src/core/project/backends/boxRelease.json`; build, deploy and container `dev` stop on any other version. To try an +unreleased box build, publish it as a pre-release with the same file names and run +`bun scripts/bump-box-release.ts --box ` in your CLI checkout, then set `box.version` to it. ## Prerequisites diff --git a/src/core/dev/boxDevSecrets.test.ts b/src/core/dev/boxDevSecrets.test.ts index d0005152c..c2c29c9fa 100644 --- a/src/core/dev/boxDevSecrets.test.ts +++ b/src/core/dev/boxDevSecrets.test.ts @@ -48,7 +48,7 @@ describe("boxDevSecrets", () => { test("leaves out a pack's variable, a secret that is not env://, and a blank name", () => { const profile = - 'packs = ["box/bedrock"]\n[egress.s3]\ndestinations = ["s3.amazonaws.com"]\nsecret.ref = "aws://default"\n' + + 'packs = ["@box/bedrock"]\n[egress.s3]\ndestinations = ["s3.amazonaws.com"]\nsecret.ref = "aws://default"\n' + '[egress.blank]\ndestinations = ["blank.example.com"]\nsecret.ref = "env:// "\n'; expect(fromShell(profile, { AWS_BEARER_TOKEN_BEDROCK: "token", default: "x" })).toEqual({ env: {}, diff --git a/src/core/dev/boxDevSecrets.ts b/src/core/dev/boxDevSecrets.ts index ad9b3f86a..46c98d23d 100644 --- a/src/core/dev/boxDevSecrets.ts +++ b/src/core/dev/boxDevSecrets.ts @@ -25,7 +25,7 @@ export type BoxDevSecrets = { * ({@link BoxKeySources}): the shell's when it is set and not blank, else `.env.local`'s. On * Windows, where variable names are case-insensitive, the shell's `Github_Token` sets * `GITHUB_TOKEN`. Dev hands these to `box run` as they are and writes none of them anywhere. Only - * the profile's own tables count: a pack's variable, such as box/bedrock's + * the profile's own tables count: a pack's variable, such as @box/bedrock's * `AWS_BEARER_TOKEN_BEDROCK`, is not the profile author's to pass. A profile that does not parse * has none here; `box run` reports it. */ diff --git a/src/core/dev/container.ts b/src/core/dev/container.ts index 31c36bb6a..bb386e78f 100644 --- a/src/core/dev/container.ts +++ b/src/core/dev/container.ts @@ -137,7 +137,7 @@ export class ContainerDevRunner implements DevRunner { this.toolAvailable = config.toolAvailable ?? toolAvailable; this.awsDirectory = config.awsDirectory ?? join(homedir(), ".aws"); this.processEnv = config.processEnv ?? process.env; - this.releaseFor = config.releaseFor ?? ((version) => boxReleaseFor(version, this.processEnv)); + this.releaseFor = config.releaseFor ?? boxReleaseFor; this.resolveAwsCredentials = config.resolveAwsCredentials ?? resolveDefaultAwsCredentials; this.platform = config.platform ?? process.platform; } diff --git a/src/core/project/backends/boxRelease.test.ts b/src/core/project/backends/boxRelease.test.ts index ace180ea3..913be4240 100644 --- a/src/core/project/backends/boxRelease.test.ts +++ b/src/core/project/backends/boxRelease.test.ts @@ -7,7 +7,6 @@ import { tmpdir } from "node:os"; import { join } from "node:path"; import { InvalidEnvironmentError } from "../../../errors/errors"; import { type ProcessRunner, runProcess } from "../../../io/exec"; -import { gte } from "semver"; import { BOX_INSTALL_HINT, BOX_MINIMUM_VERSION, @@ -211,54 +210,23 @@ describe("resolveBoxLinuxBuild from the box release", () => { }); describe("boxReleaseFor a runtime's box.version", () => { - /** A runner whose curl serves SHA256SUMS.txt with `text`, and records each URL. */ - function sumsServer(text: string) { - const urls: string[] = []; - const runner: ProcessRunner = async (command) => { - urls.push(command.at(-1)!); - await writeFile(command[command.indexOf("-o") + 1]!, text); - }; - return { runner, urls }; - } - - test("is the pinned release, with no download, for no version or a pinned one", async () => { - const { runner, urls } = sumsServer(""); - - expect(await boxReleaseFor(undefined, {}, { runner })).toBe(BOX_RELEASE); - expect(await boxReleaseFor(BOX_RELEASE.version, {}, { runner })).toBe(BOX_RELEASE); - expect(urls).toEqual([]); - }); - - test("takes another version's checksums from its release's SHA256SUMS.txt", async () => { - const home = await temp("box-home-"); - const linux = "a".repeat(64); - const mac = "c".repeat(64); - const { runner, urls } = sumsServer( - `${linux} box-v2.0.0-aarch64-unknown-linux-gnu.tar.gz\n` + - `${mac} box-v2.0.0-aarch64-apple-darwin.tar.gz\n`, - ); - - const release = await boxReleaseFor("2.0.0", {}, { runner, home }); - - expect(urls).toEqual([ - `https://github.com/${BOX_RELEASE.repo}/releases/download/v2.0.0/SHA256SUMS.txt`, - ]); - expect(release.version).toBe("2.0.0"); - expect(release.linux).toEqual({ - target: "aarch64-unknown-linux-gnu", - asset: "box-v2.0.0-aarch64-unknown-linux-gnu.tar.gz", - sha256: linux, - }); + test("is the pinned release for no version or the pinned one", async () => { + expect(await boxReleaseFor(undefined)).toBe(BOX_RELEASE); + expect(await boxReleaseFor(BOX_RELEASE.version)).toBe(BOX_RELEASE); }); - test("refuses a version whose release lists no Linux box", async () => { - const home = await temp("box-home-"); - const { runner } = sumsServer(`${"c".repeat(64)} box-v2.0.0-aarch64-apple-darwin.tar.gz\n`); - - await expect(boxReleaseFor("2.0.0", {}, { runner, home })).rejects.toThrow( - /box 2\.0\.0, which agentcore\.json names under box\.version, has no box-v2\.0\.0-aarch64-unknown-linux-gnu\.tar\.gz/, - ); - }); + test.each(["0.1.11-linux-preview.6", "2.0.0"])( + "refuses %s, a box this CLI does not pin, and says to set the pinned one", + async (version) => { + await expect(boxReleaseFor(version)).rejects.toThrow( + new InvalidEnvironmentError( + `agentcore.json names box ${version} under box.version, but this CLI ships box ` + + `${BOX_RELEASE.version}, the one box it pins. Set box.version to ` + + `${BOX_RELEASE.version}, then retry.`, + ), + ); + }, + ); }); describe("publishInstall", () => { @@ -306,9 +274,8 @@ describe("publishInstall", () => { }); describe("the pinned releases", () => { - test("box is at least the first release that reads the profiles the CLI writes", () => { + test("pins one box, with the asset of its own version and a SHA-256", () => { expect(BOX_MINIMUM_VERSION).toBe("0.1.11-linux-preview.7"); - expect(gte(BOX_RELEASE.version, BOX_MINIMUM_VERSION)).toBe(true); expect(BOX_RELEASE.linux.asset).toBe( `box-v${BOX_RELEASE.version}-aarch64-unknown-linux-gnu.tar.gz`, ); diff --git a/src/core/project/backends/boxRelease.ts b/src/core/project/backends/boxRelease.ts index b4e5c73e7..45eda76d9 100644 --- a/src/core/project/backends/boxRelease.ts +++ b/src/core/project/backends/boxRelease.ts @@ -291,59 +291,16 @@ async function download( } /** - * The box release of `version`, which a runtime's `box.version` names: the pinned one, else one - * in BOX_RELEASE's repository, in its layout, whose checksums come from the release's own - * SHA256SUMS.txt. No version means BOX_RELEASE. + * The box release that `version`, a runtime's `box.version`, names. It must be the pinned one, + * BOX_RELEASE, whose checksums `boxRelease.json` pins: another box is untested with this CLI (box + * 0.1.11-linux-preview.6, for one, refuses the `@box/` packs the CLI writes), and build cannot + * see that, since it checks the profile with the box on PATH. No version means BOX_RELEASE. */ -export async function boxReleaseFor( - version: string | undefined, - env: NodeJS.ProcessEnv, - options: { runner?: ProcessRunner; home?: string } = {}, -): Promise { +export async function boxReleaseFor(version: string | undefined): Promise { if (version === undefined || version === BOX_RELEASE.version) return BOX_RELEASE; - const target = BOX_RELEASE.linux.target; - const linux = `box-v${version}-${target}.tar.gz`; - const release = { repo: BOX_RELEASE.repo, version }; - const sums = await releaseChecksums(release, env, options.runner ?? runProcess, options.home); - const linuxSha = sums.get(linux); - if (!linuxSha) { - throw new InvalidEnvironmentError( - `box ${version}, which agentcore.json names under box.version, has no ${linux} in the ` + - `SHA256SUMS.txt of its release at github.com/${release.repo}. Name a box version that ` + - `release has, or remove box.version to use box ${BOX_RELEASE.version}.`, - ); - } - return { ...release, linux: { target, asset: linux, sha256: linuxSha } }; -} - -/** The SHA-256 of each asset of `release`, from the SHA256SUMS.txt it publishes. */ -async function releaseChecksums( - release: Pick, - env: NodeJS.ProcessEnv, - runner: ProcessRunner, - home: string | undefined, -): Promise> { - const cache = boxCache(home ?? env.HOME ?? homedir()); - mkdirSync(cache, { recursive: true }); - const work = mkdtempSync(join(cache, ".download-")); - try { - await download( - release, - "SHA256SUMS.txt", - work, - env, - runner, - (url) => - `agentcore.json names box ${release.version} under box.version, whose checksums ` + - `download from ${url}, which failed. Check the version and your network, then retry.`, - ); - const sums = new Map(); - for (const line of readFileSync(join(work, "SHA256SUMS.txt"), "utf8").split("\n")) { - const match = /^([0-9a-f]{64})\s+\*?(\S+)$/.exec(line.trim()); - if (match) sums.set(match[2]!, match[1]!); - } - return sums; - } finally { - rmSync(work, { recursive: true, force: true }); - } + throw new InvalidEnvironmentError( + `agentcore.json names box ${version} under box.version, but this CLI ships box ` + + `${BOX_RELEASE.version}, the one box it pins. Set box.version to ${BOX_RELEASE.version}, ` + + "then retry.", + ); } diff --git a/src/core/project/backends/cdk.ts b/src/core/project/backends/cdk.ts index 1dfce38a1..e94b9b565 100644 --- a/src/core/project/backends/cdk.ts +++ b/src/core/project/backends/cdk.ts @@ -243,7 +243,7 @@ export class CdkBackend implements ProjectBackend { // the code. The box release downloads only when a CodeZip runtime runs in a box. const events: ProjectEvent[] = []; const box = async (version: string | undefined) => { - const release = await boxReleaseFor(version, this.processEnv, { runner: this.runner }); + const release = await boxReleaseFor(version); return resolveBoxLinuxBuild(this.processEnv, { runner: this.runner, release, @@ -255,9 +255,7 @@ export class CdkBackend implements ProjectBackend { }); }; await stageBoxCodeZip(project, boxNetworks, box); - await stageBoxContainers(project, boxNetworks, (version) => - boxReleaseFor(version, this.processEnv, { runner: this.runner }), - ); + await stageBoxContainers(project, boxNetworks, boxReleaseFor); return events; } diff --git a/src/core/project/boxNetworkSource.test.ts b/src/core/project/boxNetworkSource.test.ts index 07d4e13a5..85151893e 100644 --- a/src/core/project/boxNetworkSource.test.ts +++ b/src/core/project/boxNetworkSource.test.ts @@ -111,41 +111,6 @@ describe("readBoxNetworks", () => { expect(network?.runtimeProfile?.project).toEqual({ access: "read" }); }); - test("stops before box runs when the profile names a pack or a plugin that box ships by its old box/ name", async () => { - const root = await project([]); - await writeFile( - join(root, ...LOCAL, "profile.toml"), - 'packs = ["box/base", "box/bedrock", "@box/node", "team-pack", "box/base"]\n' + - 'plugins = ["box/aws-secrets-manager"]\n', - ); - const box = new FakeBoxProfileResolver(); - - const stopped = readBoxNetworks(SPEC, root, box); - - await expect(stopped).rejects.toBeInstanceOf(ProjectStateError); - await expect(stopped).rejects.toThrow( - 'The box profile .box/agent/local/profile.toml names "box/base", "box/bedrock", ' + - '"box/aws-secrets-manager". Box now names each pack and plugin that it ships ' + - '"@box/", and it refuses the old "box/" name. In ' + - '.box/agent/local/profile.toml, change "box/base" to "@box/base", "box/bedrock" to ' + - '"@box/bedrock", "box/aws-secrets-manager" to "@box/aws-secrets-manager", then build again.', - ); - expect(box.calls).toEqual([]); - }); - - test("runs box for a profile with only @box/ names and names of its own", async () => { - const root = await project([]); - await writeFile( - join(root, ...LOCAL, "profile.toml"), - 'packs = ["@box/base", "@box/bedrock", "team-pack"]\nplugins = ["@box/aws-secrets-manager"]\n', - ); - const box = new FakeBoxProfileResolver(); - - await readBoxNetworks(SPEC, root, box); - - expect(box.calls).toHaveLength(1); - }); - test("finds each runtime's Box gateway by boundRuntime, whatever its name", async () => { const root = await project([]); const spec = { diff --git a/src/core/project/boxNetworkSource.ts b/src/core/project/boxNetworkSource.ts index d16c8cbe0..0b18cb0c2 100644 --- a/src/core/project/boxNetworkSource.ts +++ b/src/core/project/boxNetworkSource.ts @@ -200,7 +200,6 @@ async function readResolvedPolicy( const profileFile = boxLocalProfileFile(agentName); const text = profileText(projectRoot, agentName); if (text === undefined) return { parsed: noPolicy(profileFile), failures: [] }; - refuseOldShippedNames(text, profileFile); const named = profilePolicyFiles(text, profileFile); const places = profilePlaces(text, profileFile); const files = readPolicyFiles( @@ -251,39 +250,6 @@ function profileSource(text: string, profileFile: string): ParsedProfileSource | type ParsedProfileSource = NonNullable; -/** The old name of a pack or a plugin that box ships, before box named them `@box/`. */ -const OLD_SHIPPED_NAME = /^box\/[^/]+$/; - -/** - * Throws when the `packs` or `plugins` of the box profile `text` at `profileFile` name a pack or a - * plugin that box ships by its old `box/` name, which box refuses. The message names each old - * name and its `@box/` name. Build does not change the profile. Box reports a profile that is - * not TOML itself. - */ -function refuseOldShippedNames(text: string, profileFile: string): void { - let table: Record; - try { - table = parseToml(text) as Record; - } catch { - return; - } - const names = [table.packs, table.plugins].flatMap((list) => (Array.isArray(list) ? list : [])); - const old = [ - ...new Set( - names.filter( - (name): name is string => typeof name === "string" && OLD_SHIPPED_NAME.test(name), - ), - ), - ]; - if (old.length === 0) return; - const changes = old.map((name) => `"${name}" to "@${name}"`); - throw new ProjectStateError( - `The box profile ${profileFile} names ${old.map((name) => `"${name}"`).join(", ")}. Box now ` + - 'names each pack and plugin that it ships "@box/", and it refuses the old "box/" ' + - `name. In ${profileFile}, change ${changes.join(", ")}, then build again.`, - ); -} - /** The text of the local box profile of `agentName`, or `undefined` when the agent has none. */ function profileText(projectRoot: string, agentName: string): string | undefined { const path = boxLocalProfilePath(projectRoot, agentName);