Przejdź do treści
Biblioteka skilli
Programowanie · Testowanie

testing-workflow

/testing-workflow

Pokazuje, jak uruchamiać pojedyncze testy i całe zestawy, uwierzytelniać się tokenem API i unikać wzajemnego zanieczyszczania testów.

Repozytorium
NetAlertX ↗
Licencja
GPL-3.0
Ostatnia zmiana repozytorium
27.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 27.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

GPL-3.0, otwarta.

Co robi i kiedy

Pokazuje, jak uruchamiać pojedyncze testy i całe zestawy, uwierzytelniać się tokenem API i unikać wzajemnego zanieczyszczania testów.

Oryginalny opis (EN)

Read before running tests. Detailed instructions for single tests, full suites, authentication, obtaining the API Token, and a real cross-test pollution pitfall. Use this when asked to run tests, check failures, or debug failing tests.

Jak działa

  1. 0. Pre-requisites: Environment Check
  2. 1. Check for Pre-Existing Failures First
  3. 2. Full Test Suite (default)
  4. 3. Fast Unit Tests (only when explicitly requested)
  5. 4. Running Specific Tests
  6. PYTHONPATH
  7. Authentication & Environment Reset
  8. Docker Test Image
  9. Pitfall: sys.modules Stubbing Leaks Across Test Files
Sekcje z nagłówków SKILL.md, w oryginale · 130 linii, 578 słów
Podgląd SKILL.md
---
name: testing-workflow
description: Read before running tests. Detailed instructions for single tests, full suites, authentication, obtaining the API Token, and a real cross-test pollution pitfall. Use this when asked to run tests, check failures, or debug failing tests.
---

# Testing Workflow

**Crucial:** Tests MUST be run inside the devcontainer to access the correct runtime environment (DB, config, dependencies).

## 0. Pre-requisites: Environment Check

Before running any tests, verify you are inside the development container:

```bash
ls -d /workspaces/NetAlertX
```

If this directory does not exist, you are likely on the host machine — load the `devcontainer-management` skill (or its `.github`/`.gemini` equivalents) to enter the container or run commands inside it.

## 1. Check for Pre-Existing Failures First

Before attributing any failure to your own changes, see what was already broken:

```bash
cd /workspaces/NetAlertX; pytest test/ --tb=no -q 2>&1 | tail -20
```

Do not fix pre-existing failures unless that is the explicit goal.

## 2. Full Test Suite (default)

Unless the user explicitly asks for "fast"/"quick" tests, run the full suite. Don't optimize for time — comprehensive coverage is the priority.

```bash
cd /workspaces/NetAlertX; pytest test/
```

## 3. Fast Unit Tests (only when explicitly requested)

Excludes tests marked `docker` or `feature_complete`:

```bash
cd /workspaces/NetAlertX; pytest test/ -m 'not docker and not feature_complete'
```

## 4. Running Specific Tests

```bash
cd /workspaces/NetAlertX; pytest test/<path_to_test>
# e.g. pytest test/api_endpoints/test_mcp_extended_endpoints.py
# or a single test: pytest test/plugins/test_adguard_export.py::TestManagedNames::test_round_trip
```

## PYTHONPATH

Pre-configured with:
- `/app` — primary location where Python runs in production
- `/app/server`, `/app/server/plugins` — symlinks to `/workspaces/NetAlertX/server[/plugins]`
- `/opt/venv/lib/pythonX.Y/site-packages`, `/usr/lib/pythonX.Y/site-packages`
- `/workspaces/NetAlertX`, `/workspaces/NetAlertX/server`, `/workspaces/NetAlertX/test`

## Authentication & Environment Reset

After making code changes, reset the environment to pick up the new code and get a fresh `API_TOKEN`:

```bash
bash /workspaces/NetAlertX/.devcontainer/scripts/setup.sh
sleep 5   # let nginx/python server/etc. stabilize
python3 -c "from helper import get_setting_value; print(get_setting_value('API_TOKEN'))"
```

Use the retrieved token for any subsequent authenticated API/test calls.

### Troubleshooting 403 Forbidden / empty token

1. Confirm the server is running; re-run `setup.sh` if needed.
2. Verify config loaded: `cat /data/config/app.conf`, or `get_setting_value("API_TOKEN")` returns non-empty.

## Docker Test Image

If the Dockerfile or dependencies changed, rebuild before running tests:

```bash
docker buildx build -t netalertx-test .
```

~30 seconds normally, ~90 seconds if the venv stage changed.

## Pitfall: `sys.modules` Stubbing Leaks Across Test Files

Some plugin tests (e.g. `test/plugins/test_ntfy_custom_headers.py`) stub NetAlertX
modules (`conf`, `helper`, `models.notification_instance`, etc.) via
`sys.modules[name] = fake_module` so the plugin script can be imported standalone,
outside the container. Because `sys.modules` is a single process-wide cache shared
by the whole pytest session, a fake module inserted by one test file silently
shadows the real module for every other test file collected afterwards — pytest
imports all test files during collection, before any test runs, so this can happen
regardless of alphabetical/directory order.

Symptom: `AttributeError: <module 'models.notification_instance'> does not have
the attribute 'get_setting_value'` (or similar) in an unrelated test file, where
the module repr has no `from '<path>'` suffix — a giveaway that a stub, not the
real module, was resolved.

Fix pattern: track which module names your stub actually inserted, and pop them
back out of `sys.modules` immediately after the one-time import that needed them
(the already-imported script keeps its bound names regardless):

```python
_stubbed_module_names = []

def _stub(name, **attrs):
    if name not in sys.modules:
        mod = types.ModuleType(name)
        for k, v in attrs.items():
            setattr(mod, k, v)
        sys.modules[name] = mod
        _stubbed_module_names.append(name)

# ... _stub(...) calls, then the one-time import ...
import ntfy

for _name in _stubbed_module_names:
    sys.modules.pop(_name, None)
```

Reproduce cross-file pollution locally by running the suspect file together with
the affected one in a single pytest invocation (order matters less than you'd
think — collection happens for all files first):

```bash
pytest test/plugins/test_ntfy_custom_headers.py test/backend/test_notification_templates.py -v
```

Wersje

RepozytoriumWynikLicencja
Ta strona · netalertx/NetAlertX100GPL-3.0
gaelic-ghost/socket100Apache-2.0
VilnaCRM-Org/rust-service-template96CC0-1.0

Migawka bazy z 13.11.2026 · wersja paczki 9fa45719c01a (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 85proof
    Działa jako inżynier QA i testów: strategia testów, zestawy E2E, testy API, triage niestabilnych testów i pokrycie.
  • 90proof-api
    Buduje zestawy testów API: testy endpointów, kontraktowe i obciążeniowe dla REST, GraphQL i gRPC.
  • 100api-test-suite-builder
    Generuje testy API, zestawy testów integracyjnych, testy endpointów REST i testy kontraktowe.
  • 95netalertx-testing-workflow
    Uruchamia i debuguje testy w devcontainerze NetAlertX, analizując nieudane przypadki w pytest.
  • 95tarn-api-testing
    Pisze i uruchamia testy API w Tarn, w plikach .tarn.yaml, a także generuje testy z OpenAPI lub poleceń curl.
  • 100run-tests
    Podpowiada, jak lokalnie uruchamiać testy pytest, aby zweryfikować zmiany w kodzie.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.