Repository navigation
fix(box): refuse build-owned target names on a Box gateway #2864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: box-integration
Are you sure you want to change the base?
Changes from all commits
1661e23
65b494f
e6376c9
929cbe2
1a231a0
5461f2f
7cb96da
cb5bee7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,7 @@ import { | |
| validateHarnessTemplateSource, | ||
| } from "./templates/harness"; | ||
| 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"; | ||
|
|
@@ -671,6 +672,13 @@ 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 the Box gateway of a boxed runtime. | ||
| const parent = projectSpec.agentCoreGateways.find( | ||
| (candidate) => candidate.name === input.gatewayName, | ||
| ); | ||
| const reserved = | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking nit. This only covers |
||
| 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. | ||
| const engine = projectSpec.policyEngines.find((candidate) => | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 } from "../../../../projectSchemas/project"; | ||
|
|
||
| const DISCOVERY_URL = "https://idp.example.com/.well-known/openid-configuration"; | ||
|
|
@@ -75,6 +76,77 @@ describe("project add gateway-target", () => { | |
| expect(JSON.parse(asJson.stdout()).notes).toEqual([note]); | ||
| }); | ||
|
|
||
| /** 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 runtime = spec.runtimes[0]; | ||
| const box = boxGatewaySpec(runtime.name); | ||
| await writeProjectSpec(projectRoot, { | ||
| ...spec, | ||
| projectType: "box", | ||
| runtimes: [boxed ? { ...runtime, box: { version: BOX_RELEASE.version } } : runtime], | ||
| agentCoreGateways: [box], | ||
| }); | ||
| await addGateway(); | ||
| return { projectRoot, box }; | ||
| } | ||
|
|
||
| async function targetNames(projectRoot: string, gateway: string): Promise<string[]> { | ||
| 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); | ||
|
|
||
| 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. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking. This test asserts that Two options:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking, carried over from my last review. Here |
||
| await run([ | ||
| "add", | ||
| "gateway-target", | ||
| ...["--gateway", "tools", "--name", name, "--endpoint", ENDPOINT], | ||
| ...["--outbound-auth", "none"], | ||
| ]); | ||
|
|
||
| expect(await targetNames(projectRoot, box.name)).toEqual([]); | ||
| expect(await targetNames(projectRoot, "tools")).toEqual([name]); | ||
| }, | ||
| ); | ||
|
|
||
| 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); | ||
|
|
||
| await run([ | ||
| "add", | ||
| "gateway-target", | ||
| ...["--gateway", box.name, "--name", name, "--endpoint", ENDPOINT], | ||
| ...["--outbound-auth", "none"], | ||
| ]); | ||
|
|
||
| expect(await targetNames(projectRoot, box.name)).toEqual([name]); | ||
| }, | ||
| ); | ||
|
|
||
| test("adds endpoint and project Runtime shortcuts", async () => { | ||
| const projectRoot = await inProject(); | ||
| await addGateway(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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'", | ||
| ]); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking, about merge order with #2877. After #2877, build keeps a user's
egress-*target as the user's, by its record inagentcore/box-gateway-targets.json. So this prefix check stays only as a guard against name collisions with the targets build writes, and #2887'segress-gateway-<name>targets are covered. The two PRs are consistent. A short note here, or in the PR body, would help readers: it would say that hand-writtenegress-*targets still work after #2877, and thataddrefuses the prefix only for new targets.