TypeScript
fix(usage): explain price edits blocked by model mappings (#23768)
Victor Vogel90235549bf04
diff --git a/apps/web/src/components/usage/usagePriceTable.test.ts b/apps/web/src/components/usage/usagePriceTable.test.tsindex 2ef6ea31c9b..43539fb970d 100644--- a/apps/web/src/components/usage/usagePriceTable.test.ts+++ b/apps/web/src/components/usage/usagePriceTable.test.ts@@ -120,6 +120,26 @@ describe("price table edits", () => {),).toBe("Map to a different model.");});++ it("requires clearing a mapping before a price edit can apply to every environment", () => {+ const mapped = target("mapped", {}, { example: "example-model" });+ const priced = target("priced", { example: price });+ const edit = draft({ inputCostPerMillionTokens: "3", outputCostPerMillionTokens: "8" });+ expect(usagePriceTableErrors([mapped, priced], [edit]).get(edit.id)).toBe(+ 'mapped maps this model. Remove it from "Apply to" or clear its mapping first.',+ );+ expect(usagePriceTableChanges(mapped, [edit]).changes).toEqual([]);++ const cleared = { ...edit, alias: "" };+ expect(usagePriceTableErrors([mapped, priced], [cleared]).size).toBe(0);+ expect(usagePriceTableChanges(mapped, [cleared]).changes).toEqual([+ { model: "example", alias: null },+ { model: "example", price: { inputCostPerMillionTokens: 3, outputCostPerMillionTokens: 8 } },+ ]);+ expect(usagePriceTableChanges(priced, [cleared]).changes).toEqual([+ { model: "example", price: { inputCostPerMillionTokens: 3, outputCostPerMillionTokens: 8 } },+ ]);+ });});describe("model mapping validation", () => {diff --git a/apps/web/src/components/usage/usagePriceTable.ts b/apps/web/src/components/usage/usagePriceTable.tsindex 04b667c2ec3..5bf86ec4caf 100644--- a/apps/web/src/components/usage/usagePriceTable.ts+++ b/apps/web/src/components/usage/usagePriceTable.ts@@ -78,6 +78,13 @@ export function usagePriceTableChanges(}const alias = (draft.alias ?? currentAlias ?? "").trim();if (alias !== "") {+ if (draft.alias === undefined && Object.keys(draft.values).length > 0) {+ errors.set(+ draft.id,+ `${target.label} maps this model. Remove it from "Apply to" or clear its mapping first.`,+ );+ continue;+ }if (model === "") errors.set(draft.id, "Enter a model ID.");else if (alias === model) errors.set(draft.id, "Map to a different model.");else {