Repository navigation
chore: development commands (Makefile) and read-only pre-commit checks - #46
pawelkiszczak wants to merge 5 commits into
Conversation
sglang, strix, tpu and llamacpp were added to basal-serve after this branch was first written; the help text and the serving-mode test follow basal.server.MODES of 2.4.1.
Reviewer's GuideAdds reproducible, configurable Makefile commands and opt-in pinned pre-commit checks without changing application code or dependencies, with documentation and standard-library coverage for command construction, early validation, and strict JSONL syntax checking. Sequence diagram for validated batch executionsequenceDiagram
participant Developer
participant Make as Makefile
participant Python as PYTHON
participant Server as basal.server
participant Runner as basal.run
Developer->>Make: make serve MODE=... HOST=... PORT=...
Make->>Make: check-backend
Make->>Python: -m basal.server
Python->>Server: start with backend and host options
Server-->>Developer: server ready
Developer->>Make: make run INPUT=... OUTPUT=...
Make->>Make: check-input
Make->>Python: -m basal.run --url --input --output
Python->>Runner: process batch requests
Runner-->>Developer: write output file
Flow diagram for Makefile development commandsflowchart TD
Start[make target] --> Validate{Validation needed}
Validate -->|backend options| Backend[check-backend]
Validate -->|input and output files| Input[check-input]
Validate -->|none| Launch
Backend --> Launch[Invoke selected PYTHON module]
Input --> Launch
Launch --> Serve[basal.server]
Launch --> Bench[basal.bench]
Launch --> Run[basal.run]
Launch --> Loadtest[basal.loadtest]
Flow diagram for read-only development checksflowchart LR
Check[make check] --> Precommit[pre-commit run --all-files]
Precommit --> Ruff[Ruff critical Python errors]
Precommit --> Files[Conflict markers and private keys]
Precommit --> Structured[TOML YAML JSON checks]
Precommit --> JSONL[check_jsonl.py]
Ruff --> Result[Pass or report findings]
Files --> Result
Structured --> Result
JSONL --> Result
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 7 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="Makefile" line_range="39" />
<code_context>
+ "$$UV" tool run pre-commit==4.7.0 run --all-files
+
+test:
+ "$$PYTHON" -m pytest $(ARGS)
+
+check-backend:
</code_context>
<issue_to_address>
**Extra options execute shell commands**
When a wrapper or CI job forwards an attacker-controlled `ARGS` value, the recipe expands `ARGS` directly into shell command text, so shell metacharacters in that value run arbitrary commands alongside the requested target; an attacker who can supply `ARGS` through a wrapper or CI input gets command execution as the make process.
Do not interpolate untrusted `ARGS` as shell text; pass additional options through a safely encoded argument vector or accept only validated, trusted values.
Also at `Makefile:53`, `Makefile:58`, `Makefile:62`, `Makefile:66`.
</issue_to_address>
### Comment 2
<location path="Makefile" line_range="7" />
<code_context>
+EXTRAS ?= test
+MODEL ?= Remek/basal-1.0-4.5B
+MODE ?=
+HOST ?= 0.0.0.0
+PORT ?= 8000
+URL ?= http://127.0.0.1:$(PORT)/v1/systemone
</code_context>
<issue_to_address>
**Server listens on every interface**
When the machine running `make serve` is reachable by other network peers, the `serve` target passes the default `0.0.0.0` host to an unauthenticated server, allowing network peers to submit inference requests and consume the machine's backend resources.
Default the Make target to `127.0.0.1` and require an explicit host override to listen on external interfaces.
Also at `Makefile:50`.
</issue_to_address>
### Comment 3
<location path="Makefile" line_range="66" />
<code_context>
+ "$$PYTHON" -m basal.bench --model "$$MODEL" \
+ $(if $(MODE),--modes "$$MODE") $(if $(GGUF),--gguf "$$GGUF") \
+ $(if $(OLLAMA_MODEL),--ollama-model "$$OLLAMA_MODEL") \
+ $(if $(INPUT),--questions "$$INPUT") $(if $(OUTPUT),--out "$$OUTPUT") $(ARGS)
+
+run: check-input
</code_context>
<issue_to_address>
**Load-test output leaks URL credentials**
When the configured URL contains credentials or a signed token and the logs or output artifact are visible to other users, `basal.loadtest` records the configured URL verbatim in its results and prints it to stdout; credentials or signed query tokens in `URL` therefore appear in logs and any `OUTPUT` artifact, where other users can read them.
Redact URL user information and sensitive query parameters before printing or writing load-test results.
</issue_to_address>
### Comment 4
<location path="Makefile" line_range="62" />
<code_context>
+
+run: check-input
+ @test -n "$$INPUT" && test -n "$$OUTPUT" || { echo 'run requires INPUT=<file> and OUTPUT=<file>' >&2; exit 1; }
+ "$$PYTHON" -m basal.run --url "$$URL" --input "$$INPUT" --output "$$OUTPUT" $(ARGS)
+
+loadtest: check-input
</code_context>
<issue_to_address>
**Batch runs overwrite their input**
When `INPUT` and `OUTPUT` refer to the same file, `basal.run.run` reads the questions and then opens the output with mode `w`, replacing the source JSONL with answer rows; the benchmark and load-test recipes likewise pass both paths without checking that they differ, so the source dataset is lost.
Reject input/output paths that resolve to the same file before launching each command.
Also at `Makefile:58`, `Makefile:66`.
</issue_to_address>
### Comment 5
<location path=".pre-commit-config.yaml" line_range="16" />
<code_context>
+ hooks:
+ - id: ruff-check
+ types_or: [python, pyi]
+ args: [--select, 'E9,F63,F7,F82', --target-version, py310, --no-fix, --no-cache]
+
+ - repo: local
</code_context>
<issue_to_address>
**Default checks fail on an existing finding**
When the existing F821 in `basal/gemma4.py:471` remains, ruff selects `F82` and reports the undefined `kpos` in `Gemma4Forward._prefix`, so `make check` exits nonzero even when the files changed by the PR are clean.
Fix the existing `F821` or configure the hook so it does not make the default check fail on this finding.
</issue_to_address>
### Comment 6
<location path="scripts/check_jsonl.py" line_range="15" />
<code_context>
+ if not line.strip(): # The batch runner also skips blank lines.
+ continue
+ try:
+ json.loads(line)
+ except ValueError as error:
+ print(f"{filename}:{number}: {error}")
</code_context>
<issue_to_address>
**Invalid JSON values pass validation**
When a JSONL line contains `NaN`, `Infinity`, or `-Infinity`, `json.loads` accepts these non-standard constants by default, so `check_jsonl.py` reports the line as valid and strict JSON consumers reject the file.
Reject non-standard constants when parsing each JSONL line.
</issue_to_address>
### Comment 7
<location path="Makefile" line_range="5" />
<code_context>
+PYTHON ?= .venv/bin/python
+UV ?= uv
+EXTRAS ?= test
+MODEL ?= Remek/basal-1.0-4.5B
+MODE ?=
+HOST ?= 0.0.0.0
</code_context>
<issue_to_address>
**Make targets use a different checkpoint**
When `MODEL` is not overridden, `serve` and `bench` pass `MODEL` explicitly, overriding both CLIs’ `Remek/basal-1.5-4.5B` default with `Remek/basal-1.0-4.5B`, so users get a different checkpoint and benchmark defaults than when invoking the CLIs directly.
Set the Makefile’s default `MODEL` to the CLIs’ `Remek/basal-1.5-4.5B` default.
</issue_to_address>| "$$UV" tool run pre-commit==4.7.0 run --all-files | ||
|
|
||
| test: | ||
| "$$PYTHON" -m pytest $(ARGS) |
There was a problem hiding this comment.
🟠 High · Extra options execute shell commands
When a wrapper or CI job forwards an attacker-controlled ARGS value, the recipe expands ARGS directly into shell command text, so shell metacharacters in that value run arbitrary commands alongside the requested target; an attacker who can supply ARGS through a wrapper or CI input gets command execution as the make process.
Do not interpolate untrusted ARGS as shell text; pass additional options through a safely encoded argument vector or accept only validated, trusted values.
Also at Makefile:53, Makefile:58, Makefile:62, Makefile:66.
Prompt for AI agents
In `Makefile` at line 39:
**Extra options execute shell commands**
When a wrapper or CI job forwards an attacker-controlled `ARGS` value, the recipe expands `ARGS` directly into shell command text, so shell metacharacters in that value run arbitrary commands alongside the requested target; an attacker who can supply `ARGS` through a wrapper or CI input gets command execution as the make process.
Do not interpolate untrusted `ARGS` as shell text; pass additional options through a safely encoded argument vector or accept only validated, trusted values.
Also at `Makefile:53`, `Makefile:58`, `Makefile:62`, `Makefile:66`.|
|
||
| loadtest: check-input | ||
| "$$PYTHON" -m basal.loadtest --url "$$URL" \ | ||
| $(if $(INPUT),--questions "$$INPUT") $(if $(OUTPUT),--out "$$OUTPUT") $(ARGS) |
There was a problem hiding this comment.
🟡 Medium · Load-test output leaks URL credentials
When the configured URL contains credentials or a signed token and the logs or output artifact are visible to other users, basal.loadtest records the configured URL verbatim in its results and prints it to stdout; credentials or signed query tokens in URL therefore appear in logs and any OUTPUT artifact, where other users can read them.
Redact URL user information and sensitive query parameters before printing or writing load-test results.
Prompt for AI agents
In `Makefile` at line 66:
**Load-test output leaks URL credentials**
When the configured URL contains credentials or a signed token and the logs or output artifact are visible to other users, `basal.loadtest` records the configured URL verbatim in its results and prints it to stdout; credentials or signed query tokens in `URL` therefore appear in logs and any `OUTPUT` artifact, where other users can read them.
Redact URL user information and sensitive query parameters before printing or writing load-test results.| hooks: | ||
| - id: ruff-check | ||
| types_or: [python, pyi] | ||
| args: [--select, 'E9,F63,F7,F82', --target-version, py310, --no-fix, --no-cache] |
There was a problem hiding this comment.
🟠 High · Default checks fail on an existing finding
When the existing F821 in basal/gemma4.py:471 remains, ruff selects F82 and reports the undefined kpos in Gemma4Forward._prefix, so make check exits nonzero even when the files changed by the PR are clean.
Fix the existing F821 or configure the hook so it does not make the default check fail on this finding.
Prompt for AI agents
In `.pre-commit-config.yaml` at line 16:
**Default checks fail on an existing finding**
When the existing F821 in `basal/gemma4.py:471` remains, ruff selects `F82` and reports the undefined `kpos` in `Gemma4Forward._prefix`, so `make check` exits nonzero even when the files changed by the PR are clean.
Fix the existing `F821` or configure the hook so it does not make the default check fail on this finding.- make serve listens on 127.0.0.1; HOST=0.0.0.0 is an explicit choice - MODEL empty: serve and bench keep the CLIs' own default model instead of a second, diverging default - run, bench and loadtest refuse an OUTPUT that is the INPUT file (same path or same file under another spelling) - check_jsonl rejects NaN, Infinity and -Infinity, which json.loads accepts and strict JSON readers do not - README: the new defaults; ARGS runs as shell text, trusted input only
|
Thanks for the review. Addressed in d5cccff:
Not changed, with the reason:
Re-run on |
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path=".pre-commit-config.yaml" line_range="16" />
<code_context>
+ hooks:
+ - id: ruff-check
+ types_or: [python, pyi]
+ args: [--select, 'E9,F63,F7,F82', --target-version, py310, --no-fix, --no-cache]
+
+ - repo: local
</code_context>
<issue_to_address>
**Checks fail on existing lint error**
When `make check` runs against the repository contents in this PR, the all-files Ruff hook selects F821 through F82 and reports the existing `kpos` reference in `basal/gemma4.py`, so pre-commit exits nonzero and `make check` fails.
Fix the existing `kpos` reference or configure the hook so the new check passes on this tree.
Also at `Makefile:37`.
</issue_to_address>
### Comment 2
<location path="Makefile" line_range="61" />
<code_context>
+ - id: check-toml
+ - id: check-yaml
+ - id: check-json
+
+ - repo: https://github.com/astral-sh/ruff-pre-commit
+ rev: v0.17.1
</code_context>
<issue_to_address>
**Input data gets truncated**
When `ARGS` supplies a later output option equal to the input path, including a later input/output pair that selects the same file, the Make recipes append `ARGS` after the checked file options, so the CLI uses the later values and opens the input as its output, truncating the source file.
Prevent `ARGS` from overriding the checked input and output options, or validate the effective options after applying `ARGS`.
Also at `Makefile:60`, `Makefile:64`, `Makefile:68`.
</issue_to_address>
### Comment 3
<location path="scripts/check_jsonl.py" line_range="17" />
<code_context>
+ try:
+ with open(filename, encoding="utf-8") as source:
+ for number, line in enumerate(source, 1):
+ if not line.strip(): # The batch runner also skips blank lines.
+ continue
+ try:
</code_context>
<issue_to_address>
**Invalid JSONL passes validation**
When a JSONL file contains a line consisting only of non-JSON Unicode whitespace, `line.strip()` treats Unicode whitespace such as a non-breaking space as blank, so the checker skips that line instead of passing it to `json.loads`; a file containing it passes the advertised JSONL syntax check despite not being valid JSON whitespace.
Check for blank lines using only JSON whitespace characters (`space`, tab, CR, and LF) before parsing.
</issue_to_address>| hooks: | ||
| - id: ruff-check | ||
| types_or: [python, pyi] | ||
| args: [--select, 'E9,F63,F7,F82', --target-version, py310, --no-fix, --no-cache] |
There was a problem hiding this comment.
🟡 Medium · Checks fail on existing lint error
When make check runs against the repository contents in this PR, the all-files Ruff hook selects F821 through F82 and reports the existing kpos reference in basal/gemma4.py, so pre-commit exits nonzero and make check fails.
Fix the existing kpos reference or configure the hook so the new check passes on this tree.
Also at Makefile:37.
Prompt for AI agents
In `.pre-commit-config.yaml` at line 16:
**Checks fail on existing lint error**
When `make check` runs against the repository contents in this PR, the all-files Ruff hook selects F821 through F82 and reports the existing `kpos` reference in `basal/gemma4.py`, so pre-commit exits nonzero and `make check` fails.
Fix the existing `kpos` reference or configure the hook so the new check passes on this tree.
Also at `Makefile:37`.| $(if $(MODE),--modes "$$MODE") $(if $(GGUF),--gguf "$$GGUF") \ | ||
| $(if $(OLLAMA_MODEL),--ollama-model "$$OLLAMA_MODEL") \ | ||
| $(if $(INPUT),--questions "$$INPUT") $(if $(OUTPUT),--out "$$OUTPUT") $(ARGS) | ||
|
|
There was a problem hiding this comment.
🟠 High · Input data gets truncated
When ARGS supplies a later output option equal to the input path, including a later input/output pair that selects the same file, the Make recipes append ARGS after the checked file options, so the CLI uses the later values and opens the input as its output, truncating the source file.
Prevent ARGS from overriding the checked input and output options, or validate the effective options after applying ARGS.
Also at Makefile:60, Makefile:64, Makefile:68.
Prompt for AI agents
In `Makefile` at line 61:
**Input data gets truncated**
When `ARGS` supplies a later output option equal to the input path, including a later input/output pair that selects the same file, the Make recipes append `ARGS` after the checked file options, so the CLI uses the later values and opens the input as its output, truncating the source file.
Prevent `ARGS` from overriding the checked input and output options, or validate the effective options after applying `ARGS`.
Also at `Makefile:60`, `Makefile:64`, `Makefile:68`.| try: | ||
| with open(filename, encoding="utf-8") as source: | ||
| for number, line in enumerate(source, 1): | ||
| if not line.strip(): # The batch runner also skips blank lines. |
There was a problem hiding this comment.
🟡 Medium · Invalid JSONL passes validation
When a JSONL file contains a line consisting only of non-JSON Unicode whitespace, line.strip() treats Unicode whitespace such as a non-breaking space as blank, so the checker skips that line instead of passing it to json.loads; a file containing it passes the advertised JSONL syntax check despite not being valid JSON whitespace.
Check for blank lines using only JSON whitespace characters (space, tab, CR, and LF) before parsing.
Prompt for AI agents
In `scripts/check_jsonl.py` at line 17:
**Invalid JSONL passes validation**
When a JSONL file contains a line consisting only of non-JSON Unicode whitespace, `line.strip()` treats Unicode whitespace such as a non-breaking space as blank, so the checker skips that line instead of passing it to `json.loads`; a file containing it passes the advertised JSONL syntax check despite not being valid JSON whitespace.
Check for blank lines using only JSON whitespace characters (`space`, tab, CR, and LF) before parsing.… for the seven 2.5 pull requests
…z Koryto) Without .github/dependabot.yml: automatic dependency pull requests are the maintainer's call. The conflict in basal/gemma4.py keeps 2.5's kpos fix from #46 (None until the first keys).
Problem
Launching basal-serve, a benchmark, a batch run or a load test means assembling the command line by hand each time (mode, model, host / port, GGUF file, Ollama import, input / output files), and the repository has no commit checks for syntax errors, merge-conflict markers, private keys or broken TOML / YAML / JSON / JSONL files.
Change
Makefile(default target:help):setup,check,test,serve,bench,run,loadtest.MODEselects any of basal-serve's 16 modes (basal.server.MODESof 2.4.1: eager, fast, fast-nocompile, fast-exit, fp8, nvfp4, vllm, sglang, mlx, mlx-q8, mps, gguf, strix, tpu, ollama, llamacpp);MODEL(default: the CLIs' own),HOST(default127.0.0.1),PORT,URL,INPUT,OUTPUT,GGUF,OLLAMA_MODELandARGSare configurable. Commands call the selectedPYTHONdirectly, so they never sync the environment or replace the installed PyTorch build.MODE=ggufwithoutGGUF,MODE=ollamawithoutOLLAMA_MODEL, unreadable input files and anOUTPUTthat is theINPUTfile fail before anything is launched..pre-commit-config.yaml: seven pinned, read-only hooks: RuffE9,F63,F7,F82(syntax and critical errors only, no formatting), merge-conflict markers, private keys, TOML, YAML, JSON, and a standard-library JSONL checker (scripts/check_jsonl.py) for the bundled example files. Installing the Git hook is opt-in (pre-commit install);make checkruns them without installing anything.tests/test_makefile.py(command construction for every mode, quoted values, early failures, an interpreter path with spaces; fake Python / uv executables, standard library only) andtests/test_check_jsonl.py.App source, dependencies and
uv.lockare unchanged.Tests
On
main@ b20f0f9 (2.4.1), Apple M4 Max, macOS:python3 -m unittest tests/test_makefile.py tests/test_check_jsonl.pyuv run pytest -q(whole suite)uvx pre-commit==4.7.0 validate-configuvx pre-commit==4.7.0 run --all-filesmake serve MODE=mlx MODEL=Remek/basal-2.0-mini-MLX-8bit HOST=127.0.0.1 PORT=8771make run PORT=8771 INPUT=basal/examples/questions.jsonl OUTPUT=…Ruff finding in existing code (not changed here)
F821 Undefined name kposatbasal/gemma4.py:471, inGemma4Forward._prefix:ctx=(kv, kpos) if kv else Nonereadskpos, which is first assigned at the end of the loop body (line 483). At runtime it is always defined when read (kvis empty in the first part, andkposis set beforekvcan be non-empty), so this is not a crash, butmake checkfails on it until the name is defined before the loop, e.g.kv, bufs, kpos = {}, {}, {}. Left to you, since it touches the engine.Not done / not tested
make serve/benchfor the CUDA modes (fast, fp8, nvfp4, fast-exit, vllm, sglang), gguf, ollama, llamacpp, strix and tpu are covered by the command-construction tests only.make benchandmake loadtestwere not run against a real server (command construction tests only).pre-commit installis opt-in and documented).Summary by Sourcery
Provide configurable development commands and opt-in read-only repository checks without changing application dependencies or source behavior.
New Features:
Enhancements:
Documentation:
Tests: