跪拜 Guibai
← Back to the summary

One Full-Path E2E Run: 20 Symptoms, 5 Root Causes, All Missed by Unit Tests

Full-Path E2E: One Run Produces 20 Symptoms, Converging to 5 Root Causes

Alioth Technical Notes · Issue 25 · Testing / Regression Repository: https://github.com/aide-family/moon | Online demo: https://web.alioth.asia/

Introduction

Unit tests prove "each brick is good"; e2e proves "this wall can stand". Between the two lies a whole category of defects: no one wrote anything wrong, but when assembled together it's wrong. In one full-path e2e run, Alioth saw dozens of anomalies in the UI, eventually converging to 5 root causes—each of which was "completely correct" in the unit tests of some module. This post covers how the e2e was set up, what it surfaced, and how to prevent recurrence after fixing.

1. Login: mint a JWT directly

The most time-consuming part of e2e is usually login. Captchas, email, third-party callbacks—any unstable link makes the whole chain flaky. Alioth's approach is to bypass it—issue a token locally:

export function mintToken(uid = E2E_UID, ttlSeconds = 3600): string {
  const encode = (value: Buffer | string) => Buffer.from(value).toString("base64url")
  const header = encode(JSON.stringify({ alg: "HS256", typ: "JWT" }))
  const now = Math.floor(Date.now() / 1000)
  const payload = encode(JSON.stringify({ uid, kind: "access", iat: now, exp: now + ttlSeconds }))
  const signature = crypto.createHmac("sha256", E2E_SECRET)
    .update(`${header}.${payload}`).digest("base64url")
  return `${header}.${payload}.${signature}`
}

Then use Playwright's storageState to write token, tenant, language, theme into localStorage, so the page opens already logged in.

We must honestly state the boundary: this path skips the login flow itself. So processes like "captcha rate limiting" and "third-party login binding" cannot be tested with this fixture; they need separate real-login cases. Using a fixture saves time, but you can't pretend it covers what it skipped.

2. Data prep via API, not UI

async function seedGroup(api: ReturnType<typeof createApi>, name: string) {
  const created = await api.post("/v1/alert-rule-group", { name })
  expect(created.status).toBe(200)
  return created.json.group.uid as string
}

test("current step validation failure prevents next step", async ({ page }) => {
  const api = createApi()
  const groupUid = await seedGroup(api, `e2e-step-${Date.now()}`)
  try {
    ...
  } finally {
    await api.delete(`/v1/alert-rule-group/${groupUid}`)
    await api.dispose()
  }
})

Three conventions:

  1. Don't click the UI to prep data. Use API for preconditions; the UI is only responsible for the single action under assertion. Otherwise one case tests three things at once, and when it fails you can't tell what broke.
  2. Each case creates its own data and cleans it up. Delete in finally, name with Date.now(). The test database is shared; leftover data makes the next case fail for no reason.
  3. workers: 1. Because all cases share one database and one tenant dataset, parallel runs step on each other. The cost is slowness; the benefit is stability—a worthwhile trade for a self-hosted platform.

3. Assert what shouldn't happen

Here's the most typical case: the alert rule's three-step form. When the first step fails validation, clicking "Next" must stay on step one and show the error:

await dialog.getByRole("button", { name: "下一步" }).click()
await expect(dialog.getByText("1 / 3")).toBeVisible()
await expect(dialog.getByText("请填写名称")).toBeVisible()

Good e2e cases assert behavioral constraints, not pixels. The three-step form's most common bug is "you can move to the next step, but the second step is empty"—each step individually looks right, but chained together it's wrong. Such defects only surface by exercising the real flow.

4. Twenty symptoms, five root causes

After that full run, the fix commit message was restrained, just five lines:

- probe: keep newly added targets when updating a target group; fill
  target_spec on result list/latest reads from probe_targets
- kubernetes: retry workload image changes and rollbacks on 409 conflict
  with a fresh Get inside the retry loop
- user: allow granting SYSTEM_READONLY platform role in the data layer
- datasource: validate availability window/threshold before applying
  defaults so enabled with 0 is rejected
- alert event: return not found when intervening on unknown event uids

Five root causes, five different levels of error:

Root cause Symptom Essence
Updating a target group drops new targets Newly created probe targets missing Update semantics: full replace vs incremental merge
K8s 409 conflict lacking retry Random failure when changing image Optimistic concurrency: read-modify-write must retry
Data layer rejects SYSTEM_READONLY Granting read-only admin fails New enum value, a switch missed a branch
Availability alert allows enabled + 0 Switch on but never triggers Defaults take effect before validation
Intervening on unknown event returns success Clicked intervene, nothing happened Batch operation lacks semantics for zero hits

Notably: none were "a function written wrong"—all were "two correct assumptions not meeting each other". The first is interface contract (replace vs merge), the second is concurrency model, the third is enum extension, the fourth is default value vs validation order, the fifth is empty-set semantics.

5. Fix order: data first, then concurrency, then UI

The order of fixing the five root causes wasn't arbitrary:

  1. Fix semantic and data layers first (target-group merge, read-only role grant, empty-set returning not-found)—these define "what the interface says it should do"; UI behavior becomes explainable only after they're fixed;
  2. Then concurrency (409 retry)—it affects stability, not semantic correctness, but it turns sporadic failures into noise;
  3. Finally default-value ordering (validate before applying defaults)—this kind of problem most often appears in the UI as "save succeeded but nothing happened". Fixing the first two categories confirms it's really the root cause.

If you reverse and adjust UI copy first, you get "the hint is correct but behavior is still wrong"—because UI is only a projection of backend semantics.

6. Every root cause gets a regression test

This was the most valuable action of that fix: the commit added 4 test files and +1022 lines, with probe_repo_fix_test.go, user_repo_fix_test.go, and kubernetes_rollout_test.go pinning three of the root causes at the data layer.

Why the data layer rather than e2e? Because e2e takes tens of seconds per run and can't be done for every edge case; once a root cause is localized to a specific function, lock it with a unit test that runs in milliseconds. E2E discovers, unit tests lock down—that's the most cost-effective division of labor.

7. A few real pitfalls

  1. Keep full evidence on failure. trace: "retain-on-failure" + screenshot: "only-on-failure" gives failed cases a full trace; successful cases produce no garbage files.
  2. Set retries to 0. retries: 0 is deliberate: retries hide flakiness, and flakiness itself is usually a real defect (timing, race, cache). Let it go red so it gets fixed.
  3. Use the local Chrome. channel: "chrome" skips downloading a browser; just preinstall it in the CI image.
  4. Expect timeout shorter than API timeout. expect.timeout = 10s, while some page polls are 5 seconds apart; setting it to 30s makes failing cases wait pointlessly and slows feedback.
  5. Don't swallow cleanup failures. A deletion in finally that fails should at least be logged, otherwise leftover data surfaces next run as "another case failing", doubling debugging cost.

8. How to run

git clone https://github.com/aide-family/moon.git && cd moon
make dev-up
cd web && npm run e2e

Environment variables can override E2E_API_URL / E2E_WEB_URL / E2E_JWT_SECRET / E2E_USER_UID / E2E_NAMESPACE. Defaults correspond to local dev environment; ensure make dev-up is up before running, and that UID is a real superadmin.

Conclusion

E2E's value isn't "how many interfaces were covered", but it puts non-adjacent modules into one shared real state. Those twenty symptoms and five root causes—none could be found by single-module testing—because each module was working correctly per its own assumptions. And the end of the fix wasn't "the UI looks normal", but every root cause has a millisecond unit test guarding it; next time someone reverts a change, CI speaks first.


Next: series closing—consolidating the design decisions from the previous 25 posts into a checklist.

Comments

Top 1 of 2 from juejin.cn, machine-translated. The original thread is authoritative.

用户7959111904680

Hello, great master. I've benefited a lot from reading your article. May I ask if I can repost some of your articles for more peers to see? I'll credit the author and source~ [heart]

一条Go

OK