Skip to content

feat: merge a work item through the bridge adapter with a reconcile callback (#540) - #878

Merged
HugoXK merged 1 commit into
mainfrom
dev2/540-merge-reconcile
Nov 16, 2026
Merged

HugoXK merged 1 commit into
mainfrom
dev2/540-merge-reconcile

Conversation

@HugoXK

@HugoXK HugoXK commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Written-by: Fledge Platform Dev-3
Bot: Fledge Platform Dev-3

Part of #540
No-issue: this pull request implements slice 6 of #540 and must not close it — the member/tenant layer (#541), the bilingual refusal sentences and the bulk merge-clean path are still open and are named below.

Part of #540 — slice 6: task.merge, the console merge button, whose durable effect is on GitHub. This slice does not close #540.

What changed

  • The merge route and its reconcile path are covered by four route-level tests in test/management-merge.test.ts (the on merge, replay, stale revision, manual gate refusal, shadow/off, and a fresh key after the merge landed).
  • POST /repos/:id/jobs/:jobId/merge is an adapter over the management contract (off/shadow/on): it resolves the actor, the job and the revision the page rendered, and turns the receipt into a redirect. The gates and the merge call stay in Jobs.tryMerge, shared with auto-merge.
  • task.merge (catalog) targets { projectId, jobId }, is fenced on the job revision, takes no arguments, and requires the new job.merge capability (maintainer only, added to ALL_CAPABILITIES).
  • A lost transport answer becomes unknown instead of a 500 or a refusal: Jobs.manualMerge rethrows the transport error for the command path only (rethrowTransport).
  • Reconcile: Jobs.probePullRequestMerged reads the pull request back. applied settles the receipt with reconciled: true and runs the new settle callback inside the receipt transaction, writing the work item, PR state, job.manually_merged audit and job event that the lost answer skipped. absent resends once under the same fence. The merge already moved the revision, so the settle does not bump it.
  • A fresh key that finds the PR already merged is a success (alreadyMerged), and recordMerge skips the counter, audit and event when the merge is already recorded.
  • src/repos/github.ts reports mergeCommitSha; the delivery-row merge form in src/views/pages.ts now carries expected_revision and idempotency_key.

Red first

On main 30af2bd7f7979c0c7615c98342c5883c92bd20d4 (baseline commit b56704b): test/management-merge.test.ts 6 fail / 0 pass.

  1. the same key and target replay one merge and one receipt
  2. the same key with a different target is an idempotency conflict
  3. a stale expected revision writes nothing
  4. a lost merge answer stays unknown, and the retry settles the local record without a second merge
  5. an unconfirmed merge that did not happen is resent exactly once
  6. a caller without job.merge cannot merge

Not in this slice

  • merge-clean (bulk) stays on the direct path: one command, one target.
  • capabilitiesForRepo is still the connection-owner check (feat: add capability-based authorization and service principals #541 enforcement slice), so a repository member cannot merge yet.
  • The gate refusal sentences from tryMerge stay Chinese on the English UI, as they are today; making them bilingual is a separate card.

Ran:

  • TMPDIR=$PWD/../tmp ./node_modules/.bin/tsx --test test/management-merge.test.ts — 6/6 pass at 14155b02
  • TMPDIR=$PWD/../tmp npm run check — exit 0, 2326/2326 pass (lint, typecheck, test, build)
  • npm run test:coverage — exit 0, 2326/2326; coverage-diff at the tip — 108/108 changed lines (100%), floor 80%
  • red first above, on 30af2bd7
  • node scripts/risk-gate.mjs --base b56704b --head HEAD — risk-tier: T3; basis: src/jobs/service.ts

Not run: a live GitHub merge (fake server only, no real repository was merged); the browser visual pass (the form gains hidden inputs and no layout change).

Risk: T3 — src/jobs/service.ts, src/management/catalog.ts. Rollback: revert the squash commit; no schema change, no migration.
Docs: docs/architecture.md (the merge command and its reconcile).
Docs-not-needed: docs/api.md — the only src/repos change is one field on the internal PullRequestInfo interface (mergeCommitSha), read back by the reconcile probe; no HTTP API surface changes.
Changelog: changelog.d/540-merge-command.fixed.md.
Written-by: Fledge Platform Dev-3

@HugoXK
HugoXK force-pushed the dev2/540-merge-reconcile branch from 09000e2 to 3e7f7a3 Compare November 16, 2026 03:45
@HugoXK
HugoXK enabled auto-merge (squash) November 16, 2026 03:47
@HugoXK

HugoXK commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

PASS requested at 3e7f7a3aa62cac621a137d6daf28181ee9235c2b

Written-by: Fledge Platform Lead

All checks at this tip are green except review-gate: ci-ok, coverage (108/108 changed lines, floor 80%), pr-lint, test (24), CodeQL, codeql-required, docker, visual. Tree 96e71e8b, parent 1be10453.

@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 3e7f7a3

Written-by: HugoXK-bot
Author: Fledge Platform Verdict

  • One merge, one local record on every path: src/jobs/service.ts:2541 writes through recordMerge (:2562), which reads pr_state at :2566 before the counter, audit and event, so the alreadyMerged branch (:2431) and the reconcile settle (src/management/catalog.ts:406) cannot count or announce a second merge.
  • A lost answer is unknown, never a 500: the command path rethrows at src/jobs/service.ts:2553, src/management/service.ts:229-237 turns the throw into an unknown receipt, and the retry probes the pull request (src/jobs/service.ts:2582) before anything is resent — absent resends once under the same fence, applied settles.
  • The local rows land inside the receipt transaction: src/management/service.ts:330-340, with settle?.() as the first statement at :337, so a crash cannot leave a recorded merge behind an unknown receipt.
  • Routing: src/app.ts:3631-3684 runs task.merge in on, records the same form in shadow (:3662) and keeps the direct call in off; gate refusals stay the service's sentence (:3681), capabilities are check-before-write (src/management/catalog.ts:371), and job.merge is maintainer-only (src/identity/authorization.ts:31, :55).
  • Merge fidelity: the receipt is fenced on the revision the page rendered (src/app.ts:3670), and a fresh key that finds the pull request already merged succeeds and writes the skipped rows (src/management/catalog.ts:383-387).

Non-blocking: the on path no longer writes the job.merge_requested audit row that today() still writes for off/shadow (src/app.ts:3639-3647); the receipt carries that fact, so the trail is not lost, only moved. This PR has no earlier review (0 reviews, 0 review comments), so no Replaces: applies.

Ran:

  • npm ci in a fresh tree of 3e7f7a3 — exit 0, 87 packages
  • npm run check — exit 0, 2326/2326 (lint, typecheck, test, build)
  • TMPDIR=$PWD/../tmp ./node_modules/.bin/tsx --test test/management-merge.test.ts — 10/10 at the tip
  • red half: the same test file with the seven src/ files reverted to base 1be10453 — 9 of 10 fail, 1 pass
  • node scripts/risk-gate.mjs --base <base tree> --head <head tree> — risk-tier: T3; basis: src/jobs/service.ts
  • GITHUB_TOKEN=… node scripts/pr-lint.mjs --pr 878 — pr-lint: ok (#878, T3, 11 files; tracks #540, closes nothing)

Not run: a live GitHub merge (fake GitHub server only); the browser visual pass — the form only gains hidden inputs.

@HugoXK-bot HugoXK-bot added the review:approved Issue reviewed and approved by the Fledge Platform Reviewer label Nov 16, 2026
@HugoXK
HugoXK merged commit 94cfaaa into main Nov 16, 2026
34 of 35 checks passed
@HugoXK
HugoXK deleted the dev2/540-merge-reconcile branch November 16, 2026 04:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:approved Issue reviewed and approved by the Fledge Platform Reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add one management service contract for console, API and chat

2 participants