test(hooks): testmon-selected unit tests in the pre-push guard #414
<h3>PR Summary by Qodo</h3>
Run testmon-selected unit tests in the pre-push hook
<code>✨ Enhancement</code> <code>⚙️ Configuration changes</code> <code>🕐 10-20 Minutes</code>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<details>
<summary>AI Description</summary>
<dl>
<dd>
<br/>
><pre>
>• Replace the pre-push coverage run with testmon-selected unit tests to shorten routine pushes.
>• Keep lint on every push and offer FULL=1 for a complete local unit run.
>• Leave full-suite, coverage, and integration enforcement in CI.
></pre>
</dd>
</dl>
</details>
<details>
<summary>Diagram</summary>
<dl>
<dd>
<br/>
graph TD
Push["git push"] --> Hook["Pre-push hook"] --> Lint["make lint"] --> Mode{"FULL=1?"}
Mode -->|No| Selected["Testmon unit tests"] --> CI["CI full gates"]
Mode -->|Yes| Full["Full unit suite"] --> CI
</dd>
</dl>
</details>
<details>
<summary>High-Level Assessment</summary>
<dl>
<dd>
<br/>
>The following are alternative approaches to this PR:
<details>
<summary><b>1. Run only lint locally and rely on CI for tests</b></summary>
<dl>
<dd>
</dd>
</dl>
</details>
<details>
<summary><b>2. Keep the complete local coverage gate</b></summary>
<dl>
<dd>
</dd>
</dl>
</details>
>Recommendation: Keep the proposed split: selected tests provide useful local feedback without repeating CI's full coverage run. Reviewers should accept that import-time changes may not select local tests and will depend on CI; FULL=1 remains available when a complete local run is warranted.
</dd>
</dl>
</details>
<details>
<summary> Files changed (5) <code> +32 / -2 </code> </summary>
<dl>
<dd>
<br/>
<details>
<summary>Enhancement (2) <code> +15 / -2 </code></summary>
<dl>
<dd>
<details>
<summary>pre-push<code>Select fast unit tests by default on push</code> <code>+11/-2</code></summary>
<br/>
>Select fast unit tests by default on push
><pre>
>• Runs lint followed by test-changed instead of coverage. FULL=1 switches the hook to the complete non-integration unit suite.
></pre>
><a href='https://github.com/traust-security/traust-core/pull/414/files#diff-d98b367aa518731b4158dd028ca94d051dfe32fefe54c4affde19f591ebc5fb6'>.githooks/pre-push</a>
</details>
<details>
<summary>Makefile<code>Add a testmon-selected unit-test target</code> <code>+4/-0</code></summary>
<br/>
>Add a testmon-selected unit-test target
><pre>
>• Adds and documents make test-changed, using pytest-testmon forced selection with the existing parallel, non-integration unit-test settings. The existing full-test and coverage targets remain available.
></pre>
><a href='https://github.com/traust-security/traust-core/pull/414/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52'>Makefile</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Other (3) <code> +17 / -0 </code></summary>
<dl>
<dd>
<details>
<summary>.gitignore<code>Ignore testmon's local selection data</code> <code>+1/-0</code></summary>
<br/>
>Ignore testmon's local selection data
><pre>
>• Excludes .testmondata from version control so the local test-selection database stays checkout-specific.
></pre>
><a href='https://github.com/traust-security/traust-core/pull/414/files#diff-bc37d034bad564583790a46f19d807abfe519c5671395fd494d8cce506c42947'>.gitignore</a>
</details>
<details>
<summary>pyproject.toml<code>Declare pytest-testmon as a development dependency</code> <code>+1/-0</code></summary>
<br/>
>Declare pytest-testmon as a development dependency
><pre>
>• Adds pytest-testmon to the dev dependency group for the new local test target.
></pre>
><a href='https://github.com/traust-security/traust-core/pull/414/files#diff-50c86b7ed8ac2cf95bd48334961bf0530cdc77b5a56f852c5c61b89d735fd711'>pyproject.toml</a>
</details>
<details>
<summary>uv.lock<code>Lock pytest-testmon 2.3.0</code> <code>+15/-0</code></summary>
<br/>
>Lock pytest-testmon 2.3.0
><pre>
>• Adds the pytest-testmon package and records it in the project's locked dev dependencies without unrelated package revisions.
></pre>
><a href='https://github.com/traust-security/traust-core/pull/414/files#diff-84321598744d84dbee2318e634c74c9aae39a1c253f1c4bd17ebf9ef2f807b11'>uv.lock</a>
</details>
</dd>
</dl>
</details>
</dd>
</dl>
</details>
<h3>Code Review by Qodo</h3>
<br/>
<details><summary><ins><strong>View low (1)</strong></ins></summary><br/>
<img src="https://img.shields.io/badge/Low-634FD1?style=flat-square" height="20px" alt="Informational">
<details>
<summary> 1. Local push no longer enforces the 80% coverage gate <code>🐞 Bug</code> <code>⭐ New</code> <code>👈 Shift left</code></summary>
<br/>
<details>
><summary>Description</summary>
><br/>
><pre>
>The hook drops <b><i>make coverage</i></b> and so no longer fails a push that takes coverage below the
><b><i>fail_under</i></b> threshold in pyproject. Coverage regressions are now detected only after the push, in
>the CI job that runs <b><i>make coverage</i></b>.
></pre>
></details>
<details>
><summary>Agent prompt</summary>
><br/>
>>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution > >## Issue description >The pre-push hook no longer runs the coverage gate, so a push that drops coverage below 80% is accepted locally and only fails in CI. > >## Fix Focus Areas >- .githooks/pre-push[1-16] > >## Recommended Fix >This is an intentional trade-off; keep it but make the header and any contributor docs say that coverage is enforced only in CI, and point developers to `make coverage` before large changes. >
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
</details>
</details>
<br/>
<!-- qodo-self-review-slot -->
<!-- https://github.com/traust-security/traust-core/commit/8378b7ff2f881d7fd33a0f2c7fa3e491fde2c520 -->
<h3>Code Review by Qodo</h3>
<code>🐞 Bugs (1)</code> <code>📘 Rule violations (0)</code> <code>📜 Skill insights (0)</code>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<br/>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
<details>
<summary> 1. Data-file changes can pass the push guard <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
<details open>
><summary>Description</summary>
><br/>
><pre>
><b><i>test-changed</i></b> selects tests from executed-code dependencies, so it does not select a test merely
>because that test reads a changed YAML file or parses changed Python source as text. If a shipped
>YAML file becomes invalid, or an import violates a rule checked by the source-reading architecture
>tests, the default hook can pass without running the relevant test; CI's full suite still runs it.
></pre>
></details>
<details>
><summary>Code</summary>
><br/>
><code>[Makefile[65]](https://github.com/traust-security/traust-core/pull/414/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52R65-R65)</code>
>>+ uv run pytest tests/ -q -n auto -m "not integration" --testmon-forceselect >
></details>
<details>
><summary>Evidence</summary>
><br/>
><pre>
>The shipped-file test reads and validates YAML, while the architecture tests read Python files with
><b><i>read_text()</i></b> and parse them; neither operation executes the changed input as test-covered code.
>Testmon's maintainer confirms that ordinary file I/O is not tracked as a dependency. The hook now
>relies on this selection by default, whereas CI still runs <b><i>make coverage</i></b>.
></pre>
> <code>[tests/v1/context/test_traust_yaml.py\[255-268\]](https://github.com/traust-security/traust-core/blob/8378b7ff2f881d7fd33a0f2c7fa3e491fde2c520/tests/v1/context/test_traust_yaml.py/#L255-L268)</code>
<code>[tests/v1/test_architecture.py\[52-54\]](https://github.com/traust-security/traust-core/blob/8378b7ff2f881d7fd33a0f2c7fa3e491fde2c520/tests/v1/test_architecture.py/#L52-L54)</code>
<code>[tests/v1/test_layering.py\[54-70\]](https://github.com/traust-security/traust-core/blob/8378b7ff2f881d7fd33a0f2c7fa3e491fde2c520/tests/v1/test_layering.py/#L54-L70)</code>
<code>[.github/workflows/ci.yml\[27-44\]](https://github.com/traust-security/traust-core/blob/8378b7ff2f881d7fd33a0f2c7fa3e491fde2c520/.github/workflows/ci.yml/#L27-L44)</code>
<code>🌐 The testmon maintainer states that reading a data file does not register it as a code dependency.</code>
></details>
<details>
><summary>Agent prompt</summary>
><br/>
>>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution > >## Issue description >The selected-test push guard misses tests whose changed inputs are read as data rather than executed as Python code. > >## Fix Focus Areas >- Makefile[64-65] >- .githooks/pre-push[11-16] > >## Recommended Fix >Run the shipped-configuration validation and source-reading architecture tests in addition to the testmon selection, or add a reliable changed-input mapping for them. Add a guard regression that changes a shipped YAML file and confirms its validation test runs. >
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details>
<summary> 2. <s>A local filename can skip push tests</s> <code>✓ Resolved</code></summary>
<br/>
<p><b>Resolving commit:</b> <a href="https://github.com/traust-security/traust-core/commit/8378b7ff2f881d7fd33a0f2c7fa3e491fde2c520"><code>8378b7f</code></a></p>
<details>
><summary>Resolution reason</summary>
><br/>
><pre>
>Added <b><i>test-changed</i></b> to the Makefile's .PHONY declaration, so make always runs the target's pytest
>recipe regardless of any same-named file or directory at the repository root.
></pre>
></details>
<!-- qodo-finding-reference
<code>↗ Makefile[R64-65]</code>
-->
<details>
><summary>Description</summary>
><br/>
><pre>
><b><i>test-changed</i></b> is added as a Make target but not to the existing <b><i>.PHONY</i></b> declaration. If a file or
>directory named <b><i>test-changed</i></b> exists at the repository root, Make treats the target as up to date,
>and the default pre-push hook proceeds without invoking pytest.
></pre>
></details>
<hr/>
</details>
<br/>
<img src="https://img.shields.io/badge/Low-634FD1?style=flat-square" height="20px" alt="Informational">
<details>
<summary> 3. <s>Push guidance still promises coverage</s> <code>✓ Resolved</code></summary>
<br/>
<p><b>Resolving commit:</b> <a href="https://github.com/traust-security/traust-core/commit/8378b7ff2f881d7fd33a0f2c7fa3e491fde2c520"><code>8378b7f</code></a></p>
<details>
><summary>Resolution reason</summary>
><br/>
><pre>
>The setup message in Makefile and the README development section now describe the selected-test
>default, the FULL=1 full-suite option, and CI coverage, instead of promising local coverage on push.
></pre>
></details>
<!-- qodo-finding-reference
<code>↗ .githooks/pre-push[L7]</code>
-->
<details>
><summary>Description</summary>
><br/>
><pre>
>The hook replaces <b><i>make coverage</i></b> with <b><i>make test-changed</i></b> by default and <b><i>make test</i></b> under
><b><i>FULL=1</i></b>, but the setup message and developer instructions still say the pre-push hook runs
>coverage. Developers and agents following those instructions are therefore told that a local
>coverage gate ran when coverage is now enforced by CI instead.
></pre>
></details>
<hr/>
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-self-review-slot -->
<!-- qodo-context:start -->
<details><summary><strong>Context sources</strong></summary>
<div>Review mode: <code>Auto: 🚀 Fast</code>: Makefile .PHONY, help and echo text plus README line; no logic change.</div>
<div>✅ Fix-loop round: <code>fix loop</code></div>
<!-- qodo-context:end -->
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-daily-tip:start -->
<details>
<summary><strong>Tip of the day</strong></summary>
<br/>
<pre>💡 Did you know, you can move or hide resolved findings to focus on what still needs action</pre>
<a href="https://docs.qodo.ai/tips-and-tricks">More tips ↗</a> | <a href="https://app.qodo.ai/configurations?tab=display-preferences">Customize Qodo ↗</a> | <a href="https://docs.qodo.ai">Qodo docs ↗</a>
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-daily-tip:end -->
<!-- https://github.com/traust-security/traust-core/commit/8378b7ff2f881d7fd33a0f2c7fa3e491fde2c520 -->
<!-- qodo-previous-reviews:start -->
<!-- FOLDED_SECTION_START -->
<details>
<summary><strong>Previous reviews</strong></summary>
<br/>
Review updated until commit <a href="https://github.com/traust-security/traust-core/commit/8378b7ff2f881d7fd33a0f2c7fa3e491fde2c520">8378b7f</a>
<details><summary>Results up to commit 3bde9ff <code>⚖️ Balanced</code></summary>
<br><code>🐞 Bugs (1)</code> <code>📘 Rule violations (0)</code> <code>📎 Requirement gaps (0)</code> <code>🎨 UX issues (0)</code> <code>🔗 Cross-repo conflicts (0)</code> <code>📜 Skill insights (0)</code>
<br/>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
<details>
<summary> 1. Data-file changes can pass the push guard <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
<details open>
><summary>Description</summary>
><br/>
><pre>
><b><i>test-changed</i></b> selects tests from executed-code dependencies, so it does not select a test merely
>because that test reads a changed YAML file or parses changed Python source as text. If a shipped
>YAML file becomes invalid, or an import violates a rule checked by the source-reading architecture
>tests, the default hook can pass without running the relevant test; CI's full suite still runs it.
></pre>
></details>
<details>
><summary>Code</summary>
><br/>
><code>[Makefile[65]](https://github.com/traust-security/traust-core/pull/414/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52R65-R65)</code>
>>+ uv run pytest tests/ -q -n auto -m "not integration" --testmon-forceselect >
></details>
<details>
><summary>Evidence</summary>
><br/>
><pre>
>The shipped-file test reads and validates YAML, while the architecture tests read Python files with
><b><i>read_text()</i></b> and parse them; neither operation executes the changed input as test-covered code.
>Testmon's maintainer confirms that ordinary file I/O is not tracked as a dependency. The hook now
>relies on this selection by default, whereas CI still runs <b><i>make coverage</i></b>.
></pre>
> <code>[tests/v1/context/test_traust_yaml.py\[255-268\]](https://github.com/traust-security/traust-core/blob/8378b7ff2f881d7fd33a0f2c7fa3e491fde2c520/tests/v1/context/test_traust_yaml.py/#L255-L268)</code>
<code>[tests/v1/test_architecture.py\[52-54\]](https://github.com/traust-security/traust-core/blob/8378b7ff2f881d7fd33a0f2c7fa3e491fde2c520/tests/v1/test_architecture.py/#L52-L54)</code>
<code>[tests/v1/test_layering.py\[54-70\]](https://github.com/traust-security/traust-core/blob/8378b7ff2f881d7fd33a0f2c7fa3e491fde2c520/tests/v1/test_layering.py/#L54-L70)</code>
<code>[.github/workflows/ci.yml\[27-44\]](https://github.com/traust-security/traust-core/blob/8378b7ff2f881d7fd33a0f2c7fa3e491fde2c520/.github/workflows/ci.yml/#L27-L44)</code>
<code>🌐 The testmon maintainer states that reading a data file does not register it as a code dependency.</code>
></details>
<details>
><summary>Agent prompt</summary>
><br/>
>>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution > >## Issue description >The selected-test push guard misses tests whose changed inputs are read as data rather than executed as Python code. > >## Fix Focus Areas >- Makefile[64-65] >- .githooks/pre-push[11-16] > >## Recommended Fix >Run the shipped-configuration validation and source-reading architecture tests in addition to the testmon selection, or add a reliable changed-input mapping for them. Add a guard regression that changes a shipped YAML file and confirms its validation test runs. >
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details>
<summary> 2. <s>A local filename can skip push tests</s> <code>✓ Resolved</code></summary>
<br/>
<p><b>Resolving commit:</b> <a href="https://github.com/traust-security/traust-core/commit/8378b7ff2f881d7fd33a0f2c7fa3e491fde2c520"><code>8378b7f</code></a></p>
<details>
><summary>Resolution reason</summary>
><br/>
><pre>
>Added <b><i>test-changed</i></b> to the Makefile's .PHONY declaration, so make always runs the target's pytest
>recipe regardless of any same-named file or directory at the repository root.
></pre>
></details>
<!-- qodo-finding-reference
<code>↗ Makefile[R64-65]</code>
-->
<details>
><summary>Description</summary>
><br/>
><pre>
><b><i>test-changed</i></b> is added as a Make target but not to the existing <b><i>.PHONY</i></b> declaration. If a file or
>directory named <b><i>test-changed</i></b> exists at the repository root, Make treats the target as up to date,
>and the default pre-push hook proceeds without invoking pytest.
></pre>
></details>
<hr/>
</details>
<br/>
<img src="https://img.shields.io/badge/Low-634FD1?style=flat-square" height="20px" alt="Informational">
<details>
<summary> 3. <s>Push guidance still promises coverage</s> <code>✓ Resolved</code></summary>
<br/>
<p><b>Resolving commit:</b> <a href="https://github.com/traust-security/traust-core/commit/8378b7ff2f881d7fd33a0f2c7fa3e491fde2c520"><code>8378b7f</code></a></p>
<details>
><summary>Resolution reason</summary>
><br/>
><pre>
>The setup message in Makefile and the README development section now describe the selected-test
>default, the FULL=1 full-suite option, and CI coverage, instead of promising local coverage on push.
></pre>
></details>
<!-- qodo-finding-reference
<code>↗ .githooks/pre-push[L7]</code>
-->
<details>
><summary>Description</summary>
><br/>
><pre>
>The hook replaces <b><i>make coverage</i></b> with <b><i>make test-changed</i></b> by default and <b><i>make test</i></b> under
><b><i>FULL=1</i></b>, but the setup message and developer instructions still say the pre-push hook runs
>coverage. Developers and agents following those instructions are therefore told that a local
>coverage gate ran when coverage is now enforced by CI instead.
></pre>
></details>
<hr/>
</details>
<!-- qodo-self-review-slot -->
</details>
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-previous-reviews:end -->
<a href="https://www.qodo.ai"><img src="https://www.qodo.ai/wp-content/uploads/2025/03/qodo-logo.svg" width="80" alt="Qodo Logo"></a>
Code review by qodo was updated up to the latest commit https://github.com/traust-security/traust-core/commit/8378b7ff2f881d7fd33a0f2c7fa3e491fde2c520
/lgtm
gurnben
smith-xyz
What
make lint+make test-changed(pytest-testmon--testmon-forceselect) instead ofmake lint+make coverage— only the tests whose executed code the diff touches run locally (~5–15s typical vs 2.5–3.5 min).FULL=1 git pushruns the complete unit suite through the hook;make testremains the manual full run;make coveragemoves to CI-only (CI already ran the same checks the hook duplicated — the hook header said so itself)..testmondataignored; first run per checkout builds the baseline (~60–85s, one-time); stale/missing data falls back to a full run — worst case is today's speed, never a silent skip.Decisions
--testmon-forceselect, not--testmon: plain testmon silently deactivates selection under-mfilters (-m "not integration"forces noselect → always a full run).Model.model_configextra=selects zero tests.FULL=1runs all 11,971 tests in ~57s.Tests
make lintgreen; full unit suite green (11,971 passed) via theFULL=1hook path on this exact tree.Plan: none — developer-workflow change, no work item.