codify-plugin-lib 1.0.180 → 1.0.182-beta1
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/dist/bin/build.d.ts +1 -0
- package/dist/bin/build.js +80 -0
- package/dist/bin/deploy-plugin.d.ts +2 -0
- package/dist/bin/deploy-plugin.js +8 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/plugin/plugin.js +5 -2
- package/dist/pty/background-pty.d.ts +1 -0
- package/dist/pty/background-pty.js +17 -3
- package/dist/pty/index.d.ts +17 -1
- package/dist/pty/seqeuntial-pty.d.ts +16 -0
- package/dist/pty/seqeuntial-pty.js +84 -0
- package/dist/resource/parsed-resource-settings.d.ts +3 -1
- package/dist/resource/parsed-resource-settings.js +4 -6
- package/dist/resource/resource-settings.d.ts +5 -1
- package/dist/resource/resource-settings.js +4 -3
- package/dist/scripts/deploy.d.ts +1 -0
- package/dist/scripts/deploy.js +2 -0
- package/dist/utils/codify-spawn.d.ts +29 -0
- package/dist/utils/codify-spawn.js +136 -0
- package/dist/utils/index.d.ts +25 -0
- package/dist/utils/index.js +108 -0
- package/dist/utils/internal-utils.d.ts +18 -0
- package/dist/utils/internal-utils.js +86 -0
- package/dist/utils/pty-local-storage.d.ts +0 -1
- package/package.json +17 -12
- package/src/index.ts +1 -1
- package/src/plan/plan.test.ts +6 -1
- package/src/plugin/plugin.test.ts +11 -2
- package/src/plugin/plugin.ts +5 -2
- package/src/pty/background-pty.ts +20 -3
- package/src/pty/index.test.ts +7 -4
- package/src/pty/index.ts +17 -1
- package/src/pty/seqeuntial-pty.ts +105 -0
- package/src/pty/sequential-pty.test.ts +61 -0
- package/src/resource/parsed-resource-settings.ts +8 -7
- package/src/resource/resource-controller-stateful-mode.test.ts +2 -1
- package/src/resource/resource-controller.test.ts +22 -4
- package/src/resource/resource-settings.test.ts +29 -2
- package/src/resource/resource-settings.ts +16 -4
- package/src/utils/index.ts +140 -0
- package/src/utils/{utils.test.ts → internal-utils.test.ts} +1 -1
- package/src/utils/test-utils.test.ts +5 -2
- /package/src/utils/{utils.ts → internal-utils.ts} +0 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import pty from '@homebridge/node-pty-prebuilt-multiarch';
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
3
|
+
import stripAnsi from 'strip-ansi';
|
|
4
|
+
|
|
5
|
+
import { Shell, Utils } from '../utils/index.js';
|
|
6
|
+
import { VerbosityLevel } from '../utils/internal-utils.js';
|
|
7
|
+
import { IPty, SpawnError, SpawnOptions, SpawnResult, SpawnStatus } from './index.js';
|
|
8
|
+
|
|
9
|
+
EventEmitter.defaultMaxListeners = 1000;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The background pty is a specialized pty designed for speed. It can launch multiple tasks
|
|
13
|
+
* in parallel by moving them to the background. It attaches unix FIFO pipes to each process
|
|
14
|
+
* to listen to stdout and stderr. One limitation of the BackgroundPty is that the tasks run
|
|
15
|
+
* without a tty (or even a stdin) attached so interactive commands will not work.
|
|
16
|
+
*/
|
|
17
|
+
export class SequentialPty implements IPty {
|
|
18
|
+
async spawn(cmd: string, options?: SpawnOptions): Promise<SpawnResult> {
|
|
19
|
+
const spawnResult = await this.spawnSafe(cmd, options);
|
|
20
|
+
|
|
21
|
+
if (spawnResult.status !== 'success') {
|
|
22
|
+
throw new SpawnError(cmd, spawnResult.exitCode, spawnResult.data);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return spawnResult;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async spawnSafe(cmd: string, options?: SpawnOptions): Promise<SpawnResult> {
|
|
29
|
+
console.log(`Running command: ${cmd}` + (options?.cwd ? `(${options?.cwd})` : ''))
|
|
30
|
+
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
const output: string[] = [];
|
|
33
|
+
|
|
34
|
+
const historyIgnore = Utils.getShell() === Shell.ZSH ? { HISTORY_IGNORE: '*' } : { HISTIGNORE: '*' };
|
|
35
|
+
|
|
36
|
+
// If TERM_PROGRAM=Apple_Terminal is set then ANSI escape characters may be included
|
|
37
|
+
// in the response.
|
|
38
|
+
const env = {
|
|
39
|
+
...process.env, ...options?.env,
|
|
40
|
+
TERM_PROGRAM: 'codify',
|
|
41
|
+
COMMAND_MODE: 'unix2003',
|
|
42
|
+
COLORTERM: 'truecolor', ...historyIgnore
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Initial terminal dimensions
|
|
46
|
+
const initialCols = process.stdout.columns ?? 80;
|
|
47
|
+
const initialRows = process.stdout.rows ?? 24;
|
|
48
|
+
|
|
49
|
+
const args = (options?.interactive ?? true) ? ['-i', '-c', `"${cmd}"`] : ['-c', `"${cmd}"`]
|
|
50
|
+
|
|
51
|
+
// Run the command in a pty for interactivity
|
|
52
|
+
const mPty = pty.spawn(this.getDefaultShell(), args, {
|
|
53
|
+
...options,
|
|
54
|
+
cols: initialCols,
|
|
55
|
+
rows: initialRows,
|
|
56
|
+
env
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
mPty.onData((data) => {
|
|
60
|
+
if (VerbosityLevel.get() > 0) {
|
|
61
|
+
process.stdout.write(data);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
output.push(data.toString());
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
const stdinListener = (data: any) => {
|
|
68
|
+
mPty.write(data.toString());
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const resizeListener = () => {
|
|
72
|
+
const { columns, rows } = process.stdout;
|
|
73
|
+
mPty.resize(columns, rows);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Listen to resize events for the terminal window;
|
|
77
|
+
process.stdout.on('resize', resizeListener);
|
|
78
|
+
// Listen for user input
|
|
79
|
+
process.stdin.on('data', stdinListener);
|
|
80
|
+
|
|
81
|
+
mPty.onExit((result) => {
|
|
82
|
+
process.stdout.off('resize', resizeListener);
|
|
83
|
+
process.stdin.off('data', stdinListener);
|
|
84
|
+
|
|
85
|
+
resolve({
|
|
86
|
+
status: result.exitCode === 0 ? SpawnStatus.SUCCESS : SpawnStatus.ERROR,
|
|
87
|
+
exitCode: result.exitCode,
|
|
88
|
+
data: stripAnsi(output.join('\n').trim()),
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async kill(): Promise<{ exitCode: number, signal?: number | undefined }> {
|
|
95
|
+
// No-op here. Each pty instance is stand alone and tied to the parent process. Everything should be killed as expected.
|
|
96
|
+
return {
|
|
97
|
+
exitCode: 0,
|
|
98
|
+
signal: 0,
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private getDefaultShell(): string {
|
|
103
|
+
return process.env.SHELL!;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { SequentialPty } from './seqeuntial-pty.js';
|
|
3
|
+
import { VerbosityLevel } from '../utils/internal-utils.js';
|
|
4
|
+
|
|
5
|
+
describe('SequentialPty tests', () => {
|
|
6
|
+
it('Can launch a simple command', async () => {
|
|
7
|
+
const pty = new SequentialPty();
|
|
8
|
+
|
|
9
|
+
VerbosityLevel.set(1);
|
|
10
|
+
|
|
11
|
+
const result = await pty.spawnSafe('ls');
|
|
12
|
+
expect(result).toMatchObject({
|
|
13
|
+
status: 'success',
|
|
14
|
+
exitCode: 0,
|
|
15
|
+
data: expect.any(String),
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const exitCode = await pty.kill();
|
|
19
|
+
expect(exitCode).toMatchObject({
|
|
20
|
+
exitCode: 0,
|
|
21
|
+
});
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('Reports back the correct exit code and status', async () => {
|
|
25
|
+
const pty = new SequentialPty();
|
|
26
|
+
|
|
27
|
+
const resultSuccess = await pty.spawnSafe('ls');
|
|
28
|
+
expect(resultSuccess).toMatchObject({
|
|
29
|
+
status: 'success',
|
|
30
|
+
exitCode: 0,
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const resultFailed = await pty.spawnSafe('which sjkdhsakjdhjkash');
|
|
34
|
+
expect(resultFailed).toMatchObject({
|
|
35
|
+
status: 'error',
|
|
36
|
+
exitCode: 127,
|
|
37
|
+
data: 'zsh:1: command not found: which sjkdhsakjdhjkash' // This might change on different os or shells. Keep for now.
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('Can use a different cwd', async () => {
|
|
42
|
+
const pty = new SequentialPty();
|
|
43
|
+
|
|
44
|
+
const resultSuccess = await pty.spawnSafe('pwd', { cwd: '/tmp' });
|
|
45
|
+
expect(resultSuccess).toMatchObject({
|
|
46
|
+
status: 'success',
|
|
47
|
+
exitCode: 0,
|
|
48
|
+
data: '/tmp'
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('It can launch a command in interactive mode', async () => {
|
|
53
|
+
const pty = new SequentialPty();
|
|
54
|
+
|
|
55
|
+
const resultSuccess = await pty.spawnSafe('ls', { interactive: false });
|
|
56
|
+
expect(resultSuccess).toMatchObject({
|
|
57
|
+
status: 'success',
|
|
58
|
+
exitCode: 0,
|
|
59
|
+
})
|
|
60
|
+
});
|
|
61
|
+
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSONSchemaType } from 'ajv';
|
|
2
|
-
import { StringIndexedObject } from 'codify-schemas';
|
|
2
|
+
import { OS, StringIndexedObject } from 'codify-schemas';
|
|
3
3
|
|
|
4
4
|
import { StatefulParameterController } from '../stateful-parameter/stateful-parameter-controller.js';
|
|
5
5
|
import {
|
|
@@ -46,16 +46,17 @@ export class ParsedResourceSettings<T extends StringIndexedObject> implements Re
|
|
|
46
46
|
removeStatefulParametersBeforeDestroy?: boolean | undefined;
|
|
47
47
|
dependencies?: string[] | undefined;
|
|
48
48
|
transformation?: InputTransformation;
|
|
49
|
+
|
|
50
|
+
operatingSystems!: Array<OS>;
|
|
51
|
+
isSensitive?: boolean;
|
|
52
|
+
|
|
49
53
|
private settings: ResourceSettings<T>;
|
|
50
54
|
|
|
51
55
|
constructor(settings: ResourceSettings<T>) {
|
|
52
56
|
this.settings = settings;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this
|
|
56
|
-
this.removeStatefulParametersBeforeDestroy = settings.removeStatefulParametersBeforeDestroy;
|
|
57
|
-
this.dependencies = settings.dependencies;
|
|
58
|
-
this.transformation = settings.transformation;
|
|
57
|
+
|
|
58
|
+
const { parameterSettings, ...rest } = settings;
|
|
59
|
+
Object.assign(this, rest);
|
|
59
60
|
|
|
60
61
|
this.validateSettings();
|
|
61
62
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { ParameterOperation, ResourceOperation } from 'codify-schemas';
|
|
2
|
+
import { OS, ParameterOperation, ResourceOperation } from 'codify-schemas';
|
|
3
3
|
import { TestConfig, TestResource, TestStatefulParameter } from '../utils/test-utils.test.js';
|
|
4
4
|
import { ResourceSettings } from './resource-settings.js';
|
|
5
5
|
import { ResourceController } from './resource-controller.js';
|
|
@@ -179,6 +179,7 @@ describe('Resource tests for stateful plans', () => {
|
|
|
179
179
|
getSettings(): ResourceSettings<TestConfig> {
|
|
180
180
|
return {
|
|
181
181
|
id: 'type',
|
|
182
|
+
operatingSystems: [OS.Darwin],
|
|
182
183
|
parameterSettings: {
|
|
183
184
|
propD: { type: 'stateful', definition: statefulParameter },
|
|
184
185
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Resource } from './resource.js';
|
|
2
|
-
import { ResourceOperation } from 'codify-schemas';
|
|
2
|
+
import { OS, ResourceOperation } from 'codify-schemas';
|
|
3
3
|
import { spy } from 'sinon';
|
|
4
4
|
import { describe, expect, it } from 'vitest'
|
|
5
5
|
import { ArrayParameterSetting, ParameterSetting, ResourceSettings } from './resource-settings.js';
|
|
@@ -7,7 +7,7 @@ import { CreatePlan, DestroyPlan, ModifyPlan } from '../plan/plan-types.js';
|
|
|
7
7
|
import { ParameterChange } from '../plan/change-set.js';
|
|
8
8
|
import { ResourceController } from './resource-controller.js';
|
|
9
9
|
import { TestConfig, testPlan, TestResource, TestStatefulParameter } from '../utils/test-utils.test.js';
|
|
10
|
-
import { tildify, untildify } from '../utils/utils.js';
|
|
10
|
+
import { tildify, untildify } from '../utils/internal-utils.js';
|
|
11
11
|
import { ArrayStatefulParameter, StatefulParameter } from '../stateful-parameter/stateful-parameter.js';
|
|
12
12
|
import { Plan } from '../plan/plan.js';
|
|
13
13
|
import os from 'node:os';
|
|
@@ -19,6 +19,7 @@ describe('Resource tests', () => {
|
|
|
19
19
|
getSettings(): ResourceSettings<TestConfig> {
|
|
20
20
|
return {
|
|
21
21
|
id: 'type',
|
|
22
|
+
operatingSystems: [OS.Darwin],
|
|
22
23
|
dependencies: ['homebrew', 'python'],
|
|
23
24
|
parameterSettings: {
|
|
24
25
|
propA: {
|
|
@@ -197,6 +198,7 @@ describe('Resource tests', () => {
|
|
|
197
198
|
getSettings(): ResourceSettings<TestConfig> {
|
|
198
199
|
return {
|
|
199
200
|
id: 'resource',
|
|
201
|
+
operatingSystems: [OS.Darwin],
|
|
200
202
|
parameterSettings: {
|
|
201
203
|
propA: { canModify: true },
|
|
202
204
|
propB: { canModify: true },
|
|
@@ -232,6 +234,7 @@ describe('Resource tests', () => {
|
|
|
232
234
|
getSettings(): ResourceSettings<TestConfig> {
|
|
233
235
|
return {
|
|
234
236
|
id: 'type',
|
|
237
|
+
operatingSystems: [OS.Darwin],
|
|
235
238
|
dependencies: ['homebrew', 'python'],
|
|
236
239
|
parameterSettings: {
|
|
237
240
|
propA: { canModify: true },
|
|
@@ -254,6 +257,7 @@ describe('Resource tests', () => {
|
|
|
254
257
|
getSettings(): ResourceSettings<TestConfig> {
|
|
255
258
|
return {
|
|
256
259
|
id: 'type',
|
|
260
|
+
operatingSystems: [OS.Darwin],
|
|
257
261
|
dependencies: ['homebrew', 'python'],
|
|
258
262
|
parameterSettings: {
|
|
259
263
|
propA: { canModify: true },
|
|
@@ -270,6 +274,7 @@ describe('Resource tests', () => {
|
|
|
270
274
|
getSettings(): ResourceSettings<TestConfig> {
|
|
271
275
|
return {
|
|
272
276
|
id: 'type',
|
|
277
|
+
operatingSystems: [OS.Darwin],
|
|
273
278
|
parameterSettings: {
|
|
274
279
|
propA: { default: 'propADefault' }
|
|
275
280
|
}
|
|
@@ -298,6 +303,7 @@ describe('Resource tests', () => {
|
|
|
298
303
|
getSettings(): ResourceSettings<TestConfig> {
|
|
299
304
|
return {
|
|
300
305
|
id: 'type',
|
|
306
|
+
operatingSystems: [OS.Darwin],
|
|
301
307
|
parameterSettings: {
|
|
302
308
|
propE: { default: 'propEDefault' }
|
|
303
309
|
}
|
|
@@ -325,6 +331,7 @@ describe('Resource tests', () => {
|
|
|
325
331
|
getSettings(): ResourceSettings<TestConfig> {
|
|
326
332
|
return {
|
|
327
333
|
id: 'type',
|
|
334
|
+
operatingSystems: [OS.Darwin],
|
|
328
335
|
parameterSettings: {
|
|
329
336
|
propE: { default: 'propEDefault' }
|
|
330
337
|
}
|
|
@@ -348,6 +355,7 @@ describe('Resource tests', () => {
|
|
|
348
355
|
getSettings(): ResourceSettings<TestConfig> {
|
|
349
356
|
return {
|
|
350
357
|
id: 'type',
|
|
358
|
+
operatingSystems: [OS.Darwin],
|
|
351
359
|
parameterSettings: {
|
|
352
360
|
propA: { default: 'propADefault' }
|
|
353
361
|
}
|
|
@@ -376,6 +384,7 @@ describe('Resource tests', () => {
|
|
|
376
384
|
getSettings(): ResourceSettings<TestConfig> {
|
|
377
385
|
return {
|
|
378
386
|
id: 'type',
|
|
387
|
+
operatingSystems: [OS.Darwin],
|
|
379
388
|
parameterSettings: {
|
|
380
389
|
propA: { default: 'propADefault' }
|
|
381
390
|
}
|
|
@@ -392,7 +401,7 @@ describe('Resource tests', () => {
|
|
|
392
401
|
it('Has the correct typing for applys', () => {
|
|
393
402
|
const resource = new class extends Resource<TestConfig> {
|
|
394
403
|
getSettings(): ResourceSettings<TestConfig> {
|
|
395
|
-
return { id: 'type' }
|
|
404
|
+
return { id: 'type', operatingSystems: [OS.Darwin], }
|
|
396
405
|
}
|
|
397
406
|
|
|
398
407
|
async refresh(): Promise<Partial<TestConfig> | null> {
|
|
@@ -418,7 +427,8 @@ describe('Resource tests', () => {
|
|
|
418
427
|
const parameter1 = new class extends StatefulParameter<any, any> {
|
|
419
428
|
getSettings(): ParameterSetting {
|
|
420
429
|
return {
|
|
421
|
-
type: 'version'
|
|
430
|
+
type: 'version',
|
|
431
|
+
operatingSystems: [OS.Darwin],
|
|
422
432
|
}
|
|
423
433
|
}
|
|
424
434
|
|
|
@@ -462,6 +472,7 @@ describe('Resource tests', () => {
|
|
|
462
472
|
getSettings(): ResourceSettings<TestConfig> {
|
|
463
473
|
return {
|
|
464
474
|
id: 'nvm',
|
|
475
|
+
operatingSystems: [OS.Darwin],
|
|
465
476
|
parameterSettings: {
|
|
466
477
|
global: { type: 'stateful', definition: parameter1, order: 2 },
|
|
467
478
|
nodeVersions: { type: 'stateful', definition: parameter2, order: 1 },
|
|
@@ -514,6 +525,7 @@ describe('Resource tests', () => {
|
|
|
514
525
|
getSettings(): ResourceSettings<TestConfig> {
|
|
515
526
|
return {
|
|
516
527
|
id: 'nvm',
|
|
528
|
+
operatingSystems: [OS.Darwin],
|
|
517
529
|
parameterSettings: {
|
|
518
530
|
global: { type: 'stateful', definition: parameter1, order: 2 },
|
|
519
531
|
nodeVersions: { type: 'stateful', definition: parameter2, order: 1 },
|
|
@@ -546,6 +558,7 @@ describe('Resource tests', () => {
|
|
|
546
558
|
getSettings(): ResourceSettings<TestConfig> {
|
|
547
559
|
return {
|
|
548
560
|
id: 'resourceType',
|
|
561
|
+
operatingSystems: [OS.Darwin],
|
|
549
562
|
parameterSettings: {
|
|
550
563
|
propD: {
|
|
551
564
|
type: 'array',
|
|
@@ -630,6 +643,7 @@ describe('Resource tests', () => {
|
|
|
630
643
|
getSettings(): ResourceSettings<TestConfig> {
|
|
631
644
|
return {
|
|
632
645
|
id: 'resourceType',
|
|
646
|
+
operatingSystems: [OS.Darwin],
|
|
633
647
|
parameterSettings: {
|
|
634
648
|
propD: {
|
|
635
649
|
type: 'array',
|
|
@@ -720,6 +734,7 @@ describe('Resource tests', () => {
|
|
|
720
734
|
getSettings(): ResourceSettings<TestConfig> {
|
|
721
735
|
return {
|
|
722
736
|
id: 'resourceType',
|
|
737
|
+
operatingSystems: [OS.Darwin],
|
|
723
738
|
parameterSettings: {
|
|
724
739
|
propA: { type: 'string', default: 'defaultValue' },
|
|
725
740
|
propB: { type: 'boolean', default: true }
|
|
@@ -755,6 +770,7 @@ describe('Resource tests', () => {
|
|
|
755
770
|
getSettings(): ResourceSettings<any> {
|
|
756
771
|
return {
|
|
757
772
|
id: 'path',
|
|
773
|
+
operatingSystems: [OS.Darwin],
|
|
758
774
|
parameterSettings: {
|
|
759
775
|
path: { type: 'string', isEqual: 'directory' },
|
|
760
776
|
paths: { canModify: true, type: 'array', isElementEqual: 'directory' },
|
|
@@ -797,6 +813,7 @@ describe('Resource tests', () => {
|
|
|
797
813
|
getSettings(): ResourceSettings<any> {
|
|
798
814
|
return {
|
|
799
815
|
id: 'path',
|
|
816
|
+
operatingSystems: [OS.Darwin],
|
|
800
817
|
parameterSettings: {
|
|
801
818
|
path: { type: 'string', isEqual: 'directory' },
|
|
802
819
|
paths: { canModify: true, type: 'array', isElementEqual: 'directory' },
|
|
@@ -840,6 +857,7 @@ describe('Resource tests', () => {
|
|
|
840
857
|
getSettings(): ResourceSettings<any> {
|
|
841
858
|
return {
|
|
842
859
|
id: 'path',
|
|
860
|
+
operatingSystems: [OS.Darwin],
|
|
843
861
|
parameterSettings: {
|
|
844
862
|
path: { type: 'directory' },
|
|
845
863
|
paths: { canModify: true, type: 'array', itemType: 'directory' },
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import { Plan } from '../plan/plan.js';
|
|
3
3
|
import { spy } from 'sinon';
|
|
4
|
-
import { ParameterOperation, ResourceOperation } from 'codify-schemas';
|
|
4
|
+
import { OS, ParameterOperation, ResourceOperation } from 'codify-schemas';
|
|
5
5
|
import {
|
|
6
6
|
TestArrayStatefulParameter,
|
|
7
7
|
TestConfig,
|
|
@@ -26,6 +26,7 @@ describe('Resource parameter tests', () => {
|
|
|
26
26
|
getSettings(): ResourceSettings<TestConfig> {
|
|
27
27
|
return {
|
|
28
28
|
id: 'type',
|
|
29
|
+
operatingSystems: [OS.Darwin],
|
|
29
30
|
parameterSettings: {
|
|
30
31
|
propA: { type: 'stateful', definition: statefulParameter }
|
|
31
32
|
},
|
|
@@ -71,6 +72,7 @@ describe('Resource parameter tests', () => {
|
|
|
71
72
|
getSettings(): ResourceSettings<TestConfig> {
|
|
72
73
|
return {
|
|
73
74
|
id: 'type',
|
|
75
|
+
operatingSystems: [OS.Darwin],
|
|
74
76
|
parameterSettings: {
|
|
75
77
|
propA: { type: 'stateful', definition: statefulParameterSpy }
|
|
76
78
|
},
|
|
@@ -105,6 +107,7 @@ describe('Resource parameter tests', () => {
|
|
|
105
107
|
getSettings(): ResourceSettings<TestConfig> {
|
|
106
108
|
return {
|
|
107
109
|
id: 'type',
|
|
110
|
+
operatingSystems: [OS.Darwin],
|
|
108
111
|
parameterSettings: {
|
|
109
112
|
propA: { type: 'stateful', definition: statefulParameterSpy },
|
|
110
113
|
propB: { canModify: true },
|
|
@@ -137,7 +140,8 @@ describe('Resource parameter tests', () => {
|
|
|
137
140
|
const statefulParameter = spy(new class extends TestStatefulParameter {
|
|
138
141
|
getSettings(): ParameterSetting {
|
|
139
142
|
return {
|
|
140
|
-
default: 'abc'
|
|
143
|
+
default: 'abc',
|
|
144
|
+
operatingSystems: [OS.Darwin],
|
|
141
145
|
};
|
|
142
146
|
}
|
|
143
147
|
|
|
@@ -150,6 +154,7 @@ describe('Resource parameter tests', () => {
|
|
|
150
154
|
getSettings(): ResourceSettings<TestConfig> {
|
|
151
155
|
return {
|
|
152
156
|
id: 'type',
|
|
157
|
+
operatingSystems: [OS.Darwin],
|
|
153
158
|
parameterSettings: {
|
|
154
159
|
propA: { type: 'stateful', definition: statefulParameter }
|
|
155
160
|
},
|
|
@@ -191,6 +196,7 @@ describe('Resource parameter tests', () => {
|
|
|
191
196
|
getSettings(): ResourceSettings<TestConfig> {
|
|
192
197
|
return {
|
|
193
198
|
id: 'type',
|
|
199
|
+
operatingSystems: [OS.Darwin],
|
|
194
200
|
parameterSettings: {
|
|
195
201
|
propA: { type: 'stateful', definition: statefulParameterSpy },
|
|
196
202
|
},
|
|
@@ -225,6 +231,7 @@ describe('Resource parameter tests', () => {
|
|
|
225
231
|
getSettings(): ResourceSettings<TestConfig> {
|
|
226
232
|
return {
|
|
227
233
|
id: 'type',
|
|
234
|
+
operatingSystems: [OS.Darwin],
|
|
228
235
|
parameterSettings: {
|
|
229
236
|
propA: { type: 'stateful', definition: statefulParameterSpy }
|
|
230
237
|
},
|
|
@@ -251,6 +258,7 @@ describe('Resource parameter tests', () => {
|
|
|
251
258
|
getSettings(): ResourceSettings<TestConfig> {
|
|
252
259
|
return {
|
|
253
260
|
id: 'type',
|
|
261
|
+
operatingSystems: [OS.Darwin],
|
|
254
262
|
parameterSettings: {
|
|
255
263
|
hosts: {
|
|
256
264
|
type: 'array',
|
|
@@ -360,6 +368,7 @@ describe('Resource parameter tests', () => {
|
|
|
360
368
|
getSettings(): ResourceSettings<TestConfig> {
|
|
361
369
|
return {
|
|
362
370
|
id: 'type',
|
|
371
|
+
operatingSystems: [OS.Darwin],
|
|
363
372
|
parameterSettings: {
|
|
364
373
|
propA: { type: 'stateful', definition: statefulParameterSpy }
|
|
365
374
|
},
|
|
@@ -416,6 +425,7 @@ describe('Resource parameter tests', () => {
|
|
|
416
425
|
getSettings(): ResourceSettings<TestConfig> {
|
|
417
426
|
return {
|
|
418
427
|
id: 'resourceType',
|
|
428
|
+
operatingSystems: [OS.Darwin],
|
|
419
429
|
parameterSettings: {
|
|
420
430
|
propA: { type: 'stateful', definition: statefulParameterA, order: 3 },
|
|
421
431
|
propB: { type: 'stateful', definition: statefulParameterB, order: 1 },
|
|
@@ -494,6 +504,7 @@ describe('Resource parameter tests', () => {
|
|
|
494
504
|
getSettings(): ResourceSettings<TestConfig> {
|
|
495
505
|
return {
|
|
496
506
|
id: 'resourceType',
|
|
507
|
+
operatingSystems: [OS.Darwin],
|
|
497
508
|
parameterSettings: {
|
|
498
509
|
propA: { type: 'stateful', definition: statefulParameterA, order: 3 },
|
|
499
510
|
propB: { type: 'stateful', definition: statefulParameterB, order: 1 },
|
|
@@ -569,6 +580,7 @@ describe('Resource parameter tests', () => {
|
|
|
569
580
|
getSettings(): ResourceSettings<TestConfig> {
|
|
570
581
|
return {
|
|
571
582
|
id: 'resourceType',
|
|
583
|
+
operatingSystems: [OS.Darwin],
|
|
572
584
|
transformation: {
|
|
573
585
|
to: (desired) => ({
|
|
574
586
|
propA: 'propA',
|
|
@@ -610,6 +622,7 @@ describe('Resource parameter tests', () => {
|
|
|
610
622
|
getSettings(): ResourceSettings<TestConfig> {
|
|
611
623
|
return {
|
|
612
624
|
id: 'resourceType',
|
|
625
|
+
operatingSystems: [OS.Darwin],
|
|
613
626
|
transformation: {
|
|
614
627
|
to: (desired) => ({
|
|
615
628
|
propA: 'propA',
|
|
@@ -649,6 +662,7 @@ describe('Resource parameter tests', () => {
|
|
|
649
662
|
getSettings(): ResourceSettings<TestConfig> {
|
|
650
663
|
return {
|
|
651
664
|
id: 'resourceType',
|
|
665
|
+
operatingSystems: [OS.Darwin],
|
|
652
666
|
importAndDestroy: {
|
|
653
667
|
requiredParameters: [
|
|
654
668
|
'propA',
|
|
@@ -668,6 +682,7 @@ describe('Resource parameter tests', () => {
|
|
|
668
682
|
getSettings(): ResourceSettings<TestConfig> {
|
|
669
683
|
return {
|
|
670
684
|
id: 'resourceType',
|
|
685
|
+
operatingSystems: [OS.Darwin],
|
|
671
686
|
parameterSettings: {
|
|
672
687
|
propA: { type: 'directory' }
|
|
673
688
|
}
|
|
@@ -695,6 +710,7 @@ describe('Resource parameter tests', () => {
|
|
|
695
710
|
getSettings(): ResourceSettings<TestConfig> {
|
|
696
711
|
return {
|
|
697
712
|
id: 'resourceType',
|
|
713
|
+
operatingSystems: [OS.Darwin],
|
|
698
714
|
parameterSettings: {
|
|
699
715
|
propA: { type: 'string', setting: true },
|
|
700
716
|
propB: { type: 'number' }
|
|
@@ -737,6 +753,7 @@ describe('Resource parameter tests', () => {
|
|
|
737
753
|
getSettings(): ResourceSettings<TestConfig> {
|
|
738
754
|
return {
|
|
739
755
|
id: 'resourceType',
|
|
756
|
+
operatingSystems: [OS.Darwin],
|
|
740
757
|
importAndDestroy: {
|
|
741
758
|
requiredParameters: ['propA'],
|
|
742
759
|
refreshKeys: ['propB', 'propA'],
|
|
@@ -754,6 +771,7 @@ describe('Resource parameter tests', () => {
|
|
|
754
771
|
getSettings(): ResourceSettings<TestConfig> {
|
|
755
772
|
return {
|
|
756
773
|
id: 'resourceType',
|
|
774
|
+
operatingSystems: [OS.Darwin],
|
|
757
775
|
parameterSettings: {
|
|
758
776
|
propA: { type: 'string', isEqual: 'version' }
|
|
759
777
|
}
|
|
@@ -780,6 +798,7 @@ describe('Resource parameter tests', () => {
|
|
|
780
798
|
getSettings(): ResourceSettings<TestConfig> {
|
|
781
799
|
return {
|
|
782
800
|
id: 'resourceType',
|
|
801
|
+
operatingSystems: [OS.Darwin],
|
|
783
802
|
parameterSettings: {
|
|
784
803
|
propD: { type: 'object' }
|
|
785
804
|
}
|
|
@@ -822,6 +841,7 @@ describe('Resource parameter tests', () => {
|
|
|
822
841
|
getSettings(): ResourceSettings<TestConfig> {
|
|
823
842
|
return {
|
|
824
843
|
id: 'resourceType',
|
|
844
|
+
operatingSystems: [OS.Darwin],
|
|
825
845
|
parameterSettings: {
|
|
826
846
|
propD: { type: 'object' }
|
|
827
847
|
}
|
|
@@ -863,6 +883,7 @@ describe('Resource parameter tests', () => {
|
|
|
863
883
|
getSettings(): ResourceSettings<TestConfig> {
|
|
864
884
|
return {
|
|
865
885
|
id: 'resourceType',
|
|
886
|
+
operatingSystems: [OS.Darwin],
|
|
866
887
|
parameterSettings: {
|
|
867
888
|
propD: {
|
|
868
889
|
type: 'array',
|
|
@@ -968,6 +989,7 @@ describe('Resource parameter tests', () => {
|
|
|
968
989
|
getSettings(): ResourceSettings<TestConfig> {
|
|
969
990
|
return {
|
|
970
991
|
id: 'resourceType',
|
|
992
|
+
operatingSystems: [OS.Darwin],
|
|
971
993
|
parameterSettings: {
|
|
972
994
|
propD: { type: 'stateful', definition: sp }
|
|
973
995
|
}
|
|
@@ -1007,6 +1029,7 @@ describe('Resource parameter tests', () => {
|
|
|
1007
1029
|
getSettings(): ResourceSettings<TestConfig> {
|
|
1008
1030
|
return {
|
|
1009
1031
|
id: 'resourceType',
|
|
1032
|
+
operatingSystems: [OS.Darwin],
|
|
1010
1033
|
parameterSettings: {
|
|
1011
1034
|
propA: { type: 'array', itemType: 'version' }
|
|
1012
1035
|
}
|
|
@@ -1036,6 +1059,7 @@ describe('Resource parameter tests', () => {
|
|
|
1036
1059
|
getSettings(): ResourceSettings<TestConfig> {
|
|
1037
1060
|
return {
|
|
1038
1061
|
id: 'resourceType',
|
|
1062
|
+
operatingSystems: [OS.Darwin],
|
|
1039
1063
|
parameterSettings: {
|
|
1040
1064
|
propA: { type: 'array', itemType: 'directory' }
|
|
1041
1065
|
}
|
|
@@ -1065,6 +1089,7 @@ describe('Resource parameter tests', () => {
|
|
|
1065
1089
|
getSettings(): ResourceSettings<TestConfig> {
|
|
1066
1090
|
return {
|
|
1067
1091
|
id: 'resourceType',
|
|
1092
|
+
operatingSystems: [OS.Darwin],
|
|
1068
1093
|
parameterSettings: {
|
|
1069
1094
|
propA: { type: 'array', itemType: 'directory' }
|
|
1070
1095
|
},
|
|
@@ -1101,6 +1126,7 @@ describe('Resource parameter tests', () => {
|
|
|
1101
1126
|
getSettings(): ResourceSettings<TestConfig> {
|
|
1102
1127
|
return {
|
|
1103
1128
|
id: 'resourceType',
|
|
1129
|
+
operatingSystems: [OS.Darwin],
|
|
1104
1130
|
parameterSettings: {
|
|
1105
1131
|
propA: { type: 'array', itemType: 'directory' }
|
|
1106
1132
|
},
|
|
@@ -1127,6 +1153,7 @@ describe('Resource parameter tests', () => {
|
|
|
1127
1153
|
getSettings(): ResourceSettings<TestConfig> {
|
|
1128
1154
|
return {
|
|
1129
1155
|
id: 'resourceType',
|
|
1156
|
+
operatingSystems: [OS.Darwin],
|
|
1130
1157
|
parameterSettings: {
|
|
1131
1158
|
propA: { type: 'directory' }
|
|
1132
1159
|
},
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { JSONSchemaType } from 'ajv';
|
|
2
|
-
import { StringIndexedObject } from 'codify-schemas';
|
|
2
|
+
import { OS, StringIndexedObject } from 'codify-schemas';
|
|
3
3
|
import isObjectsEqual from 'lodash.isequal'
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
|
|
6
6
|
import { ArrayStatefulParameter, StatefulParameter } from '../stateful-parameter/stateful-parameter.js';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
addVariablesToPath,
|
|
9
|
+
areArraysEqual,
|
|
10
|
+
resolvePathWithVariables,
|
|
11
|
+
tildify,
|
|
12
|
+
untildify
|
|
13
|
+
} from '../utils/internal-utils.js';
|
|
8
14
|
import { RefreshContext } from './resource.js';
|
|
9
15
|
|
|
10
16
|
export interface InputTransformation {
|
|
@@ -22,6 +28,11 @@ export interface ResourceSettings<T extends StringIndexedObject> {
|
|
|
22
28
|
*/
|
|
23
29
|
id: string;
|
|
24
30
|
|
|
31
|
+
/**
|
|
32
|
+
* List of supported operating systems
|
|
33
|
+
*/
|
|
34
|
+
operatingSystems: Array<OS>;
|
|
35
|
+
|
|
25
36
|
/**
|
|
26
37
|
* Schema to validate user configs with. Must be in the format JSON Schema draft07
|
|
27
38
|
*/
|
|
@@ -350,8 +361,9 @@ const ParameterEqualsDefaults: Partial<Record<ParameterSettingType, (a: unknown,
|
|
|
350
361
|
transformedB = path.resolve(transformedB)
|
|
351
362
|
}
|
|
352
363
|
|
|
353
|
-
|
|
354
|
-
|
|
364
|
+
// macOS has case-insensitive filesystem by default, Linux is case-sensitive
|
|
365
|
+
const isCaseSensitive = process.platform === 'linux';
|
|
366
|
+
if (!isCaseSensitive) {
|
|
355
367
|
transformedA = transformedA.toLowerCase();
|
|
356
368
|
transformedB = transformedB.toLowerCase();
|
|
357
369
|
}
|