errorworks 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. errorworks-0.1.0/.github/workflows/ci.yml +43 -0
  2. errorworks-0.1.0/.github/workflows/release.yaml +34 -0
  3. errorworks-0.1.0/.gitignore +36 -0
  4. errorworks-0.1.0/CHANGELOG.md +51 -0
  5. errorworks-0.1.0/LICENSE +21 -0
  6. errorworks-0.1.0/PKG-INFO +63 -0
  7. errorworks-0.1.0/README.md +3 -0
  8. errorworks-0.1.0/pyproject.toml +172 -0
  9. errorworks-0.1.0/src/errorworks/__init__.py +3 -0
  10. errorworks-0.1.0/src/errorworks/engine/__init__.py +53 -0
  11. errorworks-0.1.0/src/errorworks/engine/admin.py +116 -0
  12. errorworks-0.1.0/src/errorworks/engine/cli.py +37 -0
  13. errorworks-0.1.0/src/errorworks/engine/config_loader.py +153 -0
  14. errorworks-0.1.0/src/errorworks/engine/injection_engine.py +176 -0
  15. errorworks-0.1.0/src/errorworks/engine/latency.py +78 -0
  16. errorworks-0.1.0/src/errorworks/engine/metrics_store.py +614 -0
  17. errorworks-0.1.0/src/errorworks/engine/types.py +270 -0
  18. errorworks-0.1.0/src/errorworks/engine/validators.py +120 -0
  19. errorworks-0.1.0/src/errorworks/engine/vocabulary.py +219 -0
  20. errorworks-0.1.0/src/errorworks/llm/__init__.py +70 -0
  21. errorworks-0.1.0/src/errorworks/llm/cli.py +558 -0
  22. errorworks-0.1.0/src/errorworks/llm/config.py +498 -0
  23. errorworks-0.1.0/src/errorworks/llm/error_injector.py +354 -0
  24. errorworks-0.1.0/src/errorworks/llm/metrics.py +289 -0
  25. errorworks-0.1.0/src/errorworks/llm/presets/chaos.yaml +63 -0
  26. errorworks-0.1.0/src/errorworks/llm/presets/gentle.yaml +61 -0
  27. errorworks-0.1.0/src/errorworks/llm/presets/realistic.yaml +61 -0
  28. errorworks-0.1.0/src/errorworks/llm/presets/silent.yaml +62 -0
  29. errorworks-0.1.0/src/errorworks/llm/presets/stress_aimd.yaml +61 -0
  30. errorworks-0.1.0/src/errorworks/llm/presets/stress_extreme.yaml +63 -0
  31. errorworks-0.1.0/src/errorworks/llm/response_generator.py +460 -0
  32. errorworks-0.1.0/src/errorworks/llm/server.py +811 -0
  33. errorworks-0.1.0/src/errorworks/llm_mcp/__init__.py +26 -0
  34. errorworks-0.1.0/src/errorworks/llm_mcp/server.py +1203 -0
  35. errorworks-0.1.0/src/errorworks/py.typed +0 -0
  36. errorworks-0.1.0/src/errorworks/testing/__init__.py +5 -0
  37. errorworks-0.1.0/src/errorworks/web/__init__.py +65 -0
  38. errorworks-0.1.0/src/errorworks/web/cli.py +363 -0
  39. errorworks-0.1.0/src/errorworks/web/config.py +551 -0
  40. errorworks-0.1.0/src/errorworks/web/content_generator.py +576 -0
  41. errorworks-0.1.0/src/errorworks/web/error_injector.py +436 -0
  42. errorworks-0.1.0/src/errorworks/web/metrics.py +266 -0
  43. errorworks-0.1.0/src/errorworks/web/presets/gentle.yaml +32 -0
  44. errorworks-0.1.0/src/errorworks/web/presets/realistic.yaml +56 -0
  45. errorworks-0.1.0/src/errorworks/web/presets/silent.yaml +25 -0
  46. errorworks-0.1.0/src/errorworks/web/presets/stress_extreme.yaml +69 -0
  47. errorworks-0.1.0/src/errorworks/web/presets/stress_scraping.yaml +57 -0
  48. errorworks-0.1.0/src/errorworks/web/server.py +937 -0
  49. errorworks-0.1.0/tests/__init__.py +0 -0
  50. errorworks-0.1.0/tests/fixtures/__init__.py +0 -0
  51. errorworks-0.1.0/tests/fixtures/chaosllm.py +239 -0
  52. errorworks-0.1.0/tests/fixtures/chaosweb.py +312 -0
  53. errorworks-0.1.0/tests/integration/__init__.py +0 -0
  54. errorworks-0.1.0/tests/integration/conftest.py +13 -0
  55. errorworks-0.1.0/tests/integration/test_llm_pipeline.py +115 -0
  56. errorworks-0.1.0/tests/integration/test_mcp_pipeline.py +157 -0
  57. errorworks-0.1.0/tests/integration/test_web_pipeline.py +147 -0
  58. errorworks-0.1.0/tests/unit/__init__.py +0 -0
  59. errorworks-0.1.0/tests/unit/engine/__init__.py +0 -0
  60. errorworks-0.1.0/tests/unit/engine/test_admin.py +291 -0
  61. errorworks-0.1.0/tests/unit/engine/test_config_loader.py +229 -0
  62. errorworks-0.1.0/tests/unit/engine/test_injection_engine.py +304 -0
  63. errorworks-0.1.0/tests/unit/engine/test_metrics_store.py +708 -0
  64. errorworks-0.1.0/tests/unit/engine/test_types.py +367 -0
  65. errorworks-0.1.0/tests/unit/llm/__init__.py +0 -0
  66. errorworks-0.1.0/tests/unit/llm/conftest.py +3 -0
  67. errorworks-0.1.0/tests/unit/llm/test_cli.py +285 -0
  68. errorworks-0.1.0/tests/unit/llm/test_config.py +412 -0
  69. errorworks-0.1.0/tests/unit/llm/test_error_injector.py +897 -0
  70. errorworks-0.1.0/tests/unit/llm/test_fixture.py +229 -0
  71. errorworks-0.1.0/tests/unit/llm/test_latency_simulator.py +368 -0
  72. errorworks-0.1.0/tests/unit/llm/test_metrics.py +1102 -0
  73. errorworks-0.1.0/tests/unit/llm/test_response_generator.py +938 -0
  74. errorworks-0.1.0/tests/unit/llm/test_server.py +1029 -0
  75. errorworks-0.1.0/tests/unit/llm_mcp/__init__.py +0 -0
  76. errorworks-0.1.0/tests/unit/llm_mcp/test_server.py +929 -0
  77. errorworks-0.1.0/tests/unit/web/__init__.py +0 -0
  78. errorworks-0.1.0/tests/unit/web/conftest.py +3 -0
  79. errorworks-0.1.0/tests/unit/web/test_cli.py +239 -0
  80. errorworks-0.1.0/tests/unit/web/test_config.py +386 -0
  81. errorworks-0.1.0/tests/unit/web/test_content_generator.py +665 -0
  82. errorworks-0.1.0/tests/unit/web/test_error_injector.py +910 -0
  83. errorworks-0.1.0/tests/unit/web/test_fixture.py +186 -0
  84. errorworks-0.1.0/tests/unit/web/test_metrics.py +720 -0
  85. errorworks-0.1.0/tests/unit/web/test_server.py +1051 -0
@@ -0,0 +1,43 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+ workflow_call:
9
+
10
+ concurrency:
11
+ group: ci-${{ github.ref }}
12
+ cancel-in-progress: true
13
+
14
+ jobs:
15
+ lint:
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ - uses: astral-sh/setup-uv@v6
20
+ - run: uv sync --all-extras
21
+ - run: uv run ruff check src tests
22
+ - run: uv run ruff format --check src tests
23
+
24
+ typecheck:
25
+ runs-on: ubuntu-latest
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+ - uses: astral-sh/setup-uv@v6
29
+ - run: uv sync --all-extras
30
+ - run: uv run mypy src
31
+
32
+ test:
33
+ runs-on: ubuntu-latest
34
+ strategy:
35
+ matrix:
36
+ python-version: ["3.12", "3.13"]
37
+ steps:
38
+ - uses: actions/checkout@v4
39
+ - uses: astral-sh/setup-uv@v6
40
+ with:
41
+ python-version: ${{ matrix.python-version }}
42
+ - run: uv sync --all-extras
43
+ - run: uv run pytest --cov --cov-report=term-missing
@@ -0,0 +1,34 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ ci:
9
+ uses: ./.github/workflows/ci.yml
10
+
11
+ build:
12
+ needs: ci
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: astral-sh/setup-uv@v6
17
+ - run: uv build
18
+ - uses: actions/upload-artifact@v4
19
+ with:
20
+ name: dist
21
+ path: dist/
22
+
23
+ publish:
24
+ needs: build
25
+ runs-on: ubuntu-latest
26
+ environment: pypi
27
+ permissions:
28
+ id-token: write
29
+ steps:
30
+ - uses: actions/download-artifact@v4
31
+ with:
32
+ name: dist
33
+ path: dist/
34
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,36 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+
7
+ # Distribution / packaging
8
+ build/
9
+ dist/
10
+ *.egg-info/
11
+ *.egg
12
+
13
+ # Virtual environments
14
+ .venv/
15
+ venv/
16
+
17
+ # IDE
18
+ .idea/
19
+ .vscode/
20
+ *.swp
21
+ *.swo
22
+
23
+ # Testing
24
+ .pytest_cache/
25
+ .coverage
26
+ htmlcov/
27
+ .mypy_cache/
28
+
29
+ # OS
30
+ .DS_Store
31
+ Thumbs.db
32
+
33
+ # Environment
34
+ .env
35
+ .env.*
36
+ .hypothesis/
@@ -0,0 +1,51 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.0] - 2026-03-12
9
+
10
+ Initial release of Errorworks — composable chaos-testing services for various pipelines.
11
+
12
+ ### Added
13
+
14
+ #### Core Engine (`errorworks.engine`)
15
+ - **InjectionEngine**: Burst state machine with priority and weighted error selection modes
16
+ - **MetricsStore**: Thread-safe SQLite metrics storage with schema-driven DDL and time-series bucketing
17
+ - **LatencySimulator**: Configurable artificial latency injection with jitter support
18
+ - **Config loader**: YAML preset system with deep-merge precedence (CLI > file > preset > defaults)
19
+ - Shared vocabulary banks for content generation (English and Lorem Ipsum)
20
+ - Frozen Pydantic models for immutable, validated configuration throughout
21
+
22
+ #### ChaosLLM (`errorworks.llm`)
23
+ - OpenAI-compatible fake LLM server (chat completions API) with Starlette/ASGI
24
+ - Streaming and non-streaming response modes
25
+ - Error injection: rate limiting (429), server errors (500/502/503), connection errors, malformed JSON
26
+ - Burst pattern simulation for provider stress testing
27
+ - Response generation with gibberish, lorem, and template modes
28
+ - SQLite-backed metrics recording per endpoint/deployment/model
29
+ - Six built-in presets: `silent`, `gentle`, `realistic`, `chaos`, `stress_aimd`, `stress_extreme`
30
+ - `chaosllm` CLI with full configuration via flags, YAML files, or presets
31
+
32
+ #### ChaosLLM MCP (`errorworks.llm_mcp`)
33
+ - Model Context Protocol server for ChaosLLM metrics analysis
34
+ - Tools for querying error rates, latency distributions, and time-series trends
35
+ - `chaosllm-mcp` CLI entry point
36
+
37
+ #### ChaosWeb (`errorworks.web`)
38
+ - Fake web server for scraping pipeline resilience testing
39
+ - Error injection: rate limiting (429), forbidden (403), redirects, connection errors, malformed HTML
40
+ - Anti-scraping simulation: SSRF injection, redirect chains, content corruption
41
+ - HTML content generation with configurable structure and link density
42
+ - Five built-in presets: `silent`, `gentle`, `realistic`, `stress_scraping`, `stress_extreme`
43
+ - `chaosweb` CLI with full configuration via flags, YAML files, or presets
44
+
45
+ #### Unified CLI
46
+ - `chaosengine` command that mounts `chaosllm` and `chaosweb` as subcommands
47
+
48
+ #### Testing Support
49
+ - `ChaosLLMFixture`: In-process pytest fixture with marker-based configuration
50
+ - `ChaosWebFixture`: In-process pytest fixture with 23 configurable parameters
51
+ - 583 unit tests with 72% overall code coverage
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Digital Transformation Agency
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,63 @@
1
+ Metadata-Version: 2.4
2
+ Name: errorworks
3
+ Version: 0.1.0
4
+ Summary: Composable chaos-testing services for various pipelines
5
+ Project-URL: Repository, https://github.com/johnm-dta/errorworks
6
+ Author-email: John Morrissey <john.morrissey@dta.gov.au>
7
+ Maintainer: Digital Transformation Agency
8
+ License: MIT License
9
+
10
+ Copyright (c) 2026 Digital Transformation Agency
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+ License-File: LICENSE
30
+ Keywords: chaos,fault-injection,llm,resilience,testing,web
31
+ Classifier: Development Status :: 4 - Beta
32
+ Classifier: Intended Audience :: Developers
33
+ Classifier: License :: OSI Approved :: MIT License
34
+ Classifier: Programming Language :: Python :: 3
35
+ Classifier: Programming Language :: Python :: 3.12
36
+ Classifier: Programming Language :: Python :: 3.13
37
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
38
+ Classifier: Topic :: Software Development :: Testing
39
+ Requires-Python: >=3.12
40
+ Requires-Dist: httpx<1,>=0.27
41
+ Requires-Dist: jinja2<4,>=3.1
42
+ Requires-Dist: mcp<2,>=1.0
43
+ Requires-Dist: pydantic<3,>=2.12
44
+ Requires-Dist: pyyaml<7,>=6.0
45
+ Requires-Dist: starlette<1,>=0.45
46
+ Requires-Dist: structlog<26,>=25.0
47
+ Requires-Dist: typer<1,>=0.21
48
+ Requires-Dist: uvicorn<1,>=0.34
49
+ Provides-Extra: dev
50
+ Requires-Dist: hypothesis<7,>=6.98; extra == 'dev'
51
+ Requires-Dist: mypy<2,>=1.19; extra == 'dev'
52
+ Requires-Dist: pre-commit<5,>=4.0; extra == 'dev'
53
+ Requires-Dist: pytest-asyncio<2,>=1.0; extra == 'dev'
54
+ Requires-Dist: pytest-cov<6,>=4.1; extra == 'dev'
55
+ Requires-Dist: pytest-timeout<3,>=2.3; extra == 'dev'
56
+ Requires-Dist: pytest<10,>=9.0; extra == 'dev'
57
+ Requires-Dist: ruff<1,>=0.15; extra == 'dev'
58
+ Requires-Dist: types-pyyaml<7,>=6.0; extra == 'dev'
59
+ Description-Content-Type: text/markdown
60
+
61
+ # errorworks
62
+
63
+ Composable chaos-testing services for various pipelines.
@@ -0,0 +1,3 @@
1
+ # errorworks
2
+
3
+ Composable chaos-testing services for various pipelines.
@@ -0,0 +1,172 @@
1
+ [project]
2
+ name = "errorworks"
3
+ version = "0.1.0"
4
+ description = "Composable chaos-testing services for various pipelines"
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ license = { file = "LICENSE" }
8
+ authors = [{ name = "John Morrissey", email = "john.morrissey@dta.gov.au" }]
9
+ maintainers = [{ name = "Digital Transformation Agency" }]
10
+ keywords = ["chaos", "testing", "llm", "web", "fault-injection", "resilience"]
11
+ classifiers = [
12
+ "Development Status :: 4 - Beta",
13
+ "Intended Audience :: Developers",
14
+ "License :: OSI Approved :: MIT License",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.12",
17
+ "Programming Language :: Python :: 3.13",
18
+ "Topic :: Software Development :: Testing",
19
+ "Topic :: Software Development :: Libraries :: Python Modules",
20
+ ]
21
+
22
+ dependencies = [
23
+ # Configuration
24
+ "pydantic>=2.12,<3",
25
+ "pyyaml>=6.0,<7",
26
+
27
+ # CLI
28
+ "typer>=0.21,<1",
29
+
30
+ # Templating (response/content generation)
31
+ "jinja2>=3.1,<4",
32
+
33
+ # Logging
34
+ "structlog>=25.0,<26",
35
+
36
+ # HTTP server
37
+ "starlette>=0.45,<1",
38
+ "uvicorn>=0.34,<1",
39
+
40
+ # HTTP client (for test fixtures)
41
+ "httpx>=0.27,<1",
42
+
43
+ # MCP server for ChaosLLM metrics analysis
44
+ "mcp>=1.0,<2",
45
+ ]
46
+
47
+ [project.optional-dependencies]
48
+ dev = [
49
+ "pytest>=9.0,<10",
50
+ "pytest-cov>=4.1,<6",
51
+ "pytest-asyncio>=1.0,<2",
52
+ "pytest-timeout>=2.3,<3",
53
+ "hypothesis>=6.98,<7",
54
+ "mypy>=1.19,<2",
55
+ "ruff>=0.15,<1",
56
+ "pre-commit>=4.0,<5",
57
+ "types-PyYAML>=6.0,<7",
58
+ ]
59
+
60
+ [project.scripts]
61
+ chaosengine = "errorworks.engine.cli:main"
62
+ chaosllm = "errorworks.llm.cli:main"
63
+ chaosllm-mcp = "errorworks.llm.cli:mcp_main_entry"
64
+ chaosweb = "errorworks.web.cli:main"
65
+
66
+ [project.urls]
67
+ Repository = "https://github.com/johnm-dta/errorworks"
68
+
69
+ [build-system]
70
+ requires = ["hatchling"]
71
+ build-backend = "hatchling.build"
72
+
73
+ [tool.hatch.build.targets.wheel]
74
+ packages = ["src/errorworks"]
75
+
76
+ [tool.hatch.build.targets.sdist]
77
+ exclude = [
78
+ ".claude/",
79
+ "CLAUDE.md",
80
+ "docs/plans/",
81
+ "docs/arch-analysis-*",
82
+ "uv.lock",
83
+ ]
84
+
85
+ # === Ruff Configuration ===
86
+ [tool.ruff]
87
+ target-version = "py312"
88
+ line-length = 140
89
+ src = ["src", "tests"]
90
+
91
+ [tool.ruff.lint]
92
+ select = [
93
+ "E", # pycodestyle errors
94
+ "F", # pyflakes
95
+ "W", # pycodestyle warnings
96
+ "I", # isort
97
+ "UP", # pyupgrade
98
+ "B", # flake8-bugbear
99
+ "SIM", # flake8-simplify
100
+ "C4", # flake8-comprehensions
101
+ "DTZ", # flake8-datetimez
102
+ "T20", # flake8-print
103
+ "RUF", # Ruff-specific rules
104
+ ]
105
+ ignore = [
106
+ "E501", # line too long (handled by formatter)
107
+ "SIM108", # ternary operator - prefer explicit if/else
108
+ ]
109
+
110
+ [tool.ruff.lint.isort]
111
+ known-first-party = ["errorworks"]
112
+
113
+ [tool.ruff.lint.flake8-bugbear]
114
+ extend-immutable-calls = ["typer.Option", "typer.Argument"]
115
+
116
+ [tool.ruff.lint.per-file-ignores]
117
+ "tests/**/*.py" = ["T20"]
118
+
119
+ # === Mypy Configuration ===
120
+ [tool.mypy]
121
+ python_version = "3.12"
122
+ strict = true
123
+ warn_return_any = true
124
+ warn_unused_configs = true
125
+ warn_unreachable = true
126
+ show_error_codes = true
127
+ plugins = ["pydantic.mypy"]
128
+ warn_unused_ignores = true
129
+
130
+ [[tool.mypy.overrides]]
131
+ module = [
132
+ "mcp.*",
133
+ "hypothesis.*",
134
+ ]
135
+ ignore_missing_imports = true
136
+
137
+ [[tool.mypy.overrides]]
138
+ module = "tests.*"
139
+ disallow_untyped_decorators = false
140
+ disallow_untyped_defs = false
141
+ disallow_incomplete_defs = false
142
+ check_untyped_defs = false
143
+
144
+ # === Pytest Configuration ===
145
+ [tool.pytest.ini_options]
146
+ testpaths = ["tests"]
147
+ pythonpath = ["src"]
148
+ addopts = [
149
+ "-ra",
150
+ "--strict-markers",
151
+ "--strict-config",
152
+ ]
153
+ markers = [
154
+ "slow: marks tests as slow",
155
+ "stress: marks tests as stress tests",
156
+ "chaosllm: Configure ChaosLLM server for the test",
157
+ "chaosweb: Configure ChaosWeb server for the test",
158
+ "integration: marks tests as integration tests",
159
+ ]
160
+
161
+ # === Coverage Configuration ===
162
+ [tool.coverage.run]
163
+ source = ["src/errorworks"]
164
+ branch = true
165
+
166
+ [tool.coverage.report]
167
+ exclude_lines = [
168
+ "pragma: no cover",
169
+ "if TYPE_CHECKING:",
170
+ "raise NotImplementedError",
171
+ "@abstractmethod",
172
+ ]
@@ -0,0 +1,3 @@
1
+ """Composable chaos-testing servers for LLM and web scraping pipelines."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,53 @@
1
+ """ChaosEngine: Shared utilities for chaos testing servers.
2
+
3
+ Provides composition-based building blocks used by ChaosLLM, ChaosWeb, and
4
+ future chaos plugins (ChaosFile, ChaosSQL, etc.):
5
+
6
+ - InjectionEngine: Burst state machine + priority/weighted error selection
7
+ - MetricsStore: Thread-safe SQLite with schema-driven DDL
8
+ - LatencySimulator: Configurable artificial latency
9
+ - Config loading: deep_merge, preset loading, YAML precedence
10
+
11
+ Each chaos plugin *composes* these utilities rather than inheriting from
12
+ base classes, avoiding covariant return type friction and HTTP-leakage
13
+ into non-HTTP domains.
14
+ """
15
+
16
+ from errorworks.engine.config_loader import (
17
+ deep_merge,
18
+ list_presets,
19
+ load_preset,
20
+ )
21
+ from errorworks.engine.injection_engine import InjectionEngine
22
+ from errorworks.engine.latency import LatencySimulator
23
+ from errorworks.engine.metrics_store import MetricsStore
24
+ from errorworks.engine.types import (
25
+ DANGEROUS_BIND_HOSTS,
26
+ BurstConfig,
27
+ ErrorSpec,
28
+ LatencyConfig,
29
+ MetricsConfig,
30
+ MetricsSchema,
31
+ SelectionMode,
32
+ ServerConfig,
33
+ )
34
+ from errorworks.engine.vocabulary import ENGLISH_VOCABULARY, LOREM_VOCABULARY
35
+
36
+ __all__ = [
37
+ "DANGEROUS_BIND_HOSTS",
38
+ "ENGLISH_VOCABULARY",
39
+ "LOREM_VOCABULARY",
40
+ "BurstConfig",
41
+ "ErrorSpec",
42
+ "InjectionEngine",
43
+ "LatencyConfig",
44
+ "LatencySimulator",
45
+ "MetricsConfig",
46
+ "MetricsSchema",
47
+ "MetricsStore",
48
+ "SelectionMode",
49
+ "ServerConfig",
50
+ "deep_merge",
51
+ "list_presets",
52
+ "load_preset",
53
+ ]
@@ -0,0 +1,116 @@
1
+ """Shared admin endpoint logic for chaos servers.
2
+
3
+ Provides free functions for admin authentication and endpoint handling,
4
+ composed by both ChaosLLM and ChaosWeb servers via the ChaosServer protocol.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import hmac
10
+ import json
11
+ import sqlite3
12
+ from typing import Any, Protocol, runtime_checkable
13
+
14
+ import pydantic
15
+ import structlog
16
+ from starlette.requests import Request
17
+ from starlette.responses import JSONResponse
18
+
19
+ logger = structlog.get_logger(__name__)
20
+
21
+
22
+ @runtime_checkable
23
+ class ChaosServer(Protocol):
24
+ """Minimal interface for admin endpoint handlers.
25
+
26
+ Both ChaosLLMServer and ChaosWebServer satisfy this protocol.
27
+ """
28
+
29
+ def get_admin_token(self) -> str: ...
30
+ def get_current_config(self) -> dict[str, Any]: ...
31
+ def update_config(self, updates: dict[str, Any]) -> None: ...
32
+ def reset(self) -> str: ...
33
+ def export_metrics(self) -> dict[str, Any]: ...
34
+ def get_stats(self) -> dict[str, Any]: ...
35
+
36
+
37
+ def check_admin_auth(request: Request, token: str) -> JSONResponse | None:
38
+ """Check admin authentication.
39
+
40
+ Returns None if auth passes, or a 401/403 JSONResponse if it fails.
41
+ """
42
+ auth_header = request.headers.get("Authorization", "")
43
+ if not auth_header.startswith("Bearer "):
44
+ return JSONResponse(
45
+ {"error": {"type": "authentication_error", "message": "Missing Authorization: Bearer <token> header"}},
46
+ status_code=401,
47
+ )
48
+ if not hmac.compare_digest(auth_header[7:], token):
49
+ return JSONResponse(
50
+ {"error": {"type": "authorization_error", "message": "Invalid admin token"}},
51
+ status_code=403,
52
+ )
53
+ return None
54
+
55
+
56
+ async def handle_admin_config(request: Request, server: ChaosServer) -> JSONResponse:
57
+ """Handle GET/POST /admin/config."""
58
+ if (denied := check_admin_auth(request, server.get_admin_token())) is not None:
59
+ return denied
60
+ if request.method == "GET":
61
+ return JSONResponse(server.get_current_config())
62
+ try:
63
+ body = await request.json()
64
+ except (json.JSONDecodeError, ValueError, UnicodeDecodeError):
65
+ return JSONResponse(
66
+ {"error": {"type": "invalid_request_error", "message": "Request body must be valid JSON"}},
67
+ status_code=400,
68
+ )
69
+ try:
70
+ server.update_config(body)
71
+ except (ValueError, TypeError, pydantic.ValidationError) as e:
72
+ return JSONResponse(
73
+ {"error": {"type": "validation_error", "message": str(e)}},
74
+ status_code=422,
75
+ )
76
+ return JSONResponse({"status": "updated", "config": server.get_current_config()})
77
+
78
+
79
+ async def handle_admin_stats(request: Request, server: ChaosServer) -> JSONResponse:
80
+ """Handle GET /admin/stats."""
81
+ if (denied := check_admin_auth(request, server.get_admin_token())) is not None:
82
+ return denied
83
+ try:
84
+ return JSONResponse(server.get_stats())
85
+ except sqlite3.Error as e:
86
+ return JSONResponse(
87
+ {"error": {"type": "database_error", "message": f"Failed to retrieve stats: {e}"}},
88
+ status_code=503,
89
+ )
90
+
91
+
92
+ async def handle_admin_reset(request: Request, server: ChaosServer) -> JSONResponse:
93
+ """Handle POST /admin/reset."""
94
+ if (denied := check_admin_auth(request, server.get_admin_token())) is not None:
95
+ return denied
96
+ try:
97
+ new_run_id = server.reset()
98
+ except sqlite3.Error as e:
99
+ return JSONResponse(
100
+ {"error": {"type": "database_error", "message": f"Failed to reset metrics: {e}"}},
101
+ status_code=503,
102
+ )
103
+ return JSONResponse({"status": "reset", "new_run_id": new_run_id})
104
+
105
+
106
+ async def handle_admin_export(request: Request, server: ChaosServer) -> JSONResponse:
107
+ """Handle GET /admin/export."""
108
+ if (denied := check_admin_auth(request, server.get_admin_token())) is not None:
109
+ return denied
110
+ try:
111
+ return JSONResponse(server.export_metrics())
112
+ except sqlite3.Error as e:
113
+ return JSONResponse(
114
+ {"error": {"type": "database_error", "message": f"Failed to export metrics: {e}"}},
115
+ status_code=503,
116
+ )
@@ -0,0 +1,37 @@
1
+ """Unified CLI for ChaosEngine testing servers.
2
+
3
+ Aggregates ChaosLLM and ChaosWeb under a single ``chaosengine`` command:
4
+
5
+ chaosengine llm serve --preset=gentle
6
+ chaosengine llm presets
7
+ chaosengine web serve --preset=stress_scraping
8
+ chaosengine web presets
9
+
10
+ Standalone entry points (``chaosllm``, ``chaosweb``) continue to work
11
+ unchanged — this CLI simply mounts the same Typer apps as sub-commands.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import typer
17
+
18
+ from errorworks.llm.cli import app as llm_app
19
+ from errorworks.web.cli import app as web_app
20
+
21
+ app = typer.Typer(
22
+ name="chaosengine",
23
+ help="ChaosEngine: Unified chaos testing server management.",
24
+ no_args_is_help=True,
25
+ )
26
+
27
+ app.add_typer(llm_app, name="llm", help="ChaosLLM: Fake LLM server for load testing and fault injection.")
28
+ app.add_typer(web_app, name="web", help="ChaosWeb: Fake web server for scraping pipeline resilience testing.")
29
+
30
+
31
+ def main() -> None:
32
+ """Entry point for chaosengine CLI."""
33
+ app()
34
+
35
+
36
+ if __name__ == "__main__":
37
+ main()