ticket-runner 0.6.2 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/readiness.ts CHANGED
@@ -4,6 +4,7 @@ import type { Labels } from "./config.js";
4
4
  import { CLAUDE_SECTION, CONVENTIONS_PATH, conventionsMark } from "./conventions.js";
5
5
  import { OPERATOR_SKILL_PATH } from "./operator-skill.js";
6
6
  import type { Authentication, Tracker } from "./ports/tracker.js";
7
+ import type { Workspace } from "./ports/workspace.js";
7
8
 
8
9
  /**
9
10
  * What `ticket-runner init` must have left in a Target before a Run may start.
@@ -22,17 +23,26 @@ import type { Authentication, Tracker } from "./ports/tracker.js";
22
23
  * Version it names: an Operator installs the pipeline a cloud Host runs at that
23
24
  * Version, and a Target without one leaves it guessing (ADR-0008).
24
25
  *
25
- * The Target's own files are read here rather than through a port, which every
26
+ * The checkout's files are read here rather than through a port, which every
26
27
  * external effect of a Run goes through. What a port buys is a fake to drive the
27
- * state machine with, and there is no state machine here: this is five questions
28
+ * state machine with, and there is no state machine here: these are questions
28
29
  * asked of a directory before a Run exists, and the answers are already driven
29
30
  * from a temporary repository root, which is how the local state under
30
- * `.ticket-runner/` is tested too (ADR-0004). Widening the `Workspace` port for
31
- * them would put reads no Stage and no Ticket ever makes on the interface the
32
- * orchestrator depends on.
31
+ * `.ticket-runner/` is tested too (ADR-0004).
32
+ *
33
+ * The same files on the remote's Base branch are the one exception, read
34
+ * through `Workspace` like every other question about the remote: every
35
+ * Ticket's worktree is made from that branch, so a file `init` wrote and nobody
36
+ * pushed is in the checkout and in no Stage's worktree. The conventions
37
+ * document, the `CLAUDE.md` pointer and the Operator's skill are asked of it
38
+ * the same way they are asked of the checkout. The gitignore lines are not:
39
+ * the directories they cover exist only in the main checkout, and only its
40
+ * copy takes effect there.
33
41
  *
34
42
  * Every item is asked on every Host, the cloud's own needs included, so a
35
- * Target a workstation accepts is never one a cloud Run then refuses.
43
+ * Target a workstation accepts is never one a cloud Run then refuses. A cloud
44
+ * Host's checkout is a clone of the remote, so there the remote's answers are
45
+ * the checkout's.
36
46
  */
37
47
 
38
48
  /** The file every agent session in a Target reads first. */
@@ -148,6 +158,10 @@ export interface ReadinessOptions {
148
158
  * is refused without a network call at all. Whether `gh` is there to ask comes
149
159
  * next, so a Host without it is refused in words rather than with the spawn
150
160
  * error the first label lookup would crash on.
161
+ *
162
+ * What the remote's Base branch lacks is asked after all of these, by
163
+ * {@link unpushedRefusal}, once the Run has resolved which branch that is: the
164
+ * lookup may ask GitHub, which only a `gh` that runs can.
151
165
  */
152
166
  export async function readinessRefusal({
153
167
  repoRoot,
@@ -155,7 +169,7 @@ export async function readinessRefusal({
155
169
  tracker,
156
170
  }: ReadinessOptions): Promise<string | undefined> {
157
171
  const missing =
158
- missingFileMessage(repoRoot) ??
172
+ (await missingFileMessage(repoRoot)) ??
159
173
  (await missingGhMessage(tracker)) ??
160
174
  (await missingLabelMessage(tracker, labels)) ??
161
175
  (await missingBranchDeletionMessage(tracker));
@@ -168,14 +182,56 @@ export async function readinessRefusal({
168
182
  ].join(" ");
169
183
  }
170
184
 
185
+ export interface UnpushedOptions {
186
+ workspace: Pick<Workspace, "remote" | "readRemoteFile">;
187
+ /** The Run's Base branch, resolved once and carried on into the Run. */
188
+ baseBranch: string;
189
+ }
190
+
191
+ /**
192
+ * The message a Run is refused with when the remote's Base branch lacks a file
193
+ * the checkout has, and nothing when it has them all.
194
+ *
195
+ * Asked once {@link readinessRefusal} has found nothing missing, so a Target
196
+ * that never ran `init` is told to run it and only one that did is told to
197
+ * push. A Base branch the remote does not have lacks every file. The remedy is
198
+ * a commit and a push, which `init` leaves to the human, so this names no
199
+ * command of the pipeline's.
200
+ */
201
+ export async function unpushedRefusal({
202
+ workspace,
203
+ baseBranch,
204
+ }: UnpushedOptions): Promise<string | undefined> {
205
+ const remoteBase = `${workspace.remote}/${baseBranch}`;
206
+ const missing = await missingItemMessage((path) => workspace.readRemoteFile(baseBranch, path));
207
+ if (missing === undefined) return undefined;
208
+
209
+ return [
210
+ `This Target's \`${remoteBase}\` is not set up: ${missing}.`,
211
+ `Every Ticket's worktree is made from \`${remoteBase}\`, not from this checkout:`,
212
+ "commit and push what `init` wrote there, then start again.",
213
+ ].join(" ");
214
+ }
215
+
171
216
  /** Names the first thing `init` writes into a Target that this one does not have. */
172
- function missingFileMessage(repoRoot: string): string | undefined {
217
+ async function missingFileMessage(repoRoot: string): Promise<string | undefined> {
173
218
  const [unignored] = missingIgnoreLines(repoRoot);
174
219
  if (unignored !== undefined) {
175
220
  return `\`.gitignore\` does not ignore \`${unignored.line}\``;
176
221
  }
177
222
 
178
- const conventions = readTargetFile(join(repoRoot, CONVENTIONS_PATH));
223
+ return missingItemMessage(async (path) => readTargetFile(join(repoRoot, path)));
224
+ }
225
+
226
+ /**
227
+ * Names the first of the items both the checkout and the remote's Base branch
228
+ * must carry that `read` does not find, asking each the same question in both
229
+ * places. Where it was asked is the refusal's to say.
230
+ */
231
+ async function missingItemMessage(
232
+ read: (path: string) => Promise<string | undefined>,
233
+ ): Promise<string | undefined> {
234
+ const conventions = await read(CONVENTIONS_PATH);
179
235
  if (conventions === undefined) {
180
236
  return `\`${CONVENTIONS_PATH}\` is not there`;
181
237
  }
@@ -183,13 +239,13 @@ function missingFileMessage(repoRoot: string): string | undefined {
183
239
  return `\`${CONVENTIONS_PATH}\` carries no Version`;
184
240
  }
185
241
 
186
- if (!hasClaudePointer(readTargetFile(join(repoRoot, CLAUDE_FILENAME)))) {
242
+ if (!hasClaudePointer(await read(CLAUDE_FILENAME))) {
187
243
  return `\`${CLAUDE_FILENAME}\` does not point at \`${CONVENTIONS_PATH}\``;
188
244
  }
189
245
 
190
246
  // Asked of a workstation too, though only a cloud session reads it: a Target
191
247
  // a local Run accepts is then one the app can run as well (ADR-0008).
192
- if (readTargetFile(join(repoRoot, OPERATOR_SKILL_PATH)) === undefined) {
248
+ if ((await read(OPERATOR_SKILL_PATH)) === undefined) {
193
249
  return `the Operator's skill \`${OPERATOR_SKILL_PATH}\` is not there`;
194
250
  }
195
251
 
package/src/run.ts CHANGED
@@ -5,7 +5,15 @@ import type { RoutedNote } from "./notes.js";
5
5
  import { type Pipeline, type TicketOutcome, processTicket } from "./orchestrator.js";
6
6
  import { StopSignal, stopLine } from "./stop.js";
7
7
  import { holdsClaim, strandedTickets } from "./stranded.js";
8
- import { RELEASE_WORDS } from "./templates.js";
8
+ import { releaseWords } from "./templates.js";
9
+ import { startTimer } from "./timer.js";
10
+
11
+ /**
12
+ * How long a free Lane waits, after the Run last listed the Frontier, before it
13
+ * looks at the Frontier again while another Lane is busy. Fixed: nothing in the
14
+ * Target's config or on the command line sets it, and nothing turns it off.
15
+ */
16
+ export const POLL_MS = 5 * 60_000;
9
17
 
10
18
  /**
11
19
  * What a Run has to show for itself: every Ticket it took, in the order they
@@ -46,6 +54,7 @@ export type RunStop =
46
54
  resetsAt?: string;
47
55
  }
48
56
  | { reason: "api-error" }
57
+ | { reason: "out-of-budget" }
49
58
  | {
50
59
  reason: "failing-base";
51
60
  baseBranch: string;
@@ -72,14 +81,23 @@ export type RunStop =
72
81
  * working is still an open blocker. Those edges are the whole of what keeps two
73
82
  * Tickets apart: no heuristic here decides which are safe together.
74
83
  *
84
+ * A Ticket can also join the Frontier with no Lane ending — a human labels it
85
+ * `ready-for-agent`, or closes its last blocker outside the Run — so while one
86
+ * Lane is free and another busy, the Run looks at the Frontier again
87
+ * {@link POLL_MS} after it last listed it, whatever listed it, and takes what
88
+ * a refill would. A Run with nothing busy has nothing to wait for and ends, as
89
+ * before: it never waits for new Tickets. A look that cannot list is logged
90
+ * and tried again next time, since nothing about the Run depended on it; a
91
+ * refill that cannot list still ends the Run's claiming.
92
+ *
75
93
  * A Ticket that fails is handed off and the Lane moves on: one bad Ticket must
76
94
  * not cost the rest of the night.
77
95
  *
78
96
  * A Release stops the Run filling Lanes and nothing more. Nothing was wrong with
79
- * the Ticket — the subscription ran out of room, or the API failed on its own
80
- * side after the CLI had given up retrying it — so the next one would be stopped
81
- * the same way, and claiming it would spend a Claim, a worktree and a doomed
82
- * Stage to learn what the first one already said. The Lanes still busy finish
97
+ * the Ticket — the subscription or the API key ran out of room, or the API
98
+ * failed on its own side after the CLI had given up retrying it — so the next
99
+ * one would be stopped the same way, and claiming it would spend a Claim, a
100
+ * worktree and a doomed Stage to learn what the first one already said. The Lanes still busy finish
83
101
  * what they hold, and the Run reports what stopped it once the last of them
84
102
  * comes back. It does not wait for the limit to reset: a human or an Operator
85
103
  * starts the next Run, and the summary says when the limit resets.
@@ -121,14 +139,14 @@ export async function processRun(
121
139
  // that several Lanes came back during sees every one of them free.
122
140
  const busy = new Map<number, Promise<void>>();
123
141
  // What the last Frontier this Run computed held back, which is what a Run
124
- // that drained the Frontier reports. Replaced at every refill: a candidate a
142
+ // that drained the Frontier reports. Replaced at every listing: a candidate a
125
143
  // Lane unblocked on the way is not one the Run was still held up by.
126
144
  let blocked: number[] = [];
127
145
  // Why this Run stopped, which is also what it reports. Set by whichever of
128
146
  // the Release and the Stop came first: a Stop that arrives after a Release
129
147
  // asked for what was already happening, and a Release afterwards stopped
130
- // nothing that was not stopped already. Only a later rate limit overwrites
131
- // it, and only where limitOutranks says so. Undefined is a Run still taking
148
+ // nothing that was not stopped already. Only a later API budget or rate
149
+ // limit overwrites it, and only where `outranks` says so. Undefined is a Run still taking
132
150
  // Tickets, which is why it doubles as the guard at every refill.
133
151
  let runStop: RunStop | undefined;
134
152
  // A Frontier the tracker refused to list, kept until the Lanes still busy are
@@ -136,6 +154,12 @@ export async function processRun(
136
154
  // went down, so the error waits for them and is thrown where a Run with one
137
155
  // Lane threw it: out of the Run, with nothing else left running.
138
156
  let listing: unknown;
157
+ // How many Lanes have ended, and how many had when the last pass listed the
158
+ // Frontier, which tells a refill a Lane's ending brought from a look the
159
+ // clock brought: a listing that fails is the Run's to throw only in the
160
+ // first. -1 until the first pass, which is a refill too.
161
+ let ended = 0;
162
+ let endedAtLastPass = -1;
139
163
 
140
164
  // Registered before the sweep, because a Stop that arrives during it is a Run
141
165
  // that claims nothing at all: the Lanes are empty, so there is nothing to
@@ -166,14 +190,13 @@ export async function processRun(
166
190
  * Put a Ticket in a Lane, and record what came back when it ends.
167
191
  *
168
192
  * The line about the Run stopping is logged by the Release that stopped it and
169
- * by no other, even where a later rate limit replaces the API failure it
170
- * stopped the Run with. The Ticket's own release is already logged where it
171
- * happened; this says the Run goes no further, so a transcript shows the
172
- * Frontier was left alone rather than found empty, and a Release into a Run
173
- * that an earlier Release or a Stop had stopped already claims to have
174
- * stopped nothing. It leads with the Ticket's number all the same: a
175
- * transcript of interleaved Lanes must not lose the line that explains why
176
- * one Lane was the last to be filled.
193
+ * by no other, even where a later Release outranks it on the last line. The
194
+ * Ticket's own release is already logged where it happened; this says the Run
195
+ * goes no further, so a transcript shows the Frontier was left alone rather
196
+ * than found empty, and a Release into a Run that an earlier Release or a
197
+ * Stop had stopped already claims to have stopped nothing. It leads with the
198
+ * Ticket's number all the same: a transcript of interleaved Lanes must not
199
+ * lose the line that explains why one Lane was the last to be filled.
177
200
  */
178
201
  function fillLane(ticket: Taken): void {
179
202
  taken.add(ticket.number);
@@ -181,12 +204,15 @@ export async function processRun(
181
204
  ticket.number,
182
205
  take(pipeline, ticket).then((outcome) => {
183
206
  busy.delete(ticket.number);
207
+ ended += 1;
184
208
  outcomes.push(outcome);
185
209
  if (outcome.outcome !== "released") return;
186
210
  if (runStop === undefined) {
187
211
  runStop = releaseStop(outcome, pipeline.baseBranch);
188
- pipeline.log?.(`#${outcome.ticket} stopped the Run · ${RELEASE_WORDS[outcome.cause]}`);
189
- } else if (outcome.cause === "rate-limited" && limitOutranks(runStop)) {
212
+ pipeline.log?.(
213
+ `#${outcome.ticket} stopped the Run · ${releaseWords(outcome.cause, pipeline.credential)}`,
214
+ );
215
+ } else if (outranks(outcome, runStop)) {
190
216
  runStop = releaseStop(outcome, pipeline.baseBranch);
191
217
  }
192
218
  }),
@@ -226,18 +252,50 @@ export async function processRun(
226
252
  }
227
253
  }
228
254
 
255
+ /**
256
+ * Whether a free Lane should look at the Frontier again before a busy one
257
+ * ends. Only after a pass that listed it, which every pass that leaves a Lane
258
+ * free while the Run is still taking Tickets did: so the wait counts from
259
+ * that listing.
260
+ */
261
+ function polling(): boolean {
262
+ return runStop === undefined && listing === undefined && busy.size > 0 && laneFree();
263
+ }
264
+
265
+ /** Wait for a Lane to end, or for the time to look at the Frontier again. */
266
+ async function nextPass(): Promise<void> {
267
+ const ending = Promise.race(busy.values());
268
+ if (!polling()) return await ending;
269
+ const poll = (pipeline.startTimer ?? startTimer)(POLL_MS);
270
+ try {
271
+ await Promise.race([ending, poll.elapsed]);
272
+ } finally {
273
+ poll.cancel();
274
+ }
275
+ }
276
+
229
277
  for (;;) {
230
278
  if (runStop === undefined && listing === undefined) {
279
+ const endedBefore = ended;
280
+ const looking = endedBefore === endedAtLastPass;
231
281
  try {
232
282
  await fillLanes();
283
+ endedAtLastPass = ended;
233
284
  } catch (error) {
234
- listing = error;
285
+ if (!looking) {
286
+ listing = error;
287
+ } else {
288
+ pipeline.log?.(pollFailure(error));
289
+ // A Lane that ended while the look was listing is still owed its
290
+ // refill, which runs now, and only that one's failure is the Run's.
291
+ if (ended !== endedBefore) continue;
292
+ }
235
293
  }
236
294
  }
237
295
  // Never while a Lane is busy, whatever the Frontier had to offer: that Lane
238
296
  // may be about to close the blocker the rest of the Frontier is waiting on.
239
297
  if (busy.size === 0) break;
240
- await Promise.race(busy.values());
298
+ await nextPass();
241
299
  }
242
300
 
243
301
  if (listing !== undefined) throw listing;
@@ -253,6 +311,12 @@ export async function processRun(
253
311
  return { outcomes, stop };
254
312
  }
255
313
 
314
+ /** The one line a look at the Frontier that could not list it earns. */
315
+ function pollFailure(error: unknown): string {
316
+ const minutes = POLL_MS / 60_000;
317
+ return `listing the Frontier failed, trying again in ${minutes} minutes · ${(error as Error).message}`;
318
+ }
319
+
256
320
  /**
257
321
  * The stop a Release puts on the Run: what released it, when a limit resets,
258
322
  * and which Check the Base branch fails.
@@ -262,6 +326,7 @@ function releaseStop(
262
326
  baseBranch: string,
263
327
  ): RunStop {
264
328
  if (outcome.cause === "api-error") return { reason: "api-error" };
329
+ if (outcome.cause === "out-of-budget") return { reason: "out-of-budget" };
265
330
  if (outcome.failingBase !== undefined) {
266
331
  return { reason: "failing-base", baseBranch, ...outcome.failingBase };
267
332
  }
@@ -272,14 +337,30 @@ function releaseStop(
272
337
  }
273
338
 
274
339
  /**
275
- * Whether a Ticket the rate limit released after `stop` puts the limit in its
276
- * place. An API failure says nothing of when the next Run can start, so the
277
- * limit outranks it; a limit nobody was told the end of is outranked by one a
340
+ * Whether a Ticket released after `stop` puts its own stop in its place.
341
+ *
342
+ * An API key out of budget outranks the rate limit and an API failure, since
343
+ * it alone needs the human to act: no wait mends it, only the Console. The
344
+ * rate limit outranks an API failure, which says nothing of when the next Run
345
+ * can start, and a limit nobody was told the end of is outranked by one a
278
346
  * Stage was told. A failing Base branch and a Stop stay whatever comes after
279
- * them, and so does a limit already told when it resets.
347
+ * them, and so does an API budget, and a limit already told when it resets.
280
348
  */
281
- function limitOutranks(stop: RunStop): boolean {
282
- return stop.reason === "api-error" || (stop.reason === "rate-limited" && stop.resetsAt === undefined);
349
+ function outranks(
350
+ outcome: Extract<TicketOutcome, { outcome: "released" }>,
351
+ stop: RunStop,
352
+ ): boolean {
353
+ switch (outcome.cause) {
354
+ case "out-of-budget":
355
+ return stop.reason === "rate-limited" || stop.reason === "api-error";
356
+ case "rate-limited":
357
+ return (
358
+ stop.reason === "api-error" ||
359
+ (stop.reason === "rate-limited" && stop.resetsAt === undefined)
360
+ );
361
+ default:
362
+ return false;
363
+ }
283
364
  }
284
365
 
285
366
  /**
package/src/start.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { resolveBaseBranch } from "./base-branch.js";
2
2
  import type { Config } from "./config.js";
3
- import { hostKind } from "./host.js";
3
+ import { type Credential, credentialRefusal, emptyBilling } from "./credential.js";
4
+ import { type HostKind, hostKind } from "./host.js";
4
5
  import { BaseBranchChecks } from "./failing-base.js";
5
6
  import { Landing } from "./landing.js";
6
7
  import { StandingNotes } from "./notes.js";
@@ -9,7 +10,7 @@ import type { Pipeline, TicketOutcome } from "./orchestrator.js";
9
10
  import type { AgentRunner } from "./ports/agent-runner.js";
10
11
  import type { Tracker } from "./ports/tracker.js";
11
12
  import type { Workspace } from "./ports/workspace.js";
12
- import { readinessRefusal } from "./readiness.js";
13
+ import { readinessRefusal, unpushedRefusal } from "./readiness.js";
13
14
  import { LOCAL_STATE_DIR, localStateTickets } from "./resume.js";
14
15
  import { writeRunVersion } from "./run-log.js";
15
16
  import { type RunStop, processRun } from "./run.js";
@@ -36,11 +37,15 @@ import { runSummary } from "./templates.js";
36
37
  * because how many Tickets a Host can carry at once is the Host's business, not
37
38
  * the Target's (ADR-0008). It may also be narrowed to the Tickets a human
38
39
  * named, ascending and each once; with none it drains the whole Frontier.
40
+ * It runs its Stages on the Host's API key only when it was started with
41
+ * `--api-key`, for the same reason: whose money a Run spends is the Host's
42
+ * business.
39
43
  */
40
44
  export interface Work {
41
45
  command: "run";
42
46
  lanes?: number;
43
47
  tickets?: number[];
48
+ apiKey?: true;
44
49
  }
45
50
 
46
51
  export interface StartOptions {
@@ -68,15 +73,21 @@ export interface StartOptions {
68
73
  error?: (line: string) => void;
69
74
  /** Where SIGTERM comes from. The process itself, unless a test is watching. */
70
75
  signals?: StopSource;
76
+ /**
77
+ * The Host's environment, which says what kind of Host this is and whether it
78
+ * exports a key. The process's own, unless a test says otherwise.
79
+ */
80
+ env?: Record<string, string | undefined>;
71
81
  }
72
82
 
73
83
  /**
74
84
  * Start a Run, and answer with the exit code it earned.
75
85
  *
76
- * Every refusal comes before the lock: a Target `init` has not set up, one
77
- * holding State files an earlier pipeline left in the checkout, and one with
78
- * nothing to gate a merge. None is a Run that went wrong, so none should leave
79
- * a lock behind for the next one to reclaim.
86
+ * Every refusal comes before the lock: an `--api-key` the Host cannot honour,
87
+ * a Target `init` has not set up, one whose remote lacks what `init` wrote,
88
+ * one holding State files an earlier pipeline left in the checkout, and one
89
+ * with nothing to gate a merge. None is a Run that went wrong, so none should
90
+ * leave a lock behind for the next one to reclaim.
80
91
  */
81
92
  export async function startRun(given: StartOptions): Promise<number> {
82
93
  // The count a Run was told is folded into the config once, here, so
@@ -87,6 +98,17 @@ export async function startRun(given: StartOptions): Promise<number> {
87
98
  const { repoRoot, config, tracker, workspace } = options;
88
99
  const log = options.log ?? ((line: string) => console.log(line));
89
100
  const error = options.error ?? ((line: string) => console.error(line));
101
+ const env = options.env ?? process.env;
102
+
103
+ // First, because it asks nothing of the Target: the Host either can or
104
+ // cannot run the Stages on the credential the Run was started with.
105
+ const credential: Credential = options.work.apiKey === true ? "api-key" : "subscription";
106
+ const host = hostKind(env);
107
+ const refusedCredential = credentialRefusal(credential, host, env);
108
+ if (refusedCredential !== undefined) {
109
+ error(refusedCredential);
110
+ return 2;
111
+ }
90
112
 
91
113
  const notReady = await readinessRefusal({ repoRoot, labels: config.labels, tracker });
92
114
  if (notReady !== undefined) {
@@ -94,6 +116,18 @@ export async function startRun(given: StartOptions): Promise<number> {
94
116
  return 2;
95
117
  }
96
118
 
119
+ // Once per Run, and here rather than with the rest of the Run's setup:
120
+ // readiness asks the remote's copy of this branch for what `init` wrote, and
121
+ // every branch, rebase, pull request and pull of the Run goes to the same one.
122
+ // After readiness's own questions, since the lookup may ask GitHub, which only
123
+ // a `gh` that runs can.
124
+ const baseBranch = await resolveBaseBranch(tracker, config);
125
+ const notPushed = await unpushedRefusal({ workspace, baseBranch });
126
+ if (notPushed !== undefined) {
127
+ error(notPushed);
128
+ return 2;
129
+ }
130
+
97
131
  const leftBehind = localStateTickets(repoRoot);
98
132
  if (leftBehind.length > 0) {
99
133
  error(localStateMessage(leftBehind));
@@ -140,7 +174,7 @@ export async function startRun(given: StartOptions): Promise<number> {
140
174
  const stopping = new StopSignal();
141
175
  const deafen = listenForStop(stopping, options.signals);
142
176
  try {
143
- return await execute(options, log, stopping);
177
+ return await execute(options, { credential, host, baseBranch }, log, stopping);
144
178
  } finally {
145
179
  // The lock goes first: SIGTERM between the two is a kill again, and a kill
146
180
  // that leaves the lock behind costs the next Run a stale holder to reclaim,
@@ -159,6 +193,11 @@ export async function startRun(given: StartOptions): Promise<number> {
159
193
 
160
194
  async function execute(
161
195
  options: StartOptions,
196
+ {
197
+ credential,
198
+ host,
199
+ baseBranch,
200
+ }: { credential: Credential; host: HostKind; baseBranch: string },
162
201
  log: (line: string) => void,
163
202
  stopping: StopSignal,
164
203
  ): Promise<number> {
@@ -183,11 +222,7 @@ async function execute(
183
222
  repository: options.repository,
184
223
  });
185
224
 
186
- // Once per Run, before any Ticket: every branch, rebase, pull request and
187
- // pull of this Run goes to the branch this answers.
188
- const baseBranch = await resolveBaseBranch(tracker, config);
189
-
190
- // Once per Run as well: only a Target that is the pipeline's own repository
225
+ // Once per Run: only a Target that is the pipeline's own repository
191
226
  // has a checkout that is the pipeline, and every Stage is told which it is in.
192
227
  const selfHosted = await isPipelineRepository(tracker, options.repository);
193
228
 
@@ -199,7 +234,9 @@ async function execute(
199
234
  repoRoot,
200
235
  runId,
201
236
  version,
202
- host: hostKind(process.env),
237
+ host,
238
+ credential,
239
+ billing: emptyBilling(),
203
240
  baseBranch,
204
241
  // Once per Run as well, and for the same reason: the Tickets of one Run
205
242
  // take turns between their rebase and their merge, and a Landing made per
@@ -223,7 +260,9 @@ async function execute(
223
260
  version,
224
261
  runId,
225
262
  durationMs: Date.now() - startedAt,
263
+ credential,
226
264
  outcomes,
265
+ billing: pipeline.billing,
227
266
  ...(newer === undefined ? {} : { newer }),
228
267
  stop,
229
268
  });