Skip to content

Commit 4faab9f

Browse files
VirtualAgenticsAlmostBald-TRADINGcoderabbitai[bot]
authored
fix: resolve CodeQL syntax errors, type checking issues, and update dependency version bounds (#45)
* fix: resolve CodeQL syntax errors in JavaScript/TypeScript and Python files - Fix TypeScript syntax errors in contextforgeClient.ts: - Fix missing JSDoc comment opening - Fix method call parameter mismatch in shouldRetry - Implement complete v1Checkpoint method - Remove orphaned code blocks - Fix Python syntax errors in test_vulnerability_scripts.py: - Remove duplicate @patch decorators - Remove invalid @@ syntax characters - Fix malformed test structure - Remove empty test_optional_properties.ts file - Add test_syntax.py for syntax validation Resolves CodeQL parse errors for both JavaScript/TypeScript and Python languages * docs: update cursor rules to prohibit --no-verify usage - Add strict guidelines against using --no-verify flag - Emphasize fixing all errors before pushing - Add detailed explanations of why --no-verify is dangerous - Provide specific solutions for common pre-commit failures - Update Python, testing, and general rules with quality gates - Ensure CI/CD alignment by preventing bypassed checks This prevents CI failures and maintains code quality standards. * fix: resolve all type checking issues - Add type: ignore comments to tiktoken import in openai.py - Add type: ignore comments to handler imports in test files - Fix import resolution errors for dynamic path manipulation - All type checking now passes with 0 errors, 0 warnings Resolves pyright type checking issues: - tiktoken import error in src/contextforge_memory/summarize/openai.py - handlers.json_handler import error in tests/test_json_handler.py - handlers.toml_handler import error in tests/test_toml_handler.py * Update clients/typescript/contextforgeClient.ts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * feat: add metadata validation to v1Checkpoint method - Add validation guard for metadata parameter in v1Checkpoint method - Validate that metadata is a non-null object when provided - Reject arrays and null values to match validateMemoryItem behavior - Throw descriptive error message for invalid metadata types - Ensures type safety and consistency across the TypeScript client * chore: update dependencies - Update click from 8.1.8 to 8.3.0 - Update rich from 13.5.3 to 14.2.0 - Update tomli from 2.0.2 to 2.3.0 - Addresses potential CI dependency issues * fix: add mypy dependency and resolve type checking issues - Add mypy>=1.0.0 to requirements-dev.in - Regenerate requirements-dev.txt with mypy==1.18.2 - Remove unused type: ignore comments in openai.py - Fixes CI failure: 'mypy: command not found' - Resolves mypy strict mode type checking errors The CI was failing because mypy was not installed in the environment. This commit adds mypy as a development dependency and removes unnecessary type suppressions that were causing mypy errors. * security: add SHA256 integrity hashes to requirements.txt - Regenerate requirements.txt with pip-compile --generate-hashes - All 20 dependencies now have corresponding --hash=sha256:... lines - Ensures package integrity and prevents supply chain attacks - Meets security requirements for dependency verification Dependencies updated with hashes: - click==8.3.0, rich==14.2.0, tomli==2.3.0 (previously missing hashes) - All other dependencies also regenerated with current hashes - Maintains exact same versions while adding security verification * feat: update OpenAI and tiktoken version bounds - Update openai constraint from <2.0.0 to <3.0.0 to allow 2.x versions - Update tiktoken constraint from <1.0.0 to <1.0.0 (corrected from <2.0.0) - Allows OpenAI 2.x versions for latest features and security patches - Maintains tiktoken 0.x compatibility while preventing breaking 1.x changes - All functionality tested and verified working - Code formatting applied to maintain consistency Resolves version constraint issues and future-proofs dependencies. * fix: resolve CI hash mismatch by adding setuptools to requirements - Add setuptools>=65.5.1 to requirements.in to resolve hash mismatch - Regenerate requirements.txt with proper setuptools hashes - Fixes CI failure: 'setuptools>=65.5.1' missing from requirements.txt - Maintains version bounds for openai and tiktoken * fix: include setuptools in requirements.txt to resolve CI hash mismatch - Use --allow-unsafe flag with pip-compile to include setuptools - Add setuptools==80.9.0 with proper hashes to requirements.txt - Fixes CI failure: 'setuptools>=65.5.1' missing from requirements.txt - Maintains version bounds for openai and tiktoken --------- Co-authored-by: Ben De Cock <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 0c9e2db commit 4faab9f

File tree

15 files changed

+2072
-61
lines changed

15 files changed

+2072
-61
lines changed

.cursor/rules/general.mdc

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,66 @@ globs: **/*
7676
5. Run linting ONLY in venv: `source .venv/bin/activate && make lint`
7777
6. Run type checking ONLY in venv: `source .venv/bin/activate && make type-check`
7878
7. Format code ONLY in venv: `source .venv/bin/activate && make format`
79-
8. Update documentation if needed
80-
9. Create pull request
79+
8. **CRITICAL**: Fix ALL errors before committing - never use `--no-verify`
80+
9. Update documentation if needed
81+
10. Create pull request
8182

8283
**REMINDER**: All Python commands must be run within the activated virtual environment
8384

85+
## Pre-commit and Push Rules
86+
87+
🚨 **CRITICAL**: Never use `--no-verify` flag when pushing commits
88+
89+
- **ALWAYS** fix all pre-commit hook errors before pushing
90+
- **ALWAYS** fix all linting errors before pushing
91+
- **ALWAYS** fix all type checking errors before pushing
92+
- **ALWAYS** fix all test failures before pushing
93+
- **ALWAYS** ensure all security scans pass before pushing
94+
95+
### Why Never Use --no-verify
96+
97+
- **CI/CD will fail**: GitHub Actions will catch the same errors and fail the build
98+
- **Security risks**: Bypassing security scans defeats the purpose of automated checks
99+
- **Code quality**: Skipping quality checks leads to technical debt
100+
- **Team workflow**: Other developers expect clean, tested code
101+
- **Production safety**: Errors that pass locally will fail in production
102+
103+
### When Pre-commit Hooks Fail
104+
105+
1. **Read the error message carefully**
106+
2. **Fix the underlying issue** (don't just suppress the error)
107+
3. **Run the specific command that failed** to understand the error
108+
4. **Test your fix** by running the command again
109+
5. **Only commit when all checks pass**
110+
111+
### Common Pre-commit Failures and Solutions
112+
113+
```bash
114+
# If ruff linting fails
115+
source .venv/bin/activate && make lint
116+
117+
# If black formatting fails
118+
source .venv/bin/activate && make format
119+
120+
# If mypy type checking fails
121+
source .venv/bin/activate && make type-check
122+
123+
# If tests fail
124+
source .venv/bin/activate && make test
125+
126+
# If security scans fail
127+
source .venv/bin/activate && pip-audit -r requirements.txt
128+
```
129+
130+
### Emergency Situations
131+
132+
If you absolutely must bypass pre-commit hooks (emergency fixes only):
133+
134+
1. **Document why** in the commit message
135+
2. **Create a follow-up issue** to fix the bypassed checks
136+
3. **Fix the issues immediately** in the next commit
137+
4. **Never merge** code that bypasses security or quality checks
138+
84139
## Testing Strategy
85140

86141
- **Dual-suite architecture**: Public API tests (`test_backfill_scanning.py`) + Integration tests (`test_backfill_integration.py`)

.cursor/rules/python.mdc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,46 @@ globs: **/*.py
1313
- Use `from __future__ import annotations` for forward references - MUST be placed before any other imports or executable code, but may come after optional module-level elements (shebang, encoding declaration, license/comments block, or module docstring) to ensure consistent forward-reference behavior across the codebase
1414
- Docstrings required for public functions and classes (Google style)
1515

16+
## Pre-commit and Quality Gates
17+
18+
🚨 **CRITICAL**: Never use `--no-verify` when pushing Python code
19+
20+
- **ALWAYS** fix all linting errors before pushing
21+
- **ALWAYS** fix all type checking errors before pushing
22+
- **ALWAYS** fix all formatting issues before pushing
23+
- **ALWAYS** fix all security scan failures before pushing
24+
- **ALWAYS** ensure all tests pass before pushing
25+
26+
### Python-Specific Quality Checks
27+
28+
```bash
29+
# Activate virtual environment first
30+
source .venv/bin/activate
31+
32+
# Run all quality checks
33+
make lint # ruff linting
34+
make format # black formatting
35+
make type-check # mypy type checking
36+
make test # pytest testing
37+
pip-audit -r requirements.txt # security scanning
38+
```
39+
40+
### Common Python Quality Issues
41+
42+
```python
43+
# Fix import sorting issues
44+
# Run: ruff check --fix
45+
46+
# Fix type annotation issues
47+
# Run: mypy src/ --strict
48+
49+
# Fix formatting issues
50+
# Run: black src/
51+
52+
# Fix security issues
53+
# Run: pip-audit -r requirements.txt
54+
```
55+
1656
## Type Hints
1757

1858
```python

.cursor/rules/testing.mdc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,39 @@ globs: **/tests/**/*.py
55

66
# Testing Guidelines
77

8+
## Pre-commit Testing Rules
9+
10+
🚨 **CRITICAL**: Never use `--no-verify` when pushing test code
11+
12+
- **ALWAYS** ensure all tests pass before pushing
13+
- **ALWAYS** fix all test failures before pushing
14+
- **ALWAYS** ensure test coverage meets requirements before pushing
15+
- **ALWAYS** run both API and integration tests before pushing
16+
17+
### Test Quality Gates
18+
19+
```bash
20+
# Activate virtual environment first
21+
source .venv/bin/activate
22+
23+
# Run all tests
24+
make test-api # Quick API validation (recommended for development)
25+
make test-integration # Comprehensive functionality testing
26+
make test # Full test suite (for CI/CD)
27+
28+
# Run with coverage
29+
make test-coverage # Run tests with coverage reporting
30+
```
31+
32+
### When Tests Fail
33+
34+
1. **Read the test failure message carefully**
35+
2. **Run the specific test that failed** to understand the issue
36+
3. **Fix the underlying problem** (don't just skip the test)
37+
4. **Re-run the test** to confirm the fix
38+
5. **Run the full test suite** to ensure no regressions
39+
6. **Only commit when all tests pass**
40+
841
## Testing Strategy
942

1043
### Dual Test Suite Architecture

.github/scripts/test_vulnerability_scripts.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,6 @@ def test_create_issue_body_with_empty_vulns(self):
180180
self.assertIn("HIGH/CRITICAL vulnerabilities: 0", body)
181181

182182
@patch("create_security_issue.subprocess.run")
183-
@@
184-
@patch("create_security_issue.subprocess.run")
185-
@@
186-
@patch("create_security_issue.subprocess.run")
187-
@@
188-
@patch("create_security_issue.subprocess.run")
189-
@patch("subprocess.run")
190183
def test_create_github_issue_failure(self, mock_run):
191184
"""Test handling GitHub issue creation failure."""
192185
from subprocess import CalledProcessError

clients/typescript/contextforgeClient.ts

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ export class ContextForgeClient {
188188
}
189189
return false;
190190
}
191+
192+
/**
191193
* Parses error response body for better error messages.
192194
* @private
193195
*/
@@ -247,7 +249,7 @@ export class ContextForgeClient {
247249
}
248250

249251
// Decide whether to retry
250-
if (attempt < this.retryConfig.maxRetries && lastError !== undefined && this.shouldRetry(lastError, lastResponse)) {
252+
if (attempt < this.retryConfig.maxRetries && lastError !== undefined && this.shouldRetry(lastError)) {
251253
const delay = this.calculateDelay(attempt);
252254
// Log retry decision
253255
this.logger?.warn(`Retry attempt ${attempt + 1}/${this.retryConfig.maxRetries} for ${url}`, {
@@ -499,12 +501,54 @@ export class ContextForgeClient {
499501
return r.json() as Promise<{ vectors: number[][] }>;
500502
}
501503

502-
if (summary !== undefined && typeof summary !== 'string') {
503-
throw new Error('summary must be a string when provided');
504-
}
505-
if (summary !== undefined && summary.trim() === '') {
506-
throw new Error('summary must be a non-empty string when provided');
507-
}
504+
/**
505+
* Creates a checkpoint for a session using the v1 API.
506+
*
507+
* @param session_id - The session ID to create a checkpoint for
508+
* @param phase - The phase of the session (planning, execution, review)
509+
* @param summary - Optional summary of the checkpoint
510+
* @param metadata - Optional metadata for the checkpoint
511+
* @returns Promise resolving to an object indicating success
512+
* @throws Error if the API request fails
513+
*/
514+
async v1Checkpoint(
515+
session_id: string,
516+
phase: 'planning' | 'execution' | 'review',
517+
summary?: string,
518+
metadata?: Record<string, unknown>
519+
): Promise<{ ok: boolean }> {
520+
// Validate input
521+
if (!session_id || typeof session_id !== 'string' || session_id.trim() === '') {
522+
throw new Error('session_id must be a non-empty string');
523+
}
524+
if (!phase || !['planning', 'execution', 'review'].includes(phase)) {
525+
throw new Error('phase must be one of: planning, execution, review');
526+
}
527+
if (summary !== undefined && (typeof summary !== 'string' || summary.trim() === '')) {
528+
throw new Error('summary must be a non-empty string when provided');
529+
}
530+
if (metadata !== undefined) {
531+
if (typeof metadata !== 'object' || metadata === null || Array.isArray(metadata)) {
532+
throw new Error('metadata must be a non-null object when provided');
533+
}
534+
}
535+
536+
const body: {
537+
session_id: string;
538+
phase: string;
539+
summary?: string;
540+
metadata?: Record<string, unknown>;
541+
} = { session_id, phase };
542+
if (summary !== undefined) body.summary = summary;
543+
if (metadata !== undefined) body.metadata = metadata;
544+
545+
const r = await this.fetchWithRetry(`${this.baseUrl}/v1/checkpoint`, {
546+
method: "POST",
547+
headers: this.authHeaders(true),
548+
body: JSON.stringify(body),
549+
});
550+
return r.json() as Promise<{ ok: boolean }>;
551+
}
508552

509553
/**
510554
* Restores context for a session using the v1 API with retry logic.

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ dev = [
7676
"safety==3.6.2",
7777
"pip-audit==2.9.0",
7878
]
79+
openai = [
80+
"openai>=1.0.0,<3.0.0",
81+
"tiktoken>=0.5.0,<1.0.0",
82+
]
7983

8084
[tool.setuptools.packages.find]
8185
where = ["src"]

requirements-dev.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ tomli>=2.0.0
1313
tomli-w>=1.0.0
1414
pip-tools>=7.0.0
1515
pyright>=1.1.0
16+
mypy>=1.0.0

requirements-dev.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ mdurl==0.1.2
6464
# via markdown-it-py
6565
msgpack==1.1.2
6666
# via cachecontrol
67+
mypy==1.18.2
68+
# via -r requirements-dev.in
6769
mypy-extensions==1.1.0
68-
# via black
70+
# via
71+
# black
72+
# mypy
6973
nodeenv==1.9.1
7074
# via
7175
# pre-commit
@@ -81,7 +85,9 @@ packaging==25.0
8185
# pip-requirements-parser
8286
# pytest
8387
pathspec==0.12.1
84-
# via black
88+
# via
89+
# black
90+
# mypy
8591
pip-api==0.0.34
8692
# via pip-audit
8793
pip-audit==2.9.0
@@ -152,7 +158,9 @@ types-aiofiles==25.1.0.20251011
152158
types-pyyaml==6.0.12.20250915
153159
# via -r requirements-dev.in
154160
typing-extensions==4.15.0
155-
# via pyright
161+
# via
162+
# mypy
163+
# pyright
156164
urllib3==2.5.0
157165
# via requests
158166
virtualenv==20.35.3

requirements.in

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Core dependencies
2+
fastapi==0.120.0
3+
uvicorn[standard]==0.38.0
4+
pydantic==2.12.3
5+
orjson==3.11.3
6+
numpy==2.3.4
7+
pytest==8.4.2
8+
httpx==0.28.1
9+
ruff==0.14.2
10+
black==25.9.0
11+
starlette==0.48.0
12+
safety==3.6.2
13+
pip-audit==2.9.0
14+
tenacity==9.1.2
15+
aiofiles==25.1.0
16+
filelock==3.20.0
17+
click==8.3.0
18+
rich==14.2.0
19+
tomli==2.3.0
20+
tomli_w==1.2.0
21+
tiktoken>=0.5.0,<1.0.0
22+
openai>=1.0.0,<3.0.0
23+
# setuptools==80.9.0

0 commit comments

Comments
 (0)