@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
package/test/parser.ts DELETED
@@ -1,117 +0,0 @@
1
- import t from 'tap'
2
- import postcssSelectorParser from 'postcss-selector-parser'
3
- import { parse, escapeScopedNamesSlashes } from '../src/parser.ts'
4
-
5
- t.test('escapeScopedNamesSlashes', async t => {
6
- t.equal(
7
- escapeScopedNamesSlashes('#@scope/package'),
8
- '#@scope\\/package',
9
- 'should escape forward slash in #@scope/package pattern',
10
- )
11
-
12
- t.equal(
13
- escapeScopedNamesSlashes('#@scope-dash-sep/package'),
14
- '#@scope-dash-sep\\/package',
15
- 'should escape forward slash with dashes',
16
- )
17
-
18
- t.equal(
19
- escapeScopedNamesSlashes('#@scope.dot.sep/package'),
20
- '#@scope.dot.sep\\/package',
21
- 'should escape forward slash with dots',
22
- )
23
-
24
- t.equal(
25
- escapeScopedNamesSlashes('#@multiple/package #@another/pkg'),
26
- '#@multiple\\/package #@another\\/pkg',
27
- 'should escape multiple instances of the pattern',
28
- )
29
-
30
- t.equal(
31
- escapeScopedNamesSlashes('#@name/package[attr]'),
32
- '#@name\\/package[attr]',
33
- 'should work with attribute selectors',
34
- )
35
-
36
- t.equal(
37
- escapeScopedNamesSlashes('#regular #@123/456'),
38
- '#regular #@123\\/456',
39
- 'should work with numeric components',
40
- )
41
-
42
- t.equal(
43
- escapeScopedNamesSlashes('#regular-selector'),
44
- '#regular-selector',
45
- 'should not modify strings without the specific pattern',
46
- )
47
-
48
- t.equal(
49
- escapeScopedNamesSlashes('a > b #@xyz/abc'),
50
- 'a > b #@xyz\\/abc',
51
- 'should work with combinators',
52
- )
53
- })
54
-
55
- t.test('parse', async t => {
56
- // Test basic parsing
57
- t.ok(parse(':root > *'), 'should parse simple selectors')
58
-
59
- // Compare with direct postcss parser for equivalence (minus the escaping)
60
- const simpleSelector = 'div > span'
61
- const directAst = postcssSelectorParser().astSync(simpleSelector)
62
- const ourAst = parse(simpleSelector)
63
-
64
- t.same(
65
- ourAst.toString(),
66
- directAst.toString(),
67
- 'should produce equivalent AST to direct postcss parser',
68
- )
69
-
70
- // Test with a selector that needs escaping
71
- const selectorWithScoped = '#@scope/package'
72
- t.doesNotThrow(
73
- () => parse(selectorWithScoped),
74
- 'should parse selectors with scoped packages without throwing',
75
- )
76
-
77
- // Test a complex selector
78
- const complexSelector = 'a > #@scope/pkg.class:pseudo[attr=val]'
79
- t.ok(
80
- parse(complexSelector),
81
- 'should parse complex selectors with scoped packages',
82
- )
83
-
84
- t.ok(parse(':root > :v(2.0.0)'), 'should parse dots in parameters')
85
- t.ok(
86
- parse(':root > :v("2.0.0")'),
87
- 'should parse dots in string parameters',
88
- )
89
-
90
- const res: any[] = []
91
- parse(':v(>2)').walk(node => {
92
- res.push({
93
- type: node.type,
94
- source: node.source,
95
- ...(node.value ? { value: node.value } : undefined),
96
- })
97
- })
98
- t.matchSnapshot(
99
- res,
100
- 'should clean up usage of combinators params in pseudo selectors that accept only string values',
101
- )
102
-
103
- res.length = 0
104
- parse(
105
- ':root > :v(>1 >2 >3):not(:v(2.0.0-pre+build0.13adsfa1)) > published(<=2024-01-01T11:11:11.111Z) :severity(>=0):score( > 0.9)',
106
- ).walk(node => {
107
- res.push({
108
- type: node.type,
109
- source: node.source,
110
- ...(node.value ? { value: node.value } : undefined),
111
- })
112
- })
113
- t.matchSnapshot(
114
- res,
115
- 'should clean up usage of multiple pseudo selectors requiring cleaning up',
116
- )
117
- })
@@ -1,98 +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 { abandoned } from '../../src/pseudo/abandoned.ts'
8
-
9
- t.test('selects packages with an abandoned 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
- securityArchive: asSecurityArchiveLike(
31
- new Map([
32
- [
33
- joinDepIDTuple(['registry', '', 'e@1.0.0']),
34
- { alerts: [{ type: 'missingAuthor' }] },
35
- ],
36
- ]),
37
- ),
38
- importers: new Set(graph.importers),
39
- retries: 0,
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 abandoned(getState(':abandoned'))
50
- t.strictSame(
51
- [...res.partial.nodes].map(n => n.name),
52
- ['e'],
53
- 'should select only abandoned 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
- securityArchive: undefined,
85
- importers: new Set(),
86
- retries: 0,
87
- signal: new AbortController().signal,
88
- specificity: { idCounter: 0, commonCounter: 0 },
89
- }
90
- return state
91
- }
92
-
93
- await t.rejects(
94
- abandoned(getState(':abandoned')),
95
- { message: /Missing security archive/ },
96
- 'should throw an error',
97
- )
98
- })
@@ -1,298 +0,0 @@
1
- import t from 'tap'
2
- import postcssSelectorParser from 'postcss-selector-parser'
3
- import type { ParserState } from '../../src/types.ts'
4
- import { attr } from '../../src/pseudo/attr.ts'
5
- import { getSimpleGraph } from '../fixtures/graph.ts'
6
-
7
- t.test('selects packages based on attribute properties', async t => {
8
- const getState = (query: string, graph = getSimpleGraph()) => {
9
- const ast = postcssSelectorParser().astSync(query)
10
- const current = ast.first.first
11
- const state: ParserState = {
12
- comment: '',
13
- current,
14
- initial: {
15
- edges: new Set(graph.edges.values()),
16
- nodes: new Set(graph.nodes.values()),
17
- },
18
- partial: {
19
- edges: new Set(graph.edges.values()),
20
- nodes: new Set(graph.nodes.values()),
21
- },
22
- collect: {
23
- edges: new Set(),
24
- nodes: new Set(),
25
- },
26
- cancellable: async () => {},
27
- walk: async i => i,
28
- securityArchive: undefined,
29
- importers: new Set(graph.importers),
30
- retries: 0,
31
- signal: new AbortController().signal,
32
- specificity: { idCounter: 0, commonCounter: 0 },
33
- }
34
- return state
35
- }
36
-
37
- await t.test('selects nodes with a specific attribute', async t => {
38
- // Based on the getSimpleGraph fixture, only package 'b' has 'scripts' property
39
- const res = await attr(getState(':attr([scripts])'))
40
- t.strictSame(
41
- [...res.partial.nodes].map(n => n.name),
42
- ['b'],
43
- 'should select only package with scripts property',
44
- )
45
- t.matchSnapshot({
46
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
47
- edges: [...res.partial.edges].map(e => e.name).sort(),
48
- })
49
- })
50
-
51
- await t.test(
52
- 'selects nodes with a specific attribute value',
53
- async t => {
54
- // In getSimpleGraph, only package 'd' has private=true
55
- const res = await attr(getState(':attr([private=true])'))
56
- t.strictSame(
57
- [...res.partial.nodes].map(n => n.name),
58
- ['d'],
59
- 'should select only package with private=true',
60
- )
61
- t.matchSnapshot({
62
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
63
- edges: [...res.partial.edges].map(e => e.name).sort(),
64
- })
65
- },
66
- )
67
-
68
- await t.test(
69
- 'selects nodes with nested attribute paths',
70
- async t => {
71
- // Package 'b' has a nested scripts.postinstall property
72
- const res = await attr(
73
- getState(':attr(scripts, [postinstall])'),
74
- )
75
- t.strictSame(
76
- [...res.partial.nodes].map(n => n.name),
77
- ['b'],
78
- 'should select packages with nested attributes',
79
- )
80
- t.matchSnapshot({
81
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
82
- edges: [...res.partial.edges].map(e => e.name).sort(),
83
- })
84
- },
85
- )
86
-
87
- await t.test(
88
- 'selects nodes with nested attribute value',
89
- async t => {
90
- // Package 'b' has a nested scripts.test="test" property
91
- const res = await attr(getState(':attr(scripts, [test=test])'))
92
- t.strictSame(
93
- [...res.partial.nodes].map(n => n.name),
94
- ['b'],
95
- 'should select packages with specific nested attribute values',
96
- )
97
- t.matchSnapshot({
98
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
99
- edges: [...res.partial.edges].map(e => e.name).sort(),
100
- })
101
- },
102
- )
103
-
104
- await t.test(
105
- 'supports quoted strings for property names',
106
- async t => {
107
- // Package 'b' has a nested scripts.test="test" property using quoted strings
108
- const res = await attr(
109
- getState(':attr("scripts", [test=test])'),
110
- )
111
- t.strictSame(
112
- [...res.partial.nodes].map(n => n.name),
113
- ['b'],
114
- 'should select packages with quoted property name',
115
- )
116
- t.matchSnapshot({
117
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
118
- edges: [...res.partial.edges].map(e => e.name).sort(),
119
- })
120
- },
121
- )
122
-
123
- await t.test(
124
- 'supports multiple quoted strings for nested properties',
125
- async t => {
126
- // Package 'd' has a deeply nested structure with a.b[].c.d="foo" using quoted strings
127
- const res = await attr(
128
- getState(':attr("a", "b", "c", [d=foo])'),
129
- )
130
- t.strictSame(
131
- [...res.partial.nodes].map(n => n.name),
132
- ['d'],
133
- 'should select packages with deeply nested attributes using quoted strings',
134
- )
135
- t.matchSnapshot({
136
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
137
- edges: [...res.partial.edges].map(e => e.name).sort(),
138
- })
139
- },
140
- )
141
-
142
- await t.test(
143
- 'supports mixed quoted and unquoted property names',
144
- async t => {
145
- // Package 'd' has a deeply nested structure mixing quoted and unquoted property names
146
- const res = await attr(getState(':attr("a", b, "c", [d=foo])'))
147
- t.strictSame(
148
- [...res.partial.nodes].map(n => n.name),
149
- ['d'],
150
- 'should select packages with mixed quoted and unquoted property names',
151
- )
152
- t.matchSnapshot({
153
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
154
- edges: [...res.partial.edges].map(e => e.name).sort(),
155
- })
156
- },
157
- )
158
-
159
- await t.test(
160
- 'selects nodes with complex nested attributes',
161
- async t => {
162
- // Package 'd' has a deeply nested structure with a.b[].c.d="foo"
163
- const res = await attr(getState(':attr(a, b, c, [d=foo])'))
164
- t.strictSame(
165
- [...res.partial.nodes].map(n => n.name),
166
- ['d'],
167
- 'should select packages with deeply nested attributes',
168
- )
169
- t.matchSnapshot({
170
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
171
- edges: [...res.partial.edges].map(e => e.name).sort(),
172
- })
173
- },
174
- )
175
-
176
- await t.test(
177
- 'selects nodes with array value attributes',
178
- async t => {
179
- // Package 'c' has keywords=['something', 'someother']
180
- const res = await attr(getState(':attr([keywords=something])'))
181
- t.strictSame(
182
- [...res.partial.nodes].map(n => n.name),
183
- ['c'],
184
- 'should select packages with array value attributes',
185
- )
186
- t.matchSnapshot({
187
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
188
- edges: [...res.partial.edges].map(e => e.name).sort(),
189
- })
190
- },
191
- )
192
-
193
- await t.test(
194
- 'selects nodes with complex nested object in arrays',
195
- async t => {
196
- // Package 'b' has contributors array with objects
197
- const res = await attr(
198
- getState(':attr(contributors, [name^=Ruy])'),
199
- )
200
- t.strictSame(
201
- [...res.partial.nodes].map(n => n.name),
202
- ['b'],
203
- 'should select packages with objects in arrays by attribute',
204
- )
205
- t.matchSnapshot({
206
- nodes: [...res.partial.nodes].map(n => n.name).sort(),
207
- edges: [...res.partial.edges].map(e => e.name).sort(),
208
- })
209
- },
210
- )
211
-
212
- await t.test(
213
- 'returns no nodes for non-existent attribute',
214
- async t => {
215
- const res = await attr(getState(':attr([nonexistent])'))
216
- t.strictSame(
217
- [...res.partial.nodes].map(n => n.name),
218
- [],
219
- 'should return no nodes when attribute does not exist',
220
- )
221
- t.matchSnapshot({
222
- nodes: [...res.partial.nodes].map(n => n.name),
223
- edges: [...res.partial.edges].map(e => e.name),
224
- })
225
- },
226
- )
227
-
228
- await t.test(
229
- 'returns no nodes for non-existent nested attribute',
230
- async t => {
231
- const res = await attr(
232
- getState(':attr(scripts, [nonexistent])'),
233
- )
234
- t.strictSame(
235
- [...res.partial.nodes].map(n => n.name),
236
- [],
237
- 'should return no nodes when nested attribute does not exist',
238
- )
239
- t.matchSnapshot({
240
- nodes: [...res.partial.nodes].map(n => n.name),
241
- edges: [...res.partial.edges].map(e => e.name),
242
- })
243
- },
244
- )
245
-
246
- await t.test('handles attribute operator matching', async t => {
247
- // Test starts-with operator
248
- const startsWithRes = await attr(getState(':attr([version^=1])'))
249
- t.strictSame(
250
- [...startsWithRes.partial.nodes].map(n => n.name).sort(),
251
- ['a', 'c', 'd', 'e', 'f', '@x/y', 'my-project'].sort(),
252
- 'should match attributes with starts-with operator',
253
- )
254
-
255
- // Test ends-with operator
256
- const endsWithRes = await attr(getState(':attr([version$=0])'))
257
- t.strictSame(
258
- [...endsWithRes.partial.nodes].map(n => n.name).sort(),
259
- ['@x/y', 'a', 'b', 'c', 'd', 'e', 'f', 'my-project'].sort(),
260
- 'should match attributes with ends-with operator',
261
- )
262
-
263
- t.matchSnapshot({
264
- startsWith: [...startsWithRes.partial.nodes]
265
- .map(n => n.name)
266
- .sort(),
267
- endsWith: [...endsWithRes.partial.nodes]
268
- .map(n => n.name)
269
- .sort(),
270
- })
271
- })
272
-
273
- await t.test('handles an empty partial state', async t => {
274
- // Create a state with empty partial nodes
275
- const state = getState(':attr([scripts])')
276
- state.partial.nodes.clear()
277
- state.partial.edges.clear()
278
-
279
- const res = await attr(state)
280
- t.strictSame(
281
- [...res.partial.nodes].map(n => n.name),
282
- [],
283
- 'should return empty array when starting with empty partial state',
284
- )
285
- t.matchSnapshot({
286
- nodes: [...res.partial.nodes].map(n => n.name),
287
- edges: [...res.partial.edges].map(e => e.name),
288
- })
289
- })
290
-
291
- await t.test('invalid parameter handling', async t => {
292
- await t.rejects(
293
- attr(getState(':attr(>)')),
294
- /Failed to parse :attr selector/,
295
- 'should throw error for invalid parameters',
296
- )
297
- })
298
- })