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
//! Stderr diagnostic normalization and absence classifiers.
pub
/// Returns `true` if `stderr` from an `nb show <sel>` invocation
/// matches the exact `nb 7.24.0` selector-absence diagnostic
/// shape for the given expected selector. The complete
/// normalized diagnostic must equal `! Not found: <expected>`,
/// with no other content (no appended text, no mismatched
/// selector name, no other failure-mode substring).
///
/// Diagnostic normalization: ANSI escape sequences and
/// singleton control bytes (e.g., the Shift-In byte `\x0f`)
/// that `nb 7.24.0` emits between the diagnostic-bang and the
/// visible text are dropped. The criterion applies to the
/// resulting printable form.
///
/// Verified failure modes that MUST NOT match even though they
/// mention a "not found" string:
/// - `"Permission denied: file not found: /etc/x"` (real
/// subprocess failure with a non-existent path substring).
/// - `"Notebook not found: scratch"` (notebook-absence shape,
/// different classifier).
/// - `"! error: not found during expansion"` (real error with
/// "not found" mid-sentence, not the canonical shape).
///
/// Note: this helper is a transient bridge while `NbClient`
/// still wraps `nb` as a subprocess. The native rewrite
/// (`nb-api:todos/2`) will let `show_note` and friends read
/// the on-disk file directly via the P1 note-document-model,
/// removing the need to classify `nb` stderr at all. Whether
/// this helper is deleted is a separate change when the
/// native rewrite lands; the deletion is NOT automatic.
pub
/// Returns `true` if `stderr` from `nb notebooks show <name>
/// --path` matches the exact `nb 7.24.0` notebook-absence
/// diagnostic shape for the given expected notebook name. The
/// complete normalized diagnostic must equal
/// `! Notebook not found: <expected>`. See
/// [`is_selector_not_found`] for normalization details and
/// verified failure-mode negatives.
pub
/// Verify the normalized diagnostic for `nb show` / `nb
/// notebooks show` ABSENCE shapes. Returns `true` only when
/// the printable form, with the pinned normalization sequence
/// applied, equals the literal template `<keyword><expected>`.
///
/// Normalization sequence (pinned; do not reorder):
/// 1. Reduce to printable form via [`printable_form`] (drops
/// ANSI escapes and singleton control bytes except
/// newline / carriage-return / tab).
/// 2. Trim trailing `\n` / `\r` bytes (`trim_end_matches`).
/// 3. Strip exactly one leading `!` diagnostic-bang
/// (`strip_prefix('!')`).
/// 4. Strip leading ASCII whitespace (`trim_start`).
/// 5. Compare byte-exact against the literal template
/// `<keyword><expected>`.
///
/// Pathological stderr (multiline, trailing garbage, foreign
/// diagnostic styles) is rejected because the criterion is
/// byte-exact post-normalization. This prevents appended
/// failures (e.g., a retry that succeeds after a missing-
/// selector error) from being absorbed as a "not found" when
/// they were actually transient.
pub
/// Reduce `stderr` to its printable-canonical form by
/// dropping ANSI escape sequences and singleton control
/// characters while preserving spaces, tabs, and newlines.
///
/// `nb 7.24.0` decorates its error diagnostics with mixed
/// ANSI/control bytes between the diagnostic-bang and the
/// visible text (e.g., `!<ANSI reset><SI> Not found: ...`).
/// Without this normalization, the byte-exact classifiers
/// above cannot reach the visible prefix. The function is
/// intentionally narrow: it only normalizes the bytes that
/// `nb 7.24.0` is known to emit; non-printable bytes inside
/// an unrelated error's message will be dropped, which is
/// acceptable because the classifiers compare against the
/// pinned literal template and would not match a different
/// message anyway.
pub