Skip to content

Commit d1f99fc

Browse files
mchwangclaude
andcommitted
Pin that publish is refused while a merge job runs, and document why
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b721ca6 commit d1f99fc

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

‎docs/implementation/merge-handoff.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ A rebase moves the pull request's base. The guarded merge would then scan only t
6868

6969
## Storage
7070

71-
Schema v19 adds `task_pull_requests.check_id` (the pre-PR check each opening followed) and `merge_jobs`: one row per job or refused click, with three columns: `id` (the click's action ID, primary key), `plan_key` (the task, indexed by `merge_jobs_plan`) and `data`. `data` is a JSON record holding the rest: the click's review token, the guarded merge's action ID once the job reaches that step, `state`, `step`, `reason`, required-check names and states, the merge result URL, start and update times, and `refused` for a refused click. Lookups by state (the running job, the latest job that was not refused) read these JSON fields. A refused click's row is replayed to that click and never shown as the task's job. Writing it never changes the task's state version, so the readiness preparation recorded stays valid while the job waits. A resend of the same click returns its row; another click while a job runs is refused.
71+
Schema v19 adds `task_pull_requests.check_id` (the pre-PR check each opening followed) and `merge_jobs`: one row per job or refused click, with three columns: `id` (the click's action ID, primary key), `plan_key` (the task, indexed by `merge_jobs_plan`) and `data`. `data` is a JSON record holding the rest: the click's review token, the guarded merge's action ID once the job reaches that step, `state`, `step`, `reason`, required-check names and states, the merge result URL, start and update times, and `refused` for a refused click. Lookups by state (the running job, the latest job that was not refused) read these JSON fields. A refused click's row is replayed to that click and never shown as the task's job. Writing it never changes the task's state version, so the readiness preparation recorded stays valid while the job waits. A resend of the same click returns its row; another click while a job runs is refused. While a job runs, `prepare-merge` is refused (the job prepares the merge itself). `publish` is refused too, by publishing's own status rule: it publishes only a running task whose plan items have all run, or a task that needs a person, and a job runs only for a task in review or approved but merge blocked. So no publish can push the pull request's head or begin a refresh of it while the job prepares, waits or merges.
7272

7373
## API and browser
7474

‎test/runner-publishing.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1817,7 +1817,7 @@ describe('the one-click merge job (F6b of #22)', () => {
18171817
};
18181818
const mergeState = async (app: App) => (await fetch(`${new URL(app.url).origin}/api/merge`, { headers: { 'x-codeboost-token': app.token } })).json() as Promise<Record<string, any>>;
18191819

1820-
it('offers Merge PR while only blockers the job resolves remain, then waits for checks and merges, refusing prepare-merge meanwhile', async () => {
1820+
it('offers Merge PR while only blockers the job resolves remain, then waits for checks and merges, refusing prepare-merge and publish meanwhile', async () => {
18211821
const w = world(); mergeable(w);
18221822
let checks: RequiredCheck[] = [{ context: 'ci', appId: null, state: 'pending' }], storeRef: Store | null = null;
18231823
const gh = gateway(() => storeRef!, () => checks);
@@ -1835,6 +1835,9 @@ describe('the one-click merge job (F6b of #22)', () => {
18351835
expect(started.body.merge).toMatchObject({ ready: false, job: { state: 'running' } });
18361836
await vi.waitFor(async () => expect((await mergeState(served.app)).job).toMatchObject({ step: 'checks', checks: [{ context: 'ci', state: 'pending' }] }), { timeout: 10_000 });
18371837
expect(await act(served.app, 'prepare-merge')).toMatchObject({ status: 409, body: { error: expect.stringMatching(/merge is running/) } });
1838+
// A publish cannot begin a refresh of the PR the job waits on: publishing refuses a task in review.
1839+
expect(await act(served.app, 'publish')).toMatchObject({ status: 409, body: { error: expect.stringMatching(/The task is in review/) } });
1840+
expect(served.store.taskPullRequests(served.identity).every(pr => pr.refresh === null)).toBe(true);
18381841
checks = [{ context: 'ci', appId: null, state: 'success' }];
18391842
await vi.waitFor(async () => expect((await mergeState(served.app)).job).toMatchObject({ state: 'merged' }), { timeout: 10_000 });
18401843
expect(gh.merged).toEqual([served.store.getSnapshot(served.identity).head]);

0 commit comments

Comments
 (0)