Skip to content

Commit 993bf36

Browse files
committed
Test that v1 creates no organizations and sends org-less sessions to v2
1 parent d1919a0 commit 993bf36

25 files changed

Lines changed: 581 additions & 665 deletions
Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,8 @@
11
import { describe, expect, it } from "@effect/vitest";
22

3-
import {
4-
FREE_ORGANIZATIONS_PER_USER_LIMIT,
5-
hasNonFreeOrganizationSubscription,
6-
hasPaidOrganizationSubscription,
7-
isOverFreeOrganizationLimit,
8-
shouldApplyFreeOrganizationLimit,
9-
} from "../extensions/billing/plans";
3+
import { hasNonFreeOrganizationSubscription } from "../extensions/billing/plans";
104

115
describe("organization limits", () => {
12-
it("treats active and trialing paid org subscriptions as paid", () => {
13-
expect(hasPaidOrganizationSubscription([{ planId: "team", status: "active" }])).toBe(true);
14-
expect(hasPaidOrganizationSubscription([{ planId: "team", status: "trialing" }])).toBe(true);
15-
expect(hasPaidOrganizationSubscription([{ planId: "enterprise", status: "active" }])).toBe(
16-
true,
17-
);
18-
});
19-
20-
it("does not treat inactive paid plans or free plans as paid", () => {
21-
expect(hasPaidOrganizationSubscription([{ planId: "team", status: "canceled" }])).toBe(false);
22-
expect(hasPaidOrganizationSubscription([{ planId: "free", status: "active" }])).toBe(false);
23-
expect(hasPaidOrganizationSubscription([{ planId: null, status: "active" }])).toBe(false);
24-
});
25-
266
it("exempts any active non-free subscription from the execution rate limit", () => {
277
expect(hasNonFreeOrganizationSubscription([{ planId: "team", status: "active" }])).toBe(true);
288
expect(hasNonFreeOrganizationSubscription([{ planId: "enterprise", status: "trialing" }])).toBe(
@@ -53,34 +33,4 @@ describe("organization limits", () => {
5333
);
5434
expect(hasNonFreeOrganizationSubscription([{ planId: null, status: "active" }])).toBe(false);
5535
});
56-
57-
it("applies the free org limit only when none of the user's active orgs are paid", () => {
58-
const activeMemberships = [
59-
{ organizationId: "org_free_1", status: "active" },
60-
{ organizationId: "org_paid", status: "active" },
61-
];
62-
63-
expect(shouldApplyFreeOrganizationLimit(activeMemberships, new Set())).toBe(true);
64-
expect(shouldApplyFreeOrganizationLimit(activeMemberships, new Set(["org_paid"]))).toBe(false);
65-
});
66-
67-
it("caps free-only users at active org memberships, not pending invitations", () => {
68-
expect(
69-
isOverFreeOrganizationLimit(
70-
Array.from({ length: FREE_ORGANIZATIONS_PER_USER_LIMIT - 1 }, (_, index) => ({
71-
organizationId: `org_${index}`,
72-
status: "active",
73-
})),
74-
),
75-
).toBe(false);
76-
77-
expect(
78-
isOverFreeOrganizationLimit(
79-
Array.from({ length: FREE_ORGANIZATIONS_PER_USER_LIMIT }, (_, index) => ({
80-
organizationId: `org_${index}`,
81-
status: "active",
82-
})),
83-
),
84-
).toBe(true);
85-
});
8636
});

‎apps/cloud/src/edge/marketing.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import {
77
isV2Path,
88
marketingProxyRequest,
99
parseV2Edge,
10+
v2AppOrigin,
1011
v2EdgeResponse,
1112
v2PageForSlashedPath,
13+
v2SignUpUrl,
1214
type V2EdgeEnv,
1315
type V2Service,
1416
} from "./marketing";
@@ -254,6 +256,31 @@ describe("parseV2Edge", () => {
254256
});
255257
});
256258

259+
// Where v1 sends anything that would create an organization: v2's sign-up page
260+
// (and its origin, v2's app host).
261+
describe("v2SignUpUrl", () => {
262+
const service: V2Service = { fetch: () => Promise.resolve(new Response(null)) };
263+
const settings = {
264+
V2: service,
265+
V2_SIGN_UP_URL: "https://app.executor.sh/login?mode=signup",
266+
V2_OAUTH_STATE_PREFIX: "x2.",
267+
V2_ANALYTICS_PROXY_PATH: "/api/0123456789abcdef",
268+
V2_ERROR_TUNNEL_PATH: "/api/fedcba9876543210/submit",
269+
};
270+
271+
it("is v2's sign-up page, query kept, and v2AppOrigin is its origin", () => {
272+
expect(v2SignUpUrl(settings)?.href).toBe("https://app.executor.sh/login?mode=signup");
273+
expect(v2AppOrigin(settings)?.href).toBe("https://app.executor.sh/");
274+
});
275+
276+
it("is null where v1 has no v2: no settings, or broken ones", () => {
277+
expect(v2SignUpUrl({})).toBeNull();
278+
expect(v2SignUpUrl({ ...settings, V2: undefined })).toBeNull();
279+
expect(v2SignUpUrl({ ...settings, V2_SIGN_UP_URL: "/login?mode=signup" })).toBeNull();
280+
expect(v2AppOrigin({})).toBeNull();
281+
});
282+
});
283+
257284
describe("v2EdgeResponse", () => {
258285
const SIGN_UP_URL = "https://v2.executor.sh/login?mode=signup";
259286
const STATE_PREFIX = "x2.";

‎e2e/cloud/account-api.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// React shell + api-keys page consume. Happy paths go through the typed
33
// AccountHttpApi client (the same contract the UI's AccountApiClient uses);
44
// refusal edges and the bearer cross-check use raw fetch with the identity's
5-
// real sealed-session cookie (the org-limit cross-check pattern).
5+
// real sealed-session cookie.
66
import { expect } from "@effect/vitest";
77
import { Effect } from "effect";
88
import { AccountHttpApi } from "@executor-js/api";

‎e2e/cloud/admin-users-console.test.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
// most here — that a plain member who reaches the URL is told they don't have
99
// access rather than shown an empty workspace.
1010
//
11-
// Two members are built through the REAL flows (login → create-organization →
12-
// invite → accept-invitation, in `./support/session`). Each connects a Personal
13-
// credential; the plain member's Workspace attempt is refused, so the directory
14-
// and connection UI prove the owner-aware permission boundary together.
11+
// Two members are built through the REAL flows (login into the admin's
12+
// organization → invite → accept-invitation, in `./support/session`). Each
13+
// connects a Personal credential; the plain member's Workspace attempt is
14+
// refused, so the directory and connection UI prove the owner-aware permission
15+
// boundary together.
1516
import { randomBytes } from "node:crypto";
1617

1718
import { expect } from "@effect/vitest";

‎e2e/cloud/admin-users.test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
// "who uses my workspace, and what have they connected", reading across every
44
// member of the tenant instead of binding to one.
55
//
6-
// Two members are built through the REAL flows (login → create-organization →
7-
// invite → accept-invitation), each connects their own Personal credential, and
8-
// the admin then reads the joined view — the exact shape a customer dashboard's
9-
// icon grid consumes. The guarantees pinned here:
6+
// Two members are built through the REAL flows (login into the admin's
7+
// organization → invite → accept-invitation), each connects their own Personal
8+
// credential, and the admin then reads the joined view — the exact shape a
9+
// customer dashboard's icon grid consumes. The guarantees pinned here:
1010
//
1111
// 1. the joined view reports BOTH members and each one's own connections,
1212
// even though no single product-view caller can see another member's;

‎e2e/cloud/auth-routing-flow.test.ts‎

Lines changed: 80 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
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

2122
import { expect } from "@effect/vitest";
2223
import { Effect } from "effect";
24+
import type { Page } from "playwright";
2325

2426
import { scenario } from "../src/scenario";
2527
import { 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: /Continue/ }).click();
44+
});
45+
};
2746

2847
scenario(
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: /Continue/ }).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-z0-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: /Flow Test Org/ }).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+
);

‎e2e/cloud/billing-customer-provisioning.test.ts‎

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77
// executions and NONE of them reach the meter. The product looks perfectly
88
// healthy while every execution is unbilled and unmetered.
99
//
10-
// Three guarantees are pinned here, all read from Autumn's own state rather than
10+
// Two guarantees are pinned here, all read from Autumn's own state rather than
1111
// from the execution's response (which can never show any of them):
1212
//
13-
// 1. creating an organization provisions its billing customer up front,
14-
// 2. if a customer is missing anyway, the billing seam heals it in place and
15-
// the execution still lands on the meter, and
16-
// 3. any OTHER billing failure is left alone — the repair is scoped to the
13+
// 1. if an organization's customer is missing, the billing seam heals it in
14+
// place and the execution still lands on the meter, and
15+
// 2. any OTHER billing failure is left alone — the repair is scoped to the
1716
// "no such customer" answer, so a real provider failure is still reported
1817
// rather than quietly retried away.
1918
//
19+
// (v1 no longer creates organizations — they are created in Executor v2 — so
20+
// there is no creation step left to provision a customer up front.)
21+
//
2022
// The missing customer is produced with the emulator's fault injector — one
2123
// 404 `customer_not_found` per billing endpoint — because the emulator, like
2224
// real Autumn's SDK flow, otherwise auto-creates customers on contact.
@@ -54,31 +56,6 @@ const UNRELATED_NOT_FOUND = {
5456
body: { message: "Not Found", code: "not_found" },
5557
} as const;
5658

57-
scenario(
58-
"Billing · creating an organization provisions it as a billing customer",
59-
{ timeout: 180_000 },
60-
Effect.gen(function* () {
61-
yield* Billing;
62-
const autumn = yield* Autumn;
63-
const target = yield* Target;
64-
const mcp = yield* Mcp;
65-
66-
// A brand-new user creating their first organization: none of the
67-
// opportunistic billing lookups (the over-the-free-limit check, the members
68-
// page's seat count, the rate limiter's paid-plan exemption) are reached on
69-
// this journey, so org creation is the only chance to provision.
70-
const identity = yield* target.newIdentity();
71-
const bearer = yield* mcp.mintBearer(emailOf(identity));
72-
const organizationId = orgIdOf(bearer);
73-
74-
const customerIds = yield* autumn.customerIds();
75-
expect(
76-
customerIds,
77-
"the new organization exists as a customer at the billing provider",
78-
).toContain(organizationId);
79-
}),
80-
);
81-
8259
scenario(
8360
"Billing · a missing billing customer is healed in place and the execution is still metered",
8461
{ timeout: 180_000 },

0 commit comments

Comments
 (0)