@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,73 +0,0 @@
1
- import t from 'tap'
2
- import { pseudo } from '../../src/pseudo.ts'
3
- import {
4
- selectorFixture,
5
- copyGraphSelectionState,
6
- } from '../fixtures/selector.ts'
7
- import { getSimpleGraph } from '../fixtures/graph.ts'
8
- import type { TestCase } from '../fixtures/types.ts'
9
- import type { GraphSelectionState } from '../../src/types.ts'
10
-
11
- const testPseudo = selectorFixture(pseudo)
12
-
13
- t.test(':optional pseudo-selector', async t => {
14
- // Get a simple graph for testing
15
- const simpleGraph = getSimpleGraph()
16
-
17
- // Get the full selection state
18
- const all = {
19
- edges: new Set(simpleGraph.edges),
20
- nodes: new Set(simpleGraph.nodes.values()),
21
- }
22
-
23
- // Create an empty selection state
24
- const empty: GraphSelectionState = {
25
- edges: new Set(),
26
- nodes: new Set(),
27
- }
28
-
29
- // Run tests in the same pattern as the main pseudo.ts tests
30
- const queryToExpected = new Set<TestCase>([
31
- [':optional', all, ['f']], // Should return optional dependencies
32
- [':optional', empty, []], // Empty input should return empty output
33
- ])
34
-
35
- const initial = copyGraphSelectionState(all)
36
- for (const [query, partial, expected] of queryToExpected) {
37
- const result = await testPseudo(
38
- query,
39
- initial,
40
- copyGraphSelectionState(partial),
41
- )
42
-
43
- t.strictSame(
44
- result.nodes.map(i => i.name),
45
- expected,
46
- `query > "${query}"`,
47
- )
48
-
49
- // Verify all edges have type 'optional' if any
50
- const edgeArray = [...result.edges]
51
- if (edgeArray.length > 0) {
52
- for (const edge of edgeArray) {
53
- t.equal(
54
- edge.type,
55
- 'optional',
56
- `edge ${edge.name} should be of type 'optional'`,
57
- )
58
- }
59
- }
60
-
61
- // Verify all nodes have optional property if any
62
- const nodeArray = [...result.nodes]
63
- if (nodeArray.length > 0) {
64
- for (const node of nodeArray) {
65
- t.ok(
66
- node.optional ||
67
- [...node.edgesIn].some(e => e.type === 'optional'),
68
- `node ${node.name} should be optional or connected by optional edge`,
69
- )
70
- }
71
- }
72
- }
73
- })
@@ -1,461 +0,0 @@
1
- import t from 'tap'
2
- import { joinDepIDTuple } from '@vltpkg/dep-id'
3
- import { parse, asPostcssNodeWithChildren } from '@vltpkg/dss-parser'
4
- import {
5
- outdated,
6
- parseInternals,
7
- queueNode,
8
- retrieveRemoteVersions,
9
- } from '../../src/pseudo/outdated.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
- const fetchedUrls: string[] = []
26
- const fetchedUserAgents: (string | undefined)[] = []
27
-
28
- global.fetch = (async (
29
- url: string,
30
- init?: { headers?: Record<string, string> },
31
- ) => {
32
- fetchedUrls.push(url)
33
- fetchedUserAgents.push(init?.headers?.['User-Agent'])
34
- if (url.startsWith('http://example.com/private/registry/')) {
35
- if (init?.headers?.authorization !== 'Bearer test-token') {
36
- return {
37
- status: 401,
38
- ok: false,
39
- }
40
- }
41
- return {
42
- ok: true,
43
- json: async () => ({
44
- versions: {
45
- '1.0.0': {},
46
- '2.0.0': {},
47
- },
48
- }),
49
- }
50
- }
51
- if (url === 'https://registry.npmjs.org/h') {
52
- return {
53
- ok: false,
54
- }
55
- } else if (url === 'https://registry.npmjs.org/i') {
56
- throw new Error('ERR')
57
- } else if (url === 'https://registry.npmjs.org/c') {
58
- return {
59
- status: 404,
60
- ok: false,
61
- }
62
- }
63
- return {
64
- ok: true,
65
- json: async () => {
66
- switch (url) {
67
- case 'https://registry.npmjs.org/a': {
68
- return {
69
- versions: {
70
- '1.0.0': {},
71
- '2.0.0': {},
72
- '3.0.0': {},
73
- },
74
- }
75
- }
76
- case 'https://registry.npmjs.org/b': {
77
- return {
78
- versions: {
79
- '1.0.0': {},
80
- '2.0.0': {},
81
- '2.1.0': {},
82
- '2.2.0': {},
83
- },
84
- }
85
- }
86
- case 'http://example.com/c': {
87
- return {
88
- versions: {
89
- '3.0.0': {},
90
- '3.4.0': {},
91
- '4.0.0': {},
92
- '5.0.0': {},
93
- },
94
- }
95
- }
96
- case 'https://registry.npmjs.org/d': {
97
- return {
98
- versions: {
99
- '1.0.0': {},
100
- '1.2.0': {},
101
- '2.3.4': {},
102
- '2.3.5': {},
103
- },
104
- }
105
- }
106
- case 'https://registry.npmjs.org/e': {
107
- return {
108
- versions: {
109
- '120.0.0': {},
110
- '120.1.0': {},
111
- '121.0.0': {},
112
- '122.0.0': {},
113
- },
114
- }
115
- }
116
- case 'https://registry.npmjs.org/f': {
117
- return {
118
- versions: {
119
- '4.0.0': {},
120
- '4.5.6': {},
121
- },
122
- }
123
- }
124
- case 'https://registry.npmjs.org/g': {
125
- return {
126
- versions: {
127
- '1.2.3-rc.1+rev.1': {},
128
- '1.2.3-rc.1+rev.2': {},
129
- '1.2.3-rc.2+rev.3': {},
130
- '1.2.3-rc.3+rev.4': {},
131
- },
132
- }
133
- }
134
- }
135
- },
136
- }
137
- }) as unknown as typeof global.fetch
138
-
139
- const getState = (query: string, graph = getSemverRichGraph()) => {
140
- const ast = parse(query)
141
- const current = asPostcssNodeWithChildren(ast.first.first)
142
- const state: ParserState = {
143
- comment: '',
144
- current,
145
- initial: {
146
- edges: new Set(graph.edges.values()),
147
- nodes: new Set(graph.nodes.values()),
148
- },
149
- partial: {
150
- edges: new Set(graph.edges.values()),
151
- nodes: new Set(graph.nodes.values()),
152
- },
153
- collect: {
154
- edges: new Set(),
155
- nodes: new Set(),
156
- },
157
- cancellable: async () => {},
158
- walk: async i => i,
159
- retries: 0,
160
- securityArchive: undefined,
161
- importers: new Set(graph.importers),
162
- signal: new AbortController().signal,
163
- specificity: { idCounter: 0, commonCounter: 0 },
164
- }
165
- return state
166
- }
167
-
168
- t.test('select from outdated definition', async t => {
169
- await t.test('outdated as an element', async t => {
170
- const res = await outdated(getState(':outdated'))
171
- t.strictSame(
172
- [...res.partial.nodes].map(n => n.name),
173
- ['a', 'c', 'd', 'e', 'g', 'e'],
174
- 'should have expected result using outdated defaulting to "any"',
175
- )
176
- t.matchSnapshot({
177
- nodes: [...res.partial.nodes].map(n => n.name),
178
- edges: [...res.partial.edges].map(e => e.name),
179
- })
180
- })
181
-
182
- await t.test('outdated kind any', async t => {
183
- const res = await outdated(getState(':outdated(any)'))
184
- t.strictSame(
185
- [...res.partial.nodes].map(n => n.name),
186
- ['a', 'c', 'd', 'e', 'g', 'e'],
187
- 'should have expected result using outdated kind "any"',
188
- )
189
- t.matchSnapshot({
190
- nodes: [...res.partial.nodes].map(n => n.name),
191
- edges: [...res.partial.edges].map(e => e.name),
192
- })
193
- })
194
-
195
- await t.test('outdated kind major', async t => {
196
- const res = await outdated(getState(':outdated(major)'))
197
- t.strictSame(
198
- [...res.partial.nodes].map(n => n.name),
199
- ['a', 'c', 'e', 'e'],
200
- 'should have expected result using outdated kind "major"',
201
- )
202
- t.matchSnapshot({
203
- nodes: [...res.partial.nodes].map(n => n.name),
204
- edges: [...res.partial.edges].map(e => e.name),
205
- })
206
- })
207
-
208
- await t.test('outdated kind minor', async t => {
209
- const res = await outdated(getState(':outdated("minor")'))
210
- t.strictSame(
211
- [...res.partial.nodes].map(n => n.name),
212
- ['e'],
213
- 'should have expected result using outdated kind "minor"',
214
- )
215
- t.matchSnapshot({
216
- nodes: [...res.partial.nodes].map(n => n.name),
217
- edges: [...res.partial.edges].map(e => e.name),
218
- })
219
- })
220
-
221
- await t.test('outdated kind patch', async t => {
222
- const res = await outdated(getState(':outdated("patch")'))
223
- t.strictSame(
224
- [...res.partial.nodes].map(n => n.name),
225
- ['d'],
226
- 'should have expected result using outdated kind "patch"',
227
- )
228
- t.matchSnapshot({
229
- nodes: [...res.partial.nodes].map(n => n.name),
230
- edges: [...res.partial.edges].map(e => e.name),
231
- })
232
- })
233
-
234
- await t.test('outdated kind in-range', async t => {
235
- const res = await outdated(getState(':outdated(in-range)'))
236
- t.strictSame(
237
- [...res.partial.nodes].map(n => n.name),
238
- ['c', 'e'],
239
- 'should have expected result using outdated kind "in-range"',
240
- )
241
- t.matchSnapshot({
242
- nodes: [...res.partial.nodes].map(n => n.name),
243
- edges: [...res.partial.edges].map(e => e.name),
244
- })
245
- })
246
-
247
- await t.test('outdated kind out-of-range', async t => {
248
- const res = await outdated(getState(':outdated(out-of-range)'))
249
- t.strictSame(
250
- [...res.partial.nodes].map(n => n.name),
251
- ['a', 'd', 'g', 'e'],
252
- 'should have expected result using outdated kind "out-of-range"',
253
- )
254
- t.matchSnapshot({
255
- nodes: [...res.partial.nodes].map(n => n.name),
256
- edges: [...res.partial.edges].map(e => e.name),
257
- })
258
- })
259
-
260
- await t.test('invalid pseudo selector usage', async t => {
261
- await t.rejects(
262
- outdated(getState(':outdated(foo)')),
263
- /Failed to parse :outdated selector/,
264
- 'should throw an error for invalid pseudo selector usage',
265
- )
266
- })
267
-
268
- await t.test('missing package response', async t => {
269
- const log = t.capture(console, 'warn').args
270
- const res = await outdated(
271
- getState(':outdated(any)', getSimpleGraph()),
272
- )
273
- // mind this is a different graph that is being asserted,
274
- // as manifests differs so are the results here
275
- t.strictSame(
276
- [...res.partial.nodes].map(n => n.name),
277
- ['a', 'b', 'e', 'f'],
278
- 'should have expected results still',
279
- )
280
- t.matchSnapshot(
281
- log(),
282
- 'should log a warning for missing package response',
283
- )
284
- })
285
- })
286
-
287
- t.test('parseInternals', async t => {
288
- const ast = parse(':outdated(any)')
289
- const nodes = asPostcssNodeWithChildren(ast.first.first).nodes
290
- const internals = parseInternals(nodes)
291
- t.strictSame(
292
- internals,
293
- { kind: 'any' },
294
- 'should correctly parse internals from outdated selector',
295
- )
296
- })
297
-
298
- t.test('invalid outdated kind', async t => {
299
- const ast = parse(':outdated(unsupported)')
300
- const nodes = asPostcssNodeWithChildren(ast.first.first).nodes
301
- t.throws(
302
- () => parseInternals(nodes),
303
- /Expected a valid outdated kind/,
304
- 'should throw an error for invalid outdated kind',
305
- )
306
- })
307
-
308
- t.test('retrieveRemoveVersions', async t => {
309
- t.capture(console, 'warn')
310
-
311
- const missingName = {
312
- id: joinDepIDTuple(['registry', '', 'a@1.0.0']),
313
- } as NodeLike
314
- t.strictSame(
315
- await retrieveRemoteVersions(missingName),
316
- [],
317
- 'should return an empty array if missing essential info',
318
- )
319
-
320
- await t.test('no response from registry', async t => {
321
- const missingName = {
322
- name: 'h',
323
- id: joinDepIDTuple(['registry', '', 'h@1.0.0']),
324
- options: npmSpecOptions,
325
- } as NodeLike
326
- await t.rejects(
327
- retrieveRemoteVersions(missingName),
328
- /Failed to fetch packument/,
329
- 'should throw an internal error so that it may be retried',
330
- )
331
- })
332
-
333
- await t.test('fetch error', async t => {
334
- const missingName = {
335
- name: 'i',
336
- id: joinDepIDTuple(['registry', '', 'i@1.0.0']),
337
- options: npmSpecOptions,
338
- } as NodeLike
339
- await t.rejects(
340
- retrieveRemoteVersions(missingName),
341
- /ERR/,
342
- 'should throw the original error that will be retried',
343
- )
344
- })
345
-
346
- await t.test('authenticated path-prefixed registry', async t => {
347
- const privateSpecOptions: SpecOptions = {
348
- registries: { private: 'http://example.com/private/registry' },
349
- }
350
- const node = {
351
- name: 'p',
352
- id: joinDepIDTuple(['registry', 'private', 'p@1.0.0']),
353
- options: privateSpecOptions,
354
- } as NodeLike
355
-
356
- t.strictSame(
357
- await retrieveRemoteVersions(
358
- node,
359
- undefined,
360
- async () => 'Bearer test-token',
361
- ),
362
- ['1.0.0', '2.0.0'],
363
- 'should retrieve versions using auth header',
364
- )
365
- t.strictSame(
366
- fetchedUrls.at(-1),
367
- 'http://example.com/private/registry/p',
368
- 'should preserve the registry path prefix',
369
- )
370
-
371
- const scoped = {
372
- name: '@scope/s',
373
- id: joinDepIDTuple(['registry', 'private', '@scope/s@1.0.0']),
374
- options: privateSpecOptions,
375
- } as NodeLike
376
- t.strictSame(
377
- await retrieveRemoteVersions(
378
- scoped,
379
- undefined,
380
- async () => 'Bearer test-token',
381
- ),
382
- ['1.0.0', '2.0.0'],
383
- 'should retrieve versions for scoped package',
384
- )
385
- t.strictSame(
386
- fetchedUrls.at(-1),
387
- 'http://example.com/private/registry/@scope/s',
388
- 'should preserve prefix with scoped name',
389
- )
390
-
391
- await t.rejects(
392
- retrieveRemoteVersions(node),
393
- /Failed to fetch packument/,
394
- 'should fail when no auth header is available',
395
- )
396
- })
397
-
398
- await t.test('sends a vlt user-agent', async t => {
399
- const node = {
400
- name: 'a',
401
- id: joinDepIDTuple(['registry', '', 'a@1.0.0']),
402
- options: npmSpecOptions,
403
- } as NodeLike
404
- await retrieveRemoteVersions(node)
405
- t.match(
406
- fetchedUserAgents.at(-1),
407
- /^vlt\/\d+\.\d+\.\d+/,
408
- 'user-agent header is vlt/<version>',
409
- )
410
- })
411
- })
412
-
413
- t.test('queueNode', async t => {
414
- const missingName = {
415
- id: joinDepIDTuple(['registry', '', 'a@1.0.0']),
416
- } as NodeLike
417
- t.strictSame(
418
- await queueNode(getState(':outdated(any)'), missingName, 'any'),
419
- missingName,
420
- 'should return an empty array if missing essential info',
421
- )
422
-
423
- await t.test('collects errors via onError', async t => {
424
- const log = t.capture(console, 'warn').args
425
- const failing = {
426
- name: 'h',
427
- version: '1.0.0',
428
- id: joinDepIDTuple(['registry', '', 'h@1.0.0']),
429
- options: npmSpecOptions,
430
- } as NodeLike
431
- const failures: unknown[] = []
432
- t.strictSame(
433
- await queueNode(
434
- getState(':outdated(any)'),
435
- failing,
436
- 'any',
437
- (node, err) => failures.push([node.name, err]),
438
- ),
439
- failing,
440
- 'should keep node when versions cannot be retrieved',
441
- )
442
- t.strictSame(failures.length, 1, 'should collect the failure')
443
- t.strictSame(log().length, 0, 'should not warn directly')
444
- })
445
-
446
- await t.test('warns directly without onError', async t => {
447
- const log = t.capture(console, 'warn').args
448
- const failing = {
449
- name: 'h',
450
- version: '1.0.0',
451
- id: joinDepIDTuple(['registry', '', 'h@1.0.0']),
452
- options: npmSpecOptions,
453
- } as NodeLike
454
- t.strictSame(
455
- await queueNode(getState(':outdated(any)'), failing, 'any'),
456
- failing,
457
- 'should keep node when versions cannot be retrieved',
458
- )
459
- t.strictSame(log().length, 1, 'should warn once')
460
- })
461
- })