@ship.zone/runner 2.0.0 → 3.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.
Files changed (180) hide show
  1. package/.smartconfig.json +101 -3
  2. package/changelog.md +69 -0
  3. package/dist_rust/runnerworkspace_linux_amd64_musl +0 -0
  4. package/dist_rust/runnerworkspace_linux_amd64_musl.third-party-notices.json +679 -0
  5. package/dist_rust/runnerworkspace_linux_amd64_musl.third-party-notices.txt +15719 -0
  6. package/dist_rust/runnerworkspace_linux_amd64_musl.tsrust-build.json +5 -5
  7. package/dist_rust/runnerworkspace_linux_arm64_musl +0 -0
  8. package/dist_rust/runnerworkspace_linux_arm64_musl.third-party-notices.json +679 -0
  9. package/dist_rust/runnerworkspace_linux_arm64_musl.third-party-notices.txt +15719 -0
  10. package/dist_rust/runnerworkspace_linux_arm64_musl.tsrust-build.json +5 -5
  11. package/dist_ts/00_commitinfo_data.d.ts +8 -0
  12. package/dist_ts/00_commitinfo_data.js +9 -0
  13. package/dist_ts/api-client.d.ts +46 -0
  14. package/dist_ts/api-client.js +592 -0
  15. package/dist_ts/artifact-manager.d.ts +11 -0
  16. package/dist_ts/artifact-manager.js +140 -0
  17. package/dist_ts/attempt-state.d.ts +18 -0
  18. package/dist_ts/attempt-state.js +151 -0
  19. package/dist_ts/cache-manager.d.ts +13 -0
  20. package/dist_ts/cache-manager.js +300 -0
  21. package/dist_ts/cli-entry.d.ts +2 -0
  22. package/dist_ts/cli-entry.js +4 -0
  23. package/dist_ts/cli.d.ts +14 -0
  24. package/dist_ts/cli.js +215 -0
  25. package/dist_ts/config.d.ts +8 -0
  26. package/dist_ts/config.js +445 -0
  27. package/dist_ts/errors.d.ts +41 -0
  28. package/dist_ts/errors.js +90 -0
  29. package/dist_ts/filesystem.d.ts +73 -0
  30. package/dist_ts/filesystem.js +207 -0
  31. package/dist_ts/index.d.ts +16 -0
  32. package/dist_ts/index.js +17 -0
  33. package/dist_ts/interfaces.d.ts +614 -0
  34. package/dist_ts/interfaces.js +3 -0
  35. package/dist_ts/log-sender.d.ts +26 -0
  36. package/dist_ts/log-sender.js +124 -0
  37. package/dist_ts/oci-executor.d.ts +155 -0
  38. package/dist_ts/oci-executor.js +2238 -0
  39. package/dist_ts/plugins.d.ts +19 -0
  40. package/dist_ts/plugins.js +23 -0
  41. package/dist_ts/protocol-validator.d.ts +39 -0
  42. package/dist_ts/protocol-validator.js +483 -0
  43. package/dist_ts/redactor.d.ts +78 -0
  44. package/dist_ts/redactor.js +235 -0
  45. package/dist_ts/registration-state.d.ts +16 -0
  46. package/dist_ts/registration-state.js +171 -0
  47. package/dist_ts/runner.d.ts +64 -0
  48. package/dist_ts/runner.js +882 -0
  49. package/dist_ts/source-workspace.d.ts +10 -0
  50. package/dist_ts/source-workspace.js +125 -0
  51. package/dist_ts/spec-version.d.ts +11 -0
  52. package/dist_ts/spec-version.js +41 -0
  53. package/dist_ts/staging-scavenger.d.ts +7 -0
  54. package/dist_ts/staging-scavenger.js +63 -0
  55. package/dist_ts/state-owner.d.ts +74 -0
  56. package/dist_ts/state-owner.js +289 -0
  57. package/dist_ts/transfer-archive.d.ts +78 -0
  58. package/dist_ts/transfer-archive.js +1619 -0
  59. package/dist_ts/validation.d.ts +11 -0
  60. package/dist_ts/validation.js +79 -0
  61. package/dist_ts/wire-schema.d.ts +10 -0
  62. package/dist_ts/wire-schema.js +114 -0
  63. package/native-notices/crates/bitflags-2.13.1/license-apache +201 -0
  64. package/native-notices/crates/bitflags-2.13.1/license-mit +25 -0
  65. package/native-notices/crates/cc-1.8.0/license-apache +201 -0
  66. package/native-notices/crates/cc-1.8.0/license-mit +25 -0
  67. package/native-notices/crates/cfg-if-1.0.4/license-apache +201 -0
  68. package/native-notices/crates/cfg-if-1.0.4/license-mit +25 -0
  69. package/native-notices/crates/cfg_aliases-0.2.2/license +9 -0
  70. package/native-notices/crates/cfg_aliases-0.2.2/notices.md +26 -0
  71. package/native-notices/crates/find-msvc-tools-0.1.14/license-apache +201 -0
  72. package/native-notices/crates/find-msvc-tools-0.1.14/license-mit +25 -0
  73. package/native-notices/crates/itoa-1.0.18/license-apache +176 -0
  74. package/native-notices/crates/itoa-1.0.18/license-mit +23 -0
  75. package/native-notices/crates/libc-0.2.189/license-apache +176 -0
  76. package/native-notices/crates/libc-0.2.189/license-mit +25 -0
  77. package/native-notices/crates/memchr-2.8.3/copying +3 -0
  78. package/native-notices/crates/memchr-2.8.3/license-mit +21 -0
  79. package/native-notices/crates/memchr-2.8.3/unlicense +24 -0
  80. package/native-notices/crates/nix-0.30.1/license +21 -0
  81. package/native-notices/crates/proc-macro2-1.0.107/license-apache +176 -0
  82. package/native-notices/crates/proc-macro2-1.0.107/license-mit +23 -0
  83. package/native-notices/crates/quote-1.0.47/license-apache +176 -0
  84. package/native-notices/crates/quote-1.0.47/license-mit +23 -0
  85. package/native-notices/crates/serde-1.0.229/license-apache +176 -0
  86. package/native-notices/crates/serde-1.0.229/license-mit +23 -0
  87. package/native-notices/crates/serde_core-1.0.229/license-apache +176 -0
  88. package/native-notices/crates/serde_core-1.0.229/license-mit +23 -0
  89. package/native-notices/crates/serde_derive-1.0.229/license-apache +176 -0
  90. package/native-notices/crates/serde_derive-1.0.229/license-mit +23 -0
  91. package/native-notices/crates/serde_json-1.0.151/license-apache +176 -0
  92. package/native-notices/crates/serde_json-1.0.151/license-mit +23 -0
  93. package/native-notices/crates/shlex-2.0.1/license-apache +13 -0
  94. package/native-notices/crates/shlex-2.0.1/license-mit +21 -0
  95. package/native-notices/crates/syn-3.0.3/license-apache +176 -0
  96. package/native-notices/crates/syn-3.0.3/license-mit +23 -0
  97. package/native-notices/crates/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/license-apache +201 -0
  98. package/native-notices/crates/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/license-mit +25 -0
  99. package/native-notices/crates/tikv-jemallocator-0.7.0/license-apache +201 -0
  100. package/native-notices/crates/tikv-jemallocator-0.7.0/license-mit +25 -0
  101. package/native-notices/crates/unicode-ident-1.0.24/license-apache +176 -0
  102. package/native-notices/crates/unicode-ident-1.0.24/license-mit +23 -0
  103. package/native-notices/crates/unicode-ident-1.0.24/license-unicode +39 -0
  104. package/native-notices/crates/zmij-1.0.23/license-mit +23 -0
  105. package/native-notices/manifest.json +763 -0
  106. package/native-notices/native/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/jemalloc-5.3.1/jemalloc-copying +27 -0
  107. package/native-notices/readme.md +46 -0
  108. package/native-notices/runtime/gcc/gpl-3.0.txt +674 -0
  109. package/native-notices/runtime/gcc/runtime-library-exception-3.1.txt +73 -0
  110. package/native-notices/runtime/libunwind-22.1.2/license.txt +311 -0
  111. package/native-notices/runtime/musl-1.2.5/copyright +193 -0
  112. package/native-notices/rust/compiler-builtins-license.txt +275 -0
  113. package/native-notices/rust/copyright-library.html +8266 -0
  114. package/native-notices/rust/crates/addr2line-0.25.1/license-apache +201 -0
  115. package/native-notices/rust/crates/addr2line-0.25.1/license-mit +25 -0
  116. package/native-notices/rust/crates/adler2-2.0.1/license-0bsd +12 -0
  117. package/native-notices/rust/crates/adler2-2.0.1/license-apache +201 -0
  118. package/native-notices/rust/crates/adler2-2.0.1/license-mit +23 -0
  119. package/native-notices/rust/crates/memchr-2.7.6/copying +3 -0
  120. package/native-notices/rust/crates/memchr-2.7.6/license-mit +21 -0
  121. package/native-notices/rust/crates/memchr-2.7.6/unlicense +24 -0
  122. package/native-notices/rust/crates/miniz_oxide-0.8.9/license +25 -0
  123. package/native-notices/rust/crates/miniz_oxide-0.8.9/license-apache.md +177 -0
  124. package/native-notices/rust/crates/miniz_oxide-0.8.9/license-mit.md +24 -0
  125. package/native-notices/rust/crates/miniz_oxide-0.8.9/license-zlib.md +14 -0
  126. package/native-notices/rust/crates/object-0.37.3/license-apache +201 -0
  127. package/native-notices/rust/crates/object-0.37.3/license-mit +25 -0
  128. package/native-notices/rust/licenses/apache-2.0.txt +73 -0
  129. package/native-notices/rust/licenses/bsd-2-clause.txt +9 -0
  130. package/native-notices/rust/licenses/cc-by-sa-4.0.txt +427 -0
  131. package/native-notices/rust/licenses/gcc-exception-3.1.txt +30 -0
  132. package/native-notices/rust/licenses/gpl-2.0-only.txt +133 -0
  133. package/native-notices/rust/licenses/gpl-3.0-or-later.txt +202 -0
  134. package/native-notices/rust/licenses/isc.txt +7 -0
  135. package/native-notices/rust/licenses/llvm-exception.txt +15 -0
  136. package/native-notices/rust/licenses/mit.txt +9 -0
  137. package/native-notices/rust/licenses/ncsa.txt +29 -0
  138. package/native-notices/rust/licenses/ofl-1.1.txt +43 -0
  139. package/native-notices/rust/licenses/unicode-3.0.txt +39 -0
  140. package/package.json +24 -21
  141. package/readme.md +91 -40
  142. package/rust/.cargo/config.toml +1 -1
  143. package/rust/Cargo.lock +43 -0
  144. package/rust/Cargo.toml +4 -1
  145. package/rust/src/lib.rs +156 -1
  146. package/rust/src/main.rs +5 -1
  147. package/rust-toolchain.toml +4 -0
  148. package/ts/00_commitinfo_data.ts +1 -1
  149. package/ts/api-client.ts +10 -7
  150. package/ts/artifact-manager.ts +9 -7
  151. package/ts/attempt-state.ts +75 -84
  152. package/ts/cache-manager.ts +22 -28
  153. package/ts/cli-entry.ts +4 -0
  154. package/ts/cli.ts +56 -45
  155. package/ts/config.ts +50 -39
  156. package/ts/errors.ts +19 -0
  157. package/ts/filesystem.ts +316 -0
  158. package/ts/index.ts +16 -15
  159. package/ts/interfaces.ts +2 -2
  160. package/ts/log-sender.ts +4 -4
  161. package/ts/oci-executor.ts +235 -383
  162. package/ts/plugins.ts +21 -3
  163. package/ts/protocol-validator.ts +5 -5
  164. package/ts/redactor.ts +2 -2
  165. package/ts/registration-state.ts +82 -90
  166. package/ts/runner.ts +30 -17
  167. package/ts/source-workspace.ts +11 -8
  168. package/ts/spec-version.ts +2 -2
  169. package/ts/staging-scavenger.ts +37 -26
  170. package/ts/state-owner.ts +346 -0
  171. package/ts/transfer-archive.ts +214 -243
  172. package/ts/validation.ts +1 -1
  173. package/ts/wire-schema.ts +3 -3
  174. package/deno.json +0 -56
  175. package/deno.lock +0 -1762
  176. package/dist_npm/mod.d.ts +0 -967
  177. package/dist_npm/mod.js +0 -10058
  178. package/mod.ts +0 -8
  179. package/musl-copyright.md +0 -81
  180. package/third-party-licenses.md +0 -95
@@ -1,5 +1,18 @@
1
- import { join } from '@std/path';
2
- import { RunnerError } from './errors.ts';
1
+ import * as plugins from './plugins.js';
2
+ import { RunnerError } from './errors.js';
3
+ import {
4
+ createNewWriteFlags,
5
+ isNotFound,
6
+ readInto,
7
+ removePath,
8
+ sameFileIdentity,
9
+ syncDirectory,
10
+ withOpenFile,
11
+ writeAll,
12
+ } from './filesystem.js';
13
+ import { ensurePrivateStateDirectory, type RunnerStateOwner } from './state-owner.js';
14
+
15
+ const { join } = plugins.path;
3
16
 
4
17
  export interface IAttemptJournal {
5
18
  previousSessionId: string;
@@ -38,29 +51,20 @@ const validateJournal = (value: unknown): IAttemptJournal => {
38
51
  };
39
52
  };
40
53
 
41
- const writeAll = async (file: Deno.FsFile, bytes: Uint8Array): Promise<void> => {
42
- let offset = 0;
43
- while (offset < bytes.byteLength) {
44
- const written = await file.write(bytes.subarray(offset));
45
- if (written <= 0) throw new RunnerError('Attempt journal write made no progress');
46
- offset += written;
47
- }
48
- };
49
-
50
- const isNotFound = (error: unknown): boolean => error instanceof Deno.errors.NotFound;
51
-
52
54
  export class AttemptStateStore {
53
55
  readonly path: string;
56
+ private readonly stateDirectory: string;
54
57
 
55
- constructor(private readonly stateDirectory: string) {
56
- this.path = join(stateDirectory, journalName);
58
+ constructor(private readonly owner: RunnerStateOwner) {
59
+ this.stateDirectory = owner.stateDirectory;
60
+ this.path = join(this.stateDirectory, journalName);
57
61
  }
58
62
 
59
63
  async load(): Promise<IAttemptJournal | undefined> {
60
64
  await this.ensureDirectory();
61
- let pathStat: Deno.FileInfo;
65
+ let pathStat: plugins.Stats;
62
66
  try {
63
- pathStat = await Deno.lstat(this.path);
67
+ pathStat = await plugins.fs.lstat(this.path);
64
68
  } catch (error) {
65
69
  if (isNotFound(error)) return undefined;
66
70
  throw error;
@@ -69,73 +73,71 @@ export class AttemptStateStore {
69
73
  if (pathStat.size > maximumJournalBytes) {
70
74
  throw new RunnerError('Attempt journal exceeds its size limit');
71
75
  }
72
- const file = await Deno.open(this.path, { read: true });
73
- try {
74
- const openStat = await file.stat();
75
- if (
76
- !openStat.isFile ||
77
- (pathStat.dev !== null && openStat.dev !== pathStat.dev) ||
78
- (pathStat.ino !== null && openStat.ino !== pathStat.ino)
79
- ) {
80
- throw new RunnerError('Attempt journal changed while it was opened');
81
- }
82
- const bytes = new Uint8Array(pathStat.size + 1);
83
- let offset = 0;
84
- while (offset < bytes.byteLength) {
85
- const read = await file.read(bytes.subarray(offset));
86
- if (read === null) break;
87
- offset += read;
88
- }
89
- if (offset !== pathStat.size) {
90
- throw new RunnerError('Attempt journal changed while it was read');
91
- }
92
- let parsed: unknown;
93
- try {
94
- parsed = JSON.parse(new TextDecoder().decode(bytes.subarray(0, offset)));
95
- } catch (error) {
96
- throw new RunnerError('Attempt journal is not valid JSON', { cause: error });
97
- }
98
- return validateJournal(parsed);
99
- } finally {
100
- file.close();
101
- }
76
+ return await withOpenFile(
77
+ this.path,
78
+ 'r',
79
+ undefined,
80
+ async (file) => {
81
+ const openStat = await file.stat();
82
+ if (!openStat.isFile() || !sameFileIdentity(pathStat, openStat)) {
83
+ throw new RunnerError('Attempt journal changed while it was opened');
84
+ }
85
+ const bytes = new Uint8Array(pathStat.size + 1);
86
+ let offset = 0;
87
+ while (offset < bytes.byteLength) {
88
+ const read = await readInto(file, bytes.subarray(offset));
89
+ if (read === null) break;
90
+ offset += read;
91
+ }
92
+ if (offset !== pathStat.size) {
93
+ throw new RunnerError('Attempt journal changed while it was read');
94
+ }
95
+ let parsed: unknown;
96
+ try {
97
+ parsed = JSON.parse(new TextDecoder().decode(bytes.subarray(0, offset)));
98
+ } catch (error) {
99
+ throw new RunnerError('Attempt journal is not valid JSON', { cause: error });
100
+ }
101
+ return validateJournal(parsed);
102
+ },
103
+ 'Attempt journal read and close failed',
104
+ );
102
105
  }
103
106
 
104
107
  async save(journal: IAttemptJournal): Promise<void> {
105
108
  const validated = validateJournal(journal);
106
109
  await this.ensureDirectory();
107
110
  try {
108
- this.assertSafeJournalFile(await Deno.lstat(this.path));
111
+ this.assertSafeJournalFile(await plugins.fs.lstat(this.path));
109
112
  } catch (error) {
110
113
  if (!isNotFound(error)) throw error;
111
114
  }
112
115
  const temporaryPath = join(
113
116
  this.stateDirectory,
114
- `.${crypto.randomUUID()}.attempt-journal.tmp`,
117
+ `.${plugins.crypto.randomUUID()}.attempt-journal.tmp`,
115
118
  );
116
119
  const bytes = new TextEncoder().encode(`${JSON.stringify(validated)}\n`);
117
120
  if (bytes.byteLength > maximumJournalBytes) {
118
121
  throw new RunnerError('Attempt journal exceeds its size limit');
119
122
  }
120
- let file: Deno.FsFile | undefined;
121
123
  try {
122
- file = await Deno.open(temporaryPath, {
123
- write: true,
124
- createNew: true,
125
- mode: 0o600,
126
- });
127
- await writeAll(file, bytes);
128
- await file.sync();
129
- file.close();
130
- file = undefined;
131
- await Deno.chmod(temporaryPath, 0o600);
132
- await Deno.rename(temporaryPath, this.path);
133
- await Deno.chmod(this.path, 0o600);
124
+ await withOpenFile(
125
+ temporaryPath,
126
+ createNewWriteFlags,
127
+ 0o600,
128
+ async (file) => {
129
+ await writeAll(file, bytes, 'Attempt journal write made no progress');
130
+ await file.sync();
131
+ },
132
+ 'Attempt journal write and close failed',
133
+ );
134
+ await plugins.fs.chmod(temporaryPath, 0o600);
135
+ await plugins.fs.rename(temporaryPath, this.path);
136
+ await plugins.fs.chmod(this.path, 0o600);
134
137
  await this.syncDirectory();
135
138
  } catch (error) {
136
- file?.close();
137
139
  try {
138
- await Deno.remove(temporaryPath);
140
+ await removePath(temporaryPath);
139
141
  } catch (cleanupError) {
140
142
  if (!isNotFound(cleanupError)) {
141
143
  throw new AggregateError([error, cleanupError], 'Attempt journal write cleanup failed');
@@ -147,44 +149,33 @@ export class AttemptStateStore {
147
149
 
148
150
  async clear(): Promise<void> {
149
151
  await this.ensureDirectory();
150
- let stat: Deno.FileInfo;
152
+ let stat: plugins.Stats;
151
153
  try {
152
- stat = await Deno.lstat(this.path);
154
+ stat = await plugins.fs.lstat(this.path);
153
155
  } catch (error) {
154
156
  if (isNotFound(error)) return;
155
157
  throw error;
156
158
  }
157
159
  this.assertSafeJournalFile(stat);
158
- await Deno.remove(this.path);
160
+ await removePath(this.path);
159
161
  await this.syncDirectory();
160
162
  }
161
163
 
162
164
  private async ensureDirectory(): Promise<void> {
163
- await Deno.mkdir(this.stateDirectory, { recursive: true, mode: 0o700 });
164
- const stat = await Deno.lstat(this.stateDirectory);
165
- if (!stat.isDirectory || stat.isSymlink) {
166
- throw new RunnerError('Runner state directory must be a real directory');
167
- }
168
- if (Deno.build.os !== 'windows' && stat.mode !== null && (stat.mode & 0o077) !== 0) {
169
- throw new RunnerError('Runner state directory permissions are not private');
170
- }
165
+ this.owner.assertHeld();
166
+ await ensurePrivateStateDirectory(this.stateDirectory);
171
167
  }
172
168
 
173
- private assertSafeJournalFile(stat: Deno.FileInfo): void {
174
- if (!stat.isFile || stat.isSymlink) {
169
+ private assertSafeJournalFile(stat: plugins.Stats): void {
170
+ if (!stat.isFile() || stat.isSymbolicLink()) {
175
171
  throw new RunnerError('Attempt journal must be a regular file');
176
172
  }
177
- if (Deno.build.os !== 'windows' && stat.mode !== null && (stat.mode & 0o777) !== 0o600) {
173
+ if ((stat.mode & 0o777) !== 0o600) {
178
174
  throw new RunnerError('Attempt journal permissions must be 0600');
179
175
  }
180
176
  }
181
177
 
182
178
  private async syncDirectory(): Promise<void> {
183
- const directory = await Deno.open(this.stateDirectory, { read: true });
184
- try {
185
- await directory.sync();
186
- } finally {
187
- directory.close();
188
- }
179
+ await syncDirectory(this.stateDirectory, 'Runner state directory sync and close failed');
189
180
  }
190
181
  }
@@ -1,5 +1,6 @@
1
- import { dirname, join, resolve } from '@std/path';
2
- import { ProtocolError, ResourceCleanupError, RunnerError } from './errors.ts';
1
+ import * as plugins from './plugins.js';
2
+ import { lstatIfPresent, makeTempDir, removePath } from './filesystem.js';
3
+ import { ProtocolError, ResourceCleanupError, RunnerError } from './errors.js';
3
4
  import type {
4
5
  ICacheDeclaration,
5
6
  ICacheManager,
@@ -11,7 +12,7 @@ import type {
11
12
  ITransferRecord,
12
13
  TCacheDownload,
13
14
  TOpenTransferBody,
14
- } from './interfaces.ts';
15
+ } from './interfaces.js';
15
16
  import {
16
17
  createTarGzipArchive,
17
18
  ensureStagingCapacity,
@@ -20,7 +21,9 @@ import {
20
21
  stageTransferDownload,
21
22
  validateRelativeSelections,
22
23
  validateTransferRecord,
23
- } from './transfer-archive.ts';
24
+ } from './transfer-archive.js';
25
+
26
+ const { dirname, join, resolve } = plugins.path;
24
27
 
25
28
  export interface ICacheApiClient {
26
29
  downloadCache(
@@ -143,15 +146,6 @@ const validateCaches = (
143
146
  return limits;
144
147
  };
145
148
 
146
- const lstatIfPresent = async (path: string): Promise<Deno.FileInfo | undefined> => {
147
- try {
148
- return await Deno.lstat(path);
149
- } catch (error) {
150
- if (error instanceof Deno.errors.NotFound) return undefined;
151
- throw error;
152
- }
153
- };
154
-
155
149
  const assertSafeDestinationParents = async (workspacePath: string, path: string): Promise<void> => {
156
150
  let current = resolve(workspacePath);
157
151
  const segments = path.split('/');
@@ -159,7 +153,7 @@ const assertSafeDestinationParents = async (workspacePath: string, path: string)
159
153
  current = join(current, segments[index]);
160
154
  const stat = await lstatIfPresent(current);
161
155
  if (!stat) return;
162
- if (!stat.isDirectory || stat.isSymlink) {
156
+ if (!stat.isDirectory() || stat.isSymbolicLink()) {
163
157
  throw new RunnerError('Cache destination has an unsafe ancestor');
164
158
  }
165
159
  }
@@ -182,14 +176,14 @@ const restoreSelectedPaths = async (
182
176
  await assertSafeDestinationParents(workspacePath, path);
183
177
  const destination = join(resolve(workspacePath), ...path.split('/'));
184
178
  const destinationStat = await lstatIfPresent(destination);
185
- if (destinationStat?.isSymlink) {
179
+ if (destinationStat?.isSymbolicLink()) {
186
180
  throw new RunnerError('Cache destination is a symbolic link');
187
181
  }
188
182
  candidates.push({ source, destination, existed: destinationStat !== undefined });
189
183
  }
190
184
 
191
185
  const workspaceRoot = resolve(workspacePath);
192
- const backupRoot = await Deno.makeTempDir({
186
+ const backupRoot = await makeTempDir({
193
187
  dir: dirname(workspaceRoot),
194
188
  prefix: '.cache-restore-',
195
189
  });
@@ -200,15 +194,15 @@ const restoreSelectedPaths = async (
200
194
  const candidate = candidates[index];
201
195
  if (!candidate.existed) continue;
202
196
  const backup = join(backupRoot, String(index));
203
- await Deno.rename(candidate.destination, backup);
197
+ await plugins.fs.rename(candidate.destination, backup);
204
198
  backedUp.push({ backup, destination: candidate.destination });
205
199
  }
206
200
  for (const candidate of candidates) {
207
- await Deno.mkdir(dirname(candidate.destination), { recursive: true, mode: 0o700 });
208
- await Deno.rename(candidate.source, candidate.destination);
201
+ await plugins.fs.mkdir(dirname(candidate.destination), { recursive: true, mode: 0o700 });
202
+ await plugins.fs.rename(candidate.source, candidate.destination);
209
203
  installed.push(candidate.destination);
210
204
  }
211
- await Deno.remove(backupRoot, { recursive: true });
205
+ await removePath(backupRoot, { recursive: true });
212
206
  } catch (error) {
213
207
  const errors = [error];
214
208
  for (const destination of installed.reverse()) {
@@ -220,8 +214,8 @@ const restoreSelectedPaths = async (
220
214
  }
221
215
  for (const entry of backedUp.reverse()) {
222
216
  try {
223
- await Deno.mkdir(dirname(entry.destination), { recursive: true, mode: 0o700 });
224
- await Deno.rename(entry.backup, entry.destination);
217
+ await plugins.fs.mkdir(dirname(entry.destination), { recursive: true, mode: 0o700 });
218
+ await plugins.fs.rename(entry.backup, entry.destination);
225
219
  } catch (rollbackError) {
226
220
  errors.push(rollbackError);
227
221
  }
@@ -316,12 +310,12 @@ export class CacheManager implements ICacheManager {
316
310
  let restorePath: string | undefined;
317
311
  let primaryError: unknown;
318
312
  try {
319
- await Deno.mkdir(restoreRoot, { recursive: true, mode: 0o700 });
320
- restorePath = await Deno.makeTempDir({
313
+ await plugins.fs.mkdir(restoreRoot, { recursive: true, mode: 0o700 });
314
+ restorePath = await makeTempDir({
321
315
  dir: restoreRoot,
322
316
  prefix: 'cache-',
323
317
  });
324
- await Deno.chmod(restorePath, 0o700);
318
+ await plugins.fs.chmod(restorePath, 0o700);
325
319
  const extracted = await extractTarGzipArchive({
326
320
  archivePath: staged.path,
327
321
  destinationPath: restorePath,
@@ -368,7 +362,7 @@ export class CacheManager implements ICacheManager {
368
362
  for (const cache of context.job.caches) {
369
363
  if (cache.access !== 'read-write') continue;
370
364
  if (context.signal.aborted) throw context.signal.reason;
371
- await Deno.mkdir(this.config.stateDirectory, { recursive: true, mode: 0o700 });
365
+ await plugins.fs.mkdir(this.config.stateDirectory, { recursive: true, mode: 0o700 });
372
366
  await ensureStagingCapacity(
373
367
  this.config.stateDirectory,
374
368
  cache.maximumExtractedBytes,
@@ -387,7 +381,7 @@ export class CacheManager implements ICacheManager {
387
381
  signal: context.signal,
388
382
  });
389
383
  const archiveRoot = join(this.config.stateDirectory, 'cache-uploads');
390
- await Deno.mkdir(archiveRoot, { recursive: true, mode: 0o700 });
384
+ await plugins.fs.mkdir(archiveRoot, { recursive: true, mode: 0o700 });
391
385
  await ensureStagingCapacity(
392
386
  archiveRoot,
393
387
  cache.maximumBytes,
@@ -408,7 +402,7 @@ export class CacheManager implements ICacheManager {
408
402
  redactionSet: context.redactionSet,
409
403
  signal: context.signal,
410
404
  });
411
- const transferRequestId = crypto.randomUUID();
405
+ const transferRequestId = plugins.crypto.randomUUID();
412
406
  const record = await this.api.uploadCache(
413
407
  context.identity,
414
408
  cache.name,
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { runCli } from './cli.js';
3
+
4
+ await runCli(process.argv.slice(2));
package/ts/cli.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { RunnerApiClient } from './api-client.ts';
2
- import { ArtifactManager } from './artifact-manager.ts';
3
- import { CacheManager } from './cache-manager.ts';
1
+ import { RunnerApiClient } from './api-client.js';
2
+ import { ArtifactManager } from './artifact-manager.js';
3
+ import { CacheManager } from './cache-manager.js';
4
4
  import {
5
5
  defaultRunnerConfig,
6
6
  loadRunnerConfig,
@@ -8,27 +8,28 @@ import {
8
8
  saveRunnerConfig,
9
9
  validateRunnerConfig,
10
10
  withRunnerCredential,
11
- } from './config.ts';
12
- import { ConfigurationError } from './errors.ts';
11
+ } from './config.js';
12
+ import { ConfigurationError } from './errors.js';
13
13
  import type {
14
14
  IRegisterRunnerRequest,
15
15
  IRegisterRunnerResponse,
16
16
  IRunnerCapabilities,
17
17
  IRunnerConfig,
18
- } from './interfaces.ts';
19
- import { runnerVersion } from './interfaces.ts';
20
- import { OciExecutor } from './oci-executor.ts';
21
- import { RegistrationStateStore } from './registration-state.ts';
22
- import { reconcileProtocolLimits, runnerCapabilities, ShipRunner } from './runner.ts';
23
- import { runnerSpecVersion } from './spec-version.ts';
24
- import { SourceWorkspaceManager } from './source-workspace.ts';
18
+ } from './interfaces.js';
19
+ import { runnerVersion } from './interfaces.js';
20
+ import { OciExecutor } from './oci-executor.js';
21
+ import { RegistrationStateStore } from './registration-state.js';
22
+ import { reconcileProtocolLimits, runnerCapabilities, ShipRunner } from './runner.js';
23
+ import { runnerSpecVersion } from './spec-version.js';
24
+ import { SourceWorkspaceManager } from './source-workspace.js';
25
+ import { RunnerStateOwner } from './state-owner.js';
25
26
 
26
27
  interface IParsedArguments {
27
28
  command: string;
28
29
  options: Map<string, string | true>;
29
30
  }
30
31
 
31
- const cliInvocation = 'deno run --allow-all npm:@ship.zone/runner';
32
+ const cliInvocation = 'ship-zone-runner';
32
33
 
33
34
  const usage = `ship.zone runner ${runnerVersion}
34
35
 
@@ -38,7 +39,7 @@ Usage:
38
39
  ${cliInvocation} run [--config <path>]
39
40
  ${cliInvocation} once [--config <path>]
40
41
  ${cliInvocation} config [--config <path>]
41
- ${cliInvocation} version
42
+ ${cliInvocation} version | --version
42
43
 
43
44
  Bootstrap credentials must be supplied through SHIP_RUNNER_BOOTSTRAP_TOKEN or the
44
45
  0600 config file. Secret values are intentionally not accepted as command arguments.
@@ -73,7 +74,7 @@ const stringOption = (
73
74
  };
74
75
 
75
76
  const configPath = (options: Map<string, string | true>): string =>
76
- stringOption(options, 'config') ?? Deno.env.get('SHIP_RUNNER_CONFIG') ?? './runner.config.json';
77
+ stringOption(options, 'config') ?? process.env.SHIP_RUNNER_CONFIG ?? './runner.config.json';
77
78
 
78
79
  const apiFor = (config: IRunnerConfig): RunnerApiClient =>
79
80
  new RunnerApiClient({
@@ -97,15 +98,14 @@ export const registerRunnerDurably = async (options: {
97
98
  bootstrapToken: string,
98
99
  ): Promise<IRegisterRunnerResponse>;
99
100
  };
100
- stateStore?: RegistrationStateStore;
101
+ stateStore: RegistrationStateStore;
101
102
  createRequestId?: () => string;
102
103
  persistConfig?: (path: string, config: IRunnerConfig) => Promise<void>;
103
104
  }): Promise<IRunnerConfig> => {
104
105
  if (!options.config.bootstrapToken) {
105
106
  throw new ConfigurationError('SHIP_RUNNER_BOOTSTRAP_TOKEN is required for registration');
106
107
  }
107
- const stateStore = options.stateStore ??
108
- new RegistrationStateStore(options.config.stateDirectory);
108
+ const stateStore = options.stateStore;
109
109
  const request = await stateStore.loadOrCreate({
110
110
  spec: runnerSpecVersion,
111
111
  runnerVersion,
@@ -147,44 +147,53 @@ const runRegister = async (options: Map<string, string | true>): Promise<void> =
147
147
  if (!config.bootstrapToken) {
148
148
  throw new ConfigurationError('SHIP_RUNNER_BOOTSTRAP_TOKEN is required for registration');
149
149
  }
150
- const api = apiFor(config);
151
- const executor = new OciExecutor(config);
152
- const runtime = await executor.verifyRuntime();
153
- const discovery = await api.discover();
154
- const capabilities = runnerCapabilities(config, runtime);
155
- reconcileProtocolLimits(config, discovery, capabilities);
156
- const registered = await registerRunnerDurably({
157
- configPath: path,
158
- config,
159
- capabilities,
160
- api,
161
- });
162
- console.log(`Registered runner ${registered.runnerId}`);
150
+ const stateOwner = await acquireStateOwner(config);
151
+ try {
152
+ const api = apiFor(config);
153
+ const executor = new OciExecutor(config, stateOwner);
154
+ const runtime = await executor.verifyRuntime();
155
+ const discovery = await api.discover();
156
+ const capabilities = runnerCapabilities(config, runtime);
157
+ reconcileProtocolLimits(config, discovery, capabilities);
158
+ const registered = await registerRunnerDurably({
159
+ configPath: path,
160
+ config,
161
+ capabilities,
162
+ api,
163
+ stateStore: new RegistrationStateStore(stateOwner),
164
+ });
165
+ console.log(`Registered runner ${registered.runnerId}`);
166
+ } finally {
167
+ await stateOwner.release();
168
+ }
163
169
  };
164
170
 
171
+ /** Takes the exclusive lock of the configured state directory before anything else uses it. */
172
+ const acquireStateOwner = async (config: IRunnerConfig): Promise<RunnerStateOwner> =>
173
+ await RunnerStateOwner.acquire({
174
+ stateDirectory: config.stateDirectory,
175
+ ...(config.oci.workspaceHelperPath
176
+ ? { helperSourcePath: config.oci.workspaceHelperPath }
177
+ : {}),
178
+ });
179
+
165
180
  const runDaemon = async (
166
181
  options: Map<string, string | true>,
167
182
  once: boolean,
168
183
  ): Promise<void> => {
169
184
  const path = configPath(options);
170
185
  let config = await loadRunnerConfig(path);
171
- const api = apiFor(config);
172
- const executor = new OciExecutor(config);
173
- await executor.verifyRuntime();
186
+ const stateOwner = await acquireStateOwner(config);
174
187
  const shutdown = new AbortController();
175
188
  const shutdownListener = (): void => shutdown.abort('runner_shutdown');
176
- const installedSignals: Array<'SIGINT' | 'SIGTERM'> = [];
177
- for (const signal of ['SIGINT', 'SIGTERM'] as const) {
178
- try {
179
- Deno.addSignalListener(signal, shutdownListener);
180
- installedSignals.push(signal);
181
- } catch {
182
- // Signal listeners are unavailable on some supported hosts.
183
- }
184
- }
189
+ const signals = ['SIGINT', 'SIGTERM'] as const;
190
+ for (const signal of signals) process.on(signal, shutdownListener);
185
191
  try {
192
+ const api = apiFor(config);
193
+ const executor = new OciExecutor(config, stateOwner);
186
194
  const reportMessage = (message: string): void => console.error(message);
187
195
  const runner = new ShipRunner(config, {
196
+ stateOwner,
188
197
  api,
189
198
  executor,
190
199
  workspaceManager: new SourceWorkspaceManager(config, api),
@@ -200,7 +209,8 @@ const runDaemon = async (
200
209
  const result = await runner.run({ once, signal: shutdown.signal });
201
210
  if (once) console.log(result.claimed ? `Job ${result.status}` : 'No job available');
202
211
  } finally {
203
- for (const signal of installedSignals) Deno.removeSignalListener(signal, shutdownListener);
212
+ for (const signal of signals) process.off(signal, shutdownListener);
213
+ await stateOwner.release();
204
214
  }
205
215
  };
206
216
 
@@ -226,6 +236,7 @@ export const runCli = async (arguments_: string[]): Promise<void> => {
226
236
  break;
227
237
  }
228
238
  case 'version':
239
+ case '--version':
229
240
  console.log(runnerVersion);
230
241
  break;
231
242
  case 'help':
@@ -238,6 +249,6 @@ export const runCli = async (arguments_: string[]): Promise<void> => {
238
249
  }
239
250
  } catch (error) {
240
251
  console.error(error instanceof Error ? error.message : 'Runner failed');
241
- Deno.exitCode = 1;
252
+ process.exitCode = 1;
242
253
  }
243
254
  };