Skip to content

fix(plugin-auth): a SCIM PATCH of only the name parts recomposes a derived display name - #38181

Merged
objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/issue-32380-scim-name-recompose
Nov 28, 2026
Merged

objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/issue-32380-scim-name-recompose

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Fixes #32380
Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:企业身份系统(Okta、Entra)只改员工的名或姓时,控制台显示的姓名现在随之更新;单独设定、与名和姓不同的显示名保持不变。
  • 为什么做:属于企业单点登录与用户同步,替只同步名和姓的租户解决旧名长期不变的问题,按维护者「现在临时修、同时修源头」的裁决执行。
  • 出错会怎样:只同步名或姓的租户会看到显示名被改成「名 姓」;去掉这个临时补丁即可直接撤回到原来的行为。
  • 要你做什么:确认下文「边界情况」可以接受(身份系统明确发来、但恰好等于「名 姓」的显示名,改名时也会被重新拼接,供应商自己的测试要求保留它),然后把文末上游草稿提交给供应商。

What changes

  • patches/@better-auth__scim@1.7.12.patch (new, written with pnpm patch / pnpm patch-commit): a TEMPORARY vendor patch by maintainer ruling record 6845302116 (option C), with a header naming the ruling and its removal condition. In setNamePart, it recomposes name.formatted (and, through the vendor's own setFormattedName, displayName) with the vendor's own composeName when name.formatted equalled composeName of the parts before the part changed. Four lines in dist/index.mjs; nothing else in the package moves.
  • pnpm-workspace.yaml: the patchedDependencies row beside the three existing patches, plus a note in the block's comment (ruling, what it fixes, who receives it, removal condition). patch-commit wrote the key into package.json's pnpm field; it was moved here as the block's own comment prescribes, and package.json is unchanged.
  • pnpm-lock.yaml: as pnpm wrote it (the patch hash on the @better-auth/scim snapshot).
  • packages/plugins/plugin-auth/src/scim-name-recompose.test.ts (new): the regression pin, every case through AuthManager.handleRequest() with a real SCIM bearer on a real ObjectQL over better-sqlite3.

No changeset, skip-changeset: the published @objectstack/plugin-auth tarball (files: dist, README.md, CHANGELOG.md) is byte-for-byte what it was; @better-auth/scim is an external dependency of its bundle, and a pnpm patch applies only to installs of THIS workspace (dev, CI, and the framework build base image built from it), never to an npm install of the published package. A changelog line would tell npm consumers about a fix their install does not get. Measured, see Verification.

Read first (by risk)

  1. patches/@better-auth__scim@1.7.12.patch, the setNamePart hunk: the derived test is a VALUE test (state.formattedName === composeName(state), read BEFORE the assignment). That line decides every case below, including the edge one.
  2. packages/plugins/plugin-auth/src/scim-name-recompose.test.ts, case (c): the edge where the value test and the vendor's own suite disagree.
  3. pnpm-workspace.yaml, the patchedDependencies note: what removes the patch.

Tests

  • (a) Entra path-addressed (Replace on name.givenName and name.familyName) and Okta path-less (replace with dotted keys): displayName, name.formatted and sys_user.name move to the new parts; an unrelated PATCH (title) afterwards keeps the new name (the vendor rewrites sys_user.name from its stored displayName on every profile PATCH).
  • (b) CONTROLS: an explicit displayName (which seeds name.formatted at create) survives a part change; an explicit name.formatted survives, with the displayName derived from it; a displayName set by an earlier PATCH survives while the derived name.formatted moves; a displayName sent in the same PATCH as the parts wins, in both operation orders.
  • (c) EDGE: a displayName and name.formatted supplied explicitly but EQUAL to the composed parts read as derived and move. Pinned on purpose, so the upgrade PR that removes the patch reads the reversal (Acceptance notes).
Red without the patch, green with it (tree 58bebae, patch registration removed and reinstalled for the red run)

Red (patch row deleted from pnpm-workspace.yaml, pnpm install, installed vendor dist/index.mjs carrying 0 occurrences of the patched line):

os-verify-lock: VERDICT command-exit 1
     × (a) Entra path-addressed: displayName, name.formatted and sys_user.name move with the parts
     × (a) Okta path-less: displayName, name.formatted and sys_user.name move with the parts
     × (b) CONTROL: a displayName set by an earlier PATCH survives; only the derived formatted name moves
     × (c) a formatted and display name supplied explicitly but EQUAL to the parts reads as derived and moves
     × (b) CONTROL: a displayName sent with the parts wins (displayName first)
     × (b) CONTROL: a displayName sent with the parts wins (displayName last)
 Test Files  1 failed (1)
      Tests  6 failed | 2 passed (8)
-   "displayName": "Entra Style",
+   "displayName": "Renamed InOkta",
-   "formatted": "Entra Style",
+   "formatted": "Renamed InOkta",
-   "userName": "Entra Style",
+   "userName": "Renamed InOkta",

The two that pass red are the explicit-name controls, which assert preservation and hold either way. This red run is also the re-measure of the card's premise on current main: both shapes still leave the old name.

Green (registration restored with git restore --source=HEAD, pnpm install --frozen-lockfile):

os-verify-lock: VERDICT command-exit 0
 Test Files  1 passed (1)
      Tests  8 passed (8)
Whole package, with the patch (tree 6206923)

pnpm --filter @objectstack/plugin-auth build && pnpm --filter @objectstack/plugin-auth typecheck && pnpm --filter @objectstack/plugin-auth exec vitest run --maxWorkers=2, under the shared verify lock:

os-verify-lock: VERDICT command-exit 0
check:test-typecheck: OK — @objectstack/plugin-auth's test layer compiles under packages/plugins/plugin-auth/tsconfig.test.json
 Test Files  297 passed (297)
      Tests  6313 passed | 10 skipped (6323)

Every other SCIM suite in the package (deactivation, manager and group projection, SSO adoption, transaction scope, refusal audit) runs over the patched vendor and stays green.

Final head c40d3488e5 is 6206923 plus a merge of origin/main; that merge changes no file under packages/plugins/plugin-auth, patches/, pnpm-lock.yaml, pnpm-workspace.yaml or package.json (git diff --stat 6206923a6 c40d3488e5 -- ... is empty). The re-run of the SCIM suites on the final head is NOT MEASURED: the shared verify lock was not acquired in three 9-minute windows behind another session's dogfood run. CI's Test Core runs the package on this head.

Acceptance notes

  • The value test reverses one vendor-pinned case. @better-auth/scim's own suite at v1.7.12 (and at main, 1.7.28) carries preserves explicitly supplied formatted and display names when patching one name part: create with displayName and name.formatted both Ada Lovelace and parts Ada / Lovelace, PATCH name.givenName to Augusta, expect both names kept. The vendor stores no record of whether a name was supplied or composed, so the ruled test (the value test setFormattedName already makes) reads that shape as derived and recomposes it to Augusta Lovelace; case (c) pins it. Every explicit name that differs from the parts is still kept (b). The upstream draft below changes that vendor test's fixture to an explicit name that differs from the parts; if the vendor wants the equal case preserved, the only fix is a persisted provenance bit, which is a larger vendor change.
  • Who receives the fix. Every install of this workspace, so every image built from the framework build base and every dev and CI run. An npm install of the published @objectstack/plugin-auth resolves an unpatched @better-auth/scim until the vendor ships the recompose (ruling item 3).
  • Not covered by the value test. A user created with no name parts has name.formatted = the primary email; a later PATCH that adds parts does not recompose it (the email is not composed from parts). Removing both parts one by one leaves name.formatted on the last single part (composeName of nothing is empty, and an empty name is never written).
  • pnpm patch-commit writes patchedDependencies into package.json's pnpm field, duplicating the three existing rows there; the comment in pnpm-workspace.yaml already says to move it, which this PR did.

Verification

Two-minute check: pnpm --filter @objectstack/plugin-auth exec vitest run --maxWorkers=2 src/scim-name-recompose.test.ts after pnpm install and a build of @objectstack/plugin-auth's dependencies; expect Tests 8 passed (8). Then delete the @better-auth/scim@1.7.12 row from pnpm-workspace.yaml, pnpm install, re-run: expect 6 failed | 2 passed (8).

Local gates (the 61 derived families)

node scripts/pm/dispatch-gates.mjs --commands derived 61 families for this change set; all 61 were run on the final head c40d3488e5, exit code captured before any pipe and recorded per line. --ran reconciliation: 61 derived famil(ies) accounted for — 60 run, 1 NOT-MEASURED (1 DERIVED from a recorded exit 3). 60 exited 0. pnpm check:type-check-debt exited 3 (prerequisite not met: the merge moved packages/spec and the package builds it re-measures were not refreshed, because the verify lock was not acquired); on the pre-merge head 58bebae it read 0 ledger entr(ies) re-measured in 817.5s, 0 raw tsc error(s) total. It is NOT MEASURED on the final head; CI runs it. check:test-source-alias was red on the first draft of the new test (the SSO egress guard loaded inside a case) and is green after the module-top import.

Published-content check (positive control included): after building @objectstack/plugin-auth, the patched line occurs in 0 files of its dist/, while dist/index.js and dist/index.mjs import @better-auth/scim as an external dependency, so the tarball carries the vendor as a reference and none of its code.

Upstream draft (for the maintainer to submit)

Against better-auth/better-auth main (8c5c68010b, packages/scim 1.7.28, where setNamePart is unchanged from 1.7.12). Agents cannot open it; NOT MEASURED against the vendor's own suite (its workspace was not installed here), so run pnpm --filter @better-auth/scim test before submitting.

Title: fix(scim): recompose derived name.formatted and displayName when a name part changes

Description: A SCIM User PATCH that replaces only name.givenName and/or name.familyName (Microsoft Entra ID sends one path-addressed Replace per part; Okta sends a path-less replace whose value carries name.givenName / name.familyName keys) updates the parts but leaves name.formatted, displayName and the backing Better Auth user's name on the old name. setNamePart stores the part and never recomposes, while composeName is used only by the name.formatted remove path, so an identity provider whose attribute mapping sends only the parts keeps showing the old name indefinitely; only a displayName PATCH or a full PUT moves it. This change recomposes name.formatted in setNamePart when it equalled composeName of the parts before the change, and lets setFormattedName carry displayName along when that was derived from name.formatted, the same derived-value test setFormattedName already makes. A formatted or display name that differs from the parts is never overwritten. One existing test changes: preserves explicitly supplied formatted and display names when patching one name part used an explicit name equal to the composed parts, which the stored state cannot tell from a derived one; its fixture now uses explicit names that differ from the parts, so it still pins preservation.

diff --git a/packages/scim/src/scim-user-patch.test.ts b/packages/scim/src/scim-user-patch.test.ts
index 859ee43..81f958b 100644
--- a/packages/scim/src/scim-user-patch.test.ts
+++ b/packages/scim/src/scim-user-patch.test.ts
@@ -710,9 +710,9 @@ describe("SCIM User PATCH provider compatibility", () => {
 			body: {
 				schemas: ["urn:ietf:params:scim:schemas:core:2.0:User"],
 				userName: "explicit-name@example.com",
-				displayName: "Ada Lovelace",
+				displayName: "Countess Lovelace",
 				name: {
-					formatted: "Ada Lovelace",
+					formatted: "Augusta Ada King, Countess of Lovelace",
 					givenName: "Ada",
 					familyName: "Lovelace",
 				},
@@ -741,15 +741,103 @@ describe("SCIM User PATCH provider compatibility", () => {
 				headers,
 			}),
 		).resolves.toMatchObject({
-			displayName: "Ada Lovelace",
+			displayName: "Countess Lovelace",
 			name: {
-				formatted: "Ada Lovelace",
+				formatted: "Augusta Ada King, Countess of Lovelace",
 				givenName: "Augusta",
 				familyName: "Lovelace",
 			},
 		});
 	});
 
+	it.each([
+		[
+			"Entra path-addressed",
+			[
+				{ op: "Replace", path: "name.givenName", value: "Augusta" },
+				{ op: "Replace", path: "name.familyName", value: "King" },
+			],
+		],
+		[
+			"Okta path-less",
+			[
+				{
+					op: "replace",
+					value: { "name.givenName": "Augusta", "name.familyName": "King" },
+				},
+			],
+		],
+	])("recomposes derived formatted and display names when the name parts change (%s)", async (_shape, Operations) => {
+		const { auth, data, headers } = createTestContext();
+		const created = await auth.api.createSCIMUser({
+			body: {
+				schemas: ["urn:ietf:params:scim:schemas:core:2.0:User"],
+				userName: "derived-name@example.com",
+				name: { givenName: "Ada", familyName: "Lovelace" },
+			},
+			headers,
+		});
+		expect(created).toMatchObject({
+			displayName: "Ada Lovelace",
+			name: { formatted: "Ada Lovelace" },
+		});
+
+		await auth.api.patchSCIMUser({
+			params: { userId: created.id },
+			body: { schemas: [PATCH_OP_SCHEMA], Operations },
+			headers,
+		});
+
+		await expect(
+			auth.api.getSCIMUser({
+				params: { userId: created.id },
+				headers,
+			}),
+		).resolves.toMatchObject({
+			displayName: "Augusta King",
+			name: {
+				formatted: "Augusta King",
+				givenName: "Augusta",
+				familyName: "King",
+			},
+		});
+		expect(getPersistedUser(data, created.id).user.name).toBe("Augusta King");
+	});
+
+	it("keeps a separately patched display name when a part recomposes the formatted name", async () => {
+		const { auth, headers } = createTestContext();
+		const created = await auth.api.createSCIMUser({
+			body: {
+				schemas: ["urn:ietf:params:scim:schemas:core:2.0:User"],
+				userName: "chosen-display@example.com",
+				name: { givenName: "Ada", familyName: "Lovelace" },
+			},
+			headers,
+		});
+
+		await auth.api.patchSCIMUser({
+			params: { userId: created.id },
+			body: {
+				schemas: [PATCH_OP_SCHEMA],
+				Operations: [
+					{ op: "replace", path: "displayName", value: "Countess Lovelace" },
+					{ op: "replace", path: "name.givenName", value: "Augusta" },
+				],
+			},
+			headers,
+		});
+
+		await expect(
+			auth.api.getSCIMUser({
+				params: { userId: created.id },
+				headers,
+			}),
+		).resolves.toMatchObject({
+			displayName: "Countess Lovelace",
+			name: { formatted: "Augusta Lovelace", givenName: "Augusta" },
+		});
+	});
+
 	it("rejects whitespace inside a simple PATCH attribute path", async () => {
 		const { auth, headers } = createTestContext();
 		const created = await auth.api.createSCIMUser({
diff --git a/packages/scim/src/user-patch.ts b/packages/scim/src/user-patch.ts
index 80ff46f..24e1566 100644
--- a/packages/scim/src/user-patch.ts
+++ b/packages/scim/src/user-patch.ts
@@ -242,7 +242,12 @@ function setNamePart(
 		| "middleName",
 	value: string | undefined,
 ): void {
+	const formattedNameWasDerived = state.formattedName === composeName(state);
 	state[attribute] = value;
+	const composedName = composeName(state);
+	if (formattedNameWasDerived && composedName) {
+		setFormattedName(state, composedName);
+	}
 }
 
 function setEmails(

Generated by Claude Code

…rived display name

Temporary pnpm patch on @better-auth/scim 1.7.12 (maintainer ruling record
6845302116, option C): setNamePart recomposes name.formatted, and through
setFormattedName displayName, when name.formatted was composed from the parts
before the part changed. An explicit name is never overwritten. Removed in the
upgrade PR to the vendor release that ships the recompose; the regression pin
scim-name-recompose.test.ts stays.

Claude-Session: https://claude.ai/code/session_017xRBcSAaBEfQpU2yJexSJ8
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet objectstack-fleet Bot added the skip-changeset PR has no user-facing published change; bypasses the changeset gate label Nov 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

Nothing in this diff resolved to a documentable surface (no symbol, route or SDK anchor derived from 0 changed package(s)), so this run has no opinion about the docs.

What this run could not see

Coarse fallback — 0 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 7605e0c9cca2b890e48a47117d4518ae9c602f27 → packageMentionDocs.

@github-actions github-actions Bot added dependencies Pull requests that update a dependency file tests labels Nov 28, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#8 · sunhaolin · session_017xRBcSAaBEfQpU2yJexSJ8

L1: ACCEPT · head c40d3488e587f27aa90a5dec3e3089ed3cc59087 · 2026-11-28T07:04Z · card #32380

席位核对

  1. Shape — draft on main, mergeable_state clean, first line Fixes #32380 only, Clause-②: no · Metadata-protocol: none, skip-changeset. Fixes is right: ruling 6845302116 items (1) the upstream draft (in the PR body, for the maintainer to submit) and (2) the temporary patch + regression pin are delivered; item (3) is the future upgrade PR by the ruling's own words.
  2. Premise measured — both PATCH shapes (Entra path-addressed, Okta path-less) re-measured through AuthManager.handleRequest with a real SCIM bearer on current main: displayName, name.formatted, sys_user.name stay on the old name. Registration ablation: patch row removed + reinstall ⇒ Tests 6 failed | 2 passed (8) (the two passing are the explicit-name CONTROLs); restored ⇒ 8 passed (8).
  3. Gates at this head — 60 success · 12 expected skip · 0 failed · 0 pending; Lint & Repo Gates and TypeScript Type Check success. NOT governed (+429/−2).
  4. Read by the seat — the patch: 4 lines in the vendor's setNamePart, recomposing through the vendor's own composeName / setFormattedName only when name.formatted equalled the composed parts before the change — the ruling's "the same test setFormattedName already makes". Header names the ruling and the removal condition, as the ruling requires; registered in pnpm-workspace.yaml beside the three existing patches (no other better-auth patch). The vendor package ships only dist/index.mjs (exports['.'].default), so the one patched file covers every runtime import. skip-changeset holds: the published @objectstack/plugin-auth tarball is byte-unchanged (patched line in 0 files of its dist/, positive control: it imports @better-auth/scim); a pnpm patch reaches installs of this workspace only.
  5. Dev's open question — the value test also recomposes an IdP-supplied name that equals the composed parts, which the vendor's own suite pins as preserved. Answered A, per the ruling's own words (the value test is the ruled test); the upstream draft changes that vendor fixture, and a vendor refusal of it comes back as a new decision then (item (3) would not fire). Recorded here, no ruling owed now.
  6. Out of scope — an npm install of the published plugin-auth resolves an unpatched vendor until the vendor ships (the ruling's item (3), Acceptance notes); the ruling's note that cloud's SCIM known-issue line can go once this lands → cloud's lane (the seat tells cloud at merge); an email-seeded name.formatted is not recomposed (Acceptance notes). L2: not owed (no contract face).

Landing — non-governed, ≤3000 lines: the seat lands it through the ordinary queue.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#8 · sunhaolin · session_017xRBcSAaBEfQpU2yJexSJ8

Landing · 2026-11-28T07:05Z · head c40d3488

probe reading
check-governed-merges.mjs --pr 38181 NOT governed · +429/−2 ≤ 3000
landing-k.mjs --pr 38181 K = 10 < 15

State: ready for review + auto-merge (L1 ACCEPT 7235697648).

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 28, 2026 07:05
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit 5253e16 Nov 28, 2026
75 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-32380-scim-name-recompose branch November 28, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file size/m skip-changeset PR has no user-facing published change; bypasses the changeset gate tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SCIM: a PATCH that replaces only name.givenName / name.familyName leaves displayName and sys_user.name on the old name

2 participants