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
14 changes: 12 additions & 2 deletions src/core/project/backends/cdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,18 @@ describe("CdkBackend.resolveDeployedResources", () => {
const resources = await subject.backend.resolveDeployedResources(input, { target: TARGET });

expect(resources).toEqual([
{ resourceType: "runtime", name: "checkout_agent", id: "checkout_agent-AbCdEf1234" },
{ resourceType: "harness", name: "support_agent", id: "support_agent-AbCdEf1234" },
{
resourceType: "runtime",
name: "checkout_agent",
id: "checkout_agent-AbCdEf1234",
target: TARGET,
},
{
resourceType: "harness",
name: "support_agent",
id: "support_agent-AbCdEf1234",
target: TARGET,
},
]);
expect(subject.stackReads).toHaveLength(1);
});
Expand Down
8 changes: 4 additions & 4 deletions src/core/project/backends/cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { join } from "node:path";
import type { Stack } from "@aws-sdk/client-cloudformation";
import { MalformedServiceResponseError, ProjectStateError } from "../../../errors/errors";
import type {
DeployedProjectResource,
DeployResult,
Project,
ProjectEvent,
ResolvedDeployedResource,
} from "../../../handlers/project/types";
import {
FsReadWriteJson,
Expand Down Expand Up @@ -53,7 +53,7 @@ type StackDescriber = typeof describeStack;

function findDeployedResourceId(
stack: Stack,
input: Pick<DeployedProjectResource, "resourceType" | "name">,
input: Pick<ResolvedDeployedResource, "resourceType" | "name">,
): string | undefined {
if (!stack.StackName) return undefined;
const exportResourceName = input.name.replaceAll("_", "-");
Expand Down Expand Up @@ -265,7 +265,7 @@ export class CdkBackend implements ProjectBackend {
public async resolveDeployedResources(
project: Project,
input: ResolveDeployedResourcesBackendInput,
): Promise<DeployedProjectResource[]> {
): Promise<ResolvedDeployedResource[]> {
const { target } = input;
const deployedState = await readDeployedState(this.json, project.rootPath);
const stackArn = deployedState.targets[target.name]?.stackArn;
Expand All @@ -291,7 +291,7 @@ export class CdkBackend implements ProjectBackend {
];
return resources.flatMap((resource) => {
const id = findDeployedResourceId(stack, resource);
return id ? [{ ...resource, id }] : [];
return id ? [{ ...resource, id, target }] : [];
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/project/backends/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type {
DeployedProjectResource,
DeployResult,
Project,
ProjectEvent,
ResolvedDeployedResource,
TeardownConfirmationHandler,
} from "../../../handlers/project/types";
import type { AwsDeploymentTarget } from "../../../projectSchemas/aws-targets";
Expand All @@ -25,5 +25,5 @@ export interface ProjectBackend {
resolveDeployedResources(
project: Project,
input: ResolveDeployedResourcesBackendInput,
): Promise<DeployedProjectResource[]>;
): Promise<ResolvedDeployedResource[]>;
}
5 changes: 4 additions & 1 deletion src/core/project/manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,10 @@ export class FsProjectManager implements ProjectManager {
const resource = resolved.resources.find(
({ resourceType, name }) => resourceType === input.resourceType && name === input.name,
);
if (resource) return { id: resource.id, target: resolved.target };
// The declared target wins over the copy on the item: the manager resolved it
// from aws-targets.json, and both invoke handlers pin the AWS region off this
// value, so trusting a backend's echo would let it redirect the call.
if (resource) return { ...resource, target: resolved.target };

const label = input.resourceType === "runtime" ? "Runtime" : "Harness";
throw new ProjectStateError(
Expand Down
2 changes: 2 additions & 0 deletions src/handlers/project/invoke/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ function backend() {
resourceType: "runtime" as const,
name,
id: RUNTIME_ID,
target: input.target,
})),
...project.spec.harnesses.map(({ name }) => ({
resourceType: "harness" as const,
name,
id: HARNESS_ID,
target: input.target,
})),
];
},
Expand Down
14 changes: 8 additions & 6 deletions src/handlers/project/invoke/invoke.screen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
import { ProjectSpecSchema } from "../../../projectSchemas/project";
import { ProjectKey } from "../../../router";
import { cleanupScreens, renderScreen, TestCoreClient, waitForText } from "../../../testing";
import type { DeployedProjectResource, Project } from "../types";
import type { Project, ResolvedDeployedResource } from "../types";

afterEach(cleanupScreens);

Expand Down Expand Up @@ -46,14 +46,16 @@ function endpoint(name: string): AgentRuntimeEndpoint {

const TARGET = { name: "default", account: "111122223333", region: "eu-west-1" } as const;

const DEPLOYED_RESOURCES: DeployedProjectResource[] = [
{ resourceType: "runtime", name: "checkout", id: "runtime-123" },
{ resourceType: "harness", name: "support", id: "harness-123" },
const DEPLOYED_RESOURCES: ResolvedDeployedResource[] = [
{ resourceType: "runtime", name: "checkout", id: "runtime-123", target: TARGET },
{ resourceType: "harness", name: "support", id: "harness-123", target: TARGET },
];

function core(resources: DeployedProjectResource[] = DEPLOYED_RESOURCES): TestCoreClient {
function core(resources: ResolvedDeployedResource[] = DEPLOYED_RESOURCES): TestCoreClient {
const value = new TestCoreClient();
value.projectManager.resolveDeployedResource = async (_project, input) => ({
resourceType: input.resourceType,
name: input.name,
id: input.resourceType === "runtime" ? "runtime-123" : "harness-123",
target: TARGET,
});
Expand All @@ -76,7 +78,7 @@ function core(resources: DeployedProjectResource[] = DEPLOYED_RESOURCES): TestCo
describe("project invoke picker", () => {
test("lists only resources present in the deployed target", async () => {
const screen = renderScreen("/agentcore/project/invoke", {
core: core([{ resourceType: "harness", name: "support", id: "harness-123" }]),
core: core([{ resourceType: "harness", name: "support", id: "harness-123", target: TARGET }]),
withContext: (ctx) => ctx.withValue(ProjectKey, project),
});

Expand Down
8 changes: 2 additions & 6 deletions src/handlers/project/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,15 @@ export type ResolveDeployedResourcesInput = {
target: string;
};

export type DeployedProjectResource = {
export type ResolvedDeployedResource = {
resourceType: ProjectInvokableResource;
name: string;
id: string;
};

export type ResolvedDeployedResource = {
id: string;
target: AwsDeploymentTarget;
};

export type ResolvedDeployedResources = {
resources: DeployedProjectResource[];
resources: ResolvedDeployedResource[];
target: AwsDeploymentTarget;
};

Expand Down
Loading