@rocket.chat/houston 0.27.0-next.3 → 2.1.8
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 +1 -1
- package/README.md +108 -15
- package/bin/houston +62 -0
- package/data/docs/ARCHITECTURE.md +387 -0
- package/data/docs/automation.md +107 -0
- package/data/docs/e2ee.md +76 -0
- package/data/docs/eks.md +258 -0
- package/data/docs/gui.md +282 -0
- package/data/docs/guide.md +669 -0
- package/data/docs/kubernetes.md +138 -0
- package/data/docs/troubleshooting.md +193 -0
- package/data/docs/upgrading.md +84 -0
- package/data/docs/voice.md +253 -0
- package/data/iam/engineer-policy.json +11 -0
- package/data/iam/engineer-rbac.yaml +42 -0
- package/data/iam/operator-policy.json +211 -0
- package/data/loadtest/badbot.js +22 -0
- package/data/loadtest/common.js +168 -0
- package/data/loadtest/custom.js +20 -0
- package/data/loadtest/journey.js +58 -0
- package/data/loadtest/login.js +18 -0
- package/data/loadtest/messages.js +13 -0
- package/data/loadtest/mixed.js +39 -0
- package/data/loadtest/read.js +12 -0
- package/data/loadtest/webhook.js +20 -0
- package/data/monitoring/houston-logs.json +98 -0
- package/data/monitoring/k6-loadtest.json +610 -0
- package/data/monitoring/mongodb-exporter.json +3007 -0
- package/data/monitoring/node-exporter-full.json +16114 -0
- package/data/monitoring/rocketchat-metrics.json +6471 -0
- package/data/presets/airgapped.yaml +16 -0
- package/data/presets/default.yaml +9 -0
- package/data/seed/avatar-0.png +0 -0
- package/data/seed/avatar-1.png +0 -0
- package/data/seed/avatar-2.png +0 -0
- package/data/seed/avatar-3.png +0 -0
- package/data/seed/avatar-4.png +0 -0
- package/data/seed/avatar-5.png +0 -0
- package/data/seed/avatar-6.png +0 -0
- package/data/seed/avatar-7.png +0 -0
- package/data/seed/seed-metrics.csv +3 -0
- package/data/seed/seed-preview.png +0 -0
- package/data/seed/seed-report.pdf +32 -0
- package/data/seed/seed-runbook.txt +3 -0
- package/data/skill/SKILL.md +399 -0
- package/data/versions.yaml +55 -0
- package/data/voice/freeswitch/drachtio.xml +52 -0
- package/data/voice/freeswitch/public.xml +87 -0
- package/data/webui/app.css +2003 -0
- package/data/webui/index.html +678 -0
- package/data/webui/js/api.js +561 -0
- package/data/webui/js/boot.js +44 -0
- package/data/webui/js/clusters-tail.js +1377 -0
- package/data/webui/js/clusters.js +896 -0
- package/data/webui/js/create.js +276 -0
- package/data/webui/js/detail.js +507 -0
- package/data/webui/js/jobs.js +636 -0
- package/data/webui/js/logs.js +634 -0
- package/data/webui/js/main.js +14 -0
- package/data/webui/js/options.js +408 -0
- package/data/webui/js/people.js +438 -0
- package/data/webui/js/perf.js +303 -0
- package/data/webui/js/render.js +438 -0
- package/data/webui/js/shared.js +3 -0
- package/data/webui/js/state.js +583 -0
- package/data/webui/js/theme.js +123 -0
- package/data/webui/js/util.js +584 -0
- package/dist/cli/app.js +593 -0
- package/dist/cli/capabilities.js +76 -0
- package/dist/cli/cell-widths.js +495 -0
- package/dist/cli/entry.js +10 -0
- package/dist/cli/error-panel.js +492 -0
- package/dist/cli/handlers/actor.js +84 -0
- package/dist/cli/handlers/https.js +614 -0
- package/dist/cli/handlers/prompt.js +299 -0
- package/dist/cli/handlers/users.js +226 -0
- package/dist/cli/handlers.js +3678 -0
- package/dist/cli/help.js +183 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/perf.js +810 -0
- package/dist/cli/render.js +254 -0
- package/dist/cli/serve.js +858 -0
- package/dist/cli/spec-data.js +2593 -0
- package/dist/cli/spec-types.js +8 -0
- package/dist/cli/usage-error.js +520 -0
- package/dist/cli/wire.js +70 -0
- package/dist/core/audit.js +346 -0
- package/dist/core/backup-compat.js +85 -0
- package/dist/core/backup.js +1639 -0
- package/dist/core/cluster.js +1398 -0
- package/dist/core/configimport.js +344 -0
- package/dist/core/data.js +267 -0
- package/dist/core/database-of.js +82 -0
- package/dist/core/diagnose.js +159 -0
- package/dist/core/doctor.js +1518 -0
- package/dist/core/edge/acme.js +338 -0
- package/dist/core/edge/engine.js +500 -0
- package/dist/core/edge/networks.js +174 -0
- package/dist/core/edge/paths.js +107 -0
- package/dist/core/edge/routes.js +251 -0
- package/dist/core/edge/routeyml.js +195 -0
- package/dist/core/edge/runtime.js +493 -0
- package/dist/core/edge/spec.js +305 -0
- package/dist/core/edge/types.js +202 -0
- package/dist/core/eks-docs.js +135 -0
- package/dist/core/eks.js +2240 -0
- package/dist/core/envvars.js +562 -0
- package/dist/core/eventlog.js +541 -0
- package/dist/core/firstrun.js +153 -0
- package/dist/core/journal.js +691 -0
- package/dist/core/kube/ask.js +231 -0
- package/dist/core/kube/capabilities.js +269 -0
- package/dist/core/kube/certmanager.js +452 -0
- package/dist/core/kube/chart.js +413 -0
- package/dist/core/kube/cluster.js +196 -0
- package/dist/core/kube/context.js +545 -0
- package/dist/core/kube/endpoints.js +448 -0
- package/dist/core/kube/exec.js +195 -0
- package/dist/core/kube/forward.js +732 -0
- package/dist/core/kube/grafana-ingress.js +110 -0
- package/dist/core/kube/ingress.js +218 -0
- package/dist/core/kube/manifests.js +361 -0
- package/dist/core/kube/monitoring.js +768 -0
- package/dist/core/kube/names.js +237 -0
- package/dist/core/kube/namespace.js +678 -0
- package/dist/core/kube/operator.js +941 -0
- package/dist/core/kube/probe.js +202 -0
- package/dist/core/kube/reachability.js +163 -0
- package/dist/core/kube/release.js +439 -0
- package/dist/core/kube/replicaset.js +180 -0
- package/dist/core/kube/scale.js +398 -0
- package/dist/core/kube/status.js +633 -0
- package/dist/core/kube/tools.js +238 -0
- package/dist/core/kube/transfer.js +173 -0
- package/dist/core/kube/workspace.js +423 -0
- package/dist/core/lifecycle/admin.js +64 -0
- package/dist/core/lifecycle/create-docker.js +1533 -0
- package/dist/core/lifecycle/create-k8s.js +939 -0
- package/dist/core/lifecycle/destroy.js +339 -0
- package/dist/core/lifecycle/inspect.js +635 -0
- package/dist/core/lifecycle/naming.js +298 -0
- package/dist/core/lifecycle/notes.js +726 -0
- package/dist/core/lifecycle/ownership.js +313 -0
- package/dist/core/lifecycle/payload.js +401 -0
- package/dist/core/lifecycle/ports.js +388 -0
- package/dist/core/lifecycle/preconditions.js +367 -0
- package/dist/core/lifecycle/pruning.js +551 -0
- package/dist/core/lifecycle/ready.js +753 -0
- package/dist/core/lifecycle/request.js +525 -0
- package/dist/core/lifecycle/seeding.js +281 -0
- package/dist/core/lifecycle/sizing.js +392 -0
- package/dist/core/lifecycle/state.js +286 -0
- package/dist/core/lifecycle/tlsplan.js +704 -0
- package/dist/core/lifecycle/types.js +232 -0
- package/dist/core/loadtest.js +995 -0
- package/dist/core/migrate.js +612 -0
- package/dist/core/monitor.js +494 -0
- package/dist/core/postready.js +969 -0
- package/dist/core/promote.js +804 -0
- package/dist/core/rcapi.js +1285 -0
- package/dist/core/recovery.js +75 -0
- package/dist/core/runner/engine.js +394 -0
- package/dist/core/runner/host.js +298 -0
- package/dist/core/runner/locks.js +129 -0
- package/dist/core/runner/paths.js +173 -0
- package/dist/core/runner/ports.js +172 -0
- package/dist/core/runner/queries.js +612 -0
- package/dist/core/runner/record.js +563 -0
- package/dist/core/scaleseed.js +271 -0
- package/dist/core/seed-db.js +208 -0
- package/dist/core/sessions.js +472 -0
- package/dist/core/skill.js +326 -0
- package/dist/core/sso-identities.js +172 -0
- package/dist/core/sso.js +703 -0
- package/dist/core/tls-local.js +311 -0
- package/dist/core/tls.js +878 -0
- package/dist/core/topology.js +482 -0
- package/dist/core/upgrade.js +868 -0
- package/dist/core/users.js +739 -0
- package/dist/lib/audit.js +100 -0
- package/dist/lib/close-matches.js +238 -0
- package/dist/lib/compose.js +672 -0
- package/dist/lib/config.js +1398 -0
- package/dist/lib/context.js +18 -0
- package/dist/lib/errors.js +305 -0
- package/dist/lib/events.js +208 -0
- package/dist/lib/float-text.js +126 -0
- package/dist/lib/format.js +1320 -0
- package/dist/lib/home.js +325 -0
- package/dist/lib/journal.js +122 -0
- package/dist/lib/json-text.js +733 -0
- package/dist/lib/jsonout.js +382 -0
- package/dist/lib/lock.js +516 -0
- package/dist/lib/login-name.js +202 -0
- package/dist/lib/map-limit.js +29 -0
- package/dist/lib/mkdir-parents.js +90 -0
- package/dist/lib/mongo-kernel.js +67 -0
- package/dist/lib/monitoring.js +492 -0
- package/dist/lib/platform-name.js +59 -0
- package/dist/lib/presets/common.js +390 -0
- package/dist/lib/presets/composite.js +326 -0
- package/dist/lib/presets/e2ee.js +143 -0
- package/dist/lib/presets/email.js +172 -0
- package/dist/lib/presets/guides.js +27 -0
- package/dist/lib/presets/index.js +490 -0
- package/dist/lib/presets/keycloak.js +369 -0
- package/dist/lib/presets/ldap.js +1285 -0
- package/dist/lib/presets/livechat.js +220 -0
- package/dist/lib/presets/multi-instance.js +124 -0
- package/dist/lib/presets/oidc.js +161 -0
- package/dist/lib/presets/public.js +496 -0
- package/dist/lib/presets/registry.js +64 -0
- package/dist/lib/presets/s3-minio.js +300 -0
- package/dist/lib/presets/saml.js +149 -0
- package/dist/lib/presets/scenario.js +51 -0
- package/dist/lib/presets/types.js +86 -0
- package/dist/lib/presets/voice-pbx.js +320 -0
- package/dist/lib/presets/voice.js +345 -0
- package/dist/lib/presets/webhooks.js +182 -0
- package/dist/lib/redact.js +106 -0
- package/dist/lib/seed-options.js +68 -0
- package/dist/lib/seed-profiles.js +59 -0
- package/dist/lib/targz.js +1383 -0
- package/dist/lib/teammode.js +25 -0
- package/dist/lib/tempdir.js +162 -0
- package/dist/lib/unicode-tables.js +2335 -0
- package/dist/lib/version-spec.js +357 -0
- package/dist/lib/versions.js +463 -0
- package/dist/lib/yaml-dump.js +1361 -0
- package/dist/perf/baseline.js +168 -0
- package/dist/perf/constrain.js +296 -0
- package/dist/perf/k6.js +235 -0
- package/dist/perf/mongoprof.js +171 -0
- package/dist/perf/rcmetrics.js +178 -0
- package/dist/perf/report.js +386 -0
- package/dist/perf/resources.js +224 -0
- package/dist/perf/slo.js +111 -0
- package/dist/perf/timeline.js +187 -0
- package/dist/perf/timings.js +85 -0
- package/dist/perf/verdict.js +201 -0
- package/dist/seams/aws-cli.js +126 -0
- package/dist/seams/docker-cli.js +280 -0
- package/dist/seams/exec.js +861 -0
- package/dist/seams/fs/lock.js +528 -0
- package/dist/seams/kubectl.js +83 -0
- package/dist/seams/rc-http.js +921 -0
- package/dist/seed/apply.js +190 -0
- package/dist/seed/assets.js +76 -0
- package/dist/seed/check.js +391 -0
- package/dist/seed/client.js +172 -0
- package/dist/seed/executor.js +726 -0
- package/dist/seed/history.js +281 -0
- package/dist/seed/kinds.js +91 -0
- package/dist/seed/plan.js +432 -0
- package/dist/seed/receipt.js +339 -0
- package/dist/seed/repairs.js +75 -0
- package/dist/seed/verification.js +363 -0
- package/dist/seed/wording.js +248 -0
- package/dist/web/app.js +326 -0
- package/dist/web/jobs.js +510 -0
- package/dist/web/route-deps.js +211 -0
- package/dist/web/route-table.js +213 -0
- package/dist/web/routes/backup.js +244 -0
- package/dist/web/routes/clusters.js +303 -0
- package/dist/web/routes/data.js +187 -0
- package/dist/web/routes/edge.js +82 -0
- package/dist/web/routes/index.js +63 -0
- package/dist/web/routes/jobs.js +95 -0
- package/dist/web/routes/logs.js +297 -0
- package/dist/web/routes/meta.js +191 -0
- package/dist/web/routes/people.js +151 -0
- package/dist/web/routes/perf.js +95 -0
- package/dist/web/routes/repros.js +550 -0
- package/dist/web/routes/session.js +361 -0
- package/dist/web/routes/spa.js +198 -0
- package/dist/web/security.js +475 -0
- package/dist/web/signin.js +246 -0
- package/package.json +67 -32
- package/.eslintrc +0 -94
- package/.swcrc +0 -18
- package/dist/bin.js +0 -3
- package/dist/cli.js +0 -184
- package/dist/commands/createBranch.js +0 -194
- package/dist/outputCI.js +0 -59
- package/src/bin.js +0 -4
- package/src/cli.ts +0 -25
- package/src/commands/createBranch.ts +0 -28
- package/src/outputCI.ts +0 -12
- package/src-old/logs.js +0 -323
- package/src-old/md.js +0 -191
- package/src-old/release-table.js +0 -60
- package/src-old/set-version.js +0 -614
- package/src-old/utils.js +0 -15
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.OPEN_FOR_WRITE = exports.LockUnavailable = exports.LOCK_PLATFORM_MATRIX = exports.HELD_SENTINEL = exports.CONFLICT_EXIT_CODE = exports.requireThisImplementation = exports.conflictReason = exports.claim = exports.readImplementation = exports.markerPath = exports.DUAL_IMPLEMENTATION = exports.THIS_IMPLEMENTATION = exports.MARKER_NAME = void 0;
|
|
37
|
+
exports.platformKey = platformKey;
|
|
38
|
+
exports.flockTool = flockTool;
|
|
39
|
+
exports.resetLockProbe = resetLockProbe;
|
|
40
|
+
exports.lockStatus = lockStatus;
|
|
41
|
+
exports.acquireFileLock = acquireFileLock;
|
|
42
|
+
exports.withFileLock = withFileLock;
|
|
43
|
+
exports.holdsFileLock = holdsFileLock;
|
|
44
|
+
exports.conflictFrom = conflictFrom;
|
|
45
|
+
/**
|
|
46
|
+
* The cross-process lock, and the marker that is the real dual-run safety mechanism.
|
|
47
|
+
*
|
|
48
|
+
* `src/lib/lock.ts` owns the `~/.houston/IMPLEMENTATION` marker and nothing else,
|
|
49
|
+
* because `config.ts` is one of the five lock sites and has to import it. THIS module
|
|
50
|
+
* is the other half: the file lock itself, which needs the process seam and therefore
|
|
51
|
+
* cannot sit underneath `config`. Both halves are re-exported here so a state owner
|
|
52
|
+
* has one import rather than two, and so the marker policy and the lock protocol
|
|
53
|
+
* cannot drift apart.
|
|
54
|
+
*
|
|
55
|
+
* ## Why a child process holds the lock
|
|
56
|
+
*
|
|
57
|
+
* Node has no `flock`. The one native module that would provide it (`fs-ext`) was
|
|
58
|
+
* measured and ruled out: it ships no prebuilt binary for any platform, so it is
|
|
59
|
+
* ABI-pinned to whichever Node compiled it -- NODE_MODULE_VERSION 137 against 147 --
|
|
60
|
+
* which one `node_modules` cannot satisfy for this project's own Node 24 + 26 matrix,
|
|
61
|
+
* and it does not install on a stock musl image at all.
|
|
62
|
+
*
|
|
63
|
+
* What that measurement did NOT consider is that `flock(1)` from util-linux is already on
|
|
64
|
+
* every Linux box, takes a real `flock(2)` on the file, and then `exec`s a command
|
|
65
|
+
* that inherits the locked descriptor. So the lock is taken by a child that holds it
|
|
66
|
+
* for exactly as long as the critical section, and the kernel releases it when that
|
|
67
|
+
* child dies -- including a SIGKILL of this process, because the holder's stdin pipe
|
|
68
|
+
* closes and it exits.
|
|
69
|
+
*
|
|
70
|
+
* MEASURED HERE, both directions, which is the claim this module exists to make:
|
|
71
|
+
*
|
|
72
|
+
* an earlier release holds flock+OFD -> a flock(1) acquirer: BLOCKED (conflict exit)
|
|
73
|
+
* flock(1) holds -> an earlier release's acquirer: BLOCKED (EWOULDBLOCK)
|
|
74
|
+
*
|
|
75
|
+
* ## What is degraded, and where
|
|
76
|
+
*
|
|
77
|
+
* NO OFD LOCK IS TAKEN. Earlier releases take `flock` plus an additive OFD lock because
|
|
78
|
+
* the two do not exclude each other, so a build taking only OFD would walk straight
|
|
79
|
+
* through a `flock` holder. This build takes only `flock`, and that is safe against
|
|
80
|
+
* earlier releases for a reason worth stating rather than assuming: they take BOTH, so
|
|
81
|
+
* whichever one an acquirer takes, it contends. The additive OFD line protects
|
|
82
|
+
* against a third implementation that takes OFD alone -- which this build is not.
|
|
83
|
+
* `LOCK_PLATFORM_MATRIX` says so per platform rather than leaving a reader to infer it.
|
|
84
|
+
*
|
|
85
|
+
* Where `flock(1)` is absent -- macOS and Windows have no such binary -- the tier is
|
|
86
|
+
* `none` and cross-process exclusion degrades to the marker, which is the same
|
|
87
|
+
* degradation earlier releases already accept on Windows. The ordering is deliberate: the
|
|
88
|
+
* marker is the dual-run safety mechanism and the lock is defence in depth.
|
|
89
|
+
*/
|
|
90
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
91
|
+
const fs = __importStar(require("node:fs"));
|
|
92
|
+
const path = __importStar(require("node:path"));
|
|
93
|
+
const node_stream_1 = require("node:stream");
|
|
94
|
+
const errors_1 = require("../../lib/errors");
|
|
95
|
+
const format_1 = require("../../lib/format");
|
|
96
|
+
const exec_1 = require("../exec");
|
|
97
|
+
var lock_1 = require("../../lib/lock");
|
|
98
|
+
Object.defineProperty(exports, "MARKER_NAME", { enumerable: true, get: function () { return lock_1.MARKER_NAME; } });
|
|
99
|
+
Object.defineProperty(exports, "THIS_IMPLEMENTATION", { enumerable: true, get: function () { return lock_1.THIS_IMPLEMENTATION; } });
|
|
100
|
+
Object.defineProperty(exports, "DUAL_IMPLEMENTATION", { enumerable: true, get: function () { return lock_1.DUAL_IMPLEMENTATION; } });
|
|
101
|
+
Object.defineProperty(exports, "markerPath", { enumerable: true, get: function () { return lock_1.markerPath; } });
|
|
102
|
+
Object.defineProperty(exports, "readImplementation", { enumerable: true, get: function () { return lock_1.readImplementation; } });
|
|
103
|
+
Object.defineProperty(exports, "claim", { enumerable: true, get: function () { return lock_1.claim; } });
|
|
104
|
+
Object.defineProperty(exports, "conflictReason", { enumerable: true, get: function () { return lock_1.conflictReason; } });
|
|
105
|
+
Object.defineProperty(exports, "requireThisImplementation", { enumerable: true, get: function () { return lock_1.requireThisImplementation; } });
|
|
106
|
+
/** The exit code `flock(1)` is told to use for "somebody else holds it". */
|
|
107
|
+
exports.CONFLICT_EXIT_CODE = 4;
|
|
108
|
+
/**
|
|
109
|
+
* Written on stdout by the holder AFTER `flock` has taken the lock and `exec`ed it.
|
|
110
|
+
* Seeing it is the only proof of acquisition: `flock` itself says nothing on success.
|
|
111
|
+
*/
|
|
112
|
+
exports.HELD_SENTINEL = 'houston-lock-held';
|
|
113
|
+
/**
|
|
114
|
+
* The holder. It announces the lock, then lives until its stdin closes -- which
|
|
115
|
+
* happens when the owner releases, exits, or is killed. There is no timer on purpose:
|
|
116
|
+
* the pipe closing is the one event that is delivered in every one of those cases,
|
|
117
|
+
* including SIGKILL, where a handler would never run.
|
|
118
|
+
*
|
|
119
|
+
* ONE SIGNAL IS HANDLED, SIGINT, and handled by doing nothing (see `IGNORING_SIGINT`):
|
|
120
|
+
* Node resets an inherited SIG_IGN to the default when it starts, so the holder has to
|
|
121
|
+
* ignore it itself, and it does so BEFORE it announces the lock: the owner treats the
|
|
122
|
+
* sentinel as the lock being held, so a Ctrl-C landing after the announcement and before
|
|
123
|
+
* the handler would have killed the holder and freed a lock its owner believes it has.
|
|
124
|
+
* Every other signal still ends it, as it ends its owner.
|
|
125
|
+
*/
|
|
126
|
+
const HOLDER_SOURCE = "process.on('SIGINT', () => undefined);" +
|
|
127
|
+
`process.stdout.write(${JSON.stringify(`${exports.HELD_SENTINEL}\n`)});` +
|
|
128
|
+
"process.stdin.on('end', () => process.exit(0));" +
|
|
129
|
+
'process.stdin.resume();';
|
|
130
|
+
/**
|
|
131
|
+
* flock(1) with SIGINT IGNORED, which an `exec` keeps: `sh -c 'trap "" INT; exec "$@"'`.
|
|
132
|
+
*
|
|
133
|
+
* A terminal's Ctrl-C reaches its whole foreground process group, flock(1) and the holder
|
|
134
|
+
* included. flock(1) died of the keypress that interrupted its owner, Node closes a child's
|
|
135
|
+
* stdin when the child exits, and the holder's stdin ending released the lock while the
|
|
136
|
+
* owner's unwind still ran under it -- `backup` starting Rocket.Chat again. The lock must
|
|
137
|
+
* be held until the interrupt's unwind leaves the block that took it. Only SIGINT: a group
|
|
138
|
+
* SIGHUP, SIGQUIT or SIGTERM -- a terminal hanging up, `timeout(1)` -- still ends flock(1)
|
|
139
|
+
* and the holder with their owner, where a session of their own left a flock(1) WAITER
|
|
140
|
+
* behind to take the lock up to fifteen minutes later. The owner's own interrupt reaches
|
|
141
|
+
* the wait (`interruptibly` below).
|
|
142
|
+
*/
|
|
143
|
+
const IGNORING_SIGINT = ['/bin/sh', '-c', 'trap "" INT; exec "$@"', 'sh'];
|
|
144
|
+
/**
|
|
145
|
+
* {platform} x {lock tier, cross-implementation exclusion, supported/degraded}.
|
|
146
|
+
*
|
|
147
|
+
* `measured` is part of the row because three platforms behave three ways and only one
|
|
148
|
+
* of them has been run here. A matrix that presents a reasoned row and a measured row
|
|
149
|
+
* identically is a matrix that will be trusted for the wrong one.
|
|
150
|
+
*/
|
|
151
|
+
exports.LOCK_PLATFORM_MATRIX = Object.freeze([
|
|
152
|
+
Object.freeze({
|
|
153
|
+
platform: 'linux-glibc',
|
|
154
|
+
tier: 'flock-cli',
|
|
155
|
+
crossImplementation: 'excluded',
|
|
156
|
+
support: 'supported',
|
|
157
|
+
measured: true,
|
|
158
|
+
note: 'util-linux flock(1) takes flock(2) and execs the holder, which inherits the ' +
|
|
159
|
+
'locked descriptor. Measured against an earlier release holding it, in both directions.',
|
|
160
|
+
}),
|
|
161
|
+
Object.freeze({
|
|
162
|
+
platform: 'linux-musl',
|
|
163
|
+
tier: 'flock-cli',
|
|
164
|
+
crossImplementation: 'excluded',
|
|
165
|
+
support: 'degraded',
|
|
166
|
+
measured: false,
|
|
167
|
+
note: 'BusyBox ships a flock applet with -w but no --conflict-exit-code, so the ' +
|
|
168
|
+
'acquisition sentinel rather than the exit code decides. Not measured here: the ' +
|
|
169
|
+
'musl probe could not reach its own egress.',
|
|
170
|
+
}),
|
|
171
|
+
Object.freeze({
|
|
172
|
+
platform: 'darwin-arm64',
|
|
173
|
+
tier: 'none',
|
|
174
|
+
crossImplementation: 'marker-only',
|
|
175
|
+
support: 'degraded',
|
|
176
|
+
measured: false,
|
|
177
|
+
note: 'macOS ships no flock(1). Cross-process exclusion is the IMPLEMENTATION marker ' +
|
|
178
|
+
'alone, which is what earlier releases already accept on a platform without fcntl.',
|
|
179
|
+
}),
|
|
180
|
+
Object.freeze({
|
|
181
|
+
platform: 'darwin-x64',
|
|
182
|
+
tier: 'none',
|
|
183
|
+
crossImplementation: 'marker-only',
|
|
184
|
+
support: 'degraded',
|
|
185
|
+
measured: false,
|
|
186
|
+
note: 'As darwin-arm64: no flock(1) in the base system.',
|
|
187
|
+
}),
|
|
188
|
+
Object.freeze({
|
|
189
|
+
platform: 'win32',
|
|
190
|
+
tier: 'none',
|
|
191
|
+
crossImplementation: 'marker-only',
|
|
192
|
+
support: 'degraded',
|
|
193
|
+
measured: false,
|
|
194
|
+
note: 'No flock(1) and no fcntl. Earlier releases are thread-only here too, so the two ' +
|
|
195
|
+
'degrade together rather than one of them claiming a guarantee the other lacks.',
|
|
196
|
+
}),
|
|
197
|
+
]);
|
|
198
|
+
/** The matrix key for the machine this process is on. */
|
|
199
|
+
function platformKey() {
|
|
200
|
+
if (process.platform === 'linux')
|
|
201
|
+
return isMusl() ? 'linux-musl' : 'linux-glibc';
|
|
202
|
+
if (process.platform === 'darwin')
|
|
203
|
+
return `darwin-${process.arch}`;
|
|
204
|
+
return process.platform;
|
|
205
|
+
}
|
|
206
|
+
function isMusl() {
|
|
207
|
+
try {
|
|
208
|
+
const report = process.report.getReport();
|
|
209
|
+
return report.header?.glibcVersionRuntime === undefined;
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/** A failure to take the lock, before the public error contract is applied. */
|
|
216
|
+
class LockUnavailable extends Error {
|
|
217
|
+
constructor(layer, path, waitedMs, reason) {
|
|
218
|
+
super(`could not lock ${path} after ${waitedMs} ms: ${reason}`);
|
|
219
|
+
this.name = 'LockUnavailable';
|
|
220
|
+
this.layer = layer;
|
|
221
|
+
this.path = path;
|
|
222
|
+
this.waitedMs = waitedMs;
|
|
223
|
+
this.reason = reason;
|
|
224
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
exports.LockUnavailable = LockUnavailable;
|
|
228
|
+
let probed = null;
|
|
229
|
+
const ABSENT = Object.freeze({
|
|
230
|
+
tier: 'none',
|
|
231
|
+
binary: '',
|
|
232
|
+
conflictExitCode: false,
|
|
233
|
+
raw: '',
|
|
234
|
+
});
|
|
235
|
+
/**
|
|
236
|
+
* The absolute path to a tool on PATH, or "": a `which`, in Node.
|
|
237
|
+
*
|
|
238
|
+
* Resolved here rather than left to the spawn, because "no flock on this box" is the
|
|
239
|
+
* answer on two of the five platforms in the matrix and it should not cost a failed
|
|
240
|
+
* spawn to learn. It also makes the degraded path reachable from a test by setting
|
|
241
|
+
* `process.env.PATH`, which a spawn's own resolution is not: a sandboxed test runner
|
|
242
|
+
* gives each test a COPY of `process.env`, so the real `environ` the child would
|
|
243
|
+
* inherit still names the real PATH.
|
|
244
|
+
*/
|
|
245
|
+
function which(tool) {
|
|
246
|
+
for (const directory of (process.env.PATH ?? '').split(path.delimiter)) {
|
|
247
|
+
if (directory === '')
|
|
248
|
+
continue;
|
|
249
|
+
const candidate = path.join(directory, tool);
|
|
250
|
+
try {
|
|
251
|
+
fs.accessSync(candidate, fs.constants.X_OK);
|
|
252
|
+
return candidate;
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
/* not here, or not executable */
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return '';
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Locate `flock(1)` once per process.
|
|
262
|
+
*
|
|
263
|
+
* Probing per acquisition would spend a spawn on every lock, and the answer cannot
|
|
264
|
+
* change under a running process in any way that matters. `resetLockProbe` exists so a
|
|
265
|
+
* test can force the degraded path without uninstalling the binary.
|
|
266
|
+
*/
|
|
267
|
+
function flockTool() {
|
|
268
|
+
// `unstoppable`: one answer for the whole process. Probed inside a job that was then
|
|
269
|
+
// stopped, the refused `flock --version` read as ABSENT, and every lock after it in this
|
|
270
|
+
// `serve` was in-process only -- no longer excluding a CLI on the same home.
|
|
271
|
+
probed ?? (probed = (0, exec_1.unstoppable)(async () => {
|
|
272
|
+
const binary = which('flock');
|
|
273
|
+
if (binary === '')
|
|
274
|
+
return ABSENT;
|
|
275
|
+
try {
|
|
276
|
+
const result = await (0, exec_1.capture)([binary, '--version'], { encoding: 'utf8', timeoutMs: 5000 });
|
|
277
|
+
const raw = `${result.stdout || ''}${result.stderr || ''}`.trim();
|
|
278
|
+
// BusyBox answers its own usage text on --version and exits non-zero. That is a
|
|
279
|
+
// usable flock; only a binary that does not identify itself at all is not.
|
|
280
|
+
if (result.exitCode !== 0 && !/flock/i.test(raw))
|
|
281
|
+
return ABSENT;
|
|
282
|
+
return {
|
|
283
|
+
tier: 'flock-cli',
|
|
284
|
+
binary,
|
|
285
|
+
conflictExitCode: /util-linux/i.test(raw),
|
|
286
|
+
raw: raw.split('\n')[0] ?? '',
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
// EACCES, or a timeout. Both mean "no usable flock here", which is a degradation
|
|
291
|
+
// rather than a failure -- see the module comment.
|
|
292
|
+
return ABSENT;
|
|
293
|
+
}
|
|
294
|
+
}));
|
|
295
|
+
return probed;
|
|
296
|
+
}
|
|
297
|
+
/** Forget the probed tool. Tests only; production probes once and keeps the answer. */
|
|
298
|
+
function resetLockProbe() {
|
|
299
|
+
probed = null;
|
|
300
|
+
}
|
|
301
|
+
/** What `doctor` prints: this machine's row, plus the whole matrix for context. */
|
|
302
|
+
async function lockStatus() {
|
|
303
|
+
const platform = platformKey();
|
|
304
|
+
const row = exports.LOCK_PLATFORM_MATRIX.find((entry) => entry.platform === platform);
|
|
305
|
+
const tool = await flockTool();
|
|
306
|
+
return {
|
|
307
|
+
platform,
|
|
308
|
+
row,
|
|
309
|
+
tier: tool.tier,
|
|
310
|
+
crossImplementation: tool.tier === 'none' ? 'marker-only' : 'excluded',
|
|
311
|
+
support: tool.tier === 'none' ? 'degraded' : 'supported',
|
|
312
|
+
detail: tool.tier === 'none'
|
|
313
|
+
? 'no flock(1) on PATH: cross-process exclusion is the IMPLEMENTATION marker alone'
|
|
314
|
+
: `${tool.raw}${tool.conflictExitCode ? '' : ' (no --conflict-exit-code; sentinel decides)'}`,
|
|
315
|
+
matrix: exports.LOCK_PLATFORM_MATRIX,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* In-process serialisation, keyed by lock path.
|
|
320
|
+
*
|
|
321
|
+
* A per-name in-process lock sits UNDERNEATH the flock, because flock is per open file
|
|
322
|
+
* DESCRIPTION: two callers in one process that each open the file would both be granted
|
|
323
|
+
* it. Two async callers here would each spawn their own holder, which do exclude each
|
|
324
|
+
* other -- but only by making the second one wait out a real timeout for a conflict this
|
|
325
|
+
* process could have resolved itself.
|
|
326
|
+
*/
|
|
327
|
+
const inProcess = new Map();
|
|
328
|
+
async function enterInProcess(key, timeoutMs) {
|
|
329
|
+
const started = Date.now();
|
|
330
|
+
for (;;) {
|
|
331
|
+
const waiting = inProcess.get(key);
|
|
332
|
+
if (waiting === undefined)
|
|
333
|
+
break;
|
|
334
|
+
const remaining = timeoutMs - (Date.now() - started);
|
|
335
|
+
if (remaining <= 0) {
|
|
336
|
+
throw new LockUnavailable('in-process', key, Date.now() - started, 'held by this process');
|
|
337
|
+
}
|
|
338
|
+
// The seam's sleep, so a job that is stopped while it queues for a busy workspace
|
|
339
|
+
// leaves the queue rather than waiting out the holder.
|
|
340
|
+
await Promise.race([waiting, (0, exec_1.sleep)(Math.min(remaining, 50))]);
|
|
341
|
+
}
|
|
342
|
+
let release;
|
|
343
|
+
inProcess.set(key, new Promise((resolve) => {
|
|
344
|
+
release = resolve;
|
|
345
|
+
}));
|
|
346
|
+
return () => {
|
|
347
|
+
inProcess.delete(key);
|
|
348
|
+
release();
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
/** A plain write-mode open, truncating at 0o666: the workspace, users and sessions locks. */
|
|
352
|
+
exports.OPEN_FOR_WRITE = Object.freeze({ truncate: true, mode: 0o666 });
|
|
353
|
+
/** Open `target` for writing as the lock site always has, raising that open's `FileError`. */
|
|
354
|
+
function openForWrite(target, how) {
|
|
355
|
+
const flags = fs.constants.O_WRONLY | fs.constants.O_CREAT | (how.truncate ? fs.constants.O_TRUNC : 0);
|
|
356
|
+
let fd;
|
|
357
|
+
try {
|
|
358
|
+
fd = fs.openSync(target, flags, how.mode);
|
|
359
|
+
}
|
|
360
|
+
catch (error) {
|
|
361
|
+
throw (0, format_1.fileErrorOf)(error, target);
|
|
362
|
+
}
|
|
363
|
+
fs.closeSync(fd);
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Take an exclusive cross-process lock on `path`, creating it if absent.
|
|
367
|
+
*
|
|
368
|
+
* Returns a handle rather than taking a callback so a state owner can hold the lock
|
|
369
|
+
* across its own write-ahead ordering. `withFileLock` is the ordinary way in.
|
|
370
|
+
*/
|
|
371
|
+
async function acquireFileLock(path, options = {}) {
|
|
372
|
+
const timeoutMs = options.timeoutMs ?? 900000;
|
|
373
|
+
const leaveInProcess = await enterInProcess(path, timeoutMs);
|
|
374
|
+
// After the in-process layer and before the tier, in the established order: the
|
|
375
|
+
// in-process lock comes first, and the file is opened whatever the tier, macOS included.
|
|
376
|
+
if (options.open !== undefined) {
|
|
377
|
+
try {
|
|
378
|
+
openForWrite(path, options.open);
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
leaveInProcess();
|
|
382
|
+
throw error;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
const tool = await flockTool();
|
|
386
|
+
if (tool.tier === 'none') {
|
|
387
|
+
// Degraded exactly as earlier releases degrade without flock: this process is serialised,
|
|
388
|
+
// and a foreign process is stopped by the marker rather than by this.
|
|
389
|
+
return { path, tier: 'none', release: async () => leaveInProcess() };
|
|
390
|
+
}
|
|
391
|
+
const started = Date.now();
|
|
392
|
+
const control = new node_stream_1.PassThrough();
|
|
393
|
+
let acquired = false;
|
|
394
|
+
let seen = '';
|
|
395
|
+
let settle;
|
|
396
|
+
const held = new Promise((resolve, reject) => {
|
|
397
|
+
settle = (error) => {
|
|
398
|
+
if (error !== undefined)
|
|
399
|
+
reject(error);
|
|
400
|
+
else
|
|
401
|
+
resolve();
|
|
402
|
+
};
|
|
403
|
+
});
|
|
404
|
+
const argv = [
|
|
405
|
+
...IGNORING_SIGINT,
|
|
406
|
+
tool.binary,
|
|
407
|
+
'--exclusive',
|
|
408
|
+
'--timeout',
|
|
409
|
+
String(Math.max(0, timeoutMs) / 1000),
|
|
410
|
+
...(tool.conflictExitCode ? ['--conflict-exit-code', String(exports.CONFLICT_EXIT_CODE)] : []),
|
|
411
|
+
path,
|
|
412
|
+
process.execPath,
|
|
413
|
+
'-e',
|
|
414
|
+
HOLDER_SOURCE,
|
|
415
|
+
];
|
|
416
|
+
// CTRL-C WHILE WAITING means the lock was never taken and nothing may go on waiting for
|
|
417
|
+
// it. Here the wait is a flock(1) child, and `process.exit` left it waiting: `down`
|
|
418
|
+
// Ctrl-C'd behind another command's lock exited 130, and its waiter took the lock when
|
|
419
|
+
// the other released it, minutes after the command that wanted it had gone. So the WAIT
|
|
420
|
+
// is what an interrupt takes over -- the waiter is SIGKILLed at once -- and the child is
|
|
421
|
+
// not: once it holds the lock it IS the lock, held until the unwind leaves the block
|
|
422
|
+
// that took it.
|
|
423
|
+
const waiter = new AbortController();
|
|
424
|
+
let finished;
|
|
425
|
+
const start = () => {
|
|
426
|
+
const running = (0, exec_1.stream)(argv, {
|
|
427
|
+
stdin: control,
|
|
428
|
+
encoding: 'utf8',
|
|
429
|
+
interrupt: 'caller',
|
|
430
|
+
abortSignal: waiter.signal,
|
|
431
|
+
abortKillSignal: 'SIGKILL',
|
|
432
|
+
onStdout: (chunk) => {
|
|
433
|
+
seen += typeof chunk === 'string' ? chunk : chunk.toString('utf8');
|
|
434
|
+
if (!acquired && seen.includes(exports.HELD_SENTINEL)) {
|
|
435
|
+
acquired = true;
|
|
436
|
+
settle();
|
|
437
|
+
}
|
|
438
|
+
},
|
|
439
|
+
});
|
|
440
|
+
finished = running.then((result) => {
|
|
441
|
+
if (!acquired) {
|
|
442
|
+
// No sentinel means the lock was never taken. The exit code says why when the
|
|
443
|
+
// tool can spell it; otherwise not seeing the sentinel IS the answer.
|
|
444
|
+
settle(new LockUnavailable('process', path, Date.now() - started, result.exitCode === exports.CONFLICT_EXIT_CODE || !tool.conflictExitCode
|
|
445
|
+
? 'another process holds it'
|
|
446
|
+
: `flock exited ${String(result.exitCode)}: ${String(result.stderr ?? '').trim()}`));
|
|
447
|
+
}
|
|
448
|
+
return result;
|
|
449
|
+
}, (error) => {
|
|
450
|
+
if (!acquired) {
|
|
451
|
+
settle(error instanceof exec_1.SpawnFailure
|
|
452
|
+
? new LockUnavailable('process', path, Date.now() - started, error.message)
|
|
453
|
+
: error);
|
|
454
|
+
}
|
|
455
|
+
throw error;
|
|
456
|
+
});
|
|
457
|
+
// The holder's own failure after acquisition must not surface as an unhandled
|
|
458
|
+
// rejection; `release()` is where it is waited on and reported.
|
|
459
|
+
finished.catch(() => undefined);
|
|
460
|
+
return { done: held, stop: () => waiter.abort() };
|
|
461
|
+
};
|
|
462
|
+
try {
|
|
463
|
+
await (0, exec_1.interruptibly)(start);
|
|
464
|
+
}
|
|
465
|
+
catch (error) {
|
|
466
|
+
control.end();
|
|
467
|
+
await finished?.catch(() => undefined);
|
|
468
|
+
leaveInProcess();
|
|
469
|
+
throw error;
|
|
470
|
+
}
|
|
471
|
+
let released = false;
|
|
472
|
+
return {
|
|
473
|
+
path,
|
|
474
|
+
tier: tool.tier,
|
|
475
|
+
release: async () => {
|
|
476
|
+
if (released)
|
|
477
|
+
return;
|
|
478
|
+
released = true;
|
|
479
|
+
control.end();
|
|
480
|
+
await finished?.catch(() => undefined);
|
|
481
|
+
leaveInProcess();
|
|
482
|
+
},
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
/** Lock names already held by THIS async execution, so a nested take is reentrant. */
|
|
486
|
+
const HELD = new node_async_hooks_1.AsyncLocalStorage();
|
|
487
|
+
/**
|
|
488
|
+
* Run `fn` while holding an exclusive lock on `path`.
|
|
489
|
+
*
|
|
490
|
+
* REENTRANT within one async execution, and that is load-bearing rather than tidy:
|
|
491
|
+
* `restore --new` holds a workspace's lock and then calls `createRepro`, which takes it
|
|
492
|
+
* again. A per-thread depth would track that for threads; an `AsyncLocalStorage` is the
|
|
493
|
+
* same statement about an async call tree, and the nested frame must not re-take
|
|
494
|
+
* the file lock because `flock` self-blocks on a second descriptor exactly as an OFD
|
|
495
|
+
* lock does.
|
|
496
|
+
*/
|
|
497
|
+
async function withFileLock(path, fn, options = {}) {
|
|
498
|
+
const held = HELD.getStore();
|
|
499
|
+
if (held?.has(path) === true)
|
|
500
|
+
return await fn();
|
|
501
|
+
const handle = await acquireFileLock(path, options);
|
|
502
|
+
const nested = new Set(held ?? []);
|
|
503
|
+
nested.add(path);
|
|
504
|
+
try {
|
|
505
|
+
return await HELD.run(nested, async () => await fn());
|
|
506
|
+
}
|
|
507
|
+
finally {
|
|
508
|
+
await handle.release();
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
/** Whether this async execution already holds `path`. For an adapter's own bookkeeping. */
|
|
512
|
+
function holdsFileLock(path) {
|
|
513
|
+
return HELD.getStore()?.has(path) === true;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* The refusal an adapter raises when a lock cannot be taken.
|
|
517
|
+
*
|
|
518
|
+
* The seam reports the failure; the adapter owns the public contract. This helper
|
|
519
|
+
* exists so the two workspace-level sentences `reproLock` raises -- one naming
|
|
520
|
+
* another OPERATION, one naming another PROCESS -- stay one substitution apart
|
|
521
|
+
* instead of being retyped at each call site.
|
|
522
|
+
*/
|
|
523
|
+
function conflictFrom(error, what, timeoutSeconds) {
|
|
524
|
+
const who = error.layer === 'in-process' ? 'operation' : 'process';
|
|
525
|
+
return new errors_1.ConflictError(`another houston ${who} is still working on '${what}' ` +
|
|
526
|
+
`(waited ${String(Math.trunc(timeoutSeconds))}s). Check \`houston list\` and the ` +
|
|
527
|
+
'Activity list, then retry.');
|
|
528
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.kubectl = exports.LAUNCH_FAILURE_CODE = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The one way a Kubernetes tool is launched: `kubectl`, `helm`, `kind`, `eksctl`.
|
|
6
|
+
*
|
|
7
|
+
* Thin, like `docker-cli`: this module knows argv, a timeout and an environment. It
|
|
8
|
+
* knows nothing about contexts, ownership, namespaces or what any of those tools mean.
|
|
9
|
+
* `core/kube/exec.ts` is the half that does, and it is the only module allowed to reach
|
|
10
|
+
* this one -- `.dependency-cruiser.js` carries that as a rule, because "nothing bypasses
|
|
11
|
+
* the seam" is a claim a gate has to make rather than a comment.
|
|
12
|
+
*
|
|
13
|
+
* ## It never throws, and that is this adapter's contract rather than a universal one
|
|
14
|
+
*
|
|
15
|
+
* A preflight that raised on a missing binary or an unreachable API server would have to
|
|
16
|
+
* be wrapped at every call site, and one forgotten wrapper takes down `doctor` -- which is
|
|
17
|
+
* the command someone runs precisely because things are already wrong. So a spawn failure
|
|
18
|
+
* or a timeout becomes a result with `returncode: 127` carrying the reason on stderr, and
|
|
19
|
+
* every caller reads a return code instead of choosing between an exception and a result.
|
|
20
|
+
*
|
|
21
|
+
* `runner.compose` raises for the same class of failure and the TLS adapters translate
|
|
22
|
+
* it into a `ReproError`. Three contracts, deliberately, on one primitive -- see
|
|
23
|
+
* `seams/exec.ts`.
|
|
24
|
+
*
|
|
25
|
+
* ## The result shape is the established one, on purpose
|
|
26
|
+
*
|
|
27
|
+
* `returncode`, `stdout` and `stderr` are the field names every reader was written
|
|
28
|
+
* against. `why()` and every `classify` call read them, and code that renamed them would
|
|
29
|
+
* make every comparison with an earlier release a translation.
|
|
30
|
+
*/
|
|
31
|
+
const exec_1 = require("./exec");
|
|
32
|
+
/**
|
|
33
|
+
* The synthetic code a launch failure reports.
|
|
34
|
+
*
|
|
35
|
+
* 127 is the shell's "command not found", picked so a caller that only reads return codes
|
|
36
|
+
* still sees a distinctly hopeless one rather than a 1 it might confuse with "the object is
|
|
37
|
+
* not there".
|
|
38
|
+
*/
|
|
39
|
+
exports.LAUNCH_FAILURE_CODE = 127;
|
|
40
|
+
async function invoke(argv, options) {
|
|
41
|
+
let result;
|
|
42
|
+
try {
|
|
43
|
+
result = await (0, exec_1.capture)(argv, {
|
|
44
|
+
encoding: 'utf8',
|
|
45
|
+
...(options.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs } : {}),
|
|
46
|
+
...(options.env !== undefined ? { env: options.env } : {}),
|
|
47
|
+
...(options.cwd !== undefined ? { cwd: options.cwd } : {}),
|
|
48
|
+
...(options.input !== undefined ? { input: options.input } : {}),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
// Not a failure to report: Ctrl-C or a stopped job, which must unwind (see exec).
|
|
53
|
+
if (error instanceof exec_1.Interrupted)
|
|
54
|
+
throw error;
|
|
55
|
+
// A launch failure and a timeout both land here. The reason goes on stderr because
|
|
56
|
+
// that is where `why()` looks for it.
|
|
57
|
+
return {
|
|
58
|
+
argv: [...argv],
|
|
59
|
+
returncode: exports.LAUNCH_FAILURE_CODE,
|
|
60
|
+
stdout: '',
|
|
61
|
+
stderr: error instanceof Error ? error.message : String(error),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
argv: result.argv,
|
|
66
|
+
// A signalled tool has no exit code. The established result held a negative number
|
|
67
|
+
// there; the only thing any caller does with it is compare against zero, so a signal is
|
|
68
|
+
// reported as the same hopeless code a failed launch gets rather than as success.
|
|
69
|
+
returncode: result.exitCode ?? exports.LAUNCH_FAILURE_CODE,
|
|
70
|
+
stdout: String(result.stdout ?? ''),
|
|
71
|
+
stderr: String(result.stderr ?? ''),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The injectable callable, on an exported OBJECT rather than as a module binding.
|
|
76
|
+
*
|
|
77
|
+
* A test cannot replace a module-local binding in emitted TypeScript to intercept sibling
|
|
78
|
+
* functions -- swc compiles an export into a non-configurable getter, so `jest.spyOn` on
|
|
79
|
+
* it fails outright. Keeping the callable on one object makes the dependency injectable.
|
|
80
|
+
*/
|
|
81
|
+
exports.kubectl = {
|
|
82
|
+
run: (argv, options = {}) => invoke(argv, options),
|
|
83
|
+
};
|