Repository navigation
Commit 857941d
fix(cloud-connection): install-local seeds a composed bundle's package datasets on install, reseed, upgrade and restart (#34403)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XHBgb29oZuAnPqZyY6nR8UE)_
Fixes #34336
Clause-②: no
Metadata-protocol: none
## 维护者速读
- **改了什么**:install-local
的所有样例数据入口(安装、重新灌入、升级、重启自愈、清除、计数、已装应用列表)改为同一个读法,组合包(`packages[]`)每个子包里的
seed 数据都能读到。
- **为什么改**:HotCRM 6.2 起发布的是组合包,没有顶层 `data`,托管租户装上后 订单与回款、项目交付
等模块一条演示数据都没有。
- **风险与回滚**:低。单包(平铺)读法不变,已有对照测试钉住;回滚即 revert 本 PR。
-
**先看**:`packages/cloud-connection/src/marketplace-install-local-plugin.ts`
的 `seedDatasetsOf` 与 `applySideEffects` 第 2
步;`marketplace-install-local-composed-bundle-seeds.test.ts`。
- **两分钟验证**:`pnpm --filter @objectstack/cloud-connection exec vitest run
src/marketplace-install-local-composed-bundle-seeds.test.ts`,预期 9/9 通过。
- **需要你做的**:无,席位落地。卡上第 2 条(升级时把新增 seed 补进所有已有组织)是新产品行为,未实现,见下方
Acceptance notes,待决定。
## What changes
Every seed door of `MarketplaceInstallLocalPlugin` read the top-level
`data` only. A composed bundle (`dist/objectstack.json` with
`packages[]`, ADR-0130 D4) has no top-level `data`, so all of them
answered as if the package had no sample data.
They now share one reader, `seedDatasetsOf(body)`, which is
`resolveStackCollection(body, 'data')` from `@objectstack/core` filtered
to datasets that name an object and carry records. It reads the
top-level `data` when the body has one. Otherwise it reads every package
body's `data`, in the artifact's package order (dependency order, the
order the packages register in).
| Seed door | Before (composed bundle) | After |
|:--|:--|:--|
| install, `POST install-local` (`applySideEffects` step 2 + 3) |
`seeded: skipped / no-datasets`, nothing shared | every package body
seeded, merged into `seed-datasets` |
| upgrade (re-install of a newer version) | same as install | incoming
version's datasets seeded into the caller's organization (single-tenant:
the database), a package the upgrade adds included |
| reseed, `POST …/reseed-sample-data` | `400 RESEED_SKIPPED no-datasets`
| seeds every package body |
| restart rehydrate (`applySideEffects` with `seedNow: false`) | nothing
merged for the per-organization replay | merged, so a new organization
gets them |
| restart heal (`maybeHealSampleData`) | nothing to heal | heals an
empty single-tenant database |
| purge, `POST …/purge-sample-data` | `400 NOTHING_TO_PURGE` | matches
every package body's rows |
| count, `GET …/sample-data` | `count: 0` | counts every package body's
rows |
| listing `withSampleData` | `false` | read from every package body |
The unmanaged copy (`installMode: 'unmanaged'`) is unchanged: its import
refuses a multi-package artifact by name, and its doors read the seed
receipt, not the body.
A malformed `packages` gets the resolver's ADR-0112 refusal, the same
one the `manifest` service raises on those bytes. `applySideEffects`
reports it in `seeded` (`seed-datasets-unread: …`) and does not throw,
as its contract says. The listing answers `withSampleData: false` for
that entry and logs it at `warn`. The heal logs it and skips.
## Tests
New file
`packages/cloud-connection/src/marketplace-install-local-composed-bundle-seeds.test.ts`,
9 cases. The composed fixture lists the order module before the core
module it depends on, so package order is not array order:
- install: the loader gets `[core, o2c]`, and `seed-datasets` gets the
same list;
- reseed, count, purge, listing: each door is handed `[core, o2c]`;
- upgrade 6.3.0 to 6.4.0 adding a PSA package: the loader gets all
three, core first;
- restart: `seed-datasets` is refilled and the heal seeds `[core, o2c]`;
- controls: a flat bundle reads its top-level `data` unchanged; a
composed artifact that still carries a flattened top-level `data` reads
it once, not again per package; a composed artifact with no datasets
still answers `no-datasets`.
<details><summary>Red on the base plugin source, green on the fix (HEAD
f54ec13)</summary>
Red leg: `marketplace-install-local-plugin.ts` restored from `719b6b537`
(base), the new test run, then restored with `git checkout HEAD --` and
the blob hash checked against HEAD.
```
× install seeds every package body's datasets … (expected { mode: 'skipped', …(1) } to match object { mode: 'inline', inserted: 3 })
× reseed loads them again ({"code":"RESEED_SKIPPED","message":"Reseed did not run: no-datasets"}: expected 400 to be 200)
× an upgrade that adds a package seeds the incoming version's datasets …
× the sample-data count and the purge match the rows of every package body
× the installed-apps listing reads the package's sample data from every package body
× a restart shares them for new organizations and heals an empty database from them
Tests 6 failed | 3 passed (9)
```
Green leg: `Tests 9 passed (9)`.
Package: `pnpm --filter @objectstack/cloud-connection typecheck` (both
`tsc --noEmit` programs) and `vitest run`: `Test Files 84 passed (84)`,
`Tests 1236 passed (1236)`.
</details>
## Acceptance notes
- **Card ask 2 is not built.** The card says an upgrade replays new seed
keys into existing organizations, and that `sys_seed_landed_key` already
keeps a deleted row from coming back. Measured on this door, for a flat
bundle as well as a composed one:
- an upgrade seeds only the organization the request acts in (or the
single-tenant database). No code path replays an upgrade's seed into
other existing organizations. The per-organization replayer runs only
when a `sys_organization` row is inserted;
- `runInlineSeed` builds `SeedLoaderService` with no `landedKeys`
option, so this door neither reads nor writes `sys_seed_landed_key`. On
this door a row a tenant deleted comes back on reinstall or reseed
(create-only `ignore` default).
So ask 2 would be new behaviour, not a fix. After this PR a composed
upgrade does what a flat upgrade does: a package the upgrade adds gets
its rows in the upgrading organization. The question is open on the
card.
- **Same family, not changed here:** `applySideEffects` step 1 reads
`translations` from the top level only. Measured on a scratch run: a
composed bundle with a package-body `translations` answers
`translationsLoaded: 0`, and the same translations on a flat bundle
answer `1`. The ADR-0120 D5e global-unique gate
(`evaluateGlobalUniqueGate`) also reads `manifest.objects` from the top
level only. That one is read from the code, not measured. Both are
reported to the seat.
- The seed locale's last fallback (`appDefaultSeedLocale`) still reads
the composed artifact's top-level `i18n`, the same as
`AppPlugin.resolveSeedLocale` does for a boot bundle. That is unchanged.
## Verification
<details><summary>Local gates (HEAD f54ec13)</summary>
- `node scripts/pm/dispatch-gates.mjs --commands`: 71 families derived.
All 71 were run. Reconciliation with `--ran` and recorded exit codes:
`71 derived famil(ies) accounted for — 70 run, 1 NOT-MEASURED (1 DERIVED
from a recorded exit 3)`.
- 70 passed with exit 0. Among them: `check:type-check-debt` (`0 raw tsc
error(s) total`), `check:durability-log-level`,
`check:startup-registry-verdict`, `check:test-source-alias`,
`check:nul-bytes`, `check:route-envelope`.
- `pnpm check:dual-build-cjs-loads`: exit 3, PREREQUISITE NOT MET (it
needs a full workspace build). NOT MEASURED locally; CI runs it.
- Before push, a `git merge-tree` against the one open PR that touches
`marketplace-install-local-plugin.ts` (#34316, `claude/area-A5-33922`)
produced no conflict.
</details>
## Fix round 2 (head `543a53e54b`)
- Merged `origin/main` (`9e67ea6cf4`, no conflicts; none of the 17
incoming commits touches `packages/cloud-connection`).
- L1 Should (6918284604): the purge (`POST …/purge-sample-data`) and the
sample-data count (`GET …/sample-data`) now read a ledger entry's seed
datasets through `ledgerSeedDatasets`. A body the resolver refuses (a
malformed `packages`, ADR-0112 `INVALID_ARTIFACT_PACKAGES`) now gets the
unreadable-entry answer the reseed already gives (500
`MARKETPLACE_STORAGE_FAILED`, naming the ledger file and quoting the
refusal) instead of a throw into the route's error path. No row is
matched or deleted. `LocalManifestSource.fileNameOf` names the file by
the existing `safeFilename` rule.
- Pins: two new cases in
`marketplace-install-local-composed-bundle-seeds.test.ts`, red on
`f54ec13b` (2 failed, thrown refusal), green at head (11/11).
- Package: typecheck clean, 84 files / 1238 tests passed. Local gates:
72 derived, 71 exit 0, `check:dual-build-cjs-loads` not measured (exit
3, needs a full build; CI runs it).
- CI on `543a53e54b`: 35 success, 16 skipped, 0 failure. Dev report
6920915310 on #34336.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01FEkQ5pHNFS9mn8hS13iGyL)_
<!-- signed: repo:objectstack#1 · os-project-manager ·
session_01FEkQ5pHNFS9mn8hS13iGyL -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent fa9d695 commit 857941d
4 files changed
Lines changed: 443 additions & 20 deletions
File tree
- .changeset
- packages/cloud-connection/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
436 | 436 | | |
437 | 437 | | |
438 | 438 | | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
439 | 449 | | |
440 | 450 | | |
441 | 451 | | |
| |||
| 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 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
0 commit comments