@selfhelp/shared 1.2.5 → 1.3.1
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/CHANGELOG.md +341 -326
- package/LICENSE +381 -381
- package/README.md +57 -57
- package/dist/index.d.mts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.js +2 -0
- package/dist/index.mjs +2 -0
- package/package.json +102 -102
- package/src/api/__tests__/endpoints.test.ts +45 -0
- package/src/api/endpoints.ts +2 -0
- package/src/api/index.ts +5 -5
- package/src/assets/__tests__/resolveAssetUrl.test.ts +61 -61
- package/src/assets/index.ts +5 -5
- package/src/assets/resolveAssetUrl.ts +44 -44
- package/src/cms-classes/__tests__/classify.test.ts +63 -63
- package/src/cms-classes/allow-list.ts +158 -158
- package/src/cms-classes/classify.ts +90 -90
- package/src/cms-classes/index.ts +7 -7
- package/src/cms-classes/remap.ts +44 -44
- package/src/condition/__tests__/evaluate.test.ts +54 -54
- package/src/condition/evaluate.ts +121 -121
- package/src/condition/index.ts +5 -5
- package/src/index.ts +25 -25
- package/src/interpolation/__tests__/replaceCalcedValues.test.ts +41 -41
- package/src/interpolation/index.ts +5 -5
- package/src/interpolation/replaceCalcedValues.ts +27 -27
- package/src/plugin-sdk/define.ts +89 -89
- package/src/plugin-sdk/index.ts +103 -103
- package/src/plugin-sdk/lock.ts +124 -124
- package/src/plugin-sdk/manifest.ts +307 -307
- package/src/plugin-sdk/realtime.ts +277 -277
- package/src/plugin-sdk/registry.ts +105 -105
- package/src/plugin-sdk/runtime-shim.ts +140 -140
- package/src/plugin-sdk/types.ts +315 -315
- package/src/plugin-sdk/version.ts +209 -209
- package/src/registry/__tests__/registry.test.ts +135 -135
- package/src/registry/index.ts +94 -94
- package/src/registry/styles.registry.ts +295 -295
- package/src/testing/__tests__/testing-kit.test.ts +228 -228
- package/src/testing/index.ts +483 -483
- package/src/theme/index.ts +6 -6
- package/src/theme/tailwind.ts +73 -73
- package/src/theme/tokens.ts +177 -177
- package/src/types/api/auth.ts +22 -0
- package/src/types/api/envelope.ts +34 -34
- package/src/types/api/forms.ts +76 -76
- package/src/types/api/index.ts +9 -9
- package/src/types/api/language.ts +12 -12
- package/src/types/api/page.ts +9 -9
- package/src/types/index.ts +17 -17
- package/src/types/mantine/common.ts +142 -142
- package/src/types/pages.ts +107 -107
- package/src/types/styles/auth.ts +184 -184
- package/src/types/styles/base.ts +72 -72
- package/src/types/styles/composite.ts +131 -131
- package/src/types/styles/forms.ts +439 -439
- package/src/types/styles/interactive.ts +165 -165
- package/src/types/styles/layout.ts +184 -184
- package/src/types/styles/media.ts +68 -68
- package/src/types/styles/typography.ts +118 -118
- package/src/types/styles/unknown.ts +220 -220
- package/src/utils/__tests__/transformPageData.test.ts +69 -69
- package/src/utils/spacing.ts +64 -64
- package/src/utils/transformPageData.ts +99 -99
|
@@ -1,228 +1,228 @@
|
|
|
1
|
-
/*
|
|
2
|
-
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
-
SPDX-License-Identifier: MPL-2.0
|
|
4
|
-
*/
|
|
5
|
-
import { describe, it, expect } from 'vitest';
|
|
6
|
-
import type { IPluginManifest } from '../../plugin-sdk';
|
|
7
|
-
import {
|
|
8
|
-
CERTIFICATION_CHECKS,
|
|
9
|
-
CERTIFICATION_KIT_VERSION,
|
|
10
|
-
checkCapabilitiesVsTrustLevel,
|
|
11
|
-
checkCompatibilityShape,
|
|
12
|
-
checkDbNaming,
|
|
13
|
-
checkLookupOwnership,
|
|
14
|
-
checkManifestValid,
|
|
15
|
-
definePluginCertification,
|
|
16
|
-
mockMercureHub,
|
|
17
|
-
seedFromLockFile,
|
|
18
|
-
} from '../index';
|
|
19
|
-
|
|
20
|
-
/** A minimal but valid `official` manifest modelled on the SurveyJS plugin. */
|
|
21
|
-
function validManifest(): IPluginManifest {
|
|
22
|
-
return {
|
|
23
|
-
id: 'sh2-shp-survey-js',
|
|
24
|
-
name: 'SurveyJS',
|
|
25
|
-
version: '0.2.20',
|
|
26
|
-
pluginApiVersion: '1.1',
|
|
27
|
-
compatibility: {
|
|
28
|
-
selfhelp: '>=8.0.0-dev <9.0.0',
|
|
29
|
-
php: '^8.4',
|
|
30
|
-
node: '^22',
|
|
31
|
-
react: '^19',
|
|
32
|
-
},
|
|
33
|
-
security: {
|
|
34
|
-
trustLevel: 'official',
|
|
35
|
-
capabilities: [
|
|
36
|
-
'backendBundle',
|
|
37
|
-
'databaseMigrations',
|
|
38
|
-
'readDataTables',
|
|
39
|
-
'writeDataTables',
|
|
40
|
-
'lookupOwnGroup',
|
|
41
|
-
'frontendStyles',
|
|
42
|
-
'adminPages',
|
|
43
|
-
'realtimePublish',
|
|
44
|
-
],
|
|
45
|
-
},
|
|
46
|
-
backend: {
|
|
47
|
-
package: 'humdek/sh2-shp-survey-js',
|
|
48
|
-
bundleClass: 'Humdek\\SurveyJsBundle\\HumdekSurveyJsBundle',
|
|
49
|
-
migrationsNamespace: 'Humdek\\SurveyJsBundle\\Migrations',
|
|
50
|
-
},
|
|
51
|
-
adminPages: [{ slug: 'surveys', label: 'SurveyJS', permission: 'surveyjs.surveys.manage' }],
|
|
52
|
-
realtimeTopics: [{ key: 'surveys/{id}/responses', description: 'responses' }],
|
|
53
|
-
styles: [{ name: 'surveyjs', description: 'survey', canHaveChildren: false }],
|
|
54
|
-
dataAccess: {
|
|
55
|
-
ownedTables: ['surveys', 'survey_runs', 'survey_versions'],
|
|
56
|
-
ownedDataTablePrefix: 'sh2_surveyjs_',
|
|
57
|
-
read: ['data_tables', 'lookups'],
|
|
58
|
-
write: ['data_tables', 'data_cells'],
|
|
59
|
-
},
|
|
60
|
-
lookups: {
|
|
61
|
-
extends: [
|
|
62
|
-
{
|
|
63
|
-
typeCode: 'surveyJsTheme',
|
|
64
|
-
ownership: 'plugin_owned',
|
|
65
|
-
entries: [{ code: 'default', value: 'Default' }],
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
describe('plugin certification kit (contract)', () => {
|
|
73
|
-
it('exposes a stable 1.0.0 kit version + ordered static check list', () => {
|
|
74
|
-
expect(CERTIFICATION_KIT_VERSION).toBe('1.0.0');
|
|
75
|
-
expect(CERTIFICATION_CHECKS).toEqual([
|
|
76
|
-
'manifest-valid',
|
|
77
|
-
'capabilities-vs-trust-level',
|
|
78
|
-
'compatibility-shape',
|
|
79
|
-
'lookup-ownership',
|
|
80
|
-
'db-naming',
|
|
81
|
-
]);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('definePluginCertification returns a suite that runs against a manifest', () => {
|
|
85
|
-
const suite = definePluginCertification({ pluginId: 'sh2-shp-survey-js' });
|
|
86
|
-
expect(suite.pluginId).toBe('sh2-shp-survey-js');
|
|
87
|
-
expect(suite.kitVersion).toBe(CERTIFICATION_KIT_VERSION);
|
|
88
|
-
expect(suite.checks).toEqual(CERTIFICATION_CHECKS);
|
|
89
|
-
|
|
90
|
-
const report = suite.run(validManifest());
|
|
91
|
-
expect(report.passed).toBe(true);
|
|
92
|
-
expect(report.results.map((r) => r.name)).toEqual(CERTIFICATION_CHECKS);
|
|
93
|
-
expect(report.results.every((r) => r.passed)).toBe(true);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('definePluginCertification rejects a missing pluginId', () => {
|
|
97
|
-
expect(() => definePluginCertification({ pluginId: '' })).toThrow(/pluginId is required/);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe('certification checks produce real, specific findings', () => {
|
|
102
|
-
it('manifest-valid flags missing required fields + bad version', () => {
|
|
103
|
-
const result = checkManifestValid({
|
|
104
|
-
...validManifest(),
|
|
105
|
-
id: '',
|
|
106
|
-
version: 'not-semver',
|
|
107
|
-
});
|
|
108
|
-
expect(result.passed).toBe(false);
|
|
109
|
-
expect(result.errors.some((e) => e.includes('id is required'))).toBe(true);
|
|
110
|
-
expect(result.errors.some((e) => e.includes('not valid semver'))).toBe(true);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('capabilities-vs-trust-level rejects an untrusted plugin shipping a bundle', () => {
|
|
114
|
-
const manifest = validManifest();
|
|
115
|
-
const result = checkCapabilitiesVsTrustLevel({
|
|
116
|
-
...manifest,
|
|
117
|
-
security: { trustLevel: 'untrusted', capabilities: ['backendBundle', 'databaseMigrations'] },
|
|
118
|
-
});
|
|
119
|
-
expect(result.passed).toBe(false);
|
|
120
|
-
expect(result.errors.some((e) => e.includes("untrusted plugins may not declare capability 'backendBundle'"))).toBe(
|
|
121
|
-
true,
|
|
122
|
-
);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('capabilities-vs-trust-level flags a declared surface missing its capability', () => {
|
|
126
|
-
const manifest = validManifest();
|
|
127
|
-
const result = checkCapabilitiesVsTrustLevel({
|
|
128
|
-
...manifest,
|
|
129
|
-
security: { trustLevel: 'official', capabilities: [] },
|
|
130
|
-
});
|
|
131
|
-
expect(result.passed).toBe(false);
|
|
132
|
-
expect(result.errors.some((e) => e.includes("'backendBundle'"))).toBe(true);
|
|
133
|
-
expect(result.errors.some((e) => e.includes("'realtimePublish'"))).toBe(true);
|
|
134
|
-
expect(result.errors.some((e) => e.includes("'lookupOwnGroup'"))).toBe(true);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('capabilities-vs-trust-level flags an unknown capability', () => {
|
|
138
|
-
const manifest = validManifest();
|
|
139
|
-
const result = checkCapabilitiesVsTrustLevel({
|
|
140
|
-
...manifest,
|
|
141
|
-
security: { trustLevel: 'official', capabilities: [...manifest.security.capabilities, 'timeTravel'] },
|
|
142
|
-
} as unknown as IPluginManifest);
|
|
143
|
-
expect(result.passed).toBe(false);
|
|
144
|
-
expect(result.errors.some((e) => e.includes("unknown capability 'timeTravel'"))).toBe(true);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('compatibility-shape rejects the per-surface object shape', () => {
|
|
148
|
-
const manifest = validManifest();
|
|
149
|
-
const result = checkCompatibilityShape({
|
|
150
|
-
...manifest,
|
|
151
|
-
compatibility: {
|
|
152
|
-
selfhelp: { backend: '^8.0', shared: '^8.0' },
|
|
153
|
-
} as unknown as IPluginManifest['compatibility'],
|
|
154
|
-
});
|
|
155
|
-
expect(result.passed).toBe(false);
|
|
156
|
-
expect(result.errors.some((e) => e.includes('single-range shape'))).toBe(true);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('compatibility-shape accepts the adopted single-range shape', () => {
|
|
160
|
-
expect(checkCompatibilityShape(validManifest()).passed).toBe(true);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('lookup-ownership rejects an invalid ownership + empty entries', () => {
|
|
164
|
-
const manifest = validManifest();
|
|
165
|
-
const result = checkLookupOwnership({
|
|
166
|
-
...manifest,
|
|
167
|
-
lookups: {
|
|
168
|
-
extends: [{ typeCode: 'surveyJsTheme', ownership: 'world_owned' as never, entries: [] }],
|
|
169
|
-
},
|
|
170
|
-
});
|
|
171
|
-
expect(result.passed).toBe(false);
|
|
172
|
-
expect(result.errors.some((e) => e.includes('invalid ownership'))).toBe(true);
|
|
173
|
-
expect(result.errors.some((e) => e.includes('at least one entry'))).toBe(true);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it('db-naming rejects non snake_case owned tables and a bad prefix', () => {
|
|
177
|
-
const manifest = validManifest();
|
|
178
|
-
const result = checkDbNaming({
|
|
179
|
-
...manifest,
|
|
180
|
-
dataAccess: {
|
|
181
|
-
ownedTables: ['SurveyRuns', 'survey runs'],
|
|
182
|
-
ownedDataTablePrefix: 'SurveyJS',
|
|
183
|
-
},
|
|
184
|
-
});
|
|
185
|
-
expect(result.passed).toBe(false);
|
|
186
|
-
expect(result.errors.some((e) => e.includes("owned table 'SurveyRuns'"))).toBe(true);
|
|
187
|
-
expect(result.errors.some((e) => e.includes('ownedDataTablePrefix'))).toBe(true);
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
describe('mockMercureHub', () => {
|
|
192
|
-
it('records published topics + payloads and supports counting/reset (no polling)', () => {
|
|
193
|
-
const hub = mockMercureHub();
|
|
194
|
-
hub.publish('plugin/sh2-shp-survey-js/progress', { pct: 10 });
|
|
195
|
-
hub.publish('plugin/sh2-shp-survey-js/progress', { pct: 100 });
|
|
196
|
-
hub.publish('plugin/sh2-shp-survey-js/done');
|
|
197
|
-
|
|
198
|
-
expect(hub.updates).toHaveLength(3);
|
|
199
|
-
expect(hub.publishedTopics()).toEqual([
|
|
200
|
-
'plugin/sh2-shp-survey-js/progress',
|
|
201
|
-
'plugin/sh2-shp-survey-js/done',
|
|
202
|
-
]);
|
|
203
|
-
expect(hub.countForTopic('plugin/sh2-shp-survey-js/progress')).toBe(2);
|
|
204
|
-
|
|
205
|
-
hub.reset();
|
|
206
|
-
expect(hub.updates).toHaveLength(0);
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
describe('seedFromLockFile', () => {
|
|
211
|
-
it('extracts plugin id + version pairs from a lock document', () => {
|
|
212
|
-
const seed = seedFromLockFile({
|
|
213
|
-
plugins: {
|
|
214
|
-
'sh2-shp-survey-js': { version: '1.1.0' },
|
|
215
|
-
'sh2-shp-llm': { version: '2.0.1' },
|
|
216
|
-
},
|
|
217
|
-
});
|
|
218
|
-
expect(seed.plugins).toEqual([
|
|
219
|
-
{ pluginId: 'sh2-shp-survey-js', version: '1.1.0' },
|
|
220
|
-
{ pluginId: 'sh2-shp-llm', version: '2.0.1' },
|
|
221
|
-
]);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it('tolerates a missing/empty plugins map', () => {
|
|
225
|
-
expect(seedFromLockFile({}).plugins).toEqual([]);
|
|
226
|
-
expect(seedFromLockFile(null).plugins).toEqual([]);
|
|
227
|
-
});
|
|
228
|
-
});
|
|
1
|
+
/*
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { describe, it, expect } from 'vitest';
|
|
6
|
+
import type { IPluginManifest } from '../../plugin-sdk';
|
|
7
|
+
import {
|
|
8
|
+
CERTIFICATION_CHECKS,
|
|
9
|
+
CERTIFICATION_KIT_VERSION,
|
|
10
|
+
checkCapabilitiesVsTrustLevel,
|
|
11
|
+
checkCompatibilityShape,
|
|
12
|
+
checkDbNaming,
|
|
13
|
+
checkLookupOwnership,
|
|
14
|
+
checkManifestValid,
|
|
15
|
+
definePluginCertification,
|
|
16
|
+
mockMercureHub,
|
|
17
|
+
seedFromLockFile,
|
|
18
|
+
} from '../index';
|
|
19
|
+
|
|
20
|
+
/** A minimal but valid `official` manifest modelled on the SurveyJS plugin. */
|
|
21
|
+
function validManifest(): IPluginManifest {
|
|
22
|
+
return {
|
|
23
|
+
id: 'sh2-shp-survey-js',
|
|
24
|
+
name: 'SurveyJS',
|
|
25
|
+
version: '0.2.20',
|
|
26
|
+
pluginApiVersion: '1.1',
|
|
27
|
+
compatibility: {
|
|
28
|
+
selfhelp: '>=8.0.0-dev <9.0.0',
|
|
29
|
+
php: '^8.4',
|
|
30
|
+
node: '^22',
|
|
31
|
+
react: '^19',
|
|
32
|
+
},
|
|
33
|
+
security: {
|
|
34
|
+
trustLevel: 'official',
|
|
35
|
+
capabilities: [
|
|
36
|
+
'backendBundle',
|
|
37
|
+
'databaseMigrations',
|
|
38
|
+
'readDataTables',
|
|
39
|
+
'writeDataTables',
|
|
40
|
+
'lookupOwnGroup',
|
|
41
|
+
'frontendStyles',
|
|
42
|
+
'adminPages',
|
|
43
|
+
'realtimePublish',
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
backend: {
|
|
47
|
+
package: 'humdek/sh2-shp-survey-js',
|
|
48
|
+
bundleClass: 'Humdek\\SurveyJsBundle\\HumdekSurveyJsBundle',
|
|
49
|
+
migrationsNamespace: 'Humdek\\SurveyJsBundle\\Migrations',
|
|
50
|
+
},
|
|
51
|
+
adminPages: [{ slug: 'surveys', label: 'SurveyJS', permission: 'surveyjs.surveys.manage' }],
|
|
52
|
+
realtimeTopics: [{ key: 'surveys/{id}/responses', description: 'responses' }],
|
|
53
|
+
styles: [{ name: 'surveyjs', description: 'survey', canHaveChildren: false }],
|
|
54
|
+
dataAccess: {
|
|
55
|
+
ownedTables: ['surveys', 'survey_runs', 'survey_versions'],
|
|
56
|
+
ownedDataTablePrefix: 'sh2_surveyjs_',
|
|
57
|
+
read: ['data_tables', 'lookups'],
|
|
58
|
+
write: ['data_tables', 'data_cells'],
|
|
59
|
+
},
|
|
60
|
+
lookups: {
|
|
61
|
+
extends: [
|
|
62
|
+
{
|
|
63
|
+
typeCode: 'surveyJsTheme',
|
|
64
|
+
ownership: 'plugin_owned',
|
|
65
|
+
entries: [{ code: 'default', value: 'Default' }],
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
describe('plugin certification kit (contract)', () => {
|
|
73
|
+
it('exposes a stable 1.0.0 kit version + ordered static check list', () => {
|
|
74
|
+
expect(CERTIFICATION_KIT_VERSION).toBe('1.0.0');
|
|
75
|
+
expect(CERTIFICATION_CHECKS).toEqual([
|
|
76
|
+
'manifest-valid',
|
|
77
|
+
'capabilities-vs-trust-level',
|
|
78
|
+
'compatibility-shape',
|
|
79
|
+
'lookup-ownership',
|
|
80
|
+
'db-naming',
|
|
81
|
+
]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('definePluginCertification returns a suite that runs against a manifest', () => {
|
|
85
|
+
const suite = definePluginCertification({ pluginId: 'sh2-shp-survey-js' });
|
|
86
|
+
expect(suite.pluginId).toBe('sh2-shp-survey-js');
|
|
87
|
+
expect(suite.kitVersion).toBe(CERTIFICATION_KIT_VERSION);
|
|
88
|
+
expect(suite.checks).toEqual(CERTIFICATION_CHECKS);
|
|
89
|
+
|
|
90
|
+
const report = suite.run(validManifest());
|
|
91
|
+
expect(report.passed).toBe(true);
|
|
92
|
+
expect(report.results.map((r) => r.name)).toEqual(CERTIFICATION_CHECKS);
|
|
93
|
+
expect(report.results.every((r) => r.passed)).toBe(true);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('definePluginCertification rejects a missing pluginId', () => {
|
|
97
|
+
expect(() => definePluginCertification({ pluginId: '' })).toThrow(/pluginId is required/);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe('certification checks produce real, specific findings', () => {
|
|
102
|
+
it('manifest-valid flags missing required fields + bad version', () => {
|
|
103
|
+
const result = checkManifestValid({
|
|
104
|
+
...validManifest(),
|
|
105
|
+
id: '',
|
|
106
|
+
version: 'not-semver',
|
|
107
|
+
});
|
|
108
|
+
expect(result.passed).toBe(false);
|
|
109
|
+
expect(result.errors.some((e) => e.includes('id is required'))).toBe(true);
|
|
110
|
+
expect(result.errors.some((e) => e.includes('not valid semver'))).toBe(true);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('capabilities-vs-trust-level rejects an untrusted plugin shipping a bundle', () => {
|
|
114
|
+
const manifest = validManifest();
|
|
115
|
+
const result = checkCapabilitiesVsTrustLevel({
|
|
116
|
+
...manifest,
|
|
117
|
+
security: { trustLevel: 'untrusted', capabilities: ['backendBundle', 'databaseMigrations'] },
|
|
118
|
+
});
|
|
119
|
+
expect(result.passed).toBe(false);
|
|
120
|
+
expect(result.errors.some((e) => e.includes("untrusted plugins may not declare capability 'backendBundle'"))).toBe(
|
|
121
|
+
true,
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('capabilities-vs-trust-level flags a declared surface missing its capability', () => {
|
|
126
|
+
const manifest = validManifest();
|
|
127
|
+
const result = checkCapabilitiesVsTrustLevel({
|
|
128
|
+
...manifest,
|
|
129
|
+
security: { trustLevel: 'official', capabilities: [] },
|
|
130
|
+
});
|
|
131
|
+
expect(result.passed).toBe(false);
|
|
132
|
+
expect(result.errors.some((e) => e.includes("'backendBundle'"))).toBe(true);
|
|
133
|
+
expect(result.errors.some((e) => e.includes("'realtimePublish'"))).toBe(true);
|
|
134
|
+
expect(result.errors.some((e) => e.includes("'lookupOwnGroup'"))).toBe(true);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('capabilities-vs-trust-level flags an unknown capability', () => {
|
|
138
|
+
const manifest = validManifest();
|
|
139
|
+
const result = checkCapabilitiesVsTrustLevel({
|
|
140
|
+
...manifest,
|
|
141
|
+
security: { trustLevel: 'official', capabilities: [...manifest.security.capabilities, 'timeTravel'] },
|
|
142
|
+
} as unknown as IPluginManifest);
|
|
143
|
+
expect(result.passed).toBe(false);
|
|
144
|
+
expect(result.errors.some((e) => e.includes("unknown capability 'timeTravel'"))).toBe(true);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('compatibility-shape rejects the per-surface object shape', () => {
|
|
148
|
+
const manifest = validManifest();
|
|
149
|
+
const result = checkCompatibilityShape({
|
|
150
|
+
...manifest,
|
|
151
|
+
compatibility: {
|
|
152
|
+
selfhelp: { backend: '^8.0', shared: '^8.0' },
|
|
153
|
+
} as unknown as IPluginManifest['compatibility'],
|
|
154
|
+
});
|
|
155
|
+
expect(result.passed).toBe(false);
|
|
156
|
+
expect(result.errors.some((e) => e.includes('single-range shape'))).toBe(true);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('compatibility-shape accepts the adopted single-range shape', () => {
|
|
160
|
+
expect(checkCompatibilityShape(validManifest()).passed).toBe(true);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('lookup-ownership rejects an invalid ownership + empty entries', () => {
|
|
164
|
+
const manifest = validManifest();
|
|
165
|
+
const result = checkLookupOwnership({
|
|
166
|
+
...manifest,
|
|
167
|
+
lookups: {
|
|
168
|
+
extends: [{ typeCode: 'surveyJsTheme', ownership: 'world_owned' as never, entries: [] }],
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
expect(result.passed).toBe(false);
|
|
172
|
+
expect(result.errors.some((e) => e.includes('invalid ownership'))).toBe(true);
|
|
173
|
+
expect(result.errors.some((e) => e.includes('at least one entry'))).toBe(true);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('db-naming rejects non snake_case owned tables and a bad prefix', () => {
|
|
177
|
+
const manifest = validManifest();
|
|
178
|
+
const result = checkDbNaming({
|
|
179
|
+
...manifest,
|
|
180
|
+
dataAccess: {
|
|
181
|
+
ownedTables: ['SurveyRuns', 'survey runs'],
|
|
182
|
+
ownedDataTablePrefix: 'SurveyJS',
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
expect(result.passed).toBe(false);
|
|
186
|
+
expect(result.errors.some((e) => e.includes("owned table 'SurveyRuns'"))).toBe(true);
|
|
187
|
+
expect(result.errors.some((e) => e.includes('ownedDataTablePrefix'))).toBe(true);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
describe('mockMercureHub', () => {
|
|
192
|
+
it('records published topics + payloads and supports counting/reset (no polling)', () => {
|
|
193
|
+
const hub = mockMercureHub();
|
|
194
|
+
hub.publish('plugin/sh2-shp-survey-js/progress', { pct: 10 });
|
|
195
|
+
hub.publish('plugin/sh2-shp-survey-js/progress', { pct: 100 });
|
|
196
|
+
hub.publish('plugin/sh2-shp-survey-js/done');
|
|
197
|
+
|
|
198
|
+
expect(hub.updates).toHaveLength(3);
|
|
199
|
+
expect(hub.publishedTopics()).toEqual([
|
|
200
|
+
'plugin/sh2-shp-survey-js/progress',
|
|
201
|
+
'plugin/sh2-shp-survey-js/done',
|
|
202
|
+
]);
|
|
203
|
+
expect(hub.countForTopic('plugin/sh2-shp-survey-js/progress')).toBe(2);
|
|
204
|
+
|
|
205
|
+
hub.reset();
|
|
206
|
+
expect(hub.updates).toHaveLength(0);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
describe('seedFromLockFile', () => {
|
|
211
|
+
it('extracts plugin id + version pairs from a lock document', () => {
|
|
212
|
+
const seed = seedFromLockFile({
|
|
213
|
+
plugins: {
|
|
214
|
+
'sh2-shp-survey-js': { version: '1.1.0' },
|
|
215
|
+
'sh2-shp-llm': { version: '2.0.1' },
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
expect(seed.plugins).toEqual([
|
|
219
|
+
{ pluginId: 'sh2-shp-survey-js', version: '1.1.0' },
|
|
220
|
+
{ pluginId: 'sh2-shp-llm', version: '2.0.1' },
|
|
221
|
+
]);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('tolerates a missing/empty plugins map', () => {
|
|
225
|
+
expect(seedFromLockFile({}).plugins).toEqual([]);
|
|
226
|
+
expect(seedFromLockFile(null).plugins).toEqual([]);
|
|
227
|
+
});
|
|
228
|
+
});
|