@vltpkg/query 1.4.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 (213) hide show
  1. package/dist/index.d.ts +7 -2
  2. package/dist/index.js +23 -4
  3. package/dist/pseudo/skill.d.ts +7 -0
  4. package/dist/pseudo/skill.js +52 -0
  5. package/dist/pseudo/skills.d.ts +6 -0
  6. package/dist/pseudo/skills.js +26 -0
  7. package/dist/pseudo.js +7 -0
  8. package/dist/types.d.ts +29 -1
  9. package/package.json +10 -12
  10. package/skills/dss-query/REFERENCE.md +0 -123
  11. package/skills/dss-query/SKILL.md +0 -190
  12. package/skills/dss-query/evals/README.md +0 -81
  13. package/skills/dss-query/evals/evals.json +0 -89
  14. package/skills/dss-query/evals/grade.mjs +0 -481
  15. package/src/attribute.ts +0 -190
  16. package/src/combinator.ts +0 -135
  17. package/src/error.ts +0 -78
  18. package/src/id.ts +0 -46
  19. package/src/index.ts +0 -640
  20. package/src/parser.ts +0 -122
  21. package/src/pseudo/abandoned.ts +0 -9
  22. package/src/pseudo/attr.ts +0 -92
  23. package/src/pseudo/built.ts +0 -19
  24. package/src/pseudo/confused.ts +0 -29
  25. package/src/pseudo/cve.ts +0 -93
  26. package/src/pseudo/cwe.ts +0 -97
  27. package/src/pseudo/debug.ts +0 -9
  28. package/src/pseudo/deprecated.ts +0 -9
  29. package/src/pseudo/dev.ts +0 -18
  30. package/src/pseudo/diff.ts +0 -90
  31. package/src/pseudo/dist.ts +0 -148
  32. package/src/pseudo/dynamic.ts +0 -9
  33. package/src/pseudo/empty.ts +0 -15
  34. package/src/pseudo/entropic.ts +0 -9
  35. package/src/pseudo/env.ts +0 -6
  36. package/src/pseudo/eval.ts +0 -9
  37. package/src/pseudo/fs.ts +0 -9
  38. package/src/pseudo/helpers.ts +0 -106
  39. package/src/pseudo/host.ts +0 -111
  40. package/src/pseudo/hostname.ts +0 -156
  41. package/src/pseudo/license.ts +0 -134
  42. package/src/pseudo/link.ts +0 -30
  43. package/src/pseudo/malware.ts +0 -41
  44. package/src/pseudo/minified.ts +0 -9
  45. package/src/pseudo/missing.ts +0 -16
  46. package/src/pseudo/native.ts +0 -9
  47. package/src/pseudo/network.ts +0 -9
  48. package/src/pseudo/obfuscated.ts +0 -9
  49. package/src/pseudo/optional.ts +0 -18
  50. package/src/pseudo/outdated.ts +0 -345
  51. package/src/pseudo/overridden.ts +0 -20
  52. package/src/pseudo/path.ts +0 -146
  53. package/src/pseudo/peer.ts +0 -18
  54. package/src/pseudo/prerelease.ts +0 -47
  55. package/src/pseudo/private.ts +0 -19
  56. package/src/pseudo/prod.ts +0 -18
  57. package/src/pseudo/published.ts +0 -250
  58. package/src/pseudo/registry.ts +0 -29
  59. package/src/pseudo/root.ts +0 -19
  60. package/src/pseudo/scanned.ts +0 -20
  61. package/src/pseudo/score.ts +0 -186
  62. package/src/pseudo/scripts.ts +0 -61
  63. package/src/pseudo/semver.ts +0 -320
  64. package/src/pseudo/severity.ts +0 -231
  65. package/src/pseudo/shell.ts +0 -9
  66. package/src/pseudo/shrinkwrap.ts +0 -9
  67. package/src/pseudo/spec.ts +0 -131
  68. package/src/pseudo/squat.ts +0 -225
  69. package/src/pseudo/suspicious.ts +0 -9
  70. package/src/pseudo/tracker.ts +0 -9
  71. package/src/pseudo/trivial.ts +0 -9
  72. package/src/pseudo/type.ts +0 -26
  73. package/src/pseudo/undesirable.ts +0 -9
  74. package/src/pseudo/unknown.ts +0 -9
  75. package/src/pseudo/unmaintained.ts +0 -9
  76. package/src/pseudo/unpopular.ts +0 -9
  77. package/src/pseudo/unstable.ts +0 -9
  78. package/src/pseudo/vuln.ts +0 -273
  79. package/src/pseudo/workspace.ts +0 -22
  80. package/src/pseudo.ts +0 -433
  81. package/src/types.ts +0 -176
  82. package/tap-snapshots/test/attribute.ts.test.cjs +0 -304
  83. package/tap-snapshots/test/combinator.ts.test.cjs +0 -333
  84. package/tap-snapshots/test/id.ts.test.cjs +0 -118
  85. package/tap-snapshots/test/parser.ts.test.cjs +0 -344
  86. package/tap-snapshots/test/pseudo/abandoned.ts.test.cjs +0 -18
  87. package/tap-snapshots/test/pseudo/attr.ts.test.cjs +0 -161
  88. package/tap-snapshots/test/pseudo/built.ts.test.cjs +0 -70
  89. package/tap-snapshots/test/pseudo/confused.ts.test.cjs +0 -32
  90. package/tap-snapshots/test/pseudo/cve.ts.test.cjs +0 -49
  91. package/tap-snapshots/test/pseudo/cwe.ts.test.cjs +0 -49
  92. package/tap-snapshots/test/pseudo/debug.ts.test.cjs +0 -18
  93. package/tap-snapshots/test/pseudo/deprecated.ts.test.cjs +0 -18
  94. package/tap-snapshots/test/pseudo/dist.ts.test.cjs +0 -30
  95. package/tap-snapshots/test/pseudo/dynamic.ts.test.cjs +0 -18
  96. package/tap-snapshots/test/pseudo/empty.ts.test.cjs +0 -50
  97. package/tap-snapshots/test/pseudo/entropic.ts.test.cjs +0 -18
  98. package/tap-snapshots/test/pseudo/env.ts.test.cjs +0 -18
  99. package/tap-snapshots/test/pseudo/eval.ts.test.cjs +0 -18
  100. package/tap-snapshots/test/pseudo/fs.ts.test.cjs +0 -18
  101. package/tap-snapshots/test/pseudo/helpers.ts.test.cjs +0 -18
  102. package/tap-snapshots/test/pseudo/hostname.ts.test.cjs +0 -148
  103. package/tap-snapshots/test/pseudo/license.ts.test.cjs +0 -41
  104. package/tap-snapshots/test/pseudo/link.ts.test.cjs +0 -36
  105. package/tap-snapshots/test/pseudo/malware.ts.test.cjs +0 -22
  106. package/tap-snapshots/test/pseudo/minified.ts.test.cjs +0 -18
  107. package/tap-snapshots/test/pseudo/missing.ts.test.cjs +0 -30
  108. package/tap-snapshots/test/pseudo/native.ts.test.cjs +0 -18
  109. package/tap-snapshots/test/pseudo/network.ts.test.cjs +0 -18
  110. package/tap-snapshots/test/pseudo/obfuscated.ts.test.cjs +0 -18
  111. package/tap-snapshots/test/pseudo/outdated.ts.test.cjs +0 -132
  112. package/tap-snapshots/test/pseudo/overridden.ts.test.cjs +0 -75
  113. package/tap-snapshots/test/pseudo/prerelease.ts.test.cjs +0 -101
  114. package/tap-snapshots/test/pseudo/private.ts.test.cjs +0 -38
  115. package/tap-snapshots/test/pseudo/published.ts.test.cjs +0 -171
  116. package/tap-snapshots/test/pseudo/registry.ts.test.cjs +0 -68
  117. package/tap-snapshots/test/pseudo/root.ts.test.cjs +0 -24
  118. package/tap-snapshots/test/pseudo/scanned.ts.test.cjs +0 -18
  119. package/tap-snapshots/test/pseudo/score.ts.test.cjs +0 -239
  120. package/tap-snapshots/test/pseudo/scripts.ts.test.cjs +0 -62
  121. package/tap-snapshots/test/pseudo/semver.ts.test.cjs +0 -575
  122. package/tap-snapshots/test/pseudo/severity.ts.test.cjs +0 -122
  123. package/tap-snapshots/test/pseudo/shell.ts.test.cjs +0 -18
  124. package/tap-snapshots/test/pseudo/shrinkwrap.ts.test.cjs +0 -18
  125. package/tap-snapshots/test/pseudo/spec.ts.test.cjs +0 -148
  126. package/tap-snapshots/test/pseudo/squat.ts.test.cjs +0 -129
  127. package/tap-snapshots/test/pseudo/suspicious.ts.test.cjs +0 -18
  128. package/tap-snapshots/test/pseudo/tracker.ts.test.cjs +0 -18
  129. package/tap-snapshots/test/pseudo/trivial.ts.test.cjs +0 -18
  130. package/tap-snapshots/test/pseudo/type.ts.test.cjs +0 -51
  131. package/tap-snapshots/test/pseudo/undesirable.ts.test.cjs +0 -18
  132. package/tap-snapshots/test/pseudo/unknown.ts.test.cjs +0 -18
  133. package/tap-snapshots/test/pseudo/unmaintained.ts.test.cjs +0 -18
  134. package/tap-snapshots/test/pseudo/unpopular.ts.test.cjs +0 -18
  135. package/tap-snapshots/test/pseudo/unstable.ts.test.cjs +0 -18
  136. package/tap-snapshots/test/pseudo/vuln.ts.test.cjs +0 -208
  137. package/tap-snapshots/test/pseudo/vulnerable.ts.test.cjs +0 -20
  138. package/tap-snapshots/test/pseudo/workspace.ts.test.cjs +0 -19
  139. package/tap-snapshots/test/pseudo.ts.test.cjs +0 -1247
  140. package/test/attribute.ts +0 -273
  141. package/test/combinator.ts +0 -175
  142. package/test/error.ts +0 -60
  143. package/test/fixtures/graph.ts +0 -999
  144. package/test/fixtures/selector.ts +0 -103
  145. package/test/fixtures/types.ts +0 -7
  146. package/test/id.ts +0 -102
  147. package/test/index.ts +0 -1049
  148. package/test/parser.ts +0 -117
  149. package/test/pseudo/abandoned.ts +0 -98
  150. package/test/pseudo/attr.ts +0 -298
  151. package/test/pseudo/built.ts +0 -214
  152. package/test/pseudo/confused.ts +0 -160
  153. package/test/pseudo/cve.ts +0 -249
  154. package/test/pseudo/cwe.ts +0 -255
  155. package/test/pseudo/debug.ts +0 -98
  156. package/test/pseudo/deprecated.ts +0 -98
  157. package/test/pseudo/dev.ts +0 -61
  158. package/test/pseudo/diff.ts +0 -417
  159. package/test/pseudo/dist.ts +0 -215
  160. package/test/pseudo/dynamic.ts +0 -98
  161. package/test/pseudo/empty.ts +0 -108
  162. package/test/pseudo/entropic.ts +0 -101
  163. package/test/pseudo/env.ts +0 -98
  164. package/test/pseudo/eval.ts +0 -98
  165. package/test/pseudo/fs.ts +0 -98
  166. package/test/pseudo/helpers.ts +0 -370
  167. package/test/pseudo/host-context.ts +0 -276
  168. package/test/pseudo/hostname.ts +0 -314
  169. package/test/pseudo/license.ts +0 -265
  170. package/test/pseudo/link.ts +0 -94
  171. package/test/pseudo/malware.ts +0 -184
  172. package/test/pseudo/minified.ts +0 -98
  173. package/test/pseudo/missing.ts +0 -111
  174. package/test/pseudo/native.ts +0 -98
  175. package/test/pseudo/network.ts +0 -98
  176. package/test/pseudo/obfuscated.ts +0 -98
  177. package/test/pseudo/optional.ts +0 -73
  178. package/test/pseudo/outdated.ts +0 -461
  179. package/test/pseudo/overridden.ts +0 -317
  180. package/test/pseudo/path.ts +0 -680
  181. package/test/pseudo/peer.ts +0 -101
  182. package/test/pseudo/prerelease.ts +0 -279
  183. package/test/pseudo/private.ts +0 -108
  184. package/test/pseudo/prod.ts +0 -61
  185. package/test/pseudo/published.ts +0 -557
  186. package/test/pseudo/registry.ts +0 -122
  187. package/test/pseudo/root.ts +0 -66
  188. package/test/pseudo/scanned.ts +0 -144
  189. package/test/pseudo/score.ts +0 -591
  190. package/test/pseudo/scripts.ts +0 -324
  191. package/test/pseudo/semver.ts +0 -822
  192. package/test/pseudo/severity.ts +0 -342
  193. package/test/pseudo/shell.ts +0 -98
  194. package/test/pseudo/shrinkwrap.ts +0 -98
  195. package/test/pseudo/spec.ts +0 -525
  196. package/test/pseudo/squat.ts +0 -565
  197. package/test/pseudo/suspicious.ts +0 -98
  198. package/test/pseudo/tracker.ts +0 -98
  199. package/test/pseudo/trivial.ts +0 -98
  200. package/test/pseudo/type.ts +0 -105
  201. package/test/pseudo/undesirable.ts +0 -98
  202. package/test/pseudo/unknown.ts +0 -98
  203. package/test/pseudo/unmaintained.ts +0 -98
  204. package/test/pseudo/unpopular.ts +0 -98
  205. package/test/pseudo/unstable.ts +0 -98
  206. package/test/pseudo/vuln.ts +0 -625
  207. package/test/pseudo/vulnerable.ts +0 -137
  208. package/test/pseudo/workspace.ts +0 -111
  209. package/test/pseudo.ts +0 -584
  210. package/tsconfig.json +0 -3
  211. package/tsconfig.publish.json +0 -19
  212. package/tsconfig.publish.tsbuildinfo +0 -1
  213. 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
- })