Skip to content

Commit a0fd4e0

Browse files
committed
refactor: remove duplicate Lab portability projection
1 parent 6e224f5 commit a0fd4e0

13 files changed

Lines changed: 49 additions & 86 deletions

File tree

src/command_contract/lab.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,10 @@ pub(super) fn apply_lab_contract_to_descriptor(
10711071
}
10721072

10731073
impl LabCommandContract {
1074+
pub const fn is_portable(self) -> bool {
1075+
matches!(self.portability, LabCommandPortability::Portable)
1076+
}
1077+
10741078
pub(crate) fn into_route_contract(
10751079
self,
10761080
required_extensions: Vec<String>,

src/commands/infra/route.rs

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ fn strip_component_target_args(
10861086
mod tests {
10871087
use super::*;
10881088
use clap::Parser;
1089-
use homeboy::command_contract::lab_runner_supports_contract_label;
1089+
use homeboy::command_contract::{lab_runner_supports_contract_label, LabCommandPortability};
10901090
use std::fs;
10911091
use std::path::Path;
10921092
use std::sync::{Mutex, MutexGuard, OnceLock};
@@ -1228,8 +1228,7 @@ mod tests {
12281228
let command = lab_offload_command(&cli.command).unwrap().unwrap();
12291229

12301230
assert_eq!(command.hot_label, "review lint");
1231-
assert!(command.portable);
1232-
assert!(command.unsupported_reason.is_none());
1231+
assert!(command.is_portable());
12331232
}
12341233

12351234
#[test]
@@ -1278,8 +1277,7 @@ mod tests {
12781277
let command = lab_offload_command(&cli.command).unwrap().unwrap();
12791278

12801279
assert_eq!(command.hot_label, "review lint");
1281-
assert!(command.portable);
1282-
assert!(command.unsupported_reason.is_none());
1280+
assert!(command.is_portable());
12831281
}
12841282

12851283
#[test]
@@ -1331,8 +1329,7 @@ mod tests {
13311329

13321330
assert_eq!(cli.runner.as_deref(), Some("homeboy-lab"));
13331331
assert_eq!(command.hot_label, "review test");
1334-
assert!(command.portable);
1335-
assert!(command.unsupported_reason.is_none());
1332+
assert!(command.is_portable());
13361333
}
13371334

13381335
#[test]
@@ -1977,7 +1974,7 @@ mod tests {
19771974
let command = lab_offload_command(&cli.command).unwrap().unwrap();
19781975

19791976
assert_eq!(command.hot_label, "rig check");
1980-
assert!(command.portable);
1977+
assert!(command.is_portable());
19811978
assert!(!command.routing_policy.default_lab_offload);
19821979
assert!(!command.routing_policy.infer_source_path_tools);
19831980
assert!(cli.command.supports_lab_runner());
@@ -2018,7 +2015,7 @@ mod tests {
20182015
let command = lab_offload_command(&cli.command).unwrap().unwrap();
20192016

20202017
assert_eq!(command.hot_label, "rig check");
2021-
assert!(command.portable);
2018+
assert!(command.is_portable());
20222019
assert!(command.routing_policy.default_lab_offload);
20232020
assert!(!command.routing_policy.infer_source_path_tools);
20242021
}
@@ -2030,8 +2027,7 @@ mod tests {
20302027
let command = lab_offload_command(&cli.command).unwrap().unwrap();
20312028

20322029
assert_eq!(command.hot_label, "review lint");
2033-
assert!(command.portable);
2034-
assert!(command.unsupported_reason.is_none());
2030+
assert!(command.is_portable());
20352031
assert!(command.routing_policy.requires_extension_parity);
20362032
}
20372033

@@ -2049,9 +2045,8 @@ mod tests {
20492045
let command = lab_offload_command(&cli.command).unwrap().unwrap();
20502046

20512047
assert_eq!(command.hot_label, "extension update");
2052-
assert!(command.portable);
2048+
assert!(command.is_portable());
20532049
assert!(!command.routing_policy.default_lab_offload);
2054-
assert!(command.unsupported_reason.is_none());
20552050
assert!(!command.routing_policy.requires_extension_parity);
20562051
assert!(command.required_extensions.is_empty());
20572052
assert!(!command.routing_policy.infer_source_path_tools);
@@ -2076,9 +2071,8 @@ mod tests {
20762071
let command = lab_offload_command(&cli.command).unwrap().unwrap();
20772072

20782073
assert_eq!(command.hot_label, "extension refresh");
2079-
assert!(command.portable);
2074+
assert!(command.is_portable());
20802075
assert!(!command.routing_policy.default_lab_offload);
2081-
assert!(command.unsupported_reason.is_none());
20822076
assert!(!command.routing_policy.requires_extension_parity);
20832077
assert!(command.required_extensions.is_empty());
20842078
assert!(!command.routing_policy.infer_source_path_tools);
@@ -2117,9 +2111,8 @@ mod tests {
21172111
let command = lab_offload_command(&cli.command).unwrap().unwrap();
21182112

21192113
assert_eq!(command.hot_label, "extension show");
2120-
assert!(command.portable);
2114+
assert!(command.is_portable());
21212115
assert!(!command.routing_policy.default_lab_offload);
2122-
assert!(command.unsupported_reason.is_none());
21232116
assert!(!command.routing_policy.requires_extension_parity);
21242117
assert!(command.required_extensions.is_empty());
21252118
assert!(!command.routing_policy.infer_source_path_tools);
@@ -2150,7 +2143,7 @@ mod tests {
21502143
assert!(local_policy.deny_local_execution());
21512144
assert_eq!(command.hot_label, "fuzz doctor");
21522145
assert!(lab_runner_supports_contract_label(command.hot_label));
2153-
assert!(command.portable);
2146+
assert!(command.is_portable());
21542147
assert!(!command.routing_policy.default_lab_offload);
21552148
assert!(command.routing_policy.requires_extension_parity);
21562149
assert!(command.routing_policy.read_only_polling);
@@ -2372,7 +2365,7 @@ mod tests {
23722365

23732366
assert_eq!(cli.runner.as_deref(), Some("homeboy-lab"));
23742367
assert!(lab_runner_supports_contract_label(command.hot_label));
2375-
assert!(command.portable);
2368+
assert!(command.is_portable());
23762369
assert!(command.routing_policy.default_lab_offload);
23772370
}
23782371
}
@@ -2391,7 +2384,7 @@ mod tests {
23912384
"cargo test --locked",
23922385
]);
23932386
let automatic_command = lab_offload_command(&automatic.command).unwrap().unwrap();
2394-
assert!(automatic_command.portable);
2387+
assert!(automatic_command.is_portable());
23952388
assert!(automatic_command.routing_policy.default_lab_offload);
23962389

23972390
let explicit = Cli::parse_from([
@@ -2409,7 +2402,7 @@ mod tests {
24092402
]);
24102403
let explicit_command = lab_offload_command(&explicit.command).unwrap().unwrap();
24112404
assert_eq!(explicit.runner.as_deref(), Some("homeboy-lab"));
2412-
assert!(explicit_command.portable);
2405+
assert!(explicit_command.is_portable());
24132406

24142407
let lab_only = Cli::parse_from([
24152408
"homeboy",
@@ -2428,12 +2421,10 @@ mod tests {
24282421
lab_only.allow_local_fallback,
24292422
lab_only.lab_only,
24302423
);
2431-
assert!(
2432-
lab_offload_command(&lab_only.command)
2433-
.unwrap()
2434-
.unwrap()
2435-
.portable
2436-
);
2424+
assert!(lab_offload_command(&lab_only.command)
2425+
.unwrap()
2426+
.unwrap()
2427+
.is_portable());
24372428
assert!(local_policy.deny_local_execution());
24382429
}
24392430

@@ -2451,7 +2442,7 @@ mod tests {
24512442

24522443
assert_eq!(cli.runner.as_deref(), Some("homeboy-lab"));
24532444
assert!(lab_runner_supports_contract_label(command.hot_label));
2454-
assert!(command.portable);
2445+
assert!(command.is_portable());
24552446
assert!(!command.routing_policy.default_lab_offload);
24562447
assert!(!command.routing_policy.requires_extension_parity);
24572448
assert!(command.required_extensions.is_empty());
@@ -2486,7 +2477,7 @@ mod tests {
24862477
command.hot_label,
24872478
"agent-task controller from-spec --resume/run-from-spec/materialize"
24882479
);
2489-
assert!(command.portable);
2480+
assert!(command.is_portable());
24902481
assert!(command.routing_policy.default_lab_offload);
24912482
assert!(!command.routing_policy.requires_extension_parity);
24922483
assert_eq!(
@@ -2536,7 +2527,7 @@ mod tests {
25362527
command.hot_label,
25372528
"agent-task controller from-spec --resume/run-from-spec/materialize"
25382529
);
2539-
assert!(command.portable);
2530+
assert!(command.is_portable());
25402531
assert!(command.routing_policy.default_lab_offload);
25412532
assert!(command.routing_policy.infer_source_path_tools);
25422533
assert!(!command.routing_policy.requires_extension_parity);
@@ -2604,7 +2595,7 @@ mod tests {
26042595
assert_eq!(cli.runner.as_deref(), Some("homeboy-lab"));
26052596
assert!(local_policy.deny_local_execution());
26062597
assert_eq!(command.hot_label, "agent-task fanout run-plan");
2607-
assert!(command.portable);
2598+
assert!(command.is_portable());
26082599
assert!(command.routing_policy.default_lab_offload);
26092600
assert!(command.routing_policy.requires_extension_parity);
26102601
}
@@ -2638,7 +2629,7 @@ mod tests {
26382629
assert_eq!(cli.runner.as_deref(), Some("homeboy-lab"));
26392630
assert!(local_policy.deny_local_execution());
26402631
assert_eq!(command.hot_label, "agent-task fanout cook-batch");
2641-
assert!(command.portable);
2632+
assert!(command.is_portable());
26422633
assert!(command.routing_policy.default_lab_offload);
26432634
assert!(command.routing_policy.requires_extension_parity);
26442635
}
@@ -2671,7 +2662,7 @@ mod tests {
26712662

26722663
assert_eq!(cli.runner.as_deref(), Some("homeboy-lab"));
26732664
assert_eq!(command.hot_label, "agent-task fanout status/artifacts");
2674-
assert!(command.portable);
2665+
assert!(command.is_portable());
26752666
assert!(!command.routing_policy.default_lab_offload);
26762667
assert_eq!(
26772668
command.source_path_mode,
@@ -2707,7 +2698,7 @@ mod tests {
27072698

27082699
assert_eq!(cli.runner.as_deref(), Some("homeboy-lab"));
27092700
assert_eq!(command.hot_label, "tunnel service start");
2710-
assert!(command.portable);
2701+
assert!(command.is_portable());
27112702
assert!(!command.routing_policy.default_lab_offload);
27122703
assert_eq!(
27132704
command.source_path_mode,
@@ -2740,7 +2731,7 @@ mod tests {
27402731
let command = lab_offload_command(&cli.command).unwrap().unwrap();
27412732

27422733
assert_eq!(command.hot_label, "tunnel preview-consumer run");
2743-
assert!(command.portable);
2734+
assert!(command.is_portable());
27442735
assert!(!command.routing_policy.default_lab_offload);
27452736
}
27462737

@@ -2751,8 +2742,7 @@ mod tests {
27512742
let command = lab_offload_command(&cli.command).unwrap().unwrap();
27522743

27532744
assert_eq!(command.hot_label, "review audit");
2754-
assert!(command.portable);
2755-
assert_eq!(command.unsupported_reason, None);
2745+
assert!(command.is_portable());
27562746
assert!(command.routing_policy.requires_extension_parity);
27572747
}
27582748

@@ -2763,8 +2753,7 @@ mod tests {
27632753
let command = lab_offload_command(&cli.command).unwrap().unwrap();
27642754

27652755
assert_eq!(command.hot_label, "review audit");
2766-
assert!(command.portable);
2767-
assert_eq!(command.unsupported_reason, None);
2756+
assert!(command.is_portable());
27682757
assert!(command.routing_policy.requires_extension_parity);
27692758
}
27702759

@@ -2775,8 +2764,10 @@ mod tests {
27752764
let command = lab_offload_command(&cli.command).unwrap().unwrap();
27762765

27772766
assert_eq!(command.hot_label, "rig up");
2778-
assert!(!command.portable);
2779-
assert!(command.unsupported_reason.is_some());
2767+
assert!(matches!(
2768+
command.portability,
2769+
LabCommandPortability::LocalOnly(_)
2770+
));
27802771
assert!(!command.routing_policy.requires_extension_parity);
27812772
}
27822773

src/core/api_jobs/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,6 @@ mod tests {
820820
false,
821821
&[],
822822
),
823-
portable: true,
824-
unsupported_reason: None,
825823
required_extensions: Vec::new(),
826824
required_capabilities: Vec::new(),
827825
workload: None,

src/core/lab_routing.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,14 +447,8 @@ pub fn lab_route_plan_from_contract(contract: LabCommandContract) -> LabRoutePla
447447
pub fn lab_offload_command_from_route_contract(
448448
route_contract: LabCommandRouteContract,
449449
) -> runners::LabOffloadCommand {
450-
let portability = route_contract.command.portability;
451450
runners::LabOffloadCommand {
452451
command: route_contract.command,
453-
portable: matches!(portability, LabCommandPortability::Portable),
454-
unsupported_reason: match portability {
455-
LabCommandPortability::Portable => None,
456-
LabCommandPortability::LocalOnly(reason) => Some(reason),
457-
},
458452
required_extensions: route_contract.required_extensions,
459453
required_capabilities: route_contract.required_capabilities,
460454
workload: route_contract.workload,
@@ -643,9 +637,8 @@ mod tests {
643637

644638
assert_eq!(command.command, lab_contract());
645639
assert_eq!(command.hot_label, "trace");
646-
assert!(command.portable);
640+
assert!(command.is_portable());
647641
assert!(command.routing_policy.default_lab_offload);
648-
assert_eq!(command.unsupported_reason, None);
649642
assert_eq!(
650643
command.workspace_mode_policy,
651644
runners::LabOffloadWorkspaceModePolicy::GitCheckoutRequired

src/core/runner/execution/tests/exec.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,6 @@ fn worker_local_workload_validation_uses_implicit_command_secret_names() {
474474
false,
475475
&[],
476476
),
477-
portable: true,
478-
unsupported_reason: None,
479477
required_extensions: Vec::new(),
480478
required_capabilities: Vec::new(),
481479
workload: None,

src/core/runner/lab/offload/execute.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,14 @@ pub fn execute_lab_offload(request: LabOffloadRequest<'_>) -> Result<LabOffloadO
6363
});
6464
};
6565

66-
if !contract.portable {
66+
if let crate::command_contract::LabCommandPortability::LocalOnly(reason) = contract.portability
67+
{
6768
if let Some(runner_id) = request.explicit_runner {
68-
let message = contract.unsupported_reason.map_or_else(
69-
|| lab_runner_support_summary().unsupported_message,
70-
|reason| format!("--runner is unavailable for this local-only resource-pressure command. {reason}"),
69+
let message = format!(
70+
"--runner is unavailable for this local-only resource-pressure command. {reason}"
7171
);
7272
return Err(unsupported_runner_error(runner_id, message));
7373
}
74-
let reason = contract
75-
.unsupported_reason
76-
.unwrap_or("command is local-only");
7774
if request.local_policy.deny_local_execution() {
7875
return Err(local_execution_denied_error(reason, None));
7976
}

src/core/runner/lab/offload/tests/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ mod workspace_sync;
2929
pub(super) fn portable_lab_command(label: &'static str) -> LabOffloadCommand {
3030
LabOffloadCommand {
3131
command: crate::command_contract::LabCommandContract::portable(label, None, true, &[]),
32-
portable: true,
33-
unsupported_reason: None,
3432
required_extensions: Vec::new(),
3533
required_capabilities: Vec::new(),
3634
workload: None,
@@ -40,8 +38,6 @@ pub(super) fn portable_lab_command(label: &'static str) -> LabOffloadCommand {
4038
pub(super) fn local_only_lab_command(reason: &'static str) -> LabOffloadCommand {
4139
LabOffloadCommand {
4240
command: crate::command_contract::LabCommandContract::local_only("rig up", reason),
43-
portable: false,
44-
unsupported_reason: Some(reason),
4541
required_extensions: Vec::new(),
4642
required_capabilities: Vec::new(),
4743
workload: None,

src/core/runner/lab/offload/types.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ pub struct LabJobOverrides {
7070
#[derive(Debug, Clone, PartialEq, Eq)]
7171
pub struct LabOffloadCommand {
7272
pub command: crate::command_contract::LabCommandContract,
73-
pub portable: bool,
74-
pub unsupported_reason: Option<&'static str>,
7573
pub required_extensions: Vec<String>,
7674
pub required_capabilities: Vec<crate::command_contract::RunnerWorkloadCapability>,
7775
pub workload: Option<crate::command_contract::LabRigWorkloadArguments>,

src/core/runner/lab/offload/workspace_stage.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,8 +1883,6 @@ mod tests {
18831883
&[],
18841884
)
18851885
},
1886-
portable: true,
1887-
unsupported_reason: None,
18881886
required_extensions: Vec::new(),
18891887
required_capabilities: Vec::new(),
18901888
workload: None,
@@ -1972,8 +1970,6 @@ mod tests {
19721970
&[],
19731971
)
19741972
},
1975-
portable: true,
1976-
unsupported_reason: None,
19771973
required_extensions: Vec::new(),
19781974
required_capabilities: Vec::new(),
19791975
workload: None,

src/core/runner/lab_capabilities.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(super) fn lab_runner_capability_contract(
77
source_path: &Path,
88
command_prefix_required_tools: &[RunnerRequiredTool],
99
) -> Option<LabRunnerCapabilityContract> {
10-
if !command.portable {
10+
if !command.is_portable() {
1111
return None;
1212
}
1313

0 commit comments

Comments
 (0)