Skip to content

Commit 3fcdd4f

Browse files
committed
fix: Changed validation schema to work directly on user import. Fixed tests
1 parent 77189e3 commit 3fcdd4f

10 files changed

Lines changed: 88 additions & 49 deletions

File tree

.github/workflows/unit-test-ci.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ jobs:
1515
node-version: '20.x'
1616
cache: 'npm'
1717
- run: npm ci
18-
- run: tsc
1918
- run: npm run test

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
{
22
"name": "codify-plugin-lib",
3-
"version": "1.0.129",
3+
"version": "1.0.131",
44
"description": "Library plugin library",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",
77
"type": "module",
88
"scripts": {
9-
"test": "vitest"
9+
"test": "vitest",
10+
"posttest": "tsc",
11+
"prepublishOnly": "tsc"
1012
},
1113
"keywords": [],
1214
"author": "",
1315
"license": "ISC",
1416
"dependencies": {
1517
"ajv": "^8.12.0",
1618
"ajv-formats": "^2.1.1",
17-
"codify-schemas": "1.0.61",
19+
"codify-schemas": "1.0.63",
1820
"@npmcli/promise-spawn": "^7.0.1",
1921
"@homebridge/node-pty-prebuilt-multiarch": "^0.12.0-beta.5",
2022
"uuid": "^10.0.0",

src/plugin/plugin.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,49 @@ describe('Plugin tests', () => {
280280
await testPlugin.apply({ plan })
281281
expect(resource.refresh.calledOnce).to.be.true;
282282
})
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+
})
283328
});

src/pty/background-pty.test.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,22 @@ describe('BackgroundPty tests', () => {
1818
});
1919
})
2020

21-
it('Can launch 100 commands in parallel', { timeout: 15000 }, async () => {
22-
const pty = new BackgroundPty();
23-
24-
const fn = async () => pty.spawnSafe('ls');
25-
26-
const results = await Promise.all(
27-
Array.from({ length: 100 }, (_, i) => i + 1)
28-
.map(() => fn())
29-
)
30-
31-
expect(results.length).to.eq(100);
32-
expect(results.every((r) => r.exitCode === 0))
33-
34-
await pty.kill();
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+
// })
3637

3738
it('Reports back the correct exit code and status', async () => {
3839
const pty = new BackgroundPty();

src/pty/index.test.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ describe('General tests for PTYs', () => {
2525

2626
const plugin = Plugin.create('test plugin', [testResource])
2727
const plan = await plugin.plan({
28-
desired: {
29-
type: 'type'
30-
},
28+
core: { type: 'type' },
29+
desired: {},
3130
state: undefined,
3231
isStateful: false,
3332
})
@@ -84,17 +83,15 @@ describe('General tests for PTYs', () => {
8483

8584
const plugin = Plugin.create('test plugin', [testResource1, testResource2]);
8685
await plugin.plan({
87-
desired: {
88-
type: 'type1'
89-
},
86+
core: { type: 'type1' },
87+
desired: {},
9088
state: undefined,
9189
isStateful: false,
9290
})
9391

9492
await plugin.plan({
95-
desired: {
96-
type: 'type2'
97-
},
93+
core: { type: 'type2' },
94+
desired: {},
9895
state: undefined,
9996
isStateful: false,
10097
})

src/pty/vitest.config.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/resource/resource-controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ export class ResourceController<T extends StringIndexedObject> {
5757
core: ResourceConfig,
5858
parameters: Partial<T>,
5959
): Promise<ValidateResponseData['resourceValidations'][0]> {
60+
const originalParameters = structuredClone(parameters);
6061
await this.applyTransformParameters(parameters);
6162
this.addDefaultValues(parameters);
6263

6364
if (this.schemaValidator) {
6465
// Schema validator uses pre transformation parameters
65-
const isValid = this.schemaValidator(parameters);
66+
const isValid = this.schemaValidator(originalParameters);
6667

6768
if (!isValid) {
6869
return {

src/utils/test-utils.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Resource } from '../resource/resource.js';
55
import { CreatePlan, DestroyPlan } from '../plan/plan-types.js';
66
import { ArrayStatefulParameter, StatefulParameter } from '../stateful-parameter/stateful-parameter.js';
77
import { ParsedResourceSettings } from '../resource/parsed-resource-settings.js';
8+
import { describe, it } from 'vitest';
89

910
export function testPlan<T extends StringIndexedObject>(params: {
1011
desired?: Partial<T> | null;
@@ -85,3 +86,8 @@ export class TestArrayStatefulParameter extends ArrayStatefulParameter<TestConfi
8586
return Promise.resolve(undefined);
8687
}
8788
}
89+
90+
describe('Empty tests', () => {
91+
it('empty', () => {
92+
})
93+
})

vitest.config.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import { defaultExclude, defineConfig } from 'vitest/config';
22

33
export default defineConfig({
44
test: {
5+
pool: 'forks',
56
exclude: [
6-
...defaultExclude,
7-
'./src/utils/test-utils.test.ts',
8-
'./src/pty/*'
7+
...defaultExclude
98
]
109
},
1110
});

0 commit comments

Comments
 (0)