1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
//! Mechanical verification that a filed issue satisfies the ticketing standard
//! (#7097).
//!
//! Why: #7067 made a milestone, a project, and native relationships mandatory
//! on every new issue, but the only thing enforcing that was the filing agent's
//! own self-check. An issue filed outside a `ticketing` dispatch — #7092 and
//! #7093 were the trigger — could carry or miss any of it with nothing
//! producing evidence either way. This module is the check that reads the
//! filed artifact back and says which requirements it actually meets.
//!
//! What: the [`IssueFacts`] wire shape `gh issue view --json` /
//! `gh issue list --json` return, [`audit_issue`] folding one issue's facts
//! against a [`ResolvedTicketing`] and a [`ComponentLabels`] set into an
//! [`IssueAudit`], and the two renderers ([`render_audit`] for one issue,
//! [`render_summary`] for a batch). Everything here is pure — the `gh` reads
//! live in [`crate::core::issue_audit_gh`] and the Cargo-manifest reads in
//! [`crate::core::component_labels`], so every verdict is unit-testable against
//! fixture JSON with no network and no filesystem.
//!
//! # What is and is not a failure
//!
//! A missing milestone or project is a FAIL only when the operator's
//! `agents.ticketing` block requires it; an unset requirement renders as INFO
//! so the report never invents a rule the config does not carry. A
//! `no-milestone: <reason>` comment is the standard's own escape hatch and
//! renders as SKIP with the reason quoted, never as a pass — a reader must be
//! able to tell "no milestone was needed, here is why" from "a milestone is
//! present". `no-component-label: <reason>` is the same hatch for the component
//! row (#7198): when no component unit owns the changed path — a Cargo crate
//! here, an npm workspace package or a Go module elsewhere; a `website/` or
//! CI-only issue is the shape — applying no component label is policy-correct.
//! Relationships are always INFO: a standalone issue legitimately has
//! no parent, no blocker, and no sub-issues, so their absence is a fact to
//! report and never a violation.
//!
//! Test: `issue_audit_tests.rs`.
use Deserialize;
use crateComponentLabels;
use crateResolvedTicketing;
/// The `--json` field list both `gh issue view` and `gh issue list` are asked
/// for.
///
/// Why: the audit's two entry points must read the SAME facts, or a batch run
/// would silently evaluate fewer requirements than a single-issue run. Naming
/// the list once is what keeps them in agreement.
/// What: the seven fields the requirements read, plus the three relationship
/// fields. `gh` 2.98 serves `parent`, `blockedBy` and `subIssues` from both
/// verbs, so the audit needs no separate `gh api` call for them. `title` is
/// read by `tm pr open` for a phase issue's `[EPIC_N PHASE_M]` tag (#9571).
/// Test: `json_fields_cover_every_audited_requirement`.
pub const AUDIT_JSON_FIELDS: &str = "number,title,milestone,projectItems,labels,comments,state,\
createdAt,parent,blockedBy,subIssues";
/// The comment prefix that excuses an unset milestone (#7067's escape hatch).
pub const NO_MILESTONE_PREFIX: &str = "no-milestone:";
/// The comment prefix that excuses an absent component label (#7198).
///
/// Why: when no component unit owns the changed path — the unit is a Cargo
/// crate here and an npm package or Go module in another stack; a `website/` or
/// CI-only issue is the shape — `tm-ticketing` policy is that applying no
/// component label is correct, so the audit needs the same recorded-waiver
/// escape hatch the milestone row already has.
/// Test: `a_missing_component_label_with_a_reason_comment_is_a_skip`.
pub const NO_COMPONENT_LABEL_PREFIX: &str = "no-component-label:";
/// The `gh` invocation that actually attaches an issue to a project (#7952).
///
/// Why: `gh issue edit <N> --add-project "<title>"` exits 0 and attaches
/// NOTHING when the title does not resolve inside the scope gh derives from the
/// repository — several projects share the title, or the project is owned by a
/// different login. The caller reads exit 0 as success, so the miss surfaces
/// only when this audit fails on the same issue afterwards. Naming the
/// owner-and-number form in the remediation is what stops the silent form from
/// being retried. `tm issue standard` prints each open project's number beside
/// its title, so the number never has to be guessed.
/// What: `gh project item-add <number> --owner <owner> --url <issue-url>` —
/// owner-scoped and keyed by number, so it names exactly one project.
/// Test: `a_missing_project_names_the_owner_scoped_attach`,
/// `issue_audit_warning_names_the_owner_scoped_attach`.
pub const PROJECT_ATTACH_HINT: &str =
"gh project item-add <number> --owner <owner> --url <issue-url>";
/// A `{"title": …}` node — a milestone or a project item.
/// A `{"name": …}` node — a label.
/// A `{"body": …}` node — an issue comment.
/// A `{"number": …}` node — the `parent` link.
/// A GraphQL connection (`blockedBy`, `subIssues`).
///
/// Why: gh renders these as `{"nodes":[…],"totalCount":N}`, and `totalCount`
/// can exceed the returned `nodes` page. Reporting the count rather than the
/// node list keeps the INFO line honest about a truncated page.
/// Test: `relationships_report_what_is_set` — which failed until the
/// `camelCase` rename landed here, since `rename_all` on [`IssueFacts`] does
/// not reach a nested type and `totalCount` silently parsed as 0.
/// One issue's audited facts, as `gh` returns them.
///
/// Why: the audit reads exactly what GitHub holds, so a fixture of this shape
/// is a faithful stand-in for a live issue and every verdict is testable
/// offline.
/// What: deserialized from a `gh issue view --json <AUDIT_JSON_FIELDS>` object,
/// or one element of the `gh issue list` array. Every field defaults, so a
/// caller that asks for fewer fields still parses.
/// Test: `facts_parse_a_live_view_payload`, `facts_parse_a_list_payload`.
/// One requirement's verdict.
///
/// Why: PASS/FAIL alone cannot express the two states the standard actually
/// has beyond them — a requirement waived on the record, and a fact reported
/// without a rule attached. Collapsing either into PASS is what would let a
/// waived milestone read as a set one.
/// What: `Pass`, `Fail` (the only verdict that exits 1), `Skip` (satisfied by
/// the recorded escape hatch), `Info` (reported, never gating).
/// Test: `an_unset_milestone_with_a_reason_comment_is_a_skip`.
/// One audited requirement.
/// One issue's complete audit.
/// Requirement names, in the order [`audit_issue`] emits them.
const REQ_PROJECT: &str = "project";
const REQ_MILESTONE: &str = "milestone";
const REQ_COMPONENT: &str = "component label";
const REQ_RELATIONSHIPS: &str = "relationships";
/// The requirement columns a batch summary table carries.
pub const SUMMARY_REQUIREMENTS: & = &;
/// Audit one issue's facts against the resolved ticketing standard.
///
/// Why: the whole point of #7097 — the standard was enforced only by the filing
/// agent's self-report, so this reads the artifact back and states, per
/// requirement, what it found. Taking [`ResolvedTicketing`] rather than
/// hardcoded booleans is what keeps the audit and `tm issue standard` reporting
/// the same rules.
/// What: four rows in a fixed order. `project` and `milestone` are PASS/FAIL
/// only when `project_required` / `milestone_required` are set and INFO
/// otherwise; an unset milestone with a `no-milestone: <reason>` comment is
/// SKIP with the reason quoted. `component label` requires at least one label
/// from `components` — the accepted set [`ComponentLabels`] derives, which is
/// the seed table plus the repository's own crate labels (#7123). The
/// `ws/<session>` workstream label is never in it, since a workstream is not a
/// component. `relationships` is always INFO.
/// Test: `a_compliant_issue_passes_every_requirement`, `a_missing_project_fails`,
/// `an_unset_milestone_with_a_reason_comment_is_a_skip`,
/// `an_unset_milestone_without_a_comment_fails`,
/// `an_unrequired_milestone_is_informational`,
/// `a_missing_component_label_fails`,
/// `a_non_mpm_crate_component_label_passes`,
/// `relationships_are_never_a_failure`.
/// The `project` row.
/// The `milestone` row, including the `no-milestone:` escape hatch.
/// The reason from the first `no-milestone: <reason>` comment, if any.
///
/// Test: `an_unset_milestone_with_a_reason_comment_is_a_skip`,
/// `the_no_milestone_comment_is_matched_case_insensitively`,
/// `a_no_milestone_note_inside_a_longer_comment_counts`.
/// The reason from the first `no-component-label: <reason>` comment, if any.
///
/// Test: `a_missing_component_label_with_a_reason_comment_is_a_skip`,
/// `the_no_component_label_comment_is_matched_case_insensitively`.
// #7198: mirrors `no_milestone_reason` over the component-label prefix.
/// The reason from the first `<prefix> <reason>` comment line, if any.
///
/// Why: the standard's escape hatches are comments, so the audit has to read
/// comment bodies rather than infer intent from an absent field. #7198 added a
/// second prefix, and one matcher is what keeps the two hatches behaving
/// identically.
/// What: matches `prefix` case-insensitively at the start of any LINE of any
/// comment (an agent posting the note inside a longer comment still counts),
/// and returns the trimmed remainder. An empty remainder still counts as
/// recorded — the standard asks for a reason, and reporting an empty one is
/// more useful than silently treating the comment as absent.
/// Test: `a_no_milestone_note_inside_a_longer_comment_counts`,
/// `the_no_component_label_comment_is_matched_case_insensitively`.
/// The `component label` row.
///
/// Why: #7123 — this row used to build its own accepted set from the labels the
/// harness SEEDS, which on this workspace is `trusty-mpm` alone, so an issue
/// correctly labelled with the crate that owns it failed. The accepted set is
/// now [`ComponentLabels`]'s, and the FAIL line names every label in it so the
/// fix is a label the reader can copy rather than a guess.
/// A `no-component-label: <reason>` comment renders SKIP with the reason
/// quoted, never PASS — the website/CI shape where no crate owns the changed
/// path is policy-correct, and a reader must still be able to tell a waived
/// row from a labelled one (#7198).
/// Test: `a_missing_component_label_fails`,
/// `a_non_mpm_crate_component_label_passes`,
/// `trusty_audit_alone_passes_the_component_label_check`,
/// `a_missing_component_label_with_a_reason_comment_is_a_skip`,
/// `a_present_component_label_wins_over_a_waiver_comment`.
/// The `relationships` row — always INFO.
///
/// Why: a standalone issue legitimately has no parent, no blocker and no
/// sub-issues, so their absence is a fact to report, never a violation.
/// Test: `relationships_are_never_a_failure`, `relationships_report_what_is_set`.
/// Whether an issue was created on or after `date` (`YYYY-MM-DD`).
///
/// Why: `--since` asks gh for `created:>=<date>`, and gh's search index can lag
/// or over-return. Re-checking the timestamp gh itself returned keeps the
/// reported window equal to the requested one rather than to whatever the
/// search served.
/// What: an RFC-3339 `createdAt` sorts lexicographically, so a prefix
/// comparison against the `YYYY-MM-DD` date is the whole test. An issue with no
/// `createdAt` (a caller that asked for fewer fields) is KEPT — dropping it
/// would silently shrink the audited set.
/// Test: `the_since_window_keeps_the_boundary_day`,
/// `the_since_window_keeps_an_issue_with_no_timestamp`.
/// Render one issue's audit as the per-requirement report.
///
/// Why: one line per requirement is the whole deliverable — a reader must see
/// which rule was checked, what was found, and the verdict, without reading the
/// config.
/// What: a `#<number>` header then one aligned ` <requirement> <TAG> <detail>`
/// line per row.
/// Test: `render_audit_prints_one_line_per_requirement`.
/// Render a batch of audits as a summary table.
///
/// Why: `--recent`/`--since` audits many issues, and a full per-requirement
/// block for each buries the failures. The table is one row per issue with one
/// column per gating requirement, then a count.
/// What: a header row, one row per audit carrying each
/// [`SUMMARY_REQUIREMENTS`] verdict tag and the overall verdict, then the
/// audited/failing counts. Relationships are omitted — they never gate.
/// Test: `render_summary_tabulates_every_issue`,
/// `render_summary_counts_only_failures`.