Skip to content

Commit 4153d0a

Browse files
committed
ci(dependabot): make every cargo entry lockfile-only, and hold it by path edges
Addresses the review on this PR. - Generalise the lockfile-only guard. A new test reads every path dependency across the cargo Dependabot workspaces and requires `versioning-strategy: lockfile-only` on each entry at either end of one. That covers protect-ffi (path dep on eql-bindings) and the root entry (the fuzz crates and Go guests depend on root crates, and EQL depends on stack-encrypt/stack-kms), both the #1205 shape one edge over. Both entries are now lockfile-only. - State in each lockfile-only comment that it also drops a security update needing a manifest edit, and that osv-scanner still reports it; reword the "Security fixes are unaffected" line. - Count an EXEMPT entry only when its reason is non-blank. - Rewrap the long EQL entry comment. - Relax eql-codegen's `prettyplease = "=0.2.37"` pin to "0.2": nothing records a reason for it, rustfmt formats the output last, and under lockfile-only Dependabot could never move an exact pin. Cargo.lock is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MvUm3CCvX9dh2AZMh9vXct
1 parent b1ab8c8 commit 4153d0a

4 files changed

Lines changed: 227 additions & 26 deletions

File tree

‎.github/dependabot.yml‎

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ updates:
6666
# found" on a log page nobody visits, and the symptom is simply that no PR
6767
# ever arrives. The e2e test asserts this path holds a Cargo.toml.
6868
directory: /languages/typescript/packages/protect-ffi
69+
# Lockfile only, like the EQL entry below and for the same reason: this
70+
# workspace depends by path on eql-bindings, a member of the EQL
71+
# workspace. A requirement this entry raised could be written into
72+
# packages/eql/crates/eql-bindings/Cargo.toml without the EQL Cargo.lock,
73+
# the #1205 shape one edge over. An update that needs a manifest change,
74+
# in this workspace or that one, is dropped and made by hand. This applies
75+
# to Dependabot security updates too; osv-scanner still reports the
76+
# advisory. Held by
77+
# scripts/__tests__/dependabot-cargo-cross-workspace.test.mjs.
78+
versioning-strategy: lockfile-only
6979
# Monthly, where npm and actions are weekly. The deviation is about
7080
# validation cost, not risk appetite: a Cargo.lock bump is checked by
7181
# tests-rust.yml — one Blacksmith job, 45-minute timeout, cargo test +
@@ -140,12 +150,13 @@ updates:
140150
# ── Cargo (packages/eql — the second Rust workspace) ───────────
141151
# The EQL subtree brought a second Cargo workspace: six members
142152
# (crates/eql-{domains,codegen,tests-macros,bindings}, tests/sqlx and
143-
# tests/encryption) and its own Cargo.lock. It needs its own entry because Dependabot's cargo
144-
# `directory:` is a single workspace root, not a glob — the protect-ffi entry
145-
# above cannot reach it. The lockfile-to-ecosystem check in
146-
# e2e/tests/supply-chain.e2e.test.ts asserts coverage per ECOSYSTEM, so it
147-
# was already satisfied by that entry and would NOT have caught this gap;
148-
# the symptom would simply have been that no PR ever arrived.
153+
# tests/encryption) and its own Cargo.lock. It needs its own entry because
154+
# Dependabot's cargo `directory:` is a single workspace root, not a glob —
155+
# the protect-ffi entry above cannot reach it. The lockfile-to-ecosystem
156+
# check in e2e/tests/supply-chain.e2e.test.ts asserts coverage per
157+
# ECOSYSTEM, so it was already satisfied by that entry and would NOT have
158+
# caught this gap; the symptom would simply have been that no PR ever
159+
# arrived.
149160
- package-ecosystem: cargo
150161
# The workspace root, where Cargo.toml and Cargo.lock live. Not `/`, and
151162
# not a crate directory — same trap as the protect-ffi entry documents.
@@ -156,12 +167,20 @@ updates:
156167
# workspace; editing it there without the root Cargo.lock broke every root
157168
# `--locked` build (#1205, #1207). An update that needs a manifest change is
158169
# dropped rather than proposed, and is made by hand.
170+
#
171+
# That includes Dependabot SECURITY updates: `versioning-strategy` governs
172+
# them as well as version updates, so a security fix that needs a
173+
# requirement raised gets no PR from this entry. osv-scanner still reports
174+
# the advisory (it reaches this lockfile with `--recursive ./`), and the fix
175+
# is made by hand. Held, with the other two cargo entries, by
176+
# scripts/__tests__/dependabot-cargo-cross-workspace.test.mjs.
159177
versioning-strategy: lockfile-only
160178
# Monthly, matching protect-ffi and for the same reason: validating a
161179
# Cargo.lock bump here means the sharded SQLx matrix in test-eql.yml, which
162180
# compiles the full dependency tree and runs against live Postgres with
163-
# CipherStash credentials. Security fixes are unaffected — those are driven
164-
# by alerts, not by `schedule`.
181+
# CipherStash credentials. The schedule does not delay security fixes —
182+
# those are driven by alerts, not by `schedule` — though `lockfile-only`
183+
# above still drops one that needs a manifest edit.
165184
#
166185
# No `day:`, for the reason recorded above: it applies to `interval: weekly`
167186
# and would be configuration that does nothing.
@@ -217,8 +236,7 @@ updates:
217236
# versioning-strategy above already stops the manifest edit; these keep
218237
# the lockfile from moving these crates apart from the root's.
219238
# scripts/__tests__/dependabot-eql-inherited-ignores.test.mjs fails when
220-
# the root entry ignores a crate this entry does not, or when this entry
221-
# stops being lockfile-only.
239+
# the root entry ignores a crate this entry does not.
222240
- dependency-name: "recipher"
223241
- dependency-name: "cllw-ore"
224242
- dependency-name: "zerokms-protocol"
@@ -241,6 +259,17 @@ updates:
241259
- /packages/stack-encrypt/fuzz
242260
- /languages/golang/encrypt/guest
243261
- /languages/golang/auth/guest
262+
# Lockfile only, like the other two cargo entries. Every one of these
263+
# workspaces shares crates by path with another: the fuzz crates and both
264+
# guests depend on root-workspace crates, the encrypt guest also on
265+
# eql-bindings, and the EQL workspace on stack-encrypt and stack-kms. Those
266+
# root crates take `{ workspace = true }` requirements from the root
267+
# Cargo.toml, so a manifest edit made for any one of these lockfiles can
268+
# leave the others stale under `--locked`. An update that needs a manifest
269+
# change, security updates included, is dropped and made by hand; osv-scanner
270+
# still reports the advisory. Held by
271+
# scripts/__tests__/dependabot-cargo-cross-workspace.test.mjs.
272+
versioning-strategy: lockfile-only
244273
# Monthly, matching the other two cargo entries.
245274
schedule:
246275
interval: monthly

‎packages/eql/crates/eql-codegen/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ thiserror = "2"
1313
quote = "1"
1414
proc-macro2 = "1"
1515
syn = { version = "2", features = ["full"] }
16-
prettyplease = "=0.2.37"
16+
prettyplease = "0.2"
1717

1818
[[bin]]
1919
name = "eql-codegen"
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
import { existsSync, readFileSync, statSync } from 'node:fs'
2+
import { join, relative, resolve, sep } from 'node:path'
3+
import yaml from 'js-yaml'
4+
import { beforeAll, describe, expect, it } from 'vitest'
5+
import { REPO_ROOT } from './lib/repo-root.mjs'
6+
7+
/**
8+
* Every cargo Dependabot entry whose workspaces share crates with another
9+
* workspace by path must be `versioning-strategy: lockfile-only`.
10+
*
11+
* Each cargo `directory:` is one Cargo workspace with its own Cargo.lock, and
12+
* a Dependabot PR updates exactly that one lockfile. A path dependency crosses
13+
* that line in both directions:
14+
* - OUTWARD: a workspace that depends by path on another workspace's crate
15+
* resolves that crate's requirements, including any `{ workspace = true }`
16+
* ones from the other workspace's root Cargo.toml. To satisfy a bump it may
17+
* edit those manifests, outside its own workspace, and leave the other
18+
* workspace's Cargo.lock behind. That is #1205: the EQL entry rewrote the
19+
* root Cargo.toml, and every root `--locked` build failed (#1207).
20+
* - INWARD: a workspace whose crate another workspace depends on by path can
21+
* raise a requirement in its own manifest and update its own lockfile, and
22+
* the depending workspace's Cargo.lock is then stale under `--locked`.
23+
*
24+
* `lockfile-only` stops both: the entry never edits a manifest. An update that
25+
* needs one is dropped and made by hand, across every affected lockfile.
26+
*
27+
* The edges are read from the tracked manifests, so a new path dependency is
28+
* covered the day it lands.
29+
*/
30+
31+
const DEPENDABOT = join(REPO_ROOT, '.github/dependabot.yml')
32+
33+
/** Repo-relative, `/`-separated, no leading slash: the form Cargo uses. */
34+
function repoRel(abs) {
35+
return relative(REPO_ROOT, abs).split(sep).join('/')
36+
}
37+
38+
function readManifest(dir) {
39+
return readFileSync(join(REPO_ROOT, dir, 'Cargo.toml'), 'utf8')
40+
}
41+
42+
/**
43+
* The crate directories of the workspace rooted at `dir`: its `members`, plus
44+
* the root itself when it is also a package (a detached single-crate
45+
* workspace, such as a fuzz crate or a Go guest).
46+
*/
47+
function workspaceCrates(dir, manifest) {
48+
const crates = []
49+
if (/^\[package\]/m.test(manifest)) crates.push(dir)
50+
const block = manifest.match(/^members\s*=\s*\[([\s\S]*?)\]/m)
51+
if (block) {
52+
for (const [, member] of block[1].matchAll(/"([^"]+)"/g)) {
53+
expect(
54+
member,
55+
`${dir}/Cargo.toml: glob members are not expanded here`,
56+
).not.toMatch(/[*?[]/)
57+
crates.push(repoRel(resolve(REPO_ROOT, dir, member)))
58+
}
59+
}
60+
return crates
61+
}
62+
63+
/**
64+
* The crates a manifest depends on by path, repo-relative. A `path =` that
65+
* names a file (`[lib]`, `[[bin]]`) is not a dependency and is skipped.
66+
*/
67+
function pathDependencies(crateDir, manifest) {
68+
const deps = []
69+
for (const [, path] of manifest.matchAll(/\bpath\s*=\s*"([^"]+)"/g)) {
70+
const abs = resolve(REPO_ROOT, crateDir, path)
71+
if (!existsSync(abs) || !statSync(abs).isDirectory()) continue
72+
if (!existsSync(join(abs, 'Cargo.toml'))) continue
73+
deps.push(repoRel(abs))
74+
}
75+
return deps
76+
}
77+
78+
/**
79+
* Every cross-workspace path dependency, as
80+
* `{ from, to, fromDir, toDir }`: crate `from` in the workspace at `fromDir`
81+
* depends on crate `to` in the workspace at `toDir`. `toDir` is null when no
82+
* Dependabot cargo directory covers `to`.
83+
*/
84+
function crossWorkspaceEdges(workspaces) {
85+
const owner = new Map()
86+
for (const [dir, crates] of workspaces) {
87+
for (const crate of crates) owner.set(crate, dir)
88+
}
89+
const edges = []
90+
for (const [dir, crates] of workspaces) {
91+
for (const crate of crates) {
92+
for (const to of pathDependencies(crate, readManifest(crate))) {
93+
const toDir = owner.get(to) ?? null
94+
const seen = edges.some((e) => e.from === crate && e.to === to)
95+
if (toDir !== dir && !seen) {
96+
edges.push({ from: crate, to, fromDir: dir, toDir })
97+
}
98+
}
99+
}
100+
}
101+
return edges
102+
}
103+
104+
/** The directories of a Dependabot entry, without the leading `/`. */
105+
function entryDirs(entry) {
106+
const dirs = entry.directories ?? [entry.directory]
107+
return dirs.map((d) => d.replace(/^\/+/, '').replace(/\/+$/, ''))
108+
}
109+
110+
describe('cargo Dependabot entries that share crates across workspaces never edit a manifest', () => {
111+
let entries
112+
let edges
113+
114+
beforeAll(() => {
115+
const config = yaml.load(readFileSync(DEPENDABOT, 'utf8'))
116+
entries = config.updates.filter((u) => u['package-ecosystem'] === 'cargo')
117+
const workspaces = new Map()
118+
for (const entry of entries) {
119+
for (const dir of entryDirs(entry)) {
120+
workspaces.set(dir, workspaceCrates(dir, readManifest(dir)))
121+
}
122+
}
123+
edges = crossWorkspaceEdges(workspaces)
124+
})
125+
126+
it('finds cross-workspace path dependencies', () => {
127+
// If these all go away the rule below has nothing to hold, and this file
128+
// can be retired rather than left vacuously green.
129+
expect(edges).not.toHaveLength(0)
130+
})
131+
132+
it('covers every crate a path dependency reaches', () => {
133+
const uncovered = edges.filter((e) => e.toDir === null)
134+
expect(
135+
uncovered.map((e) => `${e.from} -> ${e.to}`),
136+
'path dependencies on crates no cargo Dependabot directory covers',
137+
).toEqual([])
138+
})
139+
140+
it('makes every entry on either end of one lockfile-only', () => {
141+
const involved = new Set(edges.flatMap((e) => [e.fromDir, e.toDir]))
142+
const offenders = entries
143+
.filter((entry) => entryDirs(entry).some((d) => involved.has(d)))
144+
.filter((entry) => entry['versioning-strategy'] !== 'lockfile-only')
145+
.map((entry) => {
146+
const dirs = new Set(entryDirs(entry))
147+
const why = edges
148+
.filter((e) => dirs.has(e.fromDir) || dirs.has(e.toDir))
149+
.map((e) => `${e.from} -> ${e.to}`)
150+
return `${(entry.directories ?? [entry.directory]).join(', ')}: ${why.join('; ')}`
151+
})
152+
expect(
153+
offenders,
154+
'these cargo entries share crates by path with another workspace, so a manifest ' +
155+
"edit can leave the other workspace's Cargo.lock behind. Set " +
156+
'`versioning-strategy: lockfile-only` on each.',
157+
).toEqual([])
158+
})
159+
})

‎scripts/__tests__/dependabot-eql-inherited-ignores.test.mjs‎

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ import { REPO_ROOT } from './lib/repo-root.mjs'
2323
* root `Cargo.lock` or the guest's pin (#1205). Every root `--locked` build and
2424
* the Go guest failed (#1207).
2525
*
26-
* Two defences, both held here:
26+
* Two defences:
2727
* - the EQL entry is `versioning-strategy: lockfile-only`, so it can never
28-
* edit a manifest, the root one included;
29-
* - it ignores every crate the root entry moves by hand, so its lockfile does
28+
* edit a manifest, the root one included. That one is held, for every cargo
29+
* entry a path dependency crosses into or out of, by
30+
* dependabot-cargo-cross-workspace.test.mjs;
31+
* - held here: it ignores every crate the root entry moves by hand, so its lockfile does
3032
* not move those crates apart from the root's. The two ignore lists are
3133
* hand-written copies, so this compares them.
3234
*/
@@ -44,6 +46,17 @@ const EXEMPT = new Map([
4446
// ['crate-name', 'why the EQL workspace cannot resolve it through a path dependency'],
4547
])
4648

49+
/**
50+
* The crates `rootIgnored` names that `eqlIgnored` does not, less those
51+
* `exempt` excuses. Only a written reason excuses one: an exemption whose
52+
* reason is empty is no exemption.
53+
*/
54+
function unexempted(rootIgnored, eqlIgnored, exempt) {
55+
return [...rootIgnored].filter(
56+
(name) => !eqlIgnored.has(name) && !exempt.get(name)?.trim(),
57+
)
58+
}
59+
4760
/** The `cargo` entry covering `dir`, from `directory:` or `directories:`. */
4861
function cargoEntry(config, dir) {
4962
const matches = config.updates.filter(
@@ -126,15 +139,6 @@ describe('the /packages/eql Dependabot entry ignores what it inherits from the r
126139
pathDeps = eqlPathDependenciesIntoRoot()
127140
})
128141

129-
it('never edits a manifest: the EQL entry is lockfile-only', () => {
130-
expect(
131-
eqlEntry['versioning-strategy'],
132-
`the ${EQL_DIR} entry must be \`versioning-strategy: lockfile-only\`. Its path ` +
133-
'dependencies inherit requirements from the ROOT Cargo.toml, so any manifest edit ' +
134-
'it makes can land outside its own workspace.',
135-
).toBe('lockfile-only')
136-
})
137-
138142
it('finds the root ignore list it compares against', () => {
139143
expect(rootIgnored.size).toBeGreaterThan(0)
140144
})
@@ -149,9 +153,7 @@ describe('the /packages/eql Dependabot entry ignores what it inherits from the r
149153
})
150154

151155
it('ignores every crate the root entry ignores, unless exempted with a reason', () => {
152-
const missing = [...rootIgnored].filter(
153-
(name) => !eqlIgnored.has(name) && !EXEMPT.has(name),
154-
)
156+
const missing = unexempted(rootIgnored, eqlIgnored, EXEMPT)
155157
expect(
156158
missing,
157159
`the root cargo entry ignores these but the ${EQL_DIR} entry does not. The EQL workspace ` +
@@ -162,6 +164,17 @@ describe('the /packages/eql Dependabot entry ignores what it inherits from the r
162164
).toEqual([])
163165
})
164166

167+
it('counts an exemption only when it gives a reason', () => {
168+
const root = new Set(['recipher', 'cllw-ore', 'vitaminc*'])
169+
const eql = new Set()
170+
const exempt = new Map([
171+
['recipher', 'the EQL workspace resolves no crate that requires it'],
172+
['cllw-ore', ''],
173+
['vitaminc*', ' '],
174+
])
175+
expect(unexempted(root, eql, exempt)).toEqual(['cllw-ore', 'vitaminc*'])
176+
})
177+
165178
it('carries no stale exemption', () => {
166179
const stale = [...EXEMPT.keys()].filter(
167180
(name) => !rootIgnored.has(name) || eqlIgnored.has(name),

0 commit comments

Comments
 (0)