-
-
Notifications
You must be signed in to change notification settings - Fork 3
ci: harden CI/security pipelines, add smoke workflow and reference implementations #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| name: Smoke | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| pull_request: | ||
| branches: [main, master] | ||
|
|
||
| jobs: | ||
| smoke: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.11" | ||
|
|
||
| - name: Install package | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install -e . | ||
|
|
||
| - name: Run smoke script | ||
| run: ./scripts/smoke.sh |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,50 @@ | ||
| PYTHON ?= python3 | ||
| PIP ?= $(PYTHON) -m pip | ||
|
|
||
| .PHONY: install install-dev lint format typecheck test test-cov security ci clean | ||
| .PHONY: install install-dev lint format format-check typecheck test test-cov security dep-scan smoke build ci clean | ||
|
|
||
| install: | ||
| $(PIP) install -e . | ||
|
|
||
| install-dev: | ||
| $(PIP) install -e . | ||
| $(PIP) install pytest pytest-cov ruff mypy bandit pre-commit | ||
| $(PIP) install pytest pytest-cov ruff mypy bandit safety pip-audit build twine pre-commit | ||
|
|
||
| lint: | ||
| ruff check . | ||
|
|
||
| format: | ||
| ruff format . | ||
|
|
||
| format-check: | ||
| ruff format --check . | ||
|
|
||
| typecheck: | ||
| mypy kernels | ||
| mypy kernels implementations | ||
|
|
||
| test: | ||
| pytest | ||
|
|
||
| test-cov: | ||
| pytest --cov=kernels --cov-report=term-missing --cov-fail-under=80 | ||
| pytest --cov=kernels --cov=implementations --cov-report=term-missing --cov-fail-under=80 | ||
|
|
||
| security: | ||
| bandit -r kernels -q | ||
| bandit -r kernels implementations -q | ||
|
|
||
| dep-scan: | ||
| safety check --full-report || true | ||
| pip-audit | ||
|
|
||
| smoke: | ||
| ./scripts/smoke.sh | ||
|
|
||
| build: | ||
| $(PYTHON) -m build | ||
|
|
||
| twine-check: | ||
| twine check dist/* | ||
|
|
||
| ci: lint typecheck security test-cov | ||
| ci: lint format-check typecheck security test-cov smoke build | ||
|
|
||
| clean: | ||
| rm -rf .mypy_cache .pytest_cache .ruff_cache .coverage htmlcov dist build *.egg-info | ||
| rm -rf .mypy_cache .pytest_cache .ruff_cache .coverage htmlcov dist build *.egg-info .tmp |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,30 +4,68 @@ | |
| set -e | ||
|
|
||
| cd "$(dirname "$0")/.." | ||
| export PYTHONPATH="${PYTHONPATH:+$PYTHONPATH:}$(pwd)" | ||
|
|
||
| echo "Kernels Smoke Test" | ||
| echo "==================" | ||
|
|
||
| echo "" | ||
| echo "[1/5] Checking Python version..." | ||
| echo "[1/7] Checking Python version..." | ||
| python3 --version | ||
|
|
||
| echo "" | ||
| echo "[2/5] Running minimal example..." | ||
| echo "[2/7] Running minimal example..." | ||
| python3 examples/01_minimal_request.py | ||
|
|
||
| echo "" | ||
| echo "[3/5] Running tool execution example..." | ||
| echo "[3/7] Running tool execution example..." | ||
| python3 examples/02_tool_execution.py | ||
|
|
||
| echo "" | ||
| echo "[4/5] Checking CLI help..." | ||
| echo "[4/7] Checking CLI help..." | ||
| python3 -m kernels --help | ||
|
|
||
| echo "" | ||
| echo "[5/5] Checking CLI version..." | ||
| echo "[5/7] Checking CLI version..." | ||
| python3 -m kernels --version | ||
|
|
||
| echo "" | ||
| echo "[6/7] Exercising thread-safe nonce registry..." | ||
| python3 - <<'PY' | ||
| from implementations.permits_threadsafe import ThreadSafeNonceRegistry | ||
|
|
||
| registry = ThreadSafeNonceRegistry(ttl_ms=100) | ||
| assert registry.check_and_record("n", "iss", "sub", "permit", 2, 1000) | ||
| assert registry.check_and_record("n", "iss", "sub", "permit", 2, 1001) | ||
| assert not registry.check_and_record("n", "iss", "sub", "permit", 2, 1002) | ||
| assert registry.cleanup(1205) == 1 | ||
| print("Nonce registry stats:", registry.stats()) | ||
| PY | ||
|
|
||
| echo "" | ||
| echo "[7/7] Exercising SQLite audit storage..." | ||
| python3 - <<'PY' | ||
| from implementations.storage import SQLiteAuditStorage | ||
|
|
||
| entry = { | ||
| "ledger_seq": 1, | ||
| "entry_hash": "h1", | ||
| "prev_hash": "genesis", | ||
| "ts_ms": 1, | ||
| "request_id": "req-1", | ||
| "actor": "smoke", | ||
| "intent": "verify", | ||
| "decision": "allow", | ||
| "state_from": "requested", | ||
| "state_to": "approved", | ||
| } | ||
|
|
||
| storage = SQLiteAuditStorage(".tmp/smoke/audit.db") | ||
| storage.append("kernel-smoke", entry) | ||
|
Comment on lines
+63
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The smoke script always writes to Useful? React with 👍 / 👎. |
||
| print("Storage health:", storage.health()) | ||
| assert storage.list_entries("kernel-smoke")[0]["request_id"] == "req-1" | ||
| PY | ||
|
|
||
| echo "" | ||
| echo "==================" | ||
| echo "Smoke test passed." | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lowering
requires-pythonto 3.9 advertises support that the codebase does not currently have: modules such askernels/execution/dispatcher.pyuse PEP 604 unions (e.g.ToolCall | dict[str, Any]) withoutfrom __future__ import annotations, which raisesTypeErrorduring import on Python 3.9. This means users installing on 3.9 (now allowed by metadata) and the new 3.9 CI lane will fail at runtime/import time rather than getting a compatible build.Useful? React with 👍 / 👎.