devcontour-harness 0.1.0-alpha.26 → 0.1.0-alpha.28
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 +15 -2
- package/docs/architecture.md +59 -0
- package/docs/compatibility.md +25 -12
- package/docs/connectors.md +5 -2
- package/docs/contracts.md +80 -25
- package/docs/release-notes/0.1.0-alpha.27.md +36 -0
- package/docs/release-notes/0.1.0-alpha.28.md +37 -0
- package/docs/review-protocol.md +10 -4
- package/docs/toolchains.md +83 -0
- package/docs/upgrade.md +22 -0
- package/lib/cli.js +13 -0
- package/lib/contracts/cli.d.ts +147 -19
- package/lib/contracts/cli.js +66 -0
- package/lib/contracts/diagnosis.d.ts +1 -1
- package/lib/contracts/events.d.ts +6 -6
- package/lib/contracts/execution.d.ts +268 -16
- package/lib/contracts/execution.js +3 -1
- package/lib/contracts/policy.d.ts +37 -5
- package/lib/contracts/policy.js +42 -2
- package/lib/contracts/profiles.d.ts +2 -0
- package/lib/contracts/published.d.ts +226 -20
- package/lib/contracts/result.d.ts +268 -12
- package/lib/contracts/result.js +66 -0
- package/lib/control/harness.d.ts +64 -7
- package/lib/control/harness.js +4 -0
- package/lib/control/recovery.d.ts +1 -1
- package/lib/control/review.js +6 -1
- package/lib/engine/engine.d.ts +117 -12
- package/lib/engine/joint-runner.d.ts +96 -6
- package/lib/engine/joint-runner.js +47 -1
- package/lib/engine/runner.d.ts +29 -0
- package/lib/engine/runner.js +200 -2
- package/lib/engine/worktree-cleanup.d.ts +131 -0
- package/lib/engine/worktree-cleanup.js +520 -0
- package/lib/environment/isolation.d.ts +1 -0
- package/lib/environment/isolation.js +2 -1
- package/lib/environment/os-tools.d.ts +4 -2
- package/lib/environment/os-tools.js +4 -2
- package/lib/environment/process.d.ts +5 -0
- package/lib/environment/process.js +40 -17
- package/lib/environment/resources.d.ts +9 -0
- package/lib/environment/resources.js +24 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/integrations/connector/commands.d.ts +2 -1
- package/lib/integrations/connector/commands.js +10 -2
- package/lib/integrations/connector/store.d.ts +1 -1
- package/lib/integrations/connector/store.js +11 -6
- package/lib/profiles/resolve.d.ts +8 -0
- package/lib/storage/document.d.ts +132 -12
- package/lib/toolchains/inspect.d.ts +1 -1
- package/lib/toolchains/inspect.js +29 -1
- package/lib/toolchains/probe.d.ts +16 -0
- package/lib/toolchains/probe.js +20 -0
- package/lib/verification/confirm.d.ts +3 -1
- package/lib/verification/confirm.js +16 -2
- package/lib/verification/dependencies.d.ts +3 -0
- package/lib/verification/dependencies.js +11 -0
- package/lib/verification/dependency-store.d.ts +117 -0
- package/lib/verification/dependency-store.js +811 -0
- package/lib/verification/gate-artifacts.d.ts +34 -0
- package/lib/verification/gate-artifacts.js +303 -0
- package/lib/verification/gates-at.js +18 -0
- package/lib/verification/gates.js +15 -0
- package/lib/verification/joint.d.ts +48 -3
- package/package.json +1 -1
- package/schemas/execution-document.schema.json +372 -0
- package/schemas/execution-policy.schema.json +56 -0
- package/schemas/joint-verification.schema.json +279 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { gateArtifactLimits, type GateArtifactFiles } from '../contracts/index.ts';
|
|
2
|
+
import type { Redactor } from '../environment/redaction.ts';
|
|
3
|
+
type Limits = {
|
|
4
|
+
-readonly [K in keyof typeof gateArtifactLimits]: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Сохранить artifacts gate в `dest` и описать результат для evidence.
|
|
8
|
+
*
|
|
9
|
+
* Пути — относительно корня дерева `root`; каталог обходится в порядке имён
|
|
10
|
+
* в пределах `scan` записей. Ссылки не разыменовываются ни в объявленном
|
|
11
|
+
* пути, ни в его компонентах, ни внутри каталога: такой путь записывается как
|
|
12
|
+
* `symlink`. Копируются только обычные файлы с одной жёсткой ссылкой и с
|
|
13
|
+
* разрешёнными расширениями в пределах `gateArtifactLimits`; файл,
|
|
14
|
+
* разрешающийся перед чтением вне дерева, не
|
|
15
|
+
* копируется. Всё прочее и всякий отказ чтения или записи записываются в
|
|
16
|
+
* `skipped` с причиной. Функция не бросает: исход gate от сохранения не
|
|
17
|
+
* зависит, а отказ сохранения остаётся в evidence.
|
|
18
|
+
*
|
|
19
|
+
* `dest` принадлежит harness: прежние копии того же gate удаляются, чтобы
|
|
20
|
+
* они не выдали себя за результат этого запуска. Каталог, совпадающий с
|
|
21
|
+
* деревом, содержащий его или лежащий внутри него, отклоняется до удаления.
|
|
22
|
+
*/
|
|
23
|
+
export declare function keepGateArtifacts(options: {
|
|
24
|
+
root: string;
|
|
25
|
+
paths: readonly string[];
|
|
26
|
+
dest: string;
|
|
27
|
+
redact: Redactor;
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
/** Только для тестов: меньшие пределы. */
|
|
30
|
+
limits?: Partial<Limits>;
|
|
31
|
+
/** Только для тестов: вызывается перед посещением каждого пути. */
|
|
32
|
+
beforeVisit?: (rel: string) => Promise<void> | void;
|
|
33
|
+
}): Promise<GateArtifactFiles>;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import { lstat, mkdir, open, opendir, realpath, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { basename, dirname, extname, join, resolve, sep } from 'node:path';
|
|
4
|
+
import { gateArtifactExtensions, gateArtifactLimits, sha256, } from "../contracts/index.js";
|
|
5
|
+
/** Текстовые расширения: в копии маскируются секреты окружения, как в логе gate. */
|
|
6
|
+
const textExtensions = new Set(['.json', '.txt', '.xml', '.log']);
|
|
7
|
+
const allowed = new Set(gateArtifactExtensions);
|
|
8
|
+
const message = (error) => (error instanceof Error ? error.message : String(error));
|
|
9
|
+
const inside = (path, root) => path.startsWith(root + sep);
|
|
10
|
+
/** Реальный путь, даже если хвоста ещё нет: ближайший существующий предок разрешается. */
|
|
11
|
+
async function realTarget(path) {
|
|
12
|
+
const absolute = resolve(path);
|
|
13
|
+
try {
|
|
14
|
+
return await realpath(absolute);
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (error.code !== 'ENOENT')
|
|
18
|
+
throw error;
|
|
19
|
+
const parent = dirname(absolute);
|
|
20
|
+
if (parent === absolute)
|
|
21
|
+
throw error;
|
|
22
|
+
return join(await realTarget(parent), basename(absolute));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Секрет в байтах не текстового файла. Изображение не переписывается (маска
|
|
27
|
+
* испортила бы его), поэтому такой файл не копируется. Формы секрета — те же,
|
|
28
|
+
* что маскирует redactor (`secrets`); у redactor без них — его же проверка
|
|
29
|
+
* по байтам, прочитанным как UTF-8 и как latin1.
|
|
30
|
+
*/
|
|
31
|
+
function binaryHasSecret(bytes, redact) {
|
|
32
|
+
if (redact.secrets)
|
|
33
|
+
return redact.secrets.some((secret) => secret.length > 0 &&
|
|
34
|
+
(bytes.includes(Buffer.from(secret, 'utf8')) ||
|
|
35
|
+
bytes.includes(Buffer.from(secret, 'utf16le'))));
|
|
36
|
+
for (const encoding of ['utf8', 'latin1']) {
|
|
37
|
+
const text = bytes.toString(encoding);
|
|
38
|
+
if (redact(text) !== text)
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
const marker = Buffer.from('[REDACTED]');
|
|
44
|
+
/**
|
|
45
|
+
* Маска секретов в байтах текстового файла; `undefined` — секретов нет. По
|
|
46
|
+
* списку форм redactor замена идёт по байтам: невалидный UTF-8 вокруг секрета
|
|
47
|
+
* остаётся как был. Redactor без списка применяется к тексту UTF-8.
|
|
48
|
+
*/
|
|
49
|
+
function maskText(bytes, redact) {
|
|
50
|
+
if (!redact.secrets) {
|
|
51
|
+
const text = bytes.toString('utf8');
|
|
52
|
+
const masked = redact(text);
|
|
53
|
+
return masked === text ? undefined : Buffer.from(masked);
|
|
54
|
+
}
|
|
55
|
+
let out = bytes, changed = false;
|
|
56
|
+
for (const secret of redact.secrets) {
|
|
57
|
+
if (!secret)
|
|
58
|
+
continue;
|
|
59
|
+
const needle = Buffer.from(secret, 'utf8');
|
|
60
|
+
const parts = [];
|
|
61
|
+
let from = 0;
|
|
62
|
+
for (let at = out.indexOf(needle); at >= 0; at = out.indexOf(needle, from)) {
|
|
63
|
+
parts.push(out.subarray(from, at), marker);
|
|
64
|
+
from = at + needle.length;
|
|
65
|
+
}
|
|
66
|
+
if (!parts.length)
|
|
67
|
+
continue;
|
|
68
|
+
parts.push(out.subarray(from));
|
|
69
|
+
out = Buffer.concat(parts);
|
|
70
|
+
changed = true;
|
|
71
|
+
}
|
|
72
|
+
return changed ? out : undefined;
|
|
73
|
+
}
|
|
74
|
+
/** Объявленные пути без повторов и без путей внутри уже объявленного каталога. */
|
|
75
|
+
function declaredRoots(paths) {
|
|
76
|
+
const unique = [...new Set(paths.map((p) => p.replace(/\/+$/, '')))];
|
|
77
|
+
return unique.filter((p) => !unique.some((other) => other !== p && p.startsWith(other + '/')));
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Сохранить artifacts gate в `dest` и описать результат для evidence.
|
|
81
|
+
*
|
|
82
|
+
* Пути — относительно корня дерева `root`; каталог обходится в порядке имён
|
|
83
|
+
* в пределах `scan` записей. Ссылки не разыменовываются ни в объявленном
|
|
84
|
+
* пути, ни в его компонентах, ни внутри каталога: такой путь записывается как
|
|
85
|
+
* `symlink`. Копируются только обычные файлы с одной жёсткой ссылкой и с
|
|
86
|
+
* разрешёнными расширениями в пределах `gateArtifactLimits`; файл,
|
|
87
|
+
* разрешающийся перед чтением вне дерева, не
|
|
88
|
+
* копируется. Всё прочее и всякий отказ чтения или записи записываются в
|
|
89
|
+
* `skipped` с причиной. Функция не бросает: исход gate от сохранения не
|
|
90
|
+
* зависит, а отказ сохранения остаётся в evidence.
|
|
91
|
+
*
|
|
92
|
+
* `dest` принадлежит harness: прежние копии того же gate удаляются, чтобы
|
|
93
|
+
* они не выдали себя за результат этого запуска. Каталог, совпадающий с
|
|
94
|
+
* деревом, содержащий его или лежащий внутри него, отклоняется до удаления.
|
|
95
|
+
*/
|
|
96
|
+
export async function keepGateArtifacts(options) {
|
|
97
|
+
const { redact, signal } = options;
|
|
98
|
+
const paths = declaredRoots(options.paths);
|
|
99
|
+
const limits = { ...gateArtifactLimits, ...options.limits };
|
|
100
|
+
const files = [];
|
|
101
|
+
const skipped = [];
|
|
102
|
+
let skippedMore = 0, total = 0, scanned = 0, stopped = false;
|
|
103
|
+
const skip = (path, reason, detail) => {
|
|
104
|
+
if (skipped.length >= limits.skipped) {
|
|
105
|
+
skippedMore++;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
skipped.push({
|
|
109
|
+
path: redact(path).slice(0, 1000) || '.',
|
|
110
|
+
reason,
|
|
111
|
+
...(detail ? { detail: redact(detail).slice(0, 500) } : {}),
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
const done = () => ({ dir: dest, files, skipped, ...(skippedMore ? { skippedMore } : {}) });
|
|
115
|
+
let root, dest = resolve(options.dest);
|
|
116
|
+
// Отменённый запуск не трогает и прежние копии: удалять их уже незачем.
|
|
117
|
+
if (signal?.aborted) {
|
|
118
|
+
for (const path of paths)
|
|
119
|
+
skip(path, 'copy-failed', 'проверка отменена');
|
|
120
|
+
return done();
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
root = await realpath(options.root);
|
|
124
|
+
// Удаляется только свой каталог копий: никогда не дерево, не его предок и
|
|
125
|
+
// не каталог внутри него. Сравниваются реальные пути (/var и /private/var).
|
|
126
|
+
dest = await realTarget(options.dest);
|
|
127
|
+
if (dest === root || inside(root, dest) || inside(dest, root))
|
|
128
|
+
throw new Error('каталог копий artifacts пересекается с деревом проверки');
|
|
129
|
+
await rm(dest, { recursive: true, force: true });
|
|
130
|
+
await mkdir(dest, { recursive: true });
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
for (const path of paths)
|
|
134
|
+
skip(path, 'copy-failed', message(error));
|
|
135
|
+
return done();
|
|
136
|
+
}
|
|
137
|
+
const read = async (abs) => {
|
|
138
|
+
// Каталог-предок мог быть подменён ссылкой после обхода: копия берётся
|
|
139
|
+
// только из пути, который и сейчас разрешается внутрь дерева. Между этой
|
|
140
|
+
// проверкой и open остаётся окно гонки: без openat его не закрыть по пути.
|
|
141
|
+
// Его может использовать только процесс, переживший gate; потомков gate
|
|
142
|
+
// harness завершает до копирования (см. docs/contracts.md).
|
|
143
|
+
const real = await realpath(abs);
|
|
144
|
+
if (!inside(real, root))
|
|
145
|
+
return 'outside';
|
|
146
|
+
const handle = await open(real, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
147
|
+
try {
|
|
148
|
+
const stat = await handle.stat();
|
|
149
|
+
if (!stat.isFile())
|
|
150
|
+
return 'not-regular';
|
|
151
|
+
// Жёсткая ссылка на файл вне дерева неотличима от своего файла по пути.
|
|
152
|
+
if (stat.nlink > 1)
|
|
153
|
+
return 'hardlink';
|
|
154
|
+
if (stat.size > limits.fileBytes)
|
|
155
|
+
return 'file-limit';
|
|
156
|
+
const buffer = Buffer.allocUnsafe(Math.min(stat.size, limits.fileBytes) + 1);
|
|
157
|
+
let size = 0;
|
|
158
|
+
for (;;) {
|
|
159
|
+
const { bytesRead } = await handle.read(buffer, size, buffer.length - size);
|
|
160
|
+
if (!bytesRead)
|
|
161
|
+
break;
|
|
162
|
+
size += bytesRead;
|
|
163
|
+
if (size > limits.fileBytes)
|
|
164
|
+
return 'file-limit';
|
|
165
|
+
// Файл вырос после stat: копия была бы не тем, что описано.
|
|
166
|
+
if (size === buffer.length)
|
|
167
|
+
throw new Error('файл изменился при чтении');
|
|
168
|
+
}
|
|
169
|
+
return Buffer.from(buffer.subarray(0, size));
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
await handle.close();
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
const copy = async (rel, abs) => {
|
|
176
|
+
if (!allowed.has(extname(rel).toLowerCase()))
|
|
177
|
+
return skip(rel, 'extension');
|
|
178
|
+
// Имя копии на диске равно пути в evidence: путь с секретом не сохраняется.
|
|
179
|
+
if (redact(rel) !== rel)
|
|
180
|
+
return skip(rel, 'secret');
|
|
181
|
+
if (files.length >= limits.files)
|
|
182
|
+
return skip(rel, 'count-limit');
|
|
183
|
+
let bytes;
|
|
184
|
+
try {
|
|
185
|
+
const result = await read(abs);
|
|
186
|
+
if (!Buffer.isBuffer(result))
|
|
187
|
+
return skip(rel, result);
|
|
188
|
+
bytes = result;
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
return skip(rel, 'copy-failed', message(error));
|
|
192
|
+
}
|
|
193
|
+
let redacted = false;
|
|
194
|
+
if (textExtensions.has(extname(rel).toLowerCase())) {
|
|
195
|
+
const masked = maskText(bytes, redact);
|
|
196
|
+
if (masked) {
|
|
197
|
+
bytes = masked;
|
|
198
|
+
redacted = true;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// Секрет, оставшийся после маски (текст в UTF-16 и других кодировках), и
|
|
202
|
+
// секрет в не текстовом файле: такой файл не копируется.
|
|
203
|
+
if (binaryHasSecret(bytes, redact))
|
|
204
|
+
return skip(rel, 'secret');
|
|
205
|
+
if (bytes.length > limits.fileBytes)
|
|
206
|
+
return skip(rel, 'file-limit');
|
|
207
|
+
if (total + bytes.length > limits.totalBytes)
|
|
208
|
+
return skip(rel, 'total-limit');
|
|
209
|
+
try {
|
|
210
|
+
const target = join(dest, ...rel.split('/'));
|
|
211
|
+
await mkdir(dirname(target), { recursive: true });
|
|
212
|
+
await writeFile(target, bytes, { flag: 'wx' });
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
return skip(rel, 'copy-failed', message(error));
|
|
216
|
+
}
|
|
217
|
+
total += bytes.length;
|
|
218
|
+
files.push({
|
|
219
|
+
path: rel,
|
|
220
|
+
sha256: sha256(bytes),
|
|
221
|
+
bytes: bytes.length,
|
|
222
|
+
...(redacted ? { redacted: true } : {}),
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
const visit = async (rel, abs) => {
|
|
226
|
+
if (signal?.aborted)
|
|
227
|
+
return skip(rel, 'copy-failed', 'проверка отменена');
|
|
228
|
+
await options.beforeVisit?.(rel);
|
|
229
|
+
let info;
|
|
230
|
+
try {
|
|
231
|
+
info = await lstat(abs);
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
return skip(rel, 'copy-failed', message(error));
|
|
235
|
+
}
|
|
236
|
+
if (info.isSymbolicLink())
|
|
237
|
+
return skip(rel, 'symlink');
|
|
238
|
+
if (info.isFile())
|
|
239
|
+
return copy(rel, abs);
|
|
240
|
+
if (!info.isDirectory())
|
|
241
|
+
return skip(rel, 'not-regular');
|
|
242
|
+
// Записи читаются только до предела обхода: огромный каталог не
|
|
243
|
+
// перечисляется целиком. Прочитанное посещается в порядке имён.
|
|
244
|
+
const names = [];
|
|
245
|
+
try {
|
|
246
|
+
const handle = await opendir(abs);
|
|
247
|
+
try {
|
|
248
|
+
for await (const entry of handle) {
|
|
249
|
+
if (scanned >= limits.scan) {
|
|
250
|
+
stopped = true;
|
|
251
|
+
skip(rel, 'scan-limit', `обход остановлен после ${limits.scan} записей`);
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
scanned++;
|
|
255
|
+
names.push(entry.name);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
finally {
|
|
259
|
+
// Прерванный for await уже закрыл каталог; повторное закрытие — не ошибка.
|
|
260
|
+
await handle.close().catch(() => undefined);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
return skip(rel, 'copy-failed', message(error));
|
|
265
|
+
}
|
|
266
|
+
for (const name of names.sort())
|
|
267
|
+
await visit(`${rel}/${name}`, join(abs, name));
|
|
268
|
+
};
|
|
269
|
+
for (const rel of paths) {
|
|
270
|
+
if (stopped) {
|
|
271
|
+
skip(rel, 'scan-limit', `обход остановлен после ${limits.scan} записей`);
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
const abs = resolve(root, rel);
|
|
275
|
+
if (!inside(abs, root)) {
|
|
276
|
+
skip(rel, 'outside');
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
// Компоненты пути проверяются по одному: ссылка на любом уровне могла бы
|
|
280
|
+
// увести копирование за пределы дерева.
|
|
281
|
+
const parts = rel.split('/');
|
|
282
|
+
let blocked, detail;
|
|
283
|
+
for (let i = 1; i <= parts.length && !blocked; i++) {
|
|
284
|
+
try {
|
|
285
|
+
const info = await lstat(join(root, ...parts.slice(0, i)));
|
|
286
|
+
if (info.isSymbolicLink())
|
|
287
|
+
blocked = 'symlink';
|
|
288
|
+
else if (i < parts.length && !info.isDirectory())
|
|
289
|
+
blocked = 'missing';
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
blocked = error.code === 'ENOENT' ? 'missing' : 'copy-failed';
|
|
293
|
+
detail = blocked === 'copy-failed' ? message(error) : undefined;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (blocked) {
|
|
297
|
+
skip(rel, blocked, detail);
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
await visit(rel, abs);
|
|
301
|
+
}
|
|
302
|
+
return done();
|
|
303
|
+
}
|
|
@@ -9,6 +9,7 @@ import { defaultResourceDatabase, withResources } from "../environment/resources
|
|
|
9
9
|
import { removeSnapshots, snapshotDependencies } from "./dependencies.js";
|
|
10
10
|
import { runGate } from "./gates.js";
|
|
11
11
|
import { checkoutPath, chooseCheckoutRoot } from "../environment/checkout-root.js";
|
|
12
|
+
import { dependencyStoreRoot, materializeStore } from "./dependency-store.js";
|
|
12
13
|
import { credentialPaths } from "../environment/isolation.js";
|
|
13
14
|
import { explicitPrerequisites, orderedScope, standaloneScope } from "./gate-scope.js";
|
|
14
15
|
/**
|
|
@@ -61,6 +62,21 @@ export async function runGatesAt(ctx, input) {
|
|
|
61
62
|
const failed = new Set();
|
|
62
63
|
let snapshots = [];
|
|
63
64
|
let added = false;
|
|
65
|
+
const boundaryOf = ctx.boundary();
|
|
66
|
+
const store = {
|
|
67
|
+
policy: ctx.policy,
|
|
68
|
+
root: (rid) => dependencyStoreRoot(placement, ctx.stateDir, rid),
|
|
69
|
+
repoPath: (r) => ctx.repoPath(r),
|
|
70
|
+
boundary: {
|
|
71
|
+
hidden: boundaryOf.hidden,
|
|
72
|
+
checkouts: [
|
|
73
|
+
...new Set([...(boundaryOf.checkouts ?? []), ...(placement.root ? [placement.root] : [])]),
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
resourceDatabase: ctx.resourceDatabase ?? defaultResourceDatabase(),
|
|
77
|
+
deadline: Date.now() + ctx.policy.runTimeoutMs,
|
|
78
|
+
phaseMs: ctx.policy.runTimeoutMs,
|
|
79
|
+
};
|
|
64
80
|
await mkdir(root, { recursive: true });
|
|
65
81
|
await mkdir(dirname(cwd), { recursive: true });
|
|
66
82
|
try {
|
|
@@ -88,6 +104,7 @@ export async function runGatesAt(ctx, input) {
|
|
|
88
104
|
policy: ctx.policy,
|
|
89
105
|
environment: source,
|
|
90
106
|
signal,
|
|
107
|
+
store,
|
|
91
108
|
});
|
|
92
109
|
await git(path, 'worktree', 'add', '--detach', cwd, input.sha);
|
|
93
110
|
added = true;
|
|
@@ -104,6 +121,7 @@ export async function runGatesAt(ctx, input) {
|
|
|
104
121
|
}, source);
|
|
105
122
|
const boundary = ctx.boundary();
|
|
106
123
|
await withEnvironment(repo.lifecycle ?? ctx.policy.lifecycle, cwd, join(artifacts, 'environment'), execution, signal, async () => {
|
|
124
|
+
await materializeStore(store, { repo, cwd, execution, signal, dir: artifacts });
|
|
107
125
|
await runSteps(repo.prepare, cwd, join(artifacts, 'prepare'), execution, signal);
|
|
108
126
|
for (const gate of gates) {
|
|
109
127
|
// Пропускается только gate, чья явная предпосылка (`dependsOn`) не
|
|
@@ -11,6 +11,7 @@ import { UntrustedCheckoutError } from "../environment/git-trust.js";
|
|
|
11
11
|
import { TaskFailure } from "../engine/failure.js";
|
|
12
12
|
import { redactDeep } from "../environment/redaction.js";
|
|
13
13
|
import { expectsReference, manifestDigest, propertyCoverage, propertyFailure, propertySeed, readPropertyReport, } from "./property.js";
|
|
14
|
+
import { keepGateArtifacts } from "./gate-artifacts.js";
|
|
14
15
|
/** Длинное имя testcase заменяется хешем, а не обрезается: обрезка дала бы ложные совпадения. */
|
|
15
16
|
export const TEST_ID_LIMIT = 1000;
|
|
16
17
|
export function portableTest(test) {
|
|
@@ -716,6 +717,19 @@ export async function runGate(run) {
|
|
|
716
717
|
}
|
|
717
718
|
else if (corpusDir)
|
|
718
719
|
await rm(corpusDir, { recursive: true, force: true }).catch(() => undefined);
|
|
720
|
+
// Artifacts gate (снимки экрана, отчёты) сохраняются при любом исходе:
|
|
721
|
+
// провал — тот случай, когда они нужнее всего. Пропуски и отказы копирования
|
|
722
|
+
// названы в evidence и на исход gate не влияют.
|
|
723
|
+
const artifactFiles = gate.artifacts?.length
|
|
724
|
+
? await keepGateArtifacts({
|
|
725
|
+
root,
|
|
726
|
+
paths: gate.artifacts,
|
|
727
|
+
// Точки в ID нет: имя не совпадёт с каталогом другого gate или фазы.
|
|
728
|
+
dest: join(artifactDir, `${gate.id}.artifacts`),
|
|
729
|
+
redact,
|
|
730
|
+
signal,
|
|
731
|
+
})
|
|
732
|
+
: undefined;
|
|
719
733
|
await mkdir(artifactDir, { recursive: true });
|
|
720
734
|
const logPath = join(artifactDir, `${gate.id}.log`);
|
|
721
735
|
log = redact(log);
|
|
@@ -735,6 +749,7 @@ export async function runGate(run) {
|
|
|
735
749
|
...(manifest?.truncated ? { testsTruncated: true } : {}),
|
|
736
750
|
...(run.consumer ? { consumer: run.consumer } : {}),
|
|
737
751
|
...(propertyEvidence ? { property: propertyEvidence } : {}),
|
|
752
|
+
...(artifactFiles ? { artifactFiles } : {}),
|
|
738
753
|
...(run.recheck
|
|
739
754
|
? {
|
|
740
755
|
recheck: {
|
|
@@ -37,6 +37,21 @@ export declare function jointBudgetAttempts(view: ExecutionView, workIds: string
|
|
|
37
37
|
path: string;
|
|
38
38
|
digest: string;
|
|
39
39
|
}[];
|
|
40
|
+
artifactFiles?: {
|
|
41
|
+
dir: string;
|
|
42
|
+
files: {
|
|
43
|
+
path: string;
|
|
44
|
+
sha256: string;
|
|
45
|
+
bytes: number;
|
|
46
|
+
redacted?: true | undefined;
|
|
47
|
+
}[];
|
|
48
|
+
skipped: {
|
|
49
|
+
path: string;
|
|
50
|
+
reason: "missing" | "symlink" | "outside" | "not-regular" | "hardlink" | "secret" | "extension" | "file-limit" | "total-limit" | "count-limit" | "scan-limit" | "copy-failed";
|
|
51
|
+
detail?: string | undefined;
|
|
52
|
+
}[];
|
|
53
|
+
skippedMore?: number | undefined;
|
|
54
|
+
} | undefined;
|
|
40
55
|
durationMs?: number | undefined;
|
|
41
56
|
}[];
|
|
42
57
|
token: string;
|
|
@@ -50,7 +65,7 @@ export declare function jointBudgetAttempts(view: ExecutionView, workIds: string
|
|
|
50
65
|
changed: string[];
|
|
51
66
|
affected: string[];
|
|
52
67
|
gateIds: string[];
|
|
53
|
-
mode: "
|
|
68
|
+
mode: "affected" | "all";
|
|
54
69
|
reason: string;
|
|
55
70
|
baseline?: string | undefined;
|
|
56
71
|
} | undefined;
|
|
@@ -77,6 +92,21 @@ export declare function jointBudgetAttempts(view: ExecutionView, workIds: string
|
|
|
77
92
|
path: string;
|
|
78
93
|
digest: string;
|
|
79
94
|
}[];
|
|
95
|
+
artifactFiles?: {
|
|
96
|
+
dir: string;
|
|
97
|
+
files: {
|
|
98
|
+
path: string;
|
|
99
|
+
sha256: string;
|
|
100
|
+
bytes: number;
|
|
101
|
+
redacted?: true | undefined;
|
|
102
|
+
}[];
|
|
103
|
+
skipped: {
|
|
104
|
+
path: string;
|
|
105
|
+
reason: "missing" | "symlink" | "outside" | "not-regular" | "hardlink" | "secret" | "extension" | "file-limit" | "total-limit" | "count-limit" | "scan-limit" | "copy-failed";
|
|
106
|
+
detail?: string | undefined;
|
|
107
|
+
}[];
|
|
108
|
+
skippedMore?: number | undefined;
|
|
109
|
+
} | undefined;
|
|
80
110
|
durationMs?: number | undefined;
|
|
81
111
|
}[];
|
|
82
112
|
token: string;
|
|
@@ -90,7 +120,7 @@ export declare function jointBudgetAttempts(view: ExecutionView, workIds: string
|
|
|
90
120
|
changed: string[];
|
|
91
121
|
affected: string[];
|
|
92
122
|
gateIds: string[];
|
|
93
|
-
mode: "
|
|
123
|
+
mode: "affected" | "all";
|
|
94
124
|
reason: string;
|
|
95
125
|
baseline?: string | undefined;
|
|
96
126
|
} | undefined;
|
|
@@ -121,6 +151,21 @@ export declare function jointBudgetAttempts(view: ExecutionView, workIds: string
|
|
|
121
151
|
path: string;
|
|
122
152
|
digest: string;
|
|
123
153
|
}[];
|
|
154
|
+
artifactFiles?: {
|
|
155
|
+
dir: string;
|
|
156
|
+
files: {
|
|
157
|
+
path: string;
|
|
158
|
+
sha256: string;
|
|
159
|
+
bytes: number;
|
|
160
|
+
redacted?: true | undefined;
|
|
161
|
+
}[];
|
|
162
|
+
skipped: {
|
|
163
|
+
path: string;
|
|
164
|
+
reason: "missing" | "symlink" | "outside" | "not-regular" | "hardlink" | "secret" | "extension" | "file-limit" | "total-limit" | "count-limit" | "scan-limit" | "copy-failed";
|
|
165
|
+
detail?: string | undefined;
|
|
166
|
+
}[];
|
|
167
|
+
skippedMore?: number | undefined;
|
|
168
|
+
} | undefined;
|
|
124
169
|
durationMs?: number | undefined;
|
|
125
170
|
}[];
|
|
126
171
|
token: string;
|
|
@@ -129,7 +174,7 @@ export declare function jointBudgetAttempts(view: ExecutionView, workIds: string
|
|
|
129
174
|
changed: string[];
|
|
130
175
|
affected: string[];
|
|
131
176
|
gateIds: string[];
|
|
132
|
-
mode: "
|
|
177
|
+
mode: "affected" | "all";
|
|
133
178
|
reason: string;
|
|
134
179
|
baseline?: string | undefined;
|
|
135
180
|
} | undefined;
|
package/package.json
CHANGED