Skip to content

Commit adfce19

Browse files
authored
Merge pull request #346 from prayzey/Windsurf
fix: keep Windsurf quota visible when extra usage balance is missing
2 parents 857f537 + bbbb6cc commit adfce19

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

plugins/windsurf/plugin.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
function formatDollarsFromMicros(value) {
9898
var micros = readFiniteNumber(value)
9999
if (micros === null) return null
100+
if (!Number.isFinite(micros)) return null
100101
if (micros < 0) micros = 0
101102
return "$" + (micros / 1000000).toFixed(2)
102103
}
@@ -119,7 +120,6 @@
119120
return (
120121
readFiniteNumber(planStatus && planStatus.dailyQuotaRemainingPercent) !== null &&
121122
readFiniteNumber(planStatus && planStatus.weeklyQuotaRemainingPercent) !== null &&
122-
readFiniteNumber(planStatus && planStatus.overageBalanceMicros) !== null &&
123123
readFiniteNumber(planStatus && planStatus.dailyQuotaResetAtUnix) !== null &&
124124
readFiniteNumber(planStatus && planStatus.weeklyQuotaResetAtUnix) !== null
125125
)
@@ -138,20 +138,21 @@
138138
var weeklyReset = unixSecondsToIso(ctx, planStatus.weeklyQuotaResetAtUnix)
139139
var extraUsageBalance = formatDollarsFromMicros(planStatus.overageBalanceMicros)
140140

141-
if (!dailyReset || !weeklyReset || !extraUsageBalance) throw QUOTA_HINT
141+
if (!dailyReset || !weeklyReset) throw QUOTA_HINT
142142

143143
var dailyLine = buildQuotaLine(ctx, "Daily quota", planStatus.dailyQuotaRemainingPercent, dailyReset, DAY_MS)
144144
var weeklyLine = buildQuotaLine(ctx, "Weekly quota", planStatus.weeklyQuotaRemainingPercent, weeklyReset, WEEK_MS)
145145

146146
if (!dailyLine || !weeklyLine) throw QUOTA_HINT
147147

148+
var lines = [dailyLine, weeklyLine]
149+
if (extraUsageBalance) {
150+
lines.push(ctx.line.text({ label: "Extra usage balance", value: extraUsageBalance }))
151+
}
152+
148153
return {
149154
plan: planName,
150-
lines: [
151-
dailyLine,
152-
weeklyLine,
153-
ctx.line.text({ label: "Extra usage balance", value: extraUsageBalance }),
154-
],
155+
lines: lines,
155156
}
156157
}
157158

plugins/windsurf/plugin.test.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,26 @@ describe("windsurf plugin", () => {
276276
expect(result.lines.find((line) => line.label === "Extra usage balance")?.value).toBe("$0.00")
277277
})
278278

279+
it("renders quota lines when Windsurf omits extra usage balance", async () => {
280+
const ctx = makeCtx()
281+
setupCloudMock(ctx, {
282+
stableAuth: "sk-ws-01-stable",
283+
stableResponse: {
284+
status: 200,
285+
bodyText: JSON.stringify(makeQuotaResponse({ overageBalanceMicros: undefined })),
286+
},
287+
})
288+
289+
const plugin = await loadPlugin()
290+
const result = plugin.probe(ctx)
291+
292+
expect(result.plan).toBe("Teams")
293+
expect(result.lines).toHaveLength(2)
294+
expect(result.lines.find((line) => line.label === "Daily quota")?.used).toBe(0)
295+
expect(result.lines.find((line) => line.label === "Weekly quota")?.used).toBe(0)
296+
expect(result.lines.find((line) => line.label === "Extra usage balance")).toBeUndefined()
297+
})
298+
279299
it("falls back to Unknown plan when planInfo is null", async () => {
280300
const ctx = makeCtx()
281301
setupCloudMock(ctx, {
@@ -687,7 +707,7 @@ describe("windsurf plugin", () => {
687707
finiteSpy.mockRestore()
688708
})
689709

690-
it("throws quota unavailable when extra usage balance becomes invalid after contract validation", async () => {
710+
it("omits extra usage balance when it becomes invalid after contract validation", async () => {
691711
const ctx = makeCtx()
692712
const originalTryParseJson = ctx.util.tryParseJson
693713
ctx.util.tryParseJson = vi.fn((text) => {
@@ -723,7 +743,8 @@ describe("windsurf plugin", () => {
723743
})
724744

725745
const plugin = await loadPlugin()
726-
expect(() => plugin.probe(ctx)).toThrow("Windsurf quota data unavailable. Try again later.")
746+
const result = plugin.probe(ctx)
747+
expect(result.lines.find((line) => line.label === "Extra usage balance")).toBeUndefined()
727748
finiteSpy.mockRestore()
728749
})
729750

0 commit comments

Comments
 (0)