Repository navigation
Commit d99b746
fix(plugin-sharing): warn once per boot when a hierarchy scope falls back to owner-only (#35780)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6Jao6bxiPKCvVuzoFTExumbxoz)_
Fixes #35172
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:运维人员在不经命令行启动的运行时里,第一次有人用到上下级可见范围而企业版组件没装时,日志里会出现一条警告,说明这些范围只按本人记录生效;终端用户无感。
- 为什么做:属于权限可见性排查这条线,替自托管运行时的运维人员解决「为什么每个人只看得到自己的记录」查不到原因的问题。
- 出错会怎样:最坏是这条警告不出现或多出现几次,访问结果本身不变;可以直接撤回。
- 要你做什么:无
## What changes
`SharingService.resolveOwnerScopeIds` (plugin-sharing) fails closed to
owner-only when a hierarchy scope (`own_and_reports`, `unit`,
`unit_and_below`) is asked for and no `hierarchy-scope-resolver` service
is registered. That branch used to log nothing, so only `os serve` (the
CLI line added by #35168) ever said so.
- The first time that fallback is taken, the service logs one `warn`
(`HIERARCHY_RESOLVER_ABSENT_NOTICE`), with meta `{ capability:
'hierarchy-security', provider, scope }`. The provider is read from
`PLATFORM_CAPABILITY_PROVIDERS['hierarchy-security'].package`, so it is
the same `@objectstack/security-enterprise` string `os validate` / `os
verify` / `os serve` print. The prefix and level match the no-org
warning just below it (`[sharing] hierarchy scope NOT widened: ...`,
`warn`). Per AGENTS.md "Degradation log levels", this is a functional
degradation, so `warn` is the right level.
- **Once per boot.** The latch is a boolean on the service instance. The
plugin builds exactly one `SharingService`, in its `kernel:ready` hook
(`sharing-plugin.ts`), so one instance means one boot. The callers (read
filter, write gates, share management, middleware) run per request. The
condition belongs to the composition, not to a caller or an object, so a
finer key would only repeat the line. The latch is claimed before the
log, inside a `try`, so a throwing logger cannot fail a gate or throw
once per request.
- **Only when the fallback is taken.** `own`, `org` and an unset scope
return before the resolver lookup, so an app that never uses a hierarchy
scope logs nothing. A registered resolver also logs nothing.
- **The CLI stops claiming silence for this token** (patch round 1,
claim amendment 7033136082). `enterpriseAbsenceConsequence`
(`packages/cli/src/utils/capability-preflight.ts`) used to end every
enterprise-token sentence with "and no log line says so". A new table,
`ENTERPRISE_ABSENCE_RUNTIME_NOTICE`, maps a token to the opening words
of the warning its runtime logs. For `hierarchy-security`, the sentence
now says the runtime logs one warning (`[sharing] hierarchy scope NOT
widened ...`) the first time it falls back. Any token without a row
keeps the old clause. I made it a separate table, not a clause folded
into `ENTERPRISE_ABSENCE_CONSEQUENCE`, for two reasons. First, the
consequence is what the metadata does and the notice is what the runtime
says, and a token can have either without the other. Second, the
exported table's type stays unchanged.
- **Logging only.** The latch records no verdict: the resolver is still
looked up on every call, and the returned ids are unchanged (`[me]`).
`check:startup-registry-verdict` is green on this tree.
## Tests
New top-level `describe` in `src/sharing-service.test.ts` (the shared
harness file). It has six cases:
- the notice names the capability, the registry provider and the
owner-only consequence;
- a resolver-less hierarchy scope warns once across two calls
(`unit_and_below`, then `own_and_reports`) plus a public
`canManageShares` gate, and every call answers `['bob']`;
- a fresh instance, standing for a new boot, warns again;
- CONTROL: `undefined` / `own` / `org` produce no `warn` at all;
- CONTROL: a registered resolver produces no notice and returns its own
ids;
- a throwing logger leaves the answer intact and is called only once.
The plugin-side notice pin also asserts the prefix the CLI quotes.
`packages/cli/test/capability-preflight.test.ts` gains three pins:
- every runtime-notice row keys an enterprise-edition registry token;
- `hierarchy-security` no longer contains "no log line says so" and
names the `[sharing] hierarchy scope NOT widened` prefix;
- CONTROL: a generic token still says "no log line says so".
## Acceptance notes
- The round-1 finding (the CLI sentence claiming "no log line says so")
is fixed in this PR under the claim amendment.
- Round 2 (claim amendment 7035179372, head `9c805c664c`), comment only:
the comment on the unmounted-known-tokens block in
`packages/cli/src/commands/serve.ts` no longer says the owner-only
fallback happens "without a word". It now says the runtime logs it once
at the first fallback, and that `os serve` says it at start-up, before
any request. Readings on that file: eslint `--no-inline-config` exit 0;
check:doc-authoring, check:issue-citations, check:nul-bytes,
check:closed-ceremony-text and check-drift-comment all exit 0.
## Verification
Two-minute check: `pnpm --filter @objectstack/plugin-sharing exec vitest
run --maxWorkers=2 src/sharing-service.test.ts -t "said once per boot"`
should show 6 passed.
Files to read first:
`packages/plugins/plugin-sharing/src/sharing-service.ts`. The risk hunk
is the `if (!resolver)` branch in `resolveOwnerScopeIds`.
Round-1 readings are on head `e26a7e36bb`. Round-0 readings, on
`4ae41bb446`, are kept below.
Two-minute check (CLI): `pnpm --filter @objectstack/cli exec vitest run
--project unit --maxWorkers=2 test/capability-preflight.test.ts` should
show 50 passed.
<details><summary>Round 1 (e26a7e3): affected test files, CLI
ablation, derived gates</summary>
```
narrowed build (core/types/lint/plugin-sharing closures) + both files, under os-verify-lock:
test/capability-preflight.test.ts Tests 50 passed (50)
src/sharing-service.test.ts Tests 174 passed (174)
os-verify-lock: VERDICT command-exit 0
ablation: ENTERPRISE_ABSENCE_RUNTIME_NOTICE hierarchy-security row deleted
ablation-replace: ok mutation landed: anchor 1 -> 0, blob deafdf7 -> a609ab686a4c
x hierarchy-security no longer claims silence: it names the warning the runtime logs
Tests 1 failed | 49 passed (50)
ablation-replace: blob after restore deafdf7
ablation-replace: blob at HEAD deafdf7
Run reconciliation — 71 derived, 69 run, 2 NOT-MEASURED, 0 UNRUN.
```
NOT MEASURED: `check:dual-build-cjs-loads` and `check:i18n`. Reason:
both exit 3 PREREQUISITE NOT MET, for want of a repo-wide build; CI runs
both.
Declared narrowing: the full CLI `unit` tier and `pnpm --filter
@objectstack/cli typecheck` were not run locally. The verify lock was
queued for about 75 minutes behind dogfood runs, so the build was
narrowed to the closures the two touched test files import. CI `Test
Core` and `TypeScript Type Check` run the full set.
</details>
Round 0 (`4ae41bb446`):
<details><summary>Package test + typecheck (under
os-verify-lock)</summary>
```
Test Files 75 passed (75)
Tests 1601 passed (1601)
> tsc --noEmit && tsc --noEmit -p tsconfig.scripts.json && pnpm check:test-typecheck
os-verify-lock: VERDICT command-exit 0
```
</details>
<details><summary>Ablation: latch removed, the once-pin goes red;
restored by blob hash</summary>
```
ablation-replace: ok mutation landed: anchor 1 -> 0, blob 865061d -> a7557d5d43f7
x a hierarchy scope with no resolver warns ONCE across two calls, and still answers owner-only
x a throwing logger neither fails the gate nor throws again
Tests 2 failed | 4 passed | 168 skipped (174)
ablation-replace: blob after restore 865061d
ablation-replace: blob at HEAD 865061d
```
</details>
<details><summary>Derived gates (dispatch-gates --commands, reconciled
with --ran)</summary>
```
Run reconciliation — 67 derived, 65 run, 2 NOT-MEASURED, 0 UNRUN.
dispatch-gates --ran: 67 derived famil(ies) accounted for — 65 run, 2 NOT-MEASURED (2 DERIVED from a recorded exit 3).
```
NOT MEASURED: `check:dual-build-cjs-loads` and `check:i18n`. Reason:
both exit 3, PREREQUISITE NOT MET, because they need a repo-wide build
(58+ packages without `dist/`). CI runs both. As a direct substitute,
the rebuilt `plugin-sharing` `dist/index.js` (CJS) and `dist/index.mjs`
(ESM) both load and export `SharingService`. Also run, beyond the
derivation: `check:startup-registry-verdict` exit 0 and
`check:durability-log-level` exit 0.
</details>
Not run locally: the full `test:repo` project (CI `Test Core`), dogfood
(no `!` and no narrowing arm), and `pnpm lint` (CI-owned).
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibwJEh7hMPPvagWM1g7)_
<!-- signed: repo:objectstack#7 · os-tesla ·
session_01L9qibwJEh7hMPPvagWM1g7 -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 401eb44 commit d99b746
6 files changed
Lines changed: 221 additions & 9 deletions
File tree
- .changeset
- packages
- cli
- src
- commands
- utils
- test
- plugins/plugin-sharing/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 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5475 | 5475 | | |
5476 | 5476 | | |
5477 | 5477 | | |
5478 | | - | |
| 5478 | + | |
| 5479 | + | |
| 5480 | + | |
5479 | 5481 | | |
5480 | 5482 | | |
5481 | 5483 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
| 96 | + | |
96 | 97 | | |
97 | 98 | | |
98 | 99 | | |
99 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
100 | 122 | | |
101 | 123 | | |
102 | | - | |
103 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
104 | 127 | | |
105 | 128 | | |
106 | | - | |
| 129 | + | |
| 130 | + | |
107 | 131 | | |
108 | 132 | | |
109 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
110 | 137 | | |
111 | 138 | | |
112 | 139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
384 | 386 | | |
385 | 387 | | |
386 | 388 | | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
387 | 409 | | |
388 | 410 | | |
389 | 411 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
6 | 10 | | |
7 | 11 | | |
8 | 12 | | |
| |||
2367 | 2371 | | |
2368 | 2372 | | |
2369 | 2373 | | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
| 2381 | + | |
| 2382 | + | |
| 2383 | + | |
| 2384 | + | |
| 2385 | + | |
| 2386 | + | |
| 2387 | + | |
| 2388 | + | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
| 2397 | + | |
| 2398 | + | |
| 2399 | + | |
| 2400 | + | |
| 2401 | + | |
| 2402 | + | |
| 2403 | + | |
| 2404 | + | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
| 2409 | + | |
| 2410 | + | |
| 2411 | + | |
| 2412 | + | |
| 2413 | + | |
| 2414 | + | |
| 2415 | + | |
| 2416 | + | |
| 2417 | + | |
| 2418 | + | |
| 2419 | + | |
| 2420 | + | |
| 2421 | + | |
| 2422 | + | |
| 2423 | + | |
| 2424 | + | |
| 2425 | + | |
| 2426 | + | |
| 2427 | + | |
| 2428 | + | |
| 2429 | + | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
| 2438 | + | |
| 2439 | + | |
| 2440 | + | |
| 2441 | + | |
| 2442 | + | |
| 2443 | + | |
| 2444 | + | |
| 2445 | + | |
| 2446 | + | |
| 2447 | + | |
| 2448 | + | |
| 2449 | + | |
| 2450 | + | |
| 2451 | + | |
| 2452 | + | |
| 2453 | + | |
| 2454 | + | |
| 2455 | + | |
| 2456 | + | |
| 2457 | + | |
| 2458 | + | |
| 2459 | + | |
| 2460 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
443 | 443 | | |
444 | 444 | | |
445 | 445 | | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
446 | 470 | | |
447 | 471 | | |
448 | 472 | | |
| |||
682 | 706 | | |
683 | 707 | | |
684 | 708 | | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
685 | 723 | | |
686 | 724 | | |
687 | 725 | | |
| |||
2474 | 2512 | | |
2475 | 2513 | | |
2476 | 2514 | | |
2477 | | - | |
| 2515 | + | |
| 2516 | + | |
| 2517 | + | |
| 2518 | + | |
| 2519 | + | |
| 2520 | + | |
| 2521 | + | |
| 2522 | + | |
| 2523 | + | |
| 2524 | + | |
| 2525 | + | |
| 2526 | + | |
| 2527 | + | |
| 2528 | + | |
| 2529 | + | |
| 2530 | + | |
| 2531 | + | |
2478 | 2532 | | |
2479 | 2533 | | |
2480 | 2534 | | |
| |||
0 commit comments