@ship.zone/runner 0.2.3 → 1.0.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/ts/api-client.ts CHANGED
@@ -14,17 +14,16 @@ import type {
14
14
  ICompleteJobRequest,
15
15
  ICompleteJobResponse,
16
16
  IDiscoveryResponse,
17
+ IErrorResponse,
17
18
  IJobHeartbeatRequest,
18
19
  IJobHeartbeatResponse,
19
20
  IJobIdentity,
20
21
  IJobSource,
21
22
  ILogAcknowledgement,
22
23
  ILogChunk,
23
- IProtocolLimits,
24
24
  IRecoverAttemptRequest,
25
25
  IRegisterRunnerRequest,
26
26
  IRegisterRunnerResponse,
27
- IRunnerCredential,
28
27
  IRunnerHeartbeatRequest,
29
28
  IRunnerHeartbeatResponse,
30
29
  IStartSessionRequest,
@@ -35,8 +34,10 @@ import type {
35
34
  TCacheDownload,
36
35
  TOpenTransferBody,
37
36
  } from './interfaces.ts';
38
- import { ciSpecStatus, runnerProtocolBasePath, runnerProtocolIdentifier } from './plugins.ts';
39
- import { isRecord, validateHttpUrl } from './validation.ts';
37
+ import { runnerProtocolBasePath } from './plugins.ts';
38
+ import { runnerSpecVersion, specMajorVersionsMatch } from './spec-version.ts';
39
+ import { isProtocolTimestamp, isRecord, validateHttpUrl } from './validation.ts';
40
+ import { isValidWireMessage, type TWireSchemaName, validateWireMessage } from './wire-schema.ts';
40
41
 
41
42
  export type TRunnerFetch = (
42
43
  input: RequestInfo | URL,
@@ -57,6 +58,7 @@ export interface IRunnerApiClientOptions {
57
58
  }
58
59
 
59
60
  interface IJsonRequestOptions {
61
+ requestSchema: TWireSchemaName;
60
62
  token?: string;
61
63
  signal?: AbortSignal;
62
64
  fenced?: boolean;
@@ -73,8 +75,6 @@ const retryableStatuses = new Set([429, 502, 503, 504]);
73
75
  const maximumAttempts = 4;
74
76
  const identifierPattern = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
75
77
  const sha256Pattern = /^[a-f0-9]{64}$/;
76
- const timestampPattern =
77
- /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|[+-](\d{2}):(\d{2}))$/;
78
78
 
79
79
  const defaultSleep = (milliseconds: number, signal?: AbortSignal): Promise<void> =>
80
80
  new Promise((resolve, reject) => {
@@ -157,185 +157,41 @@ const parseRetryAfter = (value: string | null): number | undefined => {
157
157
  return Math.min(Math.max(0, timestamp - Date.now()), 30_000);
158
158
  };
159
159
 
160
- const exactRecord = (
161
- value: unknown,
162
- required: readonly string[],
163
- optional: readonly string[] = [],
164
- field = 'coordinator response',
165
- ): Record<string, unknown> => {
166
- if (!isRecord(value)) throw new ProtocolError(`Invalid ${field}`);
167
- const allowed = new Set([...required, ...optional]);
168
- if (
169
- required.some((key) => !Object.hasOwn(value, key)) ||
170
- Object.keys(value).some((key) => !allowed.has(key))
171
- ) {
172
- throw new ProtocolError(`Invalid ${field}`);
160
+ const requireCompatibleSpec = (spec: string, message: string): string => {
161
+ if (!specMajorVersionsMatch(spec, runnerSpecVersion)) {
162
+ throw new ProtocolError(
163
+ `${message}: coordinator specification ${spec} and runner specification ${runnerSpecVersion} have different major versions`,
164
+ );
173
165
  }
174
- return value;
166
+ return spec;
175
167
  };
176
168
 
177
- const stringField = (
178
- value: unknown,
179
- field: string,
180
- minimumLength: number,
181
- maximumLength: number,
182
- pattern?: RegExp,
183
- ): string => {
169
+ const parseClaimResponse = (value: unknown): IClaimJobResponse => {
170
+ if (!isRecord(value)) throw new ProtocolError('Invalid claim response');
171
+ const allowed = new Set(['serverTime', 'retryAfterMs', 'lease']);
184
172
  if (
185
- typeof value !== 'string' || value.length < minimumLength || value.length > maximumLength ||
186
- (pattern && !pattern.test(value))
173
+ !Object.hasOwn(value, 'serverTime') || !Object.hasOwn(value, 'lease') ||
174
+ Object.keys(value).some((key) => !allowed.has(key))
187
175
  ) {
188
- throw new ProtocolError(`Invalid coordinator field: ${field}`);
176
+ throw new ProtocolError('Invalid claim response');
189
177
  }
190
- return value;
191
- };
192
-
193
- const identifierField = (value: unknown, field: string): string =>
194
- stringField(value, field, 1, 64, identifierPattern);
195
-
196
- const sha256Field = (value: unknown, field: string): string =>
197
- stringField(value, field, 64, 64, sha256Pattern);
198
-
199
- const integerField = (
200
- value: unknown,
201
- field: string,
202
- minimum: number,
203
- maximum: number,
204
- ): number => {
205
- if (
206
- typeof value !== 'number' || !Number.isSafeInteger(value) || value < minimum ||
207
- value > maximum
208
- ) {
209
- throw new ProtocolError(`Invalid coordinator field: ${field}`);
178
+ if (typeof value.serverTime !== 'string' || !isProtocolTimestamp(value.serverTime)) {
179
+ throw new ProtocolError('Invalid coordinator field: serverTime');
210
180
  }
211
- return value;
212
- };
213
-
214
- const timestampField = (value: unknown, field: string): string => {
215
- if (typeof value !== 'string') throw new ProtocolError(`Invalid coordinator field: ${field}`);
216
- const match = timestampPattern.exec(value);
217
- if (!match) throw new ProtocolError(`Invalid coordinator field: ${field}`);
218
- const year = Number(match[1]);
219
- const month = Number(match[2]);
220
- const day = Number(match[3]);
221
- const hour = Number(match[4]);
222
- const minute = Number(match[5]);
223
- const second = Number(match[6]);
224
- const offsetHour = match[7] === undefined ? 0 : Number(match[7]);
225
- const offsetMinute = match[8] === undefined ? 0 : Number(match[8]);
226
- const lastDay = new Date(Date.UTC(year, month, 0)).getUTCDate();
227
181
  if (
228
- month < 1 || month > 12 || day < 1 || day > lastDay || hour > 23 || minute > 59 ||
229
- second > 59 || offsetHour > 23 || offsetMinute > 59 || !Number.isFinite(Date.parse(value))
182
+ value.retryAfterMs !== undefined &&
183
+ (typeof value.retryAfterMs !== 'number' || !Number.isSafeInteger(value.retryAfterMs) ||
184
+ value.retryAfterMs < 0 || value.retryAfterMs > 30_000)
230
185
  ) {
231
- throw new ProtocolError(`Invalid coordinator field: ${field}`);
186
+ throw new ProtocolError('Invalid coordinator field: retryAfterMs');
232
187
  }
233
- return value;
234
- };
235
-
236
- const parseCredential = (value: unknown, field = 'credential'): IRunnerCredential => {
237
- const record = exactRecord(
238
- value,
239
- ['credentialId', 'runnerId', 'token', 'expiresAt'],
240
- ['previousCredentialValidUntil'],
241
- field,
242
- );
243
- return {
244
- credentialId: identifierField(record.credentialId, `${field}.credentialId`),
245
- runnerId: identifierField(record.runnerId, `${field}.runnerId`),
246
- token: stringField(record.token, `${field}.token`, 32, 8192),
247
- expiresAt: timestampField(record.expiresAt, `${field}.expiresAt`),
248
- ...(record.previousCredentialValidUntil === undefined ? {} : {
249
- previousCredentialValidUntil: timestampField(
250
- record.previousCredentialValidUntil,
251
- `${field}.previousCredentialValidUntil`,
252
- ),
253
- }),
254
- };
255
- };
256
-
257
- const parseProtocolLimits = (value: unknown): IProtocolLimits => {
258
- const record = exactRecord(
259
- value,
260
- [
261
- 'maximumJsonBytes',
262
- 'maximumLogChunkBytes',
263
- 'maximumTotalLogBytes',
264
- 'minimumLeaseSeconds',
265
- 'maximumLeaseSeconds',
266
- ],
267
- [],
268
- 'discovery limits',
269
- );
270
- const limits: IProtocolLimits = {
271
- maximumJsonBytes: integerField(
272
- record.maximumJsonBytes,
273
- 'limits.maximumJsonBytes',
274
- 1,
275
- 2_097_152,
276
- ),
277
- maximumLogChunkBytes: integerField(
278
- record.maximumLogChunkBytes,
279
- 'limits.maximumLogChunkBytes',
280
- 1,
281
- 65_536,
282
- ),
283
- maximumTotalLogBytes: integerField(
284
- record.maximumTotalLogBytes,
285
- 'limits.maximumTotalLogBytes',
286
- 0,
287
- 1_073_741_824,
288
- ),
289
- minimumLeaseSeconds: integerField(
290
- record.minimumLeaseSeconds,
291
- 'limits.minimumLeaseSeconds',
292
- 30,
293
- 600,
294
- ),
295
- maximumLeaseSeconds: integerField(
296
- record.maximumLeaseSeconds,
297
- 'limits.maximumLeaseSeconds',
298
- 30,
299
- 600,
300
- ),
301
- };
302
- if (limits.minimumLeaseSeconds > limits.maximumLeaseSeconds) {
303
- throw new ProtocolError('Coordinator discovery lease limits are incoherent');
304
- }
305
- return limits;
306
- };
307
-
308
- const parseTransferRecord = (value: unknown): ITransferRecord => {
309
- const record = exactRecord(
310
- value,
311
- [
312
- 'name',
313
- 'format',
314
- 'sha256',
315
- 'sizeBytes',
316
- 'extractedSizeBytes',
317
- 'entryCount',
318
- 'createdAt',
319
- ],
320
- [],
321
- 'transfer record',
322
- );
323
- if (record.format !== 'tar.gz') {
324
- throw new ProtocolError('Invalid coordinator field: transferRecord.format');
188
+ if (value.lease !== null && !isRecord(value.lease)) {
189
+ throw new ProtocolError('Invalid coordinator field: lease');
325
190
  }
326
191
  return {
327
- name: identifierField(record.name, 'transferRecord.name'),
328
- format: 'tar.gz',
329
- sha256: sha256Field(record.sha256, 'transferRecord.sha256'),
330
- sizeBytes: integerField(record.sizeBytes, 'transferRecord.sizeBytes', 0, 17_179_869_184),
331
- extractedSizeBytes: integerField(
332
- record.extractedSizeBytes,
333
- 'transferRecord.extractedSizeBytes',
334
- 0,
335
- 137_438_953_472,
336
- ),
337
- entryCount: integerField(record.entryCount, 'transferRecord.entryCount', 0, 1_000_000),
338
- createdAt: timestampField(record.createdAt, 'transferRecord.createdAt'),
192
+ serverTime: value.serverTime,
193
+ ...(value.retryAfterMs === undefined ? {} : { retryAfterMs: value.retryAfterMs }),
194
+ lease: value.lease,
339
195
  };
340
196
  };
341
197
 
@@ -405,6 +261,13 @@ const sanitizeErrorText = (value: string): string =>
405
261
  return codePoint < 0x20 || codePoint === 0x7f ? '?' : character;
406
262
  }).join('');
407
263
 
264
+ const identifierField = (value: string, field: string): string => {
265
+ if (!identifierPattern.test(value)) {
266
+ throw new ProtocolError(`Invalid runner field: ${field}`);
267
+ }
268
+ return value;
269
+ };
270
+
408
271
  const errorDetail = (body: Uint8Array): string | undefined => {
409
272
  if (body.byteLength === 0) return undefined;
410
273
  let parsed: unknown;
@@ -413,14 +276,8 @@ const errorDetail = (body: Uint8Array): string | undefined => {
413
276
  } catch {
414
277
  return undefined;
415
278
  }
416
- if (!isRecord(parsed) || !isRecord(parsed.error)) return undefined;
417
- const { code, message } = parsed.error;
418
- if (
419
- typeof code !== 'string' || !/^[a-z][a-z0-9_]{0,63}$/.test(code) ||
420
- typeof message !== 'string' || message.length < 1 || message.length > 512
421
- ) {
422
- return undefined;
423
- }
279
+ if (!isValidWireMessage('ErrorResponse', parsed)) return undefined;
280
+ const { code, message } = (parsed as IErrorResponse).error;
424
281
  return `${code}: ${sanitizeErrorText(message)}`;
425
282
  };
426
283
 
@@ -474,25 +331,18 @@ export class RunnerApiClient {
474
331
  if (response.status !== 200) {
475
332
  await this.throwResponseError(response, false, 'Coordinator discovery failed');
476
333
  }
477
- const value = exactRecord(
334
+ const discovery = validateWireMessage<IDiscoveryResponse>(
335
+ 'DiscoveryResponse',
478
336
  await parseJsonResponse(response, this.options.maximumResponseBytes),
479
- ['protocol', 'basePath', 'status', 'serverTime', 'limits'],
480
- [],
481
- 'discovery response',
482
337
  );
483
- if (
484
- value.protocol !== runnerProtocolIdentifier || value.basePath !== runnerProtocolBasePath ||
485
- value.status !== ciSpecStatus
486
- ) {
338
+ if (discovery.basePath !== runnerProtocolBasePath) {
487
339
  throw new ProtocolError('Coordinator discovery is incompatible with this runner');
488
340
  }
489
- return {
490
- protocol: runnerProtocolIdentifier,
491
- basePath: runnerProtocolBasePath,
492
- status: ciSpecStatus,
493
- serverTime: timestampField(value.serverTime, 'serverTime'),
494
- limits: parseProtocolLimits(value.limits),
495
- };
341
+ requireCompatibleSpec(discovery.spec, 'Coordinator discovery is incompatible');
342
+ if (discovery.limits.minimumLeaseSeconds > discovery.limits.maximumLeaseSeconds) {
343
+ throw new ProtocolError('Coordinator discovery lease limits are incoherent');
344
+ }
345
+ return discovery;
496
346
  }
497
347
  throw new CoordinatorError('Coordinator discovery failed');
498
348
  }
@@ -502,99 +352,60 @@ export class RunnerApiClient {
502
352
  bootstrapToken: string,
503
353
  signal?: AbortSignal,
504
354
  ): Promise<IRegisterRunnerResponse> {
505
- const value = exactRecord(
506
- await this.requestJson('runners/register', request, { token: bootstrapToken, signal }),
507
- ['protocol', 'serverTime', 'registrationReplayUntil', 'credential'],
508
- [],
509
- 'registration response',
355
+ const response = validateWireMessage<IRegisterRunnerResponse>(
356
+ 'RegisterRunnerResponse',
357
+ await this.requestJson('runners/register', request, {
358
+ requestSchema: 'RegisterRunnerRequest',
359
+ token: bootstrapToken,
360
+ signal,
361
+ }),
510
362
  );
511
- if (value.protocol !== runnerProtocolIdentifier) {
512
- throw new ProtocolError('Coordinator returned an incompatible registration protocol');
513
- }
514
- return {
515
- protocol: runnerProtocolIdentifier,
516
- serverTime: timestampField(value.serverTime, 'serverTime'),
517
- registrationReplayUntil: timestampField(
518
- value.registrationReplayUntil,
519
- 'registrationReplayUntil',
520
- ),
521
- credential: parseCredential(value.credential),
522
- };
363
+ requireCompatibleSpec(response.spec, 'Coordinator registration is incompatible');
364
+ return response;
523
365
  }
524
366
 
525
367
  public async startSession(
526
368
  request: IStartSessionRequest,
527
369
  signal?: AbortSignal,
528
370
  ): Promise<IStartSessionResponse> {
529
- const value = exactRecord(
371
+ const response = validateWireMessage<IStartSessionResponse>(
372
+ 'StartSessionResponse',
530
373
  await this.requestJson(
531
374
  `runners/${encodeURIComponent(request.runnerId)}/sessions`,
532
375
  request,
533
- { signal },
376
+ { requestSchema: 'StartSessionRequest', signal },
534
377
  ),
535
- ['sessionId', 'protocol', 'serverTime'],
536
- ['credential'],
537
- 'session response',
538
378
  );
539
- if (value.protocol !== runnerProtocolIdentifier) {
540
- throw new ProtocolError('Coordinator returned an incompatible session protocol');
541
- }
542
- return {
543
- sessionId: identifierField(value.sessionId, 'sessionId'),
544
- protocol: runnerProtocolIdentifier,
545
- serverTime: timestampField(value.serverTime, 'serverTime'),
546
- ...(value.credential === undefined ? {} : { credential: parseCredential(value.credential) }),
547
- };
379
+ requireCompatibleSpec(response.spec, 'Coordinator session is incompatible');
380
+ return response;
548
381
  }
549
382
 
550
383
  public async heartbeatRunner(
551
384
  request: IRunnerHeartbeatRequest,
552
385
  signal?: AbortSignal,
553
386
  ): Promise<IRunnerHeartbeatResponse> {
554
- const value = exactRecord(
387
+ return validateWireMessage<IRunnerHeartbeatResponse>(
388
+ 'RunnerHeartbeatResponse',
555
389
  await this.requestJson(
556
390
  `runners/${encodeURIComponent(request.runnerId)}/heartbeat`,
557
391
  request,
558
- { signal },
392
+ { requestSchema: 'RunnerHeartbeatRequest', signal },
559
393
  ),
560
- ['serverTime', 'drainRequested'],
561
- ['credential'],
562
- 'runner heartbeat response',
563
394
  );
564
- if (typeof value.drainRequested !== 'boolean') {
565
- throw new ProtocolError('Invalid coordinator field: drainRequested');
566
- }
567
- return {
568
- serverTime: timestampField(value.serverTime, 'serverTime'),
569
- drainRequested: value.drainRequested,
570
- ...(value.credential === undefined ? {} : { credential: parseCredential(value.credential) }),
571
- };
572
395
  }
573
396
 
574
397
  public async claimJob(
575
398
  request: IClaimJobRequest,
576
399
  signal?: AbortSignal,
577
400
  ): Promise<IClaimJobResponse> {
578
- const value = exactRecord(
579
- await this.requestJson('jobs/claim', request, { signal }),
580
- ['serverTime', 'lease'],
581
- ['retryAfterMs'],
582
- 'claim response',
401
+ return parseClaimResponse(
402
+ await this.requestJson('jobs/claim', request, { requestSchema: 'ClaimJobRequest', signal }),
583
403
  );
584
- if (value.lease !== null && !isRecord(value.lease)) {
585
- throw new ProtocolError('Invalid coordinator field: lease');
586
- }
587
- return {
588
- serverTime: timestampField(value.serverTime, 'serverTime'),
589
- ...(value.retryAfterMs === undefined ? {} : {
590
- retryAfterMs: integerField(value.retryAfterMs, 'retryAfterMs', 0, 30_000),
591
- }),
592
- lease: value.lease,
593
- };
594
404
  }
595
405
 
596
406
  public async acceptJob(request: IAcceptJobRequest, signal?: AbortSignal): Promise<void> {
597
407
  await this.requestJson(this.jobPath(request.identity, 'accept'), request, {
408
+ requestSchema: 'AcceptJobRequest',
598
409
  signal,
599
410
  fenced: true,
600
411
  expectedStatus: 204,
@@ -605,80 +416,44 @@ export class RunnerApiClient {
605
416
  request: IJobHeartbeatRequest,
606
417
  signal?: AbortSignal,
607
418
  ): Promise<IJobHeartbeatResponse> {
608
- const value = exactRecord(
419
+ return validateWireMessage<IJobHeartbeatResponse>(
420
+ 'JobHeartbeatResponse',
609
421
  await this.requestJson(this.jobPath(request.identity, 'heartbeat'), request, {
422
+ requestSchema: 'JobHeartbeatRequest',
610
423
  signal,
611
424
  fenced: true,
612
425
  }),
613
- ['serverTime', 'leaseExpiresAt'],
614
- ['cancellation'],
615
- 'job heartbeat response',
616
426
  );
617
- let cancellation: IJobHeartbeatResponse['cancellation'];
618
- if (value.cancellation !== undefined) {
619
- const directive = exactRecord(
620
- value.cancellation,
621
- ['requestId', 'requestedAt', 'reason', 'terminateBy'],
622
- [],
623
- 'cancellation directive',
624
- );
625
- if (
626
- directive.reason !== 'user_requested' && directive.reason !== 'superseded' &&
627
- directive.reason !== 'policy' && directive.reason !== 'coordinator_shutdown'
628
- ) {
629
- throw new ProtocolError('Invalid coordinator field: cancellation.reason');
630
- }
631
- cancellation = {
632
- requestId: identifierField(directive.requestId, 'cancellation.requestId'),
633
- requestedAt: timestampField(directive.requestedAt, 'cancellation.requestedAt'),
634
- reason: directive.reason,
635
- terminateBy: timestampField(directive.terminateBy, 'cancellation.terminateBy'),
636
- };
637
- }
638
- return {
639
- serverTime: timestampField(value.serverTime, 'serverTime'),
640
- leaseExpiresAt: timestampField(value.leaseExpiresAt, 'leaseExpiresAt'),
641
- ...(cancellation ? { cancellation } : {}),
642
- };
643
427
  }
644
428
 
645
429
  public async appendLog(chunk: ILogChunk, signal?: AbortSignal): Promise<ILogAcknowledgement> {
646
- const value = exactRecord(
430
+ return validateWireMessage<ILogAcknowledgement>(
431
+ 'LogAcknowledgement',
647
432
  await this.requestJson(this.jobPath(chunk.identity, 'logs'), chunk, {
433
+ requestSchema: 'LogChunk',
648
434
  signal,
649
435
  fenced: true,
650
436
  }),
651
- ['serverTime', 'nextSequence'],
652
- [],
653
- 'log acknowledgement',
654
437
  );
655
- return {
656
- serverTime: timestampField(value.serverTime, 'serverTime'),
657
- nextSequence: integerField(value.nextSequence, 'nextSequence', 0, Number.MAX_SAFE_INTEGER),
658
- };
659
438
  }
660
439
 
661
440
  public async completeJob(
662
441
  request: ICompleteJobRequest,
663
442
  signal?: AbortSignal,
664
443
  ): Promise<ICompleteJobResponse> {
665
- const value = exactRecord(
444
+ return validateWireMessage<ICompleteJobResponse>(
445
+ 'CompleteJobResponse',
666
446
  await this.requestJson(this.jobPath(request.identity, 'complete'), request, {
447
+ requestSchema: 'CompleteJobRequest',
667
448
  signal,
668
449
  fenced: true,
669
450
  }),
670
- ['serverTime', 'accepted'],
671
- [],
672
- 'completion response',
673
451
  );
674
- if (value.accepted !== true) {
675
- throw new ProtocolError('Invalid coordinator field: accepted');
676
- }
677
- return { serverTime: timestampField(value.serverTime, 'serverTime'), accepted: true };
678
452
  }
679
453
 
680
454
  public async abandonJob(request: IAbandonJobRequest, signal?: AbortSignal): Promise<void> {
681
455
  await this.requestJson(this.jobPath(request.identity, 'abandon'), request, {
456
+ requestSchema: 'AbandonJobRequest',
682
457
  signal,
683
458
  fenced: true,
684
459
  expectedStatus: 204,
@@ -689,7 +464,11 @@ export class RunnerApiClient {
689
464
  request: IRecoverAttemptRequest,
690
465
  signal?: AbortSignal,
691
466
  ): Promise<void> {
692
- await this.requestJson('jobs/recover', request, { signal, expectedStatus: 204 });
467
+ await this.requestJson('jobs/recover', request, {
468
+ requestSchema: 'RecoverAttemptRequest',
469
+ signal,
470
+ expectedStatus: 204,
471
+ });
693
472
  }
694
473
 
695
474
  public async downloadSource(
@@ -834,9 +613,10 @@ export class RunnerApiClient {
834
613
  private async requestJson(
835
614
  path: string,
836
615
  body: unknown,
837
- options: IJsonRequestOptions = {},
616
+ options: IJsonRequestOptions,
838
617
  ): Promise<unknown> {
839
618
  const token = options.token ?? this.requireRunnerToken();
619
+ validateWireMessage(options.requestSchema, body);
840
620
  let serializedBody: string;
841
621
  try {
842
622
  serializedBody = JSON.stringify(body);
@@ -989,7 +769,8 @@ export class RunnerApiClient {
989
769
  if (response.status !== 200) {
990
770
  await this.throwResponseError(response, true, 'Coordinator upload failed');
991
771
  }
992
- const record = parseTransferRecord(
772
+ const record = validateWireMessage<ITransferRecord>(
773
+ 'TransferRecord',
993
774
  await parseJsonResponse(response, this.options.maximumResponseBytes),
994
775
  );
995
776
  if (
@@ -4,6 +4,7 @@ import {
4
4
  LeaseLostError,
5
5
  ProtocolError,
6
6
  ResourceCleanupError,
7
+ SecretDisclosureError,
7
8
  } from './errors.ts';
8
9
  import type {
9
10
  IArtifactDeclaration,
@@ -59,8 +60,8 @@ const validateArtifacts = (
59
60
  if (context.job.permissions.artifacts !== 'write') {
60
61
  throw new ProtocolError('Job does not permit artifact uploads');
61
62
  }
62
- if (!context.job.requirements.features.includes('artifacts.v1')) {
63
- throw new ProtocolError('Job does not declare the artifacts.v1 feature');
63
+ if (!context.job.requirements.features.includes('artifacts')) {
64
+ throw new ProtocolError('Job does not declare the artifacts feature');
64
65
  }
65
66
  const maximumArtifacts = Math.min(
66
67
  config.maximumArtifacts,
@@ -170,6 +171,7 @@ export class ArtifactManager implements IArtifactManager {
170
171
  maximumExtractedBytes: artifact.maximumExtractedBytes,
171
172
  maximumEntries: artifact.maximumEntries,
172
173
  allowSymlinks: true,
174
+ redactionSet: context.redactionSet,
173
175
  signal: context.signal,
174
176
  });
175
177
  const transferRequestId = crypto.randomUUID();
@@ -209,7 +211,11 @@ export class ArtifactManager implements IArtifactManager {
209
211
  if (optionalFailureMustPropagate(operationError, artifact, context.signal)) {
210
212
  throw operationError;
211
213
  }
212
- this.onMessage?.(`Optional artifact ${artifact.name} was omitted`);
214
+ this.onMessage?.(
215
+ operationError instanceof SecretDisclosureError
216
+ ? `Optional artifact ${artifact.name} was omitted: it contains a redacted secret value`
217
+ : `Optional artifact ${artifact.name} was omitted`,
218
+ );
213
219
  continue;
214
220
  }
215
221
  this.onMessage?.(`Artifact ${artifact.name} uploaded`);
@@ -101,8 +101,8 @@ const validateCaches = (
101
101
  if (job.permissions.caches === 'none') {
102
102
  throw new ProtocolError('Job does not permit cache transfers');
103
103
  }
104
- if (!job.requirements.features.includes('caches.v1')) {
105
- throw new ProtocolError('Job does not declare the caches.v1 feature');
104
+ if (!job.requirements.features.includes('caches')) {
105
+ throw new ProtocolError('Job does not declare the caches feature');
106
106
  }
107
107
  if (caches.length > limits.count) throw new ProtocolError('Job declares too many caches');
108
108
  const allPaths: Array<{ cache: string; path: string }> = [];
@@ -405,6 +405,7 @@ export class CacheManager implements ICacheManager {
405
405
  maximumExtractedBytes: cache.maximumExtractedBytes,
406
406
  maximumEntries: cache.maximumEntries,
407
407
  allowSymlinks: false,
408
+ redactionSet: context.redactionSet,
408
409
  signal: context.signal,
409
410
  });
410
411
  const transferRequestId = crypto.randomUUID();
package/ts/cli.ts CHANGED
@@ -16,10 +16,16 @@ import type {
16
16
  IRunnerCapabilities,
17
17
  IRunnerConfig,
18
18
  } from './interfaces.ts';
19
- import { runnerProtocolIdentifier, runnerVersion } from './interfaces.ts';
19
+ import { runnerVersion } from './interfaces.ts';
20
20
  import { OciExecutor } from './oci-executor.ts';
21
21
  import { RegistrationStateStore } from './registration-state.ts';
22
- import { reconcileProtocolLimits, runnerCapabilities, ShipRunner } from './runner.ts';
22
+ import {
23
+ capabilitiesForCoordinator,
24
+ reconcileProtocolLimits,
25
+ runnerCapabilities,
26
+ ShipRunner,
27
+ } from './runner.ts';
28
+ import { runnerSpecVersion } from './spec-version.ts';
23
29
  import { SourceWorkspaceManager } from './source-workspace.ts';
24
30
 
25
31
  interface IParsedArguments {
@@ -106,7 +112,7 @@ export const registerRunnerDurably = async (options: {
106
112
  const stateStore = options.stateStore ??
107
113
  new RegistrationStateStore(options.config.stateDirectory);
108
114
  const request = await stateStore.loadOrCreate({
109
- protocol: runnerProtocolIdentifier,
115
+ spec: runnerSpecVersion,
110
116
  runnerVersion,
111
117
  name: options.config.name,
112
118
  capabilities: options.capabilities,
@@ -129,7 +135,11 @@ const runInit = async (options: Map<string, string | true>): Promise<void> => {
129
135
  const helperPath = stringOption(options, 'workspace-helper-path');
130
136
  if (helperPath) config.oci.workspaceHelperPath = helperPath;
131
137
  if (options.has('allow-insecure-loopback')) config.allowInsecureLoopback = true;
132
- if (options.has('allow-network')) config.oci.allowedNetworks = ['none', 'bridge'];
138
+ if (options.has('allow-network')) {
139
+ throw new ConfigurationError(
140
+ '--allow-network is not supported: this runner does not enforce egress allowlists',
141
+ );
142
+ }
133
143
  validateRunnerConfig(config);
134
144
  const path = configPath(options);
135
145
  await saveRunnerConfig(path, config);
@@ -144,9 +154,9 @@ const runRegister = async (options: Map<string, string | true>): Promise<void> =
144
154
  }
145
155
  const api = apiFor(config);
146
156
  const executor = new OciExecutor(config);
147
- await executor.verifyRuntime();
157
+ const runtime = await executor.verifyRuntime();
148
158
  const discovery = await api.discover();
149
- const capabilities = runnerCapabilities(config);
159
+ const capabilities = capabilitiesForCoordinator(runnerCapabilities(config, runtime), discovery);
150
160
  reconcileProtocolLimits(config, discovery, capabilities);
151
161
  const registered = await registerRunnerDurably({
152
162
  configPath: path,