@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.
- package/dist/index.js +10 -6
- package/dist/parser.js +2 -1
- package/dist/pseudo/hostname.js +3 -1
- package/dist/pseudo/malware.d.ts +3 -16
- package/dist/pseudo/malware.js +11 -171
- package/dist/pseudo/scripts.js +1 -1
- package/dist/pseudo/vuln.d.ts +22 -0
- package/dist/pseudo/vuln.js +220 -0
- package/dist/pseudo.js +3 -3
- package/dist/types.d.ts +3 -2
- package/package.json +19 -10
- package/skills/dss-query/REFERENCE.md +123 -0
- package/skills/dss-query/SKILL.md +190 -0
- package/skills/dss-query/evals/README.md +79 -0
- package/skills/dss-query/evals/evals.json +89 -0
- package/skills/dss-query/evals/grade.mjs +480 -0
- package/src/attribute.ts +186 -0
- package/src/combinator.ts +132 -0
- package/src/id.ts +46 -0
- package/src/index.ts +620 -0
- package/src/parser.ts +122 -0
- package/src/pseudo/abandoned.ts +9 -0
- package/src/pseudo/attr.ts +92 -0
- package/src/pseudo/built.ts +19 -0
- package/src/pseudo/confused.ts +29 -0
- package/src/pseudo/cve.ts +93 -0
- package/src/pseudo/cwe.ts +97 -0
- package/src/pseudo/debug.ts +9 -0
- package/src/pseudo/deprecated.ts +9 -0
- package/src/pseudo/dev.ts +18 -0
- package/src/pseudo/diff.ts +90 -0
- package/src/pseudo/dist.ts +144 -0
- package/src/pseudo/dynamic.ts +9 -0
- package/src/pseudo/empty.ts +15 -0
- package/src/pseudo/entropic.ts +9 -0
- package/src/pseudo/env.ts +6 -0
- package/src/pseudo/eval.ts +9 -0
- package/src/pseudo/fs.ts +9 -0
- package/src/pseudo/helpers.ts +106 -0
- package/src/pseudo/host.ts +111 -0
- package/src/pseudo/hostname.ts +156 -0
- package/src/pseudo/license.ts +134 -0
- package/src/pseudo/link.ts +30 -0
- package/src/pseudo/malware.ts +41 -0
- package/src/pseudo/minified.ts +9 -0
- package/src/pseudo/missing.ts +16 -0
- package/src/pseudo/native.ts +9 -0
- package/src/pseudo/network.ts +9 -0
- package/src/pseudo/obfuscated.ts +9 -0
- package/src/pseudo/optional.ts +18 -0
- package/src/pseudo/outdated.ts +305 -0
- package/src/pseudo/overridden.ts +20 -0
- package/src/pseudo/path.ts +146 -0
- package/src/pseudo/peer.ts +18 -0
- package/src/pseudo/prerelease.ts +47 -0
- package/src/pseudo/private.ts +19 -0
- package/src/pseudo/prod.ts +18 -0
- package/src/pseudo/published.ts +248 -0
- package/src/pseudo/registry.ts +29 -0
- package/src/pseudo/root.ts +19 -0
- package/src/pseudo/scanned.ts +20 -0
- package/src/pseudo/score.ts +186 -0
- package/src/pseudo/scripts.ts +54 -0
- package/src/pseudo/semver.ts +320 -0
- package/src/pseudo/severity.ts +231 -0
- package/src/pseudo/shell.ts +9 -0
- package/src/pseudo/shrinkwrap.ts +9 -0
- package/src/pseudo/spec.ts +131 -0
- package/src/pseudo/squat.ts +225 -0
- package/src/pseudo/suspicious.ts +9 -0
- package/src/pseudo/tracker.ts +9 -0
- package/src/pseudo/trivial.ts +9 -0
- package/src/pseudo/type.ts +26 -0
- package/src/pseudo/undesirable.ts +9 -0
- package/src/pseudo/unknown.ts +9 -0
- package/src/pseudo/unmaintained.ts +9 -0
- package/src/pseudo/unpopular.ts +9 -0
- package/src/pseudo/unstable.ts +9 -0
- package/src/pseudo/vuln.ts +273 -0
- package/src/pseudo/workspace.ts +22 -0
- package/src/pseudo.ts +413 -0
- package/src/types.ts +165 -0
- package/tap-snapshots/test/attribute.ts.test.cjs +304 -0
- package/tap-snapshots/test/combinator.ts.test.cjs +333 -0
- package/tap-snapshots/test/id.ts.test.cjs +118 -0
- package/tap-snapshots/test/parser.ts.test.cjs +344 -0
- package/tap-snapshots/test/pseudo/abandoned.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/attr.ts.test.cjs +161 -0
- package/tap-snapshots/test/pseudo/built.ts.test.cjs +70 -0
- package/tap-snapshots/test/pseudo/confused.ts.test.cjs +32 -0
- package/tap-snapshots/test/pseudo/cve.ts.test.cjs +49 -0
- package/tap-snapshots/test/pseudo/cwe.ts.test.cjs +49 -0
- package/tap-snapshots/test/pseudo/debug.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/deprecated.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/dist.ts.test.cjs +30 -0
- package/tap-snapshots/test/pseudo/dynamic.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/empty.ts.test.cjs +50 -0
- package/tap-snapshots/test/pseudo/entropic.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/env.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/eval.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/fs.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/helpers.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/hostname.ts.test.cjs +148 -0
- package/tap-snapshots/test/pseudo/license.ts.test.cjs +41 -0
- package/tap-snapshots/test/pseudo/link.ts.test.cjs +36 -0
- package/tap-snapshots/test/pseudo/malware.ts.test.cjs +22 -0
- package/tap-snapshots/test/pseudo/minified.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/missing.ts.test.cjs +30 -0
- package/tap-snapshots/test/pseudo/native.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/network.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/obfuscated.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/outdated.ts.test.cjs +130 -0
- package/tap-snapshots/test/pseudo/overridden.ts.test.cjs +75 -0
- package/tap-snapshots/test/pseudo/prerelease.ts.test.cjs +101 -0
- package/tap-snapshots/test/pseudo/private.ts.test.cjs +38 -0
- package/tap-snapshots/test/pseudo/published.ts.test.cjs +171 -0
- package/tap-snapshots/test/pseudo/registry.ts.test.cjs +68 -0
- package/tap-snapshots/test/pseudo/root.ts.test.cjs +24 -0
- package/tap-snapshots/test/pseudo/scanned.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/score.ts.test.cjs +239 -0
- package/tap-snapshots/test/pseudo/scripts.ts.test.cjs +61 -0
- package/tap-snapshots/test/pseudo/semver.ts.test.cjs +575 -0
- package/tap-snapshots/test/pseudo/severity.ts.test.cjs +95 -0
- package/tap-snapshots/test/pseudo/shell.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/shrinkwrap.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/spec.ts.test.cjs +148 -0
- package/tap-snapshots/test/pseudo/squat.ts.test.cjs +129 -0
- package/tap-snapshots/test/pseudo/suspicious.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/tracker.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/trivial.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/type.ts.test.cjs +51 -0
- package/tap-snapshots/test/pseudo/undesirable.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/unknown.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/unmaintained.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/unpopular.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/unstable.ts.test.cjs +18 -0
- package/tap-snapshots/test/pseudo/vuln.ts.test.cjs +208 -0
- package/tap-snapshots/test/pseudo/vulnerable.ts.test.cjs +20 -0
- package/tap-snapshots/test/pseudo/workspace.ts.test.cjs +19 -0
- package/tap-snapshots/test/pseudo.ts.test.cjs +1247 -0
- package/test/attribute.ts +266 -0
- package/test/combinator.ts +168 -0
- package/test/fixtures/graph.ts +999 -0
- package/test/fixtures/selector.ts +103 -0
- package/test/fixtures/types.ts +7 -0
- package/test/id.ts +102 -0
- package/test/index.ts +1000 -0
- package/test/parser.ts +117 -0
- package/test/pseudo/abandoned.ts +98 -0
- package/test/pseudo/attr.ts +298 -0
- package/test/pseudo/built.ts +214 -0
- package/test/pseudo/confused.ts +160 -0
- package/test/pseudo/cve.ts +249 -0
- package/test/pseudo/cwe.ts +255 -0
- package/test/pseudo/debug.ts +98 -0
- package/test/pseudo/deprecated.ts +98 -0
- package/test/pseudo/dev.ts +61 -0
- package/test/pseudo/diff.ts +417 -0
- package/test/pseudo/dist.ts +215 -0
- package/test/pseudo/dynamic.ts +98 -0
- package/test/pseudo/empty.ts +108 -0
- package/test/pseudo/entropic.ts +101 -0
- package/test/pseudo/env.ts +98 -0
- package/test/pseudo/eval.ts +98 -0
- package/test/pseudo/fs.ts +98 -0
- package/test/pseudo/helpers.ts +370 -0
- package/test/pseudo/host-context.ts +276 -0
- package/test/pseudo/hostname.ts +314 -0
- package/test/pseudo/license.ts +265 -0
- package/test/pseudo/link.ts +94 -0
- package/test/pseudo/malware.ts +184 -0
- package/test/pseudo/minified.ts +98 -0
- package/test/pseudo/missing.ts +111 -0
- package/test/pseudo/native.ts +98 -0
- package/test/pseudo/network.ts +98 -0
- package/test/pseudo/obfuscated.ts +98 -0
- package/test/pseudo/optional.ts +73 -0
- package/test/pseudo/outdated.ts +331 -0
- package/test/pseudo/overridden.ts +317 -0
- package/test/pseudo/path.ts +680 -0
- package/test/pseudo/peer.ts +101 -0
- package/test/pseudo/prerelease.ts +279 -0
- package/test/pseudo/private.ts +108 -0
- package/test/pseudo/prod.ts +61 -0
- package/test/pseudo/published.ts +557 -0
- package/test/pseudo/registry.ts +122 -0
- package/test/pseudo/root.ts +66 -0
- package/test/pseudo/scanned.ts +78 -0
- package/test/pseudo/score.ts +591 -0
- package/test/pseudo/scripts.ts +294 -0
- package/test/pseudo/semver.ts +822 -0
- package/test/pseudo/severity.ts +310 -0
- package/test/pseudo/shell.ts +98 -0
- package/test/pseudo/shrinkwrap.ts +98 -0
- package/test/pseudo/spec.ts +525 -0
- package/test/pseudo/squat.ts +565 -0
- package/test/pseudo/suspicious.ts +98 -0
- package/test/pseudo/tracker.ts +98 -0
- package/test/pseudo/trivial.ts +98 -0
- package/test/pseudo/type.ts +105 -0
- package/test/pseudo/undesirable.ts +98 -0
- package/test/pseudo/unknown.ts +98 -0
- package/test/pseudo/unmaintained.ts +98 -0
- package/test/pseudo/unpopular.ts +98 -0
- package/test/pseudo/unstable.ts +98 -0
- package/test/pseudo/vuln.ts +625 -0
- package/test/pseudo/vulnerable.ts +137 -0
- package/test/pseudo/workspace.ts +111 -0
- package/test/pseudo.ts +558 -0
- package/tsconfig.json +3 -0
- package/tsconfig.publish.json +19 -0
- package/tsconfig.publish.tsbuildinfo +1 -0
- package/typedoc.mjs +2 -0
- package/dist/pseudo/vulnerable.d.ts +0 -8
- package/dist/pseudo/vulnerable.js +0 -17
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
import t from 'tap'
|
|
2
|
+
import { joinDepIDTuple } from '@vltpkg/dep-id'
|
|
3
|
+
import { asPostcssNodeWithChildren, parse } from '@vltpkg/dss-parser'
|
|
4
|
+
import { asSecurityArchiveLike } from '@vltpkg/security-archive'
|
|
5
|
+
import { getSimpleGraph } from '../fixtures/graph.ts'
|
|
6
|
+
import {
|
|
7
|
+
squat,
|
|
8
|
+
isSquatKind,
|
|
9
|
+
asSquatKind,
|
|
10
|
+
parseInternals,
|
|
11
|
+
} from '../../src/pseudo/squat.ts'
|
|
12
|
+
import type { ParserState } from '../../src/types.ts'
|
|
13
|
+
|
|
14
|
+
t.test('selects packages with a specific squat kind', async t => {
|
|
15
|
+
const getState = (query: string, graph = getSimpleGraph()) => {
|
|
16
|
+
const ast = parse(query)
|
|
17
|
+
const current = ast.first.first
|
|
18
|
+
const state: ParserState = {
|
|
19
|
+
comment: '',
|
|
20
|
+
current,
|
|
21
|
+
initial: {
|
|
22
|
+
edges: new Set(graph.edges.values()),
|
|
23
|
+
nodes: new Set(graph.nodes.values()),
|
|
24
|
+
},
|
|
25
|
+
partial: {
|
|
26
|
+
edges: new Set(graph.edges.values()),
|
|
27
|
+
nodes: new Set(graph.nodes.values()),
|
|
28
|
+
},
|
|
29
|
+
collect: {
|
|
30
|
+
edges: new Set(),
|
|
31
|
+
nodes: new Set(),
|
|
32
|
+
},
|
|
33
|
+
cancellable: async () => {},
|
|
34
|
+
walk: async i => i,
|
|
35
|
+
securityArchive: asSecurityArchiveLike(
|
|
36
|
+
new Map([
|
|
37
|
+
[
|
|
38
|
+
joinDepIDTuple(['registry', '', 'e@1.0.0']),
|
|
39
|
+
{
|
|
40
|
+
id: joinDepIDTuple(['registry', '', 'e@1.0.0']),
|
|
41
|
+
alerts: [{ type: 'didYouMean' }],
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
[
|
|
45
|
+
joinDepIDTuple(['registry', '', 'f@1.0.0']),
|
|
46
|
+
{
|
|
47
|
+
id: joinDepIDTuple(['registry', '', 'f@1.0.0']),
|
|
48
|
+
alerts: [{ type: 'gptDidYouMean' }],
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
]),
|
|
52
|
+
),
|
|
53
|
+
importers: new Set(graph.importers),
|
|
54
|
+
retries: 0,
|
|
55
|
+
signal: new AbortController().signal,
|
|
56
|
+
specificity: { idCounter: 0, commonCounter: 0 },
|
|
57
|
+
}
|
|
58
|
+
return state
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
await t.test(
|
|
62
|
+
'filter out any node that does not have the squat alert',
|
|
63
|
+
async t => {
|
|
64
|
+
const res = await squat(getState(':squat("critical")'))
|
|
65
|
+
t.strictSame(
|
|
66
|
+
[...res.partial.nodes].map(n => n.name),
|
|
67
|
+
['e'],
|
|
68
|
+
'should select only packages with the specified squat alert',
|
|
69
|
+
)
|
|
70
|
+
t.matchSnapshot({
|
|
71
|
+
nodes: [...res.partial.nodes].map(n => n.name),
|
|
72
|
+
edges: [...res.partial.edges].map(e => e.name),
|
|
73
|
+
})
|
|
74
|
+
},
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
await t.test('filter out using unquoted param', async t => {
|
|
78
|
+
const res = await squat(getState(':squat(medium)'))
|
|
79
|
+
t.strictSame(
|
|
80
|
+
[...res.partial.nodes].map(n => n.name),
|
|
81
|
+
['f'],
|
|
82
|
+
'should select only packages with the specified squat alert',
|
|
83
|
+
)
|
|
84
|
+
t.matchSnapshot({
|
|
85
|
+
nodes: [...res.partial.nodes].map(n => n.name),
|
|
86
|
+
edges: [...res.partial.edges].map(e => e.name),
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
await t.test('filter using numbered param', async t => {
|
|
91
|
+
const res = await squat(getState(':squat(0)'))
|
|
92
|
+
t.strictSame(
|
|
93
|
+
[...res.partial.nodes].map(n => n.name),
|
|
94
|
+
['e'],
|
|
95
|
+
'should select only packages with the specified squat alert',
|
|
96
|
+
)
|
|
97
|
+
t.matchSnapshot({
|
|
98
|
+
nodes: [...res.partial.nodes].map(n => n.name),
|
|
99
|
+
edges: [...res.partial.edges].map(e => e.name),
|
|
100
|
+
})
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
await t.test(
|
|
104
|
+
'greater than comparator with number (unquoted)',
|
|
105
|
+
async t => {
|
|
106
|
+
const res = await squat(getState(':squat(>0)'))
|
|
107
|
+
t.strictSame(
|
|
108
|
+
[...res.partial.nodes].map(n => n.name).sort(),
|
|
109
|
+
['f'],
|
|
110
|
+
'should select packages with squat greater than critical/0',
|
|
111
|
+
)
|
|
112
|
+
t.matchSnapshot({
|
|
113
|
+
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
114
|
+
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
115
|
+
})
|
|
116
|
+
},
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
await t.test(
|
|
120
|
+
'less than comparator with number (quoted)',
|
|
121
|
+
async t => {
|
|
122
|
+
const res = await squat(getState(':squat("<2")'))
|
|
123
|
+
t.strictSame(
|
|
124
|
+
[...res.partial.nodes].map(n => n.name).sort(),
|
|
125
|
+
['e'],
|
|
126
|
+
'should select packages with squat less than medium/2',
|
|
127
|
+
)
|
|
128
|
+
t.matchSnapshot({
|
|
129
|
+
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
130
|
+
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
131
|
+
})
|
|
132
|
+
},
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
await t.test(
|
|
136
|
+
'greater than or equal to comparator with number (quoted)',
|
|
137
|
+
async t => {
|
|
138
|
+
const res = await squat(getState(':squat(">=2")'))
|
|
139
|
+
t.strictSame(
|
|
140
|
+
[...res.partial.nodes].map(n => n.name).sort(),
|
|
141
|
+
['f'],
|
|
142
|
+
'should select packages with squat greater than or equal to medium/2',
|
|
143
|
+
)
|
|
144
|
+
t.matchSnapshot({
|
|
145
|
+
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
146
|
+
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
147
|
+
})
|
|
148
|
+
},
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
await t.test(
|
|
152
|
+
'greater than or equal to comparator - exact match (unquoted)',
|
|
153
|
+
async t => {
|
|
154
|
+
const res = await squat(getState(':squat(>=0)'))
|
|
155
|
+
t.strictSame(
|
|
156
|
+
[...res.partial.nodes].map(n => n.name).sort(),
|
|
157
|
+
['e', 'f'],
|
|
158
|
+
'should select packages with squat greater than or equal to critical/0 (including exact matches)',
|
|
159
|
+
)
|
|
160
|
+
t.matchSnapshot({
|
|
161
|
+
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
162
|
+
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
163
|
+
})
|
|
164
|
+
},
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
await t.test(
|
|
168
|
+
'less than or equal to comparator with number (unquoted)',
|
|
169
|
+
async t => {
|
|
170
|
+
const res = await squat(getState(':squat(<=0)'))
|
|
171
|
+
t.strictSame(
|
|
172
|
+
[...res.partial.nodes].map(n => n.name).sort(),
|
|
173
|
+
['e'],
|
|
174
|
+
'should select packages with squat less than or equal to critical/0',
|
|
175
|
+
)
|
|
176
|
+
t.matchSnapshot({
|
|
177
|
+
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
178
|
+
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
179
|
+
})
|
|
180
|
+
},
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
await t.test(
|
|
184
|
+
'less than or equal to comparator - exact match (quoted)',
|
|
185
|
+
async t => {
|
|
186
|
+
const res = await squat(getState(':squat("<=2")'))
|
|
187
|
+
t.strictSame(
|
|
188
|
+
[...res.partial.nodes].map(n => n.name).sort(),
|
|
189
|
+
['e', 'f'],
|
|
190
|
+
'should select packages with squat less than or equal to medium/2 (including exact matches)',
|
|
191
|
+
)
|
|
192
|
+
t.matchSnapshot({
|
|
193
|
+
nodes: [...res.partial.nodes].map(n => n.name).sort(),
|
|
194
|
+
edges: [...res.partial.edges].map(e => e.name).sort(),
|
|
195
|
+
})
|
|
196
|
+
},
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
await t.test('empty alerts array', async t => {
|
|
200
|
+
const getCustomState = (
|
|
201
|
+
query: string,
|
|
202
|
+
graph = getSimpleGraph(),
|
|
203
|
+
) => {
|
|
204
|
+
const ast = parse(query)
|
|
205
|
+
const current = ast.first.first
|
|
206
|
+
const state: ParserState = {
|
|
207
|
+
comment: '',
|
|
208
|
+
current,
|
|
209
|
+
initial: {
|
|
210
|
+
edges: new Set(graph.edges.values()),
|
|
211
|
+
nodes: new Set(graph.nodes.values()),
|
|
212
|
+
},
|
|
213
|
+
partial: {
|
|
214
|
+
edges: new Set(graph.edges.values()),
|
|
215
|
+
nodes: new Set(graph.nodes.values()),
|
|
216
|
+
},
|
|
217
|
+
collect: {
|
|
218
|
+
edges: new Set(),
|
|
219
|
+
nodes: new Set(),
|
|
220
|
+
},
|
|
221
|
+
cancellable: async () => {},
|
|
222
|
+
walk: async i => i,
|
|
223
|
+
securityArchive: asSecurityArchiveLike(
|
|
224
|
+
new Map([
|
|
225
|
+
[
|
|
226
|
+
joinDepIDTuple(['registry', '', 'e@1.0.0']),
|
|
227
|
+
{
|
|
228
|
+
id: joinDepIDTuple(['registry', '', 'e@1.0.0']),
|
|
229
|
+
alerts: [{ type: 'didYouMean' }],
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
[
|
|
233
|
+
joinDepIDTuple(['registry', '', 'f@1.0.0']),
|
|
234
|
+
{
|
|
235
|
+
id: joinDepIDTuple(['registry', '', 'f@1.0.0']),
|
|
236
|
+
alerts: [{ type: 'gptDidYouMean' }],
|
|
237
|
+
},
|
|
238
|
+
],
|
|
239
|
+
[
|
|
240
|
+
joinDepIDTuple(['registry', '', 'c@1.0.0']),
|
|
241
|
+
{
|
|
242
|
+
id: joinDepIDTuple(['registry', '', 'c@1.0.0']),
|
|
243
|
+
alerts: [], // Empty alerts array
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
]),
|
|
247
|
+
),
|
|
248
|
+
importers: new Set(graph.importers),
|
|
249
|
+
retries: 0,
|
|
250
|
+
signal: new AbortController().signal,
|
|
251
|
+
specificity: { idCounter: 0, commonCounter: 0 },
|
|
252
|
+
}
|
|
253
|
+
return state
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const res = await squat(getCustomState(':squat(>0)'))
|
|
257
|
+
t.strictSame(
|
|
258
|
+
[...res.partial.nodes].map(n => n.name).sort(),
|
|
259
|
+
['f'],
|
|
260
|
+
'should exclude nodes with empty alerts array',
|
|
261
|
+
)
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
await t.test('node with unknown alert type', async t => {
|
|
265
|
+
const getCustomState = (
|
|
266
|
+
query: string,
|
|
267
|
+
graph = getSimpleGraph(),
|
|
268
|
+
) => {
|
|
269
|
+
const ast = parse(query)
|
|
270
|
+
const current = ast.first.first
|
|
271
|
+
const state: ParserState = {
|
|
272
|
+
comment: '',
|
|
273
|
+
current,
|
|
274
|
+
initial: {
|
|
275
|
+
edges: new Set(graph.edges.values()),
|
|
276
|
+
nodes: new Set(graph.nodes.values()),
|
|
277
|
+
},
|
|
278
|
+
partial: {
|
|
279
|
+
edges: new Set(graph.edges.values()),
|
|
280
|
+
nodes: new Set(graph.nodes.values()),
|
|
281
|
+
},
|
|
282
|
+
collect: {
|
|
283
|
+
edges: new Set(),
|
|
284
|
+
nodes: new Set(),
|
|
285
|
+
},
|
|
286
|
+
cancellable: async () => {},
|
|
287
|
+
walk: async i => i,
|
|
288
|
+
securityArchive: asSecurityArchiveLike(
|
|
289
|
+
new Map([
|
|
290
|
+
[
|
|
291
|
+
joinDepIDTuple(['registry', '', 'e@1.0.0']),
|
|
292
|
+
{
|
|
293
|
+
id: joinDepIDTuple(['registry', '', 'e@1.0.0']),
|
|
294
|
+
alerts: [{ type: 'didYouMean' }],
|
|
295
|
+
},
|
|
296
|
+
],
|
|
297
|
+
[
|
|
298
|
+
joinDepIDTuple(['registry', '', 'f@1.0.0']),
|
|
299
|
+
{
|
|
300
|
+
id: joinDepIDTuple(['registry', '', 'f@1.0.0']),
|
|
301
|
+
alerts: [{ type: 'gptDidYouMean' }],
|
|
302
|
+
},
|
|
303
|
+
],
|
|
304
|
+
[
|
|
305
|
+
joinDepIDTuple(['registry', '', 'c@1.0.0']),
|
|
306
|
+
{
|
|
307
|
+
id: joinDepIDTuple(['registry', '', 'c@1.0.0']),
|
|
308
|
+
// Use an unknown alert type that won't have a matching level
|
|
309
|
+
alerts: [{ type: 'unknownAlertType' }],
|
|
310
|
+
},
|
|
311
|
+
],
|
|
312
|
+
]),
|
|
313
|
+
),
|
|
314
|
+
importers: new Set(graph.importers),
|
|
315
|
+
retries: 0,
|
|
316
|
+
signal: new AbortController().signal,
|
|
317
|
+
specificity: { idCounter: 0, commonCounter: 0 },
|
|
318
|
+
}
|
|
319
|
+
return state
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const res = await squat(getCustomState(':squat(>0)'))
|
|
323
|
+
t.strictSame(
|
|
324
|
+
[...res.partial.nodes].map(n => n.name).sort(),
|
|
325
|
+
['f'],
|
|
326
|
+
'should exclude nodes with unknown alert types',
|
|
327
|
+
)
|
|
328
|
+
})
|
|
329
|
+
|
|
330
|
+
await t.test('pseudo state form works', async t => {
|
|
331
|
+
// :squat without parameters should now work as pseudo state
|
|
332
|
+
const result = await squat(getState(':squat'))
|
|
333
|
+
t.ok(result, 'should not throw an error for pseudo state form')
|
|
334
|
+
})
|
|
335
|
+
})
|
|
336
|
+
|
|
337
|
+
t.test('missing security archive', async t => {
|
|
338
|
+
const getState = (query: string) => {
|
|
339
|
+
const ast = parse(query)
|
|
340
|
+
const current = ast.first.first
|
|
341
|
+
const state: ParserState = {
|
|
342
|
+
comment: '',
|
|
343
|
+
current,
|
|
344
|
+
initial: {
|
|
345
|
+
edges: new Set(),
|
|
346
|
+
nodes: new Set(),
|
|
347
|
+
},
|
|
348
|
+
partial: {
|
|
349
|
+
edges: new Set(),
|
|
350
|
+
nodes: new Set(),
|
|
351
|
+
},
|
|
352
|
+
collect: {
|
|
353
|
+
edges: new Set(),
|
|
354
|
+
nodes: new Set(),
|
|
355
|
+
},
|
|
356
|
+
cancellable: async () => {},
|
|
357
|
+
walk: async i => i,
|
|
358
|
+
securityArchive: undefined,
|
|
359
|
+
importers: new Set(),
|
|
360
|
+
retries: 0,
|
|
361
|
+
signal: new AbortController().signal,
|
|
362
|
+
specificity: { idCounter: 0, commonCounter: 0 },
|
|
363
|
+
}
|
|
364
|
+
return state
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
await t.rejects(
|
|
368
|
+
squat(getState(':squat(critical)')),
|
|
369
|
+
{ message: /Missing security archive/ },
|
|
370
|
+
'should throw an error',
|
|
371
|
+
)
|
|
372
|
+
})
|
|
373
|
+
|
|
374
|
+
t.test('isSquatKind', async t => {
|
|
375
|
+
t.ok(
|
|
376
|
+
isSquatKind('critical'),
|
|
377
|
+
'should return true for valid squat kinds',
|
|
378
|
+
)
|
|
379
|
+
t.notOk(
|
|
380
|
+
isSquatKind('invalid'),
|
|
381
|
+
'should return false for invalid squat kinds',
|
|
382
|
+
)
|
|
383
|
+
})
|
|
384
|
+
|
|
385
|
+
t.test('asSquatKind', async t => {
|
|
386
|
+
t.equal(
|
|
387
|
+
asSquatKind('critical'),
|
|
388
|
+
'critical',
|
|
389
|
+
'should return the squat kind',
|
|
390
|
+
)
|
|
391
|
+
t.throws(
|
|
392
|
+
() => asSquatKind('invalid'),
|
|
393
|
+
{ message: /Expected a valid squat kind/ },
|
|
394
|
+
'should throw an error for invalid squat kinds',
|
|
395
|
+
)
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
t.test('parseInternals', async t => {
|
|
399
|
+
const testParseInternals = (query: string) => {
|
|
400
|
+
const ast = parse(query)
|
|
401
|
+
return parseInternals(
|
|
402
|
+
asPostcssNodeWithChildren(ast.first.first).nodes,
|
|
403
|
+
)
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
t.strictSame(
|
|
407
|
+
testParseInternals(':squat(critical)'),
|
|
408
|
+
{ kind: 'critical', comparator: undefined },
|
|
409
|
+
'should parse exact squat kind',
|
|
410
|
+
)
|
|
411
|
+
|
|
412
|
+
t.strictSame(
|
|
413
|
+
testParseInternals(':squat(>medium)'),
|
|
414
|
+
{ kind: 'medium', comparator: '>' },
|
|
415
|
+
'should parse squat kind with > comparator',
|
|
416
|
+
)
|
|
417
|
+
|
|
418
|
+
t.strictSame(
|
|
419
|
+
testParseInternals(':squat(<critical)'),
|
|
420
|
+
{ kind: 'critical', comparator: '<' },
|
|
421
|
+
'should parse squat kind with < comparator',
|
|
422
|
+
)
|
|
423
|
+
|
|
424
|
+
t.strictSame(
|
|
425
|
+
testParseInternals(':squat(>=2)'),
|
|
426
|
+
{ kind: '2', comparator: '>=' },
|
|
427
|
+
'should parse squat kind with >= comparator',
|
|
428
|
+
)
|
|
429
|
+
|
|
430
|
+
t.strictSame(
|
|
431
|
+
testParseInternals(':squat(<=0)'),
|
|
432
|
+
{ kind: '0', comparator: '<=' },
|
|
433
|
+
'should parse squat kind with <= comparator',
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
t.throws(
|
|
437
|
+
() => testParseInternals(':squat'),
|
|
438
|
+
/Expected a query node/,
|
|
439
|
+
'should throw for missing parameter',
|
|
440
|
+
)
|
|
441
|
+
|
|
442
|
+
t.throws(
|
|
443
|
+
() => testParseInternals(':squat(>invalid)'),
|
|
444
|
+
{
|
|
445
|
+
message: /Expected a valid squat kind for comparison/,
|
|
446
|
+
},
|
|
447
|
+
'should throw for invalid kind with comparator',
|
|
448
|
+
)
|
|
449
|
+
|
|
450
|
+
t.throws(
|
|
451
|
+
() => testParseInternals(':squat(>3)'),
|
|
452
|
+
{
|
|
453
|
+
message: /Expected a valid squat kind for comparison/,
|
|
454
|
+
},
|
|
455
|
+
'should throw for out of range number with comparator',
|
|
456
|
+
)
|
|
457
|
+
})
|
|
458
|
+
|
|
459
|
+
t.test('pseudo state form - :squat without parameters', async t => {
|
|
460
|
+
const getState = (graph = getSimpleGraph()) => {
|
|
461
|
+
const ast = parse(':squat')
|
|
462
|
+
const current = ast.first.first
|
|
463
|
+
const state: ParserState = {
|
|
464
|
+
comment: '',
|
|
465
|
+
current,
|
|
466
|
+
initial: {
|
|
467
|
+
edges: new Set(graph.edges.values()),
|
|
468
|
+
nodes: new Set(graph.nodes.values()),
|
|
469
|
+
},
|
|
470
|
+
partial: {
|
|
471
|
+
edges: new Set(graph.edges.values()),
|
|
472
|
+
nodes: new Set(graph.nodes.values()),
|
|
473
|
+
},
|
|
474
|
+
collect: {
|
|
475
|
+
edges: new Set(),
|
|
476
|
+
nodes: new Set(),
|
|
477
|
+
},
|
|
478
|
+
cancellable: async () => {},
|
|
479
|
+
walk: async i => i,
|
|
480
|
+
securityArchive: asSecurityArchiveLike(
|
|
481
|
+
new Map([
|
|
482
|
+
[
|
|
483
|
+
joinDepIDTuple(['registry', '', 'e@1.0.0']),
|
|
484
|
+
{
|
|
485
|
+
id: joinDepIDTuple(['registry', '', 'e@1.0.0']),
|
|
486
|
+
alerts: [{ type: 'didYouMean' }],
|
|
487
|
+
},
|
|
488
|
+
],
|
|
489
|
+
[
|
|
490
|
+
joinDepIDTuple(['registry', '', 'f@1.0.0']),
|
|
491
|
+
{
|
|
492
|
+
id: joinDepIDTuple(['registry', '', 'f@1.0.0']),
|
|
493
|
+
alerts: [{ type: 'gptDidYouMean' }],
|
|
494
|
+
},
|
|
495
|
+
],
|
|
496
|
+
]),
|
|
497
|
+
),
|
|
498
|
+
importers: new Set(graph.importers),
|
|
499
|
+
retries: 0,
|
|
500
|
+
signal: new AbortController().signal,
|
|
501
|
+
specificity: { idCounter: 0, commonCounter: 0 },
|
|
502
|
+
}
|
|
503
|
+
return state
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
const state = getState()
|
|
507
|
+
const result = await squat(state)
|
|
508
|
+
t.matchSnapshot(
|
|
509
|
+
{
|
|
510
|
+
nodes: [...result.partial.nodes].map(n => n.id),
|
|
511
|
+
edges: [...result.partial.edges].map(
|
|
512
|
+
e => `${e.from.id}->${e.to?.id}`,
|
|
513
|
+
),
|
|
514
|
+
},
|
|
515
|
+
'should match any packages with squat alerts',
|
|
516
|
+
)
|
|
517
|
+
})
|
|
518
|
+
|
|
519
|
+
t.test('error handling for non-query node errors', async t => {
|
|
520
|
+
// Create a state that will trigger a non-"Expected a query node" error
|
|
521
|
+
const ast = parse(':squat(invalid)')
|
|
522
|
+
const current = ast.first.first
|
|
523
|
+
|
|
524
|
+
// Create a corrupted current node that will cause parsing to fail differently
|
|
525
|
+
const corruptedCurrent = {
|
|
526
|
+
...current,
|
|
527
|
+
nodes: [
|
|
528
|
+
{
|
|
529
|
+
type: 'function',
|
|
530
|
+
value: 'squat',
|
|
531
|
+
nodes: null, // This will cause asPostcssNodeWithChildren to fail differently
|
|
532
|
+
},
|
|
533
|
+
],
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
const state: ParserState = {
|
|
537
|
+
comment: '',
|
|
538
|
+
current: corruptedCurrent as any,
|
|
539
|
+
initial: {
|
|
540
|
+
edges: new Set(),
|
|
541
|
+
nodes: new Set(),
|
|
542
|
+
},
|
|
543
|
+
partial: {
|
|
544
|
+
edges: new Set(),
|
|
545
|
+
nodes: new Set(),
|
|
546
|
+
},
|
|
547
|
+
collect: {
|
|
548
|
+
edges: new Set(),
|
|
549
|
+
nodes: new Set(),
|
|
550
|
+
},
|
|
551
|
+
cancellable: async () => {},
|
|
552
|
+
walk: async i => i,
|
|
553
|
+
securityArchive: asSecurityArchiveLike(new Map()),
|
|
554
|
+
importers: new Set(),
|
|
555
|
+
retries: 0,
|
|
556
|
+
signal: new AbortController().signal,
|
|
557
|
+
specificity: { idCounter: 0, commonCounter: 0 },
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
await t.rejects(
|
|
561
|
+
squat(state),
|
|
562
|
+
{ message: /Failed to parse :squat selector/ },
|
|
563
|
+
'should throw error for parsing failures other than missing query node',
|
|
564
|
+
)
|
|
565
|
+
})
|
|
@@ -0,0 +1,98 @@
|
|
|
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 { suspicious } from '../../src/pseudo/suspicious.ts'
|
|
7
|
+
import { parse } from '../../src/parser.ts'
|
|
8
|
+
|
|
9
|
+
t.test('selects packages with a suspicious 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: 'suspiciousStarActivity' }] },
|
|
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 suspicious(getState(':suspicious'))
|
|
50
|
+
t.strictSame(
|
|
51
|
+
[...res.partial.nodes].map(n => n.name),
|
|
52
|
+
['e'],
|
|
53
|
+
'should select only suspicious 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
|
+
suspicious(getState(':suspicious')),
|
|
95
|
+
{ message: /Missing security archive/ },
|
|
96
|
+
'should throw an error',
|
|
97
|
+
)
|
|
98
|
+
})
|