The best way to control Claude Code, Codex and more from any computer or phone

main
md 155 lines 8.56 KB
Rendered Raw
1 ---
2 name: harden
3 description: Harden one or more providers' live test suites until they are stable — repeat full suite runs with a leak census after each, root-cause every failure and leak (provider bug first, then distilled patch, then test, timeouts last), make every name and stage deterministic and isolated per user and worktree, and stop only when consecutive runs are green and clean. Use for "harden cloudflare", "harden the aws provider", "/harden gcp neon", "make the X suite stable", "do a few more runs to see how stable it is", or as the per-provider loop inside prepare-release.
4 metadata:
5 internal: true
6 ---
7
8 # Harden a provider's test suite
9
10 A suite is hardened when it passes **two consecutive full runs** and the
11 account census after each run shows nothing left behind. One green run proves
12 little: most of what this skill finds only shows up in some runs — eventual
13 consistency, retries that leak, other users or worktrees deploying the same
14 names, an API that sometimes ignores a write.
15
16 The arguments name the providers (`cloudflare`, `aws gcp`, …). You own the
17 runs, the fixes, the census and the commits. Work in this checkout, one test
18 process at a time. Fixes land in the branch you are on (the release PR when
19 prepare-release invoked you). The user merges; you never do.
20
21 ## The loop
22
23 1. **Run the provider's full suite once.** Detach it and write its output to
24 a numbered file, then census:
25
26 ```sh
27 pnpm test:integration test/<Provider> --profile testing > /tmp/harden/run-N.out 2>&1
28 pnpm nuke --profile testing --include '<Provider>.*' --dry-run --no-input > /tmp/harden/census-N.out
29 echo "run N: $(grep '^Tests:' /tmp/harden/run-N.out)" >> /tmp/harden/stability.log
30 ```
31
32 Keep `stability.log` as the table you report: one line per run, plus what
33 the census found.
34
35 2. **List the failures and leaks.** Failed tests are the `^✗ ` lines in the
36 summary. Each one's error follows it in the run output; the full record,
37 including retried attempts, is in the run log under
38 `packages/integration-tests/.alchemy/log/test/`.
39
40 3. **Root-cause every one.** In this order, stop at the first that applies:
41
42 | Cause | Fix |
43 | --- | --- |
44 | Provider bug (wrong read/diff/reconcile/delete, leak, name the API rejects) | the provider |
45 | Untyped or mis-typed error | a distilled patch |
46 | Test bug (shared name or stage, missing lock, unbounded or missing retry) | the test |
47 | Eventual consistency the provider can't own | a bounded retry in the test |
48 | Genuinely slow work (image builds, cold starts) | a longer timeout, matching its neighbors |
49 | Permanent account blocker (quota, entitlement) | `test.provider.skip` with a comment quoting the exact error |
50 | Platform outage (every test of a service fails at once with a 5xx-style error) | nothing; note it |
51
52 A longer timeout is the last resort, and only for work that is slow by
53 nature. A test that fails because a call raced the cloud is not slow.
54
55 **Never widen a permission to make a test pass.** An IAM `Resource: ["*"]`,
56 a dropped `Condition`, a broader Cloudflare permission group or GCP role is
57 a security regression, not a fix. When a cloud's own check rejects a scoped
58 grant (Lambda checks a Kafka event source's ENI-delete permission with no
59 subnet in the request), find the scoping that passes the check and still
60 limits real calls: `ArnEqualsIfExists` / `StringEqualsIfExists` skip a key
61 the check leaves out and enforce it on every real request. Assert the
62 scoping out of band (`iam.simulatePrincipalPolicy`: allowed inside the
63 scope, denied outside it).
64
65 4. **Verify each fix by rerunning the affected files, not the whole suite.**
66 Rerun them several times when the failure was intermittent:
67
68 ```sh
69 for i in 1 2 3 4 5; do pnpm test:integration <files> --profile testing 2>&1 | grep -E "^✗ |^Tests:"; done
70 ```
71
72 5. **Type-check, commit and push** each fix as its own conventional commit
73 (`fix(cloudflare): …`, `test(cloudflare/queues): …`).
74
75 6. **Clean up leaks you've root-caused** with a scoped nuke once no suite is
76 running, then start the next full run. Stop after two consecutive runs
77 with zero failures and a clean census. If a failure stays intermittent
78 after three fix attempts, stop fixing it and report it with its evidence.
79
80 ## Isolation: names, stages, locks
81
82 A test may only collide with itself. Most intermittent failures in a shared
83 account came from two runs — another user, another worktree, or the same
84 suite's retry — touching the same cloud object.
85
86 - **Names.** Let the resource generate the physical name. Only a test about
87 explicitly provided names passes one, built with `testName(base)` from
88 `packages/integration-tests/test/names.ts` (a short hash of the test stage),
89 or derived from `stack.stage`. Hostnames in a test zone follow the same rule.
90 Never `Date.now()`, UUIDs or random values in a name. A resource the API can
91 never delete (RealtimeKit apps, Intel indicator feeds) keeps one shared
92 constant name that every run adopts.
93 - **Stages.** A suite that sets its own stage (per-variant stages in
94 `describe.each`, a `stage:` on `Test.make`) prefixes it with
95 `Test.defaultStage()`. A linked git worktree defaults to
96 `test_$USER_<worktree>`, so two worktrees running the same suite never share
97 deployments; `--stage` overrides it.
98 - **Account-wide singletons.** Tests that contend for one account-level object
99 (Cloudflare allows one event subscription per source per account; SES
100 sending is account-wide) take the same `exclusive: "<label>"` in every file
101 that touches it.
102 - **Content-addressed ids.** Some APIs return the same id when you upload the
103 same content twice (Cloudflare mTLS certificates). Whatever a run attached to
104 that id comes back on the next upload, so its delete must be complete before
105 the parent is deleted.
106
107 ## Patterns that were provider bugs
108
109 Each of these looked like a flaky test and was fixed in the provider:
110
111 - **Generated names longer than the API allows** (Cloudflare managed networks
112 cap at 50, a DNS label at 63). Pass `maxLength` to `createPhysicalName`;
113 short names that already worked don't change.
114 - **A listing that lags a fresh write.** A Worker's attached-domain list
115 missed a domain attached seconds earlier, so the redirect rule for it was
116 never cleaned up. Fall back to a direct lookup instead of trusting the list.
117 - **A write the API sometimes ignores.** Clearing a CA's hostname association
118 occasionally didn't take. Re-send the write until a read shows it, and fail
119 the delete with a typed error rather than continue and leak.
120 - **A cold read with an unresolved Output.** Treating an unresolved id as
121 absent read a different singleton (the zone's managed CA) and reported a
122 conflict. Return `undefined` until the id resolves.
123
124 ## Investigating
125
126 - **Probe the API directly** with a throwaway test file (`ZZProbe.test.ts`
127 next to the suite, using `test.provider` and distilled calls), run it alone,
128 and delete it afterwards. Use it to settle a hypothesis ("does a re-upload
129 reuse the id?") instead of guessing.
130 - **Provider `console.log` doesn't reach the run log.** Log with
131 `yield* Effect.logInfo(...)` while debugging, and remove it after.
132 - **Before deleting a leftover, find its owner.** Check
133 `ps -eo etime,command | grep alchemy-test` for other worktrees running
134 suites against the same account; their live resources show up in your
135 census. Leave them alone.
136 - **Never run `pnpm` inside `submodules/distilled`** (`pnpm exec oxfmt`,
137 `pnpm exec tsrs`): it installs distilled's own workspace, a second `effect`
138 copy every alchemy type then mismatches ("Property '[NodeInspectSymbol]' is
139 missing"). Run every command from the repo root. If it happened, move
140 `submodules/distilled/node_modules` and `submodules/distilled/packages/*/node_modules`
141 aside, run `pnpm install` at the root, and type-check with
142 `pnpm exec tsrs -b --force` — a plain `-b` keeps the stale build state.
143 - **Credentials expire mid-run.** A suite that also deploys to another cloud
144 (Cloudflare bindings on an AWS Lambda) fails its teardown when that cloud's
145 session expires, and leaks its resources. Refresh sessions (`aws sso login`)
146 before each round, and rerun the file to clean up.
147 - **An error with an empty message hides the cause.** Give the tagged error a
148 `message` getter naming what failed, so the next occurrence is diagnosable.
149
150 ## Reporting
151
152 Report each round briefly: the run table, then one line per failure with its
153 cause, fix and verification. End with what is not fixed and why (outage,
154 account blocker, residual flake with evidence). Put fixes in the PR you are
155 on; report test results, not CI status.