Repository navigation
Commit 41d6ab0
committed
fix(usage): route malformed-counter diagnostics to a production-active sink
What: replace the `logger` import in chat-usage-normalization.ts with a
module-local `CompactLogger` instance, and guard the emit so a sink failure
cannot escape into usage accounting. Rewrite the spec cases to spy on
`CompactLogger.prototype.warn`, and add two cases: one that simulates the
production branch (NODE_ENV=production) and asserts the warning still reaches
a real logger, and one that asserts a throwing sink does not abort accounting.
Why: CodeRabbit thread r4426014105 (and reviewer F-01). The exported `logger`
is `process.env.NODE_ENV === "test" ? new CompactLogger() : noopLogger`, so
every `logger.warn` in production is discarded. The hardening added for the
mlarge P2 finding therefore promised a diagnostic that no real install would
ever emit. The sink is now active regardless of NODE_ENV.
Impact: malformed-counter warnings are actually emitted in production, once
per alias, with the same dedupe semantics as before. Valid-shape behavior is
unchanged: all pre-existing helper cases pass unmodified. A broken log sink
degrades to silence rather than surfacing as a usage failure.
Disclosed separately, NOT fixed here: `src/utils/logging/index.ts:25` selects
CompactLogger only when NODE_ENV === "test", which is the inverse of its own
docstring ("Uses CompactLogger for normal operation, switches to noop logger in
Jest test environment"). Correcting that ternary would change logging for every
extension call site, so it is reported as a pre-existing repo-wide finding
rather than widened into this PR.
Refs: #2254 (comment)1 parent b0567c5 commit 41d6ab0
2 files changed
Lines changed: 83 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
| 183 | + | |
184 | 184 | | |
185 | | - | |
| 185 | + | |
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
199 | 248 | | |
200 | 249 | | |
201 | | - | |
| 250 | + | |
202 | 251 | | |
203 | | - | |
| 252 | + | |
204 | 253 | | |
205 | 254 | | |
206 | 255 | | |
| |||
215 | 264 | | |
216 | 265 | | |
217 | 266 | | |
218 | | - | |
| 267 | + | |
219 | 268 | | |
220 | | - | |
| 269 | + | |
221 | 270 | | |
222 | 271 | | |
223 | 272 | | |
| |||
236 | 285 | | |
237 | 286 | | |
238 | 287 | | |
239 | | - | |
| 288 | + | |
240 | 289 | | |
241 | 290 | | |
242 | 291 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
104 | 128 | | |
105 | 129 | | |
106 | 130 | | |
| |||
113 | 137 | | |
114 | 138 | | |
115 | 139 | | |
116 | | - | |
| 140 | + | |
117 | 141 | | |
118 | 142 | | |
119 | 143 | | |
| |||
0 commit comments