@vltpkg/query 1.5.0 → 1.6.1

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 (211) hide show
  1. package/dist/id.js +12 -5
  2. package/package.json +10 -12
  3. package/skills/dss-query/REFERENCE.md +0 -125
  4. package/skills/dss-query/SKILL.md +0 -190
  5. package/skills/dss-query/evals/README.md +0 -81
  6. package/skills/dss-query/evals/evals.json +0 -89
  7. package/skills/dss-query/evals/grade.mjs +0 -481
  8. package/src/attribute.ts +0 -190
  9. package/src/combinator.ts +0 -135
  10. package/src/error.ts +0 -78
  11. package/src/id.ts +0 -46
  12. package/src/index.ts +0 -670
  13. package/src/parser.ts +0 -122
  14. package/src/pseudo/abandoned.ts +0 -9
  15. package/src/pseudo/attr.ts +0 -92
  16. package/src/pseudo/built.ts +0 -19
  17. package/src/pseudo/confused.ts +0 -29
  18. package/src/pseudo/cve.ts +0 -93
  19. package/src/pseudo/cwe.ts +0 -97
  20. package/src/pseudo/debug.ts +0 -9
  21. package/src/pseudo/deprecated.ts +0 -9
  22. package/src/pseudo/dev.ts +0 -18
  23. package/src/pseudo/diff.ts +0 -90
  24. package/src/pseudo/dist.ts +0 -148
  25. package/src/pseudo/dynamic.ts +0 -9
  26. package/src/pseudo/empty.ts +0 -15
  27. package/src/pseudo/entropic.ts +0 -9
  28. package/src/pseudo/env.ts +0 -6
  29. package/src/pseudo/eval.ts +0 -9
  30. package/src/pseudo/fs.ts +0 -9
  31. package/src/pseudo/helpers.ts +0 -106
  32. package/src/pseudo/host.ts +0 -111
  33. package/src/pseudo/hostname.ts +0 -156
  34. package/src/pseudo/license.ts +0 -134
  35. package/src/pseudo/link.ts +0 -30
  36. package/src/pseudo/malware.ts +0 -41
  37. package/src/pseudo/minified.ts +0 -9
  38. package/src/pseudo/missing.ts +0 -16
  39. package/src/pseudo/native.ts +0 -9
  40. package/src/pseudo/network.ts +0 -9
  41. package/src/pseudo/obfuscated.ts +0 -9
  42. package/src/pseudo/optional.ts +0 -18
  43. package/src/pseudo/outdated.ts +0 -345
  44. package/src/pseudo/overridden.ts +0 -20
  45. package/src/pseudo/path.ts +0 -146
  46. package/src/pseudo/peer.ts +0 -18
  47. package/src/pseudo/prerelease.ts +0 -47
  48. package/src/pseudo/private.ts +0 -19
  49. package/src/pseudo/prod.ts +0 -18
  50. package/src/pseudo/published.ts +0 -250
  51. package/src/pseudo/registry.ts +0 -29
  52. package/src/pseudo/root.ts +0 -19
  53. package/src/pseudo/scanned.ts +0 -20
  54. package/src/pseudo/score.ts +0 -186
  55. package/src/pseudo/scripts.ts +0 -61
  56. package/src/pseudo/semver.ts +0 -320
  57. package/src/pseudo/severity.ts +0 -231
  58. package/src/pseudo/shell.ts +0 -9
  59. package/src/pseudo/shrinkwrap.ts +0 -9
  60. package/src/pseudo/skill.ts +0 -59
  61. package/src/pseudo/skills.ts +0 -29
  62. package/src/pseudo/spec.ts +0 -131
  63. package/src/pseudo/squat.ts +0 -225
  64. package/src/pseudo/suspicious.ts +0 -9
  65. package/src/pseudo/tracker.ts +0 -9
  66. package/src/pseudo/trivial.ts +0 -9
  67. package/src/pseudo/type.ts +0 -26
  68. package/src/pseudo/undesirable.ts +0 -9
  69. package/src/pseudo/unknown.ts +0 -9
  70. package/src/pseudo/unmaintained.ts +0 -9
  71. package/src/pseudo/unpopular.ts +0 -9
  72. package/src/pseudo/unstable.ts +0 -9
  73. package/src/pseudo/vuln.ts +0 -273
  74. package/src/pseudo/workspace.ts +0 -22
  75. package/src/pseudo.ts +0 -440
  76. package/src/types.ts +0 -206
  77. package/tap-snapshots/test/attribute.ts.test.cjs +0 -304
  78. package/tap-snapshots/test/combinator.ts.test.cjs +0 -333
  79. package/tap-snapshots/test/id.ts.test.cjs +0 -118
  80. package/tap-snapshots/test/parser.ts.test.cjs +0 -344
  81. package/tap-snapshots/test/pseudo/abandoned.ts.test.cjs +0 -18
  82. package/tap-snapshots/test/pseudo/attr.ts.test.cjs +0 -161
  83. package/tap-snapshots/test/pseudo/built.ts.test.cjs +0 -70
  84. package/tap-snapshots/test/pseudo/confused.ts.test.cjs +0 -32
  85. package/tap-snapshots/test/pseudo/cve.ts.test.cjs +0 -49
  86. package/tap-snapshots/test/pseudo/cwe.ts.test.cjs +0 -49
  87. package/tap-snapshots/test/pseudo/debug.ts.test.cjs +0 -18
  88. package/tap-snapshots/test/pseudo/deprecated.ts.test.cjs +0 -18
  89. package/tap-snapshots/test/pseudo/dist.ts.test.cjs +0 -30
  90. package/tap-snapshots/test/pseudo/dynamic.ts.test.cjs +0 -18
  91. package/tap-snapshots/test/pseudo/empty.ts.test.cjs +0 -50
  92. package/tap-snapshots/test/pseudo/entropic.ts.test.cjs +0 -18
  93. package/tap-snapshots/test/pseudo/env.ts.test.cjs +0 -18
  94. package/tap-snapshots/test/pseudo/eval.ts.test.cjs +0 -18
  95. package/tap-snapshots/test/pseudo/fs.ts.test.cjs +0 -18
  96. package/tap-snapshots/test/pseudo/helpers.ts.test.cjs +0 -18
  97. package/tap-snapshots/test/pseudo/hostname.ts.test.cjs +0 -148
  98. package/tap-snapshots/test/pseudo/license.ts.test.cjs +0 -41
  99. package/tap-snapshots/test/pseudo/link.ts.test.cjs +0 -36
  100. package/tap-snapshots/test/pseudo/malware.ts.test.cjs +0 -22
  101. package/tap-snapshots/test/pseudo/minified.ts.test.cjs +0 -18
  102. package/tap-snapshots/test/pseudo/missing.ts.test.cjs +0 -30
  103. package/tap-snapshots/test/pseudo/native.ts.test.cjs +0 -18
  104. package/tap-snapshots/test/pseudo/network.ts.test.cjs +0 -18
  105. package/tap-snapshots/test/pseudo/obfuscated.ts.test.cjs +0 -18
  106. package/tap-snapshots/test/pseudo/outdated.ts.test.cjs +0 -132
  107. package/tap-snapshots/test/pseudo/overridden.ts.test.cjs +0 -75
  108. package/tap-snapshots/test/pseudo/prerelease.ts.test.cjs +0 -101
  109. package/tap-snapshots/test/pseudo/private.ts.test.cjs +0 -38
  110. package/tap-snapshots/test/pseudo/published.ts.test.cjs +0 -171
  111. package/tap-snapshots/test/pseudo/registry.ts.test.cjs +0 -68
  112. package/tap-snapshots/test/pseudo/root.ts.test.cjs +0 -24
  113. package/tap-snapshots/test/pseudo/scanned.ts.test.cjs +0 -18
  114. package/tap-snapshots/test/pseudo/score.ts.test.cjs +0 -239
  115. package/tap-snapshots/test/pseudo/scripts.ts.test.cjs +0 -62
  116. package/tap-snapshots/test/pseudo/semver.ts.test.cjs +0 -575
  117. package/tap-snapshots/test/pseudo/severity.ts.test.cjs +0 -122
  118. package/tap-snapshots/test/pseudo/shell.ts.test.cjs +0 -18
  119. package/tap-snapshots/test/pseudo/shrinkwrap.ts.test.cjs +0 -18
  120. package/tap-snapshots/test/pseudo/skills.ts.test.cjs +0 -19
  121. package/tap-snapshots/test/pseudo/spec.ts.test.cjs +0 -148
  122. package/tap-snapshots/test/pseudo/squat.ts.test.cjs +0 -129
  123. package/tap-snapshots/test/pseudo/suspicious.ts.test.cjs +0 -18
  124. package/tap-snapshots/test/pseudo/tracker.ts.test.cjs +0 -18
  125. package/tap-snapshots/test/pseudo/trivial.ts.test.cjs +0 -18
  126. package/tap-snapshots/test/pseudo/type.ts.test.cjs +0 -51
  127. package/tap-snapshots/test/pseudo/undesirable.ts.test.cjs +0 -18
  128. package/tap-snapshots/test/pseudo/unknown.ts.test.cjs +0 -18
  129. package/tap-snapshots/test/pseudo/unmaintained.ts.test.cjs +0 -18
  130. package/tap-snapshots/test/pseudo/unpopular.ts.test.cjs +0 -18
  131. package/tap-snapshots/test/pseudo/unstable.ts.test.cjs +0 -18
  132. package/tap-snapshots/test/pseudo/vuln.ts.test.cjs +0 -208
  133. package/tap-snapshots/test/pseudo/vulnerable.ts.test.cjs +0 -20
  134. package/tap-snapshots/test/pseudo/workspace.ts.test.cjs +0 -19
  135. package/tap-snapshots/test/pseudo.ts.test.cjs +0 -1247
  136. package/test/attribute.ts +0 -273
  137. package/test/combinator.ts +0 -175
  138. package/test/error.ts +0 -60
  139. package/test/fixtures/graph.ts +0 -999
  140. package/test/fixtures/selector.ts +0 -103
  141. package/test/fixtures/types.ts +0 -7
  142. package/test/id.ts +0 -102
  143. package/test/index.ts +0 -1148
  144. package/test/parser.ts +0 -117
  145. package/test/pseudo/abandoned.ts +0 -98
  146. package/test/pseudo/attr.ts +0 -298
  147. package/test/pseudo/built.ts +0 -214
  148. package/test/pseudo/confused.ts +0 -160
  149. package/test/pseudo/cve.ts +0 -249
  150. package/test/pseudo/cwe.ts +0 -255
  151. package/test/pseudo/debug.ts +0 -98
  152. package/test/pseudo/deprecated.ts +0 -98
  153. package/test/pseudo/dev.ts +0 -61
  154. package/test/pseudo/diff.ts +0 -417
  155. package/test/pseudo/dist.ts +0 -215
  156. package/test/pseudo/dynamic.ts +0 -98
  157. package/test/pseudo/empty.ts +0 -108
  158. package/test/pseudo/entropic.ts +0 -101
  159. package/test/pseudo/env.ts +0 -98
  160. package/test/pseudo/eval.ts +0 -98
  161. package/test/pseudo/fs.ts +0 -98
  162. package/test/pseudo/helpers.ts +0 -370
  163. package/test/pseudo/host-context.ts +0 -276
  164. package/test/pseudo/hostname.ts +0 -314
  165. package/test/pseudo/license.ts +0 -265
  166. package/test/pseudo/link.ts +0 -94
  167. package/test/pseudo/malware.ts +0 -184
  168. package/test/pseudo/minified.ts +0 -98
  169. package/test/pseudo/missing.ts +0 -111
  170. package/test/pseudo/native.ts +0 -98
  171. package/test/pseudo/network.ts +0 -98
  172. package/test/pseudo/obfuscated.ts +0 -98
  173. package/test/pseudo/optional.ts +0 -73
  174. package/test/pseudo/outdated.ts +0 -461
  175. package/test/pseudo/overridden.ts +0 -317
  176. package/test/pseudo/path.ts +0 -680
  177. package/test/pseudo/peer.ts +0 -101
  178. package/test/pseudo/prerelease.ts +0 -279
  179. package/test/pseudo/private.ts +0 -108
  180. package/test/pseudo/prod.ts +0 -61
  181. package/test/pseudo/published.ts +0 -557
  182. package/test/pseudo/registry.ts +0 -122
  183. package/test/pseudo/root.ts +0 -66
  184. package/test/pseudo/scanned.ts +0 -144
  185. package/test/pseudo/score.ts +0 -591
  186. package/test/pseudo/scripts.ts +0 -324
  187. package/test/pseudo/semver.ts +0 -822
  188. package/test/pseudo/severity.ts +0 -342
  189. package/test/pseudo/shell.ts +0 -98
  190. package/test/pseudo/shrinkwrap.ts +0 -98
  191. package/test/pseudo/skill.ts +0 -189
  192. package/test/pseudo/skills.ts +0 -90
  193. package/test/pseudo/spec.ts +0 -525
  194. package/test/pseudo/squat.ts +0 -565
  195. package/test/pseudo/suspicious.ts +0 -98
  196. package/test/pseudo/tracker.ts +0 -98
  197. package/test/pseudo/trivial.ts +0 -98
  198. package/test/pseudo/type.ts +0 -105
  199. package/test/pseudo/undesirable.ts +0 -98
  200. package/test/pseudo/unknown.ts +0 -98
  201. package/test/pseudo/unmaintained.ts +0 -98
  202. package/test/pseudo/unpopular.ts +0 -98
  203. package/test/pseudo/unstable.ts +0 -98
  204. package/test/pseudo/vuln.ts +0 -625
  205. package/test/pseudo/vulnerable.ts +0 -137
  206. package/test/pseudo/workspace.ts +0 -111
  207. package/test/pseudo.ts +0 -584
  208. package/tsconfig.json +0 -3
  209. package/tsconfig.publish.json +0 -19
  210. package/tsconfig.publish.tsbuildinfo +0 -1
  211. package/typedoc.mjs +0 -2
@@ -1,314 +0,0 @@
1
- import t from 'tap'
2
- import postcssSelectorParser from 'postcss-selector-parser'
3
- import type { ParserState } from '../../src/types.ts'
4
- import { hostname } from '../../src/pseudo/hostname.ts'
5
- import {
6
- getSimpleGraph,
7
- getAliasedGraph,
8
- getGitGraph,
9
- getRemoteGraph,
10
- getLinkedGraph,
11
- getCustomGitHostGraph,
12
- getHttpsGitGraph,
13
- getBrokenGitGraph,
14
- getUnknownRegistryGraph,
15
- } from '../fixtures/graph.ts'
16
-
17
- t.test('selects nodes by hostname', async t => {
18
- const getState = (query: string, graph = getSimpleGraph()) => {
19
- const ast = postcssSelectorParser().astSync(query)
20
- const current = ast.first.first
21
- const state: ParserState = {
22
- comment: '',
23
- current,
24
- initial: {
25
- edges: new Set(graph.edges.values()),
26
- nodes: new Set(graph.nodes.values()),
27
- },
28
- partial: {
29
- edges: new Set(graph.edges.values()),
30
- nodes: new Set(graph.nodes.values()),
31
- },
32
- collect: {
33
- edges: new Set(),
34
- nodes: new Set(),
35
- },
36
- cancellable: async () => {},
37
- walk: async i => i,
38
- retries: 0,
39
- securityArchive: undefined,
40
- importers: new Set(graph.importers),
41
- signal: new AbortController().signal,
42
- specificity: { idCounter: 0, commonCounter: 0 },
43
- }
44
- return state
45
- }
46
-
47
- await t.test(
48
- 'matches default registry deps by hostname',
49
- async t => {
50
- const res = await hostname(
51
- getState(':hostname("registry.npmjs.org")'),
52
- )
53
- t.strictSame(
54
- [...res.partial.nodes].map(n => n.name).sort(),
55
- ['a', 'b', 'c', 'd', 'e', 'f'],
56
- 'should match all default registry packages',
57
- )
58
- t.matchSnapshot({
59
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
60
- edges: [...res.partial.edges].map(e => e.name).sort(),
61
- })
62
- },
63
- )
64
-
65
- await t.test(
66
- 'matches custom registry deps by hostname',
67
- async t => {
68
- const graph = getAliasedGraph()
69
- const res = await hostname(
70
- getState(':hostname("example.com")', graph),
71
- )
72
- t.strictSame(
73
- [...res.partial.nodes].map(n => n.name).sort(),
74
- ['c'],
75
- 'should match only custom registry packages',
76
- )
77
- t.matchSnapshot({
78
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
79
- edges: [...res.partial.edges].map(e => e.name).sort(),
80
- })
81
- },
82
- )
83
-
84
- await t.test('matches github git deps by hostname', async t => {
85
- const graph = getGitGraph()
86
- const res = await hostname(
87
- getState(':hostname("github.com")', graph),
88
- )
89
- t.strictSame(
90
- [...res.partial.nodes].map(n => n.name).sort(),
91
- ['a'],
92
- 'should match only github deps',
93
- )
94
- t.matchSnapshot({
95
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
96
- edges: [...res.partial.edges].map(e => e.name).sort(),
97
- })
98
- })
99
-
100
- await t.test('matches gitlab git deps by hostname', async t => {
101
- const graph = getGitGraph()
102
- const res = await hostname(
103
- getState(':hostname("gitlab.com")', graph),
104
- )
105
- t.strictSame(
106
- [...res.partial.nodes].map(n => n.name).sort(),
107
- ['b'],
108
- 'should match only gitlab deps',
109
- )
110
- t.matchSnapshot({
111
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
112
- edges: [...res.partial.edges].map(e => e.name).sort(),
113
- })
114
- })
115
-
116
- await t.test(
117
- 'matches git deps with full URL by hostname',
118
- async t => {
119
- const graph = getGitGraph()
120
- const res = await hostname(
121
- getState(':hostname("custom-git.example.com")', graph),
122
- )
123
- t.strictSame(
124
- [...res.partial.nodes].map(n => n.name).sort(),
125
- ['c'],
126
- 'should match git dep with full URL',
127
- )
128
- t.matchSnapshot({
129
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
130
- edges: [...res.partial.edges].map(e => e.name).sort(),
131
- })
132
- },
133
- )
134
-
135
- await t.test('matches remote deps by hostname', async t => {
136
- const graph = getRemoteGraph()
137
- const res = await hostname(
138
- getState(':hostname("cdn.example.com")', graph),
139
- )
140
- t.strictSame(
141
- [...res.partial.nodes].map(n => n.name).sort(),
142
- ['a'],
143
- 'should match remote dep by hostname',
144
- )
145
- t.matchSnapshot({
146
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
147
- edges: [...res.partial.edges].map(e => e.name).sort(),
148
- })
149
- })
150
-
151
- await t.test(
152
- 'excludes file deps from hostname matching',
153
- async t => {
154
- const graph = getLinkedGraph()
155
- const res = await hostname(
156
- getState(':hostname("registry.npmjs.org")', graph),
157
- )
158
- t.strictSame(
159
- [...res.partial.nodes].map(n => n.name).sort(),
160
- ['b'],
161
- 'should exclude file deps and only match registry dep',
162
- )
163
- t.matchSnapshot({
164
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
165
- edges: [...res.partial.edges].map(e => e.name).sort(),
166
- })
167
- },
168
- )
169
-
170
- await t.test(
171
- 'returns empty when hostname does not match',
172
- async t => {
173
- const res = await hostname(
174
- getState(':hostname("nonexistent.com")'),
175
- )
176
- t.strictSame(
177
- [...res.partial.nodes].map(n => n.name),
178
- [],
179
- 'should return no nodes for nonexistent hostname',
180
- )
181
- t.matchSnapshot({
182
- nodes: [...res.partial.nodes].map(n => n.name),
183
- edges: [...res.partial.edges].map(e => e.name),
184
- })
185
- },
186
- )
187
-
188
- await t.test(
189
- 'falls back to default registry for unknown registry name',
190
- async t => {
191
- const graph = getUnknownRegistryGraph()
192
- const res = await hostname(
193
- getState(':hostname("registry.npmjs.org")', graph),
194
- )
195
- t.strictSame(
196
- [...res.partial.nodes].map(n => n.name).sort(),
197
- ['a'],
198
- 'should fall back to default registry hostname',
199
- )
200
- t.matchSnapshot({
201
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
202
- edges: [...res.partial.edges].map(e => e.name).sort(),
203
- })
204
- },
205
- )
206
-
207
- await t.test(
208
- 'matches custom named git host via template URL',
209
- async t => {
210
- const graph = getCustomGitHostGraph()
211
- const res = await hostname(
212
- getState(':hostname("myserver.example.com")', graph),
213
- )
214
- t.strictSame(
215
- [...res.partial.nodes].map(n => n.name).sort(),
216
- ['a'],
217
- 'should match custom git host via template URL parsing',
218
- )
219
- t.matchSnapshot({
220
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
221
- edges: [...res.partial.edges].map(e => e.name).sort(),
222
- })
223
- },
224
- )
225
-
226
- await t.test(
227
- 'matches git dep with plain https URL remote',
228
- async t => {
229
- const graph = getHttpsGitGraph()
230
- const res = await hostname(
231
- getState(':hostname("git.example.org")', graph),
232
- )
233
- t.strictSame(
234
- [...res.partial.nodes].map(n => n.name).sort(),
235
- ['a'],
236
- 'should match git dep with plain https URL',
237
- )
238
- t.matchSnapshot({
239
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
240
- edges: [...res.partial.edges].map(e => e.name).sort(),
241
- })
242
- },
243
- )
244
-
245
- await t.test(
246
- 'excludes git deps with unparseable remote URLs',
247
- async t => {
248
- const graph = getBrokenGitGraph()
249
- const res = await hostname(
250
- getState(':hostname("anything.com")', graph),
251
- )
252
- t.strictSame(
253
- [...res.partial.nodes].map(n => n.name),
254
- [],
255
- 'should not match any nodes with broken git URLs',
256
- )
257
- t.matchSnapshot({
258
- nodes: [...res.partial.nodes].map(n => n.name),
259
- edges: [...res.partial.edges].map(e => e.name),
260
- })
261
- },
262
- )
263
-
264
- await t.test('throws on invalid selector', async t => {
265
- const ast = postcssSelectorParser().astSync(':hostname')
266
- const current = ast.first.first
267
- const graph = getSimpleGraph()
268
- const state: ParserState = {
269
- comment: '',
270
- current,
271
- initial: {
272
- edges: new Set(graph.edges.values()),
273
- nodes: new Set(graph.nodes.values()),
274
- },
275
- partial: {
276
- edges: new Set(graph.edges.values()),
277
- nodes: new Set(graph.nodes.values()),
278
- },
279
- collect: {
280
- edges: new Set(),
281
- nodes: new Set(),
282
- },
283
- cancellable: async () => {},
284
- walk: async i => i,
285
- retries: 0,
286
- securityArchive: undefined,
287
- importers: new Set(graph.importers),
288
- signal: new AbortController().signal,
289
- specificity: { idCounter: 0, commonCounter: 0 },
290
- }
291
- await t.rejects(
292
- hostname(state),
293
- { message: /Failed to parse :hostname selector/ },
294
- 'should throw an error for invalid selector',
295
- )
296
- })
297
-
298
- await t.test('handles empty partial state', async t => {
299
- const state = getState(':hostname("registry.npmjs.org")')
300
- state.partial.nodes.clear()
301
- state.partial.edges.clear()
302
-
303
- const res = await hostname(state)
304
- t.strictSame(
305
- [...res.partial.nodes].map(n => n.name),
306
- [],
307
- 'should return empty when partial state is empty',
308
- )
309
- t.matchSnapshot({
310
- nodes: [...res.partial.nodes].map(n => n.name),
311
- edges: [...res.partial.edges].map(e => e.name),
312
- })
313
- })
314
- })
@@ -1,265 +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 { parse } from '../../src/parser.ts'
7
- import {
8
- license,
9
- isLicenseKind,
10
- asLicenseKind,
11
- } from '../../src/pseudo/license.ts'
12
-
13
- t.test('selects packages with a specific license kind', async t => {
14
- const getState = (query: string, graph = getSimpleGraph()) => {
15
- const ast = parse(query)
16
- const current = ast.first.first
17
- const state: ParserState = {
18
- comment: '',
19
- current,
20
- initial: {
21
- edges: new Set(graph.edges.values()),
22
- nodes: new Set(graph.nodes.values()),
23
- },
24
- partial: {
25
- edges: new Set(graph.edges.values()),
26
- nodes: new Set(graph.nodes.values()),
27
- },
28
- collect: {
29
- edges: new Set(),
30
- nodes: new Set(),
31
- },
32
- cancellable: async () => {},
33
- walk: async i => i,
34
- retries: 0,
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: 'explicitlyUnlicensedItem' }],
42
- },
43
- ],
44
- [
45
- joinDepIDTuple(['registry', '', 'f@1.0.0']),
46
- {
47
- id: joinDepIDTuple(['registry', '', 'f@1.0.0']),
48
- alerts: [{ type: 'miscLicenseIssues' }],
49
- },
50
- ],
51
- ]),
52
- ),
53
- importers: new Set(graph.importers),
54
- signal: new AbortController().signal,
55
- specificity: { idCounter: 0, commonCounter: 0 },
56
- }
57
- return state
58
- }
59
-
60
- await t.test(
61
- 'filter out any node that does not have the license',
62
- async t => {
63
- const res = await license(getState(':license("unlicensed")'))
64
- t.strictSame(
65
- [...res.partial.nodes].map(n => n.name),
66
- ['e'],
67
- 'should select only packages with the specified license',
68
- )
69
- t.matchSnapshot({
70
- nodes: [...res.partial.nodes].map(n => n.name),
71
- edges: [...res.partial.edges].map(e => e.name),
72
- })
73
- },
74
- )
75
-
76
- await t.test('filter out using unquoted param', async t => {
77
- const res = await license(getState(':license(misc)'))
78
- t.strictSame(
79
- [...res.partial.nodes].map(n => n.name),
80
- ['f'],
81
- 'should select only packages with the specified license',
82
- )
83
- t.matchSnapshot({
84
- nodes: [...res.partial.nodes].map(n => n.name),
85
- edges: [...res.partial.edges].map(e => e.name),
86
- })
87
- })
88
-
89
- await t.test('pseudo state form works', async t => {
90
- // :license without parameters should now work as pseudo state
91
- const result = await license(getState(':license'))
92
- t.ok(result, 'should not throw an error for pseudo state form')
93
- })
94
- })
95
-
96
- t.test('missing security archive', async t => {
97
- const getState = (query: string) => {
98
- const ast = parse(query)
99
- const current = ast.first.first
100
- const state: ParserState = {
101
- comment: '',
102
- current,
103
- initial: {
104
- edges: new Set(),
105
- nodes: new Set(),
106
- },
107
- partial: {
108
- edges: new Set(),
109
- nodes: new Set(),
110
- },
111
- collect: {
112
- edges: new Set(),
113
- nodes: new Set(),
114
- },
115
- cancellable: async () => {},
116
- walk: async i => i,
117
- retries: 0,
118
- securityArchive: undefined,
119
- importers: new Set(),
120
- signal: new AbortController().signal,
121
- specificity: { idCounter: 0, commonCounter: 0 },
122
- }
123
- return state
124
- }
125
-
126
- await t.rejects(
127
- license(getState(':license(unlicensed)')),
128
- { message: /Missing security archive/ },
129
- 'should throw an error',
130
- )
131
- })
132
-
133
- t.test('isLicenseKind', async t => {
134
- t.ok(
135
- isLicenseKind('unlicensed'),
136
- 'should return true for valid license kinds',
137
- )
138
- t.notOk(
139
- isLicenseKind('invalid'),
140
- 'should return false for invalid license kinds',
141
- )
142
- })
143
-
144
- t.test('asLicenseKind', async t => {
145
- t.equal(
146
- asLicenseKind('unlicensed'),
147
- 'unlicensed',
148
- 'should return the license kind',
149
- )
150
- t.throws(
151
- () => asLicenseKind('invalid'),
152
- { message: /Expected a valid license kind/ },
153
- 'should throw an error for invalid license kinds',
154
- )
155
- })
156
-
157
- t.test('pseudo state form - :license without parameters', async t => {
158
- const getState = (graph = getSimpleGraph()) => {
159
- const ast = parse(':license')
160
- const current = ast.first.first
161
- const state: ParserState = {
162
- comment: '',
163
- current,
164
- initial: {
165
- edges: new Set(graph.edges.values()),
166
- nodes: new Set(graph.nodes.values()),
167
- },
168
- partial: {
169
- edges: new Set(graph.edges.values()),
170
- nodes: new Set(graph.nodes.values()),
171
- },
172
- collect: {
173
- edges: new Set(),
174
- nodes: new Set(),
175
- },
176
- cancellable: async () => {},
177
- walk: async i => i,
178
- securityArchive: asSecurityArchiveLike(
179
- new Map([
180
- [
181
- joinDepIDTuple(['registry', '', 'e@1.0.0']),
182
- {
183
- id: joinDepIDTuple(['registry', '', 'e@1.0.0']),
184
- alerts: [{ type: 'explicitlyUnlicensedItem' }],
185
- },
186
- ],
187
- [
188
- joinDepIDTuple(['registry', '', 'f@1.0.0']),
189
- {
190
- id: joinDepIDTuple(['registry', '', 'f@1.0.0']),
191
- alerts: [{ type: 'noLicenseFound' }],
192
- },
193
- ],
194
- ]),
195
- ),
196
- importers: new Set(graph.importers),
197
- retries: 0,
198
- signal: new AbortController().signal,
199
- specificity: { idCounter: 0, commonCounter: 0 },
200
- }
201
- return state
202
- }
203
-
204
- const state = getState()
205
- const result = await license(state)
206
- t.matchSnapshot(
207
- {
208
- nodes: [...result.partial.nodes].map(n => n.id),
209
- edges: [...result.partial.edges].map(
210
- e => `${e.from.id}->${e.to?.id}`,
211
- ),
212
- },
213
- 'should match packages with any license defined (not none)',
214
- )
215
- })
216
-
217
- t.test('error handling for non-query node errors', async t => {
218
- // Create a state that will trigger a non-"Expected a query node" error
219
- // by providing malformed AST structure that causes a different parsing error
220
- const ast = parse(':license(invalid)')
221
- const current = ast.first.first
222
-
223
- // Create a corrupted current node that will cause asPostcssNodeWithChildren to fail
224
- // with a different error than "Expected a query node"
225
- const corruptedCurrent = {
226
- ...current,
227
- nodes: [
228
- {
229
- type: 'function',
230
- value: 'license',
231
- nodes: null, // This will cause asPostcssNodeWithChildren to fail differently
232
- },
233
- ],
234
- }
235
-
236
- const state: ParserState = {
237
- comment: '',
238
- current: corruptedCurrent as any,
239
- initial: {
240
- edges: new Set(),
241
- nodes: new Set(),
242
- },
243
- partial: {
244
- edges: new Set(),
245
- nodes: new Set(),
246
- },
247
- collect: {
248
- edges: new Set(),
249
- nodes: new Set(),
250
- },
251
- cancellable: async () => {},
252
- walk: async i => i,
253
- securityArchive: asSecurityArchiveLike(new Map()),
254
- importers: new Set(),
255
- retries: 0,
256
- signal: new AbortController().signal,
257
- specificity: { idCounter: 0, commonCounter: 0 },
258
- }
259
-
260
- await t.rejects(
261
- license(state),
262
- { message: /Failed to parse :license selector/ },
263
- 'should throw error for parsing failures other than missing query node',
264
- )
265
- })
@@ -1,94 +0,0 @@
1
- import t from 'tap'
2
- import postcssSelectorParser from 'postcss-selector-parser'
3
- import type { ParserState } from '../../src/types.ts'
4
- import { link } from '../../src/pseudo/link.ts'
5
- import { getSimpleGraph, getLinkedGraph } from '../fixtures/graph.ts'
6
-
7
- t.test('selects file links and tar.gz packages', async t => {
8
- const getState = (query: string, graph = getSimpleGraph()) => {
9
- const ast = postcssSelectorParser().astSync(query)
10
- const current = ast.first.first
11
- const state: ParserState = {
12
- comment: '',
13
- current,
14
- initial: {
15
- edges: new Set(graph.edges.values()),
16
- nodes: new Set(graph.nodes.values()),
17
- },
18
- partial: {
19
- edges: new Set(graph.edges.values()),
20
- nodes: new Set(graph.nodes.values()),
21
- },
22
- collect: {
23
- edges: new Set(),
24
- nodes: new Set(),
25
- },
26
- cancellable: async () => {},
27
- walk: async i => i,
28
- retries: 0,
29
- securityArchive: undefined,
30
- importers: new Set(graph.importers),
31
- signal: new AbortController().signal,
32
- specificity: { idCounter: 0, commonCounter: 0 },
33
- }
34
- return state
35
- }
36
-
37
- await t.test(
38
- 'selects nodes that are file links in simple graph',
39
- async t => {
40
- // Based on the getSimpleGraph fixture, only '@x/y' is a file link
41
- const res = await link(getState(':link'))
42
- t.strictSame(
43
- [...res.partial.nodes].map(n => n.name).sort(),
44
- ['@x/y'].sort(),
45
- 'should select only file link packages in simple graph',
46
- )
47
- t.matchSnapshot({
48
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
49
- edges: [...res.partial.edges].map(e => e.name).sort(),
50
- })
51
- },
52
- )
53
-
54
- await t.test(
55
- 'selects nodes that are file links or tar.gz in linked graph',
56
- async t => {
57
- // In getLinkedGraph, 'a' is a file
58
- const linkedGraph = getLinkedGraph()
59
- const res = await link(getState(':link', linkedGraph))
60
- t.strictSame(
61
- [...res.partial.nodes].map(n => n.name).sort(),
62
- ['a'].sort(),
63
- 'should select file links packages',
64
- )
65
- t.strictSame(
66
- [...res.partial.edges].map(e => e.name).sort(),
67
- ['a', 'd'].sort(),
68
- 'should select file links edges including to missing packages',
69
- )
70
- t.matchSnapshot({
71
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
72
- edges: [...res.partial.edges].map(e => e.name).sort(),
73
- })
74
- },
75
- )
76
-
77
- await t.test('handles an empty partial state', async t => {
78
- // Create a state with empty partial nodes
79
- const state = getState(':link')
80
- state.partial.nodes.clear()
81
- state.partial.edges.clear()
82
-
83
- const res = await link(state)
84
- t.strictSame(
85
- [...res.partial.nodes].map(n => n.name),
86
- [],
87
- 'should return empty array when starting with empty partial state',
88
- )
89
- t.matchSnapshot({
90
- nodes: [...res.partial.nodes].map(n => n.name),
91
- edges: [...res.partial.edges].map(e => e.name),
92
- })
93
- })
94
- })