fix(lambda): close the remaining contract validation gaps - #7241
Conversation
Follow-up to #7216, from review on the release PR. Every bound added here is one the AWS Lambda API reference documents; findings that asked for undocumented limits were left alone. Code source selection had two holes. `hasS3` required both S3 fields, so a partial pair alongside `imageUri` read as "image only" and the stray S3 field still went to AWS; and an `imageUri` with no `packageType` was accepted even though the package type then defaults to Zip. Both now fail at the boundary, naming the field to change, and the zip-only `s3ObjectVersion` and `sourceKmsKeyArn` count as S3 fields for the exclusivity check. The VPC guard only checked that both lists were supplied, so supplying both with one empty passed and produced a partial update. Both must now be empty (detach) or both populated (attach). Documented bounds added: - alias names: 1-128 and the documented pattern, which excludes all-digit names - descriptions: 256 characters - layer names: 140 characters and the name-or-ARN pattern - optional `functionName` on the event source mapping operations: 1-256 - `RemovePermission` statement IDs: 1-100 and its own pattern, which allows a dot where `AddPermission` does not Also rejects values that are structurally meaningless rather than merely out of range: empty tag keys, empty Kafka bootstrap servers, more than one weighted routing entry, and an event source mapping that supplies both an event source ARN and self-managed Kafka bootstrap servers.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThe PR tightens AWS Lambda request validation and aligns response projections with nullable or partially returned AWS fields.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the previously reported layer ARN validation defect is corrected at current HEAD.
|
| Filename | Overview |
|---|---|
| apps/sim/lib/api/contracts/tools/aws/lambda-get-layer-version.ts | The corrected layer-name regex accepts bare names and layer ARNs containing twelve-digit AWS account IDs. |
| apps/sim/lib/api/contracts/tools/aws/lambda-list-layer-versions.ts | The layer-listing contract uses the same corrected ARN validation as the get-layer-version contract. |
| apps/sim/lib/api/contracts/tools/aws/lambda-create-function.ts | Code-source and VPC validation now rejects mixed, incomplete, and structurally inconsistent inputs. |
| apps/sim/lib/api/contracts/tools/aws/lambda-shared.ts | Shared Lambda response schemas now reflect nullable AWS fields and additional projected event-source data. |
| apps/sim/lib/internal/lambda/execute-tool.test.ts | Regression tests cover valid layer-name forms and reject ARNs without a twelve-digit account segment. |
Reviews (5): Last reviewed commit: "test(lambda): prove every projection mat..." | Re-trigger Greptile
There was a problem hiding this comment.
2 issues found across 16 files
Confidence score: 3/5
- In
apps/sim/lib/api/contracts/tools/aws/lambda-get-layer-version.ts, the ARN regex rejects valid 12-digit account IDs, preventing documentedget-layer-versionrequests from succeeding; replace the literald{12}with\d{12}. - In
apps/sim/lib/api/contracts/tools/aws/lambda-create-function.ts, an empty optional S3 field can pass validation alongsideimageUribut still be forwarded to the create operation, causing inconsistent source selection; reject the field when present or reject empty values.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/sim/lib/api/contracts/tools/aws/lambda-get-layer-version.ts">
<violation number="1" location="apps/sim/lib/api/contracts/tools/aws/lambda-get-layer-version.ts:20">
P1: Valid layer ARN inputs are rejected because this regex uses literal `d{12}` instead of the digit escape. Replace it with `\d{12}` so `get-layer-version` accepts the ARN form documented by the contract.</violation>
</file>
<file name="apps/sim/lib/api/contracts/tools/aws/lambda-create-function.ts">
<violation number="1" location="apps/sim/lib/api/contracts/tools/aws/lambda-create-function.ts:52">
P2: When `imageUri` is accompanied by an optional S3 field set to `''`, this truthiness check treats the field as absent. The create operation still forwards defined empty source fields, so reject field presence or empty strings before sending the mixed code source to AWS.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
The account-ID segment was written as `\d{12}` inside a template literal, so the
emitted regex carried a literal `d{12}` and rejected every real layer ARN. The
existing test only covered an over-long name, which is why it passed.
Escapes the backslash and adds the coverage that would have caught it: a real
layer ARN and a bare layer name are both accepted, and an ARN whose account
segment is not twelve digits is rejected.
The mutual-exclusivity check used truthiness, so `imageUri` alongside `s3Bucket: ''` read as image-only while the create operation still forwarded the defined empty field to AWS. An empty string is meaningless for every code-source field, so each is now `.min(1)` at the contract rather than special-cased in the refinement.
|
@cubic review |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
1 issue found across 16 files
Confidence score: 3/5
- In
apps/sim/lib/api/contracts/tools/aws/lambda-create-event-source-mapping.ts, an emptyeventSourceArncan pass validation when bootstrap servers are provided, causing the executor to send bothEventSourceArn: ''andSelfManagedEventSourceto AWS; validate the field explicitly and add coverage for the empty-string case.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/sim/lib/api/contracts/tools/aws/lambda-create-event-source-mapping.ts">
<violation number="1" location="apps/sim/lib/api/contracts/tools/aws/lambda-create-event-source-mapping.ts:70">
P2: When `eventSourceArn` is an empty string and bootstrap servers are present, this truthiness check accepts the request and the executor sends both `EventSourceArn: ''` and `SelfManagedEventSource` to AWS. Check field presence (or reject empty `eventSourceArn`) so malformed requests fail contract validation instead of reaching AWS.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
An empty `eventSourceArn` alongside bootstrap servers slipped past the mutual-exclusivity check for the same reason the code-source fields did: the guard tests truthiness, so a defined-but-empty value reads as absent while the operation still forwards it. Rather than patch each field as it surfaces, every optional string field now rejects an empty value. The tool layer already drops `''` before it reaches a contract, so an empty value can only arrive from a malformed direct call, and forwarding it to AWS is never right. `description` is exempt: AWS documents it as "Minimum length of 0", so an empty value legitimately clears it. Both behaviours are covered by tests.
A comprehensive validation pass against the API reference found the previous commit's blanket "no empty optional strings" rule was wrong. Several Lambda parameters document an empty string as meaningful, and their patterns say so: KMSKeyArn, SourceKMSKeyArn, and DeadLetterConfig.TargetArn all carry `(arn:...)|()`, whose trailing alternative matches the empty string, and the on-success/on-failure destinations document `Minimum length of 0` with a pattern beginning `$|`. For each, empty is how the setting is cleared. The rule is now opt-in rather than opt-out: only the five fields feeding a truthiness-based cross-field check reject an empty value. That removes 47 constraints and leaves the ones that were actually reported. Also from the same pass: - Supplying an image URI no longer demands an explicit `packageType`. That subBlock is advanced with no default, so requiring it produced a 400 naming a control the user cannot see; the operation derives Image from the code source instead, and only an explicit Zip alongside an image is rejected. - `fileSystemConfigs` was the one projection without a null guard, so an omitted field vanished from the block output rather than reading null. - An absent function URL now maps to null instead of an empty string a workflow could build a request against. - GetFunction reports `tagsError`, so a partial tag-read failure is distinguishable from a function with no tags, and marks `configuration` nullable to match what the operation returns. - Event source mappings report `selfManagedKafkaBootstrapServers`, which could be set but never read back. - TagResource rejects an empty tag map instead of reporting "0 tags applied".
|
Ran a comprehensive validation pass over all 50 operations against the AWS Lambda API reference, and it found a regression I had introduced in The regression. That commit blanket-applied
For each of those, empty is how you clear the setting. 14 call sites across 4 parameter types, plus three more where the reference states The rule is now opt-in instead of opt-out: only the five fields feeding a truthiness-based cross-field check reject an empty value. Net 47 constraints removed, 0 added, with a regression test pinning that the clearable fields still accept My mistake was reaching for a sweeping default under review pressure after the same defect shape came up three times. A blanket rule applied to fields nobody examined is how you regress silently. Also fixed from the same pass, one of which was a real UX break:
Two findings I deliberately did not act on:
The pass confirmed the rest is sound: all 50 response projections match their contracts key-for-key, every SDK request field name is valid, the block/tool/contract three-way alignment has zero drift across all 50 operations, and every remaining numeric range, pattern, and enum matches the documented values. |
Reading code confirmed the projections and schemas agree, but nothing ran them against each other. This runs all eight shared mappers against their schemas in both directions: every declared key is emitted and non-undefined, no undeclared key is emitted, and the result parses — for an empty AWS response, which is the common case, and for a fully-populated one. Verified the suite fails when either defect class is reintroduced: a mapper that stops emitting a declared key, and a projection that leaks `undefined` where the schema declares a value.
Summary
hasS3required both S3 fields, so a partial pair alongsideimageUriread as "image only" and the stray field still reached AWS; and animageUriwith nopackageTypewas accepted even though it then defaults to ZipfunctionNameon the event source mapping operations (1–256), andRemovePermissionstatement IDs (1–100 plus its own pattern, which allows a dot whereAddPermissiondoes not)Every bound here is one the AWS Lambda API reference documents. Two review findings asked for constraints the reference does not state and were left alone — see the PR discussion for the reasoning.
Type of Change
Testing
bun run type-checkclean; all 39check:auditspass, plusdocs-manifest:checkand the block-registry checkChecklist