From 33724761d683b0c6124ce22c266eb14d61875cf8 Mon Sep 17 00:00:00 2001 From: David Zhang Date: Fri, 19 Jun 2026 20:08:31 +0000 Subject: [PATCH 1/4] ci: catch conflict markers and check desktop rust --- .github/workflows/lint.yml | 38 ++++++++++++++++++++++++++++++++++++++ scripts/pre-commit | 26 ++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 58c3fe2ab01..0b8466dda27 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -33,6 +33,24 @@ jobs: echo "has_firmware=$(echo "$FILES" | grep -qE '^(omi|omiGlass)/.*\.(c|cpp|cc|cxx|h|hpp)$' && echo true || echo false)" >> $GITHUB_OUTPUT echo "has_frontend=$(echo "$FILES" | grep -q '^web/frontend/' && echo true || echo false)" >> $GITHUB_OUTPUT echo "has_personas=$(echo "$FILES" | grep -q '^web/personas-open-source/' && echo true || echo false)" >> $GITHUB_OUTPUT + # Also run the Rust check when this workflow changes so CI PRs dogfood + # the new guard instead of only validating YAML syntax. + echo "has_desktop_rust=$(echo "$FILES" | grep -qE '^desktop/macos/Backend-Rust/.*\.rs$|^\.github/workflows/lint\.yml$' && echo true || echo false)" >> $GITHUB_OUTPUT + + # -- Universal source hygiene -- + - name: Check merge conflict markers + run: | + failed=0 + while IFS= read -r file; do + if [ -f "$file" ] && grep -I -nE '^(<<<<<<<|>>>>>>>)' "$file"; then + failed=1 + fi + done < /tmp/changed-files.txt + + if [ "$failed" -eq 1 ]; then + echo "FAIL: unresolved merge conflict markers found in changed files" + exit 1 + fi # -- Dart -- - name: Setup Flutter @@ -103,6 +121,26 @@ jobs: echo "$FILES" | xargs clang-format --dry-run --Werror fi + # -- Desktop Rust backend -- + - name: Cache desktop Rust backend build + if: steps.changed.outputs.has_desktop_rust == 'true' + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + desktop/macos/Backend-Rust/target + key: ${{ runner.os }}-desktop-rust-${{ hashFiles('desktop/macos/Backend-Rust/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-desktop-rust- + + - name: Check desktop Rust backend + if: steps.changed.outputs.has_desktop_rust == 'true' + working-directory: desktop/macos/Backend-Rust + run: | + cargo fmt --check + cargo check --locked + # -- Frontend -- - name: Setup Node.js if: steps.changed.outputs.has_frontend == 'true' || steps.changed.outputs.has_personas == 'true' diff --git a/scripts/pre-commit b/scripts/pre-commit index fc7011f1c00..a39f47cce6d 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -1,5 +1,15 @@ #!/bin/sh +# Universal source hygiene: fail fast on unresolved merge conflict markers. +STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM) + +if [ -n "$STAGED_FILES" ]; then + if git grep --cached -n -I -E '^(<<<<<<<|>>>>>>>)' -- $STAGED_FILES; then + echo "Unresolved merge conflict markers found in staged files" >&2 + exit 1 + fi +fi + # Dart formatting for app/ STAGED_DART_FILES=$(git diff --cached --name-only --diff-filter=ACM "app/**.dart" | grep -v -e '\.gen\.dart$' -e '\.g\.dart$') @@ -79,4 +89,20 @@ if [ -n "$STAGED_C_FILES" ]; then echo "$STAGED_C_FILES" | xargs git add fi +# Rust formatting/checking for desktop backend. +STAGED_DESKTOP_RUST_FILES=$(git diff --cached --name-only --diff-filter=ACM "desktop/macos/Backend-Rust/**.rs") + +if [ -n "$STAGED_DESKTOP_RUST_FILES" ]; then + echo "Checking desktop Rust backend..." + if ! command -v cargo >/dev/null 2>&1; then + echo "cargo is not installed. Please install Rust/Cargo first" >&2 + exit 1 + fi + ( + cd desktop/macos/Backend-Rust && \ + cargo fmt --check && \ + cargo check --locked + ) +fi + exit 0 From b96fbfed58c3c905e116def11ba0562720639a3a Mon Sep 17 00:00:00 2001 From: David Zhang Date: Fri, 19 Jun 2026 20:12:16 +0000 Subject: [PATCH 2/4] fix: limit rustfmt guard to changed files --- .github/workflows/lint.yml | 7 +++++-- scripts/pre-commit | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 0b8466dda27..493cadcddef 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -136,9 +136,12 @@ jobs: - name: Check desktop Rust backend if: steps.changed.outputs.has_desktop_rust == 'true' - working-directory: desktop/macos/Backend-Rust run: | - cargo fmt --check + FILES=$(grep -E '^desktop/macos/Backend-Rust/.*\.rs$' /tmp/changed-files.txt || true) + if [ -n "$FILES" ]; then + echo "$FILES" | xargs rustfmt --check + fi + cd desktop/macos/Backend-Rust cargo check --locked # -- Frontend -- diff --git a/scripts/pre-commit b/scripts/pre-commit index a39f47cce6d..9d777d8697d 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -98,9 +98,10 @@ if [ -n "$STAGED_DESKTOP_RUST_FILES" ]; then echo "cargo is not installed. Please install Rust/Cargo first" >&2 exit 1 fi + echo "$STAGED_DESKTOP_RUST_FILES" | xargs rustfmt + echo "$STAGED_DESKTOP_RUST_FILES" | xargs git add ( cd desktop/macos/Backend-Rust && \ - cargo fmt --check && \ cargo check --locked ) fi From be6245106f695e78e49743124c395daae56a7199 Mon Sep 17 00:00:00 2001 From: David Zhang Date: Fri, 19 Jun 2026 21:21:11 +0000 Subject: [PATCH 3/4] fix: address guard review comments --- .github/workflows/lint.yml | 2 +- scripts/pre-commit | 34 +++++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 493cadcddef..8424b2e6b53 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -35,7 +35,7 @@ jobs: echo "has_personas=$(echo "$FILES" | grep -q '^web/personas-open-source/' && echo true || echo false)" >> $GITHUB_OUTPUT # Also run the Rust check when this workflow changes so CI PRs dogfood # the new guard instead of only validating YAML syntax. - echo "has_desktop_rust=$(echo "$FILES" | grep -qE '^desktop/macos/Backend-Rust/.*\.rs$|^\.github/workflows/lint\.yml$' && echo true || echo false)" >> $GITHUB_OUTPUT + echo "has_desktop_rust=$(echo "$FILES" | grep -qE '^desktop/macos/Backend-Rust/|^\.github/workflows/lint\.yml$' && echo true || echo false)" >> $GITHUB_OUTPUT # -- Universal source hygiene -- - name: Check merge conflict markers diff --git a/scripts/pre-commit b/scripts/pre-commit index 9d777d8697d..1a3575c9a25 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -4,7 +4,17 @@ STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM) if [ -n "$STAGED_FILES" ]; then - if git grep --cached -n -I -E '^(<<<<<<<|>>>>>>>)' -- $STAGED_FILES; then + conflict_found=0 + while IFS= read -r file; do + [ -n "$file" ] || continue + if git grep --cached -n -I -E '^(<<<<<<<|>>>>>>>)' -- "$file"; then + conflict_found=1 + fi + done <&2 exit 1 fi @@ -90,20 +100,30 @@ if [ -n "$STAGED_C_FILES" ]; then fi # Rust formatting/checking for desktop backend. -STAGED_DESKTOP_RUST_FILES=$(git diff --cached --name-only --diff-filter=ACM "desktop/macos/Backend-Rust/**.rs") +STAGED_DESKTOP_RUST_INPUTS=$(git diff --cached --name-only --diff-filter=ACM | grep -E '^desktop/macos/Backend-Rust/' || true) +STAGED_DESKTOP_RUST_FILES=$(printf '%s\n' "$STAGED_DESKTOP_RUST_INPUTS" | grep -E '\.rs$' || true) -if [ -n "$STAGED_DESKTOP_RUST_FILES" ]; then +if [ -n "$STAGED_DESKTOP_RUST_INPUTS" ]; then echo "Checking desktop Rust backend..." if ! command -v cargo >/dev/null 2>&1; then echo "cargo is not installed. Please install Rust/Cargo first" >&2 exit 1 fi - echo "$STAGED_DESKTOP_RUST_FILES" | xargs rustfmt - echo "$STAGED_DESKTOP_RUST_FILES" | xargs git add - ( + if [ -n "$STAGED_DESKTOP_RUST_FILES" ]; then + while IFS= read -r file; do + [ -n "$file" ] || continue + rustfmt "$file" + git add "$file" + done < Date: Fri, 19 Jun 2026 21:36:20 +0000 Subject: [PATCH 4/4] fix: harden desktop rust formatting guard --- .github/workflows/lint.yml | 2 +- scripts/pre-commit | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8424b2e6b53..2f9ba8e95c6 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -139,7 +139,7 @@ jobs: run: | FILES=$(grep -E '^desktop/macos/Backend-Rust/.*\.rs$' /tmp/changed-files.txt || true) if [ -n "$FILES" ]; then - echo "$FILES" | xargs rustfmt --check + echo "$FILES" | xargs rustfmt --edition 2021 --check fi cd desktop/macos/Backend-Rust cargo check --locked diff --git a/scripts/pre-commit b/scripts/pre-commit index 1a3575c9a25..eaef5dfdcd1 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -112,7 +112,10 @@ if [ -n "$STAGED_DESKTOP_RUST_INPUTS" ]; then if [ -n "$STAGED_DESKTOP_RUST_FILES" ]; then while IFS= read -r file; do [ -n "$file" ] || continue - rustfmt "$file" + if ! rustfmt --edition 2021 "$file"; then + echo "rustfmt failed for $file" >&2 + exit 1 + fi git add "$file" done <