7.2 KiB
Story 11.14: Danfoss Parser
Status: done
Story
As a refrigeration engineer, I want Danfoss compressor data integration, so that I can use Danfoss coefficients in simulations.
Acceptance Criteria
-
Given a
DanfossBackendstruct When constructed viaDanfossBackend::new()Then it loads the compressor index fromdata/danfoss/compressors/index.jsonAnd eagerly pre-caches all referenced model JSON files into memory -
Given a valid Danfoss JSON file When parsed by
DanfossBackendThen it yields aCompressorCoefficientsstruct with all 10 capacity and 10 power coefficients And it supports AHRI 540 format extraction -
Given
DanfossBackendimplementsVendorBackendWhen I calllist_compressor_models()Then it returns all model names from the pre-loaded cache in sorted order -
Given a valid model name When I call
get_compressor_coefficients("some_model")Then it returns the fullCompressorCoefficientsstruct -
Given a model name not in the catalog When I call
get_compressor_coefficients("NONEXISTENT")Then it returnsVendorError::ModelNotFound("NONEXISTENT") -
Given
list_bphx_models()called onDanfossBackendWhen Danfoss only provides compressor data here Then it returnsOk(vec![])(empty list, not an error) -
Given
get_bphx_parameters("anything")called onDanfossBackendWhen Danfoss only provides compressor data here Then it returnsVendorError::InvalidFormatwith descriptive message -
Given unit tests When
cargo test -p entropyk-vendorsis run Then all existing tests still pass And new Danfoss-specific tests pass (model loading, error cases)
Tasks / Subtasks
- Task 1: Create sample Danfoss JSON data files (AC: 2)
- Subtask 1.1: Create
data/danfoss/compressors/index.jsonwith sample models - Subtask 1.2: Create
data/danfoss/compressors/model1.jsonwith realistic coefficients - Subtask 1.3: Create
data/danfoss/compressors/model2.jsonas second model
- Subtask 1.1: Create
- Task 2: Implement
DanfossBackend(AC: 1, 3, 4, 5, 6, 7)- Subtask 2.1: Create
src/compressors/danfoss.rswithDanfossBackendstruct - Subtask 2.2: Implement
DanfossBackend::new()resolving toENTROPYK_DATAwith fallback toCARGO_MANIFEST_DIR/data - Subtask 2.3: Implement
load_index()andload_model()pre-caching logic (incorporating fixes from Swep) - Subtask 2.4: Implement
VendorBackendtrait forDanfossBackend
- Subtask 2.1: Create
- Task 3: Wire up module exports
- Subtask 3.1: Add
pub mod danfoss;insrc/compressors/mod.rs - Subtask 3.2: Re-export
DanfossBackendinsrc/lib.rs
- Subtask 3.1: Add
- Task 4: Write unit tests (AC: 8)
- Subtask 4.1: Test
DanfossBackend::new()successfully constructs - Subtask 4.2: Test
list_compressor_models()returns sorted models - Subtask 4.3: Test
get_compressor_coefficients()returns valid data - Subtask 4.4: Test
ModelNotFounderror for unknown model - Subtask 4.5: Test
list_bphx_models()returns empty - Subtask 4.6: Test
get_bphx_parameters()returnsInvalidFormat
- Subtask 4.1: Test
- Task 5: Verify all tests pass (AC: 8)
- Subtask 5.1: Run
cargo test -p entropyk-vendors - Subtask 5.2: Run
cargo clippy -p entropyk-vendors -- -D warnings
- Subtask 5.1: Run
- Task 6: Review Follow-ups (AI)
- Fix Error Swallowing during JSON deserialization to provide contextual file paths
- Fix Path Traversal vulnerability by sanitizing model parameter
- Improve Test Quality by asserting multiple coefficients per array
- Improve Test Coverage by adding test directly validating
DanfossBackend::from_path() - Address Code Duplication with
CopelandBackend(deferred to future technical debt story)
Dev Notes
Architecture
This builds entirely on the VendorBackend trait pattern established in epic 11. Similar to CopelandBackend and SwepBackend, DanfossBackend pre-caches JSON files containing coefficients mapping to CompressorCoefficients.
Project Structure Notes
crates/vendors/
├── data/danfoss/compressors/
│ ├── index.json # NEW: ["model1", "model2"]
│ ├── model1.json # NEW: Ahri 540 coefficients
│ └── model2.json # NEW: Ahri 540 coefficients
└── src/
├── compressors/
│ ├── danfoss.rs # NEW: main implementation
│ └── mod.rs # MODIFY: add `pub mod danfoss;`
├── lib.rs # MODIFY: export DanfossBackend
Critical Git/Dev Context
- Keep error logging idiomatic: use
log::warn!instead ofeprintln!(from recentSwepBackendfixc5a51d8). - Maintain an internal sorted
Vecfor models in the struct to guarantee deterministic output fromlist_compressor_models()without resorting every time (Issue M1 from Swep). - Make sure
datadirectory resolution uses standard patternENTROPYK_DATAwith fallback toCARGO_MANIFEST_DIRin debug mode.
Testing Standards
- 100% test coverage for success paths, missing files, invalid formats, and
vendor_name(). - Place tests in
src/compressors/danfoss.rsinmod testsblock.
References
- Source: epics.md#Story-11.14
- Source: copeland.rs - Primary implementation reference for compressors
- Source: swep.rs - Reference for the latest architectural best-practices applied
Dev Agent Record
Agent Model Used
Antigravity (Gemini)
Debug Log References
Completion Notes List
- Comprehensive story details extracted from Epic 11 analysis and previously corrected Swep implementation.
- Status set to ready-for-dev with BMad-compliant Acceptance Criteria list.
- Implemented
DanfossBackendmimicking the robust pattern ofCopelandBackend, and applied architectural fixes fromSwepBackend(idomatic error logging, sortinglist_compressor_models). - Created Danfoss JSON data files:
index.json,SH090-4.json,SH140-4.json. - Integrated
danfossmodule into the vendors crate and re-exportedDanfossBackendinsidelib.rs. - Added unit tests mimicking Copeland coverage. Ran
cargo testandcargo clippyto achieve zero warnings with all tests passing. - Advanced story status to
review. - Code review findings addressed: fixed error swallowing during deserialization, sanitized input to prevent path traversal, added
from_path()test coverage, and tightened test assertions. Deferred code duplication cleanup. - Advanced story status from
reviewtodone.
File List
crates/vendors/data/danfoss/compressors/index.json(created)crates/vendors/data/danfoss/compressors/SH090-4.json(created)crates/vendors/data/danfoss/compressors/SH140-4.json(created)crates/vendors/src/compressors/danfoss.rs(created)crates/vendors/src/compressors/mod.rs(modified)crates/vendors/src/lib.rs(modified)