Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
81ef3ab
[TRUNK-14658] Add relative test file support
cmillar-trunk Jun 2, 2025
5b377e4
Lint errors
cmillar-trunk Jun 3, 2025
7fde9e7
Merge branch 'main' into christian/trunk-14658-investigate-better-sup…
cmillar-trunk Jun 3, 2025
9487cfb
Fix failing tests
cmillar-trunk Jun 4, 2025
54ccca6
Relativise paths
cmillar-trunk Jun 5, 2025
729b3e9
Test that uploaded file has the relative-to-root file listing
cmillar-trunk Jun 5, 2025
2cdff70
Merge branch 'main' into christian/trunk-14658-investigate-better-sup…
cmillar-trunk Jun 6, 2025
d93a9d3
lint errors
cmillar-trunk Jun 6, 2025
b1f26fb
Revert "Relativise paths"
cmillar-trunk Jun 6, 2025
44a2f0f
Merge branch 'main' into christian/trunk-14658-investigate-better-sup…
cmillar-trunk Jun 9, 2025
c6f7617
Test failure from merge
cmillar-trunk Jun 9, 2025
0f75674
Printlns for the mac build
cmillar-trunk Jun 9, 2025
dfc3a94
Merge branch 'main' into christian/trunk-14658-investigate-better-sup…
cmillar-trunk Jun 9, 2025
319212f
seems that tempfile isn't returning a totally-absolute path in test
cmillar-trunk Jun 9, 2025
9a92b82
Remove logging
cmillar-trunk Jun 9, 2025
17fea27
Merge branch 'main' into christian/trunk-14658-investigate-better-sup…
cmillar-trunk Jun 11, 2025
d86ee26
Fix for failing tests out of merge, comments
cmillar-trunk Jun 11, 2025
b447410
Merge branch 'main' into christian/trunk-14658-investigate-better-sup…
cmillar-trunk Jun 11, 2025
bae24ae
fmt
cmillar-trunk Jun 11, 2025
e1c6bbb
Merge branch 'main' into christian/trunk-14658-investigate-better-sup…
cmillar-trunk Jul 2, 2025
02b91f0
Change to storing detected files in a detected_file field and using t…
cmillar-trunk Jul 2, 2025
ddc33bd
Merge branch 'main' into christian/trunk-14658-investigate-better-sup…
cmillar-trunk Jul 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 64 additions & 4 deletions cli-tests/src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use lazy_static::lazy_static;
use predicates::prelude::*;
use pretty_assertions::assert_eq;
use prost::Message;
use tempfile::tempdir;
use tempfile::{tempdir, TempDir};
#[cfg(target_os = "macos")]
use test_utils::inputs::unpack_archive_to_dir;
use test_utils::{
Expand All @@ -39,9 +39,9 @@ use crate::utils::{
// NOTE: must be multi threaded to start a mock server
#[tokio::test(flavor = "multi_thread")]
async fn upload_bundle() {
let temp_dir = tempdir().unwrap();
let temp_dir = TempDir::with_prefix("not-hidden").unwrap();
generate_mock_git_repo(&temp_dir);
generate_mock_valid_junit_xmls(&temp_dir);
generate_mock_valid_junit_xmls(temp_dir.path());
generate_mock_codeowners(&temp_dir);

let state = MockServerBuilder::new().spawn_mock_server().await;
Expand Down Expand Up @@ -1403,7 +1403,7 @@ enum CreateBundleResponse {
}

#[tokio::test(flavor = "multi_thread")]
async fn do_not_quarantines_tests_when_quarantine_disabled_set() {
async fn do_not_quarantine_tests_when_quarantine_disabled_set() {
let temp_dir = tempdir().unwrap();
generate_mock_git_repo(&temp_dir);
generate_mock_valid_junit_xmls(&temp_dir);
Expand Down Expand Up @@ -1626,6 +1626,66 @@ async fn uses_passed_exit_code_if_unquarantined_tests_fail() {
println!("{assert}");
}

#[tokio::test(flavor = "multi_thread")]
async fn uploaded_file_contains_updated_test_files() {
let temp_dir = TempDir::with_prefix("not_hidden").unwrap();
generate_mock_git_repo(&temp_dir);

let inner_dir = temp_dir.path().join("inner_dir");
fs::create_dir(inner_dir).unwrap();

let test_location = temp_dir.path().join("inner_dir").join("test_file.ts");
let mut test_file = fs::File::create(test_location).unwrap();
write!(test_file, r#"it("does stuff", x)"#).unwrap();

let junit_location = temp_dir.path().join("junit_file.xml");
let mut junit_file = fs::File::create(junit_location).unwrap();
write!(junit_file, r#"
<?xml version="1.0" encoding="UTF-8" ?>
<testsuites name="vitest tests" tests="1" failures="0" errors="0" time="1.128069555">
<testsuite name="test_file.ts" timestamp="2025-05-27T15:31:07.510Z" hostname="christian-cloudtop" tests="10" failures="0" errors="0" skipped="0" time="0.007118101">
<testcase classname="test_file.ts" name="Product Parsers &gt; Server-side parsers &gt; has parsers for all products" time="0.001408508">
</testcase>
</testsuite>
</testsuites>
"#).unwrap();

let state = MockServerBuilder::new().spawn_mock_server().await;
let assert = CommandBuilder::upload(temp_dir.path(), state.host.clone())
.junit_paths("junit_file.xml")
.command()
.assert()
.success();

let requests = state.requests.lock().unwrap().clone();
assert_eq!(requests.len(), 3);

let file_upload = assert_matches!(requests.get(1).unwrap(), RequestPayload::S3Upload(d) => d);
let file = fs::File::open(file_upload.join("meta.json")).unwrap();
let reader = BufReader::new(file);
let bundle_meta: BundleMeta = serde_json::from_reader(reader).unwrap();
let internal_bundled_file = bundle_meta.internal_bundled_file.as_ref().unwrap();
let bin = fs::read(file_upload.join(&internal_bundled_file.path)).unwrap();
let report = proto::test_context::test_run::TestResult::decode(&*bin).unwrap();

assert_eq!(report.test_case_runs.len(), 1);
let test_case_run = &report.test_case_runs.first().unwrap();
assert_eq!(test_case_run.classname, "test_file.ts");
let expected_file = temp_dir
.path()
.canonicalize()
.unwrap()
.join("inner_dir")
.join("test_file.ts")
.to_str()
.unwrap()
.to_string();
assert_eq!(test_case_run.file, String::from("test_file.ts"));
assert_eq!(test_case_run.detected_file, expected_file);

println!("{assert}");
}

#[tokio::test(flavor = "multi_thread")]
async fn does_not_print_exit_code_with_validation_reports_none() {
let temp_dir = tempdir().unwrap();
Expand Down
25 changes: 15 additions & 10 deletions cli-tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,18 @@ fn generate_mock_valid_junit_mocker() -> JunitMock {
JunitMock::new(junit_mock::Options::default())
}

pub fn generate_mock_valid_junit_xmls<T: AsRef<Path>>(directory: T) -> Vec<PathBuf> {
pub fn generate_mock_valid_junit_xmls<T: AsRef<Path> + Clone>(directory: T) -> Vec<PathBuf> {
let mut jm = generate_mock_valid_junit_mocker();
let reports = jm.generate_reports();
let tmp_dir = Some(directory.clone());
let reports = jm.generate_reports(&tmp_dir);
jm.write_reports_to_file(directory.as_ref(), reports)
.unwrap()
}

pub fn generate_mock_bazel_bep<T: AsRef<Path>>(directory: T) -> PathBuf {
pub fn generate_mock_bazel_bep<T: AsRef<Path> + Clone>(directory: T) -> PathBuf {
let mut jm = generate_mock_valid_junit_mocker();
let reports = jm.generate_reports();
let tmp_dir = Some(directory.clone());
let reports = jm.generate_reports(&tmp_dir);
let mock_junits = jm
.write_reports_to_file(directory.as_ref(), &reports)
.unwrap();
Expand Down Expand Up @@ -128,33 +130,36 @@ pub fn generate_mock_bazel_bep<T: AsRef<Path>>(directory: T) -> PathBuf {
file_path
}

pub fn generate_mock_invalid_junit_xmls<T: AsRef<Path>>(directory: T) {
pub fn generate_mock_invalid_junit_xmls<T: AsRef<Path> + Clone>(directory: T) {
let mut jm_options = junit_mock::Options::default();
jm_options.test_suite.test_suite_names = Some(vec!["".to_string()]);
jm_options.global.timestamp = Utc::now()
.fixed_offset()
.checked_sub_signed(TimeDelta::minutes(1));
let mut jm = JunitMock::new(jm_options);
let reports = jm.generate_reports();
let tmp_dir = Some(directory.clone());
let reports = jm.generate_reports(&tmp_dir);
jm.write_reports_to_file(directory.as_ref(), reports)
.unwrap();
}

pub fn generate_mock_suboptimal_junit_xmls<T: AsRef<Path>>(directory: T) {
pub fn generate_mock_suboptimal_junit_xmls<T: AsRef<Path> + Clone>(directory: T) {
let mut jm_options = junit_mock::Options::default();
jm_options.global.timestamp = Utc::now()
.fixed_offset()
.checked_sub_signed(TimeDelta::hours(24));
let mut jm = JunitMock::new(jm_options);
let reports = jm.generate_reports();
let tmp_dir = Some(directory.clone());
let reports = jm.generate_reports(&tmp_dir);
jm.write_reports_to_file(directory.as_ref(), reports)
.unwrap();
}

pub fn generate_mock_missing_filepath_suboptimal_junit_xmls<T: AsRef<Path>>(directory: T) {
pub fn generate_mock_missing_filepath_suboptimal_junit_xmls<T: AsRef<Path> + Clone>(directory: T) {
let jm_options = junit_mock::Options::default();
let mut jm = JunitMock::new(jm_options);
let mut reports = jm.generate_reports();
let tmp_dir = Some(directory.clone());
let mut reports = jm.generate_reports(&tmp_dir);
for report in reports.iter_mut() {
for testsuite in report.test_suites.iter_mut() {
for test_case in testsuite.test_cases.iter_mut() {
Expand Down
7 changes: 4 additions & 3 deletions cli-tests/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use superconsole::{
style::{style, Color, Stylize},
Line, Span,
};
use tempfile::tempdir;
use tempfile::{tempdir, TempDir};

use crate::{
command_builder::CommandBuilder,
utils::{
generate_mock_codeowners, generate_mock_invalid_junit_xmls,
generate_mock_codeowners, generate_mock_git_repo, generate_mock_invalid_junit_xmls,
generate_mock_missing_filepath_suboptimal_junit_xmls, generate_mock_suboptimal_junit_xmls,
generate_mock_valid_junit_xmls, write_junit_xml_to_dir,
},
Expand Down Expand Up @@ -170,7 +170,7 @@ fn validate_invalid_xml() {

#[test]
fn validate_suboptimal_junits() {
let temp_dir = tempdir().unwrap();
let temp_dir = TempDir::with_prefix("not-hidden").unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here, intentional?

generate_mock_suboptimal_junit_xmls(&temp_dir);

let assert = CommandBuilder::validate(temp_dir.path())
Expand All @@ -196,6 +196,7 @@ fn validate_suboptimal_junits() {
#[test]
fn validate_missing_filepath_suboptimal_junits() {
let temp_dir = tempdir().unwrap();
generate_mock_git_repo(&temp_dir);
generate_mock_missing_filepath_suboptimal_junit_xmls(&temp_dir);
generate_mock_codeowners(&temp_dir);

Expand Down
4 changes: 3 additions & 1 deletion cli/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ pub fn generate_internal_file(
file_sets: &[FileSet],
temp_dir: &TempDir,
codeowners: Option<&CodeOwners>,
repo: &BundleRepo,
show_warnings: bool,
variant: Option<String>,
) -> anyhow::Result<(
Expand Down Expand Up @@ -254,10 +255,11 @@ pub fn generate_internal_file(
Ok(validate(
&reports[0],
file_set.test_runner_report.map(|t| t.into()),
repo,
)),
);
}
test_case_runs.extend(junit_parser.into_test_case_runs(codeowners));
test_case_runs.extend(junit_parser.into_test_case_runs(codeowners, repo));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions cli/src/upload_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ pub async fn run_upload(
&meta.base_props.file_sets,
&temp_dir,
meta.base_props.codeowners.as_ref(),
&meta.base_props.repo,
// hide warnings on parsed xcresult output
#[cfg(target_os = "macos")]
upload_args.xcresult_path.is_none(),
Expand Down
8 changes: 7 additions & 1 deletion cli/src/validate_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use context::{
JunitValidationLevel,
},
},
repo::BundleRepo,
};
use display::end_output::EndOutput;
use pluralizer::pluralize;
Expand Down Expand Up @@ -537,14 +538,19 @@ async fn validate(
(parsed_reports, parse_issues)
},
);
let repo = BundleRepo::new(None, None, None, None, None, None, false).unwrap_or_default();
let file_parse_issues = gen_parse_issues(parse_issues);

let report_validations: JunitFileToValidation = parsed_reports
.into_iter()
.map(|(file, (report, test_runner_report))| {
(
file,
validate_report(&report, test_runner_report.map(TestRunnerReport::from)),
validate_report(
&report,
test_runner_report.map(TestRunnerReport::from),
&repo,
),
)
})
.collect();
Expand Down
1 change: 1 addition & 0 deletions context-js/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ pub fn junit_validate(
junit::bindings::BindingsJunitReportValidation::from(junit::validator::validate(
&report.clone().into(),
test_runner_report.map(junit::junit_path::TestRunnerReport::from),
&repo::BundleRepo::default(),
))
}

Expand Down
1 change: 1 addition & 0 deletions context-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ fn junit_validate(
junit::bindings::BindingsJunitReportValidation::from(junit::validator::validate(
&report.into(),
test_runner_report.map(TestRunnerReport::from),
&repo::BundleRepo::default(),
))
}

Expand Down
1 change: 1 addition & 0 deletions context/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ prost-wkt-types = { version = "0.5.1", features = ["vendored-protox"] }
tracing = "0.1.41"
prost = "0.12.6"
codeowners = { version = "0.1.3", path = "../codeowners" }
walkdir = "2.5.0"

[target.'cfg(target_os = "linux")'.dependencies]
pyo3 = { version = "0.22.5", optional = true, features = [
Expand Down
22 changes: 17 additions & 5 deletions context/src/junit/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ impl From<TestCaseRun> for BindingsTestCase {
attempt_number,
is_quarantined,
codeowners,
detected_file: _detected_file,
}: TestCaseRun,
) -> Self {
let started_at = started_at.unwrap_or_default();
Expand Down Expand Up @@ -1067,8 +1068,11 @@ mod tests {
#[test]
fn parse_test_report_to_bindings() {
use prost_wkt_types::Timestamp;
use tempfile::TempDir;

use crate::junit::validator::validate;
use crate::{junit::validator::validate, repo::BundleRepo};

let temp_dir = TempDir::with_prefix("not-hidden").unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

let test_started_at = Timestamp {
seconds: 1000,
nanos: 0,
Expand All @@ -1080,11 +1084,13 @@ mod tests {
let codeowner1 = CodeOwner {
name: "@user".into(),
};
let test_file = temp_dir.path().join("test_file");
let file_str = String::from(test_file.as_os_str().to_str().unwrap());
let test1 = TestCaseRun {
id: "test_id1".into(),
name: "test_name".into(),
classname: "test_classname".into(),
file: "test_file".into(),
file: file_str.clone(),
parent_name: "test_parent_name1".into(),
line: 1,
status: TestCaseRunStatus::Success.into(),
Expand All @@ -1100,7 +1106,7 @@ mod tests {
id: "test_id2".into(),
name: "test_name".into(),
classname: "test_classname".into(),
file: "test_file".into(),
file: file_str,
parent_name: "test_parent_name2".into(),
line: 1,
status: TestCaseRunStatus::Failure.into(),
Expand Down Expand Up @@ -1188,7 +1194,11 @@ mod tests {
assert_eq!(test_case2.codeowners.clone().unwrap().len(), 0);

// verify that the test report is valid
let results = validate(&converted_bindings.clone().into(), None);
let results = validate(
&converted_bindings.clone().into(),
None,
&BundleRepo::default(),
);
assert_eq!(results.all_issues_flat().len(), 1);
results
.all_issues_flat()
Expand Down Expand Up @@ -1224,6 +1234,8 @@ mod tests {
#[cfg(feature = "bindings")]
#[test]
fn test_junit_conversion_paths() {
use crate::repo::BundleRepo;

let mut junit_parser = JunitParser::new();
let file_contents = r#"
<xml version="1.0" encoding="UTF-8"?>
Expand All @@ -1242,7 +1254,7 @@ mod tests {
assert!(parsed_results.is_ok());

// Get test case runs from parser
let test_case_runs = junit_parser.into_test_case_runs(None);
let test_case_runs = junit_parser.into_test_case_runs(None, &BundleRepo::default());
assert_eq!(test_case_runs.len(), 2);

// Convert test case runs to bindings
Expand Down
Loading