master-zapier-plan-draft/packages/verae-fleet/test/ssh.test.js
George Lambert e89e006542
Some checks are pending
offline / test (push) Waiting to run
Control remote fleet workers over SSH with user, host, and key path
NS1 is marchon@70.88.205.138 using ~/.ssh/id_ed25519. Private key
bytes stay off git. Spawn, health, and kill go through ssh; remote
workers bind loopback only.
2026-09-11 13:31:21 -04:00

56 lines
1.9 KiB
JavaScript

import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { expandHome, shellQuote, sshBaseArgs, sshTarget } from '../src/ssh.js';
import { normalizeMachine, pickMachine } from '../src/machines.js';
describe('SSH remote machine config', () => {
it('expands ~ in identityFile and quotes remote commands', () => {
assert.equal(expandHome('~/foo'), `${os.homedir()}/foo`);
assert.equal(shellQuote("a'b"), `'a'"'"'b'`);
});
it('builds ssh argv with user, host, port, and key path (not key bytes)', () => {
const key = path.join(os.tmpdir(), 'verae-fleet-test-id');
fs.writeFileSync(key, 'not-a-real-key\n', { mode: 0o600 });
const m = normalizeMachine({
id: 'ns1',
kind: 'ssh',
host: '70.88.205.138',
user: 'marchon',
sshPort: 22,
identityFile: key,
});
assert.equal(m.kind, 'ssh');
assert.equal(sshTarget(m), 'marchon@70.88.205.138');
const args = sshBaseArgs(m);
assert.ok(args.includes('-i'));
assert.ok(args.includes(key));
assert.ok(!args.some((a) => a.includes('BEGIN')));
assert.equal(m.user, 'marchon');
fs.unlinkSync(key);
});
it('places load on ssh hosts when they have free capacity', () => {
const machines = [
normalizeMachine({ id: 'local', kind: 'local', host: '127.0.0.1', capacity: 2, roles: ['*'] }),
normalizeMachine({
id: 'ns1',
kind: 'ssh',
host: '70.88.205.138',
user: 'marchon',
identityFile: '~/.ssh/id_ed25519',
capacity: 8,
roles: ['tree-node'],
}),
];
const instances = [
{ machine: 'local', pid: 1 },
{ machine: 'local', pid: 2 },
];
const pick = pickMachine(machines, instances, 'tree-node', 'tree-node');
assert.equal(pick.id, 'ns1');
});
});