Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Use stable hosted signup owner ids
rcourtmanfdb9ad17f66a
diff --git a/docs/release-control/v6/internal/IDENTITY_INVARIANTS.md b/docs/release-control/v6/internal/IDENTITY_INVARIANTS.mdindex 177c34c2f6..f7f1e7050a 100644--- a/docs/release-control/v6/internal/IDENTITY_INVARIANTS.md+++ b/docs/release-control/v6/internal/IDENTITY_INVARIANTS.md@@ -78,10 +78,11 @@ principal once a stable user ID exists.2. Magic-link sessions bind to the stored organization principal resolved fromcontact email at verification time, not to the email embedded in the token.3. Hosted checkout and tenant provisioning seed organization membership from- registry user IDs. Contact email is copied separately.- Provisioning with an owner contact email must create or resolve a stable+ stable Pulse user IDs. Registry-backed paths must create or resolve theregistry user before writing hosted tenant `OwnerUserID` or member `UserID`;- it must not synthesize those durable IDs from email.+ legacy public hosted signup must generate an opaque `u_...` owner principal+ and copy email only into contact metadata and magic-link delivery. No hosted+ provisioning path may synthesize durable owner/member IDs from email.4. Webhook payloads must never create organizations or memberships from email.They may update billing only after server-owned org/customer linkage exists.5. Legacy email-keyed records may be accepted only at migration boundaries anddiff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.mdindex 995b251863..a739d39df6 100644--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md@@ -943,6 +943,10 @@ membership and derive the bounded effective role before it lands in protectedhosted routes. Direct opens must fail closed on missing membership, blank-ownerorgs, or owner/admin role escalation attempts instead of diverging from thenewer portal exchange path by repairing org metadata on arrival.+Lifecycle-adjacent entry surfaces must also treat public hosted signup as a+server-side identity bootstrap: the signup response cannot expose or define the+owner principal, and follow-on lifecycle access must rely on the stored+organization membership reached through magic-link verification.That same shared `internal/api/` organization boundary also now assumesself-hosted org membership is consent-backed rather than manager-written for atarget user ID. Lifecycle-adjacent setup, install, or hosted-entry surfacesdiff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex 9280673ef7..1a49693cc3 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -393,6 +393,10 @@ the canonical monitored-system blocked payload.the token may carry contact email for delivery, but `/api/public/magic-link/verify`must resolve that email against current server-side organization metadataand create the browser session for the stored owner/member principal.+ Public hosted signup must therefore keep the generated owner user ID+ server-side for org metadata and RBAC assignment while using returned+ contact email only for `GenerateToken`/`SendMagicLink`; the accepted signup+ response remains uniform and must not expose the owner principal.19. Keep tenant settings-scope authorization aligned with org management: `internal/api/security_setup_fix.go`, `internal/api/contract_test.go`, and settings-bound hosted callers must allow the current non-default org owner/admin membership to exercise privileged tenant routes, rather than requiring a separate configured local admin identity after hosted handoff.Hosted handoff must not be treated as an org-management side effect for that same privilege boundary. Onlycanonical invitation, membership-management, or explicit owner-transfer flows may create tenant membership ordiff --git a/docs/release-control/v6/internal/subsystems/cloud-paid.md b/docs/release-control/v6/internal/subsystems/cloud-paid.mdindex 900cb768be..c416385594 100644--- a/docs/release-control/v6/internal/subsystems/cloud-paid.md+++ b/docs/release-control/v6/internal/subsystems/cloud-paid.md@@ -290,9 +290,10 @@ runtime gating as separate unlinked claims.the existing tenant record instead of creating parallel orgs for oneaccount identity.The idempotency key remains the contact email only at the provisioning- edge. Once a stable control-plane user exists, hosted org `OwnerUserID` and- member `UserID` values must carry that durable user ID while owner/member- email fields preserve delivery and display contact metadata.+ edge. New public hosted signup orgs must generate an opaque stable owner+ user ID, and registry-backed hosted paths must resolve a registry user ID,+ before writing hosted org `OwnerUserID` or member `UserID`; owner/member+ email fields preserve delivery and display contact metadata only.13. Add or change hosted billing-admin presentation through `frontend-modern/src/components/Settings/BillingAdminPanel.tsx`, `frontend-modern/src/components/Settings/BillingAdminOrganizationsTable.tsx`, and `frontend-modern/src/components/Settings/useBillingAdminPanelState.ts`14. Add or change shared commercial plan/usage presentation through `frontend-modern/src/components/Settings/CommercialBillingSections.tsx` and `frontend-modern/src/utils/commercialBillingModel.ts`15. Add or change organization billing and usage presentation through `frontend-modern/src/components/Settings/OrganizationBillingPanel.tsx`, `frontend-modern/src/components/Settings/OrganizationBillingLoadingState.tsx`, and `frontend-modern/src/components/Settings/useOrganizationBillingPanelState.ts`@@ -1789,6 +1790,12 @@ handler owns request validation, trial billing initialization, and magic-linkissuance, while `internal/hosted/provisioner.go` owns the shared orgbootstrap/admin-role assignment, duplicate-owner-email idempotency, androllback path for hosted signup failures.+The same boundary is identity-stable: `internal/hosted/provisioner.go` must+generate a stable opaque owner user ID for new hosted signup organizations,+store the signup email only as `OwnerEmail`/member contact metadata, assign+RBAC against the stable owner ID, and return contact email separately so the+public signup handler can issue magic links without turning email into the+tenant principal.That duplicate-owner-email rule is fail-closed and server-owned. Repeatedhosted signup attempts for an email that already owns a tenant must resolve tothe existing org identity instead of minting a second tenant and relying ondiff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.mdindex 20b6cffe78..dbf26c5e0c 100644--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md@@ -308,7 +308,10 @@ handling must not duplicate those lifecycle events.That same adjacent `internal/api/` boundary also keeps public hosted signupcommercial-only: storage and recovery surfaces must not infer tenantexistence, email issuance, or readiness from `/api/public/signup` response- codes or payload fields when shared backend API helpers change nearby.+ codes or payload fields when shared backend API helpers change nearby, and+ they must not treat that response as a source for owner identity because the+ stable hosted owner principal is server-side org metadata resolved later+ through magic-link verification.7. Preserve fail-closed API assignment and lookup behavior in shared `internal/api/` helpers so storage and recovery surfaces do not inherit orphaned profile or resource references from unrelated transport mutations.8. Preserve canonical configured public endpoint selection in shared `internal/api/` helpers so recovery and storage links do not inherit loopback-local scheme drift from admin-originated setup/install flows.9. Preserve trailing-slash normalization in those shared install-command helpers so recovery-adjacent transport and link surfaces do not inherit double-slash installer paths or slash-suffixed public endpoint drift from canonical backend install payloads.diff --git a/internal/api/contract_test.go b/internal/api/contract_test.goindex dd1cd83538..be7dbfe8b0 100644--- a/internal/api/contract_test.go+++ b/internal/api/contract_test.go@@ -2414,6 +2414,9 @@ func TestContract_HostedSignupResponseJSONSnapshot(t *testing.T) {if err != nil {t.Fatalf("marshal hosted signup response: %v", err)}+ if strings.Contains(string(got), "user_id") || strings.Contains(string(got), "org_id") {+ t.Fatalf("hosted signup accepted response must not expose identity fields: %s", got)+ }const want = `{"message":"If that email can finish signup, you'll receive a Pulse Account sign-in link shortly."diff --git a/internal/api/hosted_signup_handlers_test.go b/internal/api/hosted_signup_handlers_test.goindex 39032c5667..839c31ae7c 100644--- a/internal/api/hosted_signup_handlers_test.go+++ b/internal/api/hosted_signup_handlers_test.go@@ -45,15 +45,18 @@ func TestHostedSignupSuccess(t *testing.T) {if org.DisplayName != "My Organization" {t.Fatalf("expected org display name My Organization, got %q", org.DisplayName)}- if org.OwnerUserID != "[email protected]" {- t.Fatalf("expected owner [email protected], got %q", org.OwnerUserID)+ if org.OwnerUserID == "" || strings.Contains(org.OwnerUserID, "@") {+ t.Fatalf("expected stable owner user id, got %q", org.OwnerUserID)+ }+ if org.OwnerEmail != "[email protected]" {+ t.Fatalf("expected owner email [email protected], got %q", org.OwnerEmail)}manager, err := rbacProvider.GetManager(orgID)if err != nil {t.Fatalf("get rbac manager: %v", err)}- assignment, ok := manager.GetUserAssignment("[email protected]")+ assignment, ok := manager.GetUserAssignment(org.OwnerUserID)if !ok {t.Fatal("expected user role assignment to exist")}@@ -359,7 +362,7 @@ func requireHostedSignupProvisionedOrgID(t *testing.T, persistence *config.Multiif org == nil || org.ID == "default" {continue}- if strings.EqualFold(org.OwnerUserID, ownerEmail) {+ if strings.EqualFold(org.OwnerEmail, ownerEmail) {return org.ID}}diff --git a/internal/api/identity_invariant_contract_test.go b/internal/api/identity_invariant_contract_test.goindex 1352f18a0d..867ca3b085 100644--- a/internal/api/identity_invariant_contract_test.go+++ b/internal/api/identity_invariant_contract_test.go@@ -30,7 +30,9 @@ func TestContract_HostedIdentityUsesStablePrincipals(t *testing.T) {"deploy_handlers.go": readIdentityContractFile(t, "deploy_handlers.go"),"router.go": readIdentityContractFile(t, "router.go"),"security_setup_fix.go": readIdentityContractFile(t, "security_setup_fix.go"),+ "public_signup_handlers.go": readIdentityContractFile(t, "public_signup_handlers.go"),"../cloudcp/stripe/provisioner.go": readIdentityContractFile(t, "../cloudcp/stripe/provisioner.go"),+ "../hosted/provisioner.go": readIdentityContractFile(t, "../hosted/provisioner.go"),"../models/organization.go": readIdentityContractFile(t, "../models/organization.go"),"../../docs/release-control/v6/internal/IDENTITY_INVARIANTS.md": readIdentityContractFile(t, "../../docs/release-control/v6/internal/IDENTITY_INVARIANTS.md"),}@@ -87,12 +89,23 @@ func TestContract_HostedIdentityUsesStablePrincipals(t *testing.T) {"setAPITokenOwnerUserID(tokenRecord, setupRequest.Username)","setAPITokenOwnerUserID(tokenRecord, apiTokenOwnerUserIDForRequest(r.config, rq))",},+ "public_signup_handlers.go": {+ "ownerEmail := strings.ToLower(strings.TrimSpace(result.OwnerEmail))",+ "GenerateToken(ownerEmail, orgID)",+ "SendMagicLink(ownerEmail, orgID, token, baseURL)",+ },"../cloudcp/stripe/provisioner.go": {"ownerUserID = strings.TrimSpace(user.ID)","org.OwnerEmail = ownerEmail","UserID: seed.userID","Email: seed.email",},+ "../hosted/provisioner.go": {+ "newUserID: registry.GenerateUserID",+ "OwnerEmail: ownerEmail",+ "UpdateUserRoles(userID, []string{auth.RoleAdmin})",+ "generated user id must not be an email",+ },"../models/organization.go": {"OwnerEmail string","ResolvePrincipalByEmail",@@ -144,6 +157,15 @@ func TestContract_HostedIdentityUsesStablePrincipals(t *testing.T) {"UserID: seed.email","memberSeeds[ownerEmail]",},+ "public_signup_handlers.go": {+ "GenerateToken(userID, orgID)",+ "SendMagicLink(userID, orgID, token, baseURL)",+ },+ "../hosted/provisioner.go": {+ "OwnerUserID: ownerEmail",+ "UserID: ownerEmail",+ "contactEmailForLegacyUserID",+ },}for file, needles := range forbidden {for _, needle := range needles {diff --git a/internal/api/public_signup_handlers.go b/internal/api/public_signup_handlers.goindex 9e6722e2f1..0a5283e899 100644--- a/internal/api/public_signup_handlers.go+++ b/internal/api/public_signup_handlers.go@@ -139,7 +139,10 @@ func (h *HostedSignupHandlers) HandlePublicSignup(w http.ResponseWriter, r *http}orgID := result.OrgID- userID := result.UserID+ ownerEmail := strings.ToLower(strings.TrimSpace(result.OwnerEmail))+ if ownerEmail == "" {+ ownerEmail = strings.ToLower(strings.TrimSpace(req.Email))+ }var cleanupOnce sync.OncecleanupProvisioning := func() {@@ -167,13 +170,13 @@ func (h *HostedSignupHandlers) HandlePublicSignup(w http.ResponseWriter, r *http}// Issue a magic link for passwordless sign-in.- token, err := h.magicLinks.GenerateToken(userID, orgID)+ token, err := h.magicLinks.GenerateToken(ownerEmail, orgID)if err != nil {cleanupProvisioning()writeErrorResponse(w, http.StatusInternalServerError, "magic_link_failed", "Failed to generate magic link", nil)return}- if err := h.magicLinks.SendMagicLink(userID, orgID, token, baseURL); err != nil {+ if err := h.magicLinks.SendMagicLink(ownerEmail, orgID, token, baseURL); err != nil {cleanupProvisioning()writeErrorResponse(w, http.StatusInternalServerError, "magic_link_failed", "Failed to send magic link", nil)returndiff --git a/internal/hosted/provisioner.go b/internal/hosted/provisioner.goindex 8a939f1bde..b6a88f0250 100644--- a/internal/hosted/provisioner.go+++ b/internal/hosted/provisioner.go@@ -10,6 +10,7 @@ import ("time""github.com/google/uuid"+ "github.com/rcourtman/pulse-go-rewrite/internal/cloudcp/registry""github.com/rcourtman/pulse-go-rewrite/internal/config""github.com/rcourtman/pulse-go-rewrite/internal/models""github.com/rcourtman/pulse-go-rewrite/pkg/auth"@@ -54,6 +55,7 @@ type Provisioner struct {persistence OrgPersistenceauthProvider AuthProvidernewOrgID func() string+ newUserID func() (string, error)now func() time.Time}@@ -69,9 +71,10 @@ type HostedSignupRequest struct {}type ProvisionResult struct {- OrgID string- UserID string- Status ProvisionStatus+ OrgID string+ UserID string+ OwnerEmail string+ Status ProvisionStatus}type ValidationError struct {@@ -114,6 +117,7 @@ func NewProvisioner(persistence OrgPersistence, authProvider AuthProvider) *Provpersistence: persistence,authProvider: authProvider,newOrgID: uuid.NewString,+ newUserID: registry.GenerateUserID,now: time.Now,}}@@ -173,10 +177,19 @@ func (p *Provisioner) findExistingOrganizationByOwnerEmail(email string) (*Provicontinue}if strings.EqualFold(strings.TrimSpace(org.OwnerEmail), email) || strings.EqualFold(strings.TrimSpace(org.OwnerUserID), email) {+ userID, _, ok := org.ResolvePrincipalByEmail(email)+ if !ok {+ userID = strings.TrimSpace(org.OwnerUserID)+ }+ ownerEmail := strings.ToLower(strings.TrimSpace(org.OwnerEmail))+ if ownerEmail == "" {+ ownerEmail = strings.ToLower(strings.TrimSpace(email))+ }return &ProvisionResult{- OrgID: org.ID,- UserID: strings.TrimSpace(org.OwnerUserID),- Status: ProvisionStatusExisting,+ OrgID: org.ID,+ UserID: userID,+ OwnerEmail: ownerEmail,+ Status: ProvisionStatusExisting,}, nil}}@@ -227,7 +240,7 @@ func (p *Provisioner) ensureReady() error {return nil}-func (p *Provisioner) createOrganization(ctx context.Context, orgID, userID, orgName string) (*ProvisionResult, error) {+func (p *Provisioner) createOrganization(ctx context.Context, orgID, ownerEmail, orgName string) (*ProvisionResult, error) {tenantPersistence, err := p.persistence.GetPersistence(orgID)if err != nil {return nil, &SystemError{Op: "initialize_tenant_directory", Err: err}@@ -239,18 +252,24 @@ func (p *Provisioner) createOrganization(ctx context.Context, orgID, userID, orgp.RollbackProvisioning(orgID)return nil, err}+ userID, err := p.generateOwnerUserID()+ if err != nil {+ p.RollbackProvisioning(orgID)+ return nil, &SystemError{Op: "generate_owner_user_id", Err: err}+ }now := p.now().UTC()+ ownerEmail = strings.ToLower(strings.TrimSpace(ownerEmail))org := &models.Organization{ID: orgID,DisplayName: orgName,CreatedAt: now,OwnerUserID: userID,- OwnerEmail: contactEmailForLegacyUserID(userID),+ OwnerEmail: ownerEmail,Members: []models.OrganizationMember{{UserID: userID,- Email: contactEmailForLegacyUserID(userID),+ Email: ownerEmail,Role: models.OrgRoleOwner,AddedAt: now,AddedBy: userID,@@ -281,18 +300,29 @@ func (p *Provisioner) createOrganization(ctx context.Context, orgID, userID, org}return &ProvisionResult{- OrgID: orgID,- UserID: userID,- Status: ProvisionStatusCreated,+ OrgID: orgID,+ UserID: userID,+ OwnerEmail: ownerEmail,+ Status: ProvisionStatusCreated,}, nil}-func contactEmailForLegacyUserID(userID string) string {- userID = strings.ToLower(strings.TrimSpace(userID))+func (p *Provisioner) generateOwnerUserID() (string, error) {+ if p == nil || p.newUserID == nil {+ return "", errors.New("user id generator is nil")+ }+ userID, err := p.newUserID()+ if err != nil {+ return "", err+ }+ userID = strings.TrimSpace(userID)+ if userID == "" {+ return "", errors.New("generated user id is empty")+ }if strings.Contains(userID, "@") {- return userID+ return "", errors.New("generated user id must not be an email")}- return ""+ return userID, nil}func (p *Provisioner) cleanupOrgDirectory(orgID, dataDir string) {diff --git a/internal/hosted/provisioner_additional_test.go b/internal/hosted/provisioner_additional_test.goindex 12b7356dc0..5733831606 100644--- a/internal/hosted/provisioner_additional_test.go+++ b/internal/hosted/provisioner_additional_test.go@@ -402,6 +402,42 @@ func TestProvisionTenantAuthManagerFailuresCleanup(t *testing.T) {}}+func TestProvisionTenantRejectsEmailShapedGeneratedOwnerUserID(t *testing.T) {+ baseDir := t.TempDir()+ authManager := &mockAuthManager{}+ authProvider := &mockAuthProvider{manager: authManager}+ p := NewProvisioner(config.NewMultiTenantPersistence(baseDir), authProvider)+ p.newOrgID = func() string { return "org-email-shaped-owner" }+ p.newUserID = func() (string, error) { return "[email protected]", nil }++ _, err := p.ProvisionTenant(context.Background(), ProvisionRequest{+ Email: "[email protected]",+ Password: "securepass123",+ OrgName: "Valid Org",+ })+ if err == nil {+ t.Fatal("expected generated owner user id error, got nil")+ }+ var systemErr *SystemError+ if !errors.As(err, &systemErr) {+ t.Fatalf("expected SystemError, got %T (%v)", err, err)+ }+ if systemErr.Op != "generate_owner_user_id" {+ t.Fatalf("expected op generate_owner_user_id, got %q", systemErr.Op)+ }+ if systemErr.Err == nil || systemErr.Err.Error() != "generated user id must not be an email" {+ t.Fatalf("unexpected underlying error: %v", systemErr.Err)+ }+ if authProvider.calls != 0 || authManager.calls != 0 {+ t.Fatalf("expected no RBAC calls, got provider=%d manager=%d", authProvider.calls, authManager.calls)+ }++ orgDir := filepath.Join(baseDir, "orgs", "org-email-shaped-owner")+ if _, statErr := os.Stat(orgDir); !os.IsNotExist(statErr) {+ t.Fatalf("expected org dir to be removed on rollback, stat error: %v", statErr)+ }+}+func TestValidationHelpersAdditionalBranches(t *testing.T) {if isValidSignupEmail("user@[email protected]") {t.Fatal("expected second @ in domain to be invalid")diff --git a/internal/hosted/provisioner_test.go b/internal/hosted/provisioner_test.goindex 0cb3260b95..bc346fcf95 100644--- a/internal/hosted/provisioner_test.go+++ b/internal/hosted/provisioner_test.go@@ -83,6 +83,7 @@ func TestProvisionTenantSuccess(t *testing.T) {provisioner := NewProvisioner(persistence, authProvider)provisioner.newOrgID = func() string { return "org-success" }+ provisioner.newUserID = func() (string, error) { return "u_owner_success", nil }provisioner.now = func() time.Time { return time.Unix(1700000000, 0).UTC() }result, err := provisioner.ProvisionTenant(context.Background(), ProvisionRequest{@@ -102,8 +103,11 @@ func TestProvisionTenantSuccess(t *testing.T) {if result.OrgID != "org-success" {t.Fatalf("expected org ID org-success, got %q", result.OrgID)}- if result.UserID != "[email protected]" {- t.Fatalf("expected user ID [email protected], got %q", result.UserID)+ if result.UserID != "u_owner_success" {+ t.Fatalf("expected stable user ID u_owner_success, got %q", result.UserID)+ }+ if result.OwnerEmail != "[email protected]" {+ t.Fatalf("expected owner email [email protected], got %q", result.OwnerEmail)}org, err := persistence.LoadOrganization("org-success")@@ -113,14 +117,20 @@ func TestProvisionTenantSuccess(t *testing.T) {if org.DisplayName != "My Organization" {t.Fatalf("expected org display name My Organization, got %q", org.DisplayName)}- if org.OwnerUserID != "[email protected]" {- t.Fatalf("expected owner [email protected], got %q", org.OwnerUserID)+ if org.OwnerUserID != "u_owner_success" {+ t.Fatalf("expected owner u_owner_success, got %q", org.OwnerUserID)+ }+ if org.OwnerEmail != "[email protected]" {+ t.Fatalf("expected owner email [email protected], got %q", org.OwnerEmail)}if len(org.Members) != 1 {t.Fatalf("expected 1 member, got %d", len(org.Members))}- if org.Members[0].UserID != "[email protected]" {- t.Fatalf("expected member user ID [email protected], got %q", org.Members[0].UserID)+ if org.Members[0].UserID != "u_owner_success" {+ t.Fatalf("expected member user ID u_owner_success, got %q", org.Members[0].UserID)+ }+ if org.Members[0].Email != "[email protected]" {+ t.Fatalf("expected member email [email protected], got %q", org.Members[0].Email)}if org.Members[0].Role != models.OrgRoleOwner {t.Fatalf("expected owner role, got %q", org.Members[0].Role)@@ -135,8 +145,8 @@ func TestProvisionTenantSuccess(t *testing.T) {if authManager.calls != 1 {t.Fatalf("expected UpdateUserRoles to be called once, got %d", authManager.calls)}- if authManager.lastUser != "[email protected]" {- t.Fatalf("expected UpdateUserRoles for [email protected], got %q", authManager.lastUser)+ if authManager.lastUser != "u_owner_success" {+ t.Fatalf("expected UpdateUserRoles for u_owner_success, got %q", authManager.lastUser)}if len(authManager.lastRoles) != 1 || authManager.lastRoles[0] != auth.RoleAdmin {t.Fatalf("expected roles [%s], got %v", auth.RoleAdmin, authManager.lastRoles)@@ -154,13 +164,15 @@ func TestProvisionTenantIdempotentDuplicateEmail(t *testing.T) {ID: "existing-org",DisplayName: "Existing Org",CreatedAt: time.Now().UTC(),- OwnerUserID: "[email protected]",+ OwnerUserID: "u_existing_owner",+ OwnerEmail: "[email protected]",Members: []models.OrganizationMember{{- UserID: "[email protected]",+ UserID: "u_existing_owner",+ Email: "[email protected]",Role: models.OrgRoleOwner,AddedAt: time.Now().UTC(),- AddedBy: "[email protected]",+ AddedBy: "u_existing_owner",},},}@@ -185,8 +197,11 @@ func TestProvisionTenantIdempotentDuplicateEmail(t *testing.T) {if result.OrgID != "existing-org" {t.Fatalf("expected org ID existing-org, got %q", result.OrgID)}- if result.UserID != "[email protected]" {- t.Fatalf("expected user ID [email protected], got %q", result.UserID)+ if result.UserID != "u_existing_owner" {+ t.Fatalf("expected stable user ID u_existing_owner, got %q", result.UserID)+ }+ if result.OwnerEmail != "[email protected]" {+ t.Fatalf("expected owner email [email protected], got %q", result.OwnerEmail)}if authProvider.calls != 0 {t.Fatalf("expected GetManager to not be called for idempotent path, got %d", authProvider.calls)@@ -207,13 +222,15 @@ func TestProvisionTenantIdempotentDuplicateEmailCaseInsensitive(t *testing.T) {ID: "existing-org",DisplayName: "Existing Org",CreatedAt: time.Now().UTC(),- OwnerUserID: "[email protected]",+ OwnerUserID: "u_existing_owner",+ OwnerEmail: "[email protected]",Members: []models.OrganizationMember{{- UserID: "[email protected]",+ UserID: "u_existing_owner",+ Email: "[email protected]",Role: models.OrgRoleOwner,AddedAt: time.Now().UTC(),- AddedBy: "[email protected]",+ AddedBy: "u_existing_owner",},},}@@ -238,8 +255,11 @@ func TestProvisionTenantIdempotentDuplicateEmailCaseInsensitive(t *testing.T) {if result.OrgID != "existing-org" {t.Fatalf("expected org ID existing-org, got %q", result.OrgID)}- if result.UserID != "[email protected]" {- t.Fatalf("expected normalized user ID [email protected], got %q", result.UserID)+ if result.UserID != "u_existing_owner" {+ t.Fatalf("expected stable user ID u_existing_owner, got %q", result.UserID)+ }+ if result.OwnerEmail != "[email protected]" {+ t.Fatalf("expected owner email [email protected], got %q", result.OwnerEmail)}if authProvider.calls != 0 {t.Fatalf("expected GetManager to not be called for idempotent path, got %d", authProvider.calls)@@ -365,6 +385,7 @@ func TestProvisionHostedSignupSuccess(t *testing.T) {provisioner := NewProvisioner(persistence, authProvider)provisioner.newOrgID = func() string { return "org-hosted-signup" }+ provisioner.newUserID = func() (string, error) { return "u_hosted_signup_owner", nil }provisioner.now = func() time.Time { return time.Unix(1700000100, 0).UTC() }result, err := provisioner.ProvisionHostedSignup(context.Background(), HostedSignupRequest{@@ -383,8 +404,11 @@ func TestProvisionHostedSignupSuccess(t *testing.T) {if result.OrgID != "org-hosted-signup" {t.Fatalf("expected org ID org-hosted-signup, got %q", result.OrgID)}- if result.UserID != "[email protected]" {- t.Fatalf("expected normalized user ID [email protected], got %q", result.UserID)+ if result.UserID != "u_hosted_signup_owner" {+ t.Fatalf("expected stable user ID u_hosted_signup_owner, got %q", result.UserID)+ }+ if result.OwnerEmail != "[email protected]" {+ t.Fatalf("expected owner email [email protected], got %q", result.OwnerEmail)}org, err := persistence.LoadOrganization("org-hosted-signup")@@ -394,14 +418,17 @@ func TestProvisionHostedSignupSuccess(t *testing.T) {if org.DisplayName != "My Organization" {t.Fatalf("expected org display name My Organization, got %q", org.DisplayName)}- if org.OwnerUserID != "[email protected]" {- t.Fatalf("expected owner [email protected], got %q", org.OwnerUserID)+ if org.OwnerUserID != "u_hosted_signup_owner" {+ t.Fatalf("expected owner u_hosted_signup_owner, got %q", org.OwnerUserID)+ }+ if org.OwnerEmail != "[email protected]" {+ t.Fatalf("expected owner email [email protected], got %q", org.OwnerEmail)}if authProvider.calls != 1 || authProvider.lastOrgID != "org-hosted-signup" {t.Fatalf("expected auth manager lookup for org-hosted-signup, got calls=%d org=%q", authProvider.calls, authProvider.lastOrgID)}- if authManager.calls != 1 || authManager.lastUser != "[email protected]" {- t.Fatalf("expected admin role assignment for [email protected], got calls=%d user=%q", authManager.calls, authManager.lastUser)+ if authManager.calls != 1 || authManager.lastUser != "u_hosted_signup_owner" {+ t.Fatalf("expected admin role assignment for u_hosted_signup_owner, got calls=%d user=%q", authManager.calls, authManager.lastUser)}}@@ -416,13 +443,15 @@ func TestProvisionHostedSignupIdempotentDuplicateEmailCaseInsensitive(t *testingID: "existing-org",DisplayName: "Existing Org",CreatedAt: time.Now().UTC(),- OwnerUserID: "[email protected]",+ OwnerUserID: "u_existing_owner",+ OwnerEmail: "[email protected]",Members: []models.OrganizationMember{{- UserID: "[email protected]",+ UserID: "u_existing_owner",+ Email: "[email protected]",Role: models.OrgRoleOwner,AddedAt: time.Now().UTC(),- AddedBy: "[email protected]",+ AddedBy: "u_existing_owner",},},}@@ -446,8 +475,11 @@ func TestProvisionHostedSignupIdempotentDuplicateEmailCaseInsensitive(t *testingif result.OrgID != "existing-org" {t.Fatalf("expected org ID existing-org, got %q", result.OrgID)}- if result.UserID != "[email protected]" {- t.Fatalf("expected normalized user ID [email protected], got %q", result.UserID)+ if result.UserID != "u_existing_owner" {+ t.Fatalf("expected stable user ID u_existing_owner, got %q", result.UserID)+ }+ if result.OwnerEmail != "[email protected]" {+ t.Fatalf("expected owner email [email protected], got %q", result.OwnerEmail)}if authProvider.calls != 0 {t.Fatalf("expected GetManager to not be called for idempotent hosted signup, got %d", authProvider.calls)