Skip to content

Commit f4de1de

Browse files
fix(spec): one rename rule for every unknown-key suggester (#35639)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuRTHmmdYhGsPrpf8EzYYxUk)_ Part of #35420 — the shared budget rule lands here; the retired-key half (the card's last sentence) needs no code change under the standing ruling, see Acceptance notes. The card is closed by hand after merge with that reading. Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:元数据作者在对象定义或种子数据里写错一个很短的键名时,报错不再附带一个毫不相干的"你是不是想写"建议;真正差一个字母或两个字母互换的笔误仍会被提示,其余入口不变。 - 为什么做:这是上一轮"短键名拼写建议收紧"的收尾,把同一条规则推到另外两个还在各自计算的报错入口,替编写元数据的作者(多数是 AI)解决被错误建议带偏的问题。 - 出错会怎样:最坏只是报错里的建议文字不准或缺失,任何键的接受与拒绝都不变,可以直接撤回。 - 要你做什么:无需你操作。卡片最后一句(退役旧键是否还附带拼写改名建议)按已有裁决处理:ADR-0087 2026-10-26 修订(#25767 D2=A)规定退役超过一个大版本的键按普通未知键拒绝、给出最接近的拼写并指向协议升级指南,现状正是如此,不改代码,也不另行请你裁定。 ## What changes One rename rule for every unknown-key suggester in `packages/spec`, in a new leaf module `packages/spec/src/shared/rename-guess.ts` (imports nothing; not re-exported from `shared/index.ts`, like `alias-probe.ts`): - `renameBudget(key)` = `max(2, floor(len / 3))`, and `suggestRename(key, knownKeys)` = the settled rule from the strict refusal: above five characters the first `findClosestMatches` answer inside the budget; at five or fewer only a candidate one edit away, an adjacent swap counted as one; nothing for an empty key. - `levenshteinDistance` and `findClosestMatches` moved into the leaf with their docblocks verbatim and are re-exported from `suggestions.zod.ts`, so the published names and import path are unchanged (`check:api-surface` green; `export-origins/` regenerated for the two moved origins). The leaf exists so `data/*.zod.ts` can share the rule without a cycle through `suggestions.zod.ts` and without adding a published export. - Doors now calling it: `strictUnknownKeyError` (unchanged behaviour), `ObjectSchema.create()` (its private `editDistance` + `suggestKey` copy is deleted) `defineSeed` (its inline `max(2, floor(len / 3))` is deleted) and the authoring-key lint `lintAuthoredRecordKeys` in `data/authoring-key-lint.ts`, which `defineStack` and the CLI report through (its flat `findClosestMatches(key, candidates, 3, 1)` is replaced; the `hint?.to ?? (hint?.why ? undefined : …)` precedence is unchanged). The leaf's header now names every unknown-key door; the value-vocabulary suggesters (`error-map.zod.ts` enum hint, `suggestFieldType`) stay on `findClosestMatches`' default on purpose. - `field-value.zod.ts` and `default-value-shape.ts` held no code copy: they read the rule through `strictObject` already. Their comments restated the old budget and lookup and now name `suggestRename`. - The `strictUnknownKeyError` docblock said its fallback matched `suggestKey` in `object.zod.ts` (comment 7004171725); it now names `suggestRename`, which both doors call, so the sentence is true by construction. - Nit: the header of `packages/rest/src/rest-meta-packaged-action-permission-refusal.test.ts` named the retired data route for the permission-set clone; it now names `POST /api/v1/security/permission-sets/:name/clone`, the route the regime table's refusal spells. Observable change, suggestion text only: `ObjectSchema.create({ page: 1 })` no longer says "did you mean `name`", `defineSeed` no longer answers a record key `kind` with `id`, and the authoring-key report no longer answers `aria` with `areas` or an eight-character key three edits away (`descrptn`) at all, while `dfltValue` → `defaultValue` (nine characters, budget 3) is still answered. One-edit slips (`nmae`, `labl`, `queeu`) are still answered. No key is accepted or refused differently. ## Tests <details><summary>Pins, one per door, plus the rule and a class guard</summary> - `data/object.test.ts`: `page` gets no rename; `nmae` → `name`, `labl` → `label` still answered. - `data/define-seed-record-keys.test.ts`: `kind` gets no rename; `queeu` → `queue` (adjacent swap) still answered. - `data/field-value.test.ts`: `LocationValueSchema` `lon` gets no rename; `lgn` → `lng` still answered. - `data/default-value-shape.test.ts`: `checkLiteralDefaultValue` on a location default, same pair. - `data/authoring-key-lint.test.ts`: `aria` gets no rename; `lable` and `lbael` → `label` still answered; `descrptn` (8 characters, 3 edits) gets nothing while `dfltValue` (9 characters, 3 edits) → `defaultValue`. - `shared/suggestions.test.ts`: `renameBudget`, `suggestRename` (short, long, empty key), and a guard that no non-test source file under `packages/spec/src` other than `rename-guess.ts` spells `Math.max(2, Math.floor(` or hands `findClosestMatches` its own distance (a third argument) in code (comment lines skipped). - The strict door's own pins stay in `shared/strict-object.test.ts` (unchanged). </details> <details><summary>Readings (head 945afc3)</summary> - At 945afc3 (authoring-key-lint fold): `pnpm --filter @objectstack/spec build && pnpm --filter @objectstack/spec check:generated` → exit 0 (all 14 artifacts up to date); `pnpm --filter @objectstack/spec typecheck` → exit 0; `vitest run src/shared/ src/data/authoring-key-lint.test.ts src/data/object.test.ts src/data/define-seed-record-keys.test.ts src/data/field-value.test.ts src/data/default-value-shape.test.ts` → 45 files, 1359 tests passed; the lint's consumers `src/kernel/metadata-authoring-lint.test.ts src/cron-typed-positions-retirement.test.ts src/stack.test.ts src/kernel/functional-completeness.test.ts` → 4 files, 216 tests passed. `dispatch-gates.mjs --commands` derives the same 96 commands and no full spec suite; `--ran` → 93 run, 3 NOT MEASURED (shallow-clone fixture, full-workspace dist), including `check:lean-entry-closure` exit 0 after building objectql. - Ablation at 945afc3: the call site reverted to `findClosestMatches(key, candidates, 3, 1)[0]` (import held, then the call replaced; both anchors x1 then x0, blob ebad5a5 to ad0aef4d): `authoring-key-lint.test.ts` + `suggestions.test.ts` → 3 failed / 54 passed (the short-key and length-relative cases and the class guard red; the one-edit slip control stays green). Restored: blob == HEAD ebad5a5, `git diff HEAD` empty. - At b8bdbfb (before the fold), the readings below. - `pnpm --filter @objectstack/spec build && pnpm --filter @objectstack/spec check:generated` → GEN_EXIT=0 (14 artifacts up to date after the `export-origins/` regeneration). - `pnpm --filter @objectstack/spec typecheck` → TC_EXIT=0. - `pnpm --filter @objectstack/spec test` → Test Files 858 passed (858), Tests 27414 passed, 1 todo; TEST_EXIT=0. - Ablation (one, since every door reads one rule): `node scripts/ablation-replace.mjs` on `rename-guess.ts`, anchor `foldForScoring(candidate)) <= 1);` hit x1 then x0, blob 06f1011 to 9292b58e; the six harness files ran 8 failed / 367 passed (6 files red: object, seed, field-value, default-value-shape, strict-object, suggestions). Restored by the tool; working blob hash equal to the HEAD blob 06f1011, `git diff HEAD` empty. Expected direction (red) observed. </details> ## Acceptance notes - **The retired-key half needs no change: the standing ruling covers it.** Measured at the `/meta` write door (the real `PUT /api/v1/meta/:type/:name` route handler of an in-process `RestServer` over a real `ObjectStackProtocolImplementation` and `SchemaRegistry`, built dists, head b8bdbfb): a form view body with `defaultSort` answers `422 INVALID_METADATA` with "Unrecognized key(s) on this inline form view: `defaultSort`. Did you mean `defaultSort` → `defaults`? Keys retired before the previous protocol major are no longer prescribed here — see the protocol upgrade guide…", and the `unrecognized_keys` entry in `issues[]` names the upgrade guide too. The same probe with `aria` answers with no guess (the short-key rule working at the door). The ADR-0087 2026-10-26 amendment (#25767 D2 = A) rules that once a retirement kit ages out "a removed key is refused as a strict unknown key whose refusal names the protocol upgrade guide" (ADR-0087 status line; the same words under D2), which is exactly the reading above. The amendment is silent on the rename guess a strict unknown-key refusal carries, so the guess stays the ordinary strict-refusal behaviour. Keeping a rename guess off a retired key would mean the spec remembers aged-out keys again, which that amendment chose not to do. The seat routed this half to that ruling (no B or C option, nothing put to the maintainer); the card is closed after merge citing this reading. - The retired checklist item `access-security.packaged-permission-set-lifecycle` was left unchanged: its title already says "at the retired sys_permission_set data door" and its `retiredReason` already names `POST /api/v1/security/permission-sets/:name/clone`; its steps describe what the item tested before it retired. - Other copies of the budget, outside this diff's reach, reported to the seat and not changed here: `packages/formula/src/validate.ts` (`nearest`), `packages/lint/src/object-graph.ts`, `packages/cli/src/utils/collect-docs.ts`. Prose that still describes the pre-screen budget: `kernel/manifest.zod.ts` (the `hosts` alias comment says the fallback would answer `hooks`; the short-key screen now refuses that guess on its own, so the alias fills a gap rather than overruling a wrong answer). ## Out of scope Other copies of the rename budget, found by grep and not changed here. None was measured at a public door, and no card is filed: - `packages/formula/src/validate.ts:1497` (`nearest`): `max(2, floor(len / 3))` without the short-key screen. - `packages/lint/src/object-graph.ts:809`: the same budget, without the screen. - `packages/cli/src/utils/collect-docs.ts:974`: the same budget, without the screen. ## Verification Read first, by risk: 1. `packages/spec/src/shared/rename-guess.ts` — `suggestRename` (the moved rule; the empty-key guard moved into it). 2. `packages/spec/src/shared/suggestions.zod.ts` — the re-export line and the `strictUnknownKeyError` call site. 3. `packages/spec/src/data/object.zod.ts` — `unknownKeyError` now calls `suggestRename`. Two-minute check: `pnpm --filter @objectstack/spec exec vitest run src/data/object.test.ts src/data/define-seed-record-keys.test.ts` — expect both files green, including the two new `a short unknown key gets the shared rename rule` describes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L6bhgUZrkMKgGrXXe8zPGq <!-- signed: repo:objectstack#1 · os-sales · session_01L6bhgUZrkMKgGrXXe8zPGq --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5dd856f commit f4de1de

17 files changed

Lines changed: 439 additions & 205 deletions
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/spec': patch
3+
---
4+
5+
fix(spec): `ObjectSchema.create()`, `defineSeed` and the `defineStack` / CLI unknown-authoring-key report no longer answer a short unknown key with an unrelated one
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The strict unknown-key refusal on every `strictObject` surface stopped offering a key of five characters or fewer a rename that is two unrelated edits away: such a key is answered only by a candidate one edit away, an adjacent swap counted as one. `ObjectSchema.create()` and `defineSeed` carried their own copy of the `max(2, len/3)` budget without that screen, so they went on answering, for example, an object key `page` with `name` and a seed key `kind` with `id`. The unknown-authoring-key report that `defineStack` and the CLI print (`… is not a declared … key, so its value is dropped at load — did you mean …?`) used a flat distance of 3 for every key, so `aria` was answered `areas`, and the budget did not follow the key's length.
11+
12+
All four now read one rename rule. A genuine one-edit slip is still answered (`nmae` → `name`, `labl` → `label`, `queeu` → `queue`), and keys longer than five characters keep the same `max(2, len/3)` budget (for the authoring-key report that budget replaces the flat 3, so an eight-character key three edits away, `descrptn`, is no longer answered, while a nine-character one, `dfltValue` → `defaultValue`, still is); `ObjectSchema.create()` now also ranks its candidates the way the strict refusal does (case and separators folded on both sides, the author's own capitalisation breaking a tie). Only the "did you mean" text changes: no key is accepted or refused that was not before, and no export is added or removed.

‎packages/rest/src/rest-meta-packaged-action-permission-refusal.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
* action-clone half is not chartered; [#30065] its save names the declared
1717
* override from the base's paired `.custom` first (ADR-0146 D9 `action`);
1818
* - a PERMISSION SET has its clone (§8 item 3, the "New similar" action, which posts
19-
* to `POST /api/v1/data/sys_permission_set`) and no switch named here.
19+
* to the catalog's clone door `POST /api/v1/security/permission-sets/:name/clone`
20+
* since C3 stage 8 retired the row object's data route) and no switch named here.
2021
*
2122
* The protocol-side pins are
2223
* `packages/metadata-protocol/src/protocol.packaged-base-refusal.test.ts`; this

‎packages/spec/export-origins/root.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
"expandViewContainer": "src/ui/view.zod.ts#expandViewContainer (function)",
179179
"expandViewContainerWithDiagnostics": "src/ui/view.zod.ts#expandViewContainerWithDiagnostics (function)",
180180
"expression": "src/shared/expression.zod.ts#expression (function)",
181-
"findClosestMatches": "src/shared/suggestions.zod.ts#findClosestMatches (function)",
181+
"findClosestMatches": "src/shared/rename-guess.ts#findClosestMatches (function)",
182182
"formatSuggestion": "src/shared/suggestions.zod.ts#formatSuggestion (function)",
183183
"formatUnknownAuthoringKey": "src/data/authoring-key-lint.ts#formatUnknownAuthoringKey (function)",
184184
"formatZodError": "src/shared/error-map.zod.ts#formatZodError (function)",

‎packages/spec/export-origins/shared.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@
103103
"cron": "src/shared/expression.zod.ts#cron (function)",
104104
"currencyForLocale": "src/shared/region-currency.ts#currencyForLocale (function)",
105105
"expression": "src/shared/expression.zod.ts#expression (function)",
106-
"findClosestMatches": "src/shared/suggestions.zod.ts#findClosestMatches (function)",
106+
"findClosestMatches": "src/shared/rename-guess.ts#findClosestMatches (function)",
107107
"formatSuggestion": "src/shared/suggestions.zod.ts#formatSuggestion (function)",
108108
"formatZodError": "src/shared/error-map.zod.ts#formatZodError (function)",
109109
"formatZodIssue": "src/shared/error-map.zod.ts#formatZodIssue (function)",
110110
"isValueDomainMember": "src/shared/value-domain.zod.ts#isValueDomainMember (function)",
111111
"keySetMatches": "src/shared/suggestions.zod.ts#keySetMatches (function)",
112112
"lazySchema": "src/shared/lazy-schema.ts#lazySchema (function)",
113-
"levenshteinDistance": "src/shared/suggestions.zod.ts#levenshteinDistance (function)",
113+
"levenshteinDistance": "src/shared/rename-guess.ts#levenshteinDistance (function)",
114114
"metaUrlSpellingRefusal": "src/meta-spelling/metadata-url-spelling.ts#metaUrlSpellingRefusal (function)",
115115
"normalizeMetadataCollection": "src/shared/metadata-collection.zod.ts#normalizeMetadataCollection (function)",
116116
"normalizePluginMetadata": "src/shared/metadata-collection.zod.ts#normalizePluginMetadata (function)",

‎packages/spec/src/data/authoring-key-lint.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,35 @@ describe('a typed list declared on an embedded-JSON field is refused with the ch
213213
}
214214
});
215215
});
216+
217+
/**
218+
* The authoring-key lint (read by `defineStack` and the CLI) answers an unknown
219+
* key with the package's ONE rename rule (`shared/rename-guess.ts`). It used to
220+
* pass a flat distance of 3 to `findClosestMatches`, so a four-letter key was
221+
* offered any declared key three edits away, and the budget did not grow or
222+
* shrink with the key.
223+
*/
224+
describe('lintAuthoredRecordKeys — an unknown key gets the shared rename rule', () => {
225+
const declared = ['description', 'label', 'required', 'areas', 'defaultValue'];
226+
227+
it('a short key two unrelated edits from a declared key gets no rename', () => {
228+
// `aria` → `areas` is one substitution and one insertion: inside the old
229+
// flat 3, outside the one-edit screen a short key gets.
230+
const [f] = runComparator({ aria: 'x' }, declared);
231+
expect(f).toMatchObject({ path: 'p.aria', key: 'aria' });
232+
expect(f.suggestion).toBeUndefined();
233+
expect(formatUnknownAuthoringKey(f)).not.toContain('did you mean');
234+
});
235+
236+
it('a one-edit or adjacent-swap slip on a short key is still answered', () => {
237+
expect(runComparator({ lable: 'x' }, declared)[0]?.suggestion).toBe('label');
238+
expect(runComparator({ lbael: 'x' }, declared)[0]?.suggestion).toBe('label');
239+
});
240+
241+
it('the budget is length-relative: three edits are too many at eight characters, enough at nine', () => {
242+
// Both are three edits from their declared key. `descrptn` (8 characters)
243+
// gets a budget of 2; `dfltValue` (9 characters) gets 3.
244+
expect(runComparator({ descrptn: 'x' }, declared)[0]?.suggestion).toBeUndefined();
245+
expect(runComparator({ dfltValue: 'x' }, declared)[0]?.suggestion).toBe('defaultValue');
246+
});
247+
});

‎packages/spec/src/data/authoring-key-lint.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* @see ADR-0049 enforce-or-remove · ADR-0104 · #4001 (the strict tiers)
4444
*/
4545

46-
import { findClosestMatches } from '../shared/suggestions.zod';
46+
import { suggestRename } from '../shared/rename-guess';
4747

4848
/**
4949
* Which authoring surface a finding came from — a metadata type machine name
@@ -267,7 +267,9 @@ export function lintAuthoredRecordKeys(
267267
// A retirement (`why`, no `to`) deliberately suppresses the edit-distance
268268
// fallback: there IS no successor, and the nearest declared key by spelling
269269
// is noise — `pii` is 3 edits from `min`, which would read as real advice.
270-
const suggestion = hint?.to ?? (hint?.why ? undefined : findClosestMatches(key, candidates, 3, 1)[0]);
270+
// The fallback is the package's one rename rule (`shared/rename-guess.ts`):
271+
// a flat distance of 3 answered a short key with anything three edits away.
272+
const suggestion = hint?.to ?? (hint?.why ? undefined : suggestRename(key, candidates));
271273
out.push({
272274
path: `${basePath}.${key}`,
273275
surface,

‎packages/spec/src/data/default-value-shape.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,25 @@ describe('suggestDefaultValueToken — Object.prototype fall-through', () => {
219219
expect(suggestDefaultValueToken('current_time')).toBe('NOW()');
220220
});
221221
});
222+
223+
/**
224+
* A literal default is judged by the value shape's own refusal, so its detail
225+
* carries the package's ONE rename rule (`shared/rename-guess.ts`) — pinned at
226+
* this door because `actionableValueIssueMessage`'s docblock restates it.
227+
*/
228+
describe('checkLiteralDefaultValue — a short unknown key gets the shared rename rule', () => {
229+
it('a short key two unrelated edits from a member is offered nothing', () => {
230+
const v = checkLiteralDefaultValue({ type: 'location' }, { lat: 1, lng: 2, lon: 3 });
231+
expect(v.ok).toBe(false);
232+
if (v.ok) return;
233+
expect(v.detail).toContain('Unrecognized key(s) on this location value: `lon`.');
234+
expect(v.detail).not.toContain('Did you mean');
235+
});
236+
237+
it('a genuine one-edit slip on a short key is still answered', () => {
238+
const v = checkLiteralDefaultValue({ type: 'location' }, { lat: 1, lng: 2, lgn: 3 });
239+
expect(v.ok).toBe(false);
240+
if (v.ok) return;
241+
expect(v.detail).toContain('Did you mean `lgn` → `lng`?');
242+
});
243+
});

‎packages/spec/src/data/default-value-shape.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,11 @@ export interface LiteralDefaultValueVerdict {
122122
* The rename IS the prescription. Which channel produced it depends on the
123123
* key, and the two cases this function is pinned against are one of each — so
124124
* "the curated `aliases` map is what makes the rename possible" is true of only
125-
* half of them. The fallback budget is `Math.max(2, Math.floor(key.length / 3))`
126-
* (`shared/suggestions.zod.ts`), and the lookup is
127-
* `aliases[aliasProbe(key)] ?? findClosestMatches(key, knownKeys, budget, 1)[0]`
128-
* — the table is consulted first and wins outright.
125+
* half of them. The fallback is `suggestRename` (`shared/rename-guess.ts`, the
126+
* package's one rename rule: budget `max(2, floor(len / 3))`, and at five
127+
* characters or fewer one edit counting an adjacent swap as one), and the
128+
* lookup is `aliases[aliasProbe(key)] ?? suggestRename(key, knownKeys)` — the
129+
* table is consulted first and wins outright.
129130
*
130131
* - `postal_code` -> `postalCode`, the example rendered above, is the
131132
* FALLBACK's own answer: scoring folds case and separators on both sides, so

‎packages/spec/src/data/define-seed-record-keys.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,26 @@ describe('defineSeed holds a `columns` key to the same column set (#25761)', ()
193193
expect(error.message).toContain('columns: `stauts` is not a field of `crm_lead`');
194194
});
195195
});
196+
197+
/**
198+
* `defineSeed` answers an unknown record key with the package's ONE rename rule
199+
* (`shared/rename-guess.ts`). It used to pass `max(2, len/3)` to
200+
* `findClosestMatches` itself, without the short-key screen, so a short key was
201+
* offered any column two unrelated edits away.
202+
*/
203+
describe('defineSeed — a short unknown key gets the shared rename rule', () => {
204+
it('a short key two unrelated edits from a column is offered nothing', () => {
205+
// `kind` → `id` is two deletions, inside the old budget of 2.
206+
const rows: Record<string, unknown>[] = [{ first_name: 'Gil', kind: 'web' }];
207+
const error = refusalOf(() => defineSeed(Lead, { externalId: 'first_name', records: rows }));
208+
expect(error.message).toContain('records[0]: `kind` is not a field of `crm_lead`.\n');
209+
expect(error.message).not.toContain('Did you mean');
210+
});
211+
212+
it('a genuine one-edit slip on a short key is still answered', () => {
213+
// An adjacent swap counts as one edit.
214+
const rows: Record<string, unknown>[] = [{ first_name: 'Hal', queeu: 'support' }];
215+
const error = refusalOf(() => defineSeed(Lead, { externalId: 'first_name', records: rows }));
216+
expect(error.message).toContain("records[0]: `queeu` is not a field of `crm_lead`. Did you mean 'queue'?");
217+
});
218+
});

‎packages/spec/src/data/field-value.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,3 +547,28 @@ describe('valueSchemaFor — stored form (field-zoo reality)', () => {
547547
});
548548
});
549549
});
550+
551+
/**
552+
* The value shapes answer an unknown key through `strictObject`, so they read
553+
* the package's ONE rename rule (`shared/rename-guess.ts`) — pinned here at
554+
* this door so the comment on `LocationValueSchema` that names the rule cannot
555+
* drift from what the door does.
556+
*/
557+
describe('LocationValueSchema — a short unknown key gets the shared rename rule', () => {
558+
const messageFor = (extra: Record<string, unknown>): string => {
559+
const result = LocationValueSchema.safeParse({ lat: 1, lng: 2, ...extra });
560+
if (result.success) throw new Error('expected LocationValueSchema to refuse the value');
561+
return result.error.issues.find((i) => i.code === 'unrecognized_keys')?.message ?? '';
562+
};
563+
564+
it('a short key two unrelated edits from a member is offered nothing', () => {
565+
// `lon` is two edits from both `lat` and `lng`, inside the old budget of 2.
566+
const m = messageFor({ lon: 3 });
567+
expect(m).toContain('Unrecognized key(s) on this location value: `lon`.');
568+
expect(m).not.toContain('Did you mean');
569+
});
570+
571+
it('a genuine one-edit slip on a short key is still answered', () => {
572+
expect(messageFor({ lgn: 3 })).toContain('Did you mean `lgn` → `lng`?');
573+
});
574+
});

0 commit comments

Comments
 (0)