@attalabs/vinaya 0.31.0 → 0.32.0
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 -2
- package/aeg-root/roles/developer/reference.md +3 -3
- package/aeg-root/templates/pr-report-template.md +7 -2
- package/dist/checks/bin/check-body-bare-digits.js +229 -86
- package/dist/checks/bin/check-branch-topology.js +101 -89
- package/dist/checks/bin/check-brief-shape.js +222 -79
- package/dist/checks/bin/check-changeset-coverage.js +739 -232
- package/dist/checks/bin/check-ci-shard-coverage.js +82 -0
- package/dist/checks/bin/check-closes-n.js +101 -89
- package/dist/checks/bin/check-coherence.js +233 -129
- package/dist/checks/bin/check-dead-branch-push.js +97 -44
- package/dist/checks/bin/check-dispatch-readiness.js +238 -134
- package/dist/checks/bin/check-doc-coverage-push.js +722 -215
- package/dist/checks/bin/check-doc-coverage.js +726 -219
- package/dist/checks/bin/check-doctrine-no-procedures.js +222 -79
- package/dist/checks/bin/check-doctrine-portability.js +724 -217
- package/dist/checks/bin/check-evidence-fresh.js +720 -206
- package/dist/checks/bin/check-exec-bits.js +720 -213
- package/dist/checks/bin/check-first-push-dispatch.js +231 -129
- package/dist/checks/bin/check-issue-assignment.js +103 -91
- package/dist/checks/bin/check-issue-milestone-attach.js +94 -41
- package/dist/checks/bin/check-issue-objectives-numbering.js +94 -41
- package/dist/checks/bin/check-issue-parts-coverage.js +94 -41
- package/dist/checks/bin/check-issue-surface-globs.js +251 -127
- package/dist/checks/bin/check-issue-title-grammar.js +94 -41
- package/dist/checks/bin/check-issue-tranche-label.js +94 -41
- package/dist/checks/bin/check-main-branch-refusal.js +94 -41
- package/dist/checks/bin/check-no-disk-state.js +94 -41
- package/dist/checks/bin/check-pr-premise-reassert.js +222 -77
- package/dist/checks/bin/check-pr-report-density.js +94 -41
- package/dist/checks/bin/check-principal-test-plan-wait.js +94 -39
- package/dist/checks/bin/check-quoted-command.js +710 -201
- package/dist/checks/bin/check-reader-resolvable-prose.js +722 -213
- package/dist/checks/bin/check-registry-gates.js +104 -41
- package/dist/checks/bin/check-retired-vocabulary.js +708 -199
- package/dist/checks/bin/check-review-gate.js +224 -79
- package/dist/checks/bin/check-single-plan-pr.js +94 -41
- package/dist/checks/bin/check-surface-scope.js +101 -89
- package/dist/checks/bin/check-test-plan.js +94 -39
- package/dist/checks/bin/check-token-collection-wired.js +100 -42
- package/dist/checks/bin/check-token-report.js +96 -43
- package/dist/checks/bin/check-workspace-escape.js +722 -213
- package/dist/index.js +3725 -3148
- package/dist/lib/pre-push-cache-test-run.js +4175 -0
- package/dist/lib/pre-push-select-tests.js +709 -101
- package/package.json +3 -2
|
@@ -121,9 +121,11 @@ function parseHunkRanges(patch) {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
// src/lib/config.ts
|
|
124
|
-
import {
|
|
124
|
+
import { execFile as execFile4, execFileSync as execFileSync2 } from "node:child_process";
|
|
125
|
+
import { promisify as promisify4 } from "node:util";
|
|
126
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync3, realpathSync, writeFileSync } from "node:fs";
|
|
125
127
|
import { homedir } from "node:os";
|
|
126
|
-
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
128
|
+
import { dirname as dirname2, isAbsolute, join as join2, resolve as resolve2 } from "node:path";
|
|
127
129
|
import { z as z4 } from "zod";
|
|
128
130
|
// ../../packages/aeg-forge-state/src/gh.ts
|
|
129
131
|
import { execFile, execFileSync } from "node:child_process";
|
|
@@ -352,6 +354,52 @@ var systemEnv3 = {
|
|
|
352
354
|
...process.env,
|
|
353
355
|
PATH: [process.env.PATH, "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin"].filter(Boolean).join(":")
|
|
354
356
|
};
|
|
357
|
+
var defaultExec = () => execFileAsync3("git", ["remote", "get-url", "origin"], { env: systemEnv3, timeout: 5000 });
|
|
358
|
+
var cached;
|
|
359
|
+
var inflight;
|
|
360
|
+
async function resolveRepo(exec = defaultExec) {
|
|
361
|
+
if (cached !== undefined)
|
|
362
|
+
return cached;
|
|
363
|
+
const fromEnv = process.env.AEG_REPO;
|
|
364
|
+
if (fromEnv) {
|
|
365
|
+
const parsed = parseOwnerRepo(fromEnv);
|
|
366
|
+
if (parsed) {
|
|
367
|
+
cached = parsed;
|
|
368
|
+
return cached;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
if (inflight)
|
|
372
|
+
return inflight;
|
|
373
|
+
inflight = (async () => {
|
|
374
|
+
try {
|
|
375
|
+
const { stdout } = await exec();
|
|
376
|
+
cached = parseGitRemoteUrl(stdout.trim());
|
|
377
|
+
return cached;
|
|
378
|
+
} catch (err) {
|
|
379
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
380
|
+
console.warn(`[aeg-forge-state] resolveRepo: git remote lookup failed (will retry): ${message}`);
|
|
381
|
+
return null;
|
|
382
|
+
} finally {
|
|
383
|
+
inflight = undefined;
|
|
384
|
+
}
|
|
385
|
+
})();
|
|
386
|
+
return inflight;
|
|
387
|
+
}
|
|
388
|
+
function parseGitRemoteUrl(url) {
|
|
389
|
+
const ssh = url.match(/^git@github\.com:([^/]+)\/(.+?)(?:\.git)?$/);
|
|
390
|
+
if (ssh?.[1] && ssh[2])
|
|
391
|
+
return { owner: ssh[1], repo: ssh[2] };
|
|
392
|
+
const https = url.match(/^https?:\/\/(?:[^@]+@)?github\.com\/([^/]+)\/(.+?)(?:\.git)?\/?$/);
|
|
393
|
+
if (https?.[1] && https[2])
|
|
394
|
+
return { owner: https[1], repo: https[2] };
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
function parseOwnerRepo(value) {
|
|
398
|
+
const match = value.match(/^([^/]+)\/(.+)$/);
|
|
399
|
+
if (!match?.[1] || !match[2])
|
|
400
|
+
return null;
|
|
401
|
+
return { owner: match[1], repo: match[2] };
|
|
402
|
+
}
|
|
355
403
|
// ../../packages/aeg-core/src/state-machine-model.ts
|
|
356
404
|
var FORGE_FACT_INPUTS = [
|
|
357
405
|
{
|
|
@@ -681,6 +729,13 @@ var TASK_TOOL_NAMES = [
|
|
|
681
729
|
];
|
|
682
730
|
var OPERATOR_STATUS_FOLLOW = "task_status_follow";
|
|
683
731
|
var OPERATOR_TOOL_GRANT = [...TASK_TOOL_NAMES, OPERATOR_STATUS_FOLLOW];
|
|
732
|
+
// ../../packages/aeg-core/src/dev-review-loop/types.ts
|
|
733
|
+
var SEVERITY_COLUMNS = ["blocker", "major", "minor", "critical", "high", "medium", "low"];
|
|
734
|
+
// ../../packages/aeg-core/src/dev-review-loop/journal-reconstruction.ts
|
|
735
|
+
var SUMMARY_TABLE_HEADER = `| round | ${SEVERITY_COLUMNS.join(" | ")} | confidence | outcome |`;
|
|
736
|
+
// ../../packages/aeg-core/src/log/envelope.ts
|
|
737
|
+
import { createHash } from "node:crypto";
|
|
738
|
+
|
|
684
739
|
// ../../packages/aeg-core/src/log/schema.ts
|
|
685
740
|
import { z as z2 } from "zod";
|
|
686
741
|
var CONFIDENCE_REASON_MAX_LENGTH = 280;
|
|
@@ -1103,10 +1158,197 @@ var LogEventSchema = z2.union([
|
|
|
1103
1158
|
HandoffEventSchema,
|
|
1104
1159
|
EffectEventSchema
|
|
1105
1160
|
]);
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1161
|
+
|
|
1162
|
+
// ../../packages/aeg-core/src/log/envelope.ts
|
|
1163
|
+
function isRole(value) {
|
|
1164
|
+
return value !== undefined && ROLE_VALUES.includes(value);
|
|
1165
|
+
}
|
|
1166
|
+
function actorIdFromEnv(role) {
|
|
1167
|
+
return role === undefined || role === "" ? null : role;
|
|
1168
|
+
}
|
|
1169
|
+
function lineageFieldFromEnv(value) {
|
|
1170
|
+
return value === undefined || value === "" ? null : value;
|
|
1171
|
+
}
|
|
1172
|
+
function attemptFromEnv(value) {
|
|
1173
|
+
if (value === undefined || value === "")
|
|
1174
|
+
return null;
|
|
1175
|
+
const n = Number(value);
|
|
1176
|
+
return Number.isInteger(n) ? n : null;
|
|
1177
|
+
}
|
|
1178
|
+
function provenanceFor(input) {
|
|
1179
|
+
if (input.provenance)
|
|
1180
|
+
return input.provenance;
|
|
1181
|
+
if (input.env.role || input.env.task)
|
|
1182
|
+
return "env_correlated";
|
|
1183
|
+
return "unavailable";
|
|
1184
|
+
}
|
|
1185
|
+
function issueFromTask(task) {
|
|
1186
|
+
if (task === undefined || task === "")
|
|
1187
|
+
return null;
|
|
1188
|
+
const n = Number(task);
|
|
1189
|
+
return Number.isInteger(n) ? n : null;
|
|
1190
|
+
}
|
|
1191
|
+
function roundFromEnv(round) {
|
|
1192
|
+
if (round === undefined || round === "")
|
|
1193
|
+
return;
|
|
1194
|
+
const n = Number(round);
|
|
1195
|
+
return Number.isInteger(n) ? n : undefined;
|
|
1196
|
+
}
|
|
1197
|
+
function buildHeader(input) {
|
|
1198
|
+
const role = isRole(input.env.role) ? input.env.role : "unattributed";
|
|
1199
|
+
const round = roundFromEnv(input.env.round);
|
|
1200
|
+
const subject = {
|
|
1201
|
+
issue: issueFromTask(input.env.task),
|
|
1202
|
+
role,
|
|
1203
|
+
...round !== undefined ? { round } : {},
|
|
1204
|
+
...input.subject ?? {}
|
|
1205
|
+
};
|
|
1206
|
+
return {
|
|
1207
|
+
meta: {
|
|
1208
|
+
schema: 2,
|
|
1209
|
+
ts: input.now.toISOString(),
|
|
1210
|
+
run_id: input.runId,
|
|
1211
|
+
seq: input.seq,
|
|
1212
|
+
repo: input.repo,
|
|
1213
|
+
vinaya: input.vinaya,
|
|
1214
|
+
doctrine: input.doctrine,
|
|
1215
|
+
host: input.host,
|
|
1216
|
+
machine: createHash("sha256").update(input.hostname).digest("hex"),
|
|
1217
|
+
event_id: input.eventId,
|
|
1218
|
+
process_id: input.processId,
|
|
1219
|
+
actor_id: actorIdFromEnv(input.env.role),
|
|
1220
|
+
lineage: {
|
|
1221
|
+
run: lineageFieldFromEnv(input.env.run),
|
|
1222
|
+
attempt: attemptFromEnv(input.env.attempt),
|
|
1223
|
+
parent: lineageFieldFromEnv(input.env.parent)
|
|
1224
|
+
},
|
|
1225
|
+
input_versions: {
|
|
1226
|
+
objectives_version: input.inputVersions?.objectivesVersion ?? null,
|
|
1227
|
+
brief_hash: input.inputVersions?.briefHash ?? null,
|
|
1228
|
+
ruling_ordinal: input.inputVersions?.rulingOrdinal ?? null,
|
|
1229
|
+
policy_digest: input.inputVersions?.policyDigest ?? null
|
|
1230
|
+
},
|
|
1231
|
+
provenance: provenanceFor(input)
|
|
1232
|
+
},
|
|
1233
|
+
subject
|
|
1234
|
+
};
|
|
1235
|
+
}
|
|
1236
|
+
// ../../packages/aeg-core/src/log/redact.ts
|
|
1237
|
+
var GITHUB_TOKEN_PATTERN = /\b(?:gho_|ghp_|ghs_|ghu_|ghr_|github_pat_)[A-Za-z0-9_]+\b/g;
|
|
1238
|
+
var CLASSIC_GITHUB_PAT_PATTERN = /\b((?:token|GITHUB_TOKEN|PAT|api[_-]?key|api[_-]?token)\s*[:=]\s*)[a-f0-9]{40}\b/gi;
|
|
1239
|
+
var BEARER_TOKEN_PATTERN = /\bBearer\s+\S+/g;
|
|
1240
|
+
var AWS_ACCESS_KEY_PATTERN = /\bAKIA[0-9A-Z]{16}\b/g;
|
|
1241
|
+
var SLACK_TOKEN_PATTERN = /\bxox[baprs]-[0-9A-Za-z-]+\b/g;
|
|
1242
|
+
var STRIPE_KEY_PATTERN = /\b(?:sk|pk|rk)_(?:live|test)_[0-9A-Za-z]{10,}\b/g;
|
|
1243
|
+
var ANTHROPIC_KEY_PATTERN = /\bsk-ant-[A-Za-z0-9_-]{20,}\b/g;
|
|
1244
|
+
var OPENAI_KEY_PATTERN = /\bsk-(?!ant-)[A-Za-z0-9]{20,}\b/g;
|
|
1245
|
+
var NPM_TOKEN_PATTERN = /\bnpm_[A-Za-z0-9]{36}\b/g;
|
|
1246
|
+
var JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/g;
|
|
1247
|
+
var PEM_BLOCK_PATTERN = /-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z ]*PRIVATE KEY-----/g;
|
|
1248
|
+
var BASIC_AUTH_URL_PATTERN = /(https?:\/\/)[^/\s:@]+:[^/\s@]+@/g;
|
|
1249
|
+
var GENERIC_SECRET_ASSIGNMENT_PATTERN = /\b((?:secret|password|passwd|api[_-]?key|access[_-]?key|client[_-]?secret|private[_-]?key)\s*[:=]\s*)[A-Za-z0-9+/_=-]{16,}\b/gi;
|
|
1250
|
+
function redactString(value, home) {
|
|
1251
|
+
let out = value.replace(GITHUB_TOKEN_PATTERN, "<redacted>").replace(CLASSIC_GITHUB_PAT_PATTERN, "$1<redacted>").replace(BEARER_TOKEN_PATTERN, "<redacted>").replace(AWS_ACCESS_KEY_PATTERN, "<redacted>").replace(SLACK_TOKEN_PATTERN, "<redacted>").replace(STRIPE_KEY_PATTERN, "<redacted>").replace(ANTHROPIC_KEY_PATTERN, "<redacted>").replace(OPENAI_KEY_PATTERN, "<redacted>").replace(NPM_TOKEN_PATTERN, "<redacted>").replace(JWT_PATTERN, "<redacted>").replace(PEM_BLOCK_PATTERN, "<redacted>").replace(BASIC_AUTH_URL_PATTERN, "$1<redacted>@").replace(GENERIC_SECRET_ASSIGNMENT_PATTERN, "$1<redacted>");
|
|
1252
|
+
if (home.length > 0 && out.startsWith(home)) {
|
|
1253
|
+
const rest = out.slice(home.length);
|
|
1254
|
+
if (rest === "" || rest.startsWith("/"))
|
|
1255
|
+
out = `~${rest}`;
|
|
1256
|
+
}
|
|
1257
|
+
return out;
|
|
1258
|
+
}
|
|
1259
|
+
function redact(value, home) {
|
|
1260
|
+
if (typeof value === "string")
|
|
1261
|
+
return redactString(value, home);
|
|
1262
|
+
if (Array.isArray(value))
|
|
1263
|
+
return value.map((v) => redact(v, home));
|
|
1264
|
+
if (value !== null && typeof value === "object") {
|
|
1265
|
+
const out = {};
|
|
1266
|
+
for (const [k, v] of Object.entries(value)) {
|
|
1267
|
+
out[k] = redact(v, home);
|
|
1268
|
+
}
|
|
1269
|
+
return out;
|
|
1270
|
+
}
|
|
1271
|
+
return value;
|
|
1272
|
+
}
|
|
1273
|
+
// ../../packages/aeg-core/src/log/store.ts
|
|
1274
|
+
var KNOWN_SCHEMA_VERSIONS = [1, 2];
|
|
1275
|
+
function metaOf(obj) {
|
|
1276
|
+
if (obj === null || typeof obj !== "object")
|
|
1277
|
+
return null;
|
|
1278
|
+
const meta = obj.meta;
|
|
1279
|
+
if (meta === null || typeof meta !== "object")
|
|
1280
|
+
return null;
|
|
1281
|
+
return meta;
|
|
1282
|
+
}
|
|
1283
|
+
function recordIdentity(obj) {
|
|
1284
|
+
const meta = metaOf(obj);
|
|
1285
|
+
if (meta === null)
|
|
1286
|
+
return null;
|
|
1287
|
+
const eventId = meta.event_id;
|
|
1288
|
+
if (typeof eventId === "string" && eventId.length > 0)
|
|
1289
|
+
return eventId;
|
|
1290
|
+
const runId = meta.run_id;
|
|
1291
|
+
const seq = meta.seq;
|
|
1292
|
+
if (typeof runId === "string" && runId.length > 0 && typeof seq === "number" && Number.isInteger(seq)) {
|
|
1293
|
+
return `${runId}:${seq}`;
|
|
1294
|
+
}
|
|
1295
|
+
return null;
|
|
1296
|
+
}
|
|
1297
|
+
function schemaVersionOf(obj) {
|
|
1298
|
+
const meta = metaOf(obj);
|
|
1299
|
+
const schema = meta?.schema;
|
|
1300
|
+
return typeof schema === "number" ? schema : null;
|
|
1301
|
+
}
|
|
1302
|
+
function isKnownSchema(version) {
|
|
1303
|
+
return version !== null && KNOWN_SCHEMA_VERSIONS.includes(version);
|
|
1304
|
+
}
|
|
1305
|
+
function classifyStoredLine(raw, home) {
|
|
1306
|
+
let obj;
|
|
1307
|
+
try {
|
|
1308
|
+
obj = JSON.parse(raw);
|
|
1309
|
+
} catch {
|
|
1310
|
+
return { status: "invalid", identity: null, raw, reason: "not valid JSON" };
|
|
1311
|
+
}
|
|
1312
|
+
const version = schemaVersionOf(obj);
|
|
1313
|
+
if (version === null) {
|
|
1314
|
+
return { status: "invalid", identity: recordIdentity(obj), raw, reason: "no readable meta.schema" };
|
|
1315
|
+
}
|
|
1316
|
+
if (!isKnownSchema(version)) {
|
|
1317
|
+
return {
|
|
1318
|
+
status: "unknown_version",
|
|
1319
|
+
identity: recordIdentity(obj),
|
|
1320
|
+
schema: version,
|
|
1321
|
+
raw,
|
|
1322
|
+
reason: `schema version ${version} is not one this build validates (${KNOWN_SCHEMA_VERSIONS.join(", ")}) — kept for diagnosis`
|
|
1323
|
+
};
|
|
1324
|
+
}
|
|
1325
|
+
const result = LogEventSchema.safeParse(obj);
|
|
1326
|
+
if (!result.success) {
|
|
1327
|
+
return {
|
|
1328
|
+
status: "invalid",
|
|
1329
|
+
identity: recordIdentity(obj),
|
|
1330
|
+
raw,
|
|
1331
|
+
reason: result.error.issues[0]?.message ?? "schema violation"
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1334
|
+
const event = result.data;
|
|
1335
|
+
const identity = recordIdentity(event);
|
|
1336
|
+
if (identity === null) {
|
|
1337
|
+
return { status: "invalid", identity: null, raw, reason: "valid event with no derivable identity" };
|
|
1338
|
+
}
|
|
1339
|
+
const redacted = redact(event, home);
|
|
1340
|
+
const provenance = version === 2 ? event.meta.provenance ?? null : null;
|
|
1341
|
+
return {
|
|
1342
|
+
status: "ok",
|
|
1343
|
+
identity,
|
|
1344
|
+
runId: event.meta.run_id,
|
|
1345
|
+
seq: event.meta.seq,
|
|
1346
|
+
schema: version,
|
|
1347
|
+
provenance,
|
|
1348
|
+
event,
|
|
1349
|
+
postLine: JSON.stringify(redacted)
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1110
1352
|
// ../../packages/aeg-core/src/control-store/records.ts
|
|
1111
1353
|
import { z as z3 } from "zod";
|
|
1112
1354
|
var isoTimestamp = z3.string().min(1);
|
|
@@ -1236,6 +1478,82 @@ var ResolutionRecordSchema = z3.object({
|
|
|
1236
1478
|
authenticatedFrom: z3.string().min(1),
|
|
1237
1479
|
consumedAt: isoTimestamp
|
|
1238
1480
|
}).strict();
|
|
1481
|
+
// ../../packages/aeg-core/src/control-store/local.ts
|
|
1482
|
+
import {
|
|
1483
|
+
closeSync as closeSync2,
|
|
1484
|
+
constants as fsConstants2,
|
|
1485
|
+
existsSync,
|
|
1486
|
+
fsyncSync,
|
|
1487
|
+
linkSync,
|
|
1488
|
+
lstatSync,
|
|
1489
|
+
mkdirSync,
|
|
1490
|
+
openSync as openSync2,
|
|
1491
|
+
readdirSync,
|
|
1492
|
+
readFileSync as readFileSync2,
|
|
1493
|
+
renameSync,
|
|
1494
|
+
statSync,
|
|
1495
|
+
unlinkSync,
|
|
1496
|
+
writeSync
|
|
1497
|
+
} from "node:fs";
|
|
1498
|
+
import { dirname, join, resolve, sep } from "node:path";
|
|
1499
|
+
function isErrnoException(err, code) {
|
|
1500
|
+
return typeof err === "object" && err !== null && err.code === code;
|
|
1501
|
+
}
|
|
1502
|
+
function isTrustedDirStat(stat, ownUid) {
|
|
1503
|
+
if (typeof ownUid !== "number")
|
|
1504
|
+
return true;
|
|
1505
|
+
if (stat.uid !== ownUid && stat.uid !== 0)
|
|
1506
|
+
return false;
|
|
1507
|
+
const worldWritable = (stat.mode & 2) !== 0;
|
|
1508
|
+
const sticky = (stat.mode & 512) !== 0;
|
|
1509
|
+
return !worldWritable || sticky;
|
|
1510
|
+
}
|
|
1511
|
+
function currentUid() {
|
|
1512
|
+
return typeof process.getuid === "function" ? process.getuid() : undefined;
|
|
1513
|
+
}
|
|
1514
|
+
function mkdirNoSymlinks(dir, mode, trustedRoot) {
|
|
1515
|
+
const absolute = resolve(dir);
|
|
1516
|
+
const rootSegments = resolve(trustedRoot).split(sep).filter((s) => s.length > 0);
|
|
1517
|
+
const segments = absolute.split(sep).filter((s) => s.length > 0);
|
|
1518
|
+
const ownUid = currentUid();
|
|
1519
|
+
let current = absolute.startsWith(sep) ? sep : "";
|
|
1520
|
+
segments.forEach((segment, index) => {
|
|
1521
|
+
current = current === "" || current === sep ? `${current}${segment}` : `${current}${sep}${segment}`;
|
|
1522
|
+
const atOrBelowTrustedRoot = index >= rootSegments.length - 1;
|
|
1523
|
+
try {
|
|
1524
|
+
mkdirSync(current, { mode });
|
|
1525
|
+
} catch (err) {
|
|
1526
|
+
if (!isErrnoException(err, "EEXIST"))
|
|
1527
|
+
throw err;
|
|
1528
|
+
}
|
|
1529
|
+
const stat = lstatSync(current);
|
|
1530
|
+
if (stat.isSymbolicLink()) {
|
|
1531
|
+
if (atOrBelowTrustedRoot) {
|
|
1532
|
+
throw new Error(`control-store: refusing to create a run directory through ${current} — it already exists and is not a real directory (a symlink or a file)`);
|
|
1533
|
+
}
|
|
1534
|
+
let real;
|
|
1535
|
+
try {
|
|
1536
|
+
real = statSync(current);
|
|
1537
|
+
} catch (err) {
|
|
1538
|
+
throw new Error(`control-store: refusing to create a run directory through ${current} — it is a symlink whose target could not be resolved: ${err instanceof Error ? err.message : String(err)}`);
|
|
1539
|
+
}
|
|
1540
|
+
if (!real.isDirectory()) {
|
|
1541
|
+
throw new Error(`control-store: refusing to create a run directory through ${current} — it is a symlink that does not resolve to a real directory`);
|
|
1542
|
+
}
|
|
1543
|
+
if (!isTrustedDirStat(real, ownUid)) {
|
|
1544
|
+
throw new Error(`control-store: refusing to create a run directory through ${current} — its symlink target is owned by uid ${real.uid} with mode ${(real.mode & 4095).toString(8)}, neither this process's own user nor a safe shared mode`);
|
|
1545
|
+
}
|
|
1546
|
+
return;
|
|
1547
|
+
}
|
|
1548
|
+
if (!stat.isDirectory()) {
|
|
1549
|
+
throw new Error(`control-store: refusing to create a run directory through ${current} — it already exists and is not a real directory (a symlink or a file)`);
|
|
1550
|
+
}
|
|
1551
|
+
if (!isTrustedDirStat(stat, ownUid)) {
|
|
1552
|
+
throw new Error(`control-store: refusing to create a run directory through ${current} — it already exists, owned by uid ${stat.uid} with mode ${(stat.mode & 4095).toString(8)}, neither this process's own user nor a safe shared mode`);
|
|
1553
|
+
}
|
|
1554
|
+
});
|
|
1555
|
+
}
|
|
1556
|
+
var CONTROL_AREA_DIRNAME = "control";
|
|
1239
1557
|
// src/lib/agent-vendors.ts
|
|
1240
1558
|
var AGENT_VENDORS = ["skills", "claude", "gemini"];
|
|
1241
1559
|
|
|
@@ -1257,10 +1575,10 @@ var CheckEntrySchema = z4.object({
|
|
|
1257
1575
|
ownWorkflow: z4.boolean().optional(),
|
|
1258
1576
|
principalOwed: z4.literal(true).optional(),
|
|
1259
1577
|
validates: z4.enum(["body", "issue"]).optional()
|
|
1260
|
-
}).superRefine((
|
|
1261
|
-
if (!
|
|
1578
|
+
}).superRefine((entry, ctx) => {
|
|
1579
|
+
if (!entry.env)
|
|
1262
1580
|
return;
|
|
1263
|
-
for (const [key, value] of Object.entries(
|
|
1581
|
+
for (const [key, value] of Object.entries(entry.env)) {
|
|
1264
1582
|
if (typeof value !== "object" || value === null || !("anyOf" in value))
|
|
1265
1583
|
continue;
|
|
1266
1584
|
const members = value.anyOf;
|
|
@@ -1417,31 +1735,32 @@ var VinayaConfigSchema = z4.object({
|
|
|
1417
1735
|
});
|
|
1418
1736
|
}
|
|
1419
1737
|
}).optional(),
|
|
1420
|
-
logPublish: z4.
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
}).refine((v) => v.
|
|
1429
|
-
message: "
|
|
1430
|
-
}).
|
|
1431
|
-
|
|
1738
|
+
logPublish: z4.unknown().refine((v) => v === undefined, {
|
|
1739
|
+
message: "logPublish is removed — telemetry is never posted to a tracker or a code host; configure `logs` instead (a folder or a server destination)"
|
|
1740
|
+
}),
|
|
1741
|
+
runtimeDir: z4.string().min(1).refine((v) => isAbsolute(v), { message: "runtimeDir: must be an absolute path" }).optional(),
|
|
1742
|
+
logs: z4.object({
|
|
1743
|
+
folder: z4.string().min(1).refine((v) => isAbsolute(v), { message: "logs.folder: must be an absolute path" }).optional(),
|
|
1744
|
+
url: z4.string().url().optional(),
|
|
1745
|
+
headers: z4.record(z4.string()).optional()
|
|
1746
|
+
}).refine((v) => [v.folder, v.url].filter((x) => x !== undefined).length <= 1, {
|
|
1747
|
+
message: "logs: set at most one of folder/url"
|
|
1748
|
+
}).refine((v) => v.headers === undefined || v.url !== undefined, {
|
|
1749
|
+
message: "logs: headers requires url"
|
|
1750
|
+
}).optional()
|
|
1432
1751
|
});
|
|
1433
|
-
var GLOBAL_VINAYA_HOME =
|
|
1434
|
-
var GLOBAL_CONFIG_PATH =
|
|
1752
|
+
var GLOBAL_VINAYA_HOME = join2(homedir(), ".vinaya");
|
|
1753
|
+
var GLOBAL_CONFIG_PATH = join2(GLOBAL_VINAYA_HOME, "config.json");
|
|
1435
1754
|
var LOCAL_CONFIG_FILENAME = "vinaya.config.json";
|
|
1436
1755
|
function findLocalConfig() {
|
|
1437
1756
|
let dir = process.cwd();
|
|
1438
1757
|
while (true) {
|
|
1439
|
-
const candidate =
|
|
1440
|
-
if (
|
|
1758
|
+
const candidate = join2(dir, LOCAL_CONFIG_FILENAME);
|
|
1759
|
+
if (existsSync2(candidate))
|
|
1441
1760
|
return candidate;
|
|
1442
|
-
if (
|
|
1761
|
+
if (existsSync2(join2(dir, ".git")))
|
|
1443
1762
|
return null;
|
|
1444
|
-
const parent =
|
|
1763
|
+
const parent = dirname2(dir);
|
|
1445
1764
|
if (parent === dir)
|
|
1446
1765
|
return null;
|
|
1447
1766
|
dir = parent;
|
|
@@ -1451,7 +1770,7 @@ function configPath() {
|
|
|
1451
1770
|
const local = findLocalConfig();
|
|
1452
1771
|
if (local)
|
|
1453
1772
|
return local;
|
|
1454
|
-
if (
|
|
1773
|
+
if (existsSync2(GLOBAL_CONFIG_PATH))
|
|
1455
1774
|
return GLOBAL_CONFIG_PATH;
|
|
1456
1775
|
return null;
|
|
1457
1776
|
}
|
|
@@ -1473,52 +1792,206 @@ function globalTokensCollectIgnoredWarning(path) {
|
|
|
1473
1792
|
function globalRuntimeDirIgnoredWarning(path) {
|
|
1474
1793
|
return `${path}: "runtimeDir" in the global config is ignored — it carries no repository segment, so a machine-wide value would collapse every repository's task folders into one tree. Declare it from a repo-local vinaya.config.json.`;
|
|
1475
1794
|
}
|
|
1795
|
+
var emittedGlobalKeyWarnings = new Set;
|
|
1796
|
+
function warnGlobalKeyIgnoredOnce(message) {
|
|
1797
|
+
if (emittedGlobalKeyWarnings.has(message))
|
|
1798
|
+
return;
|
|
1799
|
+
emittedGlobalKeyWarnings.add(message);
|
|
1800
|
+
console.error(`⚠ ${message}`);
|
|
1801
|
+
}
|
|
1476
1802
|
function stripGlobalOnlyKeys(config, path) {
|
|
1477
1803
|
if (path !== GLOBAL_CONFIG_PATH)
|
|
1478
1804
|
return config;
|
|
1479
1805
|
let result = config;
|
|
1480
1806
|
if (result.checks && Object.keys(result.checks).length > 0) {
|
|
1481
|
-
|
|
1807
|
+
warnGlobalKeyIgnoredOnce(globalChecksIgnoredWarning(path));
|
|
1482
1808
|
result = { ...result, checks: undefined };
|
|
1483
1809
|
}
|
|
1484
1810
|
if (result.roles && Object.keys(result.roles).length > 0) {
|
|
1485
|
-
|
|
1811
|
+
warnGlobalKeyIgnoredOnce(globalRolesIgnoredWarning(path));
|
|
1486
1812
|
result = { ...result, roles: undefined };
|
|
1487
1813
|
}
|
|
1488
1814
|
if (result.principals && result.principals.length > 0) {
|
|
1489
|
-
|
|
1815
|
+
warnGlobalKeyIgnoredOnce(globalPrincipalsIgnoredWarning(path));
|
|
1490
1816
|
result = { ...result, principals: undefined };
|
|
1491
1817
|
}
|
|
1492
1818
|
if (result.releaseActor) {
|
|
1493
|
-
|
|
1819
|
+
warnGlobalKeyIgnoredOnce(globalReleaseActorIgnoredWarning(path));
|
|
1494
1820
|
result = { ...result, releaseActor: undefined };
|
|
1495
1821
|
}
|
|
1496
1822
|
if (result.tokens) {
|
|
1497
|
-
|
|
1823
|
+
warnGlobalKeyIgnoredOnce(globalTokensCollectIgnoredWarning(path));
|
|
1498
1824
|
result = { ...result, tokens: undefined };
|
|
1499
1825
|
}
|
|
1500
1826
|
if (result.runtimeDir) {
|
|
1501
|
-
|
|
1827
|
+
warnGlobalKeyIgnoredOnce(globalRuntimeDirIgnoredWarning(path));
|
|
1502
1828
|
result = { ...result, runtimeDir: undefined };
|
|
1503
1829
|
}
|
|
1504
1830
|
return result;
|
|
1505
1831
|
}
|
|
1832
|
+
function resolveRuntimeDirSetting(config) {
|
|
1833
|
+
return config?.runtimeDir ?? null;
|
|
1834
|
+
}
|
|
1835
|
+
function resolveTrustAnchorRuntimeDir(localRuntimeDir, trustAnchorConfig) {
|
|
1836
|
+
const anchored = resolveRuntimeDirSetting(trustAnchorConfig);
|
|
1837
|
+
return anchored !== null && anchored === localRuntimeDir ? anchored : null;
|
|
1838
|
+
}
|
|
1839
|
+
function resolveLogsSetting(config) {
|
|
1840
|
+
const raw = config?.logs;
|
|
1841
|
+
if (!raw)
|
|
1842
|
+
return null;
|
|
1843
|
+
if (raw.url !== undefined)
|
|
1844
|
+
return { url: raw.url, headers: raw.headers };
|
|
1845
|
+
if (raw.folder !== undefined)
|
|
1846
|
+
return { folder: raw.folder };
|
|
1847
|
+
return null;
|
|
1848
|
+
}
|
|
1849
|
+
function resolveTrustAnchorLogsDestination(local, trustAnchorConfig) {
|
|
1850
|
+
const anchored = resolveLogsSetting(trustAnchorConfig);
|
|
1851
|
+
if (!anchored)
|
|
1852
|
+
return null;
|
|
1853
|
+
if ("url" in local)
|
|
1854
|
+
return "url" in anchored && anchored.url === local.url ? anchored : null;
|
|
1855
|
+
return "folder" in anchored && anchored.folder === local.folder ? anchored : null;
|
|
1856
|
+
}
|
|
1857
|
+
function resolveLogsHeaderValues(headers, env) {
|
|
1858
|
+
if (!headers)
|
|
1859
|
+
return;
|
|
1860
|
+
const resolved = {};
|
|
1861
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
1862
|
+
resolved[key] = value.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (_match, name) => env[name] ?? "");
|
|
1863
|
+
}
|
|
1864
|
+
return resolved;
|
|
1865
|
+
}
|
|
1866
|
+
function trustAnchorRepo() {
|
|
1867
|
+
const fromRunner = trustAnchorRepoFromRunner();
|
|
1868
|
+
if (fromRunner)
|
|
1869
|
+
return fromRunner;
|
|
1870
|
+
try {
|
|
1871
|
+
const url = execFileSync2("git", ["remote", "get-url", "origin"], {
|
|
1872
|
+
encoding: "utf-8",
|
|
1873
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
1874
|
+
});
|
|
1875
|
+
return trustAnchorRepoFromRemoteUrl(url);
|
|
1876
|
+
} catch {
|
|
1877
|
+
return null;
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
async function trustAnchorRepoAsync() {
|
|
1881
|
+
const fromRunner = trustAnchorRepoFromRunner();
|
|
1882
|
+
if (fromRunner)
|
|
1883
|
+
return fromRunner;
|
|
1884
|
+
try {
|
|
1885
|
+
const { stdout } = await execFileAsync4("git", ["remote", "get-url", "origin"], {
|
|
1886
|
+
encoding: "utf-8",
|
|
1887
|
+
timeout: 1e4
|
|
1888
|
+
});
|
|
1889
|
+
return trustAnchorRepoFromRemoteUrl(stdout);
|
|
1890
|
+
} catch {
|
|
1891
|
+
return null;
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
function wellFormedRepoSlug(slug) {
|
|
1895
|
+
return /^[^/\s]+\/[^/\s]+$/.test(slug) ? slug : null;
|
|
1896
|
+
}
|
|
1897
|
+
function trustAnchorRepoFromRunner() {
|
|
1898
|
+
const fromRunner = process.env.GITHUB_REPOSITORY?.trim();
|
|
1899
|
+
return fromRunner ? wellFormedRepoSlug(fromRunner) : null;
|
|
1900
|
+
}
|
|
1901
|
+
function trustAnchorRepoFromRemoteUrl(url) {
|
|
1902
|
+
const m = url.trim().match(/github\.com[:/]([^/]+)\/(.+?)(?:\.git)?\/?$/);
|
|
1903
|
+
return m?.[1] && m[2] ? wellFormedRepoSlug(`${m[1]}/${m[2]}`) : null;
|
|
1904
|
+
}
|
|
1905
|
+
var execFileAsync4 = promisify4(execFile4);
|
|
1906
|
+
function ghFetchTrustAnchorConfig() {
|
|
1907
|
+
const repo = trustAnchorRepo();
|
|
1908
|
+
if (!repo)
|
|
1909
|
+
throw new Error("could not resolve repo identity for the trust-anchor read");
|
|
1910
|
+
return execFileSync2("gh", ["api", `repos/${repo}/contents/${LOCAL_CONFIG_FILENAME}`, "--jq", ".content"], {
|
|
1911
|
+
encoding: "utf-8",
|
|
1912
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
1913
|
+
});
|
|
1914
|
+
}
|
|
1915
|
+
async function ghFetchTrustAnchorConfigAsync() {
|
|
1916
|
+
const repo = await trustAnchorRepoAsync();
|
|
1917
|
+
if (!repo)
|
|
1918
|
+
throw new Error("could not resolve repo identity for the trust-anchor read");
|
|
1919
|
+
const { stdout } = await execFileAsync4("gh", ["api", `repos/${repo}/contents/${LOCAL_CONFIG_FILENAME}`, "--jq", ".content"], { encoding: "utf-8", timeout: 1e4 });
|
|
1920
|
+
return stdout;
|
|
1921
|
+
}
|
|
1922
|
+
function firstLine(err) {
|
|
1923
|
+
return err?.message?.split(`
|
|
1924
|
+
`)[0] ?? "unknown error";
|
|
1925
|
+
}
|
|
1926
|
+
function isMissingFileError(err) {
|
|
1927
|
+
const stderr = err?.stderr;
|
|
1928
|
+
const haystack = [
|
|
1929
|
+
err?.message ?? "",
|
|
1930
|
+
typeof stderr === "string" ? stderr : stderr?.toString() ?? ""
|
|
1931
|
+
].join(`
|
|
1932
|
+
`);
|
|
1933
|
+
return /\b404\b|not found/i.test(haystack);
|
|
1934
|
+
}
|
|
1935
|
+
function loadTrustAnchorConfig(fetcher = ghFetchTrustAnchorConfig) {
|
|
1936
|
+
let base64;
|
|
1937
|
+
try {
|
|
1938
|
+
base64 = fetcher();
|
|
1939
|
+
} catch (err) {
|
|
1940
|
+
return trustAnchorFetchFailed(err);
|
|
1941
|
+
}
|
|
1942
|
+
return parseTrustAnchorContent(base64);
|
|
1943
|
+
}
|
|
1944
|
+
async function loadTrustAnchorConfigAsync(fetcher = ghFetchTrustAnchorConfigAsync, options = {}) {
|
|
1945
|
+
const warn = options.quiet ? () => {} : warnTrustAnchorFallback;
|
|
1946
|
+
let base64;
|
|
1947
|
+
try {
|
|
1948
|
+
base64 = await fetcher();
|
|
1949
|
+
} catch (err) {
|
|
1950
|
+
return trustAnchorFetchFailed(err, warn);
|
|
1951
|
+
}
|
|
1952
|
+
return parseTrustAnchorContent(base64, warn);
|
|
1953
|
+
}
|
|
1954
|
+
function warnTrustAnchorFallback(why) {
|
|
1955
|
+
process.stdout.write(`⚠ could not read the trust-anchor config (\`principals\`/\`releaseActor\`) from the default branch (${why}) — falling back to vinaya's built-in defaults.
|
|
1956
|
+
`);
|
|
1957
|
+
}
|
|
1958
|
+
function trustAnchorFetchFailed(err, warn = warnTrustAnchorFallback) {
|
|
1959
|
+
if (!isMissingFileError(err))
|
|
1960
|
+
warn(firstLine(err));
|
|
1961
|
+
return null;
|
|
1962
|
+
}
|
|
1963
|
+
function parseTrustAnchorContent(content, warn = warnTrustAnchorFallback) {
|
|
1964
|
+
const base64 = content.trim();
|
|
1965
|
+
if (!base64)
|
|
1966
|
+
return null;
|
|
1967
|
+
try {
|
|
1968
|
+
const raw = Buffer.from(base64, "base64").toString("utf-8");
|
|
1969
|
+
const parsed = VinayaConfigSchema.safeParse(JSON.parse(raw));
|
|
1970
|
+
if (parsed.success)
|
|
1971
|
+
return parsed.data;
|
|
1972
|
+
warn("it did not satisfy the config schema");
|
|
1973
|
+
return null;
|
|
1974
|
+
} catch {
|
|
1975
|
+
warn("it was not readable as JSON");
|
|
1976
|
+
return null;
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1506
1979
|
function loadConfig() {
|
|
1507
1980
|
const path = configPath();
|
|
1508
1981
|
if (!path)
|
|
1509
1982
|
return null;
|
|
1510
1983
|
try {
|
|
1511
|
-
const raw = JSON.parse(
|
|
1984
|
+
const raw = JSON.parse(readFileSync3(path, "utf-8"));
|
|
1512
1985
|
return stripGlobalOnlyKeys(VinayaConfigSchema.parse(raw), path);
|
|
1513
1986
|
} catch {
|
|
1514
1987
|
return null;
|
|
1515
1988
|
}
|
|
1516
1989
|
}
|
|
1517
|
-
var TOKENS_COLLECT_TRUST_PATH =
|
|
1990
|
+
var TOKENS_COLLECT_TRUST_PATH = join2(GLOBAL_VINAYA_HOME, "tokens-collect-trust.json");
|
|
1518
1991
|
|
|
1519
1992
|
// src/lib/remote-base.ts
|
|
1520
|
-
import { execFileSync as
|
|
1521
|
-
import { join as
|
|
1993
|
+
import { execFileSync as execFileSync3 } from "node:child_process";
|
|
1994
|
+
import { join as join3 } from "node:path";
|
|
1522
1995
|
function cleanGitEnv() {
|
|
1523
1996
|
const env = { ...process.env };
|
|
1524
1997
|
for (const key of Object.keys(env)) {
|
|
@@ -1529,7 +2002,7 @@ function cleanGitEnv() {
|
|
|
1529
2002
|
}
|
|
1530
2003
|
function git(repoRoot, args) {
|
|
1531
2004
|
try {
|
|
1532
|
-
return
|
|
2005
|
+
return execFileSync3("git", args, {
|
|
1533
2006
|
cwd: repoRoot,
|
|
1534
2007
|
encoding: "utf8",
|
|
1535
2008
|
stdio: ["ignore", "pipe", "ignore"],
|
|
@@ -1555,7 +2028,7 @@ function changedFilesSinceRemoteBase(repoRoot) {
|
|
|
1555
2028
|
`).map((s) => s.trim()).filter(Boolean);
|
|
1556
2029
|
}
|
|
1557
2030
|
function changedFilesSinceRemoteBaseAbsolute(repoRoot) {
|
|
1558
|
-
return changedFilesSinceRemoteBase(repoRoot).map((f) =>
|
|
2031
|
+
return changedFilesSinceRemoteBase(repoRoot).map((f) => join3(repoRoot, f));
|
|
1559
2032
|
}
|
|
1560
2033
|
function addedOrRenamedFilesSinceRemoteBase(repoRoot) {
|
|
1561
2034
|
const base = resolveRemoteBase(repoRoot);
|
|
@@ -1564,7 +2037,7 @@ function addedOrRenamedFilesSinceRemoteBase(repoRoot) {
|
|
|
1564
2037
|
`).map((s) => s.trim()).filter(Boolean);
|
|
1565
2038
|
}
|
|
1566
2039
|
function addedOrRenamedFilesSinceRemoteBaseAbsolute(repoRoot) {
|
|
1567
|
-
return addedOrRenamedFilesSinceRemoteBase(repoRoot).map((f) =>
|
|
2040
|
+
return addedOrRenamedFilesSinceRemoteBase(repoRoot).map((f) => join3(repoRoot, f));
|
|
1568
2041
|
}
|
|
1569
2042
|
function changedFileDiffsSinceRemoteBase(repoRoot) {
|
|
1570
2043
|
const base = resolveRemoteBase(repoRoot);
|
|
@@ -1574,7 +2047,7 @@ function changedFileDiffsSinceRemoteBase(repoRoot) {
|
|
|
1574
2047
|
const patch = git(repoRoot, ["diff", "-U0", `${mergeBase}..HEAD`, "--", relative]);
|
|
1575
2048
|
const { beforeRanges, afterRanges } = parseHunkRanges(patch);
|
|
1576
2049
|
out.push({
|
|
1577
|
-
file:
|
|
2050
|
+
file: join3(repoRoot, relative),
|
|
1578
2051
|
after: showBlob(repoRoot, "HEAD", relative),
|
|
1579
2052
|
before: showBlob(repoRoot, mergeBase, relative),
|
|
1580
2053
|
beforeRanges,
|
|
@@ -1585,7 +2058,7 @@ function changedFileDiffsSinceRemoteBase(repoRoot) {
|
|
|
1585
2058
|
}
|
|
1586
2059
|
function showBlob(repoRoot, ref, relative) {
|
|
1587
2060
|
try {
|
|
1588
|
-
return
|
|
2061
|
+
return execFileSync3("git", ["show", `${ref}:${relative}`], {
|
|
1589
2062
|
cwd: repoRoot,
|
|
1590
2063
|
encoding: "utf8",
|
|
1591
2064
|
maxBuffer: 64 * 1024 * 1024,
|
|
@@ -1598,11 +2071,124 @@ function showBlob(repoRoot, ref, relative) {
|
|
|
1598
2071
|
}
|
|
1599
2072
|
|
|
1600
2073
|
// src/lib/test-selector.ts
|
|
1601
|
-
import { readdirSync, readFileSync as
|
|
1602
|
-
import { dirname as
|
|
2074
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync4, statSync as statSync2 } from "node:fs";
|
|
2075
|
+
import { dirname as dirname6, extname, isAbsolute as isAbsolute4, join as join7, resolve as resolve6 } from "node:path";
|
|
2076
|
+
|
|
2077
|
+
// src/lib/cli-spawn-tests.ts
|
|
2078
|
+
import { dirname as dirname3, isAbsolute as isAbsolute2, join as join4, resolve as resolve3 } from "node:path";
|
|
2079
|
+
function evaluateExpression(ts, node, file, fileDir, repoRoot, bindings) {
|
|
2080
|
+
if (ts.isStringLiteral(node))
|
|
2081
|
+
return node.text;
|
|
2082
|
+
if (ts.isIdentifier(node))
|
|
2083
|
+
return node.text === "__dirname" ? fileDir : bindings.get(node.text) ?? null;
|
|
2084
|
+
if (ts.isPropertyAccessExpression(node)) {
|
|
2085
|
+
const text = node.getText();
|
|
2086
|
+
if (text === "import.meta.dir" || text === "import.meta.dirname")
|
|
2087
|
+
return fileDir;
|
|
2088
|
+
if (text === "import.meta.url")
|
|
2089
|
+
return file;
|
|
2090
|
+
return null;
|
|
2091
|
+
}
|
|
2092
|
+
if (ts.isCallExpression(node)) {
|
|
2093
|
+
const callee = ts.isIdentifier(node.expression) ? node.expression.text : ts.isPropertyAccessExpression(node.expression) ? node.expression.name.text : "";
|
|
2094
|
+
if (callee === "cwd")
|
|
2095
|
+
return repoRoot;
|
|
2096
|
+
if (callee === "dirname") {
|
|
2097
|
+
const arg = node.arguments[0];
|
|
2098
|
+
const inner = arg ? evaluateExpression(ts, arg, file, fileDir, repoRoot, bindings) : null;
|
|
2099
|
+
return inner !== null ? dirname3(inner) : null;
|
|
2100
|
+
}
|
|
2101
|
+
if (callee === "fileURLToPath") {
|
|
2102
|
+
const arg = node.arguments[0];
|
|
2103
|
+
return arg ? evaluateExpression(ts, arg, file, fileDir, repoRoot, bindings) : null;
|
|
2104
|
+
}
|
|
2105
|
+
if (callee === "join" || callee === "resolve") {
|
|
2106
|
+
const parts = [];
|
|
2107
|
+
for (const arg of node.arguments) {
|
|
2108
|
+
const part = evaluateExpression(ts, arg, file, fileDir, repoRoot, bindings);
|
|
2109
|
+
if (part === null)
|
|
2110
|
+
return null;
|
|
2111
|
+
parts.push(part);
|
|
2112
|
+
}
|
|
2113
|
+
if (parts.length === 0)
|
|
2114
|
+
return null;
|
|
2115
|
+
const first = parts[0];
|
|
2116
|
+
if (!isAbsolute2(first))
|
|
2117
|
+
return null;
|
|
2118
|
+
return callee === "join" ? join4(...parts) : resolve3(...parts);
|
|
2119
|
+
}
|
|
2120
|
+
return null;
|
|
2121
|
+
}
|
|
2122
|
+
if (ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "URL") {
|
|
2123
|
+
const base = node.arguments?.[1];
|
|
2124
|
+
if (base?.getText() !== "import.meta.url")
|
|
2125
|
+
return null;
|
|
2126
|
+
const relativeArg = node.arguments?.[0];
|
|
2127
|
+
if (!relativeArg || !ts.isStringLiteral(relativeArg))
|
|
2128
|
+
return null;
|
|
2129
|
+
return join4(fileDir, relativeArg.text);
|
|
2130
|
+
}
|
|
2131
|
+
return null;
|
|
2132
|
+
}
|
|
2133
|
+
function collectTopLevelBindings(ts, sourceFile, file, fileDir, repoRoot) {
|
|
2134
|
+
const bindings = new Map;
|
|
2135
|
+
for (const statement of sourceFile.statements) {
|
|
2136
|
+
if (!ts.isVariableStatement(statement))
|
|
2137
|
+
continue;
|
|
2138
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
2139
|
+
if (!ts.isIdentifier(declaration.name) || !declaration.initializer)
|
|
2140
|
+
continue;
|
|
2141
|
+
const value = evaluateExpression(ts, declaration.initializer, file, fileDir, repoRoot, bindings);
|
|
2142
|
+
if (value !== null)
|
|
2143
|
+
bindings.set(declaration.name.text, value);
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
return bindings;
|
|
2147
|
+
}
|
|
2148
|
+
function cliSpawnEdgeOf(ts, file, source, repoRoot, entrypoint) {
|
|
2149
|
+
const fileDir = dirname3(file);
|
|
2150
|
+
let sourceFile;
|
|
2151
|
+
try {
|
|
2152
|
+
sourceFile = ts.createSourceFile(file, source, ts.ScriptTarget.ES2022, true);
|
|
2153
|
+
} catch {
|
|
2154
|
+
return null;
|
|
2155
|
+
}
|
|
2156
|
+
const bindings = collectTopLevelBindings(ts, sourceFile, file, fileDir, repoRoot);
|
|
2157
|
+
let classification = null;
|
|
2158
|
+
const visit = (node) => {
|
|
2159
|
+
if (ts.isCallExpression(node)) {
|
|
2160
|
+
const candidates = [];
|
|
2161
|
+
for (const arg of node.arguments) {
|
|
2162
|
+
candidates.push(arg);
|
|
2163
|
+
if (ts.isArrayLiteralExpression(arg)) {
|
|
2164
|
+
for (const element of arg.elements) {
|
|
2165
|
+
if (!ts.isSpreadElement(element))
|
|
2166
|
+
candidates.push(element);
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
}
|
|
2170
|
+
let sawBun = false;
|
|
2171
|
+
let sawEntrypoint = false;
|
|
2172
|
+
for (const candidate of candidates) {
|
|
2173
|
+
const value = evaluateExpression(ts, candidate, file, fileDir, repoRoot, bindings);
|
|
2174
|
+
if (value === "bun")
|
|
2175
|
+
sawBun = true;
|
|
2176
|
+
else if (value === entrypoint)
|
|
2177
|
+
sawEntrypoint = true;
|
|
2178
|
+
}
|
|
2179
|
+
if (sawBun && sawEntrypoint)
|
|
2180
|
+
classification = "entrypoint";
|
|
2181
|
+
else if ((sawBun || sawEntrypoint) && classification !== "entrypoint")
|
|
2182
|
+
classification = "fallback";
|
|
2183
|
+
}
|
|
2184
|
+
ts.forEachChild(node, visit);
|
|
2185
|
+
};
|
|
2186
|
+
visit(sourceFile);
|
|
2187
|
+
return classification;
|
|
2188
|
+
}
|
|
1603
2189
|
|
|
1604
2190
|
// src/lib/repo-scanner-tests.ts
|
|
1605
|
-
import { dirname as
|
|
2191
|
+
import { dirname as dirname4, isAbsolute as isAbsolute3, join as join5, resolve as resolve4 } from "node:path";
|
|
1606
2192
|
var TREE_READERS = new Set([
|
|
1607
2193
|
"readdirSync",
|
|
1608
2194
|
"readdir",
|
|
@@ -1642,9 +2228,9 @@ function evaluatePath(ts, node, fileDir, repoRoot, bindings) {
|
|
|
1642
2228
|
if (parts.length === 0)
|
|
1643
2229
|
return null;
|
|
1644
2230
|
const first = parts[0];
|
|
1645
|
-
if (!
|
|
2231
|
+
if (!isAbsolute3(first))
|
|
1646
2232
|
return null;
|
|
1647
|
-
return callee === "join" ?
|
|
2233
|
+
return callee === "join" ? join5(...parts) : resolve4(...parts);
|
|
1648
2234
|
}
|
|
1649
2235
|
return null;
|
|
1650
2236
|
}
|
|
@@ -1655,12 +2241,12 @@ function evaluatePath(ts, node, fileDir, repoRoot, bindings) {
|
|
|
1655
2241
|
const relativeArg = node.arguments?.[0];
|
|
1656
2242
|
if (!relativeArg || !ts.isStringLiteral(relativeArg))
|
|
1657
2243
|
return null;
|
|
1658
|
-
return
|
|
2244
|
+
return join5(fileDir, relativeArg.text);
|
|
1659
2245
|
}
|
|
1660
2246
|
return null;
|
|
1661
2247
|
}
|
|
1662
2248
|
function scannedRootsOf(ts, file, source, repoRoot) {
|
|
1663
|
-
const fileDir =
|
|
2249
|
+
const fileDir = dirname4(file);
|
|
1664
2250
|
let sourceFile;
|
|
1665
2251
|
try {
|
|
1666
2252
|
sourceFile = ts.createSourceFile(file, source, ts.ScriptTarget.ES2022, true);
|
|
@@ -1711,9 +2297,9 @@ function scannedRootsOf(ts, file, source, repoRoot) {
|
|
|
1711
2297
|
|
|
1712
2298
|
// src/lib/ts-module-graph.ts
|
|
1713
2299
|
import { createRequire } from "node:module";
|
|
1714
|
-
import { dirname as
|
|
2300
|
+
import { dirname as dirname5, join as join6, resolve as resolve5 } from "node:path";
|
|
1715
2301
|
function loadTypeScript(repoRoot) {
|
|
1716
|
-
for (const from of [
|
|
2302
|
+
for (const from of [join6(repoRoot, "package.json"), import.meta.url]) {
|
|
1717
2303
|
try {
|
|
1718
2304
|
const loaded = createRequire(from)("typescript");
|
|
1719
2305
|
if (loaded && typeof loaded.createProgram === "function" && loaded.ScriptTarget)
|
|
@@ -1732,8 +2318,8 @@ var SCAN_PREFIX = "scan:";
|
|
|
1732
2318
|
var NAME_SEPARATOR = "#";
|
|
1733
2319
|
function graphCompilerOptions(ts, input) {
|
|
1734
2320
|
const paths = {};
|
|
1735
|
-
for (const [specifier,
|
|
1736
|
-
paths[specifier] = [
|
|
2321
|
+
for (const [specifier, entry] of input.entrypoints)
|
|
2322
|
+
paths[specifier] = [entry];
|
|
1737
2323
|
return {
|
|
1738
2324
|
baseUrl: input.repoRoot,
|
|
1739
2325
|
paths,
|
|
@@ -1841,7 +2427,7 @@ ${specifier}`;
|
|
|
1841
2427
|
const resolveWithLiteral = (specifier, into) => {
|
|
1842
2428
|
const target = resolveToWorkspaceFile(specifier, file);
|
|
1843
2429
|
if (specifier.startsWith(".")) {
|
|
1844
|
-
const literal =
|
|
2430
|
+
const literal = resolve5(dirname5(file), specifier);
|
|
1845
2431
|
if (literal !== target && fileSet.has(literal))
|
|
1846
2432
|
into.push(`${ALL_PREFIX}${literal}`);
|
|
1847
2433
|
}
|
|
@@ -1996,8 +2582,8 @@ function parseNamedList(inside) {
|
|
|
1996
2582
|
if (entries.length === 0)
|
|
1997
2583
|
clean = false;
|
|
1998
2584
|
for (const raw of entries) {
|
|
1999
|
-
const
|
|
2000
|
-
const origin =
|
|
2585
|
+
const entry = raw.replace(/^type\s+/, "");
|
|
2586
|
+
const origin = entry.split(/\s+as\s+/)[0].trim();
|
|
2001
2587
|
if (/^[A-Za-z_$][\w$]*$/.test(origin))
|
|
2002
2588
|
names.push(origin);
|
|
2003
2589
|
else
|
|
@@ -2056,17 +2642,17 @@ function walkFiles(root) {
|
|
|
2056
2642
|
const out = [];
|
|
2057
2643
|
let entries;
|
|
2058
2644
|
try {
|
|
2059
|
-
entries =
|
|
2645
|
+
entries = readdirSync2(root);
|
|
2060
2646
|
} catch {
|
|
2061
2647
|
return out;
|
|
2062
2648
|
}
|
|
2063
|
-
for (const
|
|
2064
|
-
if (SKIP_DIRS.has(
|
|
2649
|
+
for (const entry of entries) {
|
|
2650
|
+
if (SKIP_DIRS.has(entry))
|
|
2065
2651
|
continue;
|
|
2066
|
-
const abs =
|
|
2652
|
+
const abs = join7(root, entry);
|
|
2067
2653
|
let s;
|
|
2068
2654
|
try {
|
|
2069
|
-
s =
|
|
2655
|
+
s = statSync2(abs);
|
|
2070
2656
|
} catch {
|
|
2071
2657
|
continue;
|
|
2072
2658
|
}
|
|
@@ -2092,7 +2678,7 @@ function resolveFileCandidate(base, knownFiles) {
|
|
|
2092
2678
|
return base + ext;
|
|
2093
2679
|
}
|
|
2094
2680
|
for (const ext of SOURCE_EXTENSIONS) {
|
|
2095
|
-
const indexed =
|
|
2681
|
+
const indexed = join7(base, `index${ext}`);
|
|
2096
2682
|
if (knownFiles.has(indexed))
|
|
2097
2683
|
return indexed;
|
|
2098
2684
|
}
|
|
@@ -2101,7 +2687,7 @@ function resolveFileCandidate(base, knownFiles) {
|
|
|
2101
2687
|
function resolveRelativeImport(fromFile, specifier, knownFiles) {
|
|
2102
2688
|
if (!specifier.startsWith("."))
|
|
2103
2689
|
return null;
|
|
2104
|
-
return resolveFileCandidate(
|
|
2690
|
+
return resolveFileCandidate(resolve6(dirname6(fromFile), specifier), knownFiles);
|
|
2105
2691
|
}
|
|
2106
2692
|
function isBunTestScript(script) {
|
|
2107
2693
|
if (!script)
|
|
@@ -2130,7 +2716,7 @@ function deriveEntrypoints(dir, pkg, knownFiles) {
|
|
|
2130
2716
|
for (const target of declaredTargets(value)) {
|
|
2131
2717
|
if (!target.startsWith("."))
|
|
2132
2718
|
return;
|
|
2133
|
-
const resolved = resolveFileCandidate(
|
|
2719
|
+
const resolved = resolveFileCandidate(resolve6(dir, target), knownFiles);
|
|
2134
2720
|
if (resolved)
|
|
2135
2721
|
files.add(resolved);
|
|
2136
2722
|
}
|
|
@@ -2150,10 +2736,10 @@ function deriveEntrypoints(dir, pkg, knownFiles) {
|
|
|
2150
2736
|
return out;
|
|
2151
2737
|
}
|
|
2152
2738
|
function discoverWorkspacePackages(repoRoot) {
|
|
2153
|
-
const rootPkgPath =
|
|
2739
|
+
const rootPkgPath = join7(repoRoot, "package.json");
|
|
2154
2740
|
let workspaces = [];
|
|
2155
2741
|
try {
|
|
2156
|
-
const rootPkg = JSON.parse(
|
|
2742
|
+
const rootPkg = JSON.parse(readFileSync4(rootPkgPath, "utf8"));
|
|
2157
2743
|
workspaces = rootPkg.workspaces ?? [];
|
|
2158
2744
|
} catch {
|
|
2159
2745
|
return [];
|
|
@@ -2163,19 +2749,19 @@ function discoverWorkspacePackages(repoRoot) {
|
|
|
2163
2749
|
const m = /^([^*]+)\*$/.exec(glob);
|
|
2164
2750
|
if (!m)
|
|
2165
2751
|
continue;
|
|
2166
|
-
const parentDir =
|
|
2752
|
+
const parentDir = join7(repoRoot, m[1].replace(/\/$/, ""));
|
|
2167
2753
|
let entries;
|
|
2168
2754
|
try {
|
|
2169
|
-
entries =
|
|
2755
|
+
entries = readdirSync2(parentDir);
|
|
2170
2756
|
} catch {
|
|
2171
2757
|
continue;
|
|
2172
2758
|
}
|
|
2173
|
-
for (const
|
|
2174
|
-
const dir =
|
|
2175
|
-
const pkgPath =
|
|
2759
|
+
for (const entry of entries) {
|
|
2760
|
+
const dir = join7(parentDir, entry);
|
|
2761
|
+
const pkgPath = join7(dir, "package.json");
|
|
2176
2762
|
let pkg;
|
|
2177
2763
|
try {
|
|
2178
|
-
pkg = JSON.parse(
|
|
2764
|
+
pkg = JSON.parse(readFileSync4(pkgPath, "utf8"));
|
|
2179
2765
|
} catch {
|
|
2180
2766
|
continue;
|
|
2181
2767
|
}
|
|
@@ -2223,10 +2809,10 @@ function parseExportTable(source) {
|
|
|
2223
2809
|
for (let m = EXPORT_BRACE_RE.exec(source);m !== null; m = EXPORT_BRACE_RE.exec(source)) {
|
|
2224
2810
|
const specifier = m[3];
|
|
2225
2811
|
for (const raw of m[1].split(",")) {
|
|
2226
|
-
const
|
|
2227
|
-
if (
|
|
2812
|
+
const entry = raw.trim().replace(/^type\s+/, "");
|
|
2813
|
+
if (entry.length === 0)
|
|
2228
2814
|
continue;
|
|
2229
|
-
const parts =
|
|
2815
|
+
const parts = entry.split(/\s+as\s+/);
|
|
2230
2816
|
const origin = parts[0].trim();
|
|
2231
2817
|
const exported = (parts[1] ?? parts[0]).trim();
|
|
2232
2818
|
if (!/^[A-Za-z_$][\w$]*$/.test(origin) || !/^[A-Za-z_$][\w$]*$/.test(exported))
|
|
@@ -2250,10 +2836,10 @@ function parseExportTable(source) {
|
|
|
2250
2836
|
const specifier = m[5];
|
|
2251
2837
|
if (m[1] !== undefined) {
|
|
2252
2838
|
for (const raw of m[1].split(",")) {
|
|
2253
|
-
const
|
|
2254
|
-
if (
|
|
2839
|
+
const entry = raw.trim().replace(/^type\s+/, "");
|
|
2840
|
+
if (entry.length === 0)
|
|
2255
2841
|
continue;
|
|
2256
|
-
const parts =
|
|
2842
|
+
const parts = entry.split(/\s+as\s+/);
|
|
2257
2843
|
const origin = parts[0].trim();
|
|
2258
2844
|
const local = (parts[1] ?? parts[0]).trim();
|
|
2259
2845
|
if (/^[A-Za-z_$][\w$]*$/.test(local))
|
|
@@ -2274,7 +2860,7 @@ function makeSourceReader() {
|
|
|
2274
2860
|
let cached = cache.get(file);
|
|
2275
2861
|
if (cached === undefined) {
|
|
2276
2862
|
try {
|
|
2277
|
-
cached =
|
|
2863
|
+
cached = readFileSync4(file, "utf8");
|
|
2278
2864
|
} catch {
|
|
2279
2865
|
cached = "";
|
|
2280
2866
|
}
|
|
@@ -2309,12 +2895,12 @@ function resolveExportedName(ctx, file, name, stack) {
|
|
|
2309
2895
|
ctx.resultCache.set(cacheKey, result);
|
|
2310
2896
|
return result;
|
|
2311
2897
|
}
|
|
2312
|
-
function resolveHopNames(ctx,
|
|
2898
|
+
function resolveHopNames(ctx, entry, names, stack) {
|
|
2313
2899
|
if (names.length === 0)
|
|
2314
2900
|
return null;
|
|
2315
2901
|
const deps = [];
|
|
2316
2902
|
for (const name of names) {
|
|
2317
|
-
const sub = resolveExportedName(ctx,
|
|
2903
|
+
const sub = resolveExportedName(ctx, entry, name, stack);
|
|
2318
2904
|
if (!sub.resolved)
|
|
2319
2905
|
return null;
|
|
2320
2906
|
for (const t of sub.touched)
|
|
@@ -2350,13 +2936,13 @@ function resolveThroughTable(ctx, file, name, table, stack) {
|
|
|
2350
2936
|
out.add(`${EXTERNAL_PREFIX}${pkg.name}`);
|
|
2351
2937
|
continue;
|
|
2352
2938
|
}
|
|
2353
|
-
const
|
|
2354
|
-
const precise = record.kind === "named" && record.clean ? resolveHopNames(ctx,
|
|
2939
|
+
const entry = pkg.entry;
|
|
2940
|
+
const precise = record.kind === "named" && record.clean ? resolveHopNames(ctx, entry, record.names, stack) : null;
|
|
2355
2941
|
if (precise)
|
|
2356
2942
|
for (const dep of precise)
|
|
2357
2943
|
out.add(dep);
|
|
2358
2944
|
else
|
|
2359
|
-
out.add(
|
|
2945
|
+
out.add(entry);
|
|
2360
2946
|
}
|
|
2361
2947
|
return out;
|
|
2362
2948
|
};
|
|
@@ -2407,11 +2993,12 @@ function resolveThroughTable(ctx, file, name, table, stack) {
|
|
|
2407
2993
|
hopDeps: new Set([...ownHopDeps(), ...only.hopDeps])
|
|
2408
2994
|
};
|
|
2409
2995
|
}
|
|
2996
|
+
var DEFAULT_CLI_ENTRYPOINT = "apps/cli/src/index.ts";
|
|
2410
2997
|
function selectAffectedTestFiles(repoRoot, changedFiles, options = {}) {
|
|
2411
2998
|
const packages = discoverWorkspacePackages(repoRoot);
|
|
2412
|
-
const absChanged = new Set(changedFiles.map((f) =>
|
|
2999
|
+
const absChanged = new Set(changedFiles.map((f) => isAbsolute4(f) ? f : join7(repoRoot, f)));
|
|
2413
3000
|
const alwaysRunRegexes = (options.alwaysRun ?? []).map(globToRegex);
|
|
2414
|
-
const addedOrRenamed = new Set((options.addedOrRenamed ?? []).map((f) =>
|
|
3001
|
+
const addedOrRenamed = new Set((options.addedOrRenamed ?? []).map((f) => isAbsolute4(f) ? f : join7(repoRoot, f)));
|
|
2415
3002
|
const readSource = makeSourceReader();
|
|
2416
3003
|
const tableCache = new Map;
|
|
2417
3004
|
const resultCache = new Map;
|
|
@@ -2473,8 +3060,8 @@ function selectAffectedTestFiles(repoRoot, changedFiles, options = {}) {
|
|
|
2473
3060
|
if (graphTypescript) {
|
|
2474
3061
|
const entrypoints = new Map;
|
|
2475
3062
|
for (const pkg of packages) {
|
|
2476
|
-
for (const [subpath,
|
|
2477
|
-
entrypoints.set(subpath === "." ? pkg.name : `${pkg.name}${subpath.slice(1)}`,
|
|
3063
|
+
for (const [subpath, entry] of pkg.entrypoints) {
|
|
3064
|
+
entrypoints.set(subpath === "." ? pkg.name : `${pkg.name}${subpath.slice(1)}`, entry);
|
|
2478
3065
|
}
|
|
2479
3066
|
}
|
|
2480
3067
|
const graph = buildCompilerGraph(graphTypescript, {
|
|
@@ -2510,14 +3097,14 @@ function selectAffectedTestFiles(repoRoot, changedFiles, options = {}) {
|
|
|
2510
3097
|
continue;
|
|
2511
3098
|
if (coarsePackages.has(match.pkg.name))
|
|
2512
3099
|
continue;
|
|
2513
|
-
const
|
|
2514
|
-
if (record.kind !== "named" || !record.clean || !
|
|
3100
|
+
const entry = match.pkg.entrypoints.get(match.subpath);
|
|
3101
|
+
if (record.kind !== "named" || !record.clean || !entry) {
|
|
2515
3102
|
coarsePackages.add(match.pkg.name);
|
|
2516
3103
|
continue;
|
|
2517
3104
|
}
|
|
2518
3105
|
let acc = resolvedNamed.get(match.pkg.name);
|
|
2519
3106
|
for (const name of record.names) {
|
|
2520
|
-
const resolution = resolveExportedName(ctx,
|
|
3107
|
+
const resolution = resolveExportedName(ctx, entry, name, new Set);
|
|
2521
3108
|
if (!resolution.resolved) {
|
|
2522
3109
|
coarsePackages.add(match.pkg.name);
|
|
2523
3110
|
acc = undefined;
|
|
@@ -2563,18 +3150,21 @@ function selectAffectedTestFiles(repoRoot, changedFiles, options = {}) {
|
|
|
2563
3150
|
}
|
|
2564
3151
|
}
|
|
2565
3152
|
}
|
|
2566
|
-
const
|
|
3153
|
+
const affectedNames = options.affectedNames ?? new Map;
|
|
2567
3154
|
const changeFacts = {
|
|
2568
3155
|
files: absChanged,
|
|
2569
3156
|
packages: changedPackageNames,
|
|
2570
3157
|
nonSourcePackages: nonSourceChangedPackages,
|
|
2571
3158
|
packageOfFile: (f) => fileToPackage.get(f) ?? null,
|
|
2572
3159
|
affects: (file, name) => {
|
|
2573
|
-
const affected =
|
|
3160
|
+
const affected = affectedNames.get(file) ?? affectedNames.get(file.startsWith(repoRoot) ? file.slice(repoRoot.length + 1) : file);
|
|
2574
3161
|
return affected === undefined || affected === "all" || affected.has(name);
|
|
2575
3162
|
}
|
|
2576
3163
|
};
|
|
2577
|
-
|
|
3164
|
+
const depthOneDefault = options.depth === "one" ? "ignore" : "select";
|
|
3165
|
+
const repoTreeScanners = options.repoTreeScanners ?? depthOneDefault;
|
|
3166
|
+
const cliSpawnDetection = options.cliSpawnDetection ?? depthOneDefault;
|
|
3167
|
+
if (typescript && repoTreeScanners !== "ignore") {
|
|
2578
3168
|
for (const file of allSourceFiles) {
|
|
2579
3169
|
if (!isTestFile(file))
|
|
2580
3170
|
continue;
|
|
@@ -2585,6 +3175,20 @@ function selectAffectedTestFiles(repoRoot, changedFiles, options = {}) {
|
|
|
2585
3175
|
edges.set(key, [...edges.get(key) ?? [], ...roots.map((r) => `${SCAN_PREFIX}${r}`)]);
|
|
2586
3176
|
}
|
|
2587
3177
|
}
|
|
3178
|
+
if (typescript && cliSpawnDetection !== "ignore") {
|
|
3179
|
+
const cliEntrypoint = join7(repoRoot, options.cliEntrypoint ?? DEFAULT_CLI_ENTRYPOINT);
|
|
3180
|
+
const cliEntrypointSourceRoot = dirname6(cliEntrypoint);
|
|
3181
|
+
for (const file of allSourceFiles) {
|
|
3182
|
+
if (!isTestFile(file))
|
|
3183
|
+
continue;
|
|
3184
|
+
const classification = cliSpawnEdgeOf(typescript, file, readSource(file), repoRoot, cliEntrypoint);
|
|
3185
|
+
if (!classification)
|
|
3186
|
+
continue;
|
|
3187
|
+
const key = `${ALL_PREFIX}${file}`;
|
|
3188
|
+
const edge = classification === "entrypoint" ? `${ALL_PREFIX}${cliEntrypoint}` : `${SCAN_PREFIX}${cliEntrypointSourceRoot}`;
|
|
3189
|
+
edges.set(key, [...edges.get(key) ?? [], edge]);
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
2588
3192
|
const anythingChanged = absChanged.size > 0 || changedPackageNames.size > 0;
|
|
2589
3193
|
const selected = [];
|
|
2590
3194
|
let totalTestFiles = 0;
|
|
@@ -2593,26 +3197,29 @@ function selectAffectedTestFiles(repoRoot, changedFiles, options = {}) {
|
|
|
2593
3197
|
totalTestFiles += testFiles.length;
|
|
2594
3198
|
if (!pkg.bunTestCompatible)
|
|
2595
3199
|
continue;
|
|
3200
|
+
const maxDepth = options.depth === "one" ? 1 : Number.POSITIVE_INFINITY;
|
|
2596
3201
|
for (const test of testFiles) {
|
|
2597
3202
|
const forced = alwaysRunRegexes.some((re) => re.test(test.slice(repoRoot.length + 1))) || addedOrRenamed.has(test);
|
|
2598
|
-
if (forced || anythingChanged && reaches(`${ALL_PREFIX}${test}`, edges, changeFacts)) {
|
|
3203
|
+
if (forced || anythingChanged && reaches(`${ALL_PREFIX}${test}`, edges, changeFacts, maxDepth)) {
|
|
2599
3204
|
selected.push(test);
|
|
2600
3205
|
}
|
|
2601
3206
|
}
|
|
2602
3207
|
}
|
|
2603
3208
|
return { selected, totalTestFiles, resolver: graphTypescript ? "compiler" : "text-scan", programMs };
|
|
2604
3209
|
}
|
|
2605
|
-
function reaches(start, edges, changed) {
|
|
3210
|
+
function reaches(start, edges, changed, maxDepth = Number.POSITIVE_INFINITY) {
|
|
2606
3211
|
const visited = new Set;
|
|
2607
|
-
const stack = [start];
|
|
3212
|
+
const stack = [[start, 0]];
|
|
2608
3213
|
while (stack.length > 0) {
|
|
2609
|
-
const current = stack.pop();
|
|
3214
|
+
const [current, depth] = stack.pop();
|
|
2610
3215
|
if (visited.has(current))
|
|
2611
3216
|
continue;
|
|
2612
3217
|
visited.add(current);
|
|
2613
3218
|
const currentFile = current.startsWith(ALL_PREFIX) ? current.slice(ALL_PREFIX.length) : current.startsWith(OWN_PREFIX) ? current.slice(OWN_PREFIX.length) : null;
|
|
2614
3219
|
if (current.startsWith(ALL_PREFIX) && currentFile && changed.files.has(currentFile))
|
|
2615
3220
|
return true;
|
|
3221
|
+
if (depth >= maxDepth)
|
|
3222
|
+
continue;
|
|
2616
3223
|
const ownPackage = currentFile ? changed.packageOfFile(currentFile) : null;
|
|
2617
3224
|
for (const dep of edges.get(current) ?? []) {
|
|
2618
3225
|
if (dep.startsWith(NAME_PREFIX)) {
|
|
@@ -2648,7 +3255,7 @@ function reaches(start, edges, changed) {
|
|
|
2648
3255
|
continue;
|
|
2649
3256
|
}
|
|
2650
3257
|
if (!visited.has(dep))
|
|
2651
|
-
stack.push(dep);
|
|
3258
|
+
stack.push([dep, depth + 1]);
|
|
2652
3259
|
}
|
|
2653
3260
|
}
|
|
2654
3261
|
return false;
|
|
@@ -2666,7 +3273,8 @@ function main() {
|
|
|
2666
3273
|
const { selected, totalTestFiles, resolver, programMs } = selectAffectedTestFiles(repoRoot, changed, {
|
|
2667
3274
|
alwaysRun,
|
|
2668
3275
|
addedOrRenamed,
|
|
2669
|
-
affectedNames: names
|
|
3276
|
+
affectedNames: names,
|
|
3277
|
+
depth: "one"
|
|
2670
3278
|
});
|
|
2671
3279
|
const elapsed = performance.now() - started;
|
|
2672
3280
|
for (const file of selected)
|