credentials: a credential store per agent, its own git identity, pushes to a remote (row 199, #1697)
Squash of Megavolt's 627979a17..86963d281 on origin/megavolt/row199-on-190 (base00d4cc1f6, row 190's landing), the 37 manifest paths, build.patch 05383075, manifest 35f900fd (Duckworth approve round 1, comment 29779, rev 2540). Mutant batches 1 and 2 in agents/megavolt/work/queue-199/BUILD.md: batch 2 26 of 28 killed, M17 and M27 equivalent. docs/TOOLS.md is a 3-way merge with row 200 (9e1085816): row 199's hunk applies unchanged (patch-id d88379111e2e) and no test reads the file. Gate on9e1085816plus the patch: 15 package suites 2735 pass 0 fail, 10 scripts/test-*.sh suites 429 pass 0 fail (plus 156 node tests in the queue suite). Refactor moved to76134dfdesince, a brief touching no manifest path. No live change: the stack runs from copy4429a104funtil the 10-24 re-pin window.
This commit is contained in:
1 parent
76134dfde1
commit
cb5fdb064f
37 files changed
+3016
-78
No files matched your search
@@ -26,6 +26,19 @@
|
||||
// squash that will land. The gate runs after the answer, and its
|
||||
// outcome is the broker's: recordLand or landRefused, each on the
|
||||
// task's trail and told to the role as a RESULT message.
|
||||
// publish {"cap", "op": "publish", "task_ref", "project", "branch", "decision"}
|
||||
// (row 199, #1697, design D9 to D11). The host answers {"ok": true,
|
||||
// "result": {fork, ref, commit, previous}} or a refusal. The broker's
|
||||
// checkPublish names the fork, the agent's email, the source commit
|
||||
// and the destination; the request names none of them. publish
|
||||
// (working.mjs) checks the work ref and the commits' identity under
|
||||
// the repository's lock, then the bus process runs ls-remote and the
|
||||
// push with the agent's gitea token (publishPush), and the host polls
|
||||
// publishResult every publishPollMs: the host's op channel answers
|
||||
// one op at a time within 10 s. The poll ends at publishDeadlineMs
|
||||
// (publish-timeout), past git's own limit on each of the four git
|
||||
// runs. recordPublish files the push; any refusal after checkPublish
|
||||
// is filed once, by publishRefused.
|
||||
//
|
||||
// A refusal is {"ok": false, "error": "<code>"}, and the connection ends.
|
||||
// The host checks, in order: identity (a role of this business), the request
|
||||
@@ -64,9 +77,10 @@ import { randomBytes } from "node:crypto";
|
||||
import { closeSync, createReadStream, existsSync, lstatSync, mkdirSync, openSync, rmSync, statSync, symlinkSync, writeSync, chmodSync } from "node:fs";
|
||||
import { createServer } from "node:net";
|
||||
import { join } from "node:path";
|
||||
import { GIT_GRACE_MS, GIT_TIMEOUT_MS } from "../../seat/src/checkout.mjs";
|
||||
import { gitSocketPath } from "../../seat/src/session.mjs";
|
||||
import { gateEnv, isMosaicStack, rootHits, runGate } from "../../seat/src/landing.mjs";
|
||||
import { BUNDLE_MAX, dropLand, finishLand, FSCK, HAVE_MAX, prepareLand, push, review, validBranch, workRef, WorkingError } from "../../seat/src/working.mjs";
|
||||
import { BUNDLE_MAX, dropLand, finishLand, FSCK, HAVE_MAX, prepareLand, publish, push, review, validBranch, workRef, WorkingError } from "../../seat/src/working.mjs";
|
||||
import { CliError } from "./errors.mjs";
|
||||
|
||||
const HEADER_MAX = 4096;
|
||||
@@ -84,6 +98,11 @@ export const bodyDeadline = (size) => BODY_IDLE_MS + Math.ceil(size / BODY_MIN_R
|
||||
const MAX_ACTIVE = 8;
|
||||
// The longest close() waits for its host-closing answers to leave.
|
||||
export const CLOSE_WAIT_MS = 2000;
|
||||
// How often the host asks the bus process whether a publish's push ended.
|
||||
const PUBLISH_POLL_MS = 200;
|
||||
// The longest the host polls: publishRemote runs at most four git commands
|
||||
// (ls-remote, cat-file, merge-base, push), each ended by git's own limit.
|
||||
const PUBLISH_DEADLINE_MS = 4 * (GIT_TIMEOUT_MS + GIT_GRACE_MS) + 30_000;
|
||||
const CAP = /^[0-9a-f]{64}$/;
|
||||
const OID = /^[0-9a-f]{40}([0-9a-f]{24})?$/;
|
||||
|
||||
@@ -272,7 +291,7 @@ Applied-under: git socket land (bus host)
|
||||
// host: startHost()'s handle; business: loadBusiness() output. bundleMax,
|
||||
// bodyDeadline, bodyIdle, maxActive, fsck and gate (LAND_GATE's shape) are
|
||||
// for the tests.
|
||||
export function createGitSocket({ host, business: b, dataRoot, env = process.env, log = () => {}, bundleMax = BUNDLE_MAX, bodyDeadline: deadlineOf = bodyDeadline, bodyIdle = BODY_IDLE_MS, maxActive = MAX_ACTIVE, fsck = FSCK, gate = LAND_GATE }) {
|
||||
export function createGitSocket({ host, business: b, dataRoot, env = process.env, log = () => {}, bundleMax = BUNDLE_MAX, bodyDeadline: deadlineOf = bodyDeadline, bodyIdle = BODY_IDLE_MS, maxActive = MAX_ACTIVE, fsck = FSCK, gate = LAND_GATE, publishPollMs = PUBLISH_POLL_MS, publishDeadlineMs = PUBLISH_DEADLINE_MS }) {
|
||||
const path = gitSocketPath(dataRoot);
|
||||
const dir = join(dataRoot, "bus-host");
|
||||
let server = null;
|
||||
@@ -386,6 +405,55 @@ export function createGitSocket({ host, business: b, dataRoot, env = process.env
|
||||
})();
|
||||
}
|
||||
|
||||
async function doPublish(socket, cap, req) {
|
||||
const { task_ref, branch, decision } = req;
|
||||
const p = project(req.project);
|
||||
if (!p || !validBranch(branch) || (decision !== undefined && typeof decision !== "string")) throw new Refusal("invalid-request");
|
||||
workRef(task_ref);
|
||||
const facts = await op({ op: "checkPublish", cap, args: { task_ref, project: req.project, branch, ...(decision === undefined ? {} : { decision }) } });
|
||||
const { ticket } = facts;
|
||||
// From the ticket on, a refusal is the publish's own, filed once by publishRefused.
|
||||
const refused = async (e) => {
|
||||
const code = e instanceof Refusal || e instanceof Recorded || e instanceof WorkingError ? e.code : "git-failed";
|
||||
if (code === "git-failed") log(`git socket: publish ${task_ref}: ${code}: ${e.message}`);
|
||||
await host.op({ op: "publishRefused", ticket, args: { code } }).catch((x) => log(`git socket: publish ${task_ref}: refusal ${code} not recorded: ${x.code ?? x.message}`));
|
||||
return new Recorded(code);
|
||||
};
|
||||
let pushed;
|
||||
try {
|
||||
pushed = await publish({
|
||||
dataRoot, business: b.id, project: req.project, root: p.root, taskRef: task_ref, source: facts.source, email: facts.email, env,
|
||||
remote: async () => {
|
||||
await op({ op: "publishPush", ticket });
|
||||
const until = Date.now() + publishDeadlineMs;
|
||||
for (;;) {
|
||||
// The bus's git may still finish after this; the fork could then hold the commit with
|
||||
// no record, as when recordPublish refuses after a push.
|
||||
if (Date.now() >= until) {
|
||||
log(`git socket: publish ${task_ref}: publish-timeout; the bus process's push may still reach the fork`);
|
||||
throw new Refusal("publish-timeout");
|
||||
}
|
||||
await new Promise((r) => setTimeout(r, publishPollMs));
|
||||
const r = await op({ op: "publishResult", ticket });
|
||||
if (r.state === "pushed") return { ref: r.ref, commit: r.commit, previous: r.previous };
|
||||
if (r.state === "refused") throw new Recorded(r.code);
|
||||
}
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
throw await refused(e);
|
||||
}
|
||||
// The commit is on the fork now; a record the broker refuses is filed as that refusal.
|
||||
let result;
|
||||
try {
|
||||
result = await op({ op: "recordPublish", ticket, pushed });
|
||||
} catch (e) {
|
||||
log(`git socket: publish ${task_ref}: ${pushed.commit} is on ${facts.fork} but wasn't recorded: ${e.code}`);
|
||||
throw await refused(e);
|
||||
}
|
||||
socket.end(`${JSON.stringify({ ok: true, result: { fork: result.fork, ref: result.ref, commit: result.commit, previous: result.previous } })}\n`);
|
||||
}
|
||||
|
||||
async function serve(socket) {
|
||||
let cap = null;
|
||||
let subject = null;
|
||||
@@ -410,7 +478,8 @@ export function createGitSocket({ host, business: b, dataRoot, env = process.env
|
||||
if (req.op === "push") await doPush(socket, cap, req, rest, file);
|
||||
else if (req.op === "fetch") await doFetch(socket, cap, req, file);
|
||||
else if (req.op === "land") await doLand(socket, cap, req);
|
||||
else throw new Refusal("invalid-request", "op is push, fetch or land");
|
||||
else if (req.op === "publish") await doPublish(socket, cap, req);
|
||||
else throw new Refusal("invalid-request", "op is push, fetch, land or publish");
|
||||
} catch (e) {
|
||||
if (e instanceof Recorded) return fail(e.code);
|
||||
const code = e instanceof Refusal || e instanceof WorkingError ? e.code : "git-failed";
|
||||
|
||||
Reference in new issue
Block a user