Files
clawmates/frontend/tests/e2e/p5-billing.spec.ts
T
Omar SobhandClaude Fable 5 add4f79fed Rebrand: TeamClaw -> Clawmates (clawmates.work)
Full-depth rename per the approved plan; the 'claw' product vocabulary
(claws, /claws routes, clawId, Claw Chat) stays — it is now the brand.

- Display brand: Clawmates (manifest, titles, hero, login/rail logo
  'clawmates'); default host app.clawmates.work; registry
  ghcr.io/clawmates
- Crates tc-* -> cm-* (16 crates + all imports); binaries
  clawmates-server/broker/bundler; images clawmates/*; env prefix
  CLAWMATES_* (+ CM_TEST_DATABASE_URL / CM_LIVE_LLM); config
  clawmates.toml; helm chart deploy/helm/clawmates with clawmates-*
  resources; db names clawmates*; sockets /run/clawmates; cookie
  cm_session; kind cluster clawmates-test; seccomp node profile
  clawmates-agent-profile.json
- All 9 Playwright brand assertions updated in lockstep; historical
  spec document left untouched as the only remaining 'TeamClaw'
- Local env migrated: dev pg clawmates-dev-pg/clawmates_dev, shared
  test server clawmates-test-pg, kind cluster recreated with image +
  profile, compose images rebuilt under clawmates/*

Verified end to end: 161 Rust + 68 frontend tests, 29 Playwright
journeys, 4 live kind tests, helm/install/LOC/placeholder gates, and
the clean-room install rehearsal serving the clawmates login page from
a signed bundle of the rebuilt images.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-06-10 12:31:25 -05:00

69 lines
2.5 KiB
TypeScript

import { expect, test, type Page } from "@playwright/test";
// P5 exit criterion (spec §17): the full admin + billing loop — credit
// decrement matches token usage, and promo redemption grants credits.
const OWNER_EMAIL = "[email protected]";
const OWNER_PASSWORD = "e2e-password";
async function signIn(page: Page) {
await page.goto("/login");
await page.getByLabel("Email").fill(OWNER_EMAIL);
await page.getByLabel("Password").fill(OWNER_PASSWORD);
await page.getByRole("button", { name: "Sign in" }).click();
await expect(page.getByRole("heading", { name: "Clawmates" })).toBeVisible();
}
async function readBalance(page: Page): Promise<number> {
await page.getByRole("link", { name: "Credits" }).click();
await expect(page.getByText("Available credits")).toBeVisible();
const text = await page.getByTestId("credit-balance").innerText();
return Number(text.replace(/,/g, ""));
}
test("chat usage decrements credits and shows in the 7-day meter", async ({
page,
}) => {
await signIn(page);
const before = await readBalance(page);
await page.getByRole("link", { name: /Scout/ }).click();
await expect(page).toHaveURL(/\/claws\/.+\/chat\//);
// Fresh session: older sessions carry scenario markers in history that
// would steer the scripted provider away from the plain echo.
const before_url = page.url();
await page.getByRole("button", { name: "New" }).click();
await page.waitForURL((url) => url.toString() !== before_url);
const box = page.getByLabel("Message Scout");
await box.fill("bill me for this message");
await box.press("Enter");
await expect(
page.getByText("I received: bill me for this message"),
).toBeVisible();
await expect
.poll(async () => readBalance(page), { timeout: 15000 })
.toBeLessThan(before);
await expect(page.getByText(/Usage · last 7 days/i)).toBeVisible();
await expect(page.getByText(/tokens \(/)).toBeVisible();
});
test("a promo code redeems exactly once", async ({ page }) => {
await signIn(page);
const before = await readBalance(page);
await page.getByLabel("Promo code").fill("WELCOME500");
await page.getByRole("button", { name: "Redeem" }).click();
await expect(page.getByText("Added 500 credits.")).toBeVisible();
await expect
.poll(async () => readBalance(page))
.toBe(before + 500);
// Second redemption refuses.
await page.getByLabel("Promo code").fill("WELCOME500");
await page.getByRole("button", { name: "Redeem" }).click();
await expect(
page.getByText("That code is invalid or already redeemed."),
).toBeVisible();
});