Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ clap = { version = "4.5", features = ["derive", "env", "string"] }
homeboy-core = { version = "0.1.0", path = "crates/homeboy-core", features = ["test-support"] }
homeboy-extension = { version = "0.1.0", path = "crates/homeboy-extension" }
homeboy-engine-primitives = { version = "0.1.0", path = "crates/homeboy-engine-primitives" }
# Enables CLI argument fixtures used by root integration tests without adding a
# production default for those constructors.
homeboy-cli = { version = "0.1.0", path = "crates/homeboy-cli", features = ["test-support"] }
# Integration tests here spawn the real binary via CARGO_BIN_EXE_homeboy and
# dispatch `--backend fixture` (tests/reverse_cook_queue_acceptance.rs). That
# executor double is compiled only under `homeboy-agents/test-support`, and this
Expand Down
35 changes: 35 additions & 0 deletions crates/homeboy-cli/src/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,32 @@ pub struct LintArgs {
}

impl LintArgs {
/// Canonical test fixture with explicit command target and no internal source.
#[cfg(any(test, feature = "test-support"))]
pub fn for_test(component: impl Into<String>, path: impl AsRef<std::path::Path>) -> Self {
Self {
comp: PositionalComponentArgs {
component: Some(component.into()),
path: Some(path.as_ref().to_string_lossy().into_owned()),
},
release_readiness_source: None,
extension_override: ExtensionOverrideArgs::default(),
summary: false,
file: None,
glob: None,
changed: ChangedScopeArgs::default(),
force_main_workflow: false,
ci_job: None,
sniff_filters: LintSniffArgs::default(),
category: None,
fix: false,
force: false,
setting_args: SettingArgs::default(),
baseline_args: BaselineArgs::default(),
json_summary: false,
}
}

pub(crate) fn lab_contract(&self) -> Option<LabCommandContract> {
if self.is_full_workspace_run()
|| self.changed.is_scoped()
Expand Down Expand Up @@ -552,6 +578,15 @@ mod tests {
assert_eq!(cli.lint.ci_job.as_deref(), Some("lint-typecheck"));
}

#[test]
fn test_fixture_keeps_target_explicit_and_internal_source_absent() {
let args = LintArgs::for_test("fixture", "/tmp/fixture");

assert_eq!(args.comp.component.as_deref(), Some("fixture"));
assert_eq!(args.comp.path.as_deref(), Some("/tmp/fixture"));
assert!(args.release_readiness_source.is_none());
}

#[test]
fn self_check_dispatch_only_allows_unscoped_default_lint() {
let default = TestCli::try_parse_from(["lint", "homeboy"])
Expand Down
36 changes: 36 additions & 0 deletions crates/homeboy-cli/src/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,33 @@ pub struct TestArgs {
}

impl TestArgs {
/// Canonical test fixture with explicit command target and no internal source.
#[cfg(any(test, feature = "test-support"))]
pub fn for_test(component: impl Into<String>, path: impl AsRef<std::path::Path>) -> Self {
Self {
comp: PositionalComponentArgs {
component: Some(component.into()),
path: Some(path.as_ref().to_string_lossy().into_owned()),
},
release_readiness_source: None,
extension_override: ExtensionOverrideArgs::default(),
skip_lint: false,
coverage: false,
coverage_min: None,
baseline_args: BaselineArgs::default(),
analyze: false,
drift: false,
write: false,
since: "HEAD~10".to_string(),
changed: LabChangedScopeArgs::default(),
ci_job: None,
setting_args: SettingArgs::default(),
args: Vec::new(),
json_summary: false,
restore_checkout: false,
}
}

pub(crate) fn lab_contract(&self) -> LabCommandContract {
if self.baseline_args.baseline || self.baseline_args.ratchet {
return LabCommandContract::local_only(
Expand Down Expand Up @@ -1162,6 +1189,15 @@ mod tests {
assert_eq!(cli.test.ci_job.as_deref(), Some("unit"));
}

#[test]
fn test_fixture_keeps_target_explicit_and_internal_source_absent() {
let args = TestArgs::for_test("fixture", "/tmp/fixture");

assert_eq!(args.comp.component.as_deref(), Some("fixture"));
assert_eq!(args.comp.path.as_deref(), Some("/tmp/fixture"));
assert!(args.release_readiness_source.is_none());
}

#[test]
fn parses_settings_json_file_and_profile_alias() {
let cli = TestCli::try_parse_from([
Expand Down
30 changes: 1 addition & 29 deletions tests/core/extension/component_script_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ use std::path::{Path, PathBuf};
use std::process::Command;

use crate::commands::test::{run as run_test, TestArgs};
use crate::commands::utils::args::{
BaselineArgs, ExtensionOverrideArgs, LabChangedScopeArgs, PositionalComponentArgs, SettingArgs,
};
use homeboy_core::component::{Component, ComponentScriptsConfig, ScopedExtensionConfig};
use homeboy_core::engine::run_dir::RunDir;
use homeboy_core::test_support::with_isolated_home;
Expand All @@ -17,33 +14,8 @@ use homeboy_extension::component_script::{
};
use homeboy_extension::ExtensionCapability;

fn component_script_args(root: &Path) -> PositionalComponentArgs {
PositionalComponentArgs {
component: Some("fixture".to_string()),
path: Some(root.to_string_lossy().to_string()),
}
}

fn test_command_args(root: &Path) -> TestArgs {
TestArgs {
comp: component_script_args(root),
release_readiness_source: None,
extension_override: ExtensionOverrideArgs::default(),
skip_lint: false,
coverage: false,
coverage_min: None,
baseline_args: BaselineArgs::default(),
analyze: false,
drift: false,
write: false,
since: "HEAD~10".to_string(),
changed: LabChangedScopeArgs::default(),
ci_job: None,
setting_args: SettingArgs::default(),
args: Vec::new(),
json_summary: false,
restore_checkout: false,
}
TestArgs::for_test("fixture", root)
}

fn write_component_script(root: &Path, name: &str, body: &str) {
Expand Down
55 changes: 2 additions & 53 deletions tests/self_checks_test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
use homeboy::commands::lint::{run as run_lint, LintArgs};
use homeboy::commands::test::{run as run_test, TestArgs};
use homeboy::commands::utils::args::{
BaselineArgs, ChangedScopeArgs, ExtensionOverrideArgs, LabChangedScopeArgs, LintSniffArgs,
PositionalComponentArgs, SettingArgs,
};
use std::fs;
use std::path::Path;

Expand All @@ -27,59 +23,12 @@ fn write_script(root: &Path, name: &str, body: &str) {
fs::write(script_dir.join(name), body).expect("script should be written");
}

fn component_args(root: &Path) -> PositionalComponentArgs {
PositionalComponentArgs {
component: Some("fixture".to_string()),
path: Some(root.to_string_lossy().to_string()),
}
}

fn lint_args(root: &Path) -> LintArgs {
LintArgs {
comp: component_args(root),
release_readiness_source: None,
extension_override: ExtensionOverrideArgs::default(),
release_readiness_source: None,
summary: false,
file: None,
glob: None,
changed: ChangedScopeArgs::default(),
force_main_workflow: false,
ci_job: None,
sniff_filters: LintSniffArgs::default(),
category: None,
fix: false,
force: false,
setting_args: SettingArgs::default(),
baseline_args: BaselineArgs::default(),
release_readiness_source: None,
json_summary: false,
}
LintArgs::for_test("fixture", root)
}

fn test_args(root: &Path) -> TestArgs {
TestArgs {
comp: component_args(root),
release_readiness_source: None,
extension_override: ExtensionOverrideArgs::default(),
release_readiness_source: None,
skip_lint: false,
release_readiness_source: None,
coverage: false,
coverage_min: None,
baseline_args: BaselineArgs::default(),
analyze: false,
drift: false,
write: false,
since: "HEAD~10".to_string(),
changed: LabChangedScopeArgs::default(),
ci_job: None,
setting_args: SettingArgs::default(),
release_readiness_source: None,
args: Vec::new(),
json_summary: false,
restore_checkout: false,
}
TestArgs::for_test("fixture", root)
}

fn json_test_args(root: &Path) -> TestArgs {
Expand Down
Loading