Add linter rule arm-post-lro-response-mismatch for ARM POST LRO operations#4145
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. |
Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
…r-arm-post-lro Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Raw operations decorated with @armResourceAction have simple HTTP paths (e.g. "/generate") that getResourceInfo cannot resolve into ARM resource type info. Previously these operations were silently dropped. Now, when getResourceInfo returns undefined for an operation, the code tries to match it against already-resolved resources by comparing the operation's resource model name against path segments. A deferred pass handles cases where the matching resource hasn't been resolved yet. Updated the low-level LRO test to expect the diagnostic (since the operation is now properly discovered). Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Done. Investigated and fixed the issue. Raw |
|
Hi @@copilot. Your PR has had no update for 14 days and it is marked as a stale PR. If it is not updated within 14 days, the PR will automatically be closed. If you want to refresh the PR, please remove the |
|
Hi @@copilot. This PR will be closed since it has had no update for 28 days. If this change is still relevant, please reopen the PR. |
|
@copilot Please pull the latest from main, ensure that all tests pass and all files are correctly formatted, and ensure that only the changes associated with this pr are in the pr diff/ |
…r-arm-post-lro Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Done in 42100f6. Pulled latest from main (merged cleanly), all 368 tests pass, all files formatted correctly, only PR-related files in the diff. |
| @@ -0,0 +1,363 @@ | |||
| import { | |||
There was a problem hiding this comment.
rename this rule to 'lro-response-mismatch"
There was a problem hiding this comment.
Renamed in commit that was just pushed. The rule is now lro-response-mismatch, and all files, const names, docs, tests, and references have been updated to match.
| /** | ||
| * Verify that the final result of an ARM LRO POST operation matches the Response parameter. | ||
| */ | ||
| export const armPostLroResponseMismatchRule = createRule({ |
There was a problem hiding this comment.
rename the rule to lro-response-mismatch and update the files and the associated name of this const, docs and tests to match
There was a problem hiding this comment.
Done in the latest commit. Rule renamed to lro-response-mismatch, file renamed to arm-lro-response-mismatch.ts, export renamed to armLroResponseMismatchRule, all docs/tests/references updated.
| export const armPostLroResponseMismatchRule = createRule({ | ||
| name: "arm-post-lro-response-mismatch", | ||
| severity: "warning", | ||
| url: "https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/post-lro-response-mismatch", |
There was a problem hiding this comment.
Need to add another check to ensure that the final response for a long-running PUT or PATCH matches the resource type and the final response for a delete operation matches void. This should add other messages
mismatchedPutOperation: The final result type of operation ${"operationName"} does not match the resource type. Please use standard Async templates or set the FinalResult type in the 201 response.
mismatchedPatchOperation: The final result type of operation ${"operationName"} does not match the resource type. Please use standard Async templates or set the FinalResult type in the 202 response.
mismatchedPDeleteOperation: The final result type of operation ${"operationName"} does not match the resource type. Please use standard Async templates or set the FinalResult type in the 202 response to void.
There was a problem hiding this comment.
@copilot also need to regen samples and ensure no errors
There was a problem hiding this comment.
Added in the latest commit. Three new message IDs:
mismatchedPutOperation: checkscreateOrUpdatelifecycle ops, final result must match resource typemismatchedPatchOperation: checksupdatelifecycle ops, final result must match resource typemismatchedDeleteOperation: checksdeletelifecycle ops, final result must be void
Tests added for each: valid cases using standard templates (ArmResourceCreateOrReplaceAsync, ArmResourcePatchAsync, ArmResourceDeleteWithoutOkAsync) and invalid cases with mismatched FinalResult. All 374 tests pass.
There was a problem hiding this comment.
Regenerated samples and fixed the rule to handle header-only models (like RetryAfterHeader and ArmCombinedLroHeaders) as effectively void from a body perspective. The isHeaderOnlyModel check ensures that models with only @header/@statusCode properties don't trigger a mismatch when the 200 response body is empty. All 69 sample tests pass with no errors, all 374 ARM package tests pass.
Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Done. Pulled latest from main (already up to date), renamed rule to |
…n samples Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
…main Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Done. Pulled latest from main (already up to date), removed codefix and all supporting code/tests, rewrote documentation as user-facing text, regenerated docs, formatted all files. All 372 tests pass, only PR-related files in the diff. |
|
@copilot there is a merge conflict, please pull the latest, resolve the conflict, make sure only the changes associated with this pr are in the pr diff and update the pr |
…r-arm-post-lro # Conflicts: # packages/typespec-azure-resource-manager/src/linter.ts Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Resolved the merge conflict in |
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>— handles:resolveArmResourceOperations: raw@armResourceActionoperations (with simple HTTP paths like/generate) are now properly discovered by matching against already-resolved resources when path-based resolution fails. Previously these operations were silently dropped becausegetResourceInfocouldn't derive ARM resource type info from relative paths....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.