Commit 50d07d7
[@azure/playwright] Add sourceType option for browser session attribution (#38693)
### 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 <ekanshlnu@microsoft.com>1 parent 472d931 commit 50d07d7
13 files changed
Lines changed: 116 additions & 5 deletions
File tree
- sdk/loadtesting/playwright
- review
- samples/v1
- javascript/customising-service-parameters
- typescript/customising-service-parameters
- src
- common
- core
- utils
- test
- common
- core
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
7 | 12 | | |
8 | 13 | | |
9 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
| |||
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| 48 | + | |
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
| 118 | + | |
| 119 | + | |
119 | 120 | | |
120 | 121 | | |
121 | 122 | | |
| |||
Lines changed: 11 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
11 | 16 | | |
12 | 17 | | |
13 | 18 | | |
| |||
22 | 27 | | |
23 | 28 | | |
24 | 29 | | |
| 30 | + | |
25 | 31 | | |
26 | 32 | | |
27 | 33 | | |
| |||
35 | 41 | | |
36 | 42 | | |
37 | 43 | | |
| 44 | + | |
38 | 45 | | |
39 | 46 | | |
40 | 47 | | |
| |||
116 | 123 | | |
117 | 124 | | |
118 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
119 | 129 | | |
120 | 130 | | |
121 | 131 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
148 | 158 | | |
149 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
150 | 167 | | |
151 | 168 | | |
152 | 169 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
| 177 | + | |
177 | 178 | | |
178 | 179 | | |
179 | 180 | | |
| |||
249 | 250 | | |
250 | 251 | | |
251 | 252 | | |
| 253 | + | |
252 | 254 | | |
253 | 255 | | |
254 | 256 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
5 | 11 | | |
6 | 12 | | |
7 | 13 | | |
| |||
129 | 135 | | |
130 | 136 | | |
131 | 137 | | |
132 | | - | |
133 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
134 | 145 | | |
135 | 146 | | |
136 | 147 | | |
| |||
0 commit comments