rollbridge 0.1.59 → 0.1.61
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/README.md +1 -1
- package/changelog.d/20261106-release-dependency-boot-budgets.md +32 -0
- package/changelog.d/20261109-path-filtered-builds.md +11 -0
- package/changelog.d/20261110-default-boot-budget-above-measured-startup.md +26 -0
- package/changelog.d/20261111-contention-sensitive-daemon-specs.md +27 -0
- package/docs/config.md +42 -2
- package/docs/troubleshooting.md +22 -6
- package/docs/velocious.md +1 -1
- package/examples/tensorbuzz.com.js +1 -1
- package/package.json +1 -1
- package/src/config.js +104 -3
- package/src/health.js +99 -8
- package/src/process-order.js +26 -0
- package/src/release-group.js +157 -22
- package/tensorbuzz.yml +17 -0
- package/test/config-validation.test.js +102 -0
- package/test/fixtures/deferred-boot-app.js +106 -0
- package/test/health.test.js +74 -1
- package/test/owner-replacement.test.js +22 -2
- package/test/rollbridge.test.js +202 -14
- package/test/tensorbuzz-config.test.js +228 -0
package/test/rollbridge.test.js
CHANGED
|
@@ -19,6 +19,7 @@ describe("rollbridge", () => {
|
|
|
19
19
|
const currentDir = path.dirname(fileURLToPath(import.meta.url))
|
|
20
20
|
const binPath = path.join(currentDir, "..", "bin", "rollbridge")
|
|
21
21
|
const dependentAppPath = path.join(currentDir, "fixtures", "dependent-app.js")
|
|
22
|
+
const deferredBootAppPath = path.join(currentDir, "fixtures", "deferred-boot-app.js")
|
|
22
23
|
const dummyAppPath = path.join(currentDir, "fixtures", "dummy-app.js")
|
|
23
24
|
const memoryHogPath = path.join(currentDir, "fixtures", "memory-hog.js")
|
|
24
25
|
const serviceAppPath = path.join(currentDir, "fixtures", "service-app.js")
|
|
@@ -243,6 +244,139 @@ test("failed release startup logs process output and cleanup status", async () =
|
|
|
243
244
|
}
|
|
244
245
|
})
|
|
245
246
|
|
|
247
|
+
test("the dependency wait is charged to its own budget, not to the proxied boot budget", async () => {
|
|
248
|
+
const fixture = await createFixture()
|
|
249
|
+
const config = deferredBootConfig(fixture, {dependencyTimeoutMs: 5000, serviceBootMs: 1200, webBootMs: 600, webHealthTimeoutMs: 900})
|
|
250
|
+
/** @type {Array<{data?: Record<string, import("../src/json.js").JsonValue>, message: string}>} */
|
|
251
|
+
const logs = []
|
|
252
|
+
const daemon = new RollbridgeDaemon({config, logger: (message, data = {}) => logs.push({data, message})})
|
|
253
|
+
|
|
254
|
+
await daemon.start()
|
|
255
|
+
|
|
256
|
+
try {
|
|
257
|
+
await daemon.deploy({releaseId: "v1", releasePath: fixture.root, revision: "v1"})
|
|
258
|
+
|
|
259
|
+
const dependencyLog = logs.find((entry) => entry.message === "release process dependency ready")
|
|
260
|
+
const healthLog = logs.find((entry) => entry.message === "release candidate health ready")
|
|
261
|
+
|
|
262
|
+
if (!dependencyLog?.data || !healthLog?.data) throw new Error("expected the dependency wait and the boot time to be logged")
|
|
263
|
+
// The dependency took ~1200ms and the app boot ~600ms. The boot budget is 900ms, so this
|
|
264
|
+
// deploy only succeeds because the dependency wait is charged to a budget of its own.
|
|
265
|
+
expect(Number(dependencyLog.data.elapsedMs)).toBeGreaterThanOrEqual(1000)
|
|
266
|
+
expect(Number(healthLog.data.bootMs)).toBeLessThan(900)
|
|
267
|
+
expect(Number(healthLog.data.waitedForDependenciesMs)).toBeGreaterThanOrEqual(1000)
|
|
268
|
+
expect(await fetchText(daemon, "/release")).toBe("v1")
|
|
269
|
+
} finally {
|
|
270
|
+
await daemon.shutdown()
|
|
271
|
+
await fs.rm(fixture.root, {force: true, recursive: true})
|
|
272
|
+
}
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
test("a release whose app boots past the old 30000ms window publishes on the default boot budget while the incumbent serves", {timeoutMs: 180000}, async () => {
|
|
276
|
+
const fixture = await createFixture()
|
|
277
|
+
// Measured on TensorBuzz production (server3, 2026-11-06): the candidate web process was
|
|
278
|
+
// still initialising when the 30000ms release health deadline expired and was killed at
|
|
279
|
+
// 30287ms without ever logging a listening line. 32000ms reproduces a boot the old default
|
|
280
|
+
// killed; nothing here configures a health budget, so the release runs on the default.
|
|
281
|
+
const lateBootMs = 32000
|
|
282
|
+
const incumbentConfig = deferredBootConfig(fixture, {dependencyTimeoutMs: 30000, serviceBootMs: 0, webBootMs: 0})
|
|
283
|
+
const configPath = await writeConfigFile(incumbentConfig, fixture.root)
|
|
284
|
+
/** @type {Array<{data?: Record<string, import("../src/json.js").JsonValue>, message: string}>} */
|
|
285
|
+
const logs = []
|
|
286
|
+
const daemon = new RollbridgeDaemon({config: incumbentConfig, configPath, logger: (message, data = {}) => logs.push({data, message})})
|
|
287
|
+
|
|
288
|
+
await daemon.start()
|
|
289
|
+
|
|
290
|
+
try {
|
|
291
|
+
await daemon.deploy({releaseId: "v1", releasePath: fixture.root, revision: "v1"})
|
|
292
|
+
expect(await fetchText(daemon, "/release")).toBe("v1")
|
|
293
|
+
|
|
294
|
+
await writeConfigFile(deferredBootConfig(fixture, {dependencyTimeoutMs: 30000, serviceBootMs: 0, webBootMs: lateBootMs}), fixture.root)
|
|
295
|
+
const deployment = daemon.deploy({releaseId: "v2", releasePath: fixture.root, revision: "v2"})
|
|
296
|
+
|
|
297
|
+
// The candidate is still booting a second later: the incumbent keeps serving traffic.
|
|
298
|
+
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
299
|
+
expect(await fetchText(daemon, "/release")).toBe("v1")
|
|
300
|
+
await deployment
|
|
301
|
+
|
|
302
|
+
const ready = logs.find((entry) => entry.message === "release candidate health ready" && entry.data?.releaseId === "v2")
|
|
303
|
+
|
|
304
|
+
if (!ready?.data) throw new Error("expected the v2 boot time to be recorded in the event log")
|
|
305
|
+
expect(Number(ready.data.bootMs)).toBeGreaterThanOrEqual(lateBootMs)
|
|
306
|
+
expect(Number(ready.data.healthGateMs)).toBeGreaterThanOrEqual(lateBootMs)
|
|
307
|
+
expect(Number(ready.data.deadlineMs)).toBe(120000)
|
|
308
|
+
expect(daemon.status().activeReleaseId).toBe("v2")
|
|
309
|
+
expect(await fetchText(daemon, "/release")).toBe("v2")
|
|
310
|
+
} finally {
|
|
311
|
+
await daemon.shutdown()
|
|
312
|
+
await fs.rm(fixture.root, {force: true, recursive: true})
|
|
313
|
+
}
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
test("a dependency that never opens fails the deploy on its own budget and keeps the incumbent serving", async () => {
|
|
317
|
+
const fixture = await createFixture()
|
|
318
|
+
const initialConfig = deferredBootConfig(fixture, {dependencyTimeoutMs: 5000, serviceBootMs: 0, webBootMs: 0, webHealthTimeoutMs: 900})
|
|
319
|
+
const configPath = await writeConfigFile(initialConfig, fixture.root)
|
|
320
|
+
/** @type {Array<{data?: Record<string, import("../src/json.js").JsonValue>, message: string}>} */
|
|
321
|
+
const logs = []
|
|
322
|
+
const daemon = new RollbridgeDaemon({config: initialConfig, configPath, logger: (message, data = {}) => logs.push({data, message})})
|
|
323
|
+
|
|
324
|
+
await daemon.start()
|
|
325
|
+
|
|
326
|
+
try {
|
|
327
|
+
await daemon.deploy({releaseId: "v1", releasePath: fixture.root, revision: "v1"})
|
|
328
|
+
expect(await fetchText(daemon, "/release")).toBe("v1")
|
|
329
|
+
|
|
330
|
+
// v2's service never binds its port, so the dependency gate runs out before the app is started.
|
|
331
|
+
await writeConfigFile(deferredBootConfig(fixture, {dependencyTimeoutMs: 300, serviceBootMs: 60000, webBootMs: 0, webHealthTimeoutMs: 900}), fixture.root)
|
|
332
|
+
await expect(daemon.deploy({releaseId: "v2", releasePath: fixture.root, revision: "v2"})).rejects.toThrow(/did not accept a connection within 300ms/)
|
|
333
|
+
|
|
334
|
+
expect(daemon.status().activeReleaseId).toBe("v1")
|
|
335
|
+
expect(await fetchText(daemon, "/release")).toBe("v1")
|
|
336
|
+
|
|
337
|
+
const failure = logs.find((entry) => entry.message === "release startup failed" && entry.data?.phase === "before cleanup")
|
|
338
|
+
|
|
339
|
+
if (!failure?.data) throw new Error("expected the dependency failure to name its budget")
|
|
340
|
+
expect(failure.data.stage).toBe("dependency")
|
|
341
|
+
expect(failure.data.deadlineMs).toBe(300)
|
|
342
|
+
expect(Number(failure.data.dependencyWaitMs)).toBeGreaterThanOrEqual(300)
|
|
343
|
+
expect(failure.data.readyProcesses).toEqual(["beacon"])
|
|
344
|
+
expect(failure.data.unreadyProcesses).toEqual([])
|
|
345
|
+
} finally {
|
|
346
|
+
await daemon.shutdown()
|
|
347
|
+
await fs.rm(fixture.root, {force: true, recursive: true})
|
|
348
|
+
}
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
test("a startup timeout names the deadline, the elapsed boot, the ready processes, and the last output", async () => {
|
|
352
|
+
const fixture = await createFixture()
|
|
353
|
+
const config = deferredBootConfig(fixture, {dependencyTimeoutMs: 5000, serviceBootMs: 0, webBootMs: 1200, webHealthTimeoutMs: 400})
|
|
354
|
+
/** @type {Array<{data?: Record<string, import("../src/json.js").JsonValue>, message: string}>} */
|
|
355
|
+
const logs = []
|
|
356
|
+
const daemon = new RollbridgeDaemon({config, logger: (message, data = {}) => logs.push({data, message})})
|
|
357
|
+
|
|
358
|
+
await daemon.start()
|
|
359
|
+
|
|
360
|
+
try {
|
|
361
|
+
await expect(daemon.deploy({releaseId: "v1", releasePath: fixture.root, revision: "v1"})).rejects.toThrow(/health deadline/)
|
|
362
|
+
|
|
363
|
+
const failure = logs.find((entry) => entry.message === "release startup failed" && entry.data?.phase === "before cleanup")
|
|
364
|
+
|
|
365
|
+
if (!failure?.data) throw new Error("expected the startup failure to name its budget")
|
|
366
|
+
expect(failure.data.stage).toBe("health")
|
|
367
|
+
expect(failure.data.deadlineMs).toBe(400)
|
|
368
|
+
expect(Number(failure.data.elapsedMs)).toBeGreaterThanOrEqual(400)
|
|
369
|
+
expect(Number(failure.data.probes)).toBeGreaterThanOrEqual(1)
|
|
370
|
+
expect(failure.data.readyProcesses).toEqual(["beacon"])
|
|
371
|
+
expect(failure.data.unreadyProcesses).toEqual(["web"])
|
|
372
|
+
expect(String(failure.data.lastOutput)).toMatch(/accepted a connection/)
|
|
373
|
+
expect(String(failure.data.lastOutputAt)).toMatch(/^\d{4}-\d{2}-\d{2}T/)
|
|
374
|
+
} finally {
|
|
375
|
+
await daemon.shutdown()
|
|
376
|
+
await fs.rm(fixture.root, {force: true, recursive: true})
|
|
377
|
+
}
|
|
378
|
+
})
|
|
379
|
+
|
|
246
380
|
test("singleton processes restart without overlap during deploy", async () => {
|
|
247
381
|
const fixture = await createFixture({includeSingleton: true})
|
|
248
382
|
const daemon = await startDaemon(fixture.config)
|
|
@@ -269,6 +403,13 @@ test("singleton processes restart without overlap during deploy", async () => {
|
|
|
269
403
|
}
|
|
270
404
|
})
|
|
271
405
|
|
|
406
|
+
// Budget for waiting on the old jobs generation's quiet marker in the spec below. Measured with the
|
|
407
|
+
// marker read directly: the spec completes in 1.740s on this host, so this is not a boot budget but a
|
|
408
|
+
// generous ceiling on a handoff that already happened; the number only decides how long a genuinely
|
|
409
|
+
// stuck quiescence takes to report itself, and it now reports the marker path instead of the runner's
|
|
410
|
+
// ambient 60s default.
|
|
411
|
+
const SINGLETON_QUIET_MARKER_TIMEOUT_MS = 20000
|
|
412
|
+
|
|
272
413
|
test("candidate activation quiesces the old jobs generation before a blocked singleton replacement completes", async () => {
|
|
273
414
|
const fixture = await createFixture({handoffService: true, handoffServiceQuiet: true, includeSingleton: true, webDependsOnService: true})
|
|
274
415
|
const singletonGatePath = path.join(fixture.root, "singleton-replacement.gate")
|
|
@@ -291,24 +432,27 @@ test("candidate activation quiesces the old jobs generation before a blocked sin
|
|
|
291
432
|
try {
|
|
292
433
|
await daemon.deploy({releaseId: "v1", releasePath: fixture.root, revision: "v1"})
|
|
293
434
|
|
|
294
|
-
const abortController = new AbortController()
|
|
295
|
-
const changes = fs.watch(fixture.root, {signal: abortController.signal})
|
|
296
|
-
const singletonReplacementBlocked = (async () => {
|
|
297
|
-
try {
|
|
298
|
-
for await (const change of changes) {
|
|
299
|
-
if (change.filename === path.basename(singletonQuietPath)) return
|
|
300
|
-
}
|
|
301
|
-
} finally {
|
|
302
|
-
abortController.abort()
|
|
303
|
-
}
|
|
304
|
-
})()
|
|
305
|
-
|
|
306
435
|
deployPromise = daemon.deploy({releaseId: "v2", releasePath: fixture.root, revision: "v2"})
|
|
307
436
|
let deploySettled = false
|
|
308
437
|
|
|
309
438
|
void deployPromise.then(() => { deploySettled = true }, () => { deploySettled = true })
|
|
310
|
-
|
|
311
|
-
|
|
439
|
+
|
|
440
|
+
// Wait on the durable marker the old jobs generation writes, not on an inotify event for it.
|
|
441
|
+
// fs.watch surfaces nothing in runtimes whose filesystem does not deliver events (measured in
|
|
442
|
+
// this container: a minimal fs.watch receives 0 events for a file written by an external
|
|
443
|
+
// process, on both overlayfs /tmp and ext3 /data, with max_user_watches at 1048576), and an
|
|
444
|
+
// unguarded event loop turns that into a bare runner timeout naming no stage. Reading the
|
|
445
|
+
// marker is the same observation with a fallback the event never had, and the three assertions
|
|
446
|
+
// below are unchanged: candidate traffic active, deploy still pending, old generation quiesced.
|
|
447
|
+
const quietDeadline = Date.now() + SINGLETON_QUIET_MARKER_TIMEOUT_MS
|
|
448
|
+
let sawQuietMarker = false
|
|
449
|
+
|
|
450
|
+
while (Date.now() < quietDeadline && !sawQuietMarker) {
|
|
451
|
+
sawQuietMarker = await fs.readFile(singletonQuietPath, "utf8").then((content) => content.includes("quiet"), () => false)
|
|
452
|
+
if (!sawQuietMarker) await new Promise((resolve) => setTimeout(resolve, 10))
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if (!sawQuietMarker) throw new Error(`Old jobs generation never wrote its quiet marker within ${SINGLETON_QUIET_MARKER_TIMEOUT_MS}ms: ${singletonQuietPath}`)
|
|
312
456
|
|
|
313
457
|
// Candidate traffic must already be active.
|
|
314
458
|
expect(daemon.status().activeReleaseId).toBe("v2")
|
|
@@ -2199,6 +2343,50 @@ async function createFixture(options = {}) {
|
|
|
2199
2343
|
return {activationGatePath, config, gatePath, lifecycleLogPath, retirementGatePath, root, serviceLogPath, serviceQuietPath, singletonLogPath, statePath}
|
|
2200
2344
|
}
|
|
2201
2345
|
|
|
2346
|
+
/**
|
|
2347
|
+
* Config where both processes run the deferred-boot fixture, so a measured boot budget can be
|
|
2348
|
+
* compared against a dependency wait that must not be charged to it. Omitting
|
|
2349
|
+
* webHealthTimeoutMs leaves both the per-process and the release health budget unconfigured, so
|
|
2350
|
+
* the normalized config carries the default boot budget instead of a test-chosen one.
|
|
2351
|
+
* @param {{config: import("../src/config.js").RollbridgeConfig, root: string}} fixture - Fixture.
|
|
2352
|
+
* @param {{dependencyTimeoutMs: number, serviceBootMs: number, webBootMs: number, webHealthTimeoutMs?: number}} options - Budgets.
|
|
2353
|
+
* @returns {import("../src/config.js").RollbridgeConfig} Config for the deferred-boot processes.
|
|
2354
|
+
*/
|
|
2355
|
+
function deferredBootConfig(fixture, options) {
|
|
2356
|
+
const appCommand = `${JSON.stringify(process.execPath)} ${JSON.stringify(deferredBootAppPath)}`
|
|
2357
|
+
/** @type {Partial<import("../src/config.js").ProxyConfig>} */
|
|
2358
|
+
const proxyWithoutHealthBudget = structuredClone(fixture.config.proxy)
|
|
2359
|
+
|
|
2360
|
+
delete proxyWithoutHealthBudget.healthTimeoutMs
|
|
2361
|
+
|
|
2362
|
+
return normalizeConfig({
|
|
2363
|
+
...fixture.config,
|
|
2364
|
+
...(options.webHealthTimeoutMs === undefined ? {proxy: proxyWithoutHealthBudget} : {}),
|
|
2365
|
+
processes: [
|
|
2366
|
+
{
|
|
2367
|
+
command: appCommand,
|
|
2368
|
+
deployStrategy: "handoff",
|
|
2369
|
+
env: {ROLLBRIDGE_BOOT_MS: String(options.serviceBootMs)},
|
|
2370
|
+
id: "beacon",
|
|
2371
|
+
policy: "service",
|
|
2372
|
+
port: {from: 15000, to: 15099}
|
|
2373
|
+
},
|
|
2374
|
+
{
|
|
2375
|
+
command: appCommand,
|
|
2376
|
+
dependsOn: ["beacon"],
|
|
2377
|
+
dependencyTimeoutMs: options.dependencyTimeoutMs,
|
|
2378
|
+
env: {ROLLBRIDGE_BOOT_MS: String(options.webBootMs), ROLLBRIDGE_DEPENDENCY_PORT: "{{ports.beacon}}"},
|
|
2379
|
+
...(options.webHealthTimeoutMs === undefined
|
|
2380
|
+
? {}
|
|
2381
|
+
: {health: {intervalMs: 50, path: "/ping", timeoutMs: options.webHealthTimeoutMs}}),
|
|
2382
|
+
id: "web",
|
|
2383
|
+
policy: "proxied",
|
|
2384
|
+
port: {from: 0, to: 0}
|
|
2385
|
+
}
|
|
2386
|
+
]
|
|
2387
|
+
})
|
|
2388
|
+
}
|
|
2389
|
+
|
|
2202
2390
|
/**
|
|
2203
2391
|
* @param {string} lifecycleLogPath - Fixture lifecycle event file.
|
|
2204
2392
|
* @returns {Promise<string[]>} Ordered lifecycle events.
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import {execFile} from "node:child_process"
|
|
4
|
+
import fs from "node:fs/promises"
|
|
5
|
+
import path from "node:path"
|
|
6
|
+
import {describe, expect, test} from "@velocious/testing"
|
|
7
|
+
import {fileURLToPath} from "node:url"
|
|
8
|
+
import {promisify} from "node:util"
|
|
9
|
+
|
|
10
|
+
describe("tensorbuzz-config", () => {
|
|
11
|
+
|
|
12
|
+
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..")
|
|
13
|
+
const execFileAsync = promisify(execFile)
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {object} PathRule
|
|
17
|
+
* @property {boolean} negated True when the rule carves the paths it matches out of the lane.
|
|
18
|
+
* @property {string} pattern Rule body without its YAML quotes and without the `!` prefix.
|
|
19
|
+
* @property {RegExp} regexp Matcher compiled from the rule body.
|
|
20
|
+
* @property {string} raw Rule exactly as declared in tensorbuzz.yml, quotes included.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @typedef {object} PathDecision
|
|
25
|
+
* @property {string} filePath Repo-relative path the decision was taken on.
|
|
26
|
+
* @property {string} matchedPattern Last rule that matched, empty when no rule matched.
|
|
27
|
+
* @property {boolean} skipped True when the last matching rule negates the path.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {object} GateInput
|
|
32
|
+
* @property {string[]} readPaths Paths `npm run all-checks` opens: the suite and the linters read
|
|
33
|
+
* these, so carving any of them out of the lane would skip a check that the change can break.
|
|
34
|
+
* @property {string[]} skippedPaths Paths the lane must not need: Markdown the gate never opens.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
const GATE_INPUTS = [
|
|
38
|
+
"src/daemon.js",
|
|
39
|
+
"src/process-guardian.js",
|
|
40
|
+
"test/rollbridge.test.js",
|
|
41
|
+
"test/fixtures/dummy-app.js",
|
|
42
|
+
"bin/rollbridge",
|
|
43
|
+
"examples/tensorbuzz.com.js",
|
|
44
|
+
"package.json",
|
|
45
|
+
"package-lock.json",
|
|
46
|
+
"tsconfig.json",
|
|
47
|
+
"eslint.config.js",
|
|
48
|
+
".npmignore",
|
|
49
|
+
"LICENSE",
|
|
50
|
+
"compose.yml",
|
|
51
|
+
"tensorbuzz.yml"
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
const MARKDOWN_PATHS = [
|
|
55
|
+
"README.md",
|
|
56
|
+
"AGENTS.md",
|
|
57
|
+
"docs/tensorbuzz-runbook.md",
|
|
58
|
+
"docs/releasing.md",
|
|
59
|
+
"changelog.d/20261109-path-filtered-builds.md"
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Reads the root `paths` rules out of tensorbuzz.yml.
|
|
64
|
+
* @param {string} configText Full tensorbuzz.yml contents.
|
|
65
|
+
* @returns {PathRule[]} Rules in declaration order.
|
|
66
|
+
*/
|
|
67
|
+
function readPathRules(configText) {
|
|
68
|
+
const lines = configText.split("\n")
|
|
69
|
+
const start = lines.findIndex((line) => line.trim() === "paths:")
|
|
70
|
+
|
|
71
|
+
if (start < 0) return []
|
|
72
|
+
|
|
73
|
+
/** @type {PathRule[]} */
|
|
74
|
+
const rules = []
|
|
75
|
+
|
|
76
|
+
for (const line of lines.slice(start + 1)) {
|
|
77
|
+
const entry = line.trim()
|
|
78
|
+
|
|
79
|
+
if (!entry.startsWith("- ")) break
|
|
80
|
+
if (!entry) continue
|
|
81
|
+
|
|
82
|
+
const raw = entry.slice(2).trim()
|
|
83
|
+
const quoted = raw.startsWith("\"") && raw.endsWith("\"") && raw.length > 1
|
|
84
|
+
const body = quoted ? raw.slice(1, -1) : raw
|
|
85
|
+
const negated = body.startsWith("!")
|
|
86
|
+
|
|
87
|
+
rules.push({
|
|
88
|
+
negated,
|
|
89
|
+
pattern: negated ? body.slice(1) : body,
|
|
90
|
+
raw,
|
|
91
|
+
regexp: compileRuleRegExp(negated ? body.slice(1) : body)
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return rules
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Compiles a `paths` glob the way TensorBuzz does, for the syntax this config declares: `**`
|
|
100
|
+
* crosses segments, `*` stays inside one segment, a rule containing `/` is anchored at the repo
|
|
101
|
+
* root while a bare name matches at any depth, and a matched directory covers everything below
|
|
102
|
+
* it. The `supported glob syntax` test keeps the config inside that subset.
|
|
103
|
+
* @param {string} pattern Rule body without the `!` prefix.
|
|
104
|
+
* @returns {RegExp} Anchored matcher for one repo-relative path.
|
|
105
|
+
*/
|
|
106
|
+
function compileRuleRegExp(pattern) {
|
|
107
|
+
const body = pattern.replace(/^\/+/, "").replace(/\/+$/, "")
|
|
108
|
+
const segments = body.split("/")
|
|
109
|
+
let source = body.includes("/") ? "" : "(?:[^/]+/)*"
|
|
110
|
+
|
|
111
|
+
for (let index = 0; index < segments.length; index += 1) {
|
|
112
|
+
const segment = segments[index]
|
|
113
|
+
const isLast = index === segments.length - 1
|
|
114
|
+
|
|
115
|
+
if (segment === "**") {
|
|
116
|
+
source += isLast ? ".*" : "(?:.*/)?"
|
|
117
|
+
|
|
118
|
+
continue
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
source += segment.split("*").map(escapeForRegExp).join("[^/]*")
|
|
122
|
+
|
|
123
|
+
if (!isLast) source += "/"
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (!body.endsWith("**")) source += "(?:/.*)?"
|
|
127
|
+
|
|
128
|
+
return new RegExp(`^${source}$`)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @param {string} text Literal text to make regexp-safe.
|
|
133
|
+
* @returns {string} Escaped text.
|
|
134
|
+
*/
|
|
135
|
+
function escapeForRegExp(text) {
|
|
136
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Applies ordered rules to one path; the last match wins, exactly like TensorBuzz.
|
|
141
|
+
* @param {{filePath: string, rules: PathRule[]}} args Path and the declared rules.
|
|
142
|
+
* @returns {PathDecision} Whether the lane runs for that path.
|
|
143
|
+
*/
|
|
144
|
+
function decidePath({filePath, rules}) {
|
|
145
|
+
/** @type {PathRule | null} */
|
|
146
|
+
let lastMatch = null
|
|
147
|
+
|
|
148
|
+
for (const rule of rules) {
|
|
149
|
+
if (rule.regexp.test(filePath)) lastMatch = rule
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
filePath,
|
|
154
|
+
matchedPattern: lastMatch ? lastMatch.pattern : "",
|
|
155
|
+
skipped: lastMatch !== null && lastMatch.negated
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @returns {Promise<PathRule[]>} Rules parsed from the repository's tensorbuzz.yml.
|
|
161
|
+
*/
|
|
162
|
+
async function declaredPathRules() {
|
|
163
|
+
return readPathRules(await fs.readFile(path.join(repoRoot, "tensorbuzz.yml"), "utf8"))
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
test("tensorbuzz.yml declares a paths block that defaults to running the lane", async () => {
|
|
167
|
+
const rules = await declaredPathRules()
|
|
168
|
+
|
|
169
|
+
expect(rules.length >= 2).toBeTruthy()
|
|
170
|
+
expect(rules[0].pattern).toBe("**")
|
|
171
|
+
expect(rules[0].negated).toBe(false)
|
|
172
|
+
|
|
173
|
+
const firstNegation = rules.findIndex((rule) => rule.negated)
|
|
174
|
+
|
|
175
|
+
expect(firstNegation > 0).toBeTruthy()
|
|
176
|
+
|
|
177
|
+
// A positive rule after a negation would re-admit every path the negation carved out, because
|
|
178
|
+
// the last match wins.
|
|
179
|
+
expect(rules.slice(firstNegation).filter((rule) => !rule.negated).map((rule) => rule.raw)).toEqual([])
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
test("every paths rule is a quoted glob the config validator accepts", async () => {
|
|
183
|
+
const rules = await declaredPathRules()
|
|
184
|
+
|
|
185
|
+
// An unquoted `!x` is a YAML tag, not a string, and the validator rejects the whole config.
|
|
186
|
+
expect(rules.map((rule) => rule.raw).filter((raw) => !raw.startsWith("\""))).toEqual([])
|
|
187
|
+
expect(rules.map((rule) => rule.pattern).filter((pattern) => !/^[A-Za-z0-9_./*-]+$/.test(pattern))).toEqual([])
|
|
188
|
+
expect(rules.map((rule) => rule.pattern).filter((pattern) => pattern.length < 1)).toEqual([])
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
test("a delivery that changes only Markdown is filtered out of the lane", async () => {
|
|
192
|
+
const rules = await declaredPathRules()
|
|
193
|
+
|
|
194
|
+
for (const filePath of MARKDOWN_PATHS) {
|
|
195
|
+
const decision = decidePath({filePath, rules})
|
|
196
|
+
|
|
197
|
+
expect({context: filePath, skipped: decision.skipped}).toEqual({context: filePath, skipped: true})
|
|
198
|
+
}
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
test("every path the gate reads stays inside the lane", async () => {
|
|
202
|
+
const rules = await declaredPathRules()
|
|
203
|
+
|
|
204
|
+
for (const filePath of GATE_INPUTS) {
|
|
205
|
+
const decision = decidePath({filePath, rules})
|
|
206
|
+
|
|
207
|
+
expect({context: filePath, matchedPattern: decision.matchedPattern, skipped: decision.skipped})
|
|
208
|
+
.toEqual({context: filePath, matchedPattern: "**", skipped: false})
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
test("the declared rules partition every tracked path between the lane and the skip set", async () => {
|
|
213
|
+
const rules = await declaredPathRules()
|
|
214
|
+
const {stdout} = await execFileAsync("git", ["ls-files"], {cwd: repoRoot})
|
|
215
|
+
const trackedPaths = stdout.split("\n").filter((line) => line.length > 0)
|
|
216
|
+
|
|
217
|
+
const skipped = trackedPaths.filter((filePath) => decidePath({filePath, rules}).skipped)
|
|
218
|
+
const runs = trackedPaths.filter((filePath) => !decidePath({filePath, rules}).skipped)
|
|
219
|
+
|
|
220
|
+
expect(skipped.length > 0).toBeTruthy()
|
|
221
|
+
expect(runs.length > 0).toBeTruthy()
|
|
222
|
+
|
|
223
|
+
// Only Markdown may be carved out: any other tracked path is a gate input the lane must run for.
|
|
224
|
+
expect(skipped.filter((filePath) => !filePath.endsWith(".md"))).toEqual([])
|
|
225
|
+
expect(runs.filter((filePath) => filePath.endsWith(".md"))).toEqual([])
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
})
|