topmark.pipeline.outcomes¶
Pure outcome bucketing and counting helpers used across frontends.
This module owns the presentation-free bucketing logic that maps a
ProcessingContext
to a stable public outcome and an optional human-facing reason.
Design goals:
- Presentation-free: no ANSI styling, markdown, or CLI-only wording.
- Reusable across frontends: CLI, docs tooling, and the public API.
- Stable outcomes: bucketing produces shared
Outcome values that are independent of the
chosen frontend.
- Deterministic summaries: (outcome, reason) counting is stable and ordered
using OUTCOME_ORDER defined in topmark.core.outcomes.
Outcome primitives live in topmark.core.outcomes
rather than topmark.api.types so this pipeline layer does not import the API
package while classifying results.
Notes
Styling is layered on top in frontend modules such as
topmark.presentation.shared.outcomes,
topmark.core.presentation and
topmark.cli.presentation.
Intent ¶
Bases: Enum
High-level action intent inferred from pipeline status.
Intent is a small internal classification used by map_bucket() to decide
whether a detected change should be reported as an insert, update, strip,
or a more generic change.
This is intentionally derived from status axes rather than from the chosen pipeline name so that bucketing remains robust across pipeline variants.
ResultBucket
dataclass
¶
Outcome + optional human-facing reason used for bucketing.
ResultBucket is the small value object returned by map_bucket(). It
couples the stable public outcome with the reason text used in summaries.
Attributes:
| Name | Type | Description |
|---|---|---|
outcome |
Outcome
|
The classified public outcome. |
reason |
str | None
|
Optional human-facing reason used in summary output. |
OutcomeReasonCount
dataclass
¶
Count for a specific (outcome, reason) summary bucket.
This value object is the canonical summary row used by human and machine output layers. It preserves both axes of classification:
outcome: the stable publicOutcomereason: the human-facing bucket reason used within that outcome
Keeping both axes avoids collapsing multiple distinct reasons into a single per-outcome count in summary views.
determine_intent ¶
Infer the high-level action intent from the current context.
The inferred intent is used only for public bucketing. It is intentionally derived from status axes so that it still works when different pipeline variants omit certain steps (for example, strip-summary pipelines may not run the comparer).
Inference rules:
- STRIP: the strip axis is non-pending, meaning a strip-oriented pipeline ran.
- INSERT: the header axis reports a missing header.
- UPDATE: the header axis is decided (not PENDING) and not missing.
- NONE: there is not yet enough information to infer a concrete action.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
ProcessingContext
|
The processing context. |
required |
Returns:
| Type | Description |
|---|---|
Intent
|
The inferred bucketing intent. |
Source code in src/topmark/pipeline/outcomes.py
map_bucket ¶
Map a processing context to a public bucket (Outcome + reason).
This logic is precedence-ordered: the first matching rule wins. The ordering matters because
some axes may remain PENDING depending on the chosen pipeline (for example, strip pipelines
may omit comparison).
Precedence (high → low):
1) Hard skips/errors (resolve/fs/content fatal states).
2) Content-level soft skips (mixed newlines / BOM-before-shebang / reflow).
3) Empty-file default compliance: empty files are UNCHANGED unless policy allows inserting
headers into empty files.
4) Strip intent mapping based on the strip axis (READY/NOT_NEEDED/FAILED). This must
not depend on comparison.
5) Malformed headers that TopMark cannot safely interpret.
6) Policy veto (add-only / update-only).
7) Comparison/write outcomes (for pipelines that ran compare and/or write).
8) Dry-run previews and remaining fallbacks (NO_FIELDS, plan status, generic would-change
cases).
9) Pending fallback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
ProcessingContext
|
The per-file pipeline context. |
required |
apply
|
bool
|
Whether the run is in apply mode. |
required |
Returns:
| Type | Description |
|---|---|
ResultBucket
|
Bucket containing public Outcome and a human label. |
Source code in src/topmark/pipeline/outcomes.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 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 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |
classify_outcome ¶
Return the public Outcome classification for a processing context.
This is a thin convenience wrapper around map_bucket() when only the
public Outcome (and not the human-facing reason) is needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
ProcessingContext
|
The processing context to classify. |
required |
apply
|
bool
|
Whether the run is in apply mode. |
required |
Returns:
| Type | Description |
|---|---|
Outcome
|
The public outcome classification derived by |
Source code in src/topmark/pipeline/outcomes.py
collect_outcome_reason_counts ¶
Collect summary counts grouped by (outcome, reason).
Unlike a plain per-outcome aggregation, this helper preserves the second
bucketing axis (reason) so summary views do not collapse distinct
sub-buckets inside the same Outcome.
Ordering is deterministic and stable:
1. Fixed public OUTCOME_ORDER
2. Alphabetical reason within each outcome
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
list[ProcessingContext]
|
Processing contexts to bucket and count. |
required |
Returns:
| Type | Description |
|---|---|
list[OutcomeReasonCount]
|
Sorted list of |