start-command 0.38.0 → 0.39.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.
Files changed (62) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +4 -2
  3. package/bunfig.toml +4 -0
  4. package/eslint.config.mjs +1 -0
  5. package/package.json +4 -4
  6. package/src/lib/args-parser.js +9 -0
  7. package/src/lib/cgroup-memory.js +120 -24
  8. package/src/lib/command-builder.js +4 -0
  9. package/src/lib/container-removal.js +4 -5
  10. package/src/lib/detached-finalize.js +1 -0
  11. package/src/lib/docker-init-option.js +65 -0
  12. package/src/lib/docker-inspect-batch.js +176 -0
  13. package/src/lib/docker-resource-options.js +21 -2
  14. package/src/lib/docker-runtime-args.js +12 -3
  15. package/src/lib/execution-control.js +8 -6
  16. package/src/lib/execution-recovery.js +4 -1
  17. package/src/lib/execution-resume.js +4 -1
  18. package/src/lib/execution-store.js +19 -1
  19. package/src/lib/exit-evidence.js +139 -7
  20. package/src/lib/output-blocks.js +11 -0
  21. package/src/lib/resume-resources.js +2 -2
  22. package/src/lib/screen-isolation.js +72 -42
  23. package/src/lib/status-formatter.js +34 -130
  24. package/src/lib/status-probe.js +149 -0
  25. package/src/lib/store-decode-cache.js +141 -0
  26. package/src/lib/usage.js +3 -0
  27. package/test/cargo-lock-version.mjs +121 -0
  28. package/test/check-rust-coverage.mjs +71 -0
  29. package/test/check-web-archive.mjs +154 -0
  30. package/test/ci-workflow-invariants.js +204 -0
  31. package/test/command-builder-docker-cleanup.js +24 -0
  32. package/test/command-exit-codes.mjs +91 -0
  33. package/test/docker-runtime-options.js +2 -0
  34. package/test/docker-snapshot-safety.js +39 -0
  35. package/test/execution-resume.js +2 -0
  36. package/test/fixtures/fake-npm.sh +64 -0
  37. package/test/fixtures/lychee-report.md +39 -0
  38. package/test/isolation.js +32 -0
  39. package/test/javascript-first-ci.js +69 -0
  40. package/test/links-workflow.mjs +127 -0
  41. package/test/lint-gate.mjs +56 -0
  42. package/test/npm-publish.mjs +181 -0
  43. package/test/recheck-broken-links.mjs +452 -0
  44. package/test/regression-176.js +2 -0
  45. package/test/regression-187.js +2 -0
  46. package/test/regression-191.js +4 -0
  47. package/test/regression-193.js +2 -0
  48. package/test/regression-198.js +2 -0
  49. package/test/regression-207.js +8 -2
  50. package/test/regression-224.js +2 -0
  51. package/test/regression-236.js +250 -0
  52. package/test/regression-238.js +129 -0
  53. package/test/regression-241.js +254 -0
  54. package/test/regression-242.js +241 -0
  55. package/test/regression-243.js +493 -0
  56. package/test/regression-244.js +471 -0
  57. package/test/regression-247.js +140 -0
  58. package/test/release-push-retry.mjs +172 -0
  59. package/test/run-js-tests.mjs +15 -3
  60. package/test/setup/private-snapshot-lock.js +17 -0
  61. package/test/shared-golden.js +29 -2
  62. package/test/transient-links.mjs +139 -0
@@ -14,7 +14,7 @@ const {
14
14
  formatTextOptionValue,
15
15
  } = require('./status-links-notation');
16
16
  const { collectProcessIds } = require('./execution-control');
17
- const { getDockerCommand, getDockerSpawnOptions } = require('./docker-cleanup');
17
+ const { getDockerCommand } = require('./docker-cleanup');
18
18
  const {
19
19
  describeExitCode,
20
20
  CGROUP_OOM_EXIT_REASON,
@@ -25,136 +25,31 @@ const {
25
25
  FATAL_MARKER_TAIL_BYTES,
26
26
  readLogTail,
27
27
  } = require('./isolation-log-utils');
28
- const { normalizeDockerTimestamp } = require('./docker-post-mortem');
29
28
  const { END_TIME_SOURCE } = require('./detached-finalize');
30
29
  const { formatCgroupMemory } = require('./cgroup-memory');
30
+ const { addLostWatcherEvidence } = require('./exit-evidence');
31
31
  const {
32
32
  attachContainerRemoval,
33
- dockerInspect,
34
33
  persistContainerRemoval,
35
34
  } = require('./container-removal');
36
-
37
- /**
38
- * Inspect the live state of a detached docker container by name.
39
- *
40
- * Distinguishes three outcomes that matter for status reporting:
41
- * - the container exists and is running,
42
- * - the container exists but has stopped (with a real exit code), and
43
- * - the container cannot be inspected at all.
44
- *
45
- * The last case is crucial on slow Docker-in-Docker hosts (issue #136): right
46
- * after `docker run -d` returns, `docker inspect <name>` can transiently fail
47
- * because the container is not visible yet. A failed inspect must NOT be read
48
- * as "stopped"; it means "unknown", so callers can keep the session running
49
- * instead of fabricating a terminal `-1` result.
50
- *
51
- * @param {string} sessionName - Container name
52
- * @param {Object|null} [probe] - Receives `sessionNotFound` (issue #225)
53
- * @returns {{running: boolean, exitCode: number|null, oomKilled: boolean|null}|null} State,
54
- * or null when the container cannot be inspected (not found yet, removed, or docker error)
55
- */
56
- function inspectDockerState(sessionName, probe = null) {
57
- const { stdout, notFound } = dockerInspect(
58
- getDockerCommand(),
59
- dockerProbeSpawnOptions(),
60
- '{{.State.Running}} {{.State.ExitCode}} {{.State.OOMKilled}} ' +
61
- '{{.State.StartedAt}} {{.State.FinishedAt}}',
62
- sessionName
63
- );
64
- if (probe) {
65
- // "No such container" is a fact, unlike a docker that cannot be reached
66
- // (issue #225); it still reads as unknown liveness here (issue #136).
67
- probe.sessionNotFound = notFound;
68
- }
69
- if (stdout === null) {
70
- return null;
71
- }
72
- // Parsed positionally and defensively: an older docker (or a stubbed one)
73
- // may answer with fewer fields than the template asks for.
74
- const [runningRaw, exitRaw, oomKilledRaw, startedRaw, finishedRaw] = stdout
75
- .trim()
76
- .split(/\s+/);
77
- const exitCode = Number.parseInt(exitRaw, 10);
35
+ const { withDockerInspectBatch } = require('./docker-inspect-batch');
36
+ const {
37
+ backendExitCode,
38
+ dockerProbeSpawnOptions,
39
+ inspectDockerState,
40
+ isDetachedDockerRecord,
41
+ readDockerState,
42
+ resolveOomObservation,
43
+ } = require('./status-probe');
44
+
45
+ /** How the status probes run docker. */
46
+ function dockerProbe() {
78
47
  return {
79
- running: runningRaw === 'true',
80
- exitCode: Number.isFinite(exitCode) ? exitCode : null,
81
- oomKilled:
82
- oomKilledRaw === 'true' ? true : oomKilledRaw === 'false' ? false : null,
83
- startedAt: normalizeDockerTimestamp(startedRaw),
84
- finishedAt: normalizeDockerTimestamp(finishedRaw),
48
+ dockerCommand: getDockerCommand(),
49
+ spawnOptions: dockerProbeSpawnOptions(),
85
50
  };
86
51
  }
87
52
 
88
- function isDetachedDockerRecord(record) {
89
- const opts = record.options || {};
90
- return (
91
- opts.isolated === 'docker' &&
92
- opts.isolationMode === 'detached' &&
93
- Boolean(opts.sessionName)
94
- );
95
- }
96
-
97
- function dockerProbeSpawnOptions() {
98
- return getDockerSpawnOptions({
99
- encoding: 'utf8',
100
- env: process.env,
101
- stdio: ['pipe', 'pipe', 'pipe'],
102
- });
103
- }
104
-
105
- function readDockerState(record, probe = null) {
106
- const opts = record.options || {};
107
- if (opts.isolated !== 'docker' || !opts.sessionName) {
108
- return null;
109
- }
110
- const state = inspectDockerState(opts.sessionName, probe);
111
- if (
112
- record.attempt &&
113
- state?.startedAt &&
114
- Date.parse(state.startedAt) < Date.parse(record.attempt.startedAt)
115
- ) {
116
- return null;
117
- }
118
- return state;
119
- }
120
-
121
- /**
122
- * Best-effort terminal exit code reported by the isolation backend itself
123
- * (currently docker via `docker inspect .State.ExitCode`). Returns null when
124
- * the backend cannot provide a real code, so callers never surface the `-1`
125
- * sentinel for a session whose real exit code is simply not available yet.
126
- * A running container has no terminal exit code (docker reports `0` for it),
127
- * so only a stopped container contributes one.
128
- * @param {{running: boolean, exitCode: number|null}|null} dockerState - Inspected state
129
- * @returns {number|null}
130
- */
131
- function backendExitCode(dockerState) {
132
- return dockerState && !dockerState.running ? dockerState.exitCode : null;
133
- }
134
-
135
- /**
136
- * Reconcile the OOM observation from the stored record and from `docker inspect`.
137
- *
138
- * `State.OOMKilled` is a container-cgroup flag: the kernel sets it when ANY
139
- * process in the cgroup is OOM-killed and it is never cleared for the life of
140
- * the container (moby/moby#47618). It is therefore an *observation*, never a
141
- * verdict about the session (issue #151) — a container that lost one child
142
- * process keeps running and can still exit `0`. Once observed, the flag stays
143
- * `true` for the record.
144
- * @param {Object} record - Execution record
145
- * @param {{oomKilled: boolean|null}|null} dockerState - Inspected state
146
- * @returns {boolean|undefined} Observation, or undefined when nothing is known
147
- */
148
- function resolveOomObservation(record, dockerState) {
149
- if (record.oomKilled === true || dockerState?.oomKilled === true) {
150
- return true;
151
- }
152
- if (record.oomKilled === false || dockerState?.oomKilled === false) {
153
- return false;
154
- }
155
- return undefined;
156
- }
157
-
158
53
  /**
159
54
  * Check if a detached isolation session is still running
160
55
  * @param {Object} record - Execution record
@@ -433,6 +328,7 @@ function resolveDetachedStatus(record, logTail, probe = null) {
433
328
  (oomKilled === true ? 137 : -1);
434
329
  }
435
330
  applyEndTime(enriched, dockerState, footer.finishedAt);
331
+ addLostWatcherEvidence(enriched, record, dockerState, logTail);
436
332
  }
437
333
 
438
334
  return enriched;
@@ -563,10 +459,7 @@ function enrichDetachedStatus(record) {
563
459
  const logTail = record
564
460
  ? readAttemptLogTail(record, FATAL_MARKER_TAIL_BYTES)
565
461
  : null;
566
- const probe = {
567
- dockerCommand: getDockerCommand(),
568
- spawnOptions: dockerProbeSpawnOptions(),
569
- };
462
+ const probe = dockerProbe();
570
463
  const resolved = attachContainerRemoval(
571
464
  resolveDetachedStatus(record, logTail, probe),
572
465
  probe
@@ -920,10 +813,17 @@ function queryStatus(store, identifier, outputFormat) {
920
813
  };
921
814
  }
922
815
  try {
923
- // Enrich detached execution status with live session check
924
- const enrichedRecord = enrichDetachedStatus(record);
925
- persistContainerRemoval(store, record, enrichedRecord);
926
- const withProcessIds = attachProcessIds(enrichedRecord);
816
+ // Enrich detached execution status with live session check; its docker
817
+ // probes are answered by one inspect (issue #243).
818
+ const withProcessIds = withDockerInspectBatch(
819
+ [record],
820
+ dockerProbe(),
821
+ () => {
822
+ const enrichedRecord = enrichDetachedStatus(record);
823
+ persistContainerRemoval(store, record, enrichedRecord);
824
+ return attachProcessIds(enrichedRecord);
825
+ }
826
+ );
927
827
  // Attach currentTime so callers can see how long an executing command has been running
928
828
  const withCurrentTime = require('./execution-chain').attachIdentity(
929
829
  attachCurrentTime(withProcessIds),
@@ -952,8 +852,12 @@ function listExecutions(store, outputFormat, options = {}) {
952
852
  }
953
853
 
954
854
  try {
855
+ const all = store.getAll();
856
+ // One docker inspect for every listed container (issue #243).
955
857
  const enriched = sortRecordsByStartTimeDesc(
956
- store.getAll().map(prepareRecordForList)
858
+ withDockerInspectBatch(all, dockerProbe(), () =>
859
+ all.map(prepareRecordForList)
860
+ )
957
861
  );
958
862
  // --running reports the reconciled status, not the stored one: a record
959
863
  // whose session already died is listed as executed even if the store still
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Live docker state of a detached execution, for `--status` and `--list`.
3
+ *
4
+ * Split out of `status-formatter` (as `status_probe.rs` is in Rust) so the
5
+ * probing stays separate from the rendering and both files stay under the
6
+ * repository line budget (issue #243).
7
+ */
8
+
9
+ const { getDockerCommand, getDockerSpawnOptions } = require('./docker-cleanup');
10
+ const { normalizeDockerTimestamp } = require('./docker-post-mortem');
11
+ const {
12
+ CONTAINER_STATE_REMOVED,
13
+ dockerInspect,
14
+ } = require('./container-removal');
15
+
16
+ /**
17
+ * Inspect the live state of a detached docker container by name.
18
+ *
19
+ * Distinguishes three outcomes that matter for status reporting:
20
+ * - the container exists and is running,
21
+ * - the container exists but has stopped (with a real exit code), and
22
+ * - the container cannot be inspected at all.
23
+ *
24
+ * The last case is crucial on slow Docker-in-Docker hosts (issue #136): right
25
+ * after `docker run -d` returns, `docker inspect <name>` can transiently fail
26
+ * because the container is not visible yet. A failed inspect must NOT be read
27
+ * as "stopped"; it means "unknown", so callers can keep the session running
28
+ * instead of fabricating a terminal `-1` result.
29
+ *
30
+ * @param {string} sessionName - Container name
31
+ * @param {Object|null} [probe] - Receives `sessionNotFound` (issue #225)
32
+ * @returns {{running: boolean, exitCode: number|null, oomKilled: boolean|null}|null} State,
33
+ * or null when the container cannot be inspected (not found yet, removed, or docker error)
34
+ */
35
+ function inspectDockerState(sessionName, probe = null) {
36
+ const { stdout, notFound } = dockerInspect(
37
+ getDockerCommand(),
38
+ dockerProbeSpawnOptions(),
39
+ '{{.State.Running}} {{.State.ExitCode}} {{.State.OOMKilled}} ' +
40
+ '{{.State.StartedAt}} {{.State.FinishedAt}}',
41
+ sessionName
42
+ );
43
+ if (probe) {
44
+ // "No such container" is a fact, unlike a docker that cannot be reached
45
+ // (issue #225); it still reads as unknown liveness here (issue #136).
46
+ probe.sessionNotFound = notFound;
47
+ }
48
+ if (stdout === null) {
49
+ return null;
50
+ }
51
+ // Parsed positionally and defensively: an older docker (or a stubbed one)
52
+ // may answer with fewer fields than the template asks for.
53
+ const [runningRaw, exitRaw, oomKilledRaw, startedRaw, finishedRaw] = stdout
54
+ .trim()
55
+ .split(/\s+/);
56
+ const exitCode = Number.parseInt(exitRaw, 10);
57
+ return {
58
+ running: runningRaw === 'true',
59
+ exitCode: Number.isFinite(exitCode) ? exitCode : null,
60
+ oomKilled:
61
+ oomKilledRaw === 'true' ? true : oomKilledRaw === 'false' ? false : null,
62
+ startedAt: normalizeDockerTimestamp(startedRaw),
63
+ finishedAt: normalizeDockerTimestamp(finishedRaw),
64
+ };
65
+ }
66
+
67
+ function isDetachedDockerRecord(record) {
68
+ const opts = record.options || {};
69
+ return (
70
+ opts.isolated === 'docker' &&
71
+ opts.isolationMode === 'detached' &&
72
+ Boolean(opts.sessionName)
73
+ );
74
+ }
75
+
76
+ function dockerProbeSpawnOptions() {
77
+ return getDockerSpawnOptions({
78
+ encoding: 'utf8',
79
+ env: process.env,
80
+ stdio: ['pipe', 'pipe', 'pipe'],
81
+ });
82
+ }
83
+
84
+ function readDockerState(record, probe = null) {
85
+ const opts = record.options || {};
86
+ if (opts.isolated !== 'docker' || !opts.sessionName) {
87
+ return null;
88
+ }
89
+ if (record.containerState === CONTAINER_STATE_REMOVED) {
90
+ // A removed container stays removed: a relaunch clears the marker, so
91
+ // there is nothing left to ask Docker (issue #243).
92
+ return null;
93
+ }
94
+ const state = inspectDockerState(opts.sessionName, probe);
95
+ if (
96
+ record.attempt &&
97
+ state?.startedAt &&
98
+ Date.parse(state.startedAt) < Date.parse(record.attempt.startedAt)
99
+ ) {
100
+ return null;
101
+ }
102
+ return state;
103
+ }
104
+
105
+ /**
106
+ * Best-effort terminal exit code reported by the isolation backend itself
107
+ * (currently docker via `docker inspect .State.ExitCode`). Returns null when
108
+ * the backend cannot provide a real code, so callers never surface the `-1`
109
+ * sentinel for a session whose real exit code is simply not available yet.
110
+ * A running container has no terminal exit code (docker reports `0` for it),
111
+ * so only a stopped container contributes one.
112
+ * @param {{running: boolean, exitCode: number|null}|null} dockerState - Inspected state
113
+ * @returns {number|null}
114
+ */
115
+ function backendExitCode(dockerState) {
116
+ return dockerState && !dockerState.running ? dockerState.exitCode : null;
117
+ }
118
+
119
+ /**
120
+ * Reconcile the OOM observation from the stored record and from `docker inspect`.
121
+ *
122
+ * `State.OOMKilled` is a container-cgroup flag: the kernel sets it when ANY
123
+ * process in the cgroup is OOM-killed and it is never cleared for the life of
124
+ * the container (moby/moby#47618). It is therefore an *observation*, never a
125
+ * verdict about the session (issue #151) — a container that lost one child
126
+ * process keeps running and can still exit `0`. Once observed, the flag stays
127
+ * `true` for the record.
128
+ * @param {Object} record - Execution record
129
+ * @param {{oomKilled: boolean|null}|null} dockerState - Inspected state
130
+ * @returns {boolean|undefined} Observation, or undefined when nothing is known
131
+ */
132
+ function resolveOomObservation(record, dockerState) {
133
+ if (record.oomKilled === true || dockerState?.oomKilled === true) {
134
+ return true;
135
+ }
136
+ if (record.oomKilled === false || dockerState?.oomKilled === false) {
137
+ return false;
138
+ }
139
+ return undefined;
140
+ }
141
+
142
+ module.exports = {
143
+ backendExitCode,
144
+ dockerProbeSpawnOptions,
145
+ inspectDockerState,
146
+ isDetachedDockerRecord,
147
+ readDockerState,
148
+ resolveOomObservation,
149
+ };
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Decoded execution store, shared within one process and between processes
3
+ * (issue #243).
4
+ *
5
+ * Decoding `executions.lino` costs about 1-4 ms per record, and one
6
+ * `--status` used to decode it up to three times (`get`, then `getAll` twice
7
+ * for the execution chain). The file is still read on every call, so a write
8
+ * by any process is seen at once, but it is decoded again only when its
9
+ * content differs from the last decoded copy. The content itself is the key:
10
+ * unlike an mtime, it cannot miss two same-size writes within one clock tick.
11
+ *
12
+ * A new process (every `$ --status` poll) still had to decode once. The
13
+ * decoded records are therefore also kept as JSON next to the store, tagged
14
+ * with the SHA-256 of the content they were decoded from; `JSON.parse` of
15
+ * that copy is about 250 times faster than the lino decode. A copy whose
16
+ * digest does not match the current content is ignored and replaced.
17
+ */
18
+
19
+ const fs = require('fs');
20
+ const crypto = require('crypto');
21
+ const { isDeepStrictEqual } = require('util');
22
+ const { atomicWrite } = require('./atomic-write');
23
+
24
+ /** Format tag of the JSON copy; a different tag is ignored. */
25
+ const DECODED_COPY_FORMAT = 'start-command-decoded-store-js-1';
26
+
27
+ /** @type {Map<string, {content: string, data: *, decodes: number}>} */
28
+ const decodedStores = new Map();
29
+
30
+ function digestOf(content) {
31
+ return crypto.createHash('sha256').update(content).digest('hex');
32
+ }
33
+
34
+ /**
35
+ * Records of the JSON copy at `copyPath`, when it was decoded from content
36
+ * with this digest; otherwise undefined.
37
+ */
38
+ function readDecodedCopy(copyPath, digest) {
39
+ try {
40
+ const copy = JSON.parse(fs.readFileSync(copyPath, 'utf8'));
41
+ if (copy && copy.format === DECODED_COPY_FORMAT && copy.sha256 === digest) {
42
+ return copy.records;
43
+ }
44
+ } catch {
45
+ /* Missing or unreadable: decode instead. */
46
+ }
47
+ return undefined;
48
+ }
49
+
50
+ /**
51
+ * Keep `data` as JSON for the next process, unless JSON cannot represent it
52
+ * exactly. Best effort: a read-only folder only costs the next decode.
53
+ */
54
+ function writeDecodedCopy(copyPath, digest, data) {
55
+ try {
56
+ const json = JSON.stringify({
57
+ format: DECODED_COPY_FORMAT,
58
+ sha256: digest,
59
+ records: data,
60
+ });
61
+ if (!isDeepStrictEqual(JSON.parse(json).records, data)) {
62
+ return;
63
+ }
64
+ atomicWrite(copyPath, json);
65
+ } catch {
66
+ /* Not kept; the next process decodes again. */
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Decode `content` of the store at `filePath`, or reuse an earlier decode of
72
+ * the same content. Every call returns its own deep copy, so callers may
73
+ * mutate the records they get.
74
+ * @param {string} filePath - Store file the content was read from
75
+ * @param {string} content - Current file content
76
+ * @param {function(string): *} decode - Decoder for a changed content
77
+ * @param {{copyPath?: string}} [options] - JSON copy shared between processes
78
+ * @returns {{data: *, reused: boolean, source: 'memory'|'copy'|'decode'}}
79
+ */
80
+ function decodeStoreContent(filePath, content, decode, options = {}) {
81
+ const cached = decodedStores.get(filePath);
82
+ if (cached && cached.content === content) {
83
+ return {
84
+ data: structuredClone(cached.data),
85
+ reused: true,
86
+ source: 'memory',
87
+ };
88
+ }
89
+ const decodes = cached ? cached.decodes : 0;
90
+ const { copyPath } = options;
91
+ const digest = copyPath ? digestOf(content) : null;
92
+ const copied = copyPath ? readDecodedCopy(copyPath, digest) : undefined;
93
+ if (copied !== undefined) {
94
+ decodedStores.set(filePath, {
95
+ content,
96
+ data: structuredClone(copied),
97
+ decodes,
98
+ });
99
+ return { data: copied, reused: true, source: 'copy' };
100
+ }
101
+ const data = decode(content);
102
+ decodedStores.set(filePath, {
103
+ content,
104
+ data: structuredClone(data),
105
+ decodes: decodes + 1,
106
+ });
107
+ if (copyPath) {
108
+ writeDecodedCopy(copyPath, digest, data);
109
+ }
110
+ return { data, reused: false, source: 'decode' };
111
+ }
112
+
113
+ /**
114
+ * How many times this process decoded the store at `filePath` since it was
115
+ * last forgotten.
116
+ * @param {string} filePath - Store file
117
+ * @returns {number}
118
+ */
119
+ function decodeCount(filePath) {
120
+ const cached = decodedStores.get(filePath);
121
+ return cached ? cached.decodes : 0;
122
+ }
123
+
124
+ /**
125
+ * Drop the decoded copy of a store held by this process.
126
+ * @param {string} [filePath] - Store file; all stores when omitted
127
+ */
128
+ function forgetDecodedStore(filePath) {
129
+ if (filePath === undefined) {
130
+ decodedStores.clear();
131
+ } else {
132
+ decodedStores.delete(filePath);
133
+ }
134
+ }
135
+
136
+ module.exports = {
137
+ DECODED_COPY_FORMAT,
138
+ decodeCount,
139
+ decodeStoreContent,
140
+ forgetDecodedStore,
141
+ };
package/src/lib/usage.js CHANGED
@@ -18,12 +18,14 @@ Options:
18
18
  --env, -e <KEY=VALUE> Environment variable for docker container (repeatable, docker only)
19
19
  --label <KEY=VALUE> Container attribution (repeatable, docker only; start-command.* reserved)
20
20
  --privileged Run docker container in privileged mode (docker only)
21
+ --init, --no-init Run tini as PID 1 to reap orphaned processes (docker only; default START_COMMAND_DOCKER_INIT=1)
21
22
  --network <name> Connect to a named network (repeatable, docker only)
22
23
  --network-alias <alias> Add alias to the first network (repeatable, docker only)
23
24
  --on-kill-resume <N> Resume a killed (exit 137 / OOM) detached docker session up to N times
24
25
  --recovery-command <cmd> Command to run in the same container on such a resume
25
26
  --on-kill-resume-delay <min[-max]> Wait a random number of seconds before each such resume (default 0)
26
27
  --memory <size|N%|MIN%-MAX%> Docker RAM cap; percentages use daemon capacity
28
+ --memory-reservation <spec> Soft memory limit (Docker size or N%, below --memory)
27
29
  --memory-swap <spec> Combined memory+swap cap (defaults to memory, no extra swap)
28
30
  --cpus <n|N%|MIN%-MAX%> Docker CPU cap; ranges draw once per creation
29
31
  --on-kill-resume-memory <spec> New memory cap before a qualifying OOM recovery
@@ -79,6 +81,7 @@ Examples:
79
81
  $ --isolated docker --image ghcr.io/link-foundation/box-js:latest -- bun --version
80
82
  $ -i docker -v ~/.config/gh:/root/.config/gh -e TOKEN=abc -- gh repo list
81
83
  $ -i docker --image konard/hive-mind-dind:latest --privileged -- solve ...
84
+ $ -i docker --init -d -- solve ... # tini reaps zombies of long-running tasks
82
85
  $ --isolated ssh --endpoint user@remote.server -- ls -la
83
86
  $ --isolated-user -- npm test # Create isolated user
84
87
  $ -u myuser -- npm start # Custom username
@@ -0,0 +1,121 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+ import { mkdtempSync, readFileSync, writeFileSync } from 'fs';
3
+ import { tmpdir } from 'os';
4
+ import path from 'path';
5
+ import {
6
+ setCargoLockPackageVersion,
7
+ syncCargoLockVersion,
8
+ } from '../../scripts/cargo-lock-version.mjs';
9
+
10
+ const repoRoot = path.resolve(import.meta.dir, '../..');
11
+ const lock = (version, eol = '\n') =>
12
+ [
13
+ '# This file is automatically @generated by Cargo.',
14
+ 'version = 4',
15
+ '',
16
+ '[[package]]',
17
+ 'name = "start-command"',
18
+ `version = "${version}"`,
19
+ 'dependencies = [',
20
+ ' "serde",',
21
+ ']',
22
+ '',
23
+ '[[package]]',
24
+ 'name = "start-command-helper"',
25
+ 'version = "9.9.9"',
26
+ '',
27
+ ].join(eol);
28
+
29
+ describe('setCargoLockPackageVersion', () => {
30
+ it('rewrites only the named package entry', () => {
31
+ const result = setCargoLockPackageVersion(
32
+ lock('0.23.0'),
33
+ 'start-command',
34
+ '0.27.0'
35
+ );
36
+ expect(result).toEqual({
37
+ text: lock('0.27.0'),
38
+ found: true,
39
+ changed: true,
40
+ });
41
+ expect(result.text).toContain('version = "9.9.9"');
42
+ });
43
+
44
+ it('reports an already synced entry as unchanged', () => {
45
+ expect(
46
+ setCargoLockPackageVersion(lock('0.27.0'), 'start-command', '0.27.0')
47
+ ).toEqual({ text: lock('0.27.0'), found: true, changed: false });
48
+ });
49
+
50
+ it('keeps CRLF line endings', () => {
51
+ expect(
52
+ setCargoLockPackageVersion(
53
+ lock('0.1.0', '\r\n'),
54
+ 'start-command',
55
+ '0.2.0'
56
+ ).text
57
+ ).toBe(lock('0.2.0', '\r\n'));
58
+ });
59
+
60
+ it('does not match a package whose name only starts with the crate name', () => {
61
+ expect(
62
+ setCargoLockPackageVersion(lock('0.1.0'), 'start', '1.0.0').found
63
+ ).toBe(false);
64
+ });
65
+ });
66
+
67
+ describe('syncCargoLockVersion', () => {
68
+ it('writes the file only when the version changes', () => {
69
+ const file = path.join(mkdtempSync(path.join(tmpdir(), 'lock-')), 'l');
70
+ writeFileSync(file, lock('0.1.0'));
71
+ expect(syncCargoLockVersion(file, 'start-command', '0.2.0')).toBe(true);
72
+ expect(readFileSync(file, 'utf8')).toBe(lock('0.2.0'));
73
+ expect(syncCargoLockVersion(file, 'start-command', '0.2.0')).toBe(false);
74
+ });
75
+
76
+ it('skips a missing lock file and rejects a lock without the crate', () => {
77
+ const dir = mkdtempSync(path.join(tmpdir(), 'lock-'));
78
+ expect(
79
+ syncCargoLockVersion(path.join(dir, 'none'), 'start-command', '1.0.0')
80
+ ).toBe(false);
81
+ const file = path.join(dir, 'Cargo.lock');
82
+ writeFileSync(file, lock('0.1.0'));
83
+ expect(() => syncCargoLockVersion(file, 'other', '1.0.0')).toThrow(
84
+ /no \[\[package\]\] entry for other/
85
+ );
86
+ });
87
+ });
88
+
89
+ describe('repository Cargo.lock (issue #234)', () => {
90
+ it('records the Cargo.toml version of the crate', () => {
91
+ const manifest = readFileSync(
92
+ path.join(repoRoot, 'rust/Cargo.toml'),
93
+ 'utf8'
94
+ );
95
+ const name = manifest.match(/^name\s*=\s*"([^"]+)"/m)[1];
96
+ const version = manifest.match(/^version\s*=\s*"([^"]+)"/m)[1];
97
+ const result = setCargoLockPackageVersion(
98
+ readFileSync(path.join(repoRoot, 'rust/Cargo.lock'), 'utf8'),
99
+ name,
100
+ version
101
+ );
102
+ expect(result.found).toBe(true);
103
+ expect(result.changed).toBe(false);
104
+ });
105
+
106
+ it('is synced and staged by both Rust version bump scripts', () => {
107
+ for (const script of ['version-and-commit.mjs', 'bump-version.mjs']) {
108
+ const source = readFileSync(
109
+ path.join(repoRoot, 'scripts', script),
110
+ 'utf8'
111
+ );
112
+ expect(source).toContain("syncCargoLockVersion('Cargo.lock'");
113
+ }
114
+ expect(
115
+ readFileSync(
116
+ path.join(repoRoot, 'scripts/version-and-commit.mjs'),
117
+ 'utf8'
118
+ )
119
+ ).toContain("['Cargo.toml', 'Cargo.lock', 'CHANGELOG.md', 'changelog.d']");
120
+ });
121
+ });