codify-plugin-test 0.0.12 → 0.0.14
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/.eslintrc.json +3 -10
- package/dist/plugin-tester.d.ts +1 -1
- package/dist/plugin-tester.js +23 -24
- package/dist/plugin-tester.js.map +1 -1
- package/package.json +1 -1
- package/src/plugin-tester.ts +27 -28
- package/test/plugin-tester.test.ts +1 -1
package/.eslintrc.json
CHANGED
|
@@ -9,16 +9,9 @@
|
|
|
9
9
|
"warn",
|
|
10
10
|
"always"
|
|
11
11
|
],
|
|
12
|
-
"perfectionist/sort-classes":
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"perfectionist/sort-objects": "off",
|
|
16
|
-
"perfectionist/sort-object-types": "off",
|
|
17
|
-
"unicorn/no-array-reduce": "off",
|
|
18
|
-
"unicorn/no-array-for-each": "off",
|
|
19
|
-
"unicorn/prefer-object-from-entries": "off",
|
|
20
|
-
"unicorn/prefer-type-error": "off",
|
|
21
|
-
"no-await-in-loop": "off",
|
|
12
|
+
"perfectionist/sort-classes": [
|
|
13
|
+
"off"
|
|
14
|
+
],
|
|
22
15
|
"quotes": [
|
|
23
16
|
"error",
|
|
24
17
|
"single"
|
package/dist/plugin-tester.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { ChildProcess } from 'node:child_process';
|
|
|
3
3
|
export declare class PluginTester {
|
|
4
4
|
childProcess: ChildProcess;
|
|
5
5
|
constructor(pluginPath: string);
|
|
6
|
-
fullTest(configs: ResourceConfig[],
|
|
6
|
+
fullTest(configs: ResourceConfig[], assertPlans?: (plans: PlanResponseData[]) => void): Promise<void>;
|
|
7
7
|
uninstall(configs: ResourceConfig[]): Promise<void>;
|
|
8
8
|
initialize(): Promise<InitializeResponseData>;
|
|
9
9
|
validate(data: ValidateRequestData): Promise<ValidateResponseData>;
|
package/dist/plugin-tester.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import Ajv from 'ajv';
|
|
2
|
-
import { IpcMessageSchema, MessageCmd, ResourceOperation, SpawnStatus, SudoRequestDataSchema } from 'codify-schemas';
|
|
2
|
+
import { IpcMessageSchema, MessageCmd, ParameterOperation, ResourceOperation, SpawnStatus, SudoRequestDataSchema } from 'codify-schemas';
|
|
3
3
|
import { fork, spawn } from 'node:child_process';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { CodifyTestUtils } from './test-utils.js';
|
|
6
|
+
import inspector from 'node:inspector';
|
|
6
7
|
const ajv = new Ajv.default({
|
|
7
8
|
strict: true
|
|
8
9
|
});
|
|
@@ -17,11 +18,11 @@ export class PluginTester {
|
|
|
17
18
|
this.childProcess = fork(pluginPath, [], {
|
|
18
19
|
detached: true,
|
|
19
20
|
env: { ...process.env },
|
|
20
|
-
execArgv: ['--import', 'tsx/esm', '--inspect'],
|
|
21
|
+
execArgv: ['--import', 'tsx/esm', isInDebugMode() ? '--inspect-brk=9221' : ''],
|
|
21
22
|
});
|
|
22
23
|
this.handleSudoRequests(this.childProcess);
|
|
23
24
|
}
|
|
24
|
-
async fullTest(configs,
|
|
25
|
+
async fullTest(configs, assertPlans) {
|
|
25
26
|
const initializeResult = await this.initialize();
|
|
26
27
|
const unsupportedConfigs = configs.filter((c) => !initializeResult.resourceDefinitions.some((rd) => rd.type === c.type));
|
|
27
28
|
if (unsupportedConfigs.length > 0) {
|
|
@@ -61,38 +62,33 @@ export class PluginTester {
|
|
|
61
62
|
throw new Error(`The following applies were not successful. Re-running plan shows that the resources did not return no-op but instead returned:
|
|
62
63
|
${JSON.stringify(unsuccessfulPlans, null, 2)}`);
|
|
63
64
|
}
|
|
64
|
-
if (!skipUninstall) {
|
|
65
|
-
await this.uninstall(configs.toReversed());
|
|
66
|
-
}
|
|
67
65
|
}
|
|
68
66
|
async uninstall(configs) {
|
|
69
|
-
const plans = [];
|
|
70
67
|
for (const config of configs) {
|
|
71
|
-
|
|
72
|
-
desired: undefined,
|
|
73
|
-
isStateful: true,
|
|
74
|
-
state: config
|
|
75
|
-
}));
|
|
76
|
-
}
|
|
77
|
-
for (const plan of plans) {
|
|
78
|
-
if (plan.operation !== ResourceOperation.DESTROY) {
|
|
79
|
-
throw new Error(`Expect resource operation to be 'destory' but instead received plan: \n ${JSON.stringify(plan, null, 2)}`);
|
|
80
|
-
}
|
|
68
|
+
const { dependsOn, name, type, ...parameters } = config;
|
|
81
69
|
await this.apply({
|
|
82
|
-
|
|
70
|
+
plan: {
|
|
71
|
+
operation: ResourceOperation.DESTROY,
|
|
72
|
+
parameters: Object.entries(parameters).map(([key, value]) => ({
|
|
73
|
+
name: key,
|
|
74
|
+
newValue: null,
|
|
75
|
+
operation: ParameterOperation.REMOVE,
|
|
76
|
+
previousValue: value,
|
|
77
|
+
})),
|
|
78
|
+
resourceType: type,
|
|
79
|
+
}
|
|
83
80
|
});
|
|
84
|
-
}
|
|
85
|
-
for (const config of configs) {
|
|
86
81
|
const validationPlan = await this.plan({
|
|
87
82
|
desired: config,
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
state: undefined,
|
|
84
|
+
isStateful: false,
|
|
90
85
|
});
|
|
91
86
|
if (validationPlan.operation !== ResourceOperation.CREATE) {
|
|
92
|
-
throw new Error(`Resource was not successfully destroyed.
|
|
87
|
+
throw new Error(`Resource ${type} was not successfully destroyed.
|
|
93
88
|
Validation plan shows:
|
|
94
89
|
${JSON.stringify(validationPlan, null, 2)}
|
|
95
|
-
|
|
90
|
+
Previous config:
|
|
91
|
+
${JSON.stringify(config, null, 2)}`);
|
|
96
92
|
}
|
|
97
93
|
}
|
|
98
94
|
}
|
|
@@ -172,4 +168,7 @@ async function sudoSpawn(cmd, opts) {
|
|
|
172
168
|
});
|
|
173
169
|
});
|
|
174
170
|
}
|
|
171
|
+
function isInDebugMode() {
|
|
172
|
+
return inspector.url() !== undefined;
|
|
173
|
+
}
|
|
175
174
|
//# sourceMappingURL=plugin-tester.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-tester.js","sourceRoot":"","sources":["../src/plugin-tester.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAGL,gBAAgB,EAChB,UAAU,
|
|
1
|
+
{"version":3,"file":"plugin-tester.js","sourceRoot":"","sources":["../src/plugin-tester.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAGL,gBAAgB,EAChB,UAAU,EACV,kBAAkB,EAIlB,iBAAiB,EACjB,WAAW,EAEX,qBAAqB,EAGtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAA8B,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,SAAS,MAAM,gBAAgB,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;AAC1D,MAAM,oBAAoB,GAAG,GAAG,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAEhE,MAAM,OAAO,YAAY;IACvB,YAAY,CAAc;IAO1B,YAAY,UAAkB;QAC5B,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;QAC7E,CAAC;QAED,IAAI,CAAC,YAAY,GAAG,IAAI,CACtB,UAAU,EACV,EAAE,EACF;YAEE,QAAQ,EAAE,IAAI;YACd,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE;YACvB,QAAQ,EAAE,CAAC,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,oBAAoB,CAAC,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,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,aAAa;IACpB,OAAO,SAAS,CAAC,GAAG,EAAE,KAAK,SAAS,CAAC;AACvC,CAAC"}
|
package/package.json
CHANGED
package/src/plugin-tester.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
InitializeResponseData,
|
|
5
5
|
IpcMessageSchema,
|
|
6
6
|
MessageCmd,
|
|
7
|
+
ParameterOperation,
|
|
7
8
|
PlanRequestData,
|
|
8
9
|
PlanResponseData,
|
|
9
10
|
ResourceConfig,
|
|
@@ -18,6 +19,7 @@ import { ChildProcess, SpawnOptions, fork, spawn } from 'node:child_process';
|
|
|
18
19
|
import path from 'node:path';
|
|
19
20
|
|
|
20
21
|
import { CodifyTestUtils } from './test-utils.js';
|
|
22
|
+
import inspector from 'node:inspector';
|
|
21
23
|
|
|
22
24
|
const ajv = new Ajv.default({
|
|
23
25
|
strict: true
|
|
@@ -45,14 +47,14 @@ export class PluginTester {
|
|
|
45
47
|
// Use default true to test plugins in secure mode (un-able to request sudo directly)
|
|
46
48
|
detached: true,
|
|
47
49
|
env: { ...process.env },
|
|
48
|
-
execArgv: ['--import', 'tsx/esm', '--inspect'],
|
|
50
|
+
execArgv: ['--import', 'tsx/esm', isInDebugMode() ? '--inspect-brk=9221' : ''],
|
|
49
51
|
},
|
|
50
52
|
)
|
|
51
53
|
|
|
52
54
|
this.handleSudoRequests(this.childProcess);
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
async fullTest(configs: ResourceConfig[],
|
|
57
|
+
async fullTest(configs: ResourceConfig[], assertPlans?: (plans: PlanResponseData[]) => void): Promise<void> {
|
|
56
58
|
const initializeResult = await this.initialize();
|
|
57
59
|
|
|
58
60
|
const unsupportedConfigs = configs.filter((c) =>
|
|
@@ -104,45 +106,38 @@ export class PluginTester {
|
|
|
104
106
|
${JSON.stringify(unsuccessfulPlans, null, 2)}`
|
|
105
107
|
)
|
|
106
108
|
}
|
|
107
|
-
|
|
108
|
-
if (!skipUninstall) {
|
|
109
|
-
await this.uninstall(configs.toReversed());
|
|
110
|
-
}
|
|
111
109
|
}
|
|
112
110
|
|
|
113
111
|
async uninstall(configs: ResourceConfig[]) {
|
|
114
|
-
const plans = [];
|
|
115
|
-
|
|
116
112
|
for (const config of configs) {
|
|
117
|
-
|
|
118
|
-
desired: undefined,
|
|
119
|
-
isStateful: true,
|
|
120
|
-
state: config
|
|
121
|
-
}))
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
for (const plan of plans) {
|
|
125
|
-
if (plan.operation !== ResourceOperation.DESTROY) {
|
|
126
|
-
throw new Error(`Expect resource operation to be 'destory' but instead received plan: \n ${JSON.stringify(plan, null, 2)}`)
|
|
127
|
-
}
|
|
113
|
+
const { dependsOn, name, type, ...parameters } = config
|
|
128
114
|
|
|
129
115
|
await this.apply({
|
|
130
|
-
|
|
116
|
+
plan: {
|
|
117
|
+
operation: ResourceOperation.DESTROY,
|
|
118
|
+
parameters: Object.entries(parameters).map(([key, value]) => ({
|
|
119
|
+
name: key,
|
|
120
|
+
newValue: null,
|
|
121
|
+
operation: ParameterOperation.REMOVE,
|
|
122
|
+
previousValue: value,
|
|
123
|
+
})),
|
|
124
|
+
resourceType: type,
|
|
125
|
+
}
|
|
131
126
|
});
|
|
132
|
-
}
|
|
133
127
|
|
|
134
|
-
|
|
135
|
-
for (const config of configs) {
|
|
128
|
+
// Validate that the destroy was successful
|
|
136
129
|
const validationPlan = await this.plan({
|
|
137
130
|
desired: config,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
})
|
|
131
|
+
state: undefined,
|
|
132
|
+
isStateful: false,
|
|
133
|
+
});
|
|
141
134
|
if (validationPlan.operation !== ResourceOperation.CREATE) {
|
|
142
|
-
throw new Error(`Resource was not successfully destroyed.
|
|
135
|
+
throw new Error(`Resource ${type} was not successfully destroyed.
|
|
143
136
|
Validation plan shows:
|
|
144
137
|
${JSON.stringify(validationPlan, null, 2)}
|
|
145
|
-
|
|
138
|
+
Previous config:
|
|
139
|
+
${JSON.stringify(config, null, 2)}`
|
|
140
|
+
);
|
|
146
141
|
}
|
|
147
142
|
}
|
|
148
143
|
}
|
|
@@ -262,3 +257,7 @@ async function sudoSpawn(
|
|
|
262
257
|
})
|
|
263
258
|
})
|
|
264
259
|
}
|
|
260
|
+
|
|
261
|
+
function isInDebugMode() {
|
|
262
|
+
return inspector.url() !== undefined;
|
|
263
|
+
}
|
|
@@ -139,7 +139,7 @@ describe('Plugin tester integration tests', () => {
|
|
|
139
139
|
propA: 'a',
|
|
140
140
|
propB: 10,
|
|
141
141
|
propC: 'c',
|
|
142
|
-
}],
|
|
142
|
+
}], (plans) => {
|
|
143
143
|
expect(plans[0]).toMatchObject({
|
|
144
144
|
planId: expect.any(String),
|
|
145
145
|
operation: ResourceOperation.NOOP,
|