Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

fix(web,server): keep the catalog's display name when syncing presets (#679)

Yaowei Zheng733836bc706b
diff --git a/.agents/skills/penguin-harness-dev/reference/model-catalog.md b/.agents/skills/penguin-harness-dev/reference/model-catalog.md
index e9f88e3b..0176fb54 100644
--- a/.agents/skills/penguin-harness-dev/reference/model-catalog.md
+++ b/.agents/skills/penguin-harness-dev/reference/model-catalog.md
@@ -58,4 +58,6 @@ and the `[[models]]` row it names (a default naming no entry is rejected on load
Existing Projects never migrate automatically: presets are copied into `.project_config.toml` at
creation and nothing rewrites them. Users pick changes up through the models page's explicit "sync
presets", which appends and updates catalog-owned fields but never deletes and never touches the
-stored default. Say so in the entry.
+stored default. `display_name` is the one catalog-owned field a sync fills rather than overwrites —
+a stored name may be the user's own rename — so a name the user cleared is filled back in, while a
+rename survives. Say so in the entry.
diff --git a/changelog/unreleased/2026-09-11-catalog-sync-display-name.md b/changelog/unreleased/2026-09-11-catalog-sync-display-name.md
new file mode 100644
index 00000000..c4a1fd3a
--- /dev/null
+++ b/changelog/unreleased/2026-09-11-catalog-sync-display-name.md
@@ -0,0 +1,32 @@
+# Syncing presets keeps the model's display name
+
+- **Date:** 2026-09-11
+- **Type:** fix
+- **Scope:** `web`, `server`
+- **PR:** [#679](https://github.com/Prism-Shadow/penguin-harness/pull/679)
+
+[中文版](2026-09-11-catalog-sync-display-name.zh.md)
+
+A model added to a Project by the Models page's "sync presets" button was saved without a display
+name and listed under its raw model id, and syncing again never brought the name back. The rows a
+sync builds now carry the built-in catalog's name, and a sync fills in the name of any preset row
+that has none, which repairs the Projects an earlier sync had already written.
+
+## Details
+
+- The models endpoint distinguishes an absent display name from an empty one. Absent means
+ "inherit whatever the built-in catalog calls this model"; the empty string means the user
+ cleared the name, and only it records that deletion on disk. The route previously dropped an
+ empty string before the service saw it, leaving the service to read an absent name as a
+ deliberate clearing — so a client that merely had no name for a model cleared the name of every
+ catalog model it sent.
+- `GET /projects/:id/models` reports a cleared name as an empty string rather than as no name, so
+ the whole table coming back on the next PUT still says "cleared" instead of asking for the
+ catalog's name again.
+- "Sync presets" fills a blank name from the catalog and leaves a name that is already there
+ alone: unlike pricing or the context window, a stored name may be the user's own rename. A name
+ the user deliberately cleared is therefore filled in again by the next sync. The Models nav
+ badge counts that repair on the same rule, so the badge and the button still agree about
+ whether there is anything to sync.
+- Existing config files are unchanged until the user syncs: `display_name = ""` keeps meaning
+ "cleared", and an ordinary save on the Models page preserves it.
diff --git a/changelog/unreleased/2026-09-11-catalog-sync-display-name.zh.md b/changelog/unreleased/2026-09-11-catalog-sync-display-name.zh.md
new file mode 100644
index 00000000..de7dca1b
--- /dev/null
+++ b/changelog/unreleased/2026-09-11-catalog-sync-display-name.zh.md
@@ -0,0 +1,26 @@
+# 同步预置后模型名不再丢失
+
+- **Date:** 2026-09-11
+- **Type:** fix
+- **Scope:** `web`, `server`
+- **PR:** [#679](https://github.com/Prism-Shadow/penguin-harness/pull/679)
+
+[English](2026-09-11-catalog-sync-display-name.md)
+
+通过 Models 页的「同步预置」按钮加入 Project 的模型,保存时不带显示名,列表里只显示原始 model id,
+再同步一次也找不回名字。现在同步构造的行会带上内置目录中的名称,并为任何没有名称的预置行补上它,
+从而修复此前同步已经写坏的 Project。
+
+## 细节
+
+- 模型接口区分「字段缺失」与「空字符串」。缺失表示「沿用内置目录给这个模型的名称」;空字符串表示
+ 用户清空了名称,磁盘上也只有它记录这次删除。此前路由层在服务层看到之前就丢弃了空字符串,服务层
+ 只能把「字段缺失」当作有意清空——于是一个只是拿不出名称的客户端,会清空它所提交的每个目录模型的
+ 名称。
+- `GET /projects/:id/models` 把已清空的名称报为空字符串,而不是报成没有名称,使整张表在下一次 PUT
+ 回传时仍然表示「已清空」,而不是转而索取目录里的名称。
+- 「同步预置」只填补空缺的名称,已有名称一律保留:与价格、上下文窗口不同,存下来的名称可能是用户
+ 自己的重命名。代价是用户特意清空的名称会在下一次同步时被重新填上。Models 导航徽标按同一规则计入
+ 这项修复,因此徽标与按钮对「是否还有内容需要同步」仍然口径一致。
+- 用户主动同步之前,既有配置文件不受影响:`display_name = ""` 的含义仍是「已清空」,在 Models 页上
+ 的普通保存也会保留它。
diff --git a/packages/server/src/api/types.ts b/packages/server/src/api/types.ts
index a3bdd393..57b8e843 100644
--- a/packages/server/src/api/types.ts
+++ b/packages/server/src/api/types.ts
@@ -388,7 +388,12 @@ export interface ModelInfo {
provider: string;
/** Upstream model id (the request id actually sent to AgentHub); paired with `provider` forms the entry's unique key. */
modelId: string;
- /** Display name: explicit TOML field (user-edited) takes priority, then the built-in catalog; falls back to unset (frontend shows modelId). */
+ /**
+ * Display name: explicit TOML field (user-edited) takes priority, then the built-in catalog;
+ * falls back to unset (frontend shows modelId). The empty string is reported as such and
+ * means the user cleared the name on a model the catalog does name — render it as modelId,
+ * and send it back unchanged, since absent would ask for the catalog's name instead.
+ */
displayName?: string;
contextWindow?: number;
/** AgentHub client protocol (`openai-chat`, `openai-responses`, etc.); defaults to AgentHub inferring it from modelId. */
@@ -449,7 +454,11 @@ export interface ModelUpdateEntry {
provider: string;
/** Upstream model id (sent to AgentHub as-is). */
modelId: string;
- /** Display name; the server does not persist it when it matches the built-in catalog (keeps the config file clean). */
+ /**
+ * Display name; the server does not persist it when it matches the built-in catalog (keeps
+ * the config file clean). Absent and empty are different requests: absent inherits whatever
+ * the catalog calls the model, the empty string records that the user cleared the name.
+ */
displayName?: string;
/**
* The pair reference this entry was renamed from (provided when either the group or the
diff --git a/packages/server/src/http/routes/models.ts b/packages/server/src/http/routes/models.ts
index b8c085c2..1c99e66e 100644
--- a/packages/server/src/http/routes/models.ts
+++ b/packages/server/src/http/routes/models.ts
@@ -94,7 +94,10 @@ function parseModelsUpdate(body: Record<string, unknown>): ModelsUpdateRequest {
if (typeof m.displayName !== "string" || m.displayName.length > 100) {
throw badRequest(`models[${i}].displayName must be a string of at most 100 characters.`);
}
- if (m.displayName) entry.displayName = m.displayName;
+ // The empty string is carried through rather than dropped: an absent field means
+ // "inherit the built-in catalog's name" and an empty one means "the user cleared it",
+ // and the service cannot tell those apart if the validator collapses them here.
+ entry.displayName = m.displayName;
}
// A key change (either the provider group or the upstream id) goes through renamedFrom's paired old reference; unknown fields are ignored.
if (m.renamedFrom !== undefined) {
diff --git a/packages/server/src/services/project-config-service.ts b/packages/server/src/services/project-config-service.ts
index daedee76..d8111b9a 100644
--- a/packages/server/src/services/project-config-service.ts
+++ b/packages/server/src/services/project-config-service.ts
@@ -849,8 +849,11 @@ export class ProjectConfigService {
// catalog. An empty string is not the same as an absent field — absent means "inherit
// whatever the catalog calls this model", empty means the user cleared the name on a
// model the catalog does name, and inheriting there would hand the name straight back.
+ // The distinction is reported rather than flattened, because the whole table comes back
+ // on the next PUT: a cleared name that arrived as "no name" would be written back as
+ // "inherit" and undo itself. Clients render the empty string as the model id.
const displayName =
- m.display_name === "" ? undefined : (optStr(m.display_name) ?? cat?.displayName);
+ m.display_name === "" ? "" : (optStr(m.display_name) ?? cat?.displayName);
// credential is inlined on the entry: a credential block is emitted if either api_key or base_url is present.
const apiKey = optStr(m.api_key);
const credBaseUrl = optStr(m.base_url);
@@ -969,10 +972,15 @@ export class ProjectConfigService {
// catalog (looked up by the paired reference)** — preset models keep the
// config clean, only user-edited ones (including those not found in the
// catalog) get written into the TOML.
+ //
+ // An ABSENT name and an EMPTY one are different requests, and a client that confuses
+ // them destroys a name it never meant to touch: absent means "inherit whatever the
+ // catalog calls this model" (nothing is written, so the read path falls back to the
+ // catalog), empty means "the user cleared it".
const catNew = catalogEntryFor(entry.provider, entry.modelId);
if (entry.displayName && entry.displayName !== catNew?.displayName) {
next.display_name = entry.displayName;
- } else if (!entry.displayName && catNew?.displayName !== undefined) {
+ } else if (entry.displayName === "" && catNew?.displayName !== undefined) {
// Cleared on a model the catalog names. Writing nothing would leave the field absent,
// which reads as "inherit" — so the name the user just deleted would come back on the
// next load. The empty string is what records the deletion. Only reached for a catalog
diff --git a/packages/server/test/models.test.ts b/packages/server/test/models.test.ts
index 842a99ec..c20efaab 100644
--- a/packages/server/test/models.test.ts
+++ b/packages/server/test/models.test.ts
@@ -639,24 +639,37 @@ describe("model-reference rekeying and the connectivity test", () => {
});
});
- it("clearing a preset model's display name sticks: it falls back to the id, not back to the catalog", async () => {
- // Only provider and modelId are required, so an entry sent without a display name is the
- // user having cleared it. Writing nothing would leave the field absent, which reads as
- // "inherit from the catalog" — the deleted name would be handed straight back on reload.
+ it("an absent display name inherits the catalog's; only an empty one clears it", async () => {
+ // Two different requests, and reading them as one is how a client that simply has no name
+ // for a model — one built from the catalog, which stores no name of its own — destroys the
+ // name of every model it sends.
+ const cfgFile = path.join(t.root, projectId, ".project_config.toml");
await api.put(url(), { models: [{ provider: "openai", modelId: "gpt-5.5" }] });
+ const inherited = (await (await api.get(url())).json()) as ModelsResponse;
+ expect(pick(inherited, "openai", "gpt-5.5").displayName).toBe("GPT-5.5");
+ expect(await readFile(cfgFile, "utf8")).not.toContain("display_name");
+
+ // Cleared: the empty string records the deletion, so the name does not come back on the
+ // next load, and the GET reports it as an empty name rather than as no name — the whole
+ // table comes back on the next PUT, where "no name" would ask for the catalog's again.
+ await api.put(url(), {
+ models: [{ provider: "openai", modelId: "gpt-5.5", displayName: "" }],
+ });
const body = (await (await api.get(url())).json()) as ModelsResponse;
- expect(pick(body, "openai", "gpt-5.5").displayName).toBeUndefined();
- // The empty string is what records the deletion, and it survives a second full-table PUT
- // that likewise carries no name.
- const toml = await readFile(path.join(t.root, projectId, ".project_config.toml"), "utf8");
- expect(toml).toContain('display_name = ""');
- await api.put(url(), { models: [{ provider: "openai", modelId: "gpt-5.5" }] });
+ expect(pick(body, "openai", "gpt-5.5").displayName).toBe("");
+ expect(await readFile(cfgFile, "utf8")).toContain('display_name = ""');
+ // And it survives that round trip, exactly as the page performs it.
+ await api.put(url(), {
+ models: [{ provider: "openai", modelId: "gpt-5.5", displayName: "" }],
+ });
const again = (await (await api.get(url())).json()) as ModelsResponse;
- expect(pick(again, "openai", "gpt-5.5").displayName).toBeUndefined();
+ expect(pick(again, "openai", "gpt-5.5").displayName).toBe("");
});
it("a cleared name is restorable, and clearing a model the catalog does not name writes nothing", async () => {
- await api.put(url(), { models: [{ provider: "openai", modelId: "gpt-5.5" }] });
+ await api.put(url(), {
+ models: [{ provider: "openai", modelId: "gpt-5.5", displayName: "" }],
+ });
// Naming it again drops the marker rather than leaving both on disk.
await api.put(url(), {
models: [{ provider: "openai", modelId: "gpt-5.5", displayName: "Renamed" }],
@@ -667,11 +680,11 @@ describe("model-reference rekeying and the connectivity test", () => {
expect(toml).not.toContain('display_name = ""');
// A model outside the catalog has no name to inherit, so absence already says "no name"
- // and the marker would be noise in the file.
+ // and the marker would be noise in the file — an explicitly empty one included.
await api.put(url(), {
models: [
{ provider: "openai", modelId: "gpt-5.5", displayName: "Renamed" },
- { provider: "custom", modelId: "my-own-model" },
+ { provider: "custom", modelId: "my-own-model", displayName: "" },
],
});
toml = await readFile(path.join(t.root, projectId, ".project_config.toml"), "utf8");
diff --git a/packages/web/src/components/layout/project-dialogs.tsx b/packages/web/src/components/layout/project-dialogs.tsx
index 932f3b7e..e455452a 100644
--- a/packages/web/src/components/layout/project-dialogs.tsx
+++ b/packages/web/src/components/layout/project-dialogs.tsx
@@ -28,7 +28,7 @@ import {
dispatchChatDefaultsChanged,
type ChatDefaultsChangedDetail,
} from "../../features/chat/chat-defaults-event";
-import { ModelSelect } from "../../features/chat/model-select";
+import { ModelSelect, modelLabel } from "../../features/chat/model-select";
import { SELECTABLE_THINKING_LEVELS } from "../../features/chat/thinking-level";
import { WorkspaceSelect } from "../../features/chat/workspace-select";
import { sameModelRef } from "../../features/models/model-grouping";
@@ -815,9 +815,7 @@ function ChatDefaultsSection({ projectId, isOwner }: { projectId: string; isOwne
],
[
S.chat.model,
- defaultModelInfo
- ? (defaultModelInfo.displayName ?? defaultModelInfo.modelId)
- : S.project.chatDefaultsNotSet,
+ defaultModelInfo ? modelLabel(defaultModelInfo) : S.project.chatDefaultsNotSet,
],
] as const
).map(([label, value]) => (
diff --git a/packages/web/src/features/chat/model-select.tsx b/packages/web/src/features/chat/model-select.tsx
index a36914c6..61a3a900 100644
--- a/packages/web/src/features/chat/model-select.tsx
+++ b/packages/web/src/features/chat/model-select.tsx
@@ -30,9 +30,13 @@ import {
import { loadModelGroupOrder } from "../models/model-group-order";
import { useProject } from "../../state/project";
-/** Display label for a model: the display name, or falls back to the upstream id (model_id is the raw field, no prefix parsing). */
+/**
+ * Display label for a model: the display name, or falls back to the upstream id (model_id is
+ * the raw field, no prefix parsing). Blank counts as absent — a name the user cleared is sent
+ * as the empty string, which must read as the id rather than as an empty label.
+ */
export function modelLabel(m: ModelInfo): string {
- return m.displayName ?? m.modelId;
+ return m.displayName?.trim() || m.modelId;
}
/**
diff --git a/packages/web/src/features/models/catalog-sync.ts b/packages/web/src/features/models/catalog-sync.ts
index d18895fc..44eaeef0 100644
--- a/packages/web/src/features/models/catalog-sync.ts
+++ b/packages/web/src/features/models/catalog-sync.ts
@@ -6,8 +6,11 @@
* pricing the catalog doesn't carry); locally added models (including user-defined groups)
* are kept untouched. Credentials are never touched: merged rows carry no apiKey input (the
* PUT keeps the stored key) and existing rows keep their credential display state.
+ *
+ * The display name is the one catalog field that is filled but never overwritten — see
+ * {@link displayNameFill}.
*/
-import { presetModelEntries } from "@prismshadow/penguin-core/model-catalog";
+import { catalogEntryFor, presetModelEntries } from "@prismshadow/penguin-core/model-catalog";
import type { ModelsResponse } from "@prismshadow/penguin-server/api";
import type { RowState } from "./models-page";
@@ -32,13 +35,40 @@ function presetFields(p: PresetEntry) {
};
}
+/**
+ * The name a sync writes onto an entry that currently shows `current`, or undefined to leave it
+ * alone (`undefined` for `current` is a brand-new row, which shows nothing yet).
+ *
+ * Fill-only, unlike every field in `presetFields`: a stored name may be the user's own rename,
+ * which the catalog has no claim to, while a blank one (never set, or cleared on disk and
+ * reported as "") leaves the row labelled by its raw model id and is worth repairing. The cost
+ * of that trade is that a deliberately cleared name comes back on the next sync.
+ *
+ * The name comes from the catalog rather than from `p`: `presetModelEntries` emits the
+ * PERSISTED entry shape, whose `display_name` is only written when it differs from the
+ * catalog, so a preset entry never carries one. Every catalog entry is named
+ * (`ModelCatalogEntry.displayName` is required), so the undefined result means the pair is not
+ * in the catalog at all — unreachable for the default preset list, which the catalog produces,
+ * and the answer for a caller that passes a list of its own.
+ */
+function displayNameFill(p: PresetEntry, current: string | undefined): string | undefined {
+ if (current?.trim()) return undefined;
+ return catalogEntryFor(p.provider, p.model_id)?.displayName;
+}
+
/** A brand-new row for a catalog entry not configured locally (original: null -> added on PUT). */
function presetToRow(p: PresetEntry): RowState {
+ const displayName = displayNameFill(p, undefined);
return {
provider: p.provider,
modelId: p.model_id,
original: null,
...presetFields(p),
+ // The catalog's name, looked up rather than left for the server to infer: the merged rows
+ // are what the page renders and what it submits, so a row that shows a name must carry one.
+ // Deliberately outside presetFields, which the catalog owns outright — on an existing row
+ // the same lookup is fill-only (see displayNameFill).
+ ...(displayName !== undefined ? { displayName } : {}),
// The output cap and fast mode are user-owned, not catalog-owned (deliberately outside
// presetFields, so a sync never clobbers them on existing rows): fresh rows inherit the
// Agent setting / default to off.
@@ -84,9 +114,10 @@ export interface CatalogDelta {
*
* The same union `syncRowsWithCatalog` applies, so the two cannot disagree about whether there
* is anything to do: catalog entries the table does not carry are additions, entries it does
- * carry whose catalog-owned fields differ are updates, and locally added models are invisible
- * to both. `refs` is what a dismissal is stamped against, so a later catalog release touching a
- * different model raises the badge again (see `lib/todo-badges.ts`).
+ * carry whose catalog-owned fields differ — or whose display name is blank — are updates, and
+ * locally added models are invisible to both. `refs` is what a dismissal is stamped against, so
+ * a later catalog release touching a different model raises the badge again (see
+ * `lib/todo-badges.ts`).
*/
export function catalogDelta(
models: readonly ModelDto[],
@@ -103,7 +134,12 @@ export function catalogDelta(
}
const fields = savedFields(entry);
const target = presetFields(p);
- if ((Object.keys(target) as (keyof CatalogFields)[]).some((k) => fields[k] !== target[k])) {
+ // The name counts as an update on the same fill-only rule the merge applies, or a Project
+ // carrying rows with no name would hold a badge the button answers "already up to date".
+ if (
+ displayNameFill(p, entry.displayName) !== undefined ||
+ (Object.keys(target) as (keyof CatalogFields)[]).some((k) => fields[k] !== target[k])
+ ) {
delta.updated += 1;
delta.refs.push(`${p.provider}/${p.model_id}`);
}
@@ -115,7 +151,7 @@ export function catalogDelta(
* Merges the current rows with the built-in catalog. Existing rows keep their identity,
* credential state, and list position (fields are updated in place); catalog-only entries
* are appended in catalog order. Returns the merged rows plus added/updated counts for the
- * success toast (updated counts only rows whose catalog-owned fields actually changed).
+ * success toast (updated counts only rows the merge actually rewrote).
*/
export function syncRowsWithCatalog(
rows: RowState[],
@@ -135,11 +171,12 @@ export function syncRowsWithCatalog(
}
const row = next[i]!;
const fields = presetFields(p);
- const changed = (Object.keys(fields) as (keyof typeof fields)[]).some(
- (k) => row[k] !== fields[k],
- );
+ const fill = displayNameFill(p, row.displayName);
+ const changed =
+ fill !== undefined ||
+ (Object.keys(fields) as (keyof typeof fields)[]).some((k) => row[k] !== fields[k]);
if (changed) {
- next[i] = { ...row, ...fields };
+ next[i] = { ...row, ...fields, ...(fill !== undefined ? { displayName: fill } : {}) };
updated += 1;
}
}
diff --git a/packages/web/src/features/models/models-page.tsx b/packages/web/src/features/models/models-page.tsx
index e09e1059..e9466ebe 100644
--- a/packages/web/src/features/models/models-page.tsx
+++ b/packages/web/src/features/models/models-page.tsx
@@ -269,7 +269,12 @@ export interface RowState {
* server uses to migrate the credential and pointers. null for a new entry.
*/
original: ModelRefDto | null;
- /** Display name from the built-in catalog; absent for custom models. */
+ /**
+ * What the model is called: the user's own name, or the built-in catalog's. Absent means the
+ * model has no name (a custom one, or a catalog row loaded before the name was filled in) and
+ * asks the server to inherit the catalog's; the empty string means a name the user cleared,
+ * which is a different request — see rowToEntry.
+ */
displayName?: string;
/**
* Whether to treat this as a vision model (effective semantics): the server already
@@ -568,8 +573,11 @@ export function rowToEntry(row: RowState): ModelUpdateEntry {
if (row.original && !sameModelRef(row.original, rowRef(row))) {
entry.renamedFrom = row.original;
}
- // Display name: the server only persists it when it differs from the built-in catalog (keeps preset model configs clean).
- if (row.displayName?.trim()) entry.displayName = row.displayName.trim();
+ // Display name: submitted whenever the row carries one at all, the empty string included —
+ // absent means "inherit whatever the catalog calls this model" and empty means "the user
+ // cleared it", so a row that simply has no name must not travel as a deletion. The server
+ // only persists a name that differs from the built-in catalog (keeps preset configs clean).
+ if (row.displayName !== undefined) entry.displayName = row.displayName.trim();
const cw = Number(row.contextWindow.trim());
if (row.contextWindow.trim() && Number.isFinite(cw)) entry.contextWindow = cw;
// Never persists an empty protocol for a custom-like entry (that entry could not start —
diff --git a/packages/web/test/catalog-sync.test.ts b/packages/web/test/catalog-sync.test.ts
index 2b4ecb11..0bde7ca1 100644
--- a/packages/web/test/catalog-sync.test.ts
+++ b/packages/web/test/catalog-sync.test.ts
@@ -1,13 +1,15 @@
/**
* catalog-sync.ts unit tests: the "sync presets" merge — union of the local model table and
* the built-in catalog, catalog winning on differing preset entries, local additions and
- * credentials untouched — plus `catalogDelta`, the same question asked of a saved table so the
- * Models nav badge can answer it before the page has loaded any rows.
+ * credentials untouched, the display name filled but never overwritten — plus `catalogDelta`,
+ * the same question asked of a saved table so the Models nav badge can answer it before the
+ * page has loaded any rows.
*
* The last block is the one that matters most: the badge and the button must never disagree
* about whether there is anything to do, so every case above is replayed through both.
*/
import { describe, expect, it } from "vitest";
+import { catalogEntryFor } from "@prismshadow/penguin-core/model-catalog";
import type { ModelsResponse } from "@prismshadow/penguin-server/api";
import { catalogDelta, syncRowsWithCatalog } from "../src/features/models/catalog-sync";
import { presetUpdateTodo } from "../src/lib/todo-badges";
@@ -40,6 +42,34 @@ function makeRow(partial: Partial<RowState> & Pick<RowState, "provider" | "model
};
}
+/**
+ * The shipped catalog's name for a pair, read rather than pinned: the fixtures below stand in
+ * for catalog entries on every other field, and a rename in `model-catalog.ts` has no business
+ * breaking a test about the merge.
+ */
+function catalogName(provider: string, modelId: string): string {
+ return catalogEntryFor(provider, modelId)!.displayName;
+}
+
+/**
+ * A row matching the catalog on every field a sync owns, the display name included: a saved
+ * preset row always carries one, because the GET fills it in from the catalog when the config
+ * file does not. Overrides make the one field under test the only thing out of line.
+ */
+function inSyncRow(extra: Partial<RowState> = {}): RowState {
+ return makeRow({
+ provider: "deepseek",
+ modelId: "deepseek-v4-pro",
+ displayName: catalogName("deepseek", "deepseek-v4-pro"),
+ vision: false,
+ contextWindow: "1000000",
+ cacheRead: "0.003571",
+ cacheWrite: "0.428571",
+ output: "0.857143",
+ ...extra,
+ });
+}
+
const PRESET: PresetEntry[] = [
{
provider: "deepseek",
@@ -84,6 +114,15 @@ describe("syncRowsWithCatalog", () => {
expect(glm.originalBaseUrl).toBe(""); // differs from baseUrl -> the PUT submits the preset URL
expect(glm.cacheRead).toBe("0.285714");
expect(glm.vision).toBe(false);
+ // The catalog's name travels with the new row: a preset entry carries none (the persisted
+ // shape only stores a name that differs from the catalog), so a row built without it would
+ // reach the PUT nameless and be saved as a model whose name the user cleared.
+ expect(glm.displayName).toBe(catalogName("qwen-token-plan", "glm-5.2"));
+ // The lookup is against the shipped catalog, not against this list: `qwen3.8-max-preview`
+ // left the Token Plan lineup, so the pair resolves to nothing and the row stays nameless
+ // (falling back to its model id) rather than picking up an empty name.
+ expect(catalogEntryFor("qwen-token-plan", "qwen3.8-max-preview")).toBeUndefined();
+ expect(rows.find((r) => r.modelId === "qwen3.8-max-preview")!.displayName).toBeUndefined();
});
it("resets differing preset rows to the catalog's fields, keeping identity and credentials", () => {
@@ -104,6 +143,7 @@ describe("syncRowsWithCatalog", () => {
expect(updated).toBe(1);
const row = rows[0]!;
expect(row.contextWindow).toBe("1000000");
+ expect(row.displayName).toBe(catalogName("deepseek", "deepseek-v4-pro"));
expect(row.vision).toBe(false);
expect(row.cacheRead).toBe("0.003571");
expect(row.baseUrl).toBe(""); // catalog has no base_url; differs from originalBaseUrl -> cleared on PUT
@@ -116,20 +156,30 @@ describe("syncRowsWithCatalog", () => {
});
it("leaves up-to-date rows untouched (same object, updated not counted)", () => {
- const upToDate = makeRow({
- provider: "deepseek",
- modelId: "deepseek-v4-pro",
- vision: false,
- contextWindow: "1000000",
- cacheRead: "0.003571",
- cacheWrite: "0.428571",
- output: "0.857143",
- });
+ const upToDate = inSyncRow();
const { rows, updated } = syncRowsWithCatalog([upToDate], PRESET);
expect(updated).toBe(0);
expect(rows[0]).toBe(upToDate);
});
+ it("fills a blank display name from the catalog, and never overwrites one already there", () => {
+ // A preset row showing no name is one an earlier sync saved without one: it renders as the
+ // raw model id until something puts the catalog's name back, and this is that something.
+ const blank = syncRowsWithCatalog([inSyncRow({ displayName: "" })], PRESET);
+ expect(blank.updated).toBe(1);
+ expect(blank.rows[0]!.displayName).toBe(catalogName("deepseek", "deepseek-v4-pro"));
+ // Same for a row that never had the field at all.
+ const absent = syncRowsWithCatalog([inSyncRow({ displayName: undefined })], PRESET);
+ expect(absent.updated).toBe(1);
+ expect(absent.rows[0]!.displayName).toBe(catalogName("deepseek", "deepseek-v4-pro"));
+ // A name that is there stays: unlike pricing or the context window, it may be the user's
+ // own rename, and the catalog has no claim to it.
+ const renamed = inSyncRow({ displayName: "My DeepSeek" });
+ const kept = syncRowsWithCatalog([renamed], PRESET);
+ expect(kept.updated).toBe(0);
+ expect(kept.rows[0]).toBe(renamed);
+ });
+
it("preserves a user-set max output tokens through a preset sync (user-owned, not catalog-owned)", () => {
const local = makeRow({
provider: "deepseek",
@@ -177,6 +227,8 @@ describe("syncRowsWithCatalog", () => {
expect(updated).toBe(0);
// No merged row ever carries a key input: credentials are structurally untouched.
expect(rows.every((r) => r.apiKeyInput === "" && !r.clearApiKey)).toBe(true);
+ // Every catalog entry is named, so no row added from it may go out nameless.
+ expect(rows.every((r) => (r.displayName ?? "") !== "")).toBe(true);
});
});
@@ -185,30 +237,65 @@ function makeDto(partial: Partial<ModelDto> & Pick<ModelDto, "provider" | "model
return { ...partial } as ModelDto;
}
+/**
+ * A saved entry matching the catalog on every field a sync owns. The display name comes from
+ * the catalog because the GET fills it in from there whenever the config file carries none —
+ * a table saved from a sync looks like this, and nothing in it is left to do.
+ */
+function inSyncDto(p: PresetEntry, extra: Partial<ModelDto> = {}): ModelDto {
+ const displayName = catalogEntryFor(p.provider, p.model_id)?.displayName;
+ return makeDto({
+ provider: p.provider,
+ modelId: p.model_id,
+ vision: p.vision !== false,
+ ...(displayName !== undefined ? { displayName } : {}),
+ ...(p.context_window !== undefined ? { contextWindow: p.context_window } : {}),
+ ...(p.client_type !== undefined ? { clientType: p.client_type } : {}),
+ ...(p.pricing
+ ? {
+ pricing: {
+ cacheRead: p.pricing.cache_read,
+ cacheWrite: p.pricing.cache_write,
+ output: p.pricing.output,
+ } as ModelDto["pricing"],
+ }
+ : {}),
+ ...(p.base_url !== undefined
+ ? { credential: { baseUrl: p.base_url } as ModelDto["credential"] }
+ : {}),
+ ...extra,
+ });
+}
+
describe("catalogDelta", () => {
it("reports nothing when the saved table already matches the catalog", () => {
- const saved = PRESET.map((p) =>
- makeDto({
- provider: p.provider,
- modelId: p.model_id,
- vision: p.vision !== false,
- ...(p.context_window !== undefined ? { contextWindow: p.context_window } : {}),
- ...(p.client_type !== undefined ? { clientType: p.client_type } : {}),
- ...(p.pricing
- ? {
- pricing: {
- cacheRead: p.pricing.cache_read,
- cacheWrite: p.pricing.cache_write,
- output: p.pricing.output,
- } as ModelDto["pricing"],
- }
- : {}),
- ...(p.base_url !== undefined
- ? { credential: { baseUrl: p.base_url } as ModelDto["credential"] }
- : {}),
- }),
- );
- expect(catalogDelta(saved, PRESET)).toEqual({ added: 0, updated: 0, refs: [] });
+ expect(
+ catalogDelta(
+ PRESET.map((p) => inSyncDto(p)),
+ PRESET,
+ ),
+ ).toEqual({
+ added: 0,
+ updated: 0,
+ refs: [],
+ });
+ });
+
+ it("counts a blank display name as something to sync, and a user's own name as nothing", () => {
+ // The badge has to raise the same repair the button performs: a preset row saved with no
+ // name renders as its model id until a sync puts the catalog's name back.
+ expect(catalogDelta([inSyncDto(PRESET[0]!, { displayName: "" })], PRESET)).toEqual({
+ added: 2,
+ updated: 1,
+ refs: [
+ "deepseek/deepseek-v4-pro",
+ "qwen-token-plan/glm-5.2",
+ "qwen-token-plan/qwen3.8-max-preview",
+ ],
+ });
+ expect(
+ catalogDelta([inSyncDto(PRESET[0]!, { displayName: "My DeepSeek" })], PRESET).refs,
+ ).not.toContain("deepseek/deepseek-v4-pro");
});
it("names every entry it would add or rewrite, in catalog order", () => {
@@ -248,6 +335,10 @@ describe("catalogDelta", () => {
}),
],
[makeDto({ provider: "custom", modelId: "my-own", contextWindow: 8192 })],
+ // The display name: in sync, blank (an earlier sync's damage), and the user's own.
+ [inSyncDto(PRESET[0]!)],
+ [inSyncDto(PRESET[0]!, { displayName: "" })],
+ [inSyncDto(PRESET[0]!, { displayName: "My DeepSeek" })],
];
for (const table of tables) {
const merged = syncRowsWithCatalog(table.map(toRow), PRESET);