Repository navigation
Commit 24d808d
fix(service-knowledge): the knowledge-source save door names an absent object or field as such (#38465)
Fixes #38419
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 在 Studio 或 MCP
保存知识源的搭建者:以前填错对象名或字段名时,会看到"暂时无法判断、请重试"或"无权访问"的提示,现在会直接看到"该对象/字段不存在",并带上与
`os validate` 相同的规则名。
- 属于知识库检索(把业务数据建成可搜索的知识源)这条线,替搭建者解决"拼错了却被告知去重试或去找管理员"的误导。
- 出错时只影响保存知识源这一个入口的提示文字与状态码;对存在但无权访问的对象和字段,拒绝提示一字未变,可以直接撤回。
- 无。
## What changes
`KnowledgeService.admitAuthoredSource` (the save-time admission every
knowledge-source save door asks: `PUT /meta/knowledge_source/:name`, the
runtime `/meta` door, the MCP draft save, and the package duplicate)
gains a "does not exist" arm ahead of every permission arm (ADR-0161 K4,
row 4):
- `source.object` names no object the registry defines ⇒ `400
VALIDATION_ERROR`, naming the object and the rule
`knowledge-source-object-unknown`.
- a `source.content` / `source.contentFields` / `source.metadataFields`
member names neither a declared field nor `id` or a system column the
registry injects (`resolveInjectedSystemColumns`, the derivation `os
validate` uses) ⇒ `400 VALIDATION_ERROR`, naming the object, the field
(`field` on the verdict) and the rule `knowledge-source-field-unknown`.
Before this PR, with a platform-like security service, the same saves
answered `503 SERVICE_UNAVAILABLE` "... could not be judged ... try
again" (absent object), `403` "is a system object that does not opt into
AI reads" (absent `sys_` object), and `403` "you may not query field ...
hidden from you" (absent field). With no security service they were
admitted.
The arm reads the object's registered definition only. It never reads a
permission answer. Every door that asks this verdict admits only a
`manage_metadata` holder, and ADR-0106 D4 serves that caller every
object definition whole. So the arm tells the author nothing they could
not already read. It draws no verdict for an engine with no schema
registry, for an object of a disabled package (that gate still answers
it), or for an object whose fields cannot be enumerated. A registry that
throws keeps the `503`, reported once. No new error code:
`VALIDATION_ERROR` is the code this method already answers for an
unmounted adapter.
The refusal is worded for the door, as the other arms are: the
duplicate's caller is told the source cannot be copied, then to
duplicate the package again.
## Read first
1. `packages/services/service-knowledge/src/knowledge-service.ts`,
`absentSourceReference`: the riskiest hunk is the three early returns
(no `getSchema`, disabled package, no field map). Each one keeps a case
that exists from being read as absent.
2. `packages/services/service-knowledge/src/knowledge-service.ts`,
`admitAuthoredSource`, the new block after the engine check: its
position decides which arm wins.
3.
`packages/services/service-knowledge/src/__tests__/knowledge-source-save-absent-reference.test.ts`,
the `no permission answer changes for an object or a field that exists`
block, which holds the full answers taken on the base.
## Two-minute verification
`pnpm --filter @objectstack/service-knowledge exec vitest run
--maxWorkers=2
src/__tests__/knowledge-source-save-absent-reference.test.ts`. Expect 15
passed. Restore `knowledge-service.ts` from `0c1b2ffe` and the same
command shows 7 failed and 8 passed: the absent references answer 503 /
403, and every pin for what exists still passes.
## Tests
<details><summary>New file:
knowledge-source-save-absent-reference.test.ts (15 cases)</summary>
- Absent business object and absent `sys_` object, with and without a
security service: `VALIDATION_ERROR` / `400`, `object` set, no `field`,
message carries `knowledge-source-object-unknown`, never "could not be
judged", "try again", "does not opt into AI reads" or "may not query".
The engine's own write (`isSystem`) is admitted.
- Absent `content`, `metadataFields` and retired `contentFields` member,
for a member and a manager, with and without a security service:
`VALIDATION_ERROR` / `400`, `object` + `field`, message carries
`knowledge-source-field-unknown`.
- An absent field is named before a hidden one in the same source.
- CONTROL: `id`, `created_at`, `owner_id` (not declared, injected) are
admitted.
- `door: duplicate`: same status, code, object and field as the save,
worded for the duplicate.
- Exists, answer unchanged, full verdict with `toEqual`, sentences taken
from the base: hidden field (403), `sys_` object without
`enable.aiReadable` (403), security service that answers neither
question (503), disabled package with and without a served definition
(403), registry that throws (503, logged once), engine with no schema
registry (admitted).
</details>
<details><summary>Red on the base, green on the head</summary>
Base `knowledge-service.ts` (`0c1b2ffe`), head test file:
```
Tests 7 failed | 8 passed (15)
AssertionError: expected { admitted: false, status: 503, ... } to match object { admitted: false, ... } (absent object)
AssertionError: expected { admitted: false, status: 403, ... } to match object { admitted: false, ... } (absent sys_ object)
AssertionError: u_member undefined: expected { admitted: false, status: 403, ... } (absent field)
os-verify-lock: VERDICT command-exit 1
```
Head `cf125c96`, after `pnpm turbo run build
--filter='@objectstack/service-knowledge...' --concurrency=2` (20/20):
```
pnpm --filter @objectstack/service-knowledge test
Test Files 22 passed (22)
Tests 741 passed (741)
pnpm --filter @objectstack/service-knowledge typecheck
check:test-typecheck: OK — 0 file(s) / 0 error(s)
os-verify-lock: VERDICT command-exit 0
```
</details>
## Acceptance notes
- The fields a `where` reads are not checked for existence here. `os
validate` does not check them either (`validate-knowledge-source.ts`
checks `content` and `metadataFields` only), so no rule name exists for
them. Measured on `cf125c96`: a `where` naming an absent field answers
`403 PERMISSION_DENIED` "which you may not query (it is hidden from you
...)" when a security service is mounted, and is admitted when none is.
Reported to the seat to file; not changed here.
- The published `objectstack-ai` skill says `os validate` and publish
check the two rules. That is still true. It does not mention the save
door, and this PR leaves `skills/**` untouched.
- Search-time admission (`admitSources`) is untouched by this PR. Only
the save-time verdict changes.
## Verification
<details><summary>Local derived gates at cf125c9 (dispatch-gates
--commands, 71 commands)</summary>
Each derived command ran on head `cf125c96` (after merging `origin/main`
at `1afd9c13`), exit captured before any pipe:
```
dispatch-gates --ran: 71 derived famil(ies) accounted for, 70 run, 1 NOT-MEASURED (1 DERIVED from a recorded exit 3)
NOT MEASURED: node scripts/check-plugin-teardown-shape.mjs --self-test, reason: PREREQUISITE NOT MET, its positive control is pinned to a commit this shallow clone cannot reach (checker health only; CI runs it)
pnpm check:dual-build-cjs-loads: 126 published require entry point(s) across 74 package(s) load; 2593 emitted CommonJS file(s) parse
```
The other 69 commands exit 0, among them `check:nul-bytes`,
`check:doc-authoring`, `check:issue-citations`, `check:published-files`,
`check:type-check-coverage`, `check:type-check-debt`,
`check:undeclared-dep-imports`, `check:engine-double-contract`,
`check:error-status-conformance`, `check:adr-0087-registration --base
origin/main` and `check:empty-changeset --base origin/main`. Every
family CI runs beyond these is read from this PR's check-runs, not
re-run locally.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_016WV4d13AraSmVmgVtCvkWk)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 4d07ddb commit 24d808d
3 files changed
Lines changed: 371 additions & 1 deletion
File tree
- .changeset
- packages/services/service-knowledge/src
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
0 commit comments