Skip to content

Commit ef78390

Browse files
committed
Add failing tests for vlt workspace globs
vlt expands extglobs in workspaces and reads ! patterns differently from npm (1.3 drops excluded dirs wherever the ! sits until a later pattern relists them; 1.2 reads a leading ! literally). These tests pin what vlt 1.2.0 and 1.3.8 actually list (#1542). Assisted-by: Claude Code:claude-opus-5-5
1 parent 9436119 commit ef78390

2 files changed

Lines changed: 202 additions & 1 deletion

File tree

‎crates/socket-patch-core/src/hosted/governing_root.rs‎

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,6 +2143,145 @@ mod tests {
21432143
}
21442144
}
21452145

2146+
/// #1542: vlt expands extglobs in `workspaces` (vlt 1.2.0 and 1.3.8
2147+
/// install `packages/a` as a member of `packages/+(a|b)` and
2148+
/// `packages/@(a|b)`), so a member listed through one is refused, with
2149+
/// or without a stray lock of its own, whether the patterns sit in
2150+
/// `vlt.json` or in the `package.json` fallback.
2151+
#[tokio::test]
2152+
async fn vlt_extglob_member_is_refused() {
2153+
for pattern in ["packages/+(a|b)", "packages/@(a|b)"] {
2154+
for package_json_fallback in [false, true] {
2155+
for stray in [false, true] {
2156+
let tmp = tempfile::tempdir().unwrap();
2157+
let list = serde_json::json!([pattern]).to_string();
2158+
if package_json_fallback {
2159+
write(
2160+
tmp.path(),
2161+
"package.json",
2162+
&format!(r#"{{"private":true,"workspaces":{list}}}"#),
2163+
);
2164+
write(tmp.path(), "vlt.json", r#"{"registries":{}}"#);
2165+
} else {
2166+
write(tmp.path(), "package.json", r#"{"private":true}"#);
2167+
write(tmp.path(), "vlt.json", &format!(r#"{{"workspaces":{list}}}"#));
2168+
}
2169+
write(tmp.path(), VLT_LOCK, "{}");
2170+
write(tmp.path(), "packages/a/package.json", "{}");
2171+
write(tmp.path(), "packages/c/package.json", "{}");
2172+
if stray {
2173+
write(tmp.path(), "packages/a/vlt-lock.json", "{}");
2174+
write(tmp.path(), "packages/c/vlt-lock.json", "{}");
2175+
}
2176+
let case = format!(
2177+
"{pattern}, package.json fallback: {package_json_fallback}, stray: {stray}"
2178+
);
2179+
let member = tmp.path().join("packages/a");
2180+
assert_eq!(
2181+
code(&member, "npm").await.as_deref(),
2182+
Some(WORKSPACE_LOCKFILE_ELSEWHERE),
2183+
"{case}"
2184+
);
2185+
assert_eq!(
2186+
member_stray_lock(&member).await.is_some(),
2187+
stray,
2188+
"{case}"
2189+
);
2190+
// `packages/c` is not listed: its own lock governs it.
2191+
let other = tmp.path().join("packages/c");
2192+
assert_eq!(code(&other, "npm").await, None, "{case}");
2193+
assert!(member_stray_lock(&other).await.is_none(), "{case}");
2194+
}
2195+
}
2196+
}
2197+
}
2198+
2199+
/// #1542: vlt 1.3 drops a `!`-excluded directory wherever the `!`
2200+
/// pattern sits, while vlt before 1.3 ignores `!` patterns and lists
2201+
/// it. Both write the same lock, so the root's `vlt-lock.json` decides:
2202+
/// vlt records an edge from every member it installed that has a
2203+
/// dependency, so a lock with edges from the excluded member, or from
2204+
/// any other directory only older vlt lists, is older vlt's and the
2205+
/// member is refused. A lock that cannot be read keeps the wider
2206+
/// reading.
2207+
#[tokio::test]
2208+
async fn vlt_negated_member_reads_the_root_lock() {
2209+
let lock = |from: &[&str]| {
2210+
let edges: Vec<String> = from
2211+
.iter()
2212+
.map(|id| format!(r#""{id} left-pad": "prod 1.3.0 ~npm~left-pad@1.3.0""#))
2213+
.collect();
2214+
format!(
2215+
"{{\n \"lockfileVersion\": 1,\n \"options\": {{}},\n \"nodes\": {{}},\n \"edges\": {{\n {}\n }}\n}}\n",
2216+
edges.join(",\n ")
2217+
)
2218+
};
2219+
for (workspaces, root_lock, refused) in [
2220+
// vlt 1.3: `packages/a` is excluded wherever the `!` sits.
2221+
(r#"["!packages/a","packages/*"]"#, lock(&[]), false),
2222+
(r#"["packages/*","!packages/a"]"#, lock(&[]), false),
2223+
(
2224+
r#"["packages/*","!packages/a"]"#,
2225+
lock(&["workspace~packages+b"]),
2226+
false,
2227+
),
2228+
// A later pattern whose text the `!` matches lists it again.
2229+
(r#"["packages/*","!packages/a","packages/a"]"#, lock(&[]), true),
2230+
(r#"["!packages/*","packages/a"]"#, lock(&[]), true),
2231+
// vlt 1.2 installed the excluded member (or another one).
2232+
(
2233+
r#"["!packages/a","packages/*"]"#,
2234+
lock(&["workspace~packages+a"]),
2235+
true,
2236+
),
2237+
(
2238+
r#"["packages/*","!packages/a","!packages/z"]"#,
2239+
lock(&["workspace~packages+z"]),
2240+
true,
2241+
),
2242+
// An unreadable lock keeps the wider reading.
2243+
(r#"["!packages/a","packages/*"]"#, "not json".to_string(), true),
2244+
] {
2245+
let tmp = tempfile::tempdir().unwrap();
2246+
write(tmp.path(), "package.json", r#"{"private":true}"#);
2247+
write(
2248+
tmp.path(),
2249+
"vlt.json",
2250+
&format!(r#"{{"workspaces":{workspaces}}}"#),
2251+
);
2252+
write(tmp.path(), VLT_LOCK, &root_lock);
2253+
write(tmp.path(), "packages/a/package.json", "{}");
2254+
write(tmp.path(), "packages/a/vlt-lock.json", "{}");
2255+
let member = tmp.path().join("packages/a");
2256+
let case = format!("{workspaces} with {root_lock:?}");
2257+
assert_eq!(
2258+
code(&member, "npm").await.is_some(),
2259+
refused,
2260+
"{case}"
2261+
);
2262+
assert_eq!(member_stray_lock(&member).await.is_some(), refused, "{case}");
2263+
}
2264+
}
2265+
2266+
/// #1542: vlt globs each named `workspaces` group on its own, so a `!`
2267+
/// pattern in one group does not exclude what another group lists.
2268+
#[tokio::test]
2269+
async fn vlt_negation_stays_in_its_group() {
2270+
let tmp = tempfile::tempdir().unwrap();
2271+
write(tmp.path(), "package.json", r#"{"private":true}"#);
2272+
write(
2273+
tmp.path(),
2274+
"vlt.json",
2275+
r#"{"workspaces":{"libs":["!packages/a"],"apps":["packages/*"]}}"#,
2276+
);
2277+
write(tmp.path(), VLT_LOCK, "{}");
2278+
write(tmp.path(), "packages/a/package.json", "{}");
2279+
assert_eq!(
2280+
code(&tmp.path().join("packages/a"), "npm").await.as_deref(),
2281+
Some(WORKSPACE_LOCKFILE_ELSEWHERE)
2282+
);
2283+
}
2284+
21462285
/// #1101: Bun installs every `package.json` workspace member from the
21472286
/// root's `bun.lock` / `bun.lockb` and never reads a lock inside the
21482287
/// member, so a stray member Bun lock does not make the member its own

‎crates/socket-patch-core/src/utils/workspace_globs.rs‎

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ impl WorkspacesDialect {
9191
extglob: false,
9292
picomatch: false,
9393
};
94+
#[allow(dead_code)]
95+
pub(crate) const VLT_PRE_1_3: Self = Self::VLT;
9496
/// Every dialect, for a root whose package manager is unknown: it lists
9597
/// a directory when any of them does.
9698
pub(crate) const ALL: [Self; 6] = [
@@ -1145,7 +1147,8 @@ mod tests {
11451147
for (dialect, last, first, again) in [
11461148
(D::NPM, false, true, true),
11471149
(D::BUN, false, true, true),
1148-
(D::VLT, false, true, true),
1150+
(D::VLT, false, false, true),
1151+
(D::VLT_PRE_1_3, true, true, true),
11491152
(D::YARN_BERRY, false, false, false),
11501153
(D::YARN_CLASSIC, true, true, true),
11511154
(D::BUN_PRE_1_3, true, true, true),
@@ -1230,6 +1233,65 @@ mod tests {
12301233
));
12311234
}
12321235

1236+
/// #1542: vlt reads `workspaces` with node-glob / minimatch, probed on
1237+
/// vlt 1.2.0 and 1.3.8 (`vlt install` then `vlt query ':workspace'`
1238+
/// over `packages/{a,b,ab,c,.h}`): extglobs match, and wildcards skip a
1239+
/// component that starts with `.`. vlt 1.3 drops a `!` pattern's
1240+
/// directories wherever the pattern sits, until a later pattern whose
1241+
/// own text it matches lists them again (`splitNegatedPatterns`); vlt
1242+
/// before 1.3 reads a leading `!` literally, so `!x` lists nothing and
1243+
/// `!(..)` is an extglob.
1244+
#[test]
1245+
fn vlt_dialects_list_what_vlt_lists() {
1246+
use WorkspacesDialect as D;
1247+
let rel = |p: &str| p.split('/').map(str::to_string).collect::<Vec<_>>();
1248+
let pats = |p: &[&str]| p.iter().map(|s| s.to_string()).collect::<Vec<_>>();
1249+
// (patterns, directory, vlt 1.3 lists it, vlt 1.2 lists it)
1250+
for (patterns, dir, current, pre_1_3) in [
1251+
(&["packages/+(a|b)"][..], "packages/a", true, true),
1252+
(&["packages/+(a|b)"], "packages/ab", true, true),
1253+
(&["packages/+(a|b)"], "packages/c", false, false),
1254+
(&["packages/@(a|b)"], "packages/b", true, true),
1255+
(&["packages/@(a|b)"], "packages/ab", false, false),
1256+
(&["packages/?(a)b"], "packages/ab", true, true),
1257+
(&["packages/*(a)"], "packages/a", true, true),
1258+
(&["packages/*(a)"], "packages/b", false, false),
1259+
(&["packages/!(a)"], "packages/b", true, true),
1260+
(&["packages/!(a)"], "packages/a", false, false),
1261+
(&["packages/(a|b)"], "packages/a", false, false),
1262+
(&["packages/{a,b}"], "packages/a", true, true),
1263+
(&["packages/[ab]"], "packages/b", true, true),
1264+
(&["packages/*"], "packages/.h", false, false),
1265+
(&["**"], ".gh/x", false, false),
1266+
(&["packages/.h"], "packages/.h", true, true),
1267+
(&["!packages/a", "packages/*"], "packages/a", false, true),
1268+
(&["!packages/a", "packages/*"], "packages/b", true, true),
1269+
(&["packages/*", "!packages/a"], "packages/a", false, true),
1270+
(&["packages/*", "!packages/a", "packages/a"], "packages/a", true, true),
1271+
(&["packages/*", "!packages/a", "packages/[a]"], "packages/a", false, true),
1272+
(&["!packages/*", "packages/a"], "packages/a", true, true),
1273+
(&["packages/a", "!packages/*"], "packages/a", false, true),
1274+
(&["!packages/a", "packages/@(a|b)"], "packages/a", false, true),
1275+
(&["!packages/@(a|b)", "packages/a"], "packages/a", true, true),
1276+
(&["!!packages/a"], "packages/a", true, false),
1277+
(&["!(apps)/a"], "packages/a", false, true),
1278+
(&["packages/*", "!(apps)/a"], "packages/a", true, true),
1279+
] {
1280+
let patterns = pats(patterns);
1281+
let dir = rel(dir);
1282+
assert_eq!(
1283+
workspaces_include_as(&patterns, &dir, D::VLT),
1284+
current,
1285+
"vlt 1.3: {patterns:?} ~ {dir:?}"
1286+
);
1287+
assert_eq!(
1288+
workspaces_include_as(&patterns, &dir, D::VLT_PRE_1_3),
1289+
pre_1_3,
1290+
"vlt 1.2: {patterns:?} ~ {dir:?}"
1291+
);
1292+
}
1293+
}
1294+
12331295
#[test]
12341296
fn pnpm_wildcards_skip_dot_components() {
12351297
let rel = |p: &str| p.split('/').map(str::to_string).collect::<Vec<_>>();

0 commit comments

Comments
 (0)