-
Notifications
You must be signed in to change notification settings - Fork 78
feat: add Spector integration tests for Payload_Head and Payload_JsonMergePatch #4007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
02c794a
Initial plan
Copilot e51523c
feat: add Spector tests for Payload_Head and Payload_JsonMergePatch
Copilot 6096c03
feat: add explanatory comments for emitter limitations in Head and Js…
Copilot 90cb135
Merge branch 'main' into copilot/verify-implement-spector-tests
v-jiaodi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
packages/typespec-ts/test/azureModularIntegration/generated/payload/head/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /** | ||
| !/src | ||
| /src/** | ||
| !/src/index.d.ts | ||
| !/.gitignore | ||
| !/tspconfig.yaml |
24 changes: 24 additions & 0 deletions
24
packages/typespec-ts/test/azureModularIntegration/generated/payload/head/src/index.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { ClientOptions } from '@azure-rest/core-client'; | ||
| import { isRestError } from '@azure/core-rest-pipeline'; | ||
| import { OperationOptions } from '@azure-rest/core-client'; | ||
| import { Pipeline } from '@azure/core-rest-pipeline'; | ||
| import { RestError } from '@azure/core-rest-pipeline'; | ||
|
|
||
| export declare interface ContentTypeHeaderInResponseOptionalParams extends OperationOptions { | ||
| } | ||
|
|
||
| export declare class HeadClient { | ||
| private _client; | ||
| readonly pipeline: Pipeline; | ||
| constructor(options?: HeadClientOptionalParams); | ||
| contentTypeHeaderInResponse(options?: ContentTypeHeaderInResponseOptionalParams): Promise<void>; | ||
| } | ||
|
|
||
| export declare interface HeadClientOptionalParams extends ClientOptions { | ||
| } | ||
|
|
||
| export { isRestError } | ||
|
|
||
| export { RestError } | ||
|
|
||
| export { } |
13 changes: 13 additions & 0 deletions
13
packages/typespec-ts/test/azureModularIntegration/generated/payload/head/tspconfig.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| emit: | ||
| - "@azure-tools/typespec-ts" | ||
| options: | ||
| "@azure-tools/typespec-ts": | ||
| emitter-output-dir: "{project-root}" | ||
| generate-test: false | ||
| add-credentials: false | ||
| flavor: azure | ||
| azure-sdk-for-js: false | ||
| is-typespec-test: true | ||
| package-details: | ||
| name: "@msinternal/payload-head" | ||
| description: "Payload Head Test Service" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/typespec-ts/test/azureModularIntegration/payloadHead.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { describe, it, beforeEach } from "vitest"; | ||
| import { HeadClient } from "./generated/payload/head/src/index.js"; | ||
|
|
||
| describe("Payload Head Client", () => { | ||
| let client: HeadClient; | ||
|
|
||
| beforeEach(() => { | ||
| client = new HeadClient({ | ||
| endpoint: "http://localhost:3002", | ||
| allowInsecureConnection: true, | ||
| retryOptions: { | ||
| maxRetries: 0 | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| it("should call contentTypeHeaderInResponse", async () => { | ||
| // The generated client returns void for HEAD operations; response headers | ||
| // (Content-Type and x-ms-meta) are validated by the mock server (returns 200 | ||
| // only when the request is correct). No header assertions can be made here | ||
| // because the emitter does not expose response headers in the return type. | ||
| await client.contentTypeHeaderInResponse(); | ||
| }); | ||
| }); | ||
91 changes: 91 additions & 0 deletions
91
packages/typespec-ts/test/azureModularIntegration/payloadJsonMergePatch.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { assert, describe, it, beforeEach } from "vitest"; | ||
| import { JsonMergePatchClient } from "./generated/payload/json-merge-patch/src/index.js"; | ||
|
|
||
| describe("Payload JsonMergePatch Client", () => { | ||
| let client: JsonMergePatchClient; | ||
|
|
||
| beforeEach(() => { | ||
| client = new JsonMergePatchClient({ | ||
| endpoint: "http://localhost:3002", | ||
| allowInsecureConnection: true, | ||
| retryOptions: { | ||
| maxRetries: 0 | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| it("should createResource", async () => { | ||
| const body = { | ||
| name: "Madge", | ||
| description: "desc", | ||
| map: { | ||
| key: { | ||
| name: "InnerMadge", | ||
| description: "innerDesc" | ||
| } | ||
| }, | ||
| array: [{ name: "InnerMadge", description: "innerDesc" }], | ||
| intValue: 1, | ||
| floatValue: 1.25, | ||
| innerModel: { name: "InnerMadge", description: "innerDesc" }, | ||
| intArray: [1, 2, 3] | ||
| }; | ||
| const result = await client.createResource(body); | ||
| assert.strictEqual(result.name, "Madge"); | ||
| assert.strictEqual(result.description, "desc"); | ||
| assert.strictEqual(result.map?.["key"]?.name, "InnerMadge"); | ||
| assert.strictEqual(result.map?.["key"]?.description, "innerDesc"); | ||
| assert.deepEqual(result.array, [ | ||
| { name: "InnerMadge", description: "innerDesc" } | ||
| ]); | ||
| assert.strictEqual(result.intValue, 1); | ||
| assert.strictEqual(result.floatValue, 1.25); | ||
| assert.strictEqual(result.innerModel?.name, "InnerMadge"); | ||
| assert.strictEqual(result.innerModel?.description, "innerDesc"); | ||
| assert.deepEqual(result.intArray, [1, 2, 3]); | ||
| }); | ||
|
|
||
| it("should updateResource", async () => { | ||
| // null values are intentional: JSON merge-patch semantics require null to | ||
| // signal field removal. The generated ResourcePatch type uses optional (?) | ||
| // fields without null, so 'as any' is needed to pass the null values while | ||
| // still exercising the correct serialization path. | ||
| const body = { | ||
| description: null, | ||
| map: { | ||
| key: { description: null }, | ||
| key2: null | ||
| }, | ||
| array: null, | ||
| intValue: null, | ||
| floatValue: null, | ||
| innerModel: null, | ||
| intArray: null | ||
| }; | ||
| const result = await client.updateResource(body as any); | ||
| assert.strictEqual(result.name, "Madge"); | ||
| assert.strictEqual(result.map?.["key"]?.name, "InnerMadge"); | ||
| }); | ||
|
|
||
| it("should updateOptionalResource", async () => { | ||
| // null values are intentional: JSON merge-patch semantics require null to | ||
| // signal field removal. The generated ResourcePatch type uses optional (?) | ||
| // fields without null, so 'as any' is needed to pass the null values while | ||
| // still exercising the correct serialization path. | ||
| const body = { | ||
| description: null, | ||
| map: { | ||
| key: { description: null }, | ||
| key2: null | ||
| }, | ||
| array: null, | ||
| intValue: null, | ||
| floatValue: null, | ||
| innerModel: null, | ||
| intArray: null | ||
| }; | ||
| const result = await client.updateOptionalResource({ body: body as any }); | ||
| assert.strictEqual(result.name, "Madge"); | ||
| assert.strictEqual(result.map?.["key"]?.name, "InnerMadge"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot create issue for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have the ability to create GitHub issues directly. Please create an issue with the following details:
Title:
[Emitter] HEAD operations should surface response headers in the return typeDescription:
The TypeSpec emitter generates
Promise<void>for HEAD operations (e.g.HeadClient.contentTypeHeaderInResponse()), which means response headers (Content-Type,x-ms-meta) are not accessible from the returned value. This is an emitter limitation — the TypeSpec spec defines these headers as part of the response, but the generated SDK discards them.Scenario:
Payload_Head / contentTypeHeaderInResponse(payload/head/content-type-header-in-response)Expected behavior: The generated method should return an object containing the response headers, e.g.:
Actual behavior: Returns
Promise<void>, making header assertions impossible in integration tests.Related test:
packages/typespec-ts/test/azureModularIntegration/payloadHead.spec.ts