Skip to content

Add linter rule arm-post-lro-response-mismatch for ARM POST LRO operations#4145

Draft
Copilot wants to merge 41 commits into
mainfrom
copilot/add-linter-for-arm-post-lro
Draft

Add linter rule arm-post-lro-response-mismatch for ARM POST LRO operations#4145
Copilot wants to merge 41 commits into
mainfrom
copilot/add-linter-for-arm-post-lro

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 28, 2026

  • New rule arm-post-lro-response-mismatch for ARM POST LRO operations
  • Response-based checking logic driven by HTTP status codes:
    • If 200 response exists: non-void body must match finalResult; void/empty body means finalResult should be "void"
    • If 204 without 200: finalResult should be "void"
    • If both 200 (void body) and 204: finalResult should be "void"
    • If both 200 (non-void body) and 204: emit new conflictingResponses diagnostic (POST should not have both 204 NoContent and 200 OK with a non-empty body)
    • If only 202: check template instantiation of Azure.ResourceManager.ActionAsync (fully-qualified name) for Response param match with finalResult
  • doesFinalResultMatch checks both namespace-qualified name equality (for named types) and isAssignableTo from typekit for type compatibility
  • Void matching: "void" finalResult is compared against TypeSpec builtin void type via isVoidType
  • Uses resolveArmResources for both resource-level and provider-level actions
  • Codefix arm-post-lro-set-final-result using ArmLroLocationHeader<FinalResult = ResponseType>
  • Tests use ...ResourceNameParameter<Employee> throughout
  • Tests refactored to use it.each for parameterized type matching/non-matching scenarios
  • Low-level (non-template) tests use ArmAcceptedLroResponse for proper LRO constructs: invalid case (200 with Model body + ArmAcceptedLroResponse) and valid case (204 + ArmAcceptedLroResponse)
  • Tests cover: 200 body mismatch, 204 void check, ArmResourceActionAsyncBase with 200 body check, ActionAsync 202-only template check, low-level non-template LRO operations with ArmAcceptedLroResponse, conflicting 200+204 responses, and codefix
  • All tests pass, files formatted correctly
  • Documentation page added for the rule
  • Merged latest from main, regenerated docs — only PR-related files differ

💡 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.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the lib:azure-resource-manager Issues for @azure-tools/typespec-azure-core library label Mar 28, 2026
…-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>
Copilot AI changed the title [WIP] Add a linter to check Response value matches FinalResult for ARM LRO POST Add linter rule arm-post-lro-response-mismatch for ARM POST LRO operations Mar 28, 2026
Copilot AI requested a review from markcowl March 28, 2026 00:57
Copy link
Copy Markdown
Member

@markcowl markcowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Pull the latest from main and then apply the fixes in the comments. Ensure that all tests pass and all files are correctly formatted.

Copilot AI and others added 2 commits March 31, 2026 18:30
…r-arm-post-lro

Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 31, 2026

@copilot Pull the latest from main and then apply the fixes in the comments. Ensure that all tests pass and all files are correctly formatted.

Pulled latest from main, applied all review fixes, and verified all 286 tests pass with correct formatting. Changes in a9c28e6.

Copilot AI requested a review from markcowl March 31, 2026 18:58
@markcowl
Copy link
Copy Markdown
Member

@copilot Please pull the latest from main, regenrate docs for tyepspec-azure-resource-manager, validate that all files are correctly formatted.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 31, 2026

@copilot Please pull the latest from main, regenrate docs for tyepspec-azure-resource-manager, validate that all files are correctly formatted.

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.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the meta:website TypeSpec.io updates label Mar 31, 2026
Copy link
Copy Markdown
Member

@markcowl markcowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pull the latest from main, make the changes suggested, ensure all tests are passing and all files are correctly formatted.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 31, 2026

Please pull the latest from main, make the changes suggested, ensure all tests are passing and all files are correctly formatted.

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.

Copilot AI requested a review from markcowl March 31, 2026 20:28
Copy link
Copy Markdown
Member

@markcowl markcowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 8, 2026

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.

Done in 4d9b3b2. Pulled latest from main (up to date), replaced the invalid low-level test with two proper tests using ArmAcceptedLroResponse, all 316 tests pass, files formatted, only PR-related files in the diff.

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:

  • telemetry.astro.build
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/typespec-azure/typespec-azure/core/website/node_modules/.bin/../astro/bin/astro.mjs build node st/cli.mjs tput-dir ../../w--llmstxt --local 3731f02ab20a8e7f90b3a6c19ec11742cdb34dfedd95843c0a3d6fa792fd99/node_modules/pnpm/dist/node-gyp-btspd doc . --enable-experimental --output-dir ../../website/src/content/docs/docs/emitters/clients/http-client-js/reference --skip-js --no-emit sh 3731f02ab20a8e7fgenerate-scenarios-summary uname 3731�� build.json sh /typespec-azure/core/node_module--output-dir --no-emit p.blob --sentine-c rsioning/referentsx ./.scripts/regen-compiler-docs.ts sh (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from markcowl May 8, 2026 03:26
@markcowl
Copy link
Copy Markdown
Member

markcowl commented May 8, 2026

/azp run typespec-azure - PR Tools

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Copy Markdown
Member

@markcowl markcowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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 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.

Copilot AI and others added 3 commits May 13, 2026 00:31
…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>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 13, 2026

@copilot We need to reformulate how this check works:

  • When checking POST operations that are long-running:...

Fixed in 6f16aad. Reformulated the rule to check based on HTTP response status codes per the specified logic:

  • 200 response with non-void body → must match finalResult
  • 200 response with void/empty body → finalResult should be void
  • 204 without 200 → finalResult should be void
  • Both 200 (void body) and 204 → finalResult should be void
  • Both 200 (non-void body) and 204 → emits new conflictingResponses diagnostic
  • Only 202 → checks ActionAsync template instantiation for Response param match

Updated tests to match. All 324 tests pass, files formatted, only PR-related files in the diff.

Copilot AI requested a review from markcowl May 13, 2026 00:49
Copy link
Copy Markdown
Member

@markcowl markcowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 13, 2026

Pull the latest from main
Make the suggested changes
ensure all tests pass...

Done in b3074a5. Pulled latest from main (already up to date), fixed the template check to use the fully-qualified name Azure.ResourceManager.ActionAsync, all 324 tests pass, files formatted, only PR-related files in the diff.

Copilot AI requested a review from markcowl May 13, 2026 03:10
Copy link
Copy Markdown
Member

@markcowl markcowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI and others added 2 commits May 13, 2026 17:36
…r-arm-post-lro

Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 13, 2026

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 fo...

Added the documentation page at website/src/content/docs/docs/libraries/azure-resource-manager/rules/post-lro-response-mismatch.md in 092d912. Pulled latest from main, rebuilt the package, regenerated docs, formatted all files. All 324 tests pass, only PR-related files in the diff.

Copilot AI requested a review from markcowl May 13, 2026 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

int:azure-specs Run integration tests against azure-rest-api-specs lib:azure-resource-manager Issues for @azure-tools/typespec-azure-core library meta:website TypeSpec.io updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Linter] Add a linter to warn if the Response value doesn't match the FinalResult for ARM LRO POST

3 participants