Repository navigation
test(admin): pin the admin routes every literal assumes - #859
Conversation
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
|
🚅 Deployed to the SahajCloud-pr-859 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
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/accountand/resetliterals.consider—payload.config.ts:103: defeats the ticket'sgrep -n routes src/payload.config.tscheck.consider—admin-route-config.int.spec.ts:18:ADMIN_ROUTEstays 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
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
|
Addressed the adversarial review in two commits, pushed as Adopted
Asked
Gate: lint, 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
Updated #851's verification checklist, as you asked. No code changed, so nothing is pushed — 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 |
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
Summary
/adminliterals stay, and a spec now fails ifroutes.adminis ever set.admin.routes.accountand.resettoo — a second namespace twoadminUrl()callers spell into, and the comment this adds sits exactly where someone would move them.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 plusadminUrl()'s own literal against it.src/payload.config.ts— whyroutes.adminstays unset, above the block where it would be set.src/lib/utilities/adminUrl.ts— a breadcrumb from theadminRoute: '/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
AdminNavLinksmarks active by path comparisonTest results
tsc(src + tests), 2237 unit testsadmin-route-config.int.spec.tsandcors-config.int.spec.ts, 3 passed4211379): the same gate, plusadmin-route-config.int.spec.tsandmanager-auth-urls.spec.ts, 2 passedEach assertion was watched failing on its own defect, then restored:
routes: { admin: '/cms' }expected '/cms' to be '/admin'admin.routes.reset: '/password-reset'expected '/password-reset' to be '/reset'adminRoute: '/administrator'inadminUrl…/administrator/collections/…vs…/admin/collections/…Fixture pre-mortem: the spec's "fixture" is the real config. It asserts
routesis absent fromsrc/payload.config.ts— verified by reading the file, and by the resolved value coming back as Payload's/admindefault.Manual verification
None. The decision is to change no href, so there is nothing new to click.
Notes for reviewer
AnalyticsNavLink.tsxis dead code. #851 names it twice, but it is in no import map and nothing imports it;AdminNavLinks+NavLinkreplaced it, anddocs/rules/admin-ui.md:230still lists it inbeforeNavLinks. Left out of this PR and filed separately — deleting it is not this ticket.#851's
grep -n "routes" src/payload.config.tsstep 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.@Ardnivedapproved that edit, and the checklist now runstests/int/admin-route-config.int.spec.tsin its place. No code changed for it.redeemToken.ts:216is notadminUrl()'s case after all, contrary to the ticket body. The paths it joins already carry the/adminprefix (they passisAdminPath), soadminUrl()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 aNEXT_BASE_PATHdeploy:formatAdminURL's absolute branch prependsbasePathunconditionally, whileincludeBasePathgates only the relative one.tests/unit/manager-auth-urls.spec.tsstates the same rule for the same reason.Dismissed findings.
payloadConfig, sopayloadConfig({ 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.isE2ETest/isProduction/isTestEnvironmentbranch insrc/payload.config.tstouchesroutes. A laterroutes: isProduction ? … : {}would pass. Same trade as above.tests/int/cors-config.int.spec.tsis the precedent the ticket names, and importing@/payload.configis the Payload boot thatdocs/rules/testing-reqs.mdkeeps out of the unit lane.Options 2 and 3 were not costed further. Open question 1 is answered no —
NEXT_BASE_PATHappears nowhere butadminUrl.ts's own JSDoc — so onlyroutes.adminwas ever at stake, and@Ardnivedchose option 1.Adversarial review, addressed in
dd471edand4211379. Theshould-fixwas real: thepayload.config.tscomment credited the panel's hrefs andisAdminPathwith spelling/accountand/reset, and neither does —token.ts:91tests/admin/only, and those two literals live ininvite.ts:156andManagers.ts:42, bothadminUrl()callers.manager-auth-urls.spec.ts'sADMIN_ROUTEdocblock 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 becausesrc/payload.config.tsmatchessecurityReview.triggerPatternand 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