Guard CII formula protocol docs#4151
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Greptile SummaryThis PR adds a version-keyed snapshot guard that hashes CII formula coefficients (country weights, default weights, strategic-risk constants, conflict-curve constants, and
Confidence Score: 4/5Safe to merge; the snapshot guard and band-alignment tests are correct for the current codebase, and the documentation additions accurately reflect existing server-side logic. Both new tests exercise real constants from the live source files and would catch coefficient drift or cutoff divergence immediately. The two helpers (brace-counting body extractor and new Function executor) are fragile if getScoreLevel or getLevel are ever given TypeScript-specific body syntax or a return-type annotation containing '{', but pose no risk today. The MDX additions are factually accurate against the server implementation. The test helpers in tests/cii-scoring.test.mts deserve a second look — specifically extractFunctionBody and evaluateScoreLevel; the rest of the change is low-risk. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[cii-scoring.test.mts] -->|reads source text| B[cached-risk-scores.ts]
A -->|reads source text| C[country-instability.ts]
A -->|imports constants| D[_risk-config.ts]
A -->|imports constants| E[cii-weights.ts]
B -->|extractScoreLevelCutoffs| F[Snapshot Object]
D -->|STRATEGIC_RISK + CONFLICT constants| F
E -->|CII_COUNTRY_WEIGHTS + DEFAULT values| F
F -->|hashJson + compare| G[v5 stored hash]
B -->|extractScoreLevelCutoffs| H[Band Alignment Check]
C -->|extractScoreLevelCutoffs| H
H -->|assert 81 / 66 / 51 / 31| I[Pass / Fail]
B -->|evaluateScoreLevel via new Function| J[Score to Level Mapping]
C -->|evaluateScoreLevel via new Function| J
J -->|assert score equals level| I
Reviews (1): Last reviewed commit: "test(cii): guard formula protocol docs" | Re-trigger Greptile |
c85f8f8 to
36dd303
Compare
CII_FORMULA_VERSION bumped v5->v6 (#4147). No hashed coefficient changed (country weights, defaults, strategic constants, getScoreLevel cutoffs), so the v6 snapshot hash equals v5. Without this the version-keyed guard fails assert.ok(expectedHash) on main.
Summary
Coordination
This intentionally does not bump CII_FORMULA_VERSION; the separate codex/cii-v6-score-attribution-climate branch should own the v5-to-v6 formula bump and score-shifting narrative. When that branch lands, update the version-keyed protocol snapshot for the new formula version.
Validation