-
Notifications
You must be signed in to change notification settings - Fork 71
feat: add config-bundle CLI commands #1945
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
Open
nborges-aws
wants to merge
1
commit into
refactor
Choose a base branch
from
config-bundle-commands
base: refactor
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,198
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { | ||
| CreateConfigurationBundleCommand, | ||
| DeleteConfigurationBundleCommand, | ||
| GetConfigurationBundleCommand, | ||
| GetConfigurationBundleVersionCommand, | ||
| ListConfigurationBundlesCommand, | ||
| ListConfigurationBundleVersionsCommand, | ||
| UpdateConfigurationBundleCommand, | ||
| type BedrockAgentCoreControlClient, | ||
| } from "@aws-sdk/client-bedrock-agentcore-control"; | ||
| import { NetworkingError } from "../errors"; | ||
| import { EvalClient } from "./eval"; | ||
| import type { AwsClients, ClientConfig } from "./types"; | ||
|
|
||
| const OPTIONS = { region: "us-west-2", endpointUrl: "https://control.test" }; | ||
| const COMPONENTS = { | ||
| "arn:aws:bedrock-agentcore:us-west-2:123456789012:runtime/orders-agent": { | ||
| configuration: { system_prompt: "Help with orders." }, | ||
| }, | ||
| }; | ||
|
|
||
| function subject(respond: (command: unknown) => Promise<unknown>): { | ||
| client: EvalClient; | ||
| configs: ClientConfig[]; | ||
| } { | ||
| const configs: ClientConfig[] = []; | ||
| const control = { send: respond } as unknown as BedrockAgentCoreControlClient; | ||
| const clients = { | ||
| control: (config: ClientConfig) => { | ||
| configs.push(config); | ||
| return control; | ||
| }, | ||
| } as unknown as AwsClients; | ||
| return { client: new EvalClient(clients), configs }; | ||
| } | ||
|
|
||
| describe("EvalClient configuration bundles", () => { | ||
| test("create sends CreateConfigurationBundleCommand unchanged", async () => { | ||
| const sent: unknown[] = []; | ||
| const response = { | ||
| bundleArn: "arn:bundle:b-1", | ||
| bundleId: "b-1", | ||
| versionId: "v-1", | ||
| createdAt: new Date("2026-08-07T00:00:00Z"), | ||
| }; | ||
| const { client, configs } = subject(async (command) => { | ||
| sent.push(command); | ||
| return response; | ||
| }); | ||
| const input = { | ||
| bundleName: "orders-prompt", | ||
| components: COMPONENTS, | ||
| kmsKeyArn: "arn:aws:kms:us-west-2:123456789012:key/abc", | ||
| }; | ||
|
|
||
| expect(await client.createConfigurationBundle(input, OPTIONS)).toBe(response); | ||
| expect(sent[0]).toBeInstanceOf(CreateConfigurationBundleCommand); | ||
| expect((sent[0] as CreateConfigurationBundleCommand).input).toEqual(input); | ||
| expect(configs).toEqual([{ region: "us-west-2", endpoint: "https://control.test" }]); | ||
| }); | ||
|
|
||
| test("get selects the latest or immutable-version SDK operation", async () => { | ||
| const sent: unknown[] = []; | ||
| const { client } = subject(async (command) => { | ||
| sent.push(command); | ||
| return {}; | ||
| }); | ||
|
|
||
| await client.getConfigurationBundle("b-1", undefined, OPTIONS); | ||
| await client.getConfigurationBundle("b-1", "v-2", OPTIONS); | ||
|
|
||
| expect(sent[0]).toBeInstanceOf(GetConfigurationBundleCommand); | ||
| expect((sent[0] as GetConfigurationBundleCommand).input).toEqual({ bundleId: "b-1" }); | ||
| expect(sent[1]).toBeInstanceOf(GetConfigurationBundleVersionCommand); | ||
| expect((sent[1] as GetConfigurationBundleVersionCommand).input).toEqual({ | ||
| bundleId: "b-1", | ||
| versionId: "v-2", | ||
| }); | ||
| }); | ||
|
|
||
| test("list sends only the aligned pagination fields", async () => { | ||
| const sent: unknown[] = []; | ||
| const { client } = subject(async (command) => { | ||
| sent.push(command); | ||
| return { bundles: [] }; | ||
| }); | ||
|
|
||
| await client.listConfigurationBundles("token-1", 10, OPTIONS); | ||
|
|
||
| expect(sent[0]).toBeInstanceOf(ListConfigurationBundlesCommand); | ||
| expect((sent[0] as ListConfigurationBundlesCommand).input).toEqual({ | ||
| nextToken: "token-1", | ||
| maxResults: 10, | ||
| }); | ||
| }); | ||
|
|
||
| test("update gets the latest version and sends it as the sole parent", async () => { | ||
| const sent: unknown[] = []; | ||
| const response = { | ||
| bundleArn: "arn:bundle:b-1", | ||
| bundleId: "b-1", | ||
| versionId: "v-3", | ||
| updatedAt: new Date("2026-08-07T00:00:00Z"), | ||
| }; | ||
| const { client } = subject(async (command) => { | ||
| sent.push(command); | ||
| if (command instanceof GetConfigurationBundleCommand) { | ||
| return { | ||
| versionId: "v-2", | ||
| lineageMetadata: { branchName: "custom-branch" }, | ||
| }; | ||
| } | ||
| return response; | ||
| }); | ||
|
|
||
| expect( | ||
| await client.updateConfigurationBundle( | ||
| "b-1", | ||
| { | ||
| components: COMPONENTS, | ||
| commitMessage: "Replace order support configuration", | ||
| kmsKeyArn: "arn:aws:kms:us-west-2:123456789012:key/new", | ||
| }, | ||
| OPTIONS, | ||
| ), | ||
| ).toBe(response); | ||
|
|
||
| expect(sent).toHaveLength(2); | ||
| expect(sent[0]).toBeInstanceOf(GetConfigurationBundleCommand); | ||
| expect((sent[0] as GetConfigurationBundleCommand).input).toEqual({ bundleId: "b-1" }); | ||
| expect(sent[1]).toBeInstanceOf(UpdateConfigurationBundleCommand); | ||
| expect((sent[1] as UpdateConfigurationBundleCommand).input).toEqual({ | ||
| bundleId: "b-1", | ||
| components: COMPONENTS, | ||
| commitMessage: "Replace order support configuration", | ||
| kmsKeyArn: "arn:aws:kms:us-west-2:123456789012:key/new", | ||
| parentVersionIds: ["v-2"], | ||
| }); | ||
| }); | ||
|
|
||
| test("update fails before sending when latest has no version id", async () => { | ||
| const sent: unknown[] = []; | ||
| const { client } = subject(async (command) => { | ||
| sent.push(command); | ||
| return {}; | ||
| }); | ||
|
|
||
| const promise = client.updateConfigurationBundle( | ||
| "b-1", | ||
| { | ||
| components: COMPONENTS, | ||
| commitMessage: "Replace order support configuration", | ||
| kmsKeyArn: "arn:aws:kms:us-west-2:123456789012:key/new", | ||
| }, | ||
| OPTIONS, | ||
| ); | ||
|
|
||
| await expect(promise).rejects.toBeInstanceOf(NetworkingError); | ||
| await expect(promise).rejects.toThrow(/returned no latest version/); | ||
| expect(sent).toHaveLength(1); | ||
| expect(sent[0]).toBeInstanceOf(GetConfigurationBundleCommand); | ||
| }); | ||
|
|
||
| test("delete sends DeleteConfigurationBundleCommand", async () => { | ||
| const sent: unknown[] = []; | ||
| const response = { bundleId: "b-1", status: "DELETING" as const }; | ||
| const { client } = subject(async (command) => { | ||
| sent.push(command); | ||
| return response; | ||
| }); | ||
|
|
||
| expect(await client.deleteConfigurationBundle("b-1", OPTIONS)).toBe(response); | ||
| expect(sent[0]).toBeInstanceOf(DeleteConfigurationBundleCommand); | ||
| expect((sent[0] as DeleteConfigurationBundleCommand).input).toEqual({ bundleId: "b-1" }); | ||
| }); | ||
|
|
||
| test("version list sends the parent bundle and pagination fields", async () => { | ||
| const sent: unknown[] = []; | ||
| const { client } = subject(async (command) => { | ||
| sent.push(command); | ||
| return { versions: [] }; | ||
| }); | ||
|
|
||
| await client.listConfigurationBundleVersions("b-1", "token-1", 5, OPTIONS); | ||
|
|
||
| expect(sent[0]).toBeInstanceOf(ListConfigurationBundleVersionsCommand); | ||
| expect((sent[0] as ListConfigurationBundleVersionsCommand).input).toEqual({ | ||
| bundleId: "b-1", | ||
| nextToken: "token-1", | ||
| maxResults: 5, | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import z from "zod"; | ||
| import type { ComponentConfiguration } from "@aws-sdk/client-bedrock-agentcore-control"; | ||
| import type { SourceResolver } from "../../../io"; | ||
| import { InputValidationError } from "../../../errors"; | ||
| import { parseJsonFlagWithSchema } from "../../utils"; | ||
|
|
||
| const componentConfigurationSchema = z | ||
| .object({ | ||
| configuration: z.unknown().refine((value) => value !== undefined, "configuration is required"), | ||
| }) | ||
| .strict(); | ||
|
|
||
| const componentMapSchema = z | ||
| .record(z.string().min(1), componentConfigurationSchema) | ||
| .refine((components) => Object.keys(components).length > 0, { | ||
| message: "must contain at least one component", | ||
| }); | ||
|
|
||
| export type ConfigurationBundleComponents = Record<string, ComponentConfiguration>; | ||
|
|
||
| export async function resolveConfigurationBundleComponents( | ||
| value: string, | ||
| source: SourceResolver, | ||
| ): Promise<ConfigurationBundleComponents> { | ||
| const text = await source.resolveText("components", value); | ||
| const components = parseJsonFlagWithSchema("components", text, componentMapSchema); | ||
| if (components === undefined) { | ||
| throw new InputValidationError("required option '--components <components>' not specified"); | ||
| } | ||
| return components as ConfigurationBundleComponents; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I may be missing the intended branch behavior, but can we select the branch explicitly before choosing the parent version? I live-tested a mainline v1 followed by a
review-branchv2.GetConfigurationBundlewithoutbranchNamereturned v2, and this CLI update then created v3 onreview-branch. PassingbranchName: "mainline"correctly returned v1. Would it make sense to expose--branch-name, default it tomainline, and pass it to both Get and Update so an ordinary update cannot silently continue whichever branch was modified most recently?