Skip to content

Make @useFinalStateVia validation decorator-order independent for PUT operations#4394

Merged
timotheeguerin merged 10 commits into
mainfrom
copilot/fix-usefinalstatevia-decorator-order
May 12, 2026
Merged

Make @useFinalStateVia validation decorator-order independent for PUT operations#4394
timotheeguerin merged 10 commits into
mainfrom
copilot/fix-usefinalstatevia-decorator-order

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 7, 2026

@useFinalStateVia("original-uri") could incorrectly report invalid-final-state when @put was applied before/after it in a different order. The validator was effectively sensitive to decorator execution order instead of final operation shape.

  • Post-decorator validation for @useFinalStateVia

    • Moved @useFinalStateVia validation into a decorator post-validation callback (onTargetFinish).
    • This evaluates HTTP verb/final-state constraints after all decorators on the target operation are applied, removing order dependency.
  • Regression coverage for the reported ordering bug

    • Added a test for:
      • @put @useFinalStateVia("original-uri") on an LRO operation
    • Asserts no invalid-final-state diagnostic and confirms the override is stored as original-uri.
  • Behavioral impact

    • No rule semantics changed; only validation timing changed to match final decorated operation metadata.
@pollingOperation(bar)
@test @put @useFinalStateVia("original-uri")
op foo(): {};

@microsoft-github-policy-service microsoft-github-policy-service Bot added the lib:azure-core Issues for @azure-tools/typespec-azure-core library label May 7, 2026
Copilot AI changed the title [WIP] Fix @useFinalStateVia decorator to recognize put operations consistently Make @useFinalStateVia validation decorator-order independent for PUT operations May 7, 2026
Copilot AI requested a review from timotheeguerin May 7, 2026 14:39
Comment thread packages/typespec-azure-core/src/decorators/use-final-state-via.ts Outdated
Comment thread packages/typespec-azure-core/src/decorators/use-final-state-via.test.ts Outdated
Copilot AI and others added 4 commits May 7, 2026 18:07
Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/d6094bc1-183d-4852-9009-4382ff621a74

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/d6094bc1-183d-4852-9009-4382ff621a74

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/d6094bc1-183d-4852-9009-4382ff621a74

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Comment thread .chronus/changes/copilot-fix-usefinalstatevia-decorator-order-2026-4-7-18-6-39.md Outdated
Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/618a3a05-8004-439d-af10-6fde0d07caad

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
@timotheeguerin
Copy link
Copy Markdown
Member

@copilot run formatter

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 7, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@azure-tools/typespec-azure-core@4394

commit: 0c4b635

Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/ad275149-796e-4de5-9507-fb351ef41273

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

Copilot AI commented May 7, 2026

@copilot run formatter

Done in 93ef2cc. I ran the formatter and committed the resulting formatting-only update in use-final-state-via.test.ts.

@timotheeguerin timotheeguerin marked this pull request as ready for review May 7, 2026 18:46
@azure-sdk
Copy link
Copy Markdown
Collaborator

All changed packages have been documented.

  • @azure-tools/typespec-azure-core
Show changes

@azure-tools/typespec-azure-core - fix ✏️

Make @useFinalStateVia validation decorator-order independent for PUT operations.

@azure-sdk
Copy link
Copy Markdown
Collaborator

You can try these changes here

🛝 Playground 🌐 Website

@timotheeguerin
Copy link
Copy Markdown
Member

@copilot test are failing now


 FAIL   @azure-tools/typespec-autorest  test/lro.test.ts > typespec-autorest: Long-running Operations > Allows azure-async-operation override without headers for ARM PUT
AssertionError: Expected values to be strictly deep-equal:
+ actual - expected

  {
    'final-state-schema': '#/definitions/Widget',
+   'final-state-via': 'original-uri'
-   'final-state-via': 'azure-async-operation'
  }


- Expected
+ Received

  {
    "final-state-schema": "#/definitions/Widget",
-   "final-state-via": "azure-async-operation",
+   "final-state-via": "original-uri",
  }

 ❯ test/lro.test.ts:304:5
    302|       "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupNa…
    303|     deepStrictEqual(openapi.paths[itemPath].put?.["x-ms-long-running-o…
    304|     deepStrictEqual(openapi.paths[itemPath].put["x-ms-long-running-ope…
       |     ^
    305|       "final-state-via": "azure-async-operation",
    306|       "final-state-schema": "#/definitions/Widget",

i believe the validate does more than just validating we might need to split the data registration from the validaiton

…ation

Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/b6a9de46-bad2-48af-9447-ff690a8da0a1

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

Copilot AI commented May 8, 2026

@copilot test are failing now

...

Fixed in 0c4b635. I restored the PUT-specific override registration in onTargetFinish (storedValue !== undefined || operation.verb === "put"), so @useFinalStateVia("azure-async-operation") is preserved for ARM PUT even when headers are missing. I also validated with targeted tests: typespec-autorest/test/lro.test.ts (the failing case) and typespec-azure-core/src/decorators/use-final-state-via.test.ts.

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: /opt/hostedtoolcache/node/22.22.2/x64/bin/node node /home/REDACTED/work/typespec-azure/typespec-azure/core/website/node_modules/.bin/../astro/bin/astro.mjs build node enap�� run --local n/node import @typespecnode sh ents/reference node core�� build.json sh tp-server-js/node_modules/.bin/sh pm run lint-typenode sh tobuf/reference sh (dns block)

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

@timotheeguerin timotheeguerin added the int:azure-specs Run integration tests against azure-rest-api-specs label May 12, 2026
@timotheeguerin timotheeguerin added this pull request to the merge queue May 12, 2026
Merged via the queue into main with commit a90e3a0 May 12, 2026
23 checks passed
@timotheeguerin timotheeguerin deleted the copilot/fix-usefinalstatevia-decorator-order branch May 12, 2026 16:16
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-core Issues for @azure-tools/typespec-azure-core library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: @useFinalStateVia decorator shouldn't rely on decorator order to figure out if operation is put

4 participants