Skip to content

Merge pull request #718 from kali-el/feat/ai_documentation #29

Merge pull request #718 from kali-el/feat/ai_documentation

Merge pull request #718 from kali-el/feat/ai_documentation #29

# Latency Budget Enforcement CI
#
# Runs the CLI cold-start and command-latency Criterion benchmarks on every
# push / pull request and checks the results against the project's latency
# budgets. Fails the workflow when a statistically meaningful regression is
# detected, helping to keep the CLI snappy for all users.
#
# See CLI_LATENCY_BUDGETS.md for budget definitions and environment overrides.
name: Latency Budget
on:
push:
branches: [master, main]
paths:
- '**.rs'
- 'Cargo.toml'
- 'Cargo.lock'
- 'benches/**'
- '.github/workflows/benchmark-latency.yml'
pull_request:
paths:
- '**.rs'
- 'Cargo.toml'
- 'Cargo.lock'
- 'benches/**'
- '.github/workflows/benchmark-latency.yml'
# Allow manual trigger for ad-hoc budget checks.
workflow_dispatch:
jobs:
latency-budget:
name: Latency Budget Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install system dependencies
run: sudo apt-get update && sudo apt-get install -y libudev-dev
# Build the project first so benchmark compilation is faster.
- name: Build project
run: cargo build --locked
# Run only the latency-relevant benchmark groups. This keeps CI fast
# while still exercising cold-start and command-dispatch paths.
- name: Run latency benchmarks
run: |
cargo bench --locked -- \
cli_cold_start \
cli_command_latency \
latency_budget \
2>&1 | tee target/criterion/latency-bench-output.txt
# Parse Criterion output and check against latency budgets.
# The check-latency-budgets.sh script extracts median values from the
# default Criterion stdout format and compares them against the budgets
# defined in the bash script (which mirror src/utils/latency_budget.rs).
- name: Parse and check latency budget report
id: budget-check
run: |
chmod +x scripts/check-latency-budgets.sh
REPORT=$(bash scripts/check-latency-budgets.sh \
--input target/criterion/latency-bench-output.txt \
--report-path target/criterion/latency-budget-report.json \
2>&1) || EXIT_CODE=$?
echo "::group::Latency Budget Report"
echo "$REPORT"
echo "::endgroup::"
ALL_PASS=$(echo "$REPORT" | jq -r '.all_pass')
echo "all_pass=$ALL_PASS" >> "$GITHUB_OUTPUT"
if [ "$ALL_PASS" = "false" ]; then
echo "❌ Latency budget violations detected!"
echo "failures=true" >> "$GITHUB_OUTPUT"
exit 1
fi
echo "✅ All latency budgets met."
- name: Upload Criterion report (artefact)
if: always()
uses: actions/upload-artifact@v4
with:
name: criterion-latency-report
path: |
target/criterion/cli_cold_start/
target/criterion/cli_command_latency/
target/criterion/latency_budget/
target/criterion/latency-bench-output.txt
target/criterion/latency-budget-report.json
# Post a PR comment with the budget check summary when run on a PR.
- name: Comment PR with budget summary
if: github.event_name == 'pull_request' && always()
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const reportPath = 'target/criterion/latency-budget-report.json';
let summary = '## ⏱ CLI Latency Budget Check\n\n';
if (fs.existsSync(reportPath)) {
const report = JSON.parse(fs.readFileSync(reportPath, 'utf8'));
let details = '';
for (const check of report.checks) {
const icon = check.status === 'PASS' ? '✅' :
check.status === 'FAIL' ? '❌' :
check.status === 'NOISY' ? '⚠️' :
check.status === 'SKIPPED' ? '⏭️' : '❗';
summary += `| ${icon} ${check.budget} | ${check.budget_max_ms} ms | ${check.actual_median_ms} ms | ${check.status} |\n`;
}
if (report.any_fail) summary += '\n❌ **Some budgets were violated.**';
else summary += '\n✅ **All budgets met.**';
} else {
summary += '_No latency budget report was generated._';
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: summary
});