@vltpkg/query 1.0.0-rc.32 → 1.0.0-rc.34

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 (215) hide show
  1. package/dist/index.js +10 -6
  2. package/dist/parser.js +2 -1
  3. package/dist/pseudo/hostname.js +3 -1
  4. package/dist/pseudo/malware.d.ts +3 -16
  5. package/dist/pseudo/malware.js +11 -171
  6. package/dist/pseudo/scripts.js +1 -1
  7. package/dist/pseudo/vuln.d.ts +22 -0
  8. package/dist/pseudo/vuln.js +220 -0
  9. package/dist/pseudo.js +3 -3
  10. package/dist/types.d.ts +3 -2
  11. package/package.json +19 -10
  12. package/skills/dss-query/REFERENCE.md +123 -0
  13. package/skills/dss-query/SKILL.md +190 -0
  14. package/skills/dss-query/evals/README.md +79 -0
  15. package/skills/dss-query/evals/evals.json +89 -0
  16. package/skills/dss-query/evals/grade.mjs +480 -0
  17. package/src/attribute.ts +186 -0
  18. package/src/combinator.ts +132 -0
  19. package/src/id.ts +46 -0
  20. package/src/index.ts +620 -0
  21. package/src/parser.ts +122 -0
  22. package/src/pseudo/abandoned.ts +9 -0
  23. package/src/pseudo/attr.ts +92 -0
  24. package/src/pseudo/built.ts +19 -0
  25. package/src/pseudo/confused.ts +29 -0
  26. package/src/pseudo/cve.ts +93 -0
  27. package/src/pseudo/cwe.ts +97 -0
  28. package/src/pseudo/debug.ts +9 -0
  29. package/src/pseudo/deprecated.ts +9 -0
  30. package/src/pseudo/dev.ts +18 -0
  31. package/src/pseudo/diff.ts +90 -0
  32. package/src/pseudo/dist.ts +144 -0
  33. package/src/pseudo/dynamic.ts +9 -0
  34. package/src/pseudo/empty.ts +15 -0
  35. package/src/pseudo/entropic.ts +9 -0
  36. package/src/pseudo/env.ts +6 -0
  37. package/src/pseudo/eval.ts +9 -0
  38. package/src/pseudo/fs.ts +9 -0
  39. package/src/pseudo/helpers.ts +106 -0
  40. package/src/pseudo/host.ts +111 -0
  41. package/src/pseudo/hostname.ts +156 -0
  42. package/src/pseudo/license.ts +134 -0
  43. package/src/pseudo/link.ts +30 -0
  44. package/src/pseudo/malware.ts +41 -0
  45. package/src/pseudo/minified.ts +9 -0
  46. package/src/pseudo/missing.ts +16 -0
  47. package/src/pseudo/native.ts +9 -0
  48. package/src/pseudo/network.ts +9 -0
  49. package/src/pseudo/obfuscated.ts +9 -0
  50. package/src/pseudo/optional.ts +18 -0
  51. package/src/pseudo/outdated.ts +305 -0
  52. package/src/pseudo/overridden.ts +20 -0
  53. package/src/pseudo/path.ts +146 -0
  54. package/src/pseudo/peer.ts +18 -0
  55. package/src/pseudo/prerelease.ts +47 -0
  56. package/src/pseudo/private.ts +19 -0
  57. package/src/pseudo/prod.ts +18 -0
  58. package/src/pseudo/published.ts +248 -0
  59. package/src/pseudo/registry.ts +29 -0
  60. package/src/pseudo/root.ts +19 -0
  61. package/src/pseudo/scanned.ts +20 -0
  62. package/src/pseudo/score.ts +186 -0
  63. package/src/pseudo/scripts.ts +54 -0
  64. package/src/pseudo/semver.ts +320 -0
  65. package/src/pseudo/severity.ts +231 -0
  66. package/src/pseudo/shell.ts +9 -0
  67. package/src/pseudo/shrinkwrap.ts +9 -0
  68. package/src/pseudo/spec.ts +131 -0
  69. package/src/pseudo/squat.ts +225 -0
  70. package/src/pseudo/suspicious.ts +9 -0
  71. package/src/pseudo/tracker.ts +9 -0
  72. package/src/pseudo/trivial.ts +9 -0
  73. package/src/pseudo/type.ts +26 -0
  74. package/src/pseudo/undesirable.ts +9 -0
  75. package/src/pseudo/unknown.ts +9 -0
  76. package/src/pseudo/unmaintained.ts +9 -0
  77. package/src/pseudo/unpopular.ts +9 -0
  78. package/src/pseudo/unstable.ts +9 -0
  79. package/src/pseudo/vuln.ts +273 -0
  80. package/src/pseudo/workspace.ts +22 -0
  81. package/src/pseudo.ts +413 -0
  82. package/src/types.ts +165 -0
  83. package/tap-snapshots/test/attribute.ts.test.cjs +304 -0
  84. package/tap-snapshots/test/combinator.ts.test.cjs +333 -0
  85. package/tap-snapshots/test/id.ts.test.cjs +118 -0
  86. package/tap-snapshots/test/parser.ts.test.cjs +344 -0
  87. package/tap-snapshots/test/pseudo/abandoned.ts.test.cjs +18 -0
  88. package/tap-snapshots/test/pseudo/attr.ts.test.cjs +161 -0
  89. package/tap-snapshots/test/pseudo/built.ts.test.cjs +70 -0
  90. package/tap-snapshots/test/pseudo/confused.ts.test.cjs +32 -0
  91. package/tap-snapshots/test/pseudo/cve.ts.test.cjs +49 -0
  92. package/tap-snapshots/test/pseudo/cwe.ts.test.cjs +49 -0
  93. package/tap-snapshots/test/pseudo/debug.ts.test.cjs +18 -0
  94. package/tap-snapshots/test/pseudo/deprecated.ts.test.cjs +18 -0
  95. package/tap-snapshots/test/pseudo/dist.ts.test.cjs +30 -0
  96. package/tap-snapshots/test/pseudo/dynamic.ts.test.cjs +18 -0
  97. package/tap-snapshots/test/pseudo/empty.ts.test.cjs +50 -0
  98. package/tap-snapshots/test/pseudo/entropic.ts.test.cjs +18 -0
  99. package/tap-snapshots/test/pseudo/env.ts.test.cjs +18 -0
  100. package/tap-snapshots/test/pseudo/eval.ts.test.cjs +18 -0
  101. package/tap-snapshots/test/pseudo/fs.ts.test.cjs +18 -0
  102. package/tap-snapshots/test/pseudo/helpers.ts.test.cjs +18 -0
  103. package/tap-snapshots/test/pseudo/hostname.ts.test.cjs +148 -0
  104. package/tap-snapshots/test/pseudo/license.ts.test.cjs +41 -0
  105. package/tap-snapshots/test/pseudo/link.ts.test.cjs +36 -0
  106. package/tap-snapshots/test/pseudo/malware.ts.test.cjs +22 -0
  107. package/tap-snapshots/test/pseudo/minified.ts.test.cjs +18 -0
  108. package/tap-snapshots/test/pseudo/missing.ts.test.cjs +30 -0
  109. package/tap-snapshots/test/pseudo/native.ts.test.cjs +18 -0
  110. package/tap-snapshots/test/pseudo/network.ts.test.cjs +18 -0
  111. package/tap-snapshots/test/pseudo/obfuscated.ts.test.cjs +18 -0
  112. package/tap-snapshots/test/pseudo/outdated.ts.test.cjs +130 -0
  113. package/tap-snapshots/test/pseudo/overridden.ts.test.cjs +75 -0
  114. package/tap-snapshots/test/pseudo/prerelease.ts.test.cjs +101 -0
  115. package/tap-snapshots/test/pseudo/private.ts.test.cjs +38 -0
  116. package/tap-snapshots/test/pseudo/published.ts.test.cjs +171 -0
  117. package/tap-snapshots/test/pseudo/registry.ts.test.cjs +68 -0
  118. package/tap-snapshots/test/pseudo/root.ts.test.cjs +24 -0
  119. package/tap-snapshots/test/pseudo/scanned.ts.test.cjs +18 -0
  120. package/tap-snapshots/test/pseudo/score.ts.test.cjs +239 -0
  121. package/tap-snapshots/test/pseudo/scripts.ts.test.cjs +61 -0
  122. package/tap-snapshots/test/pseudo/semver.ts.test.cjs +575 -0
  123. package/tap-snapshots/test/pseudo/severity.ts.test.cjs +95 -0
  124. package/tap-snapshots/test/pseudo/shell.ts.test.cjs +18 -0
  125. package/tap-snapshots/test/pseudo/shrinkwrap.ts.test.cjs +18 -0
  126. package/tap-snapshots/test/pseudo/spec.ts.test.cjs +148 -0
  127. package/tap-snapshots/test/pseudo/squat.ts.test.cjs +129 -0
  128. package/tap-snapshots/test/pseudo/suspicious.ts.test.cjs +18 -0
  129. package/tap-snapshots/test/pseudo/tracker.ts.test.cjs +18 -0
  130. package/tap-snapshots/test/pseudo/trivial.ts.test.cjs +18 -0
  131. package/tap-snapshots/test/pseudo/type.ts.test.cjs +51 -0
  132. package/tap-snapshots/test/pseudo/undesirable.ts.test.cjs +18 -0
  133. package/tap-snapshots/test/pseudo/unknown.ts.test.cjs +18 -0
  134. package/tap-snapshots/test/pseudo/unmaintained.ts.test.cjs +18 -0
  135. package/tap-snapshots/test/pseudo/unpopular.ts.test.cjs +18 -0
  136. package/tap-snapshots/test/pseudo/unstable.ts.test.cjs +18 -0
  137. package/tap-snapshots/test/pseudo/vuln.ts.test.cjs +208 -0
  138. package/tap-snapshots/test/pseudo/vulnerable.ts.test.cjs +20 -0
  139. package/tap-snapshots/test/pseudo/workspace.ts.test.cjs +19 -0
  140. package/tap-snapshots/test/pseudo.ts.test.cjs +1247 -0
  141. package/test/attribute.ts +266 -0
  142. package/test/combinator.ts +168 -0
  143. package/test/fixtures/graph.ts +999 -0
  144. package/test/fixtures/selector.ts +103 -0
  145. package/test/fixtures/types.ts +7 -0
  146. package/test/id.ts +102 -0
  147. package/test/index.ts +1000 -0
  148. package/test/parser.ts +117 -0
  149. package/test/pseudo/abandoned.ts +98 -0
  150. package/test/pseudo/attr.ts +298 -0
  151. package/test/pseudo/built.ts +214 -0
  152. package/test/pseudo/confused.ts +160 -0
  153. package/test/pseudo/cve.ts +249 -0
  154. package/test/pseudo/cwe.ts +255 -0
  155. package/test/pseudo/debug.ts +98 -0
  156. package/test/pseudo/deprecated.ts +98 -0
  157. package/test/pseudo/dev.ts +61 -0
  158. package/test/pseudo/diff.ts +417 -0
  159. package/test/pseudo/dist.ts +215 -0
  160. package/test/pseudo/dynamic.ts +98 -0
  161. package/test/pseudo/empty.ts +108 -0
  162. package/test/pseudo/entropic.ts +101 -0
  163. package/test/pseudo/env.ts +98 -0
  164. package/test/pseudo/eval.ts +98 -0
  165. package/test/pseudo/fs.ts +98 -0
  166. package/test/pseudo/helpers.ts +370 -0
  167. package/test/pseudo/host-context.ts +276 -0
  168. package/test/pseudo/hostname.ts +314 -0
  169. package/test/pseudo/license.ts +265 -0
  170. package/test/pseudo/link.ts +94 -0
  171. package/test/pseudo/malware.ts +184 -0
  172. package/test/pseudo/minified.ts +98 -0
  173. package/test/pseudo/missing.ts +111 -0
  174. package/test/pseudo/native.ts +98 -0
  175. package/test/pseudo/network.ts +98 -0
  176. package/test/pseudo/obfuscated.ts +98 -0
  177. package/test/pseudo/optional.ts +73 -0
  178. package/test/pseudo/outdated.ts +331 -0
  179. package/test/pseudo/overridden.ts +317 -0
  180. package/test/pseudo/path.ts +680 -0
  181. package/test/pseudo/peer.ts +101 -0
  182. package/test/pseudo/prerelease.ts +279 -0
  183. package/test/pseudo/private.ts +108 -0
  184. package/test/pseudo/prod.ts +61 -0
  185. package/test/pseudo/published.ts +557 -0
  186. package/test/pseudo/registry.ts +122 -0
  187. package/test/pseudo/root.ts +66 -0
  188. package/test/pseudo/scanned.ts +78 -0
  189. package/test/pseudo/score.ts +591 -0
  190. package/test/pseudo/scripts.ts +294 -0
  191. package/test/pseudo/semver.ts +822 -0
  192. package/test/pseudo/severity.ts +310 -0
  193. package/test/pseudo/shell.ts +98 -0
  194. package/test/pseudo/shrinkwrap.ts +98 -0
  195. package/test/pseudo/spec.ts +525 -0
  196. package/test/pseudo/squat.ts +565 -0
  197. package/test/pseudo/suspicious.ts +98 -0
  198. package/test/pseudo/tracker.ts +98 -0
  199. package/test/pseudo/trivial.ts +98 -0
  200. package/test/pseudo/type.ts +105 -0
  201. package/test/pseudo/undesirable.ts +98 -0
  202. package/test/pseudo/unknown.ts +98 -0
  203. package/test/pseudo/unmaintained.ts +98 -0
  204. package/test/pseudo/unpopular.ts +98 -0
  205. package/test/pseudo/unstable.ts +98 -0
  206. package/test/pseudo/vuln.ts +625 -0
  207. package/test/pseudo/vulnerable.ts +137 -0
  208. package/test/pseudo/workspace.ts +111 -0
  209. package/test/pseudo.ts +558 -0
  210. package/tsconfig.json +3 -0
  211. package/tsconfig.publish.json +19 -0
  212. package/tsconfig.publish.tsbuildinfo +1 -0
  213. package/typedoc.mjs +2 -0
  214. package/dist/pseudo/vulnerable.d.ts +0 -8
  215. package/dist/pseudo/vulnerable.js +0 -17
@@ -0,0 +1,101 @@
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(':peer pseudo-selector', async t => {
14
+ // Get a simple graph for testing
15
+ const simpleGraph = getSimpleGraph()
16
+
17
+ // Create a peer dependency edge for testing
18
+ // Find an existing edge and change its type to 'peer'
19
+ for (const edge of simpleGraph.edges) {
20
+ if (edge.name === 'c') {
21
+ edge.type = 'peer'
22
+ break
23
+ }
24
+ }
25
+
26
+ // Get the full selection state
27
+ const all = {
28
+ edges: new Set(simpleGraph.edges),
29
+ nodes: new Set(simpleGraph.nodes.values()),
30
+ }
31
+
32
+ // Create an empty selection state
33
+ const empty: GraphSelectionState = {
34
+ edges: new Set(),
35
+ nodes: new Set(),
36
+ }
37
+
38
+ // Run tests in the same pattern as the main pseudo.ts tests
39
+ const queryToExpected = new Set<TestCase>([
40
+ [':peer', all, ['c']], // Should return nodes with peer dependency edges
41
+ [':peer', empty, []], // Empty input should return empty output
42
+ ])
43
+
44
+ const initial = copyGraphSelectionState(all)
45
+ for (const [query, partial, expected] of queryToExpected) {
46
+ const result = await testPseudo(
47
+ query,
48
+ initial,
49
+ copyGraphSelectionState(partial),
50
+ )
51
+
52
+ t.strictSame(
53
+ result.nodes.map(i => i.name),
54
+ expected,
55
+ `query > "${query}"`,
56
+ )
57
+
58
+ // Verify all edges are peer dependencies
59
+ const edgeArray = [...result.edges]
60
+ if (edgeArray.length > 0) {
61
+ for (const edge of edgeArray) {
62
+ t.ok(
63
+ edge.type === 'peer' || edge.type === 'peerOptional',
64
+ `edge ${edge.name} should have type 'peer' or 'peerOptional'`,
65
+ )
66
+ }
67
+ }
68
+ }
69
+
70
+ // Test peerOptional type
71
+ t.test('handles peerOptional dependencies', async t => {
72
+ // Change an edge to peerOptional for testing
73
+ for (const edge of simpleGraph.edges) {
74
+ if (edge.name === 'd') {
75
+ edge.type = 'peerOptional'
76
+ break
77
+ }
78
+ }
79
+
80
+ // Run the test
81
+ const result = await testPseudo(
82
+ ':peer',
83
+ initial,
84
+ copyGraphSelectionState(all),
85
+ )
86
+
87
+ // Result should include both peer and peerOptional dependencies
88
+ const nodeArray = [...result.nodes]
89
+ t.ok(
90
+ nodeArray.length >= 2,
91
+ 'Result should include both peer and peerOptional dependencies',
92
+ )
93
+
94
+ // Verify that our peerOptional dependency is included
95
+ const nodeNames = nodeArray.map(n => n.name)
96
+ t.ok(
97
+ nodeNames.includes('d'),
98
+ 'Result should include the peerOptional dependency',
99
+ )
100
+ })
101
+ })
@@ -0,0 +1,279 @@
1
+ import t from 'tap'
2
+ import postcssSelectorParser from 'postcss-selector-parser'
3
+ import type { ParserState } from '../../src/types.ts'
4
+ import { prerelease } from '../../src/pseudo/prerelease.ts'
5
+ import { parse } from '@vltpkg/semver'
6
+ import {
7
+ getSemverRichGraph,
8
+ getSimpleGraph,
9
+ newGraph,
10
+ newNode,
11
+ } from '../fixtures/graph.ts'
12
+
13
+ t.test(':prerelease pseudo-selector', async t => {
14
+ const getState = (query: string, graph = getSemverRichGraph()) => {
15
+ const ast = postcssSelectorParser().astSync(query)
16
+ const current = ast.first.first
17
+ const state: ParserState = {
18
+ comment: '',
19
+ current,
20
+ initial: {
21
+ edges: new Set(graph.edges.values()),
22
+ nodes: new Set(graph.nodes.values()),
23
+ },
24
+ partial: {
25
+ edges: new Set(graph.edges.values()),
26
+ nodes: new Set(graph.nodes.values()),
27
+ },
28
+ collect: {
29
+ edges: new Set(),
30
+ nodes: new Set(),
31
+ },
32
+ cancellable: async () => {},
33
+ walk: async i => i,
34
+ retries: 0,
35
+ securityArchive: undefined,
36
+ importers: new Set(graph.importers),
37
+ signal: new AbortController().signal,
38
+ specificity: { idCounter: 0, commonCounter: 0 },
39
+ }
40
+ return state
41
+ }
42
+
43
+ await t.test(
44
+ 'selects only nodes with prerelease versions',
45
+ async t => {
46
+ const res = await prerelease(getState(':prerelease'))
47
+
48
+ // Should only select nodes with prerelease versions
49
+ const nodeNames = [...res.partial.nodes].map(n => n.name).sort()
50
+ const nodeVersions = [...res.partial.nodes]
51
+ .map(n => n.version)
52
+ .sort()
53
+
54
+ t.strictSame(
55
+ nodeNames,
56
+ ['e', 'g'],
57
+ 'should select only nodes with prerelease versions',
58
+ )
59
+
60
+ t.strictSame(
61
+ nodeVersions,
62
+ ['1.2.3-rc.1+rev.2', '1.3.4-beta.1'],
63
+ 'should select correct prerelease versions',
64
+ )
65
+
66
+ t.matchSnapshot({
67
+ nodes: [...res.partial.nodes].map(n => ({
68
+ name: n.name,
69
+ version: n.version,
70
+ })),
71
+ edges: [...res.partial.edges].map(e => e.name),
72
+ })
73
+ },
74
+ )
75
+
76
+ await t.test('excludes non-prerelease versions', async t => {
77
+ const res = await prerelease(getState(':prerelease'))
78
+
79
+ // Verify that only prerelease versions remain
80
+ for (const node of res.partial.nodes) {
81
+ const version = node.manifest?.version
82
+ if (version) {
83
+ const parsed = parse(version)
84
+ t.ok(
85
+ parsed?.prerelease?.length,
86
+ `${node.name}@${version} should have prerelease identifiers`,
87
+ )
88
+ }
89
+ }
90
+
91
+ t.matchSnapshot([...res.partial.nodes].map(n => n.version).sort())
92
+ })
93
+
94
+ await t.test('handles nodes without version', async t => {
95
+ const graph = newGraph('test-project')
96
+ const addNode = newNode(graph)
97
+
98
+ // Create a node without version
99
+ const nodeWithoutVersion = addNode('no-version', '1.0.0')
100
+ nodeWithoutVersion.manifest = { name: 'no-version' } // No version field
101
+ graph.nodes.set(nodeWithoutVersion.id, nodeWithoutVersion)
102
+
103
+ const res = await prerelease(getState(':prerelease', graph))
104
+
105
+ t.strictSame(
106
+ [...res.partial.nodes].length,
107
+ 0,
108
+ 'should exclude all nodes when none have prerelease versions',
109
+ )
110
+
111
+ t.matchSnapshot({
112
+ nodes: [...res.partial.nodes].map(n => ({
113
+ name: n.name,
114
+ version: n.version,
115
+ })),
116
+ })
117
+ })
118
+
119
+ await t.test('handles nodes with invalid semver', async t => {
120
+ const graph = newGraph('test-project')
121
+ const addNode = newNode(graph)
122
+
123
+ // Create a node with invalid semver
124
+ const nodeWithInvalidSemver = addNode('invalid-semver', '1.0.0')
125
+ nodeWithInvalidSemver.version = 'not-a-semver'
126
+ nodeWithInvalidSemver.manifest = {
127
+ name: 'invalid-semver',
128
+ version: 'not-a-semver',
129
+ }
130
+ graph.nodes.set(nodeWithInvalidSemver.id, nodeWithInvalidSemver)
131
+
132
+ const res = await prerelease(getState(':prerelease', graph))
133
+
134
+ t.strictSame(
135
+ [...res.partial.nodes].length,
136
+ 0,
137
+ 'should exclude all nodes when none have valid prerelease versions',
138
+ )
139
+
140
+ t.matchSnapshot({
141
+ nodes: [...res.partial.nodes].map(n => ({
142
+ name: n.name,
143
+ version: n.version,
144
+ })),
145
+ })
146
+ })
147
+
148
+ await t.test('handles various prerelease formats', async t => {
149
+ const graph = newGraph('prerelease-test')
150
+ const addNode = newNode(graph)
151
+
152
+ // Create nodes with various prerelease formats
153
+ const testCases = [
154
+ { name: 'canary', version: '19.2.0-canary-fa3feba6-20250623' },
155
+ { name: 'beta', version: '1.0.0-beta.0' },
156
+ { name: 'alpha', version: '2.1.0-alpha.1' },
157
+ { name: 'rc', version: '3.0.0-rc.2' },
158
+ { name: 'dev', version: '0.0.0-16' },
159
+ { name: 'next', version: '1.5.0-next.1' },
160
+ { name: 'snapshot', version: '2.0.0-snapshot.20231201' },
161
+ { name: 'build-meta', version: '1.2.3-alpha.1+build.123' },
162
+ { name: 'stable', version: '1.0.0' }, // This should be filtered out
163
+ { name: 'another-stable', version: '2.5.3' }, // This should be filtered out
164
+ ]
165
+
166
+ for (const testCase of testCases) {
167
+ const node = addNode(testCase.name, testCase.version)
168
+ node.version = testCase.version
169
+ node.manifest = {
170
+ name: testCase.name,
171
+ version: testCase.version,
172
+ }
173
+ graph.nodes.set(node.id, node)
174
+ }
175
+
176
+ const res = await prerelease(getState(':prerelease', graph))
177
+
178
+ const selectedNodes = [...res.partial.nodes]
179
+ .map(n => ({ name: n.name, version: n.version }))
180
+ .sort((a, b) => (a.name || '').localeCompare(b.name || ''))
181
+
182
+ // Should select all prerelease versions but exclude stable ones
183
+ const expectedNodes = testCases
184
+ .filter(tc => tc.version.includes('-'))
185
+ .map(tc => ({ name: tc.name, version: tc.version }))
186
+ .sort((a, b) => a.name.localeCompare(b.name))
187
+
188
+ t.strictSame(
189
+ selectedNodes,
190
+ expectedNodes,
191
+ 'should select all prerelease versions and exclude stable ones',
192
+ )
193
+
194
+ t.matchSnapshot({
195
+ selected: selectedNodes,
196
+ total: testCases.length,
197
+ })
198
+ })
199
+
200
+ await t.test('removes dangling edges properly', async t => {
201
+ const graph = getSemverRichGraph()
202
+ const initialEdgeCount = graph.edges.size
203
+
204
+ const res = await prerelease(getState(':prerelease', graph))
205
+
206
+ // Check that dangling edges were removed
207
+ const remainingEdges = [...res.partial.edges]
208
+
209
+ t.ok(
210
+ remainingEdges.length <= initialEdgeCount,
211
+ 'should have same or fewer edges after filtering',
212
+ )
213
+
214
+ // Verify all remaining edges connect to nodes that remain
215
+ for (const edge of remainingEdges) {
216
+ if (edge.to) {
217
+ t.ok(
218
+ res.partial.nodes.has(edge.to),
219
+ `edge ${edge.name} should have valid to node`,
220
+ )
221
+ }
222
+ }
223
+
224
+ t.matchSnapshot({
225
+ remainingEdges: remainingEdges.length,
226
+ initialEdges: initialEdgeCount,
227
+ edgeNames: remainingEdges.map(e => e.name).sort(),
228
+ })
229
+ })
230
+
231
+ await t.test('works with empty graph', async t => {
232
+ const emptyGraph = newGraph('empty-test')
233
+ // Remove all nodes except root
234
+ emptyGraph.nodes.clear()
235
+ emptyGraph.edges.clear()
236
+ emptyGraph.nodes.set(
237
+ emptyGraph.mainImporter.id,
238
+ emptyGraph.mainImporter,
239
+ )
240
+
241
+ const res = await prerelease(getState(':prerelease', emptyGraph))
242
+
243
+ t.strictSame(
244
+ [...res.partial.nodes].length,
245
+ 0,
246
+ 'should have no nodes when root has no prerelease version',
247
+ )
248
+
249
+ t.strictSame(
250
+ [...res.partial.edges].length,
251
+ 0,
252
+ 'should have no edges',
253
+ )
254
+ })
255
+
256
+ await t.test(
257
+ 'works with simple graph (no prereleases)',
258
+ async t => {
259
+ const simpleGraph = getSimpleGraph()
260
+ const res = await prerelease(
261
+ getState(':prerelease', simpleGraph),
262
+ )
263
+
264
+ // Simple graph has no prerelease versions
265
+ t.strictSame(
266
+ [...res.partial.nodes].length,
267
+ 0,
268
+ 'should have no nodes when no prereleases exist',
269
+ )
270
+
271
+ t.matchSnapshot({
272
+ nodes: [...res.partial.nodes].map(n => ({
273
+ name: n.name,
274
+ version: n.version,
275
+ })),
276
+ })
277
+ },
278
+ )
279
+ })
@@ -0,0 +1,108 @@
1
+ import t from 'tap'
2
+ import postcssSelectorParser from 'postcss-selector-parser'
3
+ import type { ParserState } from '../../src/types.ts'
4
+ import { privateParser } from '../../src/pseudo/private.ts'
5
+ import {
6
+ getSimpleGraph,
7
+ getSingleWorkspaceGraph,
8
+ getCycleGraph,
9
+ } from '../fixtures/graph.ts'
10
+
11
+ t.test('selects packages with private flag', 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 private flag in simple graph',
43
+ async t => {
44
+ // Based on the getSimpleGraph fixture, only the 'd' package has private: true
45
+ const res = await privateParser(getState(':private'))
46
+ t.strictSame(
47
+ [...res.partial.nodes].map(n => n.name),
48
+ ['d'],
49
+ 'should select only packages with private flag set to true',
50
+ )
51
+ t.matchSnapshot({
52
+ nodes: [...res.partial.nodes].map(n => n.name).sort(),
53
+ edges: [...res.partial.edges].map(e => e.name).sort(),
54
+ })
55
+ },
56
+ )
57
+
58
+ await t.test(
59
+ 'selects no nodes with private flag in workspace graph',
60
+ async t => {
61
+ // In getSingleWorkspaceGraph, no nodes have private flag
62
+ const wsGraph = getSingleWorkspaceGraph()
63
+ const res = await privateParser(getState(':private', wsGraph))
64
+ t.strictSame(
65
+ [...res.partial.nodes].map(n => n.name),
66
+ [],
67
+ 'should not select any nodes in workspace graph as none have private flag',
68
+ )
69
+ t.matchSnapshot({
70
+ nodes: [...res.partial.nodes].map(n => n.name).sort(),
71
+ edges: [...res.partial.edges].map(e => e.name).sort(),
72
+ })
73
+ },
74
+ )
75
+
76
+ await t.test('selects no nodes in cycle graph', async t => {
77
+ // In getCycleGraph, no nodes have private flag
78
+ const cycleGraph = getCycleGraph()
79
+ const res = await privateParser(getState(':private', cycleGraph))
80
+ t.strictSame(
81
+ [...res.partial.nodes].map(n => n.name),
82
+ [],
83
+ 'should not select any packages in a cycle graph as none have private flag',
84
+ )
85
+ t.matchSnapshot({
86
+ nodes: [...res.partial.nodes].map(n => n.name),
87
+ edges: [...res.partial.edges].map(e => e.name),
88
+ })
89
+ })
90
+
91
+ await t.test('handles an empty partial state', async t => {
92
+ // Create a state with empty partial nodes
93
+ const state = getState(':private')
94
+ state.partial.nodes.clear()
95
+ state.partial.edges.clear()
96
+
97
+ const res = await privateParser(state)
98
+ t.strictSame(
99
+ [...res.partial.nodes].map(n => n.name),
100
+ [],
101
+ 'should return empty array when starting with empty partial state',
102
+ )
103
+ t.matchSnapshot({
104
+ nodes: [...res.partial.nodes].map(n => n.name),
105
+ edges: [...res.partial.edges].map(e => e.name),
106
+ })
107
+ })
108
+ })
@@ -0,0 +1,61 @@
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(':prod 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
+ [':prod', all, ['a', 'c', 'd', 'e']], // Should return nodes with prod edges
32
+ [':prod', 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 are of type 'prod'
50
+ const edgeArray = [...result.edges]
51
+ if (edgeArray.length > 0) {
52
+ for (const edge of edgeArray) {
53
+ t.equal(
54
+ edge.type,
55
+ 'prod',
56
+ `edge ${edge.name} should be of type 'prod'`,
57
+ )
58
+ }
59
+ }
60
+ }
61
+ })