Radish alpha
r
rad:zwTxygwuz5LDGBq255RA2CbNGrz8
Radicle CI broker
Radicle
Git
make scenario steps a little clearer
Merged liw opened 1 year ago
3 files changed +112 -123 768b9668 c377b05a
modified ci-broker.md
@@ -223,7 +223,7 @@ output is in the JSON format. It does not try to make sure the JSON
matches the YAML semantically.

~~~scenario
-
given an installed cib
+
given an installed CI broker
given file broker.yaml
when I run cib --config broker.yaml config --output actual.json
when I run jq . actual.json
@@ -241,21 +241,20 @@ nothing else has a hope of working.
_Who:_ `cib-devs`

~~~scenario
+
given an installed CI broker
+
given a CI adapter adapter.sh from dummy.sh
+

given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed synthetic-events
given file refsfetched.json
given file set-rid
when I run bash radenv.sh env HOME=../homedir python3 set-rid refsfetched.json testy
when I run synthetic-events synt.sock refsfetched.json --log log.txt

-
given an installed cib
given a directory reports
given file broker.yaml
-
given file adapter.sh from dummy.sh
-
when I run chmod +x adapter.sh

when I run bash radenv.sh RAD_SOCKET=synt.sock cib --config broker.yaml process-events
then stderr contains "CI broker starts"
@@ -264,9 +263,8 @@ then stderr contains "CI broker ends successfully"
then file reports/index.html exists
then file reports/status.json exists

-
given an installed cibtool
when I run cibtool --db ci-broker.db event list
-
then stdout is exactly ""
+
then stdout is empty

when I run cibtool --db ci-broker.db run list --json
then stdout contains ""id": "xyzzy""
@@ -284,15 +282,14 @@ reports.
_Who:_ `cib-devs`

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cib
when I run cib --version
then stdout matches regex ^radicle-ci-broker \d+\.\d+\.\d+$

-
given an installed cibtool
when I run cibtool --version
then stdout matches regex ^radicle-ci-broker \d+\.\d+\.\d+$
~~~
@@ -314,11 +311,11 @@ user can access individual logs.
_Who:_ `cib-devs`

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed synthetic-events
given file refsfetched.json
given file set-rid
when I run bash radenv.sh env HOME=../homedir python3 set-rid refsfetched.json testy
@@ -327,7 +324,6 @@ when I run synthetic-events synt.sock refsfetched.json --log log.txt
given file adapter.sh from adapter-with-url.sh
when I run chmod +x adapter.sh

-
given an installed cib
given file broker.yaml
given a directory reports

@@ -354,11 +350,11 @@ reduces the support burden on the Radicle project.
_Who:_ `cib-devs`

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cib
given file broker.yaml
when I try to run bash radenv.sh RAD_SOCKET=xyzzy.sock cib --config broker.yaml insert
then command fails
@@ -382,11 +378,11 @@ a thing that can always be made better. We can later add more
scenarios if we tighten the acceptance criteria.

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cib
given file broker.yaml
given file not-yaml.yaml
when I try to run env HOME=homedir cib --config not-yaml.yaml config
@@ -412,12 +408,11 @@ handled by a dedicated system, such as `systemd`.
_Who:_ `cib-devs`

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cib
-
given an installed synthetic-events
when I run synthetic-events synt.sock --log log.txt
given file broker.yaml
when I try to run bash radenv.sh RAD_SOCKET=synt.sock cib --config broker.yaml insert
@@ -441,19 +436,18 @@ an object id of all zeros. This should be sufficiently impossible to
happen in real life.

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cib
-
given an installed synthetic-events
given file broker.yaml
when I run synthetic-events synt.sock --log synt.log
when I try to run bash radenv.sh RAD_SOCKET=synt.sock cib --config broker.yaml insert
when I run cat synt.log
then command is successful
when I run cibtool --db ci-broker.db run list
-
then stdout is exactly ""
+
then stdout is empty
~~~


@@ -467,11 +461,11 @@ _Why:_ This is useful for diagnosis, if nothing else.
_Who:_ `cib-devs`

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cibtool
when I run bash radenv.sh cibtool --db x.db run add --repo testy --branch main --commit HEAD --failure

given a directory reports
@@ -495,19 +489,18 @@ error output. This makes it easier to debug adapter problems.
_Who:_ `adapter-devs`, `node-ops`

~~~scenario
+
given an installed CI broker
+
given a CI adapter adapter.sh from dummy.sh
+

given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cibtool
when I run bash radenv.sh cibtool --db ci-broker.db trigger --repo testy --ref main --commit HEAD
when I run bash radenv.sh cibtool --db ci-broker.db event list --json

-
given an installed cib
given file broker.yaml
given a directory reports
-
given file adapter.sh from dummy.sh
-
when I run chmod +x adapter.sh

when I run bash radenv.sh cib --config broker.yaml queued
then stderr contains "Mordor"
@@ -523,11 +516,11 @@ _Why:_ This allows controlling how much log spew log admins have to see.
_Who:_ `node-ops`

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cib
given file broker.yaml
given a directory reports

@@ -622,7 +615,7 @@ time: if the time is too short, the scenario fails spuriously, and if
it's very long, the scenario takes longer than necessary.

~~~scenario
-
given an installed synthetic-events
+
given an installed CI broker

then file synt.sock does not exist

@@ -659,7 +652,7 @@ work of multiple processes, either.
_Who:_ `cib-devs`

~~~scenario
-
given an installed cibtool
+
given an installed CI broker
then file count.db does not exist
when I run cibtool --db count.db counter show
then stdout is exactly "0\n"
@@ -681,13 +674,11 @@ in a node change.
_Who:_ `cib-devs`

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cib
-
given an installed synthetic-events
-

given file refsfetched.json
when I run synthetic-events synt.sock refsfetched.json --log synt.log

@@ -711,13 +702,11 @@ _Why:_ We need at least some rudimentary performance testing.
_Who:_ `cib-devs`

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cib
-
given an installed synthetic-events
-

given file refsfetched.json
when I run synthetic-events synt.sock refsfetched.json --log synt.log --repeat 1000

@@ -741,13 +730,11 @@ in a node change.
_Who:_ `cib-devs`

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cib
-
given an installed synthetic-events
-

given file refsfetched.json
when I run synthetic-events synt.sock refsfetched.json --log synt.log

@@ -775,16 +762,13 @@ events. We carefully add a shutdown event so that the CI broker shuts
down.

~~~scenario
+
given an installed CI broker
+
given a CI adapter adapter.sh from dummy.sh
+

given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given file adapter.sh from dummy.sh
-
when I run chmod +x adapter.sh
-

-
given an installed cib
-
given an installed cibtool
-

when I run bash radenv.sh cibtool --db ci-broker.db event add --repo testy --ref main --commit HEAD
when I run cibtool --db ci-broker.db event shutdown

@@ -796,7 +780,7 @@ then stderr contains "Action: run:"
then stderr contains "Action: shutdown"

when I run cibtool --db ci-broker.db event list
-
then stdout is exactly ""
+
then stdout is empty

when I run cibtool --db ci-broker.db run list --json
then stdout contains "success"
@@ -820,7 +804,7 @@ count to a desired goal. The script then verifies that everything went
correctly.

~~~scenario
-
given an installed cibtool
+
given an installed CI broker
given file count.sh
when I run env bash -x count.sh 100 10
then stdout contains "OK\n"
@@ -903,13 +887,13 @@ itself for this test, but the id shouldn't matter, it just needs to
be of the correct form.

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cibtool
when I run cibtool --db x.db event list
-
then stdout is exactly ""
+
then stdout is empty

when I run bash radenv.sh cibtool --db x.db event add --repo testy --ref main --commit HEAD --base HEAD --id-file id.txt

@@ -920,7 +904,7 @@ then stdout contains "main"
when I run cibtool --db x.db event remove --id-file id.txt

when I run cibtool --db x.db event list
-
then stdout is exactly ""
+
then stdout is empty
~~~

## Can remove all queued events
@@ -934,13 +918,13 @@ operator wants to prevent many CI runs from happening.
_Who:_ `cib-devs`, `node-ops`

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cibtool
when I run cibtool --db x.db event list
-
then stdout is exactly ""
+
then stdout is empty

when I run bash radenv.sh cibtool --db x.db event add --repo testy --ref main --commit HEAD --base HEAD
when I run bash radenv.sh cibtool --db x.db event add --repo testy --ref main --commit HEAD --base HEAD
@@ -951,7 +935,7 @@ when I run bash radenv.sh cibtool --db x.db event add --repo testy --ref main --

when I run cibtool --db x.db event remove --all
when I run cibtool --db x.db event list
-
then stdout is exactly ""
+
then stdout is empty
~~~

## Can add shutdown event to queue
@@ -965,9 +949,9 @@ to be able to do this cleanly.
_Who:_ `cib-devs`

~~~scenario
-
given an installed cibtool
+
given an installed CI broker
when I run cibtool --db x.db event list
-
then stdout is exactly ""
+
then stdout is empty

when I run cibtool --db x.db event shutdown --id-file id.txt

@@ -986,11 +970,11 @@ _Who:_ `cib-devs`


~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cibtool
when I run bash radenv.sh cibtool --db x.db trigger --repo testy --ref main --commit HEAD --id-file id.txt

when I run cibtool --db x.db event show --id-file id.txt
@@ -1008,13 +992,13 @@ _Why:_ This is primarily needed for testing.
_Who:_ `cib-devs`

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cibtool
when I run cibtool --db x.db run list
-
then stdout is exactly ""
+
then stdout is empty

when I run bash radenv.sh cibtool --db x.db run add --id xyzzy --repo testy --branch main --commit main --triggered
when I run cibtool --db x.db run list --json
@@ -1031,13 +1015,13 @@ _Why:_ This is primarily needed for testing.
_Who:_ `cib-dev`.

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cibtool
when I run cibtool --db x.db run list
-
then stdout is exactly ""
+
then stdout is empty

when I run bash radenv.sh cibtool --db x.db run add --repo testy --url https://x/1 --branch main --commit HEAD --running
when I run cibtool --db x.db run list --json
@@ -1056,13 +1040,13 @@ _Why:_ This is primarily needed for testing.
_Who:_ `cib-dev`.

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cibtool
when I run cibtool --db x.db run list
-
then stdout is exactly ""
+
then stdout is empty

when I run bash radenv.sh cibtool --db x.db run add --id xyzzy --repo testy --branch main --commit HEAD --success
when I run cibtool --db x.db run list --json
@@ -1081,13 +1065,13 @@ _Why:_ This is primarily needed for testing.
_Who:_ `cib-dev`.

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cibtool
when I run cibtool --db x.db run list
-
then stdout is exactly ""
+
then stdout is empty

when I run bash radenv.sh cibtool --db x.db run add --id xyzzy --repo testy --branch main --commit HEAD --failure
when I run cibtool --db x.db run list --json
@@ -1096,7 +1080,7 @@ then stdout contains ""result": "failure""
then stdout contains "xyzzy"

when I run cibtool --db x.db run list --adapter-run-id abracadabra
-
then stdout is exactly ""
+
then stdout is empty
~~~

## Update and show information about run to running
@@ -1108,13 +1092,13 @@ _Why:_ This is primarily needed for testing.
_Who:_ `cib-dev`.

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cibtool
when I run cibtool --db x.db run list
-
then stdout is exactly ""
+
then stdout is empty

when I run bash radenv.sh cibtool --db x.db run add --id x --repo testy --branch main --commit HEAD --triggered
when I run cibtool --db x.db run list
@@ -1158,12 +1142,11 @@ Note that we verify both lookup by name and by repository ID, and by
`cibtool event add` and `cibtool trigger`, to cover all the cases.

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cibtool
-

when I try to run bash radenv.sh cibtool --db x.db event add --repo missing --ref main --commit HEAD --base c0ffee
then command fails
then stderr contains "missing"
@@ -1193,17 +1176,16 @@ useful for gathering data for trying out event filters.
_Who:_ `cib-devs`, `node-ops`

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed synthetic-events
given file refsfetched.json
given file set-rid
when I run bash radenv.sh env HOME=../homedir python3 set-rid refsfetched.json testy
when I run synthetic-events synt.sock refsfetched.json --log log.txt

-
given an installed cibtool
when I run bash radenv.sh cibtool event record --output events.json
then file events.json contains ""type":"refsFetched""
~~~
@@ -1220,17 +1202,16 @@ It's also helpful for CI broker developers as a development tool.
_Who:_ `cib-dev`, `node-ops`

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed synthetic-events
given file refsfetched.json
given file set-rid
when I run bash radenv.sh env HOME=../homedir python3 set-rid refsfetched.json testy
when I run synthetic-events synt.sock refsfetched.json --log log.txt

-
given an installed cibtool
when I run bash radenv.sh cibtool event record --output node-events.json
when I run bash radenv.sh cibtool event ci --output ci-events.json node-events.json
when I run cat ci-events.json
@@ -1248,17 +1229,16 @@ event filters work as they expect.
_Who:_ `cib-dev`, `node-ops`

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed synthetic-events
given file refsfetched.json
given file set-rid
when I run bash radenv.sh env HOME=../homedir python3 set-rid refsfetched.json testy
when I run synthetic-events synt.sock refsfetched.json --log log.txt

-
given an installed cibtool
when I run bash radenv.sh cibtool event record --output node-events.json
when I run bash radenv.sh cibtool event ci --output ci-events.json node-events.json

@@ -1268,7 +1248,7 @@ then stdout contains "BranchUpdated"

given file deny.yaml
when I run cibtool event filter deny.yaml ci-events.json
-
then stdout is exactly ""
+
then stdout is empty
~~~

~~~{#allow.yaml .file .yaml}
@@ -1320,15 +1300,13 @@ any events, so `cib` just terminates at once. All of this will work,
when properly set up.

~~~scenario
+
given an installed CI broker
+
given a CI adapter adapter.sh from dummy.sh
+

given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given file adapter.sh from dummy.sh
-
when I run chmod +x adapter.sh
-

-
given an installed cib
-

given file broker.yaml
given a directory reports
when I run bash radenv.sh cib --config broker.yaml queued
@@ -1351,8 +1329,7 @@ We check this by running the CI broker without a local node. This is
an error it can't recover from.

~~~scenario
-
given an installed cib
-

+
given an installed CI broker
given file broker.yaml
when I try to run env RAD_HOME=/does/not/exist cib --config broker.yaml queued

@@ -1377,11 +1354,11 @@ monitoring system.
_Who:_ `node-ops`

~~~scenario
+
given an installed CI broker
given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cib
given file broker.yaml
given a directory reports

@@ -1430,19 +1407,17 @@ the Git commit identifiers instead. In any case, this scenario needs
to be updated when a new release is made.

~~~scenario
+
given an installed CI broker
+
given a CI adapter adapter.sh from dummy.sh
+

given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given an installed cibtool
-
given an installed cib
given file broker.yaml
given file verify-upgrade
given a directory reports

-
given file adapter.sh from dummy.sh
-
when I run chmod +x adapter.sh
-

when I touch file run-list.txt
when I run bash radenv.sh bash -x verify-upgrade run-list.txt 535b1592904125fbe62c3c8c383d7741d9f432ac
when I run bash radenv.sh bash -x verify-upgrade run-list.txt 869b451728d16719b560df142b2d901cbaf3764c
modified ci-broker.yaml
@@ -1,19 +1,19 @@
-
- given: "an installed cib"
+
- given: "an installed CI broker"
  impl:
    rust:
-
      function: install_cib
+
      function: install_ci_broker

-
- given: "an installed cibtool"
+
- given: "a CI adapter {filename:path} from {embedded:file}"
  impl:
    rust:
-
      function: install_cibtool
+
      function: install_adapter

-
- given: "an installed synthetic-events"
+
- then: "stdout has one line"
  impl:
    rust:
-
      function: install_synthetic_events
+
      function: stdout_has_one_line

-
- then: "stdout has one line"
+
- then: "stdout is empty"
  impl:
    rust:
-
      function: stdout_has_one_line
+
      function: stdout_is_empty
modified src/subplot.rs
@@ -1,7 +1,14 @@
// Implementations of Subplot scenario steps for the CI broker.

-
use std::path::{Path, PathBuf};
+
use std::{
+
    fs::{set_permissions, Permissions},
+
    io::Write,
+
    os::unix::fs::PermissionsExt,
+
    path::{Path, PathBuf},
+
};

+
use subplotlib::steplibrary::datadir::Datadir;
+
use subplotlib::steplibrary::files::Files;
use subplotlib::steplibrary::runcmd::Runcmd;

#[derive(Debug, Default)]
@@ -12,38 +19,10 @@ impl ContextElement for SubplotContext {}
#[step]
#[context(SubplotContext)]
#[context(Runcmd)]
-
fn install_cib(context: &ScenarioContext) {
+
fn install_ci_broker(context: &ScenarioContext) {
    let target_path = bindir();
    assert!(target_path.join("cib").exists());
-
    context.with_mut(
-
        |context: &mut Runcmd| {
-
            context.prepend_to_path(target_path);
-
            Ok(())
-
        },
-
        false,
-
    )?;
-
}
-

-
#[step]
-
#[context(SubplotContext)]
-
#[context(Runcmd)]
-
fn install_cibtool(context: &ScenarioContext) {
-
    let target_path = bindir();
    assert!(target_path.join("cibtool").exists());
-
    context.with_mut(
-
        |context: &mut Runcmd| {
-
            context.prepend_to_path(target_path);
-
            Ok(())
-
        },
-
        false,
-
    )?;
-
}
-

-
#[step]
-
#[context(SubplotContext)]
-
#[context(Runcmd)]
-
fn install_synthetic_events(context: &ScenarioContext) {
-
    let target_path = bindir();
    assert!(target_path.join("synthetic-events").exists());
    context.with_mut(
        |context: &mut Runcmd| {
@@ -65,6 +44,29 @@ fn bindir() -> PathBuf {

#[step]
#[context(SubplotContext)]
+
#[context(Datadir)]
+
#[context(Files)]
+
fn install_adapter(context: &Datadir, filename: &Path, embedded: SubplotDataFile) {
+
    eprintln!(
+
        "install adapter {} from {}:\n{}",
+
        filename.display(),
+
        embedded.name().display(),
+
        String::from_utf8_lossy(embedded.data()),
+
    );
+
    eprintln!("write {}", filename.display());
+
    context.open_write(filename)?.write_all(embedded.data())?;
+
    let realpath = context.canonicalise_filename(filename)?;
+
    eprintln!(
+
        "chmod {} (exists? {})",
+
        realpath.display(),
+
        realpath.exists()
+
    );
+
    let executable = Permissions::from_mode(0o755);
+
    set_permissions(realpath, executable)?;
+
}
+

+
#[step]
+
#[context(SubplotContext)]
#[context(Runcmd)]
fn stdout_has_one_line(runcmd: &Runcmd) {
    let linecount = runcmd.stdout_as_string().lines().count();
@@ -72,3 +74,15 @@ fn stdout_has_one_line(runcmd: &Runcmd) {
        throw!(format!("stdout had {linecount} lines, expected 1"));
    }
}
+

+
#[step]
+
#[context(SubplotContext)]
+
#[context(Runcmd)]
+
fn stdout_is_empty(runcmd: &Runcmd) {
+
    let stdout = runcmd.stdout_as_string();
+
    if !stdout.is_empty() {
+
        throw!(format!(
+
            "expected stdout to be empty, is actually {stdout:?}"
+
        ));
+
    }
+
}