@celljs/ta-exec 4.7.0 → 4.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/esm/node/exec-peer.js +1 -1
  2. package/esm/node/exec-protocol.d.ts +5 -1
  3. package/esm/node/exec-remote-source.js +2 -2
  4. package/esm/node/local-exec-environment.d.ts +2 -2
  5. package/esm/node/local-exec-environment.js +3 -3
  6. package/esm/node/remote-exec-environment.d.ts +2 -2
  7. package/esm/node/remote-exec-environment.js +2 -2
  8. package/lib/node/exec-peer.js +1 -1
  9. package/lib/node/exec-protocol.d.ts +5 -1
  10. package/lib/node/exec-remote-source.js +2 -2
  11. package/lib/node/local-exec-environment.d.ts +2 -2
  12. package/lib/node/local-exec-environment.js +2 -2
  13. package/lib/node/remote-exec-environment.d.ts +2 -2
  14. package/lib/node/remote-exec-environment.js +2 -2
  15. package/package.json +4 -3
  16. package/esm/node/exec-client.js.map +0 -1
  17. package/esm/node/exec-peer.js.map +0 -1
  18. package/esm/node/exec-protocol.js.map +0 -1
  19. package/esm/node/exec-remote-source.js.map +0 -1
  20. package/esm/node/exec-rpc.js.map +0 -1
  21. package/esm/node/exec-server.js.map +0 -1
  22. package/esm/node/exec-stdio.js.map +0 -1
  23. package/esm/node/index.js.map +0 -1
  24. package/esm/node/local-exec-environment.js.map +0 -1
  25. package/esm/node/remote-exec-environment.js.map +0 -1
  26. package/esm/node/ssh/node-dist.js.map +0 -1
  27. package/esm/node/ssh/ssh-askpass.js.map +0 -1
  28. package/esm/node/ssh/ssh-config.js.map +0 -1
  29. package/esm/node/ssh/ssh-host.js.map +0 -1
  30. package/esm/node/ssh/ssh-util.js.map +0 -1
  31. package/lib/node/exec-client.d.ts.map +0 -1
  32. package/lib/node/exec-client.js.map +0 -1
  33. package/lib/node/exec-peer.d.ts.map +0 -1
  34. package/lib/node/exec-peer.js.map +0 -1
  35. package/lib/node/exec-protocol.d.ts.map +0 -1
  36. package/lib/node/exec-protocol.js.map +0 -1
  37. package/lib/node/exec-remote-source.d.ts.map +0 -1
  38. package/lib/node/exec-remote-source.js.map +0 -1
  39. package/lib/node/exec-rpc.d.ts.map +0 -1
  40. package/lib/node/exec-rpc.js.map +0 -1
  41. package/lib/node/exec-server.d.ts.map +0 -1
  42. package/lib/node/exec-server.js.map +0 -1
  43. package/lib/node/exec-server.spec.d.ts +0 -2
  44. package/lib/node/exec-server.spec.d.ts.map +0 -1
  45. package/lib/node/exec-server.spec.js +0 -101
  46. package/lib/node/exec-server.spec.js.map +0 -1
  47. package/lib/node/exec-stdio.d.ts.map +0 -1
  48. package/lib/node/exec-stdio.js.map +0 -1
  49. package/lib/node/exec-stdio.spec.d.ts +0 -2
  50. package/lib/node/exec-stdio.spec.d.ts.map +0 -1
  51. package/lib/node/exec-stdio.spec.js +0 -105
  52. package/lib/node/exec-stdio.spec.js.map +0 -1
  53. package/lib/node/index.d.ts.map +0 -1
  54. package/lib/node/index.js.map +0 -1
  55. package/lib/node/local-exec-environment.d.ts.map +0 -1
  56. package/lib/node/local-exec-environment.js.map +0 -1
  57. package/lib/node/local-exec-environment.spec.d.ts +0 -2
  58. package/lib/node/local-exec-environment.spec.d.ts.map +0 -1
  59. package/lib/node/local-exec-environment.spec.js +0 -55
  60. package/lib/node/local-exec-environment.spec.js.map +0 -1
  61. package/lib/node/remote-exec-environment.d.ts.map +0 -1
  62. package/lib/node/remote-exec-environment.js.map +0 -1
  63. package/lib/node/ssh/node-dist.d.ts.map +0 -1
  64. package/lib/node/ssh/node-dist.js.map +0 -1
  65. package/lib/node/ssh/ssh-askpass.d.ts.map +0 -1
  66. package/lib/node/ssh/ssh-askpass.js.map +0 -1
  67. package/lib/node/ssh/ssh-config.d.ts.map +0 -1
  68. package/lib/node/ssh/ssh-config.js.map +0 -1
  69. package/lib/node/ssh/ssh-host.d.ts.map +0 -1
  70. package/lib/node/ssh/ssh-host.js.map +0 -1
  71. package/lib/node/ssh/ssh-host.spec.d.ts +0 -2
  72. package/lib/node/ssh/ssh-host.spec.d.ts.map +0 -1
  73. package/lib/node/ssh/ssh-host.spec.js +0 -182
  74. package/lib/node/ssh/ssh-host.spec.js.map +0 -1
  75. package/lib/node/ssh/ssh-util.d.ts.map +0 -1
  76. package/lib/node/ssh/ssh-util.js.map +0 -1
  77. package/lib/node/ssh/ssh-util.spec.d.ts +0 -2
  78. package/lib/node/ssh/ssh-util.spec.d.ts.map +0 -1
  79. package/lib/node/ssh/ssh-util.spec.js +0 -87
  80. package/lib/node/ssh/ssh-util.spec.js.map +0 -1
  81. package/src/node/exec-client.ts +0 -221
  82. package/src/node/exec-peer.ts +0 -186
  83. package/src/node/exec-protocol.ts +0 -84
  84. package/src/node/exec-remote-source.ts +0 -7
  85. package/src/node/exec-rpc.ts +0 -124
  86. package/src/node/exec-server.spec.ts +0 -110
  87. package/src/node/exec-server.ts +0 -107
  88. package/src/node/exec-stdio.spec.ts +0 -107
  89. package/src/node/exec-stdio.ts +0 -75
  90. package/src/node/index.ts +0 -14
  91. package/src/node/local-exec-environment.spec.ts +0 -58
  92. package/src/node/local-exec-environment.ts +0 -112
  93. package/src/node/remote-exec-environment.ts +0 -162
  94. package/src/node/ssh/node-dist.ts +0 -83
  95. package/src/node/ssh/ssh-askpass.ts +0 -117
  96. package/src/node/ssh/ssh-config.ts +0 -128
  97. package/src/node/ssh/ssh-host.spec.ts +0 -189
  98. package/src/node/ssh/ssh-host.ts +0 -300
  99. package/src/node/ssh/ssh-util.spec.ts +0 -97
  100. package/src/node/ssh/ssh-util.ts +0 -127
@@ -1,182 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const bun_test_1 = require("bun:test");
4
- const node_child_process_1 = require("node:child_process");
5
- const node_crypto_1 = require("node:crypto");
6
- const node_fs_1 = require("node:fs");
7
- const node_http_1 = require("node:http");
8
- const node_os_1 = require("node:os");
9
- const node_path_1 = require("node:path");
10
- const remote_exec_environment_1 = require("../remote-exec-environment");
11
- const ssh_host_1 = require("./ssh-host");
12
- const ssh_util_1 = require("./ssh-util");
13
- /**
14
- * An ssh that runs the command on this machine, as ssh would on the host: in the home directory of the
15
- * test, with a PATH of the test. Its master is a process that waits; it asks for a password through
16
- * SSH_ASKPASS when FAKE_SSH_PASSWORD is set.
17
- */
18
- const FAKE_SSH = `#!/bin/sh
19
- echo "$*" >> "$FAKE_SSH_DIR/log"
20
- master=0; control=
21
- while [ $# -gt 0 ]; do
22
- case "$1" in
23
- --) shift; break;;
24
- -N) master=1; shift;;
25
- -T) shift;;
26
- -O) control="$2"; shift 2;;
27
- -o|-F|-p|-i|-l) shift 2;;
28
- *) shift;;
29
- esac
30
- done
31
- shift
32
- if [ -n "$control" ]; then [ -f "$FAKE_SSH_DIR/master" ]; exit $?; fi
33
- if [ "$master" = 1 ]; then
34
- if [ -n "$FAKE_SSH_PASSWORD" ]; then
35
- answer=$("$SSH_ASKPASS" "fake's password: ") || { echo "Permission denied (cancelled)." >&2; exit 255; }
36
- [ "$answer" = "$FAKE_SSH_PASSWORD" ] || { echo "Permission denied (password)." >&2; exit 255; }
37
- fi
38
- touch "$FAKE_SSH_DIR/master"
39
- trap 'rm -f "$FAKE_SSH_DIR/master"; exit 0' TERM INT
40
- while :; do sleep 1 & wait $!; done
41
- fi
42
- [ -f "$FAKE_SSH_DIR/master" ] || { echo "no master" >&2; exit 255; }
43
- cmd=$(printf '%s' "$*" | sed -e 's#/opt/homebrew/bin/node#/none#g' -e 's#/usr/local/bin/node#/none#g')
44
- HOME="$FAKE_SSH_HOME" PATH="$FAKE_SSH_PATH" SHELL="$FAKE_SSH_DIR/login-sh" exec /bin/sh -c "$cmd"
45
- `;
46
- /**
47
- * The login shell of the host, with the PATH of the test: a real one reads /etc/profile, whose PATH on
48
- * macOS has /usr/local/bin, where the runners of CI have a Node.js.
49
- */
50
- const LOGIN_SH = `#!/bin/sh
51
- [ "$1" = -lc ] && shift && set -- -c "$@"
52
- exec /bin/sh "$@"
53
- `;
54
- const which = (name) => (0, node_child_process_1.execFileSync)('/bin/sh', ['-c', `command -v ${name} || true`])
55
- .toString()
56
- .trim();
57
- const node = which('node');
58
- bun_test_1.describe.skipIf(process.platform === 'win32' || !node)('SshHost', () => {
59
- const root = (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'ta-ssh-host-'));
60
- const ssh = (0, node_path_1.join)(root, 'ssh');
61
- /** A PATH with the tools the scripts use, and no Node.js. */
62
- const bare = (0, node_path_1.join)(root, 'bin');
63
- const hosts = [];
64
- let mirror;
65
- let mirrorUrl;
66
- const steps = [];
67
- const host = (options = {}) => {
68
- const created = new ssh_host_1.SshHost({ host: 'fake', stateDir: (0, node_path_1.join)(root, 'state'), ssh, onStep: step => steps.push(step), nodeMirror: mirrorUrl, ...options });
69
- hosts.push(created);
70
- return created;
71
- };
72
- const remote = (name, path) => {
73
- const home = (0, node_path_1.join)(root, name);
74
- (0, node_fs_1.mkdirSync)(home, { recursive: true });
75
- process.env.FAKE_SSH_HOME = home;
76
- process.env.FAKE_SSH_PATH = path;
77
- return home;
78
- };
79
- (0, bun_test_1.beforeAll)(async () => {
80
- (0, node_fs_1.writeFileSync)(ssh, FAKE_SSH, { mode: 0o755 });
81
- (0, node_fs_1.writeFileSync)((0, node_path_1.join)(root, 'login-sh'), LOGIN_SH, { mode: 0o755 });
82
- process.env.FAKE_SSH_DIR = root;
83
- (0, node_fs_1.mkdirSync)(bare);
84
- for (const tool of ['sh', 'uname', 'tar', 'gzip', 'cat', 'mkdir', 'mv', 'rm', 'dirname', 'tail', 'ls', 'sleep', 'sed']) {
85
- (0, node_fs_1.symlinkSync)(which(tool), (0, node_path_1.join)(bare, tool));
86
- }
87
- // A mirror of nodejs.org with one build, for this machine, whose node runs the real one.
88
- const platform = ssh_util_1.SshUtil.nodePlatform((0, node_child_process_1.execFileSync)('uname', ['-s']).toString().trim(), (0, node_child_process_1.execFileSync)('uname', ['-m']).toString().trim());
89
- const name = `node-v22.99.0-${platform}`;
90
- (0, node_fs_1.mkdirSync)((0, node_path_1.join)(root, 'dist', name, 'bin'), { recursive: true });
91
- (0, node_fs_1.writeFileSync)((0, node_path_1.join)(root, 'dist', name, 'bin', 'node'), `#!/bin/sh\nexec "${node}" "$@"\n`, { mode: 0o755 });
92
- (0, node_child_process_1.execFileSync)('tar', ['-czf', `${name}.tar.gz`, name], { cwd: (0, node_path_1.join)(root, 'dist') });
93
- const tarball = (0, node_fs_1.readFileSync)((0, node_path_1.join)(root, 'dist', `${name}.tar.gz`));
94
- const sums = `${(0, node_crypto_1.createHash)('sha256').update(tarball).digest('hex')} ${name}.tar.gz\n`;
95
- mirror = (0, node_http_1.createServer)((request, response) => {
96
- if (request.url === '/latest-v22.x/SHASUMS256.txt') {
97
- response.end(sums);
98
- }
99
- else if (request.url === `/latest-v22.x/${name}.tar.gz`) {
100
- response.end(tarball);
101
- }
102
- else {
103
- response.writeHead(404).end();
104
- }
105
- });
106
- await new Promise(resolve => mirror.listen(0, '127.0.0.1', resolve));
107
- mirrorUrl = `http://127.0.0.1:${mirror.address().port}`;
108
- });
109
- (0, bun_test_1.afterAll)(async () => {
110
- await Promise.all(hosts.map(created => created.dispose()));
111
- mirror.close();
112
- delete process.env.FAKE_SSH_PASSWORD;
113
- });
114
- (0, bun_test_1.it)('copies its server once, and runs commands there with the Node.js of the host', async () => {
115
- var _a;
116
- const home = remote('with-node', `${(0, node_path_1.join)(node, '..')}:/usr/bin:/bin`);
117
- steps.length = 0;
118
- const first = host();
119
- const env = new remote_exec_environment_1.RemoteExecEnvironment(first.client, home);
120
- const chunks = [];
121
- (0, bun_test_1.expect)((await env.exec('pwd; echo "$HOME"', { onData: data => chunks.push(data) })).exitCode).toBe(0);
122
- (0, bun_test_1.expect)(Buffer.concat(chunks).toString()).toBe(`${home}\n${home}\n`);
123
- (0, bun_test_1.expect)(steps).toEqual(['connecting', 'checking', 'copying-server', 'starting']);
124
- (0, bun_test_1.expect)((await first.client.info()).cwd).toBe((0, node_fs_1.realpathSync)(home));
125
- await first.dispose();
126
- (0, bun_test_1.expect)((0, node_fs_1.existsSync)((0, node_path_1.join)(root, 'master'))).toBe(false);
127
- steps.length = 0;
128
- const second = host();
129
- (0, bun_test_1.expect)((_a = (await new remote_exec_environment_1.RemoteExecEnvironment(second.client, home).stat('.'))) === null || _a === void 0 ? void 0 : _a.isDirectory).toBe(true);
130
- (0, bun_test_1.expect)(steps).toEqual(['connecting', 'checking', 'starting']);
131
- await second.dispose();
132
- });
133
- (0, bun_test_1.it)('installs Node.js on a host without one, from the mirror, checked', async () => {
134
- const home = remote('without-node', bare);
135
- steps.length = 0;
136
- const created = host();
137
- const env = new remote_exec_environment_1.RemoteExecEnvironment(created.client, home);
138
- (0, bun_test_1.expect)((await env.exec('true')).exitCode).toBe(0);
139
- (0, bun_test_1.expect)(steps).toEqual(['connecting', 'checking', 'installing-node', 'installing-node', 'copying-server', 'starting']);
140
- (0, bun_test_1.expect)((0, node_fs_1.existsSync)((0, node_path_1.join)(home, '.ta/server/node/bin/node'))).toBe(true);
141
- await created.dispose();
142
- });
143
- (0, bun_test_1.it)('asks for the password through Ta, and fails with what ssh said when it is wrong', async () => {
144
- remote('password', `${(0, node_path_1.join)(node, '..')}:/usr/bin:/bin`);
145
- process.env.FAKE_SSH_PASSWORD = 's3cret';
146
- try {
147
- const questions = [];
148
- const right = host({
149
- ask: async (question) => {
150
- questions.push(`${question.kind}:${question.message}`);
151
- return 's3cret';
152
- },
153
- });
154
- await right.client.info();
155
- (0, bun_test_1.expect)(questions).toEqual(["secret:fake's password:"]);
156
- await right.dispose();
157
- const wrong = host({ ask: async () => 'nope' });
158
- await (0, bun_test_1.expect)(wrong.client.info()).rejects.toThrow('Permission denied (password).');
159
- const cancelled = host({ ask: async () => undefined });
160
- await (0, bun_test_1.expect)(cancelled.client.info()).rejects.toThrow('Permission denied (cancelled).');
161
- }
162
- finally {
163
- delete process.env.FAKE_SSH_PASSWORD;
164
- }
165
- });
166
- (0, bun_test_1.it)('says the connection was lost when ssh ends', async () => {
167
- const home = remote('lost', `${(0, node_path_1.join)(node, '..')}:/usr/bin:/bin`);
168
- const created = host();
169
- const env = new remote_exec_environment_1.RemoteExecEnvironment(created.client, home);
170
- // Connected first: a first connection can take longer than the wait below, and then there would be
171
- // no server to end yet.
172
- await created.client.info();
173
- const running = env.exec('sleep 30');
174
- await new Promise(resolve => setTimeout(resolve, 300));
175
- // Not through a shell, whose command line would match too.
176
- (0, node_child_process_1.spawnSync)('pkill', ['-f', `${home}/.ta/server`]);
177
- await (0, bun_test_1.expect)(running).rejects.toThrow(/lost/);
178
- (0, bun_test_1.expect)(created.client.connected).toBe(false);
179
- (0, bun_test_1.expect)((await env.exec('true')).exitCode).toBe(0);
180
- });
181
- });
182
- //# sourceMappingURL=ssh-host.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ssh-host.spec.js","sourceRoot":"","sources":["../../../src/node/ssh/ssh-host.spec.ts"],"names":[],"mappings":";;AAAA,uCAAqE;AACrE,2DAA6D;AAC7D,6CAAyC;AACzC,qCAAqH;AACrH,yCAAsD;AACtD,qCAAiC;AACjC,yCAAiC;AACjC,wEAAmE;AACnE,yCAAwE;AACxE,yCAAqC;AAErC;;;;GAIG;AACH,MAAM,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BhB,CAAC;AAEF;;;GAGG;AACH,MAAM,QAAQ,GAAG;;;CAGhB,CAAC;AAEF,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,CAC3B,IAAA,iCAAY,EAAC,SAAS,EAAE,CAAC,IAAI,EAAE,cAAc,IAAI,UAAU,CAAC,CAAC;KACxD,QAAQ,EAAE;KACV,IAAI,EAAE,CAAC;AAChB,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;AAE3B,mBAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,GAAG,EA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AC;QACvB,IAAI,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,KAAK,QAAQ,IAAI,GAAG,KAAK,KAAK,IAAI,GAAG,KAAK,OAAO,CAAC,EAAE,CAAC;YAC/E,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,OAAO,GAAG,MAAM,IAAI,GAAG,EAAE,CAAC;IAC9B,CAAC;IAjBe,QAAA,YAAY,eAiB3B,CAAA;AACL,CAAC,EA1GgB,OAAO,aAAP,OAAO,GAAP,OAAO,QA0GvB"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=ssh-util.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ssh-util.spec.d.ts","sourceRoot":"","sources":["../../../src/node/ssh/ssh-util.spec.ts"],"names":[],"mappings":""}
@@ -1,87 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const bun_test_1 = require("bun:test");
4
- const node_child_process_1 = require("node:child_process");
5
- const node_fs_1 = require("node:fs");
6
- const node_os_1 = require("node:os");
7
- const node_path_1 = require("node:path");
8
- const node_dist_1 = require("./node-dist");
9
- const ssh_config_1 = require("./ssh-config");
10
- const ssh_util_1 = require("./ssh-util");
11
- (0, bun_test_1.describe)('SshUtil', () => {
12
- (0, bun_test_1.it)('quotes an argument for the shell of the host', () => {
13
- const value = `it's "$HOME" & more`;
14
- (0, bun_test_1.expect)((0, node_child_process_1.execFileSync)('/bin/sh', ['-c', `printf %s ${ssh_util_1.SshUtil.quote(value)}`]).toString()).toBe(value);
15
- });
16
- (0, bun_test_1.it)('runs a script with its arguments in sh, whatever the remote shell', () => {
17
- const command = ssh_util_1.SshUtil.remoteCommand('printf "%s|%s" "$1" "$2"', 'a b', `c'd`);
18
- (0, bun_test_1.expect)((0, node_child_process_1.execFileSync)('/bin/sh', ['-c', command]).toString()).toBe(`a b|c'd`);
19
- });
20
- (0, bun_test_1.it)('gives ssh a URL for a host with a port', () => {
21
- (0, bun_test_1.expect)(ssh_util_1.SshUtil.destination('dev')).toBe('dev');
22
- (0, bun_test_1.expect)(ssh_util_1.SshUtil.destination('me@dev.example.com')).toBe('me@dev.example.com');
23
- (0, bun_test_1.expect)(ssh_util_1.SshUtil.destination('me@10.0.0.2:2222')).toBe('ssh://me@10.0.0.2:2222');
24
- (0, bun_test_1.expect)(ssh_util_1.SshUtil.destination('[::1]:22')).toBe('ssh://[::1]:22');
25
- });
26
- (0, bun_test_1.it)('tells what kind of answer ssh asks for', () => {
27
- (0, bun_test_1.expect)(ssh_util_1.SshUtil.question("me@dev's password: ").kind).toBe('secret');
28
- (0, bun_test_1.expect)(ssh_util_1.SshUtil.question("Enter passphrase for key '/home/me/.ssh/id_ed25519': ").kind).toBe('secret');
29
- (0, bun_test_1.expect)(ssh_util_1.SshUtil.question('Are you sure you want to continue connecting (yes/no/[fingerprint])? ').kind).toBe('confirm');
30
- (0, bun_test_1.expect)(ssh_util_1.SshUtil.question('Verification code: ').kind).toBe('secret');
31
- });
32
- (0, bun_test_1.it)('reads what the probe prints, past what else a shell printed', () => {
33
- const home = (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'ta-probe-'));
34
- const output = (0, node_child_process_1.execFileSync)('/bin/sh', ['-c', ssh_util_1.SshUtil.probeScript('0123456789abcdef')], { env: { ...process.env, HOME: home } }).toString();
35
- const probe = ssh_util_1.SshUtil.parseProbe(`Last login: today\n${output}`);
36
- (0, bun_test_1.expect)(probe).toMatchObject({ home, server: false, musl: false });
37
- (0, bun_test_1.expect)(probe === null || probe === void 0 ? void 0 : probe.os).toBe((0, node_child_process_1.execFileSync)('uname', ['-s']).toString().trim());
38
- (0, bun_test_1.expect)(ssh_util_1.SshUtil.parseProbe('bash: sh: command not found')).toBeUndefined();
39
- });
40
- (0, bun_test_1.it)('names the build of Node.js of a host', () => {
41
- (0, bun_test_1.expect)(ssh_util_1.SshUtil.nodePlatform('Linux', 'x86_64')).toBe('linux-x64');
42
- (0, bun_test_1.expect)(ssh_util_1.SshUtil.nodePlatform('Linux', 'aarch64')).toBe('linux-arm64');
43
- (0, bun_test_1.expect)(ssh_util_1.SshUtil.nodePlatform('Darwin', 'arm64')).toBe('darwin-arm64');
44
- (0, bun_test_1.expect)(ssh_util_1.SshUtil.nodePlatform('FreeBSD', 'amd64')).toBeUndefined();
45
- });
46
- });
47
- (0, bun_test_1.describe)('NodeDist', () => {
48
- (0, bun_test_1.it)('finds the tarball of a platform in the sums', () => {
49
- const sums = [
50
- `${'a'.repeat(64)} node-v22.9.0-darwin-arm64.tar.gz`,
51
- `${'b'.repeat(64)} node-v22.9.0-linux-arm64.tar.xz`,
52
- `${'c'.repeat(64)} node-v22.9.0-linux-arm64.tar.gz`,
53
- ].join('\n');
54
- (0, bun_test_1.expect)(node_dist_1.NodeDist.find(sums, 'linux-arm64')).toEqual({ sha256: 'c'.repeat(64), name: 'node-v22.9.0-linux-arm64.tar.gz', version: 'v22.9.0' });
55
- (0, bun_test_1.expect)(node_dist_1.NodeDist.find(sums, 'linux-x64')).toBeUndefined();
56
- });
57
- });
58
- (0, bun_test_1.describe)('SshConfig', () => {
59
- (0, bun_test_1.it)('reads Host, Match and Include lines', () => {
60
- (0, bun_test_1.expect)(ssh_config_1.SshConfig.parse('Host dev prod *.example.com !bad\n HostName 10.0.0.1\nhost="quoted"\nMatch all\nInclude conf.d/*')).toEqual([
61
- { host: ['dev', 'prod', '*.example.com', '!bad'] },
62
- { host: ['quoted'] },
63
- { match: true },
64
- { include: 'conf.d/*' },
65
- ]);
66
- });
67
- (0, bun_test_1.it)('matches hosts as ssh does', () => {
68
- (0, bun_test_1.expect)(ssh_config_1.SshConfig.matches(['*.example.com'], 'a.example.com')).toBe(true);
69
- (0, bun_test_1.expect)(ssh_config_1.SshConfig.matches(['*.example.com'], 'colima')).toBe(false);
70
- (0, bun_test_1.expect)(ssh_config_1.SshConfig.matches(['*', '!bad'], 'bad')).toBe(false);
71
- (0, bun_test_1.expect)(ssh_config_1.SshConfig.matches(['dev?'], 'dev1')).toBe(true);
72
- });
73
- (0, bun_test_1.it)('lists the hosts without wildcards, with those of files included where ssh reads them', () => {
74
- const dir = (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'ta-ssh-config-'));
75
- (0, node_fs_1.mkdirSync)((0, node_path_1.join)(dir, 'conf.d'));
76
- (0, node_fs_1.writeFileSync)((0, node_path_1.join)(dir, 'config'), 'Include top.conf\nHost a\nInclude conf.d/*.conf\nHost b *.corp\n\nInclude corp.conf\nMatch all\nInclude never.conf\n');
77
- (0, node_fs_1.writeFileSync)((0, node_path_1.join)(dir, 'top.conf'), 'Host t\n');
78
- (0, node_fs_1.writeFileSync)((0, node_path_1.join)(dir, 'conf.d', 'x.conf'), 'Host c a\n');
79
- (0, node_fs_1.writeFileSync)((0, node_path_1.join)(dir, 'conf.d', 'y.txt'), 'Host d\n');
80
- // Read only for b and the hosts of *.corp: its other hosts are not reachable by their names.
81
- (0, node_fs_1.writeFileSync)((0, node_path_1.join)(dir, 'corp.conf'), 'Host colima x.corp\n');
82
- (0, node_fs_1.writeFileSync)((0, node_path_1.join)(dir, 'never.conf'), 'Host n\n');
83
- (0, bun_test_1.expect)(ssh_config_1.SshConfig.hosts((0, node_path_1.join)(dir, 'config'))).toEqual(['t', 'a', 'b', 'x.corp']);
84
- (0, bun_test_1.expect)(ssh_config_1.SshConfig.hosts((0, node_path_1.join)(dir, 'missing'))).toEqual([]);
85
- });
86
- });
87
- //# sourceMappingURL=ssh-util.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ssh-util.spec.js","sourceRoot":"","sources":["../../../src/node/ssh/ssh-util.spec.ts"],"names":[],"mappings":";;AAAA,uCAAgD;AAChD,2DAAkD;AAClD,qCAAgE;AAChE,qCAAiC;AACjC,yCAAiC;AACjC,2CAAuC;AACvC,6CAAyC;AACzC,yCAAqC;AAErC,IAAA,mBAAQ,EAAC,SAAS,EAAE,GAAG,EAA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AC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -1,221 +0,0 @@
1
- import { ExecRpc } from './exec-rpc';
2
-
3
- /** One connection to `ta exec-server`, whatever carries it: a WebSocket, or ssh (SshHost). */
4
- export interface ExecConnection {
5
- send(text: string): void;
6
- close(): void;
7
- onMessage(listener: (text: string) => void): void;
8
- /** Once, with what went wrong when it was not closed on purpose. */
9
- onClose(listener: (reason?: string) => void): void;
10
- }
11
-
12
- export interface ExecClientOptions {
13
- /** Opens a connection; rejects with an ExecError when it cannot. See {@link ExecClient.webSocket}. */
14
- connect(): Promise<ExecConnection>;
15
- /** Larger than the epoch of any host that ran these sessions before; see {@link ExecRpc.InitializeParams}. */
16
- epoch: number;
17
- /** Pings this often (milliseconds) while connected, for a server that ends without them (over stdio). */
18
- pingMs?: number;
19
- }
20
-
21
- /** A failed call to `ta exec-server`. */
22
- export class ExecError extends Error {
23
- constructor(
24
- message: string,
25
- readonly code: ExecRpc.ErrorCode,
26
- ) {
27
- super(message);
28
- this.name = 'ExecError';
29
- }
30
- }
31
-
32
- type NotificationListener = (method: string, params: { data?: string; exitCode?: number | null }) => void;
33
-
34
- interface PendingCall {
35
- resolve(result: unknown): void;
36
- reject(error: Error): void;
37
- }
38
-
39
- /**
40
- * One connection of a host to `ta exec-server`, shared by its environments. It connects on the first
41
- * call and again on the first call after a loss; processes do not survive a loss. Once fenced by a
42
- * host with a newer epoch it refuses every call: this host must stop running sessions there.
43
- */
44
- export class ExecClient {
45
- protected connection?: Promise<ExecConnection>;
46
- protected current?: ExecConnection;
47
- protected nextCall = 0;
48
- protected nextProcess = 0;
49
- protected fenced = false;
50
- protected pinger?: ReturnType<typeof setInterval>;
51
- protected initialized?: ExecRpc.InitializeResult;
52
- protected readonly pending = new Map<number, PendingCall>();
53
- protected readonly listeners = new Map<number, NotificationListener>();
54
- protected readonly stateListeners = new Set<(connected: boolean, error?: string) => void>();
55
-
56
- constructor(protected readonly options: ExecClientOptions) {}
57
-
58
- /** Connects to a `ta exec-server` listening on a WebSocket. */
59
- static webSocket(url: string, token: string): () => Promise<ExecConnection> {
60
- return async () => {
61
- const address = new URL(url);
62
- address.searchParams.set('token', token);
63
- const socket = new WebSocket(address);
64
- await new Promise<void>((resolve, reject) => {
65
- socket.onopen = () => resolve();
66
- socket.onerror = () => reject(new ExecError(`Cannot connect to ${url}.`, ExecRpc.ErrorCode.CONNECTION_LOST));
67
- });
68
- return {
69
- send: text => socket.send(text),
70
- close: () => socket.close(),
71
- onMessage: listener => {
72
- socket.onmessage = message => listener(String(message.data));
73
- },
74
- onClose: listener => {
75
- socket.onclose = () => listener();
76
- },
77
- };
78
- };
79
- }
80
-
81
- get connected(): boolean {
82
- return this.current !== undefined;
83
- }
84
-
85
- async call<T>(method: string, params: object): Promise<T> {
86
- const connection = await this.connect();
87
- return this.send<T>(connection, method, params);
88
- }
89
-
90
- /** What the server said when this client connected. */
91
- async info(): Promise<ExecRpc.InitializeResult> {
92
- await this.connect();
93
- return this.initialized as ExecRpc.InitializeResult;
94
- }
95
-
96
- /** An id for a process or a TCP connection, which its notifications carry. */
97
- processId(): number {
98
- return ++this.nextProcess;
99
- }
100
-
101
- listen(id: number, listener: NotificationListener): () => void {
102
- this.listeners.set(id, listener);
103
- return () => this.listeners.delete(id);
104
- }
105
-
106
- /** Runs when a connection opens (true), is lost or closed (false), or cannot be opened (false, with why). */
107
- onState(listener: (connected: boolean, error?: string) => void): () => void {
108
- this.stateListeners.add(listener);
109
- return () => this.stateListeners.delete(listener);
110
- }
111
-
112
- close(): void {
113
- const current = this.current;
114
- this.connection = undefined;
115
- current?.close();
116
- if (current) {
117
- this.lost(current);
118
- }
119
- }
120
-
121
- protected connect(): Promise<ExecConnection> {
122
- if (this.fenced) {
123
- return Promise.reject(new ExecError('A host with a newer epoch took over the execution environment.', ExecRpc.ErrorCode.STALE_EPOCH));
124
- }
125
- this.connection ??= this.open().catch(error => {
126
- this.connection = undefined;
127
- for (const listener of this.stateListeners) {
128
- listener(false, error instanceof Error ? error.message : String(error));
129
- }
130
- throw error;
131
- });
132
- return this.connection;
133
- }
134
-
135
- protected async open(): Promise<ExecConnection> {
136
- const connection = await this.options.connect();
137
- connection.onMessage(text => this.receive(text));
138
- connection.onClose(reason => this.lost(connection, reason));
139
- this.current = connection;
140
- try {
141
- this.initialized = await this.send(connection, ExecRpc.Method.INITIALIZE, { epoch: this.options.epoch } satisfies ExecRpc.InitializeParams);
142
- } catch (error) {
143
- if ((error as ExecError).code === ExecRpc.ErrorCode.STALE_EPOCH) {
144
- this.fenced = true;
145
- }
146
- connection.close();
147
- throw error;
148
- }
149
- if (this.options.pingMs) {
150
- clearInterval(this.pinger);
151
- this.pinger = setInterval(() => connection.send(JSON.stringify({ jsonrpc: '2.0', method: ExecRpc.PING })), this.options.pingMs);
152
- this.pinger.unref?.();
153
- }
154
- for (const listener of this.stateListeners) {
155
- listener(true);
156
- }
157
- return connection;
158
- }
159
-
160
- protected send<T>(connection: ExecConnection, method: string, params: object): Promise<T> {
161
- if (this.current !== connection) {
162
- return Promise.reject(new ExecError('The connection to the execution environment was lost.', ExecRpc.ErrorCode.CONNECTION_LOST));
163
- }
164
- const id = ++this.nextCall;
165
- return new Promise<T>((resolve, reject) => {
166
- this.pending.set(id, { resolve: resolve as (result: unknown) => void, reject });
167
- connection.send(JSON.stringify({ jsonrpc: '2.0', id, method, params } satisfies ExecRpc.Message));
168
- });
169
- }
170
-
171
- /** Anything but JSON-RPC is left alone: a shell of the other machine may have printed it first. */
172
- protected receive(text: string): void {
173
- let message: ExecRpc.Message;
174
- try {
175
- message = JSON.parse(text);
176
- } catch {
177
- return;
178
- }
179
- if (message?.jsonrpc !== '2.0') {
180
- return;
181
- }
182
- if (message.method) {
183
- this.listeners.get(message.params?.id)?.(message.method, message.params);
184
- return;
185
- }
186
- const call = this.pending.get(message.id as number);
187
- this.pending.delete(message.id as number);
188
- if (message.error) {
189
- const code = message.error.data?.code ?? ExecRpc.ErrorCode.FAILED;
190
- if (code === ExecRpc.ErrorCode.STALE_EPOCH) {
191
- this.fenced = true;
192
- }
193
- call?.reject(new ExecError(message.error.message, code));
194
- } else {
195
- call?.resolve(message.result);
196
- }
197
- }
198
-
199
- /** Calls fail, and processes are gone: the server ended them with the connection. `reason`: it was not closed on purpose. */
200
- protected lost(connection: ExecConnection, reason?: string): void {
201
- if (this.current !== connection) {
202
- return;
203
- }
204
- this.current = undefined;
205
- this.connection = undefined;
206
- clearInterval(this.pinger);
207
- this.pinger = undefined;
208
- const message = reason ?? 'The connection to the execution environment was lost.';
209
- for (const call of this.pending.values()) {
210
- call.reject(new ExecError(message, ExecRpc.ErrorCode.CONNECTION_LOST));
211
- }
212
- this.pending.clear();
213
- for (const listener of [...this.listeners.values()]) {
214
- listener(ExecRpc.Notification.EXIT, { exitCode: null });
215
- }
216
- this.listeners.clear();
217
- for (const listener of this.stateListeners) {
218
- listener(false, reason);
219
- }
220
- }
221
- }