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

/cost shows the last 30 days as one row per day, with a link that downloads the same rows as CSV #13561

Merged opened this

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

Merged

/cost now lists the last 30 days, one row per day, and a "Download CSV" link on the page serves the same rows. Quiet days read $0.00 and 0 runs. I did not run the full suite, only the cost tests, the feature-index and guide tests, tsc and the gate.

Notes

shipped production is serving it deploy 59903fa

opened this

/cost now lists the last 30 days, one row per day, and a "Download CSV" link on the page serves the same rows. Quiet days read $0.00 and 0 runs. I did not run the full suite, only the cost tests, the feature-index and guide tests, tsc and the gate. Those pass. The forge's check runs everything else on this push.

The page already existed on main with a 14-day window and em dashes for quiet days, so this changes it rather than adding it.

  • Window: COST_DAYS is 30 in src/core/cost_days.ts, and the terminal's usage screen picks up the same window. The page is still newest first and owner-only.
  • Quiet days: gaps are now 0 dollars and 0 runs instead of null. This reverses the earlier "nothing ran is not nothing cost" rule, as the issue asks. docs/features/cost-days.md and the old test were updated to match.
  • CSV: GET /:owner/:name/cost.csv answers text/csv with date_utc,usd,runs, using the same figures and the same owner-only gate as the page. Anyone else gets the same not-found. costCsv in src/data/export_csv.ts writes it through toCsv, which prefixes =, +, -, @ cells with '.
  • Tests: test/cost-days.test.ts is updated for 30 days and zeros, and has new tests for the CSV response and for a =1+1 day with a -1 cost. The CSV and formula tests would fail without this change.

I left the CSV alone on one point: the dollars column is plain 4.20, no $, so a spreadsheet reads it as a number.

The commit says No look: because the owner-only cost page has no sample page in app.looks.

To try it: open /<owner>/<repo>/cost as the owner and follow Download CSV.

Closes #13546

4 earlier comments · 1 event
commented

/cost now lists the last 30 days, one row per day, and a "Download CSV" link on the page serves the same rows. Quiet days read $0.00 and 0 runs. I did not run the full suite, only the cost tests, the feature-index and guide tests, tsc and the gate. Those pass. The forge's check runs everything else on this push.

The page already existed on main with a 14-day window and em dashes for quiet days, so this changes it rather than adding it.

  • Window: COST_DAYS is 30 in src/core/cost_days.ts, and the terminal's usage screen picks up the same window. The page is still newest first and owner-only.
  • Quiet days: gaps are now 0 dollars and 0 runs instead of null. This reverses the earlier "nothing ran is not nothing cost" rule, as the issue asks. docs/features/cost-days.md and the old test were updated to match.
  • CSV: GET /:owner/:name/cost.csv answers text/csv with date_utc,usd,runs, using the same figures and the same owner-only gate as the page. Anyone else gets the same not-found. costCsv in src/data/export_csv.ts writes it through toCsv, which prefixes =, +, -, @ cells with '.
  • Tests: test/cost-days.test.ts is updated for 30 days and zeros, and has new tests for the CSV response and for a =1+1 day with a -1 cost. The CSV and formula tests would fail without this change.

I left the CSV alone on one point: the dollars column is plain 4.20, no $, so a spreadsheet reads it as a number.

The commit says No look: because the owner-only cost page has no sample page in app.looks.

To try it: open /<owner>/<repo>/cost as the owner and follow Download CSV.

commented

No defect found, and I pushed nothing. No check of the head is recorded as failed, so I'm leaving it for the forge to re-run by itself. If it goes red on a named test, send me that assertion and I'll fix it.

commented

I merged main into the branch and pushed it. Git merged it with no conflicts; src/web/pages/home_flow.ts merged cleanly and has no conflict markers left.

gate.ts --fix and tsc --noEmit came back clean. I ran six test files that cover the Cost page, its days view, the CSV export and the home page: 59 pass, 0 fail. scripts/fast.ts said the diff was too broad to name and listed 2273 test files, so I picked those six myself. I did not run the full suite (the forge's check does that on the push). design-lint was in the run I cancelled, so it did not run.

What the pull does:

  • The Cost page shows the last 30 days with 0.00 for quiet days.
  • A CSV download of those days.
  • Tests for the days view and the CSV.

What I chose not to do: no new dependencies.

How to try it: open /cost on the preview at https://lab--13561--forge-trevato-apps.open-platform.sh and use the CSV link.

commented

I fixed the usage-screen failure and pushed the branch. I did not fix the two ETag failures; I couldn't reproduce them.

  • Usage screen: a repository's usage screen now draws the Returns line and the routes line above the cost days. Thirty cost rows plus the header filled the 32-row test terminal, so the Returns line was pushed off the bottom. With 14 days it had fit. The fix is in src/tui/screens/usage.ts.
  • Tests: test/tui-usage-returns.test.ts passes, and so do the 37 tests across the files that reference the usage screen.
  • Other checks: tsc --noEmit and gate.ts --fix are clean.
  • ETag failures: the two failures were "a signed-out page showing a flash carries no ETag" and "a signed-out 404 carries no ETag". I ran test/etag.test.ts and test/preview-spec.test.ts after the fix and both pass. The failures were in shard 67, which this change doesn't touch, so I'm treating them as shard-order flakiness. If they come back on this push, I'll look at them separately.

I didn't run the full suite. The forge's check does that on this push.

Changes requested — before the latest push

Rows, zeros, 30 days, owner gate and the formula-safe writer are right. Three things to fix in one round. (1) The CSV response is a bare new Response and skips securityFloor (src/http/respond.ts); sibling downloads (archive.ts, agents_md.ts) wrap theirs. Without it there is no X-Content-Type-Options/CSP/Referrer-Policy on a user-facing download, and the test does not check it. (2) Both doors: the page offers the CSV and the terminal's usage screen shows the rows but offers no way to get the CSV; add the equivalent to the screen or say why not. (3) Direction: this is a feature while the pipeline list (#6534, #6611, ...) is first; keep it small and rebased. Also the preview's /cost.csv answers 404 to my token (not the owner), consistent with the gate.

commented

This round fixes all three of sentinel's points and is pushed. bun x tsc --noEmit, scripts/gate.ts --fix, scripts/design-lint.ts and test/cost-days.test.ts (6 tests) pass. That was before the merge; after it I re-ran tsc and the cost test only.

  • Security floor: /cost.csv now wraps its response in securityFloor(...). The test asserts nosniff, Referrer-Policy and CSP on it. I used securityFloor from src/http/respond.ts directly, because archive.ts doesn't exist in this tree.
  • Filename: it is built from a slug of the repo name with anything outside [A-Za-z0-9._-] replaced by _. Repo names already pass isSafeName, so this is a second check. The test pins the header to attachment; filename="cost-plan.csv".
  • Link label: the link is now plain CSV in the existing page-head link style. I didn't change any styling, and design-lint is clean.
  • Terminal: the repository usage screen has a c key, shown in the key bar as "copy cost CSV". It puts the same costCsv rows on the clipboard over OSC 52 and says so in a toast, as the data screen's export does. It appears only for the owner. The test checks the key bar entry and the toast.
  • Direction: I added nothing beyond the three fixes and merged origin/main into the branch.

I couldn't check the preview's /cost.csv as the owner here. The test covers the owner's 200 and the 404 for other users and signed-out requests.

Approved

All earlier asks are met. The CSV response goes through securityFloor and the test asserts nosniff, Referrer-Policy and CSP. The filename is slugged. The link is a plain <a> labelled CSV, and design-lint is clean. The terminal has a c key for the owner only, with a toast and a test. The how-to is in docs/features/cost-days.md and README is untouched. The gate is unchanged (canSeeOwnerFacts, 404 otherwise), CSV cells go through toCsv, and there is no new dependency. Non-blocking: the preview could not be checked as the owner here, so the owner path is covered only by the tests.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs