|
| 1 | +# BUILD_PR_SHARED_EXTRACTION_05_GETSTATE_PROMOTION_STATE_ONLY |
| 2 | + |
| 3 | +## Purpose |
| 4 | +Extract the duplicated promotion-state `getState` snapshot construction into one shared helper, without touching broader `getState` usages. |
| 5 | + |
| 6 | +## Single PR Purpose |
| 7 | +Centralize the duplicated promotion-state snapshot logic currently embedded inside: |
| 8 | +- `src/advanced/promotion/createPromotionGate.js` |
| 9 | +- `src/advanced/state/createWorldGameStateSystem.js` |
| 10 | + |
| 11 | +This BUILD does **not** attempt repo-wide `getState` normalization. |
| 12 | + |
| 13 | +## Exact Files Allowed |
| 14 | +Edit only these 3 files: |
| 15 | + |
| 16 | +1. `src/shared/state/createPromotionStateSnapshot.js` **(new file)** |
| 17 | +2. `src/advanced/promotion/createPromotionGate.js` |
| 18 | +3. `src/advanced/state/createWorldGameStateSystem.js` |
| 19 | + |
| 20 | +Do not edit any other file. |
| 21 | + |
| 22 | +## Exact New File |
| 23 | +Create: |
| 24 | + |
| 25 | +`src/shared/state/createPromotionStateSnapshot.js` |
| 26 | + |
| 27 | +### Required export |
| 28 | +Export exactly one named function: |
| 29 | + |
| 30 | +```js |
| 31 | +export function createPromotionStateSnapshot({ |
| 32 | + promoted, |
| 33 | + stableFrames, |
| 34 | + stabilityWindowFrames, |
| 35 | + lastReason, |
| 36 | + lastEvaluation, |
| 37 | + cloneLastEvaluation |
| 38 | +}) { |
| 39 | + return { |
| 40 | + promoted, |
| 41 | + stableFrames, |
| 42 | + stabilityWindowFrames, |
| 43 | + lastReason, |
| 44 | + lastEvaluation: typeof cloneLastEvaluation === 'function' |
| 45 | + ? cloneLastEvaluation(lastEvaluation) |
| 46 | + : lastEvaluation ?? null |
| 47 | + }; |
| 48 | +} |
| 49 | +``` |
| 50 | +
|
| 51 | +## Exact Source Changes |
| 52 | +
|
| 53 | +### 1) `src/advanced/promotion/createPromotionGate.js` |
| 54 | +Add import: |
| 55 | +
|
| 56 | +```js |
| 57 | +import { createPromotionStateSnapshot } from '../shared/state/createPromotionStateSnapshot.js'; |
| 58 | +``` |
| 59 | +
|
| 60 | +Replace the current local `getState()` body so it returns: |
| 61 | +
|
| 62 | +```js |
| 63 | +return createPromotionStateSnapshot({ |
| 64 | + promoted, |
| 65 | + stableFrames, |
| 66 | + stabilityWindowFrames, |
| 67 | + lastReason, |
| 68 | + lastEvaluation, |
| 69 | + cloneLastEvaluation: (value) => (value ? { ...value } : null) |
| 70 | +}); |
| 71 | +``` |
| 72 | +
|
| 73 | +Do not change the function name `getState`. |
| 74 | +Do not change `getMetrics`. |
| 75 | +Do not change evaluation logic. |
| 76 | +
|
| 77 | +### 2) `src/advanced/state/createWorldGameStateSystem.js` |
| 78 | +Add import: |
| 79 | +
|
| 80 | +```js |
| 81 | +import { createPromotionStateSnapshot } from '../../shared/state/createPromotionStateSnapshot.js'; |
| 82 | +``` |
| 83 | +
|
| 84 | +Replace the current local `getState()` body so it returns: |
| 85 | +
|
| 86 | +```js |
| 87 | +return createPromotionStateSnapshot({ |
| 88 | + promoted, |
| 89 | + stableFrames, |
| 90 | + stabilityWindowFrames: windowFrames, |
| 91 | + lastReason, |
| 92 | + lastEvaluation, |
| 93 | + cloneLastEvaluation: (value) => (value ? cloneDeep(value) : null) |
| 94 | +}); |
| 95 | +``` |
| 96 | +
|
| 97 | +Do not change the function name `getState`. |
| 98 | +Do not change `getMetrics`. |
| 99 | +Do not change transition/evaluation logic. |
| 100 | +
|
| 101 | +## Hard Constraints |
| 102 | +- no repo scan |
| 103 | +- no broader `getState` cleanup |
| 104 | +- no engine API changes |
| 105 | +- no renaming of existing `getState` functions |
| 106 | +- no helper extraction beyond this promotion-state snapshot helper |
| 107 | +- no additional files |
| 108 | +- no import normalization outside the 2 exact source files above |
| 109 | +- preserve existing behavior: |
| 110 | + - `createPromotionGate.js` keeps shallow-copy behavior for `lastEvaluation` |
| 111 | + - `createWorldGameStateSystem.js` keeps `cloneDeep` behavior for `lastEvaluation` |
| 112 | + - `createWorldGameStateSystem.js` keeps `stabilityWindowFrames: windowFrames` |
| 113 | +
|
| 114 | +## Validation Checklist |
| 115 | +1. Confirm only the 3 listed files changed |
| 116 | +2. Confirm `src/shared/state/createPromotionStateSnapshot.js` exists and exports only `createPromotionStateSnapshot` |
| 117 | +3. Confirm `getState()` still exists in: |
| 118 | + - `src/advanced/promotion/createPromotionGate.js` |
| 119 | + - `src/advanced/state/createWorldGameStateSystem.js` |
| 120 | +4. Confirm both `getState()` functions now delegate to `createPromotionStateSnapshot(...)` |
| 121 | +5. Confirm behavior is preserved: |
| 122 | + - promotion gate uses shallow copy for `lastEvaluation` |
| 123 | + - world game state system uses `cloneDeep` for `lastEvaluation` |
| 124 | + - world game state system still uses `windowFrames` as `stabilityWindowFrames` |
| 125 | +6. Confirm no other `getState` call sites or implementations were touched |
| 126 | +
|
| 127 | +## Non-Goals |
| 128 | +- no repo-wide `getState` standardization |
| 129 | +- no work in `samples/shared/worldGameStateSystem.js` |
| 130 | +- no work in consumers, integration files, or engine state APIs |
| 131 | +- no alias-path migration |
| 132 | +- no refactor beyond this exact extraction |
0 commit comments