mirror of
https://github.com/hanzoai/azure-sdk-for-js.git
synced 2026-10-30 19:51:51 +00:00
### Packages impacted by this PR
@azure/playwright
### Issues associated with this PR
None.
### Describe the problem that is addressed by this PR
Today, `@azure/playwright` always sends
`sourceType=PlaywrightWorkspacesTestRun` on the remote browser WebSocket
URL. The service accepts other `sourceType` values for attributing
browser sessions to the tool that initiated them, but there is no way
for callers to opt in.
This PR adds a public `sourceType` option to
`createAzurePlaywrightConfig` and `getConnectOptions`, so callers can
choose how their sessions are attributed.
### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?
**1. Strict typed union (chosen).** `sourceType?:
BrowserSessionSourceTypeValue` where the union exposes only the
customer-facing values (`PlaywrightWorkspacesTestRun`, `Others`). Typos
are caught at compile time. Default keeps existing behaviour.
**2. Widened union (`BrowserSessionSourceTypeValue | (string & {})`).**
Would allow any string at compile time. Rejected because it makes the
public contract dishonest: customers could type any value, get no IDE
warning, and only see an HTTP 400 at runtime.
**3. Expose all service-side values publicly.** Would advertise internal
product names. Rejected as out of scope for a public type.
### Are there test cases added in this PR? _(If not, why?)_
Yes:
- `test/utils/utils.spec.ts` -- `getServiceWSEndpoint` with and without
`sourceType` arg.
- `test/common/playwrightServiceConfig.spec.ts` -- default field value
and `setOptions` override.
- `test/core/playwrightService.spec.ts` -- end-to-end plumb-through via
`createAzurePlaywrightConfig`, asserting the final `wsEndpoint` contains
the chosen `sourceType` and not the default.
All existing tests that assert `sourceType=PlaywrightWorkspacesTestRun`
in the URL continue to pass since that remains the default.
### Provide a list of related PRs _(if any)_
None.
### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_
N/A -- this is a feature PR, not a generated release PR.
### Checklists
- [x] Added impacted package name to the issue description
- [x] Does this PR needs any fixes in the SDK Generator? -- No,
hand-authored.
- [x] Added a changelog (if necessary)
### Summary of changes
**Public surface (additive, non-breaking):**
- `sourceType?: BrowserSessionSourceTypeValue` field on
`PlaywrightServiceAdditionalOptions`
- `BrowserSessionSourceTypeValue` exported type resolving to
`"PlaywrightWorkspacesTestRun" | "Others"`
**Behaviour:**
- Default value is `PlaywrightWorkspacesTestRun` -- existing callers see
no change.
- Honoured by both `createAzurePlaywrightConfig` and `getConnectOptions`
via the shared `PlaywrightServiceConfig` singleton.
- `getServiceWSEndpoint` gains a fourth `sourceType` parameter with a
default that preserves backward compatibility for in-tree callers.
**Samples:**
- `customising-service-parameters` (TS + JS) now lists `sourceType`.
Co-authored-by: Ekansh Lavania <[email protected]>