artifactize_core/
verify_tools.rs1mod catalog;
3mod error;
4mod input;
5mod page;
6mod read;
7mod tool;
8
9pub use catalog::{Hints, Tool, tools};
10pub use error::{ArgumentsError, Error};
11pub use input::Call;
12pub use page::{CursorError, Page};
13
14use serde::Serialize;
15use tokio_util::sync::CancellationToken;
16
17use crate::{project::VerifyOptions, runs};
18use input::{Command, Plugin, Verify};
19
20#[derive(Serialize)]
21#[serde(untagged)]
22pub enum Output {
23 Observation(runs::RunObservation),
24 Cancellation(runs::CancelAcknowledgement),
25 Inspection(Page),
26 Plugin(PluginResult),
27}
28
29#[derive(Serialize)]
30#[serde(tag = "action", rename_all = "lowercase")]
31pub enum PluginResult {
32 Added(crate::config::plugins::PluginInfo),
33 Removed {
34 #[serde(rename = "namespace")]
35 name: crate::config::PluginName,
36 },
37}
38
39impl Call {
40 pub async fn execute(
42 self,
43 context: &runs::Context,
44 cancel: CancellationToken,
45 ) -> Result<Output, Error> {
46 let command = match self.command {
47 Command::Verify(command) => command,
48 Command::Plugin(plugin) => {
49 use crate::config::plugins;
50 let result = match plugin {
51 Plugin::Add(args) => PluginResult::Added(
52 plugins::add(context.repo(), &args.path).map_err(Error::Config)?,
53 ),
54 Plugin::Remove(args) => {
55 plugins::remove(context.repo(), &args.name).map_err(Error::Config)?;
56 PluginResult::Removed { name: args.name }
57 }
58 };
59 return Ok(Output::Plugin(result));
60 }
61 Command::Inspect(inspection) => {
62 return Ok(Output::Inspection(
63 read::inspect(context, inspection, cancel).await?,
64 ));
65 }
66 };
67 Ok(match command {
68 Verify::Start(args) => {
69 let options = VerifyOptions {
70 jobs: args.jobs.map(|limit| limit.get() as usize),
71 modes: runs::RunModes {
72 speculate: args.speculate,
73 },
74 comment: args.comment.clone(),
75 ..Default::default()
76 };
77 let fingerprint = args.request_key.as_ref().map(|_| args.fingerprint());
78 Output::Observation(
79 runs::start_with_args_hash(
80 context,
81 args.scope.selection(),
82 &options,
83 args.request_key,
84 fingerprint,
85 )
86 .await?,
87 )
88 }
89 Verify::Cancel(run) => Output::Cancellation(runs::cancel(context, &run).await?),
90 })
91 }
92}