podster 0.0.1-test.12 → 0.0.1-test.14
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/README.md +1 -1
- package/build/core/explain.js +8 -1
- package/build/core/repository.js +92 -2
- package/build/core/run-interface.js +12 -2
- package/build/node/git.js +6 -1
- package/build/node/repo-path.js +104 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -77,7 +77,7 @@ Runner refuses a key file that's a link, that someone else can read, or that hol
|
|
|
77
77
|
|
|
78
78
|
Runner's three container images, one for each task, one for Claude Code and one for the egress proxy (used only by rooms that list hosts in `rooms[].network`), are pinned by image ID in Runner's home. The first time `run --provider-key-file` finds one missing, Runner builds it with Docker from the Dockerfile in this package, says so first, and pins what it built. A build takes a few minutes, the Claude Code image downloads Claude Code from npm's registry, and the task image downloads Node.js from nodejs.org. If a build fails, `run` stops before running anything.
|
|
79
79
|
|
|
80
|
-
The task image is Debian bookworm-slim with the tools Runner's own task tools use (`cat`, `tee`, `mkdir`, `ls`, `kill` and ripgrep's `rg`), `/bin/sh` for a run policy that allows the shell, and Node.js 22.23.5 LTS with its npm and npx, so a task's shell commands can run `node`, `npm test` or `npx` on what's already in the task's folder. Each is pinned: the base by digest, Debian's packages at exact versions from one snapshot, and Node's official tarball by a SHA-256 written in the Dockerfile. npm keeps its cache and logs in the
|
|
80
|
+
The task image is Debian bookworm-slim with the tools Runner's own task tools use (`cat`, `tee`, `mkdir`, `ls`, `kill` and ripgrep's `rg`), `/bin/sh` for a run policy that allows the shell, and Node.js 22.23.5 LTS with its npm and npx, so a task's shell commands can run `node`, `npm test` or `npx` on what's already in the task's folder. Each is pinned: the base by digest, Debian's packages at exact versions from one snapshot, and Node's official tarball by a SHA-256 written in the Dockerfile. npm keeps its cache and logs in `.cache/home/.npm` in the task's folder, under the task's `HOME` (Runner's fixed `npm_config_cache`, which overrides the image's npmrc), and its global prefix in `.npm-global` there; neither is ever committed; the rest of the container is read-only. A task's container has no network unless its room lists hosts in `rooms[].network`, so without that, `npm install`, and `npx` of a package that isn't already in the task's `node_modules`, fail. With `"network": ["registry.npmjs.org"]`, npm reaches the registry through Runner's egress proxy.
|
|
81
81
|
|
|
82
82
|
## Your run policy (`policy.json`)
|
|
83
83
|
|
package/build/core/explain.js
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
* None of this reaches the room: a start failure reaches it as one generic code, `runner_could_not_start`, in Runner's
|
|
8
8
|
* fixed note (`composeBlockedNote`), and the specific code and its explanation stay on the owner's machine.
|
|
9
9
|
*/
|
|
10
|
+
import { COMMIT_LIMITS } from "./repository.js";
|
|
11
|
+
/** A byte limit in whole MiB, for the fixed text below. */
|
|
12
|
+
const MIB = (bytes) => Math.round(bytes / (1024 * 1024));
|
|
10
13
|
const CODE = /^[a-z][a-z0-9_]{0,63}$/;
|
|
11
14
|
const group = (codes, what, todo) => codes.map((c) => [c, { what, todo }]);
|
|
12
15
|
const SEND = "send the code and the matching entry in the diagnostics file to whoever supports your Runner.";
|
|
@@ -61,13 +64,17 @@ const TABLE = new Map([
|
|
|
61
64
|
// The repository path.
|
|
62
65
|
...group(["repository_unavailable", "helper_unavailable", "git_unavailable"], "Runner can't work with this room's repository on this machine.", "Check that Git is installed and the room's repository is set in policy.json."),
|
|
63
66
|
...group(["repository_out_of_scope", "clone_url_unexpected", "repository_id_mismatch", "repository_renamed", "repository_archived", "repository_unprotected", "repository_unreadable"], "The room's repository isn't the one Runner's policy allows, or can't be used as it is.", "Check rooms[].repository in policy.json against the room's repository on GitHub."),
|
|
64
|
-
...group(["path_unsafe", "unsafe", "work_tree_git", "work_tree_link", "work_tree_special"
|
|
67
|
+
...group(["path_unsafe", "unsafe", "work_tree_git", "work_tree_link", "work_tree_special"], "The task's folder held something Runner won't commit or push.", "The details file names the check; the task is released."),
|
|
68
|
+
...group(["work_tree_too_large"], `The run's change was too large to commit: more than ${MIB(COMMIT_LIMITS.bytes)} MB, more than ${COMMIT_LIMITS.files.toLocaleString("en-US")} files, or more folder entries than Runner walks. Almost always it's a cache, a build or a download the agent left in the task's folder.`, "The task is released; add that folder to the repository's .gitignore, or ask for a smaller task."),
|
|
69
|
+
...group(["work_tree_file_too_large"], `One file in the run's change was over ${MIB(COMMIT_LIMITS.file_bytes)} MB, which GitHub warns about, close to the 100 MB it refuses.`, "The task is released; keep large files out of the repository, such as with .gitignore, or ask for a task that doesn't make them."),
|
|
70
|
+
...group(["work_tree_workflow"], "The task changed a GitHub workflow file, which Runner never commits.", "The task is released; a workflow change goes through a person."),
|
|
65
71
|
...group(["work_tree_name"], "A file or folder name in the task's folder isn't valid UTF-8, so Runner can't check it exactly.", "The task is released; rename or remove that entry if the run made it."),
|
|
66
72
|
...group(["work_tree_timeout"], "Git took too long listing what the repository ignores, so nothing was committed.", "The task is released; a .gitignore that isn't a plain file, such as a pipe, can cause this."),
|
|
67
73
|
...group(["work_tree_ignored_too_many"], "Git listed more ignored paths than Runner reads, so nothing was committed.", "Ignore whole folders in .gitignore rather than many single files; the task is released."),
|
|
68
74
|
...group(["access_authority_invalid", "access_expired", "access_fields", "access_invalid", "access_not_object", "access_permissions", "access_token_format", "token_revoked"], "Podster's repository access for this task wasn't usable.", "Try again later; if it keeps happening, check the room's repository settings in Podster."),
|
|
69
75
|
...group(["github_unavailable", "github_unreachable", "github_refused", "github_answer_too_large"], "GitHub couldn't be reached or refused a request.", "Check the network; Runner tries again later."),
|
|
70
76
|
...group(["checkout_failed", "checkout_moved", "checkout_unverified", "fetch_invalid", "git_init_failed", "default_branch_invalid", "ref_unreadable", "base_moved", "task_branch_moved"], "Runner couldn't prepare a clean checkout of the repository.", "Runner tries again later; the details file has more."),
|
|
77
|
+
...group(["push_too_large"], "GitHub or the network refused the push as too large, or dropped the connection while it was sent.", "The task is released; check what the task's branch would add, and keep caches and large files out with .gitignore."),
|
|
71
78
|
...group(["commit_failed", "commit_unexpected", "push_invalid", "push_rejected", "push_unconfirmed", "repo_publish_failed", "publish_failed"], "Runner couldn't commit or push the run's work.", "Runner retries for an hour, then releases the task; check the task branch's protection on GitHub."),
|
|
72
79
|
...group(["pull_request_commit_changed", "pull_request_not_found", "pull_request_not_open", "pull_request_refused", "pull_request_unreadable", "pull_request_wrong_base", "pull_request_wrong_head", "pull_request_wrong_repository", "pull_request_unread"], "The task's pull request wasn't as Runner pushed it.", "Check the pull request on GitHub; the task is released if it can't be submitted."),
|
|
73
80
|
...group(["run_no_changes"], "The run changed nothing, so there was nothing to submit.", "The task is released."),
|
package/build/core/repository.js
CHANGED
|
@@ -63,8 +63,98 @@ export const RENEW_BEFORE_MS = 4 * 60 * 1000;
|
|
|
63
63
|
* repository tracks under one of them is still committed as usual: an exclude applies only to untracked files.
|
|
64
64
|
*/
|
|
65
65
|
export const WORK_TREE_CACHES = [".cache", ".cargo", ".npm-global"];
|
|
66
|
-
/**
|
|
67
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Runner's default ignore list, written into its own `info/exclude` after the cache folders and applied to every
|
|
68
|
+
* repository whatever its `.gitignore` says, so a repository with none can still publish after an install and never
|
|
69
|
+
* commits what an agent leaves behind:
|
|
70
|
+
* - dependency folders that hold links: `node_modules/` and `.venv/` at any depth (a monorepo nests them);
|
|
71
|
+
* - Python's `__pycache__/` and `.pytest_cache/` at any depth;
|
|
72
|
+
* - package managers' caches at any depth: npm's `.npm-cache/` and `.npm/`, Yarn's `.yarn/cache/` (led by `**` and a slash, so it isn't
|
|
73
|
+
* anchored at the top, as a line with a `/` inside would be), pnpm's `.pnpm-store/`, and `.cache/` (2026-11-21: an
|
|
74
|
+
* agent ran npm with its cache at `/work/.npm-cache`, and Runner's one commit held 524 cache files, about 140 MB, so the
|
|
75
|
+
* push failed). `.cache/` at any depth also covers the top `.cache` that `WORK_TREE_CACHES` names, which holds the
|
|
76
|
+
* task's `HOME`; both lines stay, the first anchored there whatever this list says;
|
|
77
|
+
* - at the top only: cargo's build folder `/target/`, wrangler's local state `/.wrangler/`, and agents' scratch `/.tmp/`;
|
|
78
|
+
* - `.DS_Store` at any depth;
|
|
79
|
+
* - `.env` and `.env.*` at any depth, except `.env.example`, `.env.sample` and `.env.template`, so an agent-written
|
|
80
|
+
* `.env` is never committed.
|
|
81
|
+
* Folder lines end in `/`, so a link by one of those names isn't excluded and the work tree check still refuses it; a
|
|
82
|
+
* folder Git then ignores whole is skipped by that check (`ignoredFolders`), unless another ignored entry is listed
|
|
83
|
+
* beneath it (`wholeFolders`), so an excluded `.env` that is a link is always reached and refuses, at any depth. An exclude applies only to untracked files:
|
|
84
|
+
* a file the repository tracks under or by one of these names is still committed as usual, and a folder holding one is
|
|
85
|
+
* walked by the work tree check as before.
|
|
86
|
+
*/
|
|
87
|
+
export const WORK_TREE_DEFAULT_IGNORE = [
|
|
88
|
+
"node_modules/",
|
|
89
|
+
".venv/",
|
|
90
|
+
"__pycache__/",
|
|
91
|
+
".pytest_cache/",
|
|
92
|
+
".npm-cache/",
|
|
93
|
+
".npm/",
|
|
94
|
+
"**/.yarn/cache/",
|
|
95
|
+
".pnpm-store/",
|
|
96
|
+
".cache/",
|
|
97
|
+
"/target/",
|
|
98
|
+
"/.wrangler/",
|
|
99
|
+
"/.tmp/",
|
|
100
|
+
".DS_Store",
|
|
101
|
+
".env",
|
|
102
|
+
".env.*",
|
|
103
|
+
"!.env.example",
|
|
104
|
+
"!.env.sample",
|
|
105
|
+
"!.env.template",
|
|
106
|
+
];
|
|
107
|
+
/**
|
|
108
|
+
* The `info/exclude` Runner writes: each cache folder, anchored at the work tree's top, as a folder only, then the
|
|
109
|
+
* default ignore list (`WORK_TREE_DEFAULT_IGNORE`) as written there.
|
|
110
|
+
*/
|
|
111
|
+
export const WORK_TREE_EXCLUDE = [...WORK_TREE_CACHES.map((name) => `/${name}/`), ...WORK_TREE_DEFAULT_IGNORE].map((line) => `${line}\n`).join("");
|
|
112
|
+
/**
|
|
113
|
+
* The most one publish commits, checked after `git add --all` and before the commit (2026-11-21: a commit of npm's cache,
|
|
114
|
+
* 524 files and about 140 MB, made the push fail). All three are fixed here, in code:
|
|
115
|
+
* - `file_bytes`, 50 MiB for any one file: GitHub warns about a file over 50 MiB and refuses one over 100 MiB (GH001),
|
|
116
|
+
* so this refuses before GitHub would, with room to spare (`work_tree_file_too_large`);
|
|
117
|
+
* - `bytes`, 50 MiB for all the files the commit adds or changes, as Git stores them uncompressed: a task's change is
|
|
118
|
+
* source and a lock file, which is kilobytes to a few megabytes; a push of hundreds of megabytes is what fails over
|
|
119
|
+
* HTTPS, and anything near this is almost always a cache, a build or a download the agent left (`work_tree_too_large`);
|
|
120
|
+
* - `files`, 5,000 paths added, changed or deleted, far past any hand-made change and under the 1 MB Runner reads of
|
|
121
|
+
* Git's list of them (`work_tree_too_large`).
|
|
122
|
+
* A file over `file_bytes` is named by its own code even when the total is over too. **Proposed** figures.
|
|
123
|
+
*/
|
|
124
|
+
export const COMMIT_LIMITS = Object.freeze({ files: 5_000, bytes: 50 * 1024 * 1024, file_bytes: 50 * 1024 * 1024 });
|
|
125
|
+
const NO_OBJECT = /^0+$/;
|
|
126
|
+
/**
|
|
127
|
+
* Reads `git diff --cached --raw -z --no-renames --no-abbrev` as bytes: each entry is `:<old mode> <new mode> <old id>
|
|
128
|
+
* <new id> <status>` then the path, NUL after each. Counts every path, and keeps each new blob ID the commit would add:
|
|
129
|
+
* none for a deletion, none for a submodule (mode 160000), which carries no content. Anything else shaped refuses.
|
|
130
|
+
*/
|
|
131
|
+
export function readStagedChanges(listing) {
|
|
132
|
+
const parts = Buffer.from(listing.buffer, listing.byteOffset, listing.byteLength).toString("latin1").split("\0");
|
|
133
|
+
if (parts.at(-1) === "")
|
|
134
|
+
parts.pop();
|
|
135
|
+
if (parts.length % 2 !== 0)
|
|
136
|
+
throw new RepoPathError("commit_failed");
|
|
137
|
+
const blobs = [];
|
|
138
|
+
for (let at = 0; at < parts.length; at += 2) {
|
|
139
|
+
const head = /^:([0-7]{6}) ([0-7]{6}) ([0-9a-f]{40}|[0-9a-f]{64}) ([0-9a-f]{40}|[0-9a-f]{64}) ([A-Z])$/.exec(parts[at]);
|
|
140
|
+
if (!head || parts[at + 1] === "")
|
|
141
|
+
throw new RepoPathError("commit_failed");
|
|
142
|
+
const [, , mode, , id, status] = head;
|
|
143
|
+
if (status !== "D" && mode !== "160000" && !NO_OBJECT.test(id))
|
|
144
|
+
blobs.push(id);
|
|
145
|
+
}
|
|
146
|
+
return { paths: parts.length / 2, blobs };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Refuses a commit-to-be over `COMMIT_LIMITS`, given its path count and each added or changed blob's size, in bytes, as
|
|
150
|
+
* `git cat-file --batch-check=%(objectsize)` answers them: one file too large first, then too many paths or bytes.
|
|
151
|
+
*/
|
|
152
|
+
export function checkCommitSize(paths, sizes, limits = COMMIT_LIMITS) {
|
|
153
|
+
if (sizes.some((size) => size > limits.file_bytes))
|
|
154
|
+
throw new RepoPathError("work_tree_file_too_large");
|
|
155
|
+
if (paths > limits.files || sizes.reduce((sum, size) => sum + size, 0) > limits.bytes)
|
|
156
|
+
throw new RepoPathError("work_tree_too_large");
|
|
157
|
+
}
|
|
68
158
|
/** The prefix of every task branch. */
|
|
69
159
|
export const BRANCH_PREFIX = "podster/";
|
|
70
160
|
/** The fixed identity of a commit Runner makes, so no name or address from anywhere else is ever used. */
|
|
@@ -82,8 +82,18 @@ export function markUntrusted(bytes) {
|
|
|
82
82
|
*/
|
|
83
83
|
export const TASK_HOME_IN_FOLDER = [".cache", "home"];
|
|
84
84
|
export const TASK_HOME = `${TASK_FOLDER_IN_CONTAINER}/${TASK_HOME_IN_FOLDER.join("/")}`;
|
|
85
|
-
/**
|
|
86
|
-
|
|
85
|
+
/**
|
|
86
|
+
* npm's cache, under the task's `HOME` and so under a folder Runner excludes from a repository room's commit. The task
|
|
87
|
+
* image's npmrc puts it in /tmp, a 64 MB tmpfs an install can fill; on 2026-11-21 an agent moved it to
|
|
88
|
+
* `/work/.npm-cache` instead, and Runner committed it. Pinned here, in code, it lands where nothing is committed.
|
|
89
|
+
*/
|
|
90
|
+
export const TASK_NPM_CACHE = `${TASK_HOME}/.npm`;
|
|
91
|
+
/**
|
|
92
|
+
* The container's whole environment: fixed, nothing inherited, nothing shaped like a secret. `WRANGLER_SEND_METRICS`
|
|
93
|
+
* keeps wrangler from calling its metrics host (sparrow.cloudflare.com), and `npm_config_cache` pins npm's cache
|
|
94
|
+
* (`TASK_NPM_CACHE`); both are set here in code, never from the task.
|
|
95
|
+
*/
|
|
96
|
+
export const CONTAINER_ENV = Object.freeze({ HOME: TASK_HOME, PATH: "/usr/local/bin:/usr/bin:/bin", LANG: "C.UTF-8", WRANGLER_SEND_METRICS: "false", npm_config_cache: TASK_NPM_CACHE });
|
|
87
97
|
export const CONTAINER_WORKDIR = TASK_FOLDER_IN_CONTAINER;
|
|
88
98
|
/** The egress proxy's name on a run's internal network, and its port (`egress-proxy.ts`). */
|
|
89
99
|
export const EGRESS_ALIAS = "egress";
|
package/build/node/git.js
CHANGED
|
@@ -95,7 +95,7 @@ export function gitCli(program, home, from = process.env) {
|
|
|
95
95
|
throw new RepoPathError("git_unavailable");
|
|
96
96
|
}
|
|
97
97
|
return (args, opts) => new Promise((resolve, reject) => {
|
|
98
|
-
const child = spawn(resolved, args, { cwd: home, env, stdio: ["ignore", "pipe", "pipe", opts.secret === undefined ? "ignore" : "pipe"], signal: opts.signal, timeout: opts.timeout_ms ?? GIT_TIMEOUT_MS, killSignal: "SIGKILL" });
|
|
98
|
+
const child = spawn(resolved, args, { cwd: home, env, stdio: [opts.input === undefined ? "ignore" : "pipe", "pipe", "pipe", opts.secret === undefined ? "ignore" : "pipe"], signal: opts.signal, timeout: opts.timeout_ms ?? GIT_TIMEOUT_MS, killSignal: "SIGKILL" });
|
|
99
99
|
const out = [];
|
|
100
100
|
const err = [];
|
|
101
101
|
let size = 0;
|
|
@@ -117,6 +117,11 @@ export function gitCli(program, home, from = process.env) {
|
|
|
117
117
|
pipe.on("error", () => undefined);
|
|
118
118
|
pipe.end(`${opts.secret}\n`);
|
|
119
119
|
}
|
|
120
|
+
if (opts.input !== undefined && child.stdin) {
|
|
121
|
+
// Only Runner's own fixed-shape input (object IDs); a command that ends early leaves the rest unread.
|
|
122
|
+
child.stdin.on("error", () => undefined);
|
|
123
|
+
child.stdin.end(opts.input);
|
|
124
|
+
}
|
|
120
125
|
child.on("error", () => reject(new RepoPathError("git_unavailable", true)));
|
|
121
126
|
child.on("close", (code, signal) => {
|
|
122
127
|
if (cut)
|
package/build/node/repo-path.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* that commit, and verifies the head and a clean tree before answering it for the decision to pin.
|
|
13
13
|
* - **`publish`**, after the run's container is confirmed stopped, asks for the token again (renewing after a full
|
|
14
14
|
* recheck if it's due), checks the repository and its rules again, walks the work tree without following anything and
|
|
15
|
-
* refuses any link or `.git` look-alike the task left, commits on top of the pinned commit under a fixed identity,
|
|
15
|
+
* refuses any link or `.git` look-alike the task left, refuses a change under `.github/workflows/`, commits on top of the pinned commit under a fixed identity,
|
|
16
16
|
* pushes the one task branch, and opens its pull request, or finds the one it opened before, and verifies it.
|
|
17
17
|
*
|
|
18
18
|
* Host-side folder access goes through `safe-fs.ts` (`lstat`, `O_NOFOLLOW`, `realpath`; L3 on #459). Git runs as
|
|
@@ -23,7 +23,7 @@ import { lstat, opendir, realpath, rm } from "node:fs/promises";
|
|
|
23
23
|
import { dirname, join, relative } from "node:path";
|
|
24
24
|
import { GatewayError, meaningOf } from "../core/errors.js";
|
|
25
25
|
import { pullText } from "../core/pull-text.js";
|
|
26
|
-
import { checkProtected, COMMIT_IDENTITY, WORK_TREE_EXCLUDE, fetchArgs, GITHUB, hardening, isCommit, locate, pushArgs, readAccess, readPullRequest, readRef, readRepository, renewDue, RepoPathError, taskBranch, } from "../core/repository.js";
|
|
26
|
+
import { checkCommitSize, checkProtected, COMMIT_IDENTITY, COMMIT_LIMITS, WORK_TREE_EXCLUDE, fetchArgs, GITHUB, hardening, isCommit, locate, pushArgs, readAccess, readPullRequest, readRef, readRepository, readStagedChanges, renewDue, RepoPathError, taskBranch, } from "../core/repository.js";
|
|
27
27
|
import { foldedSegment } from "../core/tool-policy.js";
|
|
28
28
|
import { checkedHelper, findGit, GIT_OUTPUT_CUT, GIT_TIMED_OUT, gitCli } from "./git.js";
|
|
29
29
|
import { githubApi } from "./github-api.js";
|
|
@@ -152,11 +152,13 @@ export class GitRepositoryPath {
|
|
|
152
152
|
}
|
|
153
153
|
async git(task, args, opts) {
|
|
154
154
|
const helper = opts.secret === undefined ? null : this.deps.helper;
|
|
155
|
-
return this.deps.git([...hardening(helper), ...locate(this.gitDir(task.workspace_id, task.task_id), task.task_folder), ...args], { secret: opts.secret, signal: opts.signal, timeout_ms: opts.timeout_ms });
|
|
155
|
+
return this.deps.git([...hardening(helper), ...locate(this.gitDir(task.workspace_id, task.task_id), task.task_folder), ...args], { secret: opts.secret, signal: opts.signal, timeout_ms: opts.timeout_ms, ...(opts.input === undefined ? {} : { input: opts.input }) });
|
|
156
156
|
}
|
|
157
157
|
/**
|
|
158
|
-
* Runner's own `info/exclude` in the task's Git folder: the tools' cache folders (`WORK_TREE_CACHES`)
|
|
159
|
-
*
|
|
158
|
+
* Runner's own `info/exclude` in the task's Git folder: the tools' cache folders (`WORK_TREE_CACHES`) and the default
|
|
159
|
+
* ignore list (`WORK_TREE_DEFAULT_IGNORE`: dependency folders, build output, scratch, `.DS_Store` and `.env` files), so
|
|
160
|
+
* nothing untracked there is ever committed, and `ignoredFolders` names the folders so the work tree check skips them.
|
|
161
|
+
* A tracked file under one is still committed. Written at checkout, and again before a publish if it isn't exactly that.
|
|
160
162
|
*/
|
|
161
163
|
async excludeCaches(task) {
|
|
162
164
|
const gitDir = this.gitDir(task.workspace_id, task.task_id);
|
|
@@ -185,6 +187,51 @@ export class GitRepositoryPath {
|
|
|
185
187
|
throw new RepoPathError("commit_failed");
|
|
186
188
|
return wholeFolders(listed.stdout_bytes);
|
|
187
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Refuses (`work_tree_workflow`) when what would be committed adds, changes, deletes or renames anything under
|
|
192
|
+
* `.github/workflows/` (BUILDS.md rule 1): every path the index differs in from the pinned commit, renames read as a
|
|
193
|
+
* deletion and an addition, so both sides count. Runs after `git add --all`, so a workflow file the task made counts,
|
|
194
|
+
* and one the repository tracks that the task left alone doesn't. GitHub refuses such a push from the App anyway.
|
|
195
|
+
*/
|
|
196
|
+
async noWorkflowChange(task, signal) {
|
|
197
|
+
const args = ["diff", "--cached", "--name-only", "-z", "--no-renames", "--no-ext-diff", "--no-textconv", "--end-of-options", task.base_commit, "--"];
|
|
198
|
+
const listed = await this.git(task, args, { signal });
|
|
199
|
+
if (listed.code === GIT_OUTPUT_CUT)
|
|
200
|
+
throw new RepoPathError("work_tree_too_large");
|
|
201
|
+
if (listed.code !== 0 || listed.stdout_bytes === undefined)
|
|
202
|
+
throw new RepoPathError("commit_failed");
|
|
203
|
+
if (touchesWorkflows(listed.stdout_bytes))
|
|
204
|
+
throw new RepoPathError("work_tree_workflow");
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Refuses a commit-to-be over `COMMIT_LIMITS` (`work_tree_too_large`, `work_tree_file_too_large`), measured from the
|
|
208
|
+
* index after `git add --all`: every path it differs in from the pinned commit, and the size of each blob it adds or
|
|
209
|
+
* changes, read from Git's object store by ID (`cat-file --batch-check`), never from the work tree. A list past the
|
|
210
|
+
* 1 MB Runner reads is too many paths.
|
|
211
|
+
*/
|
|
212
|
+
async withinLimits(task, signal) {
|
|
213
|
+
const args = ["diff", "--cached", "--raw", "-z", "--no-renames", "--no-abbrev", "--no-ext-diff", "--no-textconv", "--end-of-options", task.base_commit, "--"];
|
|
214
|
+
const listed = await this.git(task, args, { signal });
|
|
215
|
+
if (listed.code === GIT_OUTPUT_CUT)
|
|
216
|
+
throw new RepoPathError("work_tree_too_large");
|
|
217
|
+
if (listed.code !== 0 || listed.stdout_bytes === undefined)
|
|
218
|
+
throw new RepoPathError("commit_failed");
|
|
219
|
+
const limits = this.deps.commit_limits ?? COMMIT_LIMITS;
|
|
220
|
+
const staged = readStagedChanges(listed.stdout_bytes);
|
|
221
|
+
if (staged.paths > limits.files)
|
|
222
|
+
throw new RepoPathError("work_tree_too_large");
|
|
223
|
+
if (staged.blobs.length === 0)
|
|
224
|
+
return;
|
|
225
|
+
const sized = await this.git(task, ["cat-file", "--batch-check=%(objectsize)"], { signal, input: staged.blobs.map((id) => `${id}\n`).join("") });
|
|
226
|
+
if (sized.code === GIT_OUTPUT_CUT)
|
|
227
|
+
throw new RepoPathError("work_tree_too_large");
|
|
228
|
+
const lines = sized.stdout.split("\n");
|
|
229
|
+
if (lines.at(-1) === "")
|
|
230
|
+
lines.pop();
|
|
231
|
+
if (sized.code !== 0 || lines.length !== staged.blobs.length || !lines.every((line) => /^(0|[1-9][0-9]{0,14})$/.test(line)))
|
|
232
|
+
throw new RepoPathError("commit_failed");
|
|
233
|
+
checkCommitSize(staged.paths, lines.map(Number), limits);
|
|
234
|
+
}
|
|
188
235
|
async head(task, signal, rev = "HEAD") {
|
|
189
236
|
const answer = await this.git(task, ["rev-parse", "--verify", "--quiet", "--end-of-options", `${rev}^{commit}`], { signal });
|
|
190
237
|
const sha = answer.stdout.trim();
|
|
@@ -291,6 +338,8 @@ export class GitRepositoryPath {
|
|
|
291
338
|
// `:/` names the whole work tree from its top, whatever Git's working folder is.
|
|
292
339
|
if ((await this.git(task, ["add", "--all", "--", ":/"], { signal })).code !== 0)
|
|
293
340
|
throw new RepoPathError("commit_failed");
|
|
341
|
+
await this.noWorkflowChange(task, signal);
|
|
342
|
+
await this.withinLimits(task, signal);
|
|
294
343
|
if (before === task.base_commit) {
|
|
295
344
|
if (await this.clean(task, signal))
|
|
296
345
|
return { kind: "no_changes" };
|
|
@@ -347,16 +396,28 @@ export class GitRepositoryPath {
|
|
|
347
396
|
forget(workspace_id, task_id) {
|
|
348
397
|
this.deps.broker.forget(workspace_id, task_id);
|
|
349
398
|
}
|
|
350
|
-
/**
|
|
399
|
+
/**
|
|
400
|
+
* A failed fetch or push, by a fixed code: a refused credential reads as a revoked token, and a push GitHub or the way
|
|
401
|
+
* to it plainly refused for its size as `push_too_large`; a timeout or failed connection stays `github_unreachable`. Git's words are matched here and never kept or logged.
|
|
402
|
+
*/
|
|
351
403
|
gitFailure(task, result, fallback) {
|
|
352
404
|
const text = `${result.stdout}\n${result.stderr}`;
|
|
353
405
|
if (/Authentication failed|could not read (Username|Password)|returned error: 40[13]|Invalid username or (password|token)/i.test(text)) {
|
|
354
406
|
this.deps.broker.revoked(task.workspace_id, task.task_id);
|
|
355
407
|
return new RepoPathError("token_revoked");
|
|
356
408
|
}
|
|
409
|
+
// A timeout or a connection that failed is the network's, and tried again, whatever else Git said with it: `RPC
|
|
410
|
+
// failed; curl 28 Operation timed out` is one.
|
|
411
|
+
if (/Could not resolve host|Failed to connect|Connection timed out|Operation timed out|timed out|Connection reset/i.test(text))
|
|
412
|
+
return new RepoPathError("github_unreachable", true);
|
|
413
|
+
// A push GitHub or the way to it refused for its size, only on a clear sign of it: an HTTP 413, a pack over a limit,
|
|
414
|
+
// or GitHub's large-file refusal. Only for a push; checked before the plain rejection, since GH001 arrives as one. A
|
|
415
|
+
// bare `RPC failed` or `remote end hung up` says neither, and falls back to `push_failed`.
|
|
416
|
+
if (fallback === "push_failed" && /HTTP 413|returned error: 413|pack exceeds|GH001|exceeds GitHub's file size limit|this exceeds/i.test(text))
|
|
417
|
+
return new RepoPathError("push_too_large");
|
|
357
418
|
if (/\[rejected\]|\[remote rejected\]|non-fast-forward|fetch first/.test(text))
|
|
358
419
|
return new RepoPathError("push_rejected");
|
|
359
|
-
if (/
|
|
420
|
+
if (/unable to access/i.test(text))
|
|
360
421
|
return new RepoPathError("github_unreachable", true);
|
|
361
422
|
return new RepoPathError(fallback);
|
|
362
423
|
}
|
|
@@ -384,23 +445,54 @@ export function nameOf(bytes) {
|
|
|
384
445
|
* The folders in `git ls-files -z --others --ignored --directory`'s answer, read as bytes, relative to the work tree's
|
|
385
446
|
* top: only entries Git names with a trailing `/`, which it does for a folder it ignores whole. Any entry that isn't
|
|
386
447
|
* valid UTF-8 refuses. An ignored file, a link Git ignores (Git names a link as a file), and anything with an empty,
|
|
387
|
-
* `.` or `..` part are left out, so they are walked.
|
|
448
|
+
* `.` or `..` part are left out, so they are walked. A folder with any other listed entry beneath it is left out too
|
|
449
|
+
* (the review of #508): when everything in a folder is ignored, Git lists the folder and also the ignored entries in
|
|
450
|
+
* it (`f/` and `f/.env`, `x/` and `x/node_modules/`), so skipping `f` would never `lstat` a link `f/.env`, and skipping
|
|
451
|
+
* `x` would never read the entries of `x/node_modules`, where a `.git` look-alike must refuse. Such a parent is walked
|
|
452
|
+
* as usual, and only the deepest listed folders are skipped.
|
|
388
453
|
*/
|
|
389
454
|
export function wholeFolders(listing) {
|
|
390
|
-
const
|
|
455
|
+
const entries = [];
|
|
391
456
|
const bytes = Buffer.from(listing.buffer, listing.byteOffset, listing.byteLength);
|
|
392
457
|
for (let at = 0; at < bytes.length;) {
|
|
393
458
|
const end = bytes.indexOf(0, at);
|
|
394
|
-
|
|
459
|
+
entries.push(nameOf(bytes.subarray(at, end === -1 ? bytes.length : end)));
|
|
395
460
|
at = end === -1 ? bytes.length : end + 1;
|
|
461
|
+
}
|
|
462
|
+
// Every folder some listed entry lies beneath, whatever that entry is.
|
|
463
|
+
const parents = new Set();
|
|
464
|
+
for (const entry of entries) {
|
|
465
|
+
const trimmed = entry.endsWith("/") ? entry.slice(0, -1) : entry;
|
|
466
|
+
for (let slash = trimmed.indexOf("/"); slash !== -1; slash = trimmed.indexOf("/", slash + 1))
|
|
467
|
+
parents.add(trimmed.slice(0, slash));
|
|
468
|
+
}
|
|
469
|
+
const folders = new Set();
|
|
470
|
+
for (const entry of entries) {
|
|
396
471
|
if (!entry.endsWith("/"))
|
|
397
472
|
continue;
|
|
398
473
|
const parts = entry.slice(0, -1).split("/");
|
|
399
|
-
|
|
400
|
-
|
|
474
|
+
const name = parts.join("/");
|
|
475
|
+
if (parts.every((part) => part !== "" && part !== "." && part !== "..") && !parents.has(name))
|
|
476
|
+
folders.add(name);
|
|
401
477
|
}
|
|
402
478
|
return folders;
|
|
403
479
|
}
|
|
480
|
+
/**
|
|
481
|
+
* Whether a NUL-separated list of changed paths (relative to the work tree's top) names anything under
|
|
482
|
+
* `.github/workflows/`, each part compared as a file system might see it (`foldedSegment`), so `.GitHub/Workflows/x.yml`
|
|
483
|
+
* counts too. Only the top-level folder counts: it is the only one GitHub runs workflows from.
|
|
484
|
+
*/
|
|
485
|
+
export function touchesWorkflows(listing) {
|
|
486
|
+
const bytes = Buffer.from(listing.buffer, listing.byteOffset, listing.byteLength);
|
|
487
|
+
for (let at = 0; at < bytes.length;) {
|
|
488
|
+
const end = bytes.indexOf(0, at);
|
|
489
|
+
const parts = bytes.subarray(at, end === -1 ? bytes.length : end).toString("utf8").split("/");
|
|
490
|
+
if (parts.length >= 2 && foldedSegment(parts[0]) === ".github" && foldedSegment(parts[1]) === "workflows")
|
|
491
|
+
return true;
|
|
492
|
+
at = end === -1 ? bytes.length : end + 1;
|
|
493
|
+
}
|
|
494
|
+
return false;
|
|
495
|
+
}
|
|
404
496
|
/**
|
|
405
497
|
* The work tree, walked with `lstat` and never through a link, before anything is committed from it: no link of any
|
|
406
498
|
* kind, nothing named `.git` or folding to it at any depth (a nested repository would be read by host Git), and no more
|