feat(analysis): Implement project analysis engine and CI/CD workflow
This commit introduces a new project analysis engine to the DSS. Key features include: - A new analysis module in `dss-mvp1/dss/analyze` that can parse React projects and generate a dependency graph. - A command-line interface (`dss-mvp1/dss-cli.py`) to run the analysis, designed for use in CI/CD pipelines. - A new `dss_project_export_context` tool in the Claude MCP server to allow AI agents to access the analysis results. - A `.gitlab-ci.yml` file to automate the analysis on every push, ensuring the project context is always up-to-date. - Tests for the new analysis functionality. This new architecture enables DSS to have a deep, version-controlled understanding of a project's structure, which can be used to power more intelligent agents and provide better developer guidance. The analysis is no longer automatically triggered on `init`, but is designed to be run manually or by a CI/CD pipeline.
This commit is contained in:
82
dss-mvp1/tests/conftest.py
Normal file
82
dss-mvp1/tests/conftest.py
Normal file
@@ -0,0 +1,82 @@
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def mock_react_project(tmp_path: Path) -> Path:
|
||||
"""
|
||||
Creates a temporary mock React project structure for testing.
|
||||
"""
|
||||
project_dir = tmp_path / "test-project"
|
||||
project_dir.mkdir()
|
||||
|
||||
# Create src directory
|
||||
src_dir = project_dir / "src"
|
||||
src_dir.mkdir()
|
||||
|
||||
# Create components directory
|
||||
components_dir = src_dir / "components"
|
||||
components_dir.mkdir()
|
||||
|
||||
# Component A
|
||||
(components_dir / "ComponentA.jsx").write_text("""
|
||||
import React from 'react';
|
||||
import './ComponentA.css';
|
||||
|
||||
const ComponentA = () => {
|
||||
return <div className="component-a">Component A</div>;
|
||||
};
|
||||
|
||||
export default ComponentA;
|
||||
""")
|
||||
|
||||
(components_dir / "ComponentA.css").write_text("""
|
||||
.component-a {
|
||||
color: blue;
|
||||
}
|
||||
""")
|
||||
|
||||
# Component B
|
||||
(components_dir / "ComponentB.tsx").write_text("""
|
||||
import React from 'react';
|
||||
import ComponentA from './ComponentA';
|
||||
|
||||
const ComponentB = () => {
|
||||
return (
|
||||
<div>
|
||||
<ComponentA />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ComponentB;
|
||||
""")
|
||||
|
||||
# App.js
|
||||
(src_dir / "App.js").write_text("""
|
||||
import React from 'react';
|
||||
import ComponentB from './components/ComponentB';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="App">
|
||||
<ComponentB />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
""")
|
||||
|
||||
# package.json
|
||||
(project_dir / "package.json").write_text("""
|
||||
{
|
||||
"name": "test-project",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"react": "^18.0.0"
|
||||
}
|
||||
}
|
||||
""")
|
||||
|
||||
return project_dir
|
||||
45
dss-mvp1/tests/test_project_analyzer.py
Normal file
45
dss-mvp1/tests/test_project_analyzer.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import pytest
|
||||
import json
|
||||
from pathlib import Path
|
||||
from dss.analyze.project_analyzer import run_project_analysis
|
||||
|
||||
def test_run_project_analysis(mock_react_project: Path):
|
||||
"""
|
||||
Tests the run_project_analysis function to ensure it creates the analysis graph
|
||||
and that the graph contains the expected file nodes.
|
||||
"""
|
||||
# Run the analysis on the mock project
|
||||
run_project_analysis(str(mock_react_project))
|
||||
|
||||
# Check if the analysis file was created
|
||||
analysis_file = mock_react_project / ".dss" / "analysis_graph.json"
|
||||
assert analysis_file.exists(), "The analysis_graph.json file was not created."
|
||||
|
||||
# Load the analysis data
|
||||
with open(analysis_file, 'r') as f:
|
||||
data = json.load(f)
|
||||
|
||||
# Verify the graph structure
|
||||
assert "nodes" in data, "Graph data should contain 'nodes'."
|
||||
assert "links" in data, "Graph data should contain 'links'."
|
||||
|
||||
# Get a list of node IDs (which are the relative file paths)
|
||||
node_ids = [node['id'] for node in data['nodes']]
|
||||
|
||||
# Check for the presence of the files from the mock project
|
||||
expected_files = [
|
||||
"package.json",
|
||||
"src/App.js",
|
||||
"src/components/ComponentA.css",
|
||||
"src/components/ComponentA.jsx",
|
||||
"src/components/ComponentB.tsx",
|
||||
]
|
||||
|
||||
for file_path in expected_files:
|
||||
# Path separators might be different on different OSes, so we normalize
|
||||
normalized_path = str(Path(file_path))
|
||||
assert normalized_path in node_ids, f"Expected file '{normalized_path}' not found in the analysis graph."
|
||||
|
||||
# Verify the number of nodes
|
||||
# There should be exactly the number of files we created
|
||||
assert len(node_ids) == len(expected_files), "The number of nodes in the graph does not match the number of files."
|
||||
Reference in New Issue
Block a user