codify-plugin-test 0.0.53-beta15 → 0.0.53-beta17
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/plugin-process.js +6 -6
- package/dist/plugin-process.js.map +1 -1
- package/dist/plugin-tester.d.ts +1 -0
- package/dist/plugin-tester.js +50 -3
- package/dist/plugin-tester.js.map +1 -1
- package/dist/spawn.js +1 -1
- package/dist/spawn.js.map +1 -1
- package/dist/test-utils.d.ts +38 -1
- package/dist/test-utils.js +90 -2
- package/dist/test-utils.js.map +1 -1
- package/package.json +1 -1
- package/src/plugin-process.ts +6 -6
- package/src/plugin-tester.ts +66 -9
- package/src/spawn.ts +1 -1
- package/src/test-utils.test.ts +5 -5
- package/src/test-utils.ts +108 -2
package/dist/plugin-process.js
CHANGED
|
@@ -4,7 +4,7 @@ import { nanoid } from 'nanoid';
|
|
|
4
4
|
import { fork } from 'node:child_process';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { spawnSafe } from './spawn.js';
|
|
7
|
-
import {
|
|
7
|
+
import { TestUtils } from './test-utils.js';
|
|
8
8
|
const ajv = new Ajv.default({
|
|
9
9
|
strict: true
|
|
10
10
|
});
|
|
@@ -34,35 +34,35 @@ export class PluginProcess {
|
|
|
34
34
|
this.handleIncomingRequests(this.childProcess);
|
|
35
35
|
}
|
|
36
36
|
async initialize() {
|
|
37
|
-
return
|
|
37
|
+
return TestUtils.sendMessageAndAwaitResponse(this.childProcess, {
|
|
38
38
|
cmd: 'initialize',
|
|
39
39
|
data: { verbosityLevel: 3 },
|
|
40
40
|
requestId: nanoid(6),
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
async validate(data) {
|
|
44
|
-
return
|
|
44
|
+
return TestUtils.sendMessageAndAwaitResponse(this.childProcess, {
|
|
45
45
|
cmd: 'validate',
|
|
46
46
|
data,
|
|
47
47
|
requestId: nanoid(6),
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
async plan(data) {
|
|
51
|
-
return
|
|
51
|
+
return TestUtils.sendMessageAndAwaitResponse(this.childProcess, {
|
|
52
52
|
cmd: 'plan',
|
|
53
53
|
data,
|
|
54
54
|
requestId: nanoid(6),
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
async apply(data) {
|
|
58
|
-
return
|
|
58
|
+
return TestUtils.sendMessageAndAwaitResponse(this.childProcess, {
|
|
59
59
|
cmd: 'apply',
|
|
60
60
|
data,
|
|
61
61
|
requestId: nanoid(6),
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
async import(data) {
|
|
65
|
-
return
|
|
65
|
+
return TestUtils.sendMessageAndAwaitResponse(this.childProcess, {
|
|
66
66
|
cmd: 'import',
|
|
67
67
|
data,
|
|
68
68
|
requestId: nanoid(6),
|
|
@@ -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;AAGxD,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,
|
|
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,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oBACR,SAAS;iBACV,CAAC,CAAA;YACJ,CAAC;YAED,IAAI,OAAO,CAAC,GAAG,KAAK,UAAU,CAAC,0BAA0B,EAAE,CAAC;gBAC1D,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;gBAE9B,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC;gBACjD,IAAI,CAAC,OAAO,EAAE,CAAC;oBACb,MAAM,IAAI,KAAK,CAAC,+FAA+F,CAAC,CAAC;gBACnH,CAAC;gBAED,EAAE,CAAC,IAAI,CAAe;oBACpB,GAAG,EAAE,UAAU,CAAC,0BAA0B,GAAG,WAAW;oBACxD,IAAI,EAAE,OAAO;oBACb,SAAS;iBACV,CAAC,CAAA;YACJ,CAAC;QACH,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
|
@@ -21,10 +21,12 @@ export class PluginTester {
|
|
|
21
21
|
}
|
|
22
22
|
// configs = configs.filter((c) => initializeResult.resourceDefinitions.find((rd) => rd.type === c.type)?.operatingSystems?.includes(os.platform() as OS));
|
|
23
23
|
console.info(chalk.cyan('Testing validate...'));
|
|
24
|
-
const validate = await plugin.validate({
|
|
24
|
+
const validate = await plugin.validate({
|
|
25
|
+
configs: configs.map((c) => {
|
|
25
26
|
const { coreParameters, parameters } = splitUserConfig(c);
|
|
26
27
|
return { core: coreParameters, parameters };
|
|
27
|
-
})
|
|
28
|
+
})
|
|
29
|
+
});
|
|
28
30
|
const invalidConfigs = validate.resourceValidations.filter((v) => !v.isValid);
|
|
29
31
|
if (invalidConfigs.length > 0) {
|
|
30
32
|
throw new Error(`The following configs did not validate:\n ${JSON.stringify(invalidConfigs, null, 2)}`);
|
|
@@ -116,6 +118,49 @@ ${JSON.stringify(modifyPlans, null, 2)}`);
|
|
|
116
118
|
await this.uninstall(pluginPath, configsToDestroy.toReversed(), options);
|
|
117
119
|
}
|
|
118
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
|
+
}
|
|
119
164
|
static async uninstall(pluginPath, configs, options) {
|
|
120
165
|
const destroyPlugin = new PluginProcess(pluginPath);
|
|
121
166
|
try {
|
|
@@ -153,7 +198,9 @@ ${JSON.stringify(modifyPlans, null, 2)}`);
|
|
|
153
198
|
for (const type of typeSet) {
|
|
154
199
|
const sameTypeConfigs = configs.filter((c) => c.type === type);
|
|
155
200
|
if (sameTypeConfigs.length > 1) {
|
|
156
|
-
sameTypeConfigs.forEach((c, idx) => {
|
|
201
|
+
sameTypeConfigs.forEach((c, idx) => {
|
|
202
|
+
c.name = c.name ?? idx.toString();
|
|
203
|
+
});
|
|
157
204
|
}
|
|
158
205
|
configsWithNames.push(...sameTypeConfigs);
|
|
159
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,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAG5D,MAAM,OAAO,YAAY;IACvB,MAAM,CAAC,KAAK,CA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K,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;YAC3B,MAAM,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;YAC/D,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC/B,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;oBACjC,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.js
CHANGED
|
@@ -9,7 +9,7 @@ export function spawnSafe(cmd, options) {
|
|
|
9
9
|
if (cmd.toLowerCase().includes('sudo')) {
|
|
10
10
|
throw new Error('Command must not include sudo');
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
console.log(`Running command: ${options?.requiresRoot ? 'sudo' : ''} ${cmd}` + (options?.cwd ? `(${options?.cwd})` : ''));
|
|
13
13
|
return new Promise((resolve) => {
|
|
14
14
|
const output = [];
|
|
15
15
|
const historyIgnore = ShellUtils.getShell() === Shell.ZSH ? { HISTORY_IGNORE: '*' } : { HISTIGNORE: '*' };
|
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,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AACJ,CAAC"}
|
package/dist/test-utils.d.ts
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
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
|
+
ensureHomebrewInstalled(pluginPath: string): Promise<void>;
|
|
6
|
+
getShell(): "bash" | "zsh";
|
|
7
|
+
/**
|
|
8
|
+
* Get the primary shell rc file path
|
|
9
|
+
*/
|
|
10
|
+
getPrimaryShellRc(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Get the source command for the shell rc file
|
|
13
|
+
* Usage: execSync(TestUtils.getSourceCommand())
|
|
14
|
+
*/
|
|
15
|
+
getSourceCommand(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Get shell-specific command to run with sourced environment
|
|
18
|
+
* Usage: execSync(TestUtils.getShellCommand('which brew'))
|
|
19
|
+
*/
|
|
20
|
+
getShellCommand(command: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Get shell name for execSync shell option
|
|
23
|
+
*/
|
|
24
|
+
getShellName(): string;
|
|
25
|
+
/**
|
|
26
|
+
* Get interactive shell command
|
|
27
|
+
* Usage: execSync(TestUtils.getInteractiveCommand('my-alias'))
|
|
28
|
+
*/
|
|
29
|
+
getInteractiveCommand(command: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Get which command output format based on shell
|
|
32
|
+
*/
|
|
33
|
+
getAliasWhichCommand(aliasName: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Check if running on macOS
|
|
36
|
+
*/
|
|
37
|
+
isMacOS(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Check if running on Linux
|
|
40
|
+
*/
|
|
41
|
+
isLinux(): boolean;
|
|
5
42
|
};
|
package/dist/test-utils.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import Ajv from 'ajv';
|
|
2
|
-
import { IpcMessageSchema, MessageStatus } from 'codify-schemas';
|
|
2
|
+
import { IpcMessageSchema, MessageStatus, 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) => {
|
|
@@ -25,5 +29,89 @@ export const CodifyTestUtils = {
|
|
|
25
29
|
process.send(message);
|
|
26
30
|
});
|
|
27
31
|
},
|
|
32
|
+
async ensureHomebrewInstalled(pluginPath) {
|
|
33
|
+
const homebrewQuery = await testSpawn('which homebrew');
|
|
34
|
+
if (homebrewQuery.status !== SpawnStatus.SUCCESS) {
|
|
35
|
+
await PluginTester.install(pluginPath, [{ type: 'homebrew' }]);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
getShell() {
|
|
39
|
+
const shell = process.env.SHELL || '';
|
|
40
|
+
if (shell.includes('bash')) {
|
|
41
|
+
return 'bash';
|
|
42
|
+
}
|
|
43
|
+
if (shell.includes('zsh')) {
|
|
44
|
+
return 'zsh';
|
|
45
|
+
}
|
|
46
|
+
// Default to bash for tests
|
|
47
|
+
return 'bash';
|
|
48
|
+
},
|
|
49
|
+
/**
|
|
50
|
+
* Get the primary shell rc file path
|
|
51
|
+
*/
|
|
52
|
+
getPrimaryShellRc() {
|
|
53
|
+
const shell = TestUtils.getShell();
|
|
54
|
+
const homeDir = os.homedir();
|
|
55
|
+
if (shell === 'bash') {
|
|
56
|
+
return path.join(homeDir, '.bashrc');
|
|
57
|
+
}
|
|
58
|
+
if (shell === 'zsh') {
|
|
59
|
+
return path.join(homeDir, '.zshrc');
|
|
60
|
+
}
|
|
61
|
+
throw new Error('Unsupported shell');
|
|
62
|
+
},
|
|
63
|
+
/**
|
|
64
|
+
* Get the source command for the shell rc file
|
|
65
|
+
* Usage: execSync(TestUtils.getSourceCommand())
|
|
66
|
+
*/
|
|
67
|
+
getSourceCommand() {
|
|
68
|
+
return `source ${TestUtils.getPrimaryShellRc()}`;
|
|
69
|
+
},
|
|
70
|
+
/**
|
|
71
|
+
* Get shell-specific command to run with sourced environment
|
|
72
|
+
* Usage: execSync(TestUtils.getShellCommand('which brew'))
|
|
73
|
+
*/
|
|
74
|
+
getShellCommand(command) {
|
|
75
|
+
return `${TestUtils.getSourceCommand()}; ${command}`;
|
|
76
|
+
},
|
|
77
|
+
/**
|
|
78
|
+
* Get shell name for execSync shell option
|
|
79
|
+
*/
|
|
80
|
+
getShellName() {
|
|
81
|
+
return TestUtils.getShell();
|
|
82
|
+
},
|
|
83
|
+
/**
|
|
84
|
+
* Get interactive shell command
|
|
85
|
+
* Usage: execSync(TestUtils.getInteractiveCommand('my-alias'))
|
|
86
|
+
*/
|
|
87
|
+
getInteractiveCommand(command) {
|
|
88
|
+
const shell = TestUtils.getShell();
|
|
89
|
+
return shell === 'bash'
|
|
90
|
+
? `bash -i -c "${command}"`
|
|
91
|
+
: `zsh -i -c "${command}"`;
|
|
92
|
+
},
|
|
93
|
+
/**
|
|
94
|
+
* Get which command output format based on shell
|
|
95
|
+
*/
|
|
96
|
+
getAliasWhichCommand(aliasName) {
|
|
97
|
+
const shell = TestUtils.getShell();
|
|
98
|
+
// zsh outputs: "alias_name: aliased to command"
|
|
99
|
+
// bash outputs: "alias alias_name='command'"
|
|
100
|
+
return shell === 'bash'
|
|
101
|
+
? `${TestUtils.getShellCommand(`alias ${aliasName}`)}`
|
|
102
|
+
: `${TestUtils.getShellCommand(`which ${aliasName}`)}`;
|
|
103
|
+
},
|
|
104
|
+
/**
|
|
105
|
+
* Check if running on macOS
|
|
106
|
+
*/
|
|
107
|
+
isMacOS() {
|
|
108
|
+
return os.platform() === 'darwin';
|
|
109
|
+
},
|
|
110
|
+
/**
|
|
111
|
+
* Check if running on Linux
|
|
112
|
+
*/
|
|
113
|
+
isLinux() {
|
|
114
|
+
return os.platform() === 'linux';
|
|
115
|
+
},
|
|
28
116
|
};
|
|
29
117
|
//# 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,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE5F,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC;IAC1B,MAAM,EAAE,IAAI;CACb,CAAC,CAAC;AACH,MAAM,mBAAmB,GAAG,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAE1D,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,2BAA2B,CAAC,OAAqB,EAAE,OAAqB;QACtE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,QA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AAE,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/package.json
CHANGED
package/src/plugin-process.ts
CHANGED
|
@@ -21,7 +21,7 @@ import * as os from 'node:os';
|
|
|
21
21
|
import path from 'node:path';
|
|
22
22
|
|
|
23
23
|
import { spawnSafe } from './spawn.js';
|
|
24
|
-
import {
|
|
24
|
+
import { TestUtils } from './test-utils.js';
|
|
25
25
|
|
|
26
26
|
const ajv = new Ajv.default({
|
|
27
27
|
strict: true
|
|
@@ -64,7 +64,7 @@ export class PluginProcess {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
async initialize(): Promise<InitializeResponseData> {
|
|
67
|
-
return
|
|
67
|
+
return TestUtils.sendMessageAndAwaitResponse(this.childProcess, {
|
|
68
68
|
cmd: 'initialize',
|
|
69
69
|
data: { verbosityLevel: 3 },
|
|
70
70
|
requestId: nanoid(6),
|
|
@@ -72,7 +72,7 @@ export class PluginProcess {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
async validate(data: ValidateRequestData): Promise<ValidateResponseData> {
|
|
75
|
-
return
|
|
75
|
+
return TestUtils.sendMessageAndAwaitResponse(this.childProcess, {
|
|
76
76
|
cmd: 'validate',
|
|
77
77
|
data,
|
|
78
78
|
requestId: nanoid(6),
|
|
@@ -80,7 +80,7 @@ export class PluginProcess {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
async plan(data: PlanRequestData): Promise<PlanResponseData> {
|
|
83
|
-
return
|
|
83
|
+
return TestUtils.sendMessageAndAwaitResponse(this.childProcess, {
|
|
84
84
|
cmd: 'plan',
|
|
85
85
|
data,
|
|
86
86
|
requestId: nanoid(6),
|
|
@@ -88,7 +88,7 @@ export class PluginProcess {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
async apply(data: ApplyRequestData): Promise<void> {
|
|
91
|
-
return
|
|
91
|
+
return TestUtils.sendMessageAndAwaitResponse(this.childProcess, {
|
|
92
92
|
cmd: 'apply',
|
|
93
93
|
data,
|
|
94
94
|
requestId: nanoid(6),
|
|
@@ -96,7 +96,7 @@ export class PluginProcess {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
async import(data: ImportRequestData): Promise<ImportResponseData> {
|
|
99
|
-
return
|
|
99
|
+
return TestUtils.sendMessageAndAwaitResponse(this.childProcess, {
|
|
100
100
|
cmd: 'import',
|
|
101
101
|
data,
|
|
102
102
|
requestId: nanoid(6),
|
package/src/plugin-tester.ts
CHANGED
|
@@ -26,7 +26,7 @@ export class PluginTester {
|
|
|
26
26
|
modifiedConfigs: ResourceConfig[],
|
|
27
27
|
validateModify?: (plans: PlanResponseData[]) => Promise<void> | void,
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
}): Promise<void> {
|
|
30
30
|
configs = configs.filter((c) => !c.os || c.os.includes(getPlatformOs()));
|
|
31
31
|
const ids = configs
|
|
32
32
|
.map((c) => `${c.type}${c.name ? `.${c.name}` : ''}`)
|
|
@@ -54,10 +54,12 @@ export class PluginTester {
|
|
|
54
54
|
// configs = configs.filter((c) => initializeResult.resourceDefinitions.find((rd) => rd.type === c.type)?.operatingSystems?.includes(os.platform() as OS));
|
|
55
55
|
|
|
56
56
|
console.info(chalk.cyan('Testing validate...'))
|
|
57
|
-
const validate = await plugin.validate({
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
const validate = await plugin.validate({
|
|
58
|
+
configs: configs.map((c) => {
|
|
59
|
+
const { coreParameters, parameters } = splitUserConfig(c)
|
|
60
|
+
return { core: coreParameters, parameters };
|
|
61
|
+
})
|
|
62
|
+
});
|
|
61
63
|
|
|
62
64
|
const invalidConfigs = validate.resourceValidations.filter((v) => !v.isValid)
|
|
63
65
|
if (invalidConfigs.length > 0) {
|
|
@@ -68,7 +70,7 @@ export class PluginTester {
|
|
|
68
70
|
const plans = [];
|
|
69
71
|
for (const config of configs) {
|
|
70
72
|
const { coreParameters, parameters } = splitUserConfig(config);
|
|
71
|
-
|
|
73
|
+
|
|
72
74
|
plans.push(await plugin.plan({
|
|
73
75
|
core: coreParameters,
|
|
74
76
|
desired: parameters,
|
|
@@ -127,7 +129,7 @@ export class PluginTester {
|
|
|
127
129
|
const modifyPlans = [];
|
|
128
130
|
for (const config of options.testModify.modifiedConfigs) {
|
|
129
131
|
const { coreParameters, parameters } = splitUserConfig(config);
|
|
130
|
-
|
|
132
|
+
|
|
131
133
|
modifyPlans.push(await modifyPlugin.plan({
|
|
132
134
|
core: coreParameters,
|
|
133
135
|
desired: parameters,
|
|
@@ -167,6 +169,59 @@ ${JSON.stringify(modifyPlans, null, 2)}`)
|
|
|
167
169
|
}
|
|
168
170
|
}
|
|
169
171
|
|
|
172
|
+
static async install(pluginPath: string, configs: ResourceConfig[]) {
|
|
173
|
+
const plugin = new PluginProcess(pluginPath);
|
|
174
|
+
|
|
175
|
+
try {
|
|
176
|
+
console.info(chalk.cyan('Testing initialization...'))
|
|
177
|
+
const initializeResult = await plugin.initialize();
|
|
178
|
+
|
|
179
|
+
const unsupportedConfigs = configs.filter((c) =>
|
|
180
|
+
!initializeResult.resourceDefinitions.some((rd) => rd.type === c.type)
|
|
181
|
+
)
|
|
182
|
+
if (unsupportedConfigs.length > 0) {
|
|
183
|
+
throw new Error(`The plugin does not support the following configs supplied:\n ${JSON.stringify(unsupportedConfigs, null, 2)}\n Initialize result: ${JSON.stringify(initializeResult)}`)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// configs = configs.filter((c) => initializeResult.resourceDefinitions.find((rd) => rd.type === c.type)?.operatingSystems?.includes(os.platform() as OS));
|
|
187
|
+
|
|
188
|
+
console.info(chalk.cyan('Testing validate...'))
|
|
189
|
+
const validate = await plugin.validate({
|
|
190
|
+
configs: configs.map((c) => {
|
|
191
|
+
const { coreParameters, parameters } = splitUserConfig(c)
|
|
192
|
+
return { core: coreParameters, parameters };
|
|
193
|
+
})
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const invalidConfigs = validate.resourceValidations.filter((v) => !v.isValid)
|
|
197
|
+
if (invalidConfigs.length > 0) {
|
|
198
|
+
throw new Error(`The following configs did not validate:\n ${JSON.stringify(invalidConfigs, null, 2)}`)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
console.info(chalk.cyan('Testing plan...'))
|
|
202
|
+
const plans = [];
|
|
203
|
+
for (const config of configs) {
|
|
204
|
+
const { coreParameters, parameters } = splitUserConfig(config);
|
|
205
|
+
|
|
206
|
+
plans.push(await plugin.plan({
|
|
207
|
+
core: coreParameters,
|
|
208
|
+
desired: parameters,
|
|
209
|
+
isStateful: false,
|
|
210
|
+
state: undefined,
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
console.info(chalk.cyan('Testing apply...'))
|
|
215
|
+
for (const plan of plans) {
|
|
216
|
+
await plugin.apply({
|
|
217
|
+
planId: plan.planId
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
} finally {
|
|
221
|
+
plugin.kill();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
170
225
|
static async uninstall(pluginPath: string, configs: ResourceConfig[], options?: {
|
|
171
226
|
validateDestroy?: (plans: PlanResponseData[]) => Promise<void> | void
|
|
172
227
|
}) {
|
|
@@ -179,7 +234,7 @@ ${JSON.stringify(modifyPlans, null, 2)}`)
|
|
|
179
234
|
const plans = [];
|
|
180
235
|
for (const config of configs) {
|
|
181
236
|
const { coreParameters, parameters } = splitUserConfig(config);
|
|
182
|
-
|
|
237
|
+
|
|
183
238
|
plans.push(await destroyPlugin.plan({
|
|
184
239
|
core: coreParameters,
|
|
185
240
|
isStateful: true,
|
|
@@ -213,7 +268,9 @@ ${JSON.stringify(modifyPlans, null, 2)}`)
|
|
|
213
268
|
for (const type of typeSet) {
|
|
214
269
|
const sameTypeConfigs = configs.filter((c) => c.type === type);
|
|
215
270
|
if (sameTypeConfigs.length > 1) {
|
|
216
|
-
sameTypeConfigs.forEach((c, idx) => {
|
|
271
|
+
sameTypeConfigs.forEach((c, idx) => {
|
|
272
|
+
c.name = c.name ?? idx.toString()
|
|
273
|
+
});
|
|
217
274
|
}
|
|
218
275
|
|
|
219
276
|
configsWithNames.push(...sameTypeConfigs);
|
package/src/spawn.ts
CHANGED
|
@@ -27,7 +27,7 @@ export function spawnSafe(cmd: string, options?: SpawnOptions): Promise<SpawnRes
|
|
|
27
27
|
throw new Error('Command must not include sudo')
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
console.log(`Running command: ${options?.requiresRoot ? 'sudo' : ''} ${cmd}` + (options?.cwd ? `(${options?.cwd})` : ''))
|
|
31
31
|
|
|
32
32
|
return new Promise((resolve) => {
|
|
33
33
|
const output: string[] = [];
|
package/src/test-utils.test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
2
|
import { ChildProcess } from 'node:child_process';
|
|
3
3
|
import { Readable } from 'stream';
|
|
4
|
-
import {
|
|
4
|
+
import { TestUtils } from './test-utils.js';
|
|
5
5
|
import { describe, expect, it, vi } from 'vitest';
|
|
6
6
|
import { MessageStatus } from 'codify-schemas';
|
|
7
7
|
import { nanoid } from 'nanoid';
|
|
@@ -22,7 +22,7 @@ describe('Test Utils tests', async () => {
|
|
|
22
22
|
const sendMock = vi.spyOn(process, 'send');
|
|
23
23
|
const requestId = nanoid(6);
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
TestUtils.sendMessageAndAwaitResponse(process, { cmd: 'message', data: 'data', requestId })
|
|
26
26
|
|
|
27
27
|
expect(sendMock.mock.calls.length).to.eq(1);
|
|
28
28
|
expect(sendMock.mock.calls[0][0]).to.deep.eq({ cmd: 'message', data: 'data', requestId });
|
|
@@ -38,7 +38,7 @@ describe('Test Utils tests', async () => {
|
|
|
38
38
|
// Note that the response must end in _Response. In accordance to the message schema rules.
|
|
39
39
|
process.emit('message', { cmd: 'message_Response', status: MessageStatus.SUCCESS, data: 'data', requestId })
|
|
40
40
|
})(),
|
|
41
|
-
|
|
41
|
+
TestUtils.sendMessageAndAwaitResponse(process, { cmd: 'message', data: 'data', requestId }),
|
|
42
42
|
]);
|
|
43
43
|
|
|
44
44
|
expect(result[1]).to.eq('data')
|
|
@@ -54,7 +54,7 @@ describe('Test Utils tests', async () => {
|
|
|
54
54
|
// Note that the response must end in _Response. In accordance to the message schema rules.
|
|
55
55
|
process.emit('message', { cmd: 'message_Response', status: MessageStatus.ERROR, data: 'error message', requestId })
|
|
56
56
|
})(),
|
|
57
|
-
|
|
57
|
+
TestUtils.sendMessageAndAwaitResponse(process, { cmd: 'message', data: 'data', requestId }),
|
|
58
58
|
])).rejects.toThrowError(new Error('error message'))
|
|
59
59
|
});
|
|
60
60
|
|
|
@@ -70,7 +70,7 @@ describe('Test Utils tests', async () => {
|
|
|
70
70
|
process.emit('message', { cmd: 'randomMessage2', status: MessageStatus.SUCCESS, data: 'message2', requestId: nanoid(6) })
|
|
71
71
|
process.emit('message', { cmd: 'message_Response', status: MessageStatus.SUCCESS, data: 'data', requestId })
|
|
72
72
|
})(),
|
|
73
|
-
|
|
73
|
+
TestUtils.sendMessageAndAwaitResponse(process, { cmd: 'message', data: 'data', requestId }),
|
|
74
74
|
]);
|
|
75
75
|
|
|
76
76
|
// Only the final _Response message should be returned.
|
package/src/test-utils.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import Ajv from 'ajv';
|
|
2
|
-
import { IpcMessageSchema, IpcMessageV2, MessageStatus } from 'codify-schemas';
|
|
2
|
+
import { IpcMessageSchema, IpcMessageV2, MessageStatus, SpawnStatus } from 'codify-schemas';
|
|
3
3
|
import { ChildProcess } from 'node:child_process';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
|
|
7
|
+
import { PluginTester } from './plugin-tester.js';
|
|
8
|
+
import { testSpawn } from './spawn.js';
|
|
4
9
|
|
|
5
10
|
const ajv = new Ajv.default({
|
|
6
11
|
strict: true
|
|
7
12
|
});
|
|
8
13
|
const ipcMessageValidator = ajv.compile(IpcMessageSchema);
|
|
9
14
|
|
|
10
|
-
export const
|
|
15
|
+
export const TestUtils = {
|
|
11
16
|
sendMessageAndAwaitResponse(process: ChildProcess, message: IpcMessageV2): Promise<any> {
|
|
12
17
|
return new Promise((resolve, reject) => {
|
|
13
18
|
process.on('message', (response: IpcMessageV2) => {
|
|
@@ -30,4 +35,105 @@ export const CodifyTestUtils = {
|
|
|
30
35
|
});
|
|
31
36
|
},
|
|
32
37
|
|
|
38
|
+
async ensureHomebrewInstalled(pluginPath: string) {
|
|
39
|
+
const homebrewQuery = await testSpawn('which homebrew');
|
|
40
|
+
if (homebrewQuery.status !== SpawnStatus.SUCCESS) {
|
|
41
|
+
await PluginTester.install(pluginPath, [{ type: 'homebrew' }])
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
getShell(): 'bash' | 'zsh' {
|
|
46
|
+
const shell = process.env.SHELL || '';
|
|
47
|
+
|
|
48
|
+
if (shell.includes('bash')) {
|
|
49
|
+
return 'bash';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (shell.includes('zsh')) {
|
|
53
|
+
return 'zsh';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Default to bash for tests
|
|
57
|
+
return 'bash';
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Get the primary shell rc file path
|
|
62
|
+
*/
|
|
63
|
+
getPrimaryShellRc(): string {
|
|
64
|
+
const shell = TestUtils.getShell();
|
|
65
|
+
const homeDir = os.homedir();
|
|
66
|
+
|
|
67
|
+
if (shell === 'bash') {
|
|
68
|
+
return path.join(homeDir, '.bashrc')
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (shell === 'zsh') {
|
|
72
|
+
return path.join(homeDir, '.zshrc');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
throw new Error('Unsupported shell')
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Get the source command for the shell rc file
|
|
80
|
+
* Usage: execSync(TestUtils.getSourceCommand())
|
|
81
|
+
*/
|
|
82
|
+
getSourceCommand(): string {
|
|
83
|
+
return `source ${TestUtils.getPrimaryShellRc()}`;
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Get shell-specific command to run with sourced environment
|
|
88
|
+
* Usage: execSync(TestUtils.getShellCommand('which brew'))
|
|
89
|
+
*/
|
|
90
|
+
getShellCommand(command: string): string {
|
|
91
|
+
return `${TestUtils.getSourceCommand()}; ${command}`;
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Get shell name for execSync shell option
|
|
96
|
+
*/
|
|
97
|
+
getShellName(): string {
|
|
98
|
+
return TestUtils.getShell();
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Get interactive shell command
|
|
103
|
+
* Usage: execSync(TestUtils.getInteractiveCommand('my-alias'))
|
|
104
|
+
*/
|
|
105
|
+
getInteractiveCommand(command: string): string {
|
|
106
|
+
const shell = TestUtils.getShell();
|
|
107
|
+
|
|
108
|
+
return shell === 'bash'
|
|
109
|
+
? `bash -i -c "${command}"`
|
|
110
|
+
: `zsh -i -c "${command}"`;
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Get which command output format based on shell
|
|
115
|
+
*/
|
|
116
|
+
getAliasWhichCommand(aliasName: string): string {
|
|
117
|
+
const shell = TestUtils.getShell();
|
|
118
|
+
|
|
119
|
+
// zsh outputs: "alias_name: aliased to command"
|
|
120
|
+
// bash outputs: "alias alias_name='command'"
|
|
121
|
+
return shell === 'bash'
|
|
122
|
+
? `${TestUtils.getShellCommand(`alias ${aliasName}`)}`
|
|
123
|
+
: `${TestUtils.getShellCommand(`which ${aliasName}`)}`;
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Check if running on macOS
|
|
128
|
+
*/
|
|
129
|
+
isMacOS(): boolean {
|
|
130
|
+
return os.platform() === 'darwin';
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Check if running on Linux
|
|
135
|
+
*/
|
|
136
|
+
isLinux(): boolean {
|
|
137
|
+
return os.platform() === 'linux';
|
|
138
|
+
},
|
|
33
139
|
};
|