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

The wallet's spends download as one CSV through the data export door #13412

Merged opened this

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

Merged

The cost page now has a "Download as CSV" link, and /:owner/:name/cost.csv serves the same 14 days as one file. tsc, the gate and test/cost-days.test.ts pass; I did not run the full suite or try the download on a preview. Interpretation.

Notes

shipped production is serving it deploy 59903fa

opened this

The cost page now has a "Download as CSV" link, and /:owner/:name/cost.csv serves the same 14 days as one file. tsc, the gate and test/cost-days.test.ts pass; I did not run the full suite or try the download on a preview.

Interpretation. There is no "wallet page" in the repo. I took "the wallet's spends" to mean /:owner/:name/cost (#13330), the owner's per-day spend table. If you meant something else, say so.

What changed

  • CSV rows: src/core/cost_csv.ts (costCsv) writes date_utc,dollars,runs through the shared toCsv writer, which prefixes a text cell starting with =, +, - or @ with a '. It is built from the page's own costDays rows. Dollars are numbers to the cent, and a day with no run is empty cells, the page's em dash.
  • Gate and cap: the route uses the page's gate (canSeeOwnerFacts), so anyone else, signed in or not, gets the same 404. It is capped at the page's 14 rows.
  • Terminal and docs: the terminal's repository usage screen prints the CSV path. docs/features/cost-days.md describes it.
  • Test: test/cost-days.test.ts checks that the CSV lines equal the page rows, that a cell beginning = comes out as '=…, and that the owner gets 200 while another user and a guest get 404.

Left out

  • exportRows: I did not route this through exportRows or sources.ts. exportRows reads a SQLite file the viewer may open, and the cost rows are computed from the usage ledger, so it would not fit. The row cap and the 404 gate carry over instead.
  • Test file: I put the test in test/cost-days.test.ts rather than a new test/wallet-csv.test.ts, since it shares that file's fixtures.
  • Terminal door: the gate's "both doors" rule wanted a new terminal screen, so the commit carries a No door: line. The existing usage screen prints the path instead of a new screen.

Try it: open /<owner>/<name>/cost as the repository's owner and follow "Download as CSV".

🤖 Generated with Claude Code

Closes #13386

2 earlier comments · 1 event
commented

The cost page now has a "Download as CSV" link, and /:owner/:name/cost.csv serves the same 14 days as one file. tsc, the gate and test/cost-days.test.ts pass; I did not run the full suite or try the download on a preview.

Interpretation. There is no "wallet page" in the repo. I took "the wallet's spends" to mean /:owner/:name/cost (#13330), the owner's per-day spend table. If you meant something else, say so.

What changed

  • CSV rows: src/core/cost_csv.ts (costCsv) writes date_utc,dollars,runs through the shared toCsv writer, which prefixes a text cell starting with =, +, - or @ with a '. It is built from the page's own costDays rows. Dollars are numbers to the cent, and a day with no run is empty cells, the page's em dash.
  • Gate and cap: the route uses the page's gate (canSeeOwnerFacts), so anyone else, signed in or not, gets the same 404. It is capped at the page's 14 rows.
  • Terminal and docs: the terminal's repository usage screen prints the CSV path. docs/features/cost-days.md describes it.
  • Test: test/cost-days.test.ts checks that the CSV lines equal the page rows, that a cell beginning = comes out as '=…, and that the owner gets 200 while another user and a guest get 404.

Left out

  • exportRows: I did not route this through exportRows or sources.ts. exportRows reads a SQLite file the viewer may open, and the cost rows are computed from the usage ledger, so it would not fit. The row cap and the 404 gate carry over instead.
  • Test file: I put the test in test/cost-days.test.ts rather than a new test/wallet-csv.test.ts, since it shares that file's fixtures.
  • Terminal door: the gate's "both doors" rule wanted a new terminal screen, so the commit carries a No door: line. The existing usage screen prints the path instead of a new screen.

Try it: open /<owner>/<name>/cost as the repository's owner and follow "Download as CSV".

🤖 Generated with Claude Code

Changes requested — before the latest push

High: this puts the CSV on the wrong page. The issue asks for the wallet's spends. The wallet page exists (/:owner/:name/wallet, src/web/pages/wallet.ts, src/actions/wallet.ts, docs/features/wallet.md, merged in #13324), and its last-20 spends rows are what the issue means. The pull instead adds /cost.csv for the per-day cost table. The pull says there is no wallet page, but there is one. Fix, in one round: (1) add the CSV at the wallet page, built from the wallet page's own spend rows through exportRows/toCsv, with a link on the wallet page. (2) Use the wallet page's gate and masking, with a cap and a 404 for a viewer who may not see owner facts. (3) Test that the CSV equals the wallet page rows and that a cell beginning = is neutralised. (4) Document it in docs/features/wallet.md. (5) Add the path to the terminal wallet screen (src/tui/screens/money.ts). Drop or justify the cost.csv addition: it is outside the issue. The toCsv use, 404 gate, no-store and nosniff headers on the cost route are otherwise fine.

commented

The wallet page now downloads its last 20 spends as one CSV at /:owner/:name/wallet.csv, and the cost.csv addition is gone. You were right that a wallet page exists; my branch was behind main, so I never saw it.

What changed

  • Download: the CSV has the columns date_utc,dollars,paid_for,outcome,run. It is built from readWallet, the same rows the page shows, through toCsv in src/actions/wallet_csv.ts. The route is walletCsvDownload in src/web/pages/wallet.ts.
  • Gate: readWallet already applies the page's gate and its 20-row cap. A guest or a viewer who may not see owner facts gets 404. Responses carry nosniff, private, no-store and an attachment filename.
  • Link: "Download as CSV" sits next to the spends text on the wallet page, and only when there are rows.
  • Terminal: the wallet screen's header line in src/tui/screens/money.ts prints the CSV path.
  • Docs: docs/features/wallet.md has a CSV bullet.
  • Cost page: cost.csv, cost_csv.ts, the cost-page link, the usage-screen line and the cost-days test and doc are removed. src/http/server.ts is again as on main apart from the wallet route.

Tests: a new test in test/wallet.test.ts checks that the CSV equals the rows readWallet returns for 20 data rows and that the page links it. It also checks that a cell starting = comes out as '=…, and that a guest and a non-writer get 404 with no figure in the body.

I ran the wallet, TUI wallet, TUI money, repo wallet routes, cost-days and unused-exports tests, plus tsc and gate.ts --fix; all passed. bun scripts/design-lint.ts passed on the first version, but I did not re-run it after the final edits. Because scripts/fast.ts named 2,245 files, I ran those covering tests by hand.

Pushes: I pushed the cost-route removal in two steps, and the first push was red for about a minute (tsc failed on a leftover import). The next push fixed it. The branch history also carries a merge, because the rebase onto main had diverged from the remote.

Disagreement: I did not use exportRows. It reads a table inside an app's own database and applies per-source masking, and the wallet's rows come from the forge's usage ledger. toCsv over readWallet already gives the same gate, the same cap and no secrets in the rows. docs/features/wallet.md says so.

Left out: paging past 20 rows, and a JSON form.

To try: sign in as a writer and open /<owner>/<name>/wallet, then follow Download as CSV.

commented

The three red tests don't come from this pull's change. I merged current main and pushed, and nothing in the pull's own code needed fixing.

  • talk-page (byte budget) and started-from-line: the forge's own check found both red on main at b85d599 too, and didn't count them against this pull. The byte-budget test still fails after the merge, so main is red there and I left it alone.
  • quotas-running (the sleeping preview woken at the limit): it ran into its 120 s limit in the shard, but passes here, 7 of 7 in about 10 s. I read it as a slow-machine timeout. I changed nothing.
  • Merge and checks: the merge brought in the latest main. After it, scripts/gate.ts --fix and tsc --noEmit gave no errors.
  • What I did not finish: scripts/fast.ts named 2,259 of 3,444 test files, too broad to run here. A partial run of them showed only the same talk-page byte-budget failure. I stopped waiting for that run, so it did not finish. The full check on the push is what will settle the rest.

What this pull does: the wallet's last 20 spends download as one formula-safe CSV, and the cost.csv route is dropped.

To try it: open the wallet page, follow Download as CSV, and bun test test/wallet.test.ts test/repo-wallet-routes.test.ts.

Approved

Approved. The earlier asks are not checkable here: the clone lacks 16be43c8cd40, so I read the whole diff. Nothing in it breaks the security list. The route reuses readWallet, so it has the page gate and the 20-row cap, and a guest or non-writer gets 404. The filename is sanitised, the response sends nosniff and no-store, and the writer neutralises formula cells. The terminal prints the CSV path, the how-to is in docs/features/wallet.md rather than README, and the link is a plain <a> that works without JavaScript. The test covers equality with the page rows, the formula cell, and the 404s. I could not try the download on the preview: unauthenticated it returned 404, as designed. Non-blocking: the pull skips exportRows with a reason (the ledger is the forge's own table), which is fine.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs