Skip to content

Commit 97f5917

Browse files
authored
Merge pull request #67 from HyperionGray/Q-DEV-issue-62-1766538095
pf task check
2 parents e84565d + e9073bc commit 97f5917

19 files changed

+1168
-0
lines changed

.pf

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Python CDP Library Tasks
2+
# Simple wrappers around existing Makefile targets
3+
# Following pf simplicity rules - just calls to existing scripts
4+
5+
# Default task - runs the complete build pipeline
6+
default:
7+
poetry run make default
8+
9+
# Code generation tasks
10+
generate:
11+
poetry run make generate
12+
13+
# Type checking tasks
14+
typecheck:
15+
poetry run make mypy-cdp mypy-generate
16+
17+
# Testing tasks
18+
test:
19+
poetry run make test-cdp test-generate test-import
20+
21+
# Individual test components
22+
test-cdp:
23+
poetry run make test-cdp
24+
25+
test-generate:
26+
poetry run make test-generate
27+
28+
test-import:
29+
poetry run make test-import
30+
31+
# Documentation
32+
docs:
33+
poetry run make docs
34+
35+
# Development workflow - complete validation
36+
validate:
37+
poetry run make default
38+
39+
# Clean and rebuild everything
40+
rebuild:
41+
poetry run make generate
42+
poetry run make mypy-cdp mypy-generate
43+
poetry run make test-cdp test-generate test-import
44+
45+
# Quick check - just run tests on existing code
46+
check:
47+
poetry run make test-cdp test-import

PROJECT.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Python Chrome DevTools Protocol (CDP) Library
2+
3+
This is a Python library that provides type wrappers for the Chrome DevTools Protocol.
4+
The project generates Python bindings from the official CDP JSON specifications.
5+
6+
Project Type: Python Library
7+
Build System: Poetry + Makefile
8+
Primary Purpose: Provide typed Python interfaces for Chrome DevTools Protocol
9+
10+
Key Components:
11+
- cdp/ - Generated Python modules for each CDP domain
12+
- generator/ - Code generation scripts that create the CDP bindings
13+
- docs/ - Sphinx documentation
14+
- test/ - Test suites for both generated code and generator
15+
16+
Build Workflow:
17+
1. Generate CDP bindings from JSON specs (make generate)
18+
2. Run type checking (make mypy-cdp, make mypy-generate)
19+
3. Run tests (make test-cdp, make test-generate)
20+
4. Test imports (make test-import)
21+
5. Build documentation (make docs)
22+
23+
This project follows standard Python library patterns and uses Poetry for dependency
24+
management. The pf files in this repository provide simple wrappers around the
25+
existing Makefile targets for organizational consistency.

WARP.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# WARP Context for Python CDP Library
2+
3+
## Project Overview
4+
This repository contains a Python library for Chrome DevTools Protocol (CDP) type wrappers.
5+
It's a code generation project that creates Python bindings from official CDP specifications.
6+
7+
## WARP Usage Context
8+
When using this project through WARP:
9+
10+
### Primary Use Cases
11+
- Generating updated CDP bindings when Chrome DevTools Protocol changes
12+
- Running comprehensive tests on generated code
13+
- Building documentation for the CDP Python API
14+
- Type checking the generated Python modules
15+
16+
### Performance Metrics
17+
- **Code Generation Speed**: Time to generate all CDP modules from JSON specs
18+
- **Test Coverage**: Percentage of generated code covered by tests
19+
- **Type Safety**: MyPy validation of generated type annotations
20+
- **Import Performance**: Time to import generated modules
21+
22+
### Build Automation
23+
The project uses a hybrid approach:
24+
- **Primary**: Poetry + Makefile (standard Python toolchain)
25+
- **Secondary**: pf tasks (organizational consistency wrappers)
26+
27+
### Key Performance Indicators
28+
- Generation time for ~50 CDP domains
29+
- Memory usage during code generation
30+
- Test execution time across all modules
31+
- Documentation build time
32+
33+
### Development Workflow
34+
1. Update CDP JSON specifications (browser_protocol.json, js_protocol.json)
35+
2. Run code generation (pf generate)
36+
3. Validate with type checking (pf typecheck)
37+
4. Run comprehensive tests (pf test)
38+
5. Build and verify documentation (pf docs)
39+
40+
### Automation Notes
41+
This project is suitable for automated builds and can be integrated into
42+
larger CDP-dependent projects. The pf tasks provide simple, reliable
43+
entry points for automation systems.

basic_check.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
cd /workspace
3+
echo "Current directory: $(pwd)"
4+
echo "Python version: $(python3 --version)"
5+
echo "Files in workspace:"
6+
ls -la
7+
echo
8+
echo "Testing basic Python import:"
9+
python3 simple_test.py

check_poetry.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
# Simple test to check poetry availability
3+
poetry --version

comprehensive_pf_test.py

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
import subprocess
6+
import json
7+
from datetime import datetime
8+
9+
class PFTaskTester:
10+
def __init__(self):
11+
self.results = {}
12+
self.workspace = '/workspace'
13+
14+
def run_command(self, cmd, timeout=60):
15+
"""Run a command and return (success, stdout, stderr)"""
16+
try:
17+
os.chdir(self.workspace)
18+
result = subprocess.run(
19+
cmd,
20+
shell=True,
21+
capture_output=True,
22+
text=True,
23+
timeout=timeout
24+
)
25+
return result.returncode == 0, result.stdout, result.stderr
26+
except subprocess.TimeoutExpired:
27+
return False, "", "Command timed out"
28+
except Exception as e:
29+
return False, "", str(e)
30+
31+
def test_task(self, task_name, command, description=""):
32+
"""Test a single pf task"""
33+
print(f"\n{'='*50}")
34+
print(f"Testing: {task_name}")
35+
print(f"Command: {command}")
36+
if description:
37+
print(f"Description: {description}")
38+
print('='*50)
39+
40+
success, stdout, stderr = self.run_command(command)
41+
42+
self.results[task_name] = {
43+
'command': command,
44+
'success': success,
45+
'stdout': stdout[:500] if stdout else "",
46+
'stderr': stderr[:500] if stderr else "",
47+
'description': description
48+
}
49+
50+
if success:
51+
print(f"✓ {task_name}: PASSED")
52+
if stdout:
53+
print(f"Output: {stdout[:200]}...")
54+
else:
55+
print(f"✗ {task_name}: FAILED")
56+
if stderr:
57+
print(f"Error: {stderr[:200]}...")
58+
59+
return success
60+
61+
def test_all_pf_tasks(self):
62+
"""Test all tasks defined in .pf file"""
63+
print("=== COMPREHENSIVE PF TASK TESTING ===")
64+
print(f"Started at: {datetime.now()}")
65+
print(f"Workspace: {self.workspace}")
66+
67+
# Read the .pf file to understand what we're testing
68+
try:
69+
with open(f"{self.workspace}/.pf", 'r') as f:
70+
pf_content = f.read()
71+
print(f"\nPF file content preview:\n{pf_content[:300]}...")
72+
except Exception as e:
73+
print(f"Could not read .pf file: {e}")
74+
75+
# Test each task from the .pf file
76+
# Note: Testing the underlying commands since pf tool may not be available
77+
78+
tasks_to_test = [
79+
# Basic functionality tests
80+
("test-import", "python3 -c 'import cdp; print(cdp.accessibility)'",
81+
"Test basic CDP module import"),
82+
83+
# Code generation
84+
("generate", "python3 generator/generate.py",
85+
"Generate CDP bindings from JSON specs"),
86+
87+
# Testing tasks
88+
("test-generate", "python3 -m pytest generator/ -v",
89+
"Run tests on the generator code"),
90+
91+
("test-cdp", "python3 -m pytest test/ -v",
92+
"Run tests on the CDP modules"),
93+
94+
# Type checking tasks
95+
("mypy-generate", "python3 -m mypy generator/",
96+
"Type check the generator code"),
97+
98+
("mypy-cdp", "python3 -m mypy cdp/",
99+
"Type check the CDP modules"),
100+
101+
# Documentation
102+
("docs", "cd docs && python3 -m sphinx -b html . _build/html",
103+
"Build documentation"),
104+
105+
# Combined tasks (these map to pf tasks)
106+
("typecheck-combined", "python3 -m mypy generator/ && python3 -m mypy cdp/",
107+
"Combined type checking (typecheck pf task)"),
108+
109+
("test-combined", "python3 -m pytest test/ -v && python3 -m pytest generator/ -v && python3 -c 'import cdp; print(cdp.accessibility)'",
110+
"Combined testing (test pf task)"),
111+
112+
("check-combined", "python3 -m pytest test/ -v && python3 -c 'import cdp; print(cdp.accessibility)'",
113+
"Quick check (check pf task)"),
114+
]
115+
116+
# Run all tests
117+
passed = 0
118+
total = len(tasks_to_test)
119+
120+
for task_name, command, description in tasks_to_test:
121+
if self.test_task(task_name, command, description):
122+
passed += 1
123+
124+
# Summary
125+
print(f"\n{'='*60}")
126+
print("FINAL TEST RESULTS")
127+
print('='*60)
128+
129+
for task_name in self.results:
130+
result = self.results[task_name]
131+
status = "✓ PASS" if result['success'] else "✗ FAIL"
132+
print(f"{task_name:20} {status}")
133+
134+
print(f"\nSummary: {passed}/{total} tasks passed")
135+
136+
if passed == total:
137+
print("🎉 ALL PF TASKS ARE WORKING CORRECTLY!")
138+
print("✓ Every command in the .pf file has been tested and works.")
139+
else:
140+
print("⚠️ SOME PF TASKS NEED ATTENTION")
141+
print("✗ Failed tasks need to be fixed or removed per rules.")
142+
143+
# Save detailed results
144+
self.save_results()
145+
146+
return passed == total
147+
148+
def save_results(self):
149+
"""Save test results to file"""
150+
try:
151+
with open(f"{self.workspace}/pf_test_results.json", 'w') as f:
152+
json.dump({
153+
'timestamp': datetime.now().isoformat(),
154+
'summary': {
155+
'total_tasks': len(self.results),
156+
'passed_tasks': sum(1 for r in self.results.values() if r['success']),
157+
'failed_tasks': sum(1 for r in self.results.values() if not r['success'])
158+
},
159+
'results': self.results
160+
}, f, indent=2)
161+
print(f"\n📄 Detailed results saved to: pf_test_results.json")
162+
except Exception as e:
163+
print(f"Could not save results: {e}")
164+
165+
def main():
166+
tester = PFTaskTester()
167+
success = tester.test_all_pf_tasks()
168+
169+
if not success:
170+
print("\n⚠️ ACTION REQUIRED:")
171+
print("Some pf tasks failed. Per rules, these need to be:")
172+
print("1. Fixed if they're still relevant")
173+
print("2. Removed if they're no longer needed")
174+
print("3. Updated if they're outdated")
175+
176+
return 0 if success else 1
177+
178+
if __name__ == "__main__":
179+
sys.exit(main())

comprehensive_test.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env python3
2+
3+
import subprocess
4+
import sys
5+
import os
6+
7+
def run_command(cmd, description):
8+
"""Run a command and report results"""
9+
print(f"\n=== {description} ===")
10+
print(f"Running: {cmd}")
11+
12+
try:
13+
result = subprocess.run(cmd, shell=True, capture_output=True, text=True, cwd='/workspace')
14+
15+
if result.returncode == 0:
16+
print(f"✓ {description}: PASS")
17+
if result.stdout:
18+
print("Output:", result.stdout[:200] + "..." if len(result.stdout) > 200 else result.stdout)
19+
else:
20+
print(f"✗ {description}: FAIL")
21+
print("Error:", result.stderr[:200] + "..." if len(result.stderr) > 200 else result.stderr)
22+
23+
return result.returncode == 0
24+
25+
except Exception as e:
26+
print(f"✗ {description}: ERROR - {e}")
27+
return False
28+
29+
def main():
30+
print("=== Testing PF Tasks (Direct Commands) ===")
31+
32+
# Change to workspace directory
33+
os.chdir('/workspace')
34+
35+
# Test basic Python functionality
36+
success_count = 0
37+
total_tests = 0
38+
39+
# Test 1: Basic import
40+
total_tests += 1
41+
if run_command("python3 -c 'import cdp; print(cdp.accessibility)'", "Basic CDP Import"):
42+
success_count += 1
43+
44+
# Test 2: Generator tests
45+
total_tests += 1
46+
if run_command("python3 -m pytest generator/ -v", "Generator Tests"):
47+
success_count += 1
48+
49+
# Test 3: CDP tests
50+
total_tests += 1
51+
if run_command("python3 -m pytest test/ -v", "CDP Tests"):
52+
success_count += 1
53+
54+
# Test 4: Code generation
55+
total_tests += 1
56+
if run_command("python3 generator/generate.py", "Code Generation"):
57+
success_count += 1
58+
59+
# Test 5: MyPy on generator
60+
total_tests += 1
61+
if run_command("python3 -m mypy generator/", "MyPy Generator"):
62+
success_count += 1
63+
64+
# Test 6: MyPy on CDP
65+
total_tests += 1
66+
if run_command("python3 -m mypy cdp/", "MyPy CDP"):
67+
success_count += 1
68+
69+
print(f"\n=== Test Summary ===")
70+
print(f"Passed: {success_count}/{total_tests}")
71+
print(f"Failed: {total_tests - success_count}/{total_tests}")
72+
73+
if success_count == total_tests:
74+
print("✓ All pf tasks are working correctly!")
75+
else:
76+
print("✗ Some pf tasks have issues that need to be addressed.")
77+
78+
if __name__ == "__main__":
79+
main()

0 commit comments

Comments
 (0)