Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t.sh
91 linesCodeBlameRaw

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

The sidebar asks billing whether it is on, not for the account, so no page waits on the card processor1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { cancelTask, enqueueTask, handedOverStep, selfHostedRoute, taskEnv, taskRepo } from "./self-hosted.ts";
5
6/** An actions service that answers each method with what `answers` says. */
7function actions(answers: Record<string, unknown>, calls: { method: string; body: unknown }[] = []) {
8 return {
9 async fetch(url: string, init?: RequestInit): Promise<Response> {
10 const method = new URL(url).pathname.replace("/rpc/", "");
11 calls.push({ method, body: JSON.parse(String(init?.body ?? "{}")) });
12 if (!(method in answers)) return new Response("no", { status: 500 });
13 return Response.json(answers[method]);
14 },
15 };
16}
17
18const repo = { namespace: "Acme", name: "web" };
19
20test("work goes to self-hosted runners only when the workspace says so", async () => {
21 const calls: { method: string; body: unknown }[] = [];
22 assert.deepEqual(await selfHostedRoute(actions({ runner_route: ["self-hosted", "linux"] }, calls), repo), ["self-hosted", "linux"]);
23 assert.deepEqual(calls[0], { method: "runner_route", body: { workspace: "acme", repo } });
24 assert.equal(await selfHostedRoute(actions({ runner_route: null }), repo), null);
25 assert.equal(await selfHostedRoute(actions({ runner_route: [] }), repo), null);
26 // The actions service cannot say: a sandbox, as before.
27 assert.equal(await selfHostedRoute(actions({}), repo), null);
28});
29
30test("a task carries the sandbox's environment, without what only a sandbox has", () => {
31 const env = taskEnv({
32 MODE: "checks",
33 G1T_TOKEN: "g1t_x",
34 HTTPS_PROXY: "http://proxy",
35 NODE_EXTRA_CA_CERTS: "/etc/ca.crt",
36 GUARDRAILS: "{}",
37 });
38 assert.equal(env.MODE, "checks");
39 assert.equal(env.G1T_TOKEN, "g1t_x");
40 assert.equal(env.GUARDRAILS, "{}");
41 assert.equal(env.HTTPS_PROXY, undefined);
42 assert.equal(env.NODE_EXTRA_CA_CERTS, undefined);
43 assert.equal(env.G1T_ABUSE, "off");
44 assert.equal(env.G1T_SELF_HOSTED, "1");
45});
46
47test("handing over and withdrawing a task", async () => {
48 const calls: { method: string; body: unknown }[] = [];
49 const service = actions({ enqueue_task: { ok: true, value: "rtk_1" }, cancel_task: { ok: true, value: true } }, calls);
50 const id = await enqueueTask(service, {
51 sandbox: "do_1",
52 repo,
53 kind: "checks",
54 title: "Checks on acme/web#3",
55 labels: ["self-hosted"],
56 env: { MODE: "checks" },
57 timeoutMinutes: 45,
The Runners page shows the machines a workspace's agents and workflow jobs run on, in Workspace under Compute: g1t's cloud beside your own runners, what each is running now with a link to it, what's waiting, this month's machine time and its cost (your own runners' free), where agent work and workflow jobs run, adding a runner, and groups; runner_activity in Actions says what runs where, work handed to your runners keeps its agent run, and the self-hosted runners guide says how.58 runId: "run_9",
The sidebar asks billing whether it is on, not for the account, so no page waits on the card processor59 });
60 assert.equal(id, "rtk_1");
61 assert.equal((calls[0]!.body as { workspace: string }).workspace, "acme");
The Runners page shows the machines a workspace's agents and workflow jobs run on, in Workspace under Compute: g1t's cloud beside your own runners, what each is running now with a link to it, what's waiting, this month's machine time and its cost (your own runners' free), where agent work and workflow jobs run, adding a runner, and groups; runner_activity in Actions says what runs where, work handed to your runners keeps its agent run, and the self-hosted runners guide says how.62 // The agent run it is goes as run_id, for the Runners page's links.
63 assert.equal((calls[0]!.body as { run_id: string }).run_id, "run_9");
The sidebar asks billing whether it is on, not for the account, so no page waits on the card processor64 await cancelTask(service, "do_1", "Stopped.");
65 assert.deepEqual(calls[1], { method: "cancel_task", body: { sandbox: "do_1", reason: "Stopped." } });
66 await assert.rejects(
67 enqueueTask(actions({ enqueue_task: { ok: false, error: { message: "no key" } } }), {
68 sandbox: "do_2",
69 repo,
70 kind: "agent",
71 title: "x",
72 labels: ["self-hosted"],
73 env: {},
74 timeoutMinutes: 1,
75 }),
76 /no key/,
77 );
78 // Never throws.
79 await cancelTask(actions({}), "do_3", null);
80});
81
82test("the run says where it went and what is not enforced there", () => {
83 assert.match(handedOverStep(["self-hosted", "linux"]), /self-hosted, linux.*guardrails are not enforced/);
84});
85
86test("a task's repository comes from what the sandbox was started with", () => {
87 assert.deepEqual(taskRepo({ repo }, undefined, undefined), repo);
88 assert.deepEqual(taskRepo(undefined, { repo: "acme/api" }, undefined), { namespace: "acme", name: "api" });
89 assert.deepEqual(taskRepo(undefined, undefined, { repo: "acme/docs" }), { namespace: "acme", name: "docs" });
90 assert.equal(taskRepo(undefined, undefined, undefined), null);
91});

This file's history is long; its oldest lines are credited to the oldest commit read.