@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,214 +0,0 @@
1
- import t from 'tap'
2
- import postcssSelectorParser from 'postcss-selector-parser'
3
- import type { ParserState } from '../../src/types.ts'
4
- import { built } from '../../src/pseudo/built.ts'
5
- import {
6
- getSimpleGraph,
7
- getSingleWorkspaceGraph,
8
- getCycleGraph,
9
- } from '../fixtures/graph.ts'
10
-
11
- t.test('selects packages with built buildState', async t => {
12
- const getState = (query: string, graph = getSimpleGraph()) => {
13
- const ast = postcssSelectorParser().astSync(query)
14
- const current = ast.first.first
15
- const state: ParserState = {
16
- comment: '',
17
- current,
18
- initial: {
19
- edges: new Set(graph.edges.values()),
20
- nodes: new Set(graph.nodes.values()),
21
- },
22
- partial: {
23
- edges: new Set(graph.edges.values()),
24
- nodes: new Set(graph.nodes.values()),
25
- },
26
- collect: {
27
- edges: new Set(),
28
- nodes: new Set(),
29
- },
30
- cancellable: async () => {},
31
- walk: async i => i,
32
- retries: 0,
33
- securityArchive: undefined,
34
- importers: new Set(graph.importers),
35
- signal: new AbortController().signal,
36
- specificity: { idCounter: 0, commonCounter: 0 },
37
- }
38
- return state
39
- }
40
-
41
- await t.test(
42
- 'selects nodes with built buildState in simple graph',
43
- async t => {
44
- const graph = getSimpleGraph()
45
- // Set some nodes to have buildState 'built'
46
- const nodes = [...graph.nodes.values()]
47
- if (nodes.length >= 5) {
48
- nodes[0]!.buildState = 'built'
49
- nodes[1]!.buildState = 'needed'
50
- nodes[2]!.buildState = 'built'
51
- nodes[3]!.buildState = 'failed'
52
- nodes[4]!.buildState = 'none'
53
-
54
- const res = await built(getState(':built', graph))
55
- const resultNames = [...res.partial.nodes].map(n => n.name)
56
-
57
- t.ok(
58
- resultNames.includes(nodes[0]!.name),
59
- 'should include first node with built state',
60
- )
61
- t.ok(
62
- resultNames.includes(nodes[2]!.name),
63
- 'should include second node with built state',
64
- )
65
- t.notOk(
66
- resultNames.includes(nodes[1]!.name),
67
- 'should not include node with needed state',
68
- )
69
- t.notOk(
70
- resultNames.includes(nodes[3]!.name),
71
- 'should not include node with failed state',
72
- )
73
- t.notOk(
74
- resultNames.includes(nodes[4]!.name),
75
- 'should not include node with none state',
76
- )
77
-
78
- t.matchSnapshot({
79
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
80
- edges: [...res.partial.edges].map(e => e.name).sort(),
81
- })
82
- }
83
- },
84
- )
85
-
86
- await t.test(
87
- 'selects no nodes when none have built state',
88
- async t => {
89
- const graph = getSingleWorkspaceGraph()
90
- // Set all nodes to have non-built buildState
91
- for (const node of graph.nodes.values()) {
92
- node.buildState = 'needed'
93
- }
94
-
95
- const res = await built(getState(':built', graph))
96
- t.strictSame(
97
- [...res.partial.nodes].map(n => n.name),
98
- [],
99
- 'should not select any nodes when none have built state',
100
- )
101
- t.matchSnapshot({
102
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
103
- edges: [...res.partial.edges].map(e => e.name).sort(),
104
- })
105
- },
106
- )
107
-
108
- await t.test(
109
- 'selects all nodes when all have built state',
110
- async t => {
111
- const graph = getCycleGraph()
112
- // Set all nodes to have built buildState
113
- for (const node of graph.nodes.values()) {
114
- node.buildState = 'built'
115
- }
116
-
117
- const res = await built(getState(':built', graph))
118
- const allNodeNames = [...graph.nodes.values()].map(n => n.name)
119
- const resultNodeNames = [...res.partial.nodes].map(n => n.name)
120
-
121
- t.strictSame(
122
- resultNodeNames.sort(),
123
- allNodeNames.sort(),
124
- 'should select all nodes when all have built state',
125
- )
126
- t.matchSnapshot({
127
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
128
- edges: [...res.partial.edges].map(e => e.name).sort(),
129
- })
130
- },
131
- )
132
-
133
- await t.test('handles an empty partial state', async t => {
134
- // Create a state with empty partial nodes
135
- const state = getState(':built')
136
- state.partial.nodes.clear()
137
- state.partial.edges.clear()
138
-
139
- const res = await built(state)
140
- t.strictSame(
141
- [...res.partial.nodes].map(n => n.name),
142
- [],
143
- 'should return empty array when starting with empty partial state',
144
- )
145
- t.matchSnapshot({
146
- nodes: [...res.partial.nodes].map(n => n.name),
147
- edges: [...res.partial.edges].map(e => e.name),
148
- })
149
- })
150
-
151
- await t.test('properly removes dangling edges', async t => {
152
- const graph = getSimpleGraph()
153
- const nodes = [...graph.nodes.values()]
154
-
155
- // Set only one node to be built
156
- if (nodes[0]) {
157
- nodes[0].buildState = 'built'
158
- for (let i = 1; i < nodes.length; i++) {
159
- if (nodes[i]) {
160
- nodes[i]!.buildState = 'none'
161
- }
162
- }
163
- }
164
-
165
- const res = await built(getState(':built', graph))
166
-
167
- // Check that edges pointing to removed nodes are also removed
168
- for (const edge of res.partial.edges) {
169
- t.ok(
170
- edge.to?.buildState === 'built' || !edge.to,
171
- 'edges should only point to built nodes or be missing',
172
- )
173
- }
174
-
175
- t.matchSnapshot({
176
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
177
- edges: [...res.partial.edges].map(e => e.name).sort(),
178
- })
179
- })
180
-
181
- await t.test(
182
- 'filters mixed buildState values correctly',
183
- async t => {
184
- const graph = getSimpleGraph()
185
- const nodes = [...graph.nodes.values()]
186
-
187
- // Create a realistic scenario with mixed buildStates
188
- if (nodes.length >= 5) {
189
- nodes[0]!.buildState = 'built'
190
- nodes[1]!.buildState = 'needed'
191
- nodes[2]!.buildState = 'built'
192
- nodes[3]!.buildState = 'failed'
193
- nodes[4]!.buildState = 'built'
194
- }
195
-
196
- const res = await built(getState(':built', graph))
197
- const resultNodes = [...res.partial.nodes]
198
-
199
- // All resulting nodes should have buildState === 'built'
200
- for (const node of resultNodes) {
201
- t.equal(
202
- node.buildState,
203
- 'built',
204
- `node ${node.name} should have buildState 'built'`,
205
- )
206
- }
207
-
208
- t.matchSnapshot({
209
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
210
- edges: [...res.partial.edges].map(e => e.name).sort(),
211
- })
212
- },
213
- )
214
- })
@@ -1,160 +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 { confused } from '../../src/pseudo/confused.ts'
8
-
9
- t.test('selects packages with a manifestConfusion alert', async t => {
10
- const getState = (query: string, graph = getSimpleGraph()) => {
11
- const ast = parse(query)
12
- const current = ast.first.first
13
- const state: ParserState = {
14
- comment: '',
15
- current,
16
- initial: {
17
- edges: new Set(graph.edges.values()),
18
- nodes: new Set(graph.nodes.values()),
19
- },
20
- partial: {
21
- edges: new Set(graph.edges.values()),
22
- nodes: new Set(graph.nodes.values()),
23
- },
24
- collect: {
25
- edges: new Set(),
26
- nodes: new Set(),
27
- },
28
- cancellable: async () => {},
29
- walk: async i => i,
30
- retries: 0,
31
- securityArchive: asSecurityArchiveLike(
32
- new Map([
33
- [
34
- joinDepIDTuple(['registry', '', 'e@1.0.0']),
35
- { alerts: [{ type: 'manifestConfusion' }] },
36
- ],
37
- ]),
38
- ),
39
- importers: new Set(graph.importers),
40
- signal: new AbortController().signal,
41
- specificity: { idCounter: 0, commonCounter: 0 },
42
- }
43
- return state
44
- }
45
-
46
- await t.test(
47
- 'filter out any node that does not have the alert',
48
- async t => {
49
- const res = await confused(getState(':confused'))
50
- t.strictSame(
51
- [...res.partial.nodes].map(n => n.name),
52
- ['e'],
53
- 'should select only confused packages',
54
- )
55
- t.matchSnapshot({
56
- nodes: [...res.partial.nodes].map(n => n.name),
57
- edges: [...res.partial.edges].map(e => e.name),
58
- })
59
- },
60
- )
61
- })
62
-
63
- t.test('missing security archive', async t => {
64
- const getState = (query: string) => {
65
- const ast = parse(query)
66
- const current = ast.first.first
67
- const state: ParserState = {
68
- comment: '',
69
- current,
70
- initial: {
71
- edges: new Set(),
72
- nodes: new Set(),
73
- },
74
- partial: {
75
- edges: new Set(),
76
- nodes: new Set(),
77
- },
78
- collect: {
79
- edges: new Set(),
80
- nodes: new Set(),
81
- },
82
- cancellable: async () => {},
83
- walk: async i => i,
84
- retries: 0,
85
- securityArchive: undefined,
86
- importers: new Set(),
87
- signal: new AbortController().signal,
88
- specificity: { idCounter: 0, commonCounter: 0 },
89
- }
90
- return state
91
- }
92
-
93
- await t.rejects(
94
- confused(getState(':confused')),
95
- { message: /Missing security archive/ },
96
- 'should throw an error',
97
- )
98
- })
99
-
100
- t.test('nodes with confused=true flag', async t => {
101
- const getState = (query: string) => {
102
- const ast = parse(query)
103
- const current = ast.first.first
104
- const graph = getSimpleGraph()
105
-
106
- // Find node 'a' and set confused=true
107
- const nodeA = [...graph.nodes.values()].find(n => n.name === 'a')
108
- if (nodeA) {
109
- nodeA.confused = true
110
- t.teardown(() => {
111
- nodeA.confused = false // Reset the flag after the test
112
- })
113
- }
114
-
115
- const state: ParserState = {
116
- comment: '',
117
- current,
118
- initial: {
119
- edges: new Set(graph.edges.values()),
120
- nodes: new Set(graph.nodes.values()),
121
- },
122
- partial: {
123
- edges: new Set(graph.edges.values()),
124
- nodes: new Set(graph.nodes.values()),
125
- },
126
- collect: {
127
- edges: new Set(),
128
- nodes: new Set(),
129
- },
130
- cancellable: async () => {},
131
- walk: async i => i,
132
- retries: 0,
133
- securityArchive: asSecurityArchiveLike(
134
- new Map([
135
- [
136
- joinDepIDTuple(['registry', '', 'e@1.0.0']),
137
- { alerts: [{ type: 'manifestConfusion' }] },
138
- ],
139
- ]),
140
- ),
141
- importers: new Set(graph.importers),
142
- signal: new AbortController().signal,
143
- specificity: { idCounter: 0, commonCounter: 0 },
144
- }
145
- return state
146
- }
147
-
148
- await t.test('filter out nodes that are not confused', async t => {
149
- const res = await confused(getState(':confused'))
150
- t.strictSame(
151
- [...res.partial.nodes].map(n => n.name),
152
- ['a', 'e'],
153
- 'should select both confused=true nodes and nodes with manifestConfusion alert',
154
- )
155
- t.matchSnapshot({
156
- nodes: [...res.partial.nodes].map(n => n.name),
157
- edges: [...res.partial.edges].map(e => e.name),
158
- })
159
- })
160
- })
@@ -1,249 +0,0 @@
1
- import t from 'tap'
2
- import { joinDepIDTuple } from '@vltpkg/dep-id'
3
- import {
4
- asPackageReportData,
5
- asSecurityArchiveLike,
6
- } from '@vltpkg/security-archive'
7
- import { getSimpleGraph } from '../fixtures/graph.ts'
8
- import type { ParserState } from '../../src/types.ts'
9
- import { parse } from '../../src/parser.ts'
10
- import { cve } from '../../src/pseudo/cve.ts'
11
-
12
- t.test('selects packages with a CVE alert', async t => {
13
- const getState = (query: string, graph = getSimpleGraph()) => {
14
- const ast = parse(query)
15
- const current = ast.first.first
16
- const state: ParserState = {
17
- comment: '',
18
- current,
19
- initial: {
20
- edges: new Set(graph.edges.values()),
21
- nodes: new Set(graph.nodes.values()),
22
- },
23
- partial: {
24
- edges: new Set(graph.edges.values()),
25
- nodes: new Set(graph.nodes.values()),
26
- },
27
- collect: {
28
- edges: new Set(),
29
- nodes: new Set(),
30
- },
31
- cancellable: async () => {},
32
- walk: async i => i,
33
- retries: 0,
34
- securityArchive: asSecurityArchiveLike(
35
- new Map([
36
- [
37
- joinDepIDTuple(['registry', '', 'e@1.0.0']),
38
- asPackageReportData({
39
- id: 'e@1.0.0',
40
- author: [],
41
- size: 0,
42
- type: 'npm',
43
- name: 'e',
44
- version: '1.0.0',
45
- license: 'MIT',
46
- score: {
47
- overall: 0,
48
- license: 0,
49
- maintenance: 0,
50
- quality: 0,
51
- supplyChain: 0,
52
- vulnerability: 0,
53
- signal: new AbortController().signal,
54
- specificity: { idCounter: 0, commonCounter: 0 },
55
- },
56
- alerts: [
57
- {
58
- key: '12314320948130',
59
- type: 'cve',
60
- severity: 'high',
61
- category: 'security',
62
- props: {
63
- cveId: 'CVE-2023-1234',
64
- lastPublish: '2023-01-01',
65
- },
66
- },
67
- ],
68
- }),
69
- ],
70
- ]),
71
- ),
72
- importers: new Set(graph.importers),
73
- signal: new AbortController().signal,
74
- specificity: { idCounter: 0, commonCounter: 0 },
75
- }
76
- return state
77
- }
78
-
79
- await t.test(
80
- 'filter out any node that does not have the alert',
81
- async t => {
82
- const res = await cve(getState(':cve(CVE-2023-1234)'))
83
- t.strictSame(
84
- [...res.partial.nodes].map(n => n.name),
85
- ['e'],
86
- 'should select only packages with matching CVE ID',
87
- )
88
- t.matchSnapshot({
89
- nodes: [...res.partial.nodes].map(n => n.name),
90
- edges: [...res.partial.edges].map(e => e.name),
91
- })
92
- },
93
- )
94
-
95
- await t.test('should not match an unseen CVE ID', async t => {
96
- const res = await cve(getState(':cve(CVE-2023-5678)'))
97
- t.strictSame(
98
- [...res.partial.nodes].map(n => n.name),
99
- [],
100
- 'should not select any packages when CVE ID does not match',
101
- )
102
- t.matchSnapshot({
103
- nodes: [...res.partial.nodes].map(n => n.name),
104
- edges: [...res.partial.edges].map(e => e.name),
105
- })
106
- })
107
-
108
- await t.test(
109
- 'filter out any node that does not match the quoted CVE ID',
110
- async t => {
111
- const res = await cve(getState(':cve("CVE-2023-1234")'))
112
- t.strictSame(
113
- [...res.partial.nodes].map(n => n.name),
114
- ['e'],
115
- 'should select only packages with matching CVE ID',
116
- )
117
- t.matchSnapshot({
118
- nodes: [...res.partial.nodes].map(n => n.name),
119
- edges: [...res.partial.edges].map(e => e.name),
120
- })
121
- },
122
- )
123
-
124
- await t.test(
125
- 'parameterless :cve matches any package with a CVE',
126
- async t => {
127
- const res = await cve(getState(':cve'))
128
- t.strictSame(
129
- [...res.partial.nodes].map(n => n.name),
130
- ['e'],
131
- 'should select packages with any CVE alert',
132
- )
133
- t.matchSnapshot({
134
- nodes: [...res.partial.nodes].map(n => n.name),
135
- edges: [...res.partial.edges].map(e => e.name),
136
- })
137
- },
138
- )
139
- })
140
-
141
- t.test(':cve() with empty parens matches any CVE', async t => {
142
- const graph = getSimpleGraph()
143
- const ast = parse(':cve()')
144
- const current = ast.first.first
145
- const state: ParserState = {
146
- comment: '',
147
- current,
148
- initial: {
149
- edges: new Set(graph.edges.values()),
150
- nodes: new Set(graph.nodes.values()),
151
- },
152
- partial: {
153
- edges: new Set(graph.edges.values()),
154
- nodes: new Set(graph.nodes.values()),
155
- },
156
- collect: {
157
- edges: new Set(),
158
- nodes: new Set(),
159
- },
160
- cancellable: async () => {},
161
- walk: async i => i,
162
- retries: 0,
163
- securityArchive: asSecurityArchiveLike(
164
- new Map([
165
- [
166
- joinDepIDTuple(['registry', '', 'e@1.0.0']),
167
- asPackageReportData({
168
- id: 'e@1.0.0',
169
- author: [],
170
- size: 0,
171
- type: 'npm',
172
- name: 'e',
173
- version: '1.0.0',
174
- license: 'MIT',
175
- score: {
176
- overall: 0,
177
- license: 0,
178
- maintenance: 0,
179
- quality: 0,
180
- supplyChain: 0,
181
- vulnerability: 0,
182
- signal: new AbortController().signal,
183
- specificity: { idCounter: 0, commonCounter: 0 },
184
- },
185
- alerts: [
186
- {
187
- key: '12314320948130',
188
- type: 'cve',
189
- severity: 'high',
190
- category: 'security',
191
- props: {
192
- cveId: 'CVE-2023-1234',
193
- lastPublish: '2023-01-01',
194
- },
195
- },
196
- ],
197
- }),
198
- ],
199
- ]),
200
- ),
201
- importers: new Set(graph.importers),
202
- signal: new AbortController().signal,
203
- specificity: { idCounter: 0, commonCounter: 0 },
204
- }
205
-
206
- const res = await cve(state)
207
- t.strictSame(
208
- [...res.partial.nodes].map(n => n.name),
209
- ['e'],
210
- 'should select packages with any CVE alert',
211
- )
212
- })
213
-
214
- t.test('missing security archive', async t => {
215
- const getState = (query: string) => {
216
- const ast = parse(query)
217
- const current = ast.first.first
218
- const state: ParserState = {
219
- comment: '',
220
- current,
221
- initial: {
222
- edges: new Set(),
223
- nodes: new Set(),
224
- },
225
- partial: {
226
- edges: new Set(),
227
- nodes: new Set(),
228
- },
229
- collect: {
230
- edges: new Set(),
231
- nodes: new Set(),
232
- },
233
- cancellable: async () => {},
234
- walk: async i => i,
235
- retries: 0,
236
- securityArchive: undefined,
237
- importers: new Set(),
238
- signal: new AbortController().signal,
239
- specificity: { idCounter: 0, commonCounter: 0 },
240
- }
241
- return state
242
- }
243
-
244
- await t.rejects(
245
- cve(getState(':cve(CVE-2023-1234)')),
246
- /Missing security archive/,
247
- 'should throw an error',
248
- )
249
- })