@antelopejs/tooling-configs 0.3.1 → 0.3.3
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 +26 -14
- package/dist/api-CCOiLN3w.mjs +185 -0
- package/dist/bin/checks.mjs +253 -27
- package/dist/bin/garden.mjs +6 -171
- package/dist/bin/lease.mjs +3 -279
- package/dist/bin/sync.mjs +8 -8
- package/dist/bin/triage.d.mts +1 -0
- package/dist/bin/triage.mjs +108 -0
- package/dist/bin/verify.mjs +155 -11
- package/dist/{ci-workflow-mc0vywUV.mjs → ci-workflow-CXcAZj6g.mjs} +55 -1
- package/dist/ports-DGP6bPJy.mjs +282 -0
- package/package.json +2 -1
package/dist/bin/garden.mjs
CHANGED
|
@@ -1,166 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { c as object, d as optTime, f as parseJson, h as time, i as isObject, l as optNum, m as strings, n as children, o as list, p as str, r as flag, s as num, t as child, u as optStr } from "../json-CG2L7YFl.mjs";
|
|
3
3
|
import { n as runCliAsync } from "../cli-4Tv71vYk.mjs";
|
|
4
|
-
import { c as ciRenovateSyncCallers, i as CI_RENOVATE_SYNC_REF, n as CI_NODE_REF, r as CI_PATH, s as ciNodeCallers, t as CI_CONTEXT } from "../ci-workflow-
|
|
5
|
-
import {
|
|
6
|
-
import { dirname, join } from "node:path";
|
|
7
|
-
import { execFileSync, spawnSync } from "node:child_process";
|
|
8
|
-
import { homedir, tmpdir } from "node:os";
|
|
4
|
+
import { c as ciRenovateSyncCallers, d as RENOVATE_PRESET, i as CI_RENOVATE_SYNC_REF, n as CI_NODE_REF, r as CI_PATH, s as ciNodeCallers, t as CI_CONTEXT, u as RENOVATE_CONFIGS } from "../ci-workflow-CXcAZj6g.mjs";
|
|
5
|
+
import { i as ghToken, n as createApi, t as ApiError } from "../api-CCOiLN3w.mjs";
|
|
9
6
|
import { parseArgs } from "node:util";
|
|
10
7
|
import { inflateRawSync } from "node:zlib";
|
|
11
|
-
//#region src/garden/api.ts
|
|
12
|
-
/** A GitHub or npm answer that is not a success. */
|
|
13
|
-
var ApiError = class extends Error {
|
|
14
|
-
status;
|
|
15
|
-
constructor(status, message) {
|
|
16
|
-
super(message);
|
|
17
|
-
this.status = status;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
const GITHUB = "https://api.github.com";
|
|
21
|
-
const NPM = "https://registry.npmjs.org";
|
|
22
|
-
const CREDENTIAL_NAME = /TOKEN|SECRET|PASSW|CREDENTIAL|API_?KEY|PRIVATE_?KEY|ACCESS_?KEY/i;
|
|
23
|
-
const MINTED_TOKENS = /* @__PURE__ */ new Set(["GH_TOKEN", "GITHUB_TOKEN"]);
|
|
24
|
-
const CREDENTIAL_FILES = [
|
|
25
|
-
".aws/credentials",
|
|
26
|
-
".netrc",
|
|
27
|
-
".pypirc",
|
|
28
|
-
".config/gcloud/application_default_credentials.json",
|
|
29
|
-
".kube/config",
|
|
30
|
-
".ssh/id_rsa",
|
|
31
|
-
".ssh/id_ed25519",
|
|
32
|
-
".ssh/id_ecdsa"
|
|
33
|
-
];
|
|
34
|
-
const MAX_ATTEMPTS = 4;
|
|
35
|
-
function ghToken() {
|
|
36
|
-
return execFileSync("gh", ["auth", "token"], { encoding: "utf8" }).trim();
|
|
37
|
-
}
|
|
38
|
-
function pause(milliseconds) {
|
|
39
|
-
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
40
|
-
}
|
|
41
|
-
function nextLink(header) {
|
|
42
|
-
return header?.match(/<([^>]+)>;\s*rel="next"/)?.[1];
|
|
43
|
-
}
|
|
44
|
-
function withPaging(path) {
|
|
45
|
-
return path.includes("per_page=") ? path : `${path}${path.includes("?") ? "&" : "?"}per_page=100`;
|
|
46
|
-
}
|
|
47
|
-
function npmrcCarriesToken(home) {
|
|
48
|
-
const path = join(home, ".npmrc");
|
|
49
|
-
return existsSync(path) && /_auth(?:Token)?\s*=/.test(readFileSync(path, "utf8"));
|
|
50
|
-
}
|
|
51
|
-
/** Reads variable names only, never values. */
|
|
52
|
-
function readSecretSurface(names, home) {
|
|
53
|
-
const files = CREDENTIAL_FILES.filter((file) => existsSync(join(home, file)));
|
|
54
|
-
if (npmrcCarriesToken(home)) files.push(".npmrc");
|
|
55
|
-
return {
|
|
56
|
-
variables: names.filter((name) => CREDENTIAL_NAME.test(name) && !MINTED_TOKENS.has(name)).sort(),
|
|
57
|
-
files: files.sort()
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
/** Runs the released `antelopejs-registry --check` against committed manifests copied to a temporary directory. */
|
|
61
|
-
function registryCheck(files) {
|
|
62
|
-
const directory = mkdtempSync(join(tmpdir(), "garden-registry-"));
|
|
63
|
-
try {
|
|
64
|
-
for (const file of files) {
|
|
65
|
-
mkdirSync(dirname(join(directory, file.path)), { recursive: true });
|
|
66
|
-
writeFileSync(join(directory, file.path), file.content);
|
|
67
|
-
}
|
|
68
|
-
const result = spawnSync("npx", [
|
|
69
|
-
"--yes",
|
|
70
|
-
"--package",
|
|
71
|
-
"@antelopejs/tooling-configs@latest",
|
|
72
|
-
"antelopejs-registry",
|
|
73
|
-
"--check",
|
|
74
|
-
directory
|
|
75
|
-
], { encoding: "utf8" });
|
|
76
|
-
if (result.error) throw result.error;
|
|
77
|
-
return result.status !== 0;
|
|
78
|
-
} finally {
|
|
79
|
-
rmSync(directory, {
|
|
80
|
-
recursive: true,
|
|
81
|
-
force: true
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/** Authenticates with the token `gh` is logged in with and with no other credential. */
|
|
86
|
-
function createApi(token) {
|
|
87
|
-
const headers = {
|
|
88
|
-
Authorization: `Bearer ${token}`,
|
|
89
|
-
Accept: "application/vnd.github+json",
|
|
90
|
-
"X-GitHub-Api-Version": "2022-11-28",
|
|
91
|
-
"User-Agent": "antelopejs-garden"
|
|
92
|
-
};
|
|
93
|
-
async function request(url, init) {
|
|
94
|
-
for (let attempt = 1;; attempt++) {
|
|
95
|
-
const response = await fetch(url, {
|
|
96
|
-
...init,
|
|
97
|
-
headers: {
|
|
98
|
-
...headers,
|
|
99
|
-
...init.headers
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
const retryAfter = Number(response.headers.get("retry-after") ?? 0);
|
|
103
|
-
if (!(response.status === 429 || response.status === 403 && retryAfter > 0 || response.status >= 502) || attempt === MAX_ATTEMPTS) return response;
|
|
104
|
-
await pause(Math.max(retryAfter, attempt) * 1e3);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
async function get(path, accept) {
|
|
108
|
-
const response = await request(path.startsWith("http") ? path : `${GITHUB}${path}`, { headers: accept ? { Accept: accept } : {} });
|
|
109
|
-
if (!response.ok) throw new ApiError(response.status, `GET ${path}: HTTP ${response.status} ${(await response.text()).slice(0, 200)}`);
|
|
110
|
-
return response;
|
|
111
|
-
}
|
|
112
|
-
return {
|
|
113
|
-
async json(path) {
|
|
114
|
-
return parseJson(await (await get(path)).text());
|
|
115
|
-
},
|
|
116
|
-
async pages(path, key) {
|
|
117
|
-
const items = [];
|
|
118
|
-
for (let url = `${GITHUB}${withPaging(path)}`; url;) {
|
|
119
|
-
const response = await get(url);
|
|
120
|
-
const body = parseJson(await response.text());
|
|
121
|
-
const page = key === void 0 || !isObject(body) ? body : body[key];
|
|
122
|
-
if (Array.isArray(page)) items.push(...page);
|
|
123
|
-
url = nextLink(response.headers.get("link"));
|
|
124
|
-
}
|
|
125
|
-
return items;
|
|
126
|
-
},
|
|
127
|
-
async text(path) {
|
|
128
|
-
return (await get(path, "application/vnd.github.raw+json")).text();
|
|
129
|
-
},
|
|
130
|
-
async bytes(path) {
|
|
131
|
-
return new Uint8Array(await (await get(path)).arrayBuffer());
|
|
132
|
-
},
|
|
133
|
-
async send(method, path, body) {
|
|
134
|
-
const response = await request(`${GITHUB}${path}`, body === void 0 ? { method } : {
|
|
135
|
-
method,
|
|
136
|
-
body: JSON.stringify(body),
|
|
137
|
-
headers: { "Content-Type": "application/json" }
|
|
138
|
-
});
|
|
139
|
-
if (!response.ok) throw new ApiError(response.status, `${method} ${path}: HTTP ${response.status}`);
|
|
140
|
-
},
|
|
141
|
-
async npm(name) {
|
|
142
|
-
const response = await fetch(`${NPM}/${name.replace("/", "%2F")}`);
|
|
143
|
-
if (response.status === 404) return void 0;
|
|
144
|
-
if (!response.ok) throw new ApiError(response.status, `npm ${name}: HTTP ${response.status}`);
|
|
145
|
-
return parseJson(await response.text());
|
|
146
|
-
},
|
|
147
|
-
async contentLength(url) {
|
|
148
|
-
const response = await fetch(url, { method: "HEAD" });
|
|
149
|
-
const length = response.headers.get("content-length");
|
|
150
|
-
return response.ok && length !== null && isString(length) ? Number(length) : void 0;
|
|
151
|
-
},
|
|
152
|
-
async registryDiffers(files) {
|
|
153
|
-
return registryCheck(files);
|
|
154
|
-
},
|
|
155
|
-
secrets() {
|
|
156
|
-
return readSecretSurface(Object.keys(process.env), homedir());
|
|
157
|
-
},
|
|
158
|
-
now() {
|
|
159
|
-
return /* @__PURE__ */ new Date();
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
//#endregion
|
|
164
8
|
//#region src/garden/decode.ts
|
|
165
9
|
function orgRepo(value) {
|
|
166
10
|
const source = object(value, "repository");
|
|
@@ -865,15 +709,6 @@ async function tooling(context) {
|
|
|
865
709
|
//#region src/garden/checks/conformance.ts
|
|
866
710
|
const CHECK$1 = "conformance";
|
|
867
711
|
const DAY$2 = 864e5;
|
|
868
|
-
const RENOVATE_CONFIGS = [
|
|
869
|
-
"renovate.json",
|
|
870
|
-
"renovate.json5",
|
|
871
|
-
".github/renovate.json",
|
|
872
|
-
".github/renovate.json5",
|
|
873
|
-
".renovaterc",
|
|
874
|
-
".renovaterc.json"
|
|
875
|
-
];
|
|
876
|
-
const RENOVATE_PRESET = /github>AntelopeJS\/\.github(?::|\/)/;
|
|
877
712
|
const MEND_EXEMPT = /* @__PURE__ */ new Set(["k8s-gitops-infra"]);
|
|
878
713
|
function problem(repo, subject, evidence, doneMeans) {
|
|
879
714
|
return finding({
|
|
@@ -1253,7 +1088,7 @@ const packageSize = {
|
|
|
1253
1088
|
//#endregion
|
|
1254
1089
|
//#region src/garden/semver.ts
|
|
1255
1090
|
const VERSION = /^v?(\d+)\.(\d+)\.(\d+)/;
|
|
1256
|
-
function parse
|
|
1091
|
+
function parse(text) {
|
|
1257
1092
|
const match = VERSION.exec(text.trim());
|
|
1258
1093
|
return match ? [
|
|
1259
1094
|
Number(match[1]),
|
|
@@ -1282,7 +1117,7 @@ function caret(floor) {
|
|
|
1282
1117
|
}
|
|
1283
1118
|
function comparator(term, version) {
|
|
1284
1119
|
const operator = /^(>=|<=|>|<|=|\^|~)?\s*(.*)$/.exec(term.trim());
|
|
1285
|
-
const bound = parse
|
|
1120
|
+
const bound = parse(operator?.[2] ?? "");
|
|
1286
1121
|
if (!operator || !bound) return true;
|
|
1287
1122
|
switch (operator[1]) {
|
|
1288
1123
|
case ">=": return compare$1(version, bound) >= 0;
|
|
@@ -1300,7 +1135,7 @@ function comparator(term, version) {
|
|
|
1300
1135
|
}
|
|
1301
1136
|
/** Whether a plain npm range (`^`, `~`, comparators, `||`, `*`) admits a release; wildcards and tags admit everything. */
|
|
1302
1137
|
function admits(range, release) {
|
|
1303
|
-
const version = parse
|
|
1138
|
+
const version = parse(release);
|
|
1304
1139
|
if (!version) return true;
|
|
1305
1140
|
return range.split("||").some((alternative) => {
|
|
1306
1141
|
return alternative.replace(/(>=|<=|>|<|=|\^|~)\s+/g, "$1").trim().split(/\s+/).every((term) => comparator(term, version));
|
package/dist/bin/lease.mjs
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { c as object, f as parseJson, i as isObject, l as optNum, p as str, s as num, t as child } from "../json-CG2L7YFl.mjs";
|
|
3
2
|
import { n as runCliAsync } from "../cli-4Tv71vYk.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { a as closeServer, c as LOCK_PORT, d as isRole, f as leaseHome, i as claimPort, l as PORT_ROLES, m as parseRecord, n as bindable, o as listenerPids, p as leaseId, r as chooseBlock, s as listensOn, t as accepting, u as isLeaseId } from "../ports-DGP6bPJy.mjs";
|
|
4
|
+
import { accessSync, closeSync, constants, mkdirSync, openSync, readFileSync, readSync, readdirSync, realpathSync, renameSync, rmSync, statSync, utimesSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { delimiter, join } from "node:path";
|
|
6
6
|
import { execFileSync, spawn } from "node:child_process";
|
|
7
|
-
import { createHash } from "node:crypto";
|
|
8
7
|
import { homedir } from "node:os";
|
|
9
8
|
import { parseArgs } from "node:util";
|
|
10
9
|
import { setTimeout } from "node:timers/promises";
|
|
11
|
-
import { connect, createServer } from "node:net";
|
|
12
10
|
//#region src/lease/env.ts
|
|
13
11
|
function isServerRole(value) {
|
|
14
12
|
return value === "api" || value === "web";
|
|
@@ -152,280 +150,6 @@ function launch(command, env) {
|
|
|
152
150
|
], env) : process.execve(verdict.file, [name, ...args], env);
|
|
153
151
|
}
|
|
154
152
|
//#endregion
|
|
155
|
-
//#region src/lease/protocol.ts
|
|
156
|
-
/**
|
|
157
|
-
* The port every antelopejs-lease version listens on, on 127.0.0.1, while it holds the registry lock.
|
|
158
|
-
* Each repository pins its own tooling-configs version, so this port, {@link leaseHome} and the v1
|
|
159
|
-
* record are a protocol between versions: they may be extended, never changed.
|
|
160
|
-
*/
|
|
161
|
-
const LOCK_PORT = 2e4;
|
|
162
|
-
const RECORD_VERSION = 1;
|
|
163
|
-
/** The offset of each role's port in its block of ten. Offsets 6 to 9 stay spare for later roles. */
|
|
164
|
-
const PORT_ROLES = {
|
|
165
|
-
api: 0,
|
|
166
|
-
web: 1,
|
|
167
|
-
mongo: 2,
|
|
168
|
-
smtp: 3,
|
|
169
|
-
inspect: 4,
|
|
170
|
-
hmr: 5
|
|
171
|
-
};
|
|
172
|
-
function isRole(value) {
|
|
173
|
-
return Object.hasOwn(PORT_ROLES, value);
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* `ANTELOPEJS_LEASE_HOME`, else `~/.antelopejs/leases`: one registry for every repository of the
|
|
177
|
-
* user. A relative `ANTELOPEJS_LEASE_HOME` throws, since each working directory would resolve it to
|
|
178
|
-
* another registry.
|
|
179
|
-
*/
|
|
180
|
-
function leaseHome(env) {
|
|
181
|
-
const home = env.ANTELOPEJS_LEASE_HOME;
|
|
182
|
-
if (!home) return join(homedir(), ".antelopejs", "leases");
|
|
183
|
-
if (!isAbsolute(home)) throw new Error(`antelopejs-lease: ANTELOPEJS_LEASE_HOME must be an absolute path, not ${home}`);
|
|
184
|
-
return home;
|
|
185
|
-
}
|
|
186
|
-
function isLeaseId(value) {
|
|
187
|
-
return /^[0-9a-f]{10}$/u.test(value);
|
|
188
|
-
}
|
|
189
|
-
/** The lease id of the worktree whose real path is `worktree`. */
|
|
190
|
-
function leaseId(worktree) {
|
|
191
|
-
const id = createHash("sha256").update(worktree).digest("hex").slice(0, 10);
|
|
192
|
-
if (!isLeaseId(id)) throw new Error(`unexpected digest ${id}`);
|
|
193
|
-
return id;
|
|
194
|
-
}
|
|
195
|
-
/** Builds a value for every role, so a new role is a compile error until each table names it. */
|
|
196
|
-
function eachRole(value) {
|
|
197
|
-
return {
|
|
198
|
-
api: value("api"),
|
|
199
|
-
web: value("web"),
|
|
200
|
-
mongo: value("mongo"),
|
|
201
|
-
smtp: value("smtp"),
|
|
202
|
-
inspect: value("inspect"),
|
|
203
|
-
hmr: value("hmr")
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
function isMongoMode(value) {
|
|
207
|
-
return value === "owned" || value === "external";
|
|
208
|
-
}
|
|
209
|
-
function decodeRecord(value) {
|
|
210
|
-
const source = object(value, "lease.json");
|
|
211
|
-
if (num(source, "version") !== RECORD_VERSION) return void 0;
|
|
212
|
-
const id = str(source, "id");
|
|
213
|
-
const mongo = str(source, "mongo");
|
|
214
|
-
if (!isLeaseId(id) || !isMongoMode(mongo)) return void 0;
|
|
215
|
-
const ports = child(source, "ports");
|
|
216
|
-
return {
|
|
217
|
-
version: RECORD_VERSION,
|
|
218
|
-
id,
|
|
219
|
-
worktree: str(source, "worktree"),
|
|
220
|
-
gitInode: num(source, "gitInode"),
|
|
221
|
-
gitBirth: num(source, "gitBirth"),
|
|
222
|
-
ports: eachRole((role) => num(ports, role)),
|
|
223
|
-
createdAt: str(source, "createdAt"),
|
|
224
|
-
mongo
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
function reservedPorts(value) {
|
|
228
|
-
if (!isObject(value) || !Object.hasOwn(value, "ports")) return [];
|
|
229
|
-
const ports = value.ports;
|
|
230
|
-
if (!isObject(ports)) return [];
|
|
231
|
-
return Object.keys(ports).map((key) => optNum(ports, key)).filter((port) => port !== void 0);
|
|
232
|
-
}
|
|
233
|
-
function tryJson(text) {
|
|
234
|
-
try {
|
|
235
|
-
return parseJson(text);
|
|
236
|
-
} catch {
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
function tryRecord(value) {
|
|
241
|
-
try {
|
|
242
|
-
return decodeRecord(value);
|
|
243
|
-
} catch {
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
/** Reads a `lease.json` leniently: unknown fields are ignored, anything unreadable is `foreign`. */
|
|
248
|
-
function parseRecord(text) {
|
|
249
|
-
const value = tryJson(text);
|
|
250
|
-
if (value === void 0) return {
|
|
251
|
-
kind: "foreign",
|
|
252
|
-
reserved: []
|
|
253
|
-
};
|
|
254
|
-
const record = tryRecord(value);
|
|
255
|
-
if (record !== void 0) return {
|
|
256
|
-
kind: "current",
|
|
257
|
-
record
|
|
258
|
-
};
|
|
259
|
-
return {
|
|
260
|
-
kind: "foreign",
|
|
261
|
-
reserved: reservedPorts(value)
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
//#endregion
|
|
265
|
-
//#region src/lease/ports.ts
|
|
266
|
-
const BAND_START = 20010;
|
|
267
|
-
const BLOCK_SIZE = 10;
|
|
268
|
-
const BLOCK_COUNT = 9990 / BLOCK_SIZE;
|
|
269
|
-
const DENIED_PORTS = [
|
|
270
|
-
24678,
|
|
271
|
-
27017,
|
|
272
|
-
27018,
|
|
273
|
-
27019
|
|
274
|
-
];
|
|
275
|
-
const CONNECT_TIMEOUT_MS = 1e3;
|
|
276
|
-
const LISTEN_STATE = "0A";
|
|
277
|
-
/**
|
|
278
|
-
* The block bases a lease tries, in order: from a block picked by a hash of the id and `uid`
|
|
279
|
-
* together, forward and around the band. Each user keeps a registry of its own, so mixing in the
|
|
280
|
-
* uid usually starts two users' worktrees at one path on different blocks. The band [20010, 30000)
|
|
281
|
-
* sits below the kernel's ephemeral range (32768 and up on Linux, 49152 and up on macOS), so no
|
|
282
|
-
* `bind(:0)` caller races for these ports. Blocks holding the Vite HMR default (24678) or a system
|
|
283
|
-
* mongod (27017 to 27019) are skipped.
|
|
284
|
-
*/
|
|
285
|
-
function candidateBases(id, uid = process.getuid?.() ?? 0) {
|
|
286
|
-
const first = createHash("sha256").update(`${uid}:${id}`).digest().readUInt32BE(0) % BLOCK_COUNT;
|
|
287
|
-
return Array.from({ length: BLOCK_COUNT }, (_, step) => BAND_START + (first + step) % BLOCK_COUNT * BLOCK_SIZE).filter((base) => !DENIED_PORTS.some((port) => port >= base && port < base + BLOCK_SIZE));
|
|
288
|
-
}
|
|
289
|
-
function blockPorts(base) {
|
|
290
|
-
return Array.from({ length: BLOCK_SIZE }, (_, offset) => base + offset);
|
|
291
|
-
}
|
|
292
|
-
async function everyBindable(ports, bindable) {
|
|
293
|
-
for (const port of ports) if (!await bindable(port)) return false;
|
|
294
|
-
return true;
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* The first candidate block none of whose ten ports is in `taken` and all of whose ports bind.
|
|
298
|
-
* Throws when the band has no such block.
|
|
299
|
-
*/
|
|
300
|
-
async function chooseBlock(id, taken, bindable) {
|
|
301
|
-
for (const base of candidateBases(id)) {
|
|
302
|
-
const ports = blockPorts(base);
|
|
303
|
-
if (ports.some((port) => taken.has(port))) continue;
|
|
304
|
-
if (await everyBindable(ports, bindable)) return eachRole((role) => base + PORT_ROLES[role]);
|
|
305
|
-
}
|
|
306
|
-
throw new Error(`antelopejs-lease: no free port block in ${BAND_START}-29999; run antelopejs-lease gc, then retry`);
|
|
307
|
-
}
|
|
308
|
-
/** Listens on `host:port`, Node's dual-stack default without `host`. `undefined` when the address is in use. */
|
|
309
|
-
function claimPort(port, host) {
|
|
310
|
-
return new Promise((resolve, reject) => {
|
|
311
|
-
const server = createServer();
|
|
312
|
-
server.once("error", (error) => {
|
|
313
|
-
if (error.code === "EADDRINUSE") resolve(void 0);
|
|
314
|
-
else reject(error);
|
|
315
|
-
});
|
|
316
|
-
server.listen({
|
|
317
|
-
port,
|
|
318
|
-
host
|
|
319
|
-
}, () => resolve(server));
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
function closeServer(server) {
|
|
323
|
-
return new Promise((resolve) => server.close(() => resolve()));
|
|
324
|
-
}
|
|
325
|
-
async function bindsOn(port, host) {
|
|
326
|
-
try {
|
|
327
|
-
const server = await claimPort(port, host);
|
|
328
|
-
if (server === void 0) return false;
|
|
329
|
-
await closeServer(server);
|
|
330
|
-
return true;
|
|
331
|
-
} catch {
|
|
332
|
-
return false;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* True when nothing holds `port`. The dual-stack wildcard bind fails on Linux for a listener on any
|
|
337
|
-
* local address; the 127.0.0.1 bind covers systems that let a wildcard sit beside a specific address.
|
|
338
|
-
*/
|
|
339
|
-
async function bindable(port) {
|
|
340
|
-
return await bindsOn(port, "127.0.0.1") && bindsOn(port);
|
|
341
|
-
}
|
|
342
|
-
function acceptsOn(port, host) {
|
|
343
|
-
return new Promise((resolve) => {
|
|
344
|
-
const socket = connect({
|
|
345
|
-
port,
|
|
346
|
-
host,
|
|
347
|
-
timeout: CONNECT_TIMEOUT_MS
|
|
348
|
-
});
|
|
349
|
-
const settle = (answer) => {
|
|
350
|
-
socket.destroy();
|
|
351
|
-
resolve(answer);
|
|
352
|
-
};
|
|
353
|
-
socket.once("connect", () => settle(true));
|
|
354
|
-
socket.once("timeout", () => settle(false));
|
|
355
|
-
socket.once("error", () => settle(false));
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
/** True when a server accepts connections on `port` on the IPv4 or the IPv6 loopback. */
|
|
359
|
-
async function accepting(port) {
|
|
360
|
-
return await acceptsOn(port, "127.0.0.1") || acceptsOn(port, "::1");
|
|
361
|
-
}
|
|
362
|
-
function listenInodes(table, port) {
|
|
363
|
-
let text;
|
|
364
|
-
try {
|
|
365
|
-
text = readFileSync(table, "utf8");
|
|
366
|
-
} catch {
|
|
367
|
-
return [];
|
|
368
|
-
}
|
|
369
|
-
return text.split("\n").slice(1).map((line) => line.trim().split(/\s+/u)).filter((columns) => columns[3] === LISTEN_STATE && Number.parseInt(columns[1]?.split(":")[1] ?? "", 16) === port).map((columns) => `socket:[${columns[9]}]`);
|
|
370
|
-
}
|
|
371
|
-
function holdsSocket(pid, sockets) {
|
|
372
|
-
let fds;
|
|
373
|
-
try {
|
|
374
|
-
fds = readdirSync(`/proc/${pid}/fd`);
|
|
375
|
-
} catch {
|
|
376
|
-
return false;
|
|
377
|
-
}
|
|
378
|
-
return fds.some((fd) => {
|
|
379
|
-
try {
|
|
380
|
-
return sockets.has(readlinkSync(`/proc/${pid}/fd/${fd}`));
|
|
381
|
-
} catch {
|
|
382
|
-
return false;
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
function listenSockets(port) {
|
|
387
|
-
return /* @__PURE__ */ new Set([...listenInodes("/proc/net/tcp", port), ...listenInodes("/proc/net/tcp6", port)]);
|
|
388
|
-
}
|
|
389
|
-
function linuxListenerPids(port) {
|
|
390
|
-
const sockets = listenSockets(port);
|
|
391
|
-
if (sockets.size === 0) return [];
|
|
392
|
-
return readdirSync("/proc").filter((name) => /^\d+$/u.test(name) && holdsSocket(name, sockets)).map(Number);
|
|
393
|
-
}
|
|
394
|
-
function lsofListenerPids(port) {
|
|
395
|
-
try {
|
|
396
|
-
return execFileSync("lsof", [
|
|
397
|
-
"-nP",
|
|
398
|
-
"-t",
|
|
399
|
-
`-iTCP:${port}`,
|
|
400
|
-
"-sTCP:LISTEN"
|
|
401
|
-
], {
|
|
402
|
-
encoding: "utf8",
|
|
403
|
-
stdio: [
|
|
404
|
-
"ignore",
|
|
405
|
-
"pipe",
|
|
406
|
-
"ignore"
|
|
407
|
-
]
|
|
408
|
-
}).split("\n").filter((line) => /^\d+$/u.test(line)).map(Number);
|
|
409
|
-
} catch {
|
|
410
|
-
return [];
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
/** The pids listening on `port` that this user may inspect; empty when none can be read. */
|
|
414
|
-
function listenerPids(port) {
|
|
415
|
-
if (process.platform === "linux") return linuxListenerPids(port);
|
|
416
|
-
if (process.platform === "darwin") return lsofListenerPids(port);
|
|
417
|
-
return [];
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* True when process `pid` listens on `port`. Where the platform gives no way to tell, true when
|
|
421
|
-
* anything accepts on `port`.
|
|
422
|
-
*/
|
|
423
|
-
async function listensOn(pid, port) {
|
|
424
|
-
if (process.platform === "linux") return holdsSocket(String(pid), listenSockets(port));
|
|
425
|
-
if (process.platform === "darwin") return lsofListenerPids(port).includes(pid);
|
|
426
|
-
return accepting(port);
|
|
427
|
-
}
|
|
428
|
-
//#endregion
|
|
429
153
|
//#region src/lease/mongo.ts
|
|
430
154
|
const READY_TIMEOUT_MS = 3e4;
|
|
431
155
|
const KILL_WAIT_MS = 2e3;
|
package/dist/bin/sync.mjs
CHANGED
|
@@ -6,8 +6,8 @@ import { a as VERIFY_KINDS, c as isVerifyKind, i as SYNCED_SKILL_FILES, l as ski
|
|
|
6
6
|
import { t as runCli } from "../cli-4Tv71vYk.mjs";
|
|
7
7
|
import { c as repositoryRoot } from "../files-DJ0TeaTU.mjs";
|
|
8
8
|
import { i as recordedRelease, t as measureBaseline } from "../ratchet-BAcLRYuM.mjs";
|
|
9
|
+
import { a as ciWorkflow, c as ciRenovateSyncCallers, f as renovateArtifacts, l as hasChecksWorkflow, o as MISSING_CHECKS_WORKFLOW, r as CI_PATH, s as ciNodeCallers } from "../ci-workflow-CXcAZj6g.mjs";
|
|
9
10
|
import { n as SUPPRESSIONS_FILE, r as adoptedBudget } from "../suppression-budget-C0SkPO5R.mjs";
|
|
10
|
-
import { a as ciWorkflow, c as ciRenovateSyncCallers, l as hasChecksWorkflow, o as MISSING_CHECKS_WORKFLOW, r as CI_PATH, s as ciNodeCallers } from "../ci-workflow-mc0vywUV.mjs";
|
|
11
11
|
import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, readlinkSync, rmdirSync, statSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs";
|
|
12
12
|
import { dirname, join, resolve } from "node:path";
|
|
13
13
|
import { execFileSync } from "node:child_process";
|
|
@@ -749,7 +749,7 @@ const KIND_TEXT = {
|
|
|
749
749
|
template: {
|
|
750
750
|
description: "Drive this AntelopeJS template the way a new user does: scaffold a project with `ajs project init` from an offline interfaces manifest, install it, run its own `pnpm run checks`, run `ajs project dev --watch` and hit its welcome page, endpoint or ready line. Use to prove a change to the template works before merge, to verify a PR, or to run the release canary.",
|
|
751
751
|
title: "Verify template",
|
|
752
|
-
user: "The user of a template is someone running `ajs project init --template`: they get a copy of the
|
|
752
|
+
user: "The user of a template is someone running `ajs project init --template`: they get a copy of the repository without `.agents/` and `.claude/skills/` and expect it to install, pass its checks and run.",
|
|
753
753
|
launch: "`new` copies the working tree, uncommitted changes included, into a local git repository, and lists it in an offline interfaces manifest (`templates`, or `projectTemplates` when `template.project` is set) under `template.name`. Journeys point `ajs config set git` at it, so no step reaches GitHub. Every `services` entry of `verify.config.ts` then starts in its own Docker container on a free loopback port, as for a module.",
|
|
754
754
|
builtins: `- \`scaffold-dev\`: \`ajs project init <app> --template <name> --pm pnpm --git-init\`, \`pnpm install --frozen-lockfile\`, then \`ajs project dev --watch\` with \`PORT\` set until \`template.probe\` answers: a path and status on that port, or a \`log\` line followed by \`settleMs\` of still running. Ctrl+C must exit 130.
|
|
755
755
|
- \`scaffold-checks\`: the same scaffold and install, then the project's own \`pnpm run checks\`.`,
|
|
@@ -758,7 +758,7 @@ const KIND_TEXT = {
|
|
|
758
758
|
- \`services\`: image, port, readiness command and \`reset\`, as for a module. \`new\` starts them in Docker on free ports; a journey reads them with \`context.service(name)\` and \`context.native(...)\` and passes their endpoints to the project it starts through the \`env\` of \`context.dev\`.
|
|
759
759
|
- \`template.probe\`: \`path\`, \`status\` and \`body\` for an HTTP welcome page or endpoint, or \`log\` and \`settleMs\` for a template that serves nothing.`,
|
|
760
760
|
smoke: "`scaffold-dev` and `scaffold-checks`",
|
|
761
|
-
gotchas: ["`ajs
|
|
761
|
+
gotchas: ["`ajs project init` leaves out `.agents/` and `.claude/skills/`, so the scaffolded project carries neither this skill nor anything else under `.agents/`. Never expect either folder there.", "Every file a user gets is user-facing here, tests included; only `.github/` and `.claude/` outside `.claude/skills/` are not."]
|
|
762
762
|
}
|
|
763
763
|
};
|
|
764
764
|
//#endregion
|
|
@@ -819,7 +819,7 @@ Each step writes \`<run>/evidence/<feature>/<journey>/<NN-step>/\` with \`comman
|
|
|
819
819
|
${BIN} clean <run>
|
|
820
820
|
\`\`\`
|
|
821
821
|
|
|
822
|
-
\`clean\` stops what the run started, by recorded PID and container name, and removes everything but \`evidence/\` and \`run.json\`. Run it after every run, failed ones included.
|
|
822
|
+
Each journey deletes its scratch folder and \`HOME\`, its install included, when it ends: passed, failed or interrupted. Only its evidence stays. \`clean\` stops what the run started, by recorded PID and container name, and removes everything but \`evidence/\` and \`run.json\`. Run it after every run, failed ones included.
|
|
823
823
|
|
|
824
824
|
## The repository's own layer
|
|
825
825
|
|
|
@@ -884,7 +884,7 @@ The skill is not Trusted yet. It becomes Trusted when it passes a shadow run of
|
|
|
884
884
|
## Gotchas
|
|
885
885
|
|
|
886
886
|
${bullets(text.gotchas)}
|
|
887
|
-
- Runs live under the system temp folder (\`TMPDIR\`), and the shared caches under \`~/.cache/antelopejs-verify\`.
|
|
887
|
+
- Runs live under the system temp folder (\`TMPDIR\`), and the shared caches under \`~/.cache/antelopejs-verify\`. \`new\` deletes every run no command touched for 7 days, unless a process it recorded is still alive.
|
|
888
888
|
- A repository that outgrows this skill runs \`antelopejs-sync --verify custom\` and keeps its own \`.agents/skills/verify-<repo>/\`.
|
|
889
889
|
`;
|
|
890
890
|
}
|
|
@@ -1321,8 +1321,8 @@ function syncRepository(root, options = {}) {
|
|
|
1321
1321
|
const writing = planWritingSkills(root, profile, verify.kind);
|
|
1322
1322
|
const actions = [...verify.actions, ...writing.actions];
|
|
1323
1323
|
const context = repositoryContext(root, current, profile, verify.verificationSkill);
|
|
1324
|
-
const
|
|
1325
|
-
let plan = [...planSync(current, modes, context), ...
|
|
1324
|
+
const standalone = [...backendBoundaryArtifacts(root), ...renovateArtifacts(root, manifest, profile === "full" || verify.kind === "template")];
|
|
1325
|
+
let plan = [...planSync(current, modes, context), ...standalone];
|
|
1326
1326
|
const errors = plan.filter((artifact) => artifact.kind === "error").map(({ message }) => message);
|
|
1327
1327
|
const entryOnly = checkEntryOnlyConfiguration(root);
|
|
1328
1328
|
errors.push(...entryOnly.errors, ...verify.errors, ...writing.errors);
|
|
@@ -1337,7 +1337,7 @@ function syncRepository(root, options = {}) {
|
|
|
1337
1337
|
...baseline,
|
|
1338
1338
|
pack: recordedRelease(void 0)
|
|
1339
1339
|
});
|
|
1340
|
-
plan = [...planSync(current, modes, context), ...
|
|
1340
|
+
plan = [...planSync(current, modes, context), ...standalone];
|
|
1341
1341
|
}
|
|
1342
1342
|
const writes = plan.filter((artifact) => artifact.kind === "write" || artifact.kind === "migrated");
|
|
1343
1343
|
if (!options.check && !errors.length) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|