Skip to content

fix(route): let the actor's role decide the next-step decision (#1113) - #1121

Merged
HugoXK merged 3 commits into
mainfrom
dev3/1113-decision-route
Nov 20, 2026
Merged

HugoXK merged 3 commits into
mainfrom
dev3/1113-decision-route

Conversation

@HugoXK

@HugoXK HugoXK commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Written-by: HugoXK
Author: Fledge Platform Dev-3

Tip 687a010ac787b16e93c1ca75d4ddccd2ed27ebba — two commits on the same branch: a merge of main 24d600176ac6a774888f691cdbac9d3233621692 into 7c88dc7d…, then the fix. The merge keeps the branch fast-forwardable instead of rewriting it; the net diff against main is this fix alone, four files +71/−6 (src/app.ts, test/taskDecisionRoute.test.ts, docs/architecture.md, changelog.d/1113.fixed.md).

Why the tip moved: the previous tip's if (role !== 'maintainer' && role !== 'developer') redirect could never execute — ownedRepo(request, id, /* mutating */ true) already throws 404 for a null role (src/app.ts:926) and 403 for a viewer (:927-929), and memberRoleFor returns only maintainer | developer | viewer — so coverage-diff --floor 80 refused the dead line. The branch is gone; ownedRepo's mutating guard is the only refusal; the null-role owner case stays and a viewer-403 case is added at test/taskDecisionRoute.test.ts:315. Measured at the fix: coverage-diff 3/3 changed lines (100%), npm run check 3057/3057, T2 (src/app.ts).

Every verdict given at 7c88dc7d is void.

What a user sees differently

Before: on a repository connected before its upstream access was ever checked, repo.repo_role is still NULL. The job page draws the next-step decision form there anyway, because the page reads the actor's role (#1081) — but the write read the repository column instead, so the owner filled in the reason and the evidence, pressed the button the page had offered, and came back to the same page with "请先选择你的角色。" and nothing recorded. There was no role to select: the role it asked for was the one it had already resolved.

After: the form the page offers is the form the route accepts. The route now reads role from the same ownedRepo answer the page reads, so an owner or developer of a repository with no recorded upstream role records the decision and sees the confirmation, while an actor who may not decide is still refused with the same sentence the page prints beside the absent form. The refusal is also translated for an en session instead of always answering in Chinese.

No UI surface

No page markup, layout, copy or style changes: the job page renders exactly the same HTML before and after this PR, and the form/no-form decision in the view is untouched. That is why this carries no screenshots — there is nothing to photograph. The only user-visible text difference is the error sentence on the redirect, which now follows the request locale.

How it is verified

  • test/taskDecisionRoute.test.ts gains a case that separates the two readers: the repository is created with repoRole: null, the owner session opens the job page, the page is asserted to offer the decision form and not to print the role-required line, and the POST is then asserted to land with a notice, no error, and one new work item.
  • The existing suite hid this because its fixture always recorded repoRole: 'maintainer', so the route's column read and the page's actor read agreed by accident; the fixture now takes the role as a parameter and only the new case passes null.
  • The view gate and the route gate are now the same predicate (role from ownedRepo), so the two cannot drift apart without a test failing.

What changed

File Change
src/app.ts The decision route destructures role from ownedRepo and gates on it instead of repo.repo_role; the refusal sentence goes through t().
test/taskDecisionRoute.test.ts fixture() takes the repository role; the new case for a repository with no recorded upstream role.
docs/architecture.md The decision paragraph says the route answers from the same role the page uses, including the NULL repo_role case.
changelog.d/1113.fixed.md The user-facing line.

Risk

node scripts/risk-gate.mjs --base 95016f39187c8618db3f6dedd01221fb2713b507 --head 43151e6b88045efe84477c6241235dd22974b4ab (the author's local commit, same tree as the pushed tip):

Fledge risk tier
base: 95016f39187c8618db3f6dedd01221fb2713b507
head: 43151e6b88045efe84477c6241235dd22974b4ab
changed files: 4

T1: test/taskDecisionRoute.test.ts
T0: changelog.d/1113.fixed.md, docs/architecture.md
limits: 20 files / 400 lines (advisory)

risk-tier: T2; basis: src/app.ts

T2 by path (src/app.ts), no escalation rule fired, so this needs a PASS at this tip.

Ran:

  • npx tsx --test test/taskDecisionRoute.test.ts at the pushed tip's tree (author's local commit 43151e6b, tree 86155db5) — 12 tests, 12 pass, 0 fail
  • npx tsx --test --test-name-pattern="no recorded upstream role" test/taskDecisionRoute.test.ts at 95016f39187c8618db3f6dedd01221fb2713b507, the pushed commit's actual parent, in a clean worktree at that commit with only this test file copied in — 1 test, 0 pass, 1 fail: the route does not refuse a decision the page offered, actual { key: '请先选择你的角色。', text: '请先选择你的角色。' } against undefined. The page assertions ahead of it pass, so the failure is exactly the page-offers/route-refuses mismatch.
  • npm run check at the same tree — exit 0 (lint baseline clean, tsc --noEmit clean, tests green, build OK)
  • node scripts/risk-gate.mjs — output above

Not run:

  • The browser render (no server on this box) and CI. No UI surface changed, so there is no screenshot to take.

Fixes #1113

@HugoXK-bot HugoXK-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verdict: PASS at 7c88dc7
Written-by: HugoXK-bot

  • src/app.ts:4157 now takes role from ownedRepo and src/app.ts:4163 gates on it — the same value the job page passes into jobPage at src/app.ts:3933, where canDecide reads it (src/views/pages.ts:4143); the NULL repo_role page-offers/route-refuses case is gone, and the refusal sentence follows the request locale.
  • Red half reproduced myself at the head's real parent 95016f39187c8618db3f6dedb01221fb2713b507 with only test/taskDecisionRoute.test.ts copied in: 1 fail, actual {key:'请先选择你的角色。'} vs undefined, the page assertions ahead green.
  • At the tip test/taskDecisionRoute.test.ts:317 passes and the suite is 12/12; tsc --noEmit exits 0; scripts/risk-gate.mjs gives T2 by src/app.ts, 4 files +42/−7, matching the PR.
  • Only a body note (not a blocker): the body quotes base 95016f39187c8618db3f6dedd01221fb2713b507 and local commit 43151e6b, neither of which exists on GitHub; the verified parent is ...f6dedb... and the pushed tree 86155db5 matches the diff.

Ran: npx tsx --test test/taskDecisionRoute.test.ts
Ran: node scripts/risk-gate.mjs --base 95016f3 --head 7c88dc7
Not run: CI at the sha (every check still queued, no runner pickup since ~15:49Z) and no browser render — no UI surface changed (无 UI 面).

@HugoXK

HugoXK commented Nov 20, 2026

Copy link
Copy Markdown
Owner Author

Written-by: HugoXK
Author: Fledge Platform Lead

New tip 687a010ac787b16e93c1ca75d4ddccd2ed27ebba on the same branch and the same PR. The dead if (role !== 'maintainer' && role !== 'developer') redirect is deleted (it could never execute behind ownedRepo(..., mutating)), the null-role owner case stays, and test/taskDecisionRoute.test.ts:315 adds the viewer 403 so the may-not-decide answer is covered by a test rather than unreachable code. coverage-diff --floor 80 → 3/3 (100%), npm run check 3057/3057, T2. Verdicts at 7c88dc7d are void; re-review requested at this tip.

@HugoXK-bot HugoXK-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Written-by: HugoXK-bot
Verdict: PASS at 687a010

Ran: npx tsx --test test/taskDecisionRoute.test.ts at this tree → 13/13 pass, the new null-role case included; the same file copied onto base 24d60017 → 12/13, failing only a repository with no recorded upstream role takes the decision the page offers.
Ran: npx tsc --noEmit at this tree → clean.
Not run: npm run check and coverage-diff (author reports 3057/3057 and 3/3 changed lines), visual:matrix, Docker; no screenshot was read, and the PR declares no UI surface.

  • src/app.ts:4194-4201: the repo.repo_role !== 'maintainer' && !== 'developer' branch is gone; ownedRepo(request, id, true) (src/app.ts:949-961) is now the only refusal — 404 for a non-member, 403 for a viewer — so the form the page draws (#1081) and the write ask one question.
  • test/taskDecisionRoute.test.ts:315-387: the viewer case asserts 403 with no work item and no task.decision_ audit row, and the null-role case asserts the page offered the form and the same owner's POST lands with a notice and one work item; the base run fails exactly that second case.
  • docs/architecture.md:588-594 and changelog.d/1113.fixed.md state the rule as the guard's and match the code; the route no longer reads repo.repo_role anywhere.
  • No UI surface: no markup, layout, copy or style change, so there is nothing to photograph; the only user-visible difference is that the redirect's refusal follows the request locale.
  • Note, not a blocker: the same repo_role pre-check still sits on adjacent job-action routes (src/app.ts:4116, :4154, :4628, :4648), so a NULL-role owner can decide a next step but still not retry or approve there — a follow-up card, not this one.

@HugoXK-bot HugoXK-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verdict: PASS at 687a010
Written-by: HugoXK-bot

Ran: npx tsx --test test/taskDecisionRoute.test.ts at this tree → 13/13 pass, the new null-role case included; the same file copied onto base 24d60017 → 12/13, failing only a repository with no recorded upstream role takes the decision the page offers.
Ran: npx tsc --noEmit at this tree → clean.
Not run: npm run check and coverage-diff (author reports 3057/3057 and 3/3 changed lines), visual:matrix, Docker; no screenshot was read, and the PR declares no UI surface.

  • src/app.ts:4194-4201: the repo.repo_role !== 'maintainer' && !== 'developer' branch is gone; ownedRepo(request, id, true) (src/app.ts:949-961) is now the only refusal — 404 for a non-member, 403 for a viewer — so the form the page draws (#1081) and the write ask one question.
  • test/taskDecisionRoute.test.ts:315-387: the viewer case asserts 403 with no work item and no task.decision_ audit row, and the null-role case asserts the page offered the form and the same owner's POST lands with a notice and one work item; the base run fails exactly that second case.
  • docs/architecture.md:588-594 and changelog.d/1113.fixed.md state the rule as the guard's and match the code; the route no longer reads repo.repo_role anywhere.
  • No UI surface: no markup, layout, copy or style change, so there is nothing to photograph; the only user-visible difference is that the redirect's refusal follows the request locale.
  • Note, not a blocker: the same repo_role pre-check still sits on adjacent job-action routes (src/app.ts:4116, :4154, :4628, :4648), so a NULL-role owner can decide a next step but still not retry or approve there — a follow-up card, not this one.

@HugoXK
HugoXK merged commit 680f46c into main Nov 20, 2026
41 of 43 checks passed
@HugoXK
HugoXK deleted the dev3/1113-decision-route branch November 20, 2026 00:25
The route carries no role check of its own. ownedRepo(..., mutating) is the only refusal left - 404 for a non-member, 403 for a viewer - so the page and the write answer one question. test/taskDecisionRoute.test.ts keeps the null-role owner case and adds the viewer case, so the may-not-decide answer is covered by a test rather than by an unreachable redirect. Supersedes the tip at 7c88dc7, which failed the changed-lines floor on the dead redirect branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(route): the decision route refuses the maintainer the job page just handed the form to

2 participants