fix: критические баги и качество кода — полный аудит

Критические фиксы:
- main.py: монтировать /static из web/static/ (CSS не грузился совсем)
- api/scans.py: filtered total count (был всегда общий, игнорируя фильтры)
- web/routes.py: исправлен VALID_SORT_FIELDS (отсутствовали ключи packages)
- web/routes.py: filtered total count для web scans list
- package_detail.html: f.data.X вместо f.X (findings не отображались)

Чистка мёртвого кода:
- config.py: удалён _parse_repos и nexus_repositories (не использовались)
- web/routes.py: удалён completed_scans/failed_scans (не отображались)
- удалён мёртвый guarddog_nexus/static/style.css (67-байтный стаб)

Качество кода:
- web/routes.py: Jinja2 Environment кэшируется на уровне модуля
- Вынесен дублирующийся JS в web/static/app.js
- Вынесены дублирующиеся inline-стили в CSS-классы
- Исправлен duplicate class attribute в списках
- Удалены гигантские SVG из empty states

Тесты:
- 20 новых edge-case тестов (CSV export, search/filter/sort, 404, pagination)
- Добавлен sample_flagged_scan fixture
- Итого: 50 тестов, все зелёные
This commit is contained in:
Marker689
2026-05-10 03:46:05 +03:00
parent 6c8e89c95e
commit c43e7c4c9b
15 changed files with 329 additions and 145 deletions

View File

@@ -32,7 +32,7 @@
</tbody>
</table>
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem;">
<div class="finding-header-row">
<h2>Findings ({{ findings|length }})</h2>
{% if findings|length > 1 %}
<button class="toggle-all-btn" onclick="toggleFindings()">Collapse All</button>
@@ -42,56 +42,26 @@
{% if findings %}
<div id="findings-container">
{% for f in findings %}
<details class="finding-card {{ f.severity }}" data-finding-id="{{ f.id }}">
<summary style="cursor: pointer; list-style: none; display: flex; align-items: center; gap: 0.5rem; padding: 0.25rem 0;">
<strong class="severity-{{ f.severity }}">[{{ f.severity }}]</strong>
<strong>{{ f.rule }}</strong>
{% if f.location %}<small> @ {{ f.location }}</small>{% endif %}
<span style="margin-left: auto; font-size: 0.8rem; opacity: 0.5;">click to expand</span>
<details class="finding-card {{ f.data.severity }}" data-finding-id="{{ f.id }}">
<summary class="finding-summary">
<strong class="severity-{{ f.data.severity }}">[{{ f.data.severity }}]</strong>
<strong>{{ f.data.rule }}</strong>
{% if f.data.location %}<small> @ {{ f.data.location }}</small>{% endif %}
<span class="finding-summary-hint">click to expand</span>
</summary>
<div class="finding-details">
<p>{{ f.message }}</p>
{% if f.code %}
<div style="display: flex; justify-content: flex-end; margin-bottom: 0.25rem;">
<p>{{ f.data.message }}</p>
{% if f.data.code %}
<div class="code-toolbar">
<button class="copy-btn" onclick="copyCode(this, 'code-{{ f.id }}')">Copy</button>
</div>
<pre><code id="code-{{ f.id }}">{{ f.code }}</code></pre>
<pre><code id="code-{{ f.id }}">{{ f.data.code }}</code></pre>
{% endif %}
</div>
</details>
{% endfor %}
</div>
{% else %}
<div class="empty-state" style="padding: 1rem;">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
<h3>No findings</h3>
<small>Package looks clean.</small>
</div>
<p class="empty-state">No findings — package looks clean.</p>
{% endif %}
{% endblock %}
{% block scripts %}
<script>
function toggleFindings() {
const container = document.getElementById('findings-container');
const details = container.querySelectorAll('details');
const first = details[0];
const isOpen = first && first.open;
details.forEach(d => d.open = !isOpen);
const btn = container.parentElement.querySelector('.toggle-all-btn');
if (btn) btn.textContent = isOpen ? 'Expand All' : 'Collapse All';
}
function copyCode(btn, codeId) {
const code = document.getElementById(codeId).textContent;
navigator.clipboard.writeText(code).then(() => {
btn.textContent = 'Copied!';
btn.classList.add('copied');
setTimeout(() => {
btn.textContent = 'Copy';
btn.classList.remove('copied');
}, 2000);
});
}
</script>
{% endblock %}