@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,101 +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(':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
- })
@@ -1,279 +0,0 @@
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
- })
@@ -1,108 +0,0 @@
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
- })
@@ -1,61 +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(':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
- })