codify-plugin-test 0.0.53-beta2 → 0.0.53-beta21
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/plugin-process.d.ts +5 -0
- package/dist/plugin-process.js +23 -21
- package/dist/plugin-process.js.map +1 -1
- package/dist/plugin-tester.d.ts +1 -0
- package/dist/plugin-tester.js +59 -7
- package/dist/plugin-tester.js.map +1 -1
- package/dist/spawn.d.ts +1 -0
- package/dist/spawn.js +11 -2
- package/dist/spawn.js.map +1 -1
- package/dist/test-utils.d.ts +39 -1
- package/dist/test-utils.js +98 -2
- package/dist/test-utils.js.map +1 -1
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +22 -1
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +1 -0
- package/src/plugin-process.ts +15 -20
- package/src/plugin-tester.ts +79 -15
- package/src/spawn.ts +6 -2
- package/src/test-utils.test.ts +5 -5
- package/src/test-utils.ts +116 -2
- package/src/utils.ts +25 -2
- package/test/plugin-tester.test.ts +19 -8
- package/test/test-plugin.ts +34 -5
- package/tsconfig.json +1 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA"}
|
package/dist/plugin-process.d.ts
CHANGED
|
@@ -2,6 +2,11 @@ import { ApplyRequestData, ImportRequestData, ImportResponseData, InitializeResp
|
|
|
2
2
|
import { ChildProcess } from 'node:child_process';
|
|
3
3
|
export declare class PluginProcess {
|
|
4
4
|
childProcess: ChildProcess;
|
|
5
|
+
/**
|
|
6
|
+
* PluginTester is a helper class to integration test plugins. It launches plugins via fork() just like CodifyCLI does.
|
|
7
|
+
*
|
|
8
|
+
* @param pluginPath A fully qualified path
|
|
9
|
+
*/
|
|
5
10
|
constructor(pluginPath: string);
|
|
6
11
|
initialize(): Promise<InitializeResponseData>;
|
|
7
12
|
validate(data: ValidateRequestData): Promise<ValidateResponseData>;
|
package/dist/plugin-process.js
CHANGED
|
@@ -2,11 +2,9 @@ import Ajv from 'ajv';
|
|
|
2
2
|
import { CommandRequestDataSchema, IpcMessageSchema, MessageCmd } from 'codify-schemas';
|
|
3
3
|
import { nanoid } from 'nanoid';
|
|
4
4
|
import { fork } from 'node:child_process';
|
|
5
|
-
import fs from 'node:fs/promises';
|
|
6
|
-
import * as os from 'node:os';
|
|
7
5
|
import path from 'node:path';
|
|
8
6
|
import { spawnSafe } from './spawn.js';
|
|
9
|
-
import {
|
|
7
|
+
import { TestUtils } from './test-utils.js';
|
|
10
8
|
const ajv = new Ajv.default({
|
|
11
9
|
strict: true
|
|
12
10
|
});
|
|
@@ -14,12 +12,19 @@ const ipcMessageValidator = ajv.compile(IpcMessageSchema);
|
|
|
14
12
|
const commandRequestValidator = ajv.compile(CommandRequestDataSchema);
|
|
15
13
|
export class PluginProcess {
|
|
16
14
|
childProcess;
|
|
15
|
+
/**
|
|
16
|
+
* PluginTester is a helper class to integration test plugins. It launches plugins via fork() just like CodifyCLI does.
|
|
17
|
+
*
|
|
18
|
+
* @param pluginPath A fully qualified path
|
|
19
|
+
*/
|
|
17
20
|
constructor(pluginPath) {
|
|
18
21
|
if (!path.isAbsolute(pluginPath)) {
|
|
19
22
|
throw new Error('A fully qualified path must be supplied to PluginTester');
|
|
20
23
|
}
|
|
21
24
|
const debug = (process.env.DEBUG) ? ['--inspect-brk=9221'] : [];
|
|
22
25
|
this.childProcess = fork(pluginPath, [], {
|
|
26
|
+
// Use default true to test plugins in secure mode (un-able to request sudo directly)
|
|
27
|
+
// detached: true,
|
|
23
28
|
env: { ...process.env },
|
|
24
29
|
execArgv: ['--import', 'tsx/esm', ...debug],
|
|
25
30
|
stdio: 'pipe',
|
|
@@ -29,35 +34,35 @@ export class PluginProcess {
|
|
|
29
34
|
this.handleIncomingRequests(this.childProcess);
|
|
30
35
|
}
|
|
31
36
|
async initialize() {
|
|
32
|
-
return
|
|
37
|
+
return TestUtils.sendMessageAndAwaitResponse(this.childProcess, {
|
|
33
38
|
cmd: 'initialize',
|
|
34
39
|
data: { verbosityLevel: 3 },
|
|
35
40
|
requestId: nanoid(6),
|
|
36
41
|
});
|
|
37
42
|
}
|
|
38
43
|
async validate(data) {
|
|
39
|
-
return
|
|
44
|
+
return TestUtils.sendMessageAndAwaitResponse(this.childProcess, {
|
|
40
45
|
cmd: 'validate',
|
|
41
46
|
data,
|
|
42
47
|
requestId: nanoid(6),
|
|
43
48
|
});
|
|
44
49
|
}
|
|
45
50
|
async plan(data) {
|
|
46
|
-
return
|
|
51
|
+
return TestUtils.sendMessageAndAwaitResponse(this.childProcess, {
|
|
47
52
|
cmd: 'plan',
|
|
48
53
|
data,
|
|
49
54
|
requestId: nanoid(6),
|
|
50
55
|
});
|
|
51
56
|
}
|
|
52
57
|
async apply(data) {
|
|
53
|
-
return
|
|
58
|
+
return TestUtils.sendMessageAndAwaitResponse(this.childProcess, {
|
|
54
59
|
cmd: 'apply',
|
|
55
60
|
data,
|
|
56
61
|
requestId: nanoid(6),
|
|
57
62
|
});
|
|
58
63
|
}
|
|
59
64
|
async import(data) {
|
|
60
|
-
return
|
|
65
|
+
return TestUtils.sendMessageAndAwaitResponse(this.childProcess, {
|
|
61
66
|
cmd: 'import',
|
|
62
67
|
data,
|
|
63
68
|
requestId: nanoid(6),
|
|
@@ -66,8 +71,9 @@ export class PluginProcess {
|
|
|
66
71
|
kill() {
|
|
67
72
|
this.childProcess.kill();
|
|
68
73
|
}
|
|
69
|
-
handleIncomingRequests(
|
|
70
|
-
|
|
74
|
+
handleIncomingRequests(cp) {
|
|
75
|
+
// Listen for incoming sudo incoming sudo requests
|
|
76
|
+
cp.on('message', async (message) => {
|
|
71
77
|
if (!ipcMessageValidator(message)) {
|
|
72
78
|
throw new Error(`Invalid message from plugin. ${JSON.stringify(message, null, 2)}`);
|
|
73
79
|
}
|
|
@@ -78,7 +84,7 @@ export class PluginProcess {
|
|
|
78
84
|
}
|
|
79
85
|
const { command, options } = data;
|
|
80
86
|
const result = await spawnSafe(command, options);
|
|
81
|
-
|
|
87
|
+
cp.send({
|
|
82
88
|
cmd: MessageCmd.COMMAND_REQUEST + '_Response',
|
|
83
89
|
data: result,
|
|
84
90
|
requestId,
|
|
@@ -89,7 +95,7 @@ export class PluginProcess {
|
|
|
89
95
|
if (!commandRequestValidator(data)) {
|
|
90
96
|
throw new Error(`Invalid sudo request from plugin. ${JSON.stringify(commandRequestValidator.errors, null, 2)}`);
|
|
91
97
|
}
|
|
92
|
-
|
|
98
|
+
cp.send({
|
|
93
99
|
cmd: MessageCmd.PRESS_KEY_TO_CONTINUE_REQUEST + '_Response',
|
|
94
100
|
data: {},
|
|
95
101
|
requestId,
|
|
@@ -97,17 +103,13 @@ export class PluginProcess {
|
|
|
97
103
|
}
|
|
98
104
|
if (message.cmd === MessageCmd.CODIFY_CREDENTIALS_REQUEST) {
|
|
99
105
|
const { requestId } = message;
|
|
100
|
-
const
|
|
101
|
-
if (!
|
|
102
|
-
throw new Error('Unable to
|
|
106
|
+
const testJwt = process.env.VITE_CODIFY_TEST_JWT;
|
|
107
|
+
if (!testJwt) {
|
|
108
|
+
throw new Error('Unable to parse login credentials from VITE_CODIFY_TEST_JWT env var. Please set and try again');
|
|
103
109
|
}
|
|
104
|
-
|
|
105
|
-
if (!login) {
|
|
106
|
-
throw new Error('Unable to parse login credentials');
|
|
107
|
-
}
|
|
108
|
-
process.send({
|
|
110
|
+
cp.send({
|
|
109
111
|
cmd: MessageCmd.CODIFY_CREDENTIALS_REQUEST + '_Response',
|
|
110
|
-
data:
|
|
112
|
+
data: testJwt,
|
|
111
113
|
requestId,
|
|
112
114
|
});
|
|
113
115
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-process.js","sourceRoot":"","sources":["../src/plugin-process.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAGL,wBAAwB,EAIxB,gBAAgB,EAEhB,UAAU,EAKX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAgB,IAAI,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin-process.js","sourceRoot":"","sources":["../src/plugin-process.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAGL,wBAAwB,EAIxB,gBAAgB,EAEhB,UAAU,EAKX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAgB,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAGxD,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC;IAC1B,MAAM,EAAE,IAAI;CACb,CAAC,CAAC;AAEH,MAAM,mBAAmB,GAAG,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC1D,MAAM,uBAAuB,GAAG,GAAG,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC;AAEtE,MAAM,OAAO,aAAa;IACxB,YAAY,CAAc;IAE1B;;;;OAIG;IACH,YAAY,UAAkB;QAC5B,IAAI,CAAC,IAAI,CAAC,UAA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H,CAAC,CAAC,CAAA;IACJ,CAAC;CAEF"}
|
package/dist/plugin-tester.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare class PluginTester {
|
|
|
12
12
|
validateModify?: (plans: PlanResponseData[]) => Promise<void> | void;
|
|
13
13
|
};
|
|
14
14
|
}): Promise<void>;
|
|
15
|
+
static install(pluginPath: string, configs: ResourceConfig[]): Promise<void>;
|
|
15
16
|
static uninstall(pluginPath: string, configs: ResourceConfig[], options?: {
|
|
16
17
|
validateDestroy?: (plans: PlanResponseData[]) => Promise<void> | void;
|
|
17
18
|
}): Promise<void>;
|
package/dist/plugin-tester.js
CHANGED
|
@@ -2,10 +2,13 @@ import chalk from 'chalk';
|
|
|
2
2
|
import { ResourceOperation, } from 'codify-schemas';
|
|
3
3
|
import unionBy from 'lodash.unionby';
|
|
4
4
|
import { PluginProcess } from './plugin-process.js';
|
|
5
|
-
import { splitUserConfig } from './utils.js';
|
|
5
|
+
import { getPlatformOs, splitUserConfig } from './utils.js';
|
|
6
6
|
export class PluginTester {
|
|
7
7
|
static async fullTest(pluginPath, configs, options) {
|
|
8
|
-
|
|
8
|
+
configs = configs.filter((c) => !c.os || c.os.includes(getPlatformOs()));
|
|
9
|
+
const ids = configs
|
|
10
|
+
.map((c) => `${c.type}${c.name ? `.${c.name}` : ''}`)
|
|
11
|
+
.join(', ');
|
|
9
12
|
console.info(chalk.cyan(`Starting full test of [ ${ids} ]...`));
|
|
10
13
|
const { skipUninstall = false, } = options ?? {};
|
|
11
14
|
const plugin = new PluginProcess(pluginPath);
|
|
@@ -16,11 +19,14 @@ export class PluginTester {
|
|
|
16
19
|
if (unsupportedConfigs.length > 0) {
|
|
17
20
|
throw new Error(`The plugin does not support the following configs supplied:\n ${JSON.stringify(unsupportedConfigs, null, 2)}\n Initialize result: ${JSON.stringify(initializeResult)}`);
|
|
18
21
|
}
|
|
22
|
+
// configs = configs.filter((c) => initializeResult.resourceDefinitions.find((rd) => rd.type === c.type)?.operatingSystems?.includes(os.platform() as OS));
|
|
19
23
|
console.info(chalk.cyan('Testing validate...'));
|
|
20
|
-
const validate = await plugin.validate({
|
|
24
|
+
const validate = await plugin.validate({
|
|
25
|
+
configs: configs.map((c) => {
|
|
21
26
|
const { coreParameters, parameters } = splitUserConfig(c);
|
|
22
27
|
return { core: coreParameters, parameters };
|
|
23
|
-
})
|
|
28
|
+
})
|
|
29
|
+
});
|
|
24
30
|
const invalidConfigs = validate.resourceValidations.filter((v) => !v.isValid);
|
|
25
31
|
if (invalidConfigs.length > 0) {
|
|
26
32
|
throw new Error(`The following configs did not validate:\n ${JSON.stringify(invalidConfigs, null, 2)}`);
|
|
@@ -55,7 +61,7 @@ export class PluginTester {
|
|
|
55
61
|
if (!options?.skipImport) {
|
|
56
62
|
const importPlugin = new PluginProcess(pluginPath);
|
|
57
63
|
try {
|
|
58
|
-
await
|
|
64
|
+
await importPlugin.initialize();
|
|
59
65
|
console.info(chalk.cyan('Testing import...'));
|
|
60
66
|
const importResults = [];
|
|
61
67
|
for (const config of configs) {
|
|
@@ -74,7 +80,7 @@ export class PluginTester {
|
|
|
74
80
|
if (options?.testModify) {
|
|
75
81
|
const modifyPlugin = new PluginProcess(pluginPath);
|
|
76
82
|
try {
|
|
77
|
-
await
|
|
83
|
+
await modifyPlugin.initialize();
|
|
78
84
|
console.info(chalk.cyan('Testing modify...'));
|
|
79
85
|
const modifyPlans = [];
|
|
80
86
|
for (const config of options.testModify.modifiedConfigs) {
|
|
@@ -104,6 +110,7 @@ ${JSON.stringify(modifyPlans, null, 2)}`);
|
|
|
104
110
|
}
|
|
105
111
|
}
|
|
106
112
|
if (!skipUninstall) {
|
|
113
|
+
// We need to add unique names to multiple configs with the same type or else it breaks the unionBy below.
|
|
107
114
|
const configsWithNames = this.addNamesToConfigs(configs);
|
|
108
115
|
const modifiedConfigs = this.addNamesToConfigs(options?.testModify?.modifiedConfigs ?? []);
|
|
109
116
|
const id = (config) => config.type + (config.name ? `.${config.name}` : '');
|
|
@@ -111,6 +118,49 @@ ${JSON.stringify(modifyPlans, null, 2)}`);
|
|
|
111
118
|
await this.uninstall(pluginPath, configsToDestroy.toReversed(), options);
|
|
112
119
|
}
|
|
113
120
|
}
|
|
121
|
+
static async install(pluginPath, configs) {
|
|
122
|
+
const plugin = new PluginProcess(pluginPath);
|
|
123
|
+
try {
|
|
124
|
+
console.info(chalk.cyan('Testing initialization...'));
|
|
125
|
+
const initializeResult = await plugin.initialize();
|
|
126
|
+
const unsupportedConfigs = configs.filter((c) => !initializeResult.resourceDefinitions.some((rd) => rd.type === c.type));
|
|
127
|
+
if (unsupportedConfigs.length > 0) {
|
|
128
|
+
throw new Error(`The plugin does not support the following configs supplied:\n ${JSON.stringify(unsupportedConfigs, null, 2)}\n Initialize result: ${JSON.stringify(initializeResult)}`);
|
|
129
|
+
}
|
|
130
|
+
// configs = configs.filter((c) => initializeResult.resourceDefinitions.find((rd) => rd.type === c.type)?.operatingSystems?.includes(os.platform() as OS));
|
|
131
|
+
console.info(chalk.cyan('Testing validate...'));
|
|
132
|
+
const validate = await plugin.validate({
|
|
133
|
+
configs: configs.map((c) => {
|
|
134
|
+
const { coreParameters, parameters } = splitUserConfig(c);
|
|
135
|
+
return { core: coreParameters, parameters };
|
|
136
|
+
})
|
|
137
|
+
});
|
|
138
|
+
const invalidConfigs = validate.resourceValidations.filter((v) => !v.isValid);
|
|
139
|
+
if (invalidConfigs.length > 0) {
|
|
140
|
+
throw new Error(`The following configs did not validate:\n ${JSON.stringify(invalidConfigs, null, 2)}`);
|
|
141
|
+
}
|
|
142
|
+
console.info(chalk.cyan('Testing plan...'));
|
|
143
|
+
const plans = [];
|
|
144
|
+
for (const config of configs) {
|
|
145
|
+
const { coreParameters, parameters } = splitUserConfig(config);
|
|
146
|
+
plans.push(await plugin.plan({
|
|
147
|
+
core: coreParameters,
|
|
148
|
+
desired: parameters,
|
|
149
|
+
isStateful: false,
|
|
150
|
+
state: undefined,
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
console.info(chalk.cyan('Testing apply...'));
|
|
154
|
+
for (const plan of plans) {
|
|
155
|
+
await plugin.apply({
|
|
156
|
+
planId: plan.planId
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
finally {
|
|
161
|
+
plugin.kill();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
114
164
|
static async uninstall(pluginPath, configs, options) {
|
|
115
165
|
const destroyPlugin = new PluginProcess(pluginPath);
|
|
116
166
|
try {
|
|
@@ -148,7 +198,9 @@ ${JSON.stringify(modifyPlans, null, 2)}`);
|
|
|
148
198
|
for (const type of typeSet) {
|
|
149
199
|
const sameTypeConfigs = configs.filter((c) => c.type === type);
|
|
150
200
|
if (sameTypeConfigs.length > 1) {
|
|
151
|
-
sameTypeConfigs.forEach((c, idx) => {
|
|
201
|
+
sameTypeConfigs.forEach((c, idx) => {
|
|
202
|
+
c.name = c.name ?? idx.toString();
|
|
203
|
+
});
|
|
152
204
|
}
|
|
153
205
|
configsWithNames.push(...sameTypeConfigs);
|
|
154
206
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-tester.js","sourceRoot":"","sources":["../src/plugin-tester.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAIL,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAErC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin-tester.js","sourceRoot":"","sources":["../src/plugin-tester.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAIL,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAErC,OAAO,EAAE,aAAa,EAAE,MAAM,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,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAA;gBACnC,CAAC,CAAC,CAAC;YACL,CAAC;YAED,gBAAgB,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,CAAC;QAC5C,CAAC;QAED,OAAO,gBAAgB,CAAC;IAC1B,CAAC;CACF"}
|
package/dist/spawn.d.ts
CHANGED
|
@@ -11,4 +11,5 @@ export interface SpawnOptions {
|
|
|
11
11
|
requiresRoot?: boolean;
|
|
12
12
|
stdin?: boolean;
|
|
13
13
|
}
|
|
14
|
+
export declare function testSpawn(cmd: string, options?: SpawnOptions): Promise<SpawnResult>;
|
|
14
15
|
export declare function spawnSafe(cmd: string, options?: SpawnOptions): Promise<SpawnResult>;
|
package/dist/spawn.js
CHANGED
|
@@ -2,14 +2,19 @@ import * as pty from '@homebridge/node-pty-prebuilt-multiarch';
|
|
|
2
2
|
import { SpawnStatus } from 'codify-schemas';
|
|
3
3
|
import stripAnsi from 'strip-ansi';
|
|
4
4
|
import { Shell, ShellUtils } from './shell.js';
|
|
5
|
+
export function testSpawn(cmd, options) {
|
|
6
|
+
return spawnSafe(cmd, { interactive: true, ...options, });
|
|
7
|
+
}
|
|
5
8
|
export function spawnSafe(cmd, options) {
|
|
6
9
|
if (cmd.toLowerCase().includes('sudo')) {
|
|
7
10
|
throw new Error('Command must not include sudo');
|
|
8
11
|
}
|
|
9
|
-
|
|
12
|
+
console.log(`Running command: ${options?.requiresRoot ? 'sudo' : ''} ${cmd}` + (options?.cwd ? `(${options?.cwd})` : ''));
|
|
10
13
|
return new Promise((resolve) => {
|
|
11
14
|
const output = [];
|
|
12
15
|
const historyIgnore = ShellUtils.getShell() === Shell.ZSH ? { HISTORY_IGNORE: '*' } : { HISTIGNORE: '*' };
|
|
16
|
+
// If TERM_PROGRAM=Apple_Terminal is set then ANSI escape characters may be included
|
|
17
|
+
// in the response.
|
|
13
18
|
const env = {
|
|
14
19
|
...process.env, ...options?.env,
|
|
15
20
|
TERM_PROGRAM: 'codify',
|
|
@@ -17,10 +22,12 @@ export function spawnSafe(cmd, options) {
|
|
|
17
22
|
COLORTERM: 'truecolor',
|
|
18
23
|
...historyIgnore
|
|
19
24
|
};
|
|
20
|
-
|
|
25
|
+
// Initial terminal dimensions
|
|
26
|
+
const initialCols = process.stdout.columns ?? 2000;
|
|
21
27
|
const initialRows = process.stdout.rows ?? 24;
|
|
22
28
|
const command = options?.requiresRoot ? `sudo ${cmd}` : cmd;
|
|
23
29
|
const args = options?.interactive ? ['-i', '-c', command] : ['-c', command];
|
|
30
|
+
// Run the command in a pty for interactivity
|
|
24
31
|
const mPty = pty.spawn(ShellUtils.getDefaultShell(), args, {
|
|
25
32
|
...options,
|
|
26
33
|
cols: initialCols,
|
|
@@ -36,8 +43,10 @@ export function spawnSafe(cmd, options) {
|
|
|
36
43
|
mPty.resize(columns, rows);
|
|
37
44
|
};
|
|
38
45
|
const stdinListener = (data) => {
|
|
46
|
+
// console.log('stdinListener', data);
|
|
39
47
|
mPty.write(data.toString());
|
|
40
48
|
};
|
|
49
|
+
// Listen to resize events for the terminal window;
|
|
41
50
|
process.stdout.on('resize', resizeListener);
|
|
42
51
|
if (options?.stdin) {
|
|
43
52
|
process.stdin.on('data', stdinListener);
|
package/dist/spawn.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spawn.js","sourceRoot":"","sources":["../src/spawn.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,yCAAyC,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAgB/C,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,OAAsB;IAC3D,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,EAA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A;QAED,MAAM,aAAa,GAAG,CAAC,IAAS,EAAE,EAAE;YAClC,sCAAsC;YACtC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC9B,CAAC,CAAA;QAED,mDAAmD;QACnD,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;QAC5C,IAAI,OAAO,EAAE,KAAK,EAAE,CAAC;YACnB,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;QACzC,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE;YACrB,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;YAC7C,IAAI,OAAO,EAAE,KAAK,EAAE,CAAC;gBACnB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;YAC3C,CAAC;YAED,OAAO,CAAC;gBACN,MAAM,EAAE,MAAM,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK;gBACvE,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;aAC1C,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/test-utils.d.ts
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
import { IpcMessageV2 } from 'codify-schemas';
|
|
2
2
|
import { ChildProcess } from 'node:child_process';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const TestUtils: {
|
|
4
4
|
sendMessageAndAwaitResponse(process: ChildProcess, message: IpcMessageV2): Promise<any>;
|
|
5
|
+
ensureHomebrewInstalledOnMacOs(pluginPath: string): Promise<void>;
|
|
6
|
+
ensureXcodeInstalledOnMacOs(pluginPath: string): Promise<void>;
|
|
7
|
+
getShell(): "bash" | "zsh";
|
|
8
|
+
/**
|
|
9
|
+
* Get the primary shell rc file path
|
|
10
|
+
*/
|
|
11
|
+
getPrimaryShellRc(): string;
|
|
12
|
+
/**
|
|
13
|
+
* Get the source command for the shell rc file
|
|
14
|
+
* Usage: execSync(TestUtils.getSourceCommand())
|
|
15
|
+
*/
|
|
16
|
+
getSourceCommand(): string;
|
|
17
|
+
/**
|
|
18
|
+
* Get shell-specific command to run with sourced environment
|
|
19
|
+
* Usage: execSync(TestUtils.getShellCommand('which brew'))
|
|
20
|
+
*/
|
|
21
|
+
getShellCommand(command: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Get shell name for execSync shell option
|
|
24
|
+
*/
|
|
25
|
+
getShellName(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Get interactive shell command
|
|
28
|
+
* Usage: execSync(TestUtils.getInteractiveCommand('my-alias'))
|
|
29
|
+
*/
|
|
30
|
+
getInteractiveCommand(command: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Get which command output format based on shell
|
|
33
|
+
*/
|
|
34
|
+
getAliasWhichCommand(aliasName: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Check if running on macOS
|
|
37
|
+
*/
|
|
38
|
+
isMacOS(): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Check if running on Linux
|
|
41
|
+
*/
|
|
42
|
+
isLinux(): boolean;
|
|
5
43
|
};
|
package/dist/test-utils.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import Ajv from 'ajv';
|
|
2
|
-
import { IpcMessageSchema, MessageStatus } from 'codify-schemas';
|
|
2
|
+
import { IpcMessageSchema, MessageStatus, ResourceOs, SpawnStatus } from 'codify-schemas';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { PluginTester } from './plugin-tester.js';
|
|
6
|
+
import { testSpawn } from './spawn.js';
|
|
3
7
|
const ajv = new Ajv.default({
|
|
4
8
|
strict: true
|
|
5
9
|
});
|
|
6
10
|
const ipcMessageValidator = ajv.compile(IpcMessageSchema);
|
|
7
|
-
export const
|
|
11
|
+
export const TestUtils = {
|
|
8
12
|
sendMessageAndAwaitResponse(process, message) {
|
|
9
13
|
return new Promise((resolve, reject) => {
|
|
10
14
|
process.on('message', (response) => {
|
|
11
15
|
if (!ipcMessageValidator(response)) {
|
|
12
16
|
throw new Error(`Invalid message from plugin. ${JSON.stringify(message, null, 2)}`);
|
|
13
17
|
}
|
|
18
|
+
// Wait for the message response. Other messages such as sudoRequest may be sent before the response returns
|
|
14
19
|
if (response.requestId === message.requestId) {
|
|
15
20
|
if (response.status === MessageStatus.SUCCESS) {
|
|
16
21
|
resolve(response.data);
|
|
@@ -20,8 +25,99 @@ export const CodifyTestUtils = {
|
|
|
20
25
|
}
|
|
21
26
|
}
|
|
22
27
|
});
|
|
28
|
+
// Send message last to ensure listeners are all registered
|
|
23
29
|
process.send(message);
|
|
24
30
|
});
|
|
25
31
|
},
|
|
32
|
+
async ensureHomebrewInstalledOnMacOs(pluginPath) {
|
|
33
|
+
const homebrewQuery = await testSpawn('which homebrew');
|
|
34
|
+
if (homebrewQuery.status !== SpawnStatus.SUCCESS) {
|
|
35
|
+
await PluginTester.install(pluginPath, [{ type: 'homebrew', os: [ResourceOs.MACOS] }]);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
async ensureXcodeInstalledOnMacOs(pluginPath) {
|
|
39
|
+
const xcodeQuery = await testSpawn('xcode-select -p');
|
|
40
|
+
if (xcodeQuery.status !== SpawnStatus.SUCCESS) {
|
|
41
|
+
await PluginTester.install(pluginPath, [{ type: 'xcode-tools', os: [ResourceOs.MACOS] }]);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
getShell() {
|
|
45
|
+
const shell = process.env.SHELL || '';
|
|
46
|
+
if (shell.includes('bash')) {
|
|
47
|
+
return 'bash';
|
|
48
|
+
}
|
|
49
|
+
if (shell.includes('zsh')) {
|
|
50
|
+
return 'zsh';
|
|
51
|
+
}
|
|
52
|
+
// Default to bash for tests
|
|
53
|
+
return 'bash';
|
|
54
|
+
},
|
|
55
|
+
/**
|
|
56
|
+
* Get the primary shell rc file path
|
|
57
|
+
*/
|
|
58
|
+
getPrimaryShellRc() {
|
|
59
|
+
const shell = TestUtils.getShell();
|
|
60
|
+
const homeDir = os.homedir();
|
|
61
|
+
if (shell === 'bash') {
|
|
62
|
+
return path.join(homeDir, '.bashrc');
|
|
63
|
+
}
|
|
64
|
+
if (shell === 'zsh') {
|
|
65
|
+
return path.join(homeDir, '.zshrc');
|
|
66
|
+
}
|
|
67
|
+
throw new Error('Unsupported shell');
|
|
68
|
+
},
|
|
69
|
+
/**
|
|
70
|
+
* Get the source command for the shell rc file
|
|
71
|
+
* Usage: execSync(TestUtils.getSourceCommand())
|
|
72
|
+
*/
|
|
73
|
+
getSourceCommand() {
|
|
74
|
+
return `source ${TestUtils.getPrimaryShellRc()}`;
|
|
75
|
+
},
|
|
76
|
+
/**
|
|
77
|
+
* Get shell-specific command to run with sourced environment
|
|
78
|
+
* Usage: execSync(TestUtils.getShellCommand('which brew'))
|
|
79
|
+
*/
|
|
80
|
+
getShellCommand(command) {
|
|
81
|
+
return `${TestUtils.getSourceCommand()}; ${command}`;
|
|
82
|
+
},
|
|
83
|
+
/**
|
|
84
|
+
* Get shell name for execSync shell option
|
|
85
|
+
*/
|
|
86
|
+
getShellName() {
|
|
87
|
+
return TestUtils.getShell();
|
|
88
|
+
},
|
|
89
|
+
/**
|
|
90
|
+
* Get interactive shell command
|
|
91
|
+
* Usage: execSync(TestUtils.getInteractiveCommand('my-alias'))
|
|
92
|
+
*/
|
|
93
|
+
getInteractiveCommand(command) {
|
|
94
|
+
const shell = TestUtils.getShell();
|
|
95
|
+
return shell === 'bash'
|
|
96
|
+
? `bash -i -c "${command}"`
|
|
97
|
+
: `zsh -i -c "${command}"`;
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
* Get which command output format based on shell
|
|
101
|
+
*/
|
|
102
|
+
getAliasWhichCommand(aliasName) {
|
|
103
|
+
const shell = TestUtils.getShell();
|
|
104
|
+
// zsh outputs: "alias_name: aliased to command"
|
|
105
|
+
// bash outputs: "alias alias_name='command'"
|
|
106
|
+
return shell === 'bash'
|
|
107
|
+
? `${TestUtils.getShellCommand(`alias ${aliasName}`)}`
|
|
108
|
+
: `${TestUtils.getShellCommand(`which ${aliasName}`)}`;
|
|
109
|
+
},
|
|
110
|
+
/**
|
|
111
|
+
* Check if running on macOS
|
|
112
|
+
*/
|
|
113
|
+
isMacOS() {
|
|
114
|
+
return os.platform() === 'darwin';
|
|
115
|
+
},
|
|
116
|
+
/**
|
|
117
|
+
* Check if running on Linux
|
|
118
|
+
*/
|
|
119
|
+
isLinux() {
|
|
120
|
+
return os.platform() === 'linux';
|
|
121
|
+
},
|
|
26
122
|
};
|
|
27
123
|
//# sourceMappingURL=test-utils.js.map
|
package/dist/test-utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAgB,aAAa,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAgB,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAExG,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,SAAS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AM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;IACtC,CAAC;IAED;;;OAGG;IACH,gBAAgB;QACd,OAAO,UAAU,SAAS,CAAC,iBAAiB,EAAE,EAAE,CAAC;IACnD,CAAC;IAED;;;OAGG;IACH,eAAe,CAAC,OAAe;QAC7B,OAAO,GAAG,SAAS,CAAC,gBAAgB,EAAE,KAAK,OAAO,EAAE,CAAC;IACvD,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACH,qBAAqB,CAAC,OAAe;QACnC,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;QAEnC,OAAO,KAAK,KAAK,MAAM;YACrB,CAAC,CAAC,eAAe,OAAO,GAAG;YAC3B,CAAC,CAAC,cAAc,OAAO,GAAG,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,oBAAoB,CAAC,SAAiB;QACpC,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;QAEnC,gDAAgD;QAChD,6CAA6C;QAC7C,OAAO,KAAK,KAAK,MAAM;YACrB,CAAC,CAAC,GAAG,SAAS,CAAC,eAAe,CAAC,SAAS,SAAS,EAAE,CAAC,EAAE;YACtD,CAAC,CAAC,GAAG,SAAS,CAAC,eAAe,CAAC,SAAS,SAAS,EAAE,CAAC,EAAE,CAAC;IAC3D,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,EAAE,CAAC,QAAQ,EAAE,KAAK,QAAQ,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,EAAE,CAAC,QAAQ,EAAE,KAAK,OAAO,CAAC;IACnC,CAAC;CACF,CAAC"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ResourceConfig, StringIndexedObject } from 'codify-schemas';
|
|
1
|
+
import { ResourceConfig, ResourceOs, StringIndexedObject } from 'codify-schemas';
|
|
2
2
|
export declare function splitUserConfig<T extends StringIndexedObject>(config: ResourceConfig & T): {
|
|
3
3
|
parameters: T;
|
|
4
4
|
coreParameters: ResourceConfig;
|
|
5
5
|
};
|
|
6
|
+
export declare function getPlatformOs(): ResourceOs;
|
package/dist/utils.js
CHANGED
|
@@ -1,13 +1,34 @@
|
|
|
1
|
+
import { ResourceOs } from 'codify-schemas';
|
|
2
|
+
import os from 'node:os';
|
|
1
3
|
export function splitUserConfig(config) {
|
|
2
4
|
const coreParameters = {
|
|
3
5
|
type: config.type,
|
|
4
6
|
...(config.name ? { name: config.name } : {}),
|
|
5
7
|
...(config.dependsOn ? { dependsOn: config.dependsOn } : {}),
|
|
8
|
+
...(config.os ? { os: config.os } : {}),
|
|
6
9
|
};
|
|
7
|
-
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
11
|
+
const { type, name, dependsOn, os, ...parameters } = config;
|
|
8
12
|
return {
|
|
9
13
|
parameters: parameters,
|
|
10
14
|
coreParameters,
|
|
11
15
|
};
|
|
12
16
|
}
|
|
17
|
+
export function getPlatformOs() {
|
|
18
|
+
const currOs = os.platform();
|
|
19
|
+
switch (currOs) {
|
|
20
|
+
case 'darwin': {
|
|
21
|
+
return ResourceOs.MACOS;
|
|
22
|
+
}
|
|
23
|
+
case 'linux': {
|
|
24
|
+
return ResourceOs.LINUX;
|
|
25
|
+
}
|
|
26
|
+
case 'win32': {
|
|
27
|
+
return ResourceOs.WINDOWS;
|
|
28
|
+
}
|
|
29
|
+
default: {
|
|
30
|
+
throw new Error(`Unsupported OS: ${currOs}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
13
34
|
//# sourceMappingURL=utils.js.map
|