Add profile identity foundation#69
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ace6371659
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Greptile SummaryThis PR lands the profile identity foundation: globally unique slugs with strict validation and generation helpers, a discriminated
Confidence Score: 4/5Safe to merge as a foundations-only slice; no mutations are introduced and the schema change is additive. The schema conversion and slug helpers are well-constructed. The main concern is in convex/_profilePermissions.ts — the permission API surface should be hardened before mutations consume it. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Input string] --> B[normalizeProfileSlugInput]
B --> C{createProfileSlugBase}
C -- too short --> D[append -profile]
C -- reserved --> E[append -profile]
C -- too long --> F[truncate to 64 chars]
D & E & F --> G[validateProfileSlug]
G -- invalid --> H[fallback: profile-page]
G -- valid --> I[base slug]
I --> J[findAvailableProfileSlug loop]
J --> K[createProfileSlugCandidate attempt N]
K --> L[checkProfileSlugAvailability]
L --> M{available?}
M -- yes --> N[return slug]
M -- no, attempt lt maxAttempts --> K
M -- exhausted --> O[throw Error]
subgraph Permission Gate
P[subject + profile] --> Q[canReadProfile]
P --> R[canEditProfileField]
R --> S{isFieldCompatibleWithProfileType}
S -- incompatible --> T[false]
S -- compatible --> U{subject role?}
U -- moderator --> V[true]
U -- claimed_owner --> W{claimState != unclaimed}
U -- community_submitter --> X{unclaimed AND allowed field?}
U -- public --> Y[false]
end
subgraph Claim State Machine
Z[unclaimed] --> AA[claimed_unverified]
Z --> AB[claimed_verified]
AA --> AB
end
Prompt To Fix All With AIFix the following 4 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 4
convex/_profilePermissions.ts:55-80
**`canEditProfileField` doesn't check `publicationState`**
`community_submitter` can pass this check for a `draft_private` unclaimed profile — even though `canReadProfile` would deny them access. The two helpers are designed to be used together, but nothing in the API enforces it. A future mutation that calls only `canEditProfileField` without first gating on `canReadProfile` would let a community submitter edit a profile they cannot read. Adding either a guard inside this function or a combined `canAccessAndEdit` helper would make the contract harder to misuse.
### Issue 2 of 4
convex/_profileStates.ts:37-42
**No-op transitions silently succeed in `canTransitionProfileClaimState`**
`from === to` is treated as valid, so `requireProfileClaimStateTransition("unclaimed", "unclaimed")` never throws. Per the mutation contract doc, future mutations must set `claimedAt` when `claimState` leaves `"unclaimed"`. Any mutation that uses `requireProfileClaimStateTransition` to gate that assignment also needs an explicit `from !== to` guard; otherwise a no-op call could skip — or incorrectly trigger — the `claimedAt` write. This is a subtle trap for the first mutation author.
### Issue 3 of 4
convex/_profilePermissions.ts:1-80
**No unit tests for pure permission and state-transition helpers**
`_profilePermissions.ts` and `_profileStates.ts` are entirely pure functions with no I/O or Convex runtime dependencies — ideal candidates for straightforward unit tests. The project's testing rule calls for stronger automated coverage when permission or verification logic changes. The edge cases (e.g., `community_submitter` on an incompatible profile type, the claim-state transition table, the reserved field gate) are the kind of things that regress silently without a test suite.
### Issue 4 of 4
convex/_profileSlugs.ts:102-119
**`createProfileSlugBase` doesn't re-check reservation after the too-short padding**
The length-pad (`< PROFILE_SLUG_MIN_LENGTH → append "-profile"`) runs before the reservation check. If a two-character slug like `"ab"` is padded to `"ab-profile"` and that result happened to match a reserved slug added to the list later, the subsequent reserved guard would append `-profile` again, and the trailing truncation and `validateProfileSlug` fallback would catch it. More fragile, if after both appends the result is still reserved, `validateProfileSlug` falls back silently to `"profile-page"` without any signal to the caller. A second reserved re-check before `validateProfileSlug` would make this function's logic easier to verify and extend.
Reviews (1): Last reviewed commit: "feat: add profile identity foundation" | Re-trigger Greptile |
| if (!canReadProfile(subject, profile)) { | ||
| return false; | ||
| } | ||
|
|
Summary
by_sluglookup indexprofilesto a discriminated person/community schema with flexible type-aware fieldsValidation
pnpm verifyCloses #10
Closes #11
Closes #12
Closes #13