@countinghouse/ch-local 0.0.0-stage → 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/LICENSE +202 -0
- package/README.md +361 -2
- package/bin/ch-local.js +472 -0
- package/clients/claude-code/.claude-plugin/plugin.json +6 -0
- package/clients/claude-code/.mcp.json +11 -0
- package/clients/claude-code/bin/launch.js +235 -0
- package/clients/claude-code/bin/win-acl.js +420 -0
- package/clients/claude-code/skills/ci-failure-triage/SKILL.md +21 -0
- package/clients/claude-code/skills/countinghouse-module/SKILL.md +177 -0
- package/clients/claude-code/skills/countinghouse-setup/SKILL.md +74 -0
- package/lib/allowlist.js +65 -0
- package/lib/aside.js +16 -0
- package/lib/atomic.js +45 -0
- package/lib/auto-apply.js +245 -0
- package/lib/auto-upgrade.js +98 -0
- package/lib/availability.js +307 -0
- package/lib/ceiling.js +280 -0
- package/lib/clean-text.js +20 -0
- package/lib/cli-change.js +38 -0
- package/lib/client-conditions-fixtures.js +143 -0
- package/lib/client-conditions.js +656 -0
- package/lib/clients.js +179 -0
- package/lib/command-line.js +202 -0
- package/lib/conditions-command.js +116 -0
- package/lib/control.js +134 -0
- package/lib/credential-store.js +414 -0
- package/lib/credentials-command.js +344 -0
- package/lib/daemon-requests.js +137 -0
- package/lib/daemon.js +888 -0
- package/lib/describe-module.js +137 -0
- package/lib/description-check.js +175 -0
- package/lib/failed-json.js +43 -0
- package/lib/gc.js +274 -0
- package/lib/github-token.js +57 -0
- package/lib/handoff-io.js +73 -0
- package/lib/held-back.js +116 -0
- package/lib/hidden-input.js +64 -0
- package/lib/history.js +49 -0
- package/lib/home.js +372 -0
- package/lib/in-place.js +1036 -0
- package/lib/install-plan.js +142 -0
- package/lib/install.js +846 -0
- package/lib/installed-description.js +153 -0
- package/lib/integrity.js +7 -0
- package/lib/lock.js +456 -0
- package/lib/lockfile-rules.js +98 -0
- package/lib/machine.js +20 -0
- package/lib/module-credentials.js +403 -0
- package/lib/module-record.js +298 -0
- package/lib/module-roles.js +44 -0
- package/lib/module-seams.js +26 -0
- package/lib/module-store.js +202 -0
- package/lib/module-values.js +334 -0
- package/lib/names.js +31 -0
- package/lib/next-steps.js +8 -0
- package/lib/node-check.js +56 -0
- package/lib/npm-fetch.js +123 -0
- package/lib/npm-release.js +99 -0
- package/lib/npm-upgrade.js +146 -0
- package/lib/npm.js +41 -0
- package/lib/outside-edits.js +162 -0
- package/lib/own-applied.js +175 -0
- package/lib/own-command.js +380 -0
- package/lib/own-file.js +120 -0
- package/lib/own-record.js +96 -0
- package/lib/own-tree.js +336 -0
- package/lib/pack-table.js +290 -0
- package/lib/packs-command.js +570 -0
- package/lib/packs.js +219 -0
- package/lib/pins.js +64 -0
- package/lib/pipe-probe.js +82 -0
- package/lib/plain-read.js +63 -0
- package/lib/private-file.js +90 -0
- package/lib/private-write.js +33 -0
- package/lib/provenance.js +234 -0
- package/lib/record.js +82 -0
- package/lib/registry.js +22 -0
- package/lib/release-pins.js +350 -0
- package/lib/release-pins.json +4225 -0
- package/lib/release-tags.js +12 -0
- package/lib/release.js +36 -0
- package/lib/restart-command.js +161 -0
- package/lib/rollback.js +227 -0
- package/lib/run-liveness.js +15 -0
- package/lib/runtime-log.js +287 -0
- package/lib/sandbox-support.js +17 -0
- package/lib/semver-order.js +40 -0
- package/lib/session-socket.js +69 -0
- package/lib/session-table.js +238 -0
- package/lib/session.js +281 -0
- package/lib/settings-command.js +82 -0
- package/lib/settings.js +564 -0
- package/lib/shim-binary.js +152 -0
- package/lib/shim-config.js +159 -0
- package/lib/shim-install.js +365 -0
- package/lib/sigstore/README.md +44 -0
- package/lib/sigstore/npm-keys.json +18 -0
- package/lib/sigstore/trusted-root.json +126 -0
- package/lib/snippets.js +76 -0
- package/lib/start.js +721 -0
- package/lib/store-files.js +48 -0
- package/lib/store-paths.js +33 -0
- package/lib/swap-preload.js +38 -0
- package/lib/tar.js +220 -0
- package/lib/uninstall.js +314 -0
- package/lib/unpack.js +41 -0
- package/lib/upgrade-stamp.js +63 -0
- package/lib/upgrade.js +281 -0
- package/lib/watch.js +40 -0
- package/lib/win-acl.js +420 -0
- package/node_modules/@sigstore/bundle/LICENSE +202 -0
- package/node_modules/@sigstore/bundle/README.md +19 -0
- package/node_modules/@sigstore/bundle/dist/build.d.ts +18 -0
- package/node_modules/@sigstore/bundle/dist/build.js +100 -0
- package/node_modules/@sigstore/bundle/dist/bundle.d.ts +74 -0
- package/node_modules/@sigstore/bundle/dist/bundle.js +24 -0
- package/node_modules/@sigstore/bundle/dist/error.d.ts +4 -0
- package/node_modules/@sigstore/bundle/dist/error.js +25 -0
- package/node_modules/@sigstore/bundle/dist/index.d.ts +8 -0
- package/node_modules/@sigstore/bundle/dist/index.js +43 -0
- package/node_modules/@sigstore/bundle/dist/serialized.d.ts +74 -0
- package/node_modules/@sigstore/bundle/dist/serialized.js +49 -0
- package/node_modules/@sigstore/bundle/dist/utility.d.ts +14 -0
- package/node_modules/@sigstore/bundle/dist/utility.js +2 -0
- package/node_modules/@sigstore/bundle/dist/validate.d.ts +7 -0
- package/node_modules/@sigstore/bundle/dist/validate.js +199 -0
- package/node_modules/@sigstore/bundle/package.json +35 -0
- package/node_modules/@sigstore/core/LICENSE +202 -0
- package/node_modules/@sigstore/core/README.md +10 -0
- package/node_modules/@sigstore/core/dist/asn1/error.d.ts +4 -0
- package/node_modules/@sigstore/core/dist/asn1/error.js +24 -0
- package/node_modules/@sigstore/core/dist/asn1/index.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/asn1/index.js +20 -0
- package/node_modules/@sigstore/core/dist/asn1/length.d.ts +3 -0
- package/node_modules/@sigstore/core/dist/asn1/length.js +62 -0
- package/node_modules/@sigstore/core/dist/asn1/obj.d.ts +14 -0
- package/node_modules/@sigstore/core/dist/asn1/obj.js +155 -0
- package/node_modules/@sigstore/core/dist/asn1/parse.d.ts +6 -0
- package/node_modules/@sigstore/core/dist/asn1/parse.js +124 -0
- package/node_modules/@sigstore/core/dist/asn1/tag.d.ts +16 -0
- package/node_modules/@sigstore/core/dist/asn1/tag.js +89 -0
- package/node_modules/@sigstore/core/dist/crypto.d.ts +6 -0
- package/node_modules/@sigstore/core/dist/crypto.js +69 -0
- package/node_modules/@sigstore/core/dist/dsse.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/dsse.js +29 -0
- package/node_modules/@sigstore/core/dist/encoding.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/encoding.js +27 -0
- package/node_modules/@sigstore/core/dist/index.d.ts +9 -0
- package/node_modules/@sigstore/core/dist/index.js +66 -0
- package/node_modules/@sigstore/core/dist/json.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/json.js +60 -0
- package/node_modules/@sigstore/core/dist/oid.d.ts +3 -0
- package/node_modules/@sigstore/core/dist/oid.js +20 -0
- package/node_modules/@sigstore/core/dist/pem.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/pem.js +43 -0
- package/node_modules/@sigstore/core/dist/rfc3161/error.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/rfc3161/error.js +21 -0
- package/node_modules/@sigstore/core/dist/rfc3161/index.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/rfc3161/index.js +20 -0
- package/node_modules/@sigstore/core/dist/rfc3161/timestamp.d.ts +36 -0
- package/node_modules/@sigstore/core/dist/rfc3161/timestamp.js +212 -0
- package/node_modules/@sigstore/core/dist/rfc3161/tstinfo.d.ts +12 -0
- package/node_modules/@sigstore/core/dist/rfc3161/tstinfo.js +72 -0
- package/node_modules/@sigstore/core/dist/stream.d.ts +21 -0
- package/node_modules/@sigstore/core/dist/stream.js +117 -0
- package/node_modules/@sigstore/core/dist/x509/cert.d.ts +43 -0
- package/node_modules/@sigstore/core/dist/x509/cert.js +245 -0
- package/node_modules/@sigstore/core/dist/x509/ext.d.ts +41 -0
- package/node_modules/@sigstore/core/dist/x509/ext.js +146 -0
- package/node_modules/@sigstore/core/dist/x509/index.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/x509/index.js +23 -0
- package/node_modules/@sigstore/core/dist/x509/sct.d.ts +25 -0
- package/node_modules/@sigstore/core/dist/x509/sct.js +158 -0
- package/node_modules/@sigstore/core/package.json +31 -0
- package/node_modules/@sigstore/protobuf-specs/LICENSE +202 -0
- package/node_modules/@sigstore/protobuf-specs/README.md +5 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/envelope.d.ts +44 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/envelope.js +59 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/events.d.ts +64 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/events.js +174 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/api/field_behavior.d.ts +74 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/api/field_behavior.js +141 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/any.d.ts +74 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/any.js +35 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/descriptor.d.ts +1309 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/descriptor.js +2191 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/timestamp.d.ts +113 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/timestamp.js +29 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/dsse.d.ts +23 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/dsse.js +55 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/entry.d.ts +43 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/entry.js +81 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/hashedrekord.d.ts +22 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/hashedrekord.js +56 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/verifier.d.ts +35 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/verifier.js +74 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_bundle.d.ts +146 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_bundle.js +103 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_common.d.ts +304 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_common.js +612 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_monitor.d.ts +33 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_monitor.js +55 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_rekor.d.ts +144 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_rekor.js +137 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_trustroot.d.ts +386 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_trustroot.js +284 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_verification.d.ts +191 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_verification.js +281 -0
- package/node_modules/@sigstore/protobuf-specs/dist/index.d.ts +6 -0
- package/node_modules/@sigstore/protobuf-specs/dist/index.js +37 -0
- package/node_modules/@sigstore/protobuf-specs/dist/rekor/v2/index.d.ts +4 -0
- package/node_modules/@sigstore/protobuf-specs/dist/rekor/v2/index.js +35 -0
- package/node_modules/@sigstore/protobuf-specs/package.json +35 -0
- package/node_modules/@sigstore/verify/README.md +9 -0
- package/node_modules/@sigstore/verify/dist/bundle/dsse.d.ts +12 -0
- package/node_modules/@sigstore/verify/dist/bundle/dsse.js +44 -0
- package/node_modules/@sigstore/verify/dist/bundle/index.d.ts +4 -0
- package/node_modules/@sigstore/verify/dist/bundle/index.js +59 -0
- package/node_modules/@sigstore/verify/dist/bundle/message.d.ts +13 -0
- package/node_modules/@sigstore/verify/dist/bundle/message.js +54 -0
- package/node_modules/@sigstore/verify/dist/error.d.ts +16 -0
- package/node_modules/@sigstore/verify/dist/error.js +34 -0
- package/node_modules/@sigstore/verify/dist/index.d.ts +6 -0
- package/node_modules/@sigstore/verify/dist/index.js +28 -0
- package/node_modules/@sigstore/verify/dist/key/certificate.d.ts +21 -0
- package/node_modules/@sigstore/verify/dist/key/certificate.js +216 -0
- package/node_modules/@sigstore/verify/dist/key/index.d.ts +10 -0
- package/node_modules/@sigstore/verify/dist/key/index.js +75 -0
- package/node_modules/@sigstore/verify/dist/key/sct.d.ts +4 -0
- package/node_modules/@sigstore/verify/dist/key/sct.js +78 -0
- package/node_modules/@sigstore/verify/dist/policy.d.ts +5 -0
- package/node_modules/@sigstore/verify/dist/policy.js +50 -0
- package/node_modules/@sigstore/verify/dist/shared.types.d.ts +50 -0
- package/node_modules/@sigstore/verify/dist/shared.types.js +2 -0
- package/node_modules/@sigstore/verify/dist/timestamp/index.d.ts +11 -0
- package/node_modules/@sigstore/verify/dist/timestamp/index.js +24 -0
- package/node_modules/@sigstore/verify/dist/timestamp/tsa.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/timestamp/tsa.js +63 -0
- package/node_modules/@sigstore/verify/dist/tlog/checkpoint.d.ts +11 -0
- package/node_modules/@sigstore/verify/dist/tlog/checkpoint.js +154 -0
- package/node_modules/@sigstore/verify/dist/tlog/dsse.d.ts +6 -0
- package/node_modules/@sigstore/verify/dist/tlog/dsse.js +106 -0
- package/node_modules/@sigstore/verify/dist/tlog/hashedrekord.d.ts +6 -0
- package/node_modules/@sigstore/verify/dist/tlog/hashedrekord.js +94 -0
- package/node_modules/@sigstore/verify/dist/tlog/index.d.ts +5 -0
- package/node_modules/@sigstore/verify/dist/tlog/index.js +92 -0
- package/node_modules/@sigstore/verify/dist/tlog/intoto.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/tlog/intoto.js +62 -0
- package/node_modules/@sigstore/verify/dist/tlog/merkle.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/tlog/merkle.js +104 -0
- package/node_modules/@sigstore/verify/dist/tlog/set.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/tlog/set.js +60 -0
- package/node_modules/@sigstore/verify/dist/trust/filter.d.ts +8 -0
- package/node_modules/@sigstore/verify/dist/trust/filter.js +23 -0
- package/node_modules/@sigstore/verify/dist/trust/index.d.ts +5 -0
- package/node_modules/@sigstore/verify/dist/trust/index.js +90 -0
- package/node_modules/@sigstore/verify/dist/trust/trust.types.d.ts +29 -0
- package/node_modules/@sigstore/verify/dist/trust/trust.types.js +2 -0
- package/node_modules/@sigstore/verify/dist/verifier.d.ts +31 -0
- package/node_modules/@sigstore/verify/dist/verifier.js +160 -0
- package/node_modules/@sigstore/verify/package.json +36 -0
- package/package.json +37 -4
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// The tag a pinned version is released under, by the workflow that builds
|
|
3
|
+
// it, never free text (docs/development/auto-upgrade.md): v<version> from
|
|
4
|
+
// publish.yml (every npm package), shim-v<version> from shim.yml (the native
|
|
5
|
+
// shim's six packages). The release-gating tag ruleset covers both. Any
|
|
6
|
+
// other workflow builds no release. Shared by lib/release-pins.js and
|
|
7
|
+
// lib/provenance.js, and dependency-free, so reading the pins loads no
|
|
8
|
+
// verifier.
|
|
9
|
+
const TAG_PREFIX = Object.freeze({'.github/workflows/publish.yml': 'v', '.github/workflows/shim.yml': 'shim-v'});
|
|
10
|
+
const tagFor = (workflow, version) => (Object.prototype.hasOwnProperty.call(TAG_PREFIX, workflow) ? `${TAG_PREFIX[workflow]}${version}` : null);
|
|
11
|
+
|
|
12
|
+
module.exports = {TAG_PREFIX, tagFor};
|
package/lib/release.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// What a release does with a directory of tarballs, shared by the smoke test
|
|
3
|
+
// and scripts/dogfood.js (and, at the first release, the release step): pack
|
|
4
|
+
// a package into it, and generate the runtime's lockfile from the manifest
|
|
5
|
+
// install writes, so --unreleased-pins (lib/pins.js) takes what these produce.
|
|
6
|
+
const fs = require('node:fs');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
const {npm} = require('./npm');
|
|
9
|
+
const {appManifest, tarballName} = require('./install');
|
|
10
|
+
|
|
11
|
+
const LOCK_FLAGS = ['--package-lock-only', '--omit=optional', '--ignore-scripts', '--no-audit', '--no-fund'];
|
|
12
|
+
|
|
13
|
+
// npm pack of `dir` into `release` -> {name, version, filename, integrity}
|
|
14
|
+
// (npm's own sha512 of the tarball).
|
|
15
|
+
async function packInto(npmIo, dir, release) {
|
|
16
|
+
const r = await npm(npmIo, ['pack', '--json', '--pack-destination', release], dir);
|
|
17
|
+
if (r.status !== 0) throw new Error(`npm pack of ${dir} failed:\n${String(r.stderr).split('\n').slice(-10).join('\n')}`);
|
|
18
|
+
const {name, version, filename, integrity} = JSON.parse(r.stdout)[0];
|
|
19
|
+
return {name, version, filename, integrity};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// The runtime's v3 lockfile, from the runtime tarballs in `release`, built in
|
|
23
|
+
// `workDir` (which must not exist). Reaches the npm registry for metadata.
|
|
24
|
+
async function runtimeLockfile(npmIo, release, runtime, pins, workDir) {
|
|
25
|
+
fs.mkdirSync(path.join(workDir, 'tarballs'), {recursive: true});
|
|
26
|
+
for (const name of runtime.packages) {
|
|
27
|
+
const file = tarballName(name, pins[name].version);
|
|
28
|
+
fs.copyFileSync(path.join(release, file), path.join(workDir, 'tarballs', file));
|
|
29
|
+
}
|
|
30
|
+
fs.writeFileSync(path.join(workDir, 'package.json'), JSON.stringify(appManifest(runtime, pins)));
|
|
31
|
+
const r = await npm(npmIo, ['install', ...LOCK_FLAGS], workDir);
|
|
32
|
+
if (r.status !== 0) throw new Error(`npm could not lock the runtime:\n${String(r.stderr).split('\n').slice(-10).join('\n')}`);
|
|
33
|
+
return JSON.parse(fs.readFileSync(path.join(workDir, 'package-lock.json'), 'utf8'));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = {packInto, runtimeLockfile};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// ch-local restart (A5, the final pass): the shared runtime takes what is
|
|
3
|
+
// stored now, its sessions asked to resume. A client's restart only attaches
|
|
4
|
+
// again to the same running runtime, which stops 10 minutes after its last
|
|
5
|
+
// session; so a change that "applies at the next start" needs the runtime
|
|
6
|
+
// itself restarted. Through the daemon's requests (lib/daemon-requests.js
|
|
7
|
+
// requestRestart: a changed ch-local handed over to, else drained and
|
|
8
|
+
// started again with its session table), never a signal. A restart reads
|
|
9
|
+
// exactly what any daemon start reads: what is stored, the ceiling's bounds
|
|
10
|
+
// applied as at any start.
|
|
11
|
+
// Said only as seen:
|
|
12
|
+
// - restarted: daemon.json's runtimeStarted changed from the baseline read
|
|
13
|
+
// under start.lock right after the request, AND its socket proves the
|
|
14
|
+
// secret;
|
|
15
|
+
// - failed: daemon.json gone and a failed.json there;
|
|
16
|
+
// - stopped: daemon.json gone, no failed.json, and no successor within the
|
|
17
|
+
// bound;
|
|
18
|
+
// - never "goes on as before" while daemon.json names no socket (it is
|
|
19
|
+
// still restarting).
|
|
20
|
+
const fs = require('node:fs');
|
|
21
|
+
const path = require('node:path');
|
|
22
|
+
const {layout} = require('./home');
|
|
23
|
+
const {chLocal} = require('./command-line');
|
|
24
|
+
|
|
25
|
+
// how long the command watches for the restart: a drain, a runtime's start,
|
|
26
|
+
// an old runtime's stop, and 20 s
|
|
27
|
+
const restartBoundMs = () => { const d = require('./daemon'); return d.drainBoundMs() + d.READY_MS + d.STOP_MS + 20000; };
|
|
28
|
+
// after a stop, how long a successor is waited for: its runtime's start, a
|
|
29
|
+
// stop, and 10 s for its own boot and its wait on start.lock. A fresh daemon's
|
|
30
|
+
// cold start ends within COLD_READY_MS of its process start, inside READY_MS
|
|
31
|
+
// and those 10 s
|
|
32
|
+
const successorWaitMs = () => { const d = require('./daemon'); return d.READY_MS + d.STOP_MS + 10000; };
|
|
33
|
+
|
|
34
|
+
// io.restartWaitMs: a test's bound. -> 0 restarted (or asked of a daemon
|
|
35
|
+
// that can't show it, or stopped) | 1 not (said)
|
|
36
|
+
async function restart(_, io) {
|
|
37
|
+
const say = (s) => io.stdout.write(s + '\n');
|
|
38
|
+
const fail = (s) => io.stderr.write(`ch-local restart: ${s}\n`);
|
|
39
|
+
const where = layout(io.env, io.homedir);
|
|
40
|
+
if (!fs.existsSync(where.home)) { fail(`nothing is installed: ${where.home} does not exist`); return 1; }
|
|
41
|
+
const d = require('./daemon');
|
|
42
|
+
const runDir = path.join(where.home, 'run', 'daemon');
|
|
43
|
+
const opts = {platform: io.platform, probePipe: io.probePipe || null, ...(typeof io.alive === 'function' ? {alive: io.alive} : {})};
|
|
44
|
+
const before = await d.daemonServing(where.home, opts);
|
|
45
|
+
if (!before.serving) {
|
|
46
|
+
say('no shared runtime runs here: restart your client, whose own runtime takes the change at its start');
|
|
47
|
+
return 1;
|
|
48
|
+
}
|
|
49
|
+
if (before.by !== 'socket' && before.by !== 'pid') {
|
|
50
|
+
fail(`whether the shared runtime runs can't be told (${path.join(runDir, 'daemon.json')} can't be read); nothing changed`);
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
// (a settings file a start refuses would fail every restart, the shared
|
|
54
|
+
// mode then off: refused now, nothing asked -- the reviewer's high, M1)
|
|
55
|
+
const settings = require('./settings').readSettings(where);
|
|
56
|
+
if (settings.error != null) {
|
|
57
|
+
fail(`${settings.error}: a restart would not start; fix it first (\`${chLocal(where, 'settings reset')}\` resets every setting); nothing changed`);
|
|
58
|
+
return 1;
|
|
59
|
+
}
|
|
60
|
+
const bound = Number.isInteger(io.restartWaitMs) ? io.restartWaitMs : restartBoundMs();
|
|
61
|
+
// (a private read only when daemon.json's stat changed: on Windows each is
|
|
62
|
+
// a blocking PowerShell run, and this waits up to minutes -- the
|
|
63
|
+
// closing pass, L3. A read that gave nothing is never kept)
|
|
64
|
+
const file = path.join(runDir, 'daemon.json');
|
|
65
|
+
let lastKey = null;
|
|
66
|
+
let lastJson = null;
|
|
67
|
+
const read = () => {
|
|
68
|
+
let st;
|
|
69
|
+
try { st = fs.lstatSync(file); } catch (e) { lastKey = null; return null; }
|
|
70
|
+
const key = `${st.ino}:${st.size}:${st.mtimeMs}`;
|
|
71
|
+
if (key === lastKey) return lastJson;
|
|
72
|
+
lastJson = d.readDaemonJson(runDir);
|
|
73
|
+
lastKey = lastJson == null ? null : key;
|
|
74
|
+
return lastJson;
|
|
75
|
+
};
|
|
76
|
+
// (the baseline read under start.lock, right after the request: a restart
|
|
77
|
+
// already under way is not taken for this one -- M2)
|
|
78
|
+
let was;
|
|
79
|
+
const asked = await require('./daemon-requests').requestRestart(where.home, {io, platform: io.platform, signal: AbortSignal.timeout(bound),
|
|
80
|
+
underLock: () => { const j = read(); was = j == null ? undefined : (j.runtimeStarted || null); }});
|
|
81
|
+
if (!asked) {
|
|
82
|
+
fail(`the restart could not be asked for (${runDir} is not this user's private folder, its requests file could not be written, or another start held it past ${bound / 1000} s); nothing changed`);
|
|
83
|
+
return 1;
|
|
84
|
+
}
|
|
85
|
+
// (a baseline that can't be known is never taken for a change: asked for,
|
|
86
|
+
// and said as what it is -- M2, N2)
|
|
87
|
+
if (was === null) {
|
|
88
|
+
say('the restart is asked for; whether the shared runtime has restarted can\'t be seen here (it was started by an earlier ch-local). It restarts once its calls finish, its sessions asked to resume');
|
|
89
|
+
return 0;
|
|
90
|
+
}
|
|
91
|
+
if (was === undefined && !fs.existsSync(path.join(runDir, 'daemon.json'))) {
|
|
92
|
+
// (gone between the check and the request: an idle stop -- the medium
|
|
93
|
+
// on #147's last round, 7)
|
|
94
|
+
say('the shared runtime stopped before the restart was asked for; the next session starts it, with what is stored');
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
if (was === undefined) {
|
|
98
|
+
say(`the restart is asked for; whether the shared runtime has restarted can't be seen here (${path.join(runDir, 'daemon.json')} couldn't be read just now). It restarts once its calls finish, its sessions asked to resume`);
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
// (the time to watch starts now, the request written: the lock's wait
|
|
102
|
+
// never eats it -- R1. A successor after "gone" is waited for only as long
|
|
103
|
+
// as a daemon takes to start -- N1)
|
|
104
|
+
const until = Date.now() + bound;
|
|
105
|
+
// (with a margin for the successor's own boot and its wait on start.lock:
|
|
106
|
+
// the medium on #147's last round, 6)
|
|
107
|
+
const successorMs = Number.isInteger(io.successorWaitMs) ? io.successorWaitMs : successorWaitMs();
|
|
108
|
+
let goneUntil = null;
|
|
109
|
+
for (;;) {
|
|
110
|
+
const now = read();
|
|
111
|
+
if (now == null && !fs.existsSync(path.join(runDir, 'daemon.json'))) {
|
|
112
|
+
const failed = readFailed(runDir);
|
|
113
|
+
if (failed != null) {
|
|
114
|
+
fail(`the shared runtime could not start again (${failed}), so the sessions run their own runtimes for now; ${path.join(runDir, 'failed.json')} records it`);
|
|
115
|
+
return 1;
|
|
116
|
+
}
|
|
117
|
+
if (goneUntil == null) {
|
|
118
|
+
goneUntil = Date.now() + successorMs;
|
|
119
|
+
say(`the shared runtime stopped; waiting up to ${successorMs / 1000} s for its successor`);
|
|
120
|
+
}
|
|
121
|
+
if (Date.now() >= Math.min(goneUntil, until)) {
|
|
122
|
+
say('the shared runtime stopped and has not started again; the next session starts it, with what is stored');
|
|
123
|
+
return 0;
|
|
124
|
+
}
|
|
125
|
+
} else if (now != null && now.runtimeStarted != null && now.runtimeStarted !== was) {
|
|
126
|
+
const after = await d.daemonServing(where.home, opts);
|
|
127
|
+
if (after.serving && after.by === 'socket') { say('the shared runtime restarted; its sessions are asked to resume'); return 0; }
|
|
128
|
+
}
|
|
129
|
+
if (Date.now() >= until) break;
|
|
130
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
131
|
+
}
|
|
132
|
+
const last = read();
|
|
133
|
+
if (last != null && last.socket == null) {
|
|
134
|
+
fail(`the shared runtime is still restarting after ${bound / 1000} s (${path.join(runDir, 'daemon.json')} names no socket yet); it serves again once its runtime listens`);
|
|
135
|
+
return 1;
|
|
136
|
+
}
|
|
137
|
+
// (a daemon gone without removing daemon.json -- killed -- serves no
|
|
138
|
+
// request: said, exit 1 -- the medium on #147's last round, 5)
|
|
139
|
+
const still = await d.daemonServing(where.home, opts);
|
|
140
|
+
if (!still.serving) {
|
|
141
|
+
fail('the shared runtime\'s daemon has gone without restarting it; the next session starts it, with what is stored');
|
|
142
|
+
return 1;
|
|
143
|
+
}
|
|
144
|
+
// (asked, written, and not yet seen: never "run it again", the request
|
|
145
|
+
// stands -- R1)
|
|
146
|
+
say(`the restart is asked for and hasn't happened yet after ${bound / 1000} s; it will once its calls finish`);
|
|
147
|
+
return 0;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// failed.json's reason, if this run directory holds one -> text | null
|
|
151
|
+
function readFailed(runDir) {
|
|
152
|
+
// (by the shim's own rule, lib/failed-json.js: a file a session ignores --
|
|
153
|
+
// stale, from the future, of another shape -- is none, so "gave up" is
|
|
154
|
+
// said only while a session would act on it -- the medium on the closing
|
|
155
|
+
// pass, 1; restart's own use was the same gap)
|
|
156
|
+
const reason = require('./failed-json').read(runDir);
|
|
157
|
+
const words = {'restarts-exhausted': 'it failed 5 times in 10 minutes', 'never-listened': 'it never listened'};
|
|
158
|
+
return reason == null ? null : words[reason];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
module.exports = {restart, readFailed, restartBoundMs, successorWaitMs};
|
package/lib/rollback.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// ch-local rollback [--yes] (plan Task 12; business review, 2026-11-12). An
|
|
3
|
+
// install over an existing one keeps the replaced release's programs in
|
|
4
|
+
// <home>/previous (app/ and its modules.json), one level. rollback swaps them
|
|
5
|
+
// with the current ones in one step, so a second rollback returns to the newer
|
|
6
|
+
// release.
|
|
7
|
+
// - Programs only: caches, usage records, settings, the identity secret, the
|
|
8
|
+
// client entries and auth.json are not touched.
|
|
9
|
+
// - A pack the restored release lacks stays recorded under `held`, with the
|
|
10
|
+
// release it was installed under; start does not load it, status names it,
|
|
11
|
+
// and remove-pack removes it.
|
|
12
|
+
// - Rolling back a release marked as a security fix names it, says what it
|
|
13
|
+
// fixed and asks; without a terminal it refuses unless --yes.
|
|
14
|
+
// - A kept release from before rollback existed is refused: its launcher
|
|
15
|
+
// could never bring you back. So is one from before the module store
|
|
16
|
+
// (previous/packs.json, #413 section 10).
|
|
17
|
+
// - One pack that got worse is remove-pack on the current release, not this.
|
|
18
|
+
//
|
|
19
|
+
// The swap is three renames and two record writes, so it is journaled: before
|
|
20
|
+
// anything moves, <home>/rollback.journal holds both records and the newer app
|
|
21
|
+
// gets a marker file holding the journal's time. While the journal exists
|
|
22
|
+
// every command refuses (lib/record.js; install too), and the next rollback
|
|
23
|
+
// finishes the swap from what is on disk, trusting only this rollback's
|
|
24
|
+
// marker; a state no step leaves is refused, the journal kept. A rename that
|
|
25
|
+
// fails part-way is undone at once, and nothing is ever removed recursively,
|
|
26
|
+
// so the newer release cannot be lost.
|
|
27
|
+
const crypto = require('node:crypto');
|
|
28
|
+
const fs = require('node:fs');
|
|
29
|
+
const path = require('node:path');
|
|
30
|
+
const {layout} = require('./home');
|
|
31
|
+
const {collectStore} = require('./gc');
|
|
32
|
+
// through the module, so a test can stop a rollback part-way at a write
|
|
33
|
+
const moduleRecord = require('./module-record');
|
|
34
|
+
const {readModulesRecord} = moduleRecord;
|
|
35
|
+
const own = (obj, key) => obj != null && Object.prototype.hasOwnProperty.call(obj, key);
|
|
36
|
+
const {writeAtomic} = require('./atomic');
|
|
37
|
+
const {withLock} = require('./lock');
|
|
38
|
+
const {chLocal} = require('./command-line');
|
|
39
|
+
// (taken at load, never after the swap: once the older release is in
|
|
40
|
+
// <home>/app, a require('./x') from this file resolves into that release's
|
|
41
|
+
// lib, which may lack what this one calls -- its `forgetAvailable`, say;
|
|
42
|
+
// C-upgrade-path's test caught it)
|
|
43
|
+
const {alignShim} = require('./shim-install');
|
|
44
|
+
const {updateStamp} = require('./upgrade-stamp');
|
|
45
|
+
const {forgetAvailable} = require('./upgrade');
|
|
46
|
+
const {requestUpgrade} = require('./daemon-requests');
|
|
47
|
+
const {preloadForSwap} = require('./swap-preload');
|
|
48
|
+
|
|
49
|
+
const MARKER = '.ch-local-rollback-newer';
|
|
50
|
+
const versionOf = (r) => (r != null && r.release != null && r.release.version != null ? r.release.version : 'an unnamed release');
|
|
51
|
+
|
|
52
|
+
// Moves done in order; each undone in reverse when a later one fails.
|
|
53
|
+
function swap(where, aside) {
|
|
54
|
+
const moves = [[where.app, path.join(aside, 'app')], [where.previousApp, where.app], [path.join(aside, 'app'), where.previousApp]];
|
|
55
|
+
const done = [];
|
|
56
|
+
for (const [a, b] of moves) {
|
|
57
|
+
try {
|
|
58
|
+
fs.renameSync(a, b);
|
|
59
|
+
done.push([a, b]);
|
|
60
|
+
} catch (err) {
|
|
61
|
+
for (const [x, y] of done.reverse()) {
|
|
62
|
+
try { fs.renameSync(y, x); } catch (e) { return {error: err, stuck: true}; }
|
|
63
|
+
}
|
|
64
|
+
return {error: err, stuck: false};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return {};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Writes both records and clears the journal: the last step of a swap, and
|
|
71
|
+
// of finishing an interrupted one.
|
|
72
|
+
function settle(where, journal, aside) {
|
|
73
|
+
moduleRecord.writeRecordAsIs(where.previousModulesRecord, journal.kept);
|
|
74
|
+
moduleRecord.writeRecordAsIs(where.modulesRecord, journal.restored);
|
|
75
|
+
// the native shim follows the restored release (lib/shim-install.js), by
|
|
76
|
+
// what is on disk: run again when an interrupted rollback is finished, it
|
|
77
|
+
// finds the restored shim in place and moves nothing
|
|
78
|
+
alignShim(where.home, {restored: journal.restored.shim || null});
|
|
79
|
+
// the version rolled back from is declined: the automatic upgrade never
|
|
80
|
+
// installs it again; only a newer one, or ch-local upgrade, does
|
|
81
|
+
// (docs/development/auto-upgrade.md, "Rollback")
|
|
82
|
+
const left = journal.kept != null && journal.kept.runtime != null && journal.kept.runtime.versions != null ? journal.kept.runtime.versions['@countinghouse/ch-local'] : null;
|
|
83
|
+
if (typeof left === 'string') {
|
|
84
|
+
updateStamp(where.home, (s) => { if (!s.declined.includes(left)) s.declined.push(left); });
|
|
85
|
+
}
|
|
86
|
+
for (const dir of [where.app, where.previousApp]) fs.rmSync(path.join(dir, MARKER), {force: true});
|
|
87
|
+
fs.rmSync(where.journal, {force: true});
|
|
88
|
+
try { if (aside != null) fs.rmdirSync(aside); } catch (err) { /* not there, or not empty: left */ }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Whether dir holds this rollback's marker: its content is the journal's
|
|
92
|
+
// time, so a marker an earlier rollback left behind does not count.
|
|
93
|
+
function marked(dir, journal) {
|
|
94
|
+
try { return fs.readFileSync(path.join(dir, MARKER), 'utf8') === journal.at; } catch (err) { return false; }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// An interrupted rollback, finished from what is on disk:
|
|
98
|
+
// -> 'finished' | 'undone' | null (the apps are not where any step leaves
|
|
99
|
+
// them: nothing is changed and the journal stays).
|
|
100
|
+
function finish(where, journal) {
|
|
101
|
+
// (an interrupted rollback finished: the same swap, so the same preload,
|
|
102
|
+
// lib/swap-preload.js)
|
|
103
|
+
preloadForSwap();
|
|
104
|
+
const aside = path.join(where.home, journal.aside);
|
|
105
|
+
const X = fs.existsSync(path.join(aside, 'app'));
|
|
106
|
+
const A = fs.existsSync(where.app);
|
|
107
|
+
const P = fs.existsSync(where.previousApp);
|
|
108
|
+
if (X && !A && P) { fs.renameSync(where.previousApp, where.app); fs.renameSync(path.join(aside, 'app'), where.previousApp); }
|
|
109
|
+
else if (X && A && !P) fs.renameSync(path.join(aside, 'app'), where.previousApp);
|
|
110
|
+
else if (!X && A && P && marked(where.app, journal)) {
|
|
111
|
+
// Nothing had moved: the newer app is still in place.
|
|
112
|
+
fs.rmSync(path.join(where.app, MARKER), {force: true});
|
|
113
|
+
fs.rmSync(where.journal, {force: true});
|
|
114
|
+
try { fs.rmdirSync(aside); } catch (err) { /* left */ }
|
|
115
|
+
return 'undone';
|
|
116
|
+
} else if (!(!X && A && P && marked(where.previousApp, journal))) {
|
|
117
|
+
// Not every move done either (the newer app, marked, is kept): unknown.
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
settle(where, journal, aside);
|
|
121
|
+
return 'finished';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async function rollback({yes = false}, io) {
|
|
125
|
+
const say = (s) => io.stdout.write(s + '\n');
|
|
126
|
+
const fail = (s, code = 1) => { io.stderr.write(`ch-local: ${s}\n`); return code; };
|
|
127
|
+
const where = layout(io.env, io.homedir);
|
|
128
|
+
if (!fs.existsSync(where.home)) return fail('nothing is installed; there is nothing to roll back');
|
|
129
|
+
|
|
130
|
+
const code = await withLock(where, io, async () => {
|
|
131
|
+
// Read inside the lock, so no install or add-pack lands in between.
|
|
132
|
+
if (fs.existsSync(where.journal)) {
|
|
133
|
+
let journal;
|
|
134
|
+
try { journal = JSON.parse(fs.readFileSync(where.journal, 'utf8')); } catch (err) { return fail(`${where.journal} is not readable; restore by hand`); }
|
|
135
|
+
// (a journal names the folder it set aside as previous.<8 hex>, never
|
|
136
|
+
// another path: the reviewer's Fable high on #126, F5)
|
|
137
|
+
if (journal == null || typeof journal.aside !== 'string' || !/^previous\.[0-9a-f]{8}$/.test(journal.aside)) return fail(`${where.journal} names no folder a rollback sets aside; restore by hand`);
|
|
138
|
+
const how = finish(where, journal);
|
|
139
|
+
if (how == null) {
|
|
140
|
+
return fail(`cannot tell how far the interrupted rollback got (${where.app}: ${fs.existsSync(where.app) ? 'present' : 'missing'}, ${where.previousApp}: ${fs.existsSync(where.previousApp) ? 'present' : 'missing'}); nothing changed, and ${where.journal} is kept for restoring by hand`);
|
|
141
|
+
}
|
|
142
|
+
if (how === 'finished') collectStore(where, {alive: io.alive, hostname: io.hostname});
|
|
143
|
+
say(how === 'finished' ? `finished the interrupted rollback to ${versionOf(journal.restored)}` : 'the interrupted rollback had moved nothing; nothing changed');
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
146
|
+
const plain = {...where, journal: null};
|
|
147
|
+
let current;
|
|
148
|
+
try { current = readModulesRecord(plain); } catch (err) { return fail(err.message); }
|
|
149
|
+
if (current == null) return fail('nothing is installed; there is nothing to roll back');
|
|
150
|
+
if (!fs.existsSync(where.app)) return fail(`the current release's programs are missing (${where.app}); install again: nothing was rolled back`);
|
|
151
|
+
// a kept release from before the module store: its record is packs.json,
|
|
152
|
+
// which this release does not read (section 10)
|
|
153
|
+
if (fs.existsSync(where.previousApp) && !fs.existsSync(where.previousModulesRecord) && fs.existsSync(where.previousRecord)) {
|
|
154
|
+
return fail('the kept release predates the module store, so it could not return you here; install it again instead');
|
|
155
|
+
}
|
|
156
|
+
if (!fs.existsSync(where.previousApp) || !fs.existsSync(where.previousModulesRecord)) return fail('no previous release is kept: rollback returns to the release an install replaced');
|
|
157
|
+
let older;
|
|
158
|
+
try { older = readModulesRecord({modulesRecord: where.previousModulesRecord}); } catch (err) { return fail(`the kept release's record: ${err.message}`); }
|
|
159
|
+
if (older == null) return fail('no previous release is kept: rollback returns to the release an install replaced');
|
|
160
|
+
if (older.release == null) return fail('the kept release predates rollback, so it could not return you here; install it again instead');
|
|
161
|
+
|
|
162
|
+
const security = current.release != null ? current.release.security : null;
|
|
163
|
+
const from = versionOf(current);
|
|
164
|
+
const to = versionOf(older);
|
|
165
|
+
if (security != null && !yes) {
|
|
166
|
+
if (io.interactive !== true) return fail(`ch-local ${from} is a security fix (${security.fixes}); without a terminal, rollback needs --yes`);
|
|
167
|
+
const answer = String(await io.ask(`ch-local ${from} is a security fix: ${security.fixes}. Roll back to ${to} anyway? (yes/no) `)).trim().toLowerCase();
|
|
168
|
+
if (answer !== 'yes') { say('nothing changed: only "yes" confirms'); return 1; }
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Packs the restored release does not have: recorded, not loaded. One
|
|
172
|
+
// that release withdrew (kept with it, below) stays held as withdrawn,
|
|
173
|
+
// never as a pack "installed under" this one.
|
|
174
|
+
// (the release returned to keeps its own held packs, as it held them)
|
|
175
|
+
const held = {...(older.held || {})};
|
|
176
|
+
for (const [name, p] of Object.entries(current.held || {})) if (!own(older.packs, name) && !own(held, name)) held[name] = p;
|
|
177
|
+
for (const [name, p] of Object.entries(current.packs)) {
|
|
178
|
+
if (!own(older.packs, name) && !own(held, name)) held[name] = {from: p.from, modules: p.modules};
|
|
179
|
+
}
|
|
180
|
+
const restored = {...older, held};
|
|
181
|
+
// Packs the older release has that the current one no longer does (removed
|
|
182
|
+
// on it): they come back with that release's record, so say so.
|
|
183
|
+
const returning = Object.keys(older.packs).filter((name) => !own(current.packs, name));
|
|
184
|
+
const aside = `previous.${crypto.randomBytes(4).toString('hex')}`;
|
|
185
|
+
// the release left keeps its held packs, withdrawn, relisted or waiting,
|
|
186
|
+
// so a roll forward holds them as it did (and gc keeps their trees)
|
|
187
|
+
const journal = {kept: current, restored, aside, at: new Date().toISOString()};
|
|
188
|
+
|
|
189
|
+
fs.writeFileSync(path.join(where.app, MARKER), journal.at);
|
|
190
|
+
writeAtomic(where.journal, JSON.stringify(journal, null, 2) + '\n');
|
|
191
|
+
const asideDir = path.join(where.home, aside);
|
|
192
|
+
fs.mkdirSync(asideDir);
|
|
193
|
+
// (everything the code after the swap may require, loaded from this
|
|
194
|
+
// release first: lib/swap-preload.js)
|
|
195
|
+
preloadForSwap();
|
|
196
|
+
const moved = swap(where, asideDir);
|
|
197
|
+
if (moved.error != null) {
|
|
198
|
+
if (moved.stuck) return fail(`rollback was interrupted (${moved.error.code || moved.error.message}); run \`${chLocal(where, 'rollback')}\` to finish it`);
|
|
199
|
+
fs.rmSync(path.join(where.app, MARKER), {force: true});
|
|
200
|
+
fs.rmSync(where.journal, {force: true});
|
|
201
|
+
try { fs.rmdirSync(asideDir); } catch (err) { /* left */ }
|
|
202
|
+
return fail(`could not swap the releases (${moved.error.code || moved.error.message}); is a client running it? nothing changed`);
|
|
203
|
+
}
|
|
204
|
+
settle(where, journal, asideDir);
|
|
205
|
+
// both releases' module versions stay (the other is the rollback target
|
|
206
|
+
// now)
|
|
207
|
+
collectStore(where, {alive: io.alive, hostname: io.hostname});
|
|
208
|
+
|
|
209
|
+
say(`rolled back from ch-local ${from} to ${to}: the runtime, packs and parts`);
|
|
210
|
+
// (what upgrade --check found was for the release rolled back from)
|
|
211
|
+
forgetAvailable(where);
|
|
212
|
+
if (security != null) say(`undid the security fix in ch-local ${from} (${security.fixes})`);
|
|
213
|
+
for (const [name, h] of Object.entries(held)) say(`the pack "${name}" needs ch-local ${h.from != null && h.from.release != null ? h.from.release : 'a later release'}; it stays recorded and is not loaded`);
|
|
214
|
+
for (const name of returning) say(`the pack "${name}" comes back with ch-local ${to}; \`${chLocal(where, `remove-pack ${name}`)}\` removes it again`);
|
|
215
|
+
say('caches, usage records, settings and the identity secret are unchanged');
|
|
216
|
+
say(`\`${chLocal(where, 'rollback')}\` again returns to the newer release; if one pack got worse, \`${chLocal(where, 'remove-pack <name>')}\` on the newer release is the way`);
|
|
217
|
+
return 0;
|
|
218
|
+
});
|
|
219
|
+
// a running daemon restarts its runtime, or itself, onto the release now
|
|
220
|
+
// in place (#236 section 6, "Upgrade"). After packs.lock is released,
|
|
221
|
+
// never under it (the review of #35: the daemon holds start.lock and waits
|
|
222
|
+
// on packs.lock). A rollback that changed nothing asks for nothing.
|
|
223
|
+
if (code === 0) await requestUpgrade(where.home, {io});
|
|
224
|
+
return code;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
module.exports = {rollback};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// A running start's heartbeat (its run.json's mtime, refreshed every
|
|
3
|
+
// HEARTBEAT_MS) and the host tag of its run directory: what start writes and
|
|
4
|
+
// collection (lib/gc.js) reads, apart from collection's own code, so start
|
|
5
|
+
// loads nothing of install's.
|
|
6
|
+
const HEARTBEAT_MS = 10 * 60 * 1000;
|
|
7
|
+
const STALE_MS = 3 * HEARTBEAT_MS;
|
|
8
|
+
const hostTag = (hostname) => String(hostname || 'host').replace(/[^A-Za-z0-9.-]/g, '_').slice(0, 64) || 'host';
|
|
9
|
+
// Whether a process on this machine is alive: what every io's `alive` is
|
|
10
|
+
// (bin/ch-local.js, the acceptance and dogfood scripts' own installs).
|
|
11
|
+
// Collection requires it (lib/gc.js), so a home's install never takes a
|
|
12
|
+
// running start for dead. EPERM: alive, another user's.
|
|
13
|
+
const processAlive = (pid) => { try { process.kill(pid, 0); return true; } catch (err) { return err.code === 'EPERM'; } };
|
|
14
|
+
|
|
15
|
+
module.exports = {HEARTBEAT_MS, STALE_MS, hostTag, processAlive};
|