Migrated Location Hints functional tests to Vitest+Playwright+MSW#1537
Migrated Location Hints functional tests to Vitest+Playwright+MSW#1537carterworks wants to merge 8 commits into
Conversation
|
|
| Filename | Overview |
|---|---|
| packages/browser/test/integration/specs/Location Hints/locationHints.spec.js | New spec file migrating C6589015 and C6944931 to Vitest+Playwright+MSW. Test logic is faithful to the originals; deleteCookies() covers all cookies including mboxEdgeCluster, so cross-test contamination is not a concern. |
Sequence Diagram
sequenceDiagram
participant T as Test
participant A as Alloy SDK
participant W as MSW Worker
participant NR as NetworkRecorder
Note over T,NR: C6589015 — EdgeNetwork hint propagation
T->>T: deleteCookies()
T->>W: worker.use(sendEventHandler)
T->>A: configure(alloyConfig)
A->>W: POST /ee/v1/interact (no hint)
W-->>A: "sendEventResponse.json (hint: or2, state:store cluster=or2)"
A->>A: "Set kndctr_..._cluster=or2 cookie"
T->>T: "Read cluster cookie → locationHint=or2"
T->>A: "sendEvent #2"
A->>W: POST /ee/or2/v1/interact
W-->>A: sendEventResponse.json
T->>NR: findCalls(edge.adobedc.net, minCalls:2)
NR-->>T: [call1, call2]
T->>T: assert call1 URL has no hint segment
T->>T: assert call2 URL contains /ee/or2/
Note over T,NR: C6944931 — Legacy mboxEdgeCluster translation
T->>T: deleteCookies()
T->>T: "Set mboxEdgeCluster=38"
T->>W: worker.use(sgp3LocationHintHandler)
T->>A: configure(alloyConfig)
A->>W: "POST /ee/t38/v1/interact (from mboxEdgeCluster=38)"
W-->>A: "sgp3 response (hint: sgp3, state:store cluster=sgp3)"
A->>A: "Set kndctr_..._cluster=sgp3 cookie"
T->>A: "sendEvent #2"
A->>W: POST /ee/sgp3/v1/interact
W-->>A: sgp3 response
T->>NR: findCalls(edge.adobedc.net, minCalls:2)
NR-->>T: [call1, call2]
T->>T: assert call1 URL contains /ee/t38/
T->>T: assert call2 URL contains /ee/sgp3/
Reviews (2): Last reviewed commit: "test(integration): migrate location hint..." | Re-trigger Greptile
| /https:\/\/edge.adobedc.net\/ee\/.*\/?v1\/interact/, | ||
| () => { | ||
| return HttpResponse.json({ | ||
| requestId: "sgp3-location-hint-test", | ||
| handle: [ | ||
| { | ||
| payload: [ | ||
| { | ||
| id: "41861666193140161934276845651148876988", | ||
| namespace: { code: "ECID" }, | ||
| }, | ||
| ], | ||
| type: "identity:result", | ||
| }, | ||
| { | ||
| payload: [ | ||
| { scope: "Target", hint: "38", ttlSeconds: 1800 }, | ||
| { scope: "AAM", hint: "3", ttlSeconds: 1800 }, | ||
| { scope: "EdgeNetwork", hint: "sgp3", ttlSeconds: 1800 }, | ||
| ], | ||
| type: "locationHint:result", | ||
| }, | ||
| { | ||
| payload: [ | ||
| { | ||
| key: MAIN_CLUSTER_COOKIE_NAME, | ||
| value: "sgp3", | ||
| maxAge: 1800, | ||
| }, | ||
| ], | ||
| type: "state:store", | ||
| }, | ||
| ], |
There was a problem hiding this comment.
sgp3LocationHintHandler does not validate configId
Every handler in helpers/mswjs/handlers.js extracts and checks configId before responding (e.g. sendEventHandler, pullDestinationsHandler, setConsentHandler). The inline sgp3LocationHintHandler skips that check entirely, so it will intercept and return the sgp3 response for any POST to the interact endpoint regardless of the configured datastream. While the handler is reset after each test, adding the same configId guard (using alloyConfig.datastreamId) would keep the handler consistent with the rest of the test harness and prevent a misconfigured alloy instance from silently matching.
| new RegExp(`edge\\.adobedc\\.net/ee/${locationHint}/v1/interact`), | ||
| ); | ||
| }); | ||
|
|
||
| // C6944931 - The legacy Adobe Target location hint is used. | ||
| test("C6944931 - legacy mboxEdgeCluster cookie is translated to a location hint on the first request", async ({ | ||
| alloy, | ||
| worker, | ||
| networkRecorder, | ||
| }) => { | ||
| await deleteCookies(); | ||
|
|
||
| // Set mboxEdgeCluster=38 (Singapore, Konductor region ID 3 = sgp3) | ||
| // Alloy reads this cookie and uses it as the initial location hint (/t38/) | ||
| document.cookie = "mboxEdgeCluster=38; path=/"; | ||
|
|
||
| worker.use(sgp3LocationHintHandler); | ||
|
|
||
| await alloy("configure", { | ||
| ...alloyConfig, | ||
| thirdPartyCookiesEnabled: false, | ||
| debugEnabled: false, | ||
| }); | ||
| await alloy("sendEvent", {}); | ||
| await alloy("sendEvent", {}); | ||
|
|
||
| const calls = await networkRecorder.findCalls(/edge\.adobedc\.net/, { | ||
| minCalls: 2, | ||
| }); | ||
| expect(calls.length).toBe(2); | ||
|
|
||
| // First request uses the legacy mboxEdgeCluster=38 hint (/t38/ in URL path) | ||
| expect(calls[0].request.url).toMatch(/edge\.adobedc\.net\/ee\/t38\//); | ||
| // Second request uses the sgp3 hint returned in the edge response | ||
| expect(calls[1].request.url).toMatch(/edge\.adobedc\.net\/ee\/sgp3\//); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Missing intermediate cookie assertion from original C6944931 test
The original C6944931.js (line 56) explicitly verified that after the first sendEvent the cluster cookie was set to "sgp3". The new test drops this assertion and jumps straight to URL-pattern checks. If the state:store response were mishandled (cookie name mismatch, wrong key, alloy bug in storing location hints), the second URL would silently fall back to the t38 path and the second assertion would fail — but the reason (the cookie was never set) would not be surfaced clearly. Adding the explicit cookie check before the second sendEvent preserves the diagnostic value of the original test.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
6d4a68b to
71ad5f5
Compare
2fb56e2 to
e183d80
Compare
71ad5f5 to
10f1006
Compare
e183d80 to
8aa9f6b
Compare
There was a problem hiding this comment.
carterworks has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
carterworks has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.
2126b41 to
8e6aa0d
Compare
8e6aa0d to
0fa5f26
Compare
… CookieStore API - Migrate document.cookie reads/writes to CookieStore API (cookieStore.get/set) - Add configId guard to inline sgp3LocationHintHandler matching convention in consent_gate.spec.js; throws when configId does not match the configured datastreamId so misconfigured handlers surface immediately - Restore intermediate cluster-cookie assertion in C6944931 between the two sendEvent calls so a storage failure surfaces here rather than as a confusing URL-path mismatch on the second request
1d7dc76 to
04be6b9
Compare
Keep the original testcafe functional specs alongside the new Vitest+Playwright+MSW integration suite until these migration branches merge, so reviewers retain the pre-migration signal.
Changed Packages
Description
Migrates the Location Hints functional tests to the new Vitest+Playwright+MSW harness.
Related Issue
Part of the functional test → integration test migration. See
packages/browser/test/FUNCTIONAL_MIGRATION_PLAN.md.Motivation and Context
The existing TestCafe functional test suite is being migrated to Vitest+Playwright+MSW to enable faster, more reliable CI testing without a running server. This PR is part of a stacked series — each PR migrates one test file.
Functional tests replaced:
packages/browser/test/functional/specs/Location Hints/C6589015.jspackages/browser/test/functional/specs/Location Hints/C6944931.jsTypes of changes
Checklist:
Stack