Skip to content

Commit 3cecdbe

Browse files
Copilotv-jiaodi
andauthored
Add spector integration test for payload/head HEAD operation response headers (#4789)
HEAD operations with response-header-only return types were generating `Promise<void>`, making headers inaccessible in the returned value. The `payload/head` spec from `@typespec/http-specs` exercises this — a HEAD endpoint returning `Content-Type` and `x-ms-meta` headers. ## Changes - **`test/commands/spector-list.js`** — Register `payload/head` for client generation - **`test/azure-modular-integration/generated/payload/head/tspconfig.yaml`** — New tspconfig with `include-headers-in-response: true` to surface response headers in the return type - **`test/azure-modular-integration/generated/payload/head/src/index.d.ts`** — Generated declarations; `contentTypeHeaderInResponse` now returns `Promise<{ contentType?: string; metadata?: string }>` instead of `Promise<void>` - **`test/azure-modular-integration/payload-head.test.ts`** — Integration test asserting headers are accessible on the returned object ```typescript // Before: Promise<void> — headers inaccessible // After: with include-headers-in-response: true const result = await client.contentTypeHeaderInResponse(); assert.strictEqual(result.contentType, "text/plain; charset=utf-8"); assert.strictEqual(result.metadata, "hello"); ``` The `include-headers-in-response` option is opt-in; this test makes the per-service tspconfig the natural place to enable it, consistent with existing usage in the storage data-plane specs. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com>
1 parent f6e42f0 commit 3cecdbe

6 files changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: internal
3+
packages:
4+
- "@azure-tools/typespec-ts"
5+
---
6+
7+
Add spector integration test for `payload/head` HEAD operation with response headers, using `include-headers-in-response: true` to surface `contentType` and `metadata` headers in the return type.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
!/src
3+
/src/**
4+
!/src/index.d.ts
5+
!/.gitignore
6+
!/tspconfig.yaml
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { ClientOptions } from '@azure-rest/core-client';
2+
import { isRestError } from '@azure/core-rest-pipeline';
3+
import { OperationOptions } from '@azure-rest/core-client';
4+
import { Pipeline } from '@azure/core-rest-pipeline';
5+
import { RestError } from '@azure/core-rest-pipeline';
6+
7+
export declare interface ContentTypeHeaderInResponseOptionalParams extends OperationOptions {
8+
}
9+
10+
export declare class HeadClient {
11+
private _client;
12+
readonly pipeline: Pipeline;
13+
constructor(options?: HeadClientOptionalParams);
14+
contentTypeHeaderInResponse(options?: ContentTypeHeaderInResponseOptionalParams): Promise<{
15+
contentType?: string;
16+
metadata?: string;
17+
}>;
18+
}
19+
20+
export declare interface HeadClientOptionalParams extends ClientOptions {
21+
}
22+
23+
export { isRestError }
24+
25+
export { RestError }
26+
27+
export { }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
emit:
2+
- "@azure-tools/typespec-ts"
3+
options:
4+
"@azure-tools/typespec-ts":
5+
emitter-output-dir: "{project-root}"
6+
generate-metadata: true
7+
generate-test: false
8+
add-credentials: false
9+
flavor: azure
10+
include-headers-in-response: true
11+
package-details:
12+
name: "@msinternal/payload-head"
13+
description: "Payload Head Test Service"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { assert, beforeEach, describe, it } from "vitest";
2+
3+
import { HeadClient } from "./generated/payload/head/src/index.js";
4+
5+
describe("Payload Head Client", () => {
6+
let client: HeadClient;
7+
8+
beforeEach(() => {
9+
client = new HeadClient({
10+
endpoint: "http://localhost:3002",
11+
allowInsecureConnection: true,
12+
});
13+
});
14+
15+
it("should surface response headers for HEAD operation", async () => {
16+
const result = await client.contentTypeHeaderInResponse();
17+
assert.strictEqual(result.contentType, "text/plain; charset=utf-8");
18+
assert.strictEqual(result.metadata, "hello");
19+
});
20+
});

packages/typespec-ts/test/commands/spector-list.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ export const azureModularTsps = [
182182
outputPath: "payload/xml",
183183
inputPath: "payload/xml",
184184
},
185+
{
186+
outputPath: "payload/head",
187+
inputPath: "payload/head",
188+
},
185189
{
186190
outputPath: "server/versions/versioned",
187191
inputPath: "server/versions/versioned",

0 commit comments

Comments
 (0)