22// through the real dev server (the e2e cloud target boots `vite dev` with the
33// SSR gate active, so this is the same routing that runs in prod):
44//
5- // signed out → /login
6- // click Sign in → WorkOS (emulator) callback → org-less → /create-org
7- // create the first org → canonical dashboard at /<slug>
5+ // member: signed out → /login → click Sign in → WorkOS (emulator) callback
6+ // → canonical dashboard at /<slug>
7+ // no org: the same sign-in → Executor v2's sign-up page (v1 creates no
8+ // organizations; they are created in v2)
89//
910// The individual hops are also covered piecewise (cloud/unauthenticated-skeleton,
1011// cloud/session-gate, scenarios/org-slug-routing) — those pin edge cases this
@@ -20,60 +21,53 @@ import { randomUUID } from "node:crypto";
2021
2122import { expect } from "@effect/vitest" ;
2223import { Effect } from "effect" ;
24+ import type { Page } from "playwright" ;
2325
2426import { scenario } from "../src/scenario" ;
2527import { Browser , Target } from "../src/services" ;
26- import { settle } from "../src/surfaces/browser" ;
28+ import { settle , type BrowserSession } from "../src/surfaces/browser" ;
29+ import { seedOrganization } from "../targets/cloud" ;
30+
31+ /** Signed out at the root, then through the hosted sign-in form as `email`. */
32+ const signInThroughTheUi = async ( page : Page , step : BrowserSession [ "step" ] , email : string ) => {
33+ await step ( "Signed out, the root redirects to /login" , async ( ) => {
34+ await page . goto ( "/" , { waitUntil : "commit" } ) ;
35+ await page . getByText ( "Sign in to manage your tools and integrations" ) . waitFor ( ) ;
36+ } ) ;
37+ expect ( new URL ( page . url ( ) ) . pathname , "the signed-out root lands on /login" ) . toBe ( "/login" ) ;
38+
39+ await step ( "Sign in through the UI" , async ( ) => {
40+ await page . getByRole ( "link" , { name : "Sign in" } ) . click ( ) ;
41+ // The emulator's hosted AuthKit form.
42+ await page . getByPlaceholder ( "new-user@example.com" ) . fill ( email ) ;
43+ await page . getByRole ( "button" , { name : / C o n t i n u e / } ) . click ( ) ;
44+ } ) ;
45+ } ;
2746
2847scenario (
29- "Auth routing · signed out → login → onboarding → dashboard, one browser session" ,
48+ "Auth routing · signed out → login → dashboard, one browser session" ,
3049 { } ,
3150 Effect . gen ( function * ( ) {
3251 const browser = yield * Browser ;
3352 yield * Target ;
3453
35- // A brand-new user the emulator provisions on first login_hint — no org, so
36- // the post-callback document is gated to onboarding .
54+ // A member of an existing organization (it lives in WorkOS, as every v1
55+ // organization does), signing in for the first time in this browser .
3756 const email = `flow-${ randomUUID ( ) . slice ( 0 , 8 ) } @e2e.test` ;
57+ yield * Effect . promise ( ( ) => seedOrganization ( email , "Flow Test Org" ) ) ;
3858
3959 // No cookies → a clean, signed-out browser.
4060 const anonymous = { label : "anonymous" } ;
4161
4262 yield * browser . session ( anonymous , async ( { page, step } ) => {
43- await step ( "Signed out, the root redirects to /login" , async ( ) => {
44- await page . goto ( "/" , { waitUntil : "commit" } ) ;
45- await page . getByText ( "Sign in to manage your tools and integrations" ) . waitFor ( ) ;
46- } ) ;
47- expect ( new URL ( page . url ( ) ) . pathname , "the signed-out root lands on /login" ) . toBe ( "/login" ) ;
48-
49- await step ( "Sign in through the UI → org-less session lands on onboarding" , async ( ) => {
50- await page . getByRole ( "link" , { name : "Sign in" } ) . click ( ) ;
51- // The emulator's hosted AuthKit form: provision a brand-new user.
52- await page . getByPlaceholder ( "new-user@example.com" ) . fill ( email ) ;
53- await page . getByRole ( "button" , { name : / C o n t i n u e / } ) . click ( ) ;
54- // callback mints the session → SSR gate sees no org → /create-org.
55- await page . waitForURL ( ( url ) => url . pathname === "/create-org" , { timeout : 30_000 } ) ;
56- await page . getByPlaceholder ( "Northwind Labs" ) . waitFor ( { timeout : 30_000 } ) ;
57- } ) ;
63+ await signInThroughTheUi ( page , step , email ) ;
5864
59- await step ( "Create the first org → canonical dashboard at /<slug>" , async ( ) => {
60- const orgName = "Flow Test Org" ;
61- const orgNameInput = page . getByPlaceholder ( "Northwind Labs" ) ;
62- await settle ( page ) ;
63- await orgNameInput . fill ( orgName ) ;
64- await page . waitForTimeout ( 250 ) ;
65- if ( ( await orgNameInput . inputValue ( ) ) !== orgName ) {
66- await orgNameInput . fill ( orgName ) ;
67- }
68- expect ( await orgNameInput . inputValue ( ) , "org name survives create-org hydration" ) . toBe (
69- orgName ,
70- ) ;
71- await page . getByRole ( "button" , { name : "Create organization" } ) . click ( ) ;
72- await page . getByText ( "Connect your MCP client" ) . waitFor ( { timeout : 30_000 } ) ;
73- await page . getByRole ( "button" , { name : "Continue to app" } ) . click ( ) ;
74- // The bare landing canonicalizes onto the new org's slug.
65+ await step ( "The callback lands on the canonical dashboard at /<slug>" , async ( ) => {
66+ // The bare landing canonicalizes onto the org's slug.
7567 await page . waitForURL ( ( url ) => / ^ \/ [ a - z 0 - 9 - ] + \/ ? $ / . test ( url . pathname ) , { timeout : 30_000 } ) ;
7668 await page . getByText ( "Integrations" ) . first ( ) . waitFor ( { timeout : 30_000 } ) ;
69+ await settle ( page ) ;
70+ await page . getByRole ( "button" , { name : / F l o w T e s t O r g / } ) . waitFor ( { timeout : 30_000 } ) ;
7771 } ) ;
7872
7973 expect (
@@ -83,3 +77,51 @@ scenario(
8377 } ) ;
8478 } ) ,
8579) ;
80+
81+ scenario (
82+ "Auth routing · a sign-in with no organization is sent to Executor v2's sign-up page" ,
83+ { } ,
84+ Effect . gen ( function * ( ) {
85+ const browser = yield * Browser ;
86+ const target = yield * Target ;
87+
88+ const email = `flow-orgless-${ randomUUID ( ) . slice ( 0 , 8 ) } @e2e.test` ;
89+ const anonymous = { label : "anonymous" } ;
90+
91+ yield * browser . session ( anonymous , async ( { page, step } ) => {
92+ // The callback's redirect chain ends on v2's real host, and Playwright
93+ // cannot hold a document at a redirect hop. So the hosted form's answer
94+ // is held here (as login-csrf does), and the browser's own request
95+ // context — its cookie jar — follows the chain one hop at a time.
96+ let callback : string | undefined ;
97+ await page . route ( "**/user_management/authorize/submit" , async ( route ) => {
98+ const response = await route . fetch ( { maxRedirects : 0 } ) ;
99+ callback = response . headers ( ) . location ;
100+ await route . fulfill ( { status : 200 , contentType : "text/plain" , body : "Signed in" } ) ;
101+ } ) ;
102+
103+ await signInThroughTheUi ( page , step , email ) ;
104+
105+ await step ( "The callback signs the browser in and returns it to the app" , async ( ) => {
106+ await expect . poll ( ( ) => callback ) . toBeDefined ( ) ;
107+ const response = await page . request . get ( callback ! , { maxRedirects : 0 } ) ;
108+ expect ( response . status ( ) , "the callback completes the sign-in" ) . toBe ( 302 ) ;
109+ expect ( response . headers ( ) . location , "…back to the app's root" ) . toBe ( "/" ) ;
110+ } ) ;
111+
112+ await step ( "The app sends the org-less session on to v2's sign-up page" , async ( ) => {
113+ const response = await page . request . get ( new URL ( "/" , target . baseUrl ) . toString ( ) , {
114+ maxRedirects : 0 ,
115+ headers : { accept : "text/html" } ,
116+ } ) ;
117+ expect ( response . status ( ) , "no app shell for a session with no organization" ) . toBe ( 302 ) ;
118+ const location = new URL ( response . headers ( ) . location ?? "" , target . baseUrl ) ;
119+ expect ( location . origin , "the session leaves v1 for v2's host" ) . not . toBe (
120+ new URL ( target . baseUrl ) . origin ,
121+ ) ;
122+ expect ( location . pathname , "v2's sign-in page…" ) . toBe ( "/login" ) ;
123+ expect ( location . searchParams . get ( "mode" ) , "…opened to sign up" ) . toBe ( "signup" ) ;
124+ } ) ;
125+ } ) ;
126+ } ) ,
127+ ) ;
0 commit comments