@ship.zone/runner 0.1.1 → 0.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ship.zone/runner",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
4
  "description": "The isolated OCI job runner for ship.zone CI/CD",
5
5
  "homepage": "https://code.foss.global/ship.zone/runner",
6
6
  "bugs": {
@@ -29,7 +29,7 @@
29
29
  }
30
30
  },
31
31
  "dependencies": {
32
- "@foss.global/ci-spec": "0.1.0",
32
+ "@foss.global/ci-spec": "0.2.0",
33
33
  "ajv": "^8.20.0"
34
34
  },
35
35
  "devDependencies": {
package/readme.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @ship.zone/runner
2
2
 
3
3
  `@ship.zone/runner` is the outbound-only OCI execution agent for ship.zone CI/CD. It implements the
4
- `foss-ci-runner/2.0-draft.1` protocol, validates compiled jobs against `@foss.global/ci-spec`, and
4
+ `foss-ci-runner/2.0-draft.2` protocol, validates compiled jobs against `@foss.global/ci-spec`, and
5
5
  runs one fenced attempt at a time on a local Docker or Podman engine.
6
6
 
7
7
  The control plane owns workflow compilation, scheduling, authorization, secrets policy, and
@@ -68,7 +68,7 @@ import { ShipRunner } from '@ship.zone/runner';
68
68
  Without an import-map entry, use the npm package directly:
69
69
 
70
70
  ```ts
71
- import { ShipRunner } from 'npm:@ship.zone/runner@0.1.0';
71
+ import { ShipRunner } from 'npm:@ship.zone/runner@0.2.0';
72
72
  ```
73
73
 
74
74
  For development in this repository, install dependencies and build the npm bundle plus the static
@@ -197,6 +197,10 @@ subsequent requests use the renewable runner credential.
197
197
 
198
198
  Transient retry statuses are 429, 502, 503, and 504. Exact retries reuse the same request ID and
199
199
  canonical body. Request, response, archive, extracted-data, entry, and stream sizes are bounded.
200
+ Each source, artifact, or cache archive also has a fixed 134,217,728-byte metadata ceiling across
201
+ its normalized UTF-8 entry paths and symbolic-link targets. Implicit parent directories count
202
+ against the workspace entry limit, and symbolic-link validation retains at most 1,000,000 canonical
203
+ path components.
200
204
 
201
205
  ## Library API
202
206
 
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@ship.zone/runner',
6
- version: '0.1.1',
6
+ version: '0.2.1',
7
7
  description: 'The isolated OCI job runner for ship.zone CI/CD'
8
8
  }
@@ -273,7 +273,14 @@ export class CacheManager implements ICacheManager {
273
273
  public async restore(context: ICacheRestoreContext): Promise<void> {
274
274
  const limits = validateCaches(this.config, context.job);
275
275
  let workspaceBytes = context.job.source.extractedSizeBytes;
276
- let workspaceEntries = context.job.source.entryCount;
276
+ let workspaceEntries = context.workspaceEntryCount;
277
+ if (
278
+ !Number.isSafeInteger(workspaceEntries) ||
279
+ workspaceEntries < 0 ||
280
+ workspaceEntries > limits.workspaceEntries
281
+ ) {
282
+ throw new ProtocolError('Current workspace entry count exceeds its effective limit');
283
+ }
277
284
  for (const cache of context.job.caches) {
278
285
  if (context.signal.aborted) throw context.signal.reason;
279
286
  const download = await this.api.downloadCache(context.identity, cache.name, context.signal);
@@ -310,24 +317,20 @@ export class CacheManager implements ICacheManager {
310
317
  let primaryError: unknown;
311
318
  try {
312
319
  await Deno.mkdir(restoreRoot, { recursive: true, mode: 0o700 });
313
- await ensureStagingCapacity(
314
- restoreRoot,
315
- staged.metadata.extractedSizeBytes,
316
- staged.metadata.entryCount + 1,
317
- this.config.transferStagingReserveBytes,
318
- this.config.transferStagingReserveInodes,
319
- );
320
320
  restorePath = await Deno.makeTempDir({
321
321
  dir: restoreRoot,
322
322
  prefix: 'cache-',
323
323
  });
324
324
  await Deno.chmod(restorePath, 0o700);
325
- await extractTarGzipArchive({
325
+ const extracted = await extractTarGzipArchive({
326
326
  archivePath: staged.path,
327
327
  destinationPath: restorePath,
328
328
  expectedMetadata: staged.metadata,
329
329
  maximumExtractedBytes: Math.min(cache.maximumExtractedBytes, remainingWorkspaceBytes),
330
330
  maximumEntries: Math.min(cache.maximumEntries, remainingWorkspaceEntries),
331
+ maximumMaterializedEntries: remainingWorkspaceEntries,
332
+ reserveBytes: this.config.transferStagingReserveBytes,
333
+ reserveInodes: this.config.transferStagingReserveInodes,
331
334
  allowSymlinks: false,
332
335
  allowedPaths: cache.paths,
333
336
  requireAllowedPaths: true,
@@ -341,7 +344,7 @@ export class CacheManager implements ICacheManager {
341
344
  );
342
345
  workspaceEntries = checkedAdd(
343
346
  workspaceEntries,
344
- staged.metadata.entryCount,
347
+ extracted.materializedEntryCount,
345
348
  'Restored workspace entry count overflow',
346
349
  );
347
350
  } catch (error) {
package/ts/interfaces.ts CHANGED
@@ -2,7 +2,7 @@ import * as plugins from './plugins.ts';
2
2
  import denoConfig from '../deno.json' with { type: 'json' };
3
3
 
4
4
  export const runnerVersion: string = denoConfig.version;
5
- export const runnerProtocolIdentifier: 'foss-ci-runner/2.0-draft.1' =
5
+ export const runnerProtocolIdentifier: 'foss-ci-runner/2.0-draft.2' =
6
6
  plugins.runnerProtocolIdentifier;
7
7
 
8
8
  export type TRunnerProtocolIdentifier = typeof runnerProtocolIdentifier;
@@ -305,7 +305,7 @@ export interface ICacheDeclaration {
305
305
  }
306
306
 
307
307
  export interface ICompiledRunnerJob {
308
- specVersion: '2.0-draft.1';
308
+ specVersion: '2.0-draft.2';
309
309
  sourceObjectId: string;
310
310
  workflowDigest: string;
311
311
  compiledPlanDigest: string;
@@ -500,6 +500,7 @@ export interface IJobExecutor {
500
500
  export interface IPreparedWorkspace {
501
501
  path: string;
502
502
  metadata: IWorkspaceTreeMetadata;
503
+ materializedEntryCount: number;
503
504
  cleanup(): Promise<void>;
504
505
  }
505
506
 
@@ -528,6 +529,7 @@ export interface IArtifactManager {
528
529
 
529
530
  export interface ICacheRestoreContext {
530
531
  workspacePath: string;
532
+ workspaceEntryCount: number;
531
533
  job: Pick<ICompiledRunnerJob, 'caches' | 'permissions' | 'requirements' | 'source'>;
532
534
  identity: IJobIdentity;
533
535
  signal: AbortSignal;
@@ -81,6 +81,32 @@ export type TOciRuntimeCommandRunner = (
81
81
  request: IOciRuntimeCommandRequest,
82
82
  ) => Promise<IOciRuntimeCommandResult>;
83
83
 
84
+ export interface IRuntimeMakeTempOptions {
85
+ dir?: string;
86
+ prefix?: string;
87
+ suffix?: string;
88
+ }
89
+
90
+ export interface IRuntimeRemoveOptions {
91
+ recursive?: boolean;
92
+ }
93
+
94
+ export interface IRuntimeDirectoryEntry {
95
+ name: string;
96
+ isFile: boolean;
97
+ isDirectory: boolean;
98
+ isSymlink: boolean;
99
+ }
100
+
101
+ export interface IRuntimeFileInfo {
102
+ isDirectory: boolean;
103
+ isSymlink: boolean;
104
+ uid: number | null;
105
+ mtime: Date | null;
106
+ dev: number | null;
107
+ ino: number | null;
108
+ }
109
+
84
110
  export interface IOciExecutorDependencies {
85
111
  commandRunner?: TOciRuntimeCommandRunner;
86
112
  runtimeEnvironment?: Record<string, string>;
@@ -88,17 +114,17 @@ export interface IOciExecutorDependencies {
88
114
  probeTmpfs?: (helperPath: string) => Promise<number>;
89
115
  randomId?: () => string;
90
116
  now?: () => number;
91
- makeTempDir?: (options: Deno.MakeTempOptions) => Promise<string>;
117
+ makeTempDir?: (options: IRuntimeMakeTempOptions) => Promise<string>;
92
118
  chmod?: (path: string, mode: number) => Promise<void>;
93
- remove?: (path: string, options?: Deno.RemoveOptions) => Promise<void>;
119
+ remove?: (path: string, options?: IRuntimeRemoveOptions) => Promise<void>;
94
120
  }
95
121
 
96
122
  export interface IHostTmpfsProbeScavengerDependencies {
97
123
  getUid?: () => number | undefined;
98
124
  now?: () => number;
99
- readDir?: (path: string) => AsyncIterable<Deno.DirEntry>;
100
- lstat?: (path: string) => Promise<Deno.FileInfo>;
101
- remove?: (path: string, options?: Deno.RemoveOptions) => Promise<void>;
125
+ readDir?: (path: string) => AsyncIterable<IRuntimeDirectoryEntry>;
126
+ lstat?: (path: string) => Promise<IRuntimeFileInfo>;
127
+ remove?: (path: string, options?: IRuntimeRemoveOptions) => Promise<void>;
102
128
  }
103
129
 
104
130
  export interface IWorkspaceVolumeLimits {
@@ -356,14 +382,14 @@ export const scavengeHostTmpfsProbes = async (
356
382
  const readDir = dependencies.readDir ?? ((path: string) => Deno.readDir(path));
357
383
  const lstat = dependencies.lstat ?? ((path: string) => Deno.lstat(path));
358
384
  const remove = dependencies.remove ?? ((path, options) => Deno.remove(path, options));
359
- const isEligible = (stat: Deno.FileInfo): boolean =>
385
+ const isEligible = (stat: IRuntimeFileInfo): boolean =>
360
386
  stat.isDirectory && !stat.isSymlink && stat.uid === uid && stat.mtime !== null &&
361
387
  now() - stat.mtime.getTime() > hostTmpfsProbeMaximumAgeMs;
362
388
 
363
389
  for await (const entry of readDir(directory)) {
364
390
  if (!hostTmpfsProbeNamePattern.test(entry.name)) continue;
365
391
  const path = join(directory, entry.name);
366
- let initial: Deno.FileInfo;
392
+ let initial: IRuntimeFileInfo;
367
393
  try {
368
394
  initial = await lstat(path);
369
395
  } catch (error) {
@@ -371,7 +397,7 @@ export const scavengeHostTmpfsProbes = async (
371
397
  throw error;
372
398
  }
373
399
  if (!isEligible(initial) || initial.dev === null || initial.ino === null) continue;
374
- let current: Deno.FileInfo;
400
+ let current: IRuntimeFileInfo;
375
401
  try {
376
402
  current = await lstat(path);
377
403
  } catch (error) {
@@ -934,9 +960,9 @@ export class OciExecutor implements IJobExecutor {
934
960
  private readonly now: () => number;
935
961
  private readonly resolveHelperPathImplementation: (target: TOciHelperTarget) => Promise<string>;
936
962
  private readonly probeTmpfsImplementation: (helperPath: string) => Promise<number>;
937
- private readonly makeTempDir: (options: Deno.MakeTempOptions) => Promise<string>;
963
+ private readonly makeTempDir: (options: IRuntimeMakeTempOptions) => Promise<string>;
938
964
  private readonly chmod: (path: string, mode: number) => Promise<void>;
939
- private readonly remove: (path: string, options?: Deno.RemoveOptions) => Promise<void>;
965
+ private readonly remove: (path: string, options?: IRuntimeRemoveOptions) => Promise<void>;
940
966
  private runtimeFacts?: IOciRuntimeFacts;
941
967
  private readonly preparedLeases = new Map<string, PreparedOciLease>();
942
968
 
package/ts/plugins.ts CHANGED
@@ -1,9 +1,13 @@
1
1
  export {
2
2
  ciSpecStatus,
3
+ maximumArchivePathMetadataBytes,
3
4
  runnerProtocolBasePath,
4
5
  runnerProtocolIdentifier,
5
6
  } from '@foss.global/ci-spec';
6
7
 
8
+ export const loadCiSpecArchiveCases = async (): Promise<unknown> =>
9
+ (await import('@foss.global/ci-spec/archive-cases.json', { with: { type: 'json' } })).default;
10
+
7
11
  import { Ajv2020 } from 'ajv/dist/2020.js';
8
12
  export { Ajv2020 };
9
13
 
package/ts/runner.ts CHANGED
@@ -676,6 +676,7 @@ export class ShipRunner {
676
676
  if (lease.job.caches.length > 0) {
677
677
  await this.dependencies.cacheManager!.restore({
678
678
  workspacePath: stagingWorkspace.path,
679
+ workspaceEntryCount: stagingWorkspace.materializedEntryCount,
679
680
  job: lease.job,
680
681
  identity,
681
682
  signal: executionSignal,
@@ -9,7 +9,6 @@ import type {
9
9
  ITransferManagerConfig,
10
10
  } from './interfaces.ts';
11
11
  import {
12
- ensureStagingCapacity,
13
12
  extractTarGzipArchive,
14
13
  removePathIfPresent,
15
14
  stageTransferDownload,
@@ -26,24 +25,30 @@ export interface ISourceApiClient {
26
25
  const effectiveSourceLimits = (
27
26
  config: ITransferManagerConfig,
28
27
  context: ISourcePrepareContext,
29
- ): { archiveBytes: number; extractedBytes: number; entries: number } => ({
30
- archiveBytes: Math.min(
31
- config.maximumSourceArchiveBytes,
32
- context.job.requirements.limits.maximumSourceArchiveBytes,
33
- ),
34
- extractedBytes: Math.min(
35
- config.maximumSourceExtractedBytes,
36
- config.oci.workspaceSizeBytes,
37
- context.job.requirements.limits.maximumSourceExtractedBytes,
38
- context.job.requirements.limits.maximumWorkspaceBytes,
39
- ),
40
- entries: Math.min(
41
- config.maximumSourceEntries,
28
+ ): { archiveBytes: number; extractedBytes: number; entries: number; workspaceEntries: number } => {
29
+ const workspaceEntries = Math.min(
42
30
  config.maximumWorkspaceEntries,
43
- context.job.requirements.limits.maximumSourceEntries,
44
31
  context.job.requirements.limits.maximumWorkspaceEntries,
45
- ),
46
- });
32
+ );
33
+ return {
34
+ archiveBytes: Math.min(
35
+ config.maximumSourceArchiveBytes,
36
+ context.job.requirements.limits.maximumSourceArchiveBytes,
37
+ ),
38
+ extractedBytes: Math.min(
39
+ config.maximumSourceExtractedBytes,
40
+ config.oci.workspaceSizeBytes,
41
+ context.job.requirements.limits.maximumSourceExtractedBytes,
42
+ context.job.requirements.limits.maximumWorkspaceBytes,
43
+ ),
44
+ entries: Math.min(
45
+ config.maximumSourceEntries,
46
+ context.job.requirements.limits.maximumSourceEntries,
47
+ workspaceEntries,
48
+ ),
49
+ workspaceEntries,
50
+ };
51
+ };
47
52
 
48
53
  const cleanupFailure = async (
49
54
  error: unknown,
@@ -110,13 +115,6 @@ export class SourceWorkspaceManager {
110
115
  });
111
116
  let workspacePath: string | undefined;
112
117
  try {
113
- await ensureStagingCapacity(
114
- workspaceRoot,
115
- source.extractedSizeBytes,
116
- source.entryCount + 1,
117
- this.config.transferStagingReserveBytes,
118
- this.config.transferStagingReserveInodes,
119
- );
120
118
  workspacePath = await Deno.makeTempDir({
121
119
  dir: workspaceRoot,
122
120
  prefix: 'attempt-',
@@ -128,6 +126,9 @@ export class SourceWorkspaceManager {
128
126
  expectedMetadata: staged.metadata,
129
127
  maximumExtractedBytes: limits.extractedBytes,
130
128
  maximumEntries: limits.entries,
129
+ maximumMaterializedEntries: limits.workspaceEntries,
130
+ reserveBytes: this.config.transferStagingReserveBytes,
131
+ reserveInodes: this.config.transferStagingReserveInodes,
131
132
  allowSymlinks: true,
132
133
  signal: context.signal,
133
134
  });
@@ -137,7 +138,11 @@ export class SourceWorkspaceManager {
137
138
  const ownedWorkspacePath = workspacePath;
138
139
  return {
139
140
  path: ownedWorkspacePath,
140
- metadata,
141
+ metadata: {
142
+ logicalBytes: metadata.logicalBytes,
143
+ entryCount: metadata.entryCount,
144
+ },
145
+ materializedEntryCount: metadata.materializedEntryCount,
141
146
  cleanup: () => {
142
147
  if (cleaned) return Promise.resolve();
143
148
  cleanupPromise ??= removePathIfPresent(ownedWorkspacePath, true).then(