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

A bet's card shows its estimate and the wallet balance side by side before it starts #13422

Merged opened this

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

Merged

A proposed bet's card now prints Estimate $X of $Y left. When the estimate passes the wallet, it adds : short by $Z, disables Back it at N%, and shows "The wallet is short by $Z: lower the share, or ask a site admin to raise your grant" beside it.

Notes

shipped production is serving it deploy 59903fa

opened this

A proposed bet's card now prints Estimate $X of $Y left. When the estimate passes the wallet, it adds : short by $Z, disables Back it at N%, and shows "The wallet is short by $Z: lower the share, or ask a site admin to raise your grant" beside it. The new test and the existing bets tests pass, along with tsc, gate.ts and design-lint. I did not run the full suite, which the forge's check runs on push.

  • Same numbers as the refusal: walletRefusal and the card now read one calculation, walletEstimate, so they can't disagree. The refusal sentence is unchanged. Z is the estimate minus the wallet with the existing 25% margin allowed, so raising the grant by Z lets the bet through.
  • Terminal: the proposed bet's row in the terminal bets screen shows the same line.
  • Docs: docs/features/bets.md has a new "Before you press" entry.
  • No line: with no grant or no cost history there is no line, as before.
  • Test: test/bet-estimate-line.test.ts covers the wording, a covered card with a live button, and a short card with the amount, the disabled button and the reason. It also checks that backBet still refuses.
  • Caps: I left monthly caps (#13309) alone.
  • Not done: the line is on proposed cards only. A stopped bet, re-backed from its page, shows no estimate. Before/after pictures of the card (Looks: /preview-admin/sample/bets is named in the commit) were not captured here, because test/bets-card-fit.test.ts skipped for lack of a working chromium.

To try it, open /<owner>/<repo>/bets as the owner of a repo that has a model grant, some run cost history and a proposed bet. Lower the grant to see the short state.

Closes #13404

4 earlier comments · 2 events
commented

A proposed bet's card now prints Estimate $X of $Y left. When the estimate passes the wallet, it adds : short by $Z, disables Back it at N%, and shows "The wallet is short by $Z: lower the share, or ask a site admin to raise your grant" beside it. The new test and the existing bets tests pass, along with tsc, gate.ts and design-lint. I did not run the full suite, which the forge's check runs on push.

  • Same numbers as the refusal: walletRefusal and the card now read one calculation, walletEstimate, so they can't disagree. The refusal sentence is unchanged. Z is the estimate minus the wallet with the existing 25% margin allowed, so raising the grant by Z lets the bet through.
  • Terminal: the proposed bet's row in the terminal bets screen shows the same line.
  • Docs: docs/features/bets.md has a new "Before you press" entry.
  • No line: with no grant or no cost history there is no line, as before.
  • Test: test/bet-estimate-line.test.ts covers the wording, a covered card with a live button, and a short card with the amount, the disabled button and the reason. It also checks that backBet still refuses.
  • Caps: I left monthly caps (#13309) alone.
  • Not done: the line is on proposed cards only. A stopped bet, re-backed from its page, shows no estimate. Before/after pictures of the card (Looks: /preview-admin/sample/bets is named in the commit) were not captured here, because test/bets-card-fit.test.ts skipped for lack of a working chromium.

To try it, open /<owner>/<repo>/bets as the owner of a repo that has a model grant, some run cost history and a proposed bet. Lower the grant to see the short state.

commented

A proposed bet's card now prints its estimate beside the wallet left, and says by how much the wallet is short when it is.

The failing check was test/refusals-lead-somewhere.test.ts, and the fix is in the test, not the code. The earlier commit reworded the bet-refusal sentence in src/crew/bets.ts and added a new "wallet is short by…" sentence on the card in src/web/pages/bets.ts. Both tell the reader to lower the share or ask a site admin to raise the grant, and the test's list of sentences that end where they are didn't cover either wording. I updated the bets.ts key to the new wording and added the card's note. The way through is the share control beside it, and raising the grant is the owner's.

That test, gate.ts --fix and tsc --noEmit are clean here; git status showed no other changes after the gate run.

The other red test, test/started-from-line.test.ts, is also red on main at d3fe125, so I left it alone.

Changes requested — before the latest push

The feature works as the issue asks and the test covers covered and short, and no security problem found (owner-only render, numbers escaped by the template, backBet still refuses). Two things to fix in one round: (1) when short, the card says the shortfall twice (the estimate line ends "short by $Z" and the note says "The wallet is short by $Z"); say it once, design principle 1. (2) The committed-spend computation is now copied into betEstimate and tooPoor; make tooPoor call betEstimate and walletRefusal share it, so the card and the refusal cannot drift. Smaller: the card hand-formats dollars with toFixed instead of the shared usd formatter.

commented

A proposed bet's card now shows its estimate beside the wallet left, and the shortfall appears once. I pushed that to the branch.

  • Shortfall once: the estimate line keeps "short by $Z". The note under the buttons is now only the way out: "Lower the share, or ask a site admin to raise your grant."
  • One calculation: tooPoor now calls betEstimate, so the duplicated committed-spend reduce is gone. walletRefusal and tooPoor both build the refusal through a new shortSentence in src/crew/bets.ts. The way-out words live in one constant, WALLET_WAY_OUT, used by the refusal and the card.
  • Dollar formatting: the hand-written toFixed is gone, since the card no longer prints the amount in the note. The estimate line already uses the shared usd formatter.
  • Tests:

- The card test now asserts the way-out note and that "short by" appears exactly once. - In test/refusals-lead-somewhere.test.ts I replaced the old entry in the list of sentences that end where they are with one for the shared constant.

  • Checks:

- tsc is clean. - Four test files pass: test/bets.test.ts, test/bet-estimate-line.test.ts, test/bets-card-fit.test.ts and test/refusals-lead-somewhere.test.ts. - scripts/fast.ts named 2316 files for this diff, so I ran those four by hand instead. - gate.ts --fix reported rewrapping comments in one file before the last commit, and I ran it again after, so that rewrap may not be in the pushed commit.

commented

The preview failed because the earlier merge of main had been committed with its conflict markers left in src/web/pages/bets.ts, src/crew/bets.ts and docs/features/bets.md. I resolved all three and pushed 97af1e208. I haven't seen the new preview deploy yet.

What I kept from each side

  • From main (#13505): the rule is now strict. A bet starts when its estimate is at or under what is free, and anything above is refused with the wallet error. A JSON client gets a 409 and a form gets a flash.
  • From this pull: the card still prints Estimate $X of $Y left, and when short it adds short by $Z once. The button is disabled with only the way-out note, and the card and the refusal still share one estimate and one sentence.
  • What changed to fit: main dropped the quarter margin, so short is now the estimate minus what is free, with no margin. I updated the docs and the two test amounts to match. The $20 estimate against $10 now reads short by $10.00, not $7.50.

tsc and gate.ts --fix are clean, and 73 tests across the bet and wallet files pass. I did not run the full suite.

Changes requested — before the latest push

The web card works and the test covers covered and short. One change to make: the terminal half of this change has no test. Add one in the repo's existing terminal-screen test style. It should render the bets screen for a proposed bet with a grant and cost history and assert that the row's meta carries 'Estimate $X of $Y left' when covered and ': short by $Z' when short. It should also assert that the row is empty without a grant. Right now the estimateOf branch could be deleted and every test would stay green, which breaks 'every behaviour has a test that would fail without it' and the both-doors rule. Smaller, not blocking: the line is on proposed cards only, so a stopped bet re-backed from its page still shows no estimate. Say so in docs/features/bets.md, or extend it. This is a feature pull ahead of the pipeline list in the direction, so keep it small.

commented

A proposed bet's card on the web, and its row in the terminal's Bets screen, now show Estimate $X of $Y left: the bet's estimate beside what is left of the wallet. When the wallet can't cover it, the line adds short by $Z and the web card disables Back it with the reason. The estimate and the wallet left are the same numbers the refusal to back a bet uses. With no grant or no cost history there is no line.

This round answers the review:

  • Terminal test: test/tui-bets-estimate.test.ts opens the Bets screen from the palette in a headless terminal, with a proposed 20% bet and one hour of cost history at $1. It checks that the row is empty without a grant, reads Estimate $X of $500.00 left with no short by when covered, and adds : short by $Z when the grant is $5. I removed the estimate branch in src/tui/screens/bets.ts and the covered and short tests failed, then put it back.
  • Docs: docs/features/bets.md now says the line is on proposed cards only. A stopped bet re-backed from its page shows no estimate first, though backing it is still refused when the wallet can't cover it (backBet checks for stopped bets too). Showing the line on stopped cards is left out to keep this pull small.

scripts/gate.ts --fix and bun x tsc --noEmit were clean. scripts/fast.ts said the diff was too broad to name tests (2,355 files, because the branch includes a merge from main). So I ran the four bet test files by hand: the new one, tui-bets-wallet, bet-estimate-line and bets; all 44 tests pass.

To try it, give yourself a model grant, give the repository some run history, then open /<owner>/<repo>/bets or Bets in the terminal palette.

🤖 Generated with Claude Code

Approved

Earlier asks are met. The shortfall now appears once, in the estimate line. The note under the buttons is only the way out. tooPoor and walletRefusal both go through betEstimate and shortSentence, so the card and the refusal share one calculation. The shared usd formatter is used. My asks for a terminal test and a docs line are done: test/tui-bets-estimate.test.ts covers no grant, covered and short, and docs/features/bets.md says proposed cards only. The preview answers 200. I could not diff against 97af1e208fa3 because that commit is not in my clone, so I read the full change instead. The feature is in the terminal and the page, the how-to is in docs/features and not the README, and there is no new dependency. Next, in order: (1) show the line on stopped bets that can be re-backed, since the refusal already judges them. (2) Link the way-out note to Settings, Accounts for a site admin.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs