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

The plan line reads its spend from the lent credit but its "of $N" from the plan notice, so the two can disagree #13811

Merged opened this

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

Merged

scout/forge:scout/13810-the-plan-line-reads-its-spend-from-the-l → main 5 commits fork 1 thread · 1 unresolved

  • Merged. scout/13810-the-plan-line-reads-its-spend-from-the-l was merged into main as a89b95a.

Review

Sign in to review this change.
3 files changed +33 −2
src/web/plan_row.ts +4 −1
@@ -39,7 +39,10 @@ export function planLine(dataDir: string): string | undefined {
3939 if (n === undefined) return undefined;
4040 const f = fundingOf(dataDir);
4141 const size = isSize(n.size) ? ` (${sizeWords(n.size)})` : "";
42 const credit = n.creditUsd > 0 && f?.spentUsd != null ? ` ${usdWords(f.spentUsd)} of ${usdWords(n.creditUsd)} crew credit used this month.${uncountedWords(f.uncountedUsd ?? 0)}` : "";
42 // The spend and the cap come from the same lent-credit counter; the plan's credit stands in only
43 // when the host lent no cap.
44 const cap = f?.capUsd ?? n.creditUsd;

Good. One comment is enough here; it says why the plan credit stands in. Optional: a test for capUsd 0 (line hidden) would pin the edge.

45 const credit = cap > 0 && f?.spentUsd != null ? ` ${usdWords(f.spentUsd)} of ${usdWords(cap)} crew credit used this month.${uncountedWords(f.uncountedUsd ?? 0)}` : "";
4346 return `${n.name}${size}. ${statusWords(n)}.${credit}`;
4447 }
4548
test/credit-uncounted.test.ts +1 −1
@@ -101,7 +101,7 @@ test("the plan line and the terminal line say the note, and only when there is o
101101 expect(planLine(dir)).not.toContain("did not count");
102102 expect(crewKeyLine(guest())).not.toContain("did not count");
103103 heard(0, 0.78);
104 expect(planLine(dir)).toContain(`$0 of $50 crew credit used this month.${SAID}`);
104 expect(planLine(dir)).toContain(`$0 of $2 crew credit used this month.${SAID}`);
105105 expect(crewKeyLine(guest())).toBe(
106106 `The crew is building on $2 of $2 included credit ($0 spent).${SAID} a adds your own key.`,
107107 );
test/plan-line-cap.test.ts added +28
@@ -0,0 +1,28 @@
1 /** The plan line's spend and cap come from the same lent-credit counter. */
2 import { expect, test } from "bun:test";
3 import { mkdtempSync, writeFileSync } from "node:fs";
4 import { tmpdir } from "node:os";
5 import { join } from "node:path";
6 import { keepNotice } from "../src/billing/notice.ts";
7 import { planLine } from "../src/web/plan_row.ts";
8
9 const told = (credit: object): string => {
10 const dir = mkdtempSync(join(tmpdir(), "forge-planline-"));
11 writeFileSync(join(dir, "parent.json"), JSON.stringify({ upstream: "https://host.example", credit: { token: "tok-12345678", ...credit } }));
12 keepNotice(dir, notice);
13 return dir;
14 };
15
16 const notice = { name: "Medium", size: "medium", priceUsd: 49, creditUsd: 50, status: "active" } as const;
17
18 test("spend reads against the lent cap, not the plan credit", () => {
19 const dir = told({ capUsd: 2, spentUsd: 0.78 });
20 const line = planLine(dir) ?? "";
21 expect(line).toContain("$0.78 of $2 crew credit");
22 expect(line).not.toContain("$50");
23 });
24
25 test("without a lent cap the plan credit stands in", () => {
26 const dir = told({ capUsd: null, spentUsd: 0.78 });
27 expect(planLine(dir)).toContain("$0.78 of $50 crew credit");
28 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs