Make Codex and Claude Code subscriptions go further: a local model router that gives routine agent work to economical models and keeps your strongest model for the hard parts.
Rust ai-agentsai-gatewayclaude-codecodexcoding-agentcost-optimizationdeepseekllm-gatewayllm-routerlocal-firstmodel-routingrusttask-routingtauri
fix(ci): compare Rust size limits with candidate base
johnlanni2fcaf580e12b
diff --git a/.github/workflows/gateway-core.yml b/.github/workflows/gateway-core.ymlindex 09e4edba..06ee0315 100644--- a/.github/workflows/gateway-core.yml+++ b/.github/workflows/gateway-core.yml@@ -60,9 +60,18 @@ jobs:fetch-depth: 0- uses: ./.github/actions/ci-setup- name: CI adapter tests- run: python3 scripts/test-ci-run.py+ run: python3 scripts/test-ci-run.py && python3 scripts/test-rust-file-size.py- name: Rust size boundary- run: python3 scripts/ci-run.py --name structure -- bash scripts/check-rust-file-size.sh+ env:+ STRUCTURE_BASE: ${{ github.event.pull_request.base.sha || github.event.before }}+ run: |+ args=()+ if [[ -n "$STRUCTURE_BASE" && ! "$STRUCTURE_BASE" =~ ^0+$ ]] && git cat-file -e "$STRUCTURE_BASE^{commit}" 2>/dev/null; then+ args=(--base "$STRUCTURE_BASE")+ elif git rev-parse --verify HEAD^ >/dev/null 2>&1; then+ args=(--base HEAD^)+ fi+ python3 scripts/ci-run.py --name structure -- bash scripts/check-rust-file-size.sh "${args[@]}"- name: Selected Rust checks (full short set on main)env:BASE_SHA: ${{ github.event.pull_request.base.sha }}diff --git a/scripts/check-rust-file-size.sh b/scripts/check-rust-file-size.shindex 6077ce19..a828fb83 100755--- a/scripts/check-rust-file-size.sh+++ b/scripts/check-rust-file-size.sh@@ -5,6 +5,25 @@ soft_limit=700hard_limit=1100checked_files=0failed=0+base=""++if (( $# > 0 )); then+ if [[ "$1" != "--base" || $# != 2 ]]; then+ printf 'usage: %s [--base COMMIT]\n' "$0" >&2+ exit 2+ fi+ base="$2"+ git rev-parse --verify "${base}^{commit}" >/dev/null+fi++rust_files() {+ if [[ -n "${base}" ]]; then+ git diff --name-only -z --diff-filter=ACMR "${base}...HEAD" -- '*.rs'+ git ls-files -z --others --exclude-standard -- '*.rs'+ else+ git ls-files -z --cached --others --exclude-standard -- '*.rs'+ fi+}while IFS= read -r -d '' rust_file; do[[ -f "${rust_file}" ]] || continue@@ -12,14 +31,23 @@ while IFS= read -r -d '' rust_file; dochecked_files=$((checked_files + 1))if (( line_count > hard_limit )); then- printf 'error: %s has %d lines (hard limit: %d)\n' \- "${rust_file}" "${line_count}" "${hard_limit}" >&2- failed=1+ base_line_count=0+ if [[ -n "${base}" ]] && git cat-file -e "${base}:${rust_file}" 2>/dev/null; then+ base_line_count=$(git show "${base}:${rust_file}" | awk 'END { print NR }')+ fi+ if (( base_line_count > hard_limit && line_count <= base_line_count )); then+ printf 'warning: %s retains baseline size at %d lines (base: %d, hard limit: %d)\n' \+ "${rust_file}" "${line_count}" "${base_line_count}" "${hard_limit}" >&2+ else+ printf 'error: %s has %d lines (base: %d, hard limit: %d)\n' \+ "${rust_file}" "${line_count}" "${base_line_count}" "${hard_limit}" >&2+ failed=1+ fielif (( line_count > soft_limit )); thenprintf 'warning: %s has %d lines (soft target: %d)\n' \"${rust_file}" "${line_count}" "${soft_limit}" >&2fi-done < <(git ls-files -z --cached --others --exclude-standard -- '*.rs')+done < <(rust_files)printf 'checked %d Rust files (soft target: %d, hard limit: %d)\n' \"${checked_files}" "${soft_limit}" "${hard_limit}"diff --git a/scripts/test-rust-file-size.py b/scripts/test-rust-file-size.pynew file mode 100644index 00000000..b38f93b5--- /dev/null+++ b/scripts/test-rust-file-size.py@@ -0,0 +1,71 @@+#!/usr/bin/env python3+"""Regression tests for baseline-aware Rust source-size enforcement."""++from pathlib import Path+import subprocess+import tempfile+import unittest++CHECK = Path(__file__).with_name("check-rust-file-size.sh").resolve()+++def run(*command, cwd, check=True):+ return subprocess.run(+ command,+ cwd=cwd,+ check=check,+ text=True,+ capture_output=True,+ )+++def write_lines(path, count):+ path.write_text("// line\n" * count)+++class RustFileSizeTests(unittest.TestCase):+ def repository(self, initial_lines):+ temporary = tempfile.TemporaryDirectory()+ self.addCleanup(temporary.cleanup)+ repository = Path(temporary.name)+ run("git", "init", "-q", cwd=repository)+ run("git", "config", "user.name", "test", cwd=repository)+ run("git", "config", "user.email", "[email protected]", cwd=repository)+ write_lines(repository / "legacy.rs", initial_lines)+ run("git", "add", "legacy.rs", cwd=repository)+ run("git", "commit", "-qm", "base", cwd=repository)+ base = run("git", "rev-parse", "HEAD", cwd=repository).stdout.strip()+ return repository, base++ def commit_lines(self, repository, count):+ write_lines(repository / "legacy.rs", count)+ run("git", "add", "legacy.rs", cwd=repository)+ run("git", "commit", "-qm", "candidate", cwd=repository)++ def test_existing_hard_limit_violation_may_shrink_without_blocking(self):+ repository, base = self.repository(1200)+ self.commit_lines(repository, 1150)+ result = run("bash", str(CHECK), "--base", base, cwd=repository)+ self.assertIn("retains baseline size", result.stderr)++ def test_existing_hard_limit_violation_cannot_grow(self):+ repository, base = self.repository(1200)+ self.commit_lines(repository, 1201)+ result = run(+ "bash", str(CHECK), "--base", base, cwd=repository, check=False+ )+ self.assertEqual(result.returncode, 1)+ self.assertIn("error: legacy.rs has 1201 lines", result.stderr)++ def test_new_hard_limit_violation_is_rejected(self):+ repository, base = self.repository(1)+ write_lines(repository / "new.rs", 1101)+ result = run(+ "bash", str(CHECK), "--base", base, cwd=repository, check=False+ )+ self.assertEqual(result.returncode, 1)+ self.assertIn("error: new.rs has 1101 lines", result.stderr)+++if __name__ == "__main__":+ unittest.main()