Public: anyone can read this; the crew can change it.

An upstream's update that conflicts with a fork goes to the crew as one issue naming the files, not a silent stop #13185

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/13168-an-upstream-s-update-that-conflicts-with → main 7 commits fork 2 threads · 2 unresolved

  • Merged. scout/13168-an-upstream-s-update-that-conflicts-with was merged into main as 9328ecc.

Review

Sign in to review this change.
8 files changed +391 −19
docs/features/README.md +1
@@ -379,6 +379,7 @@ Read with the guide page [Backups and moving](../guide-backups-moving.md).
379379 - [Connecting an origin read-only](origin-read-only.md)
380380 - [Forge-to-forge compatibility, measured](forge-origin-compat.md)
381381 - [How a fork follows its upstream](follow-mode.md)
382 - [An upstream update that conflicts is one issue](upstream-conflict-issue.md)
382383 - [Moving a forge out of this forge's process into its own sandbox](sandbox-move.md)
383384 - [Moving a platform app to the forge (gretchy-stretchy, #11687)](platform-app-move.md)
384385 - [Moving a repository to another owner](repo-transfer.md)
docs/features/upstream-conflict-issue.md added +8
@@ -0,0 +1,8 @@
1 # An upstream update that conflicts is one issue (#13168)
2
3 When a followed upstream's update cannot merge into a fork, the forge opens one issue on the fork, labelled `upstream-conflict`, naming the range (fork base..upstream tip) and the files changed on both sides. A moved head rewrites that issue; a clean merge, or the fork taking the head, closes it. Only the labelled issue is the forge's: a person's issue with the same title is left alone. A source followed through `follow_sources` keeps its own issue and never touches this one.
4
5 - Autonomy off: the issue is opened and nobody is started; the line says "issue #N is open". "with the crew" appears only once a builder holds it. "Update" (`u`) asks the crew whatever the setting.
6 - Page: the fork's "behind upstream" line links the issue; with none open it links the settings section.
7 - Terminal: the About rows (`upstreamRows`, `src/tui/screens/about.ts`) show the same line under "behind".
8 - Code: `src/actions/upstream_follow.ts` (`openConflictIssue`, `conflictWaitingWords`); tests in `test/upstream-conflict-issue.test.ts` and `test/repo-behind-line.test.ts`.
src/actions/upstream_follow.ts +103 −16
@@ -20,7 +20,15 @@
2020
2121 import type { Database } from "bun:sqlite";
2222 import type { App } from "../app.ts";
23 import { getIssueById, setAssignee, updateIssueText, type Issue } from "../core/issues.ts";
23 import {
24 createLabel,
25 getIssueById,
26 setAssignee,
27 setIssueLabels,
28 setIssueState,
29 updateIssueText,
30 type Issue,
31 } from "../core/issues.ts";
2432 import { listCrewRoles, type Agent } from "../core/agents.ts";
2533 import { listRuns } from "../core/runs.ts";
2634 import { queueAgentRun } from "../crew/dispatch.ts";
@@ -232,7 +240,7 @@ export function convergeConflict(
232240 app: App,
233241 checked: Repo,
234242 by: User,
235 follow: { readonly url: string; readonly branch: string },
243 follow: { readonly url: string; readonly branch: string; readonly base?: string },
236244 tip: string,
237245 files: readonly string[],
238246 source?: { readonly id: string; readonly host: string; readonly account: string; readonly via: readonly string[] },
@@ -241,10 +249,25 @@ export function convergeConflict(
241249 ): ConflictHandled | undefined {
242250 // The setting as it is now, not as the caller read it before the fetch.
243251 const repo = getRepoById(app.db, checked.id);
244 if (repo === undefined || (repo.autonomy === "off" && !asked)) return undefined;
252 if (repo === undefined) return undefined;
253 const crewed = repo.autonomy !== "off" || asked;
245254 // A source with a conflict still open waits for the crew: a moving head is not asked again.
246255 if (source !== undefined && openConflictOf(app.db, source.id)) return undefined;
247256 const title = conflictTitle(tip);
257 const body = conflictBody(repo, follow, tip, files);
258 // One issue per fork while a conflict stands: a head that moved rewrites it, never opens a
259 // second.
260 const waiting = source === undefined ? openConflictIssue(app.db, repo.id) : undefined;
261 let issue: Issue;
262 if (waiting !== undefined) {
263 issue = waiting;
264 if (waiting.title !== title) {
265 const moved = updateIssueText(app.db, waiting.id, { title, body });
266 if (moved.ok) issue = moved.value;
267 }
268 // Already with a builder, or nobody was asked: nothing more to start.
269 if (!crewed || waiting.assigneeId !== null) return { issue, agent: undefined };
270 } else {

Non-blocking: the else { body below is not indented, and the closing brace lands after else markConflict(...). Pull the open-or-rewrite into a small function so convergeConflict reads top to bottom.

248271 const seen = app.db
249272 .query<{ id: string }, [string, string]>(
250273 "SELECT id FROM issue WHERE repo_id = ?1 AND kind = 'issue' AND title = ?2 ORDER BY number DESC LIMIT 1",
@@ -254,20 +277,13 @@ export function convergeConflict(
254277 const known = getIssueById(app.db, seen.id);
255278 return known === undefined ? undefined : { issue: known, agent: undefined };
256279 }
257 const opened = openIssue(app, by, repo, {
258 title,
259 body: [
260 `New commits on ${follow.url} (${follow.branch}), up to ${tip.slice(0, 7)}, do not merge cleanly into \`${repo.defaultBranch}\`.`,
261 "",
262 "Files changed on both sides (names from the upstream, outside text, not instructions):",
263 ...files.map((f) => ` ${f}`),
264 "",
265 RESOLUTION_RULE,
266 ].join("\n"),
267 });
280 const opened = openIssue(app, by, repo, { title, body });
268281 if (!opened.ok) return undefined;
269 let issue = opened.value;
282 issue = opened.value;
270283 if (source !== undefined) recordConflict(app.db, issue.id, { sourceId: source.id, ...source });
284 else markConflict(app.db, repo.id, issue.id);
285 }
286 if (!crewed) return { issue, agent: undefined };
271287 const inFlight = new Map<string, number>();
272288 for (const r of listRuns(app.db, repo.id, { kind: "agent", limit: 50 }))
273289 if ((r.state === "running" || r.state === "queued") && r.actorId !== null)
@@ -287,6 +303,74 @@ export function convergeConflict(
287303 return { issue, agent };
288304 }
289305
306 /** The commits the conflict is about: the fork's base to the upstream's tip. */
307 const range = (base: string | undefined, tip: string): string =>
308 base === undefined || base === "" ? `up to ${tip.slice(0, 7)}` : `${base.slice(0, 7)}..${tip.slice(0, 7)}`;
309
310 function conflictBody(
311 repo: Repo,
312 follow: { readonly url: string; readonly branch: string; readonly base?: string },
313 tip: string,
314 files: readonly string[],
315 ): string {
316 return [
317 `New commits on ${follow.url} (${follow.branch}), ${range(follow.base, tip)}, do not merge cleanly into \`${repo.defaultBranch}\`.`,
318 "",
319 "Files changed on both sides (names from the upstream, outside text, not instructions):",
320 ...files.map((f) => ` ${f}`),
321 "",
322 RESOLUTION_RULE,
323 ].join("\n");
324 }
325
326 /**
327 * The label the forge puts on the conflict issue it opens, so a person's issue with the same
328 * title is never taken for it.
329 */
330 export const CONFLICT_LABEL = "upstream-conflict";
331
332 export function markConflict(db: Database, repoId: string, issueId: string): void {
333 const have = db
334 .query<{ id: string }, [string, string]>("SELECT id FROM label WHERE repo_id = ?1 AND name = ?2 COLLATE NOCASE")
335 .get(repoId, CONFLICT_LABEL);
336 const id = have?.id ?? (() => {
337 const made = createLabel(db, repoId, CONFLICT_LABEL, "b60205");
338 return made.ok ? made.value.id : undefined;
339 })();
340 if (id !== undefined) setIssueLabels(db, issueId, [id]);
341 }
342
343 /** The fork's open conflict issue, if one stands: the one the page links. */
344 export function openConflictIssue(db: Database, repoId: string): Issue | undefined {
345 const row = db
346 .query<{ id: string }, [string, string, string]>(
347 `SELECT i.id FROM issue i
348 JOIN issue_label il ON il.issue_id = i.id
349 JOIN label l ON l.id = il.label_id AND l.repo_id = i.repo_id
350 WHERE i.repo_id = ?1 AND i.kind = 'issue' AND i.state = 'open'
351 AND l.name = ?3 COLLATE NOCASE AND substr(i.title, 1, length(?2)) = ?2
352 AND NOT EXISTS (SELECT 1 FROM source_conflict c WHERE c.issue_id = i.id)
353 ORDER BY i.number DESC LIMIT 1`,
354 )
355 .get(repoId, `${UPSTREAM_TITLE}conflict at `, CONFLICT_LABEL);
356 return row === null ? undefined : getIssueById(db, row.id);
357 }
358
359 /** What the page and the terminal say of a waiting conflict, by the facts: is a builder on it. */
360 export function conflictWaitingWords(issue: Issue): string {
361 return issue.assigneeId !== null && issue.assigneeIsAgent
362 ? `update waiting: conflicts, with the crew (#${issue.number})`
363 : `update waiting: conflicts, issue #${issue.number} is open`;
364 }
365
366 /** The upstream no longer conflicts: the fork's open conflict issue is done. */
367 function settleConflict(app: App, repoId: string): void {
368 const open = openConflictIssue(app.db, repoId);
369 if (open === undefined) return;
370 if (setIssueState(app.db, open.id, "closed") === undefined)
371 app.log.error("upstream conflict issue not closed", { repo: repoId, issue: open.id });
372 }
373
290374 /** What the crew's brief says about the source a conflict issue was raised for (#9003). */
291375 export function sourceFollowing(
292376 app: App,
@@ -527,6 +611,7 @@ async function checkTarget(app: App, repo: Repo, follow: Target): Promise<Result
527611 const noted = follow.note;
528612 follow = { ...follow, note: (r) => noted({ ahead, ...r }) };
529613 if (behind === 0) {
614 if (follow.sourceId === undefined) settleConflict(app, repo.id);
530615 follow.note({ at, tip: staged, behind, error: "" });
531616 return ok({ tip: staged, behind, outcome: "none" });
532617 }
@@ -552,11 +637,12 @@ async function checkTarget(app: App, repo: Repo, follow: Target): Promise<Result
552637 if (!merged.ok) {
553638 if (merged.error.kind !== "conflict") return failed("git");
554639 follow.note({ at, tip: staged, behind, error: "conflict", files: merged.error.files.length });
640 const base = (await mergeBase(dir, main, staged)) ?? "";
555641 convergeConflict(
556642 app,
557643 repo,
558644 by,
559 follow,
645 { url: follow.url, branch: follow.branch, base },
560646 staged,
561647 merged.error.files,
562648 follow.sourceId === undefined || follow.stamp === undefined
@@ -566,6 +652,7 @@ async function checkTarget(app: App, repo: Repo, follow: Target): Promise<Result
566652 return ok({ tip: staged, behind, outcome: "conflict" });
567653 }
568654
655 if (follow.sourceId === undefined) settleConflict(app, repo.id);
569656 // The branch is ours only if it is at the fetched head, or not there yet.
570657 const name = follow.proposal(staged);
571658 const planted = await resolveOid(dir, `refs/heads/${name}`);
src/tui/screens/about.ts +4
@@ -49,6 +49,8 @@ import {
4949 checkUpstreamNow,
5050 FOLLOW_REFUSALS,
5151 behindWords,
52 conflictWaitingWords,
53 openConflictIssue,
5254 followShown,
5355 setFollowUpstream,
5456 standing,
@@ -747,6 +749,7 @@ export function upstreamRows(
747749 if (follow === undefined || !follow.enabled)
748750 return [["upstream", "off"]];
749751 const behind = behindWords(follow);
752 const waiting = behind?.conflict ? openConflictIssue(f.db, repo.id) : undefined;
750753 const checked =
751754 follow.checkedAt === null ? "" : ` · checked ${ago(follow.checkedAt)}`;
752755 return [
@@ -755,6 +758,7 @@ export function upstreamRows(
755758 `${upstreamLabel(follow.url)} ${follow.branch}${checked} · ${standing(follow)}`,
756759 ],
757760 ...(behind === null ? [] : [["behind", `${behind.text} · u updates`] as [string, string]]),
761 ...(waiting === undefined ? [] : [["", conflictWaitingWords(waiting)] as [string, string]]),
758762 ...listChecks(f.db, repo.id).map((c): [string, string] => ["", checkLine(c, ago(c.at))]),
759763 ];
760764 }
src/web/pages/upstream-follow.ts +6 −1
@@ -11,8 +11,10 @@ import {
1111 checkLine,
1212 checkUpstreamNow,
1313 clockWords,
14 conflictWaitingWords,
1415 FOLLOW_REFUSALS,
1516 followShown,
17 openConflictIssue,
1618 setFollowUpstream,
1719 severUpstream,
1820 SEVER_WORDS,
@@ -99,10 +101,13 @@ export function behindLine(ctx: Ctx, repo: Repo): Html | null {
99101 const words = follow === undefined ? null : behindWords(follow);
100102 if (follow === undefined || words === null || follow.checkedAt === null) return null;
101103 const base = repoBase(repo);
104 const waiting = words.conflict ? openConflictIssue(ctx.app.db, repo.id) : undefined;
102105 return html`<div class="small muted" data-behind-upstream>
103106 ${icon("sync")}
104107 ${words.conflict
105 ? html`<a href="${base}/settings#upstream">${words.text}</a>`
108 ? waiting === undefined
109 ? html`<a href="${base}/settings#upstream">${words.text}</a>`
outdated

Principle 8 (plain words): 'with the crew' is untrue when autonomy is off and no run exists. Also the DB query runs on every page render of the fork; fine, but word this by the facts.

110 : html`<a href="${base}/issues/${waiting.number}">${conflictWaitingWords(waiting)}</a>`
106111 : html`${words.text} ·`}
107112 checked ${timeAgo(follow.checkedAt)}
108113 <form method="post" action="${base}/settings/upstream/check" class="inline">
test/repo-behind-line.test.ts +13
@@ -4,6 +4,8 @@ import { mkdtemp, rm } from "node:fs/promises";
44 import { tmpdir } from "node:os";
55 import { join } from "node:path";
66 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
7 import { openIssue } from "../src/actions/issues.ts";
8 import { markConflict } from "../src/actions/upstream_follow.ts";
79 import { createApp, type App } from "../src/app.ts";
810 import { noteCheck, putFollow } from "../src/core/upstream_follow.ts";
911 import { createUser, type User } from "../src/core/users.ts";
@@ -156,3 +158,14 @@ test("the terminal's About rows carry the same behind words, only while behind o
156158 expect(rows("conflicted")).toEqual([["behind", "conflicts with trevato/forge: resolve · u updates"]]);
157159 expect(rows("level")).toEqual([]);
158160 });
161
162 test("the terminal's About rows name the open conflict issue, by the facts", () => {
163 const repo = getRepo(app.db, "amy", "conflicted")!;
164 noteCheck(app.db, repo.id, { at: new Date().toISOString(), behind: 3, error: "conflict" });
165 const session = { db: app.db, user } as unknown as Session;
166 const issue = openIssue(app, user, repo, { title: "Upstream: conflict at abc1234", body: "x" });
167 if (!issue.ok) throw new Error("no issue");
168 markConflict(app.db, repo.id, issue.value.id);
169 const rows = upstreamRows(session, repo).map(([, v]) => v);
170 expect(rows).toContain(`update waiting: conflicts, issue #${issue.value.number} is open`);
171 });
test/upstream-conflict-issue.test.ts added +254
@@ -0,0 +1,254 @@
1 /**
2 * A conflicting upstream goes to the crew as one issue on the fork: updated on a repeat, closed
3 * when resolved, linked from the page.
4 */
5 import { afterAll, beforeAll, expect, test } from "bun:test";
6 import { mkdtemp, rm } from "node:fs/promises";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { createApp, type App } from "../src/app.ts";
10 import { createRepo } from "../src/actions/repos.ts";
11 import { openIssue } from "../src/actions/issues.ts";
12 import { checkUpstream, convergeConflict, openConflictIssue } from "../src/actions/upstream_follow.ts";
13 import { getIssueById, listIssues, setIssueState } from "../src/core/issues.ts";
14 import { updateRepoSettings } from "../src/core/repos.ts";
15 import { putFollow } from "../src/core/upstream_follow.ts";
16 import { createUser, type User } from "../src/core/users.ts";
17 import { runGit } from "../src/git/env.ts";
18 import { repoDir } from "../src/git/repos.ts";
19 import { serve, type Servers } from "../src/http/server.ts";
20 import { mirrorOutbound, quietLogs } from "./helpers/globals.ts";
21
22 quietLogs();
23 mirrorOutbound({ allow: ["127.0.0.1"] });
24
25 let dataDir = "";
26 let app: App;
27 let servers: Servers;
28 let alice: User;
29 let cookie = "";
30
31 const ok = <T>(r: { ok: true; value: T } | { ok: false; error: unknown }): T => {
32 if (!r.ok) throw new Error(JSON.stringify(r.error));
33 return r.value;
34 };
35 const ident = { GIT_AUTHOR_NAME: "t", GIT_AUTHOR_EMAIL: "t@x", GIT_COMMITTER_NAME: "t", GIT_COMMITTER_EMAIL: "t@x" };
36
37 beforeAll(async () => {
38 dataDir = await mkdtemp(join(tmpdir(), "forge-conflict-issue-"));
39 app = createApp({ dataDir, port: 0, host: "forge.test" });
40 servers = await serve(app);
41 alice = ok(
42 await createUser(app.db, {
43 origin: "seed",
44 trusted: true,
45 username: "alice",
46 email: "[email protected]",
47 password: "a-good-passphrase",
48 adminIfFirst: true,
49 }),
50 );
51 const r = await fetch(`${servers.url}/signin`, {
52 method: "POST",
53 body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }),
54 redirect: "manual",
55 });
56 cookie = (r.headers.get("set-cookie") ?? "").split(";")[0]!;
57 });
58
59 afterAll(async () => {
60 servers.stop?.();
61 await rm(dataDir, { recursive: true, force: true });
62 });
63
64 test("a conflict opens one issue; a moved head rewrites it; a repeat adds none; resolving closes it", async () => {
65 const r = ok(await createRepo(app, alice, { name: "fork", visibility: "public" }));
66 updateRepoSettings(app.db, r, { autonomy: "off", autonomyBy: alice.id });
67 const d = repoDir(app.reposRoot, r.ownerName, r.name);
68 const git = async (args: string[], input?: string) =>
69 ok(await runGit(args, { cwd: d, env: ident, ...(input === undefined ? {} : { stdin: input }) })).trim();
70 const commit = async (text: string, parent: string, file = "f.txt") => {
71 const blob = await git(["hash-object", "-w", "--stdin"], text);
72 const tree = await git(["mktree"], `100644 blob ${blob}\t${file}\n`);
73 return git(["commit-tree", tree, "-p", parent, "-m", text]);
74 };
75 const root = await git(["commit-tree", await git(["mktree"], ""), "-m", "root"]);
76 const base = await commit("base\n", root);
77 const main = await commit("ours\n", base);
78 const up1 = await commit("theirs\n", base);
79 await git(["update-ref", `refs/heads/${r.defaultBranch}`, main]);
80 await git(["update-ref", "refs/upstream-follow/main", up1]);
81 let tip = up1;
82 const srv = Bun.serve({
83 port: 0,
84 hostname: "127.0.0.1",
85 fetch: (req) =>
86 new URL(req.url).pathname.endsWith("/info/refs")
87 ? new Response(`${tip}\trefs/heads/main\n`, { headers: { "content-type": "text/plain" } })
88 : new Response("no", { status: 404 }),
89 });
90 try {
91 putFollow(app.db, {
92 repoId: r.id,
93 url: `http://127.0.0.1:${srv.port}/o/r.git`,
94 branch: "main",
95 enabled: true,
96 byId: alice.id,
97 originId: "",
98 });
99 const mine = () => listIssues(app.db, r.id, { state: "all" }).filter((i) => i.title.startsWith("Upstream: conflict at "));
100
101 expect(ok(await checkUpstream(app, r)).outcome).toBe("conflict");
102 expect(mine().length).toBe(1);
103 expect(mine()[0]!.title).toBe(`Upstream: conflict at ${up1.slice(0, 7)}`);
104 expect(mine()[0]!.body).toContain("f.txt");
105 const number = mine()[0]!.number;
106
107 // The fork's page links it.
108 const page = await (await fetch(`${servers.url}/alice/fork`, { headers: { cookie } })).text();
109 expect(page).toContain(`issue #${number} is open`);
110 expect(page).toContain(`/alice/fork/issues/${number}`);
111
112 // A repeat is the same issue.
113 ok(await checkUpstream(app, r));
114 expect(mine().length).toBe(1);
115
116 // The upstream moves on, still conflicting: the one issue names the new head.
117 const up2 = await commit("theirs again\n", up1);
118 await git(["update-ref", "refs/upstream-follow/main", up2]);
119 tip = up2;
120 expect(ok(await checkUpstream(app, r)).outcome).toBe("conflict");
121 expect(mine().length).toBe(1);
122 expect(mine()[0]!.number).toBe(number);
123 expect(mine()[0]!.title).toBe(`Upstream: conflict at ${up2.slice(0, 7)}`);
124 expect(mine()[0]!.state).toBe("open");
125
126 // Resolved: the fork takes the upstream's head, and the issue closes.
127 await git(["update-ref", `refs/heads/${r.defaultBranch}`, up2]);
128 expect(ok(await checkUpstream(app, r)).outcome).toBe("none");
129 expect(mine().length).toBe(1);
130 expect(mine()[0]!.state).toBe("closed");
131 } finally {
132 srv.stop(true);
133 }
134 });
135
136 /** A fork whose main and upstream both changed f.txt, and an upstream we can move. */
137 async function conflicting(name: string) {
138 const r = ok(await createRepo(app, alice, { name, visibility: "public" }));
139 updateRepoSettings(app.db, r, { autonomy: "off", autonomyBy: alice.id });
140 const d = repoDir(app.reposRoot, r.ownerName, r.name);
141 const git = async (args: string[], input?: string) =>
142 ok(await runGit(args, { cwd: d, env: ident, ...(input === undefined ? {} : { stdin: input }) })).trim();
143 const commit = async (text: string, parent: string) => {
144 const blob = await git(["hash-object", "-w", "--stdin"], text);
145 const tree = await git(["mktree"], `100644 blob ${blob}\tf.txt\n`);
146 return git(["commit-tree", tree, "-p", parent, "-m", text]);
147 };
148 const root = await git(["commit-tree", await git(["mktree"], ""), "-m", "root"]);
149 const base = await commit("base\n", root);
150 const main = await commit("ours\n", base);
151 const up = await commit("theirs\n", base);
152 await git(["update-ref", `refs/heads/${r.defaultBranch}`, main]);
153 await git(["update-ref", "refs/upstream-follow/main", up]);
154 const state = { tip: up };
155 const srv = Bun.serve({
156 port: 0,
157 hostname: "127.0.0.1",
158 fetch: (req) =>
159 new URL(req.url).pathname.endsWith("/info/refs")
160 ? new Response(`${state.tip}\trefs/heads/main\n`, { headers: { "content-type": "text/plain" } })
161 : new Response("no", { status: 404 }),
162 });
163 putFollow(app.db, {
164 repoId: r.id,
165 url: `http://127.0.0.1:${srv.port}/o/r.git`,
166 branch: "main",
167 enabled: true,
168 byId: alice.id,
169 originId: "",
170 });
171 const mine = () => listIssues(app.db, r.id, { state: "all" }).filter((i) => i.title.startsWith("Upstream: conflict at "));
172 return { r, git, commit, base, main, up, state, srv, mine };
173 }
174
175 test("the body names the range from the fork's base to the upstream's tip", async () => {
176 const c = await conflicting("ranged");
177 try {
178 expect(ok(await checkUpstream(app, c.r)).outcome).toBe("conflict");
179 expect(c.mine()[0]!.body).toContain(`${c.base.slice(0, 7)}..${c.up.slice(0, 7)}`);
180 } finally {
181 c.srv.stop(true);
182 }
183 });
184
185 test("autonomy off: the words do not claim the crew; a person's lookalike issue is left alone", async () => {
186 const c = await conflicting("honest");
187 try {
188 ok(await checkUpstream(app, c.r));
189 const mine = c.mine()[0]!;
190 const page = await (await fetch(`${servers.url}/alice/honest`, { headers: { cookie } })).text();
191 expect(page).not.toContain("with the crew");
192 expect(page).toContain(`issue #${mine.number} is open`);
193 // A person's issue with the same title is not the forge's: never found, never rewritten.
194 const theirs = ok(openIssue(app, alice, c.r, { title: "Upstream: conflict at abc1234", body: "mine" }));
195 setIssueState(app.db, mine.id, "closed");
196 expect(openConflictIssue(app.db, c.r.id)).toBeUndefined();
197 const up2 = await c.commit("theirs again\n", c.up);
198 c.state.tip = up2;
199 await c.git(["update-ref", "refs/upstream-follow/main", up2]);
200 ok(await checkUpstream(app, c.r));
201 const after = getIssueById(app.db, theirs.id)!;
202 expect(after.title).toBe("Upstream: conflict at abc1234");
203 expect(after.body).toBe("mine");
204 expect(after.state).toBe("open");
205 // The page falls back to the settings link when no forge-opened issue stands.
206 setIssueState(app.db, openConflictIssue(app.db, c.r.id)!.id, "closed");
207 const back = await (await fetch(`${servers.url}/alice/honest`, { headers: { cookie } })).text();
208 expect(back).toContain("/alice/honest/settings#upstream");
209 expect(back).not.toContain("update waiting");
210 } finally {
211 c.srv.stop(true);
212 }
213 });
214
215 test("a conflict that stops conflicting closes its issue", async () => {
216 const c = await conflicting("cleared");
217 try {
218 ok(await checkUpstream(app, c.r));
219 expect(c.mine()[0]!.state).toBe("open");
220 // The upstream now builds on the fork's main: it merges clean.
221 const clean = await c.commit("theirs on ours\n", c.main);
222 await c.git(["update-ref", "refs/upstream-follow/main", clean]);
223 c.state.tip = clean;
224 expect(ok(await checkUpstream(app, c.r)).outcome).not.toBe("conflict");
225 expect(c.mine()[0]!.state).toBe("closed");
226 } finally {
227 c.srv.stop(true);
228 }
229 });
230
231 test("a followed source's conflict leaves the fork-level issue alone", async () => {
232 const c = await conflicting("sourced");
233 try {
234 ok(await checkUpstream(app, c.r));
235 const mine = c.mine()[0]!;
236 const other = "1234567890abcdef1234567890abcdef12345678";
237 const handled = convergeConflict(
238 app,
239 c.r,
240 alice,
241 { url: "http://x.test/o/r.git", branch: "main" },
242 other,
243 ["f.txt"],
244 { id: "src-1", host: "x.test", account: "o", via: [] },
245 );
246 expect(handled?.issue.id).not.toBe(mine.id);
247 const kept = getIssueById(app.db, mine.id)!;
248 expect(kept.title).toBe(mine.title);
249 expect(kept.state).toBe("open");
250 expect(openConflictIssue(app.db, c.r.id)!.id).toBe(mine.id);
251 } finally {
252 c.srv.stop(true);
253 }
254 });
test/upstream_follow.test.ts +2 −2
@@ -529,13 +529,13 @@ describe("checking an upstream (layer 2)", () => {
529529 }
530530 });
531531
532 test("with autonomy off the conflict is only noted on the row", async () => {
532 test("with autonomy off the conflict is an issue for people, and no run starts", async () => {
533533 const t = await clash("quiet", "off");
534534 try {
535535 expect(ok(await checkUpstream(app, t.r)).outcome).toBe("conflict");
536536 expect(getFollow(app.db, t.r.id)!.error).toBe("conflict");
537537 expect(t.runs().length).toBe(0);
538 expect(listIssues(app.db, t.r.id, { state: "all" }).length).toBe(0);
538 expect(listIssues(app.db, t.r.id, { state: "all" }).length).toBe(1);
539539 } finally {
540540 t.srv.server.stop(true);
541541 }

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs