|
| 1 | +# LoadDensity |
| 2 | + |
| 3 | +Load & Stress Automation Framework built on top of Locust. |
| 4 | + |
| 5 | +## Tech Stack |
| 6 | + |
| 7 | +- Python 3.10+ |
| 8 | +- Locust (load testing engine) |
| 9 | +- PySide6 + qt-material (optional GUI) |
| 10 | +- setuptools (build system) |
| 11 | + |
| 12 | +## Project Structure |
| 13 | + |
| 14 | +- `je_load_density/` - main package |
| 15 | + - `gui/` - PySide6 GUI with multi-language support |
| 16 | + - `utils/` - utilities (executor, file I/O, reports, logging, JSON/XML, socket server, test records) |
| 17 | + - `wrapper/` - Locust wrappers (env creation, event hooks, proxy users, start/stop) |
| 18 | +- `load_density_driver/` - driver generation |
| 19 | +- `test/` - pytest test suite |
| 20 | +- `docs/` - Sphinx documentation |
| 21 | + |
| 22 | +## Development Commands |
| 23 | + |
| 24 | +```bash |
| 25 | +# Install |
| 26 | +pip install -e . |
| 27 | +pip install -e ".[gui]" |
| 28 | + |
| 29 | +# Test |
| 30 | +pytest test/ |
| 31 | + |
| 32 | +# Build |
| 33 | +python -m build |
| 34 | +``` |
| 35 | + |
| 36 | +## Coding Standards |
| 37 | + |
| 38 | +### Design Patterns & Software Engineering |
| 39 | + |
| 40 | +- Apply appropriate design patterns (Strategy, Factory, Observer, etc.) where they reduce complexity |
| 41 | +- Follow SOLID principles: single responsibility, open-closed, Liskov substitution, interface segregation, dependency inversion |
| 42 | +- Prefer composition over inheritance |
| 43 | +- Keep functions small and focused on a single task |
| 44 | +- Use meaningful, descriptive names for variables, functions, classes, and modules |
| 45 | + |
| 46 | +### Performance |
| 47 | + |
| 48 | +- Avoid unnecessary object creation in hot paths |
| 49 | +- Prefer generators over lists for large data iteration |
| 50 | +- Use appropriate data structures (set for membership checks, dict for lookups) |
| 51 | +- Minimize I/O operations; batch when possible |
| 52 | +- Profile before optimizing - measure, don't guess |
| 53 | + |
| 54 | +### Code Hygiene |
| 55 | + |
| 56 | +- Remove all unused imports, variables, functions, classes, and dead code blocks |
| 57 | +- No commented-out code in commits |
| 58 | +- No placeholder or stub code left behind |
| 59 | +- Every import must be used; every function must be called or exported |
| 60 | + |
| 61 | +### Security |
| 62 | + |
| 63 | +- Never hardcode secrets, tokens, passwords, or API keys |
| 64 | +- Validate and sanitize all external input (user input, file content, network data) |
| 65 | +- Use parameterized queries for any database operations |
| 66 | +- Avoid `eval()`, `exec()`, and `__import__()` with untrusted input |
| 67 | +- Use `subprocess` with argument lists, never shell=True with user input |
| 68 | +- Set restrictive file permissions on sensitive files |
| 69 | +- Escape output to prevent injection (HTML, XML, JSON) |
| 70 | +- Pin dependency versions to avoid supply chain attacks |
| 71 | + |
| 72 | +### Linter Compliance (SonarQube / Codacy / Pylint / Flake8) |
| 73 | + |
| 74 | +Code must pass static analysis with no new issues introduced. Follow these rules proactively so SonarQube, Codacy, Pylint, Flake8, Bandit, and Radon do not flag regressions. |
| 75 | + |
| 76 | +#### Complexity & Structure |
| 77 | + |
| 78 | +- Cognitive complexity per function: ≤ 15 (SonarQube rule `python:S3776`) |
| 79 | +- Cyclomatic complexity per function: ≤ 10 (Radon grade A–B) |
| 80 | +- Function length: ≤ 80 lines; file length: ≤ 1000 lines |
| 81 | +- Max parameters per function: ≤ 7 (SonarQube `python:S107`) |
| 82 | +- Max nesting depth: ≤ 4 levels (SonarQube `python:S134`) |
| 83 | +- Avoid deeply nested `if/for/try` — extract helpers or use early returns |
| 84 | +- No duplicated code blocks ≥ 10 lines (SonarQube `common-py:DuplicatedBlocks`) |
| 85 | +- Keep boolean expressions simple: ≤ 3 operators (SonarQube `python:S1067`) |
| 86 | + |
| 87 | +#### Naming & Style (PEP 8 + Pylint) |
| 88 | + |
| 89 | +- `snake_case` for functions, methods, variables, modules |
| 90 | +- `PascalCase` for classes; `UPPER_SNAKE_CASE` for module-level constants |
| 91 | +- Private members prefixed with single underscore `_name` |
| 92 | +- Line length: ≤ 120 characters (soft limit), hard max 160 |
| 93 | +- No single-letter names except loop counters (`i`, `j`, `k`) and comprehensions |
| 94 | +- Avoid shadowing built-ins (`id`, `list`, `type`, `dict`, `file`, etc.) |
| 95 | +- No unused function/method parameters — prefix with `_` if required by signature |
| 96 | + |
| 97 | +#### Bug-Prone Patterns |
| 98 | + |
| 99 | +- Never use mutable default arguments (`def f(x=[])`) — use `None` sentinel (SonarQube `python:S5644`) |
| 100 | +- Do not compare with `==` / `!=` to `None`, `True`, `False` — use `is` / `is not` |
| 101 | +- Do not catch bare `except:` — catch specific exceptions; never swallow silently |
| 102 | +- Always re-raise with `raise` or `raise X from e`, preserving context |
| 103 | +- Close resources with `with` context managers (files, sockets, locks) |
| 104 | +- Do not modify a collection while iterating over it |
| 105 | +- Avoid `assert` for runtime validation (stripped by `python -O`); raise explicit exceptions |
| 106 | +- No `TODO` / `FIXME` / `XXX` comments without a tracked issue reference |
| 107 | +- Remove unreachable code after `return`, `raise`, `break`, `continue` |
| 108 | + |
| 109 | +#### Type Safety & API Design |
| 110 | + |
| 111 | +- Public functions and methods should have type hints (parameters + return) |
| 112 | +- Avoid `Any` unless truly dynamic; prefer `Optional[T]`, `Union[...]`, protocols |
| 113 | +- Do not return inconsistent types from one function (e.g. `str` or `None` or `int`) |
| 114 | +- Prefer `@dataclass` or `TypedDict` over ad-hoc dict payloads |
| 115 | +- Use `enum.Enum` instead of string/int constants for closed sets |
| 116 | + |
| 117 | +#### Security (Bandit + SonarQube Security Hotspots) |
| 118 | + |
| 119 | +- No `eval`, `exec`, `pickle.loads`, `yaml.load` (use `yaml.safe_load`) on untrusted input |
| 120 | +- No `hashlib.md5` / `sha1` for security purposes — use `sha256` or `blake2b` |
| 121 | +- No `random` module for tokens/secrets — use `secrets` module |
| 122 | +- No `tempfile.mktemp` — use `mkstemp` / `NamedTemporaryFile` |
| 123 | +- Never log secrets, tokens, or raw request bodies containing credentials |
| 124 | +- Validate file paths against traversal (`..`, absolute paths, symlinks) |
| 125 | +- Set explicit timeouts on `requests.*` and socket operations |
| 126 | + |
| 127 | +#### Testing Hygiene |
| 128 | + |
| 129 | +- Tests must be deterministic — no reliance on wall-clock, network, or ordering |
| 130 | +- Each test asserts something; no test without an `assert` |
| 131 | +- Mock external side effects (filesystem writes, HTTP, subprocess) |
| 132 | +- Test names describe behavior: `test_<unit>_<condition>_<expected>` |
| 133 | + |
| 134 | +### Git Commit Rules |
| 135 | + |
| 136 | +- Commit messages must NOT reference any AI tool, assistant, or model name |
| 137 | +- No `Co-Authored-By` lines referencing AI |
| 138 | +- Write commit messages as if authored solely by the developer |
| 139 | +- Use conventional commit style: `feat:`, `fix:`, `refactor:`, `test:`, `docs:`, `chore:` |
| 140 | +- Keep subject line under 72 characters |
| 141 | +- Use imperative mood ("add feature" not "added feature") |
0 commit comments