Repository navigation
Commit ca54eac
fix(service-datasource)!: external validate answers an unknown datasource 404 RESOURCE_NOT_FOUND (#27911)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D3czSGepvH7z6EH8Tx6ZZYv)_
Fixes #27696
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — no `skills/**` file or authored doc teaches what
validate answers for an unknown name (`git grep "external/validate" --
skills content docs` hits only release notes and QA checklist items
about the auth floor and the in-sync report)
**BREAKING** for a caller of `POST
/api/v1/datasources/:name/external/validate`, or of
`ExternalDatasourceService.validateDatasource`, that addresses a
datasource name that does not exist: `200 { ok: true, results: [] }`
becomes `404 RESOURCE_NOT_FOUND`. The changeset carries the before / now
/ fix and its ADR-0087 marker (`not-required
(no-migration-prescription)`).
## 维护者速读
- 改了什么:外部数据源校验接口 `POST /datasources/NAME/external/validate`
遇到不存在的数据源名时,改为返回 404「数据源不存在」,与查看数据源和其它联邦接口一致。
- 为什么改:以前返回 200 和一份空的「全部通过」报告,调用方分不清「这个数据源没有联邦对象」和「这个数据源根本不存在」。
- 风险与回滚:只影响不存在的名字;已保存的数据源(含托管数据源与主数据源)照旧 200。后台漂移检查若碰到已删除的数据源,会多记一条
warn。回滚即还原本 PR。
-
先看:`packages/services/service-datasource/src/external-datasource-service.ts`
的 `validateDatasource` 开头三行;再看
`packages/rest/src/external-datasource-unknown-name.test.ts` 新增的三个用例。
- 两分钟验证:`pnpm --filter @objectstack/rest exec vitest run
src/external-datasource-unknown-name.test.ts`,预期 15 个用例全绿,其中未知名字
404、`warehouse` 与 `default` 仍 200 空报告。
- 需要你做的:无,席位落地。
## What changes
- `ExternalDatasourceService.validateDatasource(name)`
(service-datasource) now checks the datasource exists before anything is
listed or introspected, the same check `testConnection` makes (#27510):
the primary datasource is not looked up (it may have no stored record),
and any other name with no saved record throws the package's one
`datasourceNotFoundError` (`404`, `RESOURCE_NOT_FOUND`, `Datasource
"NAME" does not exist.`).
- The REST route needed no code change: its catch already relays that
envelope as `404` since #27618 (`answerThrown`). It gains a comment
naming the answer.
- Only existence is asked, not the full federation guard
(`assertFederationSource`): that guard refuses managed datasources and
the primary one with `400`, and the ruling keeps a datasource that
exists and has nothing federated at its `200` empty report.
- The method's doc comment, which said the unknown-name question was
left for a separate ruling, now records this ruling.
- Side effect, in the changeset: the runtime drift check
(`external-validation-plugin.ts`) also calls `validateDatasource`; for a
datasource deleted after its timer was armed, a tick lands in its
existing catch (one `warn`, no events) instead of returning an empty
report silently. No code change there.
- File surface: the claim was amended (seat, before push) to add
`external-datasource-service.ts` and its test; the dispatch order had
named only the route file.
## Tests
- `packages/rest/src/external-datasource-unknown-name.test.ts`: validate
on `no_such_ds` answers `404 RESOURCE_NOT_FOUND` in `GET
/datasources/:name`'s words; validate on a saved managed datasource
(`warehouse`) and on `default` keeps `200 { ok: true, results: [] }`.
Real `ExternalDatasourceService` over the real `HonoHttpServer`.
- `packages/rest/src/external-datasource-validate-scope.test.ts`: the
cell that pinned the old empty `200` for an unknown name now pins the
`404`, still with no introspection and no `validateAll` call.
-
`packages/services/service-datasource/src/__tests__/external-datasource-service.test.ts`:
`validateDatasource` on an unknown name rejects with `status 404` /
`code RESOURCE_NOT_FOUND` / `datasourceNotFoundError`'s message, with
`listObjects` never called and nothing introspected; a saved datasource
nothing is bound to still answers the empty report.
<details><summary>Red on main, ablation, results</summary>
- On `main` (da94c11) with only the new pins: rest validate cell red,
`expected { status: 200, success: true, … } to deeply equal { status:
404, success: false, … }`; the two `200` cells green.
- Ablation (the three-line check removed from the service, then
restored): service pin red (1 failed / 42), rest pin red (1 failed /
14); restored: 43/43 and 15/15. Both suites resolve
`@objectstack/service-datasource` to `src/` (rest's vitest alias), so no
rebuild was in the path.
- `packages/rest`: Test Files 352 passed (352), Tests 7023 passed / 350
skipped.
- `packages/services/service-datasource`: Test Files 63 passed (63),
Tests 1029 passed.
- `packages/runtime` `src/external-validation*`: Test Files 4 passed,
Tests 44 passed.
- `tsc --noEmit`: rest exit 0, service-datasource exit 0.
</details>
## Acceptance notes
- None outside the card.
## Verification
<details><summary>Gates at bdbdaae</summary>
- `node scripts/pm/dispatch-gates.mjs --commands`: 62 families derived.
All run; 61 exit 0; `pnpm check:dual-build-cjs-loads` exit 3
(PREREQUISITE NOT MET, needs every package's dist), NOT MEASURED
locally, CI runs it.
- `dispatch-gates --ran`: 62 derived, 61 run, 1 NOT-MEASURED, 0 UNRUN.
- `pnpm lint`: exit 0.
- `node scripts/check-commit-card-trailers.mjs --range
origin/main..HEAD`: exit 0.
- Full dogfood battery at the final head: reported in the os-dev-report
comment.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_016WV4cx56cEs32AZSfABRR8)_
Co-authored-by: Claude <noreply@anthropic.com>1 parent ed8b237 commit ca54eac
6 files changed
Lines changed: 137 additions & 15 deletions
File tree
- .changeset
- packages
- rest/src
- services/service-datasource/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 | |
|---|---|---|---|
| |||
599 | 599 | | |
600 | 600 | | |
601 | 601 | | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
602 | 607 | | |
603 | 608 | | |
604 | 609 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
216 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
217 | 221 | | |
218 | 222 | | |
219 | 223 | | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
226 | 228 | | |
227 | 229 | | |
228 | 230 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
662 | 663 | | |
663 | 664 | | |
664 | 665 | | |
665 | | - | |
666 | | - | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
667 | 677 | | |
668 | | - | |
| 678 | + | |
669 | 679 | | |
670 | 680 | | |
671 | 681 | | |
672 | 682 | | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
673 | 712 | | |
674 | 713 | | |
675 | 714 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1425 | 1425 | | |
1426 | 1426 | | |
1427 | 1427 | | |
1428 | | - | |
1429 | | - | |
1430 | | - | |
1431 | | - | |
1432 | | - | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
1433 | 1441 | | |
1434 | 1442 | | |
1435 | 1443 | | |
| |||
1439 | 1447 | | |
1440 | 1448 | | |
1441 | 1449 | | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
1442 | 1453 | | |
1443 | 1454 | | |
1444 | 1455 | | |
| |||
0 commit comments