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
//! What:
//! The log entries of the standards-review shadow run, rendered as the root `mise.toml` task `shadow-review` writes
//! them, and their append to the log file.
//! Why:
//! `doc/audit/standards-review-gate-shadow.md` already holds that task's entries, and readers and scorers parse them,
//! so the port writes the same lines. The script appends line by line; this port appends each entry in one write, so
//! entries of two concurrent runs cannot interleave.
//!
//! In TS you'd write (pseudocode):
//! ```ts
//! entry('- Date:'); entry(` ${new Date().toISOString()}`); // ...
//! ```
use super::standards_review_request::ROUTE;
use super::standards_review_input::CAP_LINES;
use super::standards_review_text::on_one_line;
use std::io::Write;
use std::path::Path;
/// Leading characters of the commit name the log prints.
pub const SHORT_SHA_LENGTH: usize = 12;
/// What:
/// Everything one review entry prints.
/// Why:
/// The renderer is a pure function of these values, so a test can fix the clock and the elapsed time.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// type ReviewEntry = { date: string; sha: string; subject: string; codeFiles: number; diffLines: number; truncated: boolean; inputUnits: number; seconds: string; top: string; outcome: string };
/// ```
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ReviewEntry {
/// `toISOString` text of the moment the entry is written.
pub date: String,
/// Full commit name.
pub sha: String,
/// Subject line.
pub subject: String,
/// Code files in the commit.
pub code_files: usize,
/// Lines of the whole patch.
pub diff_lines: usize,
/// Whether the patch was over the cap.
pub truncated: bool,
/// Reported model input length in UTF-16 units.
pub input_units: usize,
/// One-decimal seconds of the gateway call.
pub seconds: String,
/// The judged choice, or empty.
pub top: String,
/// The `Findings kept` line.
pub outcome: String,
}
/// What:
/// The first `SHORT_SHA_LENGTH` characters of a commit name.
/// Why:
/// The log names commits by that prefix.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// sha.slice(0, 12)
/// ```
fn short(sha: &str) -> String {
return sha.chars().take(SHORT_SHA_LENGTH).collect();
}
/// What:
/// The three-line entry for a commit with no code files.
/// Why:
/// Coverage stays visible: every skipped landing leaves a line.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// entry('- Skipped:'); entry(` ${sha.slice(0, 12)} (no code files):`); entry(` \`${subject}\``);
/// ```
pub fn render_skipped(sha: &str, subject: &str) -> String {
return format!("- Skipped:\n {} (no code files):\n `{}`\n", short(sha), on_one_line(subject));
}
/// What:
/// The review entry, ending in the blank line that separates entries.
/// Why:
/// `Named superlinear cost` is the choice for `yes` and `no`, the two-line gesture for `partial`, and `unjudged` for
/// anything else, as the script prints it.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// entry('- Date:'); // ... entry('')
/// ```
pub fn render_review(entry: &ReviewEntry) -> String {
let capped: String = if entry.truncated { format!(", capped at {CAP_LINES}") } else { String::new() };
let judged: String = match entry.top.as_str() {
"partial" => String::from(" partial (cost gestured as unverified,\n not named)"),
"yes" | "no" => format!(" {}", entry.top),
_ => String::from(" unjudged"),
};
return format!(
"- Date:\n {date}\n Subject:\n {sha} `{subject}`\n Input size:\n `{files} code files, {lines} diff lines{capped}, luna input {units} chars`\n Reviewer route:\n `{ROUTE}`\n Wall-clock cost:\n {seconds} s\n Named superlinear cost:\n{judged}\n Findings kept:\n `````text\n {outcome}\n `````\n\n",
date = entry.date,
sha = short(entry.sha.as_str()),
subject = on_one_line(entry.subject.as_str()),
files = entry.code_files,
lines = entry.diff_lines,
units = entry.input_units,
seconds = entry.seconds,
outcome = on_one_line(entry.outcome.as_str()),
);
}
/// What:
/// Append `text` to the log file, creating it when missing, in one write.
/// Why:
/// The log is shared by every run; an append-mode file takes one write whole, where the script's per-line appends of
/// two runs could interleave.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// appendFileSync(logPath, text)
/// ```
pub fn append_entry(log_path: &Path, text: &str) -> std::io::Result<()> {
let mut file: std::fs::File = std::fs::OpenOptions::new().append(true).create(true).open(log_path)?;
return file.write_all(text.as_bytes());
}
/// Controls stay out of the release executable.
#[cfg(test)]
#[path = "standards_review_entry_tests.rs"]
mod tests;