Skip to content

fix(plugin-auth): Set Manager refuses only a person a SCIM directory holds - #33991

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/area-A1-33200
Nov 15, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/area-A1-33200

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Steedos · project thread

Fixes #33200
Clause-②: yes (widening)
Metadata-protocol: none

维护者速读

  • 改了什么: 「设置上级」(Set Manager) 现在只拒绝真正由 SCIM 目录同步的人;只通过 SSO 登录、背后没有目录的人,管理员可以照常改上级。按钮对平台管理员在每一行用户上都显示。
  • 为什么改: 托管环境里第一次通过平台 SSO 登录的人都会被标成 idp_provisioned,旧规则把他们全当成「目录持有」,登录后上级就再也改不了,按上级流转的审批跟不上组织调整。按裁决记录 6895645364 选项 A 修。
  • 风险与回滚: 只放宽:以前能成功的请求没有一个变成拒绝。SCIM 判定多读一次 sys_scim_subject,读失败返回 500 且不写入。回滚即 revert 本 PR。
  • 先看: admin-set-user-manager.ts 的 refusal 5 判断(applyUserManagerLink);scim-sso-adoption.ts 新导出的 isHeldByScimDirectory;sys-user.object.ts 的 set_user_manager visible。
  • 两分钟验证: pnpm --filter @objectstack/plugin-auth exec vitest run src/admin-set-user-manager.test.ts,预期 38 个全过,其中 "an SSO-only identity ... is SET like a local one" 为 200 并写入 manager_id。
  • 需要你做的: 无,席位落地。

What changes

Built to the maintainer ruling recorded in 6895645364 (option A: only identities a SCIM directory holds stay locked).

  • POST /api/v1/auth/admin/set-user-manager (refusal 5). It refused on sys_user.source = 'idp_provisioned' alone. ADR-0135 D4 stamps that value on every federated link without a local password, so a person who only signs in through SSO carried it with no directory behind them. The refusal now also needs a sys_scim_subject row. The answer for a SCIM-held identity keeps its envelope (403 PERMISSION_DENIED, details.reason: 'idp_provisioned'), and the message says to change the manager in the directory. It no longer claims a sync would revert the value, because nothing projects the SCIM manager attribute onto the column today. The self, cycle, depth and cross-organization refusals are unchanged.
  • One predicate, imported. scim-sso-adoption.ts now exports isHeldByScimDirectory(engine, userId). It is the same sys_scim_subject read its adoption judge already ran as condition 2, moved into an exported function. The judge calls it, and so does the endpoint. A missing sys_scim_subject table reads as "not held" at the endpoint. Any other read failure propagates, so the mount answers 500 and writes nothing.
  • The source term stays a conjunct. A SCIM-provisioned user with a local password is env_native under D4 and was accepted before. Requiring the SCIM row alone would have refused that user, so the endpoint still checks source too, and no request that was served before is refused now.
  • Bulk import and demo staff. Both run applyUserManagerLink, so their manager_id links follow the same rule with no code change. The import docblock now says who is refused.
  • sys_user.set_user_manager visibility is current_user.isPlatformAdmin == true. No column on the row says "held by SCIM", so the button is shown on every row and the endpoint refuses a SCIM-held one with its message. No new field or key.
  • Lint prescription. os explain approval-approvers-may-resolve-empty now says the operation refuses an identity a SCIM directory holds, and that an identity that only signs in through SSO is set like any other. The docblock in validate-approval-approvers.ts says the same.
  • Docs. content/docs/automation/approvals.mdx, content/docs/capabilities/approvals.mdx and content/docs/permissions/authentication.mdx state the narrowed refusal.
  • ⛔ The idp_provisioned stamp (ADR-0135 D4) and the password refusals are untouched.

Tests

On head fa70eaa06:

  • admin-set-user-manager.test.ts, refusal 5 rewritten. SCIM-held SET and CLEAR give 403 PERMISSION_DENIED / idp_provisioned, write nothing, and read sys_scim_subject for that user. SSO-only SET and CLEAR give 200, and update gets { id, manager_id }. An SSO-only self-assignment is still a 400 self_assignment. env_native gives 200, also with a SCIM subject, and the SCIM table is not read. A missing table gives 200. A failed read rejects and writes nothing.
  • admin-import-users-manager-pass.test.ts: a SCIM-held row is refused with idp_provisioned. An SSO-only row is linked, and manager_id is written. The no-fork pin also asserts that the importer spells neither sys_scim_subject nor isHeldByScimDirectory.
  • demo-staff.test.ts: the refusal fixture is now a SCIM-held identity.
  • sys-user-set-manager-action.test.ts and platform-objects.test.ts: the action is offered on an idp_provisioned row and on the sparse face. It is hidden from a non-admin. It reads no record column, which has a positive control on the standing term.
  • validate-approval-approvers.test.ts: the new prescription is present, and the old source 'idp_provisioned' sentence is absent.
Suite runs
  • @objectstack/plugin-auth full suite (locked, before the demo-staff fixture fix): 276/277 files. The one red was demo-staff.test.ts, whose fixture is fixed in the next commit. Re-run: demo-staff.test.ts + demo-staff-provisioning.test.ts 32/32.
  • Targeted: plugin-auth 3 files 76/76; platform-objects 2 files 169/169; lint 1 file 64/64.
  • @objectstack/platform-objects full: 122 files, 1994 tests passed. @objectstack/lint full: 212 files, 9026 tests passed.
  • Typecheck exit 0 for plugin-auth (all three legs, incl. check:test-typecheck), platform-objects and lint.
  • Dependent: @objectstack/runtime platform-admin-action-gate.test.ts 16/16.
Ablations (each mutation landed by ablation-replace.mjs, restored to the HEAD blob)
  • A1, refuse on source alone (the old predicate): 7 red, incl. every SSO-only pin in both endpoint and import suites.
  • A2, no refusal 5 at all: 4 red, incl. SCIM-held SET, CLEAR and the import row.
  • A3, refuse on the SCIM row alone (drop the source conjunct): 1 red, "env_native ... even one that owns a SCIM subject".
  • A4, swallow every SCIM read failure: 1 red, "a FAILED SCIM-subject read is never read as no directory".
  • A5, put the record.source term back on visible: 5 red across sys-user-set-manager-action.test.ts and platform-objects.test.ts.
  • A6, put the old lint sentence back: 1 red, "GRADES the routes".
  • A7, missing table rethrows: 1 red, "a missing sys_scim_subject table means no directory".

Acceptance notes

Verification

Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv

🤖 Generated with Claude Code

The directory refusal read sys_user.source = idp_provisioned alone, a mark
ADR-0135 D4 stamps on every SSO link without a local password, so an admin
could not change the manager of anyone who had signed in through SSO. It now
also requires a sys_scim_subject row, through the SCIM-held predicate the
adoption judge uses (extracted, not copied). Set Manager shows for every
platform admin; the lint remedy and docs say who is refused.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv
…tity

Its set-manager refusal now needs a sys_scim_subject row beside the
idp_provisioned mark, so the fixture carries one.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 15, 2026
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 3 package(s): @objectstack/lint, @objectstack/platform-objects, @objectstack/plugin-auth, touching 8 documentable anchor(s). ⚠️ 2 changed file(s) yielded no anchor (packages/lint/src/validate-approval-approvers.ts, packages/plugins/plugin-auth/src/admin-import-users.ts), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

2 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/automation/approvals.mdx (via idp_provisioned (literal, a string literal in a comment on a changed line; a string literal in actions; a string literal in applyUserManagerLink))
  • content/docs/permissions/authentication.mdx (via idp_provisioned (literal, a string literal in a comment on a changed line; a string literal in actions; a string literal in applyUserManagerLink))

⛔ 1 release-owned page(s) also name something this change touched. These are read-only:

  • content/docs/releases/v18/18-4.mdx (via idp_provisioned (literal, a string literal in a comment on a changed line; a string literal in actions; a string literal in applyUserManagerLink))

content/docs/releases/ is RELEASE-OWNED (AGENTS.md "Documentation Guardrails"): release
notes are written centrally at release time, and a code PR that edits them is the exact PR
that guardrail exists to stop. They are still audited — read-only. If one of them is actually
wrong, file an issue or open a dedicated docs-only PR; do not edit it here.

What this run could not see
  • 2 changed file(s) yielded no anchor (packages/lint/src/validate-approval-approvers.ts, packages/plugins/plugin-auth/src/admin-import-users.ts) — pages documenting those are invisible to this run
  • 1 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 65 of 247 client-bound route-ledger rows — the other 182 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 182: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 123 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 26 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json bc6b7ffd454ba9c2c420975c84a400779cb02262 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 866f210f821ba351173e709307ba23ac5f7ff840 — the merge of head 5787dda5126ee75af2bb2cef8ab2f1b5d3776d33 into base bc6b7ffd454ba9c2c420975c84a400779cb02262, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 866f210f821ba351173e709307ba23ac5f7ff840 && git checkout 866f210f821ba351173e709307ba23ac5f7ff840
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin bc6b7ffd454ba9c2c420975c84a400779cb02262 5787dda5126ee75af2bb2cef8ab2f1b5d3776d33 && git checkout -B drift-repro bc6b7ffd454ba9c2c420975c84a400779cb02262 && git merge --no-ff 5787dda5126ee75af2bb2cef8ab2f1b5d3776d33

node scripts/docs-audit/affected-docs.mjs --json bc6b7ffd454ba9c2c420975c84a400779cb02262

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs bc6b7ffd454ba9c2c420975c84a400779cb02262 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#5 · zhuangjianguo · session_01QsR2jVPGBoi3MCGoKbW1Hv

Contract review

Served-tier: TIER_DEFAULT
Head-sha: fa70eaa067974408121386101990b9804fb5e08a
Local-runs: none
Scope: packages/plugins/plugin-auth/src/admin-set-user-manager.ts, packages/plugins/plugin-auth/src/scim-sso-adoption.ts, packages/platform-objects/src/identity/sys-user.object.ts, packages/plugins/plugin-auth/src/admin-import-users.ts, packages/lint/src/validate-approval-approvers.ts, packages/lint/src/rule-explanations.ts + the PR's pins and docs

① Derived judgments

  • The face owed is the Clause-②: yes (widening) declaration alone: no packages/spec/src/** file, no governed path, no narrowing line. Read from the PR's file list and body.
  • Widening as declared, matching ruling record 6895645364 (option A): refusal 5 now fires only for source = idp_provisioned AND a sys_scim_subject row, so an SSO-only identity's manager is set like a local user's. The predicate is imported from scim-sso-adoption.ts (isHeldByScimDirectory), not copied; judgeScimSsoAdoption reads the same function.
  • Nothing served is refused: the source conjunct stays, so a SCIM-provisioned user that D4 leaves env_native keeps today's answer; the four other refusals are untouched. A missing sys_scim_subject table answers "not held"; any other read failure propagates as a 500 that writes nothing (fail closed).
  • sys_user Set Manager visible drops the record.source term and keeps the platform-admin term (ADR-0068 D4); no new column or flag. ⛔ ADR-0135 D4 stamp untouched.
  • Lint prescription, import docblock and three docs pages restate the narrowed refusal; no rule id, severity or key changes.

② Semver level

minor-or-patch behaviour widening on a server door: no schema, export of a published package surface, key or wire field added or removed. isHeldByScimDirectory is a module export inside plugin-auth, not a barrel export. Changeset patch is acceptable.

③ Boundary flags

  • Access boundary: a write refused today (admin sets an SSO-only user's manager) now lands, exactly the ruled widening; the caller gate (platform admin) is unchanged.
  • No served→refused change, so no !, BREAKING banner or ADR-0087 marker owed.
  • Pins: SSO-only → 200 + manager_id written; SCIM-held → 403 directory sentence (reverse); env_native unchanged; button visibility; 7 ablations red per the dev report 6896940762.

Implemented-by: claude/area-A1-33200
Reviewed-by: session_01QsR2jVPGBoi3MCGoKbW1Hv

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#5 · zhuangjianguo · session_01QsR2jVPGBoi3MCGoKbW1Hv

Request: review · PR #33991 · S1/A1 · Fixes #33200 · head fa70eaa · 2026-11-15T16:06Z

Reviewer: review-a of seat domain:server#5, ordinary ACCEPT read per review-checklist.md. Dev report 6896940762; TIER_DEFAULT contract record PASS 6896964420 (Clause-② yes widening); surface amendment 6896971149. Checks at this head: 58 success, 10 skipped, 0 red.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#5 · zhuangjianguo · session_01QsR2jTjrNnh6b2BkCXFugM
Review claim (review-a, S1) · head fa70eaa · 2026-11-15T16:07Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#5 · zhuangjianguo · session_01QsR2jTjrNnh6b2BkCXFugM

Review — PASS

Head-sha: fa70eaa067974408121386101990b9804fb5e08a
Reviewer: review-a (areas S1 + S3) · read 2026-11-15T16:09Z · diff read against the merge's main parent 895783a1 (16 files, +302/−96, matches the PR files list)
Implemented-by: session_01QsR2jVPGBoi3MCGoKbW1Hv (area S1 dispatch) · Reviewed-by: session_01QsR2jTjrNnh6b2BkCXFugM

Contract face: Clause-②: yes (widening) with no narrowing arm, no packages/spec/src path and no governed text, so the record is owed at TIER_DEFAULT. The area's record is comment 6896964420 (PASS). This verdict is the ordinary ACCEPT read of the whole diff.

What holds

  • The rule matches the ruling. Refusal 5 now needs both source === 'idp_provisioned' and a sys_scim_subject row. That is option A of ruling record 6895645364: "directory wins" applies only where a directory exists. Because source stays a conjunct, a SCIM-linked user with a local password (still env_native) keeps the answer it had. That case is pinned, and so is the fact that no SCIM read happens for it.
  • One predicate, not a copy. isHeldByScimDirectory is lifted out of judgeScimSsoAdoption, and the adoption judgement's behaviour is unchanged. The endpoint imports it. The import's manager_id column reaches it through applyUserManagerLink, and a source pin checks that the import names neither the table nor the predicate.
  • Fails closed. Only isMissingTableError(e, 'sys_scim_subject') reads as "not held". That passes readObject, as the callers gate requires, and follows the scim-identity-source.ts precedent. Any other read failure propagates and writes nothing, which is pinned. sys_scim_subject is a registered platform object, so an install without SCIM reaches the missing-table leg, not an unknown-object error.
  • Widening only. The code, status and details.reason of the refusal are unchanged, and only the sentence changes. The self-assignment, cycle, depth and cross-organization refusals still apply to an SSO-only identity, which is pinned for self-assignment. Nothing accepted before is refused now. The Set Manager action's visible predicate drops to the standing platform-admin predicate. The endpoint still refuses a SCIM-held row and names the directory, so the button cannot write what the door refuses. The feature-gate matrix row is updated to match.
  • The text is true of the doors. The lint remedy, the docblocks, the three docs pages and the changeset all say "a SCIM directory holds" and give the SSO-only path. The lint test asserts that the old source 'idp_provisioned' sentence is gone. The changeset patches all three published packages, and Metadata-protocol: none is right because no authorable key moves.
  • Tests. Set and clear on a SCIM-held identity are both refused. Set and clear on an SSO-only identity both land. The missing-table and failed-read legs and the import rows (SCIM-held refused, SSO-only linked) are covered, and the demo-staff harness reads the subject table. I accept the 7 ablations as reported.

Nits (no re-review needed)

  1. The predicate's docblock says the vendor never deletes a sys_scim_subject row. So a person whose SCIM connection was later removed stays refused, and the message sends the admin to a directory that is gone. That is no regression, because before this PR every idp_provisioned row was refused. File it only if someone measures it.

Gates: at review time 58 success, 10 skipped, none red, so every check is green.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#5 · zhuangjianguo · session_01QsR2jVPGBoi3MCGoKbW1Hv

席位核对 · ACCEPT · Head-sha: 5787dda · 2026-11-15T16:48Z

  • Review: review-a ACCEPT read PASS 6897400766 at fa70eaa; this head is a clean origin/main merge through the relay (pr_update_branch, K was 18), same patch-id (2472fff7) as the reviewed head, so the PASS carries. Nit recorded, not owed: a person whose SCIM connection was later removed stays refused (not a regression).
  • Contract face: Clause-②: yes (widening) only ⇒ TIER_DEFAULT record PASS 6896964420 (same patch-id). Metadata-protocol: none. Nothing served is refused, so no ! or dogfood battery owed.
  • Card relation: Fixes #33200 — the whole ruling (6895645364, option A) is delivered; follow-up SCIM: project the enterprise manager attribute into sys_user.manager_id, so SCIM-held users' managers can change at all #33918 (SCIM manager projection) is a separate card.
  • Changeset and docs sentences checked against the diff: changeset ".changeset/33200-set-manager-scim-held-only.md" (all five paragraphs: the old refusal and its cause in ADR-0135 D4; the narrowed refusal with details.reason unchanged and the import's manager_id column; Set Manager offered on every row to a platform admin; the os explain approval-approvers-may-resolve-empty text; D4 stamp unchanged); content/docs/automation/approvals.mdx (SCIM-held refusal incl. the import column, SSO-only set like anyone else); content/docs/capabilities/approvals.mdx (the set-user-manager sentence); content/docs/permissions/authentication.mdx (the new four-line paragraph). Each matches admin-set-user-manager.ts refusal 5, admin-import-users.ts and sys-user.object.ts in the diff.
  • Governed: check-governed-merges --pr 33991 NOT governed, 0 of 16 paths on the register, +302/−96.
  • Checks on this head: 58 success, 10 skipped (path-filtered), 0 red, 0 pending; Lint & Repo Gates and TypeScript Type Check success. Mergeable state clean.
  • Landing: area S1, on the maintainer's line in the area thread (2026-11-15T11:06Z). pr_ready + automerge_enable follow in this stroke.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 15, 2026 16:48
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit fb79d47 Nov 15, 2026
69 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/area-A1-33200 branch November 15, 2026 17:15
scbdzhwl pushed a commit to scbdzhwl/objectstack-analysis that referenced this pull request Nov 16, 2026
…wered with the generic message and logged (objectstack-ai#34050)

Clause-②: no
Metadata-protocol: none

## 维护者速读

- 改了什么:plugin-auth 三个辅助结果映射器(admin 用户门共用的
`mapAuthApiError`、服务账号注册的成员映射、`set-initial-password` 映射)以及
`sys-oauth-application/register` 路由的内层 catch,对未分类的内部故障改答通用文案,并用插件已有的
logger 按路由名记一次 error 日志。
- 为什么改:与 `auth-plugin.ts` 各路由 catch
已执行的同一条规则对齐:未分类的内部故障只答通用文案并在服务端记日志;厂商带 body code 的拒绝、4xx 的拒绝保持原样。
- 风险与回滚:仅 500 类答复的 message 文本变化,code(`INTERNAL_ERROR`)与 status
不变;无文档或客户端解析该文本。回滚即还原本 PR。
-
先看:`packages/plugins/plugin-auth/src/admin-user-endpoints.ts`(`mapAuthApiError`
的分类分支)、`auth-plugin.ts`(`sys-oauth-application/register` 内层
catch)、`service-account-doors.ts`(`vendorRefusal`)。
- 两分钟验证:`pnpm --filter @objectstack/plugin-auth exec vitest run
--maxWorkers=2 src/set-initial-password.test.ts`,预期全部通过,其中「an
unclassified internal failure is answered with the generic message and
logged once」一组为绿。
- 需要你做的:无,席位落地

## What changes

The rule, already applied by every route catch in `auth-plugin.ts`: a
route's unclassified internal failure is answered with a generic
message, and the error is logged server-side. A refusal the vendor
classifies (it carries a body code) keeps its own message and status,
and so does a throw whose status addresses the caller (4xx). This PR
applies it to the three result mappers the auth doors answer through,
and to one route catch that did not yet follow it:

- `mapAuthApiError` (`admin-user-endpoints.ts`), shared by create-user,
set-user-password, import-users, add-sso-user / import-sso-users
(organization join) and `/organization/add-member`: an unclassified
failure answers `INTERNAL_ERROR` with `INTERNAL_ERROR_MESSAGE` from
`@objectstack/types`, the constant those routes' own catches use, and is
logged once as `[AuthPlugin] ROUTE failed`.
- `vendorRefusal` (`service-account-doors.ts`), the membership step of
`/service-account/register`: after the existing declared-refusal check,
an unclassified failure answers `INTERNAL_ERROR` with `The request could
not be completed.`, the words that route's own catch (and this file's
`WITHHELD_SERVER_MESSAGE`) uses, and is logged once as `[AuthPlugin]
service-account/register failed`.
- `mapSetPasswordError` (`set-initial-password.ts`): an unclassified
failure answers `INTERNAL_ERROR` with `INTERNAL_ERROR_MESSAGE`, logged
once as `[AuthPlugin] set-initial-password failed`.
- The inner catch of `POST /sys-oauth-application/register`
(`auth-plugin.ts`, the client-creation call): a throw with no vendor
body and no 4xx status answers `OAUTH_REGISTER_FAILED` with
`INTERNAL_ERROR_MESSAGE` (the constant the route's outer catch uses) at
the status `resolveThrownHttpError` reads, logged once with `ctx.logger`
as `[AuthPlugin] sys-oauth-application/register failed`. A vendor
refusal (it carries a body) keeps its `error_description`, its
`details.upstreamError` and its status.

Logging seam: each helper is handed the logger the plugin already holds
(`ctx.logger`), through an optional `logger` on its deps or options
(`error` added as optional to the existing `logger` on
`AdminUserEndpointDeps`, `IdentityImportDeps`, `PendingSsoUserDeps`; a
new optional `logger` on `OrganizationAddMemberDeps`,
`ServiceAccountDoorDeps`, `SetInitialPasswordOptions`; an optional third
argument on `mapAuthApiError`). Otherwise `auth-plugin.ts` gains only
those hand-offs at three call sites (`set-initial-password`, the
service-account deps factory, `/organization/add-member`); no other
route catch, no before-hook and no vendor-classified refusal changes. No
new dependency, no module-level console, no new error code, nothing in
`packages/spec`.

**Why this is not breaking.** For each changed answer the status and the
code (`INTERNAL_ERROR`, or `OAUTH_REGISTER_FAILED` at the OAuth
registration) are unchanged; only the message of an unclassified
internal failure changes. Measured: no page under `content/docs/**`
names these routes' 500 message text, the error catalog
(`packages/spec/src/api/errors.zod.ts`, the error-code ledger) pins the
code only, and `git grep` over `ui/`, `packages/client` and
`packages/client-react` finds no consumer that reads these fallback
texts. Every refusal (a vendor body code, a declared hook refusal, a 4xx
status) answers byte-identically. The new deps fields and the third
argument are optional, so an existing host compiles and answers the
generic message without a log line. Hence a `patch` changeset with
`Clause-②: no`.

## Tests

Named by the rule, each helper beside its CONTROLs:

- `set-initial-password.test.ts` — the existing unclassified-throw row
now asserts the rule: the generic answer, and the logger called once
with the route and the error; a thrown non-Error reaches the logger as
an `Error`; CONTROL a vendor body-coded refusal keeps its message, code
and status and is not logged; CONTROL a 4xx throw keeps its answer.
- `admin-user-endpoints.test.ts` — the shared mapper directly, then
through create-user and set-user-password; CONTROLs for a vendor
body-coded refusal (409 normalisation included) and a 4xx throw.
- `organization-add-member.test.ts`, `admin-import-users.test.ts` — the
two other mapper callers hand the logger on; CONTROL a vendor body-coded
refusal at add-member.
- `oauth-register-refusal-status.test.ts` — on the real route over real
better-auth: a client-creation call that throws with no declared status
answers 500 in the generic words and the route's log line receives the
error once; CONTROL a vendor refusal keeps the vendor's own description,
`upstreamError` and status, with no log line. The file's existing pins
(declared 4xx statuses, the storage fault at 500, the accepted
registration) stay green.
- `service-account-doors.test.ts` — the membership step: generic answer,
logged once, nothing written; CONTROL a vendor body-coded refusal keeps
its prefixed message and status; CONTROL a 4xx throw keeps its answer.
The suite's deps now carry the logger.

<details><summary>Measured before the fix (rule rows red), and the suite
after</summary>

- Before (the rule tests against the source of the base commit, tests
otherwise as in this PR): `Test Files 5 failed (5) · Tests 8 failed |
194 passed (202)`; the 8 failures are exactly the unclassified rows
across the three mappers; every CONTROL passed. The OAuth registration
row, before its fix: `Tests 1 failed | 8 passed (9)`, the CONTROL
passing.
- After, `pnpm --filter @objectstack/plugin-auth exec vitest run
--maxWorkers=2` at `dbe556761a`: `Test Files 277 passed (277) · Tests
5531 passed | 10 skipped (5541)`, lock VERDICT command-exit 0.
- `pnpm --filter @objectstack/plugin-auth typecheck` (after building the
package for its examples program): exit 0; `check:test-typecheck: OK`.

</details>

## Acceptance notes

- The cloud twin of `set-initial-password` calls `runSetInitialPassword`
without a logger: it now answers the generic message, and logs only once
it passes its own logger in `SetInitialPasswordOptions.logger`.
- A body-less throw with a 4xx status keeps its message at these mappers
(the repo's thrown-error rule: a 4xx message is addressed to the
caller). Such a throw is still answered with the code `INTERNAL_ERROR`
rather than a code its status derives; that pre-existing labelling is
unchanged here.
- `PR objectstack-ai#33991` touches a docblock of `admin-import-users.ts` far from
these hunks; no overlap.

## Verification

<details><summary>Ablation: each site's generic arm put back to the
thrown-message arm, then restored</summary>

Each mutation went through `scripts/ablation-replace.mjs` (anchor hit 1
to 0, blob changed) on a committed head, and each restore was proven by
the tool (blob equal to HEAD, `git diff HEAD` empty):

- `set-initial-password.ts`: `Tests 2 failed | 9 passed (11)`, then
restored.
- `admin-user-endpoints.ts` (`mapAuthApiError`, with the add-member and
import-users suites): `Tests 5 failed | 156 passed (161)`, then
restored.
- `service-account-doors.ts`: `Tests 1 failed | 29 passed (30)`, then
restored.
- `auth-plugin.ts` (the OAuth registration inner catch): `Tests 1 failed
| 8 passed (9)`, then restored.

The tests import each subject from `src/` by relative path, so no
`dist/` sits between the mutation and the run.

</details>

Local readings on the final head `8c878cc253`:

- `dispatch-gates --commands`: 76 families derived, all 76 run (`--ran`:
76 derived, 76 run, 0 NOT-MEASURED, 0 UNRUN), every exit 0.
`check:optional-error-sink` flagged the first logger shape at
`dbe556761a`; the fix is in this head and the gate now exits 0.
- Dogfood battery, under the verify lock: `Test Files 467 passed | 3
skipped (470)` · `Tests 3962 passed | 42 skipped (4004)`, no failures,
VERDICT command-exit 0.

Every other family is CI's.

---
_Generated by [Claude
Code](https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f)_

<!-- signed: security#1 · sunhaolin · session_017xRBcT1w3zpekijraHJE4f
-->

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

1 participant