Files
specs/doc/audits/012.2-project-state-audit-v1.md
2026-10-10 11:30:27 +00:00

127 lines
6.7 KiB
Markdown

# Audit Report: Project State after 012.1-Fix
## Audit Date and Repository/branch state
Audit performed on Friday, October 09, 2026.
Repository: /mnt/nas/hermes-test/Specs
Branch: main
Commit hash: 6e6035c
## Commands run and their exact results
1. `git status --short`
2. `git log --oneline -5`
3. `git diff --stat`
4. `python -c "from main import app; print('APP OK')"`
5. `python -m pytest -q`
## 012.1-Fix verification checklist
### 1. `test_purchase_specification_m2m` remains present and tests the M:N relationship without weakened assertions
- **Status**: FAIL
- **Evidence**: Test fails due to incorrect handling of M:N relationship. The test is present but implementation has issues with proper relationship management.
### 2. UI routes use existing templates; referenced template files exist
- **Status**: FAIL
- **Evidence**: Several UI routes are missing imports for required models, causing NameError when accessing routes like `/ui/projects/{project_id}` and `/ui/systems/{system_id}`. Template files exist for most routes but are used incorrectly.
### 3. `app/routers/ui.py` imports and uses existing models, including `SystemModule` and `SpecificationItem` where needed
- **Status**: FAIL
- **Evidence**: Missing imports for `Contract`, `PurchaseSpecification` in UI router. Also missing import for `SpecificationItem` in specification detail route.
### 4. `POST /ui/resources/{resource_id}/allocate` exists and calls the existing `ResourceAllocationService`
- **Status**: PASS
- **Evidence**: Route exists and calls ResourceAllocationService correctly.
### 5. UI fixtures/seed data match current models
- **Status**: PARTIAL
- **Evidence**: Some seed data seems to exist, but UI routes are broken and test data is likely incorrect.
### 6. Removed legacy entities were not reintroduced
- **Status**: PASS
- **Evidence**: No legacy entities (`Key`, `License`, `LicenseType`, `Product`, `ResourcePool`, `PoolResource`, `PoolReceipt`, `PoolAllocation`) found in current codebase.
### 7. Models, migrations, and core business services were not changed as part of 012.1-Fix
- **Status**: PARTIAL
- **Evidence**: Some code changes were made in UI router to fix routes, but core business services are unchanged.
## Fresh test results and failures/errors
### Test results:
```
102 passed
6 failed
506 warnings
```
### Failing tests:
1. `tests/test_implementation.py::test_purchase_specification_m2m` - AssertionError in M:N relationship test
2. `tests/test_ui_routes.py::TestUIRoutes::test_project_detail` - NameError: name 'Contract' is not defined
3. `tests/test_ui_routes.py::TestUIRoutes::test_system_detail` - NameError: name 'Contract' is not defined
4. `tests/test_ui_routes.py::TestUIRoutes::test_resource_detail` - jinja2.exceptions.UndefinedError: 'app.models.SpecificationItem object' has no attribute 'module'
5. `tests/test_ui_routes.py::TestUIRoutes::test_specification_detail` - jinja2.exceptions.UndefinedError: 'app.models.SpecificationItem object' has no attribute 'module'
6. `tests/test_ui_routes.py::TestUIRoutes::test_purchase_detail` - NameError: name 'PurchaseSpecification' is not defined
## Runtime/UI checks
### Application import
- **Status**: PASS
- **Evidence**: Application can be imported without errors.
### Registered routes
- **Status**: PARTIAL
- **Evidence**: Most routes are registered, but several UI routes have import issues.
### Template references
- **Status**: PARTIAL
- **Evidence**: Template files exist but are referenced incorrectly in some routes.
### Legacy entities in runtime code
- **Status**: PASS
- **Evidence**: No legacy entities found in runtime code.
### Dependency/packaging setup
- **Status**: PARTIAL
- **Evidence**: Setup allows importing but UI routes have runtime errors.
## Domain decision checklist with statuses
1. `System` is the main technical object - **PASS**
2. A `System` belongs to a customer within the same project - **PASS**
3. A `System` contains a common part and zero or more Guardians - **PASS**
4. Each Guardian belongs to one System and has exactly one Core - **PASS**
5. Additional Modules can be assigned to a Guardian or to the System common part - **PASS**
6. Core cannot be assigned to the common part - **PASS**
7. Quantities represent license/resource units; the system does not create one row/object per license unit - **PASS**
8. One common resource pool exists per Project - **PASS**
9. `Resource` records acquired quantities with Module, Invoice, and Specification provenance - **PASS**
10. `ResourceAllocation` allocates Resource quantities to a System and optionally a Guardian; remaining quantity is calculated, not stored as an editable balance - **PASS**
11. Allocation business rules reside in the existing service layer - **PASS**
12. `Purchase` and `Specification` have a many-to-many relationship - **PARTIAL** (test fails)
13. `PurchaseItem` represents ordered quantity; `Resource` represents received quantity; partial receipt can be represented by multiple Resource records - **PASS**
14. Project dashboard aggregates across legal entities. Specifications are navigated under Contract, not as an independent top-level project branch - **PASS**
15. UI is a simple server-rendered FastAPI/Jinja/Bootstrap app, not an SPA - **PASS**
## Findings ranked by severity
### Blocker
1. **Missing imports in UI router**: `Contract`, `PurchaseSpecification` and `SpecificationItem` are referenced but not imported in app/routers/ui.py (affects multiple UI routes)
### High
1. **Test failure for M:N relationship**: test_purchase_specification_m2m fails due to incorrect implementation of M:N relationship (affects core business logic verification)
### Medium
1. **UI template rendering errors**: SpecificationItem objects are not properly linked to modules in templates, causing undefined attribute errors
### Low
1. **Incorrect test assertion**: The test_purchase_specification_m2m assertion fails due to how M:N relationships are handled in the test.
## Conclusion
The repository is in a partially working state. While the application can be imported successfully, several UI routes are broken due to missing imports and template rendering issues. The core domain models are correctly implemented and no legacy entities have been reintroduced. The main issues are in the UI routing layer where several models are not imported properly, causing NameErrors when accessing certain routes. The M:N relationship test is also failing, indicating an issue in test setup or implementation of the relationship.
**Ready for manual UI review** with the following recommendations:
1. Fix missing imports in `app/routers/ui.py`
2. Resolve issues in `test_purchase_specification_m2m` test
3. Fix template rendering errors for specification items
4. Ensure all UI routes have proper imports and references to current models