Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export function parseBillingSettings(value: unknown): BillingSettings | undefine
if (value === undefined || value === null) return undefined;
if (typeof value !== "object" || Array.isArray(value)) return undefined;
const root = value as Record<string, unknown>;
for (const k of Object.keys(root)) if (k !== "prices") return undefined;
if (root["prices"] === undefined) {
for (const k of Object.keys(root)) if (k !== "prices") return undefined;
return { prices: {} };
}
if (root["prices"] === null || typeof root["prices"] !== "object" || Array.isArray(root["prices"])) return undefined;
Expand Down
7 changes: 7 additions & 0 deletions tests/billing-prices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ test("#4899 parseBillingSettings: rejects every invalid shape loudly", () => {
assert.equal(parseBillingSettings({ prices: { m: { input: "3" } } }), undefined, "string number");
});

test("#7263 parseBillingSettings: rejects unknown root fields regardless of prices", () => {
for (const prices of [undefined, {}, { "claude-bill": { input: 3, cacheRead: 0.3 } }]) {
assert.equal(parseBillingSettings({ prices, cacheRead: 0.3 }), undefined, "misplaced price field");
assert.equal(parseBillingSettings({ prices, price: {} }), undefined, "misspelled prices field");
}
});

// ---------------------------------------------------------------------------
// resolveBillingPrice — overrides first (same name matching as the registry),
// registry second, nothing third. Conservative fallbacks: a spend estimate
Expand Down
34 changes: 34 additions & 0 deletions tests/billing-web.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,40 @@ test("null billing prices: structured and whole-file saves reject without mutati
}
});

test("#7263 unknown billing root field: load warns without rewriting config", (t) => {
resetState();
const raw = JSON.stringify({ port: 9876, billing: { prices: { "claude-bill": { input: 6 } }, cacheRead: 0.3 } });
const file = withRawConfig(t, raw);
setBillingOverrides({ "claude-bill": { input: 9 } });
const warnings: string[] = [];
setLogCapture((level, message) => { if (level === "warn") warnings.push(message); });
t.after(() => setLogCapture(null));

const options = loadOptions({});
assert.equal(options.port, 9876, "other config remains available");
assert.ok(warnings.some((message) => message.includes('ignoring invalid "billing" block')));
assert.equal(resolveBillingPrice("claude-bill")?.source, "registry", "invalid block cannot apply or retain overrides");
assert.equal(readFileSync(file, "utf8"), raw, "load preserves the complete invalid config file");
});

test("#7263 unknown billing root field: both save paths preserve config and active prices", async (t) => {
resetState();
const raw = JSON.stringify({ billing: { prices: { "claude-bill": { input: 9 } } } });
const file = withRawConfig(t, raw);
loadOptions({});

for (const prices of [{}, { "claude-bill": { input: 6 } }]) {
const billing = { prices, cacheRead: 0.3 };
for (const body of [{ billing }, { file: JSON.stringify({ billing }) }]) {
const result = await putConfig(body);
assert.equal(result.status, 400);
assert.match(String(result.payload.error), /invalid billing settings/);
assert.equal(readFileSync(file, "utf8"), raw, "rejection preserves the complete config file");
assert.equal(resolveBillingPrice("claude-bill")?.input, 9, "rejection preserves active overrides");
}
}
});

test("#4899 web summaries: sessions carry costUsd/savedUsd/model; overview totals aggregate USD", async () => {
resetState();
const priced = getSession("web-money-1", { protocol: "anthropic", upstreamOrigin: "http://api.somehost.com" });
Expand Down
Loading