Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ updates:
# CI). Deps the forks share with bashkit's own crates (fancy-regex,
# chrono, sha2, ...) are not listed: bashkit must be able to move them,
# and CI shows whether the fork still builds.
# A shared dep's proposal edits the fork manifest too (it is declared
# there as well as in the workspace), which check_monty_fork.py rejects
# unless the fork's line carries a `bashkit fork:` marker. So taking one
# of those bumps means moving the fork line and marking it, not just the
# workspace line; fancy-regex and getrandom are marked that way today.
# scripts/tests/test_dependabot_coverage.py keeps this list complete.
- dependency-name: "ahash"
- dependency-name: "hashbrown"
Expand Down
17 changes: 3 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions crates/bashkit-monty/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@ doctest = false
monty-types = { package = "bashkit-monty-types", path = "../bashkit-monty-types", version = "0.20.3" }
ahash = { version = "0.8.0", features = ["serde"] }
chrono = { version = "0.4", features = ["serde"] }
fancy-regex = { version = "0.17.0" }
getrandom = { version = "0.3" }
# bashkit fork: declared by bashkit's own crates too (workspace: 0.20), so
# upstream's 0.17 here put two majors of fancy-regex in the graph. Also what
# Dependabot keeps proposing: it does not ignore shared deps, and the proposal
# edits this manifest. Drop the marker when upstream Monty reaches 0.20.
fancy-regex = { version = "0.20.0" }
# bashkit fork: same, aligned with the workspace's 0.4. This does not drop
# 0.3 from the graph (ahash, fastbloom and rand_core still pull it); it stops
# Dependabot re-proposing a fork edit the drift check would reject. Drop the
# marker when upstream Monty reaches 0.4.
getrandom = { version = "0.4" }
hashbrown = { version = "0.16" }
indexmap = { version = "2" }
itertools = { version = "0.14.0" }
Expand Down
4 changes: 3 additions & 1 deletion crates/bashkit-monty/src/types/re_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ impl ReMatch {
/// `subject` is the already-refcounted subject `Value` this match keeps alive
/// (the caller clones it per match); `regex` supplies named-group mappings.
pub fn from_captures(
caps: &fancy_regex::Captures<'_>,
// bashkit fork: fancy-regex 0.20 made `Captures` generic over the
// haystack type; the fork is ahead of upstream's 0.17 (see Cargo.toml).
caps: &fancy_regex::Captures<'_, str>,
subject: Value,
all_ascii: bool,
regex: &fancy_regex::Regex,
Expand Down
4 changes: 3 additions & 1 deletion crates/bashkit-monty/src/types/re_pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ impl RePattern {
/// Builds a single `ReMatch` heap value from a capture result, keeping the
/// subject alive by refcount (`subject.clone_with_heap`) rather than copying
/// its text. `all_ascii` is precomputed by the caller (once per `finditer`).
fn build_match(&self, caps: &fancy_regex::Captures<'_>, subject: &Value, all_ascii: bool, heap: &Heap) -> Value {
// bashkit fork: fancy-regex 0.20 made `Captures` generic over the haystack
// type; the fork is ahead of upstream's 0.17 (see Cargo.toml).
fn build_match(&self, caps: &fancy_regex::Captures<'_, str>, subject: &Value, all_ascii: bool, heap: &Heap) -> Value {
let m = ReMatch::from_captures(caps, subject.clone_with_heap(heap), all_ascii, &self.compiled);
Value::Ref(heap.allocate(HeapData::ReMatch(Box::new(m))))
}
Expand Down
61 changes: 61 additions & 0 deletions crates/bashkit/tests/integration/python_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,67 @@ mod edge_cases {
}
}

// =============================================================================
// 14b. `re` SEMANTICS ACROSS A fancy-regex MAJOR
// =============================================================================

// The `re` module runs backreference/lookaround patterns on fancy-regex, so a
// major bump there can move Python-visible behavior. The fork is held at a
// version ahead of upstream Monty's (see crates/bashkit-monty/Cargo.toml), and
// 0.20 changed two things these cases pin: `\xHH` above 0x7F in Unicode mode
// now matches the codepoint rather than the raw byte, and word boundaries
// compile to one delegated engine instead of one branch per alternative.
// Every expected value here is what CPython 3.11 prints for the same program.
mod regex_semantics {
use super::*;

async fn re_line(body: &str) -> String {
let mut bash = bash_python();
let r = bash
.exec(&format!("python3 - <<'PYEOF'\nimport re\n{body}\nPYEOF"))
.await
.unwrap();
assert_eq!(r.exit_code, 0, "stderr: {}", r.stderr);
r.stdout.to_string()
}

#[tokio::test]
async fn high_escape_matches_the_codepoint_not_the_raw_byte() {
// CPython: `re.match('\xff', '\xff')` matches U+00FF.
let out = re_line("print(bool(re.match(chr(0xff), chr(0xff))))").await;
assert_eq!(out, "True\n");
}

#[tokio::test]
async fn non_ascii_class_range_matches() {
// Case-folding prefilters for non-ASCII ranges changed in 0.20; a
// missed candidate start position would show up as a false negative.
let out = re_line(
"print(bool(re.search('[' + chr(0xe0) + '-' + chr(0xff) + ']', 'z' + chr(0xe9) + 'z')))",
)
.await;
assert_eq!(out, "True\n");
}

#[tokio::test]
async fn word_boundary_alternation_matches() {
let out = re_line(r"print(bool(re.search(r'\b(?:foo|bar|baz)\b', 'a bar b')))").await;
assert_eq!(out, "True\n");
}

#[tokio::test]
async fn backreference_substitution_is_unchanged() {
let out = re_line(r"print(re.sub(r'(\w)\1', 'X', 'aabb'))").await;
assert_eq!(out, "XX\n");
}

#[tokio::test]
async fn fixed_width_lookbehind_matches() {
let out = re_line(r"print(bool(re.search(r'(?<=ab)c', 'abc')))").await;
assert_eq!(out, "True\n");
}
}

// =============================================================================
// 15. COMPLEX SCRIPTS
// =============================================================================
Expand Down
53 changes: 53 additions & 0 deletions knowledge/operations/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,59 @@ crates only the forks declare, so upstream security fixes arrive by re-sync:
3. Run `python_fuzz` and the tenant stress soak (`BASHKIT_STRESS_ROUNDS=300`,
as nightly runs it) before shipping, as the fork's own regression net.

### A fork dependency may be marked ahead of upstream

A dependency's *version* may diverge when the fork's `Cargo.toml` line carries
a `bashkit fork: <why>` marker, in the comment block directly above it or at
the end of the line. What a marker does **not** cover:

- **Adding or dropping** a dependency. Re-sync cannot reconcile a crate
upstream does not have.
- **Where the crate comes from** — `package`, `path`, `git`, `branch`, `rev`,
`tag`, `registry`. These decide *which* crate is built rather than which
version of it, so they are compared separately and are never markable. An
edit keeping version and features identical while adding `path = "../evil"`
or swapping `package` would otherwise read as upstream's dependency; only the
declared renames (`monty-types`) carry `package` and `path`, and the rename
check validates those on their own.
- **The same crate in another table.** A marker is scoped to the table it sits
in, so a note on `[dependencies] serde` does not silence a
`[build-dependencies] serde` drift — the second runs at compile time.
- **A `[patch]` or `[replace]` table.** These redirect a source without
touching the dependency line the per-dependency check reads, so they are
rejected on sight rather than compared; upstream has neither. `[patch]` in a
non-root manifest is inert today, but the forks are published crates and a
consumer may build one as its own workspace root.

A marker on a dependency that matches upstream is itself an error, so a note
left behind by a re-sync cannot silently excuse the next bump. Unlike source
edits there is no few-plain-lines fallback: a dependency table is one entry per
line, so the comment block is the whole window, and one note cannot cover the
entries around it.

This exists for the nine crates the forks share with bashkit's own crates
(`chrono`, `fancy-regex`, `getrandom`, `indexmap`, `num-bigint`, `num-traits`,
`serde`, `sha1`, `sha2`). They are declared twice, once in a fork and once in
the workspace, and Dependabot deliberately does not ignore them — bashkit has
to be able to move them and to receive their advisories. But a proposal for one
edits the fork manifest as well, so a strict fork-equals-upstream rule made
every such bump unmergeable: #2860 (fancy-regex 0.17 -> 0.20, getrandom
0.3 -> 0.4) is the shape, and it would have come back every week. Holding the
fork at upstream's version instead put two majors of fancy-regex in the graph.

`fancy-regex` and `getrandom` are marked today. Taking a shared bump therefore
means moving the fork line too, marking it, and re-applying whatever source
adaptation the new major needs — fancy-regex 0.20 made `Captures` generic over
the haystack type, so `re_match.rs` and `re_pattern.rs` carry marked
`Captures<'_, str>` edits. Because the `re` module is reachable from untrusted
Python, a major there can move Python-visible behavior:
`python_integration_tests::regex_semantics` pins the cases 0.20 changed
(`\xHH` above 0x7F matching the codepoint, word-boundary alternation) against
what CPython prints. fancy-regex's subroutine calls, whose compile-time
inlining 0.20's `max_prog_size` exists to bound, are not enabled by the fork's
default feature set, so no new compile-time blowup is reachable (TM-PY-033
still covers runtime backtracking).

Moving off 0.0.19 dropped the `jiter` Git patch (Monty 1.4 uses published
jiter 0.17 with pyo3 0.29), the `get-size2 =0.10.1` hold (Monty's ruff AST
moved to `compact_str` 0.10), and the `ruff_python_*` direct dependencies (the
Expand Down
Loading
Loading