Skip to content

refactor(access): speak the generated ProjectSlug throughout the access config, deleting the internal alias - #746

Merged
sydevs-bot merged 8 commits into
mainfrom
claude/refactor-713-project-slug-returns
Sep 10, 2026
Merged

sydevs-bot merged 8 commits into
mainfrom
claude/refactor-713-project-slug-returns

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The access config now speaks one name for one shape: the generated ProjectSlug, at every position in projects.ts and roles.ts. InternalProjectSlug is deleted.
  • Scope shifted twice, both times on review. A review pass found an eighth instance of the ticket's shape that its grep cannot see. @Ardnived then asked why the alias exists at all, and chose to trade it for two casts.
  • No runtime change. Every hunk is an annotation, an import type, or a comment.

Changes

File Change
plugins/access/config/projects.ts InternalProjectSlug deleted; ProjectSlug at all twelve positions; two as ProjectSlug assertions where Object.keys / Object.entries widen a key to string
plugins/access/config/roles.ts getProjectsFromRoles and getRoleProject return ProjectSlug; the Set follows; the InternalProjectSlug import goes
components/admin/PermissionsTable.tsx The hand-written project is ProjectSlug predicate deleted, with its now-dead import
components/admin/ProjectSelector/ProjectSelector.tsx Two casts deleted
components/admin/Dashboard/ProjectSelectionPrompt.tsx Cast and its now-dead import deleted
contexts/ProjectContext.tsx Cast deleted

Preview

Test results

  • Lean gate: ✓ pnpm lint, pnpm typecheck, pnpm typecheck:tests, pnpm test:unit (1671 tests) — re-run on d663518, after merging main
  • Targeted spec: ✓ role-based-access.int.spec.ts — 56 passed, no edits
  • Build: N/A — Railway builds the preview

Manual 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:

  1. The Current Project selector lists both projects, in the same order as before.
  2. Switching projects still persists (POST /api/managers/set-project) and reloads the correct scope.
  3. A manager with no roles still sees the "no projects available" prompt, not an empty selector.
  4. The Manager permissions table still lists both project pills in its footer.

Notes for reviewer

  • refactor(access): return ProjectSlug from getProjectsFromRoles and getProjectOptions, deleting four more casts #713's acceptance criterion is retired, by the reviewer's explicit decision. grep -rn "as ProjectSlug" src/ is no longer empty. It returns exactly two hits, both assertions over a key that Object.keys or Object.entries widened to string — 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.
  • getProjectSlugs now 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 stale payload-types.ts into a failing type-check, so the annotation cannot outlive the values it describes.
  • The title is the ticket's; the diff is one function wider. getRoleProject also returned the internal name, and PermissionsTable.tsx:69 compensated inside a type predicate rather than a cast — invisible to the ticket's grep. Each behaviour is its own commit, revertable separately.
  • The eighth instance is deleted, not merely enabled. With both sides ProjectSlug, the predicate only strips undefined, 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 turns pnpm typecheck red at getProjectIcon and getProjectLabel, so the compiler holds the narrowing where the annotation used to.
Detail

Why this is compiler-held rather than asserted. #712 pinned PROJECTS with as const satisfies Record<ProjectSlug, unknown>, which is bidirectional on an object literal: a missing key fails the satisfies, an extra key fails the excess-property check. Confirmed by renaming a PROJECTS key — pnpm typecheck goes red across the consumers rather than accepting the drift, including at ProjectSelectionPrompt.tsx where 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.

  • Collapse ProjectSelector's option round-trip into a filter. 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 iterates allowedProjects (role order), a filter would iterate PROJECTS order, 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.
  • Move getProjectIcon, getProjectLabel, getProjectEmailIcon, getProjectCollections to ProjectSlug too. Moot now — with the alias gone they all read ProjectSlug, which was always the same union.

Review threads, all three resolved.

  • PermissionsTable.tsx:69 (thread on roles.ts:176) — adversarial review, adopted in 142cee4.
  • The length of the InternalProjectSlug comment (thread on projects.ts:121) — adversarial review, adopted in eb37f61, 18 lines down to 8.
  • Whether PROJECTS' keys should be enforced as ProjectSlug instead of aliased (thread on projects.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: ProjectSlug at all twelve positions type-checks clean, at a cost of two casts. @Ardnived chose that trade, and 2592aba implements it. The comment those 8 lines carried is now two one-line notes at the cast sites plus four lines on getProjectSlugs — the facts survived, the name did not.

Review coverage. /pr-review-toolkit:review-pr was 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 /simplify lenses. /security-review ran because src/plugins/access/ matches this repo's trigger pattern: no findings, having verified that ProjectSlug is a closed three-member literal union, that isValidProject's runtime Object.hasOwn check is untouched, and that set-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

…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
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-746 September 9, 2026 16:21 Destroyed
@railway-app

railway-app Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

🚅 Deployed to the SahajCloud-pr-746 environment in sahajcloud

Service Status Web Updated
SahajCloud ✅ Success (View Logs) Web Sep 10, 2026 at 3:01 am UTC
1 service not affected by this PR
  • mailpit

@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 9, 2026
@sydevs-bot

sydevs-bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running
CI fix 2

recent dispatches
  • 02:53Z address-review · attempt 1 · session · done
  • 02:53Z address-review · attempt 1 · session
  • 01:26Z address-review · attempt 1 · session · done
  • 01:26Z address-review · attempt 1 · session
  • 16:50Z fix-ci · attempt 1 · session · done

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 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:69 still asserts the type this PR made redundant → thread on roles.ts:176.
  • consider — the InternalProjectSlug comment carries three rationales → thread on projects.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

Comment thread src/plugins/access/config/roles.ts Resolved
Comment thread src/plugins/access/config/projects.ts Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 9, 2026
`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
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-746 September 9, 2026 16:45 Destroyed
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Both adversarial findings adopted. Pushed eb37f61.

Nothing rebutted, nothing asked. Gate green: lint, both typechecks, 1669 unit tests, and role-based-access.int.spec.ts at 56 passed. PR body refreshed.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 9, 2026
@sydevs-bot
sydevs-bot requested a review from Ardnived September 10, 2026 00:50
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

This draft has had no CI activity for hours and no session holds it. Comment or push to wake me.

🤖 sydevs dispatcher

@sydevs-bot

Copy link
Copy Markdown
Contributor Author

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

@sydevs-bot
sydevs-bot marked this pull request as ready for review September 10, 2026 01:22
Comment thread src/plugins/access/config/projects.ts Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Sep 10, 2026
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
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-746 September 10, 2026 01:33 Destroyed
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Pushed edeaa45. One thread, and it needs your call rather than a fix.

Answered, left open — is aliasing PROJECTS' keys better than enforcing ProjectSlug?

They are already enforced: projects.ts:91, from #712. So the alias is removable, and I measured it — ProjectSlug at all twelve positions passes pnpm typecheck. It costs two as ProjectSlug casts back in src/ (:125, :205), which is the grep #713 empties. I kept the alias and documented it as that cast target, replacing a vaguer line that failed to preempt your question.

Trading two casts for one fewer name is yours to decide. Say so and I delete it.

Lean gate green on edeaa45, plus role-based-access.int.spec.ts (56 passed).

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added awaiting bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. awaiting labels Sep 10, 2026
@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
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-746 September 10, 2026 02:59 Destroyed
@sydevs-bot sydevs-bot changed the title refactor(access): return ProjectSlug from getProjectsFromRoles and getProjectOptions, deleting four more casts refactor(access): speak the generated ProjectSlug throughout the access config, deleting the internal alias Sep 10, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Pushed d663518. Your call is implemented — the alias is gone.

Adopted, resolved — remove the alias and add the casts → 2592aba

projects.ts writes ProjectSlug at all twelve positions. The two as ProjectSlug casts sit where Object.keys and Object.entries widen a key to string, each with a one-line comment saying so. getProjectSlugs now names the type its own output generates — sound, not circular, because #712's satisfies pin fails typecheck on a stale payload-types.ts.

So grep -rn "as ProjectSlug" src/ is no longer empty, which was #713's acceptance criterion. The PR body records that you retired it deliberately. Two hits, both over a widened key.

Merged main in (timezone labels, 8483cb7). Lean gate green on the merged tree — 1671 unit tests — plus role-based-access.int.spec.ts, 56 passed.

No threads left open.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 10, 2026
@sydevs-bot
sydevs-bot merged commit 88587ab into main Sep 10, 2026
21 of 22 checks passed
@sydevs-bot
sydevs-bot deleted the claude/refactor-713-project-slug-returns branch September 10, 2026 04:43
@sydevs-bot sydevs-bot moved this from Revising to Done in SYDevelopers Technical Roadmap Sep 10, 2026

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-746 — d663518c Deployed Sep 10, 2026 by railway-app[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

refactor(access): return ProjectSlug from getProjectsFromRoles and getProjectOptions, deleting four more casts

3 participants