Skip to content

test(admin): pin the admin routes every literal assumes - #859

Merged
sydevs-bot merged 3 commits into
mainfrom
claude/refactor-851-pin-admin-route
Sep 29, 2026
Merged

sydevs-bot merged 3 commits into
mainfrom
claude/refactor-851-pin-admin-route

Conversation

@sydevs-bot

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

Copy link
Copy Markdown
Contributor

Summary

  • Option 1 on refactor(admin): weigh building in-panel hrefs from routes.admin #851: the /admin literals stay, and a spec now fails if routes.admin is ever set.
  • The pin covers admin.routes.account and .reset too — a second namespace two adminUrl() callers spell into, and the comment this adds sits exactly where someone would move them.
  • No behaviour change. Nothing in src/ reads a route it did not read before.

Changes

  • tests/int/admin-route-config.int.spec.ts — reads the resolved config and pins three route defaults plus adminUrl()'s own literal against it.
  • src/payload.config.ts — why routes.admin stays unset, above the block where it would be set.
  • src/lib/utilities/adminUrl.ts — a breadcrumb from the adminRoute: '/admin' literal to the spec.
  • tests/unit/manager-auth-urls.spec.ts — ADMIN_ROUTE's docblock says why the literal stays in a lane that reads no config, and points at the pin.

Preview

  • Dashboard — the sidebar links whose hrefs this decision keeps as literals
  • Analytics — the one route AdminNavLinks marks active by path comparison

Test results

  • Lean gate: ✓ lint, tsc (src + tests), 2237 unit tests
  • Targeted specs: admin-route-config.int.spec.ts and cors-config.int.spec.ts, 3 passed
  • Re-run after review (4211379): the same gate, plus admin-route-config.int.spec.ts and manager-auth-urls.spec.ts, 2 passed
  • Build: N/A — Railway builds the preview

Each assertion was watched failing on its own defect, then restored:

Defect reintroduced Red
routes: { admin: '/cms' } expected '/cms' to be '/admin'
admin.routes.reset: '/password-reset' expected '/password-reset' to be '/reset'
adminRoute: '/administrator' in adminUrl …/administrator/collections/… vs …/admin/collections/…

Fixture pre-mortem: the spec's "fixture" is the real config. It asserts routes is absent from src/payload.config.ts — verified by reading the file, and by the resolved value coming back as Payload's /admin default.

Manual verification

None. The decision is to change no href, so there is nothing new to click.

Notes for reviewer

AnalyticsNavLink.tsx is dead code. #851 names it twice, but it is in no import map and nothing imports it; AdminNavLinks + NavLink replaced it, and docs/rules/admin-ui.md:230 still lists it in beforeNavLinks. Left out of this PR and filed separately — deleting it is not this ticket.

#851's grep -n "routes" src/payload.config.ts step is retired. The comment this PR adds makes that grep hit, so the step was obsolete rather than wrong — the pin checks the same thing and checks it better. The comment cannot avoid the bare word without dropping the key names it exists to supply, so the checklist line was the half to change. @Ardnived approved that edit, and the checklist now runs tests/int/admin-route-config.int.spec.ts in its place. No code changed for it.

redeemToken.ts:216 is not adminUrl()'s case after all, contrary to the ticket body. The paths it joins already carry the /admin prefix (they pass isAdminPath), so adminUrl() would double it. It stays a literal, covered by the pin.

Detail

Why the expectation joins through formatAdminURL. A hand-joined
`${getServerUrl()}${route}${path}` passes today and goes red on a NEXT_BASE_PATH deploy: formatAdminURL's absolute branch prepends basePath unconditionally, while includeBasePath gates only the relative one. tests/unit/manager-auth-urls.spec.ts states the same rule for the same reason.

Dismissed findings.

  • Add a boot-time throw in payloadConfig, so payloadConfig({ routes: … }) is covered too. Real door, no caller: nothing passes overrides today (export default payloadConfig() is the only call). A throw at boot is a behaviour change the ticket did not ask for, and it would refuse a legitimate future override. The named export stays unpinned, deliberately.
  • The pin observes one environment's build of an env-branched config. True, and checked: no isE2ETest / isProduction / isTestEnvironment branch in src/payload.config.ts touches routes. A later routes: isProduction ? … : {} would pass. Same trade as above.
  • Move the spec to the unit lane, since it boots no database. tests/int/cors-config.int.spec.ts is the precedent the ticket names, and importing @/payload.config is the Payload boot that docs/rules/testing-reqs.md keeps out of the unit lane.

Options 2 and 3 were not costed further. Open question 1 is answered no — NEXT_BASE_PATH appears nowhere but adminUrl.ts's own JSDoc — so only routes.admin was ever at stake, and @Ardnived chose option 1.

Adversarial review, addressed in dd471ed and 4211379. The should-fix was real: the payload.config.ts comment credited the panel's hrefs and isAdminPath with spelling /account and /reset, and neither does — token.ts:91 tests /admin/ only, and those two literals live in invite.ts:156 and Managers.ts:42, both adminUrl() callers. manager-auth-urls.spec.ts's ADMIN_ROUTE docblock restated the assumption this PR now asserts, so it points at the pin and says why the literal stays: that lane imports the Managers collection, not the config. The third finding is the retired checklist step above, closed by the issue-body edit.

Review. /simplify (reuse, simplification, altitude lenses; the efficiency lens was skipped — the diff adds no runtime code) and /security-review, which ran because src/payload.config.ts matches securityReview.triggerPattern and found nothing: the only non-test change to it is a comment. comment-lint: no banned phrasing added. Docs checked, nothing stale.

Closes #851

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

The panel builds its hrefs from literal `/admin/…` strings, and `adminUrl()`
joins outbound links against a literal `adminRoute`. Reading `routes.admin`
instead was weighed and declined (#851): nothing in this repo reads that route
and nothing sets it, so converting fourteen files — and threading the route
into `buildRegionCreateUrl`, which is a pure module and can call no hook —
buys route-awareness for a route with no buyer.

What the literals were missing is a way to fail. Setting `routes.admin` moves
the panel and strands every literal, and nothing would have said so until
someone clicked.

The spec reads the resolved config, so it fails on the value Payload applies
rather than on the source text, and it joins the expected URL through Payload's
own `formatAdminURL` — a hand-joined string would go red on a `NEXT_BASE_PATH`
deploy, which `adminUrl()` exists to keep working.

It pins `admin.routes.account` and `.reset` as well, because that is a second
namespace defaulted separately, and two `adminUrl()` callers spell one of its
segments: the reset mail's `/reset/:token` and the invitation's `/account`.
Moving either points the mail at no view, which is #320 — the recipient lands
on the login form and nothing errors. The comment this adds sits directly above
`admin: {`, where someone would set exactly that.

Each of the three was watched failing on its own defect: `routes: { admin:
'/cms' }`, `admin.routes.reset: '/password-reset'`, and `adminRoute:
'/administrator'` inside `adminUrl`.

Refs #851

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016J7RXdex3C3DQMDLqSmHQm
@railway-app

railway-app Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

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

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

@sydevs-bot

sydevs-bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 03:34Z address-review · attempt 1 · session · done
  • 03:34Z address-review · attempt 1 · session
  • 23:59Z address-review · attempt 1 · session · done
  • 23:59Z address-review · attempt 1 · session
  • 23:49Z adversarial-review · 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

Option 1 arrives at the size of the problem: one spec, two comments, no contract surface, nothing in src/ newly reading a route. The pin fails on all three routes, each watched red.

All three findings are about the comments, which is where this diff's substance sits. One is wrong about who spells /account and /reset. And the ticket asked to pin the assumption in one place — it is now explained in four.

Findings

  • should-fix — payload.config.ts:100: misattributes the /account and /reset literals.
  • consider — payload.config.ts:103: defeats the ticket's grep -n routes src/payload.config.ts check.
  • consider — admin-route-config.int.spec.ts:18: ADMIN_ROUTE stays outside the pin this diff creates.

What was checked

Read whole: #851, adminUrl.ts, token.ts, cors-config.int.spec.ts, manager-auth-urls.spec.ts. Each pinned route also has caller-side cover (manager-invite.int.spec.ts:333, manager-auth-urls.spec.ts:56). Ran the ticket's grep on both refs: exit 1 on main, exit 0 here.

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


Generated by Claude Code

Comment thread src/payload.config.ts Resolved
Comment thread src/payload.config.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 28, 2026
The comment credited the panel's hrefs, `adminUrl()` and `isAdminPath` with
spelling all three routes as literals. Two of the three have different
spellers, so a reader who trusted the line would grep the panel and
`isAdminPath` for `/account`, find nothing, and be no closer — which is the
search the comment exists to shorten.

`isAdminPath` (`plugins/login/token.ts:91`) tests `/admin/` and nothing else.
The only `/account` and `/reset` literals in `src/` are two `adminUrl()`
callers: `invite.ts:156` and `Managers.ts:42`.

Refs #851

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PFaH4dYDg6AxXE3UR3L6Gg
`ADMIN_ROUTE` justified itself by restating that `routes.admin` is unset — the
claim `admin-route-config.int.spec.ts` now asserts. Four statements of one
assumption, one of which can fail, and the docblock did not say which.

It keeps the literal: this lane imports the Managers collection, not the
config, so there is no route here to read. That is the part a reader cannot
re-derive, so it is what the docblock says now.

Refs #851

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PFaH4dYDg6AxXE3UR3L6Gg
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Addressed the adversarial review in two commits, pushed as 4211379.

Adopted

  • The misattributed spellers — dd471ed. token.ts:91 tests /admin/ and nothing else, and the only /account and /reset literals in src/ are invite.ts:156 and Managers.ts:42.
  • ADMIN_ROUTE left outside the pin — 4211379. Its docblock points here, and says why a lane that reads no config keeps the literal.

Asked

  • #851's grep -n "routes" step — the comment cannot drop the bare word without dropping the key names it exists to supply, so the checklist line is what should go. That edits an issue body, which this repo asks you to approve.

Gate: lint, tsc (src + tests), 2237 unit tests. admin-route-config.int.spec.ts and manager-auth-urls.spec.ts, 2 passed.

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


Generated by Claude Code

@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-859 September 29, 2026 00:09 Destroyed
@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 29, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review September 29, 2026 00:17
@sydevs-bot
sydevs-bot requested a review from Ardnived September 29, 2026 00:17
@sydevs-bot sydevs-bot added awaiting bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Sep 29, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Sep 29, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Updated #851's verification checklist, as you asked. No code changed, so nothing is pushed — 4211379 is still the head.

Adopted

The PR body's reviewer note said that edit was waiting on you. It now records the outcome instead.

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


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 29, 2026
Merged via the queue into main with commit d7a74ce Sep 29, 2026
84 of 87 checks passed
@sydevs-bot
sydevs-bot deleted the claude/refactor-851-pin-admin-route branch September 29, 2026 03:47
sydevs-bot pushed a commit that referenced this pull request Sep 29, 2026
Only `tests/unit/manager-auth-urls.spec.ts` conflicted: this branch deletes it,
and #859 rewrote its `ADMIN_ROUTE` docblock. The deletion stands —
`Managers.auth.forgotPassword` is gone, so the reset URL the spec asserted can
no longer be built. #859's substance is `tests/int/admin-route-config.int.spec.ts`,
which reads the resolved config and merges untouched; the conflicted hunk was a
pointer to that spec, not a claim this one made.

Three pointers the deletion left dangling are repointed. The integration spec's
docblock no longer names the deleted file, and no longer calls the reset mail an
`adminUrl()` caller — `invite.ts` and `/account` are the only pair left.
`src/payload.config.ts` says the same. `email-templates.spec.ts` points at
`manager-invite.spec.ts` for the URL shapes it takes as inputs.
`admin.routes.reset` stays pinned with no caller to spell it, since a future
one would be stranded the same way.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Rytwy6uzbxca5RgKhJomx3

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-859 — 42113790 Deployed Sep 29, 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(admin): weigh building in-panel hrefs from routes.admin

3 participants