@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,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
- })