Skip to content

Commit ba2d960

Browse files
docs(spec): knowledge-source-id-to-name names the underscore-led id as the one source its rename rebuilds (#38248)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuXRXWTshhd56mTNbwBRnBxD)_ Fixes #38217 Clause-②: no Metadata-protocol: none ## 维护者速读 - 是什么:从 18 升级时,迁移工具对“知识源 id 改名为 name”的说明原来写“值不变,所以不重建索引”。现在补上例外:id 以下划线开头的知识源要换新名字、在新名字下重建索引,旧索引由作者自己用 `dropSource` 删掉,不会自动删。 - 为什么:`name` 不允许下划线开头。PR #38050 已经在 `id` 的拒收提示和升级条目 `knowledge-source-registration-governed` 里讲了这个例外,只有转换本身的说明没讲。 - 行为变了吗:没有。转换照旧把 `_faq` 原样搬成 `name: '_faq'`,随后解析拒收并提示“去掉下划线改名”;只改了说明文字和注释,加了夹具和测试把这一例钉住。 - 要你做的:无。 ## What changes `packages/spec/src/conversions/entries/19/knowledge-source-id-to-name.ts`: - `summary` keeps "the value is unchanged, so no index is rebuilt" and adds the exception: an id that begins with an underscore, which `name` refuses, so that source takes a new name, is built again under it, and its old index is dropped with `dropSource`, which the author runs; it names the upgrade entry `knowledge-source-registration-governed` for how. The summary reaches the upgrade guide's conversion table and `os migrate meta --json`'s `specChanges.converted[].to`. - The jsdoc gains a paragraph saying what the conversion actually does with such an id: `renameKey` copies the value as it is (`id: '_faq'` → `name: '_faq'`), the parse then refuses that `name` with the router-addressable prescription (rename it without the underscore), and the conversion does not invent a new name, because only the author knows it. - The fixture carries an underscore-led id (`_legacy_faq` → `name: '_legacy_faq'`); `expectedNotices` 1 → 2. The conversion's behaviour is unchanged. New `packages/spec/src/conversions/entries/19/knowledge-source-id-to-name.test.ts`: - the step-19 chain rewrites an underscore-led id and a plain id alike, the underscore-led `name` is refused by `KnowledgeSourceSchema` with exactly `ROUTER_ADDRESSABLE_NAME_MESSAGE` at `name`, and the plain one parses; - the D3 entry lists this conversion in `conversionIds` and is listed (not proven absent) for such a stack; - the summary still reads "no index is rebuilt" and names the exception and `dropSource`; - the summary, the `id` tombstone (read off the live parse) and the D3 entry's `replacement` each name the underscore, "takes a new name" and `` `dropSource` ``, and the tombstone and summary name the same D3 entry. What `os migrate meta --from 18` prints for such a source is pinned by the report's existing PAIR pin (`packages/cli/src/commands/migrate/meta.report-order.test.ts`, "pairs every link the registry declares, replayed over the linked conversion's own fixture"), which replays this conversion's fixture, now carrying the underscore-led id, and checks that the D3 entry's review line (its `replacement` names the new name and `dropSource({ source })`) is printed beside the edits. That file is not edited here. One `patch` changeset for `@objectstack/spec`. ## Why #38217: the notice was true for every source but one class. PR #38050 taught that class on the tombstone and the upgrade entry; the conversion's own summary and comment did not. ## Verification Ablation: with the conversion file restored to `origin/main` and the new test kept, the two wording pins fail (`the summary keeps "no index is rebuilt"…` and `the summary, the id tombstone and the D3 entry…`); the rewrite and refusal pins pass, as they should, since the behaviour did not change. Restored: green. <details><summary>runs</summary> Head 8de7f0f. - `pnpm --filter @objectstack/spec build`, then `pnpm turbo run build --filter='@objectstack/cli^...'`: exit 0. - `packages/spec`: `npx vitest run --project local` (whole package): 912 files, 28855 tests passed (1 todo). - `packages/spec`: `tsc --noEmit` exit 0; `pnpm check:test-typecheck` OK; `pnpm check:generated`: every artifact up to date. - `packages/cli`: `npx vitest run src/commands/migrate/meta.report-order.test.ts`: 21/21 passed (the PAIR pin included) on the spec dist built from this branch. - `node scripts/pm/dispatch-gates.mjs --commands --changed`: 81 derived at this head, all run (on the first head, whose diff was a superset): 79 exit 0 (`pnpm check:test-source-alias` re-run at this head); 2 exit 3 (PREREQUISITE NOT MET), so NOT MEASURED locally and left to CI: `node scripts/check-plugin-teardown-shape.mjs --self-test` (its fixture commit is out of this shallow clone), `pnpm check:dual-build-cjs-loads` (reads every package's `dist/`; only the CLI closure is built here). `check:test-source-alias` was red on the first head, over the dropped CLI pin. - `node scripts/check-commit-card-trailers.mjs --range origin/main..HEAD`: OK, both commits. - `npx eslint` on the changed files: exit 0. </details> ## Acceptance notes - A separate report pin in `meta.report-order.test.ts` was written and dropped in the second commit: it duplicated the PAIR pin above, and editing that file puts its thirteen pre-existing dynamic-import reaches under `check:test-source-alias`. The diff stays inside the claim's file surface. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (prose, fixture and tests only) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; eslint on the changed files passes (the full `pnpm lint` was not run locally; CI runs it). - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. (branch `claude/project-thread-r6cjhf` is the harness-assigned name) - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: `check:generated` reports every artifact up to date (no export or schema changed). - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English (the 维护者速读 block is the maintainer summary). - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L6bhgTJs4WrxwVhFtrMRYq --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent d994002 commit ba2d960

3 files changed

Lines changed: 131 additions & 2 deletions

File tree

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+
docs(spec): the `knowledge-source-id-to-name` conversion names the underscore-led id as the one source its rename rebuilds
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
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.
11+
12+
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".
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* `knowledge-source-id-to-name` (protocol 19, ADR-0161 K6) — the one class of
5+
* source the rename's "no index is rebuilt" does not cover.
6+
*
7+
* The fixture pair (conversions.test.ts) pins the rewrite, the underscore-led
8+
* id included. This file pins what that rewrite leaves: `renameKey` copies an
9+
* underscore-led id as it is, the parse then refuses the `name` with the
10+
* router-addressable prescription, and the three texts an upgrader reads — the
11+
* conversion's `summary`, the `id` tombstone and the D3 entry
12+
* `knowledge-source-registration-governed` that judges this conversion's edits
13+
* — name the same exception and the same remedy (#38217, after #38050).
14+
*/
15+
16+
import { describe, expect, it } from 'vitest';
17+
18+
import { ALL_CONVERSIONS } from '../../registry.js';
19+
import { applyMetaMigrations } from '../../../migrations/chain.js';
20+
import { MIGRATIONS_BY_MAJOR } from '../../../migrations/registry.js';
21+
import { KnowledgeSourceSchema } from '../../../ai/knowledge-source.zod.js';
22+
import { ROUTER_ADDRESSABLE_NAME_MESSAGE } from '../../../kernel/address-grammar.js';
23+
24+
const ID = 'knowledge-source-id-to-name';
25+
const D3 = 'knowledge-source-registration-governed';
26+
const conversion = () => ALL_CONVERSIONS.find((c) => c.id === ID)!;
27+
const d3 = () => MIGRATIONS_BY_MAJOR[19]!.semantic!.find((e) => e.id === D3)!;
28+
29+
const source = (key: 'id' | 'name', value: string) => ({
30+
[key]: value,
31+
label: 'FAQ',
32+
adapter: 'memory',
33+
source: { kind: 'object', object: 'faq', content: ['answer'] },
34+
});
35+
36+
const chain = (stack: Record<string, unknown>) => applyMetaMigrations(structuredClone(stack), 18, 19);
37+
38+
/** The `id` tombstone's prescription, read off the live parse rather than copied. */
39+
function tombstone(): string {
40+
const parsed = KnowledgeSourceSchema.safeParse({ ...source('name', 'faq'), id: 'faq' });
41+
expect(parsed.success).toBe(false);
42+
const issue = parsed.error!.issues.find((i) => i.path.join('.') === 'id');
43+
expect(issue, 'the `id` key is refused with its own prescription').toBeDefined();
44+
return issue!.message;
45+
}
46+
47+
describe(`${ID}: an id that begins with an underscore`, () => {
48+
it('is copied as it is, to a `name` the parse then refuses with the router-addressable prescription', () => {
49+
const result = chain({ knowledgeSources: [source('id', '_legacy_faq'), source('id', 'support_faq')] });
50+
expect(result.applied.filter((a) => a.conversionId === ID).map((a) => a.path)).toEqual([
51+
'knowledgeSources[0].name',
52+
'knowledgeSources[1].name',
53+
]);
54+
const [underscored, plain] = result.stack.knowledgeSources as Record<string, unknown>[];
55+
// No new name is invented: only the author knows which one the source takes.
56+
expect(underscored).toEqual(source('name', '_legacy_faq'));
57+
expect(plain).toEqual(source('name', 'support_faq'));
58+
59+
const refused = KnowledgeSourceSchema.safeParse(underscored);
60+
expect(refused.success).toBe(false);
61+
expect(refused.error!.issues.map((i) => [i.path.join('.'), i.message])).toEqual([
62+
['name', ROUTER_ADDRESSABLE_NAME_MESSAGE],
63+
]);
64+
expect(KnowledgeSourceSchema.safeParse(plain).success).toBe(true);
65+
});
66+
67+
it('is judged by the D3 entry, which the chain lists beside the edit', () => {
68+
expect(d3().conversionIds).toContain(ID);
69+
const result = chain({ knowledgeSources: [source('id', '_legacy_faq')] });
70+
const absent = new Set(result.absentTodos.map((t) => `${t.toMajor}:${t.id}`));
71+
const listed = result.todos.filter((t) => !absent.has(`${t.toMajor}:${t.id}`));
72+
expect(listed.map((t) => t.id)).toContain(D3);
73+
});
74+
75+
it('the summary keeps "no index is rebuilt" for every other source, and names the exception and its remedy', () => {
76+
const { summary } = conversion();
77+
expect(summary).toContain('the value is unchanged, so no index is rebuilt, except for an id that begins with an underscore');
78+
expect(summary).toContain('takes a new name, is built again under it');
79+
expect(summary).toContain('dropped with `dropSource`, which the author runs');
80+
expect(summary).toContain(`\`${D3}\``);
81+
});
82+
83+
it('the summary, the `id` tombstone and the D3 entry name the same exception and remedy', () => {
84+
const texts = {
85+
summary: conversion().summary,
86+
tombstone: tombstone(),
87+
replacement: d3().replacement,
88+
};
89+
for (const [where, text] of Object.entries(texts)) {
90+
expect(text, `${where} names the underscore`).toMatch(/\bunderscore\b/);
91+
expect(text, `${where} says the source takes a new name`).toContain('takes a new name');
92+
expect(text, `${where} names the remedy`).toContain('`dropSource`');
93+
}
94+
// The tombstone and the summary send the reader to the same D3 entry.
95+
expect(texts.tombstone).toContain(`\`${D3}\``);
96+
expect(texts.summary).toContain(`\`${D3}\``);
97+
});
98+
});

‎packages/spec/src/conversions/entries/19/knowledge-source-id-to-name.ts‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ import { mapCollection, renameKey } from '../../walk.js';
1212
* fingerprint, computed over values, stay as they are: the rename starts no
1313
* rebuild (K6 item 4).
1414
*
15+
* **One exception: an `id` that begins with an underscore.** `renameKey` copies
16+
* the value as it is, so `id: '_faq'` becomes `name: '_faq'`, and the parse
17+
* then refuses that `name` (`ROUTER_ADDRESSABLE_NAME_PATTERN`; its message says
18+
* to rename the item without the underscore). The conversion does not choose
19+
* the new name: only the author knows it. Such a source takes a new name, is
20+
* built again under it, and its old index is dropped with `dropSource`, which
21+
* the author runs — nothing drops it automatically. That is what the `id`
22+
* tombstone and the D3 entry `knowledge-source-registration-governed` (which
23+
* judges this conversion's edits, `conversionIds`) teach, and `summary` says
24+
* the same.
25+
*
1526
* **Retired from the load path**: `KnowledgeSourceSchema` tombstones `id` with
1627
* the rename, so a live parse refuses it at every door, the registration in
1728
* code included. No stored row carries the key, because a source was never
@@ -27,7 +38,10 @@ const knowledgeSourceIdToName: MetadataConversion = {
2738
surface: 'knowledge_source.id',
2839
summary:
2940
"knowledge source key 'id' → 'name' (a knowledge source is a metadata type from this major, and a metadata "
30-
+ 'item is identified by its name; the value is unchanged, so no index is rebuilt)',
41+
+ 'item is identified by its name; the value is unchanged, so no index is rebuilt, except for an id that '
42+
+ 'begins with an underscore: `name` refuses the underscore, so that source takes a new name, is built again '
43+
+ 'under it, and its old index is dropped with `dropSource`, which the author runs; the upgrade entry '
44+
+ '`knowledge-source-registration-governed` says how)',
3145
apply(stack, emit) {
3246
return mapCollection(stack, 'knowledgeSources', (source, path) => {
3347
const renamed = renameKey(source, 'id', 'name');
@@ -44,15 +58,20 @@ const knowledgeSourceIdToName: MetadataConversion = {
4458
{ id: 'support_articles', adapter: 'memory', source: { kind: 'object', object: 'article', content: ['title', 'body'] } },
4559
// A source already on `name` keeps its identity (copy-on-write).
4660
{ name: 'policy_clauses', adapter: 'memory', source: { kind: 'object', object: 'clause', content: ['text'] } },
61+
// The exception: an underscore-led id is copied as it is, to a `name`
62+
// the parse refuses — the author picks the new name and drops the old
63+
// index (see the jsdoc above).
64+
{ id: '_legacy_faq', adapter: 'memory', source: { kind: 'object', object: 'faq', content: ['answer'] } },
4765
],
4866
},
4967
after: {
5068
knowledgeSources: [
5169
{ name: 'support_articles', adapter: 'memory', source: { kind: 'object', object: 'article', content: ['title', 'body'] } },
5270
{ name: 'policy_clauses', adapter: 'memory', source: { kind: 'object', object: 'clause', content: ['text'] } },
71+
{ name: '_legacy_faq', adapter: 'memory', source: { kind: 'object', object: 'faq', content: ['answer'] } },
5372
],
5473
},
55-
expectedNotices: 1,
74+
expectedNotices: 2,
5675
},
5776
};
5877

0 commit comments

Comments
 (0)