Commit 3c84326
authored
fix(api): keep plugin config loads side-effect free (#2025)
## Summary
Makes API config loading side-effect free for CLI plugin management
commands, so plugin install operations preserve the plugin list they are
updating.
## Root Cause
`loadApiConfig()` always ran the stale Connect cleanup when
`/boot/config/plugins/dynamix.unraid.net.plg` was not visible. CLI
plugin commands also load API config, so an install command could remove
`unraid-api-plugin-connect` while trying to add it.
During Unraid plugin-manager installation, the Connect `.plg` may not be
committed to `/boot/config/plugins` yet. That allowed the API package to
install and restart successfully while `api.json` still contained
`"plugins": []`, so the Connect Nest module never loaded.
## Change
- Gates the stale Connect cleanup on `environment.IS_MAIN_PROCESS`.
- Keeps CLI config loading side-effect free for plugin management
operations.
- Preserves the existing runtime cleanup behavior when the main API
process starts.
- Adds tests for both CLI-style config loading and main-process cleanup.
- Builds `@unraid/shared` before API type-check so workspace
package-exported types are current in CI.
## Validation
- `pnpm -C api run type-check`
- `pnpm -C api exec vitest run src/unraid-api/config/api-config.test.ts`
- `pnpm --filter @unraid/connect-plugin test`
- Prior to broadening this fix, installed a patched `.plg` on
`root@unraid.local` and verified the expected runtime outcome:
- install output included `Added bundled plugin
unraid-api-plugin-connect`
- `api.json` contained `"plugins": ["unraid-api-plugin-connect"]`
- `unraid-api plugins list` reported
`unraid-api-plugin-connect@file:packages/unraid-api-plugin-connect-4.25.3.tgz`
- `/var/log/graphql-api.log` showed `ConnectPluginModule` initialized
and Mothership connected
Note: an accidental full `pnpm --filter ./api test --
api/src/unraid-api/config/api-config.test.ts` run executed the broader
API suite and surfaced an existing unrelated metrics spec failure in
`metrics.resolver.spec.ts`; the focused config test passes.1 parent 264ddf0 commit 3c84326
3 files changed
Lines changed: 79 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | | - | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
15 | 22 | | |
16 | 23 | | |
17 | 24 | | |
| |||
39 | 46 | | |
40 | 47 | | |
41 | 48 | | |
| 49 | + | |
42 | 50 | | |
43 | 51 | | |
44 | 52 | | |
45 | 53 | | |
| 54 | + | |
| 55 | + | |
46 | 56 | | |
47 | 57 | | |
48 | 58 | | |
| |||
296 | 306 | | |
297 | 307 | | |
298 | 308 | | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
299 | 313 | | |
300 | 314 | | |
301 | 315 | | |
| |||
321 | 335 | | |
322 | 336 | | |
323 | 337 | | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
324 | 396 | | |
0 commit comments