Agent Skillsnetalertx/NetAlertX › netalertx-testing-workflow

netalertx-testing-workflow

GitHub

指导在NetAlertX开发容器中运行、调试pytest测试及排查失败的工具,涵盖前置检查、执行策略、环境配置及常见陷阱处理。

.github/skills/testing-workflow/SKILL.md netalertx/NetAlertX

Trigger Scenarios

运行测试 检查测试失败 调试失败的测试 执行pytest

Install

npx skills add netalertx/NetAlertX --skill netalertx-testing-workflow -g -y
More Options

Non-standard path

npx skills add https://github.com/netalertx/NetAlertX/tree/main/.github/skills/testing-workflow -g -y

Use without installing

npx skills use netalertx/NetAlertX@netalertx-testing-workflow

指定 Agent (Claude Code)

npx skills add netalertx/NetAlertX --skill netalertx-testing-workflow -a claude-code -g -y

安装 repo 全部 skill

npx skills add netalertx/NetAlertX --all -g -y

预览 repo 内 skill

npx skills add netalertx/NetAlertX --list

SKILL.md

Frontmatter
{
    "name": "netalertx-testing-workflow",
    "description": "Run and debug tests in the NetAlertX devcontainer. Use this when asked to run tests, check test failures, debug failing tests, or execute pytest."
}

Testing Workflow

Pre-Flight Check (MANDATORY)

Before running any tests, always check for existing failures first:

  1. Use the testFailure tool to gather current failure information
  2. Review the failures to understand what's already broken
  3. Only then proceed with test execution

Running Tests

Use VS Code's testing interface or the runTests tool with appropriate parameters:

  • To run all tests: invoke runTests without file filter
  • To run specific test file: invoke runTests with the test file path
  • To run failed tests only: invoke runTests with --lf flag

Test Location

Tests live in test/ directory. App code is under server/.

PYTHONPATH is preconfigured to include the following which should meet all needs:

  • /app # the primary location where python runs in the production system
  • /app/server # symbolic link to /wprkspaces/NetAlertX/server
  • /app/server/plugins # symbolic link to /workspaces/NetAlertX/server/plugins
  • /opt/venv/lib/pythonX.Y/site-packages
  • /workspaces/NetAlertX/test
  • /workspaces/NetAlertX/server
  • /workspaces/NetAlertX
  • /usr/lib/pythonX.Y/site-packages

Authentication in Tests

Retrieve API_TOKEN using Python (not shell):

from helper import get_setting_value
token = get_setting_value("API_TOKEN")

Troubleshooting 403 Forbidden

  1. Ensure backend is running (use devcontainer-services skill)
  2. Verify config loaded: get_setting_value("API_TOKEN") returns non-empty
  3. Re-run startup if needed (use devcontainer-setup skill)

Docker Test Image

If container changes affect tests, rebuild the test image first:

docker buildx build -t netalertx-test .

This takes ~30 seconds unless venv stage changes (~90s).

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):

_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):

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

Version History

  • 716a41a Current 2026-08-27 19:52

    新增关于在独立测试中处理模块存根(stubbing)以避免跨文件污染的指南。

  • 548d698 2026-08-19 22:09

    修正 PYTHONPATH 中插件路径拼写错误(front/plugins 改为 server/plugins);更新文档以匹配网站监控插件引入后的目录结构变更。

  • 8aec57b 2026-07-24 22:14

Same Skill Collection

.gemini/skills/devcontainer-management/SKILL.md
.gemini/skills/logging-standards/SKILL.md
.gemini/skills/mcp-activation/SKILL.md
.gemini/skills/pr-analysis/SKILL.md
.gemini/skills/project-navigation/SKILL.md
.gemini/skills/settings/SKILL.md
.gemini/skills/skills-index/SKILL.md
.gemini/skills/testing-workflow/SKILL.md
.github/skills/api-development/SKILL.md
.github/skills/authentication/SKILL.md
.github/skills/code-standards/SKILL.md
.github/skills/database-patterns/SKILL.md
.github/skills/database-reset/SKILL.md
.github/skills/devcontainer-configs/SKILL.md
.github/skills/devcontainer-services/SKILL.md
.github/skills/devcontainer-setup/SKILL.md
.github/skills/docker-build/SKILL.md
.github/skills/docker-prune/SKILL.md
.github/skills/logging-standards/SKILL.md
.github/skills/mcp-activation/SKILL.md
.github/skills/plugin-run-development/SKILL.md
.github/skills/pr-analysis/SKILL.md
.github/skills/project-navigation/SKILL.md
.github/skills/sample-data/SKILL.md
.github/skills/settings-management/SKILL.md
.github/skills/skills-overview/SKILL.md

Metadata

Files
0
Version
716a41a
Hash
2a3dbd52
Indexed
2026-07-24 22:14

trang chủ - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-01 01:34
浙ICP备14020137号-1 $bản đồ khách truy cập$