qoder 0.2.44: a spent plan beside add-on credits left is no account used up (#454)
chansee97's Qoder CN trial had its plan's 300 credits spent and 245 of 1,100 add-on credits used, and Routing read the account as 0% left: each pool was a window of its own, and routing counts the tightest. Qoder spends the pools one after another before an account stops (docs.qoder.com/Credits: soonest to expire first, the plan's before add-on on the same day; teams: then the organisation's shared add-on credits), and its own envelope's totalUsagePercentage counts them as one. So when more than one of the plan, add-on and shared pools holds credits in the same unit, "Total credits" is what they hold together (545 / 1400 here, 61% left) and the one routing counts, and each pool is shown beside it set aside, as CodeArts' buckets are under its total. One pool alone is shown as before. Dedicated packages are left as they were (no word from Qoder on their order). Run: bun test in packages/qoder (298 pass) and scripts/check.mjs, on mote. Broken by hand: the new tests against origin/main's index.mjs, red (#454's reads 0% left; the rotated-token test's windows differ). Read-only real read of the owner's Qoder account's /sash/api/v2/me/usage: plan total 0, add-on 7 / 600, which stays one window, unchanged. Not tried: a real account with both a plan and add-on credits (the owner's has no plan credits); the fields are the ones that read returns.
This commit is contained in:
@@ -60,9 +60,10 @@ test("a refused device token is rotated, saved, and the usage read with it", asy
|
||||
expect(await p.usage()).toEqual({
|
||||
plan: "pro",
|
||||
windows: [
|
||||
{ name: "Credits", used: 25, display: "25 / 100 credits" },
|
||||
{ name: "Add-on credits", used: 20, display: "10 / 50 credits" },
|
||||
{ name: "Shared credits", used: 50, display: "10 / 20 credits" },
|
||||
{ name: "Total credits", used: (100 * 45) / 170, display: "45 / 170 credits" },
|
||||
{ name: "Credits", used: 25, display: "25 / 100 credits", aside: true },
|
||||
{ name: "Add-on credits", used: 20, display: "10 / 50 credits", aside: true },
|
||||
{ name: "Shared credits", used: 50, display: "10 / 20 credits", aside: true },
|
||||
{ name: "Team", used: 20, display: "2 / 10 credits" },
|
||||
],
|
||||
signIn: "kept",
|
||||
@@ -124,6 +125,56 @@ test("snake_case fields, an expiry, units, and pools too thin to show", () => {
|
||||
expect(_internal.when(0)).toBeUndefined()
|
||||
})
|
||||
|
||||
// magpie-community/plugins#454 (chansee97): a Qoder CN trial whose plan's
|
||||
// 300 credits are spent, with 245 of 1,100 add-on credits used, read 0% left
|
||||
// in Routing. Qoder spends the add-on credits once the plan's are gone, so
|
||||
// the account has 855 of 1,400 left.
|
||||
test("a spent plan beside add-on credits left is no account used up (#454)", () => {
|
||||
const u = _internal.parseUsage({
|
||||
displayMode: "qoder",
|
||||
qoderUsage: {
|
||||
userType: "personal_professional_trial",
|
||||
usageType: "credits",
|
||||
isQuotaExceeded: false,
|
||||
userQuota: { total: 300, used: 300, remaining: 0, percentage: 1, unit: "credits" },
|
||||
addOnQuota: { total: 1100, used: 245, remaining: 855, percentage: 0.22, unit: "credits" },
|
||||
},
|
||||
})
|
||||
expect(u.windows).toEqual([
|
||||
{ name: "Total credits", used: (100 * 545) / 1400, display: "545 / 1400 credits" },
|
||||
{ name: "Credits", used: 100, display: "300 / 300 credits", aside: true },
|
||||
{ name: "Add-on credits", used: (100 * 245) / 1100, display: "245 / 1100 credits", aside: true },
|
||||
])
|
||||
// what routing counts: the windows not set aside
|
||||
const counted = u.windows.filter((w) => !w.aside)
|
||||
expect(counted.map((w) => Math.round(100 - w.used))).toEqual([61])
|
||||
})
|
||||
|
||||
test("one pool alone is shown as before, with nothing set aside", () => {
|
||||
// the owner's account (2026-10-28, read-only): a plan of 0 and add-on credits
|
||||
const u = _internal.parseUsage({
|
||||
displayMode: "qoder",
|
||||
qoderUsage: {
|
||||
userType: "personal_standard",
|
||||
totalUsagePercentage: 0.02,
|
||||
userQuota: { total: 0, used: 0, remaining: 0, percentage: 0, unit: "credits" },
|
||||
addOnQuota: { total: 600, used: 7, remaining: 593, percentage: 0.02, unit: "credits" },
|
||||
},
|
||||
})
|
||||
expect(u.windows).toEqual([{ name: "Add-on credits", used: (100 * 7) / 600, display: "7 / 600 credits" }])
|
||||
})
|
||||
|
||||
test("pools in different units are not added up", () => {
|
||||
const u = _internal.parseUsage({
|
||||
displayMode: "qoder",
|
||||
qoderUsage: { userQuota: { total: 100, used: 100, unit: "tokens" }, addOnQuota: { total: 50, used: 0, unit: "credits" } },
|
||||
})
|
||||
expect(u.windows).toEqual([
|
||||
{ name: "Credits", used: 100, display: "100 / 100 tokens" },
|
||||
{ name: "Add-on credits", used: 0, display: "0 / 50 credits" },
|
||||
])
|
||||
})
|
||||
|
||||
// the loader's fetch, as OpenCode's engine calls it, against a listing and
|
||||
// a chat reply
|
||||
async function chat(listing, reply) {
|
||||
|
||||
Reference in New Issue
Block a user