sumo-agents 0.7.1 → 0.8.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/src/verify.mjs CHANGED
@@ -5,8 +5,9 @@ import { join } from 'node:path';
5
5
  import { isSecretPath } from './guard.mjs';
6
6
  import { UsageError } from './memory.mjs';
7
7
  import { secretShape } from './redact.mjs';
8
+ import { ownGit } from './sandbox.mjs';
8
9
  import { readPlainFile, verifyCommands } from './scan.mjs';
9
- import { killGroup } from './tools.mjs';
10
+ import { digest, killGroup } from './tools.mjs';
10
11
 
11
12
  /**
12
13
  * A job's work, judged by running things rather than by reading the report.
@@ -44,7 +45,7 @@ const LOOKS_AWAY =
44
45
 
45
46
  function git(root, args) {
46
47
  try {
47
- return execFileSync('git', ['-C', root, '-c', 'core.quotePath=false', ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], maxBuffer: 64 * 1024 * 1024 });
48
+ return execFileSync('git', ['-C', root, '-c', 'core.quotePath=false', ...ownGit(args)], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], maxBuffer: 64 * 1024 * 1024 });
48
49
  } catch {
49
50
  return null;
50
51
  }
@@ -69,7 +70,7 @@ function hashesOf(root, files) {
69
70
  const there = files.filter((f) => !f.endsWith('/') && existsSync(join(root, f)));
70
71
  if (there.length === 0) return new Map();
71
72
  try {
72
- const out = execFileSync('git', ['-C', root, 'hash-object', '--stdin-paths'], { input: `${there.join('\n')}\n`, encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore'], maxBuffer: 64 * 1024 * 1024 });
73
+ const out = execFileSync('git', ['-C', root, ...ownGit(['hash-object', '--stdin-paths'])], { input: `${there.join('\n')}\n`, encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore'], maxBuffer: 64 * 1024 * 1024 });
73
74
  return new Map(out.split('\n').slice(0, there.length).map((hash, i) => [there[i], hash]));
74
75
  } catch {
75
76
  // One path git will not hash (a directory, an odd name) must not hide the others: they are asked one at a time.
@@ -129,14 +130,15 @@ function timeoutMs() {
129
130
  }
130
131
 
131
132
  /** The last lines of a check's log, read from its end rather than whole. */
132
- function tailOf(fd) {
133
+ function checkOutput(fd, failed) {
133
134
  const size = fstatSync(fd).size;
134
135
  const start = Math.max(0, size - OUTPUT_TAIL_BYTES);
135
136
  const bytes = Buffer.alloc(size - start);
136
137
  const lines = bytes.subarray(0, readSync(fd, bytes, 0, bytes.length, start)).toString('utf8').trimEnd().split('\n');
137
138
  // Read from inside a line, the first piece is half of one.
138
139
  if (start > 0 && lines.length > 1) lines.shift();
139
- return lines.slice(-OUTPUT_TAIL_LINES).join('\n');
140
+ const failures = (failed && start === 0 && namedFailures(lines)) || [];
141
+ return { output: lines.slice(-OUTPUT_TAIL_LINES).join('\n'), failures };
140
142
  }
141
143
 
142
144
  /** The sandbox a job's process hands down for its checks: the wrap's words, or null — none given, or one that is not a list of words. */
@@ -175,10 +177,10 @@ function runChecks(root, commands, dir, prefix) {
175
177
  const timedOut = run.error?.code === 'ETIMEDOUT';
176
178
  // Whatever it left running goes with it, so nothing writes to the file once it is read.
177
179
  killGroup(run.pid);
178
- const output = tailOf(into);
180
+ const { output, failures } = checkOutput(into, run.status !== 0);
179
181
  ftruncateSync(into);
180
182
  writeSync(into, `$ ${command}\n${output}\n${timedOut ? '\n(stopped: it ran past the time limit)\n' : ''}`, 0);
181
- return { name, command, ok: run.status === 0, status: run.status, timedOut, ms: Date.now() - started, file };
183
+ return { name, command, ok: run.status === 0, failures, status: run.status, timedOut, ms: Date.now() - started, file };
182
184
  } finally {
183
185
  closeSync(into);
184
186
  }
@@ -190,6 +192,88 @@ const FAILURE_LINE = /\b(?:fail(?:s|ed|ing|ures?)?|errors?|not ok)\b|[✗✕✖]
190
192
  /** A time a runner prints, which differs from one run to the next when nothing else does. */
191
193
  const TIMING = /\b\d+(?:\.\d+)?\s?m?s\b/g;
192
194
 
195
+ /** How long a named case took, after its name — `(0.84ms)`, `(5.1 s)`, vitest's bare `50ms`: it differs from one run to the next. */
196
+ const CASE_TIME = /\s*(?:\(\d+(?:\.\d+)?\s?m?s\)|\s\d+(?:\.\d+)?\s?m?s)$/;
197
+ const countOf = (line, pattern) => Number(pattern.exec(line)?.[1] ?? 0);
198
+ /** A runner's own count of what failed — a line that is never a name — and how many it says. */
199
+ const COUNTS = [
200
+ // pytest: `==== 1 failed, 2 passed, 1 error in 0.02s ====`, bare under -q.
201
+ [/^=*\s*\d+ (?:failed|passed|errors?|skipped|deselected|xfailed|xpassed|warnings?|rerun)\b.* in \d+(?:\.\d+)?s\b/, (l) => countOf(l, /(\d+) failed/) + countOf(l, /(\d+) errors?\b/)],
202
+ // unittest: `FAILED (failures=1, errors=1)`.
203
+ [/^FAILED \(\w+=\d+(?:, \w+=\d+)*\)$/, (l) => countOf(l, /\bfailures=(\d+)/) + countOf(l, /\berrors=(\d+)/)],
204
+ // jest `Tests: 1 failed, 1 passed`, vitest `Tests 1 failed | 1 passed`; node:test's spec and TAP; cargo, a line a target; mocha.
205
+ [/^Tests:?\s+\d+ failed\b/, (l) => countOf(l, /(\d+) failed/)],
206
+ [/^(?:ℹ|#) fail \d+$/, (l) => countOf(l, /(\d+)/)],
207
+ [/^test result: FAILED\./, (l) => countOf(l, /(\d+) failed/)],
208
+ [/^\d+ failing$/, (l) => countOf(l, /(\d+)/)],
209
+ ];
210
+
211
+ /**
212
+ * The cases a check's runner says failed, each under the file, target or package it printed it under — two tests called
213
+ * `works` in two files are two cases — or null when they cannot be compared: fewer named than the runner's own count, or
214
+ * a run it stopped before the rest of the suite ran, which hides whatever it never reached. A count is never a name.
215
+ */
216
+ function namedFailures(lines) {
217
+ const names = [];
218
+ let total = null;
219
+ // Where the cases that follow were printed: a cargo target, node's `test at <file>`. Go's are placed by the `FAIL<tab><package>`
220
+ // line that ends their package; node's spec reporter lists its failures again under their files, and that list names them.
221
+ let where = '';
222
+ let unplaced = [];
223
+ let listed = [];
224
+ let summary = false;
225
+ let tap = null;
226
+ let rerun = false;
227
+ let everyTarget = false;
228
+ for (const raw of lines) {
229
+ const line = raw.replace(/\x1b\[[0-9;]*m/g, '').trim();
230
+ if (/^!+ stopping after \d+ failures? !+$|^Interrupted: /.test(line)) return null;
231
+ if (/^error: test failed, to rerun pass\b/.test(line)) rerun = true;
232
+ if (/^error: \d+ targets? failed:$/.test(line)) everyTarget = true;
233
+ const count = COUNTS.find(([pattern]) => pattern.test(line));
234
+ if (count) {
235
+ total = (total ?? 0) + count[1](line);
236
+ continue;
237
+ }
238
+ let m;
239
+ if ((m = /^Running (?:unittests )?(\S+)/.exec(line) ?? /^(Doc-tests \S+)/.exec(line) ?? /^test at (.+?)(?::\d+)*$/.exec(line))) where = m[1];
240
+ else if ((m = /^location: '(.+?)(?::\d+)*'$/.exec(line))) {
241
+ if (tap !== null) names[tap] = `${m[1]} ${names[tap]}`;
242
+ tap = null;
243
+ } else if (/^✖ failing tests:$/.test(line)) [summary, listed] = [true, []];
244
+ else if ((m = /^--- FAIL: (.+)$/.exec(line))) unplaced.push(m[1].replace(CASE_TIME, ''));
245
+ else if ((m = /^FAIL\t(\S+)(?:\t\S+)?(?: (\[[^\]]+\]))?$/.exec(line))) {
246
+ names.push(...unplaced.map((name) => `${m[1]} ${name}`), [m[1], m[2]].filter(Boolean).join(' '));
247
+ unplaced = [];
248
+ } else if ((m = /^(FAILED|ERROR) (\S+\.py\b.*?)(?: - .*)?$/.exec(line) ?? /^(FAIL|ERROR): (.+)$/.exec(line))) names.push(`${m[1]} ${m[2]}`);
249
+ else if ((m = /^test (.+?) \.\.\. FAILED$/.exec(line))) names.push(`${where} ${m[1]}`.trim());
250
+ else if ((m = /^not ok(?: \d+)? - (.+)$/.exec(line))) tap = names.push(m[1].replace(CASE_TIME, '')) - 1;
251
+ else if ((m = /^(✖|[✗✕×●]|FAIL|FAILED) +(.+)$/.exec(line))) {
252
+ const name = m[2].replace(CASE_TIME, '').trim();
253
+ if (!name || /^\(?\w+=\d+(?:,\s*\w+=\d+)*\)?$|^\d+ (?:failed|failing|errors?|tests?)\b/.test(name)) continue;
254
+ if (m[1] !== '✖') names.push(name);
255
+ else if (summary) names.push(`${where} ${name}`.trim());
256
+ else listed.push(name);
257
+ }
258
+ }
259
+ if (rerun && !everyTarget) return null;
260
+ names.push(...unplaced, ...listed);
261
+ if (total !== null && names.length < total) return null;
262
+ return names.map(digest);
263
+ }
264
+
265
+ /** A new failure must not be forgiven just because the same command was red before. Count duplicate case names as well. */
266
+ function explainedBy(current, previous) {
267
+ if (!previous?.failures?.length || !current.failures.length || current.timedOut || previous.timedOut || previous.status !== current.status) return false;
268
+ const counts = new Map();
269
+ for (const name of previous.failures) counts.set(name, (counts.get(name) ?? 0) + 1);
270
+ for (const name of current.failures) {
271
+ if (!counts.get(name)) return false;
272
+ counts.set(name, counts.get(name) - 1);
273
+ }
274
+ return true;
275
+ }
276
+
193
277
  /** How a run of a check ended: its exit status and the lines that name a failure, without their times. Two runs that agree on it failed the same way. */
194
278
  const endedAs = (run) =>
195
279
  `${run.status}\n${[...new Set(readFileSync(run.file, 'utf8').split('\n').filter((l) => FAILURE_LINE.test(l)).map((l) => l.replace(TIMING, '').trim()))].sort().join('\n')}`;
@@ -224,7 +308,12 @@ export function takeBaseline(root, snap, dir) {
224
308
  }
225
309
  const checks = runChecks(root, verifyCommands(root), dir, 'baseline');
226
310
  const again = runAgain(root, checks.filter((c) => !c.ok), dir);
227
- return { checks: checks.map((c) => (again.has(c) && endedAs(again.get(c)) !== endedAs(c) ? { ...c, flaky: true, again: again.get(c).file } : c)) };
311
+ return { checks: checks.map((check) => {
312
+ const repeat = again.get(check);
313
+ if (!repeat || endedAs(repeat) === endedAs(check)) return check;
314
+ const { status, failures, timedOut } = repeat;
315
+ return { ...check, flaky: true, again: repeat.file, repeat: { status, failures, timedOut } };
316
+ }) };
228
317
  }
229
318
 
230
319
  /**
@@ -269,6 +358,7 @@ export function verify(root, { snap, baseline, testsMayChange, declared }, dir,
269
358
  const blocking = [];
270
359
  const flags = [];
271
360
  const notes = [];
361
+ const inconclusive = [];
272
362
  const beforeChecks = snap && stillThere(root, snap) ? changesSince(root, snap).fingerprint : null;
273
363
 
274
364
  // The checks that judged the start judge the end: one no longer run, or rewritten, is not part of the change.
@@ -286,11 +376,15 @@ export function verify(root, { snap, baseline, testsMayChange, declared }, dir,
286
376
  const before = new Map((baseline ?? []).map((c) => [c.command, c]));
287
377
  const ran = runChecks(root, commands, dir, 'verify');
288
378
  // One that passed when the job began and fails now is run once more before it is held against the job: passing then, it is flaky.
289
- // One recorded flaky at the start is not run again: whatever it says, it does not refuse DONE on its own.
379
+ // A baseline failure can explain only failures actually observed in its recorded runs.
290
380
  const again = runAgain(root, ran.filter((c) => !c.ok && before.get(c.command)?.ok), dir);
291
381
  const checks = ran.map((c) => {
292
382
  const was = before.get(c.command);
293
- const state = c.ok ? 'pass' : was?.flaky || again.get(c)?.ok ? 'flaky' : was && !was.ok ? 'already-failing' : 'fail';
383
+ let state = c.ok ? 'pass' : 'fail';
384
+ if (!c.ok && again.get(c)?.ok) state = 'flaky';
385
+ if (!c.ok && was && !was.ok && (explainedBy(c, was) || explainedBy(c, was.repeat))) {
386
+ state = was.flaky ? 'flaky' : 'already-failing';
387
+ }
294
388
  if (state === 'flaky') {
295
389
  flags.push(
296
390
  was.flaky
@@ -298,10 +392,16 @@ export function verify(root, { snap, baseline, testsMayChange, declared }, dir,
298
392
  : `\`${c.command}\` failed, then passed when run again — flaky, so DONE is not refused on it; read ${c.file}`,
299
393
  );
300
394
  }
395
+ if (state === 'fail' && was && !was.ok && !c.timedOut && (!c.failures.length || !was.failures?.length)) {
396
+ state = 'inconclusive';
397
+ inconclusive.push(`\`${c.command}\` failed, but its failing cases could not be compared; see ${was.file} and ${c.file}`);
398
+ }
301
399
  if (state === 'fail') {
302
400
  const why = c.timedOut ? 'ran past the time limit' : 'fails';
303
401
  blocking.push(
304
- was
402
+ was && !was.ok
403
+ ? `\`${c.command}\` ${why} with a new failure or one the baseline cannot identify; compare ${was.file} with ${c.file}`
404
+ : was
305
405
  ? `\`${c.command}\` ${why}, and it passed when this job began — read ${c.file}`
306
406
  : `\`${c.command}\` ${why}, and no baseline was taken before the work, so the failure counts as this job's — read ${c.file}`,
307
407
  );
@@ -310,7 +410,7 @@ export function verify(root, { snap, baseline, testsMayChange, declared }, dir,
310
410
  if (state === 'already-failing') flags.push(`\`${c.command}\` was already failing when this job began; compare ${was.file} with ${c.file} to see nothing new broke`);
311
411
  return { name: c.name, command: c.command, state, file: c.file };
312
412
  });
313
- if (checks.length === 0) notes.push('this project declares no check, test, lint or typecheck command — nothing was run');
413
+ if (checks.length === 0) inconclusive.push('this project declares no check, test, lint or typecheck command — nothing was run');
314
414
 
315
415
  let fingerprint = null;
316
416
  if (snap && !stillThere(root, snap)) {
@@ -338,7 +438,7 @@ export function verify(root, { snap, baseline, testsMayChange, declared }, dir,
338
438
  notes.push('not a git repository — what changed, and whether existing tests were touched, could not be checked');
339
439
  }
340
440
 
341
- return { at: now, ok: blocking.length === 0, fingerprint, checks, blocking, flags, notes };
441
+ return { version: 2, at: now, ok: blocking.length === 0 && inconclusive.length === 0, fingerprint, checks, blocking, inconclusive, flags, notes };
342
442
  }
343
443
 
344
444
  /** git's own summary of what changed in tracked files since the snapshot: a line a file, at most `count` of them, then its totals. Empty when git cannot say. */
@@ -362,7 +462,7 @@ export function writeChanges(root, snap, file) {
362
462
  // What git never tracked has no earlier side to show: a new file, and one changed outside git, are given whole.
363
463
  for (const created of [...changes.created, ...outside.filter((c) => c.status === 'M').map((c) => c.path)]) {
364
464
  // `--no-index` exits 1 when the files differ, which is every time; the diff is on stdout either way.
365
- const run = spawnSync('git', ['-C', root, '-c', 'core.quotePath=false', ...DIFF, '--no-index', '--', '/dev/null', created], { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
465
+ const run = spawnSync('git', ['-C', root, '-c', 'core.quotePath=false', ...ownGit([...DIFF, '--no-index', '--', '/dev/null', created])], { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
366
466
  parts.push(run.stdout?.trimEnd() ?? '');
367
467
  }
368
468
  writeFileSync(file, `${parts.filter(Boolean).join('\n')}\n`, { mode: 0o600 });
@@ -371,9 +471,10 @@ export function writeChanges(root, snap, file) {
371
471
 
372
472
  /** One line per check, for a status line or a report. */
373
473
  export function verdictLines(verdict) {
374
- const words = { pass: 'passed', fail: 'FAILED', 'already-failing': 'was already failing', flaky: 'was flaky' };
474
+ const words = { pass: 'passed', fail: 'FAILED', 'already-failing': 'was already failing', flaky: 'was flaky', inconclusive: 'was inconclusive' };
375
475
  return [
376
476
  ...verdict.checks.map((c) => `\`${c.command}\` ${words[c.state]}`),
477
+ ...(verdict.inconclusive ?? []).map((reason) => `unverified: ${reason}`),
377
478
  ...verdict.blocking.map((b) => `blocking: ${b}`),
378
479
  ...verdict.flags.map((f) => `look at: ${f}`),
379
480
  ...verdict.notes.map((n) => `note: ${n}`),
package/src/worktree.mjs CHANGED
@@ -1,6 +1,8 @@
1
1
  import { execFileSync, spawnSync } from 'node:child_process';
2
- import { copyFileSync, cpSync, lstatSync, mkdirSync, rmSync, statSync, symlinkSync } from 'node:fs';
3
- import { dirname, join } from 'node:path';
2
+ import { copyFileSync, cpSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, rmSync, statSync, symlinkSync } from 'node:fs';
3
+ import { dirname, isAbsolute, join, relative, sep } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { ownGit } from './sandbox.mjs';
4
6
  import { DIFF } from './verify.mjs';
5
7
 
6
8
  /**
@@ -9,13 +11,13 @@ import { DIFF } from './verify.mjs';
9
11
  * branches, and what the work changed is brought back to the project at the end. Nothing here knows about jobs.
10
12
  */
11
13
 
12
- /** Sumo's own git calls: no hook of the user's runs, nothing is signed, and a commit has an author where git has no identity. */
13
- const OWN = ['-c', 'core.hooksPath=/dev/null', '-c', 'commit.gpgsign=false', '-c', 'user.name=sumo', '-c', 'user.email=sumo@localhost'];
14
+ /** Sumo's own git calls: nothing the project's git files name runs (`ownGit`), nothing is signed, and a commit has an author where git has no identity. */
15
+ const OWN = ['-c', 'commit.gpgsign=false', '-c', 'user.name=sumo', '-c', 'user.email=sumo@localhost'];
14
16
 
15
- const git = (root, args) => execFileSync('git', ['-C', root, ...OWN, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 256 * 1024 * 1024 }).trim();
17
+ const git = (root, args) => execFileSync('git', ['-C', root, ...OWN, ...ownGit(args)], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 256 * 1024 * 1024 }).trim();
16
18
  /** How a git command that reads a patch on stdin went: whether it succeeded, and the first lines of what it said, on one line. */
17
19
  const fed = (root, args, patch, env = {}) => {
18
- const run = spawnSync('git', ['-C', root, ...OWN, ...args], { input: patch, env: { ...process.env, ...env }, stdio: ['pipe', 'ignore', 'pipe'], encoding: 'utf8' });
20
+ const run = spawnSync('git', ['-C', root, ...OWN, ...ownGit(args)], { input: patch, env: { ...process.env, ...env }, stdio: ['pipe', 'ignore', 'pipe'], encoding: 'utf8' });
19
21
  return { ok: run.status === 0, said: (run.stderr ?? '').split('\n').map((l) => l.trim()).filter(Boolean).slice(0, 3).join('; ') };
20
22
  };
21
23
  /** The paths a NUL-separated git listing names. */
@@ -74,10 +76,93 @@ export function makeTree(root, top) {
74
76
  return { top, path, prefix, base: git(top, ['rev-parse', 'HEAD']), linked };
75
77
  }
76
78
 
79
+ const within = (root, path) => {
80
+ const rel = relative(root, path);
81
+ return rel !== '..' && !rel.startsWith('..' + sep) && !isAbsolute(rel);
82
+ };
83
+ /** Where a path leads, or null for a link to nothing: that loads nothing, so it is no one's source. */
84
+ const realOrNull = (path) => {
85
+ try {
86
+ return realpathSync(path);
87
+ } catch (cause) {
88
+ if (cause.code === 'ENOENT') return null;
89
+ throw cause;
90
+ }
91
+ };
92
+
93
+ /** Inspect package-manager links, including scoped packages and pnpm's virtual store. */
94
+ function nodeLoadsOriginal(modules, repository, candidate) {
95
+ const installed = realpathSync(modules);
96
+ const queue = [modules];
97
+ const seen = new Set();
98
+ while (queue.length) {
99
+ const dir = queue.pop();
100
+ const real = realpathSync(dir);
101
+ if (seen.has(real)) continue;
102
+ seen.add(real);
103
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
104
+ const path = join(dir, entry.name);
105
+ if (entry.name === '.pnpm' && entry.isDirectory()) {
106
+ for (const name of readdirSync(path)) if (isDir(join(path, name, 'node_modules'))) queue.push(join(path, name, 'node_modules'));
107
+ } else if (entry.name.startsWith('@') && entry.isDirectory()) queue.push(path);
108
+ else if (entry.isSymbolicLink()) {
109
+ const target = realOrNull(path);
110
+ if (target && within(repository, target) && !within(installed, target) && !within(candidate, target)) return true;
111
+ } else if (entry.isDirectory() && isDir(join(path, 'node_modules'))) queue.push(join(path, 'node_modules'));
112
+ }
113
+ }
114
+ return false;
115
+ }
116
+
117
+ /** Common editable-install formats: PEP 610/660 metadata, path-based .pth files and legacy egg links — each judged by where it points. */
118
+ function pythonLoadsOriginal(env, repository, candidate) {
119
+ function loadsOriginal(path) {
120
+ const target = realOrNull(path);
121
+ return target !== null && within(repository, target) && !within(candidate, target);
122
+ }
123
+ const lib = join(env, 'lib');
124
+ const sites = [join(env, 'Lib', 'site-packages')];
125
+ if (isDir(lib)) for (const name of readdirSync(lib)) sites.push(join(lib, name, 'site-packages'));
126
+ for (const site of sites.filter(isDir)) {
127
+ for (const name of readdirSync(site)) {
128
+ const file = join(site, name);
129
+ if (name.endsWith('.egg-link') || name.endsWith('.pth')) {
130
+ for (const line of readFileSync(file, 'utf8').split(/\r?\n/)) {
131
+ const path = line.trim();
132
+ if (isAbsolute(path) && taken(path) && loadsOriginal(path)) return true;
133
+ }
134
+ }
135
+ if (name.endsWith('.dist-info') && taken(join(file, 'direct_url.json'))) {
136
+ const metadata = JSON.parse(readFileSync(join(file, 'direct_url.json'), 'utf8'));
137
+ if (metadata.dir_info?.editable && metadata.url?.startsWith('file:') && loadsOriginal(fileURLToPath(metadata.url))) return true;
138
+ }
139
+ }
140
+ }
141
+ return false;
142
+ }
143
+
144
+ /** An isolated job cannot be graded using source reached through the original checkout's installed dependencies. */
145
+ export function sharedSourceDependencies(tree, project) {
146
+ if (!tree) return [];
147
+ const shared = [];
148
+ for (const name of DEPENDENCIES) {
149
+ const dependency = join(tree.path, name);
150
+ if (!taken(dependency)) continue;
151
+ try {
152
+ const candidate = realpathSync(tree.top);
153
+ const repository = realpathSync(git(project, ['rev-parse', '--show-toplevel']));
154
+ if (name === 'node_modules' ? nodeLoadsOriginal(dependency, repository, candidate) : pythonLoadsOriginal(dependency, repository, candidate)) shared.push(name);
155
+ } catch {
156
+ shared.push(name); // Unreadable installation or link: its source cannot be verified.
157
+ }
158
+ }
159
+ return shared;
160
+ }
161
+
77
162
  /** Everything changed in the tree since it was made, new files included, as git itself writes a diff: with `binary`, whole enough to apply. */
78
163
  export function treeDiff({ top, prefix, base }, { binary = false } = {}) {
79
164
  git(top, ['add', '-A']);
80
- return execFileSync('git', ['-C', top, ...DIFF, '--cached', ...(binary ? ['--binary'] : []), base, '--', prefix || '.'], {
165
+ return execFileSync('git', ['-C', top, ...ownGit([...DIFF, '--cached', ...(binary ? ['--binary'] : []), base, '--', prefix || '.'])], {
81
166
  encoding: binary ? 'buffer' : 'utf8',
82
167
  stdio: ['ignore', 'pipe', 'ignore'],
83
168
  maxBuffer: 256 * 1024 * 1024,
@@ -91,8 +176,7 @@ export function treeDiff({ top, prefix, base }, { binary = false } = {}) {
91
176
  * unless a file it touches has edits not staged in the project: git refuses a three-way merge over those, whatever the trial
92
177
  * said. `scratch` is a folder of sumo's own for that copy. Not applied, `why` is what git said.
93
178
  */
94
- export function bringBack(root, tree, scratch) {
95
- const patch = treeDiff(tree, { binary: true });
179
+ export function bringBack(root, tree, scratch, patch = treeDiff(tree, { binary: true })) {
96
180
  if (patch.length === 0) return { applied: false, empty: true };
97
181
  const at = git(root, ['rev-parse', '--show-toplevel']);
98
182
  const plain = fed(at, ['apply', '--whitespace=nowarn'], patch);