Add myHerb sustainability shift guidance prototype#20
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
|
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bd03f01e4e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if seen != set(PILLARS): | ||
| raise ValueError("Assessments must include each pillar exactly once") | ||
|
|
||
| resolved_weights = weights or _default_weights() |
There was a problem hiding this comment.
Treat empty custom weights as invalid input
Using weights or _default_weights() makes an empty dict ({}) fall back to defaults instead of failing validation, so callers with misloaded/empty config silently get a report computed with unintended weights. In this case the "Weights must include all pillars" guard is never reached, which hides input errors and can produce incorrect guidance without any exception.
Useful? React with 👍 / 👎.
| total_weight = sum(resolved_weights.values()) | ||
| if abs(total_weight - 1.0) > 1e-9: | ||
| raise ValueError("Weights must sum to 1.0") |
There was a problem hiding this comment.
Enforce valid weight ranges before scoring
The current validation only checks that weights sum to 1.0, so invalid distributions like a negative weight offset by a >1 weight (or NaN values) can pass and yield nonsensical aggregate scores and tiers. This affects any caller providing custom weights, and it can silently corrupt the report output; each weight should be validated as finite and within an expected range (typically 0..1).
Useful? React with 👍 / 👎.
Motivation
Description
apps/myherb_shift_advisor.py, which definesPILLARS, aPillarAssessmentdataclass with input validation,generate_shift_reportthat computes a weighted score (using default weights), assigns a maturity tier, and returns the top-3 priority recommendations._default_weights()and_tier_from_score()helpers and round the aggregated score to two decimal places.apps/test_myherb_shift_advisor.pythat check report generation (tier, weighted score, and priorities) and validate that invalid weight sums raiseValueError.README.mdwith a new "myHerb Sustainability Shift Guidance (Prototype)" section including quick run and test instructions.Testing
cd apps && python -m unittest test_myherb_shift_advisor.py.71.25but the implementation produced71.75, so the expected value in the test was updated to71.75.2 tests runand all tests passed (OK).Codex Task