Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions src/core/configBundle.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { describe, expect, test } from "bun:test";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the handler's golden tests cover these core functions?

import {
GetConfigurationBundleCommand,
GetConfigurationBundleVersionCommand,
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("get passes an explicit branch or selects the immutable-version operation", async () => {
const sent: unknown[] = [];
const { client } = subject(async (command) => {
sent.push(command);
return {};
});

await client.getConfigurationBundle("b-1", undefined, "review-branch", OPTIONS);
await client.getConfigurationBundle("b-1", "v-2", "mainline", OPTIONS);

expect(sent[0]).toBeInstanceOf(GetConfigurationBundleCommand);
expect((sent[0] as GetConfigurationBundleCommand).input).toEqual({
bundleId: "b-1",
branchName: "review-branch",
});
expect(sent[1]).toBeInstanceOf(GetConfigurationBundleVersionCommand);
expect((sent[1] as GetConfigurationBundleVersionCommand).input).toEqual({
bundleId: "b-1",
versionId: "v-2",
});
});

test("update uses the same explicit branch for the parent lookup and update", 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",
{
branchName: "review-branch",
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",
branchName: "review-branch",
});
expect(sent[1]).toBeInstanceOf(UpdateConfigurationBundleCommand);
expect((sent[1] as UpdateConfigurationBundleCommand).input).toEqual({
bundleId: "b-1",
branchName: "review-branch",
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",
{
branchName: "mainline",
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);
expect((sent[0] as GetConfigurationBundleCommand).input).toEqual({
bundleId: "b-1",
branchName: "mainline",
});
});
});
97 changes: 97 additions & 0 deletions src/core/eval.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
import {
CreateConfigurationBundleCommand,
CreateDatasetCommand,
CreateDatasetVersionCommand,
CreateEvaluatorCommand,
CreateOnlineEvaluationConfigCommand,
DeleteConfigurationBundleCommand,
DeleteDatasetCommand,
DeleteEvaluatorCommand,
DeleteOnlineEvaluationConfigCommand,
GetConfigurationBundleCommand,
GetConfigurationBundleVersionCommand,
GetAgentRuntimeCommand,
GetDatasetCommand,
GetEvaluatorCommand,
GetHarnessCommand,
GetOnlineEvaluationConfigCommand,
ListConfigurationBundlesCommand,
ListConfigurationBundleVersionsCommand,
ListDatasetsCommand,
ListEvaluatorsCommand,
ListOnlineEvaluationConfigsCommand,
UpdateConfigurationBundleCommand,
UpdateEvaluatorCommand,
UpdateOnlineEvaluationConfigCommand,
type CreateConfigurationBundleResponse,
type CreateDatasetResponse,
type CreateDatasetVersionResponse,
type CreateEvaluatorRequest,
type CreateEvaluatorResponse,
type CreateOnlineEvaluationConfigResponse,
type DeleteConfigurationBundleResponse,
type DeleteDatasetResponse,
type DeleteEvaluatorResponse,
type DeleteOnlineEvaluationConfigResponse,
type EvaluatorConfig,
type GetConfigurationBundleResponse,
type GetConfigurationBundleVersionResponse,
type GetDatasetResponse,
type GetEvaluatorResponse,
type GetOnlineEvaluationConfigResponse,
type ListConfigurationBundlesResponse,
type ListConfigurationBundleVersionsResponse,
type ListDatasetsResponse,
type ListEvaluatorsResponse,
type DataSourceConfig,
type ListOnlineEvaluationConfigsResponse,
type Rule,
type UpdateConfigurationBundleResponse,
type UpdateEvaluatorResponse,
type UpdateOnlineEvaluationConfigResponse,
type BedrockAgentCoreControlClient,
Expand All @@ -53,12 +67,14 @@ import type {
CodeBasedUpdate,
RoleScopeWarning,
CoreEvalClient,
CreateConfigurationBundleInput,
CreateDatasetInput,
CreateOnlineEvalInput,
GetBatchEvaluationResult,
LlmAsAJudgeUpdate,
SessionSourceValue,
StartBatchEvaluationInput,
UpdateConfigurationBundleInput,
UpdateOnlineEvalInput,
} from "../handlers/eval/types";
import { atomicWriteStream } from "../io";
Expand Down Expand Up @@ -601,6 +617,87 @@ export class EvalClient implements CoreEvalClient {
.send(new DeleteOnlineEvaluationConfigCommand({ onlineEvaluationConfigId: id }));
}

async createConfigurationBundle(
input: CreateConfigurationBundleInput,
options: CoreOptions,
): Promise<CreateConfigurationBundleResponse> {
return this.clients
.control(toClientConfig(options))
.send(new CreateConfigurationBundleCommand(input));
}

async getConfigurationBundle(
id: string,
version: string | undefined,
branchName: string,
options: CoreOptions,
): Promise<GetConfigurationBundleResponse | GetConfigurationBundleVersionResponse> {
const control = this.clients.control(toClientConfig(options));
return version === undefined
? control.send(new GetConfigurationBundleCommand({ bundleId: id, branchName }))
: control.send(
new GetConfigurationBundleVersionCommand({ bundleId: id, versionId: version }),
);
}

async listConfigurationBundles(
nextToken: string | undefined,
maxResults: number | undefined,
options: CoreOptions,
): Promise<ListConfigurationBundlesResponse> {
return this.clients
.control(toClientConfig(options))
.send(new ListConfigurationBundlesCommand({ nextToken, maxResults }));
}

async updateConfigurationBundle(
id: string,
update: UpdateConfigurationBundleInput,
options: CoreOptions,
): Promise<UpdateConfigurationBundleResponse> {
const control = this.clients.control(toClientConfig(options));
const current = await control.send(
new GetConfigurationBundleCommand({ bundleId: id, branchName: update.branchName }),
);
if (!current.versionId) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the internal service model, this is required. I don't know why aws sdk v3 has all required response parameters as | undefined.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I saw the field was required, but the SDK type has string | undefined. I added this check to follow the service model

throw new NetworkingError(
`Configuration bundle "${id}" returned no latest version and cannot be updated`,
{ meta: { bundleId: id } },
);
}

return control.send(
new UpdateConfigurationBundleCommand({
bundleId: id,
branchName: update.branchName,
components: update.components,
commitMessage: update.commitMessage,
kmsKeyArn: update.kmsKeyArn,
parentVersionIds: [current.versionId],
}),
);
}

async deleteConfigurationBundle(
id: string,
options: CoreOptions,
): Promise<DeleteConfigurationBundleResponse> {
return this.clients
.control(toClientConfig(options))
.send(new DeleteConfigurationBundleCommand({ bundleId: id }));
}

async listConfigurationBundleVersions(
id: string,
nextToken: string | undefined,
maxResults: number | undefined,
options: CoreOptions,
): Promise<ListConfigurationBundleVersionsResponse> {
return this.clients
.control(toClientConfig(options))
.send(new ListConfigurationBundleVersionsCommand({ bundleId: id, nextToken, maxResults }));
}

async createDataset(
input: CreateDatasetInput,
options: CoreOptions,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"bundleArn": "arn:aws:bedrock-agentcore:us-west-2:685197708687:configuration-bundle/agentcore_cli_config_bundle_fixture-s03KQeHM93",
"bundleId": "agentcore_cli_config_bundle_fixture-s03KQeHM93",
"versionId": "c67c8477-9b51-4bfc-92c4-36b7f2cdcbdc",
"createdAt": {
"$date": "2026-08-13T14:04:44.109Z"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"bundleId": "agentcore_cli_config_bundle_fixture-s03KQeHM93",
"status": "DELETING"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"bundleId": "agentcore_cli_config_bundle_fixture-8R7L5N9Wyh",
"status": "DELETING"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"bundleArn": "arn:aws:bedrock-agentcore:us-west-2:685197708687:configuration-bundle/agentcore_cli_config_bundle_fixture-8R7L5N9Wyh",
"bundleId": "agentcore_cli_config_bundle_fixture-8R7L5N9Wyh",
"bundleName": "agentcore_cli_config_bundle_fixture",
"versionId": "93a10f5c-2ffa-4895-93ff-f6b64b3515ad",
"components": {
"arn:aws:bedrock-agentcore:us-west-2:314146320088:runtime/stmFixes_StmFixesAgent-XsFfJU4cAp": {
"configuration": {
"settings": {
"revision": 1
},
"system_prompt": "Configuration bundle fixture version one."
}
}
},
"createdAt": {
"$date": "2026-08-13T13:58:48.269Z"
},
"updatedAt": {
"$date": "2026-08-13T13:58:48.269Z"
},
"lineageMetadata": {
"parentVersionIds": [],
"branchName": "mainline"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"bundleArn": "arn:aws:bedrock-agentcore:us-west-2:685197708687:configuration-bundle/agentcore_cli_config_bundle_fixture-s03KQeHM93",
"bundleId": "agentcore_cli_config_bundle_fixture-s03KQeHM93",
"bundleName": "agentcore_cli_config_bundle_fixture",
"versionId": "c67c8477-9b51-4bfc-92c4-36b7f2cdcbdc",
"components": {
"arn:aws:bedrock-agentcore:us-west-2:314146320088:runtime/stmFixes_StmFixesAgent-XsFfJU4cAp": {
"configuration": {
"settings": {
"revision": 1
},
"system_prompt": "Configuration bundle fixture version one."
}
}
},
"createdAt": {
"$date": "2026-08-13T14:04:44.109Z"
},
"updatedAt": {
"$date": "2026-08-13T14:04:44.109Z"
},
"lineageMetadata": {
"parentVersionIds": [],
"branchName": "mainline"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"bundleArn": "arn:aws:bedrock-agentcore:us-west-2:685197708687:configuration-bundle/agentcore_cli_config_bundle_fixture-s03KQeHM93",
"bundleId": "agentcore_cli_config_bundle_fixture-s03KQeHM93",
"bundleName": "agentcore_cli_config_bundle_fixture",
"versionId": "c67c8477-9b51-4bfc-92c4-36b7f2cdcbdc",
"components": {
"arn:aws:bedrock-agentcore:us-west-2:314146320088:runtime/stmFixes_StmFixesAgent-XsFfJU4cAp": {
"configuration": {
"settings": {
"revision": 1
},
"system_prompt": "Configuration bundle fixture version one."
}
}
},
"createdAt": {
"$date": "2026-08-13T14:04:44.109Z"
},
"versionCreatedAt": {
"$date": "2026-08-13T14:04:44.109Z"
},
"lineageMetadata": {
"parentVersionIds": [],
"branchName": "mainline"
}
}
Loading
Loading