rig-review 2.5.0 → 2.7.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/docs/PARTS_VIEW.md +82 -3
- package/docs/REVIEW_PACKAGE.md +50 -12
- package/docs/STABILITY.md +232 -15
- package/docs/WORKFLOWS.md +37 -1
- package/package.json +1 -1
- package/src/cli.ts +52 -7
- package/src/job-act.ts +316 -8
- package/src/job-api.ts +821 -8
- package/src/job-cli.ts +219 -52
- package/src/job-contract.ts +299 -0
- package/src/job-front.ts +763 -23
- package/src/job-host.ts +9 -1
- package/src/job-hub.ts +11 -6
- package/src/job-session.ts +68 -9
- package/src/job-source.ts +787 -7
- package/src/job-store.ts +114 -8
- package/src/job-worker.ts +5 -1
- package/src/parts-server.ts +46 -7
- package/src/parts-view.ts +76 -14
- package/web/catalog-en.ts +9 -0
- package/web/catalog-ko.ts +9 -0
- package/web/job-rig-capture.ts +53 -11
- package/web/job-session.ts +196 -7
package/src/job-source.ts
CHANGED
|
@@ -1,18 +1,44 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { lstatSync, realpathSync, type Stats } from 'node:fs';
|
|
2
|
+
import { type Dirent, lstatSync, readdirSync, realpathSync, type Stats } from 'node:fs';
|
|
3
3
|
import { mkdir, open, rm, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { dirname, isAbsolute, join, posix, relative, resolve, sep } from 'node:path';
|
|
5
5
|
import { PNG } from 'pngjs';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
JOB_API_V3_SCHEMA,
|
|
8
|
+
JOB_PARTS_ENUMERATOR_RANGE,
|
|
9
|
+
} from './job-contract.ts';
|
|
7
10
|
import type {
|
|
8
11
|
JobFileIdentity, JobImageSetInput, JobModelSourceBinding, JobPartsEnumerator, JobPartsFileReference, JobPartsIdentity, JobPlanIdentity, JobPublishRequest,
|
|
9
12
|
JobSelector, JobSourceBinding, JobSubject,
|
|
13
|
+
OptionContext, OptionSource, PackageResultV3, PlanContext, PlanSource, ProjectRecord, PublishRequestV3,
|
|
14
|
+
RecordFreeze, RecordOptionResult, RecordPlanResult, RecordPublicationReader, RecordPublishedContext,
|
|
15
|
+
RecordReaderInput, RecordResult, RecordSource, RecordSubject,
|
|
10
16
|
} from './job-contract.ts';
|
|
11
|
-
import { checkedPath, readProject, readRegular, type InterviewQuestion } from './interview-project.ts';
|
|
17
|
+
import { checkedPath, jsonObject, readProject, readRegular, type InterviewQuestion, type InterviewSet } from './interview-project.ts';
|
|
12
18
|
import { loadReview } from './manifest.ts';
|
|
13
19
|
import { openKey } from './open.ts';
|
|
14
20
|
import { assertReviewUnchanged } from './reference.ts';
|
|
15
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
assertEqualRecordContexts,
|
|
23
|
+
assertJobApiSchema,
|
|
24
|
+
buildRecordSource,
|
|
25
|
+
isRecordSource,
|
|
26
|
+
jobHash,
|
|
27
|
+
jobId,
|
|
28
|
+
jobObject,
|
|
29
|
+
jobPartsEnumeratorVersion,
|
|
30
|
+
jobPath,
|
|
31
|
+
jobSha,
|
|
32
|
+
jobText,
|
|
33
|
+
parseRecordFreeze,
|
|
34
|
+
parseRecordPublishedContext,
|
|
35
|
+
parseRecordResult,
|
|
36
|
+
parseRecordSource,
|
|
37
|
+
recordInstanceKey,
|
|
38
|
+
requestDigest,
|
|
39
|
+
stripPackageResultKind,
|
|
40
|
+
validateRecordAskSubject,
|
|
41
|
+
} from './job-api.ts';
|
|
16
42
|
import { JobError, type JobSnapshotOwner } from './job-store.ts';
|
|
17
43
|
import { prepareJobImageSet } from './job-image-set.ts';
|
|
18
44
|
|
|
@@ -59,9 +85,35 @@ export interface JobRetainedSource {
|
|
|
59
85
|
readonly partIds: readonly string[];
|
|
60
86
|
}
|
|
61
87
|
|
|
88
|
+
export interface JobRetainedRecordSource {
|
|
89
|
+
readonly kind: 'record';
|
|
90
|
+
readonly root: JobRootIdentity;
|
|
91
|
+
readonly record: ProjectRecord;
|
|
92
|
+
readonly result: RecordResult;
|
|
93
|
+
readonly seals: readonly JobFileIdentity[];
|
|
94
|
+
readonly snapshotRoot: string;
|
|
95
|
+
readonly snapshotIdentity?: { readonly dev: number; readonly ino: number };
|
|
96
|
+
readonly manifestPath: null;
|
|
97
|
+
readonly source: RecordSource;
|
|
98
|
+
readonly instanceKey: string;
|
|
99
|
+
readonly label: string;
|
|
100
|
+
readonly visual: { readonly status: 'unavailable'; readonly code: 'MODEL_UNAVAILABLE' };
|
|
101
|
+
readonly subjects: readonly RecordSubject[];
|
|
102
|
+
readonly questions: readonly InterviewQuestion[];
|
|
103
|
+
readonly partIds: readonly [];
|
|
104
|
+
readonly context: RecordPublishedContext;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export type JobRetainedSourceV3 = JobRetainedSource | JobRetainedRecordSource;
|
|
108
|
+
|
|
109
|
+
export function isRetainedRecordSource(retained: JobRetainedSourceV3): retained is JobRetainedRecordSource {
|
|
110
|
+
return 'kind' in retained && retained.kind === 'record';
|
|
111
|
+
}
|
|
112
|
+
|
|
62
113
|
const maxSourceBytes = 256 * 1024 * 1024;
|
|
63
114
|
const maxSourceFiles = 4096;
|
|
64
115
|
const maxFileBytes = 64 * 1024 * 1024;
|
|
116
|
+
const maxProjectBytes = 8 * 1024 * 1024;
|
|
65
117
|
|
|
66
118
|
/** Private preservation identity. Keep the supplied seal order and fixed keys. */
|
|
67
119
|
export function jobSnapshotHash(seals: readonly JobFileIdentity[]): string {
|
|
@@ -133,7 +185,9 @@ function assertRecord(root: JobRootIdentity, record: JobFileIdentity | null): vo
|
|
|
133
185
|
/** Synchronous final read is used inside local CAS. The producer must still hold
|
|
134
186
|
* its external freeze. This does not lock an independent producer's filesystem.
|
|
135
187
|
*/
|
|
136
|
-
export function assertJobSourceCurrent(
|
|
188
|
+
export function assertJobSourceCurrent(
|
|
189
|
+
source: Pick<JobRetainedSourceV3, 'root' | 'record' | 'seals'>,
|
|
190
|
+
): void {
|
|
137
191
|
assertRecord(source.root, source.record);
|
|
138
192
|
for (const file of source.seals) {
|
|
139
193
|
try {
|
|
@@ -299,6 +353,659 @@ function collectQuestionFiles(root: string, questions: readonly InterviewQuestio
|
|
|
299
353
|
return result;
|
|
300
354
|
}
|
|
301
355
|
|
|
356
|
+
function isOptionIdentifier(value: unknown): value is string {
|
|
357
|
+
return typeof value === 'string' && /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/.test(value);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function isNonEmptyTrimmedText(value: unknown): value is string {
|
|
361
|
+
return typeof value === 'string' && value.trim().length > 0;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function asPlainObject(value: unknown): Record<string, unknown> | null {
|
|
365
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
366
|
+
? value as Record<string, unknown>
|
|
367
|
+
: null;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function validateOptionSetStructure(
|
|
371
|
+
raw: Record<string, unknown>,
|
|
372
|
+
questionId: string,
|
|
373
|
+
setId: string,
|
|
374
|
+
allowedStages: readonly string[],
|
|
375
|
+
): InterviewSet {
|
|
376
|
+
const assembly = asPlainObject(raw.assembly);
|
|
377
|
+
const rule = assembly?.rule;
|
|
378
|
+
const asksRaw = Array.isArray(raw.asks) ? raw.asks : null;
|
|
379
|
+
if (
|
|
380
|
+
raw.schema !== 'rig-create/interview-options@1' ||
|
|
381
|
+
!isOptionIdentifier(raw.id) ||
|
|
382
|
+
raw.id !== setId ||
|
|
383
|
+
!isOptionIdentifier(questionId) ||
|
|
384
|
+
raw.question !== questionId ||
|
|
385
|
+
!allowedStages.includes(String(raw.stage)) ||
|
|
386
|
+
!isNonEmptyTrimmedText(raw.drafted_by) ||
|
|
387
|
+
typeof raw.drafted_at !== 'string' ||
|
|
388
|
+
!Number.isFinite(Date.parse(raw.drafted_at)) ||
|
|
389
|
+
!asksRaw ||
|
|
390
|
+
asksRaw.length === 0 ||
|
|
391
|
+
!['single', 'concat', 'merge'].includes(String(rule)) ||
|
|
392
|
+
(rule === 'single' && asksRaw.length !== 1)
|
|
393
|
+
) {
|
|
394
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
395
|
+
}
|
|
396
|
+
const asks: Record<string, unknown>[] = [];
|
|
397
|
+
const askIds = new Set<string>();
|
|
398
|
+
for (const entry of asksRaw) {
|
|
399
|
+
const ask = asPlainObject(entry);
|
|
400
|
+
if (!ask || !isOptionIdentifier(ask.id) || askIds.has(ask.id) || !isNonEmptyTrimmedText(ask.prompt)) {
|
|
401
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
402
|
+
}
|
|
403
|
+
askIds.add(ask.id);
|
|
404
|
+
if (!Array.isArray(ask.options)) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
405
|
+
const options: Record<string, unknown>[] = [];
|
|
406
|
+
const optionIds = new Set<string>();
|
|
407
|
+
for (const optEntry of ask.options) {
|
|
408
|
+
const option = asPlainObject(optEntry);
|
|
409
|
+
if (
|
|
410
|
+
!option ||
|
|
411
|
+
!isOptionIdentifier(option.id) ||
|
|
412
|
+
optionIds.has(option.id) ||
|
|
413
|
+
!isNonEmptyTrimmedText(option.label) ||
|
|
414
|
+
!isNonEmptyTrimmedText(option.effect) ||
|
|
415
|
+
typeof option.recommended !== 'boolean' ||
|
|
416
|
+
!['value', 'other', 'auto'].includes(String(option.kind)) ||
|
|
417
|
+
(option.recommended && (option.kind !== 'value' || !isNonEmptyTrimmedText(option.reason))) ||
|
|
418
|
+
(option.kind === 'value'
|
|
419
|
+
? !('fragment' in option) ||
|
|
420
|
+
(rule === 'concat' && !Array.isArray(option.fragment)) ||
|
|
421
|
+
(rule === 'merge' && asPlainObject(option.fragment) === null)
|
|
422
|
+
: 'fragment' in option)
|
|
423
|
+
) {
|
|
424
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
425
|
+
}
|
|
426
|
+
optionIds.add(option.id);
|
|
427
|
+
options.push(option);
|
|
428
|
+
}
|
|
429
|
+
if (
|
|
430
|
+
options.filter(option => option.kind === 'value').length < 2 ||
|
|
431
|
+
options.filter(option => option.kind === 'other').length !== 1 ||
|
|
432
|
+
options.filter(option => option.kind === 'auto').length !== 1 ||
|
|
433
|
+
options.filter(option => option.recommended === true).length !== 1
|
|
434
|
+
) {
|
|
435
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
436
|
+
}
|
|
437
|
+
asks.push(ask);
|
|
438
|
+
}
|
|
439
|
+
if (raw.constraints !== undefined) {
|
|
440
|
+
if (!Array.isArray(raw.constraints)) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
441
|
+
for (const entry of raw.constraints) {
|
|
442
|
+
const constraint = asPlainObject(entry);
|
|
443
|
+
const names = constraint?.asks;
|
|
444
|
+
const allowed = constraint?.allowed;
|
|
445
|
+
if (
|
|
446
|
+
!constraint ||
|
|
447
|
+
!Array.isArray(names) ||
|
|
448
|
+
names.length === 0 ||
|
|
449
|
+
new Set(names).size !== names.length ||
|
|
450
|
+
names.some(name => typeof name !== 'string' || !askIds.has(name)) ||
|
|
451
|
+
!Array.isArray(allowed) ||
|
|
452
|
+
allowed.length === 0
|
|
453
|
+
) {
|
|
454
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
455
|
+
}
|
|
456
|
+
for (const tuple of allowed) {
|
|
457
|
+
if (!Array.isArray(tuple) || tuple.length !== names.length) {
|
|
458
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
459
|
+
}
|
|
460
|
+
for (let i = 0; i < names.length; i++) {
|
|
461
|
+
const targetAsk = asks.find(ask => ask.id === names[i]);
|
|
462
|
+
const targetOptions = Array.isArray(targetAsk?.options) ? targetAsk.options as Record<string, unknown>[] : [];
|
|
463
|
+
if (!targetOptions.some(option => option.id === tuple[i] && option.kind === 'value')) {
|
|
464
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return raw as unknown as InterviewSet;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
export function assertRetainedSnapshotIntact(
|
|
474
|
+
snapshotRoot: string,
|
|
475
|
+
seals: readonly JobFileIdentity[],
|
|
476
|
+
snapshotIdentity?: { readonly dev: number; readonly ino: number },
|
|
477
|
+
refusalCode: 'JOB_SOURCE_UNRETAINABLE' | 'JOB_ACT_SOURCE_STALE' = 'JOB_SOURCE_UNRETAINABLE',
|
|
478
|
+
): void {
|
|
479
|
+
let rootInfo: Stats;
|
|
480
|
+
try {
|
|
481
|
+
rootInfo = lstatSync(snapshotRoot);
|
|
482
|
+
if (!rootInfo.isDirectory() || realpathSync(snapshotRoot) !== snapshotRoot || (rootInfo.mode & 0o077) !== 0) {
|
|
483
|
+
throw new Error('Invalid snapshot directory');
|
|
484
|
+
}
|
|
485
|
+
if (snapshotIdentity && (rootInfo.dev !== snapshotIdentity.dev || rootInfo.ino !== snapshotIdentity.ino)) {
|
|
486
|
+
throw new Error('Snapshot directory identity changed');
|
|
487
|
+
}
|
|
488
|
+
} catch {
|
|
489
|
+
throw new JobError(refusalCode);
|
|
490
|
+
}
|
|
491
|
+
const expectedFiles = new Map<string, string>();
|
|
492
|
+
const expectedDirs = new Set<string>(['']);
|
|
493
|
+
for (const seal of seals) {
|
|
494
|
+
let normalizedPath: string;
|
|
495
|
+
let normalizedSha: string;
|
|
496
|
+
try {
|
|
497
|
+
normalizedPath = jobPath(seal.path);
|
|
498
|
+
normalizedSha = jobSha(seal.sha256);
|
|
499
|
+
} catch {
|
|
500
|
+
throw new JobError(refusalCode);
|
|
501
|
+
}
|
|
502
|
+
if (expectedFiles.has(normalizedPath)) throw new JobError(refusalCode);
|
|
503
|
+
expectedFiles.set(normalizedPath, normalizedSha);
|
|
504
|
+
let dir = posix.dirname(normalizedPath);
|
|
505
|
+
while (dir !== '.' && dir !== '') {
|
|
506
|
+
expectedDirs.add(dir);
|
|
507
|
+
dir = posix.dirname(dir);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
const visitedFiles = new Set<string>();
|
|
511
|
+
const visitDir = (relDir: string): void => {
|
|
512
|
+
const absDir = relDir ? join(snapshotRoot, relDir) : snapshotRoot;
|
|
513
|
+
let entries: Dirent[];
|
|
514
|
+
try {
|
|
515
|
+
entries = readdirSync(absDir, { withFileTypes: true });
|
|
516
|
+
} catch {
|
|
517
|
+
throw new JobError(refusalCode);
|
|
518
|
+
}
|
|
519
|
+
for (const entry of entries) {
|
|
520
|
+
const rel = relDir ? `${relDir}/${entry.name}` : entry.name;
|
|
521
|
+
const abs = join(absDir, entry.name);
|
|
522
|
+
let stat: Stats;
|
|
523
|
+
try {
|
|
524
|
+
stat = lstatSync(abs);
|
|
525
|
+
} catch {
|
|
526
|
+
throw new JobError(refusalCode);
|
|
527
|
+
}
|
|
528
|
+
if (stat.isSymbolicLink()) throw new JobError(refusalCode);
|
|
529
|
+
if (stat.isDirectory()) {
|
|
530
|
+
if (!expectedDirs.has(rel)) throw new JobError(refusalCode);
|
|
531
|
+
visitDir(rel);
|
|
532
|
+
} else if (stat.isFile()) {
|
|
533
|
+
const expectedSha = expectedFiles.get(rel);
|
|
534
|
+
if (!expectedSha || visitedFiles.has(rel)) throw new JobError(refusalCode);
|
|
535
|
+
let bytes: Buffer;
|
|
536
|
+
try {
|
|
537
|
+
bytes = sourceBytes(snapshotRoot, rel);
|
|
538
|
+
} catch {
|
|
539
|
+
throw new JobError(refusalCode);
|
|
540
|
+
}
|
|
541
|
+
if (jobHash(bytes) !== expectedSha) throw new JobError(refusalCode);
|
|
542
|
+
visitedFiles.add(rel);
|
|
543
|
+
} else {
|
|
544
|
+
throw new JobError(refusalCode);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
visitDir('');
|
|
549
|
+
if (visitedFiles.size !== expectedFiles.size) throw new JobError(refusalCode);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
function extractReaderToken(error: unknown): string | null {
|
|
553
|
+
if (!error || typeof error !== 'object') return null;
|
|
554
|
+
const candidate = error as { readonly code?: unknown; readonly message?: unknown };
|
|
555
|
+
for (const raw of [candidate.code, candidate.message]) {
|
|
556
|
+
if (typeof raw !== 'string') continue;
|
|
557
|
+
if (
|
|
558
|
+
raw === 'CREATE_PUBLICATION_CONTRACT_UNAVAILABLE' ||
|
|
559
|
+
raw === 'CREATE_PLAN_PUBLICATION_CONTRACT_UNAVAILABLE' ||
|
|
560
|
+
raw === 'JOB_RECORD_CLOSURE_INCOMPLETE' ||
|
|
561
|
+
raw === 'JOB_RECORD_PARTS_MISMATCH' ||
|
|
562
|
+
raw === 'JOB_RECORD_PARTS_LOCK_MISSING'
|
|
563
|
+
) {
|
|
564
|
+
return raw;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return null;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
function mapRecordReaderError(error: unknown, phase: 'publish' | 'ask' | 'finalize'): JobError {
|
|
571
|
+
const token = extractReaderToken(error);
|
|
572
|
+
if (
|
|
573
|
+
token === 'CREATE_PUBLICATION_CONTRACT_UNAVAILABLE' ||
|
|
574
|
+
token === 'CREATE_PLAN_PUBLICATION_CONTRACT_UNAVAILABLE'
|
|
575
|
+
) {
|
|
576
|
+
return new JobError('JOB_SOURCE_UNRETAINABLE', token);
|
|
577
|
+
}
|
|
578
|
+
const refusalCode = phase === 'finalize' ? 'JOB_ACT_SOURCE_STALE' : 'JOB_RECORD_INCOMPLETE';
|
|
579
|
+
if (
|
|
580
|
+
token === 'JOB_RECORD_CLOSURE_INCOMPLETE' ||
|
|
581
|
+
token === 'JOB_RECORD_PARTS_MISMATCH' ||
|
|
582
|
+
token === 'JOB_RECORD_PARTS_LOCK_MISSING'
|
|
583
|
+
) {
|
|
584
|
+
return new JobError(refusalCode, token);
|
|
585
|
+
}
|
|
586
|
+
return new JobError(refusalCode);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
async function readRecordPublishedPhase(
|
|
590
|
+
readRecordPublished: RecordPublicationReader,
|
|
591
|
+
input: RecordReaderInput,
|
|
592
|
+
phase: 'publish' | 'ask' | 'finalize',
|
|
593
|
+
): Promise<RecordPublishedContext> {
|
|
594
|
+
let raw: unknown;
|
|
595
|
+
try {
|
|
596
|
+
raw = input.result.kind === 'option-set'
|
|
597
|
+
? await readRecordPublished({
|
|
598
|
+
root: input.root,
|
|
599
|
+
record: input.record,
|
|
600
|
+
result: input.result,
|
|
601
|
+
phase: input.phase,
|
|
602
|
+
...(input.parts !== undefined ? { parts: input.parts } : {}),
|
|
603
|
+
})
|
|
604
|
+
: await readRecordPublished({
|
|
605
|
+
root: input.root,
|
|
606
|
+
record: input.record,
|
|
607
|
+
result: input.result,
|
|
608
|
+
phase: input.phase,
|
|
609
|
+
...(input.parts !== undefined ? { parts: input.parts } : {}),
|
|
610
|
+
});
|
|
611
|
+
} catch (error) {
|
|
612
|
+
throw mapRecordReaderError(error, phase);
|
|
613
|
+
}
|
|
614
|
+
return parseRecordPublishedContext(raw, input.result, input.record);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
function readProjectRecordBytes(root: string, record: ProjectRecord): {
|
|
618
|
+
readonly bytes: Buffer;
|
|
619
|
+
readonly project: Record<string, unknown>;
|
|
620
|
+
} {
|
|
621
|
+
let stat: Stats;
|
|
622
|
+
try {
|
|
623
|
+
stat = lstatSync(join(root, record.path));
|
|
624
|
+
} catch {
|
|
625
|
+
throw new JobError('JOB_RECORD_MOVED');
|
|
626
|
+
}
|
|
627
|
+
if (!stat.isFile()) throw new JobError('JOB_RECORD_MOVED');
|
|
628
|
+
if (stat.size > maxProjectBytes) throw new JobError('JOB_SOURCE_UNRETAINABLE');
|
|
629
|
+
let bytes: Buffer;
|
|
630
|
+
try {
|
|
631
|
+
bytes = sourceBytes(root, record.path);
|
|
632
|
+
} catch {
|
|
633
|
+
throw new JobError('JOB_RECORD_MOVED');
|
|
634
|
+
}
|
|
635
|
+
if (jobHash(bytes) !== record.sha256) throw new JobError('JOB_RECORD_MOVED');
|
|
636
|
+
let project: Record<string, unknown>;
|
|
637
|
+
try {
|
|
638
|
+
project = jsonObject(bytes);
|
|
639
|
+
} catch {
|
|
640
|
+
throw new JobError('JOB_RECORD_INCOMPLETE');
|
|
641
|
+
}
|
|
642
|
+
if (project.schema !== 'rig-create/project@0') throw new JobError('JOB_RECORD_INCOMPLETE');
|
|
643
|
+
return { bytes, project };
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
function readClosureFileBytes(root: string, file: JobFileIdentity): Buffer {
|
|
647
|
+
if (file.path === 'project.json') {
|
|
648
|
+
return readProjectRecordBytes(root, file as ProjectRecord).bytes;
|
|
649
|
+
}
|
|
650
|
+
let target: string;
|
|
651
|
+
try {
|
|
652
|
+
target = checkedPath(root, file.path);
|
|
653
|
+
} catch {
|
|
654
|
+
throw new JobError('JOB_SOURCE_UNRETAINABLE');
|
|
655
|
+
}
|
|
656
|
+
let stat: Stats;
|
|
657
|
+
try {
|
|
658
|
+
stat = lstatSync(target);
|
|
659
|
+
} catch {
|
|
660
|
+
throw new JobError('JOB_SOURCE_UNRETAINABLE');
|
|
661
|
+
}
|
|
662
|
+
if (!stat.isFile() || stat.size > maxFileBytes) throw new JobError('JOB_SOURCE_UNRETAINABLE');
|
|
663
|
+
let bytes: Buffer;
|
|
664
|
+
try {
|
|
665
|
+
bytes = sourceBytes(root, file.path);
|
|
666
|
+
} catch (error) {
|
|
667
|
+
if (error instanceof JobError) throw error;
|
|
668
|
+
throw new JobError('JOB_SOURCE_UNRETAINABLE');
|
|
669
|
+
}
|
|
670
|
+
if (jobHash(bytes) !== file.sha256) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
671
|
+
return bytes;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
function decodeRetainedRecordProject(
|
|
675
|
+
snapshotRoot: string,
|
|
676
|
+
seals: readonly JobFileIdentity[],
|
|
677
|
+
result: RecordResult,
|
|
678
|
+
context: RecordPublishedContext,
|
|
679
|
+
): {
|
|
680
|
+
readonly questions: readonly InterviewQuestion[];
|
|
681
|
+
readonly optionSetFile: JobFileIdentity | null;
|
|
682
|
+
} {
|
|
683
|
+
const sealMap = new Map<string, string>();
|
|
684
|
+
for (const seal of seals) {
|
|
685
|
+
sealMap.set(seal.path, seal.sha256);
|
|
686
|
+
}
|
|
687
|
+
const recordSha = sealMap.get('project.json');
|
|
688
|
+
if (!recordSha) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
689
|
+
const { project } = readProjectRecordBytes(snapshotRoot, { path: 'project.json', sha256: recordSha });
|
|
690
|
+
|
|
691
|
+
if (result.kind === 'option-set') {
|
|
692
|
+
if (context.plan !== null) {
|
|
693
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
694
|
+
}
|
|
695
|
+
const { questionId, setId } = result;
|
|
696
|
+
const interview = asPlainObject(project.interview);
|
|
697
|
+
if (!interview) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
698
|
+
const collections = [
|
|
699
|
+
[interview.framing, ['interview']],
|
|
700
|
+
[interview.waypoints, ['interview', 'rigging-interview']],
|
|
701
|
+
[asPlainObject(interview.post)?.items, ['post-interview']],
|
|
702
|
+
] as const;
|
|
703
|
+
const matches: { readonly pending: unknown; readonly allowedStages: readonly string[] }[] = [];
|
|
704
|
+
for (const [items, allowedStages] of collections) {
|
|
705
|
+
if (items !== undefined && !Array.isArray(items)) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
706
|
+
for (const rawItem of Array.isArray(items) ? items : []) {
|
|
707
|
+
const item = asPlainObject(rawItem);
|
|
708
|
+
if (!item) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
709
|
+
if (item.id === questionId) {
|
|
710
|
+
matches.push({ pending: item.pending_options, allowedStages });
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
if (matches.length !== 1 || matches[0]!.pending === undefined) {
|
|
715
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
716
|
+
}
|
|
717
|
+
let ref: JobFileIdentity;
|
|
718
|
+
try {
|
|
719
|
+
const pendingObj = jobObject(matches[0]!.pending, ['path', 'sha256']);
|
|
720
|
+
ref = { path: jobPath(pendingObj.path), sha256: jobSha(pendingObj.sha256) };
|
|
721
|
+
} catch {
|
|
722
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
723
|
+
}
|
|
724
|
+
if (
|
|
725
|
+
ref.path === 'project.json' ||
|
|
726
|
+
['derived', 'outputs', 'scratch', 'node_modules', '.git'].includes(ref.path.split('/')[0]!) ||
|
|
727
|
+
sealMap.get(ref.path) !== ref.sha256
|
|
728
|
+
) {
|
|
729
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
730
|
+
}
|
|
731
|
+
let optionBytes: Buffer;
|
|
732
|
+
let rawSet: Record<string, unknown>;
|
|
733
|
+
try {
|
|
734
|
+
optionBytes = sourceBytes(snapshotRoot, ref.path);
|
|
735
|
+
if (jobHash(optionBytes) !== ref.sha256) throw new Error('Option set hash mismatch');
|
|
736
|
+
rawSet = jsonObject(optionBytes);
|
|
737
|
+
} catch {
|
|
738
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
739
|
+
}
|
|
740
|
+
const set = validateOptionSetStructure(rawSet, questionId, setId, matches[0]!.allowedStages);
|
|
741
|
+
const images: InterviewQuestion['images'] = [];
|
|
742
|
+
const ctx = asPlainObject(rawSet.context);
|
|
743
|
+
if (ctx && Array.isArray(ctx.files)) {
|
|
744
|
+
for (const rawFile of ctx.files) {
|
|
745
|
+
const fileObj = asPlainObject(rawFile);
|
|
746
|
+
if (!fileObj || typeof fileObj.path !== 'string' || typeof fileObj.sha256 !== 'string') {
|
|
747
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
748
|
+
}
|
|
749
|
+
const filePath = jobPath(fileObj.path);
|
|
750
|
+
const fileSha = jobSha(fileObj.sha256);
|
|
751
|
+
if (sealMap.get(filePath) !== fileSha) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
752
|
+
const ext = posix.extname(filePath).toLowerCase();
|
|
753
|
+
const mime = ({
|
|
754
|
+
'.png': 'image/png',
|
|
755
|
+
'.jpg': 'image/jpeg',
|
|
756
|
+
'.jpeg': 'image/jpeg',
|
|
757
|
+
'.webp': 'image/webp',
|
|
758
|
+
'.svg': 'image/svg+xml',
|
|
759
|
+
} as Record<string, string>)[ext];
|
|
760
|
+
if (mime) {
|
|
761
|
+
images.push({ ref: { path: filePath, sha256: fileSha }, name: posix.basename(filePath), type: mime });
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
return {
|
|
766
|
+
questions: [{
|
|
767
|
+
ref,
|
|
768
|
+
set,
|
|
769
|
+
editable: true,
|
|
770
|
+
images,
|
|
771
|
+
hasParts: false,
|
|
772
|
+
}],
|
|
773
|
+
optionSetFile: ref,
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
if (context.plan === null) {
|
|
778
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
779
|
+
}
|
|
780
|
+
const planObj = asPlainObject(project.plan);
|
|
781
|
+
const rawSteps = planObj?.steps;
|
|
782
|
+
if (!Array.isArray(rawSteps) || rawSteps.length !== context.plan.steps.length) {
|
|
783
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
784
|
+
}
|
|
785
|
+
for (let i = 0; i < rawSteps.length; i++) {
|
|
786
|
+
const stepObj = asPlainObject(rawSteps[i]);
|
|
787
|
+
if (!stepObj || typeof stepObj.id !== 'string' || stepObj.id !== context.plan.steps[i]!.id) {
|
|
788
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
return { questions: [], optionSetFile: null };
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
export async function prepareJobRecordSource(options: {
|
|
795
|
+
readonly root: JobRootIdentity;
|
|
796
|
+
readonly stateRoot: string;
|
|
797
|
+
readonly fingerprint: string;
|
|
798
|
+
readonly request: {
|
|
799
|
+
readonly freeze: RecordFreeze;
|
|
800
|
+
readonly result: RecordResult;
|
|
801
|
+
};
|
|
802
|
+
readonly readRecordPublished?: RecordPublicationReader;
|
|
803
|
+
readonly afterSnapshot?: () => void | Promise<void>;
|
|
804
|
+
readonly afterDirectorySync?: (path: string) => void;
|
|
805
|
+
}): Promise<JobRetainedRecordSource> {
|
|
806
|
+
const { root } = options;
|
|
807
|
+
assertJobRoot(root);
|
|
808
|
+
const freeze = parseRecordFreeze(options.request.freeze);
|
|
809
|
+
const result = parseRecordResult(options.request.result);
|
|
810
|
+
const record = freeze.record;
|
|
811
|
+
readProjectRecordBytes(root.path, record);
|
|
812
|
+
if (!options.readRecordPublished) {
|
|
813
|
+
throw new JobError('JOB_SOURCE_UNRETAINABLE', 'CREATE_PUBLICATION_CONTRACT_UNAVAILABLE');
|
|
814
|
+
}
|
|
815
|
+
const inventory = await readRecordPublishedPhase(
|
|
816
|
+
options.readRecordPublished,
|
|
817
|
+
{ root: root.path, record, result, phase: 'inventory' },
|
|
818
|
+
'publish',
|
|
819
|
+
);
|
|
820
|
+
if (inventory.files.length > maxSourceFiles) {
|
|
821
|
+
throw new JobError('JOB_SOURCE_UNRETAINABLE');
|
|
822
|
+
}
|
|
823
|
+
const snapshotRoot = join(options.stateRoot, 'snapshots', randomUUID());
|
|
824
|
+
const seals: JobFileIdentity[] = [];
|
|
825
|
+
let snapshotIdentity: { dev: number; ino: number } | null = null;
|
|
826
|
+
try {
|
|
827
|
+
await mkdir(dirname(snapshotRoot), { recursive: true, mode: 0o700 });
|
|
828
|
+
await mkdir(snapshotRoot, { mode: 0o700 });
|
|
829
|
+
const info = lstatSync(snapshotRoot);
|
|
830
|
+
snapshotIdentity = { dev: info.dev, ino: info.ino };
|
|
831
|
+
let retainedBytes = 0;
|
|
832
|
+
const directories = new Set([snapshotRoot, dirname(snapshotRoot), options.stateRoot]);
|
|
833
|
+
for (const file of inventory.files) {
|
|
834
|
+
const bytes = readClosureFileBytes(root.path, file);
|
|
835
|
+
retainedBytes += bytes.length;
|
|
836
|
+
if (retainedBytes > maxSourceBytes) throw new JobError('JOB_SOURCE_UNRETAINABLE');
|
|
837
|
+
const destination = join(snapshotRoot, file.path);
|
|
838
|
+
await mkdir(dirname(destination), { recursive: true, mode: 0o700 });
|
|
839
|
+
const handle = await open(destination, 'wx', 0o600);
|
|
840
|
+
try {
|
|
841
|
+
await handle.writeFile(bytes);
|
|
842
|
+
await handle.sync();
|
|
843
|
+
} finally {
|
|
844
|
+
await handle.close();
|
|
845
|
+
}
|
|
846
|
+
let directory = dirname(destination);
|
|
847
|
+
while (directory !== snapshotRoot) {
|
|
848
|
+
directories.add(directory);
|
|
849
|
+
directory = dirname(directory);
|
|
850
|
+
}
|
|
851
|
+
seals.push({ path: file.path, sha256: file.sha256 });
|
|
852
|
+
}
|
|
853
|
+
for (const directory of [...directories].sort((a, b) => b.length - a.length)) {
|
|
854
|
+
const handle = await open(directory, 'r');
|
|
855
|
+
try {
|
|
856
|
+
await handle.sync();
|
|
857
|
+
} finally {
|
|
858
|
+
await handle.close();
|
|
859
|
+
}
|
|
860
|
+
options.afterDirectorySync?.(directory);
|
|
861
|
+
}
|
|
862
|
+
assertRetainedSnapshotIntact(snapshotRoot, seals, snapshotIdentity, 'JOB_SOURCE_UNRETAINABLE');
|
|
863
|
+
const retainedContext = await readRecordPublishedPhase(
|
|
864
|
+
options.readRecordPublished,
|
|
865
|
+
{ root: snapshotRoot, record, result, phase: 'retained', parts: inventory.parts },
|
|
866
|
+
'publish',
|
|
867
|
+
);
|
|
868
|
+
assertRetainedSnapshotIntact(snapshotRoot, seals, snapshotIdentity, 'JOB_SOURCE_UNRETAINABLE');
|
|
869
|
+
assertEqualRecordContexts(inventory, retainedContext);
|
|
870
|
+
const decoded = decodeRetainedRecordProject(snapshotRoot, seals, result, retainedContext);
|
|
871
|
+
const source = parseRecordSource(
|
|
872
|
+
result.kind === 'option-set'
|
|
873
|
+
? buildRecordSource({
|
|
874
|
+
record,
|
|
875
|
+
selection: result,
|
|
876
|
+
context: retainedContext as OptionContext,
|
|
877
|
+
optionSetFile: decoded.optionSetFile!,
|
|
878
|
+
})
|
|
879
|
+
: buildRecordSource({
|
|
880
|
+
record,
|
|
881
|
+
selection: result,
|
|
882
|
+
context: retainedContext as PlanContext,
|
|
883
|
+
optionSetFile: null,
|
|
884
|
+
}),
|
|
885
|
+
);
|
|
886
|
+
const prepared: JobRetainedRecordSource = {
|
|
887
|
+
kind: 'record',
|
|
888
|
+
root,
|
|
889
|
+
record,
|
|
890
|
+
result,
|
|
891
|
+
seals,
|
|
892
|
+
snapshotRoot,
|
|
893
|
+
snapshotIdentity,
|
|
894
|
+
manifestPath: null,
|
|
895
|
+
source,
|
|
896
|
+
instanceKey: recordInstanceKey(options.fingerprint, source.sourceHash),
|
|
897
|
+
label: retainedContext.label,
|
|
898
|
+
visual: { status: 'unavailable', code: 'MODEL_UNAVAILABLE' },
|
|
899
|
+
subjects: retainedContext.subjects,
|
|
900
|
+
questions: decoded.questions,
|
|
901
|
+
partIds: [],
|
|
902
|
+
context: retainedContext,
|
|
903
|
+
};
|
|
904
|
+
await options.afterSnapshot?.();
|
|
905
|
+
assertJobSourceCurrent(prepared);
|
|
906
|
+
assertRetainedSnapshotIntact(snapshotRoot, seals, snapshotIdentity, 'JOB_SOURCE_UNRETAINABLE');
|
|
907
|
+
return prepared;
|
|
908
|
+
} catch (error) {
|
|
909
|
+
if (snapshotIdentity) {
|
|
910
|
+
await removeOwnedJobSnapshot(options.stateRoot, { snapshotRoot, ...snapshotIdentity });
|
|
911
|
+
}
|
|
912
|
+
if (error instanceof JobError) throw error;
|
|
913
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
export async function verifyJobRecordSourceFresh(options: {
|
|
918
|
+
readonly retained: JobRetainedRecordSource;
|
|
919
|
+
readonly readRecordPublished?: RecordPublicationReader;
|
|
920
|
+
readonly phase?: 'ask' | 'finalize';
|
|
921
|
+
readonly subject?: RecordSubject;
|
|
922
|
+
}): Promise<RecordSource> {
|
|
923
|
+
const { retained } = options;
|
|
924
|
+
const phase = options.phase ?? 'ask';
|
|
925
|
+
assertJobSourceCurrent(retained);
|
|
926
|
+
assertRetainedSnapshotIntact(
|
|
927
|
+
retained.snapshotRoot,
|
|
928
|
+
retained.seals,
|
|
929
|
+
retained.snapshotIdentity,
|
|
930
|
+
'JOB_SOURCE_UNRETAINABLE',
|
|
931
|
+
);
|
|
932
|
+
if (!options.readRecordPublished) {
|
|
933
|
+
throw new JobError('JOB_SOURCE_UNRETAINABLE', 'CREATE_PUBLICATION_CONTRACT_UNAVAILABLE');
|
|
934
|
+
}
|
|
935
|
+
const inventory = await readRecordPublishedPhase(
|
|
936
|
+
options.readRecordPublished,
|
|
937
|
+
{ root: retained.root.path, record: retained.record, result: retained.result, phase: 'inventory' },
|
|
938
|
+
phase,
|
|
939
|
+
);
|
|
940
|
+
if (requestDigest(inventory.parts) !== requestDigest(retained.context.parts)) {
|
|
941
|
+
throw new JobError(phase === 'finalize' ? 'JOB_ACT_SOURCE_STALE' : 'JOB_SOURCE_MISMATCH');
|
|
942
|
+
}
|
|
943
|
+
assertRetainedSnapshotIntact(
|
|
944
|
+
retained.snapshotRoot,
|
|
945
|
+
retained.seals,
|
|
946
|
+
retained.snapshotIdentity,
|
|
947
|
+
'JOB_SOURCE_UNRETAINABLE',
|
|
948
|
+
);
|
|
949
|
+
const retainedContext = await readRecordPublishedPhase(
|
|
950
|
+
options.readRecordPublished,
|
|
951
|
+
{
|
|
952
|
+
root: retained.snapshotRoot,
|
|
953
|
+
record: retained.record,
|
|
954
|
+
result: retained.result,
|
|
955
|
+
phase: 'retained',
|
|
956
|
+
parts: retained.context.parts,
|
|
957
|
+
},
|
|
958
|
+
phase,
|
|
959
|
+
);
|
|
960
|
+
assertRetainedSnapshotIntact(
|
|
961
|
+
retained.snapshotRoot,
|
|
962
|
+
retained.seals,
|
|
963
|
+
retained.snapshotIdentity,
|
|
964
|
+
'JOB_SOURCE_UNRETAINABLE',
|
|
965
|
+
);
|
|
966
|
+
try {
|
|
967
|
+
assertEqualRecordContexts(inventory, retainedContext);
|
|
968
|
+
} catch (error) {
|
|
969
|
+
if (phase === 'finalize') throw new JobError('JOB_ACT_SOURCE_STALE');
|
|
970
|
+
throw error;
|
|
971
|
+
}
|
|
972
|
+
const decoded = decodeRetainedRecordProject(retained.snapshotRoot, retained.seals, retained.result, retainedContext);
|
|
973
|
+
const freshSource = parseRecordSource(
|
|
974
|
+
retained.result.kind === 'option-set'
|
|
975
|
+
? buildRecordSource({
|
|
976
|
+
record: retained.record,
|
|
977
|
+
selection: retained.result,
|
|
978
|
+
context: retainedContext as OptionContext,
|
|
979
|
+
optionSetFile: decoded.optionSetFile!,
|
|
980
|
+
})
|
|
981
|
+
: buildRecordSource({
|
|
982
|
+
record: retained.record,
|
|
983
|
+
selection: retained.result,
|
|
984
|
+
context: retainedContext as PlanContext,
|
|
985
|
+
optionSetFile: null,
|
|
986
|
+
}),
|
|
987
|
+
);
|
|
988
|
+
if (
|
|
989
|
+
freshSource.sourceHash !== retained.source.sourceHash ||
|
|
990
|
+
requestDigest(freshSource) !== requestDigest(retained.source) ||
|
|
991
|
+
requestDigest(retainedContext.subjects) !== requestDigest(retained.subjects) ||
|
|
992
|
+
requestDigest(retainedContext.parts) !== requestDigest(retained.context.parts) ||
|
|
993
|
+
retainedContext.label !== retained.context.label
|
|
994
|
+
) {
|
|
995
|
+
throw new JobError(phase === 'finalize' ? 'JOB_ACT_SOURCE_STALE' : 'JOB_SOURCE_MISMATCH');
|
|
996
|
+
}
|
|
997
|
+
if (options.subject !== undefined) {
|
|
998
|
+
try {
|
|
999
|
+
validateRecordAskSubject(options.subject, freshSource);
|
|
1000
|
+
} catch (error) {
|
|
1001
|
+
if (phase === 'finalize') throw new JobError('JOB_ACT_SOURCE_STALE');
|
|
1002
|
+
throw error;
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
assertJobSourceCurrent(retained);
|
|
1006
|
+
return freshSource;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
302
1009
|
export async function prepareJobSource(options: {
|
|
303
1010
|
readonly root: JobRootIdentity;
|
|
304
1011
|
readonly stateRoot: string;
|
|
@@ -308,8 +1015,81 @@ export async function prepareJobSource(options: {
|
|
|
308
1015
|
readonly partsEnumerator?: JobPartsEnumerator;
|
|
309
1016
|
readonly afterSnapshot?: () => void | Promise<void>;
|
|
310
1017
|
readonly afterDirectorySync?: (path: string) => void;
|
|
311
|
-
}): Promise<JobRetainedSource
|
|
312
|
-
|
|
1018
|
+
}): Promise<JobRetainedSource>;
|
|
1019
|
+
export async function prepareJobSource(options: {
|
|
1020
|
+
readonly root: JobRootIdentity;
|
|
1021
|
+
readonly stateRoot: string;
|
|
1022
|
+
readonly fingerprint: string;
|
|
1023
|
+
readonly request: PublishRequestV3 & { readonly result: RecordResult };
|
|
1024
|
+
readonly readRecordPublished?: RecordPublicationReader;
|
|
1025
|
+
readonly afterSnapshot?: () => void | Promise<void>;
|
|
1026
|
+
readonly afterDirectorySync?: (path: string) => void;
|
|
1027
|
+
}): Promise<JobRetainedRecordSource>;
|
|
1028
|
+
export async function prepareJobSource(options: {
|
|
1029
|
+
readonly root: JobRootIdentity;
|
|
1030
|
+
readonly stateRoot: string;
|
|
1031
|
+
readonly fingerprint: string;
|
|
1032
|
+
readonly request: PublishRequestV3 & { readonly result: PackageResultV3 };
|
|
1033
|
+
readonly readPublished?: JobPublicationReader;
|
|
1034
|
+
readonly partsEnumerator?: JobPartsEnumerator;
|
|
1035
|
+
readonly afterSnapshot?: () => void | Promise<void>;
|
|
1036
|
+
readonly afterDirectorySync?: (path: string) => void;
|
|
1037
|
+
}): Promise<JobRetainedSource>;
|
|
1038
|
+
export async function prepareJobSource(options: {
|
|
1039
|
+
readonly root: JobRootIdentity;
|
|
1040
|
+
readonly stateRoot: string;
|
|
1041
|
+
readonly fingerprint: string;
|
|
1042
|
+
readonly request: JobPublishRequest | PublishRequestV3;
|
|
1043
|
+
readonly readPublished?: JobPublicationReader;
|
|
1044
|
+
readonly readRecordPublished?: RecordPublicationReader;
|
|
1045
|
+
readonly partsEnumerator?: JobPartsEnumerator;
|
|
1046
|
+
readonly afterSnapshot?: () => void | Promise<void>;
|
|
1047
|
+
readonly afterDirectorySync?: (path: string) => void;
|
|
1048
|
+
}): Promise<JobRetainedSourceV3>;
|
|
1049
|
+
export async function prepareJobSource(options: {
|
|
1050
|
+
readonly root: JobRootIdentity;
|
|
1051
|
+
readonly stateRoot: string;
|
|
1052
|
+
readonly fingerprint: string;
|
|
1053
|
+
readonly request: JobPublishRequest | PublishRequestV3;
|
|
1054
|
+
readonly readPublished?: JobPublicationReader;
|
|
1055
|
+
readonly readRecordPublished?: RecordPublicationReader;
|
|
1056
|
+
readonly partsEnumerator?: JobPartsEnumerator;
|
|
1057
|
+
readonly afterSnapshot?: () => void | Promise<void>;
|
|
1058
|
+
readonly afterDirectorySync?: (path: string) => void;
|
|
1059
|
+
}): Promise<JobRetainedSourceV3> {
|
|
1060
|
+
if ('kind' in options.request.result) {
|
|
1061
|
+
assertJobApiSchema(options.request.schema, JOB_API_V3_SCHEMA);
|
|
1062
|
+
if (options.request.result.kind !== 'package') {
|
|
1063
|
+
return prepareJobRecordSource({
|
|
1064
|
+
root: options.root,
|
|
1065
|
+
stateRoot: options.stateRoot,
|
|
1066
|
+
fingerprint: options.fingerprint,
|
|
1067
|
+
request: {
|
|
1068
|
+
freeze: parseRecordFreeze(options.request.freeze),
|
|
1069
|
+
result: options.request.result,
|
|
1070
|
+
},
|
|
1071
|
+
readRecordPublished: options.readRecordPublished,
|
|
1072
|
+
afterSnapshot: options.afterSnapshot,
|
|
1073
|
+
afterDirectorySync: options.afterDirectorySync,
|
|
1074
|
+
});
|
|
1075
|
+
}
|
|
1076
|
+
const strippedRequest: JobPublishRequest = {
|
|
1077
|
+
schema: 'rig-review/job-api@2',
|
|
1078
|
+
jobId: options.request.jobId,
|
|
1079
|
+
requestId: options.request.requestId,
|
|
1080
|
+
verb: 'publish',
|
|
1081
|
+
expectedGeneration: options.request.expectedGeneration,
|
|
1082
|
+
idempotencyKey: options.request.idempotencyKey,
|
|
1083
|
+
freeze: options.request.freeze,
|
|
1084
|
+
result: stripPackageResultKind(options.request.result),
|
|
1085
|
+
};
|
|
1086
|
+
return prepareJobSource({
|
|
1087
|
+
...options,
|
|
1088
|
+
request: strippedRequest,
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
const { root } = options;
|
|
1092
|
+
const request = options.request as JobPublishRequest;
|
|
313
1093
|
assertJobRoot(root);
|
|
314
1094
|
const record = request.freeze.record;
|
|
315
1095
|
let project: ReturnType<typeof readProject> | null = null;
|