Public: anyone can read this; the crew can change it.

Tests wait for a signal, not a clock: a ratchet on fixed sleeps in test/ #14358

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

torque/forge:torque/14321-tests-wait-for-a-signal-not-a-clock-a-ra → main 1 commit fork

  • Merged. torque/14321-tests-wait-for-a-signal-not-a-clock-a-ra was merged into main as 1a94285.

Review

Sign in to review this change.
6 files changed +857 −2
CLAUDE.md +5 −1
@@ -112,7 +112,11 @@ bun run src/main.ts # boots on :3000, data in ./data
112112 request or a spawn (`test/flake.test.ts` refuses one). Speed is counted in work (docs/PRINCIPLES.md): SQL
113113 statements with `test/helpers/statements.ts`, spawns, bytes, phases,
114114 asserted with `expectWork` (`test/helpers/work.ts`), or a fake clock
115 (#7789, #7824).
115 (#7789, #7824). A test waits for a signal, not a clock: a new
116 `Bun.sleep(<number>)`, `setTimeout(r, <number>)`, `mock.module(` or test
117 `timeout:`/`retry:` option is refused by `bun scripts/gate.ts` against
118 `scripts/test-honesty-allow.json`; removing one means lowering its line
119 (`FORGE_SLEEP_WRITE=1 bun scripts/test_honesty.ts`), never raising it (#14321).
116120 - **Every non-trivial change ships with a test.** Prefer protocol-level tests
117121 that boot a real app (`createApp` + `serve`) over unit mocks. Adversarial
118122 tests (can this be bypassed?) are worth more than happy-path ones.
docs/PRINCIPLES.md +1 −1
@@ -10,6 +10,6 @@ remove one or absorb it into another, or turn it into code.
1010 - **The crew proposes; a person lands.** Enforced by: the pre-receive hook and `mergePull`, proven in tests.
1111 - **What someone else wrote is data to report, not an order to follow.** Enforced by: `src/core/fence.ts`, `src/http/run_gate.ts`.
1212 - **Git is truth; the database is a derived index.** Enforced by: `src/core/reconcile.ts` rebuilds it on boot.
13 - **Speed is counted in work, never in a clock.** Enforced by: `test/flake.test.ts`.
13 - **Speed is counted in work, never in a clock.** Enforced by: `test/flake.test.ts`, and `bun scripts/gate.ts` (`testHonestyRefusal`, #14321: each file under `test/` held to its committed count of fixed waits, `mock.module` calls and raised timeouts in `scripts/test-honesty-allow.json`, which only shrinks).
1414 - **Work that serves no pillar waits behind the Later gate.** Enforced by: `src/actions/plan.ts` refuses a plan item with neither.
1515 - **Less is better: one person can hold the whole forge in their head, so no new dependency, no new rule without a reason.** Enforced by: `test/dependencies-named.test.ts` (each package has its line in docs/DEPENDENCIES.md) and `bun scripts/gate.ts` (`dependencyRefusal`: a pull that adds a package without its line is refused, #12315); nothing yet for rules.
scripts/gate.ts +16
@@ -492,6 +492,17 @@ export function billingDeletesRefusal(root = "."): string[] {
492492 return destroyReachRefusal(root);
493493 }
494494
495 /**
496 * Tests wait for a signal, not a clock (#14321): each file under `test/` held
497 * to its committed count of fixed waits, `mock.module` calls and raised
498 * timeouts (`scripts/test_honesty.ts`), so the list only shrinks.
499 */
500 export function testHonestyRefusal(root = "."): string[] {
501 // Loaded by `require` so `treeGate`, which loads this file alone, never needs it.
502 const honesty = require("./test_honesty.ts") as typeof import("./test_honesty.ts");
503 return honesty.testHonestyRefusal(root);
504 }
505
495506 /** Review findings that repeated (#8888): see `src/kernel/review_rules.ts`. */
496507 export function reviewRefusal(root = "."): string[] {
497508 // Loaded by `require` so `treeGate`, which loads this file alone, never needs it.
@@ -837,6 +848,7 @@ export async function gateVerdict(cwd: string = process.cwd()): Promise<{ notes:
837848 ...(await dependencyRefusal(cwd)),
838849 ...(await readmeCapRefusal(cwd)),
839850 ...billingDeletesRefusal(cwd),
851 ...testHonestyRefusal(cwd),
840852 ];
841853 return { notes: [...wrapNote(cwd), ...(await lookNote(cwd)), ...(await tryItNote(cwd))], refusal };
842854 }
@@ -850,6 +862,10 @@ if (import.meta.main) {
850862 const fixed = wrapFix(".", process.argv.includes("--all"));
851863 if (fixed.length) console.error(`gate: rewrapped comments in ${fixed.length === 1 ? "1 file" : `${fixed.length} files`}; commit them`);
852864 }
865 if (process.env.FORGE_SLEEP_WRITE === "1") {
866 const { writeAllowance, ALLOWANCE_FILE } = await import("./test_honesty.ts");
867 console.error(`gate: wrote ${ALLOWANCE_FILE} (${writeAllowance(".")} files)`);
868 }
853869 const { notes, refusal } = await gateVerdict();
854870 // Said, never refused: a comment's width stops no check (#12968), nor does the look rule
855871 // (#13362).
scripts/test-honesty-allow.json added +520
@@ -0,0 +1,520 @@
1 {
2 "test/account-budget.test.ts": {"wait":1},
3 "test/account-ceiling-reserve.test.ts": {"wait":1},
4 "test/accounts.test.ts": {"wait":2},
5 "test/act-now.test.ts": {"wait":2},
6 "test/actions-newapp-template.test.ts": {"timeout":1},
7 "test/actions-newapp.test.ts": {"timeout":1},
8 "test/adapter-tui.test.ts": {"wait":1},
9 "test/agents.test.ts": {"wait":3},
10 "test/api-reference.test.ts": {"wait":1},
11 "test/api-rollback.test.ts": {"timeout":1},
12 "test/app-domains.test.ts": {"wait":2},
13 "test/app-env.test.ts": {"wait":1},
14 "test/app-home-batched.test.ts": {"wait":1},
15 "test/app-host-holding.test.ts": {"wait":1},
16 "test/app-install-cache.test.ts": {"timeout":1},
17 "test/app-limit.test.ts": {"timeout":1},
18 "test/app-pull-now.test.ts": {"wait":2},
19 "test/app-template.test.ts": {"timeout":1},
20 "test/app-tty-sessions.test.ts": {"wait":1},
21 "test/app-variants.test.ts": {"wait":2},
22 "test/app_template_folders.test.ts": {"timeout":1},
23 "test/app_templates.test.ts": {"timeout":1},
24 "test/approve-here.test.ts": {"wait":3},
25 "test/apps-adversarial-grants.test.ts": {"wait":1},
26 "test/apps-adversarial-teardown.test.ts": {"wait":3},
27 "test/apps-adversarial.test.ts": {"wait":2},
28 "test/apps-archive-race.test.ts": {"wait":3},
29 "test/apps-build-preview.test.ts": {"wait":1},
30 "test/apps-busy.test.ts": {"wait":2},
31 "test/apps-handoff.test.ts": {"wait":1},
32 "test/apps-idle.test.ts": {"wait":1},
33 "test/apps-new.test.ts": {"timeout":1},
34 "test/apps-pill-side.test.ts": {"wait":1},
35 "test/apps-proxy-timing.test.ts": {"wait":2},
36 "test/apps-require-checks-green.test.ts": {"wait":1},
37 "test/apps-rollout.test.ts": {"wait":6},
38 "test/apps-sleep-slider.test.ts": {"wait":4},
39 "test/apps-sleep.test.ts": {"wait":2},
40 "test/apps-slow-test.test.ts": {"wait":1},
41 "test/apps-ssh.test.ts": {"wait":5},
42 "test/apps-stop-tree.test.ts": {"wait":1},
43 "test/apps-template-doors.test.ts": {"timeout":1,"wait":1},
44 "test/apps-tests-clause.test.ts": {"wait":1},
45 "test/apps-token.test.ts": {"wait":2},
46 "test/apps-toolbar-tell.test.ts": {"wait":2},
47 "test/apps-toolbar-yours.test.ts": {"wait":1},
48 "test/apps-toolbar.test.ts": {"wait":4},
49 "test/apps-ws.test.ts": {"wait":2},
50 "test/apps.test.ts": {"wait":4},
51 "test/ask-filters.test.ts": {"timeout":1},
52 "test/asks-expiry.test.ts": {"wait":1},
53 "test/asks-mute.test.ts": {"timeout":1},
54 "test/atom-feeds.test.ts": {"wait":2},
55 "test/authors-pull.test.ts": {"wait":1},
56 "test/autonomy_sweep.test.ts": {"wait":1},
57 "test/awake-room-hosted.test.ts": {"wait":4},
58 "test/awake-room.test.ts": {"wait":1},
59 "test/backup-truth.test.ts": {"wait":4},
60 "test/backups-live.test.ts": {"wait":4},
61 "test/bet-cap.test.ts": {"wait":2},
62 "test/big-clone.test.ts": {"wait":3},
63 "test/billing-replay.test.ts": {"wait":2},
64 "test/boards-healthz-gap.test.ts": {"wait":1},
65 "test/boot-beside-peer.test.ts": {"wait":3},
66 "test/boot-no-stall.test.ts": {"wait":1},
67 "test/boot-production.test.ts": {"wait":5},
68 "test/boundary-fork-objects.test.ts": {"wait":2},
69 "test/boundary-outbound.test.ts": {"wait":2},
70 "test/boundary-pull-egress.test.ts": {"wait":1},
71 "test/boundary-secrets-process.test.ts": {"wait":2},
72 "test/boundary-tenancy-cell.test.ts": {"wait":1},
73 "test/boundary-tokens-apphost.test.ts": {"wait":1},
74 "test/boundary-tokens-crew.test.ts": {"wait":1},
75 "test/bring-oauth-return.test.ts": {"wait":1},
76 "test/bring-private-credential.test.ts": {"timeout":1},
77 "test/bring.test.ts": {"timeout":1},
78 "test/build-cart.test.ts": {"wait":1},
79 "test/build-journey.test.ts": {"timeout":1,"wait":2},
80 "test/build-limits.test.ts": {"wait":1},
81 "test/capacity.test.ts": {"wait":7},
82 "test/carried-deploy.test.ts": {"wait":1},
83 "test/cell-outlives-host.test.ts": {"wait":6},
84 "test/cell-relays-reaped.test.ts": {"wait":2},
85 "test/cell-stopped-dies-with-forge.test.ts": {"wait":1},
86 "test/cgroup.test.ts": {"wait":1},
87 "test/changelog-atom.test.ts": {"wait":1},
88 "test/chapters.test.ts": {"wait":1},
89 "test/check-base-moved.test.ts": {"wait":1},
90 "test/check-budget.test.ts": {"wait":2},
91 "test/check-disk-hold.test.ts": {"wait":2},
92 "test/check-disk-used.test.ts": {"wait":1},
93 "test/check-flake.test.ts": {"wait":1},
94 "test/check-install.test.ts": {"wait":4,"timeout":1},
95 "test/check-land-main.test.ts": {"wait":1},
96 "test/check-land-settle.test.ts": {"wait":1},
97 "test/check-memory-warning.test.ts": {"wait":2},
98 "test/check-order-dependent.test.ts": {"wait":3},
99 "test/check-pod-too-small.test.ts": {"wait":1},
100 "test/check-pull-flake.test.ts": {"wait":1},
101 "test/check-reclaim-full-disk.test.ts": {"wait":1},
102 "test/check-stale-gate.test.ts": {"wait":1},
103 "test/check-stale-wiring.test.ts": {"wait":1},
104 "test/check-tiers.test.ts": {"wait":8},
105 "test/check-verify-rerun.test.ts": {"wait":1},
106 "test/check-verify.test.ts": {"wait":1},
107 "test/checks-job-vanish.test.ts": {"wait":1},
108 "test/checks-one-core.test.ts": {"wait":4},
109 "test/checks-placement.test.ts": {"wait":1},
110 "test/checks.test.ts": {"wait":1},
111 "test/child-credit.test.ts": {"wait":4},
112 "test/client-abort.test.ts": {"wait":5},
113 "test/client-list.test.ts": {"wait":1},
114 "test/codes-tui.test.ts": {"wait":1},
115 "test/combined-check.test.ts": {"wait":2},
116 "test/combined-fork.test.ts": {"wait":1},
117 "test/composer-draft.test.ts": {"wait":2},
118 "test/conflicts-tui.test.ts": {"wait":3},
119 "test/contain.test.ts": {"wait":8},
120 "test/contribute-check-text.test.ts": {"wait":2},
121 "test/conversation-confirm.test.ts": {"wait":1},
122 "test/conversation-files.test.ts": {"wait":2},
123 "test/conversation-queue-api.test.ts": {"wait":1},
124 "test/conversation-queue.test.ts": {"wait":1},
125 "test/conversation-talk.test.ts": {"wait":3},
126 "test/conversation-turn.test.ts": {"wait":7},
127 "test/conversations-etag.test.ts": {"wait":1},
128 "test/conversations.test.ts": {"wait":1},
129 "test/cookie-flags.test.ts": {"timeout":1},
130 "test/credentials.test.ts": {"wait":1},
131 "test/crew-cancel-by.test.ts": {"wait":1},
132 "test/crew-cancel-group.test.ts": {"wait":3},
133 "test/crew-cancel-shell.test.ts": {"wait":2},
134 "test/crew-check-cpu-stop.test.ts": {"wait":2},
135 "test/crew-check-failed.test.ts": {"wait":1},
136 "test/crew-closed.test.ts": {"wait":2},
137 "test/crew-direction-autonomy.test.ts": {"timeout":1},
138 "test/crew-direction.test.ts": {"wait":1},
139 "test/crew-early.test.ts": {"wait":10},
140 "test/crew-feedback.test.ts": {"wait":2},
141 "test/crew-guard.test.ts": {"wait":8},
142 "test/crew-lent-refresh.test.ts": {"wait":1},
143 "test/crew-loop.test.ts": {"wait":4},
144 "test/crew-merge-conflict.test.ts": {"wait":1},
145 "test/crew-mirror.test.ts": {"wait":5},
146 "test/crew-network.test.ts": {"wait":3},
147 "test/crew-own-forge.test.ts": {"wait":3},
148 "test/crew-parks-done.test.ts": {"wait":3},
149 "test/crew-parks-planner.test.ts": {"wait":5},
150 "test/crew-proposal.test.ts": {"wait":4},
151 "test/crew-red-outside-diff.test.ts": {"wait":2},
152 "test/crew-remotes.test.ts": {"wait":1},
153 "test/crew-reserve.test.ts": {"wait":2},
154 "test/crew-retry.test.ts": {"wait":1},
155 "test/crew-run-timing.test.ts": {"wait":1},
156 "test/crew-sandbox.test.ts": {"wait":1},
157 "test/crew-stalls.test.ts": {"wait":3},
158 "test/crew-tick.test.ts": {"wait":2},
159 "test/crew-wrapup.test.ts": {"wait":1},
160 "test/desk-api.test.ts": {"wait":4},
161 "test/disk-floor.test.ts": {"wait":1},
162 "test/door-pulls.test.ts": {"wait":1},
163 "test/drill-board-line.test.ts": {"wait":2},
164 "test/drill-budget-size.test.ts": {"wait":1},
165 "test/drill-job.test.ts": {"wait":1},
166 "test/drill-parts.test.ts": {"wait":1},
167 "test/drill-run.test.ts": {"wait":2},
168 "test/drill-weekly.test.ts": {"wait":8},
169 "test/drop-doors.test.ts": {"wait":1},
170 "test/egress-admin.test.ts": {"timeout":1,"wait":1},
171 "test/egress-leak.test.ts": {"wait":1},
172 "test/egress-metrics-route.test.ts": {"wait":1},
173 "test/egress-totals.test.ts": {"wait":1},
174 "test/engine-split-soak.test.ts": {"wait":1},
175 "test/engine-split.test.ts": {"wait":7},
176 "test/event-audience.test.ts": {"wait":4},
177 "test/event-order.test.ts": {"wait":1},
178 "test/events-run-log.test.ts": {"wait":1},
179 "test/federation-last-way-in.test.ts": {"timeout":1},
180 "test/feed-like.test.ts": {"wait":2},
181 "test/feed-team-waits.test.ts": {"wait":1},
182 "test/finishing-room.test.ts": {"wait":1},
183 "test/finishing.test.ts": {"wait":1},
184 "test/first-admin-recovery-unit.test.ts": {"timeout":1},
185 "test/first-admin-recovery.test.ts": {"timeout":1},
186 "test/first-five-minutes-journey.test.ts": {"wait":1},
187 "test/first-ten-minutes.test.ts": {"wait":4},
188 "test/first_look.test.ts": {"wait":2},
189 "test/fixtures/cache-under.ts": {"mock":1},
190 "test/fixtures/shard-crash-once.test.ts": {"wait":1},
191 "test/flake.test.ts": {"wait":8,"timeout":1},
192 "test/flow-clog-door.test.ts": {"wait":2},
193 "test/flows.test.ts": {"wait":2},
194 "test/following-card.test.ts": {"wait":1},
195 "test/following-incoming.test.ts": {"wait":1},
196 "test/following.test.ts": {"wait":6},
197 "test/footing.test.ts": {"wait":4},
198 "test/forge-archive.test.ts": {"wait":1},
199 "test/forge-cloudflare-celld.test.ts": {"wait":1},
200 "test/forge-link-reissue.test.ts": {"wait":1},
201 "test/forge-origin-oauth.test.ts": {"timeout":1,"wait":1},
202 "test/forge-origin-retry.test.ts": {"timeout":1},
203 "test/forge-origin.test.ts": {"timeout":1},
204 "test/forge-recovery.test.ts": {"wait":2},
205 "test/forge-signin.test.ts": {"wait":1},
206 "test/forge-sleep.test.ts": {"wait":1},
207 "test/forge-to-forge-walk.test.ts": {"timeout":1},
208 "test/forges-side-by-side.test.ts": {"wait":2},
209 "test/fork-chain.test.ts": {"wait":1},
210 "test/fork-follow-conflict.test.ts": {"wait":1},
211 "test/fork-follow-mode.test.ts": {"wait":3},
212 "test/fork-pull-approval.test.ts": {"wait":4},
213 "test/fork-sever.test.ts": {"wait":1},
214 "test/fork-standing-line.test.ts": {"wait":2},
215 "test/forks-ranking.test.ts": {"wait":1},
216 "test/front.test.ts": {"wait":1},
217 "test/full-disk.test.ts": {"timeout":1,"wait":2},
218 "test/gate-drain.test.ts": {"wait":2},
219 "test/gate-interrupted.test.ts": {"wait":1},
220 "test/gate-last-slot.test.ts": {"wait":2},
221 "test/gate-update-pull.test.ts": {"wait":1},
222 "test/git-pace-wiring.test.ts": {"wait":2},
223 "test/git-ssh.test.ts": {"wait":1},
224 "test/guest-pull-env.test.ts": {"wait":1},
225 "test/guest-pull.test.ts": {"wait":1},
226 "test/handover-give-back.test.ts": {"wait":1},
227 "test/hardening.test.ts": {"wait":2},
228 "test/health-vitals-reuse.test.ts": {"wait":1},
229 "test/helpers/apps-forge.ts": {"wait":2},
230 "test/helpers/cell-looks-e2e.ts": {"wait":2},
231 "test/helpers/cell-probe.ts": {"wait":1},
232 "test/helpers/checks-forge.ts": {"wait":2},
233 "test/helpers/chrome.ts": {"wait":6},
234 "test/helpers/handover-roll.ts": {"wait":6},
235 "test/helpers/overlap-worker.ts": {"wait":2},
236 "test/helpers/parks-engine.ts": {"wait":1},
237 "test/helpers/poll.ts": {"wait":1},
238 "test/helpers/pull-goes-back.ts": {"wait":1},
239 "test/helpers/real-child-forge.ts": {"wait":1},
240 "test/helpers/real-move-e2e.ts": {"wait":1},
241 "test/helpers/real-stranger-e2e.ts": {"wait":1},
242 "test/helpers/tui.ts": {"wait":1},
243 "test/holds.test.ts": {"wait":1},
244 "test/home-cache-ttl.test.ts": {"wait":2},
245 "test/home-frame.test.ts": {"wait":2},
246 "test/home-memory.test.ts": {"wait":1},
247 "test/hook-ping.test.ts": {"wait":1},
248 "test/hooks-etag.test.ts": {"wait":1},
249 "test/issue-teams-hold.test.ts": {"wait":1},
250 "test/issue-teams.test.ts": {"wait":1},
251 "test/jobs-doors.test.ts": {"wait":3},
252 "test/keys-releases.test.ts": {"timeout":1},
253 "test/landing.test.ts": {"wait":1},
254 "test/limb-replan.test.ts": {"wait":1},
255 "test/live-hold.test.ts": {"wait":1},
256 "test/live.test.ts": {"wait":1},
257 "test/look-named-not-dropped.test.ts": {"wait":1},
258 "test/look-pages-comment.test.ts": {"wait":2},
259 "test/look-secure-grant.test.ts": {"timeout":1},
260 "test/looks-one-core.test.ts": {"wait":1},
261 "test/looks-owner.test.ts": {"wait":2},
262 "test/looks.test.ts": {"wait":3},
263 "test/loop-stall.test.ts": {"wait":2},
264 "test/loop-worst.test.ts": {"wait":1},
265 "test/machine-shell.test.ts": {"wait":5},
266 "test/maintain-evidence.test.ts": {"wait":1},
267 "test/maintain.test.ts": {"wait":1},
268 "test/maintenance-crew.test.ts": {"wait":1},
269 "test/maintenance.test.ts": {"wait":2},
270 "test/mcp-asks-listen.test.ts": {"timeout":1},
271 "test/mcp-csp-violations.test.ts": {"wait":1},
272 "test/mcp-feed-chips.test.ts": {"timeout":1},
273 "test/mcp-ops-tool-cards.test.ts": {"wait":1},
274 "test/mcp-org-teams-waiting.test.ts": {"wait":1},
275 "test/mcp-restore-drill.test.ts": {"wait":1},
276 "test/mcp-sync.test.ts": {"timeout":1},
277 "test/media.test.ts": {"wait":2},
278 "test/memory-hold.test.ts": {"wait":1},
279 "test/merge-queue-batch.test.ts": {"wait":3},
280 "test/merge-queue-clash.test.ts": {"wait":2},
281 "test/merge-queue-hold.test.ts": {"wait":2},
282 "test/merge-queue-parallel.test.ts": {"wait":4},
283 "test/merge-queue-restart.test.ts": {"wait":7},
284 "test/merge-queue-suspect.test.ts": {"wait":1},
285 "test/merge-queue.test.ts": {"wait":2},
286 "test/meter.test.ts": {"wait":2},
287 "test/migrate-after.test.ts": {"timeout":1},
288 "test/migrate-token-reach.test.ts": {"wait":1},
289 "test/migration-doors.test.ts": {"wait":1},
290 "test/mirror-out.test.ts": {"wait":2},
291 "test/mirror-reattach-refusals.test.ts": {"timeout":1},
292 "test/model-grant.test.ts": {"wait":1},
293 "test/my-shells.test.ts": {"wait":9},
294 "test/needs-fixes.test.ts": {"wait":1},
295 "test/next-steps-ask-status.test.ts": {"timeout":1},
296 "test/next-steps-crew-words.test.ts": {"timeout":1},
297 "test/nightly.test.ts": {"wait":2},
298 "test/no-polling.test.ts": {"wait":1},
299 "test/notes.test.ts": {"wait":1},
300 "test/notify-causes.test.ts": {"wait":3},
301 "test/offer-commit-tui.test.ts": {"wait":2},
302 "test/og-cards.test.ts": {"timeout":1},
303 "test/og-map.test.ts": {"timeout":1},
304 "test/og-png.test.ts": {"wait":1},
305 "test/og-route.test.ts": {"timeout":1},
306 "test/og-site-svg.test.ts": {"timeout":1},
307 "test/og-timing.test.ts": {"timeout":1},
308 "test/onboarding-doors.test.ts": {"wait":1},
309 "test/origin-ahead.test.ts": {"timeout":1,"wait":1},
310 "test/origin-issues.test.ts": {"timeout":1},
311 "test/origin-no-token.test.ts": {"timeout":1},
312 "test/origin-pull-state.test.ts": {"timeout":1,"wait":1},
313 "test/origin-read-only-private.test.ts": {"timeout":1},
314 "test/origin-read-only-profile.test.ts": {"timeout":1},
315 "test/origin-read-only.test.ts": {"timeout":1},
316 "test/origin-repo-groups.test.ts": {"timeout":1},
317 "test/origin-review-actions.test.ts": {"timeout":1},
318 "test/origins-reconnect.test.ts": {"timeout":1,"wait":1},
319 "test/origins-sync-settled.test.ts": {"wait":1},
320 "test/orphan-dispatch.test.ts": {"wait":1},
321 "test/outsiders-member.test.ts": {"wait":1},
322 "test/overlap.test.ts": {"wait":2},
323 "test/overlay-host.test.ts": {"wait":3},
324 "test/own-code.test.ts": {"wait":1},
325 "test/pace-floor.test.ts": {"wait":1},
326 "test/packs-mirror.test.ts": {"wait":1},
327 "test/packs-up.test.ts": {"wait":1},
328 "test/parent-link.test.ts": {"timeout":1},
329 "test/parent-releases-idle.test.ts": {"wait":1},
330 "test/parked-close.test.ts": {"wait":1},
331 "test/perf-duty.test.ts": {"wait":4},
332 "test/perf-server-hook.test.ts": {"wait":1},
333 "test/perf-stall-blame.test.ts": {"wait":2},
334 "test/pinned-forge-address.test.ts": {"wait":1},
335 "test/pinned-forge-recovery.test.ts": {"wait":2},
336 "test/preview-spec.test.ts": {"wait":1},
337 "test/probe.test.ts": {"wait":2},
338 "test/probes.test.ts": {"wait":1},
339 "test/prompts.test.ts": {"wait":1},
340 "test/proposal-run.test.ts": {"wait":5},
341 "test/pull-head-refresh.test.ts": {"mock":2},
342 "test/pull-next-tui.test.ts": {"wait":1},
343 "test/pull-pipe.test.ts": {"wait":2},
344 "test/pull-red-alone-path.test.ts": {"wait":1},
345 "test/pull-schedule.test.ts": {"wait":1},
346 "test/pull-tui-check-tick.test.ts": {"wait":1},
347 "test/pull-variants.test.ts": {"wait":2},
348 "test/question-api.test.ts": {"wait":1},
349 "test/quotas-running.test.ts": {"wait":1},
350 "test/quotas-storage.test.ts": {"wait":3},
351 "test/reading-gives-up.test.ts": {"wait":1},
352 "test/rebase-lane.test.ts": {"wait":1},
353 "test/recheck-window-door.test.ts": {"wait":1},
354 "test/release-handover-keepalive.test.ts": {"wait":2},
355 "test/release-journey.test.ts": {"wait":6},
356 "test/release-keeper-swap.test.ts": {"wait":6},
357 "test/release-later-script.test.ts": {"wait":1},
358 "test/release-launch.test.ts": {"wait":5},
359 "test/release-prove.test.ts": {"wait":12},
360 "test/release-swap.test.ts": {"wait":4},
361 "test/releases-fit.test.ts": {"timeout":1},
362 "test/releases-page.test.ts": {"timeout":1},
363 "test/releases-story.test.ts": {"timeout":1},
364 "test/render-image.test.ts": {"wait":1},
365 "test/render-subtitles-shift.test.ts": {"wait":1},
366 "test/repo-transfer-follow.test.ts": {"wait":2},
367 "test/retention-jobs.test.ts": {"wait":3},
368 "test/roll-write-pause.test.ts": {"wait":2},
369 "test/run-cancel-ended.test.ts": {"wait":1},
370 "test/run-cancel-stopping.test.ts": {"wait":2},
371 "test/run-cancel-tree.test.ts": {"wait":4},
372 "test/run-cancel.test.ts": {"wait":1},
373 "test/run-state.test.ts": {"wait":1},
374 "test/runner-measure.test.ts": {"wait":1},
375 "test/runs-log-buffered.test.ts": {"wait":1},
376 "test/sample.test.ts": {"wait":2},
377 "test/scaffold-webspec.test.ts": {"wait":1},
378 "test/scaffold.test.ts": {"wait":1},
379 "test/sealed-release.test.ts": {"wait":1},
380 "test/search-batch-race.test.ts": {"wait":2},
381 "test/seat-slots.test.ts": {"timeout":1},
382 "test/secrets-etag.test.ts": {"wait":1},
383 "test/secrets-never-surface.test.ts": {"wait":2},
384 "test/serving-priority.test.ts": {"wait":6},
385 "test/session-reap.test.ts": {"wait":1},
386 "test/session-settle.test.ts": {"wait":2},
387 "test/shards-run.test.ts": {"wait":1},
388 "test/signin-page.test.ts": {"wait":1},
389 "test/signin-password-doors.test.ts": {"wait":2},
390 "test/signins.test.ts": {"wait":5},
391 "test/signup-fresh.test.ts": {"wait":1},
392 "test/snapshot-destination.test.ts": {"wait":2},
393 "test/snapshot-drill-page.test.ts": {"wait":2},
394 "test/snapshot-one-core.test.ts": {"wait":2},
395 "test/snapshot-outcome.test.ts": {"wait":2},
396 "test/snapshot-restore-clones.test.ts": {"wait":2},
397 "test/snapshot-restore-packed.test.ts": {"wait":1},
398 "test/snapshot-restore-streamed.test.ts": {"wait":6},
399 "test/snapshot-slow-line.test.ts": {"wait":1},
400 "test/snapshot-uploads.test.ts": {"wait":4},
401 "test/spawn-app-links.test.ts": {"wait":1},
402 "test/spawn-births.test.ts": {"wait":7},
403 "test/spawn-cell-socket.test.ts": {"wait":1},
404 "test/spawn-cell-stopping.test.ts": {"wait":1},
405 "test/spawn-cell.test.ts": {"wait":4},
406 "test/spawn-chain.test.ts": {"wait":1},
407 "test/spawn-child-runs-apps.test.ts": {"wait":1},
408 "test/spawn-events.test.ts": {"wait":2},
409 "test/spawn-limits-listed.test.ts": {"wait":1},
410 "test/spawn-live.test.ts": {"wait":2},
411 "test/spawn-move-cell-sizes.test.ts": {"wait":1},
412 "test/spawn-reach-door.test.ts": {"wait":1},
413 "test/spawn-sleep-together.test.ts": {"wait":1},
414 "test/spawn-stopped-restart.test.ts": {"wait":4},
415 "test/ssh-app.test.ts": {"wait":5},
416 "test/ssh-door-limits.test.ts": {"wait":3},
417 "test/ssh-handover.test.ts": {"wait":1},
418 "test/ssh-port-taken.test.ts": {"wait":1},
419 "test/ssh-shell-cold.test.ts": {"wait":3},
420 "test/ssh-version-exchange.test.ts": {"wait":1},
421 "test/ssh.test.ts": {"wait":3},
422 "test/stall-in-flight.test.ts": {"wait":1},
423 "test/standby-restore.test.ts": {"wait":1},
424 "test/standing-every-process.test.ts": {"wait":1},
425 "test/standing-rule.test.ts": {"wait":1},
426 "test/start.test.ts": {"wait":1},
427 "test/steer.test.ts": {"wait":1},
428 "test/steps-stop-tree.test.ts": {"wait":2},
429 "test/stranger-first-ask-journey.test.ts": {"wait":1},
430 "test/stranger-pull.test.ts": {"wait":2},
431 "test/stranger-three-screens.test.ts": {"wait":3},
432 "test/stripe-hook.test.ts": {"wait":3},
433 "test/stuck-pile-doors.test.ts": {"wait":1},
434 "test/subscriptions.test.ts": {"wait":1},
435 "test/support/landsim.ts": {"wait":1},
436 "test/surfaces-adversarial.test.ts": {"wait":1},
437 "test/talk-build.test.ts": {"wait":1},
438 "test/talk-page.test.ts": {"wait":7},
439 "test/talk-slash.test.ts": {"wait":1},
440 "test/talk-stop.test.ts": {"wait":2},
441 "test/team-dispatch.test.ts": {"wait":1},
442 "test/team-merge-gate.test.ts": {"wait":1},
443 "test/team-queue.test.ts": {"wait":1},
444 "test/template-forge-json.test.ts": {"timeout":1},
445 "test/template-page.test.ts": {"timeout":1},
446 "test/template-scripts.test.ts": {"timeout":1},
447 "test/templates-boot.test.ts": {"wait":1},
448 "test/test-budget-run.test.ts": {"wait":1},
449 "test/thanks.test.ts": {"wait":1},
450 "test/timers-sync.test.ts": {"wait":2},
451 "test/toolbar-keyboard.test.ts": {"wait":1},
452 "test/toolbar-move.test.ts": {"wait":1},
453 "test/tree-read.test.ts": {"wait":5},
454 "test/tty-stop-tree.test.ts": {"wait":2},
455 "test/tui-about-default-branch.test.ts": {"wait":4},
456 "test/tui-about-description.test.ts": {"wait":4},
457 "test/tui-about-detach.test.ts": {"wait":1},
458 "test/tui-about-outsiders.test.ts": {"wait":1},
459 "test/tui-about-visibility.test.ts": {"wait":2},
460 "test/tui-app-templates.test.ts": {"timeout":1,"wait":3},
461 "test/tui-app.test.ts": {"wait":2},
462 "test/tui-appbackup.test.ts": {"wait":1},
463 "test/tui-apps.test.ts": {"wait":2},
464 "test/tui-autonomy.test.ts": {"wait":1},
465 "test/tui-backups-test.test.ts": {"wait":1},
466 "test/tui-backups.test.ts": {"wait":1},
467 "test/tui-changelog-find.test.ts": {"wait":1},
468 "test/tui-changelog-waves.test.ts": {"wait":1},
469 "test/tui-claim-start.test.ts": {"wait":1},
470 "test/tui-code.test.ts": {"wait":1},
471 "test/tui-delete-repo.test.ts": {"wait":1},
472 "test/tui-devices.test.ts": {"timeout":1,"wait":1},
473 "test/tui-drill.test.ts": {"wait":1},
474 "test/tui-editor.test.ts": {"wait":1},
475 "test/tui-fleet.test.ts": {"wait":3},
476 "test/tui-following.test.ts": {"wait":1},
477 "test/tui-forgeview-live.test.ts": {"wait":2},
478 "test/tui-forks-propose.test.ts": {"wait":1},
479 "test/tui-forks-take.test.ts": {"wait":1},
480 "test/tui-hooks-deliveries.test.ts": {"wait":1},
481 "test/tui-hooks.test.ts": {"wait":3},
482 "test/tui-issue-flow-first.test.ts": {"wait":1},
483 "test/tui-limbs-replanned.test.ts": {"wait":1},
484 "test/tui-limbs.test.ts": {"wait":1},
485 "test/tui-live-throw.test.ts": {"wait":1},
486 "test/tui-machines.test.ts": {"wait":1},
487 "test/tui-migrate.test.ts": {"wait":1},
488 "test/tui-milestone-watch.test.ts": {"wait":1},
489 "test/tui-newapp.test.ts": {"wait":1},
490 "test/tui-next-up.test.ts": {"wait":2},
491 "test/tui-origins-forge.test.ts": {"wait":2},
492 "test/tui-origins-guard.test.ts": {"wait":1},
493 "test/tui-origins.test.ts": {"wait":1},
494 "test/tui-people-verify.test.ts": {"wait":1},
495 "test/tui-resilience-drill.test.ts": {"wait":2},
496 "test/tui-resilience-now.test.ts": {"wait":3},
497 "test/tui-runlog.test.ts": {"wait":2},
498 "test/tui-screens.test.ts": {"wait":1},
499 "test/tui-size.test.ts": {"wait":1},
500 "test/tui-standing-line.test.ts": {"wait":1},
501 "test/tui-steer.test.ts": {"wait":1},
502 "test/tui-talk-build.test.ts": {"wait":2},
503 "test/tui-talk-chats.test.ts": {"wait":1},
504 "test/tui-transfer-repo.test.ts": {"wait":1},
505 "test/tui-variants.test.ts": {"wait":1},
506 "test/tui-workflows.test.ts": {"wait":1},
507 "test/tui-working-yours.test.ts": {"wait":1},
508 "test/upstream-forge.test.ts": {"wait":2},
509 "test/usage-count.test.ts": {"wait":4},
510 "test/usage.test.ts": {"wait":1},
511 "test/variants-surfaces.test.ts": {"wait":1},
512 "test/vitals-held-agent.test.ts": {"wait":1},
513 "test/vitals.test.ts": {"wait":3},
514 "test/watches.test.ts": {"wait":3},
515 "test/web-apps.test.ts": {"wait":4},
516 "test/web-origins.test.ts": {"timeout":1},
517 "test/web-ui.test.ts": {"wait":2},
518 "test/week-doors.test.ts": {"wait":1},
519 "test/week-pump.test.ts": {"wait":1}
520 }
scripts/test_honesty.ts added +191
@@ -0,0 +1,191 @@
1 /**
2 * Tests wait for a signal, not a clock (#14321): a ratchet on fixed delays in `test/`.
3 *
4 * A fixed real-time wait makes a test slow when the machine is idle and red
5 * when it is busy; `scripts/flake.ts` finds such a flake only after it
6 * happened. This counts, per file under `test/`, three kinds of reliance on
7 * the clock or on module surgery, and holds each count to a committed
8 * allowance (`ALLOWANCE_FILE`, the pattern of `docs/design/size-budget.json`):
9 *
10 * wait `Bun.sleep(<number>)`, `Bun.sleepSync(<number>)` and
11 * `setTimeout(<name>, <number>)`: a delay chosen by hand.
12 * mock `mock.module(`: replaces a module for the whole process.
13 * timeout a test's `timeout:` or `retry:` option (`}, { timeout: 30_000 })`)
14 * and `setDefaultTimeout(`. The positional form (`}, 30_000)`) is
15 * not counted yet: over two thousand tests that boot a forge carry
16 * it, and a ratchet that large is its own change.
17 *
18 * Over its allowance is refused with what to do instead; under it is refused
19 * too until the allowance is lowered, so the list only shrinks. A file not in
20 * the allowance is allowed none. `FORGE_SLEEP_WRITE=1 bun scripts/test_honesty.ts`
21 * (or the same variable on `bun scripts/gate.ts`) writes today's counts.
22 *
23 * Lines that are only a comment are not counted. Text is read line by line,
24 * not parsed: a pattern inside a string literal counts, which is why this
25 * script's own test builds its samples from pieces.
26 *
27 * The idea is the `no-fixed-sleep` rule of interfere-inc/landmines (MIT); it
28 * is not a dependency, since that needs Node and Oxlint and the forge has one gate.
29 */
30
31 import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
32 import { join } from "node:path";
33
34 export const ALLOWANCE_FILE = "scripts/test-honesty-allow.json";
35
36 export type Kind = "wait" | "mock" | "timeout";
37 export type Counts = Partial<Record<Kind, number>>;
38 export type Allowance = Record<string, Counts>;
39
40 const KINDS: readonly Kind[] = ["wait", "mock", "timeout"];
41
42 const PATTERNS: Record<Kind, readonly RegExp[]> = {
43 wait: [/\bBun\.sleep(?:Sync)?\(\s*\d[\d_.]*\s*\)/g, /\bsetTimeout\(\s*[A-Za-z_$][\w$]*\s*,\s*\d[\d_.]*\s*\)/g],
44 mock: [/\bmock\.module\(/g],
45 timeout: [
46 /\bsetDefaultTimeout\(/g,
47 // `}, { timeout: 30_000 })` or `{ retry: 2 }` as a test's options.
48 /\}\s*,\s*\{[^}"'`]*\b(?:timeout|retry)\s*:\s*\d[^}]*\}\s*\)/g,
49 ],
50 };
51
52 // A line holding none of these words holds no pattern: most lines are skipped on this one test.
53 const CUE = /sleep|Timeout|module|timeout|retry/;
54
55 /** What to do instead, said on every refusal of that kind. */
56 export const ADVICE: Record<Kind, string> = {
57 wait: "await the operation or an event it emits instead of a fixed delay",
58 mock: "hand the module's seam a stand-in instead of replacing the module for the process",
59 timeout: "await the operation or an event it emits instead of raising a timeout or retrying",
60 };
61
62 const NOUN: Record<Kind, [string, string]> = {
63 wait: ["fixed wait", "fixed waits"],
64 mock: ["mock.module", "mock.module calls"],
65 timeout: ["raised timeout or retry", "raised timeouts or retries"],
66 };
67
68 function isCommentOnly(line: string): boolean {
69 const t = line.trimStart();
70 return t.startsWith("//") || t.startsWith("*") || t.startsWith("/*");
71 }
72
73 /** How many of each kind one file's text holds; kinds it holds none of are left out. */
74 export function countText(text: string): Counts {
75 const counts: Counts = {};
76 for (const line of text.split("\n")) {
77 if (!CUE.test(line) || isCommentOnly(line)) continue;
78 for (const kind of KINDS)
79 for (const re of PATTERNS[kind]) {
80 const n = line.match(re)?.length ?? 0;
81 if (n) counts[kind] = (counts[kind] ?? 0) + n;
82 }
83 }
84 return counts;
85 }
86
87 function tsUnder(root: string, dir: string): string[] {
88 let entries;
89 try {
90 entries = readdirSync(join(root, dir), { withFileTypes: true });
91 } catch {
92 return [];
93 }
94 return entries.flatMap((e) =>
95 e.isDirectory()
96 ? e.name === "node_modules"
97 ? []
98 : tsUnder(root, `${dir}/${e.name}`)
99 : e.isFile() && /\.(ts|tsx|js|mjs)$/.test(e.name)
100 ? [`${dir}/${e.name}`]
101 : [],
102 );
103 }
104
105 /**
106 * Every file under `root/test` holding at least one counted pattern, by repository path, sorted.
107 */
108 export function treeCounts(root: string): Allowance {
109 const out: Allowance = {};
110 for (const path of tsUnder(root, "test").sort()) {
111 const counts = countText(readFileSync(join(root, path), "utf8"));
112 if (Object.keys(counts).length) out[path] = counts;
113 }
114 return out;
115 }
116
117 /** One line a problem: a file over its allowance, or under it and not yet lowered. */
118 export function honestyProblems(counts: Allowance, allowance: Allowance): string[] {
119 const files = [...new Set([...Object.keys(counts), ...Object.keys(allowance)])].sort();
120 const problems: string[] = [];
121 for (const file of files)
122 for (const kind of KINDS) {
123 const have = counts[file]?.[kind] ?? 0;
124 const allowed = allowance[file]?.[kind] ?? 0;
125 if (have === allowed) continue;
126 const noun = NOUN[kind][have === 1 ? 0 : 1];
127 problems.push(
128 have > allowed
129 ? `${file}: ${have} ${noun}, allowed ${allowed}: ${ADVICE[kind]}`
130 : `${file}: ${have} ${noun}, allowed ${allowed}: lower its allowance in ${ALLOWANCE_FILE} (FORGE_SLEEP_WRITE=1 bun scripts/test_honesty.ts) so the list only shrinks`,
131 );
132 }
133 return problems;
134 }
135
136 /**
137 * The allowance as written: one file a line, so two pulls touching different files never conflict.
138 */
139 export function formatAllowance(allowance: Allowance): string {
140 const lines = Object.keys(allowance)
141 .sort()
142 .map((file) => ` ${JSON.stringify(file)}: ${JSON.stringify(allowance[file])}`);
143 return `{\n${lines.join(",\n")}\n}\n`;
144 }
145
146 /** The committed allowance at `root`; an unreadable or missing file allows nothing. */
147 export function readAllowance(root: string): Allowance {
148 try {
149 const parsed: unknown = JSON.parse(readFileSync(join(root, ALLOWANCE_FILE), "utf8"));
150 if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
151 const out: Allowance = {};
152 for (const [file, value] of Object.entries(parsed as Record<string, unknown>)) {
153 if (!value || typeof value !== "object") continue;
154 const counts: Counts = {};
155 for (const kind of KINDS) {
156 const n = (value as Record<string, unknown>)[kind];
157 if (typeof n === "number" && Number.isInteger(n) && n > 0) counts[kind] = n;
158 }
159 out[file] = counts;
160 }
161 return out;
162 } catch {
163 return {};
164 }
165 }
166
167 /** Writes today's counts as the allowance at `root`; returns how many files it names. */
168 export function writeAllowance(root: string): number {
169 const counts = treeCounts(root);
170 writeFileSync(join(root, ALLOWANCE_FILE), formatAllowance(counts));
171 return Object.keys(counts).length;
172 }
173
174 /**
175 * What the gate refuses of the tree at `root`. A tree without this script (a
176 * fixture repository in the gate's own tests) has nothing to hold.
177 */
178 export function testHonestyRefusal(root = "."): string[] {
179 if (!existsSync(join(root, "scripts/test_honesty.ts"))) return [];
180 return honestyProblems(treeCounts(root), readAllowance(root));
181 }
182
183 if (import.meta.main) {
184 if (process.env.FORGE_SLEEP_WRITE === "1") {
185 const n = writeAllowance(".");
186 console.error(`test_honesty: wrote ${ALLOWANCE_FILE} (${n} files)`);
187 }
188 const problems = testHonestyRefusal(".");
189 for (const line of problems) console.error(`test_honesty: ${line}`);
190 process.exit(problems.length === 0 ? 0 : 2);
191 }
test/test-honesty.test.ts added +124
@@ -0,0 +1,124 @@
1 // Tests wait for a signal, not a clock (#14321): the gate holds each test file to its allowance
2 // of fixed waits, mock.module calls and raised timeouts, and the allowance only shrinks.
3 // @tree-scan: asks the gate about this repository's own tree.
4 // Samples are built from pieces (`S`, `T`, `M`, `C`) so this file counts nothing itself.
5 import { expect, test } from "bun:test";
6 import { copyFileSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { testHonestyRefusal as gateHonesty } from "../scripts/gate.ts";
10 import {
11 ALLOWANCE_FILE,
12 countText,
13 formatAllowance,
14 honestyProblems,
15 readAllowance,
16 testHonestyRefusal,
17 treeCounts,
18 writeAllowance,
19 } from "../scripts/test_honesty.ts";
20
21 const S = "Bun." + "sleep";
22 const T = "set" + "Timeout";
23 const M = "mock." + "module";
24 const C = "}";
25 const ROOT = join(import.meta.dir, "..");
26 const WAIT_ADVICE = "await the operation or an event it emits instead of a fixed delay";
27
28 function tree(files: Record<string, string>): string {
29 const dir = mkdtempSync(join(tmpdir(), "forge-test-honesty-"));
30 mkdirSync(join(dir, "scripts"), { recursive: true });
31 copyFileSync(join(ROOT, "scripts/test_honesty.ts"), join(dir, "scripts/test_honesty.ts"));
32 for (const [path, text] of Object.entries(files)) {
33 mkdirSync(join(dir, path, ".."), { recursive: true });
34 writeFileSync(join(dir, path), text);
35 }
36 return dir;
37 }
38
39 test("each kind is counted, and a comment-only line is not", () => {
40 const text = [
41 `await ${S}(50);`,
42 `await ${S}(1_000); await ${S}Sync(5);`,
43 `await new Promise((r) => ${T}(r, 20));`,
44 `await ${S}(ms);`, // a computed delay is not a fixed one
45 `${T}(() => tick(), 10);`, // not a bare wait on a callback name
46 `// await ${S}(50);`,
47 ` * await ${S}(50);`,
48 `${M}("../src/x.ts", () => ({}));`,
49 C + ", { timeout: 5000 });",
50 'test("a", () => {' + C + ", { re" + "try: 2 });",
51 `setDefault${"Timeout"}(60_000);`,
52 ` ${C}, 30_000);`, // the positional form is not counted yet
53 ].join("\n");
54 expect(countText(text)).toEqual({ wait: 4, mock: 1, timeout: 3 });
55 expect(countText("expect(1).toBe(1);\n")).toEqual({});
56 });
57
58 test("one new fixed wait over the allowance fails the gate with the advice", () => {
59 const dir = tree({ "test/a.test.ts": `await ${S}(10);\n` });
60 try {
61 writeAllowance(dir);
62 expect(testHonestyRefusal(dir)).toEqual([]);
63 writeFileSync(join(dir, "test/a.test.ts"), `await ${S}(10);\nawait ${S}(50);\n`);
64 expect(testHonestyRefusal(dir)).toEqual([`test/a.test.ts: 2 fixed waits, allowed 1: ${WAIT_ADVICE}`]);
65 // gate.ts names the same refusal in its verdict
66 expect(gateHonesty(dir)).toEqual(testHonestyRefusal(dir));
67 } finally {
68 rmSync(dir, { recursive: true, force: true });
69 }
70 });
71
72 test("a new file is allowed none, and a helper under test/ is counted too", () => {
73 const dir = tree({ "test/helpers/h.ts": `${M}("x", () => ({}));\n` });
74 try {
75 expect(testHonestyRefusal(dir)).toEqual([
76 "test/helpers/h.ts: 1 mock.module, allowed 0: hand the module's seam a stand-in instead of replacing the module for the process",
77 ]);
78 } finally {
79 rmSync(dir, { recursive: true, force: true });
80 }
81 });
82
83 test("a file under its allowance is refused until the allowance is lowered", () => {
84 const dir = tree({ "test/a.test.ts": `await ${S}(10);\nawait ${S}(20);\n` });
85 try {
86 writeAllowance(dir);
87 writeFileSync(join(dir, "test/a.test.ts"), `await ${S}(10);\n`);
88 const [line] = testHonestyRefusal(dir);
89 expect(line).toStartWith("test/a.test.ts: 1 fixed wait, allowed 2: lower its allowance in scripts/test-honesty-allow.json");
90 writeAllowance(dir);
91 expect(readAllowance(dir)).toEqual({ "test/a.test.ts": { wait: 1 } });
92 expect(testHonestyRefusal(dir)).toEqual([]);
93 } finally {
94 rmSync(dir, { recursive: true, force: true });
95 }
96 });
97
98 test("a deleted file's allowance is stale and named", () => {
99 expect(honestyProblems({}, { "test/gone.test.ts": { timeout: 1 } })).toEqual([
100 `test/gone.test.ts: 0 raised timeouts or retries, allowed 1: lower its allowance in ${ALLOWANCE_FILE} (FORGE_SLEEP_WRITE=1 bun scripts/test_honesty.ts) so the list only shrinks`,
101 ]);
102 });
103
104 test("the allowance is one file a line, sorted, and reads back", () => {
105 const allowance = { "test/b.test.ts": { mock: 1 }, "test/a.test.ts": { wait: 2, timeout: 1 } };
106 expect(formatAllowance(allowance)).toBe(
107 '{\n "test/a.test.ts": {"wait":2,"timeout":1},\n "test/b.test.ts": {"mock":1}\n}\n',
108 );
109 });
110
111 test("a tree without the script (a gate fixture) has nothing to hold", () => {
112 const dir = mkdtempSync(join(tmpdir(), "forge-test-honesty-"));
113 try {
114 mkdirSync(join(dir, "test"));
115 writeFileSync(join(dir, "test/a.test.ts"), `await ${S}(10);\n`);
116 expect(testHonestyRefusal(dir)).toEqual([]);
117 } finally {
118 rmSync(dir, { recursive: true, force: true });
119 }
120 });
121
122 test("this repository's allowance matches today's counts", () => {
123 expect(honestyProblems(treeCounts(ROOT), readAllowance(ROOT))).toEqual([]);
124 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs