Radish alpha
r
rad:zwTxygwuz5LDGBq255RA2CbNGrz8
Radicle CI broker
Radicle
Git
fix: "cibtool run list" shows ids without loading run info
Merged liw opened 1 year ago

If the run info can’t be parsed as JSON, loading it will fail. Change cibtool run list so that it only lists the run ids by default.

Signed-off-by: Lars Wirzenius liw@liw.fi

fix: “cibtool run remove” removed only by broker run id by default

We need to parse the run info in the database as JSON to get at the adapter run info. This fails if the run info can’t be parsed. That can happen if the database has run info from a development version. Change cibtool run remove so that it takes only broker run ids by default so that we can delete using those even if the run info is broken. Allow removing by adapter run id with the --adapter option.

Signed-off-by: Lars Wirzenius liw@liw.fi

4 files changed +53 -25 756d7ac8 765e6b60
modified ci-broker.md
@@ -434,7 +434,7 @@ when I run cibtool --db ci-broker.db event list
then stdout is empty

when I run cibtool --db ci-broker.db run list
-
then stdout has 2 lines containing "xyzzy"
+
then stdout has 2 lines
~~~


@@ -1998,7 +1998,7 @@ when I run cibtool --db x.db run list --json
then stdout contains "runny"
then stdout contains ""state": "triggered""

-
when I run cibtool --db x.db run remove runny
+
when I run cibtool --db x.db run remove --adapter runny

when I run cibtool --db x.db run list
then stdout is empty
modified ci-broker.yaml
@@ -25,6 +25,11 @@
    rust:
      function: stdout_has_one_line

+
- then: "stdout has {n:uint} lines"
+
  impl:
+
    rust:
+
      function: stdout_has_n_lines
+

- then: "stdout has {n:uint} lines containing \"{text:text}\""
  impl:
    rust:
modified src/bin/cibtoolcmd/run.rs
@@ -178,27 +178,39 @@ impl Leaf for ShowRun {
pub struct RemoveRun {
    /// Broker or adapter run IDs of runs to remove.
    ids: Vec<RunId>,
+

+
    /// The run ids are from the adapter, not the CI broker.
+
    #[clap(long)]
+
    adapter: bool,
}

impl Leaf for RemoveRun {
    fn run(&self, args: &Args) -> Result<(), CibToolError> {
        let db = args.open_db()?;
-
        let unwanted: HashSet<RunId> = HashSet::from_iter(self.ids.iter().cloned());
-
        let remove: Vec<Run> = db
-
            .get_all_runs()?
-
            .iter()
-
            .filter(|run| {
-
                if let Some(id) = run.adapter_run_id() {
-
                    unwanted.contains(id)
-
                } else {
-
                    unwanted.contains(run.broker_run_id())
-
                }
-
            })
-
            .cloned()
-
            .collect();
-

-
        for run in remove.iter() {
-
            db.remove_run(run.broker_run_id())?;
+

+
        if self.adapter {
+
            let unwanted: HashSet<RunId> = HashSet::from_iter(self.ids.iter().cloned());
+
            let remove: Vec<Run> = db
+
                .get_all_runs()?
+
                .iter()
+
                .filter(|run| {
+
                    if let Some(id) = run.adapter_run_id() {
+
                        unwanted.contains(id)
+
                    } else {
+
                        unwanted.contains(run.broker_run_id())
+
                    }
+
                })
+
                .cloned()
+
                .collect();
+

+
            for run in remove.iter() {
+
                db.remove_run(run.broker_run_id())?;
+
            }
+
        } else {
+
            for run_id in self.ids.iter() {
+
                db.remove_run(run_id)?;
+
                println!("removed run {run_id}");
+
            }
        }
        Ok(())
    }
@@ -217,18 +229,14 @@ impl Leaf for ListRuns {
    fn run(&self, args: &Args) -> Result<(), CibToolError> {
        let db = args.open_db()?;

-
        let runs = if let Some(wanted) = &self.adapter_run_id {
-
            db.find_runs(wanted)?
-
        } else {
-
            db.get_all_runs()?
-
        };
-

        if self.json {
+
            let runs = db.get_all_runs()?;
            println!(
                "{}",
                serde_json::to_string_pretty(&runs).map_err(CibToolError::RunToJson)?
            );
-
        } else {
+
        } else if let Some(wanted) = &self.adapter_run_id {
+
            let runs = db.find_runs(wanted)?;
            for run in runs {
                println!(
                    "{} {}",
@@ -238,6 +246,11 @@ impl Leaf for ListRuns {
                        .unwrap_or("unknown".into())
                );
            }
+
        } else {
+
            let run_ids = db.list_runs()?;
+
            for run_id in run_ids {
+
                println!("{}", run_id);
+
            }
        }

        Ok(())
modified src/subplot.rs
@@ -398,6 +398,16 @@ fn stdout_has_one_line(runcmd: &Runcmd) {
#[step]
#[context(SubplotContext)]
#[context(Runcmd)]
+
fn stdout_has_n_lines(runcmd: &Runcmd, n: usize) {
+
    let linecount = runcmd.stdout_as_string().lines().count();
+
    if linecount != n {
+
        throw!(format!("stdout had {linecount} lines, expected {n}"));
+
    }
+
}
+

+
#[step]
+
#[context(SubplotContext)]
+
#[context(Runcmd)]
fn stdout_has_n_lines_containing(runcmd: &Runcmd, n: usize, text: &str) {
    let linecount = runcmd
        .stdout_as_string()