Skip to content

[typespec-go] add go spector test cases - #5017

Draft
kazrael2119 wants to merge 3 commits into
Azure:mainfrom
kazrael2119:add-go-spector-test
Draft

[typespec-go] add go spector test cases#5017
kazrael2119 wants to merge 3 commits into
Azure:mainfrom
kazrael2119:add-go-spector-test

Conversation

@kazrael2119

Copy link
Copy Markdown
Member

add go spector test cases from #4992

@azure-sdk-automation

azure-sdk-automation Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @azure-tools/typespec-go
Show changes

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

[typespec-go] add go spector test cases

@pkg-pr-new

pkg-pr-new Bot commented Jul 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@azure-tools/typespec-go@5017

commit: 9166592

@azure-sdk-automation

Copy link
Copy Markdown
Contributor

You can try these changes here

🛝 Playground 🌐 Website

@kazrael2119

Copy link
Copy Markdown
Member Author

Skipped cases (blocked by emitter bugs)

Three cases from #4992 cannot be added yet and are commented out in tspcompile.js with an inline reason. All three require fixes in the @azure-tools/typespec-go emitter itself and cannot be worked around by writing tests.

Case Spec Stage Root cause
Head payload/head Generation fails unexpected kind string for HeaderMapResponse metadata
ResponseAsBool azure/client-generator-core/response-as-bool Generation fails didn't find HTTP response for kind boolean (@responseAsBool on HEAD)
Boolean encode/boolean Generates OK / fails at runtime @encode(string) on boolean is ignored; bool is serialized as a JSON boolean instead of a string

1. Head (payload/head) — emitter internal error during preprocessing

../../core/packages/compiler/lib/intrinsics.tsp - error @azure-tools/typespec-go/InternalError:
The emitter encountered an internal error during preprocessing.
Error: unexpected kind string for HeaderMapResponse metadata
    at ClientAdapter.adaptResponseEnvelope (src/tcgcadapter/clients.ts:1742:21)
    at ClientAdapter.populateMethod        (src/tcgcadapter/clients.ts:850:27)
    at ClientAdapter.adaptMethod           (src/tcgcadapter/clients.ts:688:31)
    at ClientAdapter.recursiveAdaptClient  (src/tcgcadapter/clients.ts:394:12)
    at ClientAdapter.adaptClients          (src/tcgcadapter/clients.ts:62:14)
    at Adapter.tcgcToGoCodeModel           (src/tcgcadapter/adapter.ts:116:8)

A HEAD operation that returns response headers makes the emitter hit an unexpected string kind while processing HeaderMapResponse metadata. No code is generated.

2. ResponseAsBool (azure/client-generator-core/response-as-bool) — emitter internal error during preprocessing

../../core/packages/compiler/lib/intrinsics.tsp:217:8 - error @azure-tools/typespec-go/InternalError:
The emitter encountered an internal error during preprocessing.
Error: didn't find HTTP response for kind boolean in method Exists
    at ClientAdapter.adaptResponseEnvelope (src/tcgcadapter/clients.ts:1858:13)
    at ClientAdapter.populateMethod        (src/tcgcadapter/clients.ts:850:27)
    at ClientAdapter.adaptMethod           (src/tcgcadapter/clients.ts:688:31)
    at ClientAdapter.recursiveAdaptClient  (src/tcgcadapter/clients.ts:394:12)
    at ClientAdapter.recursiveAdaptClient  (src/tcgcadapter/clients.ts:384:32)
    at ClientAdapter.adaptClients          (src/tcgcadapter/clients.ts:62:14)
    at Adapter.tcgcToGoCodeModel           (src/tcgcadapter/adapter.ts:116:8)

> 217 | scalar boolean;
      |        ^^^^^^^
Found 1 error.

For the Exists method (@responseAsBool on HEAD), the emitter cannot find an HTTP response for the boolean kind. No code is generated.

3. Boolean (encode/boolean) — generation succeeds, rejected at runtime

Unlike the other two, generation succeeds (Compilation completed successfully); the failure happens when go test runs against the spector mock:

POST http://localhost:3000/encode/boolean/property/true-lower
RESPONSE 400: 400 Bad Request
{
  "message": "Body provided doesn't match expected body: at $.value: expected a string but got boolean",
  "expected": { "value": "true" },
  "actual":   { "value": true }
}

The spec uses @encode(string) so the bool must be serialized as the string "true", but the emitter ignores the annotation and emits the JSON boolean true, which the mock rejects.

Summary

The first two are emitter preprocessing internal errors (no code produced at all); the third is a serialization bug (code is generated but the emitted body does not match the spec). All three are tracked as skipped in tspcompile.js until the emitter is fixed.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:go Issues for @azure-tools/typespec-go emitter label Jul 22, 2026
Comment thread .chronus/changes/add-go-spector-test-2026-6-22-8-25-18.md Outdated
Comment thread .chronus/changes/add-go-spector-test-2026-6-22-8-25-18.md Outdated
clientdocgroup: ["azure/client-generator-core/client-doc"],
defaultvaluegroup: ["azure/client-generator-core/client-default-value"],
emptystringgroup: ["azure/client-generator-core/deserialize-empty-string-as-null"],
exactnamegroup: ["azure/client-generator-core/exact-name", "generate-fakes=false"], // fakes reference an unexported model (my_model), so fake generation is disabled for this scenario

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.

It's should be an emitter issue, please also comment out this line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:go Issues for @azure-tools/typespec-go emitter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants