@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,591 +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 {
7
- score,
8
- isScoreKind,
9
- asScoreKind,
10
- } from '../../src/pseudo/score.ts'
11
- import type { PackageScore } from '@vltpkg/security-archive'
12
- import { parse } from '../../src/parser.ts'
13
-
14
- // Create a function to generate a security archive with varied scores for testing
15
- const createTestSecurityArchive = () => {
16
- // Define different scores for each package in the test graph
17
- const scores: Record<string, PackageScore> = {
18
- a: {
19
- overall: 0.85,
20
- license: 0.95,
21
- maintenance: 0.8,
22
- quality: 0.75,
23
- supplyChain: 0.9,
24
- vulnerability: 0.7,
25
- },
26
- b: {
27
- overall: 0.65,
28
- license: 0.5,
29
- maintenance: 0.7,
30
- quality: 0.6,
31
- supplyChain: 0.8,
32
- vulnerability: 0.45,
33
- },
34
- c: {
35
- overall: 0.4,
36
- license: 0.3,
37
- maintenance: 0.5,
38
- quality: 0.45,
39
- supplyChain: 0.35,
40
- vulnerability: 0.25,
41
- },
42
- d: {
43
- overall: 0.95,
44
- license: 1.0,
45
- maintenance: 0.9,
46
- quality: 0.85,
47
- supplyChain: 0.95,
48
- vulnerability: 0.9,
49
- },
50
- e: {
51
- overall: 0.2,
52
- license: 0.15,
53
- maintenance: 0.3,
54
- quality: 0.25,
55
- supplyChain: 0.1,
56
- vulnerability: 0.05,
57
- },
58
- f: {
59
- overall: 0.5,
60
- license: 0.55,
61
- maintenance: 0.45,
62
- quality: 0.5,
63
- supplyChain: 0.6,
64
- vulnerability: 0.4,
65
- },
66
- }
67
-
68
- // Create a map of package IDs to security data
69
- const securityMap = new Map()
70
- Object.entries(scores).forEach(([name, score]) => {
71
- securityMap.set(
72
- joinDepIDTuple(['registry', '', `${name}@1.0.0`]),
73
- {
74
- id: joinDepIDTuple(['registry', '', `${name}@1.0.0`]),
75
- author: [],
76
- size: 0,
77
- type: 'npm',
78
- name,
79
- version: '1.0.0',
80
- license: 'MIT',
81
- score,
82
- alerts: [],
83
- },
84
- )
85
- })
86
-
87
- return asSecurityArchiveLike(securityMap)
88
- }
89
-
90
- t.test('selects packages based on their security score', async t => {
91
- const getState = (query: string, graph = getSimpleGraph()) => {
92
- const ast = parse(query)
93
- const current = ast.first.first
94
- const state: ParserState = {
95
- comment: '',
96
- current,
97
- initial: {
98
- edges: new Set(graph.edges.values()),
99
- nodes: new Set(graph.nodes.values()),
100
- },
101
- partial: {
102
- edges: new Set(graph.edges.values()),
103
- nodes: new Set(graph.nodes.values()),
104
- },
105
- collect: {
106
- edges: new Set(),
107
- nodes: new Set(),
108
- },
109
- cancellable: async () => {},
110
- walk: async i => i,
111
- securityArchive: createTestSecurityArchive(),
112
- importers: new Set(graph.importers),
113
- retries: 0,
114
- signal: new AbortController().signal,
115
- specificity: { idCounter: 0, commonCounter: 0 },
116
- }
117
- return state
118
- }
119
-
120
- await t.test('exact match on overall score', async t => {
121
- const res = await score(getState(':score("0.85")'))
122
- t.strictSame(
123
- [...res.partial.nodes].map(n => n.name),
124
- ['a'],
125
- 'should select packages with exactly 0.85 overall score',
126
- )
127
- t.matchSnapshot({
128
- nodes: [...res.partial.nodes].map(n => n.name),
129
- edges: [...res.partial.edges].map(e => e.name),
130
- })
131
- })
132
-
133
- await t.test('exact match with percentage value', async t => {
134
- const res = await score(getState(':score(20)'))
135
- t.strictSame(
136
- [...res.partial.nodes].map(n => n.name),
137
- ['e'],
138
- 'should select packages with exactly 0.2 (20%) overall score',
139
- )
140
- t.matchSnapshot({
141
- nodes: [...res.partial.nodes].map(n => n.name),
142
- edges: [...res.partial.edges].map(e => e.name),
143
- })
144
- })
145
-
146
- await t.test('exact match with quoted value', async t => {
147
- const res = await score(getState(':score("0.5")'))
148
- t.strictSame(
149
- [...res.partial.nodes].map(n => n.name),
150
- ['f'],
151
- 'should select packages with exactly 0.5 overall score',
152
- )
153
- t.matchSnapshot({
154
- nodes: [...res.partial.nodes].map(n => n.name),
155
- edges: [...res.partial.edges].map(e => e.name),
156
- })
157
- })
158
-
159
- await t.test('greater than comparator', async t => {
160
- const res = await score(getState(':score(">0.8")'))
161
- t.strictSame(
162
- [...res.partial.nodes].map(n => n.name),
163
- ['a', 'd'],
164
- 'should select packages with overall score greater than 0.8',
165
- )
166
- t.matchSnapshot({
167
- nodes: [...res.partial.nodes].map(n => n.name),
168
- edges: [...res.partial.edges].map(e => e.name),
169
- })
170
- })
171
-
172
- await t.test('greater than comparator (unquoted)', async t => {
173
- const res = await score(getState(':score(>0.8)'))
174
- t.strictSame(
175
- [...res.partial.nodes].map(n => n.name),
176
- ['a', 'd'],
177
- 'should select packages with overall score greater than 0.8 using unquoted parameter',
178
- )
179
- t.matchSnapshot({
180
- nodes: [...res.partial.nodes].map(n => n.name),
181
- edges: [...res.partial.edges].map(e => e.name),
182
- })
183
- })
184
-
185
- await t.test('less than comparator', async t => {
186
- const res = await score(getState(':score("<0.5")'))
187
- t.strictSame(
188
- [...res.partial.nodes].map(n => n.name),
189
- ['c', 'e'],
190
- 'should select packages with overall score less than 0.5',
191
- )
192
- t.matchSnapshot({
193
- nodes: [...res.partial.nodes].map(n => n.name),
194
- edges: [...res.partial.edges].map(e => e.name),
195
- })
196
- })
197
-
198
- await t.test('less than comparator (unquoted)', async t => {
199
- const res = await score(getState(':score(<0.5)'))
200
- t.strictSame(
201
- [...res.partial.nodes].map(n => n.name),
202
- ['c', 'e'],
203
- 'should select packages with overall score less than 0.5 using unquoted parameter',
204
- )
205
- t.matchSnapshot({
206
- nodes: [...res.partial.nodes].map(n => n.name),
207
- edges: [...res.partial.edges].map(e => e.name),
208
- })
209
- })
210
-
211
- await t.test('greater than or equal comparator', async t => {
212
- const res = await score(getState(':score(">=0.75")'))
213
- t.strictSame(
214
- [...res.partial.nodes].map(n => n.name),
215
- ['a', 'd'],
216
- 'should select packages with overall score greater than or equal to 0.75',
217
- )
218
- t.matchSnapshot({
219
- nodes: [...res.partial.nodes].map(n => n.name),
220
- edges: [...res.partial.edges].map(e => e.name),
221
- })
222
- })
223
-
224
- await t.test(
225
- 'greater than or equal comparator (unquoted)',
226
- async t => {
227
- const res = await score(getState(':score(>=0.75)'))
228
- t.strictSame(
229
- [...res.partial.nodes].map(n => n.name),
230
- ['a', 'd'],
231
- 'should select packages with overall score greater than or equal to 0.75 using unquoted parameter',
232
- )
233
- t.matchSnapshot({
234
- nodes: [...res.partial.nodes].map(n => n.name),
235
- edges: [...res.partial.edges].map(e => e.name),
236
- })
237
- },
238
- )
239
-
240
- await t.test('less than or equal comparator', async t => {
241
- const res = await score(getState(':score(<=40)'))
242
- t.strictSame(
243
- [...res.partial.nodes].map(n => n.name),
244
- ['c', 'e'],
245
- 'should select packages with overall score less than or equal to 0.4 (40%)',
246
- )
247
- t.matchSnapshot({
248
- nodes: [...res.partial.nodes].map(n => n.name),
249
- edges: [...res.partial.edges].map(e => e.name),
250
- })
251
- })
252
-
253
- await t.test(
254
- 'less than or equal comparator (unquoted)',
255
- async t => {
256
- const res = await score(getState(':score(<=40)'))
257
- t.strictSame(
258
- [...res.partial.nodes].map(n => n.name),
259
- ['c', 'e'],
260
- 'should select packages with overall score less than or equal to 0.4 (40%) using unquoted parameter',
261
- )
262
- t.matchSnapshot({
263
- nodes: [...res.partial.nodes].map(n => n.name),
264
- edges: [...res.partial.edges].map(e => e.name),
265
- })
266
- },
267
- )
268
-
269
- await t.test('with specific kind parameter', async t => {
270
- const res = await score(getState(':score("0.95", license)'))
271
- t.strictSame(
272
- [...res.partial.nodes].map(n => n.name),
273
- ['a'],
274
- 'should select packages with license score of exactly 0.95',
275
- )
276
- t.matchSnapshot({
277
- nodes: [...res.partial.nodes].map(n => n.name),
278
- edges: [...res.partial.edges].map(e => e.name),
279
- })
280
- })
281
-
282
- await t.test(
283
- 'with specific kind and quoted parameters',
284
- async t => {
285
- const res = await score(
286
- getState(':score(">0.8", "supplyChain")'),
287
- )
288
- t.strictSame(
289
- [...res.partial.nodes].map(n => n.name),
290
- ['a', 'd'],
291
- 'should select packages with supplyChain score greater than 0.8',
292
- )
293
- t.matchSnapshot({
294
- nodes: [...res.partial.nodes].map(n => n.name),
295
- edges: [...res.partial.edges].map(e => e.name),
296
- })
297
- },
298
- )
299
-
300
- await t.test(
301
- 'with less than comparator and vulnerability kind',
302
- async t => {
303
- const res = await score(
304
- getState(':score("<0.5", vulnerability)'),
305
- )
306
- t.strictSame(
307
- [...res.partial.nodes].map(n => n.name),
308
- ['b', 'c', 'e', 'f'],
309
- 'should select packages with vulnerability score less than 0.5',
310
- )
311
- t.matchSnapshot({
312
- nodes: [...res.partial.nodes].map(n => n.name),
313
- edges: [...res.partial.edges].map(e => e.name),
314
- })
315
- },
316
- )
317
-
318
- await t.test(
319
- 'with percentage rate and maintenance kind',
320
- async t => {
321
- const res = await score(getState(':score(<=50, maintenance)'))
322
- t.strictSame(
323
- [...res.partial.nodes].map(n => n.name),
324
- ['c', 'e', 'f'],
325
- 'should select packages with maintenance score less than or equal to 0.5 (50%)',
326
- )
327
- t.matchSnapshot({
328
- nodes: [...res.partial.nodes].map(n => n.name),
329
- edges: [...res.partial.edges].map(e => e.name),
330
- })
331
- },
332
- )
333
-
334
- await t.test('exact match with perfect score', async t => {
335
- const res = await score(getState(':score(1, license)'))
336
- t.strictSame(
337
- [...res.partial.nodes].map(n => n.name),
338
- ['d'],
339
- 'should select packages with license score of exactly 1.0',
340
- )
341
- t.matchSnapshot({
342
- nodes: [...res.partial.nodes].map(n => n.name),
343
- edges: [...res.partial.edges].map(e => e.name),
344
- })
345
- })
346
- })
347
-
348
- t.test('error cases', async t => {
349
- // Test with missing security archive
350
- await t.test('missing security archive', async t => {
351
- const getState = (query: string) => {
352
- const ast = parse(query)
353
- const current = ast.first.first
354
- const state: ParserState = {
355
- comment: '',
356
- current,
357
- initial: {
358
- edges: new Set(),
359
- nodes: new Set(),
360
- },
361
- partial: {
362
- edges: new Set(),
363
- nodes: new Set(),
364
- },
365
- collect: {
366
- edges: new Set(),
367
- nodes: new Set(),
368
- },
369
- cancellable: async () => {},
370
- walk: async i => i,
371
- securityArchive: undefined,
372
- importers: new Set(),
373
- retries: 0,
374
- signal: new AbortController().signal,
375
- specificity: { idCounter: 0, commonCounter: 0 },
376
- }
377
- return state
378
- }
379
-
380
- await t.rejects(
381
- score(getState(':score(0.8)')),
382
- { message: /Missing security archive/ },
383
- 'should throw an error when security archive is missing',
384
- )
385
- })
386
-
387
- // Test with invalid rate value
388
- await t.test('invalid rate value - too high', async t => {
389
- const getState = (query: string) => {
390
- const ast = parse(query)
391
- const current = ast.first.first
392
- const state: ParserState = {
393
- comment: '',
394
- current,
395
- initial: {
396
- edges: new Set(),
397
- nodes: new Set(),
398
- },
399
- partial: {
400
- edges: new Set(),
401
- nodes: new Set(),
402
- },
403
- collect: {
404
- edges: new Set(),
405
- nodes: new Set(),
406
- },
407
- cancellable: async () => {},
408
- walk: async i => i,
409
- securityArchive: createTestSecurityArchive(),
410
- importers: new Set(),
411
- retries: 0,
412
- signal: new AbortController().signal,
413
- specificity: { idCounter: 0, commonCounter: 0 },
414
- }
415
- return state
416
- }
417
-
418
- await t.rejects(
419
- score(getState(':score(101)')),
420
- { message: /Failed to parse :score selector/ },
421
- 'should throw an error when rate value is greater than 100',
422
- )
423
- })
424
-
425
- // Test with invalid rate value - negative
426
- await t.test('invalid rate value - negative', async t => {
427
- const getState = (query: string) => {
428
- const ast = parse(query)
429
- const current = ast.first.first
430
- const state: ParserState = {
431
- comment: '',
432
- current,
433
- initial: {
434
- edges: new Set(),
435
- nodes: new Set(),
436
- },
437
- partial: {
438
- edges: new Set(),
439
- nodes: new Set(),
440
- },
441
- collect: {
442
- edges: new Set(),
443
- nodes: new Set(),
444
- },
445
- cancellable: async () => {},
446
- walk: async i => i,
447
- securityArchive: createTestSecurityArchive(),
448
- importers: new Set(),
449
- retries: 0,
450
- signal: new AbortController().signal,
451
- specificity: { idCounter: 0, commonCounter: 0 },
452
- }
453
- return state
454
- }
455
-
456
- await t.rejects(
457
- score(getState(':score("-0.5")')),
458
- { message: /Failed to parse :score selector/ },
459
- 'should throw an error when rate value is negative',
460
- )
461
- })
462
-
463
- // Test with invalid kind
464
- await t.test('invalid kind parameter', async t => {
465
- const getState = (query: string) => {
466
- const ast = parse(query)
467
- const current = ast.first.first
468
- const state: ParserState = {
469
- comment: '',
470
- current,
471
- initial: {
472
- edges: new Set(),
473
- nodes: new Set(),
474
- },
475
- partial: {
476
- edges: new Set(),
477
- nodes: new Set(),
478
- },
479
- collect: {
480
- edges: new Set(),
481
- nodes: new Set(),
482
- },
483
- cancellable: async () => {},
484
- walk: async i => i,
485
- securityArchive: createTestSecurityArchive(),
486
- importers: new Set(),
487
- retries: 0,
488
- signal: new AbortController().signal,
489
- specificity: { idCounter: 0, commonCounter: 0 },
490
- }
491
- return state
492
- }
493
-
494
- await t.rejects(
495
- score(getState(':score(0.8, invalid)')),
496
- { message: /Failed to parse :score selector/ },
497
- 'should throw an error when kind parameter is invalid',
498
- )
499
- })
500
- })
501
-
502
- t.test('utility functions', async t => {
503
- // Test isScoreKind function
504
- await t.test('isScoreKind', async t => {
505
- t.ok(
506
- isScoreKind('overall'),
507
- 'should return true for valid score kind "overall"',
508
- )
509
- t.ok(
510
- isScoreKind('license'),
511
- 'should return true for valid score kind "license"',
512
- )
513
- t.ok(
514
- isScoreKind('maintenance'),
515
- 'should return true for valid score kind "maintenance"',
516
- )
517
- t.ok(
518
- isScoreKind('quality'),
519
- 'should return true for valid score kind "quality"',
520
- )
521
- t.ok(
522
- isScoreKind('supplyChain'),
523
- 'should return true for valid score kind "supplyChain"',
524
- )
525
- t.ok(
526
- isScoreKind('vulnerability'),
527
- 'should return true for valid score kind "vulnerability"',
528
- )
529
- t.notOk(
530
- isScoreKind('invalid'),
531
- 'should return false for invalid score kind',
532
- )
533
- })
534
-
535
- // Test asScoreKind function
536
- await t.test('asScoreKind', async t => {
537
- t.equal(
538
- asScoreKind('overall'),
539
- 'overall',
540
- 'should return the score kind for valid input',
541
- )
542
- t.throws(
543
- () => asScoreKind('invalid'),
544
- { message: /Expected a valid score kind/ },
545
- 'should throw an error for invalid score kind',
546
- )
547
- })
548
- })
549
-
550
- t.test('pseudo state form - :score without parameters', async t => {
551
- const getState = (graph = getSimpleGraph()) => {
552
- const ast = parse(':score')
553
- const current = ast.first.first
554
- const state: ParserState = {
555
- comment: '',
556
- current,
557
- initial: {
558
- edges: new Set(graph.edges.values()),
559
- nodes: new Set(graph.nodes.values()),
560
- },
561
- partial: {
562
- edges: new Set(graph.edges.values()),
563
- nodes: new Set(graph.nodes.values()),
564
- },
565
- collect: {
566
- edges: new Set(),
567
- nodes: new Set(),
568
- },
569
- cancellable: async () => {},
570
- walk: async i => i,
571
- securityArchive: createTestSecurityArchive(),
572
- importers: new Set(graph.importers),
573
- retries: 0,
574
- signal: new AbortController().signal,
575
- specificity: { idCounter: 0, commonCounter: 0 },
576
- }
577
- return state
578
- }
579
-
580
- const state = getState()
581
- const result = await score(state)
582
- t.matchSnapshot(
583
- {
584
- nodes: [...result.partial.nodes].map(n => n.id),
585
- edges: [...result.partial.edges].map(
586
- e => `${e.from.id}->${e.to?.id}`,
587
- ),
588
- },
589
- 'should match any packages with score data (scanned packages)',
590
- )
591
- })