Skip to content

Commit a7f7f3f

Browse files
fix(lint)!: knowledge-source review follow-ups: absent platform objects refused at publish, ai_context accepts id, search refusal names list (#38038)
repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP Fixes #38019 Clause-②: no (narrowing) Metadata-protocol: narrowed Skills-docs: follow-up #37310 ## 维护者速读 - 用户能看到什么变化:写知识源的作者在保存被拒时,看到的原因和修法改为「开放 list、不要关掉 searchable」;发布一个指向平台不存在的系统对象的知识源会直接被拒;AI 上下文里写 `id` 不再被提示字段不存在;升级指南只对用到知识源的应用列出相关条目。 - 为什么做:知识库检索这条线(PR 37971 知识源校验)评审留下的四个收尾问题。 - 出错会怎样:最坏是某个发布被多拒或提示文字不准,作者按提示改对象名即可;本改动可直接回退。 - 要你做什么:无。 **Was stacked on PR #37971**, which merged as 3550665. `main` (f72f335) is merged here (2634eef, no rebase); the diff against `main` is now this card's 11 files, +150/−24. The add/add conflicts the squash left were resolved to this branch's side for `validate-knowledge-source.ts`, its test and the step-19 entry (main's blob equals the stack base 8301509 for each), and `rule-explanations.ts` merged three-way clean against that base. ## What changes 1. **N4, the save-door wording** (`service-knowledge`). The `object-api-not-served` refusal of `admitAuthoredSource` now uses the wording PR #37971 settled for its S2 fix: the cause is `enable.apiEnabled` false, an `enable.apiMethods` list that does not grant `list` (from which search derives), or `list` beside `enable.searchable: false`; the fix is to keep `apiEnabled` true and include `list` with `searchable` not false, or index another object. It no longer tells the author to grant `search`, a retired list value the parse strips. The admission module's gate-2 header says the same. 2. **`ai_context` and `id`** (`validate-ai-context.ts`). Field existence (`fields`, a related list's `fields`, `where`, `orderBy`, `body.field`) is now asked through `injectedColumnsFor`, as `system-fields.ts` prescribes for an existence check, beside the effective field map. `id` (driver-provisioned, absent from `injectedColumnDefsFor` by contract) is no longer `ai-context-field-unknown`; a `body.field` of `id` is reported as not long text. The type questions (body type, sortability, links) still read the definition map. 3. **N3, a platform name at the door** (`validate-knowledge-source.ts`). Against the whole collection the host serves (no package scope at publish), an absent platform-prefixed name and an absent known platform name (`sys_user`) are now `knowledge-source-object-unknown` errors, as an unprefixed name already was. The CLI arms stay: a prefixed name no known package registers warns, a known platform name the stack does not carry is not judged. Under a stated closure nothing changes. The `os explain` entry and the upgrade entry's `surface` say which arm is the CLI's. 4. **N6, `relevantWhen`** (spec). `knowledge-source-publish-refuses-missing-references-and-gated-objects` carries `relevantWhen: { kind: 'stack-declares', keys: ['knowledgeSources'] }`; `semantic-relevance.test.ts`'s reviewed table gains the row (30 entries, 3 of protocol 19: `main` had meanwhile added `19:action-locations-page-parts-retired`, so the merge corrected the counts). The four sibling `19.knowledge-source-*` entries are deliberately left without one: each names a surface outside the stack (a source registered in code through `KnowledgeServicePlugin({ sources })` / `registerSource`, or host calls to `indexDocument`), and `SemanticMigration.relevantWhen`'s contract says to omit the question unless the surface lives ONLY under the keys it names, so a stack with no `knowledgeSources` is not proven clear of them. Declaration: item 3 narrows the publish accept set (a source over an absent platform object was published with a warning or unjudged, and is now refused 422), hence `no (narrowing)` and `Metadata-protocol: narrowed` (a value refused). Item 2 widens no published accept set. Under `--strict`, where a warning fails the run, a pack naming `id` is now accepted; the refusal it removes is one the published contract already denies, since `id` exists on every object: `packages/spec/src/data/injected-system-columns.ts` names it the primary key the driver provisions on every physical table (`PRIMARY_KEY_COLUMN = 'id'`, around lines 74-79), and `packages/lint/src/system-fields.ts` reports it from `injectedColumnsFor`, the existence helper (its note near line 100 says `injectedColumnDefsFor` leaves it out by design). Removing a refusal the contract already denies, with that text cited, reads as `no`; so the PR stays `Clause-②: no (narrowing)`, the narrowing being item 3 alone. The claim carried `Metadata-protocol: none`; the dispatch left the kind to the diff, and AGENTS.md's definition ("a value refused ... is `narrowed`") fits item 3. ## Tests - `packages/services/service-knowledge/src/__tests__/knowledge-source-admission.test.ts`: a `list` + `searchable: false` row in the refusal table; a pin that the not-served refusal names `does not grant \`list\`` and `include \`list\` with \`enable.searchable\` not false`, and never prescribes a `search` grant, for all three not-served shapes. - `packages/lint/src/validate-ai-context.test.ts`: `id` in `fields`, related `fields`, `where` and `orderBy` is clean, through the rule and through `runAuthoringRules('validate', …)`; a control misspelling is still reported; `body.field: 'id'` is not long text, never unknown. - `packages/lint/src/validate-knowledge-source.test.ts`: at the door with no scope, `sys_kb_article` (prefixed, unregistered) and `sys_user` (known platform) absent from the served collection are refused as errors; the CLI arms stay (warning, not judged); a control with the platform object served publishes clean. - `packages/spec/src/migrations/semantic-relevance.test.ts`: the enumeration table and its counts. Local runs at head `4cdbceedc2`, each under `scripts/pm/os-verify-lock.sh` (verdict `command-exit 0`): - `@objectstack/lint`: 244 test files, 9859 tests passed. - `@objectstack/service-knowledge`: 19 files, 648 tests passed. - `@objectstack/spec` `src/migrations`: 5 files, 207 tests passed. - Typecheck of lint, service-knowledge and spec: clean. - Ablation (at 80a26df, the same blobs): with the four fixed files restored from 8301509, lint 3 failed (the two `id` pins and the whole-collection platform pin), service-knowledge 1 failed (the wording pin), spec 2 failed (the enumeration table and CHAIN `absentTodos`); restored, all green. - Dogfood battery (the `(narrowing)` arm): 490 files passed, 3 skipped; 4144 tests passed, 68 skipped; no failures. <details><summary>Gates at head 4cdbcee</summary> - `dispatch-gates --commands`: 98 commands derived over the 11 paths, all 98 run, each exit 0 (two first answered "not built yet" inside the lock job, `migrate-meta-engine-guidance` vitest and `check:dual-build-cjs-loads`, and exit 0 once the dogfood closure build had built their packages). - `node scripts/check-adr-0087-registration.mjs --base origin/main`: exit 0, reading the marker as `not-required (already-registered)`. - `node scripts/pm/overlap-check.mjs`: VERDICT clean exit 0 against origin/main 5b8ca36, #38107 and #38060. </details> ## Acceptance notes - The ADR-0087 marker is now `not-required (already-registered knowledge-source-publish-refuses-missing-references-and-gated-objects)`: #37971 registered the entry and this PR only edits it (commit 4cdbcee). - Full dogfood ran on the final head `4cdbceedc2` and is green (above). - Follow-up #38041 carries N1 (a known platform name absent under a stated closure, including the question of `cloud_` and `ai_` names), N2 (the rule header and explain text on which platform arm applies where) and N6 (the stack/manifest wording at a write that names no package). ## Verification Read first: `packages/lint/src/validate-knowledge-source.ts` (the `whole` condition on the two platform rungs, the one behavioural narrowing), `packages/lint/src/validate-ai-context.ts` (`fieldExists` and the `body.field` branch), `packages/services/service-knowledge/src/knowledge-service.ts` (the `object-api-not-served` text). Two minutes: `pnpm --filter @objectstack/lint exec vitest run --maxWorkers=2 src/validate-knowledge-source.test.ts src/validate-ai-context.test.ts` after building lint's closure: all green, including "against the whole collection, an absent platform name, prefixed or known, is refused as an unprefixed one is". 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6ce1975 commit a7f7f3f

11 files changed

Lines changed: 150 additions & 24 deletions
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
'@objectstack/lint': minor
3+
'@objectstack/service-knowledge': patch
4+
'@objectstack/spec': patch
5+
---
6+
7+
fix(lint)!: a knowledge source naming an absent platform object is refused at publish; `ai_context` accepts `id`; the save door's search refusal names `list`
8+
9+
Clause-②: no (narrowing)
10+
Metadata-protocol: narrowed
11+
Skills-docs: follow-up #37310
12+
13+
<!-- adr-0087: not-required (already-registered knowledge-source-publish-refuses-missing-references-and-gated-objects) the entry that registered this rule's publish refusal landed with the rule itself; this change extends its surface to an absent platform object name judged against the whole collection the host serves, says the platform-name warning is the command line's, and lists the entry only for a stack that declares knowledge sources. No id is added and no key is added, removed or re-shaped. -->
14+
15+
ADR-0161 K4, row 4.
16+
17+
**BREAKING** for the publish of a knowledge source whose `source.object` is a platform name the host does not serve: when the publish gate judges the source against the whole collection the host serves (a write that names no package), a platform-prefixed name no package registers there, and a known platform object (`sys_user`) the host does not serve, are now `knowledge-source-object-unknown` errors (422), as an unprefixed name already was. Before, the first was a warning and the second was not judged. FROM a source over such an object TO a source over an object the host serves: name the object by its full name, or install the package that registers it. On the command line nothing changes: a platform-prefixed name no known package registers stays a warning, and a known platform object the stack does not carry is not judged.
18+
19+
- `ai_context`: a field named `id` (in `fields`, a related list's `fields`, `where` or `orderBy`) is no longer reported as `ai-context-field-unknown`. The driver provisions it, so it exists on every object; existence is now asked through the same column set the other existence rules use. A `body.field` of `id` is reported as not long text, never as unknown.
20+
- `@objectstack/service-knowledge`: the save refusal for an object the API does not serve for search names the cause and fix in the words of `knowledge-source-object-not-searchable`: `enable.apiEnabled` false, an `enable.apiMethods` list that does not grant `list` (from which search derives), or `list` beside `enable.searchable: false`; the fix is to include `list` with `enable.searchable` not false. It no longer tells the author to grant `search`, a retired list value the parse strips.
21+
- `@objectstack/spec`: the upgrade entry `knowledge-source-publish-refuses-missing-references-and-gated-objects` is listed by `os migrate meta` only for a stack that declares `knowledgeSources` (`--all` still lists it), and its surface states that the platform-name warning is the CLI's.

‎packages/lint/src/rule-explanations.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6236,9 +6236,11 @@ const KNOWLEDGE_SOURCE_OBJECT_UNKNOWN_EXPLANATION: RuleExplanation = {
62366236
'An object nothing defines has no records, so the source is built empty and every search over it ' +
62376237
'answers nothing, with no error anywhere.',
62386238
'Defined means an object of this stack, of a package in the same artifact (`packages[]`), or, at the ' +
6239-
'publish gate, an object the host serves. A platform object a known package registers (`sys_user`) is ' +
6240-
'not judged when the stack does not carry its definition. A name with a platform prefix that no known ' +
6241-
'package registers is a warning, because a third-party package may still provide it. When the publish ' +
6239+
'publish gate, an object the host serves. On the command line a platform object a known package ' +
6240+
'registers (`sys_user`) is not judged when the stack does not carry its definition, and a name with a ' +
6241+
'platform prefix that no known package registers is a warning, because a third-party package may still ' +
6242+
'provide it. At the publish gate with no package stated, the source is judged against every object the ' +
6243+
'host serves, so either one is an error there when the host does not serve it. When the publish ' +
62426244
'gate states the package\'s closure (the package, the packages its manifest declares in ' +
62436245
'`dependencies`, and platform objects), an object outside it is reported with the remedy to declare the ' +
62446246
'dependency.',

‎packages/lint/src/validate-ai-context.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,33 @@ describe('validateAiContext — ADR-0160 D1 author defects', () => {
186186
expect(validateAiContext(stack)).toEqual([]);
187187
});
188188

189+
// `id` is provisioned by the driver, not the injection pass, so no injected
190+
// definition carries it; existence resolves through `injectedColumnsFor`.
191+
it('`id` is no unknown field, in fields, related fields, where and orderBy', () => {
192+
const stack = {
193+
objects,
194+
aiContexts: [pack({
195+
fields: ['title', 'id'],
196+
related: [{ object: 'policy_revision', fields: ['version', 'id'], where: { id: 'rev_1' }, orderBy: [{ field: 'id' }] }],
197+
})],
198+
};
199+
expect(objects.flatMap((o) => Object.keys(o.fields))).not.toContain('id');
200+
expect(validateAiContext(stack)).toEqual([]);
201+
// Through the CLI tier too (`os validate`).
202+
expect(runAuthoringRules('validate', { parsed: stack, normalized: stack }).filter((f) => f.rule.startsWith('ai-context-')))
203+
.toEqual([]);
204+
// CONTROL: a misspelling beside it is still reported.
205+
expect(rulesOf({ objects, aiContexts: [pack({ fields: ['idd'], related: undefined })] })).toEqual([
206+
[AI_CONTEXT_FIELD_UNKNOWN, 'aiContexts[0].fields[0]'],
207+
]);
208+
});
209+
210+
it('a body naming `id` exists and is judged not long text, never unknown', () => {
211+
expect(rulesOf({ objects, aiContexts: [pack({ body: { field: 'id' } })] })).toEqual([
212+
[AI_CONTEXT_BODY_NOT_LONG_TEXT, 'aiContexts[0].body.field'],
213+
]);
214+
});
215+
189216
it('a column the platform does not inject on the object is still unknown: owner_id under ownership org', () => {
190217
const orgOwned = objects.map((o) => (o.name === 'policy' || o.name === 'policy_revision' ? { ...o, ownership: 'org' } : o));
191218
const stack = {

‎packages/lint/src/validate-ai-context.ts‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import { REFERENCE_VALUE_TYPES, referenceTargetOf } from '@objectstack/spec/data
6363
import { closureDependencyRemedy, recordsOf } from './object-graph.js';
6464
import {
6565
injectedColumnDefsFor,
66+
injectedColumnsFor,
6667
unprovisionedAnchorFix,
6768
unprovisionedAnchorVerdict,
6869
unprovisionedInjectedColumnsFor,
@@ -103,6 +104,12 @@ const strings = (v: unknown): string[] => (Array.isArray(v) ? v.filter((x): x is
103104
* the injected one of its name. `get_record_context` judges a pack against
104105
* the published definition, which carries those columns, and reads them: a
105106
* verdict over the declared fields alone warns on a name the tool serves.
107+
*
108+
* This map answers what a field IS (its type, its reference target). Whether
109+
* a name EXISTS is asked through {@link injectedColumnsFor} as well
110+
* (`fieldExists` in the rule), as `system-fields.ts` prescribes for an
111+
* existence check: `id`, which the driver provisions, has no definition table
112+
* and so is absent from this map, yet the pack reads it.
106113
*/
107114
function fieldMapOf(object: AnyRec): Map<string, AnyRec> | undefined {
108115
const raw = object.fields;
@@ -139,6 +146,18 @@ export function validateAiContext(
139146
// (the field map above) and provenance are separate questions: a name this
140147
// set holds resolves, and is judged here instead of as unknown.
141148
const anchorsOf = new Map<string, ReadonlySet<string>>();
149+
/**
150+
* Does `name` exist on `object`: a field of its effective map, or a column
151+
* addressable without a declaration ({@link injectedColumnsFor}, which also
152+
* holds the driver's `id`).
153+
*/
154+
const addressable = new Map<string, ReadonlySet<string>>();
155+
const fieldExists = (object: string, fields: Map<string, AnyRec>, name: string): boolean => {
156+
if (fields.has(name)) return true;
157+
let names = addressable.get(object);
158+
if (!names) addressable.set(object, (names = injectedColumnsFor(objects.get(object))));
159+
return names.has(name);
160+
};
142161
const unprovisionedOf = (object: string): ReadonlySet<string> => {
143162
let anchors = anchorsOf.get(object);
144163
if (!anchors) anchorsOf.set(object, (anchors = unprovisionedInjectedColumnsFor(objects.get(object))));
@@ -196,7 +215,7 @@ export function validateAiContext(
196215
};
197216
const unknownFields = (names: string[], fields: Map<string, AnyRec>, object: string, where: string, path: string) => {
198217
names.forEach((name, k) => {
199-
if (fields.has(name)) {
218+
if (fieldExists(object, fields, name)) {
200219
if (unprovisionedOf(object).has(name)) {
201220
unprovisioned(object, name, where, `${path}[${k}]`, `names field '${name}'`, 'the pack reads it empty on every record');
202221
}
@@ -220,7 +239,7 @@ export function validateAiContext(
220239
const bodyField = str(body?.field);
221240
if (bodyField) {
222241
const def = rootFields.get(bodyField);
223-
if (!def) {
242+
if (!fieldExists(root, rootFields, bodyField)) {
224243
out.push({
225244
severity: 'warning',
226245
rule: AI_CONTEXT_FIELD_UNKNOWN,
@@ -229,14 +248,14 @@ export function validateAiContext(
229248
message: `\`body.field\` names '${bodyField}', which object '${root}' does not define, so the pack carries no body`,
230249
hint: `Name a long-text field of '${root}' (check the spelling)`,
231250
});
232-
} else if (!(AI_CONTEXT_BODY_FIELD_TYPES as readonly string[]).includes(str(def.type))) {
251+
} else if (!(AI_CONTEXT_BODY_FIELD_TYPES as readonly string[]).includes(str(def?.type))) {
233252
out.push({
234253
severity: 'warning',
235254
rule: AI_CONTEXT_BODY_NOT_LONG_TEXT,
236255
where: `${at} · body`,
237256
path: `aiContexts[${i}].body.field`,
238257
message:
239-
`\`body.field\` names '${bodyField}', a ${str(def.type) || 'untyped'} field; a body is a long-text ` +
258+
`\`body.field\` names '${bodyField}', a ${str(def?.type) || 'untyped'} field; a body is a long-text ` +
240259
`field (${AI_CONTEXT_BODY_FIELD_TYPES.join(', ')}), so the pack carries no body`,
241260
hint: `Name a long-text field of '${root}' as the body, or list '${bodyField}' in \`fields\` instead`,
242261
});
@@ -275,7 +294,7 @@ export function validateAiContext(
275294
};
276295
const noRows = 'a condition on it can never match a real value and the list reads no rows';
277296
for (const name of aiContextWhereFields(entry.where)) {
278-
if (!childFields.has(name)) listLeftOut(name, 'where', `${path}.where`);
297+
if (!fieldExists(child, childFields, name)) listLeftOut(name, 'where', `${path}.where`);
279298
else if (unprovisionedOf(child).has(name)) unprovisioned(child, name, where, `${path}.where`, `\`where\` names field '${name}'`, noRows);
280299
}
281300
const orderBy = Array.isArray(entry.orderBy) ? (entry.orderBy as unknown[]) : [];
@@ -284,7 +303,7 @@ export function validateAiContext(
284303
orderBy.forEach((node, k) => {
285304
const name = node && typeof node === 'object' ? str((node as AnyRec).field) : '';
286305
if (!name) return;
287-
if (!childFields.has(name)) {
306+
if (!fieldExists(child, childFields, name)) {
288307
listLeftOut(name, 'orderBy', `${path}.orderBy[${k}].field`);
289308
return;
290309
}

‎packages/lint/src/validate-knowledge-source.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,28 @@ describe('validateKnowledgeSource on the runtime publish door', () => {
253253
.map((f) => [f.rule, f.severity])).toEqual([[KNOWLEDGE_SOURCE_OBJECT_UNKNOWN, 'error']]);
254254
});
255255

256+
it('against the whole collection, an absent platform name, prefixed or known, is refused as an unprefixed one is', () => {
257+
for (const object of ['sys_kb_article', 'sys_user']) {
258+
const item = kbSource({ object, content: ['body'], metadataFields: [] });
259+
const verdict = runRuntimeAuthoringRules({ type: 'knowledge_source', item, context: { objects } });
260+
expect(verdict.errors.map((f) => [f.rule, f.severity, f.path]), object)
261+
.toEqual([[KNOWLEDGE_SOURCE_OBJECT_UNKNOWN, 'error', 'knowledgeSources[0].source.object']]);
262+
expect(verdict.errors[0]!.message, object).toContain(`'${object}', which this stack does not define`);
263+
expect(verdict.advisories.filter((f) => KS_RULE.test(f.rule)), object).toEqual([]);
264+
}
265+
// The CLI arms stay: a prefixed name no known package registers warns, a known platform name is not judged.
266+
expect(atValidate(kbSource({ object: 'sys_kb_article', content: ['body'], metadataFields: [] })).map((f) => f.severity))
267+
.toEqual(['warning']);
268+
expect(atValidate(kbSource({ object: 'sys_user', content: ['name'], metadataFields: [] }))).toEqual([]);
269+
// CONTROL: a served platform object is no unknown object at the door.
270+
const served = [...objects, { name: 'sys_kb_article', enable: { aiReadable: true }, fields: { body: { type: 'text' } } }];
271+
expect(runRuntimeAuthoringRules({
272+
type: 'knowledge_source',
273+
item: kbSource({ object: 'sys_kb_article', content: ['body'], metadataFields: [] }),
274+
context: { objects: served },
275+
}).errors).toEqual([]);
276+
});
277+
256278
it('an empty whole collection at the door is no universe, and judges no object', () => {
257279
const stack = { objects: [], knowledgeSources: [kbSource({ object: 'faq_entry' })] };
258280
expect(validateKnowledgeSource(stack, { wholeCollection: true })).toEqual([]);

‎packages/lint/src/validate-knowledge-source.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@
3434
* `validateObjectReferences` resolves object names by also applies: a
3535
* platform object a known package registers is not judged when the stack
3636
* does not carry it (its declaration is not in hand), and a
37-
* platform-prefixed name no known package registers is a `warning`. An
38-
* empty whole collection at the door is no universe, and judges nothing.
37+
* platform-prefixed name no known package registers is a `warning`; both
38+
* on the CLI and under a closure. Against the whole collection at the door
39+
* either one is absent from every package the host serves, so it is an
40+
* `error` as an unprefixed name is. An empty whole collection at the door
41+
* is no universe, and judges nothing.
3942
* - `knowledge-source-field-unknown` (`error`): a `source.content` or
4043
* `source.metadataFields` member names no field of the object: neither one
4144
* it declares (its own stack's extensions folded in, `objectsAsServed`) nor
@@ -193,6 +196,10 @@ export function validateKnowledgeSource(
193196
// registry read), as the list-view and form members read it: no object
194197
// verdict is drawn from it.
195198
const noUniverse = !closure && options.wholeCollection === true && objects.size === 0;
199+
// The whole collection the host serves holds every platform object a
200+
// package registers there, so an absent platform name, known or merely
201+
// prefixed, exists nowhere: judged as an unprefixed name is (K4).
202+
const whole = !closure && options.wholeCollection === true;
196203
const unseen = atDoor ? [] : unseenDeclaredDependencies(stack);
197204

198205
for (const { rec, path } of sources) {
@@ -208,7 +215,8 @@ export function validateKnowledgeSource(
208215
if (noUniverse) continue;
209216
// A platform object a known package registers: its declaration is not
210217
// in this stack, so neither its fields nor its gates can be read here.
211-
if (isPlatformProvidedObjectName(objectName)) continue;
218+
// Against the whole collection it is in hand, and its absence is final.
219+
if (!whole && isPlatformProvidedObjectName(objectName)) continue;
212220
if (closure) {
213221
out.push({
214222
severity: 'error',
@@ -222,7 +230,7 @@ export function validateKnowledgeSource(
222230
suggestName(objectName, objects.keys()),
223231
hint: closureDependencyRemedy(objectName, closure.packageId, 'name an object inside that closure'),
224232
});
225-
} else if (hasPlatformObjectPrefix(objectName)) {
233+
} else if (!whole && hasPlatformObjectPrefix(objectName)) {
226234
out.push({
227235
severity: 'warning',
228236
rule: KNOWLEDGE_SOURCE_OBJECT_UNKNOWN,

‎packages/services/service-knowledge/src/__tests__/knowledge-source-admission.test.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ describe('admitAuthoredSource — source admission at save, as the authoring pri
891891
});
892892
const sealed: ObjectDef = { ...TICKET, name: 'sealed', enable: { apiEnabled: false } };
893893
const getOnly: ObjectDef = { ...TICKET, name: 'get_only', enable: { apiMethods: ['get'] } };
894+
const unsearchable: ObjectDef = { ...TICKET, name: 'unsearchable', enable: { apiMethods: ['list'], searchable: false } };
894895
const sysClosed: ObjectDef = { ...TICKET, name: 'sys_closed_note' };
895896
const sysOpen: ObjectDef = { ...TICKET, name: 'sys_open_note', enable: { aiReadable: true } };
896897

@@ -971,7 +972,8 @@ describe('admitAuthoredSource — source admission at save, as the authoring pri
971972
it.each([
972973
['an object of a disabled package', { objects: [TICKET], disabled: ['ticket'] }, 'ticket', 'disabled package'],
973974
['an object the API does not serve at all', { objects: [sealed] }, 'sealed', 'does not serve object'],
974-
['an object whose `apiMethods` do not grant `search`', { objects: [getOnly] }, 'get_only', 'does not serve object'],
975+
['an object whose `apiMethods` do not grant `list`', { objects: [getOnly] }, 'get_only', 'does not serve object'],
976+
['an object granting `list` beside `searchable: false`', { objects: [unsearchable] }, 'unsearchable', 'does not serve object'],
975977
['a system object without `enable.aiReadable`', { objects: [sysClosed] }, 'sys_closed_note', 'does not opt into AI reads'],
976978
])('%s is refused PERMISSION_DENIED / 403, naming the object', async (_label, opts, object, said) => {
977979
const { svc } = setup({ sources: [], ...opts });
@@ -983,6 +985,20 @@ describe('admitAuthoredSource — source admission at save, as the authoring pri
983985
expect(await svc.admitAuthoredSource(item(object, ['body']), SYSTEM)).toEqual({ admitted: true });
984986
});
985987

988+
it('the not-served refusal names `list` and `searchable` as cause and fix, never a `search` grant', async () => {
989+
for (const object of ['sealed', 'get_only', 'unsearchable']) {
990+
const { svc } = setup({ sources: [], objects: [sealed, getOnly, unsearchable] });
991+
const verdict = await svc.admitAuthoredSource(item(object, ['body']), MANAGER);
992+
expect(verdict).toMatchObject({ admitted: false, code: 'PERMISSION_DENIED', status: 403, object });
993+
const message = (verdict as { message: string }).message;
994+
expect(message).toContain('does not grant `list`');
995+
expect(message).toContain('include `list` with `enable.searchable` not false');
996+
// `search` is a retired `apiMethods` value the parse strips: never prescribed as a grant.
997+
expect(message).not.toMatch(/(include|grant)s? `search`/);
998+
expect(message).not.toContain('Serve the object for `search`');
999+
}
1000+
});
1001+
9861002
it('CONTROL: a served object, and a system object that opts into AI reads, are admitted', async () => {
9871003
const { svc } = setup({ sources: [], objects: [TICKET, sysOpen] });
9881004
expect(await svc.admitAuthoredSource(item('ticket', ['body']), MANAGER)).toEqual({ admitted: true });

‎packages/services/service-knowledge/src/knowledge-service.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3191,9 +3191,11 @@ export class KnowledgeService implements IKnowledgeService {
31913191
return refuse(
31923192
403,
31933193
'PERMISSION_DENIED',
3194-
`${named}: the API does not serve object '${object}' for \`search\` (\`enable.apiEnabled\` is false, or ` +
3195-
"its `enable.apiMethods` list does not include `search`), and a knowledge search is a search over the " +
3196-
"object's records. Serve the object for `search`, or index another object.",
3194+
`${named}: the API does not serve object '${object}' for \`search\` (\`enable.apiEnabled\` is false, its ` +
3195+
'`enable.apiMethods` list does not grant `list`, from which search derives, or it grants `list` beside ' +
3196+
"`enable.searchable: false`), and a knowledge search is a search over the object's records. " +
3197+
`Serve '${object}' for search: keep \`enable.apiEnabled\` true and, where it declares ` +
3198+
'`enable.apiMethods`, include `list` with `enable.searchable` not false; or index another object.',
31973199
);
31983200
case 'system-object-not-ai-readable':
31993201
return refuse(

0 commit comments

Comments
 (0)