@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,342 +0,0 @@
1
- import t from 'tap'
2
- import { joinDepIDTuple } from '@vltpkg/dep-id'
3
- import { asPostcssNodeWithChildren, parse } from '@vltpkg/dss-parser'
4
- import { asSecurityArchiveLike } from '@vltpkg/security-archive'
5
- import { getSimpleGraph } from '../fixtures/graph.ts'
6
- import {
7
- severity,
8
- isSeverityKind,
9
- asSeverityKind,
10
- parseInternals,
11
- } from '../../src/pseudo/severity.ts'
12
- import type { ParserState } from '../../src/types.ts'
13
-
14
- t.test('selects packages with a specific severity kind', async t => {
15
- const getState = (query: string, graph = getSimpleGraph()) => {
16
- const ast = parse(query)
17
- const current = ast.first.first
18
- const state: ParserState = {
19
- comment: '',
20
- current,
21
- initial: {
22
- edges: new Set(graph.edges.values()),
23
- nodes: new Set(graph.nodes.values()),
24
- },
25
- partial: {
26
- edges: new Set(graph.edges.values()),
27
- nodes: new Set(graph.nodes.values()),
28
- },
29
- collect: {
30
- edges: new Set(),
31
- nodes: new Set(),
32
- },
33
- cancellable: async () => {},
34
- walk: async i => i,
35
- securityArchive: asSecurityArchiveLike(
36
- new Map([
37
- [
38
- joinDepIDTuple(['registry', '', 'e@1.0.0']),
39
- {
40
- id: joinDepIDTuple(['registry', '', 'e@1.0.0']),
41
- alerts: [{ type: 'criticalCVE' }],
42
- },
43
- ],
44
- [
45
- joinDepIDTuple(['registry', '', 'f@1.0.0']),
46
- {
47
- id: joinDepIDTuple(['registry', '', 'f@1.0.0']),
48
- alerts: [{ type: 'cve' }],
49
- },
50
- ],
51
- [
52
- joinDepIDTuple(['registry', '', 'a@1.0.0']),
53
- {
54
- id: joinDepIDTuple(['registry', '', 'a@1.0.0']),
55
- alerts: [{ type: 'potentialVulnerability' }],
56
- },
57
- ],
58
- [
59
- joinDepIDTuple(['registry', '', 'b@1.0.0']),
60
- {
61
- id: joinDepIDTuple(['registry', '', 'b@1.0.0']),
62
- alerts: [{ type: 'mildCVE' }],
63
- },
64
- ],
65
- ]),
66
- ),
67
- importers: new Set(graph.importers),
68
- retries: 0,
69
- signal: new AbortController().signal,
70
- specificity: { idCounter: 0, commonCounter: 0 },
71
- }
72
- return state
73
- }
74
-
75
- await t.test(
76
- 'filter out any node that does not have the severity alert',
77
- async t => {
78
- const res = await severity(getState(':severity("critical")'))
79
- t.strictSame(
80
- [...res.partial.nodes].map(n => n.name),
81
- ['e'],
82
- 'should select only packages with the specified severity alert',
83
- )
84
- t.matchSnapshot({
85
- nodes: [...res.partial.nodes].map(n => n.name),
86
- edges: [...res.partial.edges].map(e => e.name),
87
- })
88
- },
89
- )
90
-
91
- await t.test('filter using numbered param', async t => {
92
- const res = await severity(getState(':severity(0)'))
93
- t.strictSame(
94
- [...res.partial.nodes].map(n => n.name),
95
- ['e'],
96
- 'should select only packages with the specified severity alert',
97
- )
98
- t.matchSnapshot({
99
- nodes: [...res.partial.nodes].map(n => n.name),
100
- edges: [...res.partial.edges].map(e => e.name),
101
- })
102
- })
103
-
104
- await t.test('filter out using unquoted param', async t => {
105
- const res = await severity(getState(':severity(high)'))
106
- t.strictSame(
107
- [...res.partial.nodes].map(n => n.name),
108
- ['f'],
109
- 'should select only packages with the specified severity alert',
110
- )
111
- t.matchSnapshot({
112
- nodes: [...res.partial.nodes].map(n => n.name),
113
- edges: [...res.partial.edges].map(e => e.name),
114
- })
115
- })
116
-
117
- await t.test(
118
- 'greater than comparator with number (unquoted)',
119
- async t => {
120
- const res = await severity(getState(':severity(>1)'))
121
- t.strictSame(
122
- [...res.partial.nodes].map(n => n.name).sort(),
123
- ['a', 'b'],
124
- 'should select packages with severity greater than high/1',
125
- )
126
- t.matchSnapshot({
127
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
128
- edges: [...res.partial.edges].map(e => e.name).sort(),
129
- })
130
- },
131
- )
132
-
133
- await t.test(
134
- 'less than comparator with number (quoted)',
135
- async t => {
136
- const res = await severity(getState(':severity("<2")'))
137
- t.strictSame(
138
- [...res.partial.nodes].map(n => n.name).sort(),
139
- ['e', 'f'],
140
- 'should select packages with severity less than medium/2',
141
- )
142
- t.matchSnapshot({
143
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
144
- edges: [...res.partial.edges].map(e => e.name).sort(),
145
- })
146
- },
147
- )
148
-
149
- await t.test(
150
- 'greater than or equal to comparator with number (quoted)',
151
- async t => {
152
- const res = await severity(getState(':severity(">=2")'))
153
- t.strictSame(
154
- [...res.partial.nodes].map(n => n.name).sort(),
155
- ['a', 'b'],
156
- 'should select packages with severity greater than or equal to medium/2',
157
- )
158
- t.matchSnapshot({
159
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
160
- edges: [...res.partial.edges].map(e => e.name).sort(),
161
- })
162
- },
163
- )
164
-
165
- await t.test(
166
- 'less than or equal to comparator with number (unquoted)',
167
- async t => {
168
- const res = await severity(getState(':severity(<=1)'))
169
- t.strictSame(
170
- [...res.partial.nodes].map(n => n.name).sort(),
171
- ['e', 'f'],
172
- 'should select packages with severity less than or equal to high/1',
173
- )
174
- t.matchSnapshot({
175
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
176
- edges: [...res.partial.edges].map(e => e.name).sort(),
177
- })
178
- },
179
- )
180
-
181
- await t.test(
182
- 'less than or equal to comparator with critical kind (level 0)',
183
- async t => {
184
- const res = await severity(getState(':severity(<=critical)'))
185
- t.strictSame(
186
- [...res.partial.nodes].map(n => n.name).sort(),
187
- ['e'],
188
- 'should select only packages with critical severity',
189
- )
190
- t.matchSnapshot({
191
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
192
- edges: [...res.partial.edges].map(e => e.name).sort(),
193
- })
194
- },
195
- )
196
-
197
- await t.test(
198
- 'greater than comparator with 0 (critical level)',
199
- async t => {
200
- const res = await severity(getState(':severity(>0)'))
201
- t.strictSame(
202
- [...res.partial.nodes].map(n => n.name).sort(),
203
- ['a', 'b', 'f'],
204
- 'should select packages with severity less severe than critical',
205
- )
206
- t.matchSnapshot({
207
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
208
- edges: [...res.partial.edges].map(e => e.name).sort(),
209
- })
210
- },
211
- )
212
-
213
- await t.test('wrong parameter', async t => {
214
- await t.rejects(
215
- severity(getState(':severity')),
216
- { message: /Failed to parse :severity selector/ },
217
- 'should throw an error',
218
- )
219
- })
220
- })
221
-
222
- t.test('missing security archive', async t => {
223
- const getState = (query: string) => {
224
- const ast = parse(query)
225
- const current = ast.first.first
226
- const state: ParserState = {
227
- comment: '',
228
- current,
229
- initial: {
230
- edges: new Set(),
231
- nodes: new Set(),
232
- },
233
- partial: {
234
- edges: new Set(),
235
- nodes: new Set(),
236
- },
237
- collect: {
238
- edges: new Set(),
239
- nodes: new Set(),
240
- },
241
- cancellable: async () => {},
242
- walk: async i => i,
243
- securityArchive: undefined,
244
- importers: new Set(),
245
- retries: 0,
246
- signal: new AbortController().signal,
247
- specificity: { idCounter: 0, commonCounter: 0 },
248
- }
249
- return state
250
- }
251
-
252
- await t.rejects(
253
- severity(getState(':severity(critical)')),
254
- { message: /Missing security archive/ },
255
- 'should throw an error',
256
- )
257
- })
258
-
259
- t.test('isSeverityKind', async t => {
260
- t.ok(
261
- isSeverityKind('critical'),
262
- 'should return true for valid severity kinds',
263
- )
264
- t.notOk(
265
- isSeverityKind('invalid'),
266
- 'should return false for invalid severity kinds',
267
- )
268
- })
269
-
270
- t.test('asSeverityKind', async t => {
271
- t.equal(
272
- asSeverityKind('critical'),
273
- 'critical',
274
- 'should return the severity kind',
275
- )
276
- t.throws(
277
- () => asSeverityKind('invalid'),
278
- { message: /Expected a valid severity kind/ },
279
- 'should throw an error for invalid severity kinds',
280
- )
281
- })
282
-
283
- t.test('parseInternals', async t => {
284
- const testParseInternals = (query: string) => {
285
- const ast = parse(query)
286
- return parseInternals(
287
- asPostcssNodeWithChildren(ast.first.first).nodes,
288
- )
289
- }
290
-
291
- t.strictSame(
292
- testParseInternals(':severity(critical)'),
293
- { kind: 'critical', comparator: undefined },
294
- 'should parse exact severity kind',
295
- )
296
-
297
- t.strictSame(
298
- testParseInternals(':severity(>medium)'),
299
- { kind: 'medium', comparator: '>' },
300
- 'should parse severity kind with > comparator',
301
- )
302
-
303
- t.strictSame(
304
- testParseInternals(':severity(<high)'),
305
- { kind: 'high', comparator: '<' },
306
- 'should parse severity kind with < comparator',
307
- )
308
-
309
- t.strictSame(
310
- testParseInternals(':severity(>=2)'),
311
- { kind: '2', comparator: '>=' },
312
- 'should parse severity kind with >= comparator',
313
- )
314
-
315
- t.strictSame(
316
- testParseInternals(':severity(<=low)'),
317
- { kind: 'low', comparator: '<=' },
318
- 'should parse severity kind with <= comparator',
319
- )
320
-
321
- t.throws(
322
- () => testParseInternals(':severity'),
323
- { message: /Missing severity kind parameter/ },
324
- 'should throw for missing parameter',
325
- )
326
-
327
- t.throws(
328
- () => testParseInternals(':severity(>invalid)'),
329
- {
330
- message: /Expected a valid severity kind or number between 0-3/,
331
- },
332
- 'should throw for invalid kind with comparator',
333
- )
334
-
335
- t.throws(
336
- () => testParseInternals(':severity(>4)'),
337
- {
338
- message: /Expected a valid severity kind or number between 0-3/,
339
- },
340
- 'should throw for out of range number with comparator',
341
- )
342
- })
@@ -1,98 +0,0 @@
1
- import t from 'tap'
2
- import { joinDepIDTuple } from '@vltpkg/dep-id'
3
- import { asSecurityArchiveLike } from '@vltpkg/security-archive'
4
- import { getSimpleGraph } from '../fixtures/graph.ts'
5
- import type { ParserState } from '../../src/types.ts'
6
- import { shell } from '../../src/pseudo/shell.ts'
7
- import { parse } from '../../src/parser.ts'
8
-
9
- t.test('selects packages with a shellAccess alert', async t => {
10
- const getState = (query: string, graph = getSimpleGraph()) => {
11
- const ast = parse(query)
12
- const current = ast.first.first
13
- const state: ParserState = {
14
- comment: '',
15
- current,
16
- initial: {
17
- edges: new Set(graph.edges.values()),
18
- nodes: new Set(graph.nodes.values()),
19
- },
20
- partial: {
21
- edges: new Set(graph.edges.values()),
22
- nodes: new Set(graph.nodes.values()),
23
- },
24
- collect: {
25
- edges: new Set(),
26
- nodes: new Set(),
27
- },
28
- cancellable: async () => {},
29
- walk: async i => i,
30
- securityArchive: asSecurityArchiveLike(
31
- new Map([
32
- [
33
- joinDepIDTuple(['registry', '', 'e@1.0.0']),
34
- { alerts: [{ type: 'shellAccess' }] },
35
- ],
36
- ]),
37
- ),
38
- importers: new Set(graph.importers),
39
- retries: 0,
40
- signal: new AbortController().signal,
41
- specificity: { idCounter: 0, commonCounter: 0 },
42
- }
43
- return state
44
- }
45
-
46
- await t.test(
47
- 'filter out any node that does not have the alert',
48
- async t => {
49
- const res = await shell(getState(':shell'))
50
- t.strictSame(
51
- [...res.partial.nodes].map(n => n.name),
52
- ['e'],
53
- 'should select only shell packages',
54
- )
55
- t.matchSnapshot({
56
- nodes: [...res.partial.nodes].map(n => n.name),
57
- edges: [...res.partial.edges].map(e => e.name),
58
- })
59
- },
60
- )
61
- })
62
-
63
- t.test('missing security archive', async t => {
64
- const getState = (query: string) => {
65
- const ast = parse(query)
66
- const current = ast.first.first
67
- const state: ParserState = {
68
- comment: '',
69
- current,
70
- initial: {
71
- edges: new Set(),
72
- nodes: new Set(),
73
- },
74
- partial: {
75
- edges: new Set(),
76
- nodes: new Set(),
77
- },
78
- collect: {
79
- edges: new Set(),
80
- nodes: new Set(),
81
- },
82
- cancellable: async () => {},
83
- walk: async i => i,
84
- securityArchive: undefined,
85
- importers: new Set(),
86
- retries: 0,
87
- signal: new AbortController().signal,
88
- specificity: { idCounter: 0, commonCounter: 0 },
89
- }
90
- return state
91
- }
92
-
93
- await t.rejects(
94
- shell(getState(':shell')),
95
- { message: /Missing security archive/ },
96
- 'should throw an error',
97
- )
98
- })
@@ -1,98 +0,0 @@
1
- import t from 'tap'
2
- import { joinDepIDTuple } from '@vltpkg/dep-id'
3
- import { asSecurityArchiveLike } from '@vltpkg/security-archive'
4
- import { getSimpleGraph } from '../fixtures/graph.ts'
5
- import type { ParserState } from '../../src/types.ts'
6
- import { shrinkwrap } from '../../src/pseudo/shrinkwrap.ts'
7
- import { parse } from '../../src/parser.ts'
8
-
9
- t.test('selects packages with a shrinkwrap alert', async t => {
10
- const getState = (query: string, graph = getSimpleGraph()) => {
11
- const ast = parse(query)
12
- const current = ast.first.first
13
- const state: ParserState = {
14
- comment: '',
15
- current,
16
- initial: {
17
- edges: new Set(graph.edges.values()),
18
- nodes: new Set(graph.nodes.values()),
19
- },
20
- partial: {
21
- edges: new Set(graph.edges.values()),
22
- nodes: new Set(graph.nodes.values()),
23
- },
24
- collect: {
25
- edges: new Set(),
26
- nodes: new Set(),
27
- },
28
- cancellable: async () => {},
29
- walk: async i => i,
30
- securityArchive: asSecurityArchiveLike(
31
- new Map([
32
- [
33
- joinDepIDTuple(['registry', '', 'e@1.0.0']),
34
- { alerts: [{ type: 'shrinkwrap' }] },
35
- ],
36
- ]),
37
- ),
38
- importers: new Set(graph.importers),
39
- retries: 0,
40
- signal: new AbortController().signal,
41
- specificity: { idCounter: 0, commonCounter: 0 },
42
- }
43
- return state
44
- }
45
-
46
- await t.test(
47
- 'filter out any node that does not have the alert',
48
- async t => {
49
- const res = await shrinkwrap(getState(':shrinkwrap'))
50
- t.strictSame(
51
- [...res.partial.nodes].map(n => n.name),
52
- ['e'],
53
- 'should select only shrinkwrap packages',
54
- )
55
- t.matchSnapshot({
56
- nodes: [...res.partial.nodes].map(n => n.name),
57
- edges: [...res.partial.edges].map(e => e.name),
58
- })
59
- },
60
- )
61
- })
62
-
63
- t.test('missing security archive', async t => {
64
- const getState = (query: string) => {
65
- const ast = parse(query)
66
- const current = ast.first.first
67
- const state: ParserState = {
68
- comment: '',
69
- current,
70
- initial: {
71
- edges: new Set(),
72
- nodes: new Set(),
73
- },
74
- partial: {
75
- edges: new Set(),
76
- nodes: new Set(),
77
- },
78
- collect: {
79
- edges: new Set(),
80
- nodes: new Set(),
81
- },
82
- cancellable: async () => {},
83
- walk: async i => i,
84
- securityArchive: undefined,
85
- importers: new Set(),
86
- retries: 0,
87
- signal: new AbortController().signal,
88
- specificity: { idCounter: 0, commonCounter: 0 },
89
- }
90
- return state
91
- }
92
-
93
- await t.rejects(
94
- shrinkwrap(getState(':shrinkwrap')),
95
- { message: /Missing security archive/ },
96
- 'should throw an error',
97
- )
98
- })