From 8d31f9ea5537857eed28da738da67b4cc22e6c73 Mon Sep 17 00:00:00 2001 From: abu-tahir-0 Date: Mon, 16 Nov 2026 16:01:10 +0530 Subject: [PATCH] pre-commit: add a lint hook for a repository's own server The hooks only scanned a running endpoint. toolgauge-lint takes the stdio server command as one argument, reads its manifest on every commit, and needs neither Docker nor an endpoint. --- .pre-commit-hooks.yaml | 16 ++++++++++++++++ docs/USING.md | 2 +- tests/harness/test_distribution.py | 14 +++++++++++--- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 7cc6251..fd3888c 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -30,3 +30,19 @@ pass_filenames: false always_run: true stages: [pre-push, manual] + +# Lint a repository's own stdio MCP server on every commit. The command is one +# `args` entry, so a command with spaces stays one argument: +# +# - id: toolgauge-lint +# args: ["node dist/server.js"] +# +# The server is started once and its manifest is read; it needs no endpoint. +- id: toolgauge-lint + name: toolgauge MCP manifest lint + description: Lint a stdio MCP server's tool manifest and fail on a failed rule. + entry: toolgauge lint --command + language: system + pass_filenames: false + always_run: true + stages: [pre-commit, manual] diff --git a/docs/USING.md b/docs/USING.md index 93b1c76..c6760f0 100644 --- a/docs/USING.md +++ b/docs/USING.md @@ -159,7 +159,7 @@ than one from a single scan. | GitHub | `uses: patsypppe/sentinel@v0.4.0`. Inputs: `endpoint`, `gate`, `config`, `baseline`, `snapshot`, `targets`, `safe`, `no-exec`, `token`. Writes a Markdown job summary, uploads SARIF. | | GitLab | `include:` [`ci/gitlab/toolgauge.gitlab-ci.yml`](../ci/gitlab/toolgauge.gitlab-ci.yml) and `extends: .toolgauge-scan`. Publishes JUnit. | | Any CI | `docker run ghcr.io/patsypppe/toolgauge scan --endpoint ...` | -| pre-commit | the `toolgauge-scan` hook (`pre-push`, so a few hundred requests do not run on every commit) | +| pre-commit | the `toolgauge-scan` hook (`pre-push`, so a few hundred requests do not run on every commit); `toolgauge-lint` checks a stdio server's manifest on every commit | | PyPI | `uvx toolgauge scan --endpoint ...` | Releases are signed with cosign (keyless, from the release workflow's own identity, so there is no diff --git a/tests/harness/test_distribution.py b/tests/harness/test_distribution.py index 47516d9..0631c82 100644 --- a/tests/harness/test_distribution.py +++ b/tests/harness/test_distribution.py @@ -167,14 +167,22 @@ def test_every_flag_the_gitlab_template_passes_exists() -> None: def test_the_precommit_hooks_are_well_formed_and_their_flags_exist() -> None: - hooks = load(".pre-commit-hooks.yaml") - assert {h["id"] for h in hooks} == {"toolgauge-scan", "toolgauge-scan-local"} - for hook in hooks: + hooks = {h["id"]: h for h in load(".pre-commit-hooks.yaml")} + assert set(hooks) == {"toolgauge-scan", "toolgauge-scan-local", "toolgauge-lint"} + for hook_id in ("toolgauge-scan", "toolgauge-scan-local"): + hook = hooks[hook_id] assert hook["pass_filenames"] is False, "a scan is of a server, not of changed files" assert hook["language"] in {"docker_image", "system"} assert "pre-push" in hook["stages"], "a scan makes hundreds of requests" assert set(re.findall(r"--[a-z][a-z0-9-]*", hook["entry"])) <= cli_flags("scan") + lint = hooks["toolgauge-lint"] + assert lint["pass_filenames"] is False + assert lint["language"] == "system", "the server runs on the machine being committed" + assert "pre-commit" in lint["stages"] + assert lint["entry"].endswith("--command"), "the user supplies the command as one argument" + assert set(re.findall(r"--[a-z][a-z0-9-]*", lint["entry"])) <= cli_flags("lint") + def test_the_gitlab_junit_report_is_what_the_scan_writes() -> None: job = load("ci/gitlab/toolgauge.gitlab-ci.yml")[".toolgauge-scan"]