Public: anyone can read this; the crew can change it.
Talk: a Do it on a held edit to the conversation's preview branch makes the branch, not "no such branch" #17506
Merged 27h 8m ago, live in production
talk-branch → main 0 commits
2 files
changed +25
−3
src/actions/conversation_confirms.ts +4 −2
| @@ -140,8 +140,10 @@ export async function sayYes(ctx: Ctx, user: User, confirmId: string): Promise<Y | ||
| 140 | 140 | return { ok: false, error: "delete" }; |
| 141 | 141 | } |
| 142 | 142 | // The session's own authority, as a token would carry it: admin scope |
| 143 | // for an admin only, as only an admin mints an admin token. | |
| 144 | const asPerson: Ctx = { ...ctx, auth: { ...ctx.auth, user, scope: user.isAdmin ? "admin" : "rw" } }; | |
| 143 | // for an admin only, as only an admin mints an admin token. Through the conversation that asked, | |
| 144 | // as the agent's call was: a held write to its preview branch is still the lane's first write, | |
| 145 | // which makes the branch (`core/talk_lane.ts`), not "no such branch". | |
| 146 | const asPerson: Ctx = { ...ctx, auth: { ...ctx.auth, user, scope: user.isAdmin ? "admin" : "rw", through: held.via } }; | |
| 145 | 147 | const before = seen(ctx, held.args); |
| 146 | 148 | const ran = await actingVia({ userId: user.id, via: held.via }, () => |
| 147 | 149 | Promise.resolve(tool.run(asPerson, user, held.args)), |
test/talk-lane.test.ts +21 −1
| @@ -31,6 +31,7 @@ import { createUser, type User } from "../src/core/users.ts"; | ||
| 31 | 31 | import { mintViaToken } from "../src/core/via_token.ts"; |
| 32 | 32 | import { onEvent as checksHear } from "../src/checks/event_handler.ts"; |
| 33 | 33 | import type { LaneState } from "../src/checks/lane_state.ts"; |
| 34 | import { runGit } from "../src/git/env.ts"; | |
| 34 | 35 | import { refTip } from "../src/git/read.ts"; |
| 35 | 36 | import { repoDir } from "../src/git/repos.ts"; |
| 36 | 37 | import { serve, type Servers } from "../src/http/server.ts"; |
| @@ -256,7 +257,26 @@ describe("the fence still holds", () => { | ||
| 256 | 257 | await call(talk.token, "issue", { repo: name, number: issue.value.number }); |
| 257 | 258 | await call(talk.token, "read_file", { repo: name, path: "index.html" }); |
| 258 | 259 | expect(readFrom(app.db, talk.via)).toBeUndefined(); |
| 259 | expect((await write(talk.token, name, talk.branch)).held).toBe(true); | |
| 260 | const held = await write(talk.token, name, talk.branch); | |
| 261 | expect(held.held).toBe(true); | |
| 262 | // The person's Do it makes the write as the lane's first: the branch from the default | |
| 263 | // branch, the build and the draft pull, with no second ask for the branch. | |
| 264 | const confirm = /needs_confirm\\?":\\?"([0-9a-z]+)/.exec(held.text)?.[1]; | |
| 265 | if (confirm === undefined) throw new Error(held.text); | |
| 266 | const yes = await fetch(`${servers.url}/talk/confirm/${confirm}`, { | |
| 267 | method: "POST", | |
| 268 | headers: { origin: servers.url, cookie: `forge_session=${createSession(app.db, alice.id).token}`, accept: "application/json" }, | |
| 269 | body: new URLSearchParams({ answer: "yes" }), | |
| 270 | }); | |
| 271 | expect(yes.status).toBe(200); | |
| 272 | const dir = repoDir(app.reposRoot, repo.ownerName, repo.name); | |
| 273 | const tip = await refTip(dir, `refs/heads/${talk.branch}`); | |
| 274 | expect(tip).toBeDefined(); | |
| 275 | const parent = await runGit(["rev-parse", `${tip}^`], { cwd: dir }); | |
| 276 | expect(parent.ok ? parent.value.trim() : undefined).toBe(await refTip(dir, `refs/heads/${repo.defaultBranch}`)); | |
| 277 | const build = chatBuildOf(app.db, talk.id)!; | |
| 278 | expect(build.branch).toBe(talk.branch); | |
| 279 | expect(isDraft(getPull(app.db, repo.id, build.pullNumber!)!)).toBe(true); | |
| 260 | 280 | }); |
| 261 | 281 | |
| 262 | 282 | test("a read of a branch other than the default or its own widens the fence", async () => { |
new above
offline