forked from longtao.wu/droboticflow
Contract step of the account-phone-login expand-migrate-contract rollout. Phone is now the sole account identifier end to end: - domain.UserRecord/CreateUserInput: delete Email, drop Phone's omitempty (required going forward). - store: delete email_unique Mongo index; phone_unique is now non-sparse (unique, not sparse) since every account creation path requires a phone. Delete FindUserByEmail, ensureUserEmailAvailableLocked, and ErrDuplicateUserEmail (confirmed dead via grep - all real call sites were already migrated to the *Phone equivalents by tickets 01-03). Mongo duplicate-key fallback and the account-mutation-guard's stale-write snapshot/filter now key off Phone instead of Email. - api: drop the now-impossible ErrDuplicateUserEmail branch in renderUserMutationError. The account-hierarchy audit endpoint and the supplier-deletion receipt struct both switch their identifying field from Email to Phone, since both are populated fresh from current account state (not frozen historical snapshots) - continuing to read a "email" key would silently go blank for every account created after this change. - frontend: src/types.ts User.phone is now required (email removed); AccountHierarchyIssue.email -> .phone in services/api/users.ts and pages/Users.tsx to match the backend audit endpoint's renamed field. - Rewrote the wide blast radius of Go test fixtures that constructed users by email across internal/api/*_test.go and internal/store/*_test.go, including the two dedicated memory-store uniqueness tests (merged into phone-only equivalents) and several opt-in "live" acceptance-fixture tests gated behind env vars for real Fanyu deployments. Repo-wide grep of Go and TS/TSX for Email/email/邮箱 turned up no remaining account-identifier references outside of a few harmless test-only cosmetic labels (e.g. "Email Tenant" as an org display name in a seed helper) and assertions that explicitly check "邮箱" text is absent from API responses. go build/vet clean. go test ./internal/api/... ./internal/store/... ./internal/domain/... : 75 failures, identical test names to the pre-ticket-05 baseline (diffed against a throwaway worktree at the prior tip). npm run lint:web (tsc --noEmit) clean. npm run test:frontend: 599/586/13, matching the stated baseline exactly. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
108 lines
4.1 KiB
Go
108 lines
4.1 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"droboticflow/internal/domain"
|
|
"droboticflow/internal/store"
|
|
"fmt"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
"net/http"
|
|
"os"
|
|
"regexp"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// Explicitly opt-in isolated tenant fixture. Never edits customer accounts/projects.
|
|
func TestProjectMemberDisplayLiveFixture(t *testing.T) {
|
|
if os.Getenv("MEMBER_DISPLAY_FIXTURE") != "1" {
|
|
t.Skip("explicit isolated fixture only")
|
|
}
|
|
nonce := os.Getenv("MEMBER_DISPLAY_NONCE")
|
|
if !regexp.MustCompile(`^2026[0-9a-z]{8,24}$`).MatchString(nonce) {
|
|
t.Fatal("invalid nonce")
|
|
}
|
|
orgID, projectID := "org-member-display-"+nonce, "project-member-display-"+nonce
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
|
defer cancel()
|
|
var ds store.Store
|
|
if os.Getenv("MEMBER_DISPLAY_MODE") == "local" {
|
|
ds = store.NewMemoryStore()
|
|
} else {
|
|
c, e := mongo.Connect(ctx, options.Client().ApplyURI(os.Getenv("MONGO_URI")))
|
|
if e != nil {
|
|
t.Fatal("mongo connection")
|
|
}
|
|
defer c.Disconnect(context.Background())
|
|
ds = store.NewMongoStore(c.Database(os.Getenv("MONGO_DB")))
|
|
}
|
|
must := func(e error) {
|
|
t.Helper()
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
}
|
|
ids := []string{"admin", "manager", "a", "b", "disabled"}
|
|
if os.Getenv("MEMBER_DISPLAY_MODE") == "cleanup" {
|
|
for _, id := range ids {
|
|
u, e := ds.GetUser(ctx, "user-member-"+nonce+"-"+id)
|
|
must(e)
|
|
if u != nil {
|
|
if u.OrganizationID != orgID {
|
|
t.Fatal("cleanup scope")
|
|
}
|
|
u.Status = domain.UserStatusDisabled
|
|
must(ds.UpsertUser(ctx, *u))
|
|
}
|
|
}
|
|
fmt.Println("MEMBER_FIXTURE_ACCOUNTS_DISABLED")
|
|
return
|
|
}
|
|
existing, e := ds.GetOrganization(ctx, orgID)
|
|
must(e)
|
|
if existing != nil {
|
|
t.Fatal("fixture already exists")
|
|
}
|
|
password := os.Getenv("MEMBER_DISPLAY_PASSWORD")
|
|
if len(password) < 20 {
|
|
t.Fatal("ephemeral password required")
|
|
}
|
|
hash, e := hashPassword(password)
|
|
must(e)
|
|
must(ds.UpsertOrganization(ctx, domain.OrganizationRecord{ID: orgID, Name: "成员展示隔离验收", Slug: "member-display-" + nonce, Status: domain.OrganizationStatusActive, CreatedAt: nowISO()}))
|
|
must(ds.UpsertProject(ctx, domain.ProjectRecord{ID: projectID, OrganizationID: orgID, Name: "成员展示隔离验收", Status: domain.ProjectStatusActive, CreatedAt: nowISO()}))
|
|
for _, suffix := range []string{"a", "b"} {
|
|
must(ds.UpsertSupplier(ctx, domain.SupplierRecord{ID: "supplier-" + nonce + "-" + suffix, OrganizationID: orgID, Name: "测试供应商" + suffix, Status: "active", CreatedAt: nowISO()}))
|
|
}
|
|
for _, id := range ids {
|
|
role := domain.UserRoleAnnotator
|
|
if id == "admin" {
|
|
role = domain.UserRoleAdmin
|
|
}
|
|
if id == "manager" {
|
|
role = domain.UserRoleSupplierManager
|
|
}
|
|
status := domain.UserStatusActive
|
|
if id == "disabled" {
|
|
status = domain.UserStatusDisabled
|
|
}
|
|
suffix := "a"
|
|
if id == "b" {
|
|
suffix = "b"
|
|
}
|
|
userID := "user-member-" + nonce + "-" + id
|
|
must(ds.UpsertUser(ctx, domain.UserRecord{ID: userID, OrganizationID: orgID, Name: "验收成员" + id, Phone: testPhoneFromSeed(id + "-" + nonce), Role: role, Status: status, SupplierID: "supplier-" + nonce + "-" + suffix, PasswordHash: hash, CreatedAt: nowISO()}))
|
|
if id != "admin" {
|
|
must(ds.UpsertProjectMember(ctx, domain.ProjectMemberRecord{ID: "member-" + nonce + "-" + id, OrganizationID: orgID, ProjectID: projectID, UserID: userID, SupplierID: "supplier-" + nonce + "-" + suffix, Roles: []domain.AnnotationAssignmentRole{domain.AnnotationRoleAnnotator}, CreatedAt: nowISO()}))
|
|
}
|
|
}
|
|
must(ds.UpsertProjectMember(ctx, domain.ProjectMemberRecord{ID: "member-" + nonce + "-missing", OrganizationID: orgID, ProjectID: projectID, UserID: "missing-" + nonce, SupplierID: "supplier-" + nonce + "-a", Roles: []domain.AnnotationAssignmentRole{domain.AnnotationRoleAnnotator}, CreatedAt: nowISO()}))
|
|
fmt.Println("MEMBER_FIXTURE_READY " + projectID)
|
|
if os.Getenv("MEMBER_DISPLAY_MODE") == "local" {
|
|
must(ds.UpsertUser(ctx, domain.UserRecord{ID: "local-fixture-root", IsSuperAdmin: true, Role: domain.UserRoleAdmin, Status: domain.UserStatusActive, PasswordHash: hash}))
|
|
t.Setenv("DROBOTICFLOW_REQUIRE_SESSION_AUTH", "true")
|
|
must(http.ListenAndServe("127.0.0.1:3001", NewHandler(ds, nil)))
|
|
}
|
|
}
|