@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,557 +0,0 @@
1
- import t from 'tap'
2
- import { joinDepIDTuple } from '@vltpkg/dep-id'
3
- import { asPostcssNodeWithChildren, parse } from '@vltpkg/dss-parser'
4
- import {
5
- published,
6
- parseInternals,
7
- queueNode,
8
- retrieveRemoteDate,
9
- } from '../../src/pseudo/published.ts'
10
- import {
11
- getSemverRichGraph,
12
- getSimpleGraph,
13
- } from '../fixtures/graph.ts'
14
- import type { NodeLike } from '@vltpkg/types'
15
- import type { SpecOptions } from '@vltpkg/spec'
16
- import type { ParserState } from '../../src/types.ts'
17
-
18
- // the `npm` alias is no longer built in; configure it so the
19
- // default-registry DepIDs hydrate to the npm registry URL. Typed as
20
- // SpecOptions so the surrounding `as NodeLike` casts stay valid.
21
- const npmSpecOptions: SpecOptions = {
22
- registries: { npm: 'https://registry.npmjs.org/' },
23
- }
24
-
25
- global.fetch = (async (url: string) => {
26
- if (url === 'https://registry.npmjs.org/h') {
27
- return {
28
- ok: false,
29
- }
30
- } else if (url === 'https://registry.npmjs.org/i') {
31
- throw new Error('ERR')
32
- } else if (url === 'https://registry.npmjs.org/c') {
33
- return {
34
- status: 404,
35
- ok: false,
36
- }
37
- }
38
- return {
39
- ok: true,
40
- json: async () => {
41
- switch (url) {
42
- case 'https://registry.npmjs.org/a': {
43
- return {
44
- time: {
45
- '1.0.1': '2024-01-01T11:11:11.111Z',
46
- },
47
- }
48
- }
49
- case 'https://registry.npmjs.org/b': {
50
- return {
51
- time: {
52
- '2.2.1': '2024-02-01T00:00:00.000Z',
53
- },
54
- }
55
- }
56
- case 'http://example.com/c': {
57
- return {
58
- time: {
59
- '3.4.0': '2024-03-01T00:00:00.000Z',
60
- },
61
- }
62
- }
63
- case 'https://registry.npmjs.org/d': {
64
- return {
65
- time: {
66
- '2.3.4': '2024-04-01T00:00:00.000Z',
67
- },
68
- }
69
- }
70
- case 'https://registry.npmjs.org/e': {
71
- return {
72
- time: {
73
- '120.0.0': '2024-05-01T00:00:00.000Z',
74
- },
75
- }
76
- }
77
- }
78
- },
79
- }
80
- }) as unknown as typeof global.fetch
81
-
82
- const getState = (query: string, graph = getSemverRichGraph()) => {
83
- const ast = parse(query)
84
- const current = ast.first.first
85
- const state: ParserState = {
86
- comment: '',
87
- current,
88
- initial: {
89
- edges: new Set(graph.edges.values()),
90
- nodes: new Set(graph.nodes.values()),
91
- },
92
- partial: {
93
- edges: new Set(graph.edges.values()),
94
- nodes: new Set(graph.nodes.values()),
95
- },
96
- collect: {
97
- edges: new Set(),
98
- nodes: new Set(),
99
- },
100
- cancellable: async () => {},
101
- walk: async i => i,
102
- retries: 0,
103
- importers: new Set(graph.importers),
104
- securityArchive: undefined,
105
- signal: new AbortController().signal,
106
- specificity: { idCounter: 0, commonCounter: 0 },
107
- }
108
- return state
109
- }
110
-
111
- t.test('select from published definition', async t => {
112
- t.capture(console, 'warn')
113
-
114
- await t.test('published exact time', async t => {
115
- const res = await published(
116
- getState(':published(2024-01-01T11:11:11.111Z)'),
117
- )
118
- t.strictSame(
119
- [...res.partial.nodes].map(n => n.name),
120
- ['a'],
121
- 'should have expected result using exact date match',
122
- )
123
- t.matchSnapshot({
124
- nodes: [...res.partial.nodes].map(n => n.name),
125
- edges: [...res.partial.edges].map(e => e.name),
126
- })
127
- })
128
-
129
- await t.test('published exact time (quoted)', async t => {
130
- const res = await published(
131
- getState(':published("2024-01-01T11:11:11.111Z")'),
132
- )
133
- t.strictSame(
134
- [...res.partial.nodes].map(n => n.name),
135
- ['a'],
136
- 'should have expected result using greater than date',
137
- )
138
- t.matchSnapshot({
139
- nodes: [...res.partial.nodes].map(n => n.name),
140
- edges: [...res.partial.edges].map(e => e.name),
141
- })
142
- })
143
-
144
- await t.test('published exact date', async t => {
145
- const res = await published(getState(':published(2024-01-01)'))
146
- t.strictSame(
147
- [...res.partial.nodes].map(n => n.name),
148
- ['a'],
149
- 'should have expected result using exact date match',
150
- )
151
- t.matchSnapshot({
152
- nodes: [...res.partial.nodes].map(n => n.name),
153
- edges: [...res.partial.edges].map(e => e.name),
154
- })
155
- })
156
-
157
- await t.test('published greater than date (quoted)', async t => {
158
- const res = await published(getState(':published(">2024-02-01")'))
159
- t.strictSame(
160
- [...res.partial.nodes].map(n => n.name),
161
- ['c', 'd', 'e'],
162
- 'should have expected result using greater than date',
163
- )
164
- t.matchSnapshot({
165
- nodes: [...res.partial.nodes].map(n => n.name),
166
- edges: [...res.partial.edges].map(e => e.name),
167
- })
168
- })
169
-
170
- await t.test('published greater than date (unquoted)', async t => {
171
- const res = await published(getState(':published(>2024-02-01)'))
172
- t.strictSame(
173
- [...res.partial.nodes].map(n => n.name),
174
- ['c', 'd', 'e'],
175
- 'should have expected result using unquoted greater than date',
176
- )
177
- t.matchSnapshot({
178
- nodes: [...res.partial.nodes].map(n => n.name),
179
- edges: [...res.partial.edges].map(e => e.name),
180
- })
181
- })
182
-
183
- await t.test(
184
- 'published greater than or equal date (quoted)',
185
- async t => {
186
- const res = await published(
187
- getState(':published(">=2024-02-01")'),
188
- )
189
- t.strictSame(
190
- [...res.partial.nodes].map(n => n.name),
191
- ['b', 'c', 'd', 'e'],
192
- 'should have expected result using greater than date',
193
- )
194
- t.matchSnapshot({
195
- nodes: [...res.partial.nodes].map(n => n.name),
196
- edges: [...res.partial.edges].map(e => e.name),
197
- })
198
- },
199
- )
200
-
201
- await t.test(
202
- 'published greater than or equal date (unquoted)',
203
- async t => {
204
- const res = await published(
205
- getState(':published(>=2024-02-01)'),
206
- )
207
- t.strictSame(
208
- [...res.partial.nodes].map(n => n.name),
209
- ['b', 'c', 'd', 'e'],
210
- 'should have expected result using unquoted greater than or equal date',
211
- )
212
- t.matchSnapshot({
213
- nodes: [...res.partial.nodes].map(n => n.name),
214
- edges: [...res.partial.edges].map(e => e.name),
215
- })
216
- },
217
- )
218
-
219
- await t.test('published less than date (quoted)', async t => {
220
- const res = await published(getState(':published("<2024-02-01")'))
221
- t.strictSame(
222
- [...res.partial.nodes].map(n => n.name),
223
- ['a'],
224
- 'should have expected result using less than or equal date',
225
- )
226
- t.matchSnapshot({
227
- nodes: [...res.partial.nodes].map(n => n.name),
228
- edges: [...res.partial.edges].map(e => e.name),
229
- })
230
- })
231
-
232
- await t.test('published less than date (unquoted)', async t => {
233
- const res = await published(getState(':published(<2024-02-01)'))
234
- t.strictSame(
235
- [...res.partial.nodes].map(n => n.name),
236
- ['a'],
237
- 'should have expected result using unquoted less than date',
238
- )
239
- t.matchSnapshot({
240
- nodes: [...res.partial.nodes].map(n => n.name),
241
- edges: [...res.partial.edges].map(e => e.name),
242
- })
243
- })
244
-
245
- await t.test(
246
- 'published less than or equal date (quoted)',
247
- async t => {
248
- const res = await published(
249
- getState(':published("<=2024-02-01")'),
250
- )
251
- t.strictSame(
252
- [...res.partial.nodes].map(n => n.name),
253
- ['a', 'b'],
254
- 'should have expected result using less than or equal date',
255
- )
256
- t.matchSnapshot({
257
- nodes: [...res.partial.nodes].map(n => n.name),
258
- edges: [...res.partial.edges].map(e => e.name),
259
- })
260
- },
261
- )
262
-
263
- await t.test(
264
- 'published less than or equal date (unquoted)',
265
- async t => {
266
- const res = await published(
267
- getState(':published(<=2024-02-01)'),
268
- )
269
- t.strictSame(
270
- [...res.partial.nodes].map(n => n.name),
271
- ['a', 'b'],
272
- 'should have expected result using unquoted less than or equal date',
273
- )
274
- t.matchSnapshot({
275
- nodes: [...res.partial.nodes].map(n => n.name),
276
- edges: [...res.partial.edges].map(e => e.name),
277
- })
278
- },
279
- )
280
-
281
- await t.test('pseudo state form works', async t => {
282
- // :published without parameters should now work as pseudo state
283
- const result = await published(getState(':published'))
284
- t.ok(result, 'should not throw an error for pseudo state form')
285
- })
286
- })
287
-
288
- t.test('parseInternals', async t => {
289
- await t.test('with quoted parameter', async t => {
290
- const ast = parse(':published(">2024-01-01")')
291
- const nodes = asPostcssNodeWithChildren(ast.first.first).nodes
292
- const internals = parseInternals(nodes)
293
- t.strictSame(
294
- internals,
295
- { relativeDate: '2024-01-01', comparator: '>' },
296
- 'should correctly parse internals from published selector with quoted parameter',
297
- )
298
- })
299
-
300
- await t.test('with unquoted parameter', async t => {
301
- const ast = parse(':published(>2024-01-01)')
302
- const nodes = asPostcssNodeWithChildren(ast.first.first).nodes
303
- const internals = parseInternals(nodes)
304
- t.strictSame(
305
- internals,
306
- { relativeDate: '2024-01-01', comparator: '>' },
307
- 'should correctly parse internals from published selector with unquoted parameter',
308
- )
309
- })
310
-
311
- await t.test(
312
- 'with unquoted greater than or equal parameter',
313
- async t => {
314
- const ast = parse(':published(>=2024-01-01)')
315
- const nodes = asPostcssNodeWithChildren(ast.first.first).nodes
316
- const internals = parseInternals(nodes)
317
- t.strictSame(
318
- internals,
319
- { relativeDate: '2024-01-01', comparator: '>=' },
320
- 'should correctly parse internals from published selector with unquoted >= parameter',
321
- )
322
- },
323
- )
324
- })
325
-
326
- t.test('retrieveRemoteDate', async t => {
327
- t.capture(console, 'warn')
328
-
329
- const missingName = {
330
- id: joinDepIDTuple(['registry', '', 'a@1.0.0']),
331
- } as NodeLike
332
- t.strictSame(
333
- await retrieveRemoteDate(missingName),
334
- undefined,
335
- 'should return undefined if missing essential info',
336
- )
337
-
338
- await t.test('no response from registry', async t => {
339
- const node = {
340
- name: 'h',
341
- version: '1.0.0',
342
- id: joinDepIDTuple(['registry', '', 'h@1.0.0']),
343
- options: npmSpecOptions,
344
- } as NodeLike
345
- await t.rejects(
346
- retrieveRemoteDate(node),
347
- /Failed to fetch packument/,
348
- 'should throw an internal error so that it may be retried',
349
- )
350
- })
351
-
352
- await t.test('fetch error', async t => {
353
- const node = {
354
- name: 'i',
355
- id: joinDepIDTuple(['registry', '', 'i@1.0.0']),
356
- options: npmSpecOptions,
357
- } as NodeLike
358
- t.strictSame(
359
- await retrieveRemoteDate(node),
360
- undefined,
361
- 'should return undefined if fetch throws',
362
- )
363
- })
364
-
365
- await t.test('404', async t => {
366
- const node = {
367
- name: 'c',
368
- version: '1.0.0',
369
- id: joinDepIDTuple(['registry', '', 'c@1.0.0']),
370
- options: npmSpecOptions,
371
- } as NodeLike
372
- await t.rejects(
373
- retrieveRemoteDate(node),
374
- /Missing API/,
375
- 'should throw an internal error that will not be retried',
376
- )
377
- })
378
- })
379
-
380
- t.test('queueNode', async t => {
381
- const missingName = {
382
- id: joinDepIDTuple(['registry', '', 'a@1.0.0']),
383
- } as NodeLike
384
- t.strictSame(
385
- await queueNode(
386
- getState(':published("2024-01-01")'),
387
- missingName,
388
- '2024-01-01',
389
- undefined,
390
- ),
391
- missingName,
392
- 'should return node if missing essential info',
393
- )
394
- })
395
-
396
- t.test(
397
- 'pseudo state form - :published without parameters',
398
- async t => {
399
- const getState = (graph = getSimpleGraph()) => {
400
- const ast = parse(':published')
401
- const current = ast.first.first
402
- const state: ParserState = {
403
- comment: '',
404
- current,
405
- initial: {
406
- edges: new Set(graph.edges.values()),
407
- nodes: new Set(graph.nodes.values()),
408
- },
409
- partial: {
410
- edges: new Set(graph.edges.values()),
411
- nodes: new Set(graph.nodes.values()),
412
- },
413
- collect: {
414
- edges: new Set(),
415
- nodes: new Set(),
416
- },
417
- cancellable: async () => {},
418
- walk: async i => i,
419
- securityArchive: undefined,
420
- importers: new Set(graph.importers),
421
- retries: 0,
422
- signal: new AbortController().signal,
423
- specificity: { idCounter: 0, commonCounter: 0 },
424
- }
425
- return state
426
- }
427
-
428
- const state = getState()
429
- const result = await published(state)
430
- t.matchSnapshot(
431
- {
432
- nodes: [...result.partial.nodes].map(n => n.id),
433
- edges: [...result.partial.edges].map(
434
- e => `${e.from.id}->${e.to?.id}`,
435
- ),
436
- },
437
- 'should match packages with published metadata (registry packages)',
438
- )
439
- },
440
- )
441
-
442
- t.test(
443
- 'pseudo state form with nodes missing name or version',
444
- async t => {
445
- const getState = () => {
446
- const graph = getSimpleGraph()
447
- // Get a real node and modify it to lack name/version
448
- const nodeWithoutName = [...graph.nodes.values()][0]
449
-
450
- // Ensure it's a registry node that will pass initial checks
451
- Object.defineProperty(nodeWithoutName, 'id', {
452
- value: joinDepIDTuple(['registry', '', 'test@1.0.0']),
453
- writable: true,
454
- })
455
- Object.defineProperty(nodeWithoutName, 'mainImporter', {
456
- value: false,
457
- writable: true,
458
- })
459
- Object.defineProperty(nodeWithoutName, 'manifest', {
460
- value: { private: false },
461
- writable: true,
462
- })
463
- // Remove name and version to trigger the uncovered lines
464
- Object.defineProperty(nodeWithoutName, 'name', {
465
- value: undefined,
466
- writable: true,
467
- })
468
- Object.defineProperty(nodeWithoutName, 'version', {
469
- value: undefined,
470
- writable: true,
471
- })
472
-
473
- const ast = parse(':published')
474
- const current = ast.first.first
475
- const state: ParserState = {
476
- comment: '',
477
- current,
478
- initial: {
479
- edges: new Set(),
480
- nodes: new Set([nodeWithoutName] as NodeLike[]),
481
- },
482
- partial: {
483
- edges: new Set(),
484
- nodes: new Set([nodeWithoutName] as NodeLike[]),
485
- },
486
- collect: {
487
- edges: new Set(),
488
- nodes: new Set(),
489
- },
490
- cancellable: async () => {},
491
- walk: async i => i,
492
- securityArchive: undefined,
493
- importers: new Set(),
494
- retries: 0,
495
- signal: new AbortController().signal,
496
- specificity: { idCounter: 0, commonCounter: 0 },
497
- }
498
- return state
499
- }
500
-
501
- const state = getState()
502
- const result = await published(state)
503
- t.equal(
504
- result.partial.nodes.size,
505
- 0,
506
- 'should remove nodes without name or version',
507
- )
508
- },
509
- )
510
-
511
- t.test('error handling for non-query node errors', async t => {
512
- // Create a state that will trigger a non-"Expected a query node" error
513
- const ast = parse(':published(invalid)')
514
- const current = ast.first.first
515
-
516
- // Create a corrupted current node that will cause parsing to fail differently
517
- const corruptedCurrent = {
518
- ...current,
519
- nodes: [
520
- {
521
- type: 'function',
522
- value: 'published',
523
- nodes: null, // This will cause asPostcssNodeWithChildren to fail differently
524
- },
525
- ],
526
- }
527
-
528
- const state: ParserState = {
529
- comment: '',
530
- current: corruptedCurrent as any,
531
- initial: {
532
- edges: new Set(),
533
- nodes: new Set(),
534
- },
535
- partial: {
536
- edges: new Set(),
537
- nodes: new Set(),
538
- },
539
- collect: {
540
- edges: new Set(),
541
- nodes: new Set(),
542
- },
543
- cancellable: async () => {},
544
- walk: async i => i,
545
- securityArchive: undefined,
546
- importers: new Set(),
547
- retries: 0,
548
- signal: new AbortController().signal,
549
- specificity: { idCounter: 0, commonCounter: 0 },
550
- }
551
-
552
- await t.rejects(
553
- published(state),
554
- { message: /Failed to parse :published selector/ },
555
- 'should throw error for parsing failures other than missing query node',
556
- )
557
- })
@@ -1,122 +0,0 @@
1
- import t from 'tap'
2
- import postcssSelectorParser from 'postcss-selector-parser'
3
- import type { ParserState } from '../../src/types.ts'
4
- import { registry } from '../../src/pseudo/registry.ts'
5
- import { getSimpleGraph, getAliasedGraph } from '../fixtures/graph.ts'
6
-
7
- t.test('selects nodes by registry', 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 custom registry nodes in aliased graph',
39
- async t => {
40
- const graph = getAliasedGraph()
41
- const res = await registry(getState(':registry(custom)', graph))
42
- t.strictSame(
43
- [...res.partial.nodes].map(n => n.name).sort(),
44
- ['c'],
45
- 'should select only custom registry packages',
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 default npm registry nodes in aliased graph',
56
- async t => {
57
- const graph = getAliasedGraph()
58
- const res = await registry(getState(':registry(npm)', graph))
59
- t.strictSame(
60
- [...res.partial.nodes].map(n => n.name).sort(),
61
- ['a', 'd', 'foo'],
62
- 'should select only default registry packages',
63
- )
64
- t.matchSnapshot({
65
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
66
- edges: [...res.partial.edges].map(e => e.name).sort(),
67
- })
68
- },
69
- )
70
-
71
- await t.test(
72
- 'returns no nodes for nonexistent registry',
73
- async t => {
74
- const graph = getAliasedGraph()
75
- const res = await registry(
76
- getState(':registry(nonexistent)', graph),
77
- )
78
- t.strictSame(
79
- [...res.partial.nodes].map(n => n.name),
80
- [],
81
- 'should not select any packages for nonexistent registry',
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
-
90
- await t.test('handles an empty partial state', async t => {
91
- const state = getState(':registry(npm)')
92
- state.partial.nodes.clear()
93
- state.partial.edges.clear()
94
-
95
- const res = await registry(state)
96
- t.strictSame(
97
- [...res.partial.nodes].map(n => n.name),
98
- [],
99
- 'should return empty array when starting with empty partial state',
100
- )
101
- t.matchSnapshot({
102
- nodes: [...res.partial.nodes].map(n => n.name),
103
- edges: [...res.partial.edges].map(e => e.name),
104
- })
105
- })
106
-
107
- await t.test(
108
- 'selects all registry nodes in simple graph as npm',
109
- async t => {
110
- const res = await registry(getState(':registry(npm)'))
111
- t.strictSame(
112
- [...res.partial.nodes].map(n => n.name).sort(),
113
- ['a', 'b', 'c', 'd', 'e', 'f'],
114
- 'should select all registry packages as npm in simple graph',
115
- )
116
- t.matchSnapshot({
117
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
118
- edges: [...res.partial.edges].map(e => e.name).sort(),
119
- })
120
- },
121
- )
122
- })