Skip to content

Use addAzureCosmosDB in the EF Core Cosmos DB TypeScript AppHost samples - #2001

Merged
David Pine (IEvangelist) merged 2 commits into
mainfrom
aspireagent/fix-cosmos-efcore-ts-casing
Nov 1, 2026
Merged

David Pine (IEvangelist) merged 2 commits into
mainfrom
aspireagent/fix-cosmos-efcore-ts-casing

Conversation

@davidfowl

Copy link
Copy Markdown
Contributor

Summary

The TypeScript AppHost samples on Azure Cosmos DB EF Core hosting call builder.addAzureCosmosDb("cosmos-db") three times. The exported TypeScript API is addAzureCosmosDB, the casing used by the C# AddAzureCosmosDB and by the sibling Azure Cosmos DB hosting page. TypeScript member lookup is case-sensitive, so a reader who copies any of these samples into apphost.mts gets a type error ("Property 'addAzureCosmosDb' does not exist"), and plain JS execution fails with builder.addAzureCosmosDb is not a function.

Upstream evidence: src/data/ts-modules/Aspire.Hosting.Azure.CosmosDB.13.6.0.json was generated from microsoft/aspire sourceCommit f4c27f2d43ddc1cacd0dd083b30d1fea1cee7a62. It exports addAzureCosmosDB(name: string): AzureCosmosDBResource. src/data/twoslash/aspire.d.ts likewise declares only addAzureCosmosDB.

Fix: correct all three calls to addAzureCosmosDB.

Regression check: the new tests/unit/typescript-apphost-api-casing.vitest.test.ts scans TypeScript fences containing createBuilder in all English docs. It fails when a call name matches an exported Aspire TypeScript function only case-insensitively, which is a precise, low-false-positive drift signal.

  • On main it fails with exactly the three addAzureCosmosDb -> addAzureCosmosDB hits in this file.
  • With the fix it passes.

How it was found: I audited 739 TypeScript AppHost blocks (2,996 .add/with/as/...( calls, excluding whats-new) against the in-repo ts-modules data. Other unexported names were:

  • tutorial-defined helpers (addMailDev, addMy*);
  • CommunityToolkit Dapr APIs, which have no TS module data and so can't be verified;
  • withRoleAssignments, which is present in aspire.d.ts;
  • the Kubernetes gateway sample's withRoute/withHostname/withTls, which differ from the exported withGatewayPathRoute/withGatewayTls* names. That one needs a semantic API mapping, so I left it out of scope for this focused change.

Overlap: no open issue or PR mentions addAzureCosmosDb. Open PR #1635 (last updated 2026-09-10) touches this file, but its head 6311f11b still contains all three addAzureCosmosDb calls, so it doesn't fix this. A rebase there would take this one-word change.

Rendered TypeScript sample, desktop 1280×900, light theme (local dev server)

Before After
Before: EF Core Cosmos DB TypeScript AppHost sample calls builder.addAzureCosmosDb, desktop 1280x900 light theme After: EF Core Cosmos DB TypeScript AppHost sample calls builder.addAzureCosmosDB, desktop 1280x900 light theme

Third-party links and affiliations

None

Validation

  • npx vitest run tests/unit/typescript-apphost-api-casing.vitest.test.ts: fails on main with the three hits above and passes with the fix.
  • npx vitest run: 85 files, 1,121 passed, 1 skipped.
  • npx eslint . --max-warnings 0: clean. npx prettier --check on the new test: clean.
  • Playwright screenshots of the rendered TypeScript sample before and after, taken from the local astro dev server.

🤖 Posted by AspireAgent (AI Agent)

The TypeScript AppHost export is addAzureCosmosDB (Aspire.Hosting.Azure.CosmosDB
ts-module). The three EF Core Cosmos DB host samples called addAzureCosmosDb,
which fails type checking and throws at runtime because member lookup is
case-sensitive. Add a unit check that TypeScript AppHost samples in English
docs never call a casing variant of an exported Aspire TypeScript API.

Co-authored-by: Copilot <[email protected]>
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

Frontend HTML artifact ready

The latest frontend build uploaded the frontend-dist artifact for PR #2001. Use the VS Code button below to open this PR with GitHub Artifacts Explorer and browse the built HTML locally.

VS Code: Open PR #2001 artifacts

This comment updates automatically when a new frontend build artifact is uploaded.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The casing audit’s lowercase-only prefix misses uppercase-initial method names, allowing incorrectly cased calls such as builder.AddAzureCosmosDB(...) to pass undetected.

1 open issue
What changed in this PR

This PR corrects the Cosmos DB API casing in the EF Core hosting guide’s TypeScript AppHost samples and adds a documentation regression check.

Changes:

  • Replaces all three addAzureCosmosDb calls with addAzureCosmosDB.
  • Adds a test that scans English TypeScript AppHost samples for casing mismatches against exported API names.
File Description
src/​frontend/​tests/​unit/​typescript-apphost-api-casing.vitest.test.ts Adds the API-casing regression check.
src/​frontend/​src/​content/​docs/​integrations/​databases/​efcore/​azure-cosmos-db/​azure-cosmos-db-host.mdx Corrects the API name in three TypeScript samples.

Review effort: Balanced

Match method names that start with an uppercase letter, and end a sample at
any closing fence at least as long as its opener (CommonMark), so a longer
closer does not pull later C# blocks into the TypeScript scan.

Co-authored-by: Copilot <[email protected]>
@IEvangelist
David Pine (IEvangelist) enabled auto-merge (squash) November 1, 2026 14:27
@IEvangelist
David Pine (IEvangelist) merged commit 87f7634 into main Nov 1, 2026
19 checks passed
@IEvangelist
David Pine (IEvangelist) deleted the aspireagent/fix-cosmos-efcore-ts-casing branch November 1, 2026 14:27
David Pine (IEvangelist) pushed a commit that referenced this pull request Nov 1, 2026
…2002)

## Summary

The TypeScript AppHost samples for Kubernetes Ingress and Gateway
routing use the C# overload names. Those names don't exist in the
TypeScript AppHost SDK, so a reader who copies the samples hits
`withPath is not a function` (or sends the wrong argument type).

In the TypeScript SDK, each C# overload is exported under its own
capability name. Upstream `microsoft/aspire` `main`
(c77b0c13c34616d1ce4698771bdd445fd50c7a99) defines them in
[`KubernetesIngressExtensions.cs`](https://github.com/microsoft/aspire/blob/c77b0c13c34616d1ce4698771bdd445fd50c7a99/src/Aspire.Hosting.Kubernetes/KubernetesIngressExtensions.cs),
[`KubernetesGatewayExtensions.cs`](https://github.com/microsoft/aspire/blob/c77b0c13c34616d1ce4698771bdd445fd50c7a99/src/Aspire.Hosting.Kubernetes/KubernetesGatewayExtensions.cs)
and
[`CertManagerExtensions.cs`](https://github.com/microsoft/aspire/blob/c77b0c13c34616d1ce4698771bdd445fd50c7a99/src/Aspire.Hosting.Kubernetes/CertManagerExtensions.cs).
The in-repo `src/data/ts-modules/Aspire.Hosting.Kubernetes.*.json`
surface matches them.

| C# overload | Upstream `[AspireExport]` | TS sample before | TS sample
after |
| --- | --- | --- | --- |
| `WithPath(path, endpoint)` | `withIngressPath` |
`ingress.withPath(...)` | `ingress.withIngressPath(...)` |
| `WithTls()` (Ingress) | `withIngressTlsAuto` | `ingress.withTls()` (TS
`withTls` requires `secretName`) | `ingress.withIngressTlsAuto()` |
| `WithIngressClass(IResourceBuilder<ParameterResource>)` |
`withIngressClassParam` | `ingress.withIngressClass(param)` |
`ingress.withIngressClassParam(param)` |
| `WithHostname(IResourceBuilder<ParameterResource>)` (Ingress) |
`withIngressHostnameParam` | `ingress.withHostname(param)` |
`ingress.withIngressHostnameParam(param)` |
| `WithRoute(path, endpoint)` | `withGatewayPathRoute` |
`storefront.withRoute(...)` | `storefront.withGatewayPathRoute(...)` |
| `WithTls(issuer)` (Gateway) | `withGatewayTlsIssuer` |
`storefront.withTls(letsencrypt)` |
`storefront.withGatewayTlsIssuer(letsencrypt)` |
| `WithHostname(IResourceBuilder<ParameterResource>)` (Gateway) |
`withGatewayHostnameParam` | `storefront.withHostname(param)` |
`storefront.withGatewayHostnameParam(param)` |

Upstream's own TypeScript polyglot AppHost uses the same names, for
example `gateway.withGatewayTlsIssuer(stagingIssuer)` in
[`tests/PolyglotAppHosts/Aspire.Hosting.Kubernetes/TypeScript/apphost.mts`](https://github.com/microsoft/aspire/blob/c77b0c13c34616d1ce4698771bdd445fd50c7a99/tests/PolyglotAppHosts/Aspire.Hosting.Kubernetes/TypeScript/apphost.mts).

This PR changes 15 sample lines in 6 TypeScript blocks:

- `deployment/kubernetes-ingress.mdx`: 3 blocks.
- `deployment/kubernetes/aks.mdx`: 3 blocks.

The C# samples and the prose are unchanged.

### How this was found

I ran a systematic TypeScript AppHost drift audit across all docs:

- **Scope:** 1,264 TS fences in 611 files. 398 are `twoslash` blocks,
which the build already type-checks.
- **Type-check:** I compiled the remaining 635 AppHost blocks (507 full
samples, 128 fragments) against `src/data/twoslash/aspire.d.ts` with the
repo's twoslash compiler options. That produced 202 English diagnostics.
- **Triage:**
- Argument-shape diagnostics were mostly gaps in the local `.d.ts`
generator, not sample errors. For example, upstream emits options
objects for all optional parameters, so calls like `runAsEmulator({
configureContainer })` are correct.
- Name-level diagnostics were checked against the ts-modules data and
upstream source.
  - The Ingress/Gateway names are the confirmed group fixed here.
  - `addAzureCosmosDb` is already handled by #2001.

### Regression test

The new `tests/unit/typescript-kubernetes-routing-apis.vitest.test.ts`
scans the TypeScript samples in the English docs for
`addIngress`/`addGateway` resources. It checks each call on them against
the ts-modules surface for
`KubernetesIngressResource`/`KubernetesGatewayResource`, including
inherited interface targets. It flags:

- methods that aren't exported;
- calls with fewer arguments than the required parameters;
- resource variables passed where a `string` is required.

On `main` it fails with 14 problems:

```
deployment/kubernetes/aks.mdx:311: withRoute is not exported for KubernetesGatewayResource
deployment/kubernetes/aks.mdx:360: withRoute is not exported for KubernetesGatewayResource
deployment/kubernetes/aks.mdx:361: withTls expects a string but got resource letsencrypt
deployment/kubernetes/aks.mdx:458: withHostname expects a string but got resource hostname
deployment/kubernetes/aks.mdx:459: withRoute is not exported for KubernetesGatewayResource
deployment/kubernetes-ingress.mdx:100: withTls expects 1 argument(s) but got 0
deployment/kubernetes-ingress.mdx:103: withPath is not exported for KubernetesIngressResource
deployment/kubernetes-ingress.mdx:104: withPath is not exported for KubernetesIngressResource
deployment/kubernetes-ingress.mdx:137: withTls expects 1 argument(s) but got 0
deployment/kubernetes-ingress.mdx:140: withPath is not exported for KubernetesIngressResource
deployment/kubernetes-ingress.mdx:141: withPath is not exported for KubernetesIngressResource
deployment/kubernetes-ingress.mdx:198: withIngressClass expects a string but got resource ingressClass
deployment/kubernetes-ingress.mdx:199: withHostname expects a string but got resource hostname
deployment/kubernetes-ingress.mdx:200: withTls expects 1 argument(s) but got 0
```

With this change, the test passes.

The 15th line, `aks.mdx:460` (`withTls(letsencrypt)` →
`withGatewayTlsIssuer`), is the same issuer drift. The test doesn't
detect it because that snippet reuses `letsencrypt` from an earlier
block without declaring it.

### Screenshots

The only visual change is the rendered TypeScript tab text. Captures are
Playwright, desktop 1280×900, light theme, against a local dev server.

| | Before (`main`) | After |
| --- | --- | --- |
| Kubernetes Ingress — Routing paths to services (desktop, light) |
![Before: Ingress TypeScript sample uses withTls() and
withPath](https://github.com/user-attachments/assets/bf1d5fab-d6bb-4a01-9eba-1ea78fb2e4a8)
| ![After: Ingress TypeScript sample uses withIngressTlsAuto() and
withIngressPath](https://github.com/user-attachments/assets/9ac6df88-51c5-41fd-b231-bb0b03af4fc0)
|
| AKS — Add automatic HTTPS with cert-manager (desktop, light) |
![Before: Gateway TypeScript sample uses withRoute and
withTls(letsencrypt)](https://github.com/user-attachments/assets/a7343a3e-0887-4014-a119-2dd3e34211c6)
| ![After: Gateway TypeScript sample uses withGatewayPathRoute and
withGatewayTlsIssuer](https://github.com/user-attachments/assets/afc3534c-6ef7-4bfd-8cb3-fde8d1f99cbd)
|

### Out of scope

The TypeScript samples in `kubernetes-ingress-aks.mdx` and
`kubernetes-gateway-aks.mdx` use a different, non-canonical shape
(`import { DistributedApplication } from "@aspire/apphost"` with
synchronous chaining). Correcting them needs a sample rewrite rather
than a rename, so I left them for a separate change.

Overlap check: no open issue or PR mentions these names. #1996 and #1868
touch other Kubernetes pages but not these samples.

## Third-party links and affiliations

None. The links above point to `microsoft/aspire` source.

## Validation

- `npx vitest run
tests/unit/typescript-kubernetes-routing-apis.vitest.test.ts`: fails on
`main` (14 problems above) and passes with this change.
- `npx vitest run`: 85 files, 1,121 passed, 1 skipped.
- `npx eslint . --max-warnings 0`: clean.
- `npx prettier --check` on the new test: clean. The two `.mdx` files
already have Prettier warnings on `main`, unchanged by this PR.
- Playwright before/after screenshots above.

**🤖 Posted by AspireAgent (AI Agent)**

Co-authored-by: davidfowl <[email protected]>
Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants