Skip to content
13 changes: 8 additions & 5 deletions .github/workflows/bazel-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ name: Bazel patch compatibility (npm)

# The npm flows of the real-Bazel tests (`npm::` in `e2e_bazel_build`):
# hosted and vendored mode for a package that aspect_rules_js links from a
# pnpm lock, agent mode for the copy of it in `node_modules`, and hosted
# pnpm lock (hosted mode with the lock routed through the patch's registry,
# pinned beside `trustLockfile: true`, and pinned beside a `patches` entry
# of the hub), agent mode for the copy of it in `node_modules`, and hosted
# mode on a hub that keeps the lock up to date with a pnpm of its own (a
# pnpm 11, and the pnpm 10 that rules_js picks), on each Bazel release
# below. bazel-compatibility.yml holds the legs and what
# every ecosystem shares; this file says when the npm legs run and on which
# releases.
# pnpm 11, and the pnpm 10 that rules_js picks), that hub also for a patch
# whose registry the patch service offers and for a scan that is told not
# to write `trustLockfile: true`, on each Bazel release below.
# bazel-compatibility.yml holds the legs and what every ecosystem shares;
# this file says when the npm legs run and on which releases.
#
# Beyond what every leg needs, an npm leg downloads Node from nodejs.org,
# ruleset archives from codeload.github.com and, for the hubs that keep
Expand Down
8 changes: 4 additions & 4 deletions crates/socket-patch-cli/CLI_CONTRACT.md

Large diffs are not rendered by default.

48 changes: 39 additions & 9 deletions crates/socket-patch-cli/tests/e2e_bazel_build/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,12 @@
//! the same.
//! - Bazel would read that file as a package of the user's workspace. The
//! crate has a dependency ([`DEP`]), so the file names a repository of
//! the hub, which the main repository does not see, and the commands
//! that analyse every target fail on it: `bazel cquery //...` and
//! `bazel query 'deps(//...)'` ([`analyses`]). The line that the scan
//! wrote into `.bazelignore` keeps the copies out of Bazel's packages:
//! the hub, which the main repository does not see, as it does not see
//! `platforms`, which the file names too. The commands that analyse
//! every target fail on the first of the two that Bazel meets:
//! `bazel cquery //...` and `bazel query 'deps(//...)'` ([`analyses`]).
//! The line that the scan wrote into `.bazelignore` keeps the copies out
//! of Bazel's packages:
//! `//...` is the user's own target ([`every_target`]), both commands
//! pass, and the build is the patched one, because the hub reads the
//! copy by its path, not as a package. A user who comments the line out
Expand Down Expand Up @@ -872,15 +874,42 @@ fn every_target(cell: &Cell) -> Vec<String> {
targets
}

/// Whether `stderr` says that the main repository does not see a
/// repository that the build file in the copy names: one of the hub, or
/// `platforms`. Bazel names the first one it meets, and which one that is
/// differs from run to run. The same words about another repository's view
/// are another failure.
fn unseen(stderr: &str) -> bool {
(stderr.split("No repository visible as '@").skip(1))
.filter_map(|rest| rest.split_once("' from main repository"))
.any(|(repo, _)| {
!repo.contains('\'') && (repo == "platforms" || repo.starts_with("crates__"))
})
}

/// [`unseen`] takes the two messages Bazel was seen to print, and neither
/// another repository's name nor another repository's view.
#[test]
fn an_unseen_repository_is_one_the_copy_names_and_the_main_repository_misses() {
let said = |repo: &str, from: &str| {
format!("ERROR: no such package: No repository visible as '@{repo}' from {from}\n")
};
assert!(unseen(&said("platforms", "main repository")));
assert!(unseen(&said("crates__dep-1.0.0", "main repository")));
assert!(!unseen(&said("rules_cc", "main repository")));
assert!(!unseen(&said("platforms", "repository '@@rules_rust+'")));
assert!(!unseen("Loading: 0 packages loaded\n"));
}

/// Whether the commands that analyse every target of the checkout of
/// `cell` pass: `bazel cquery //...` and `bazel query 'deps(//...)'`, which
/// agree. One that fails has met a repository of the hub, which the main
/// repository does not see.
/// agree. One that fails has met a repository that the build file in the
/// copy names and the main repository does not see ([`unseen`]).
fn analyses(cell: &Cell) -> bool {
let runs = [("cquery", "//..."), ("query", "deps(//...)")];
let runs = runs.map(|(command, targets)| cell.bazel(command, &[targets]));
for run in &runs {
let unseen = run.stderr().contains("No repository visible as '@crates__");
let unseen = unseen(&run.stderr());
assert_ne!(run.ok(), unseen, "{}: {}", cell.test, run.dump());
}
assert_eq!(runs[0].ok(), runs[1].ok(), "{}", cell.test);
Expand Down Expand Up @@ -1194,8 +1223,9 @@ fn vendored_from_cargo_with_config() {
// package: `//...` is the consumer alone, and the commands that analyse
// every target pass. A user who comments the line out has the package
// back, where the ruleset writes the build file: `//...` names targets
// there, those commands fail on the repository of the dependency, and
// the file Bazel now reads is a change of the copy again.
// there, those commands fail on a repository that the file names and
// the main repository does not see, and the file Bazel now reads is a
// change of the copy again.
assert_eq!(every_target(&cell), [CONSUMER], "{test}");
assert!(analyses(&cell), "{test}: under the line of the scan");
cell.write(".bazelignore", DECLINED);
Expand Down
Loading
Loading