Skip to content

fix(ci): restore Railway preview URLs, fail closed when none is found - #703

Merged
sydevs-bot merged 5 commits into
mainfrom
claude/fix-railway-preview-fail-closed
Sep 5, 2026
Merged

sydevs-bot merged 5 commits into
mainfrom
claude/fix-railway-preview-fail-closed

Conversation

@sydevs-bot

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

Copy link
Copy Markdown
Contributor

Summary

  • A Railway deploy that reports success while publishing no host now fails CI instead of skipping the smoke lane and leaving the job green.
  • Discovery returns on the first terminal status. On this PR it took 2 seconds, against 12m15s before.
  • The decision moves into a pure module, so the unit lane covers it. Three docs asserted the false premise behind the outage.

Changes

  • scripts/railway-preview-status.ts — new. classifyStatuses (ready / unpublished / pending / failed / absent) plus discoverPreview over an injected clock, sleep and fetch. StatusFetchError carries GitHub's HTTP status, so a permanent refusal is distinguishable from a retryable one
  • scripts/get-railway-preview-url.ts — keeps env parsing, the GitHub fetch, the health check and the exit codes; gains one non-zero exit
  • tests/unit/railway-preview-status.spec.ts — new, 17 cases
  • RAILWAY_RUNBOOK.md, tests/AGENTS.md, scripts/AGENTS.md, playwright.config.ts, ci.yml comments — the corrections below

Preview

https://sahajcloud-sahajcloud-pr-703.up.railway.app

Four acceptance criteria are met by observation on this PR's own CI run, not by argument. This is the first PR opened since the production domain was added on 2026-09-05, and existing PR environments do not backfill — so it is the first commit that could ever satisfy them.

# Criterion Evidence, run 33977872448
2 The status carries a host, and the bot's Web column is populated success Success - sahajcloud-sahajcloud-pr-703.up.railway.app, and the railway-app comment links Web. #699's read a bare Success an hour earlier
3 Smoke executes rather than skipping Step 13 Run smoke specs against the Railway preview → success, 53s. Step 12, the skip warning, did not fire
5 Still exits 0 with no preview environment Unchanged path, exercised locally — see the table below
6 Discovery completes in seconds, not 12 minutes Step 11 → 2s (16:34:42 → 16:34:44). The run this ticket was filed against spent 12m15s on 48 identical polls

The Tier-3 smoke lane has now run on a PR for the first time since #653.

Test results

  • CI: ✓ green on 3551af8 — lint, typecheck, typecheck:tests, pnpm test, discovery, smoke. Re-running on 20e64c9
  • Lean gate: ✓ pnpm lint, pnpm typecheck, pnpm typecheck:tests, pnpm test:unit (124 files, 1589 tests)
  • Targeted specs: railway-preview-status 17 passed
  • Targeted integration specs: none — no spec reads these files
  • Build: N/A — Railway builds the preview

Every new assertion was confirmed to fail first. Classifying success-with-no-host as pending again — the original behaviour, at the line that caused it — turns three red. Removing the deadline clamp turns the budget assertion red (45s against a 40s budget). Removing the 401/403 branch turns the two new forbidden assertions red.

Each exit path was also exercised end to end through main() with a stubbed fetch, because a passing unit spec is not evidence that its caller reaches the branch:

Case Result
success, no host exit 1, ::error, empty preview_url, ~1s
success with host exit 0, URL exported, health check passed
error (cancelled) exit 0, empty — unchanged skip
every read 401/403 exit 1, ::error, on the first poll — measured at 1s
every read 502 still polling at 95s (7 polls), no exit — the retry path is intact. Its ::warning skip at the deadline is spec'd, not timed
missing env exit 0, empty — unchanged skip

Manual verification

  1. Nothing blocking — criteria 2, 3, 5 and 6 are settled by the run above. What remains is a judgement call, not a check.
  2. Worth one look: three of the six smoke specs still skip, on an unseeded preview DB. That is fix(test): three smoke specs skip on every PR instead of asserting #704, split out of this ticket as its Out-of-scope section asked, not a regression here. So "smoke: success" today means three specs asserted, three skipped.

Notes for reviewer

  • The extra non-zero exit is now narrow, and the question about it is smaller. Review found that failing on any run where every statuses read failed had a transient trigger — a statuses-API incident outlasting the 12-minute deadline would redden every open PR — and burnt the whole budget first. That exit is gone. In its place, fetchStatuses carries res.status and a 401/403 alone is terminal on the first refusal, since GitHub will not relent inside one run. It keeps the property worth keeping: never having looked is not evidence of absence. A sustained transient failure now warns and skips. Still outside fix(ci): restore Railway preview URLs, fail closed when none is found #661's letter, so still yours to veto — the rest of the PR does not depend on it.
  • Acting on the first unpublished is deliberate, and its evidence is now written down. The rationale used to overclaim that GitHub could not revise the status. It can. The docstring now records what is actually known: the evidence is settled-state only (docs(claude): link tests/AGENTS.md, and correct what pnpm test covers #699, fix(migrations): drop the constraint drops that CASCADE already handled #700), bounded by discovery starting about six minutes into the job, so the status it reads is already minutes old. Behaviour unchanged — fix(ci): restore Railway preview URLs, fail closed when none is found #661 resolved immediate over one grace re-poll.
  • The genuine skip paths are untouched. An absent, failed, or still-building preview still exits 0.
  • Ticket step 1 needs no action — production's SahajCloud service already carries sahajcloud-production.up.railway.app on port 8080 beside the custom domain, and the table above is the evidence it took.
Detail

What the bug actually was. state === 'success' was true immediately, but url was null, so neither the break nor the failure return fired. The loop re-read an identical, immutable status every 15s for the full budget, then exported an empty preview_url and exited 0. ci.yml gates the smoke step on that value, so the step skipped and the job reported success. All 17 most recent CI runs skipped smoke; cors-preflight, error-disclosure and images had never run in CI at all — until this run.

Why the client, not the config. The Railway domain cannot be fixed in git. What CI owed was the ability to tell "there is no preview" from "the preview is broken", and that distinction is now a first-class classification rather than a null check.

Fixture pre-mortem. The specs assume Railway posts context sahajcloud - SahajCloud — <project> - <service> — with either Success - <host>.up.railway.app or a bare Success. Verified against the live commit statuses on #700 (host present) and #699 (bare), read through the GitHub statuses API. Review caught that the sibling-service fixture used mailpit - Mailpit, a context Railway never posts; it is now sahajcloud - Mailpit, which makes the case real and puts the load-bearing detail on the record — the discrimination rests on includes being case-sensitive.

Quality passes. /simplify over four angles and /code-review at high effort. Applied: the deadline clamp (15s of dead CI clock per timing-out run, and a budget that overran by up to one interval); logging the classification rather than GitHub's raw state, which drops the statusState helper and a redundant state field; making last/elapsedMs load-bearing in the timeout message instead of test-only; trimming the remediation duplicated between the ::error string and its own comment; folding the runbook correction into the paragraph it supersedes rather than appending below it; and fixing a skip warning I had made less accurate, which claimed "no preview environment" for three different causes.

Then an adversarial review round, whose three findings are all applied above: narrowing the second hard failure to 401/403, recording the evidence behind the unpublished decision, and correcting the sibling-service fixture.

Dismissed: sharing a pollUntil between this loop and waitHealthy — real duplication, but waitHealthy is pre-existing and untouched here, so it would widen the diff past the ticket. Shortening the budget for a status never seen at all — #661 keeps the genuine skip paths as they are. Raising "any skipped smoke lane fails the job" to a workflow-level rule — a fair altitude point, and the one place this fix stays an exception rather than a policy, but #661 resolved that the fail-open is correct for PRs with no preview. Worth its own ticket if a third variant appears.

Pipeline notes. /pr-review-toolkit:review-pr all is not installed in this environment, so /code-review high ran instead — the pass the toolkit replaced. /security-review was gated off: securityReview.triggerPattern in .claude/workflow.json matches none of the changed paths. Flagged so the substitutions are visible rather than assumed.

Closes #661

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

🤖 Generated with Claude Code

https://claude.ai/code/session_012noYdvt78W3aLKqJpDpEQY

Railway can report `success` on a PR deploy while the service has no
domain, so the commit-status description reads a bare `Success` with no
host after it. Discovery treated that as "not ready yet": neither the
success break nor the failure return fired, so it re-read the identical
immutable status every 15s for the full 12-minute budget, then exported an
empty `preview_url` and exited 0. `ci.yml` gates the smoke step on that
value, so the step skipped and the job stayed green.

The cost was silent and large. `Lint, Test & Smoke: pass` has meant "unit +
integration passed" on every PR for weeks, and three specs — `cors-preflight`,
`error-disclosure`, `images` — have never run in CI at all.

**A deploy that succeeds without a host is broken configuration, not an
absent preview.** PR services inherit a domain only from a base-environment
service that has one, so this is terminal on the first poll and re-running
changes nothing. Discovery now exits 1 with an `::error` naming the cause
and the fix. The genuine skips are untouched and still exit 0: no status
within the timeout, a failed or cancelled deploy, or missing env.

Returning on the first terminal status also ends the 12-minute wait. A
healthy PR now resolves in one poll.

`scripts/railway-preview-status.ts` splits the decision out as a pure
module — `classifyStatuses` plus `discoverPreview` over injected clock,
sleep and fetch — so the unit lane can cover it without network or a
direct-run guard on the CI entrypoint. The runner keeps env parsing, the
GitHub fetch, the health check and the exit codes.

Fixture note: the specs assume Railway posts context `sahajcloud -
SahajCloud` with either `Success - <host>.up.railway.app` or a bare
`Success`. Verified against the live statuses on #700 (host present) and
#699 (bare), not inferred.

The new specs were confirmed to fail before they passed: classifying
success-with-no-host as `pending` again — the original behaviour, at the
line that caused it — turns three of them red.

Every exit path was also exercised end to end through `main()` with a
stubbed fetch, since a passing unit spec is not evidence that its caller
reaches the branch: unpublished exits 1 in ~1s, ready exits 0 with the URL
exported, a failed deploy and missing env both exit 0 empty.

Docs corrected in the same pass. `playwright.config.ts` and
`tests/AGENTS.md` said the URL is "discovered via the Railway API"; it
comes from the GitHub commit-status API. `RAILWAY_RUNBOOK.md` claimed PR
previews need "no manual per-PR configuration" — the false premise behind
this outage — and now states the coupling to production's domain, with the
three quiet symptoms. `scripts/AGENTS.md` had no row for either script.

Infra step 1 of the ticket was already applied on 2026-09-05: production's
`SahajCloud` service has `sahajcloud-production.up.railway.app` on port
8080 beside the custom domain.

Closes #661

Claude-Session: https://claude.ai/code/session_01QkaVUYxFsjHJd1aN8hYhVP

Co-Authored-By: Claude Opus 5 <[email protected]>
Quality pass over the branch, plus two review findings worth fixing.

- Never sleep past the deadline. The sleep after the last useful poll
  gated nothing, and an unclamped one overran the advertised budget by up
  to a full interval — 15s of dead CI clock on every timing-out run. The
  new assertion fails without the clamp: a 40s budget reported 45s.
- Log the classification (`unpublished`, `pending`) rather than GitHub's
  raw state. Telling `unpublished` from `success` is the whole point of
  the change, so the log should say which. Drops the `statusState` helper
  and its type subtraction, and `state` off `unpublished`, where it is
  always `success` and so derivable from `kind`.
- Make `last` and `elapsedMs` load-bearing instead of test-only: the
  timeout message now says whether a status ever appeared, or which state
  it never left. That was the diagnostic the docstring already promised
  and never delivered.
- Trim the duplicated remediation from the `::error` string and its
  comment. RAILWAY_RUNBOOK.md owns the fix; a copy in a string literal is
  the one that goes stale while the runbook gets corrected.

**A run where every statuses read failed now exits 1 too.** Review found
the same silent green as #661 through another door: a revoked
`statuses: read` scope makes every poll throw, `last` stays `absent`, and
after 12 minutes the run reports "no preview" and exits 0 — indistinguishable
from a PR that genuinely has none. `reads`/`errors` on the timeout outcome
separate the two, and never having looked is not evidence of absence. A
genuinely absent, failed, or still-building preview is untouched and still
exits 0.

Verified through `main()` with a stubbed fetch and a virtual clock, not
just through the unit lane — a passing spec is no evidence that its caller
reaches the branch. All reads failing: 48 requests over the full 720s
budget, then exit 1.

**Not taken.** Review argued that acting on the first `unpublished` is
unsound, since a context can post a later status. The premise is right and
the docstring overclaimed, so the rationale is corrected in place — but
immediate failure is a resolved decision on #661, which named one grace
re-poll as the alternative and chose immediate. Also left alone: sharing a
`pollUntil` between this loop and `waitHealthy` (pre-existing, unchanged
here), and shortening the budget for a never-seen status (#661 keeps the
genuine skip paths as they are).

Claude-Session: https://claude.ai/code/session_01QkaVUYxFsjHJd1aN8hYhVP

Co-Authored-By: Claude Opus 5 <[email protected]>
The workflow comment is the first contract description a CI reader sees,
and it still said the step "skips gracefully" with no mention that it can
now fail the job — so someone debugging a red `Discover Railway preview
URL` would read an adjacent comment telling them that step does not fail.

`RAILWAY_RUNBOOK.md`'s CI section asserted the superseded rule five lines
above the new section correcting it. Folded the correction into the
paragraph it supersedes, rather than leaving a reader to hit the old
contract first and the amendment second.

The skip warning claimed "This PR has no preview environment", which is
only one of the three cases that reach it — a failed deploy and one still
building at the deadline also skip. It now points at the discovery step's
own log instead of guessing.

`scripts/AGENTS.md` records both non-zero exits.

Claude-Session: https://claude.ai/code/session_01QkaVUYxFsjHJd1aN8hYhVP

Co-Authored-By: Claude Opus 5 <[email protected]>
@railway-app

railway-app Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

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

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

@sydevs-bot
sydevs-bot marked this pull request as ready for review September 5, 2026 16:51

@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

Holistic. The core matches #661 exactly: classify success-with-no-host as terminal, fail closed, stop re-reading an immutable status. The diff is much larger than that sentence (+443/-68 over 8 files), but most of the excess earns its keep — the entrypoint calls main() at import, so the decision could not be tested without splitting it out, and keeping the split module in scripts/ beside its single owner is what src/AGENTS.md prescribes, not a src/lib/ detour that lib-boundary.spec.ts would then have to except. No contract surface is crossed; this is CI-internal, and all three doc claims the ticket named are corrected (I grepped for survivors and found none). The one part genuinely outside the ticket is the second non-zero exit, which the body already offers for veto — my read is that it should come out, or fail fast, for the reason in the thread.

Findings

  • should-fix — scripts/get-railway-preview-url.ts:146: the reads === 0 exit adds a second hard failure that #661 explicitly scoped out, with a transient trigger and a full 12-minute cost before it fires. Drop it, or carry res.status so 401/403 fails fast.
  • consider — scripts/railway-preview-status.ts:118: "the first unpublished is terminal" is evidenced at rest (#699, #700), not across the pending→success transition — the one shape that would redden a healthy PR.
  • consider — tests/unit/railway-preview-status.spec.ts:45: the OTHER fixture's context is not the shape Railway emits, so the sibling-service case is not really covered.

What was checked

  • Ticket vs diff. #661's Expected behaviour (3 items), Resolved decisions (4), Acceptance criteria (7) and Out of scope, measured against each file. Criterion 7 confirmed by grepping the repo for "Railway API" and "preview URL … automatic" — no survivors outside the corrected sentences. The ticket says ci.yml needs no change; the change there is comments plus the skip-warning text, which is a fair reading, not scope creep.
  • Code read whole: scripts/railway-preview-status.ts, scripts/get-railway-preview-url.ts (both, not just the diff), .github/workflows/ci.yml, tests/unit/railway-preview-status.spec.ts.
  • Placement rules, because a new single-caller module is the first thing to challenge: src/AGENTS.md ("supporting modules are single-owner code and stay in the folder — putting them in src/lib/ fails the one-consumer check") and tests/unit/lib-boundary.spec.ts's scripts/ carve-out. The location is right; I am not raising it.
  • Consumer side. The only out-of-repo caller of this script is finalize-pr's Railway carve-out in sydevs/claude-workflow (workflow/skills/finalize-pr/SKILL.md:220-221), which #661 listed as out of scope. It invokes the script with no env, so it exits at :103 before either new failure path — the new exit codes do not reach it, and the fast terminal return is a straight improvement there.
  • Live evidence, not the PR body's account of it: the head SHA's combined status is sahajcloud - SahajCloud / success / Success - sahajcloud-sahajcloud-pr-703.up.railway.app, and Lint, Test & Smoke is green on run 33977872448. That is what grounds the fixture finding.
  • Spec run locally: vitest run tests/unit/railway-preview-status.spec.ts — 14 passed, 427ms. I hand-traced the two clock assertions (45_000 → reads 3; 40_000 → sleeps [15000, 15000, 10000]) against discoverPreview's clamp rather than trusting green.
  • Type check by hand on PreviewOutcome's Exclude<…>: it does resolve to ready | failed | unpublished | timeout, so main()'s final narrowing to ready is sound.
  • Reviewer profile read and applied. Nothing raised on style, naming, or test volume.

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


Generated by Claude Code

Comment thread scripts/get-railway-preview-url.ts Resolved
Comment thread scripts/railway-preview-status.ts Resolved
Review of #703 found the `reads === 0` exit too blunt. It fired on any
cause, including a transient statuses-API incident that outlasted the
12-minute deadline — turning every open PR red, clearable only by a full
re-run — and it spent the whole budget before saying so. #661 resolved
that the fail-open is correct for a PR with genuinely no preview, and
scoped exactly one new hard failure.

`fetchStatuses` collapsed every non-ok response into one opaque Error, so
the loop could not tell a permanent 401/403 from a retryable 502. It now
throws StatusFetchError carrying `res.status`, and discovery returns a
`forbidden` outcome on the first 401/403 — terminal, like `unpublished`,
because GitHub will not relent inside one run. That keeps the property
worth keeping (never having looked is not evidence of absence) and drops
both the transient trigger and the 12-minute cost.

A budget spent entirely on transient errors now warns and skips instead
of failing. The remaining causes are the ones that clear on their own.

Also from review: the OTHER fixture used `mailpit - Mailpit`, a context
Railway never posts. Railway's shape is `<project> - <service>`, so a
sibling service is `sahajcloud - Mailpit`. The old fixture asserted
against an impossible string; the new one covers the case that can occur,
and records that the discrimination rests on `includes` being
case-sensitive.

And the `unpublished`-is-terminal docstring now records its evidence:
settled-state only (#699, #700), bounded by discovery starting about six
minutes into the job, so the status it reads is already minutes old.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012noYdvt78W3aLKqJpDpEQY
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-703 September 5, 2026 17:09 Destroyed
@Ardnived Ardnived removed the awaiting label Sep 5, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

All three review findings applied, in 20e64c9. The accept-or-veto question is smaller than it was.

The should-fix landed as the second option you offered. fetchStatuses now carries res.status, and only a 401/403 is terminal — on the first refusal, not 12 minutes later. The blanket reads === 0 failure is gone, so a statuses-API incident no longer reddens every open PR; it warns and skips. What survives is the narrow property: a revoked statuses: read scope must not read as an absent preview. Still outside #661's letter, so still yours to veto.

The two consider findings: the unpublished docstring now records its evidence and its bound rather than asserting it, and the sibling-service fixture is sahajcloud - Mailpit — the shape Railway actually posts.

Lean gate green: 124 files, 1589 tests. Both new forbidden assertions were confirmed failing first, and the 401/403 exit was driven end to end through main() — exit 1 in 1s. CI is re-running.

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


Generated by Claude Code

@sydevs-bot
sydevs-bot merged commit d8a9c25 into main Sep 5, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in SYDevelopers Technical Roadmap Sep 5, 2026
sydevs-bot pushed a commit that referenced this pull request Sep 5, 2026
…rule

Adversarial review on #711 raised four threads. All four applied.

The written rule in `docs/rules/access.md` was the deliverable #701 chose
instead of a shared helper, and it said "on every request" while four
hand-rolled admin fetches legitimately do not send a locale. A reader who
greps `fetch('/api/` found four counter-examples with nothing to tell them
apart, so the rule read as approximate. It now names the condition — the
endpoint or collection runs a per-locale `hasPermission` — and tables every
call site on each side of it. `docs/rules/admin-ui.md` carried the same
overbroad claim and now defers to it.

Of the three call sites the fix touches, only the loader's URL was pinned.
The two carrying the user-visible half rested on inspection, with the manual
browser pass skipped, on a Critical bug live in production. Both now build
their URL in a pure module — `framesByNarratorKey` in the FrameEditor's
existing `utils.ts`, `eventSubmissionActionUrl` in a new `EventSubmissions/urls.ts`
— spec'd in `tests/unit/admin-locale-urls.spec.ts`. This is the reviewer's
option 2; option 1 needs a browser this run has no dev server for.

Both builders return `null` without a locale, which also settles the third
thread: the same falsy `code` was handled three different ways, and the
EventSubmissions site interpolated it unguarded. `?locale=undefined` is
rewritten to the default locale by `sanitizeLocales`, so that path
reproduced the #701 403 silently. It now reports the failure instead.

Comment cleanups: the spec docblock's dangling `The` and its argument with
the sentence it replaced, and `relationshipDocLoader.ts`'s stale "a single
request per relationTo", which the batch-key comment below it contradicted.

Every new assertion confirmed failing first, at its own site: dropping the
locale from the frames key turns 4 red, dropping the guard from the
submission URL turns 1 red.

Gate: lint, typecheck, typecheck:tests, test:unit (125 files, 1601 tests).
Rebased onto main after #703 merged.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Po2VWfKLXuT5TtZRysSDmk
sydevs-bot added a commit that referenced this pull request Sep 6, 2026
…711)

* fix(admin): send the active locale on hand-rolled admin REST fetches

Three admin components call the REST API with a hand-rolled fetch that
sends no `?locale=`. Payload resolves such a request at the default
locale, and every role gate then evaluates the manager's English roles.
Since #668 made roles genuinely per-locale, a manager whose roles live
only in another locale is denied on all three surfaces.

Confirmed on the reported record: managers/504's `roles` is
`{"fr":["path-editor","meditations-editor"]}` — no `en` key at all, so
`roles['en'] || []` is empty and `hasPermission` returns false.

- FrameEditor/hooks.ts — the locale joins the SWR key, so switching the
  admin locale refetches for free.
- ThumbnailCell — the loader is a module singleton, not a hook, so the
  locale threads through `load()` and the batch key becomes
  `relationTo:locale`. Two locales must not share a batch: the response
  is gated per locale, so merging them would answer one locale's cells
  from the other's request.
- EventSubmissionActions — both URLs carry it. DELETE is not
  locale-gated today, but consistency costs nothing.

Fixed on the client, not the server: the gates are deliberate and
documented, and Payload's own fetches already send the locale.

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

* test(admin): cover the locale gate over the real REST pipeline

The suite was green through the bug because nothing drove Payload's REST
pipeline as a manager with roles only in a non-default locale. The
handler-level specs build `req` by hand and hardcode `locale: 'en'`, so
none of them could see how `req.locale` is derived — which is exactly
where #701 lived.

- restRequest: `createRestClientAs(env, manager)` logs in any manager,
  and the caller now takes a method and a JSON body. `createRestClient`
  keeps its signature and delegates.
- frames-by-narrator: three REST cases for a French-only
  meditations-editor — no `?locale` → 403, `?locale=fr` → 200,
  `?locale=en` → 403.
- event-submissions-review: the same three for an `atlas-manager` on
  `POST /:id/review`. A sibling file, not a suite in
  event-submissions.int.spec.ts, because `getPayload` caches per config
  and a second createTestEnvironment in one file returns the first.
- relationshipDocLoader: locale forwarding, per-locale batching, and the
  default fetcher's URL — the code a comment called "not worth a unit
  test", where the defect was.

Fixture pre-mortem: `testData.createManager` writes a per-locale roles
object one locale at a time (verified in tests/utils/testData.ts), so
`{ fr: [...] }` really does leave `roles.en` empty — checked against the
reported production record, managers/504, whose roles carry no `en` key.
`anchorRegion` must be a city or venue, so the review fixture anchors on
a city under the managed country (prepareSubmission.ts:101).

Every new assertion was confirmed failing first: flipping each fixture's
locale to `en` turns all six REST cases red, dropping `locale` from the
loader's query object turns the URL case red, and collapsing the batch
key to `relationTo` turns the batching case red.

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

* docs(access): a hand-rolled admin fetch must send the active locale

The rule #701 turned on, stated where each audience reads: the role-scope
section of the access rules, and the direct-Payload-access section of the
admin UI rules.

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

* fix(admin): pin the two unasserted locale call sites, and narrow the rule

Adversarial review on #711 raised four threads. All four applied.

The written rule in `docs/rules/access.md` was the deliverable #701 chose
instead of a shared helper, and it said "on every request" while four
hand-rolled admin fetches legitimately do not send a locale. A reader who
greps `fetch('/api/` found four counter-examples with nothing to tell them
apart, so the rule read as approximate. It now names the condition — the
endpoint or collection runs a per-locale `hasPermission` — and tables every
call site on each side of it. `docs/rules/admin-ui.md` carried the same
overbroad claim and now defers to it.

Of the three call sites the fix touches, only the loader's URL was pinned.
The two carrying the user-visible half rested on inspection, with the manual
browser pass skipped, on a Critical bug live in production. Both now build
their URL in a pure module — `framesByNarratorKey` in the FrameEditor's
existing `utils.ts`, `eventSubmissionActionUrl` in a new `EventSubmissions/urls.ts`
— spec'd in `tests/unit/admin-locale-urls.spec.ts`. This is the reviewer's
option 2; option 1 needs a browser this run has no dev server for.

Both builders return `null` without a locale, which also settles the third
thread: the same falsy `code` was handled three different ways, and the
EventSubmissions site interpolated it unguarded. `?locale=undefined` is
rewritten to the default locale by `sanitizeLocales`, so that path
reproduced the #701 403 silently. It now reports the failure instead.

Comment cleanups: the spec docblock's dangling `The` and its argument with
the sentence it replaced, and `relationshipDocLoader.ts`'s stale "a single
request per relationTo", which the batch-key comment below it contradicted.

Every new assertion confirmed failing first, at its own site: dropping the
locale from the frames key turns 4 red, dropping the guard from the
submission URL turns 1 red.

Gate: lint, typecheck, typecheck:tests, test:unit (125 files, 1601 tests).
Rebased onto main after #703 merged.

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

---------

Co-authored-by: Claude <[email protected]>
Ardnived pushed a commit that referenced this pull request Nov 5, 2026
Review of #703 found the `reads === 0` exit too blunt. It fired on any
cause, including a transient statuses-API incident that outlasted the
12-minute deadline — turning every open PR red, clearable only by a full
re-run — and it spent the whole budget before saying so. #661 resolved
that the fail-open is correct for a PR with genuinely no preview, and
scoped exactly one new hard failure.

`fetchStatuses` collapsed every non-ok response into one opaque Error, so
the loop could not tell a permanent 401/403 from a retryable 502. It now
throws StatusFetchError carrying `res.status`, and discovery returns a
`forbidden` outcome on the first 401/403 — terminal, like `unpublished`,
because GitHub will not relent inside one run. That keeps the property
worth keeping (never having looked is not evidence of absence) and drops
both the transient trigger and the 12-minute cost.

A budget spent entirely on transient errors now warns and skips instead
of failing. The remaining causes are the ones that clear on their own.

Also from review: the OTHER fixture used `mailpit - Mailpit`, a context
Railway never posts. Railway's shape is `<project> - <service>`, so a
sibling service is `sahajcloud - Mailpit`. The old fixture asserted
against an impossible string; the new one covers the case that can occur,
and records that the discrimination rests on `includes` being
case-sensitive.

And the `unpublished`-is-terminal docstring now records its evidence:
settled-state only (#699, #700), bounded by discovery starting about six
minutes into the job, so the status it reads is already minutes old.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012noYdvt78W3aLKqJpDpEQY
Ardnived pushed a commit that referenced this pull request Nov 5, 2026
…rule

Adversarial review on #711 raised four threads. All four applied.

The written rule in `docs/rules/access.md` was the deliverable #701 chose
instead of a shared helper, and it said "on every request" while four
hand-rolled admin fetches legitimately do not send a locale. A reader who
greps `fetch('/api/` found four counter-examples with nothing to tell them
apart, so the rule read as approximate. It now names the condition — the
endpoint or collection runs a per-locale `hasPermission` — and tables every
call site on each side of it. `docs/rules/admin-ui.md` carried the same
overbroad claim and now defers to it.

Of the three call sites the fix touches, only the loader's URL was pinned.
The two carrying the user-visible half rested on inspection, with the manual
browser pass skipped, on a Critical bug live in production. Both now build
their URL in a pure module — `framesByNarratorKey` in the FrameEditor's
existing `utils.ts`, `eventSubmissionActionUrl` in a new `EventSubmissions/urls.ts`
— spec'd in `tests/unit/admin-locale-urls.spec.ts`. This is the reviewer's
option 2; option 1 needs a browser this run has no dev server for.

Both builders return `null` without a locale, which also settles the third
thread: the same falsy `code` was handled three different ways, and the
EventSubmissions site interpolated it unguarded. `?locale=undefined` is
rewritten to the default locale by `sanitizeLocales`, so that path
reproduced the #701 403 silently. It now reports the failure instead.

Comment cleanups: the spec docblock's dangling `The` and its argument with
the sentence it replaced, and `relationshipDocLoader.ts`'s stale "a single
request per relationTo", which the batch-key comment below it contradicted.

Every new assertion confirmed failing first, at its own site: dropping the
locale from the frames key turns 4 red, dropping the guard from the
submission URL turns 1 red.

Gate: lint, typecheck, typecheck:tests, test:unit (125 files, 1601 tests).
Rebased onto main after #703 merged.

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

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-703 — 20e64c98 Deployed Sep 5, 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.

fix(ci): restore Railway preview URLs, fail closed when none is found

3 participants