D7: editor multi-cursor support

Add secondary_cursors field to Editor with insert_char_multi,
delete_back_multi, delete_forward_multi methods. Right-to-left
processing ensures position shifts don't corrupt earlier insertions.

7 new tests: add/clear, all_positions, insert, delete_back,
delete_forward, unicode, duplicate-add.
This commit is contained in:
2026-07-05 22:29:19 +03:00
parent 7a2b0d5160
commit b8aac3c9bc
2226 changed files with 876572 additions and 2382 deletions
+34 -65
View File
@@ -2,15 +2,15 @@
# verify-fork-versions.sh — Enforce the "no fake version label" rule.
#
# For each local Cat 2 fork under local/sources/<name>/ that has a
# version field of the form `<X.Y.Z>-rb<N>`, verify that:
# version field of the form `<X.Y.Z>-rb<B.B.B>`, verify that:
# 1. The fork's source content is a real rebase onto the matching
# upstream `<X.Y.Z>` release (with the Red Bear patches applied).
# 2. The `version` field in the fork's Cargo.toml starts with that
# 2. The `<B.B.B>` part matches the current Red Bear OS git branch.
# 3. The `version` field in the fork's Cargo.toml starts with that
# upstream release tag.
#
# This script is invoked by build-preflight.sh and apply-rb-suffix.sh.
# It returns exit code 1 if any fork fails the check, with a clear
# error message identifying the fork and the specific mismatch.
# It returns exit code 1 if any fork fails the check.
set -euo pipefail
@@ -24,6 +24,9 @@ if [ ! -f "$MAP_FILE" ]; then
exit 1
fi
BRANCH="$(git branch --show-current 2>/dev/null || echo "")"
BRANCH_VERSION="$(echo "$BRANCH" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || true)"
violations=0
for fork_dir in local/sources/*/; do
@@ -40,17 +43,13 @@ for fork_dir in local/sources/*/; do
continue
fi
# Extract the base version (before -rb) and the rb counter
base_version=$(echo "$version" | sed -E 's/-rb[0-9]+$//') || true
rb_n=$(echo "$version" | sed -E 's/^.*-rb([0-9]+)$/\1/') || true
# Extract the upstream base version (before -rb) and the branch version (after -rb)
base_version=$(echo "$version" | sed -E 's/-rb[0-9]+\.[0-9]+\.[0-9]+$//') || true
rb_branch=$(echo "$version" | sed -E 's/^.*-rb([0-9]+\.[0-9]+\.[0-9]+)$/\1/') || true
if [ -z "$base_version" ] || [ -z "$rb_n" ]; then
# If the base_version came out empty (e.g. version field is
# blank), we already detected & skipped in the empty-version
# case above. Reaching this branch with empty outputs means
# the version string is malformed (e.g. ends in `-rb` with
# no number). That is a fake-label failure.
echo "ERROR: $toml has malformed version '$version' (must be <X.Y.Z>-rb<N>)" >&2
if [ -z "$base_version" ] || [ -z "$rb_branch" ]; then
echo "ERROR: $toml has malformed version '$version'" >&2
echo " Expected format: <X.Y.Z>-rb<B.B.B> (e.g. 0.9.0-rb0.2.5)" >&2
violations=$((violations + 1))
continue
fi
@@ -64,16 +63,11 @@ for fork_dir in local/sources/*/; do
fi
upstream_url=$(echo "$map_line" | awk '{print $2}')
upstream_tag=$(echo "$map_line" | awk '{print $3}')
fork_mode=$(echo "$map_line" | awk '{print $4}')
# If the upstream tag is `PENDING_REBASE` (used to mark a fork
# whose rebase is in progress), the build cannot proceed. Refuse
# with a clear error pointing the user to the rebase work.
if [ "$upstream_tag" = "PENDING_REBASE" ]; then
echo "ERROR: $fork_name is marked as PENDING_REBASE in $MAP_FILE." >&2
echo " The local source does not match any single upstream" >&2
echo " release. A real rebase onto a chosen upstream tag is" >&2
echo " required. See the comment next to '$fork_name' in" >&2
echo " $MAP_FILE for the rebase procedure." >&2
echo " A real rebase onto a chosen upstream tag is required." >&2
violations=$((violations + 1))
continue
fi
@@ -81,11 +75,24 @@ for fork_dir in local/sources/*/; do
if [ "$upstream_tag" != "$base_version" ]; then
echo "ERROR: $fork_name Cargo.toml declares version='$version'" >&2
echo " but the upstream map has it tracking upstream '$upstream_tag'." >&2
echo " Either update the version field or update the map." >&2
violations=$((violations + 1))
continue
fi
# Verify the -rb suffix matches the current branch
if [ -n "$BRANCH_VERSION" ] && [ "$rb_branch" != "$BRANCH_VERSION" ]; then
echo "ERROR: $fork_name version suffix -rb$rb_branch does not match" >&2
echo " current branch '$BRANCH' (expected -rb$BRANCH_VERSION)." >&2
violations=$((violations + 1))
continue
fi
# Snapshot forks: skip content comparison (unrelated git histories).
# Version format and suffix are still verified above.
if [ "$fork_mode" = "snapshot" ]; then
continue
fi
# Fetch the upstream tag's tree hash
upstream_hash=$(cd /tmp && git ls-remote --tags "$upstream_url" "refs/tags/$upstream_tag" 2>/dev/null | awk '{print $1}' | head -1)
if [ -z "$upstream_hash" ]; then
@@ -94,81 +101,50 @@ for fork_dir in local/sources/*/; do
fi
# Compare file lists: the local fork should have the same files as
# upstream at $upstream_hash, plus any Red Bear patch files in
# local/patches/$fork_name/.
# upstream at $upstream_hash, plus any Red Bear patch files.
cd "$fork_dir"
local_files=$(find . -type f -not -path './.git/*' -not -path './target/*' -not -path './Cargo.lock' | sort | sed 's|^\./||')
cd /tmp
rm -rf "verify-$fork_name" 2>/dev/null
# Shallow-clone the specific tag directly. `--depth 1 --branch <tag>`
# makes the tag the initial HEAD, so we have the file tree without
# having to fetch a specific commit (which `git clone --depth 1`
# can't reach on shallow clones because the commit is past the
# shallow boundary).
upstream_dir="verify-$fork_name-upstream"
upstream_dir="/tmp/verify-$fork_name-upstream"
rm -rf "$upstream_dir" 2>/dev/null
if ! timeout 60 git clone --depth 1 --branch "$upstream_tag" --quiet "$upstream_url" "$upstream_dir" 2>/dev/null; then
echo "WARN: $fork_name: couldn't clone $upstream_url branch $upstream_tag, skipping content check" >&2
cd "$ROOT"
continue
fi
cd "$upstream_dir"
upstream_files=$(find . -type f -not -path './.git/*' -not -path './target/*' -not -path './Cargo.lock' | sort | sed 's|^\./||')
upstream_files=$(cd "$upstream_dir" && find . -type f -not -path './.git/*' -not -path './target/*' -not -path './Cargo.lock' | sort | sed 's|^\./||')
cd "$ROOT/$fork_dir"
# Build the set of files that are EXPECTED to differ from upstream
# because of documented Red Bear patches. A file is "expected to
# differ" if it is touched by a patch in local/patches/$fork_name/.
# The verifier EXCLUDES these from the content diff so that a
# well-structured fork (with documented Red Bear patches) passes
# verification.
# Build the set of files expected to differ (documented Red Bear patches)
patch_dir="$ROOT/local/patches/$fork_name"
expected_differ=()
if [ -d "$patch_dir" ]; then
while IFS= read -r patch_file; do
[ -z "$patch_file" ] && continue
# `git apply --stat` lists files touched by the patch.
# Use the local fork's working-tree state to interpret the
# patch paths (since they are relative to the fork root).
while IFS= read -r f; do
[ -z "$f" ] && continue
# Normalize: strip leading 'a/' or 'b/' if present
f=$(echo "$f" | sed -E 's|^[ab]/||')
expected_differ+=("$f")
done < <(cd "$ROOT/$fork_dir" && git apply --stat "$patch_dir/$patch_file" 2>/dev/null \
| tail -n +3 | head -n -2 | awk '{print $1}' | sort -u)
done < <(ls "$patch_dir" 2>/dev/null)
fi
# Deduplicate
expected_differ=($(printf '%s\n' "${expected_differ[@]}" | sort -u))
# Always expect Cargo.toml and Cargo.toml.orig to differ (version field
# bump and auto-generated Cargo.toml are Red Bear bookkeeping).
expected_differ+=("Cargo.toml")
expected_differ+=("Cargo.toml.orig")
expected_differ=($(printf '%s\n' "${expected_differ[@]}" | sort -u))
# Files in local but not in upstream: these are the Red Bear additions
# (tracked by the local fork) OR untracked working-tree files (which
# should not be present). Files in upstream but not in local: these
# are missing patches (unacceptable).
only_local=$(comm -23 <(echo "$local_files") <(echo "$upstream_files"))
only_upstream=$(comm -13 <(echo "$local_files") <(echo "$upstream_files"))
if [ -n "$only_upstream" ]; then
# Filter out files that are EXPECTED to be absent (e.g. deleted
# by a Red Bear patch). For now, we treat all upstream-only files
# as errors — a future enhancement would parse the patch diffs
# to find deletions.
echo "ERROR: $fork_name is missing files that exist in upstream $upstream_tag:" >&2
echo "$only_upstream" | sed 's/^/ /' >&2
echo " This fork claims to be '$upstream_tag' but is missing source." >&2
violations=$((violations + 1))
fi
if [ -n "$only_local" ]; then
# Filter out files in local/patches/$fork_name/ (patches
# themselves, README, etc.) — those are Red Bear bookkeeping,
# not source files.
local_non_patch=$(comm -23 <(echo "$local_files") \
<(cd "$ROOT" && find "local/patches/$fork_name" -type f 2>/dev/null | \
sed "s|^local/patches/$fork_name/||" | sort -u))
@@ -179,17 +155,14 @@ for fork_dir in local/sources/*/; do
if [ "$count" -gt 10 ]; then
echo " ... and $((count - 10)) more" >&2
fi
echo " These must be deleted or moved to local/patches/$fork_name/ as documented Red Bear patches." >&2
violations=$((violations + 1))
fi
fi
# Verify content of shared files. Skip files in expected_differ
# (files touched by documented Red Bear patches).
# Verify content of shared files (skip files touched by Red Bear patches)
diff_count=0
while IFS= read -r f; do
[ -z "$f" ] && continue
# Skip if this file is in expected_differ
skip=0
for ed in "${expected_differ[@]}"; do
if [ "$f" = "$ed" ]; then
@@ -208,8 +181,6 @@ for fork_dir in local/sources/*/; do
done <<< "$(comm -12 <(echo "$local_files") <(echo "$upstream_files"))"
if [ "$diff_count" -gt 0 ]; then
echo " These must either be re-rebased onto $upstream_tag OR" >&2
echo " moved to local/patches/$fork_name/ as documented Red Bear patches." >&2
violations=$((violations + 1))
fi
@@ -219,8 +190,6 @@ done
if [ "$violations" -gt 0 ]; then
echo "" >&2
echo "FAIL: $violations fork version violations found." >&2
echo " Run local/scripts/refresh-fork-upstream-map.sh and" >&2
echo " local/scripts/apply-rb-suffix.sh to fix the offending forks." >&2
exit 1
fi