@ship.zone/runner 0.1.0 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ship.zone/runner",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
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": {
@@ -15,6 +15,9 @@
15
15
  "type": "module",
16
16
  "main": "./dist_npm/mod.js",
17
17
  "types": "./dist_npm/mod.d.ts",
18
+ "bin": {
19
+ "ship-zone-runner": "./dist_npm/mod.js"
20
+ },
18
21
  "exports": {
19
22
  ".": {
20
23
  "types": "./dist_npm/mod.d.ts",
@@ -26,7 +29,7 @@
26
29
  }
27
30
  },
28
31
  "dependencies": {
29
- "@foss.global/ci-spec": "0.1.0",
32
+ "@foss.global/ci-spec": "0.2.0",
30
33
  "ajv": "^8.20.0"
31
34
  },
32
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
@@ -90,7 +90,7 @@ Create a private runner configuration:
90
90
 
91
91
  ```sh
92
92
  deno run --allow-env --allow-net --allow-read --allow-write --allow-run \
93
- npm:@ship.zone/runner@0.1.0 init \
93
+ npm:@ship.zone/runner init \
94
94
  --control-plane https://foss.global \
95
95
  --runtime-path /usr/bin/docker
96
96
  ```
@@ -100,9 +100,9 @@ Register with a one-time bootstrap token, then start the daemon:
100
100
  ```sh
101
101
  SHIP_RUNNER_BOOTSTRAP_TOKEN='<one-time token>' \
102
102
  deno run --allow-env --allow-net --allow-read --allow-write --allow-run \
103
- npm:@ship.zone/runner@0.1.0 register
103
+ npm:@ship.zone/runner register
104
104
  deno run --allow-env --allow-net --allow-read --allow-write --allow-run \
105
- npm:@ship.zone/runner@0.1.0 run
105
+ npm:@ship.zone/runner run
106
106
  ```
107
107
 
108
108
  Replace `run` with `once` to claim at most one job or `config` to print the effective configuration
@@ -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.0',
6
+ version: '0.2.0',
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;
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(