-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanifest-semver.test.js
More file actions
197 lines (175 loc) · 7.96 KB
/
Copy pathmanifest-semver.test.js
File metadata and controls
197 lines (175 loc) · 7.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// @ts-check
import test from 'node:test'
import assert from 'node:assert/strict'
import { validateManifest } from '../../src/core/manifest.js'
import { matchesSemverRange } from '../../src/core/semver.js'
test('validateManifest accepts the plugin manifest fields the kernel consumes', () => {
const result = validateManifest({
schema_version: 1,
name: '@hypaware/example',
version: '1.2.3',
hypaware_api: '^1.0.0',
runtime: 'node',
entrypoint: './src/index.js',
description: 'Example plugin',
requires: {
plugins: { '@hypaware/ai-gateway': '^1.0.0' },
capabilities: { 'hypaware.blob-store': '^1.0.0' },
},
provides: {
capabilities: { 'hypaware.encoder': '1.0.0' },
},
permissions: ['network'],
contributes: {
commands: [],
},
})
assert.equal(result.ok, true)
assert.equal(result.manifest.name, '@hypaware/example')
})
test('validateManifest rejects malformed nested maps', () => {
const result = validateManifest({
schema_version: 1,
name: '@hypaware/example',
version: '1.2.3',
hypaware_api: '^1.0.0',
runtime: 'node',
entrypoint: './src/index.js',
provides: {
capabilities: { 'hypaware.encoder': 1 },
},
})
assert.equal(result.ok, false)
assert.equal(result.errorKind, 'manifest_invalid')
assert.equal(result.message, 'provides.capabilities must be a map of capability name -> version')
})
/** Minimal valid manifest scaffold for picker-contribution cases. */
function baseManifest(contributes) {
return {
schema_version: 1,
name: '@hypaware/example',
version: '1.2.3',
hypaware_api: '^1.0.0',
runtime: 'node',
entrypoint: './src/index.js',
contributes,
}
}
test('validateManifest accepts a picker array with all three probe variants', () => {
const result = validateManifest(
baseManifest({
picker: [
{ name: 'claude', label: 'Claude Code', summary: 'capture conversations', detect: { settings_file: '.claude/settings.json' } },
{ name: 'claude-desktop', label: 'Claude Desktop', detect: { app_bundle: '/Applications/Claude.app' }, needs_setup: true, configure_command: 'claude-desktop install' },
{ name: 'hermes', label: 'Hermes', detect: { path: '~/.hermes' } },
],
})
)
assert.equal(result.ok, true)
})
test('validateManifest accepts a picker row without a detect probe', () => {
const result = validateManifest(baseManifest({ picker: [{ name: 'otel', label: 'OTEL export' }] }))
assert.equal(result.ok, true)
})
test('validateManifest keeps unknown picker fields opaque (e.g. compose)', () => {
const result = validateManifest(
baseManifest({
picker: [{ name: 'raw-anthropic', label: 'raw Anthropic', compose: { plugin: '@hypaware/claude', requires_gateway: true } }],
})
)
assert.equal(result.ok, true)
})
test('validateManifest rejects a non-array picker', () => {
const result = validateManifest(baseManifest({ picker: { name: 'nope', label: 'nope' } }))
assert.equal(result.ok, false)
assert.equal(result.message, 'contributes.picker must be an array when present')
})
test('validateManifest rejects a picker row missing a name', () => {
const result = validateManifest(baseManifest({ picker: [{ label: 'no name' }] }))
assert.equal(result.ok, false)
assert.equal(result.message, 'contributes.picker entries require a name (string)')
})
test('validateManifest rejects a picker row missing a label', () => {
const result = validateManifest(baseManifest({ picker: [{ name: 'x', summary: 'no label' }] }))
assert.equal(result.ok, false)
assert.equal(result.message, 'contributes.picker entries require a label (string)')
})
test('validateManifest rejects a detect probe with no recognized variant', () => {
const result = validateManifest(baseManifest({ picker: [{ name: 'x', label: 'x', detect: { bogus: 'y' } }] }))
assert.equal(result.ok, false)
assert.equal(
result.message,
'contributes.picker detect must set exactly one of settings_file, app_bundle, path'
)
})
test('validateManifest rejects a detect probe with more than one variant', () => {
const result = validateManifest(
baseManifest({ picker: [{ name: 'x', label: 'x', detect: { app_bundle: '/A.app', path: '~/.a' } }] })
)
assert.equal(result.ok, false)
assert.equal(
result.message,
'contributes.picker detect must set exactly one of settings_file, app_bundle, path'
)
})
test('validateManifest rejects a non-string probe path', () => {
const result = validateManifest(baseManifest({ picker: [{ name: 'x', label: 'x', detect: { path: 5 } }] }))
assert.equal(result.ok, false)
assert.equal(result.message, 'contributes.picker detect.path must be a non-empty string')
})
test('validateManifest rejects a non-boolean needs_setup', () => {
const result = validateManifest(baseManifest({ picker: [{ name: 'x', label: 'x', needs_setup: 'yes' }] }))
assert.equal(result.ok, false)
assert.equal(result.message, 'contributes.picker needs_setup must be a boolean when present')
})
test('validateManifest rejects a non-boolean hidden', () => {
const result = validateManifest(baseManifest({ picker: [{ name: 'x', label: 'x', hidden: 'yes' }] }))
assert.equal(result.ok, false)
assert.equal(result.message, 'contributes.picker hidden must be a boolean when present')
})
test('validateManifest accepts a hidden picker row', () => {
const result = validateManifest(baseManifest({ picker: [{ name: 'x', label: 'x', hidden: true }] }))
assert.equal(result.ok, true)
})
test('matchesSemverRange covers exact, wildcard, caret, tilde, and comparisons', () => {
assert.equal(matchesSemverRange('1.2.3', '1.2.3'), true)
assert.equal(matchesSemverRange('1.2.3', '*'), true)
assert.equal(matchesSemverRange('1.4.0', '^1.2.3'), true)
assert.equal(matchesSemverRange('2.0.0', '^1.2.3'), false)
assert.equal(matchesSemverRange('1.2.9', '~1.2.3'), true)
assert.equal(matchesSemverRange('1.3.0', '~1.2.3'), false)
assert.equal(matchesSemverRange('1.2.4', '>1.2.3'), true)
assert.equal(matchesSemverRange('1.2.3', '>1.2.3'), false)
assert.equal(matchesSemverRange('1.2.3', '<=1.2.3'), true)
})
test('matchesSemverRange preserves zero-major caret behavior', () => {
assert.equal(matchesSemverRange('0.2.5', '^0.2.3'), true)
assert.equal(matchesSemverRange('0.3.0', '^0.2.3'), false)
assert.equal(matchesSemverRange('0.0.3', '^0.0.3'), true)
assert.equal(matchesSemverRange('0.0.4', '^0.0.3'), false)
})
test('matchesSemverRange covers compound, alternative, x and hyphen ranges', () => {
// A compound range is every comparator at once, an alternative set is any
// one of them, and both are shapes an ordinary npm dependency publishes.
assert.equal(matchesSemverRange('1.29.2', '>=1.28.0 <2.0.0'), true)
assert.equal(matchesSemverRange('2.0.0', '>=1.28.0 <2.0.0'), false)
assert.equal(matchesSemverRange('1.29.2', '>= 1.28.0 < 2.0.0'), true)
assert.equal(matchesSemverRange('2.1.0', '^1.29.0 || ^2.0.0'), true)
assert.equal(matchesSemverRange('3.0.0', '^1.29.0 || ^2.0.0'), false)
// An `x` (or an omitted position) stands for the whole span below it, and
// bounds a comparator by where that span ends rather than by 0.
assert.equal(matchesSemverRange('1.29.9', '1.29.x'), true)
assert.equal(matchesSemverRange('1.30.0', '1.29'), false)
assert.equal(matchesSemverRange('0.9.0', '0.x'), true)
assert.equal(matchesSemverRange('1.0.0', '0.x'), false)
assert.equal(matchesSemverRange('1.30.0', '>1.29'), true)
assert.equal(matchesSemverRange('1.29.9', '>1.29'), false)
assert.equal(matchesSemverRange('1.29.9', '<=1.29'), true)
assert.equal(matchesSemverRange('1.2.3', '1.2.3 - 2.0.0'), true)
assert.equal(matchesSemverRange('2.0.0', '1.2.3 - 2.0.0'), true)
assert.equal(matchesSemverRange('2.0.1', '1.2.3 - 2.0.0'), false)
assert.equal(matchesSemverRange('2.0.1', '1.2.3 - 2.0'), true)
// A shape outside the grammar is false rather than a guess.
assert.equal(matchesSemverRange('1.2.3', 'npm:other@1.2.3'), false)
assert.equal(matchesSemverRange('1.2.3', '>=1.2.3 <garbage'), false)
})