From d890912b7ed2809696440a8830168bd7d4829fa6 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 09:18:24 +0000 Subject: [PATCH 1/2] docs(spec): knowledge-source-id-to-name names the underscore-led id exception The conversion's summary and comment said the rename rebuilds no index for every knowledge source. A source whose id begins with an underscore cannot keep it as name: it takes a new name, is built again under it, and the author drops its old index with dropSource. Say so, in the words the id tombstone and the knowledge-source-registration-governed entry use, and pin the case: the fixture carries an underscore-led id, a spec test reads the chain's rewrite and the parse's refusal and holds the three texts to one remedy, and a report pin shows os migrate meta printing the edit, its judge and the refusal. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L6bhgTJs4WrxwVhFtrMRYq --- ...owledge-source-underscore-rename-notice.md | 12 +++ .../migrate/meta.report-order.test.ts | 43 ++++++++ .../19/knowledge-source-id-to-name.test.ts | 98 +++++++++++++++++++ .../entries/19/knowledge-source-id-to-name.ts | 23 ++++- 4 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 .changeset/38217-knowledge-source-underscore-rename-notice.md create mode 100644 packages/spec/src/conversions/entries/19/knowledge-source-id-to-name.test.ts diff --git a/.changeset/38217-knowledge-source-underscore-rename-notice.md b/.changeset/38217-knowledge-source-underscore-rename-notice.md new file mode 100644 index 00000000000..8f2c6226bb2 --- /dev/null +++ b/.changeset/38217-knowledge-source-underscore-rename-notice.md @@ -0,0 +1,12 @@ +--- +'@objectstack/spec': patch +--- + +docs(spec): the `knowledge-source-id-to-name` conversion names the underscore-led id as the one source its rename rebuilds + +Clause-②: no +Metadata-protocol: none + +The conversion's summary said, for every knowledge source, that the value of `id` is kept as `name`, "so no index is rebuilt". That holds for every source but one class: a source whose `id` begins with an underscore. `name` refuses the underscore, so that source takes a new name, is built again under it, and its old index is dropped with `dropSource`, which the author runs; nothing drops it automatically. The summary (which reaches the upgrade guide and `os migrate meta --json`'s `specChanges`) and the conversion's comment now say so, in the words the `id` tombstone and the upgrade entry `knowledge-source-registration-governed` already use. + +What the conversion does is unchanged: it copies an underscore-led id as it is, so `os migrate meta --from 18` shows the edit, the upgrade entry that judges it beside it, and the refusal of that `name` with the instruction to rename it without the underscore. The conversion's fixture and new tests pin that case; a plain id still reads "no index is rebuilt". diff --git a/packages/cli/src/commands/migrate/meta.report-order.test.ts b/packages/cli/src/commands/migrate/meta.report-order.test.ts index 6738b335429..17c218e4121 100644 --- a/packages/cli/src/commands/migrate/meta.report-order.test.ts +++ b/packages/cli/src/commands/migrate/meta.report-order.test.ts @@ -626,3 +626,46 @@ describe('the notices proven absent leave ③ for one counting line, and --all l } }); }); + +/** + * #38217 — the one knowledge source the rename's "no index is rebuilt" does not + * cover. The conversion copies an id that begins with an underscore as it is, + * so the report shows the edit, the D3 entry that judges it beside it (whose + * replacement names the new name and `dropSource`), and in ① the refusal of + * that `name`. A plain id beside it converts with no refusal. + */ +describe('a knowledge source whose id begins with an underscore (#38217)', () => { + const ID_TO_NAME = 'knowledge-source-id-to-name'; + const KS_JUDGE = 'knowledge-source-registration-governed'; + const ks = (id: string) => ({ + id, + label: 'FAQ', + adapter: 'memory', + source: { kind: 'object', object: 'ks_faq', content: ['answer'] }, + }); + const KS_STACK = { + manifest: { id: 'com.example.ks-underscore', name: 'KS Underscore', version: '1.0.0', type: 'app' }, + objects: [{ name: 'ks_faq', label: 'FAQ', fields: { answer: { type: 'text', label: 'Answer' } } }], + knowledgeSources: [ks('_legacy_faq'), ks('support_faq')], + }; + + it('prints both edits, the judge beside them naming the remedy, and a refusal for the underscore-led name only', () => { + const { report, result, lines } = run(KS_STACK, MIGRATION_SUPPORT_FLOOR, TERMINUS); + + const edits = result.applied.filter((a) => a.conversionId === ID_TO_NAME); + expect(edits.map((a) => a.path)).toEqual(['knowledgeSources[0].name', 'knowledgeSources[1].name']); + + const judge = todoOf(result, KS_JUDGE); + const { last, length } = runOf(lines, ID_TO_NAME); + expect(length).toBe(2); + const review = reviewLine(judge, length); + expect(reviewsUnder(lines, last)).toContain(review); + expect(review).toContain('underscore takes a new name'); + expect(review).toContain('`dropSource({ source })`'); + + const ksRefusals = report.refusals.filter((r) => r.path[0] === 'knowledgeSources'); + expect(ksRefusals.map((r) => r.path.join('.'))).toEqual(['knowledgeSources.0.name']); + expect(ksRefusals[0]!.message).toContain('A leading "_" is reserved'); + for (const line of refusalLines({ ...report, refusals: ksRefusals })) expect(lines).toContain(line); + }); +}); diff --git a/packages/spec/src/conversions/entries/19/knowledge-source-id-to-name.test.ts b/packages/spec/src/conversions/entries/19/knowledge-source-id-to-name.test.ts new file mode 100644 index 00000000000..48c66304cb8 --- /dev/null +++ b/packages/spec/src/conversions/entries/19/knowledge-source-id-to-name.test.ts @@ -0,0 +1,98 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * `knowledge-source-id-to-name` (protocol 19, ADR-0161 K6) — the one class of + * source the rename's "no index is rebuilt" does not cover. + * + * The fixture pair (conversions.test.ts) pins the rewrite, the underscore-led + * id included. This file pins what that rewrite leaves: `renameKey` copies an + * underscore-led id as it is, the parse then refuses the `name` with the + * router-addressable prescription, and the three texts an upgrader reads — the + * conversion's `summary`, the `id` tombstone and the D3 entry + * `knowledge-source-registration-governed` that judges this conversion's edits + * — name the same exception and the same remedy (#38217, after #38050). + */ + +import { describe, expect, it } from 'vitest'; + +import { ALL_CONVERSIONS } from '../../registry.js'; +import { applyMetaMigrations } from '../../../migrations/chain.js'; +import { MIGRATIONS_BY_MAJOR } from '../../../migrations/registry.js'; +import { KnowledgeSourceSchema } from '../../../ai/knowledge-source.zod.js'; +import { ROUTER_ADDRESSABLE_NAME_MESSAGE } from '../../../kernel/address-grammar.js'; + +const ID = 'knowledge-source-id-to-name'; +const D3 = 'knowledge-source-registration-governed'; +const conversion = () => ALL_CONVERSIONS.find((c) => c.id === ID)!; +const d3 = () => MIGRATIONS_BY_MAJOR[19]!.semantic!.find((e) => e.id === D3)!; + +const source = (key: 'id' | 'name', value: string) => ({ + [key]: value, + label: 'FAQ', + adapter: 'memory', + source: { kind: 'object', object: 'faq', content: ['answer'] }, +}); + +const chain = (stack: Record) => applyMetaMigrations(structuredClone(stack), 18, 19); + +/** The `id` tombstone's prescription, read off the live parse rather than copied. */ +function tombstone(): string { + const parsed = KnowledgeSourceSchema.safeParse({ ...source('name', 'faq'), id: 'faq' }); + expect(parsed.success).toBe(false); + const issue = parsed.error!.issues.find((i) => i.path.join('.') === 'id'); + expect(issue, 'the `id` key is refused with its own prescription').toBeDefined(); + return issue!.message; +} + +describe(`${ID}: an id that begins with an underscore`, () => { + it('is copied as it is, to a `name` the parse then refuses with the router-addressable prescription', () => { + const result = chain({ knowledgeSources: [source('id', '_legacy_faq'), source('id', 'support_faq')] }); + expect(result.applied.filter((a) => a.conversionId === ID).map((a) => a.path)).toEqual([ + 'knowledgeSources[0].name', + 'knowledgeSources[1].name', + ]); + const [underscored, plain] = result.stack.knowledgeSources as Record[]; + // No new name is invented: only the author knows which one the source takes. + expect(underscored).toEqual(source('name', '_legacy_faq')); + expect(plain).toEqual(source('name', 'support_faq')); + + const refused = KnowledgeSourceSchema.safeParse(underscored); + expect(refused.success).toBe(false); + expect(refused.error!.issues.map((i) => [i.path.join('.'), i.message])).toEqual([ + ['name', ROUTER_ADDRESSABLE_NAME_MESSAGE], + ]); + expect(KnowledgeSourceSchema.safeParse(plain).success).toBe(true); + }); + + it('is judged by the D3 entry, which the chain lists beside the edit', () => { + expect(d3().conversionIds).toContain(ID); + const result = chain({ knowledgeSources: [source('id', '_legacy_faq')] }); + const absent = new Set(result.absentTodos.map((t) => `${t.toMajor}:${t.id}`)); + const listed = result.todos.filter((t) => !absent.has(`${t.toMajor}:${t.id}`)); + expect(listed.map((t) => t.id)).toContain(D3); + }); + + it('the summary keeps "no index is rebuilt" for every other source, and names the exception and its remedy', () => { + const { summary } = conversion(); + expect(summary).toContain('the value is unchanged, so no index is rebuilt, except for an id that begins with an underscore'); + expect(summary).toContain('takes a new name, is built again under it'); + expect(summary).toContain('dropped with `dropSource`, which the author runs'); + expect(summary).toContain(`\`${D3}\``); + }); + + it('the summary, the `id` tombstone and the D3 entry name the same exception and remedy', () => { + const texts = { + summary: conversion().summary, + tombstone: tombstone(), + replacement: d3().replacement, + }; + for (const [where, text] of Object.entries(texts)) { + expect(text, `${where} names the underscore`).toMatch(/\bunderscore\b/); + expect(text, `${where} says the source takes a new name`).toContain('takes a new name'); + expect(text, `${where} names the remedy`).toContain('`dropSource`'); + } + // The tombstone and the summary send the reader to the same D3 entry. + expect(texts.tombstone).toContain(`\`${D3}\``); + expect(texts.summary).toContain(`\`${D3}\``); + }); +}); diff --git a/packages/spec/src/conversions/entries/19/knowledge-source-id-to-name.ts b/packages/spec/src/conversions/entries/19/knowledge-source-id-to-name.ts index 8bc79db6d54..dd0012c4689 100644 --- a/packages/spec/src/conversions/entries/19/knowledge-source-id-to-name.ts +++ b/packages/spec/src/conversions/entries/19/knowledge-source-id-to-name.ts @@ -12,6 +12,17 @@ import { mapCollection, renameKey } from '../../walk.js'; * fingerprint, computed over values, stay as they are: the rename starts no * rebuild (K6 item 4). * + * **One exception: an `id` that begins with an underscore.** `renameKey` copies + * the value as it is, so `id: '_faq'` becomes `name: '_faq'`, and the parse + * then refuses that `name` (`ROUTER_ADDRESSABLE_NAME_PATTERN`; its message says + * to rename the item without the underscore). The conversion does not choose + * the new name: only the author knows it. Such a source takes a new name, is + * built again under it, and its old index is dropped with `dropSource`, which + * the author runs — nothing drops it automatically. That is what the `id` + * tombstone and the D3 entry `knowledge-source-registration-governed` (which + * judges this conversion's edits, `conversionIds`) teach, and `summary` says + * the same. + * * **Retired from the load path**: `KnowledgeSourceSchema` tombstones `id` with * the rename, so a live parse refuses it at every door, the registration in * code included. No stored row carries the key, because a source was never @@ -27,7 +38,10 @@ const knowledgeSourceIdToName: MetadataConversion = { surface: 'knowledge_source.id', summary: "knowledge source key 'id' → 'name' (a knowledge source is a metadata type from this major, and a metadata " - + 'item is identified by its name; the value is unchanged, so no index is rebuilt)', + + 'item is identified by its name; the value is unchanged, so no index is rebuilt, except for an id that ' + + 'begins with an underscore: `name` refuses the underscore, so that source takes a new name, is built again ' + + 'under it, and its old index is dropped with `dropSource`, which the author runs; the upgrade entry ' + + '`knowledge-source-registration-governed` says how)', apply(stack, emit) { return mapCollection(stack, 'knowledgeSources', (source, path) => { const renamed = renameKey(source, 'id', 'name'); @@ -44,15 +58,20 @@ const knowledgeSourceIdToName: MetadataConversion = { { id: 'support_articles', adapter: 'memory', source: { kind: 'object', object: 'article', content: ['title', 'body'] } }, // A source already on `name` keeps its identity (copy-on-write). { name: 'policy_clauses', adapter: 'memory', source: { kind: 'object', object: 'clause', content: ['text'] } }, + // The exception: an underscore-led id is copied as it is, to a `name` + // the parse refuses — the author picks the new name and drops the old + // index (see the jsdoc above). + { id: '_legacy_faq', adapter: 'memory', source: { kind: 'object', object: 'faq', content: ['answer'] } }, ], }, after: { knowledgeSources: [ { name: 'support_articles', adapter: 'memory', source: { kind: 'object', object: 'article', content: ['title', 'body'] } }, { name: 'policy_clauses', adapter: 'memory', source: { kind: 'object', object: 'clause', content: ['text'] } }, + { name: '_legacy_faq', adapter: 'memory', source: { kind: 'object', object: 'faq', content: ['answer'] } }, ], }, - expectedNotices: 1, + expectedNotices: 2, }, }; From 8de7f0f673081f752c178a4b723cd2249b01c670 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 09:53:18 +0000 Subject: [PATCH 2/2] test(cli): drop the added report pin; the PAIR pin already replays the fixture The report-order harness's PAIR pin replays every linked conversion's own fixture, which now carries the underscore-led id, and checks the knowledge-source-registration-governed review line beside its edits. The separate describe added nothing to that and, by editing the file, put the file's thirteen dynamic-import reaches under check:test-source-alias. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L6bhgTJs4WrxwVhFtrMRYq --- .../migrate/meta.report-order.test.ts | 43 ------------------- 1 file changed, 43 deletions(-) diff --git a/packages/cli/src/commands/migrate/meta.report-order.test.ts b/packages/cli/src/commands/migrate/meta.report-order.test.ts index 17c218e4121..6738b335429 100644 --- a/packages/cli/src/commands/migrate/meta.report-order.test.ts +++ b/packages/cli/src/commands/migrate/meta.report-order.test.ts @@ -626,46 +626,3 @@ describe('the notices proven absent leave ③ for one counting line, and --all l } }); }); - -/** - * #38217 — the one knowledge source the rename's "no index is rebuilt" does not - * cover. The conversion copies an id that begins with an underscore as it is, - * so the report shows the edit, the D3 entry that judges it beside it (whose - * replacement names the new name and `dropSource`), and in ① the refusal of - * that `name`. A plain id beside it converts with no refusal. - */ -describe('a knowledge source whose id begins with an underscore (#38217)', () => { - const ID_TO_NAME = 'knowledge-source-id-to-name'; - const KS_JUDGE = 'knowledge-source-registration-governed'; - const ks = (id: string) => ({ - id, - label: 'FAQ', - adapter: 'memory', - source: { kind: 'object', object: 'ks_faq', content: ['answer'] }, - }); - const KS_STACK = { - manifest: { id: 'com.example.ks-underscore', name: 'KS Underscore', version: '1.0.0', type: 'app' }, - objects: [{ name: 'ks_faq', label: 'FAQ', fields: { answer: { type: 'text', label: 'Answer' } } }], - knowledgeSources: [ks('_legacy_faq'), ks('support_faq')], - }; - - it('prints both edits, the judge beside them naming the remedy, and a refusal for the underscore-led name only', () => { - const { report, result, lines } = run(KS_STACK, MIGRATION_SUPPORT_FLOOR, TERMINUS); - - const edits = result.applied.filter((a) => a.conversionId === ID_TO_NAME); - expect(edits.map((a) => a.path)).toEqual(['knowledgeSources[0].name', 'knowledgeSources[1].name']); - - const judge = todoOf(result, KS_JUDGE); - const { last, length } = runOf(lines, ID_TO_NAME); - expect(length).toBe(2); - const review = reviewLine(judge, length); - expect(reviewsUnder(lines, last)).toContain(review); - expect(review).toContain('underscore takes a new name'); - expect(review).toContain('`dropSource({ source })`'); - - const ksRefusals = report.refusals.filter((r) => r.path[0] === 'knowledgeSources'); - expect(ksRefusals.map((r) => r.path.join('.'))).toEqual(['knowledgeSources.0.name']); - expect(ksRefusals[0]!.message).toContain('A leading "_" is reserved'); - for (const line of refusalLines({ ...report, refusals: ksRefusals })) expect(lines).toContain(line); - }); -});