GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Test vlt 1.4 pnpm-workspace.yaml members (#1564) · SocketDev/socket-patch@84c671a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • crates/socket-patch-core/src
    • hosted
      • governing_root.rs
    • vendor
      • npm_flavor.rs
    • vex/discover
      • mod.rs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: crates/socket-patch-core/src/hosted/governing_root.rs
+191Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,6 +2530,197 @@ mod tests {
25302530
assert_eq!(code(&tmp.path().join("packages/a"), "npm").await, None);
25312531
}
25322532

2533+
/// A `vlt-lock.json` whose edges leave from the given dep ids.
2534+
fn vlt_lock_with_edges(from: &[&str]) -> String {
2535+
let edges: Vec<String> = from
2536+
.iter()
2537+
.map(|id| format!(r#""{id} left-pad": "prod 1.3.0 [email protected]""#))
2538+
.collect();
2539+
format!(
2540+
"{{\n \"lockfileVersion\": 1,\n \"options\": {{}},\n \"nodes\": {{}},\n \"edges\": {{\n {}\n }}\n}}\n",
2541+
edges.join(",\n ")
2542+
)
2543+
}
2544+
2545+
/// #1564: vlt 1.4 reads a root `pnpm-workspace.yaml`'s `packages:` when
2546+
/// neither `vlt.json` nor `package.json` has a `workspaces` field, and
2547+
/// installs a member it lists from the root's `vlt-lock.json`. A member
2548+
/// is refused with or without a stray lock of its own, whether or not
2549+
/// the root has a `vlt.json` at all.
2550+
#[tokio::test]
2551+
async fn vlt_pnpm_workspace_yaml_member_is_refused() {
2552+
for vlt_json in [None, Some(r#"{"registries":{}}"#)] {
2553+
for stray in [false, true] {
2554+
let tmp = tempfile::tempdir().unwrap();
2555+
write(tmp.path(), "package.json", r#"{"private":true}"#);
2556+
if let Some(text) = vlt_json {
2557+
write(tmp.path(), VLT_JSON, text);
2558+
}
2559+
write(
2560+
tmp.path(),
2561+
PNPM_WORKSPACE,
2562+
"packages:\n - \"packages/*\"\n",
2563+
);
2564+
write(
2565+
tmp.path(),
2566+
VLT_LOCK,
2567+
&vlt_lock_with_edges(&["file~_d", "workspace~packages+a"]),
2568+
);
2569+
write(tmp.path(), "packages/a/package.json", "{}");
2570+
if stray {
2571+
write(tmp.path(), "packages/a/vlt-lock.json", "{}");
2572+
}
2573+
let member = tmp.path().join("packages/a");
2574+
let case = format!("vlt.json: {vlt_json:?}, stray: {stray}");
2575+
let refused = refusal(&ProjectView::Disk(&member), &[candidate("npm")], true)
2576+
.await
2577+
.unwrap_or_else(|| panic!("{case}: member must be refused"));
2578+
assert_eq!(refused.code, WORKSPACE_LOCKFILE_ELSEWHERE, "{case}");
2579+
assert!(
2580+
refused.message.contains(VLT_LOCK)
2581+
&& refused.message.contains("nothing was written"),
2582+
"{case}: {}",
2583+
refused.message
2584+
);
2585+
if !stray {
2586+
assert!(
2587+
refused.message.contains(PNPM_WORKSPACE),
2588+
"{case}: {}",
2589+
refused.message
2590+
);
2591+
}
2592+
assert_eq!(member_stray_lock(&member).await.is_some(), stray, "{case}");
2593+
assert_eq!(code(tmp.path(), "npm").await, None, "{case}");
2594+
2595+
// A member with its own vlt.json is its own vlt project.
2596+
write(tmp.path(), "packages/a/vlt.json", "{}");
2597+
assert!(member_stray_lock(&member).await.is_none(), "{case}");
2598+
if stray {
2599+
assert_eq!(code(&member, "npm").await, None, "{case}");
2600+
}
2601+
}
2602+
}
2603+
}
2604+
2605+
/// #1564: vlt 1.3.8 and older ignore `pnpm-workspace.yaml`, so a lock
2606+
/// with no edge from any directory its `packages:` list is theirs and
2607+
/// the directory is its own project. vlt 1.4 records an edge from every
2608+
/// member it installed that has a dependency. `vlt.json` and
2609+
/// `package.json` `workspaces` fields win over the file, as does a `!`
2610+
/// pattern in it; a root that was never installed governs nothing; a
2611+
/// lock that cannot be read keeps the refusing side.
2612+
#[tokio::test]
2613+
async fn vlt_pnpm_workspace_yaml_reads_the_root_lock() {
2614+
let listed = "packages:\n - \"packages/*\"\n";
2615+
for (case, vlt_json, package_json, yaml, root_lock, refused) in [
2616+
(
2617+
"vlt 1.4 lock",
2618+
None,
2619+
r#"{"private":true}"#,
2620+
listed,
2621+
Some(vlt_lock_with_edges(&["workspace~packages+b"])),
2622+
true,
2623+
),
2624+
(
2625+
"vlt 1.3.8 lock",
2626+
None,
2627+
r#"{"private":true}"#,
2628+
listed,
2629+
Some(vlt_lock_with_edges(&["file~_d"])),
2630+
false,
2631+
),
2632+
(
2633+
"empty lock",
2634+
None,
2635+
r#"{"private":true}"#,
2636+
listed,
2637+
Some(vlt_lock_with_edges(&[])),
2638+
false,
2639+
),
2640+
(
2641+
"unreadable lock",
2642+
None,
2643+
r#"{"private":true}"#,
2644+
listed,
2645+
Some("not json".to_string()),
2646+
true,
2647+
),
2648+
(
2649+
"never installed",
2650+
None,
2651+
r#"{"private":true}"#,
2652+
listed,
2653+
None,
2654+
false,
2655+
),
2656+
(
2657+
"package.json workspaces win",
2658+
None,
2659+
r#"{"private":true,"workspaces":["tools/*"]}"#,
2660+
listed,
2661+
Some(vlt_lock_with_edges(&["workspace~packages+a"])),
2662+
false,
2663+
),
2664+
(
2665+
"empty package.json workspaces win",
2666+
None,
2667+
r#"{"private":true,"workspaces":[]}"#,
2668+
listed,
2669+
Some(vlt_lock_with_edges(&["workspace~packages+a"])),
2670+
false,
2671+
),
2672+
(
2673+
"vlt.json workspaces win",
2674+
Some(r#"{"workspaces":"tools/*"}"#),
2675+
r#"{"private":true}"#,
2676+
listed,
2677+
Some(vlt_lock_with_edges(&["workspace~packages+a"])),
2678+
false,
2679+
),
2680+
(
2681+
"negated in the yaml",
2682+
None,
2683+
r#"{"private":true}"#,
2684+
"packages:\n - \"packages/*\"\n - \"!packages/a\"\n",
2685+
Some(vlt_lock_with_edges(&["workspace~packages+b"])),
2686+
false,
2687+
),
2688+
(
2689+
"not listed",
2690+
None,
2691+
r#"{"private":true}"#,
2692+
"packages:\n - \"tools/*\"\n",
2693+
Some(vlt_lock_with_edges(&["workspace~tools+x"])),
2694+
false,
2695+
),
2696+
] {
2697+
for stray in [false, true] {
2698+
let tmp = tempfile::tempdir().unwrap();
2699+
write(tmp.path(), "package.json", package_json);
2700+
if let Some(text) = vlt_json {
2701+
write(tmp.path(), VLT_JSON, text);
2702+
}
2703+
write(tmp.path(), PNPM_WORKSPACE, yaml);
2704+
if let Some(text) = &root_lock {
2705+
write(tmp.path(), VLT_LOCK, text);
2706+
}
2707+
write(tmp.path(), "packages/a/package.json", "{}");
2708+
write(tmp.path(), "packages/b/package.json", "{}");
2709+
if stray {
2710+
write(tmp.path(), "packages/a/vlt-lock.json", "{}");
2711+
}
2712+
let member = tmp.path().join("packages/a");
2713+
let case = format!("{case}, stray: {stray}");
2714+
assert_eq!(code(&member, "npm").await.is_some(), refused, "{case}");
2715+
assert_eq!(
2716+
member_stray_lock(&member).await.is_some(),
2717+
refused && stray,
2718+
"{case}"
2719+
);
2720+
}
2721+
}
2722+
}
2723+
25332724
/// The nearer of a `vlt.json` root and a `package.json` root governs.
25342725
#[tokio::test]
25352726
async fn nearer_of_vlt_and_package_json_roots_is_named() {
Collapse file

‎crates/socket-patch-core/src/vendor/npm_flavor.rs‎

Copy file name to clipboardExpand all lines: crates/socket-patch-core/src/vendor/npm_flavor.rs
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,6 +1919,7 @@ mod tests {
19191919
async fn bun_and_vlt_members_with_stray_lock_are_refused() {
19201920
const BUN_TEXT: &str = "{\n \"lockfileVersion\": 1\n}\n";
19211921
const VLT_TEXT: &str = r#"{"lockfileVersion":1,"options":{},"nodes":{},"edges":{}}"#;
1922+
const VLT_PNPM_WORKSPACE_TEXT: &str = r#"{"lockfileVersion":1,"options":{},"nodes":{},"edges":{"workspace~packages+a left-pad":"prod 1.3.0 [email protected]"}}"#;
19221923
let pj_workspace = r#"{"name":"root","private":true,"workspaces":["packages/*"]}"#;
19231924
for (member_lock, member_text, root_files) in [
19241925
(
@@ -1956,6 +1957,19 @@ mod tests {
19561957
("vlt-lock.json", VLT_TEXT),
19571958
],
19581959
),
1960+
// #1564: vlt 1.4 reads `pnpm-workspace.yaml` `packages:` when
1961+
// neither `vlt.json` nor `package.json` declares `workspaces`;
1962+
// the root lock's member edge shows vlt 1.4 installed it.
1963+
(
1964+
"vlt-lock.json",
1965+
VLT_TEXT,
1966+
vec![
1967+
("package.json", r#"{"name":"root","private":true}"#),
1968+
("vlt.json", r#"{"registries":{}}"#),
1969+
("pnpm-workspace.yaml", "packages:\n - \"packages/*\"\n"),
1970+
("vlt-lock.json", VLT_PNPM_WORKSPACE_TEXT),
1971+
],
1972+
),
19591973
] {
19601974
let (tmp, record) = npm_project().await;
19611975
tokio::fs::remove_file(tmp.path().join("package-lock.json"))
Collapse file

‎crates/socket-patch-core/src/vex/discover/mod.rs‎

Copy file name to clipboardExpand all lines: crates/socket-patch-core/src/vex/discover/mod.rs
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5416,6 +5416,20 @@ mod member_stray_lock_tests {
54165416
("vlt-lock.json", "{}"),
54175417
][..],
54185418
),
5419+
// #1564: vlt 1.4's `pnpm-workspace.yaml` `packages:` source,
5420+
// shown by the root lock's edge from the member.
5421+
(
5422+
"redirect/npm/vlt/basic/expected",
5423+
"vlt-lock.json",
5424+
"aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa",
5425+
&[
5426+
("pnpm-workspace.yaml", "packages:\n - packages/*\n"),
5427+
(
5428+
"vlt-lock.json",
5429+
r#"{"lockfileVersion":1,"options":{},"nodes":{},"edges":{"workspace~packages+a left-pad":"prod 1.3.0 [email protected]"}}"#,
5430+
),
5431+
][..],
5432+
),
54195433
(
54205434
"redirect/npm/package-lock-v3/basic/expected",
54215435
"package-lock.json",

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.