Repository navigation
refactor(access): speak the generated ProjectSlug throughout the access config, deleting the internal alias - #746
Conversation
…tProjectOptions Both functions returned `InternalProjectSlug` (`keyof typeof PROJECTS`) while every consumer declares the generated `ProjectSlug`, so all four call sites followed them with `as ProjectSlug`. The two unions are the same set, so the casts asserted nothing — they read as though they did. #697 and #712 fixed the same no-op on `isValidProject`'s three call sites and named only those, leaving 3 of 7 instances done. This finishes the other four. The claim is compiler-held, not asserted: #712 pinned `PROJECTS` with `as const satisfies Record<ProjectSlug, unknown>`, so a stale `payload-types.ts` fails `pnpm typecheck` at the declaration. Confirmed by renaming a `PROJECTS` key — typecheck goes red across the consumers rather than accepting the drift. `InternalProjectSlug` stays on the internal lookup tables, where deriving from `PROJECTS` is the honest thing to say (src/types/AGENTS.md). No runtime change: only annotations and cast deletions. Closes #713 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YQzGfR6tfq5i3xSxagjN4q
The first commit left `getProjectsFromRoles` declared `ProjectSlug[]` while its body still accumulated into `new Set<InternalProjectSlug>()`, one line down — the seam moved to the signature rather than going away. `getRoleProject` is the reason. It returns a project outward, so a consumer compensated: `PermissionsTable.tsx:69` does the same `InternalProjectSlug` to `ProjectSlug` conversion inside a type predicate. That is an eighth instance of the pattern this ticket exists to finish, and the ticket's `grep "as ProjectSlug"` criterion cannot see it — a predicate, not a cast. Moving `getRoleProject` to `ProjectSlug | undefined` removes the last three uses of the internal name outside `projects.ts`, so the type is no longer exported. The rule that decides which signatures use which name was in no comment, only in three PR bodies — it is now stated at the declaration: returns speak `ProjectSlug`, parameters keep the internal name, because the unions are identical and only returns force a call site to re-assert. The `PermissionsTable` predicate still compiles and still strips `undefined`. It is now a plain narrowing rather than a rename, and is left alone. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YQzGfR6tfq5i3xSxagjN4q
The doc comment claimed every outward return speaks `ProjectSlug`. `getProjectSlugs` does not, and should not: `accessPlugin.ts` builds the `ProjectSlug` jsonSchema from its output, so declaring it as the type it generates would state the conclusion. Named as the deliberate exception. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YQzGfR6tfq5i3xSxagjN4q
|
🚅 Deployed to the SahajCloud-pr-746 environment in sahajcloud
1 service not affected by this PR
|
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff is smaller than its ticket: 5 files, +30/−17, every hunk an annotation, an import or a comment. The one widening — getRoleProject, plus making InternalProjectSlug module-private — is what src/types/AGENTS.md already requires. Both acceptance criteria hold.
Two things stop short of the PR's own claim. It names PermissionsTable.tsx:69 as the reason getRoleProject moved, then leaves that line re-declaring ProjectSlug by hand. And the new doc comment is 18 of the 30 added lines.
Findings
consider—PermissionsTable.tsx:69still asserts the type this PR made redundant → thread onroles.ts:176.consider— theInternalProjectSlugcomment carries three rationales → thread onprojects.ts:121.
What was checked
Read projects.ts and roles.ts whole against #713. Traced every consumer of the moved functions — Managers.ts:86, scalarPlugin.ts:79, permissions.ts:89, PermissionsTable.tsx:68 — the unions match. ROLES has no satisfies, yet the return is compiler-held at roles.ts:178.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`getRoleProject` now returns `ProjectSlug`, so the hand-written `(project): project is ProjectSlug` at PermissionsTable.tsx:69 no longer crosses a type boundary — it only strips `undefined`, which TypeScript 5.7 infers on its own (inferred type predicates, 5.5+). This was the eighth instance of the shape #713 set out to delete, at the site the PR body names. The `ProjectSlug` import goes with it; `RoleSlug` stays. Verified rather than assumed: replacing the filter with a non-narrowing predicate turns `pnpm typecheck` red at the two `getProjectIcon` / `getProjectLabel` call sites, so the compiler is holding the narrowing instead of the annotation. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RrsvVM9eCsiXLR8w6EQA8L
… say The comment answered three questions in 18 of this PR's 30 added lines, and the first of them — a derived alias stays local and is never re-exported — is already stated in `src/types/AGENTS.md`, so restating it here held nothing. What survives is the part a reader cannot recover from the code: that returns use the generated `ProjectSlug` while parameters keep this name, and that `getProjectSlugs` is the one return that keeps it because `accessPlugin.ts` builds the `ProjectSlug` jsonSchema from its output. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RrsvVM9eCsiXLR8w6EQA8L
|
Both adversarial findings adopted. Pushed
Nothing rebutted, nothing asked. Gate green: lint, both typechecks, 1669 unit tests, and 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
This draft has had no CI activity for hours and no session holds it. Comment or push to wake me. 🤖 sydevs dispatcher |
|
I could not mark ready here — the dispatch token is not allowed to. Everything else on this item is done, so this is the one step left for you. 🤖 sydevs dispatcher |
Ardnived asked whether the keys of `PROJECTS` should simply be enforced as `ProjectSlug` instead of being aliased. They already are — `as const satisfies Record<ProjectSlug, unknown>` (#712) pins them bidirectionally. The comment did not answer the question that follows: given that pin, why keep the alias at all? Checked rather than assumed — deleting it and writing `ProjectSlug` at all twelve positions passes `pnpm typecheck`. The cost is two `as ProjectSlug` casts back in `src/` (projects.ts:125, :205), where `Object.keys` and `Object.entries` widen a key to `string`, which is the grep #713 requires to stay empty. So the alias's remaining job is to be that cast target. The comment now says so, in place of the vaguer "for indexing it and the tables below". Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01PMVYzkDeF2h7omX6isDqFH
|
Pushed Answered, left open — is aliasing They are already enforced: Trading two casts for one fewer name is yours to decide. Say so and I delete it. Lean gate green on 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
@Ardnived chose the trade on the review thread: one fewer name for the same shape, at the price of two `as ProjectSlug` casts back in `src/`. `projects.ts` now writes the generated `ProjectSlug` at all twelve positions. The two casts are where `Object.keys` and `Object.entries` widen a key to `string` — `PROJECT_TO_COLLECTIONS`' reducer and `getProjectSlugs`. Both carry a one-line comment naming the widening, since the alias's doc comment used to carry that fact. `getProjectSlugs` now names the type its own output generates. That is sound rather than circular: the `satisfies Record<ProjectSlug, unknown>` clause on `PROJECTS` (#712) fails `pnpm typecheck` if `payload-types.ts` ever goes stale against these keys, so the annotation cannot outlive the values it describes. This retires #713's acceptance criterion — `grep -rn "as ProjectSlug" src/` is no longer empty, by the reviewer's explicit decision. The two hits it returns are the only ones, and both are assertions over a widened key, never a boundary restating its own type. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Pbm8oVh7Q9wQxmsvh3XuRb
…roject-slug-returns
|
Pushed Adopted, resolved — remove the alias and add the casts →
So Merged No threads left open. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Summary
ProjectSlug, at every position inprojects.tsandroles.ts.InternalProjectSlugis deleted.import type, or a comment.Changes
plugins/access/config/projects.tsInternalProjectSlugdeleted;ProjectSlugat all twelve positions; twoas ProjectSlugassertions whereObject.keys/Object.entrieswiden a key tostringplugins/access/config/roles.tsgetProjectsFromRolesandgetRoleProjectreturnProjectSlug; theSetfollows; theInternalProjectSlugimport goescomponents/admin/PermissionsTable.tsxproject is ProjectSlugpredicate deleted, with its now-dead importcomponents/admin/ProjectSelector/ProjectSelector.tsxcomponents/admin/Dashboard/ProjectSelectionPrompt.tsxcontexts/ProjectContext.tsxPreview
Test results
pnpm lint,pnpm typecheck,pnpm typecheck:tests,pnpm test:unit(1671 tests) — re-run ond663518, after mergingmainrole-based-access.int.spec.ts— 56 passed, no editsManual verification
Nothing automated reaches the admin project switcher, and three of the six files are that UI. As a non-admin manager holding roles in two projects:
POST /api/managers/set-project) and reloads the correct scope.Notes for reviewer
grep -rn "as ProjectSlug" src/is no longer empty. It returns exactly two hits, both assertions over a key thatObject.keysorObject.entrieswidened tostring— never a boundary restating its own type. The ticket asked for an empty grep as a proxy for "one name per shape"; deleting the alias buys the actual property and costs the proxy.getProjectSlugsnow names the type its own output generates. That is sound rather than circular:PROJECTS'as const satisfies Record<ProjectSlug, unknown>(refactor(access): make isValidProject a type predicate, deleting three ProjectSlug casts #712) turns a stalepayload-types.tsinto a failing type-check, so the annotation cannot outlive the values it describes.getRoleProjectalso returned the internal name, andPermissionsTable.tsx:69compensated inside a type predicate rather than a cast — invisible to the ticket's grep. Each behaviour is its own commit, revertable separately.ProjectSlug, the predicate only stripsundefined, which TypeScript 5.7 infers on its own (inferred type predicates, 5.5+). Checked rather than assumed: replacing the filter with a non-narrowing one turnspnpm typecheckred atgetProjectIconandgetProjectLabel, so the compiler holds the narrowing where the annotation used to.Detail
Why this is compiler-held rather than asserted. #712 pinned
PROJECTSwithas const satisfies Record<ProjectSlug, unknown>, which is bidirectional on an object literal: a missing key fails thesatisfies, an extra key fails the excess-property check. Confirmed by renaming aPROJECTSkey —pnpm typecheckgoes red across the consumers rather than accepting the drift, including atProjectSelectionPrompt.tsxwhere a deleted cast used to sit. That pin is also what makes the two restored casts honest: each asserts back to a type the same clause proves the keys inhabit.Findings dismissed, with reasons.
ProjectSelector's option round-trip into afilter. Raised by three lenses, and the redundancy is real — with the cast gone, the rebuilt object literal is field-identical to the option it was found from. Rejected because it changes ordering: the loop iteratesallowedProjects(role order), a filter would iteratePROJECTSorder, so a non-admin with two projects gets a differently ordered dropdown. That is a behaviour change this PR promises not to make. Worth doing on its own.getProjectIcon,getProjectLabel,getProjectEmailIcon,getProjectCollectionstoProjectSlugtoo. Moot now — with the alias gone they all readProjectSlug, which was always the same union.Review threads, all three resolved.
PermissionsTable.tsx:69(thread onroles.ts:176) — adversarial review, adopted in142cee4.InternalProjectSlugcomment (thread onprojects.ts:121) — adversarial review, adopted ineb37f61, 18 lines down to 8.PROJECTS' keys should be enforced asProjectSluginstead of aliased (thread onprojects.ts:113) — @Ardnived. They already are, from refactor(access): make isValidProject a type predicate, deleting three ProjectSlug casts #712, which made the alias removable rather than necessary. Measured before proposing:ProjectSlugat all twelve positions type-checks clean, at a cost of two casts. @Ardnived chose that trade, and2592abaimplements it. The comment those 8 lines carried is now two one-line notes at the cast sites plus four lines ongetProjectSlugs— the facts survived, the name did not.Review coverage.
/pr-review-toolkit:review-prwas unavailable — no plugins are enabled in this session. Substituted the in-session/code-review(no findings; it caught one inaccurate sentence in a doc comment) plus four/simplifylenses./security-reviewran becausesrc/plugins/access/matches this repo's trigger pattern: no findings, having verified thatProjectSlugis a closed three-member literal union, thatisValidProject's runtimeObject.hasOwncheck is untouched, and thatset-project's zod boundary accepts exactly what it did before. The alias deletion changes no union and no runtime check, so that verdict still holds.Closes #713
🤖 Written by the sydevs autonomous loop — see what this is
🤖 Generated with Claude Code
https://claude.ai/code/session_01Pbm8oVh7Q9wQxmsvh3XuRb