@vltpkg/query 1.5.0 → 1.6.0

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.
Files changed (210) hide show
  1. package/package.json +10 -12
  2. package/skills/dss-query/REFERENCE.md +0 -125
  3. package/skills/dss-query/SKILL.md +0 -190
  4. package/skills/dss-query/evals/README.md +0 -81
  5. package/skills/dss-query/evals/evals.json +0 -89
  6. package/skills/dss-query/evals/grade.mjs +0 -481
  7. package/src/attribute.ts +0 -190
  8. package/src/combinator.ts +0 -135
  9. package/src/error.ts +0 -78
  10. package/src/id.ts +0 -46
  11. package/src/index.ts +0 -670
  12. package/src/parser.ts +0 -122
  13. package/src/pseudo/abandoned.ts +0 -9
  14. package/src/pseudo/attr.ts +0 -92
  15. package/src/pseudo/built.ts +0 -19
  16. package/src/pseudo/confused.ts +0 -29
  17. package/src/pseudo/cve.ts +0 -93
  18. package/src/pseudo/cwe.ts +0 -97
  19. package/src/pseudo/debug.ts +0 -9
  20. package/src/pseudo/deprecated.ts +0 -9
  21. package/src/pseudo/dev.ts +0 -18
  22. package/src/pseudo/diff.ts +0 -90
  23. package/src/pseudo/dist.ts +0 -148
  24. package/src/pseudo/dynamic.ts +0 -9
  25. package/src/pseudo/empty.ts +0 -15
  26. package/src/pseudo/entropic.ts +0 -9
  27. package/src/pseudo/env.ts +0 -6
  28. package/src/pseudo/eval.ts +0 -9
  29. package/src/pseudo/fs.ts +0 -9
  30. package/src/pseudo/helpers.ts +0 -106
  31. package/src/pseudo/host.ts +0 -111
  32. package/src/pseudo/hostname.ts +0 -156
  33. package/src/pseudo/license.ts +0 -134
  34. package/src/pseudo/link.ts +0 -30
  35. package/src/pseudo/malware.ts +0 -41
  36. package/src/pseudo/minified.ts +0 -9
  37. package/src/pseudo/missing.ts +0 -16
  38. package/src/pseudo/native.ts +0 -9
  39. package/src/pseudo/network.ts +0 -9
  40. package/src/pseudo/obfuscated.ts +0 -9
  41. package/src/pseudo/optional.ts +0 -18
  42. package/src/pseudo/outdated.ts +0 -345
  43. package/src/pseudo/overridden.ts +0 -20
  44. package/src/pseudo/path.ts +0 -146
  45. package/src/pseudo/peer.ts +0 -18
  46. package/src/pseudo/prerelease.ts +0 -47
  47. package/src/pseudo/private.ts +0 -19
  48. package/src/pseudo/prod.ts +0 -18
  49. package/src/pseudo/published.ts +0 -250
  50. package/src/pseudo/registry.ts +0 -29
  51. package/src/pseudo/root.ts +0 -19
  52. package/src/pseudo/scanned.ts +0 -20
  53. package/src/pseudo/score.ts +0 -186
  54. package/src/pseudo/scripts.ts +0 -61
  55. package/src/pseudo/semver.ts +0 -320
  56. package/src/pseudo/severity.ts +0 -231
  57. package/src/pseudo/shell.ts +0 -9
  58. package/src/pseudo/shrinkwrap.ts +0 -9
  59. package/src/pseudo/skill.ts +0 -59
  60. package/src/pseudo/skills.ts +0 -29
  61. package/src/pseudo/spec.ts +0 -131
  62. package/src/pseudo/squat.ts +0 -225
  63. package/src/pseudo/suspicious.ts +0 -9
  64. package/src/pseudo/tracker.ts +0 -9
  65. package/src/pseudo/trivial.ts +0 -9
  66. package/src/pseudo/type.ts +0 -26
  67. package/src/pseudo/undesirable.ts +0 -9
  68. package/src/pseudo/unknown.ts +0 -9
  69. package/src/pseudo/unmaintained.ts +0 -9
  70. package/src/pseudo/unpopular.ts +0 -9
  71. package/src/pseudo/unstable.ts +0 -9
  72. package/src/pseudo/vuln.ts +0 -273
  73. package/src/pseudo/workspace.ts +0 -22
  74. package/src/pseudo.ts +0 -440
  75. package/src/types.ts +0 -206
  76. package/tap-snapshots/test/attribute.ts.test.cjs +0 -304
  77. package/tap-snapshots/test/combinator.ts.test.cjs +0 -333
  78. package/tap-snapshots/test/id.ts.test.cjs +0 -118
  79. package/tap-snapshots/test/parser.ts.test.cjs +0 -344
  80. package/tap-snapshots/test/pseudo/abandoned.ts.test.cjs +0 -18
  81. package/tap-snapshots/test/pseudo/attr.ts.test.cjs +0 -161
  82. package/tap-snapshots/test/pseudo/built.ts.test.cjs +0 -70
  83. package/tap-snapshots/test/pseudo/confused.ts.test.cjs +0 -32
  84. package/tap-snapshots/test/pseudo/cve.ts.test.cjs +0 -49
  85. package/tap-snapshots/test/pseudo/cwe.ts.test.cjs +0 -49
  86. package/tap-snapshots/test/pseudo/debug.ts.test.cjs +0 -18
  87. package/tap-snapshots/test/pseudo/deprecated.ts.test.cjs +0 -18
  88. package/tap-snapshots/test/pseudo/dist.ts.test.cjs +0 -30
  89. package/tap-snapshots/test/pseudo/dynamic.ts.test.cjs +0 -18
  90. package/tap-snapshots/test/pseudo/empty.ts.test.cjs +0 -50
  91. package/tap-snapshots/test/pseudo/entropic.ts.test.cjs +0 -18
  92. package/tap-snapshots/test/pseudo/env.ts.test.cjs +0 -18
  93. package/tap-snapshots/test/pseudo/eval.ts.test.cjs +0 -18
  94. package/tap-snapshots/test/pseudo/fs.ts.test.cjs +0 -18
  95. package/tap-snapshots/test/pseudo/helpers.ts.test.cjs +0 -18
  96. package/tap-snapshots/test/pseudo/hostname.ts.test.cjs +0 -148
  97. package/tap-snapshots/test/pseudo/license.ts.test.cjs +0 -41
  98. package/tap-snapshots/test/pseudo/link.ts.test.cjs +0 -36
  99. package/tap-snapshots/test/pseudo/malware.ts.test.cjs +0 -22
  100. package/tap-snapshots/test/pseudo/minified.ts.test.cjs +0 -18
  101. package/tap-snapshots/test/pseudo/missing.ts.test.cjs +0 -30
  102. package/tap-snapshots/test/pseudo/native.ts.test.cjs +0 -18
  103. package/tap-snapshots/test/pseudo/network.ts.test.cjs +0 -18
  104. package/tap-snapshots/test/pseudo/obfuscated.ts.test.cjs +0 -18
  105. package/tap-snapshots/test/pseudo/outdated.ts.test.cjs +0 -132
  106. package/tap-snapshots/test/pseudo/overridden.ts.test.cjs +0 -75
  107. package/tap-snapshots/test/pseudo/prerelease.ts.test.cjs +0 -101
  108. package/tap-snapshots/test/pseudo/private.ts.test.cjs +0 -38
  109. package/tap-snapshots/test/pseudo/published.ts.test.cjs +0 -171
  110. package/tap-snapshots/test/pseudo/registry.ts.test.cjs +0 -68
  111. package/tap-snapshots/test/pseudo/root.ts.test.cjs +0 -24
  112. package/tap-snapshots/test/pseudo/scanned.ts.test.cjs +0 -18
  113. package/tap-snapshots/test/pseudo/score.ts.test.cjs +0 -239
  114. package/tap-snapshots/test/pseudo/scripts.ts.test.cjs +0 -62
  115. package/tap-snapshots/test/pseudo/semver.ts.test.cjs +0 -575
  116. package/tap-snapshots/test/pseudo/severity.ts.test.cjs +0 -122
  117. package/tap-snapshots/test/pseudo/shell.ts.test.cjs +0 -18
  118. package/tap-snapshots/test/pseudo/shrinkwrap.ts.test.cjs +0 -18
  119. package/tap-snapshots/test/pseudo/skills.ts.test.cjs +0 -19
  120. package/tap-snapshots/test/pseudo/spec.ts.test.cjs +0 -148
  121. package/tap-snapshots/test/pseudo/squat.ts.test.cjs +0 -129
  122. package/tap-snapshots/test/pseudo/suspicious.ts.test.cjs +0 -18
  123. package/tap-snapshots/test/pseudo/tracker.ts.test.cjs +0 -18
  124. package/tap-snapshots/test/pseudo/trivial.ts.test.cjs +0 -18
  125. package/tap-snapshots/test/pseudo/type.ts.test.cjs +0 -51
  126. package/tap-snapshots/test/pseudo/undesirable.ts.test.cjs +0 -18
  127. package/tap-snapshots/test/pseudo/unknown.ts.test.cjs +0 -18
  128. package/tap-snapshots/test/pseudo/unmaintained.ts.test.cjs +0 -18
  129. package/tap-snapshots/test/pseudo/unpopular.ts.test.cjs +0 -18
  130. package/tap-snapshots/test/pseudo/unstable.ts.test.cjs +0 -18
  131. package/tap-snapshots/test/pseudo/vuln.ts.test.cjs +0 -208
  132. package/tap-snapshots/test/pseudo/vulnerable.ts.test.cjs +0 -20
  133. package/tap-snapshots/test/pseudo/workspace.ts.test.cjs +0 -19
  134. package/tap-snapshots/test/pseudo.ts.test.cjs +0 -1247
  135. package/test/attribute.ts +0 -273
  136. package/test/combinator.ts +0 -175
  137. package/test/error.ts +0 -60
  138. package/test/fixtures/graph.ts +0 -999
  139. package/test/fixtures/selector.ts +0 -103
  140. package/test/fixtures/types.ts +0 -7
  141. package/test/id.ts +0 -102
  142. package/test/index.ts +0 -1148
  143. package/test/parser.ts +0 -117
  144. package/test/pseudo/abandoned.ts +0 -98
  145. package/test/pseudo/attr.ts +0 -298
  146. package/test/pseudo/built.ts +0 -214
  147. package/test/pseudo/confused.ts +0 -160
  148. package/test/pseudo/cve.ts +0 -249
  149. package/test/pseudo/cwe.ts +0 -255
  150. package/test/pseudo/debug.ts +0 -98
  151. package/test/pseudo/deprecated.ts +0 -98
  152. package/test/pseudo/dev.ts +0 -61
  153. package/test/pseudo/diff.ts +0 -417
  154. package/test/pseudo/dist.ts +0 -215
  155. package/test/pseudo/dynamic.ts +0 -98
  156. package/test/pseudo/empty.ts +0 -108
  157. package/test/pseudo/entropic.ts +0 -101
  158. package/test/pseudo/env.ts +0 -98
  159. package/test/pseudo/eval.ts +0 -98
  160. package/test/pseudo/fs.ts +0 -98
  161. package/test/pseudo/helpers.ts +0 -370
  162. package/test/pseudo/host-context.ts +0 -276
  163. package/test/pseudo/hostname.ts +0 -314
  164. package/test/pseudo/license.ts +0 -265
  165. package/test/pseudo/link.ts +0 -94
  166. package/test/pseudo/malware.ts +0 -184
  167. package/test/pseudo/minified.ts +0 -98
  168. package/test/pseudo/missing.ts +0 -111
  169. package/test/pseudo/native.ts +0 -98
  170. package/test/pseudo/network.ts +0 -98
  171. package/test/pseudo/obfuscated.ts +0 -98
  172. package/test/pseudo/optional.ts +0 -73
  173. package/test/pseudo/outdated.ts +0 -461
  174. package/test/pseudo/overridden.ts +0 -317
  175. package/test/pseudo/path.ts +0 -680
  176. package/test/pseudo/peer.ts +0 -101
  177. package/test/pseudo/prerelease.ts +0 -279
  178. package/test/pseudo/private.ts +0 -108
  179. package/test/pseudo/prod.ts +0 -61
  180. package/test/pseudo/published.ts +0 -557
  181. package/test/pseudo/registry.ts +0 -122
  182. package/test/pseudo/root.ts +0 -66
  183. package/test/pseudo/scanned.ts +0 -144
  184. package/test/pseudo/score.ts +0 -591
  185. package/test/pseudo/scripts.ts +0 -324
  186. package/test/pseudo/semver.ts +0 -822
  187. package/test/pseudo/severity.ts +0 -342
  188. package/test/pseudo/shell.ts +0 -98
  189. package/test/pseudo/shrinkwrap.ts +0 -98
  190. package/test/pseudo/skill.ts +0 -189
  191. package/test/pseudo/skills.ts +0 -90
  192. package/test/pseudo/spec.ts +0 -525
  193. package/test/pseudo/squat.ts +0 -565
  194. package/test/pseudo/suspicious.ts +0 -98
  195. package/test/pseudo/tracker.ts +0 -98
  196. package/test/pseudo/trivial.ts +0 -98
  197. package/test/pseudo/type.ts +0 -105
  198. package/test/pseudo/undesirable.ts +0 -98
  199. package/test/pseudo/unknown.ts +0 -98
  200. package/test/pseudo/unmaintained.ts +0 -98
  201. package/test/pseudo/unpopular.ts +0 -98
  202. package/test/pseudo/unstable.ts +0 -98
  203. package/test/pseudo/vuln.ts +0 -625
  204. package/test/pseudo/vulnerable.ts +0 -137
  205. package/test/pseudo/workspace.ts +0 -111
  206. package/test/pseudo.ts +0 -584
  207. package/tsconfig.json +0 -3
  208. package/tsconfig.publish.json +0 -19
  209. package/tsconfig.publish.tsbuildinfo +0 -1
  210. package/typedoc.mjs +0 -2
@@ -1,625 +0,0 @@
1
- import t from 'tap'
2
- import { joinDepIDTuple } from '@vltpkg/dep-id'
3
- import { asPostcssNodeWithChildren } from '@vltpkg/dss-parser'
4
- import { parse } from '../../src/parser.ts'
5
- import { asSecurityArchiveLike } from '@vltpkg/security-archive'
6
- import { getSimpleGraph } from '../fixtures/graph.ts'
7
- import {
8
- vuln,
9
- isVulnKind,
10
- asVulnKind,
11
- parseInternals,
12
- } from '../../src/pseudo/vuln.ts'
13
- import type { ParserState } from '../../src/types.ts'
14
-
15
- t.test('selects packages with vulnerability alerts', async t => {
16
- const getState = (query: string, graph = getSimpleGraph()) => {
17
- const ast = parse(query)
18
- const current = ast.first.first
19
- const state: ParserState = {
20
- comment: '',
21
- current,
22
- initial: {
23
- edges: new Set(graph.edges.values()),
24
- nodes: new Set(graph.nodes.values()),
25
- },
26
- partial: {
27
- edges: new Set(graph.edges.values()),
28
- nodes: new Set(graph.nodes.values()),
29
- },
30
- collect: {
31
- edges: new Set(),
32
- nodes: new Set(),
33
- },
34
- cancellable: async () => {},
35
- walk: async i => i,
36
- securityArchive: asSecurityArchiveLike(
37
- new Map([
38
- [
39
- joinDepIDTuple(['registry', '', 'a@1.0.0']),
40
- {
41
- id: joinDepIDTuple(['registry', '', 'a@1.0.0']),
42
- alerts: [{ type: 'criticalCVE' }],
43
- },
44
- ],
45
- [
46
- joinDepIDTuple(['registry', '', 'b@1.0.0']),
47
- {
48
- id: joinDepIDTuple(['registry', '', 'b@1.0.0']),
49
- alerts: [{ type: 'cve' }],
50
- },
51
- ],
52
- [
53
- joinDepIDTuple(['registry', '', 'c@1.0.0']),
54
- {
55
- id: joinDepIDTuple(['registry', '', 'c@1.0.0']),
56
- alerts: [{ type: 'potentialVulnerability' }],
57
- },
58
- ],
59
- [
60
- joinDepIDTuple(['registry', '', 'd@1.0.0']),
61
- {
62
- id: joinDepIDTuple(['registry', '', 'd@1.0.0']),
63
- alerts: [{ type: 'mildCVE' }],
64
- },
65
- ],
66
- [
67
- joinDepIDTuple(['registry', '', 'e@1.0.0']),
68
- {
69
- id: joinDepIDTuple(['registry', '', 'e@1.0.0']),
70
- alerts: [{ type: 'gptSecurity' }],
71
- },
72
- ],
73
- [
74
- joinDepIDTuple(['registry', '', 'f@1.0.0']),
75
- {
76
- id: joinDepIDTuple(['registry', '', 'f@1.0.0']),
77
- alerts: [{ type: 'gptAnomaly' }],
78
- },
79
- ],
80
- [
81
- joinDepIDTuple(['file', 'y']),
82
- {
83
- id: joinDepIDTuple(['file', 'y']),
84
- alerts: [
85
- {
86
- type: 'deprecated',
87
- severity: 'medium' as const,
88
- category: 'maintenance',
89
- key: 'deprecated',
90
- props: { lastPublish: '2020-01-01' },
91
- },
92
- ],
93
- },
94
- ],
95
- ]),
96
- ),
97
- importers: new Set(graph.importers),
98
- retries: 0,
99
- signal: new AbortController().signal,
100
- specificity: { idCounter: 0, commonCounter: 0 },
101
- }
102
- return state
103
- }
104
-
105
- await t.test(
106
- 'filter out any node that does not have the vuln alert',
107
- async t => {
108
- const res = await vuln(getState(':vuln("critical")'))
109
- t.strictSame(
110
- [...res.partial.nodes].map(n => n.name),
111
- ['a'],
112
- 'should select only packages with the specified vuln alert',
113
- )
114
- t.matchSnapshot({
115
- nodes: [...res.partial.nodes].map(n => n.name),
116
- edges: [...res.partial.edges].map(e => e.name),
117
- })
118
- },
119
- )
120
-
121
- await t.test('filter using numbered param', async t => {
122
- const res = await vuln(getState(':vuln(0)'))
123
- t.strictSame(
124
- [...res.partial.nodes].map(n => n.name),
125
- ['a'],
126
- 'should select only packages with the specified vuln alert',
127
- )
128
- t.matchSnapshot({
129
- nodes: [...res.partial.nodes].map(n => n.name),
130
- edges: [...res.partial.edges].map(e => e.name),
131
- })
132
- })
133
-
134
- await t.test('filter out using unquoted param', async t => {
135
- const res = await vuln(getState(':vuln(high)'))
136
- t.strictSame(
137
- [...res.partial.nodes].map(n => n.name),
138
- ['b'],
139
- 'should select only packages with the specified vuln alert',
140
- )
141
- t.matchSnapshot({
142
- nodes: [...res.partial.nodes].map(n => n.name),
143
- edges: [...res.partial.edges].map(e => e.name),
144
- })
145
- })
146
-
147
- await t.test(
148
- 'medium matches both potentialVulnerability and gptSecurity',
149
- async t => {
150
- const res = await vuln(getState(':vuln(medium)'))
151
- t.strictSame(
152
- [...res.partial.nodes].map(n => n.name).sort(),
153
- ['c', 'e'],
154
- 'should select packages with potentialVulnerability or gptSecurity',
155
- )
156
- t.matchSnapshot({
157
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
158
- edges: [...res.partial.edges].map(e => e.name).sort(),
159
- })
160
- },
161
- )
162
-
163
- await t.test('low matches both mildCVE and gptAnomaly', async t => {
164
- const res = await vuln(getState(':vuln(low)'))
165
- t.strictSame(
166
- [...res.partial.nodes].map(n => n.name).sort(),
167
- ['d', 'f'],
168
- 'should select packages with mildCVE or gptAnomaly',
169
- )
170
- t.matchSnapshot({
171
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
172
- edges: [...res.partial.edges].map(e => e.name).sort(),
173
- })
174
- })
175
-
176
- await t.test(
177
- 'greater than comparator with number (unquoted)',
178
- async t => {
179
- const res = await vuln(getState(':vuln(>1)'))
180
- t.strictSame(
181
- [...res.partial.nodes].map(n => n.name).sort(),
182
- ['c', 'd', 'e', 'f'],
183
- 'should select packages with vuln kind greater than 1',
184
- )
185
- t.matchSnapshot({
186
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
187
- edges: [...res.partial.edges].map(e => e.name).sort(),
188
- })
189
- },
190
- )
191
-
192
- await t.test(
193
- 'greater than comparator with string kind (quoted)',
194
- async t => {
195
- const res = await vuln(getState(':vuln(">high")'))
196
- t.strictSame(
197
- [...res.partial.nodes].map(n => n.name).sort(),
198
- ['c', 'd', 'e', 'f'],
199
- 'should select packages with vuln kind greater than high',
200
- )
201
- t.matchSnapshot({
202
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
203
- edges: [...res.partial.edges].map(e => e.name).sort(),
204
- })
205
- },
206
- )
207
-
208
- await t.test(
209
- 'less than comparator with number (unquoted)',
210
- async t => {
211
- const res = await vuln(getState(':vuln(<2)'))
212
- t.strictSame(
213
- [...res.partial.nodes].map(n => n.name).sort(),
214
- ['a', 'b'],
215
- 'should select packages with vuln kind less than 2',
216
- )
217
- t.matchSnapshot({
218
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
219
- edges: [...res.partial.edges].map(e => e.name).sort(),
220
- })
221
- },
222
- )
223
-
224
- await t.test(
225
- 'less than comparator with string kind (quoted)',
226
- async t => {
227
- const res = await vuln(getState(':vuln("<medium")'))
228
- t.strictSame(
229
- [...res.partial.nodes].map(n => n.name).sort(),
230
- ['a', 'b'],
231
- 'should select packages with vuln kind less than medium',
232
- )
233
- t.matchSnapshot({
234
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
235
- edges: [...res.partial.edges].map(e => e.name).sort(),
236
- })
237
- },
238
- )
239
-
240
- await t.test(
241
- 'greater than or equal to comparator with number (unquoted)',
242
- async t => {
243
- const res = await vuln(getState(':vuln(>=2)'))
244
- t.strictSame(
245
- [...res.partial.nodes].map(n => n.name).sort(),
246
- ['c', 'd', 'e', 'f'],
247
- 'should select packages with vuln kind greater than or equal to 2',
248
- )
249
- t.matchSnapshot({
250
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
251
- edges: [...res.partial.edges].map(e => e.name).sort(),
252
- })
253
- },
254
- )
255
-
256
- await t.test(
257
- 'greater than or equal to comparator with string kind (quoted)',
258
- async t => {
259
- const res = await vuln(getState(':vuln(">=medium")'))
260
- t.strictSame(
261
- [...res.partial.nodes].map(n => n.name).sort(),
262
- ['c', 'd', 'e', 'f'],
263
- 'should select packages with vuln kind greater than or equal to medium',
264
- )
265
- t.matchSnapshot({
266
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
267
- edges: [...res.partial.edges].map(e => e.name).sort(),
268
- })
269
- },
270
- )
271
-
272
- await t.test(
273
- 'less than or equal to comparator with number (unquoted)',
274
- async t => {
275
- const res = await vuln(getState(':vuln(<=1)'))
276
- t.strictSame(
277
- [...res.partial.nodes].map(n => n.name).sort(),
278
- ['a', 'b'],
279
- 'should select packages with vuln kind less than or equal to 1',
280
- )
281
- t.matchSnapshot({
282
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
283
- edges: [...res.partial.edges].map(e => e.name).sort(),
284
- })
285
- },
286
- )
287
-
288
- await t.test(
289
- 'less than or equal to comparator with string kind (quoted)',
290
- async t => {
291
- const res = await vuln(getState(':vuln("<=high")'))
292
- t.strictSame(
293
- [...res.partial.nodes].map(n => n.name).sort(),
294
- ['a', 'b'],
295
- 'should select packages with vuln kind less than or equal to high',
296
- )
297
- t.matchSnapshot({
298
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
299
- edges: [...res.partial.edges].map(e => e.name).sort(),
300
- })
301
- },
302
- )
303
-
304
- await t.test(
305
- 'parameterless :vuln matches medium+ severity',
306
- async t => {
307
- const res = await vuln(getState(':vuln'))
308
- t.strictSame(
309
- [...res.partial.nodes].map(n => n.name).sort(),
310
- ['a', 'b', 'c', 'e'],
311
- 'should select packages with vuln severity >= medium (exclude low)',
312
- )
313
- // Verify that packages d (mildCVE) and f (gptAnomaly) are excluded
314
- t.notOk(
315
- [...res.partial.nodes].some(n => n.name === 'd'),
316
- 'should exclude package d with mildCVE (low severity)',
317
- )
318
- t.notOk(
319
- [...res.partial.nodes].some(n => n.name === 'f'),
320
- 'should exclude package f with gptAnomaly (low severity)',
321
- )
322
- t.matchSnapshot({
323
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
324
- edges: [...res.partial.edges].map(e => e.name).sort(),
325
- })
326
- },
327
- )
328
-
329
- await t.test(
330
- 'comparator excludes non-vuln alert types',
331
- async t => {
332
- // @x/y has only a 'deprecated' alert — its type is not in
333
- // alertLevelMap and it has no cveId, so it must be skipped
334
- // (covers the currentAlertLevel == null continue branch)
335
- const res = await vuln(getState(':vuln(">=medium")'))
336
- t.notOk(
337
- [...res.partial.nodes].some(n => n.name === '@x/y'),
338
- 'should exclude @x/y which only has a deprecated alert',
339
- )
340
- },
341
- )
342
-
343
- await t.test('wrong parameter', async t => {
344
- await t.rejects(
345
- vuln(getState(':vuln("")')),
346
- { message: /Failed to parse :vuln selector/ },
347
- 'should throw an error',
348
- )
349
- })
350
-
351
- await t.test('invalid comparison value', async t => {
352
- await t.rejects(
353
- vuln(getState(':vuln(>invalid)')),
354
- { message: /Failed to parse :vuln selector/ },
355
- 'should throw an error for invalid comparison value',
356
- )
357
- })
358
-
359
- await t.test('out of range number', async t => {
360
- await t.rejects(
361
- vuln(getState(':vuln(>5)')),
362
- { message: /Failed to parse :vuln selector/ },
363
- 'should throw an error for out of range number',
364
- )
365
- })
366
- })
367
-
368
- t.test('cveId matching', async t => {
369
- const getState = (query: string, graph = getSimpleGraph()) => {
370
- const ast = parse(query)
371
- const current = ast.first.first
372
- const state: ParserState = {
373
- comment: '',
374
- current,
375
- initial: {
376
- edges: new Set(graph.edges.values()),
377
- nodes: new Set(graph.nodes.values()),
378
- },
379
- partial: {
380
- edges: new Set(graph.edges.values()),
381
- nodes: new Set(graph.nodes.values()),
382
- },
383
- collect: {
384
- edges: new Set(),
385
- nodes: new Set(),
386
- },
387
- cancellable: async () => {},
388
- walk: async i => i,
389
- securityArchive: asSecurityArchiveLike(
390
- new Map([
391
- [
392
- joinDepIDTuple(['registry', '', 'a@1.0.0']),
393
- {
394
- id: joinDepIDTuple(['registry', '', 'a@1.0.0']),
395
- alerts: [
396
- {
397
- type: 'socketUpstreamVulnerability',
398
- severity: 'high' as const,
399
- category: 'vulnerability',
400
- key: 'upstream-vuln-1',
401
- props: {
402
- lastPublish: '2024-01-01',
403
- cveId: 'CVE-2024-1234' as const,
404
- },
405
- },
406
- ],
407
- },
408
- ],
409
- [
410
- joinDepIDTuple(['registry', '', 'b@1.0.0']),
411
- {
412
- id: joinDepIDTuple(['registry', '', 'b@1.0.0']),
413
- alerts: [
414
- {
415
- type: 'socketUpstreamVulnerability',
416
- severity: 'low' as const,
417
- category: 'vulnerability',
418
- key: 'upstream-vuln-2',
419
- props: {
420
- lastPublish: '2024-01-01',
421
- cveId: 'CVE-2024-5678' as const,
422
- },
423
- },
424
- ],
425
- },
426
- ],
427
- [
428
- joinDepIDTuple(['registry', '', 'c@1.0.0']),
429
- {
430
- id: joinDepIDTuple(['registry', '', 'c@1.0.0']),
431
- alerts: [{ type: 'criticalCVE' }],
432
- },
433
- ],
434
- ]),
435
- ),
436
- importers: new Set(graph.importers),
437
- retries: 0,
438
- signal: new AbortController().signal,
439
- specificity: { idCounter: 0, commonCounter: 0 },
440
- }
441
- return state
442
- }
443
-
444
- await t.test(
445
- 'parameterless :vuln matches cveId-bearing alerts with severity >= medium',
446
- async t => {
447
- const res = await vuln(getState(':vuln'))
448
- const names = [...res.partial.nodes].map(n => n.name).sort()
449
- t.ok(
450
- names.includes('a'),
451
- 'should include a (socketUpstreamVulnerability with high severity cveId)',
452
- )
453
- t.ok(names.includes('c'), 'should include c (criticalCVE)')
454
- t.notOk(
455
- names.includes('b'),
456
- 'should exclude b (socketUpstreamVulnerability with low severity cveId)',
457
- )
458
- },
459
- )
460
-
461
- await t.test(
462
- 'exact match :vuln(high) matches cveId-bearing alerts by severity',
463
- async t => {
464
- const res = await vuln(getState(':vuln(high)'))
465
- const names = [...res.partial.nodes].map(n => n.name).sort()
466
- t.ok(
467
- names.includes('a'),
468
- 'should include a (cveId with high severity)',
469
- )
470
- t.notOk(
471
- names.includes('b'),
472
- 'should exclude b (cveId with low severity)',
473
- )
474
- t.notOk(
475
- names.includes('c'),
476
- 'should exclude c (criticalCVE, not high)',
477
- )
478
- },
479
- )
480
-
481
- await t.test(
482
- 'comparator :vuln(">=high") matches cveId-bearing alerts by severity',
483
- async t => {
484
- const res = await vuln(getState(':vuln("<=high")'))
485
- const names = [...res.partial.nodes].map(n => n.name).sort()
486
- t.ok(
487
- names.includes('a'),
488
- 'should include a (cveId with high severity)',
489
- )
490
- t.ok(names.includes('c'), 'should include c (criticalCVE)')
491
- t.notOk(
492
- names.includes('b'),
493
- 'should exclude b (cveId with low severity)',
494
- )
495
- },
496
- )
497
- })
498
-
499
- t.test('missing security archive', async t => {
500
- const getState = (query: string) => {
501
- const ast = parse(query)
502
- const current = ast.first.first
503
- const state: ParserState = {
504
- comment: '',
505
- current,
506
- initial: {
507
- edges: new Set(),
508
- nodes: new Set(),
509
- },
510
- partial: {
511
- edges: new Set(),
512
- nodes: new Set(),
513
- },
514
- collect: {
515
- edges: new Set(),
516
- nodes: new Set(),
517
- },
518
- cancellable: async () => {},
519
- walk: async i => i,
520
- securityArchive: undefined,
521
- importers: new Set(),
522
- retries: 0,
523
- signal: new AbortController().signal,
524
- specificity: { idCounter: 0, commonCounter: 0 },
525
- }
526
- return state
527
- }
528
-
529
- await t.rejects(
530
- vuln(getState(':vuln(critical)')),
531
- { message: /Missing security archive/ },
532
- 'should throw an error',
533
- )
534
- })
535
-
536
- t.test('isVulnKind', async t => {
537
- t.ok(
538
- isVulnKind('critical'),
539
- 'should return true for valid vuln kinds',
540
- )
541
- t.notOk(
542
- isVulnKind('invalid'),
543
- 'should return false for invalid vuln kinds',
544
- )
545
- })
546
-
547
- t.test('asVulnKind', async t => {
548
- t.equal(
549
- asVulnKind('critical'),
550
- 'critical',
551
- 'should return the vuln kind',
552
- )
553
- t.throws(
554
- () => asVulnKind('invalid'),
555
- { message: /Expected a valid vuln kind/ },
556
- 'should throw an error for invalid vuln kinds',
557
- )
558
- })
559
-
560
- t.test('parseInternals', async t => {
561
- const testParseInternals = (query: string) => {
562
- const ast = parse(query)
563
- const nodes = asPostcssNodeWithChildren(ast.first.first).nodes
564
- return parseInternals(nodes)
565
- }
566
-
567
- t.strictSame(
568
- parseInternals([]),
569
- { kind: undefined, comparator: undefined },
570
- 'should handle empty nodes array (parameterless :vuln)',
571
- )
572
-
573
- // Test case for selector node exists but has no child nodes
574
- t.strictSame(
575
- parseInternals([{ type: 'selector', nodes: [] } as any]),
576
- { kind: undefined, comparator: undefined },
577
- 'should handle selector node with empty nodes array',
578
- )
579
-
580
- t.strictSame(
581
- testParseInternals(':vuln(critical)'),
582
- { kind: 'critical', comparator: undefined },
583
- 'should parse simple kind without comparator',
584
- )
585
-
586
- t.strictSame(
587
- testParseInternals(':vuln(">1")'),
588
- { kind: '1', comparator: '>' },
589
- 'should parse kind with greater than comparator',
590
- )
591
-
592
- t.strictSame(
593
- testParseInternals(':vuln(<low)'),
594
- { kind: 'low', comparator: '<' },
595
- 'should parse kind with less than comparator',
596
- )
597
-
598
- t.strictSame(
599
- testParseInternals(':vuln(">=medium")'),
600
- { kind: 'medium', comparator: '>=' },
601
- 'should parse kind with greater than or equal comparator',
602
- )
603
-
604
- t.strictSame(
605
- testParseInternals(':vuln(<=2)'),
606
- { kind: '2', comparator: '<=' },
607
- 'should parse kind with less than or equal comparator',
608
- )
609
-
610
- t.throws(
611
- () => testParseInternals(':vuln(>invalid)'),
612
- {
613
- message: /Expected a valid vuln kind or number between 0-3/,
614
- },
615
- 'should throw for invalid kind with comparator',
616
- )
617
-
618
- t.throws(
619
- () => testParseInternals(':vuln(>4)'),
620
- {
621
- message: /Expected a valid vuln kind or number between 0-3/,
622
- },
623
- 'should throw for out of range number with comparator',
624
- )
625
- })