Skip to content

Commit 5989708

Browse files
committed
Audit remediation: remove artifacts, add CI/CD, tests, and tooling
- Remove committed artifacts from version control - quantcli.log, article_processor.log, articles.json, output.html - Enhance .gitignore with comprehensive patterns - Secrets, coverage, type checking, IDE files - Add GitHub Actions CI workflow (.github/workflows/ci.yml) - Lint with black and ruff - Type check with mypy - Test on Python 3.10, 3.11, 3.12 - Security scan with pip-audit - Secret scanning with TruffleHog - Add test suite foundation (tests/) - Pytest fixtures for mocking OpenAI client and config - Unit tests for processor classes (TextPreprocessor, CodeValidator, etc.) - Unit tests for LLMHandler - Enhance pyproject.toml with additional tooling - Add pytest-cov, pytest-mock, pre-commit, pip-audit to dev deps - Configure ruff lint rules including security checks - Configure mypy with ignore patterns for third-party libs - Add pytest and coverage configuration
1 parent bf29f37 commit 5989708

File tree

11 files changed

+515
-205
lines changed

11 files changed

+515
-205
lines changed

.github/workflows/ci.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, master, develop, gamma, beta, "feature/*", "claude/*"]
6+
pull_request:
7+
branches: [main, master, develop, gamma, beta]
8+
9+
jobs:
10+
lint:
11+
name: Lint & Format
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.11"
20+
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install ruff black
25+
26+
- name: Check formatting with Black
27+
run: black --check --diff .
28+
29+
- name: Lint with Ruff
30+
run: ruff check .
31+
32+
type-check:
33+
name: Type Check
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v4
37+
38+
- name: Set up Python
39+
uses: actions/setup-python@v5
40+
with:
41+
python-version: "3.11"
42+
43+
- name: Install dependencies
44+
run: |
45+
python -m pip install --upgrade pip
46+
pip install -e ".[dev]"
47+
48+
- name: Run mypy
49+
run: mypy quantcoder --ignore-missing-imports
50+
51+
test:
52+
name: Test (Python ${{ matrix.python-version }})
53+
runs-on: ubuntu-latest
54+
strategy:
55+
fail-fast: false
56+
matrix:
57+
python-version: ["3.10", "3.11", "3.12"]
58+
59+
steps:
60+
- uses: actions/checkout@v4
61+
62+
- name: Set up Python ${{ matrix.python-version }}
63+
uses: actions/setup-python@v5
64+
with:
65+
python-version: ${{ matrix.python-version }}
66+
67+
- name: Install dependencies
68+
run: |
69+
python -m pip install --upgrade pip
70+
pip install -e ".[dev]"
71+
pip install pytest-cov pytest-mock
72+
python -m spacy download en_core_web_sm
73+
74+
- name: Run tests
75+
run: pytest tests/ -v --cov=quantcoder --cov-report=xml
76+
77+
- name: Upload coverage
78+
uses: codecov/codecov-action@v3
79+
if: matrix.python-version == '3.11'
80+
with:
81+
files: ./coverage.xml
82+
fail_ci_if_error: false
83+
84+
security:
85+
name: Security Scan
86+
runs-on: ubuntu-latest
87+
steps:
88+
- uses: actions/checkout@v4
89+
90+
- name: Set up Python
91+
uses: actions/setup-python@v5
92+
with:
93+
python-version: "3.11"
94+
95+
- name: Install dependencies
96+
run: |
97+
python -m pip install --upgrade pip
98+
pip install pip-audit
99+
100+
- name: Run pip-audit
101+
run: pip-audit --require-hashes=false || true
102+
103+
secret-scan:
104+
name: Secret Scanning
105+
runs-on: ubuntu-latest
106+
steps:
107+
- uses: actions/checkout@v4
108+
with:
109+
fetch-depth: 0
110+
111+
- name: TruffleHog Secret Scan
112+
uses: trufflesecurity/trufflehog@main
113+
with:
114+
extra_args: --only-verified

.gitignore

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
# Python
1+
# Python bytecode and cache
22
__pycache__/
33
*.py[cod]
44
*$py.class
55
*.so
66
.Python
7+
8+
# Distribution / packaging
79
build/
810
develop-eggs/
911
dist/
@@ -20,47 +22,74 @@ wheels/
2022
.installed.cfg
2123
*.egg
2224
MANIFEST
25+
*.whl
2326

2427
# Virtual Environment
2528
.venv/
2629
.venv-legacy/
2730
venv/
2831
ENV/
2932
env/
33+
.env/
3034

31-
# IDE
35+
# IDE and editors
3236
.vscode/
3337
.idea/
3438
*.swp
3539
*.swo
3640
*~
41+
.project
42+
.pydevproject
43+
.settings/
3744

38-
# Logs
45+
# Logs and output artifacts
3946
*.log
47+
logs/
4048
quantcli.log
4149
article_processor.log
4250

43-
# QuantCoder specific
51+
# QuantCoder specific - user data
4452
downloads/
4553
generated_code/
4654
articles.json
4755
output.html
56+
output.*
4857

49-
# Configuration (contains API keys)
58+
# Configuration and secrets (API keys)
5059
.env
60+
.env.*
61+
*.env
62+
.envrc
5163
.quantcoder/
64+
secrets.json
65+
credentials.json
5266

53-
# OS
67+
# OS specific
5468
.DS_Store
5569
Thumbs.db
5670

57-
# SpaCy models
71+
# SpaCy models (large binary files)
5872
*.bin
5973

60-
# Testing
74+
# Testing and coverage
6175
.pytest_cache/
6276
.coverage
77+
.coverage.*
6378
htmlcov/
79+
coverage.xml
80+
*.cover
81+
.hypothesis/
82+
.tox/
83+
.nox/
6484

65-
# Distribution
66-
*.whl
85+
# Type checking
86+
.mypy_cache/
87+
.dmypy.json
88+
dmypy.json
89+
.pytype/
90+
91+
# Jupyter
92+
.ipynb_checkpoints/
93+
94+
# Local development
95+
*.local

article_processor.log

Lines changed: 0 additions & 1 deletion
This file was deleted.

articles.json

Lines changed: 0 additions & 47 deletions
This file was deleted.

output.html

Lines changed: 0 additions & 53 deletions
This file was deleted.

pyproject.toml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@ dependencies = [
4242
[project.optional-dependencies]
4343
dev = [
4444
"pytest>=7.4.0",
45+
"pytest-cov>=4.0",
46+
"pytest-mock>=3.10",
4547
"black>=23.0.0",
4648
"ruff>=0.1.0",
4749
"mypy>=1.7.0",
50+
"pre-commit>=3.0",
51+
"pip-audit>=2.6",
4852
]
4953

5054
[project.scripts]
@@ -69,7 +73,63 @@ target-version = ['py310']
6973
line-length = 100
7074
target-version = "py310"
7175

76+
[tool.ruff.lint]
77+
select = [
78+
"E", # pycodestyle errors
79+
"W", # pycodestyle warnings
80+
"F", # pyflakes
81+
"I", # isort
82+
"B", # flake8-bugbear
83+
"C4", # flake8-comprehensions
84+
"UP", # pyupgrade
85+
"S", # flake8-bandit (security)
86+
]
87+
ignore = [
88+
"E501", # line too long (handled by black)
89+
"S101", # use of assert (ok in tests)
90+
]
91+
92+
[tool.ruff.lint.per-file-ignores]
93+
"tests/*" = ["S101"]
94+
7295
[tool.mypy]
7396
python_version = "3.10"
7497
warn_return_any = true
7598
warn_unused_configs = true
99+
ignore_missing_imports = true
100+
show_error_codes = true
101+
102+
[[tool.mypy.overrides]]
103+
module = [
104+
"pdfplumber.*",
105+
"spacy.*",
106+
"pygments.*",
107+
"InquirerPy.*",
108+
"rich.*",
109+
"toml.*",
110+
]
111+
ignore_missing_imports = true
112+
113+
[tool.pytest.ini_options]
114+
testpaths = ["tests"]
115+
python_files = ["test_*.py"]
116+
python_functions = ["test_*"]
117+
addopts = ["-v", "--tb=short"]
118+
markers = [
119+
"slow: marks tests as slow",
120+
"integration: marks tests as integration tests",
121+
]
122+
123+
[tool.coverage.run]
124+
source = ["quantcoder"]
125+
branch = true
126+
omit = ["*/tests/*"]
127+
128+
[tool.coverage.report]
129+
exclude_lines = [
130+
"pragma: no cover",
131+
"def __repr__",
132+
"raise AssertionError",
133+
"raise NotImplementedError",
134+
"if __name__ == .__main__.:",
135+
]

0 commit comments

Comments
 (0)