master-zapier-plan-draft/packages/verae-fleet/test/ssh.test.js
George Lambert ddf772454b
Some checks are pending
offline / test (push) Waiting to run
Clean prepaid SoT, identity mailbox, public access planes, leaf policy, fleet spawn
Persist account-balance books; edge caches prepaid from books. Add zappier-identity, verae-nats-accounts, verae-jobs-events, verae-access-staff, zapier-decisions. Edge binds loopback; lan-134 stays off; HTTP services prefer local spawn.
2026-09-11 17:15:16 -04:00

71 lines
2.3 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');
});
it('preferLocal keeps HTTP apps on the control host', () => {
const machines = [
normalizeMachine({ id: 'local', kind: 'local', host: '127.0.0.1', capacity: 32, roles: ['*'] }),
normalizeMachine({
id: 'ns1',
kind: 'ssh',
host: '70.88.205.138',
capacity: 24,
roles: ['*'],
}),
];
const pick = pickMachine(machines, [], 'account-balance', 'account-balance', [], { preferLocal: true });
assert.equal(pick.id, 'local');
});
});