@selvajs/cli 4.8.0-beta.7 → 4.8.0-beta.9

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.
@@ -1,65 +0,0 @@
1
- // `selva migrate` rewrites the operator's .env in place, so these pin the
2
- // blast radius: only the key changes, and only on lines that are live config.
3
- // Run by `pnpm test` via node's built-in runner.
4
-
5
- import { test } from 'node:test';
6
- import assert from 'node:assert/strict';
7
- import { renameEnvKeys, RENAMED_ENV_VARS, REPLACED_ENV_VARS } from '../env.js';
8
-
9
- test('renames a deprecated key and leaves everything else byte-identical', () => {
10
- const before = [
11
- '# Selva deployment',
12
- 'ORIGIN=https://example.com',
13
- '',
14
- '# Longest a solve may run.',
15
- 'MAX_SOLVE_DURATION_MS=45000',
16
- 'COMPUTE_RATE_LIMIT_MAX=120',
17
- ''
18
- ].join('\n');
19
-
20
- const { text, changes } = renameEnvKeys(before, RENAMED_ENV_VARS);
21
-
22
- assert.deepEqual(changes, [['MAX_SOLVE_DURATION_MS', 'COMPUTE_SOLVE_DEADLINE_MS', 'renamed']]);
23
- assert.equal(text, before.replace('MAX_SOLVE_DURATION_MS', 'COMPUTE_SOLVE_DEADLINE_MS'));
24
- });
25
-
26
- test('preserves the value verbatim, including quotes and spacing', () => {
27
- const { text } = renameEnvKeys(
28
- 'COMPUTE_RESPONSE_CACHE_MB="512"\n DEFINITION_CACHE_TTL_MS = 60000\n',
29
- RENAMED_ENV_VARS
30
- );
31
- assert.match(text, /^COMPUTE_SOLVE_CACHE_MB="512"$/m);
32
- assert.match(text, /^ {3}REMOTE_DEFINITION_CACHE_TTL_MS = 60000$/m);
33
- });
34
-
35
- test('drops the old line when the new name is already set', () => {
36
- const { text, changes } = renameEnvKeys(
37
- 'MAX_SOLVE_DURATION_MS=45000\nCOMPUTE_SOLVE_DEADLINE_MS=30000\n',
38
- RENAMED_ENV_VARS
39
- );
40
- // The server resolves the same way (new name wins), so keeping both would
41
- // preserve a line that does nothing.
42
- assert.deepEqual(changes, [['MAX_SOLVE_DURATION_MS', 'COMPUTE_SOLVE_DEADLINE_MS', 'dropped']]);
43
- assert.equal(text, 'COMPUTE_SOLVE_DEADLINE_MS=30000\n');
44
- });
45
-
46
- test('reports no changes for an already-current file', () => {
47
- const { changes } = renameEnvKeys('COMPUTE_SOLVE_DEADLINE_MS=30000\n', RENAMED_ENV_VARS);
48
- assert.deepEqual(changes, []);
49
- });
50
-
51
- test('ignores a commented-out old name — it is not active config', () => {
52
- const before = '# MAX_SOLVE_DURATION_MS=100000\n';
53
- const { text, changes } = renameEnvKeys(before, RENAMED_ENV_VARS);
54
- assert.deepEqual(changes, []);
55
- assert.equal(text, before);
56
- });
57
-
58
- test('leaves value-changing replacements alone — migrate must not guess', () => {
59
- const before = 'SELVA_FLAG_COMPUTE_DEBUG_VERBOSE=true\n';
60
- const { text, changes } = renameEnvKeys(before, RENAMED_ENV_VARS);
61
- assert.deepEqual(changes, []);
62
- assert.equal(text, before);
63
- // It is still reported by `selva doctor`, just not auto-fixed.
64
- assert.ok(REPLACED_ENV_VARS.SELVA_FLAG_COMPUTE_DEBUG_VERBOSE);
65
- });
@@ -1,60 +0,0 @@
1
- // PM2 daemon/CLI skew direction (issue #118, defect 2).
2
- //
3
- // The old check treated any `out-of-date` report as "run `pm2 update`". That is
4
- // only correct when the daemon is OLDER than the deployment-local CLI. In the
5
- // reported incident a global pm2 v6 owned the daemon while the deployment pinned
6
- // v5.4.3 — `pm2 update` ran the v5 CLI against it, downgrading the daemon and
7
- // feeding it a v6 dump, so the process table came back empty and selva-compute
8
- // was never re-registered.
9
- //
10
- // Run by `pnpm test` via node's built-in runner.
11
-
12
- import { test } from 'node:test';
13
- import assert from 'node:assert/strict';
14
- import { parsePm2Skew, daemonOutranksCli } from '../commands/pm2.js';
15
-
16
- // pm2 colourises through chalk on a TTY; build the codes rather than embedding
17
- // raw control characters in the source.
18
- const ESC = String.fromCharCode(27);
19
- const colour = (s) => `${ESC}[34m${ESC}[1m${s}${ESC}[22m${ESC}[39m`;
20
-
21
- const REAL_OUTPUT =
22
- `${ESC}[31m${ESC}[1m>>>> In-memory PM2 is out-of-date, do:\n>>>> $ pm2 update${ESC}[22m${ESC}[39m\n` +
23
- `In memory PM2 version: ${colour('6.0.14')}\n` +
24
- `Local PM2 version: ${colour('5.4.3')}\n`;
25
-
26
- test('parses both versions out of real colourised pm2 output', () => {
27
- assert.deepEqual(parsePm2Skew(REAL_OUTPUT), { daemon: '6.0.14', local: '5.4.3' });
28
- });
29
-
30
- test('parses plain uncoloured output (non-TTY)', () => {
31
- const plain = 'In memory PM2 version: 5.4.3\nLocal PM2 version: 5.4.3\n';
32
- assert.deepEqual(parsePm2Skew(plain), { daemon: '5.4.3', local: '5.4.3' });
33
- });
34
-
35
- test('returns nulls when the message shape changes, so callers fall back to resync', () => {
36
- assert.deepEqual(parsePm2Skew('something else entirely'), { daemon: null, local: null });
37
- });
38
-
39
- test('flags the incident direction — global daemon newer than the pinned CLI', () => {
40
- assert.equal(daemonOutranksCli('6.0.14', '5.4.3'), true);
41
- });
42
-
43
- test('allows the repairable direction — daemon older than the CLI', () => {
44
- assert.equal(daemonOutranksCli('5.4.3', '6.0.14'), false);
45
- });
46
-
47
- test('is false when the versions match', () => {
48
- assert.equal(daemonOutranksCli('5.4.3', '5.4.3'), false);
49
- });
50
-
51
- test('compares minor and patch, not just major', () => {
52
- assert.equal(daemonOutranksCli('5.5.0', '5.4.3'), true);
53
- assert.equal(daemonOutranksCli('5.4.4', '5.4.3'), true);
54
- assert.equal(daemonOutranksCli('5.4.3', '5.4.4'), false);
55
- });
56
-
57
- test('never blocks on an unparseable version — resync stays the default', () => {
58
- assert.equal(daemonOutranksCli(null, '5.4.3'), false);
59
- assert.equal(daemonOutranksCli('6.0.14', null), false);
60
- });