codify-plugin-lib 1.0.131 → 1.0.132
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/.github/workflows/unit-test-ci.yaml +1 -2
- package/dist/resource/resource-controller.js +2 -1
- package/package.json +2 -1
- package/src/plugin/plugin.test.ts +45 -0
- package/src/pty/background-pty.test.ts +16 -15
- package/src/pty/index.test.ts +6 -9
- package/src/resource/resource-controller.ts +2 -1
- package/src/utils/test-utils.test.ts +6 -0
- package/vitest.config.ts +2 -3
- package/src/pty/vitest.config.ts +0 -11
|
@@ -7,7 +7,7 @@ on: [ push ]
|
|
|
7
7
|
|
|
8
8
|
jobs:
|
|
9
9
|
build-and-test:
|
|
10
|
-
runs-on:
|
|
10
|
+
runs-on: macos-latest
|
|
11
11
|
steps:
|
|
12
12
|
- uses: actions/checkout@v4
|
|
13
13
|
- uses: actions/setup-node@v4
|
|
@@ -15,5 +15,4 @@ jobs:
|
|
|
15
15
|
node-version: '20.x'
|
|
16
16
|
cache: 'npm'
|
|
17
17
|
- run: npm ci
|
|
18
|
-
- run: tsc
|
|
19
18
|
- run: npm run test
|
|
@@ -31,11 +31,12 @@ export class ResourceController {
|
|
|
31
31
|
return this.resource.initialize();
|
|
32
32
|
}
|
|
33
33
|
async validate(core, parameters) {
|
|
34
|
+
const originalParameters = structuredClone(parameters);
|
|
34
35
|
await this.applyTransformParameters(parameters);
|
|
35
36
|
this.addDefaultValues(parameters);
|
|
36
37
|
if (this.schemaValidator) {
|
|
37
38
|
// Schema validator uses pre transformation parameters
|
|
38
|
-
const isValid = this.schemaValidator(
|
|
39
|
+
const isValid = this.schemaValidator(originalParameters);
|
|
39
40
|
if (!isValid) {
|
|
40
41
|
return {
|
|
41
42
|
isValid: false,
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codify-plugin-lib",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.132",
|
|
4
4
|
"description": "Library plugin library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"test": "vitest",
|
|
10
|
+
"posttest": "tsc",
|
|
10
11
|
"prepublishOnly": "tsc"
|
|
11
12
|
},
|
|
12
13
|
"keywords": [],
|
|
@@ -280,4 +280,49 @@ describe('Plugin tests', () => {
|
|
|
280
280
|
await testPlugin.apply({ plan })
|
|
281
281
|
expect(resource.refresh.calledOnce).to.be.true;
|
|
282
282
|
})
|
|
283
|
+
|
|
284
|
+
it('Maintains types for validate', async () => {
|
|
285
|
+
const resource = new class extends TestResource {
|
|
286
|
+
getSettings(): ResourceSettings<TestConfig> {
|
|
287
|
+
return {
|
|
288
|
+
id: 'type',
|
|
289
|
+
schema: {
|
|
290
|
+
'$schema': 'http://json-schema.org/draft-07/schema',
|
|
291
|
+
'$id': 'https://www.codifycli.com/ssh-config.json',
|
|
292
|
+
'type': 'object',
|
|
293
|
+
'properties': {
|
|
294
|
+
'hosts': {
|
|
295
|
+
'description': 'The host blocks inside of the ~/.ssh/config file. See http://man.openbsd.org/OpenBSD-current/man5/ssh_config.5 ',
|
|
296
|
+
'type': 'array',
|
|
297
|
+
'items': {
|
|
298
|
+
'type': 'object',
|
|
299
|
+
'description': 'The individual host blocks inside of the ~/.ssh/config file',
|
|
300
|
+
'properties': {
|
|
301
|
+
'UseKeychain': {
|
|
302
|
+
'type': 'boolean',
|
|
303
|
+
'description': 'A UseKeychain option was introduced in macOS Sierra allowing users to specify whether they would like for the passphrase to be stored in the keychain'
|
|
304
|
+
},
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const plugin = Plugin.create('testPlugin', [resource as any]);
|
|
315
|
+
const result = await plugin.validate({
|
|
316
|
+
configs: [{
|
|
317
|
+
core: { type: 'type' },
|
|
318
|
+
parameters: {
|
|
319
|
+
hosts: [{
|
|
320
|
+
UseKeychain: true,
|
|
321
|
+
}]
|
|
322
|
+
}
|
|
323
|
+
}]
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
console.log(result);
|
|
327
|
+
})
|
|
283
328
|
});
|
|
@@ -18,21 +18,22 @@ describe('BackgroundPty tests', () => {
|
|
|
18
18
|
});
|
|
19
19
|
})
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
21
|
+
// This test takes forever so going to disable for now.
|
|
22
|
+
// it('Can launch 100 commands in parallel', { timeout: 15000 }, async () => {
|
|
23
|
+
// const pty = new BackgroundPty();
|
|
24
|
+
//
|
|
25
|
+
// const fn = async () => pty.spawnSafe('ls');
|
|
26
|
+
//
|
|
27
|
+
// const results = await Promise.all(
|
|
28
|
+
// Array.from({ length: 100 }, (_, i) => i + 1)
|
|
29
|
+
// .map(() => fn())
|
|
30
|
+
// )
|
|
31
|
+
//
|
|
32
|
+
// expect(results.length).to.eq(100);
|
|
33
|
+
// expect(results.every((r) => r.exitCode === 0))
|
|
34
|
+
//
|
|
35
|
+
// await pty.kill();
|
|
36
|
+
// })
|
|
36
37
|
|
|
37
38
|
it('Reports back the correct exit code and status', async () => {
|
|
38
39
|
const pty = new BackgroundPty();
|
package/src/pty/index.test.ts
CHANGED
|
@@ -25,9 +25,8 @@ describe('General tests for PTYs', () => {
|
|
|
25
25
|
|
|
26
26
|
const plugin = Plugin.create('test plugin', [testResource])
|
|
27
27
|
const plan = await plugin.plan({
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
},
|
|
28
|
+
core: { type: 'type' },
|
|
29
|
+
desired: {},
|
|
31
30
|
state: undefined,
|
|
32
31
|
isStateful: false,
|
|
33
32
|
})
|
|
@@ -84,17 +83,15 @@ describe('General tests for PTYs', () => {
|
|
|
84
83
|
|
|
85
84
|
const plugin = Plugin.create('test plugin', [testResource1, testResource2]);
|
|
86
85
|
await plugin.plan({
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
},
|
|
86
|
+
core: { type: 'type1' },
|
|
87
|
+
desired: {},
|
|
90
88
|
state: undefined,
|
|
91
89
|
isStateful: false,
|
|
92
90
|
})
|
|
93
91
|
|
|
94
92
|
await plugin.plan({
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
},
|
|
93
|
+
core: { type: 'type2' },
|
|
94
|
+
desired: {},
|
|
98
95
|
state: undefined,
|
|
99
96
|
isStateful: false,
|
|
100
97
|
})
|
|
@@ -57,12 +57,13 @@ export class ResourceController<T extends StringIndexedObject> {
|
|
|
57
57
|
core: ResourceConfig,
|
|
58
58
|
parameters: Partial<T>,
|
|
59
59
|
): Promise<ValidateResponseData['resourceValidations'][0]> {
|
|
60
|
+
const originalParameters = structuredClone(parameters);
|
|
60
61
|
await this.applyTransformParameters(parameters);
|
|
61
62
|
this.addDefaultValues(parameters);
|
|
62
63
|
|
|
63
64
|
if (this.schemaValidator) {
|
|
64
65
|
// Schema validator uses pre transformation parameters
|
|
65
|
-
const isValid = this.schemaValidator(
|
|
66
|
+
const isValid = this.schemaValidator(originalParameters);
|
|
66
67
|
|
|
67
68
|
if (!isValid) {
|
|
68
69
|
return {
|
|
@@ -5,6 +5,7 @@ import { Resource } from '../resource/resource.js';
|
|
|
5
5
|
import { CreatePlan, DestroyPlan } from '../plan/plan-types.js';
|
|
6
6
|
import { ArrayStatefulParameter, StatefulParameter } from '../stateful-parameter/stateful-parameter.js';
|
|
7
7
|
import { ParsedResourceSettings } from '../resource/parsed-resource-settings.js';
|
|
8
|
+
import { describe, it } from 'vitest';
|
|
8
9
|
|
|
9
10
|
export function testPlan<T extends StringIndexedObject>(params: {
|
|
10
11
|
desired?: Partial<T> | null;
|
|
@@ -85,3 +86,8 @@ export class TestArrayStatefulParameter extends ArrayStatefulParameter<TestConfi
|
|
|
85
86
|
return Promise.resolve(undefined);
|
|
86
87
|
}
|
|
87
88
|
}
|
|
89
|
+
|
|
90
|
+
describe('Empty tests', () => {
|
|
91
|
+
it('empty', () => {
|
|
92
|
+
})
|
|
93
|
+
})
|
package/vitest.config.ts
CHANGED