@vzn/vx 0.0.18 → 0.0.21
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/LICENSE +1 -1
- package/README.md +99 -65
- package/package.json +10 -20
- package/src/bin.ts +12 -2
- package/src/cache/archive.ts +120 -18
- package/src/cache/cache.ts +313 -1324
- package/src/cache/chained-cache.ts +0 -8
- package/src/cache/config-evals.ts +89 -0
- package/src/cache/file-hashes.ts +262 -0
- package/src/cache/git-inputs.ts +637 -0
- package/src/cache/index.ts +16 -7
- package/src/cache/inputs.ts +246 -733
- package/src/cache/layer.ts +604 -0
- package/src/cache/layered-cache.ts +12 -17
- package/src/cache/output-index.ts +224 -0
- package/src/cache/policy.ts +84 -0
- package/src/cache/run-history.ts +147 -0
- package/src/cache/zstd.ts +160 -0
- package/src/cli/cache.ts +39 -11
- package/src/cli/completions.ts +104 -0
- package/src/cli/core-alias.ts +25 -0
- package/src/cli/help.ts +64 -36
- package/src/cli/index.ts +54 -15
- package/src/cli/info.ts +120 -91
- package/src/cli/init.ts +75 -0
- package/src/cli/last.ts +38 -6
- package/src/cli/lock.ts +2 -1
- package/src/cli/plan-format.ts +14 -3
- package/src/cli/plugin-commands.ts +15 -8
- package/src/cli/run.ts +84 -302
- package/src/cli/select.ts +332 -0
- package/src/cli/show.ts +144 -69
- package/src/cli/upgrade.ts +2 -1
- package/src/cli/watch.ts +647 -97
- package/src/cli/why.ts +44 -14
- package/src/cli/workspace-config.ts +126 -0
- package/src/config.ts +156 -136
- package/src/exec/env.ts +11 -0
- package/src/exec/executor.ts +11 -26
- package/src/exec/index.ts +6 -2
- package/src/{plugins/local-executor/index.ts → exec/local-executor.ts} +12 -16
- package/src/exec/runner.ts +57 -18
- package/src/exec/sandbox-binds.ts +182 -0
- package/src/exec/sandbox-paths.ts +50 -0
- package/src/exec/sandbox-runtime.ts +582 -370
- package/src/exec/sandbox-violations.ts +280 -0
- package/src/graph/index.ts +1 -9
- package/src/graph/scheduler.ts +158 -203
- package/src/graph/task-graph.ts +2 -2
- package/src/index.ts +97 -102
- package/src/orchestrator/admission.ts +137 -0
- package/src/orchestrator/deferred-outputs.ts +3 -0
- package/src/orchestrator/doctor.ts +255 -0
- package/src/orchestrator/events.ts +42 -8
- package/src/orchestrator/execute-task.ts +145 -554
- package/src/orchestrator/failure-mode.ts +169 -28
- package/src/orchestrator/framed-output.ts +41 -36
- package/src/orchestrator/history.ts +118 -98
- package/src/orchestrator/hit-restore.ts +221 -0
- package/src/orchestrator/index.ts +35 -4
- package/src/orchestrator/lockfile-claim.ts +281 -0
- package/src/orchestrator/logger.ts +13 -22
- package/src/orchestrator/metrics.ts +53 -20
- package/src/orchestrator/miss-save.ts +169 -0
- package/src/orchestrator/options.ts +34 -31
- package/src/orchestrator/persistent.ts +79 -0
- package/src/orchestrator/placement.ts +182 -0
- package/src/orchestrator/plugin-host.ts +195 -38
- package/src/orchestrator/plugin.ts +162 -9
- package/src/orchestrator/prepare.ts +77 -132
- package/src/orchestrator/projects.ts +259 -0
- package/src/orchestrator/remote-prefetch.ts +1 -1
- package/src/orchestrator/run-artifacts.ts +25 -3
- package/src/orchestrator/run-context.ts +1 -1
- package/src/orchestrator/run-records.ts +149 -0
- package/src/orchestrator/run-report.ts +2 -2
- package/src/orchestrator/run.ts +246 -597
- package/src/orchestrator/sandbox-request.ts +243 -0
- package/src/orchestrator/save-lane.ts +47 -0
- package/src/orchestrator/signals.ts +111 -0
- package/src/orchestrator/stable-keys.ts +60 -3
- package/src/orchestrator/status-line.ts +2 -1
- package/src/orchestrator/summary.ts +68 -25
- package/src/orchestrator/task-hash.ts +20 -18
- package/src/orchestrator/task-log-buffer.ts +8 -11
- package/src/orchestrator/telemetry-host.ts +11 -1
- package/src/orchestrator/telemetry.ts +3 -17
- package/src/util/cgroup.ts +160 -0
- package/src/util/edit-distance.ts +49 -0
- package/src/util/index.ts +11 -3
- package/src/util/paths.ts +23 -2
- package/src/util/settle.ts +19 -0
- package/src/util/verbs.ts +39 -0
- package/src/workspace/affected.ts +111 -11
- package/src/workspace/config-cache.ts +11 -2
- package/src/workspace/config-eval.ts +11 -4
- package/src/workspace/config-imports.ts +5 -4
- package/src/workspace/config-schema.ts +837 -0
- package/src/workspace/filter.ts +43 -6
- package/src/workspace/fingerprint.ts +37 -3
- package/src/workspace/index.ts +30 -3
- package/src/workspace/lockfile.ts +12 -7
- package/src/{cli → workspace}/migrate-scripts.ts +26 -19
- package/src/{cli/migrate.ts → workspace/migration.ts} +133 -124
- package/src/workspace/package-graph.ts +98 -28
- package/src/workspace/project-loader.ts +76 -746
- package/src/workspace/workspace.ts +98 -13
- package/plugins/local-cache/index.ts +0 -2
- package/plugins/local-executor/index.ts +0 -2
- package/plugins/schedule-history/index.ts +0 -2
- package/src/cache/cas-backend.ts +0 -115
- package/src/cache/digest.ts +0 -32
- package/src/cli/migrate-emit.ts +0 -21
- package/src/cli/migrate-nx.ts +0 -473
- package/src/cli/migrate-turbo.ts +0 -401
- package/src/cli/prune.ts +0 -291
- package/src/orchestrator/missing-plugin.ts +0 -9
- package/src/orchestrator/resources.ts +0 -45
- package/src/orchestrator/verify.ts +0 -174
- package/src/plugins/local-cache/index.ts +0 -11
- package/src/plugins/schedule-history/index.ts +0 -109
|
@@ -0,0 +1,837 @@
|
|
|
1
|
+
// What a config may SAY — the schema validators for `vx.config.*` and
|
|
2
|
+
// `vx.workspace.*`, split from the loader (which decides HOW a file is
|
|
3
|
+
// evaluated) on 2026-09-10. Every object level refuses a key it does not
|
|
4
|
+
// know (tests/schema-unknown-keys), every message names the level and what
|
|
5
|
+
// it accepts, and `validateProjectConfig` is the one boundary the loader,
|
|
6
|
+
// the lockfile's frozen path and the plugin `project` stage all cross.
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
PLUGIN_FUNCTION_HOOKS,
|
|
10
|
+
PLUGIN_HOOKS,
|
|
11
|
+
PLUGIN_PACKAGE,
|
|
12
|
+
type Plugin,
|
|
13
|
+
type ProjectConfig,
|
|
14
|
+
type WorkspaceConfig,
|
|
15
|
+
} from '../config.js'
|
|
16
|
+
import {
|
|
17
|
+
DISPATCHED_VERBS,
|
|
18
|
+
MAX_TIMEOUT_MS,
|
|
19
|
+
nearest,
|
|
20
|
+
normalizeGlob,
|
|
21
|
+
UserError,
|
|
22
|
+
} from '../util/index.js'
|
|
23
|
+
import { WORKSPACE_FINGERPRINT_FILES } from './fingerprint.js'
|
|
24
|
+
|
|
25
|
+
// Mirrors `WorkspaceConfig` in src/config.ts. Unknown keys are REJECTED for
|
|
26
|
+
// the same reason the task levels reject them: `plugin: [...]` (singular)
|
|
27
|
+
// declared no plugins and ran the workspace bare, `cacheDirectory` left the
|
|
28
|
+
// cache where it was — a config that loads and quietly does nothing it says.
|
|
29
|
+
const WORKSPACE_FIELDS = new Set(['concurrency', 'cacheDir', 'timeout', 'plugins'])
|
|
30
|
+
|
|
31
|
+
export function validateWorkspace(config: WorkspaceConfig, configPath: string): void {
|
|
32
|
+
assertKnownFields(config, WORKSPACE_FIELDS, configPath)
|
|
33
|
+
if (config.concurrency !== undefined) {
|
|
34
|
+
if (
|
|
35
|
+
typeof config.concurrency !== 'number' ||
|
|
36
|
+
!Number.isFinite(config.concurrency) ||
|
|
37
|
+
config.concurrency < 1 ||
|
|
38
|
+
!Number.isInteger(config.concurrency)
|
|
39
|
+
) {
|
|
40
|
+
throw new UserError(`${configPath}: \`concurrency\` must be a positive integer`)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (config.cacheDir !== undefined && typeof config.cacheDir !== 'string') {
|
|
44
|
+
throw new UserError(`${configPath}: \`cacheDir\` must be a string`)
|
|
45
|
+
}
|
|
46
|
+
if (config.timeout !== undefined) {
|
|
47
|
+
if (
|
|
48
|
+
typeof config.timeout !== 'number' ||
|
|
49
|
+
!Number.isInteger(config.timeout) ||
|
|
50
|
+
config.timeout <= 0
|
|
51
|
+
) {
|
|
52
|
+
throw new UserError(`${configPath}: \`timeout\` must be a positive integer (milliseconds)`)
|
|
53
|
+
}
|
|
54
|
+
assertTimeoutInRange(config.timeout, `${configPath}: \`timeout\``)
|
|
55
|
+
}
|
|
56
|
+
if (config.plugins !== undefined) {
|
|
57
|
+
if (!Array.isArray(config.plugins)) {
|
|
58
|
+
throw new UserError(`${configPath}: \`plugins\` must be an array of plugin objects`)
|
|
59
|
+
}
|
|
60
|
+
const verbOwners = new Map<string, string>()
|
|
61
|
+
const fileClaimants = new Map<string, string>()
|
|
62
|
+
for (const [i, p] of config.plugins.entries()) {
|
|
63
|
+
if (p === null || typeof p !== 'object') {
|
|
64
|
+
throw new UserError(`${configPath}: \`plugins[${i}]\` must be an object`)
|
|
65
|
+
}
|
|
66
|
+
// The loose schema's shape (unknown-typed hooks) plus the one retired
|
|
67
|
+
// key this loader still refuses by name.
|
|
68
|
+
const plug = p as Partial<Plugin> & { name?: unknown; backend?: unknown }
|
|
69
|
+
// A plugin's name is its package name and nothing else. `definePlugin`
|
|
70
|
+
// reads it and stamps it under a registry symbol; a plain object, or
|
|
71
|
+
// one whose `name` was overwritten after the stamp, is refused here —
|
|
72
|
+
// the one boundary every plugin crosses.
|
|
73
|
+
const pkg = (p as Record<symbol, unknown>)[PLUGIN_PACKAGE]
|
|
74
|
+
if (typeof pkg !== 'string' || pkg.length === 0) {
|
|
75
|
+
throw new UserError(
|
|
76
|
+
`${configPath}: \`plugins[${i}]\` must come from definePlugin(import.meta, { … }) — a plugin's name is its package name`,
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
if (plug.name !== pkg) {
|
|
80
|
+
throw new UserError(
|
|
81
|
+
`${configPath}: \`plugins[${i}].name\` overrides the package name ('${String(plug.name)}' over '${pkg}') — a plugin's name is its package name; drop the field`,
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
// The whole-run `backend` seam was REMOVED on 2026-08-23 with vx
|
|
85
|
+
// cloud: a run always executes in the `vx run` process. Nothing
|
|
86
|
+
// consults `.backend` any more, so leaving it in `caps` below meant a
|
|
87
|
+
// plugin declaring ONLY `backend` — a third-party one written against
|
|
88
|
+
// the old API, say — validated as "contributes a capability" and was
|
|
89
|
+
// then silently ignored. Refuse it by name and point at the seam that
|
|
90
|
+
// replaced it; a silent no-op is the failure this validation exists
|
|
91
|
+
// to prevent.
|
|
92
|
+
if (plug.backend !== undefined) {
|
|
93
|
+
throw new UserError(
|
|
94
|
+
`${configPath}: \`plugins[${i}].backend\` is no longer a capability — the whole-run ` +
|
|
95
|
+
`backend seam was removed in 2026-08. Use \`executor\` to change where a single ` +
|
|
96
|
+
`task's command runs (see docs/architecture.md § plugin capabilities).`,
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
for (const cap of PLUGIN_FUNCTION_HOOKS) {
|
|
100
|
+
if (plug[cap] !== undefined && typeof plug[cap] !== 'function') {
|
|
101
|
+
throw new UserError(`${configPath}: \`plugins[${i}].${cap}\` must be a function`)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (plug.commands !== undefined) {
|
|
105
|
+
if (plug.commands === null || typeof plug.commands !== 'object') {
|
|
106
|
+
throw new UserError(`${configPath}: \`plugins[${i}].commands\` must be an object`)
|
|
107
|
+
}
|
|
108
|
+
for (const [verb, cmd] of Object.entries(plug.commands as Record<string, unknown>)) {
|
|
109
|
+
const c = cmd as { description?: unknown; run?: unknown } | null
|
|
110
|
+
if (
|
|
111
|
+
c === null ||
|
|
112
|
+
typeof c !== 'object' ||
|
|
113
|
+
typeof c.run !== 'function' ||
|
|
114
|
+
typeof c.description !== 'string'
|
|
115
|
+
) {
|
|
116
|
+
throw new UserError(
|
|
117
|
+
`${configPath}: \`plugins[${i}].commands.${verb}\` must be { description: string, run: function }`,
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
// A verb the dispatcher would never reach is refused, not left
|
|
121
|
+
// dead: core verbs are matched first, and two plugins on one verb
|
|
122
|
+
// would run the first declared and hide the second. Here, in the
|
|
123
|
+
// schema, so every loader of the file — a run, a reading verb, the
|
|
124
|
+
// plugin-verb lookup — refuses it the same way.
|
|
125
|
+
if (DISPATCHED_VERBS.includes(verb)) {
|
|
126
|
+
throw new UserError(
|
|
127
|
+
`${configPath}: plugin '${plug.name}' declares command '${verb}', a core verb — core verbs cannot be shadowed`,
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
const owner = verbOwners.get(verb)
|
|
131
|
+
if (owner !== undefined) {
|
|
132
|
+
throw new UserError(
|
|
133
|
+
`${configPath}: plugins '${owner}' and '${plug.name}' both declare command '${verb}' — a verb has one owner`,
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
verbOwners.set(verb, plug.name)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (plug.fingerprint !== undefined) {
|
|
140
|
+
const claim = plug.fingerprint as { files?: unknown; affected?: unknown } | null
|
|
141
|
+
if (
|
|
142
|
+
claim === null ||
|
|
143
|
+
typeof claim !== 'object' ||
|
|
144
|
+
!Array.isArray(claim.files) ||
|
|
145
|
+
claim.files.length === 0 ||
|
|
146
|
+
typeof claim.affected !== 'function'
|
|
147
|
+
) {
|
|
148
|
+
throw new UserError(
|
|
149
|
+
`${configPath}: \`plugins[${i}].fingerprint\` must be { files: [name, …], affected: function }`,
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
for (const file of claim.files as unknown[]) {
|
|
153
|
+
// A name core never folds has nothing to take out; claiming it
|
|
154
|
+
// would read as covered while the plugin's material is all there is.
|
|
155
|
+
if (typeof file !== 'string' || !WORKSPACE_FINGERPRINT_FILES.includes(file)) {
|
|
156
|
+
throw new UserError(
|
|
157
|
+
`${configPath}: plugin '${plug.name}' claims fingerprint file ${JSON.stringify(file)}, which core does not fold — one of ${WORKSPACE_FINGERPRINT_FILES.join(', ')}`,
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
const owner = fileClaimants.get(file)
|
|
161
|
+
if (owner !== undefined) {
|
|
162
|
+
throw new UserError(
|
|
163
|
+
`${configPath}: plugins '${owner}' and '${plug.name}' both claim fingerprint file '${file}' — a file has one claimant`,
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
fileClaimants.set(file, plug.name)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// A plugin must contribute at least one capability or lifecycle hook
|
|
170
|
+
// — an empty `{ name }` object is a no-op authoring mistake.
|
|
171
|
+
if (PLUGIN_HOOKS.every((hook) => plug[hook] === undefined)) {
|
|
172
|
+
throw new UserError(
|
|
173
|
+
`${configPath}: \`plugins[${i}]\` must contribute at least one of ${PLUGIN_HOOKS.join('/')}`,
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Runtime validation for the user-authored config. TypeScript checks
|
|
182
|
+
* shape at edit-time, but `vx run` may load configs that were never
|
|
183
|
+
* typechecked (plain .js, or TS with errors ignored). Catch the worst
|
|
184
|
+
* shape problems early with a clear message rather than letting them
|
|
185
|
+
* crash deeper in the orchestrator. Also applied to configs loaded
|
|
186
|
+
* back from `vx-lock.json` (a hand-editable file — same boundary).
|
|
187
|
+
*/
|
|
188
|
+
export function validateProjectConfig(config: ProjectConfig, configPath: string): void {
|
|
189
|
+
// The top level too: `task:` (singular) loaded as a project with no
|
|
190
|
+
// tasks and every request against it said "no projects declare".
|
|
191
|
+
assertKnownFields(config, PROJECT_FIELDS, configPath)
|
|
192
|
+
const tasks = config.tasks
|
|
193
|
+
if (tasks === undefined) return
|
|
194
|
+
if (typeof tasks !== 'object' || tasks === null || Array.isArray(tasks)) {
|
|
195
|
+
// An ARRAY of task objects reads as valid to `typeof`, and
|
|
196
|
+
// `Object.entries` then yields a task literally named "0" — a config
|
|
197
|
+
// that loads, runs nothing the author asked for, and never says why.
|
|
198
|
+
throw new UserError(`${configPath}: \`tasks\` must be an object keyed by task name`)
|
|
199
|
+
}
|
|
200
|
+
for (const [name, task] of Object.entries(tasks)) {
|
|
201
|
+
const where = `${configPath}: tasks.${name}`
|
|
202
|
+
if (!task || typeof task !== 'object') {
|
|
203
|
+
throw new UserError(`${where} must be an object`)
|
|
204
|
+
}
|
|
205
|
+
assertKnownFields(task, TASK_FIELDS, where)
|
|
206
|
+
const exec = (task as { exec?: unknown }).exec
|
|
207
|
+
const dependsOn = (task as { dependsOn?: unknown }).dependsOn
|
|
208
|
+
const cache = (task as { cache?: unknown }).cache
|
|
209
|
+
if (exec !== undefined) {
|
|
210
|
+
if (typeof exec !== 'object' || exec === null) {
|
|
211
|
+
throw new UserError(`${where}.exec must be an object with a \`command\` string`)
|
|
212
|
+
}
|
|
213
|
+
assertKnownFields(exec, EXEC_FIELDS, `${where}.exec`)
|
|
214
|
+
const sandbox = (exec as { sandbox?: unknown }).sandbox
|
|
215
|
+
if (sandbox !== undefined) validateSandbox(sandbox, `${where}.exec`)
|
|
216
|
+
const command = (exec as { command?: unknown }).command
|
|
217
|
+
if (typeof command !== 'string' || command.length === 0) {
|
|
218
|
+
throw new UserError(`${where}.exec.command must be a non-empty string`)
|
|
219
|
+
}
|
|
220
|
+
const timeout = (exec as { timeout?: unknown }).timeout
|
|
221
|
+
if (timeout !== undefined) {
|
|
222
|
+
if (typeof timeout !== 'number' || !Number.isInteger(timeout) || timeout <= 0) {
|
|
223
|
+
throw new UserError(`${where}.exec.timeout must be a positive integer (milliseconds)`)
|
|
224
|
+
}
|
|
225
|
+
assertTimeoutInRange(timeout, `${where}.exec.timeout`)
|
|
226
|
+
}
|
|
227
|
+
const retries = (exec as { retries?: unknown }).retries
|
|
228
|
+
if (retries !== undefined) {
|
|
229
|
+
if (typeof retries !== 'number' || !Number.isInteger(retries) || retries < 0) {
|
|
230
|
+
throw new UserError(`${where}.exec.retries must be a non-negative integer`)
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const remote = (exec as { remote?: unknown }).remote
|
|
234
|
+
if (remote !== undefined && typeof remote !== 'boolean' && remote !== 'only') {
|
|
235
|
+
throw new UserError(`${where}.exec.remote must be a boolean or 'only' (or omitted)`)
|
|
236
|
+
}
|
|
237
|
+
const env = (exec as { env?: unknown }).env
|
|
238
|
+
if (env !== undefined) {
|
|
239
|
+
if (typeof env !== 'object' || env === null) {
|
|
240
|
+
throw new UserError(`${where}.exec.env must be an object (or omitted)`)
|
|
241
|
+
}
|
|
242
|
+
// `env: { set: {...} }` loaded and defined nothing — the one level
|
|
243
|
+
// without this check until 2026-09-10 (tests/schema-unknown-keys).
|
|
244
|
+
assertKnownFields(env, ENV_FIELDS, `${where}.exec.env`)
|
|
245
|
+
const passThrough = (env as { passThrough?: unknown }).passThrough
|
|
246
|
+
if (passThrough !== undefined) {
|
|
247
|
+
// A non-array here reaches `buildIsolatedEnv`'s `for (const name of
|
|
248
|
+
// passThrough)` — a number throws "not iterable" mid-run, a string
|
|
249
|
+
// silently char-iterates. Fail loud at load with a config pointer.
|
|
250
|
+
if (
|
|
251
|
+
!Array.isArray(passThrough) ||
|
|
252
|
+
passThrough.some((n) => typeof n !== 'string' || n.length === 0)
|
|
253
|
+
) {
|
|
254
|
+
throw new UserError(
|
|
255
|
+
`${where}.exec.env.passThrough must be an array of non-empty env var names`,
|
|
256
|
+
)
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
const define = (env as { define?: unknown }).define
|
|
260
|
+
if (define !== undefined) {
|
|
261
|
+
if (typeof define !== 'object' || define === null || Array.isArray(define)) {
|
|
262
|
+
throw new UserError(
|
|
263
|
+
`${where}.exec.env.define must be an object of name:value string pairs`,
|
|
264
|
+
)
|
|
265
|
+
}
|
|
266
|
+
for (const [k, val] of Object.entries(define as Record<string, unknown>)) {
|
|
267
|
+
if (typeof val !== 'string') {
|
|
268
|
+
throw new UserError(`${where}.exec.env.define.${k} must be a string`)
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const persistent = (exec as { persistent?: unknown }).persistent
|
|
274
|
+
if (persistent !== undefined) {
|
|
275
|
+
if (typeof persistent !== 'object' || persistent === null) {
|
|
276
|
+
throw new UserError(`${where}.exec.persistent must be an object (or omitted)`)
|
|
277
|
+
}
|
|
278
|
+
// The one nested object that had no unknown-key check while every
|
|
279
|
+
// sibling did — and the failure it let through is the quiet kind:
|
|
280
|
+
// `readWhen` (typo) leaves `readyWhen` undefined, so the task is
|
|
281
|
+
// ready the moment it spawns instead of when its server actually
|
|
282
|
+
// listens, and the dependents that start too early fail in a way
|
|
283
|
+
// that points at the user's code rather than at their config.
|
|
284
|
+
|
|
285
|
+
assertKnownFields(persistent, PERSISTENT_FIELDS, `${where}.exec.persistent`)
|
|
286
|
+
const readyWhen = (persistent as { readyWhen?: unknown }).readyWhen
|
|
287
|
+
if (readyWhen !== undefined && typeof readyWhen !== 'string') {
|
|
288
|
+
throw new UserError(`${where}.exec.persistent.readyWhen must be a string regex`)
|
|
289
|
+
}
|
|
290
|
+
if (cache !== undefined) {
|
|
291
|
+
throw new UserError(
|
|
292
|
+
`${where}: \`cache\` is not allowed on a persistent task — persistent tasks ` +
|
|
293
|
+
`don't terminate, so there's no exit to cache`,
|
|
294
|
+
)
|
|
295
|
+
}
|
|
296
|
+
if (retries !== undefined) {
|
|
297
|
+
throw new UserError(
|
|
298
|
+
`${where}: \`retries\` is not allowed on a persistent task — persistent tasks ` +
|
|
299
|
+
`don't terminate, so there's no failed exit to retry`,
|
|
300
|
+
)
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
} else {
|
|
304
|
+
// Group task: no exec, just dependencies. Must declare something to
|
|
305
|
+
// depend on, otherwise the task is a literal no-op with nothing to
|
|
306
|
+
// chain (almost certainly a config mistake).
|
|
307
|
+
if (dependsOn === undefined) {
|
|
308
|
+
throw new UserError(
|
|
309
|
+
`${where}: a task with no \`exec\` must declare \`dependsOn\` ` +
|
|
310
|
+
`(group tasks exist to chain dependencies)`,
|
|
311
|
+
)
|
|
312
|
+
}
|
|
313
|
+
if (cache !== undefined) {
|
|
314
|
+
throw new UserError(
|
|
315
|
+
`${where}: \`cache\` requires \`exec\` — a group task has nothing to cache`,
|
|
316
|
+
)
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
const description = (task as { description?: unknown }).description
|
|
320
|
+
if (description !== undefined && typeof description !== 'string') {
|
|
321
|
+
throw new UserError(`${where}.description must be a string`)
|
|
322
|
+
}
|
|
323
|
+
if (dependsOn !== undefined) {
|
|
324
|
+
if (!Array.isArray(dependsOn) || dependsOn.some((s) => typeof s !== 'string')) {
|
|
325
|
+
throw new UserError(
|
|
326
|
+
`${where}.dependsOn must be an array of strings ` +
|
|
327
|
+
`(Turbo/Nx micro-syntax: 'name', '^name', 'pkg#name')`,
|
|
328
|
+
)
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (cache !== undefined) {
|
|
332
|
+
if (typeof cache !== 'object' || cache === null) {
|
|
333
|
+
throw new UserError(`${where}.cache must be an object when present`)
|
|
334
|
+
}
|
|
335
|
+
assertKnownFields(cache, CACHE_FIELDS, `${where}.cache`)
|
|
336
|
+
const inputs = (cache as { inputs?: unknown }).inputs
|
|
337
|
+
const outputs = (cache as { outputs?: unknown }).outputs
|
|
338
|
+
if (!inputs || typeof inputs !== 'object') {
|
|
339
|
+
throw new UserError(`${where}.cache.inputs is required when \`cache\` is set`)
|
|
340
|
+
}
|
|
341
|
+
assertKnownFields(inputs, CACHE_INPUT_FIELDS, `${where}.cache.inputs`)
|
|
342
|
+
if (!Array.isArray((inputs as { files?: unknown }).files)) {
|
|
343
|
+
throw new UserError(`${where}.cache.inputs.files must be an array of glob strings`)
|
|
344
|
+
}
|
|
345
|
+
const envList = (inputs as { env?: unknown }).env
|
|
346
|
+
if (envList !== undefined) {
|
|
347
|
+
if (
|
|
348
|
+
!Array.isArray(envList) ||
|
|
349
|
+
envList.some((s) => typeof s !== 'string' || s.length === 0)
|
|
350
|
+
) {
|
|
351
|
+
throw new UserError(
|
|
352
|
+
`${where}.cache.inputs.env must be an array of non-empty env var names`,
|
|
353
|
+
)
|
|
354
|
+
}
|
|
355
|
+
for (const name of envList as string[]) {
|
|
356
|
+
// Reject wildcards explicitly so users don't silently miss
|
|
357
|
+
// env vars they thought they were tracking. Turbo supports
|
|
358
|
+
// `VERCEL_*` expansion; vx requires the literal names. If
|
|
359
|
+
// we add expansion later it'll be additive — until then,
|
|
360
|
+
// surface the footgun instead of returning '' for the
|
|
361
|
+
// literal env name `'VERCEL_*'`.
|
|
362
|
+
if (/[*?[\]]/.test(name)) {
|
|
363
|
+
throw new UserError(
|
|
364
|
+
`${where}.cache.inputs.env: wildcards in env names are not supported ` +
|
|
365
|
+
`(got "${name}") — list explicit env var names instead`,
|
|
366
|
+
)
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (!outputs || typeof outputs !== 'object') {
|
|
371
|
+
throw new UserError(`${where}.cache.outputs is required when \`cache\` is set`)
|
|
372
|
+
}
|
|
373
|
+
assertKnownFields(outputs, CACHE_OUTPUT_FIELDS, `${where}.cache.outputs`)
|
|
374
|
+
const outFiles = (outputs as { files?: unknown }).files
|
|
375
|
+
if (!Array.isArray(outFiles)) {
|
|
376
|
+
throw new UserError(`${where}.cache.outputs.files must be an array of glob strings`)
|
|
377
|
+
}
|
|
378
|
+
// Reject zero-length strings and absolute paths up front.
|
|
379
|
+
// Both reach `resolveOutputs` as undefined behavior; the error
|
|
380
|
+
// surfaces deep inside the glob resolver with no line pointing
|
|
381
|
+
// at the user's config. Fail loud at load time.
|
|
382
|
+
for (const g of outFiles as unknown[]) {
|
|
383
|
+
if (typeof g !== 'string' || g.length === 0) {
|
|
384
|
+
throw new UserError(`${where}.cache.outputs.files must be an array of non-empty strings`)
|
|
385
|
+
}
|
|
386
|
+
if (g.startsWith('/')) {
|
|
387
|
+
throw new UserError(
|
|
388
|
+
`${where}.cache.outputs.files: absolute paths are not allowed (got "${g}") — ` +
|
|
389
|
+
`outputs must be project-relative globs`,
|
|
390
|
+
)
|
|
391
|
+
}
|
|
392
|
+
if (hasParentSegment(g)) {
|
|
393
|
+
throw new UserError(
|
|
394
|
+
`${where}.cache.outputs.files: '..' path segments are not allowed (got "${g}") — ` +
|
|
395
|
+
`outputs must stay within the project (a glob that escapes the project dir would ` +
|
|
396
|
+
`let cleanOutputs delete files outside it)`,
|
|
397
|
+
)
|
|
398
|
+
}
|
|
399
|
+
if (namesDirItself(g)) {
|
|
400
|
+
throw new UserError(
|
|
401
|
+
`${where}.cache.outputs.files: "${g}" names the project directory itself and selects nothing — use "**" for everything under it`,
|
|
402
|
+
)
|
|
403
|
+
}
|
|
404
|
+
if (g.startsWith('!')) {
|
|
405
|
+
throw new UserError(
|
|
406
|
+
`${where}.cache.outputs.files: negation is not supported (got "${g}") — ` +
|
|
407
|
+
`unlike inputs, output globs are never split on '!', so this is read as a literal ` +
|
|
408
|
+
`path beginning with '!' and matches nothing. List the outputs you DO produce.`,
|
|
409
|
+
)
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
// Same for inputs.files.
|
|
413
|
+
for (const g of (inputs as { files: unknown[] }).files) {
|
|
414
|
+
if (typeof g !== 'string' || g.length === 0) {
|
|
415
|
+
throw new UserError(`${where}.cache.inputs.files must be an array of non-empty strings`)
|
|
416
|
+
}
|
|
417
|
+
if (g.startsWith('/')) {
|
|
418
|
+
throw new UserError(
|
|
419
|
+
`${where}.cache.inputs.files: absolute paths are not allowed (got "${g}") — ` +
|
|
420
|
+
`inputs must be project-relative globs`,
|
|
421
|
+
)
|
|
422
|
+
}
|
|
423
|
+
if (hasParentSegment(g)) {
|
|
424
|
+
throw new UserError(
|
|
425
|
+
`${where}.cache.inputs.files: '..' path segments are not allowed (got "${g}") — ` +
|
|
426
|
+
`inputs must be project-relative (a '..' glob silently matches nothing; ` +
|
|
427
|
+
`use cache.inputs.workspaceFiles for workspace-root-relative inputs)`,
|
|
428
|
+
)
|
|
429
|
+
}
|
|
430
|
+
if (namesDirItself(g)) {
|
|
431
|
+
throw new UserError(
|
|
432
|
+
`${where}.cache.inputs.files: "${g}" names the project directory itself and selects nothing — use "**" for everything under it`,
|
|
433
|
+
)
|
|
434
|
+
}
|
|
435
|
+
assertNotDoubleNegated(g, `${where}.cache.inputs.files`)
|
|
436
|
+
}
|
|
437
|
+
// A list of ONLY negations selects nothing at all. `resolveFiles`
|
|
438
|
+
// builds the file set from the POSITIVE globs and uses the `!` entries
|
|
439
|
+
// purely to subtract, so with no positive pattern it returns `[]` — the
|
|
440
|
+
// task folds ZERO file inputs and its key stops moving with its source,
|
|
441
|
+
// which is a stale hit waiting to happen.
|
|
442
|
+
//
|
|
443
|
+
// Every gitignore-trained reader parses `['!**/*.spec.ts']` as
|
|
444
|
+
// "everything except specs", and Turbo makes exactly this a hard config
|
|
445
|
+
// error for the same reason. Refusing costs nothing: such a config was
|
|
446
|
+
// already silently broken, so no working key changes.
|
|
447
|
+
assertNotNegationOnly((inputs as { files: string[] }).files, `${where}.cache.inputs.files`)
|
|
448
|
+
// The only CacheInputs field that reached the run unvalidated: a
|
|
449
|
+
// non-string entry crashes deep in `filterUpstreamHashes` /
|
|
450
|
+
// `parseDependencySpec` with a raw TypeError naming neither the task
|
|
451
|
+
// nor the config. Entry SYNTAX is already checked downstream (a
|
|
452
|
+
// `DependencySpecError` becomes a UserError naming the task) — this
|
|
453
|
+
// only pins the shape.
|
|
454
|
+
const taskFilters = (inputs as { tasks?: unknown }).tasks
|
|
455
|
+
if (taskFilters !== undefined) {
|
|
456
|
+
if (
|
|
457
|
+
!Array.isArray(taskFilters) ||
|
|
458
|
+
taskFilters.some((s) => typeof s !== 'string' || s.length === 0)
|
|
459
|
+
) {
|
|
460
|
+
throw new UserError(
|
|
461
|
+
`${where}.cache.inputs.tasks must be an array of non-empty strings ` +
|
|
462
|
+
`(Turbo/Nx micro-syntax: 'name', '^name', 'pkg#name', '*', '^*', '!name')`,
|
|
463
|
+
)
|
|
464
|
+
}
|
|
465
|
+
assertFilterNamesDeclaredDeps(taskFilters, task.dependsOn, where)
|
|
466
|
+
}
|
|
467
|
+
for (const field of ['runtime', 'workspaceRuntime'] as const) {
|
|
468
|
+
const list = (inputs as Record<string, unknown>)[field]
|
|
469
|
+
if (list !== undefined) {
|
|
470
|
+
if (!Array.isArray(list) || list.some((s) => typeof s !== 'string' || s.length === 0)) {
|
|
471
|
+
throw new UserError(
|
|
472
|
+
`${where}.cache.inputs.${field} must be an array of non-empty shell command strings`,
|
|
473
|
+
)
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
// workspaceFiles mirror the files validation: non-empty strings,
|
|
478
|
+
// never absolute (they're workspace-root-relative by definition).
|
|
479
|
+
const wsInputs = (inputs as { workspaceFiles?: unknown }).workspaceFiles
|
|
480
|
+
if (wsInputs !== undefined) {
|
|
481
|
+
validateWorkspaceGlobs(wsInputs, `${where}.cache.inputs.workspaceFiles`, true)
|
|
482
|
+
}
|
|
483
|
+
const wsOutputs = (outputs as { workspaceFiles?: unknown }).workspaceFiles
|
|
484
|
+
if (wsOutputs !== undefined) {
|
|
485
|
+
validateWorkspaceGlobs(wsOutputs, `${where}.cache.outputs.workspaceFiles`, false)
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
// Known fields per config level, mirroring the interfaces in src/config.ts.
|
|
492
|
+
// Unknown keys are REJECTED rather than silently dropped: a typo in a
|
|
493
|
+
// cache-key field (`workspaceFile`, `task`, `timeoutMs`) is otherwise
|
|
494
|
+
// discarded, so the task hashes as if the field were never written and vx
|
|
495
|
+
// serves a stale artifact — the same reasoning `sandbox` already
|
|
496
|
+
// encodes. A new field must be added here deliberately.
|
|
497
|
+
const PROJECT_FIELDS = new Set(['tasks'])
|
|
498
|
+
const TASK_FIELDS = new Set(['description', 'exec', 'dependsOn', 'cache'])
|
|
499
|
+
const EXEC_FIELDS = new Set([
|
|
500
|
+
'command',
|
|
501
|
+
'env',
|
|
502
|
+
'timeout',
|
|
503
|
+
'retries',
|
|
504
|
+
'persistent',
|
|
505
|
+
'remote',
|
|
506
|
+
'sandbox',
|
|
507
|
+
])
|
|
508
|
+
const PERSISTENT_FIELDS = new Set(['readyWhen'])
|
|
509
|
+
const ENV_FIELDS = new Set(['passThrough', 'define'])
|
|
510
|
+
const CACHE_FIELDS = new Set(['inputs', 'outputs'])
|
|
511
|
+
const CACHE_INPUT_FIELDS = new Set([
|
|
512
|
+
'files',
|
|
513
|
+
'workspaceFiles',
|
|
514
|
+
'env',
|
|
515
|
+
'tasks',
|
|
516
|
+
'runtime',
|
|
517
|
+
'workspaceRuntime',
|
|
518
|
+
])
|
|
519
|
+
const CACHE_OUTPUT_FIELDS = new Set(['files', 'workspaceFiles'])
|
|
520
|
+
|
|
521
|
+
function assertKnownFields(value: object, allowed: ReadonlySet<string>, where: string): void {
|
|
522
|
+
for (const key of Object.keys(value)) {
|
|
523
|
+
if (!allowed.has(key)) {
|
|
524
|
+
// The nearest accepted spelling first: the list says what the level
|
|
525
|
+
// takes, the hint says which one was meant.
|
|
526
|
+
const near = nearest(key, allowed)
|
|
527
|
+
throw new UserError(
|
|
528
|
+
`${where} has unknown field "${key}" (allowed: ${[...allowed].sort().join(', ')})` +
|
|
529
|
+
(near === undefined ? '' : ` — did you mean ${near}?`),
|
|
530
|
+
)
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* A millisecond delay past `MAX_TIMEOUT_MS` does not mean "effectively never" —
|
|
537
|
+
* `setTimeout` silently reduces it to 1 ms, so the task is killed the instant it
|
|
538
|
+
* spawns and reported `failed`. That is the exact inverse of the declaration,
|
|
539
|
+
* and the only clue is a `TimeoutOverflowWarning` on stderr.
|
|
540
|
+
*
|
|
541
|
+
* Refused rather than clamped, because this is a value the user WROTE and reads
|
|
542
|
+
* back: silently substituting ~24.8 days for the 317 years they asked for would
|
|
543
|
+
* trade one surprise for a quieter one. Costs nothing — such a config never
|
|
544
|
+
* worked, it killed the task in milliseconds, so refusing reports a state that
|
|
545
|
+
* already existed.
|
|
546
|
+
*/
|
|
547
|
+
function assertTimeoutInRange(ms: number, where: string): void {
|
|
548
|
+
if (ms <= MAX_TIMEOUT_MS) return
|
|
549
|
+
throw new UserError(
|
|
550
|
+
`${where}: ${ms} ms exceeds the maximum timer delay (${MAX_TIMEOUT_MS} ms, ~24.8 days). ` +
|
|
551
|
+
`Timers larger than this do NOT mean "no limit" — the platform reduces them to 1 ms, so ` +
|
|
552
|
+
`the task would be killed the moment it starts. Omit \`timeout\` for no limit.`,
|
|
553
|
+
)
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* True when a glob contains a `..` PATH SEGMENT (`../x`, `a/../b`, `x/..`), which
|
|
558
|
+
* escapes its base dir — `foo..bar` / `a..b` inside a filename are fine. A
|
|
559
|
+
* leading negation marker is stripped first so `!../x` is caught too. Used to
|
|
560
|
+
* keep output globs inside the project and workspace globs inside the workspace
|
|
561
|
+
* root: `cleanOutputs` rm()s resolved output paths before every run, and
|
|
562
|
+
* `Bun.Glob.scan` follows `..` out of its cwd, so a `..` glob is a data-loss
|
|
563
|
+
* vector (delete files outside the project / above the repo root).
|
|
564
|
+
*/
|
|
565
|
+
/**
|
|
566
|
+
* `.`, `./`, `././` (with or without a `!`) name the directory itself, which
|
|
567
|
+
* no matcher expands: the entry selected nothing and said so nowhere.
|
|
568
|
+
* `./src/**` is fine — the resolver strips the `./` (`normalizeGlob`).
|
|
569
|
+
*/
|
|
570
|
+
function namesDirItself(glob: string): boolean {
|
|
571
|
+
const g = normalizeGlob(glob.startsWith('!') ? glob.slice(1) : glob)
|
|
572
|
+
return g === '' || g === '/'
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function hasParentSegment(glob: string): boolean {
|
|
576
|
+
const g = glob.startsWith('!') ? glob.slice(1) : glob
|
|
577
|
+
return g.split('/').some((seg) => seg === '..')
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* `!!x` INVERTS the input set instead of double-negating it.
|
|
582
|
+
*
|
|
583
|
+
* The resolver strips ONE `!` and hands the remainder to `new Bun.Glob()` —
|
|
584
|
+
* which applies its OWN leading-`!` negation. So `!!vendor/**` becomes the
|
|
585
|
+
* exclude glob `Glob('!vendor/**')`, and that matches every path EXCEPT
|
|
586
|
+
* vendor's. Everything else is therefore excluded and the task folds ONLY
|
|
587
|
+
* `vendor/**`: its own source drops out of the cache key entirely, which is a
|
|
588
|
+
* permanent stale hit.
|
|
589
|
+
*
|
|
590
|
+
* Neither neighbouring guard catches it — `assertNotNegationOnly` sees the
|
|
591
|
+
* positive glob and is satisfied, and `hasParentSegment` strips one `!` before
|
|
592
|
+
* splitting so `!!../x` shows no `..` segment.
|
|
593
|
+
*
|
|
594
|
+
* Refused rather than reinterpreted: `!!` has no coherent meaning here.
|
|
595
|
+
* Negation in vx is subtraction from what a positive glob matched, not
|
|
596
|
+
* gitignore's ordered re-inclusion, so there is nothing for a second `!` to
|
|
597
|
+
* undo. Costs nothing to refuse — such a config already folds the wrong set,
|
|
598
|
+
* so no working cache key changes.
|
|
599
|
+
*/
|
|
600
|
+
function assertNotDoubleNegated(glob: string, where: string): void {
|
|
601
|
+
if (!glob.startsWith('!!')) return
|
|
602
|
+
const inner = glob.slice(2)
|
|
603
|
+
throw new UserError(
|
|
604
|
+
`${where}: '!!' is not a double negation (got "${glob}") — it INVERTS the set. ` +
|
|
605
|
+
`One '!' is stripped and the remainder is compiled as a glob, which applies its own ` +
|
|
606
|
+
`leading-'!' negation, so this excludes everything EXCEPT ${JSON.stringify(inner)} and ` +
|
|
607
|
+
`the task folds only that. Use ${JSON.stringify(`!${inner}`)} to subtract it, or ` +
|
|
608
|
+
`${JSON.stringify(inner)} to include it.`,
|
|
609
|
+
)
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* An exact `cache.inputs.tasks` entry that no `dependsOn` entry names would
|
|
614
|
+
* match nothing at hash time and fold no upstream hash — the task silently
|
|
615
|
+
* decoupled from its dependencies, which is a stale hit waiting for the
|
|
616
|
+
* next upstream change. `['buidl']` for `['build']` is the shape. Patterns,
|
|
617
|
+
* wildcards and negations stay silent (a preset-spread pattern legitimately
|
|
618
|
+
* matches nothing in some projects; excluding what is absent is harmless);
|
|
619
|
+
* an exact name must be named by some `dependsOn` entry, exactly or by that
|
|
620
|
+
* entry's own `*` pattern. `[]` is the explicit way to decouple.
|
|
621
|
+
*/
|
|
622
|
+
function assertFilterNamesDeclaredDeps(
|
|
623
|
+
filters: readonly string[],
|
|
624
|
+
dependsOn: readonly string[] | undefined,
|
|
625
|
+
where: string,
|
|
626
|
+
): void {
|
|
627
|
+
const taskHalf = (spec: string): string => {
|
|
628
|
+
const body = spec.startsWith('^') ? spec.slice(1) : spec
|
|
629
|
+
const hash = body.lastIndexOf('#')
|
|
630
|
+
return hash === -1 ? body : body.slice(hash + 1)
|
|
631
|
+
}
|
|
632
|
+
const declared = (dependsOn ?? []).map(taskHalf)
|
|
633
|
+
const named = (task: string): boolean =>
|
|
634
|
+
declared.some((d) => (d.includes('*') ? taskPatternRegExp(d).test(task) : d === task))
|
|
635
|
+
for (const raw of filters) {
|
|
636
|
+
if (raw.startsWith('!') || raw === '*' || raw === '^*') continue
|
|
637
|
+
const task = taskHalf(raw)
|
|
638
|
+
if (task.length === 0 || task.includes('*') || named(task)) continue
|
|
639
|
+
throw new UserError(
|
|
640
|
+
`${where}.cache.inputs.tasks: "${raw}" names no task in ${where}.dependsOn ` +
|
|
641
|
+
`(${declared.length === 0 ? 'none declared' : dependsOn!.map((d) => `'${d}'`).join(', ')}) — ` +
|
|
642
|
+
`it would match nothing and fold no upstream hash, decoupling the task from its ` +
|
|
643
|
+
`dependencies. Fix the name, or use [] to decouple on purpose.`,
|
|
644
|
+
)
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/** The graph's `*`-only task glob (`compileTaskPattern`), mirrored: `*` is the sole metacharacter. */
|
|
649
|
+
function taskPatternRegExp(pattern: string): RegExp {
|
|
650
|
+
const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*')
|
|
651
|
+
return new RegExp(`^${escaped}$`)
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* Refuse a non-empty glob list made up ENTIRELY of negations.
|
|
656
|
+
*
|
|
657
|
+
* The resolvers build their file set from the POSITIVE globs and use `!`
|
|
658
|
+
* entries only to subtract, so with no positive pattern they return `[]` —
|
|
659
|
+
* the task folds zero file inputs and its cache key stops moving with its
|
|
660
|
+
* source. That is a stale hit, and it is silent.
|
|
661
|
+
*
|
|
662
|
+
* Refusing is free: such a config was ALREADY selecting nothing, so no
|
|
663
|
+
* working task's key changes and no CACHE_VERSION bump is owed.
|
|
664
|
+
*/
|
|
665
|
+
function assertNotNegationOnly(globs: readonly string[], where: string): void {
|
|
666
|
+
if (globs.length === 0) return
|
|
667
|
+
if (globs.some((g) => !g.startsWith('!'))) return
|
|
668
|
+
throw new UserError(
|
|
669
|
+
`${where}: every entry is a negation, which selects NOTHING (got ${JSON.stringify(globs)}) — ` +
|
|
670
|
+
`negations only subtract from the files a positive glob already matched, so this task ` +
|
|
671
|
+
`would fold zero file inputs and its cache key would stop tracking its source. ` +
|
|
672
|
+
`Add the positive glob you meant, e.g. ['**/*', ${JSON.stringify(globs[0])}].`,
|
|
673
|
+
)
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* `negation: false` for OUTPUT globs — `resolveOutputs` /
|
|
678
|
+
* `resolveWorkspaceOutputs` never split on `!`, so such an entry is read as a
|
|
679
|
+
* literal path starting with `!` and matches nothing.
|
|
680
|
+
*/
|
|
681
|
+
function validateWorkspaceGlobs(v: unknown, where: string, negation: boolean): void {
|
|
682
|
+
if (!Array.isArray(v)) {
|
|
683
|
+
throw new UserError(`${where} must be an array of glob strings`)
|
|
684
|
+
}
|
|
685
|
+
for (const g of v as unknown[]) {
|
|
686
|
+
if (typeof g !== 'string' || g.length === 0) {
|
|
687
|
+
throw new UserError(`${where} must be an array of non-empty strings`)
|
|
688
|
+
}
|
|
689
|
+
if (g.startsWith('/') || g.startsWith('!/')) {
|
|
690
|
+
throw new UserError(
|
|
691
|
+
`${where}: absolute paths are not allowed (got "${g}") — ` +
|
|
692
|
+
`entries are workspace-root-relative globs`,
|
|
693
|
+
)
|
|
694
|
+
}
|
|
695
|
+
if (hasParentSegment(g)) {
|
|
696
|
+
throw new UserError(
|
|
697
|
+
`${where}: '..' path segments are not allowed (got "${g}") — ` +
|
|
698
|
+
`entries are workspace-root-relative and must stay within the workspace root`,
|
|
699
|
+
)
|
|
700
|
+
}
|
|
701
|
+
if (namesDirItself(g)) {
|
|
702
|
+
throw new UserError(
|
|
703
|
+
`${where}: "${g}" names the workspace root itself and selects nothing — use "**" for everything under it`,
|
|
704
|
+
)
|
|
705
|
+
}
|
|
706
|
+
if (!negation && g.startsWith('!')) {
|
|
707
|
+
throw new UserError(
|
|
708
|
+
`${where}: negation is not supported (got "${g}") — ` +
|
|
709
|
+
`unlike inputs, output globs are never split on '!', so this is read as a literal ` +
|
|
710
|
+
`path beginning with '!' and matches nothing. List the outputs you DO produce.`,
|
|
711
|
+
)
|
|
712
|
+
}
|
|
713
|
+
if (negation) assertNotDoubleNegated(g, where)
|
|
714
|
+
}
|
|
715
|
+
if (negation) assertNotNegationOnly(v as string[], where)
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
const SANDBOX_FIELDS = new Set([
|
|
719
|
+
'allow',
|
|
720
|
+
'deny',
|
|
721
|
+
'ignore',
|
|
722
|
+
'weakerWhenNested',
|
|
723
|
+
'weakerNetworkIsolation',
|
|
724
|
+
])
|
|
725
|
+
const GRANT_PATH_FIELDS = ['read', 'write'] as const
|
|
726
|
+
const GRANT_NAME_FIELDS = ['systemInfo', 'machLookup'] as const
|
|
727
|
+
const GRANT_BOOL_FIELDS = ['pty', 'gitConfig'] as const
|
|
728
|
+
const GRANT_FIELDS = new Set<string>([
|
|
729
|
+
...GRANT_PATH_FIELDS,
|
|
730
|
+
...GRANT_NAME_FIELDS,
|
|
731
|
+
...GRANT_BOOL_FIELDS,
|
|
732
|
+
'localBinding',
|
|
733
|
+
'network',
|
|
734
|
+
'unixSockets',
|
|
735
|
+
])
|
|
736
|
+
const DENY_FIELDS = new Set(['network'])
|
|
737
|
+
|
|
738
|
+
function assertStringArray(v: unknown, where: string): void {
|
|
739
|
+
if (!Array.isArray(v) || v.some((s) => typeof s !== 'string' || s.length === 0)) {
|
|
740
|
+
throw new UserError(`${where} must be an array of non-empty strings`)
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* Validate a `sandbox: {...}` block — one capability shape, whatever the
|
|
746
|
+
* platform ends up doing with it. Unknown keys are refused rather than
|
|
747
|
+
* dropped: a silently-ignored `allow.reads` would confine a task more than
|
|
748
|
+
* its author believed, and the failure reads as a broken build.
|
|
749
|
+
*/
|
|
750
|
+
function validateSandbox(sandbox: unknown, where: string): void {
|
|
751
|
+
if (typeof sandbox !== 'object' || sandbox === null || Array.isArray(sandbox)) {
|
|
752
|
+
throw new UserError(
|
|
753
|
+
`${where}.sandbox must be an object (e.g. \`{}\` for the baseline, or ` +
|
|
754
|
+
`\`{ allow: { read: [...] } }\`)`,
|
|
755
|
+
)
|
|
756
|
+
}
|
|
757
|
+
assertKnownFields(sandbox, SANDBOX_FIELDS, `${where}.sandbox`)
|
|
758
|
+
const obj = sandbox as Record<string, unknown>
|
|
759
|
+
|
|
760
|
+
for (const flag of ['weakerWhenNested', 'weakerNetworkIsolation']) {
|
|
761
|
+
if (obj[flag] !== undefined && typeof obj[flag] !== 'boolean') {
|
|
762
|
+
throw new UserError(`${where}.sandbox.${flag} must be a boolean`)
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
const allow = obj['allow']
|
|
767
|
+
if (allow !== undefined) {
|
|
768
|
+
if (typeof allow !== 'object' || allow === null || Array.isArray(allow)) {
|
|
769
|
+
throw new UserError(`${where}.sandbox.allow must be an object`)
|
|
770
|
+
}
|
|
771
|
+
assertKnownFields(allow, GRANT_FIELDS, `${where}.sandbox.allow`)
|
|
772
|
+
const g = allow as Record<string, unknown>
|
|
773
|
+
for (const f of GRANT_PATH_FIELDS) {
|
|
774
|
+
// Patterns are allowed here: macOS matches them natively, Linux
|
|
775
|
+
// expands them against the filesystem at resolve time.
|
|
776
|
+
if (g[f] !== undefined) assertStringArray(g[f], `${where}.sandbox.allow.${f}`)
|
|
777
|
+
}
|
|
778
|
+
for (const f of GRANT_NAME_FIELDS) {
|
|
779
|
+
if (g[f] !== undefined) assertStringArray(g[f], `${where}.sandbox.allow.${f}`)
|
|
780
|
+
}
|
|
781
|
+
for (const f of GRANT_BOOL_FIELDS) {
|
|
782
|
+
if (g[f] !== undefined && typeof g[f] !== 'boolean') {
|
|
783
|
+
throw new UserError(`${where}.sandbox.allow.${f} must be a boolean`)
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
// `true` (everything) or an explicit list — nothing in between.
|
|
787
|
+
for (const f of ['network', 'unixSockets']) {
|
|
788
|
+
if (g[f] !== undefined && g[f] !== true) {
|
|
789
|
+
assertStringArray(g[f], `${where}.sandbox.allow.${f}`)
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
// A boolean, or the ports to bridge out of the sandbox: a non-empty
|
|
793
|
+
// list of integers in the TCP range. An empty list would read as "no
|
|
794
|
+
// port" while granting loopback, which is `true` with extra steps.
|
|
795
|
+
const lb = g['localBinding']
|
|
796
|
+
if (lb !== undefined && typeof lb !== 'boolean') {
|
|
797
|
+
if (
|
|
798
|
+
!Array.isArray(lb) ||
|
|
799
|
+
lb.length === 0 ||
|
|
800
|
+
lb.some((p) => !Number.isInteger(p) || (p as number) < 1 || (p as number) > 65535)
|
|
801
|
+
) {
|
|
802
|
+
throw new UserError(
|
|
803
|
+
`${where}.sandbox.allow.localBinding must be a boolean or a non-empty list of ports (1–65535)`,
|
|
804
|
+
)
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
const deny = obj['deny']
|
|
810
|
+
if (deny !== undefined) {
|
|
811
|
+
if (typeof deny !== 'object' || deny === null || Array.isArray(deny)) {
|
|
812
|
+
throw new UserError(`${where}.sandbox.deny must be an object`)
|
|
813
|
+
}
|
|
814
|
+
assertKnownFields(deny, DENY_FIELDS, `${where}.sandbox.deny`)
|
|
815
|
+
const d = deny as Record<string, unknown>
|
|
816
|
+
if (d['network'] !== undefined) assertStringArray(d['network'], `${where}.sandbox.deny.network`)
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
const ignore = obj['ignore']
|
|
820
|
+
if (ignore !== undefined) {
|
|
821
|
+
if (typeof ignore !== 'object' || ignore === null || Array.isArray(ignore)) {
|
|
822
|
+
throw new UserError(`${where}.sandbox.ignore must be an object`)
|
|
823
|
+
}
|
|
824
|
+
assertKnownFields(ignore, GRANT_FIELDS, `${where}.sandbox.ignore`)
|
|
825
|
+
const g = ignore as Record<string, unknown>
|
|
826
|
+
// Patterns, not prefixes — `ignore` is vx's own filter over lines it
|
|
827
|
+
// already holds, so a glob costs nothing and works on every platform.
|
|
828
|
+
for (const f of [...GRANT_PATH_FIELDS, ...GRANT_NAME_FIELDS, 'network', 'unixSockets']) {
|
|
829
|
+
if (g[f] !== undefined) assertStringArray(g[f], `${where}.sandbox.ignore.${f}`)
|
|
830
|
+
}
|
|
831
|
+
for (const f of GRANT_BOOL_FIELDS) {
|
|
832
|
+
if (g[f] !== undefined) {
|
|
833
|
+
throw new UserError(`${where}.sandbox.ignore.${f} is a flag, not something to ignore`)
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
}
|