Skip to content

Commit cd03f1b

Browse files
committed
fix: reject stale Plan v1 SDK options
1 parent b4bf0cc commit cd03f1b

4 files changed

Lines changed: 61 additions & 1 deletion

File tree

‎packages/aws-lambda/src/sdk/renderToLambda.test.ts‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ const CURRENT_DEFINITION = JSON.stringify({
2222

2323
class FakeSFN {
2424
starts: CapturedStart[] = [];
25+
describes = 0;
2526
definition = CURRENT_DEFINITION;
2627
async send(command: unknown): Promise<unknown> {
2728
const cmdName = (command as { constructor: { name: string } }).constructor.name;
28-
if (cmdName === "DescribeStateMachineCommand") return { definition: this.definition };
29+
if (cmdName === "DescribeStateMachineCommand") {
30+
this.describes++;
31+
return { definition: this.definition };
32+
}
2933
if (cmdName === "StartExecutionCommand") {
3034
const input = (command as { input: { stateMachineArn: string; name: string; input: string } })
3135
.input;
@@ -66,6 +70,27 @@ afterEach(() => {
6670
});
6771

6872
describe("renderToLambda", () => {
73+
it("rejects a stale v1 SDK option before any AWS work", async () => {
74+
const sfn = new FakeSFN();
75+
const s3 = new FakeS3();
76+
const staleOptions = {
77+
projectDir,
78+
bucketName: "test-bucket",
79+
stateMachineArn: "arn:aws:states:us-east-1:1234:stateMachine:hf",
80+
config: baseConfig,
81+
planProtocol: "v1",
82+
sfn: asSFNClient(sfn),
83+
s3: asS3Client(s3),
84+
};
85+
86+
await expect(renderToLambda(staleOptions)).rejects.toMatchObject({
87+
name: "PLAN_PROTOCOL_UNSUPPORTED",
88+
});
89+
expect(sfn.describes).toBe(0);
90+
expect(sfn.starts).toHaveLength(0);
91+
expect(s3.ops).toHaveLength(0);
92+
});
93+
6994
it("returns a handle and starts a state-machine execution with the right input", async () => {
7095
const sfn = new FakeSFN();
7196
const s3 = new FakeS3();

‎packages/aws-lambda/src/sdk/renderToLambda.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,20 @@ export interface RenderHandle {
7575
startedAt: string;
7676
}
7777

78+
function rejectUnsupportedLegacyPlanProtocol(opts: object): void {
79+
const planProtocol = Reflect.get(opts, "planProtocol");
80+
if (planProtocol === undefined || planProtocol === "v2") return;
81+
82+
const error = new Error(
83+
`[renderToLambda] planProtocol is no longer configurable; expected "v2" or absent, got ${JSON.stringify(planProtocol)}`,
84+
);
85+
error.name = "PLAN_PROTOCOL_UNSUPPORTED";
86+
throw error;
87+
}
88+
7889
// fallow-ignore-next-line complexity
7990
export async function renderToLambda(opts: RenderToLambdaOptions): Promise<RenderHandle> {
91+
rejectUnsupportedLegacyPlanProtocol(opts);
8092
validateDistributedRenderConfig(opts.config);
8193

8294
if (!opts.bucketName) {

‎packages/gcp-cloud-run/src/sdk/renderToCloudRun.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ function opts(executions: ExecutionsClientLike) {
5757
}
5858

5959
describe("renderToCloudRun", () => {
60+
it("rejects a stale v1 SDK option before any GCP work", async () => {
61+
const fake = new FakeExecutions();
62+
const staleOptions = { ...opts(fake), planProtocol: "v1" };
63+
64+
await expect(renderToCloudRun(staleOptions)).rejects.toMatchObject({
65+
name: "PLAN_PROTOCOL_UNSUPPORTED",
66+
});
67+
expect(fake.lastArgument).toBeNull();
68+
expect(fake.lastParent).toBeNull();
69+
});
70+
6071
it("starts an execution and returns a handle", async () => {
6172
const fake = new FakeExecutions();
6273
const handle = await renderToCloudRun(opts(fake));

‎packages/gcp-cloud-run/src/sdk/renderToCloudRun.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,20 @@ export interface RenderHandle {
9797
startedAt: string;
9898
}
9999

100+
function rejectUnsupportedLegacyPlanProtocol(opts: object): void {
101+
const planProtocol = Reflect.get(opts, "planProtocol");
102+
if (planProtocol === undefined || planProtocol === "v2") return;
103+
104+
const error = new Error(
105+
`[renderToCloudRun] planProtocol is no longer configurable; expected "v2" or absent, got ${JSON.stringify(planProtocol)}`,
106+
);
107+
error.name = "PLAN_PROTOCOL_UNSUPPORTED";
108+
throw error;
109+
}
110+
100111
// fallow-ignore-next-line complexity
101112
export async function renderToCloudRun(opts: RenderToCloudRunOptions): Promise<RenderHandle> {
113+
rejectUnsupportedLegacyPlanProtocol(opts);
102114
validateDistributedRenderConfig(opts.config);
103115

104116
if (!opts.bucketName) throw new Error("[renderToCloudRun] bucketName is required");

0 commit comments

Comments
 (0)