Skip to content

Commit 11e501d

Browse files
committed
Merge remote-tracking branch 'origin/main' into pr2006
# Conflicts: # crates/socket-patch-core/src/vendor/jvm/apply.rs
2 parents 9949a3b + 7bacb8b commit 11e501d

79 files changed

Lines changed: 8900 additions & 893 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ jobs:
208208
- name: Python — test native installer harnesses
209209
run: python3 -B -m unittest discover -s scripts/tests -v
210210

211+
- name: Rust — lock model size budget
212+
# Annotates, never fails: a bug fix elsewhere may add lines to these
213+
# files. The lock-model PRs lower the budget as they delete code
214+
# (docs/design/lock-model-unification.md#size-budget).
215+
run: python3 -B scripts/loc-budget.py --warn
216+
211217
- name: Shell — shellcheck the curl|sh installer
212218
# shellcheck is pre-installed on ubuntu-latest.
213219
run: shellcheck --shell=sh scripts/install.sh

‎crates/socket-patch-cli/CLI_CONTRACT.md‎

Lines changed: 31 additions & 10 deletions
Large diffs are not rendered by default.

‎crates/socket-patch-cli/src/commands/vendor_orphans.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ pub(crate) async fn sweep_orphan_vendor_dirs_where(
6868
if candidates.is_empty() {
6969
return out;
7070
}
71-
let references = crate::commands::vendored_backend::repair::scan_vendor_references(cwd).await;
71+
// Keep-vs-delete: any case counts, as in the revert keep-checks.
72+
let references =
73+
crate::commands::vendored_backend::repair::scan_vendor_references_any_case(cwd).await;
7274
let wired: HashSet<(&str, &str)> = references
7375
.iter()
7476
.map(|(eco, uuid, _path)| (eco.as_str(), uuid.as_str()))

‎crates/socket-patch-cli/src/commands/vendored_backend/repair.rs‎

Lines changed: 146 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,78 @@ struct Candidate {
3737
/// path parser. Used by repair (references the ledger does not cover), by
3838
/// the orphan sweeps (`vendor --revert`, `scan --prune`: a dir a lockfile
3939
/// still points at is never deleted) and by rollback.
40+
///
41+
/// Every escape and separator spelling of a reference counts (an older
42+
/// composer.lock's `\/`, any run of Windows backslashes, `\u` /
43+
/// XML-entity escapes). This form REFUSES on what it finds (`vendor`'s
44+
/// ledger-missing gate, rollback's ledger-less gate, `vendor --check`), so
45+
/// it folds ASCII case only where the project's file system does: on a
46+
/// case-sensitive disk another case names another directory. The orphan
47+
/// sweep's keep-vs-delete reads [`scan_vendor_references_any_case`].
4048
pub(crate) async fn scan_vendor_references(project_root: &Path) -> Vec<(String, String, String)> {
49+
let fold_case = socket_patch_core::utils::fs::folds_case(
50+
&project_root.join(socket_patch_core::constants::SOCKET_DIR),
51+
)
52+
.await;
53+
scan_vendor_references_folding(project_root, fold_case).await
54+
}
55+
56+
/// [`scan_vendor_references`] matching the `.socket/vendor/<eco>/<uuid>`
57+
/// anchor in any ASCII case, as the revert keep-checks
58+
/// ([`socket_patch_core::utils::path_spelling::PathNeedle::keep`]) do: the
59+
/// orphan sweep only ever KEEPS a dir on what it finds, so erring toward
60+
/// "referenced" is the safe direction and the two deletion paths agree.
61+
pub(crate) async fn scan_vendor_references_any_case(
62+
project_root: &Path,
63+
) -> Vec<(String, String, String)> {
64+
scan_vendor_references_folding(project_root, true).await
65+
}
66+
67+
/// Recover a vendored reference from a folded `candidate`, ASCII
68+
/// case-insensitively when `fold_case` (eco and uuid lower-cased, the leaf
69+
/// and the relpath kept as spelled).
70+
fn parse_reference_folding(candidate: &str, fold_case: bool) -> Option<(String, String, String)> {
71+
if let Some(parts) = parse_vendor_reference(candidate) {
72+
let rel = candidate
73+
.trim_start_matches("./")
74+
.trim_end_matches('/')
75+
.to_string();
76+
return Some((parts.eco, parts.uuid, rel));
77+
}
78+
if !fold_case {
79+
return None;
80+
}
81+
let parts = parse_vendor_reference(&candidate.to_ascii_lowercase())?;
82+
// ASCII lower-casing keeps every byte offset, and the leaf is the
83+
// candidate's own tail.
84+
let trimmed = candidate.trim_end_matches('/');
85+
let leaf = &trimmed[trimmed.len() - parts.leaf.len()..];
86+
let mut rel = format!(".socket/vendor/{}/{}", parts.eco, parts.uuid);
87+
if !leaf.is_empty() {
88+
rel.push('/');
89+
rel.push_str(leaf);
90+
}
91+
Some((parts.eco, parts.uuid, rel))
92+
}
93+
94+
/// The byte offset of the first `.socket` in `text`, ASCII
95+
/// case-insensitively when `fold_case`.
96+
fn find_socket_anchor(text: &str, fold_case: bool) -> Option<usize> {
97+
const ANCHOR: &str = ".socket";
98+
if !fold_case {
99+
return text.find(ANCHOR);
100+
}
101+
text.match_indices('.').map(|(i, _)| i).find(|&i| {
102+
text.as_bytes()
103+
.get(i..i + ANCHOR.len())
104+
.is_some_and(|s| s.eq_ignore_ascii_case(ANCHOR.as_bytes()))
105+
})
106+
}
107+
108+
async fn scan_vendor_references_folding(
109+
project_root: &Path,
110+
fold_case: bool,
111+
) -> Vec<(String, String, String)> {
41112
let mut seen: HashSet<(String, String)> = HashSet::new();
42113
let mut out = Vec::new();
43114
// The binary lock is read unless a readable text lock shadows it: a
@@ -72,8 +143,13 @@ pub(crate) async fn scan_vendor_references(project_root: &Path) -> Vec<(String,
72143
let Ok(text) = read_regular_to_string(&project_root.join(file)).await else {
73144
continue;
74145
};
75-
let mut rest = text.as_str();
76-
while let Some(idx) = rest.find(".socket") {
146+
// Every spelling folded first: escapes decoded and every run of `/`
147+
// and `\` collapsed to one `/` (an older composer.lock's `\/`, any
148+
// number of Windows backslashes). Missing one here lets the orphan
149+
// sweep delete a dir a lock still installs from.
150+
let text = socket_patch_core::utils::path_spelling::canonical_path_text(&text);
151+
let mut rest: &str = &text;
152+
while let Some(idx) = find_socket_anchor(rest, fold_case) {
77153
let slice = &rest[idx..];
78154
// `:` ends a reference too: pnpm snapshot keys are
79155
// `name@file:<path>:` and yaml mappings suffix the path with a
@@ -84,18 +160,11 @@ pub(crate) async fn scan_vendor_references(project_root: &Path) -> Vec<(String,
84160
'"', '\'', '`', ' ', '\t', '\n', '\r', ',', ')', ']', '}', ';', ':', '<',
85161
])
86162
.unwrap_or(slice.len());
87-
let candidate = slice[..end].replace('\\', "/");
163+
let candidate = &slice[..end];
88164
// NuGet's feed and Maven's repository name the uuid dir itself.
89-
if let Some(parts) = parse_vendor_reference(&candidate) {
90-
if seen.insert((parts.eco.to_string(), parts.uuid.clone())) {
91-
out.push((
92-
parts.eco.to_string(),
93-
parts.uuid.clone(),
94-
candidate
95-
.trim_start_matches("./")
96-
.trim_end_matches('/')
97-
.to_string(),
98-
));
165+
if let Some((eco, uuid, rel)) = parse_reference_folding(candidate, fold_case) {
166+
if seen.insert((eco.clone(), uuid.clone())) {
167+
out.push((eco, uuid, rel));
99168
}
100169
}
101170
rest = &rest[idx + ".socket".len()..];
@@ -1275,6 +1344,70 @@ mod tests {
12751344
);
12761345
}
12771346

1347+
/// An older composer.lock spells slashes `\/` and a Windows checkout may
1348+
/// double (or quadruple) its backslashes: the scan folds every run to the
1349+
/// canonical path, so the orphan sweep keeps a dir such a lock still
1350+
/// installs from. A different uuid's dir is never this one's reference.
1351+
#[tokio::test]
1352+
async fn scan_recovers_escaped_and_doubled_backslash_references() {
1353+
let uuid = "33333333-3333-4333-8333-333333333333";
1354+
let other = "44444444-3333-4333-8333-333333333333";
1355+
let path = format!(".socket/vendor/composer/{uuid}/psr/log@3.0.2");
1356+
for lock in [
1357+
format!("{{\"url\": \"{}\"}}", path.replace('/', "\\/")),
1358+
format!("{{\"url\": \"{}\"}}", path.replace('/', "\\\\")),
1359+
format!("{{\"url\": \"{}\"}}", path.replace('/', "\\\\\\\\")),
1360+
format!("{{\"url\": \"{}\"}}", path.replace('/', "\\\\\\/")),
1361+
format!("{{\"url\": \"./{}\"}}", path.replace('/', "\\/")),
1362+
] {
1363+
let tmp = tempfile::tempdir().unwrap();
1364+
tokio::fs::write(tmp.path().join("composer.lock"), &lock)
1365+
.await
1366+
.unwrap();
1367+
let refs = scan_vendor_references(tmp.path()).await;
1368+
assert_eq!(
1369+
refs,
1370+
vec![("composer".to_string(), uuid.to_string(), path.clone())],
1371+
"{lock}"
1372+
);
1373+
assert!(
1374+
refs.iter().all(|(_, u, _)| u != other),
1375+
"a different uuid's dir is never this one's reference"
1376+
);
1377+
assert_eq!(scan_vendor_references_any_case(tmp.path()).await, refs);
1378+
}
1379+
}
1380+
1381+
/// The orphan sweep's scan matches the anchor in any case, as the revert
1382+
/// keep-checks do, so a re-cased reference keeps the dir (eco and uuid
1383+
/// reported canonical, the leaf as spelled). The refusal-side scan folds
1384+
/// case only where the disk does.
1385+
#[tokio::test]
1386+
async fn any_case_scan_recovers_a_recased_reference() {
1387+
let uuid = "55555555-3333-4333-8333-333333333333";
1388+
let tmp = tempfile::tempdir().unwrap();
1389+
let lock = format!(
1390+
"{{\"url\": \"{}\"}}",
1391+
format!(
1392+
".Socket\\Vendor\\Composer\\{}\\Psr\\Log@3.0.2",
1393+
uuid.to_ascii_uppercase()
1394+
)
1395+
);
1396+
tokio::fs::write(tmp.path().join("composer.lock"), &lock)
1397+
.await
1398+
.unwrap();
1399+
assert_eq!(
1400+
scan_vendor_references_any_case(tmp.path()).await,
1401+
vec![(
1402+
"composer".to_string(),
1403+
uuid.to_string(),
1404+
format!(".socket/vendor/composer/{uuid}/Psr/Log@3.0.2")
1405+
)]
1406+
);
1407+
// No `.socket/` to probe: the refusal-side scan keeps case.
1408+
assert!(scan_vendor_references(tmp.path()).await.is_empty());
1409+
}
1410+
12781411
/// The scanner's false-positive guard: a `.socket` mention that is NOT
12791412
/// a parseable vendored-artifact path (the committed manifest, a
12801413
/// non-uuid path segment) must never be reported as a vendor reference

‎crates/socket-patch-cli/src/commands/vex.rs‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ use socket_patch_core::vex::{
3131

3232
use crate::args::{apply_env_toggles, parse_bool_flag, GlobalArgs};
3333
use crate::commands::vex_sources::{
34-
self, Plan, RunApiClient, Sources, RECORD_MISMATCH, RECORD_UNAVAILABLE, REDIRECT_UNWIRED,
35-
VENDOR_UNWIRED, WIRING_CONFLICT,
34+
self, Plan, RunApiClient, Sources, GO_WORKSPACE_OVERRIDE, RECORD_MISMATCH, RECORD_UNAVAILABLE,
35+
REDIRECT_UNWIRED, VENDOR_UNWIRED, WIRING_CONFLICT,
3636
};
3737
use crate::ecosystem_dispatch::{find_manifest_package_copies_reusing, JvmScope};
3838
use crate::json_envelope::{Command, Envelope, EnvelopeError, PatchAction, PatchEvent, RunWarning};
@@ -1953,10 +1953,6 @@ fn join_and(items: &[&str]) -> String {
19531953
}
19541954
}
19551955

1956-
/// Omission tag for a Go patch whose go.mod replace the `go.work` in effect
1957-
/// overrides, ignores or rejects (#393, #458, #531).
1958-
const GO_WORKSPACE_OVERRIDE: &str = "go_workspace_override";
1959-
19601956
/// Omission tag for a global Go patch while a tool built from the unpatched
19611957
/// module with `go install` remains (#422).
19621958
const GO_INSTALLED_TOOL_STALE: &str = socket_patch_core::utils::go_installed_tools::STALE_WARNING;
@@ -2125,8 +2121,9 @@ fn omission_phrase(reason: &str) -> &'static str {
21252121
package any more"
21262122
}
21272123
GO_WORKSPACE_OVERRIDE => {
2128-
"the go.work in effect overrides, ignores or conflicts with its go.mod replace, \
2129-
so the build does not link the patched module"
2124+
"the Go workspace in effect keeps its replace from the build (overrides, ignores \
2125+
or rejects it, or go builds from a go.work other than the one holding it), so \
2126+
the build does not link the patched module; the run warning names which"
21302127
}
21312128
GO_INSTALLED_TOOL_STALE => {
21322129
"a tool installed with `go install` was built from the unpatched module and keeps \

0 commit comments

Comments
 (0)