Skip to content

Commit 95648e7

Browse files
Sync public snapshot from freebuff-private
Source: CodebuffAI/freebuff-private@4cb3faa56c9a4113c7e02e24fe1e1bbee8711408
1 parent 4473204 commit 95648e7

6 files changed

Lines changed: 62 additions & 66 deletions

File tree

‎bun.lock‎

Lines changed: 43 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎cli/src/hooks/__tests__/freebuff-admission-notice.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('freebuffAdmissionNotice', () => {
1818
status: 'rate_limited',
1919
freebucksShortfall: { price: 15, balance: 7 },
2020
} as FreebuffSessionResponse)
21-
expect(notice).toStartWith('Not enough hours: 1.4 hours available.')
21+
expect(notice).toStartWith('Not enough hours: 1 hour available.')
2222
expect(notice).not.toContain('Freebucks')
2323
})
2424
})

‎cli/src/utils/__tests__/freebucks.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,18 @@ describe('the header line', () => {
240240
).toBe('6/15 hours daily')
241241
})
242242

243-
test('rounds hours down, so a balance never reads as more than it buys', () => {
243+
test('rounds hours down to whole hours, so a balance never reads as more than it buys', () => {
244244
expect(
245245
freebucksHeaderLine(
246246
metered({
247247
daily: { limit: 75, spent: 46, remaining: 29, resetAt: 'x' },
248248
wallet: { balance: 6, monthlyBonus: 0 },
249249
}),
250250
),
251-
).toBe('5.8/15 hours daily · 1.2 hours in wallet')
251+
).toBe('5/15 hours daily · 1 hour in wallet')
252252
})
253253

254-
test('a wallet under a tenth of an hour is hidden, never "0 hours"', () => {
254+
test('a wallet under an hour is hidden, never "0 hours"', () => {
255255
expect(
256256
freebucksHeaderLine(metered({ wallet: { balance: 0.4, monthlyBonus: 0 } })),
257257
).toBe('6/15 hours daily')

‎cli/src/utils/freebucks.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export function freebucksHeaderLine(
125125
}
126126
// An empty wallet is the ordinary case for a free account, and "0 wallet"
127127
// reads as something to worry about. Web and Desktop hide it too; so is a
128-
// wallet too small to show as a tenth of an hour.
128+
// wallet too small to show as a whole hour.
129129
if (formatHours(freebucks.wallet.balance) !== '0') {
130130
parts.push(`${formatHoursWithUnit(freebucks.wallet.balance)} in wallet`)
131131
}

‎common/src/util/__tests__/freebuff-hours.test.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ describe('hours', () => {
2121
[0, '0'],
2222
[5, '1'],
2323
[250, '50'],
24-
[37, '7.4'],
25-
// Rounded down: never more than the balance buys.
26-
[39, '7.8'],
27-
[4, '0.8'],
24+
// Whole hours only, rounded down: never more than the balance buys, and
25+
// never a fraction of an hour.
26+
[37, '7'],
27+
[39, '7'],
28+
[4, '0'],
29+
[9.99, '1'],
2830
[-10, '0'],
2931
[6_500, '1,300'],
3032
])('%p Freebucks reads as %p', (freebucks, text) => {

‎common/src/util/freebuff-hours.ts‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,18 @@ export function freebucksToHours(freebucks: number): number {
2222
}
2323

2424
/**
25-
* Freebucks as an hour count for display: whole hours as integers, anything
26-
* else to one decimal, rounded DOWN so a balance never reads as more than it
27-
* buys. Never negative. `1,234` style grouping for large counts.
25+
* Freebucks as an hour count for display: WHOLE hours, rounded down, so a
26+
* balance never reads as more than it buys and never shows a fraction of an
27+
* hour (product, 2026-10-15: "7.4 hours" confused people). Never negative.
28+
* `1,234` style grouping for large counts.
2829
*/
2930
export function formatHours(freebucks: number): string {
30-
const tenths = Math.floor(
31-
(Math.max(0, freebucks) * 10) / FREEBUCKS_PER_HOUR + 1e-9,
32-
)
33-
return (tenths / 10).toLocaleString('en-US', {
34-
maximumFractionDigits: 1,
35-
})
31+
return Math.floor(
32+
Math.max(0, freebucks) / FREEBUCKS_PER_HOUR + 1e-9,
33+
).toLocaleString('en-US')
3634
}
3735

38-
/** `formatHours` with its unit: "1 hour", "50 hours", "7.4 hours". */
36+
/** `formatHours` with its unit: "1 hour", "50 hours". */
3937
export function formatHoursWithUnit(freebucks: number): string {
4038
const text = formatHours(freebucks)
4139
return `${text} ${text === '1' ? 'hour' : 'hours'}`

0 commit comments

Comments
 (0)