From 1661e238bf510b67bc2a96619653f04788f58ece Mon Sep 17 00:00:00 2001 From: Varun Gunda Date: Thu, 19 Nov 2026 13:51:13 -0800 Subject: [PATCH 1/7] fix(box): refuse build-owned target names on a Box gateway add gateway-target (CLI and TUI) and add gateway-connector now refuse the names 'bedrock', 'agentcore' and 'egress-*' on a Box gateway. Build writes targets with these names. A user target with one of these names took the agent's Bedrock or Memory route, or build changed or removed it. The check is in ProjectManager.addResource, which both paths use. The same names stay valid on a gateway that is not a Box gateway, and the targets that build writes stay valid in agentcore.json. --- src/core/project/boxNetwork/index.ts | 1 + src/core/project/boxNetwork/network.ts | 30 +++++++- src/core/project/manager.tsx | 12 ++- .../gateway-target.screen.test.tsx | 19 +++++ .../project/add/gateway-target/index.test.ts | 76 ++++++++++++++++++- 5 files changed, 135 insertions(+), 3 deletions(-) diff --git a/src/core/project/boxNetwork/index.ts b/src/core/project/boxNetwork/index.ts index af6e1596c..0f8c07dad 100644 --- a/src/core/project/boxNetwork/index.ts +++ b/src/core/project/boxNetwork/index.ts @@ -4,6 +4,7 @@ export { boxGatewayOf, buildBoxNetwork, isManagedTarget, + reservedBoxTargetNameProblem, type BoxEgressAuth, type BoxHostSource, type BoxNetwork, diff --git a/src/core/project/boxNetwork/network.ts b/src/core/project/boxNetwork/network.ts index 63504209f..2d83772b2 100644 --- a/src/core/project/boxNetwork/network.ts +++ b/src/core/project/boxNetwork/network.ts @@ -4,7 +4,11 @@ * the policy files to stage, and every warning and failure. Build, deploy, and staging write from * it. */ -import { boxGatewayAgentCoreHost } from "../../../handlers/project/shortcuts"; +import { + BOX_GATEWAY_AGENTCORE_TARGET_NAME, + BOX_GATEWAY_BEDROCK_TARGET_NAME, + boxGatewayAgentCoreHost, +} from "../../../handlers/project/shortcuts"; import type { AgentCoreGateway, AgentCoreGatewayTarget } from "../../../projectSchemas/gateway"; import type { ProjectSpec } from "../../../projectSchemas/project"; import type { ProjectRuntime } from "../../../projectSchemas/runtime"; @@ -226,6 +230,30 @@ export function isManagedTarget(target: Pick): b return target.name.startsWith(BOX_EGRESS_TARGET_PREFIX); } +/** The names of the Box gateway targets that build writes for the agent's model and Memory calls. */ +const BOX_DEFAULT_TARGET_NAMES: readonly string[] = [ + BOX_GATEWAY_BEDROCK_TARGET_NAME, + BOX_GATEWAY_AGENTCORE_TARGET_NAME, +]; + +/** + * The refusal of a user target named `name` on a Box gateway, or `undefined` when build does not + * own the name. Build writes the `bedrock` and `agentcore` targets and every `egress-` target, so a + * user target of such a name would take the agent's Bedrock or Memory route, or build would + * rewrite or remove it. + */ +export function reservedBoxTargetNameProblem(name: string, gateway: string): string | undefined { + if (!BOX_DEFAULT_TARGET_NAMES.includes(name) && !isManagedTarget({ name })) return undefined; + const reserved = [ + ...BOX_DEFAULT_TARGET_NAMES.map((n) => `'${n}'`), + `'${BOX_EGRESS_TARGET_PREFIX}*'`, + ]; + return ( + `the gateway target name '${name}' is reserved on Box gateway '${gateway}': build writes the ` + + `targets ${reserved.join(", ")} for the agent's model, Memory, and egress calls. Choose another name.` + ); +} + /** The host map key of a passthrough target's endpoint, or `undefined` for another target. */ function endpointKey(target: AgentCoreGatewayTarget): string | undefined { const at = target.passthrough && parseEndpoint(target.passthrough.endpoint); diff --git a/src/core/project/manager.tsx b/src/core/project/manager.tsx index c3f66e453..33b2c80e0 100644 --- a/src/core/project/manager.tsx +++ b/src/core/project/manager.tsx @@ -54,7 +54,7 @@ import { harnessApiKeyCredentialName, validateHarnessTemplateSource, } from "./templates/harness"; -import { boxGatewayIamWarnings, type BoxNetwork } from "./boxNetwork"; +import { boxGatewayIamWarnings, reservedBoxTargetNameProblem, type BoxNetwork } from "./boxNetwork"; import { boxNetworkFailureMessage, readBoxNetworks } from "./boxNetworkSource"; import { DEFAULT_REGION, regionFromConfigFile } from "../region"; import { BoxCliProfileResolver, type BoxProfileResolver } from "./boxProfileResolver"; @@ -651,6 +651,16 @@ export class FsProjectManager implements ProjectManager { `a gateway target with name '${input.resourceConfig.name}' already exists in gateway '${gateway.name}'`, ); } + // Build owns some target names on a Box gateway. A user target of such a name would take + // the agent's Bedrock or Memory route, or build would rewrite or remove it. + const parent = projectSpec.agentCoreGateways.find( + (candidate) => candidate.name === input.gatewayName, + ); + const reserved = + parent && isBoundGateway(parent) + ? reservedBoxTargetNameProblem(input.resourceConfig.name, parent.name) + : undefined; + if (reserved) throw new InputValidationError(reserved); } else if (input.resourceType === "policy") { // Policy names are account-unique on the service, so the check spans engines. const engine = projectSpec.policyEngines.find((candidate) => diff --git a/src/handlers/project/add/gateway-target/gateway-target.screen.test.tsx b/src/handlers/project/add/gateway-target/gateway-target.screen.test.tsx index 215a37205..2618d2d84 100644 --- a/src/handlers/project/add/gateway-target/gateway-target.screen.test.tsx +++ b/src/handlers/project/add/gateway-target/gateway-target.screen.test.tsx @@ -461,6 +461,25 @@ describe("project add gateway-target wizard", () => { screen.unmount(); }, 15000); + test("refuses a target name build owns on the Box gateway", async () => { + const projectRoot = await inProject(); + const spec = await projectSpec(projectRoot); + const box = boxGatewaySpec(spec.runtimes[0].name); + await writeProjectSpec(projectRoot, { ...spec, projectType: "box", agentCoreGateways: [box] }); + const screen = renderScreen("/agentcore/add/gateway-target"); + await reachAuthStep(screen, "bedrock"); + await screen.press("return"); + await waitForText(screen.lastFrame, "this Target will be added to agentcore.json"); + await screen.press("return"); + + await waitForFlatText( + screen.lastFrame, + `the gateway target name 'bedrock' is reserved on Box gateway '${box.name}'`, + ); + expect(await targetsOf(projectRoot, box.name)).toEqual([]); + screen.unmount(); + }, 15000); + test("esc on the first step returns to the add menu", async () => { await inProject(); await addGateway(); diff --git a/src/handlers/project/add/gateway-target/index.test.ts b/src/handlers/project/add/gateway-target/index.test.ts index 2df0d71a1..6d97366e7 100644 --- a/src/handlers/project/add/gateway-target/index.test.ts +++ b/src/handlers/project/add/gateway-target/index.test.ts @@ -4,7 +4,11 @@ import { join } from "node:path"; import { InputValidationError, ProjectStateError, ResourceNotFoundError } from "../../../../errors"; import { expectError } from "../../../../testing"; import { createGatewayProjectTestHarness } from "../gateway-test-support"; -import { boxGatewaySpec } from "../../../../projectSchemas/project"; +import { boxGatewaySpec, ProjectSpecSchema } from "../../../../projectSchemas/project"; +import { + getBoxGatewayAgentCoreTargetSpec, + getBoxGatewayBedrockTargetSpec, +} from "../../../project/shortcuts"; const DISCOVERY_URL = "https://idp.example.com/.well-known/openid-configuration"; const ENDPOINT = "https://mcp.example.com"; @@ -75,6 +79,76 @@ describe("project add gateway-target", () => { expect(JSON.parse(asJson.stdout()).notes).toEqual([note]); }); + test("refuses the target names build owns on a Box gateway, and only there", async () => { + const projectRoot = await inProject(); + const spec = await projectSpec(projectRoot); + const box = boxGatewaySpec(spec.runtimes[0].name); + await writeProjectSpec(projectRoot, { ...spec, projectType: "box", agentCoreGateways: [box] }); + await addGateway(); + + for (const name of ["bedrock", "agentcore", "egress-api-example-com"]) { + await expectError( + run([ + "add", + "gateway-target", + ...["--gateway", box.name, "--name", name, "--endpoint", ENDPOINT], + ...["--outbound-auth", "none"], + ]), + `the gateway target name '${name}' is reserved on Box gateway '${box.name}': build ` + + `writes the targets 'bedrock', 'agentcore', 'egress-*' for the agent's model, Memory, ` + + `and egress calls. Choose another name.`, + InputValidationError, + ); + // The same name is the user's on a gateway that is not a Box gateway. + await run([ + "add", + "gateway-target", + ...["--gateway", "tools", "--name", name, "--endpoint", ENDPOINT], + ...["--outbound-auth", "none"], + ]); + } + + const gateways = (await projectSpec(projectRoot)).agentCoreGateways; + expect(gateways.find((gateway: { name: string }) => gateway.name === box.name).targets).toEqual( + [], + ); + expect( + gateways + .find((gateway: { name: string }) => gateway.name === "tools") + .targets.map((target: { name: string }) => target.name), + ).toEqual(["bedrock", "agentcore", "egress-api-example-com"]); + }); + + test("keeps the targets build writes on a Box gateway valid", async () => { + const projectRoot = await inProject(); + const spec = await projectSpec(projectRoot); + const egress = { + name: "egress-api-example-com", + targetType: "passthrough", + passthrough: { endpoint: "https://api.example.com", protocolType: "CUSTOM" }, + }; + const box = { + ...boxGatewaySpec(spec.runtimes[0].name), + targets: [getBoxGatewayBedrockTargetSpec(), getBoxGatewayAgentCoreTargetSpec(), egress], + }; + const written = { ...spec, projectType: "box", agentCoreGateways: [box] }; + expect(ProjectSpecSchema.safeParse(written).success).toBe(true); + await writeProjectSpec(projectRoot, written); + + await run([ + "add", + "gateway-target", + ...["--gateway", box.name, "--name", "search", "--endpoint", ENDPOINT], + ...["--outbound-auth", "none"], + ]); + + expect( + (await projectSpec(projectRoot)).agentCoreGateways[0].targets.map( + (target: { name: string }) => target.name, + ), + ).toEqual(["bedrock", "agentcore", "egress-api-example-com", "search"]); + }); + test("adds endpoint and project Runtime shortcuts", async () => { const projectRoot = await inProject(); await addGateway(); From e6376c925e4a8cdbc351ada1e9283b614cd128b2 Mon Sep 17 00:00:00 2001 From: Varun Gunda Date: Fri, 20 Nov 2026 17:23:12 -0800 Subject: [PATCH 2/7] refactor(box): move the reserved Box target name check to boxMemory The check now tests the egress- prefix with a plain startsWith, so it does not depend on the signature of isManagedTarget. boxMemory already owns the bedrock and agentcore names and imports isBoundGateway. The import of BOX_EGRESS_TARGET_PREFIX from boxNetwork/egress makes no runtime import cycle. The comment now gives only the reason that stays true: a user target of such a name takes the agent's Bedrock or Memory route, or the name of an egress target that build writes. --- src/core/project/boxMemory.ts | 28 ++++++++++++++++++++++++++ src/core/project/boxNetwork/index.ts | 1 - src/core/project/boxNetwork/network.ts | 26 ------------------------ src/core/project/manager.tsx | 3 ++- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/core/project/boxMemory.ts b/src/core/project/boxMemory.ts index fe0533d70..ce1af4f32 100644 --- a/src/core/project/boxMemory.ts +++ b/src/core/project/boxMemory.ts @@ -3,6 +3,7 @@ import { partition } from "@aws-sdk/util-endpoints"; import { InputValidationError } from "../../errors/errors"; import { BOX_GATEWAY_AGENTCORE_TARGET_NAME, + BOX_GATEWAY_BEDROCK_TARGET_NAME, DEFAULT_EGRESS_BEDROCK_REGION, callsBedrockModel, getBoxGatewayAgentCoreTargetSpec, @@ -12,6 +13,7 @@ import type { AgentCoreGateway, AgentCoreGatewayTarget } from "../../projectSche import { isBoundGateway, type ProjectSpec } from "../../projectSchemas/project"; import { defaultMemoryName } from "../../projectSchemas/memory"; import type { ProjectRuntime } from "../../projectSchemas/runtime"; +import { BOX_EGRESS_TARGET_PREFIX } from "./boxNetwork/egress"; import { runtimeRunsInBox } from "./templates/boxProfile"; /** The Box gateway's target, and the box route, that the agent's AgentCore Memory calls take. */ @@ -179,6 +181,32 @@ function refuseTargetNameOutsideBoxGateways(spec: ProjectSpec, name: string, cal } } +/** The names of the Box gateway targets that build writes for the agent's model and Memory calls. */ +const BOX_DEFAULT_TARGET_NAMES: readonly string[] = [ + BOX_GATEWAY_BEDROCK_TARGET_NAME, + BOX_GATEWAY_AGENTCORE_TARGET_NAME, +]; + +/** + * The refusal of a user target named `name` on a Box gateway, or `undefined` when build does not + * own the name. Build writes the `bedrock` and `agentcore` targets, and names each egress target + * it writes with the `egress-` prefix. A user target of such a name would take the agent's Bedrock + * or Memory route, or the name of an egress target that build writes. + */ +export function reservedBoxTargetNameProblem(name: string, gateway: string): string | undefined { + if (!BOX_DEFAULT_TARGET_NAMES.includes(name) && !name.startsWith(BOX_EGRESS_TARGET_PREFIX)) { + return undefined; + } + const reserved = [ + ...BOX_DEFAULT_TARGET_NAMES.map((n) => `'${n}'`), + `'${BOX_EGRESS_TARGET_PREFIX}*'`, + ]; + return ( + `the gateway target name '${name}' is reserved on Box gateway '${gateway}': build writes the ` + + `targets ${reserved.join(", ")} for the agent's model, Memory, and egress calls. Choose another name.` + ); +} + /** * Lists `policyFile` in `gateway`'s `additionalPolicies`, unless the gateway imports its role * (`executionRoleArn`), which is the user's to grant; the L3 warns about it at synth. diff --git a/src/core/project/boxNetwork/index.ts b/src/core/project/boxNetwork/index.ts index 0f8c07dad..af6e1596c 100644 --- a/src/core/project/boxNetwork/index.ts +++ b/src/core/project/boxNetwork/index.ts @@ -4,7 +4,6 @@ export { boxGatewayOf, buildBoxNetwork, isManagedTarget, - reservedBoxTargetNameProblem, type BoxEgressAuth, type BoxHostSource, type BoxNetwork, diff --git a/src/core/project/boxNetwork/network.ts b/src/core/project/boxNetwork/network.ts index e53e0e8b7..49d72b050 100644 --- a/src/core/project/boxNetwork/network.ts +++ b/src/core/project/boxNetwork/network.ts @@ -5,8 +5,6 @@ * it. */ import { - BOX_GATEWAY_AGENTCORE_TARGET_NAME, - BOX_GATEWAY_BEDROCK_TARGET_NAME, boxGatewayAgentCoreHost, boxGatewayBedrockHost, } from "../../../handlers/project/shortcuts"; @@ -270,30 +268,6 @@ export function isManagedTarget(target: Pick): b return target.name.startsWith(BOX_EGRESS_TARGET_PREFIX); } -/** The names of the Box gateway targets that build writes for the agent's model and Memory calls. */ -const BOX_DEFAULT_TARGET_NAMES: readonly string[] = [ - BOX_GATEWAY_BEDROCK_TARGET_NAME, - BOX_GATEWAY_AGENTCORE_TARGET_NAME, -]; - -/** - * The refusal of a user target named `name` on a Box gateway, or `undefined` when build does not - * own the name. Build writes the `bedrock` and `agentcore` targets and every `egress-` target, so a - * user target of such a name would take the agent's Bedrock or Memory route, or build would - * rewrite or remove it. - */ -export function reservedBoxTargetNameProblem(name: string, gateway: string): string | undefined { - if (!BOX_DEFAULT_TARGET_NAMES.includes(name) && !isManagedTarget({ name })) return undefined; - const reserved = [ - ...BOX_DEFAULT_TARGET_NAMES.map((n) => `'${n}'`), - `'${BOX_EGRESS_TARGET_PREFIX}*'`, - ]; - return ( - `the gateway target name '${name}' is reserved on Box gateway '${gateway}': build writes the ` + - `targets ${reserved.join(", ")} for the agent's model, Memory, and egress calls. Choose another name.` - ); -} - /** The host map key of a passthrough target's endpoint, or `undefined` for another target. */ function endpointKey(target: AgentCoreGatewayTarget): string | undefined { const at = target.passthrough && parseEndpoint(target.passthrough.endpoint); diff --git a/src/core/project/manager.tsx b/src/core/project/manager.tsx index 33e83cac7..e402b7f51 100644 --- a/src/core/project/manager.tsx +++ b/src/core/project/manager.tsx @@ -54,7 +54,8 @@ import { harnessApiKeyCredentialName, validateHarnessTemplateSource, } from "./templates/harness"; -import { boxGatewayIamWarnings, reservedBoxTargetNameProblem, type BoxNetwork } from "./boxNetwork"; +import { boxGatewayIamWarnings, type BoxNetwork } from "./boxNetwork"; +import { reservedBoxTargetNameProblem } from "./boxMemory"; import { boxNetworkFailureMessage, readBoxNetworks } from "./boxNetworkSource"; import { DEFAULT_REGION, regionFromConfigFile } from "../region"; import { BoxCliProfileResolver, type BoxProfileResolver } from "./boxProfileResolver"; From 929cbe2defd65e52e3650d952fe71fe4c4b3e122 Mon Sep 17 00:00:00 2001 From: Varun Gunda Date: Fri, 20 Nov 2026 17:24:31 -0800 Subject: [PATCH 3/7] fix(box): refuse build-owned target names only for a runtime that runs in a box Build writes the bedrock, agentcore and egress- targets only on the Box gateway of a runtime that runtimeRunsInBox accepts. The check gated on isBoundGateway, so it also refused these names on a bound gateway whose runtime does not run in a box, with a reason that is not true there. The tests give the runtime a box.version, and a new test adds the three names on a bound gateway whose runtime has no box.version. --- src/core/project/boxMemory.ts | 19 ++++++++---- src/core/project/manager.tsx | 7 ++--- .../gateway-target.screen.test.tsx | 8 ++++- .../project/add/gateway-target/index.test.ts | 31 ++++++++++++++++++- 4 files changed, 52 insertions(+), 13 deletions(-) diff --git a/src/core/project/boxMemory.ts b/src/core/project/boxMemory.ts index ce1af4f32..a407cbf93 100644 --- a/src/core/project/boxMemory.ts +++ b/src/core/project/boxMemory.ts @@ -188,12 +188,19 @@ const BOX_DEFAULT_TARGET_NAMES: readonly string[] = [ ]; /** - * The refusal of a user target named `name` on a Box gateway, or `undefined` when build does not - * own the name. Build writes the `bedrock` and `agentcore` targets, and names each egress target - * it writes with the `egress-` prefix. A user target of such a name would take the agent's Bedrock - * or Memory route, or the name of an egress target that build writes. + * The refusal of a user target named `name` on `gateway`, or `undefined` when build does not own + * the name there. On the Box gateway of a runtime that runs in a box, build writes the `bedrock` + * and `agentcore` targets, and names each egress target it writes with the `egress-` prefix. A + * user target of such a name would take the agent's Bedrock or Memory route, or the name of an + * egress target that build writes. Build writes none of these for another runtime. */ -export function reservedBoxTargetNameProblem(name: string, gateway: string): string | undefined { +export function reservedBoxTargetNameProblem( + spec: ProjectSpec, + gateway: AgentCoreGateway, + name: string, +): string | undefined { + const boxed = boxedRuntimes(spec).some((runtime) => runtime.name === gateway.boundRuntime); + if (!isBoundGateway(gateway) || !boxed) return undefined; if (!BOX_DEFAULT_TARGET_NAMES.includes(name) && !name.startsWith(BOX_EGRESS_TARGET_PREFIX)) { return undefined; } @@ -202,7 +209,7 @@ export function reservedBoxTargetNameProblem(name: string, gateway: string): str `'${BOX_EGRESS_TARGET_PREFIX}*'`, ]; return ( - `the gateway target name '${name}' is reserved on Box gateway '${gateway}': build writes the ` + + `the gateway target name '${name}' is reserved on Box gateway '${gateway.name}': build writes the ` + `targets ${reserved.join(", ")} for the agent's model, Memory, and egress calls. Choose another name.` ); } diff --git a/src/core/project/manager.tsx b/src/core/project/manager.tsx index e402b7f51..1cf1338b8 100644 --- a/src/core/project/manager.tsx +++ b/src/core/project/manager.tsx @@ -672,15 +672,12 @@ export class FsProjectManager implements ProjectManager { `a gateway target with name '${input.resourceConfig.name}' already exists in gateway '${gateway.name}'`, ); } - // Build owns some target names on a Box gateway. A user target of such a name would take - // the agent's Bedrock or Memory route, or build would rewrite or remove it. + // Build owns some target names on the Box gateway of a boxed runtime. const parent = projectSpec.agentCoreGateways.find( (candidate) => candidate.name === input.gatewayName, ); const reserved = - parent && isBoundGateway(parent) - ? reservedBoxTargetNameProblem(input.resourceConfig.name, parent.name) - : undefined; + parent && reservedBoxTargetNameProblem(projectSpec, parent, input.resourceConfig.name); if (reserved) throw new InputValidationError(reserved); } else if (input.resourceType === "policy") { // Policy names are account-unique on the service, so the check spans engines. diff --git a/src/handlers/project/add/gateway-target/gateway-target.screen.test.tsx b/src/handlers/project/add/gateway-target/gateway-target.screen.test.tsx index 2618d2d84..76d343014 100644 --- a/src/handlers/project/add/gateway-target/gateway-target.screen.test.tsx +++ b/src/handlers/project/add/gateway-target/gateway-target.screen.test.tsx @@ -19,6 +19,7 @@ import type { AppIO } from "../../../../io"; import { createGatewayProjectTestHarness } from "../gateway-test-support"; import { authChoices, toGatewayTargetInput } from "./screen"; import { boxGatewaySpec } from "../../../../projectSchemas/project"; +import { BOX_RELEASE } from "../../../../core/project/backends/boxRelease"; const ENDPOINT = "https://mcp.example.com"; const OAUTH_CREDENTIAL = { @@ -465,7 +466,12 @@ describe("project add gateway-target wizard", () => { const projectRoot = await inProject(); const spec = await projectSpec(projectRoot); const box = boxGatewaySpec(spec.runtimes[0].name); - await writeProjectSpec(projectRoot, { ...spec, projectType: "box", agentCoreGateways: [box] }); + await writeProjectSpec(projectRoot, { + ...spec, + projectType: "box", + runtimes: [{ ...spec.runtimes[0], box: { version: BOX_RELEASE.version } }], + agentCoreGateways: [box], + }); const screen = renderScreen("/agentcore/add/gateway-target"); await reachAuthStep(screen, "bedrock"); await screen.press("return"); diff --git a/src/handlers/project/add/gateway-target/index.test.ts b/src/handlers/project/add/gateway-target/index.test.ts index 6d97366e7..b0e9e2731 100644 --- a/src/handlers/project/add/gateway-target/index.test.ts +++ b/src/handlers/project/add/gateway-target/index.test.ts @@ -4,6 +4,7 @@ import { join } from "node:path"; import { InputValidationError, ProjectStateError, ResourceNotFoundError } from "../../../../errors"; import { expectError } from "../../../../testing"; import { createGatewayProjectTestHarness } from "../gateway-test-support"; +import { BOX_RELEASE } from "../../../../core/project/backends/boxRelease"; import { boxGatewaySpec, ProjectSpecSchema } from "../../../../projectSchemas/project"; import { getBoxGatewayAgentCoreTargetSpec, @@ -83,7 +84,12 @@ describe("project add gateway-target", () => { const projectRoot = await inProject(); const spec = await projectSpec(projectRoot); const box = boxGatewaySpec(spec.runtimes[0].name); - await writeProjectSpec(projectRoot, { ...spec, projectType: "box", agentCoreGateways: [box] }); + await writeProjectSpec(projectRoot, { + ...spec, + projectType: "box", + runtimes: [{ ...spec.runtimes[0], box: { version: BOX_RELEASE.version } }], + agentCoreGateways: [box], + }); await addGateway(); for (const name of ["bedrock", "agentcore", "egress-api-example-com"]) { @@ -119,6 +125,29 @@ describe("project add gateway-target", () => { ).toEqual(["bedrock", "agentcore", "egress-api-example-com"]); }); + test("accepts the names on a bound gateway whose runtime does not run in a box", async () => { + const projectRoot = await inProject(); + const spec = await projectSpec(projectRoot); + const box = boxGatewaySpec(spec.runtimes[0].name); + // A Box project runtime with no box.version: build writes no targets on its gateway. + await writeProjectSpec(projectRoot, { ...spec, projectType: "box", agentCoreGateways: [box] }); + + for (const name of ["bedrock", "agentcore", "egress-api-example-com"]) { + await run([ + "add", + "gateway-target", + ...["--gateway", box.name, "--name", name, "--endpoint", ENDPOINT], + ...["--outbound-auth", "none"], + ]); + } + + expect( + (await projectSpec(projectRoot)).agentCoreGateways[0].targets.map( + (target: { name: string }) => target.name, + ), + ).toEqual(["bedrock", "agentcore", "egress-api-example-com"]); + }); + test("keeps the targets build writes on a Box gateway valid", async () => { const projectRoot = await inProject(); const spec = await projectSpec(projectRoot); From 1a231a038ad060dca1df6b02b3a5defed74f7e3f Mon Sep 17 00:00:00 2001 From: Varun Gunda Date: Fri, 20 Nov 2026 17:25:14 -0800 Subject: [PATCH 4/7] test(box): run each build-owned target name in its own project The refusal and acceptance tests now use test.each over the three names, with a new project for each name, so a failure names the target name and no state carries over from another name. --- .../project/add/gateway-target/index.test.ts | 61 ++++++++++--------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/src/handlers/project/add/gateway-target/index.test.ts b/src/handlers/project/add/gateway-target/index.test.ts index b0e9e2731..50768aeab 100644 --- a/src/handlers/project/add/gateway-target/index.test.ts +++ b/src/handlers/project/add/gateway-target/index.test.ts @@ -80,19 +80,35 @@ describe("project add gateway-target", () => { expect(JSON.parse(asJson.stdout()).notes).toEqual([note]); }); - test("refuses the target names build owns on a Box gateway, and only there", async () => { + /** A Box project with its Box gateway and the `tools` gateway; `boxed` gives the runtime a box. */ + async function boxProject(boxed: boolean) { const projectRoot = await inProject(); const spec = await projectSpec(projectRoot); - const box = boxGatewaySpec(spec.runtimes[0].name); + const runtime = spec.runtimes[0]; + const box = boxGatewaySpec(runtime.name); await writeProjectSpec(projectRoot, { ...spec, projectType: "box", - runtimes: [{ ...spec.runtimes[0], box: { version: BOX_RELEASE.version } }], + runtimes: [boxed ? { ...runtime, box: { version: BOX_RELEASE.version } } : runtime], agentCoreGateways: [box], }); await addGateway(); + return { projectRoot, box }; + } + + async function targetNames(projectRoot: string, gateway: string): Promise { + return (await projectSpec(projectRoot)).agentCoreGateways + .find((candidate: { name: string }) => candidate.name === gateway) + .targets.map((target: { name: string }) => target.name); + } + + const BUILD_OWNED_NAMES = ["bedrock", "agentcore", "egress-api-example-com"]; + + test.each(BUILD_OWNED_NAMES)( + "refuses the build-owned name %s on a Box gateway, and only there", + async (name) => { + const { projectRoot, box } = await boxProject(true); - for (const name of ["bedrock", "agentcore", "egress-api-example-com"]) { await expectError( run([ "add", @@ -112,41 +128,28 @@ describe("project add gateway-target", () => { ...["--gateway", "tools", "--name", name, "--endpoint", ENDPOINT], ...["--outbound-auth", "none"], ]); - } - const gateways = (await projectSpec(projectRoot)).agentCoreGateways; - expect(gateways.find((gateway: { name: string }) => gateway.name === box.name).targets).toEqual( - [], - ); - expect( - gateways - .find((gateway: { name: string }) => gateway.name === "tools") - .targets.map((target: { name: string }) => target.name), - ).toEqual(["bedrock", "agentcore", "egress-api-example-com"]); - }); + expect(await targetNames(projectRoot, box.name)).toEqual([]); + expect(await targetNames(projectRoot, "tools")).toEqual([name]); + }, + ); - test("accepts the names on a bound gateway whose runtime does not run in a box", async () => { - const projectRoot = await inProject(); - const spec = await projectSpec(projectRoot); - const box = boxGatewaySpec(spec.runtimes[0].name); - // A Box project runtime with no box.version: build writes no targets on its gateway. - await writeProjectSpec(projectRoot, { ...spec, projectType: "box", agentCoreGateways: [box] }); + test.each(BUILD_OWNED_NAMES)( + "accepts the name %s on a bound gateway whose runtime does not run in a box", + async (name) => { + // A Box project runtime with no box.version: build writes no targets on its gateway. + const { projectRoot, box } = await boxProject(false); - for (const name of ["bedrock", "agentcore", "egress-api-example-com"]) { await run([ "add", "gateway-target", ...["--gateway", box.name, "--name", name, "--endpoint", ENDPOINT], ...["--outbound-auth", "none"], ]); - } - expect( - (await projectSpec(projectRoot)).agentCoreGateways[0].targets.map( - (target: { name: string }) => target.name, - ), - ).toEqual(["bedrock", "agentcore", "egress-api-example-com"]); - }); + expect(await targetNames(projectRoot, box.name)).toEqual([name]); + }, + ); test("keeps the targets build writes on a Box gateway valid", async () => { const projectRoot = await inProject(); From 5461f2f66b7cc984a474e9b07dd77cf4bf6fc8b3 Mon Sep 17 00:00:00 2001 From: Varun Gunda Date: Fri, 20 Nov 2026 17:25:58 -0800 Subject: [PATCH 5/7] test(box): check build's Box gateway targets in the schema tests The test that build's bedrock, agentcore and egress- targets stay valid on a Box gateway tests ProjectSpecSchema, not add gateway-target: it passed with the name check removed. It is now a schema test in project.test.ts, where no test covered these targets before. --- .../project/add/gateway-target/index.test.ts | 36 +------------------ src/projectSchemas/project.test.ts | 17 +++++++++ 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/src/handlers/project/add/gateway-target/index.test.ts b/src/handlers/project/add/gateway-target/index.test.ts index 50768aeab..f80332e6b 100644 --- a/src/handlers/project/add/gateway-target/index.test.ts +++ b/src/handlers/project/add/gateway-target/index.test.ts @@ -5,11 +5,7 @@ import { InputValidationError, ProjectStateError, ResourceNotFoundError } from " import { expectError } from "../../../../testing"; import { createGatewayProjectTestHarness } from "../gateway-test-support"; import { BOX_RELEASE } from "../../../../core/project/backends/boxRelease"; -import { boxGatewaySpec, ProjectSpecSchema } from "../../../../projectSchemas/project"; -import { - getBoxGatewayAgentCoreTargetSpec, - getBoxGatewayBedrockTargetSpec, -} from "../../../project/shortcuts"; +import { boxGatewaySpec } from "../../../../projectSchemas/project"; const DISCOVERY_URL = "https://idp.example.com/.well-known/openid-configuration"; const ENDPOINT = "https://mcp.example.com"; @@ -151,36 +147,6 @@ describe("project add gateway-target", () => { }, ); - test("keeps the targets build writes on a Box gateway valid", async () => { - const projectRoot = await inProject(); - const spec = await projectSpec(projectRoot); - const egress = { - name: "egress-api-example-com", - targetType: "passthrough", - passthrough: { endpoint: "https://api.example.com", protocolType: "CUSTOM" }, - }; - const box = { - ...boxGatewaySpec(spec.runtimes[0].name), - targets: [getBoxGatewayBedrockTargetSpec(), getBoxGatewayAgentCoreTargetSpec(), egress], - }; - const written = { ...spec, projectType: "box", agentCoreGateways: [box] }; - expect(ProjectSpecSchema.safeParse(written).success).toBe(true); - await writeProjectSpec(projectRoot, written); - - await run([ - "add", - "gateway-target", - ...["--gateway", box.name, "--name", "search", "--endpoint", ENDPOINT], - ...["--outbound-auth", "none"], - ]); - - expect( - (await projectSpec(projectRoot)).agentCoreGateways[0].targets.map( - (target: { name: string }) => target.name, - ), - ).toEqual(["bedrock", "agentcore", "egress-api-example-com", "search"]); - }); - test("adds endpoint and project Runtime shortcuts", async () => { const projectRoot = await inProject(); await addGateway(); diff --git a/src/projectSchemas/project.test.ts b/src/projectSchemas/project.test.ts index d643bb33d..819fa96ac 100644 --- a/src/projectSchemas/project.test.ts +++ b/src/projectSchemas/project.test.ts @@ -1,4 +1,8 @@ import { describe, expect, it, test } from "bun:test"; +import { + getBoxGatewayAgentCoreTargetSpec, + getBoxGatewayBedrockTargetSpec, +} from "../handlers/project/shortcuts"; import { boxGatewaySpec, ProjectSpecSchema, ProjectNameSchema } from "./project"; const minimalProject = { name: "project", version: 2 }; @@ -588,6 +592,19 @@ describe("Box project gateways", () => { expect(parse(["agent"], [{ ...boxGatewaySpec("agent"), name: "renamed" }]).success).toBe(true); }); + test("accepts the targets build writes on a Box gateway", () => { + const egress = { + name: "egress-api-example-com", + targetType: "passthrough", + passthrough: { endpoint: "https://api.example.com", protocolType: "CUSTOM" }, + }; + const box = { + ...boxGatewaySpec("agent"), + targets: [getBoxGatewayBedrockTargetSpec(), getBoxGatewayAgentCoreTargetSpec(), egress], + }; + expect(messages(parse(["agent"], [box]))).toEqual([]); + }); + test("does not ask for Box gateways in a project without projectType", () => { const result = ProjectSpecSchema.safeParse({ ...minimalProject, runtimes: [runtime] }); expect(result.success).toBe(true); From 7cb96dac2e18681d1a37ffe96c32ca726db60870 Mon Sep 17 00:00:00 2001 From: Varun Gunda Date: Fri, 20 Nov 2026 17:27:33 -0800 Subject: [PATCH 6/7] refactor(tui): use isBoundGateway in boundRuntimeNote The wizard note now asks isBoundGateway whether a gateway is bound, as the rest of the code does, and does not check boundRuntime itself. --- src/handlers/project/add/shared.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handlers/project/add/shared.ts b/src/handlers/project/add/shared.ts index 3bf1beac1..6b8a6caff 100644 --- a/src/handlers/project/add/shared.ts +++ b/src/handlers/project/add/shared.ts @@ -112,7 +112,7 @@ export function defaultGatewayChoice( /** " · bound to runtime 'x'" for a gateway bound to one runtime, for a wizard's choice text. */ export function boundRuntimeNote(gateway: { boundRuntime?: string }): string { - return gateway.boundRuntime === undefined ? "" : ` · bound to runtime '${gateway.boundRuntime}'`; + return isBoundGateway(gateway) ? ` · bound to runtime '${gateway.boundRuntime}'` : ""; } /** From cb5bee70f6a47a34cd61fff6873887fef2d28ccc Mon Sep 17 00:00:00 2001 From: Varun Gunda Date: Fri, 20 Nov 2026 17:28:57 -0800 Subject: [PATCH 7/7] refactor(tui): build the bound gateway lines of remove runtime in one function removedGatewayLines and boundGatewayWarningLines were near copies. One function, boundGatewayLines, now makes both: the lines before the removal name each bound gateway and its targets, and the lines after it name each removed gateway and its target count. The text does not change. A new unit test pins each form for zero, one and more targets. --- src/handlers/project/remove/index.ts | 4 +- src/handlers/project/remove/notice.test.ts | 35 +++++++++++++ src/handlers/project/remove/notice.ts | 60 +++++++++++----------- src/handlers/project/remove/screen.tsx | 11 ++-- 4 files changed, 71 insertions(+), 39 deletions(-) create mode 100644 src/handlers/project/remove/notice.test.ts diff --git a/src/handlers/project/remove/index.ts b/src/handlers/project/remove/index.ts index 521800416..503d2ab0b 100644 --- a/src/handlers/project/remove/index.ts +++ b/src/handlers/project/remove/index.ts @@ -8,7 +8,7 @@ import { JsonKey } from "../../keys"; import { renderResult } from "../../utils"; import type { ProjectManager, RemoveResourceInput } from "../types"; import { projectMutationResource, projectReference, type ProjectMutationResult } from "../output"; -import { APP_CODE_RETAINED_NOTICE, removedGatewayLines, shouldShowAppCodeNotice } from "./notice"; +import { APP_CODE_RETAINED_NOTICE, boundGatewayLines, shouldShowAppCodeNotice } from "./notice"; type RemoveProjectResourceConfig = { projectManager: ProjectManager; @@ -169,7 +169,7 @@ export const createRemoveProjectHandler = (config: RemoveProjectResourceConfig) }, () => { config.io.stderr.write(`removed ${resource} with name '${name}' from project\n`); - for (const line of removedGatewayLines(name, result.removedGateways)) { + for (const line of boundGatewayLines(name, result.removedGateways)) { config.io.stderr.write(`${line}\n`); } if (showAppCodeNotice) { diff --git a/src/handlers/project/remove/notice.test.ts b/src/handlers/project/remove/notice.test.ts new file mode 100644 index 000000000..4aeaa70ef --- /dev/null +++ b/src/handlers/project/remove/notice.test.ts @@ -0,0 +1,35 @@ +import { describe, expect, test } from "bun:test"; +import { boundGatewayLines } from "./notice"; + +describe("boundGatewayLines", () => { + test("names each gateway bound to the runtime and its targets before the removal", () => { + const target = (name: string) => ({ name }); + const gateways = [ + { name: "none", boundRuntime: "agent", targets: [] }, + { name: "one", boundRuntime: "agent", targets: [target("search")] }, + { name: "two", boundRuntime: "agent", targets: [target("search"), target("docs")] }, + { name: "other", boundRuntime: "checkout", targets: [target("search")] }, + { name: "tools", targets: [target("search")] }, + ]; + + expect(boundGatewayLines("agent", gateways)).toEqual([ + "gateway 'none'", + "gateway 'one' and its target 'search'", + "gateway 'two' and its targets 'search', 'docs'", + ]); + }); + + test("names each removed gateway and its target count after the removal", () => { + const removed = [ + { name: "none", targetCount: 0 }, + { name: "one", targetCount: 1 }, + { name: "three", targetCount: 3 }, + ]; + + expect(boundGatewayLines("agent", removed)).toEqual([ + "removed gateway 'none': it is bound to runtime 'agent'", + "removed gateway 'one' and its 1 target: it is bound to runtime 'agent'", + "removed gateway 'three' and its 3 targets: it is bound to runtime 'agent'", + ]); + }); +}); diff --git a/src/handlers/project/remove/notice.ts b/src/handlers/project/remove/notice.ts index 8f7275386..309117ba7 100644 --- a/src/handlers/project/remove/notice.ts +++ b/src/handlers/project/remove/notice.ts @@ -8,38 +8,40 @@ export function shouldShowAppCodeNotice(resourceType: ProjectMutationResourceTyp return resourceType === "runtime" || resourceType === "harness" || resourceType === "evaluator"; } -/** One line for each gateway removed with runtime `runtimeName`, with its target count. */ -export function removedGatewayLines(runtimeName: string, gateways: RemovedGateway[]): string[] { - return gateways.map(({ name, targetCount }) => { - const targets = - targetCount === 0 - ? "" - : ` and its ${targetCount === 1 ? "1 target" : `${targetCount} targets`}`; - return `removed gateway '${name}'${targets}: it is bound to runtime '${runtimeName}'`; - }); -} +/** A gateway of the project, as `remove runtime` reads it before the removal. */ +type ProjectGateway = { + name: string; + boundRuntime?: string; + targets: readonly { name: string }[]; +}; /** - * One line for each gateway that `remove runtime` would remove with runtime `runtimeName`, with - * the names of its targets. The TUI shows it before the removal: a Box gateway can hold targets - * the user added, such as MCP servers, and they go with the runtime. + * One line for each gateway that `remove runtime` removes with runtime `runtimeName`. Give the + * project's gateways before the removal: the lines name each gateway bound to the runtime and the + * names of its targets, because a Box gateway can hold targets the user added, such as MCP + * servers, and the TUI shows them before they go. Give the removed gateways after the removal: + * the lines name each gateway and its target count. */ -export function boundGatewayWarningLines( +export function boundGatewayLines( runtimeName: string, - gateways: readonly { - name: string; - boundRuntime?: string; - targets: readonly { name: string }[]; - }[], + gateways: readonly (ProjectGateway | RemovedGateway)[], ): string[] { - return gateways - .filter((gateway) => gateway.boundRuntime === runtimeName) - .map(({ name, targets }) => { - const names = targets.map((target) => `'${target.name}'`).join(", "); - const what = - targets.length === 0 - ? "" - : ` and its ${targets.length === 1 ? "target" : "targets"} ${names}`; - return `gateway '${name}'${what}`; - }); + return gateways.flatMap((gateway) => { + if ("targetCount" in gateway) { + const targets = targetsPhrase(gateway.targetCount); + return [ + `removed gateway '${gateway.name}'${targets}: it is bound to runtime '${runtimeName}'`, + ]; + } + if (gateway.boundRuntime !== runtimeName) return []; + const names = gateway.targets.map((target) => `'${target.name}'`); + return [`gateway '${gateway.name}'${targetsPhrase(names.length, names)}`]; + }); +} + +/** " and its 2 targets", or with `names` " and its targets 'a', 'b'"; empty for no target. */ +function targetsPhrase(count: number, names?: readonly string[]): string { + if (count === 0) return ""; + const noun = count === 1 ? "target" : "targets"; + return names ? ` and its ${noun} ${names.join(", ")}` : ` and its ${count} ${noun}`; } diff --git a/src/handlers/project/remove/screen.tsx b/src/handlers/project/remove/screen.tsx index 9f1fa103c..8990d339d 100644 --- a/src/handlers/project/remove/screen.tsx +++ b/src/handlers/project/remove/screen.tsx @@ -10,12 +10,7 @@ import { isBoundGateway, type ProjectSpec } from "../../../projectSchemas/projec import type { Project, RemoveResourceInput } from "../types"; import type { ScreenProps } from "../../types"; import { ProjectGate, projectQueryKey } from "../ProjectGate"; -import { - APP_CODE_RETAINED_NOTICE, - boundGatewayWarningLines, - removedGatewayLines, - shouldShowAppCodeNotice, -} from "./notice"; +import { APP_CODE_RETAINED_NOTICE, boundGatewayLines, shouldShowAppCodeNotice } from "./notice"; type RootResourceType = | "runtime" @@ -337,7 +332,7 @@ function RemoveConfirm({ // A runtime takes its bound gateways (each Box gateway is) and their targets with it. const alsoRemoves = resource.resourceType === "runtime" - ? boundGatewayWarningLines(resource.name, project.spec.agentCoreGateways) + ? boundGatewayLines(resource.name, project.spec.agentCoreGateways) : []; const rows: SummaryRows = { type: config.resourceType, @@ -360,7 +355,7 @@ function RemoveConfirm({ action={async () => { const result = await core.projectManager.removeResource(project, resource); removedProject.current = result.project; - const gatewayLines = removedGatewayLines(resource.name, result.removedGateways); + const gatewayLines = boundGatewayLines(resource.name, result.removedGateways); return { rows: { removed: `${config.resourceType} '${resource.name}'`,