Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions .github/workflows/bazel-go.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name: Bazel patch compatibility (Go)

# The Go flow of the real-Bazel tests (`go::` in `e2e_bazel_build`): hosted
# mode for a module that gazelle's `go_deps` resolves from `go.mod`, on
# each Bazel release below. bazel-compatibility.yml holds the legs and what
# every ecosystem shares; this file says when the Go legs run and on which
# releases.
# The Go flows of the real-Bazel tests (`go::` in `e2e_bazel_build`):
# hosted, vendored and agent mode for a module that gazelle's `go_deps`
# resolves from `go.mod`, on each Bazel release below.
# bazel-compatibility.yml holds the legs and what every ecosystem shares;
# this file says when the Go legs run and on which releases.
#
# Beyond what every leg needs, a Go leg downloads the Go SDK from
# dl.google.com (about 100 MB, held by its repository cache) and asks go.dev
# for the Go release list on every run. A Go module under test never comes
# from the repository cache: `go` fetches a module into the output base,
# which every test makes anew.
# which every test makes anew. The same holds for the modules gazelle is
# built from, which a test that runs `bazel run //:gazelle` has `go` fetch
# from proxy.golang.org.
#
# Not required for merge: no `merge_group` trigger, and no job here is a
# `needs` of ci.yml's `ci-ok`.
Expand All @@ -20,12 +22,18 @@ on:
types: [opened, synchronize, reopened, ready_for_review]
# What a pull request run covers: the Go flow and its fixture, the
# harness and the workflows that run it, the Bazel installer and its
# pins, and the Go files the flow runs through, as go-compatibility.yml
# lists them. Nothing another ecosystem's flow owns is here, so a change
# to one ecosystem starts that ecosystem's legs only.
# pins, the Go files the flow runs through, as go-compatibility.yml
# lists them, what socket-patch does only in a Bazel workspace
# (`bazel/`), and the VEX code: `vex/` of the core and the files of the
# `vex` command. Every flow holds the exact document socket-patch writes
# about its patched build, so a change to how a document is built or
# worded starts the legs of every ecosystem. Nothing else that another
# ecosystem's flow owns is here, so any other change to one ecosystem
# starts that ecosystem's legs only.
#
# What it does not cover: shared engine code (patch/redirect/mod.rs,
# hosted/, commands/), the shared test helpers and the toolchain files.
# hosted/, the rest of commands/), the shared test helpers and the
# toolchain files.
# A change there gets its run on the push to main (when the file is in
# the list below) or in the nightly run, not on the pull request: that
# is the price of not running every ecosystem's legs on every shared
Expand All @@ -41,6 +49,9 @@ on:
- 'crates/*/src/**/*golang*'
- 'crates/*/src/**/*golang*/**'
- 'crates/socket-patch-core/src/vendor/go*.rs'
- 'crates/socket-patch-core/src/bazel/**'
- 'crates/socket-patch-core/src/vex/**'
- 'crates/socket-patch-cli/src/commands/vex*.rs'
push:
branches: [main]
# The pull request paths, and what only a push to main covers: the
Expand All @@ -60,6 +71,9 @@ on:
- 'crates/*/src/**/*golang*'
- 'crates/*/src/**/*golang*/**'
- 'crates/socket-patch-core/src/vendor/go*.rs'
- 'crates/socket-patch-core/src/bazel/**'
- 'crates/socket-patch-core/src/vex/**'
- 'crates/socket-patch-cli/src/commands/vex*.rs'
- 'crates/socket-patch-cli/tests/e2e_bazel_build/main.rs'
- 'crates/socket-patch-core/src/patch/redirect/**'
- 'crates/socket-patch-core/src/hosted/**'
Expand Down
27 changes: 17 additions & 10 deletions .github/workflows/bazel-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@ on:
# Its walk of the pnpm workspace decides what the second run of each
# flow reports, and no other test runs it beside Bazel's links. That
# file also holds the Composer, Cargo and Go parts of the gate, so a
# change to those starts the npm legs too. The
# globs name that one crate, so no bench fixture is here, and nothing
# another ecosystem's flow owns: a change to one ecosystem starts that
# ecosystem's legs only.
# change to those starts the npm legs too. The `*pnpm*` globs name that
# one crate, so no bench fixture is here. Last, the VEX code: `vex/` of
# the core and the files of the `vex` command. Every flow holds the
# exact document socket-patch writes about its patched build, so a
# change to how a document is built or worded starts the legs of every
# ecosystem. Nothing else that another ecosystem's flow owns is here:
# any other change to one ecosystem starts that ecosystem's legs only.
#
# What it does not cover: shared engine code (patch/redirect/mod.rs,
# the rest of vendor/, hosted/, commands/), the shared test helpers and
# the toolchain files. A change there gets its run on the push to main
# (when the file is in the list below) or in the nightly run, not on the
# pull request: that is the price of not running every ecosystem's legs
# on every shared change. On demand, workflow_dispatch runs the legs on
# any branch.
# the rest of vendor/, hosted/, the rest of commands/), the shared test
# helpers and the toolchain files. A change there gets its run on the
# push to main (when the file is in the list below) or in the nightly
# run, not on the pull request: that is the price of not running every
# ecosystem's legs on every shared change. On demand, workflow_dispatch
# runs the legs on any branch.
paths:
- '.github/workflows/bazel-npm.yml'
- '.github/workflows/bazel-compatibility.yml'
Expand All @@ -66,6 +69,8 @@ on:
- 'crates/socket-patch-core/src/crawlers/npm_crawler.rs'
- 'crates/socket-patch-core/src/formats/package_json.rs'
- 'crates/socket-patch-core/src/patch/user_patches.rs'
- 'crates/socket-patch-core/src/vex/**'
- 'crates/socket-patch-cli/src/commands/vex*.rs'
push:
branches: [main]
# The pull request paths, and what only a push to main covers: the
Expand All @@ -92,6 +97,8 @@ on:
- 'crates/socket-patch-core/src/crawlers/npm_crawler.rs'
- 'crates/socket-patch-core/src/formats/package_json.rs'
- 'crates/socket-patch-core/src/patch/user_patches.rs'
- 'crates/socket-patch-core/src/vex/**'
- 'crates/socket-patch-cli/src/commands/vex*.rs'
- 'crates/socket-patch-cli/tests/e2e_bazel_build/main.rs'
- 'crates/socket-patch-core/src/patch/redirect/**'
- 'crates/socket-patch-core/src/vendor/**'
Expand Down
20 changes: 14 additions & 6 deletions .github/workflows/bazel-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ on:
# `*python*` pattern would also match the benchmark fixtures, the rest
# of vendored mode and the files of the lock-file package managers
# (pdm, pipenv, poetry, uv), where this flow does no more than find
# that the project is not theirs. Nothing another ecosystem's flow owns
# is here, so a change to one ecosystem starts that ecosystem's legs
# only. Three PyPI helpers that those files call, and that are no other
# project manager's own, are listed with them: the finder of a
# project's Python lock files, the spelling of a version in a wheel's
# file name, and the hosted scan's check of an installed wheel.
# that the project is not theirs. Three PyPI helpers that those files
# call, and that are no other project manager's own, are listed with
# them: the finder of a project's Python lock files, the spelling of a
# version in a wheel's file name, and the hosted scan's check of an
# installed wheel. Last, the VEX code: `vex/` of the core and the files
# of the `vex` command. Every flow holds the exact document socket-patch
# writes about its patched build, so a change to how a document is built
# or worded starts the legs of every ecosystem. Nothing else that
# another ecosystem's flow owns is here, so any other change to one
# ecosystem starts that ecosystem's legs only.
#
# What it does not cover: shared engine code (patch/redirect/mod.rs,
# the rest of hosted/ and of commands/), the shared test helpers and the
Expand Down Expand Up @@ -69,6 +73,8 @@ on:
- 'crates/socket-patch-core/src/vendor/pypi_requirements.rs'
- 'crates/socket-patch-core/src/vendor/pypi_wheel.rs'
- 'crates/socket-patch-core/src/vex/discover/pypi_other.rs'
- 'crates/socket-patch-core/src/vex/**'
- 'crates/socket-patch-cli/src/commands/vex*.rs'
push:
branches: [main]
# The pull request paths, and what only a push to main covers: the
Expand Down Expand Up @@ -100,6 +106,8 @@ on:
- 'crates/socket-patch-core/src/vendor/pypi_requirements.rs'
- 'crates/socket-patch-core/src/vendor/pypi_wheel.rs'
- 'crates/socket-patch-core/src/vex/discover/pypi_other.rs'
- 'crates/socket-patch-core/src/vex/**'
- 'crates/socket-patch-cli/src/commands/vex*.rs'
- 'crates/socket-patch-cli/tests/e2e_bazel_build/main.rs'
- 'crates/socket-patch-core/src/patch/redirect/**'
- 'crates/socket-patch-core/src/hosted/**'
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/bazel-ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ on:
# (formats/gem), lock discovery, the lock inventory, the Ruby crawler
# (it says which lock Bundler loads), the upstream restore of
# `rollback`, and the stale-install guard that both commands end with.
# Nothing another ecosystem's flow owns is here, so a change to one
# ecosystem starts that ecosystem's legs only.
# Last, the VEX code: `vex/` of the core and the files of the `vex`
# command. Every flow holds the exact document socket-patch writes about
# its patched build, so a change to how a document is built or worded
# starts the legs of every ecosystem. Nothing else that another
# ecosystem's flow owns is here, so any other change to one ecosystem
# starts that ecosystem's legs only.
#
# What it does not cover: shared engine code. The other half of the
# hosted rewrite is there (`rewrite_gem` and its planner in
Expand Down Expand Up @@ -60,6 +64,8 @@ on:
- 'crates/socket-patch-core/src/crawlers/ruby_crawler.rs'
- 'crates/socket-patch-core/src/patch/redirect/upstream/gem.rs'
- 'crates/*/src/**/gem_refresh.rs'
- 'crates/socket-patch-core/src/vex/**'
- 'crates/socket-patch-cli/src/commands/vex*.rs'
push:
branches: [main]
# The pull request paths, and what only a push to main covers: the
Expand All @@ -82,6 +88,8 @@ on:
- 'crates/socket-patch-core/src/crawlers/ruby_crawler.rs'
- 'crates/socket-patch-core/src/patch/redirect/upstream/gem.rs'
- 'crates/*/src/**/gem_refresh.rs'
- 'crates/socket-patch-core/src/vex/**'
- 'crates/socket-patch-cli/src/commands/vex*.rs'
- 'crates/socket-patch-cli/tests/e2e_bazel_build/main.rs'
- 'crates/socket-patch-core/src/vendor/gem.rs'
- 'crates/socket-patch-core/src/patch/redirect/**'
Expand Down
1 change: 1 addition & 0 deletions crates/socket-patch-cli/CLI_CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,7 @@ command's integration tests check its output.
| `redirect_withdrawn_restore_failed` | `warnings[]` (warning; human: `Warning: …` / `Error: …`) | scan `--mode hosted`: a pin whose patch is `withdrawn` / `not_found` could not be restored to its upstream registry entry (the restore refused it, writing the restored files failed, or the apply lock was held). The pin is kept and no `rolledBack` event is recorded for it; the detail names the remedy (`git checkout -- <lockfile>`, or re-run / `socket-patch rollback <purl>`). A write failure is one warning naming every pin it kept. Status and exit unchanged, unless the failed write could not put a file back: see `lockfile_write_failed`. |
| `patch_withdrawn` | `rolledBack` / `verified` (hosted event) | scan `--mode hosted`: the lockfile pinned a patch the server reports `withdrawn` or `not_found`; the pin was restored (dry run: would be) to its upstream registry entry. `reason` names the uuid and status. See "Withdrawn pins". |
| `vendor_prebuilt_stub_invalid` | `failed` | RubyGems: the server stub lacks required attributes or is otherwise invalid; no local stub fallback is permitted. |
| `bazelignore_not_updated` | run-level `warnings[]` | Go vendored and agent mode in a Bazel workspace (additive): the `.bazelignore` at the Bazel root, which keeps Bazel and gazelle out of the module copies under `.socket/vendor/golang` and `.socket/go-patches`, was not updated. It could not be read or written (a symbolic link or a directory in its place, a read-only directory, a read-only file). The detail names the line to add, or says that the lines of a copy that is gone can be deleted; the command's patch or undo stands and its exit code is unchanged. See docs/ecosystems.md "Bazel workspaces: `.bazelignore`". |
| `vendor_*` / `pypi_*` / `gemfile_*` / `lock_*` / `locked_version_mismatch` / `user_authored_*` / `native_extensions_unsupported` / `platform_gem_unsupported` | `failed`/`skipped` | vendor: per-ecosystem refusal + drift vocabulary; see the Vendor command contract section. New tags are additive (MINOR). |

`user_patch_conflict` is a `skipped` event and a scan/apply run warning for packages
Expand Down
3 changes: 3 additions & 0 deletions crates/socket-patch-cli/src/commands/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,9 @@ pub(crate) async fn run_locked(
}
}
}
// The copies under `.socket/go-patches` are as this run leaves
// them (a reconcile may have removed the last one).
run_warnings.extend(crate::commands::sync_bazelignore(&args.common, true).await);

// Human per-package report BEFORE the embedded VEX runs, so
// the VEX step's own notes follow the report instead of
Expand Down
58 changes: 58 additions & 0 deletions crates/socket-patch-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,64 @@ pub(crate) fn project_state_in_scope(common: &crate::args::GlobalArgs) -> bool {
!common.is_global()
}

/// In a Bazel workspace the root's `.bazelignore` names the directories of
/// the project's patched Go module copies, so that Bazel and gazelle read
/// no package there (`socket_patch_core::bazel::ignore`). A command that can
/// write or remove such a copy calls this once, after the last step that
/// can change a copy or take one back and before it gives up its apply
/// lock. Nothing is done in a dry run or a `--global` run, and a run whose
/// `--ecosystems` leaves `golang` out only takes away the pair of a copy
/// that is gone. So does the prune pass of a scan, which comes here after
/// its scan has (`adds` false) and can only have removed a copy: a file
/// it cannot write is left to the next command's warning.
///
/// A human run is told here that the file changed, or why it could not be;
/// the result is that warning again, for the command's envelope.
pub(crate) async fn sync_bazelignore(
common: &crate::args::GlobalArgs,
adds: bool,
) -> Vec<crate::json_envelope::RunWarning> {
use socket_patch_core::{bazel::ignore, crawlers::Ecosystem::Golang};
let mut warnings = Vec::new();
if common.dry_run || common.is_global() {
return warnings;
}
// The agent copies are those of `--cwd`, the vendored ones those of
// the manifest's project. A root both are under is named once.
let mut projects = vec![common.cwd.clone()];
if common.manifest_project_is_foreign() {
projects.push(common.project_root());
}
let (loud, mut told) = (!common.json && !common.silent, Vec::new());
for project in projects {
match ignore::sync(&project, adds && common.ecosystem_selected(Golang)).await {
Ok(Some(file)) if loud && !told.contains(&file) => {
let (verb, what) = match file.exists() {
true => (
"Updated",
"the lines that keep patched Go module copies under .socket out of \
Bazel's packages",
),
false => ("Removed", "no patched Go module copy is left under .socket"),
};
println!("{verb} {}: {what}", file.display());
told.push(file);
}
Err(detail) if adds => {
if loud {
eprintln!("Warning: {detail}");
}
warnings.push(crate::json_envelope::RunWarning::new(
ignore::NOT_UPDATED,
detail,
));
}
_ => {}
}
}
warnings
}

/// The vendor-ledger keys (`ledger`, the project's
/// [`VendorState::purl_keys`]) that own this run's installed copies. In
/// project scope that is the whole ledger. Under global scope the ledger
Expand Down
8 changes: 7 additions & 1 deletion crates/socket-patch-cli/src/commands/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,11 @@ pub async fn run(args: RemoveArgs) -> i32 {
// Artifacts the sweep examined (repair's `details.checked`), and the
// passes that failed (`cleanup_failed` run warnings under `--json`).
let mut gc_checked = 0usize;
let mut cleanup_warnings: Vec<(String, String)> = Vec::new();
// The rollback, the vendored revert and the orphan sweep above are
// done with the Go copies.
let ignored = crate::commands::sync_bazelignore(&args.common, true).await;
let mut cleanup_warnings: Vec<(String, String)> =
ignored.into_iter().map(|w| (w.code, w.detail)).collect();
if !args.preserve_state {
let sweep = references.sweep(&socket_dir, args.common.dry_run).await;
// repair's posture: a failed pass (or a pass that could not unlink
Expand Down Expand Up @@ -1860,6 +1864,8 @@ async fn remove_ledger_only(
let mut env = Envelope::new(Command::Remove);
env.dry_run = args.common.dry_run;
env.warnings.extend(commit_recovery);
env.warnings
.extend(crate::commands::sync_bazelignore(&args.common, true).await);
// The reverts ARE the removal: every event is recorded, so
// `summary.removed` counts the reverted entries (`summary.verified`
// the would-be removals on --dry-run).
Expand Down
4 changes: 4 additions & 0 deletions crates/socket-patch-cli/src/commands/repair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ pub async fn run(args: RepairArgs) -> i32 {
// client's public-proxy advisory ahead of its own output.
let mut client: Option<ApiClient> = None;
let result = repair_inner(&args, &manifest_path, &mut client, vendor_references).await;
// A vendored Go copy may be back on disk, also when the repair failed.
let ignored = crate::commands::sync_bazelignore(&args.common, true).await;
let auth_fallback = client
.as_ref()
.and_then(crate::commands::vex_sources::api_auth_fallback_warning);
Expand All @@ -224,6 +226,7 @@ pub async fn run(args: RepairArgs) -> i32 {
Ok((mut env, counts)) => {
env.warnings.extend(commit_recovery);
env.warnings.extend(auth_fallback);
env.warnings.extend(ignored);
let had_failure = matches!(env.status, Status::PartialFailure | Status::Error);
if had_failure {
track_patch_repair_failed("One or more artifacts failed to download", &telemetry)
Expand All @@ -248,6 +251,7 @@ pub async fn run(args: RepairArgs) -> i32 {
let mut env =
error_envelope(Command::Repair, args.common.dry_run, &e.code, &e.message);
env.warnings.extend(commit_recovery);
env.warnings.extend(ignored);
crate::ui::print_json(&env.to_value());
} else {
eprintln!("Error: {}", e.message);
Expand Down
3 changes: 3 additions & 0 deletions crates/socket-patch-cli/src/commands/rollback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2671,6 +2671,9 @@ async fn run_project(args: RollbackArgs, below: BelowNotes) -> i32 {
.iter()
.chain(hosted_leg.warnings.iter())
.for_each(|(code, detail)| run_warnings.push((code.clone(), detail.clone())));
// Every leg and the orphan sweep are done with the Go copies.
let ignored = crate::commands::sync_bazelignore(&args.common, true).await;
run_warnings.extend(ignored.into_iter().map(|w| (w.code, w.detail)));
// A restored package whose ownership could not be put back, or
// whose stale bytecode could not be removed (the engine reports
// it on `error` with `success: true`), is restored but worth a
Expand Down
Loading
Loading