Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/38217-knowledge-source-underscore-rename-notice.md
Original file line number Diff line number Diff line change
@@ -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".
Original file line number Diff line number Diff line change
@@ -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<string, unknown>) => 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<string, unknown>[];
// 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}\``);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand All @@ -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,
},
};

Expand Down
Loading