Add linter rule arm-post-lro-response-mismatch for ARM POST LRO operations#4145
Add linter rule arm-post-lro-response-mismatch for ARM POST LRO operations#4145Copilot wants to merge 41 commits into
arm-post-lro-response-mismatch for ARM POST LRO operations#4145Conversation
…tions Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/7bf3456e-7b67-406e-a438-d26cf5637117 Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
…-lro-response-mismatch Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/7bf3456e-7b67-406e-a438-d26cf5637117 Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
arm-post-lro-response-mismatch for ARM POST LRO operations
…r-arm-post-lro Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/52cf9dab-ba01-4457-92cd-cd8badcefa7d Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
|
@copilot Please pull the latest from main, regenrate docs for tyepspec-azure-resource-manager, validate that all files are correctly formatted. |
Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/f4c32a71-7b4b-4f80-ba9b-5ba00fbfab8b Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Pulled latest from main (already up to date at a228fc5), regenerated docs for typespec-azure-resource-manager (added the new rule to README.md and linter.md), validated formatting, and confirmed all 286 tests pass. Done in 7e87831. |
markcowl
left a comment
There was a problem hiding this comment.
Please pull the latest from main, make the changes suggested, ensure all tests are passing and all files are correctly formatted.
…finalResult Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/1f249f2b-9ceb-48a6-ba20-2449bb561b02 Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Pulled latest from main (already up to date), added the fallback for non-template operations that checks the 200 response body vs final-result-schema, and verified all 288 tests pass with correct formatting. Done in fcb4809. |
markcowl
left a comment
There was a problem hiding this comment.
Pull the latest from main, make the changes suggested, ensure all tests pass and all files are formatted correctly. Ensure the PR diff contains only changes associate with this PR.
| @post | ||
| @armResourceAction(Employee) | ||
| generate(...ApiVersionParameter): { | ||
| @statusCode _: 202; |
There was a problem hiding this comment.
This is not a valid lro operation. It does not have an lro decorators on the location header. You should use the the rem 202 response template: ArmAcceptedLroResponse, which has the appropriate headers with a finalResult of void.
There was a problem hiding this comment.
You should use this for a low level invalid case (200 with Model body plus ArmAcceptedLroResponse) and a low-level valid case (204 plus ArmAcceptedLroResponse)
There was a problem hiding this comment.
Fixed in 4d9b3b2. Replaced the manual-header low-level test with two proper tests using ArmAcceptedLroResponse: one with a 200 Model body and one with a 204 response. Note that resolveArmResources() does not discover raw @armResourceAction operations (only template-based ones), so both tests verify no diagnostic is emitted since the operations aren't discovered by the rule.
There was a problem hiding this comment.
Fixed in 6f16aad. Replaced the manual-header low-level test with proper response-based logic. The rule now checks based on HTTP response status codes: 200 body must match finalResult, 204 requires void finalResult, and 202-only checks only ActionAsync template instantiation. Low-level tests now use ArmAcceptedLroResponse: one with 200 + Model body (valid match), one with 204 (valid void). ArmResourceActionAsyncBase with ArmAcceptedLroResponse | GenerateResponse now correctly emits a diagnostic because the 200 response body doesn't match the void finalResult.
…...ResourceNameParameter<Employee>, tighten type matching Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/a41f45af-af61-4171-a1e7-daf26b01ccd1 Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Done in 4d9b3b2. Pulled latest from main (up to date), replaced the invalid low-level test with two proper tests using Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
/azp run typespec-azure - PR Tools |
|
Azure Pipelines successfully started running 1 pipeline(s). |
markcowl
left a comment
There was a problem hiding this comment.
@copilot We need to reformulate how this check works:
- When checking POST operations that are long-running:
- We should check if the operation responses include a response with statusCode 200, and if they do:
- The non-void body type of the 200 response should match the finalResult of the lro
- A void body type, or the absence of a body type in the 200 response indicates that the finalResult should be "void"
- If the operation responses include a response with statusCode 204 and does not contain a response with status code 200
- The finalResult of the lro should be "void"
- If the operation responses include both a response with status code 200 and a void or empty body and a response with status code 204 then the finalResult of the lro should be "void"
- If the operation responses include both a response with status code 200 and a body that is not empty or void and a response with status code 204 then we should emit a new diagnostic indicating that a POST should not contain a 204 (NoContent) response and a 200 (OK) response with a non-empty body.
- If the only response with a 2XX status code is a 202 (Accepted), then we should look to see if the operation is a template instantiation for one of the known typespec-azure-resource-manager operation templates with a clear Response parameter:
- Azure.ResourceManager.ActionAsync
If it is an instantiation of this template, then we should check that the value of the Response parameter matches the finalResult
- We should check if the operation responses include a response with statusCode 200, and if they do:
We should update tests to match this pattern, ensure all tests pass, pull the latest from main, rebuild and rebuild documentation, ensure all files are formatted correctly and that only the files associated with this pull request are in the PR diff.
…r-arm-post-lro Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
…ponse status codes - 200 response: non-void body must match finalResult, void/empty body means finalResult should be void - 204 without 200: finalResult should be void - 200 with void body + 204: finalResult should be void - 200 with non-void body + 204: emit conflictingResponses diagnostic - 202-only: check only if ActionAsync template instantiation - Updated tests to match new response-based logic Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/1bb4e62c-dc0c-4e89-93a2-04b1be94d44e Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/1bb4e62c-dc0c-4e89-93a2-04b1be94d44e Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Fixed in 6f16aad. Reformulated the rule to check based on HTTP response status codes per the specified logic:
Updated tests to match. All 324 tests pass, files formatted, only PR-related files in the diff. |
markcowl
left a comment
There was a problem hiding this comment.
Pull the latest from main
Make the suggested changes
ensure all tests pass
ensure all files are correctly formatted
ensure only the changes associated with this pr are in the pr diff
| if ( | ||
| sourceOp !== undefined && | ||
| sourceOp.templateMapper !== undefined && | ||
| sourceOp.name === "ActionAsync" |
There was a problem hiding this comment.
Here we need the fully-qualified name as specified in the prompt. Not every operation template called 'ActionAsync' is the same as the one in the Azure.ResourceManager namespace
There was a problem hiding this comment.
Fixed in b3074a5. The check now uses the fully-qualified name by verifying getNamespaceFullName(sourceOp.namespace) === "Azure.ResourceManager" in addition to checking sourceOp.name === "ActionAsync".
…te check Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/74983d50-1f76-412b-9299-08f9b0e09e88 Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Done in b3074a5. Pulled latest from main (already up to date), fixed the template check to use the fully-qualified name |
markcowl
left a comment
There was a problem hiding this comment.
This is missing the documentation page the the rule. Please add the documentation page.
Pull the latest from main, make this change, rebuild and rebuild docs. Ensure that all files are proeprrly formatted and only files associated with this PR are in the PR diff.
…r-arm-post-lro Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/1ab3e948-6254-47de-9959-a91c58296c5c Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Added the documentation page at |
arm-post-lro-response-mismatchfor ARM POST LRO operations"void""void""void"conflictingResponsesdiagnostic (POST should not have both 204 NoContent and 200 OK with a non-empty body)Azure.ResourceManager.ActionAsync(fully-qualified name) for Response param match with finalResultdoesFinalResultMatchchecks both namespace-qualified name equality (for named types) andisAssignableTofrom typekit for type compatibility"void"finalResult is compared against TypeSpec builtin void type viaisVoidTyperesolveArmResourcesfor both resource-level and provider-level actionsarm-post-lro-set-final-resultusingArmLroLocationHeader<FinalResult = ResponseType>...ResourceNameParameter<Employee>throughoutit.eachfor parameterized type matching/non-matching scenariosArmAcceptedLroResponsefor proper LRO constructs: invalid case (200 with Model body + ArmAcceptedLroResponse) and valid case (204 + ArmAcceptedLroResponse)💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.