Skip to content

Commit 006b65f

Browse files
committed
AI review changes
1 parent d6b1ece commit 006b65f

4 files changed

Lines changed: 38 additions & 11 deletions

File tree

cpp-linter/src/cli/structs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl ClangParams {
229229
pub(crate) const CACHE_DIR: &str = ".cpp-linter-cache";
230230

231231
/// The file name for aggregating auto-fixes into a unified patch.
232-
pub(crate) const AUTO_FIX_PATCH: &str = "auto_fix.patch";
232+
pub(crate) const AUTO_FIX_PATCH: &str = "auto-fix.patch";
233233

234234
pub(crate) fn get_cache_path(&self) -> PathBuf {
235235
self.repo_root.join(Self::CACHE_DIR).join("patched")

cpp-linter/src/rest_client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ impl RestClient {
238238
file.maybe_append_patch(&feedback_inputs.repo_root)?;
239239
}
240240
}
241-
let auto_fix_patch_patch = feedback_inputs
241+
let auto_fix_patch_path = feedback_inputs
242242
.repo_root
243243
.join(ClangParams::CACHE_DIR)
244244
.join(ClangParams::AUTO_FIX_PATCH);
245-
if auto_fix_patch_patch.exists() {
245+
if auto_fix_patch_path.exists() {
246246
self.client.write_output_variables(&[OutputVariable {
247247
name: "fix-patch-path".to_string(),
248-
value: auto_fix_patch_patch.to_string_lossy().replace("\\", "/"),
248+
value: auto_fix_patch_path.to_string_lossy().replace("\\", "/"),
249249
}])?;
250250
}
251251
Ok(format_checks_failed + tidy_checks_failed)

cpp-linter/src/run.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ pub async fn run_main(args: Vec<String>) -> Result<()> {
157157
let cache_dir = clang_params.repo_root.join(ClangParams::CACHE_DIR);
158158
std::fs::create_dir_all(&cache_dir)
159159
.with_context(|| "Failed to create a local cache directory.")?;
160+
// delete old patch file
161+
let patch_file = cache_dir.join(ClangParams::AUTO_FIX_PATCH);
162+
if patch_file.exists() {
163+
std::fs::remove_file(&patch_file)
164+
.with_context(|| "Failed to remove old patch file from previous runs.")?;
165+
}
160166
// add gitignore file in project cache dir
161167
std::fs::write(
162168
cache_dir.join(".gitignore"),
@@ -193,7 +199,7 @@ pub(crate) mod test {
193199
#![allow(clippy::unwrap_used)]
194200

195201
use super::run_main;
196-
use crate::test_common::setup_tmp_workspace;
202+
use crate::{cli::ClangParams, test_common::setup_tmp_workspace};
197203
use std::env;
198204

199205
/// helper to avoid writing to the same GITHUB_OUTPUT file in parallel-running tests.
@@ -238,6 +244,13 @@ pub(crate) mod test {
238244
async fn force_debug_output() {
239245
let tmp_gh_out = setup_tmp_gh_out_path();
240246
let tmp_workspace = setup_tmp_workspace();
247+
248+
// create a dummy patch file to ensure it is deleted (in code coverage).
249+
let cache_dir = tmp_workspace.path().join(ClangParams::CACHE_DIR);
250+
std::fs::create_dir_all(&cache_dir).unwrap();
251+
let patch_path = cache_dir.join(ClangParams::AUTO_FIX_PATCH);
252+
std::fs::write(&patch_path, "").unwrap();
253+
241254
run_main(vec![
242255
"cpp-linter".to_string(),
243256
"-l".to_string(),

cpp-linter/tests/comments.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use cpp_linter::cli::ThreadComments;
44
use cpp_linter::run::run_main;
55
use git_bot_feedback::LinesChangedOnly;
66
use mockito::Matcher;
7-
use std::{env, fmt::Display, io::Write, path::Path};
7+
use std::{env, fmt::Display, fs, io::Write, path::Path};
88
use tempfile::{NamedTempFile, TempDir};
99

1010
mod common;
@@ -274,11 +274,25 @@ async fn setup(lib_root: &Path, tmp_dir: &TempDir, test_params: &TestParams) {
274274
for mock in mocks {
275275
mock.assert();
276276
}
277-
let patch_path = tmp_dir
278-
.path()
279-
.join(".cpp-linter-cache")
280-
.join("auto_fix.patch");
281-
if patch_path.exists() {
277+
278+
// Read the GITHUB_OUTPUT file to check for the patch path
279+
let output_vars = fs::read_to_string(tmp_out_file.path()).unwrap();
280+
let patch_path_from_output = output_vars
281+
.lines()
282+
.find(|line| line.starts_with("fix-patch-path="))
283+
.map(|line| {
284+
line.trim_start_matches("fix-patch-path=")
285+
.trim()
286+
.to_string()
287+
});
288+
if let Some(patch_path_from_output) = patch_path_from_output {
289+
// verify patch path exists and print its content
290+
println!("Patch path from GITHUB_OUTPUT: {patch_path_from_output}");
291+
let patch_path = Path::new(&patch_path_from_output);
292+
assert!(
293+
patch_path.exists(),
294+
"Patch file does not exist at expected path."
295+
);
282296
let patch_content =
283297
std::fs::read_to_string(patch_path).expect("Failed to read generated patch file.");
284298
println!("Generated patch content:\n{patch_content}");

0 commit comments

Comments
 (0)