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
201 changes: 201 additions & 0 deletions .github/workflows/app-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
# End-to-end run of the Mostro app (profile `mobile-v2`, Linux desktop)
# against a regtest stack this job builds itself: worthless sats and no
# secrets, so it runs on GitHub-hosted runners.
#
# - Reusable (`workflow_call`): MostroP2P/app's Mortsom pull request gate
# calls it with the app ref and the scenarios its map selected.
# - By hand (`workflow_dispatch`) for any app branch or pull request.
# - On pull requests that change this file, with the smoke suite, so a
# change to the job is exercised before it merges.
#
# Every input reaches the scripts through the environment, never through
# expression interpolation, and the job holds no secret and a read-only
# token: the app code it builds and runs is untrusted.
name: app e2e

on:
workflow_call:
inputs:
app_ref:
description: App branch or https://github.com/MostroP2P/app/pull/<number>
type: string
required: true
scenarios:
description: Scenario names, space separated; empty runs `tag`
type: string
default: ""
tag:
description: Scenario tag to run when `scenarios` is empty
type: string
default: smoke
bond:
description: Run on a daemon with anti-abuse bonds (the `bond` family)
type: boolean
default: false
mortsom_ref:
description: Mortsom ref to build (the caller pins it)
type: string
default: main
artifact_name:
description: Name of the uploaded summaries artifact
type: string
default: app-e2e-summaries
workflow_dispatch:
inputs:
app_ref:
description: App branch or https://github.com/MostroP2P/app/pull/<number>
required: false
default: main
scenarios:
description: Scenario names, space separated; empty runs `tag`
required: false
default: ""
tag:
description: Scenario tag to run when `scenarios` is empty
required: false
default: smoke
bond:
description: Run on a daemon with anti-abuse bonds (the `bond` family)
type: boolean
default: false
pull_request:
paths:
- ".github/workflows/app-e2e.yml"

permissions:
contents: read

jobs:
app:
name: mobile-v2 on Linux (${{ inputs.app_ref || 'main' }})
runs-on: ubuntu-latest
timeout-minutes: 300
env:
APP_REF: ${{ inputs.app_ref || 'main' }}
SCENARIOS: ${{ inputs.scenarios || '' }}
TAG: ${{ inputs.tag || 'smoke' }}
BOND: ${{ inputs.bond && 'true' || 'false' }}
MORTSOM: ./target/release/mortsom
# Versions the app's own CI pins (MostroP2P/app .github/workflows/ci.yml).
FLUTTER_VERSION: "3.41.9"
FRB_VERSION: "2.11.1"
CARGO_EXPAND_VERSION: "1.0.123"
steps:
- uses: actions/checkout@v4
with:
# Called from the app, the default would be the app repository.
repository: MostroP2P/mortsom
ref: ${{ inputs.mortsom_ref || github.sha }}
persist-credentials: false
- name: System packages
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends protobuf-compiler \
clang libclang-dev lld cmake ninja-build pkg-config libgtk-3-dev libsecret-1-dev \
xvfb dbus dbus-x11 gnome-keyring at-spi2-core imagemagick
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
# Only runs of Mortsom's own main save the cache.
save-if: ${{ github.repository == 'MostroP2P/mortsom' && github.ref == 'refs/heads/main' }}
- uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
channel: stable
# The app code this job builds is untrusted: never save a cache it
# could have written into.
cache: false
- uses: taiki-e/install-action@v2
with:
tool: cargo-expand@${{ env.CARGO_EXPAND_VERSION }},flutter_rust_bridge_codegen@${{ env.FRB_VERSION }}
- name: Build Mortsom
run: cargo build --release --locked -p mortsom-coordinator --bin mortsom
- name: Regtest stack
run: |
if [ "$BOND" = true ]; then
$MORTSOM stack up --bond
else
$MORTSOM stack up
fi
- name: Preflight
run: $MORTSOM doctor --platform linux --ref "$APP_REF"
- name: Run
run: |
start=$(date +%s)
# Split into names without globbing, and accept only scenario
# names: nothing here may become a flag. A blank list falls back
# to the tag, never to the whole registry.
set -f
read -r -a names <<< "$SCENARIOS"
if [ ${#names[@]} -gt 0 ]; then
for name in "${names[@]}"; do
if ! [[ "$name" =~ ^[a-z0-9_]+$ ]]; then
echo "::error::not a scenario name: $name"
exit 2
fi
done
$MORTSOM run --platform linux --ref "$APP_REF" "${names[@]}" || status=$?
else
$MORTSOM run --platform linux --ref "$APP_REF" --tag "$TAG" || status=$?
fi
echo "run took $(( $(date +%s) - start )) s" | tee -a "$GITHUB_STEP_SUMMARY"
exit "${status:-0}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject an end-to-end selection when every scenario is skipped

When the selected scenarios cannot run on the configured stack—for example, tag: bond with the default bond: false—this workflow can finish green without executing any scenario. gate_bond skips that selection, and Report::code() returns success when there are no failures, consistent with the README's documented exit-status semantics. The Run step forwards that status, while Collect summaries only copies the results without checking them. Add an executed-result check before accepting the job, as .github/workflows/cli-e2e.yml already does, so an incompatible selection cannot produce a successful end-to-end check.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in dc391f4: a new "Require an executed scenario" step fails the job when the summaries hold no executed (non-skipped) scenario, as cli-e2e.yml does. Also took CodeRabbit's nitpicks there: glob loops instead of ls | grep, and a note that mortsom_ref/artifact_name exist only for workflow_call; the unquoted $SCENARIOS one was already fixed in c475470.

- name: Require an executed scenario
# A run whose every scenario was skipped (a bond selection on a plain
# stack, an interruption scenario on Linux) tested nothing.
run: |
shopt -s nullglob
summaries=(artifacts/*/summary.json)
executed=0
if [ ${#summaries[@]} -gt 0 ]; then
executed=$(jq -s '[.[].results[]? | select(.outcome.outcome != "skipped")] | length' "${summaries[@]}")
fi
if [ "$executed" -eq 0 ]; then
echo "::error::no selected scenario executed: every one was skipped, or none ran"
exit 1
fi
- name: Collect summaries
if: always()
run: |
mkdir -p summaries
shopt -s nullglob
for f in artifacts/*/summary.json; do
cp "$f" "summaries/$(basename "$(dirname "$f")").json"
done
ls summaries
- uses: actions/upload-artifact@v4
if: always()
with:
name: ${{ inputs.artifact_name || 'app-e2e-summaries' }}
path: summaries
if-no-files-found: warn
retention-days: 30
- name: Cleanup what the run may have left
if: always()
run: |
shopt -s nullglob
for dir in artifacts/*/; do
run=$(basename "$dir")
[ "$run" = accounting ] && continue
$MORTSOM cleanup "$run" || echo "::warning::cleanup of $run failed; the stack is discarded with the runner"
done
- name: Publish sanitized evidence
if: always()
run: |
mkdir -p bundle
shopt -s nullglob
for dir in artifacts/*/; do
run=$(basename "$dir")
[ "$run" = accounting ] && continue
$MORTSOM publish "$run" --out "bundle/$run" --screenshots all || true
done
- uses: actions/upload-artifact@v4
if: always()
with:
name: ${{ inputs.artifact_name || 'app-e2e-summaries' }}-evidence
path: bundle
if-no-files-found: ignore
retention-days: 14
- name: Stack down
if: always()
run: $MORTSOM stack down || true
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ cargo build -p mortsom-coordinator --bin mortsom
./target/debug/mortsom run --tag smoke # the cheap subset: three scenarios, one run each
./target/debug/mortsom run # the whole catalogue: every scenario, one run each
./target/debug/mortsom list # scenarios by family; --details adds capabilities and deadlines
./target/debug/mortsom list --json # the same registry as JSON (docs/gate-contract.md)
```

Every `run` creates fresh Alice and Bob identities, runs one scenario, resolves every order it created and
Expand Down
9 changes: 8 additions & 1 deletion crates/coordinator/src/banner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,14 @@ mod tests {
#[test]
fn the_one_command_that_reads_no_config_names_what_it_reads_instead() {
// Arrange / Act
let list = caption(&Command::List { details: false }, &config(), &stack_dir());
let list = caption(
&Command::List {
details: false,
json: false,
},
&config(),
&stack_dir(),
);

// Assert
assert!(!list.contains("desktop.example.toml"), "{list}");
Expand Down
32 changes: 30 additions & 2 deletions crates/coordinator/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ pub enum Command {
/// deadline that aborts a stuck attempt.
#[arg(long)]
details: bool,
/// Print the registry as one JSON document (the catalog pull request
/// gates select scenarios from) instead of the listing.
#[arg(long, conflicts_with = "details")]
json: bool,
},
/// Recover retained desktop identities and orders of an interrupted run.
/// Refuses unresolved ownership and changed stack identities.
Expand Down Expand Up @@ -451,7 +455,7 @@ pub async fn run(cli: Cli) -> ExitCode {
};
match cli.command {
Command::Stack { action } => stack_cli(&cli.stack_dir, action).await,
Command::List { details } => list_scenarios(details),
Command::List { details, json } => list_scenarios(details, json),
Command::Cleanup {
run,
attribute_order,
Expand Down Expand Up @@ -696,13 +700,37 @@ fn relay_down_targets(names: Vec<String>, exact: Option<&str>) -> Vec<String> {
}
}

fn list_scenarios(details: bool) -> ExitCode {
/// `mortsom list --json`. A reader that closes the pipe early (`| head`)
/// is not an error.
fn print_catalog(defs: &[&'static mortsom_scenario_kit::registry::ScenarioDef]) -> ExitCode {
use std::io::Write;
let catalog = crate::scenario_list::Catalog::from_defs(defs, env!("CARGO_PKG_VERSION"));
let json = match catalog.to_json() {
Ok(json) => json,
Err(e) => {
eprintln!("cannot serialize the scenario catalog: {e}");
return ExitCode::from(2);
}
};
match std::io::stdout().write_all(json.as_bytes()) {
Err(e) if e.kind() != std::io::ErrorKind::BrokenPipe => {
eprintln!("cannot write the scenario catalog: {e}");
ExitCode::from(2)
}
_ => ExitCode::SUCCESS,
}
}

fn list_scenarios(details: bool, json: bool) -> ExitCode {
mortsom_scenarios::link();
if let Err(e) = mortsom_scenario_kit::registry::validate() {
eprintln!("{e}");
return ExitCode::from(2);
}
let defs = mortsom_scenario_kit::registry::all();
if json {
return print_catalog(&defs);
}
let listing = crate::scenario_list::Listing::from_defs(&defs);
let detail = if details {
crate::scenario_list::Detail::Full
Expand Down
2 changes: 1 addition & 1 deletion crates/coordinator/src/run/bond_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use mortsom_scenario_kit::registry::ScenarioDef;
use super::{Outcome, ScenarioResult};

/// The family whose scenarios need a bonded daemon.
pub(super) const BOND_FAMILY: &str = "bond";
pub const BOND_FAMILY: &str = "bond";

/// Splits `selected` into the scenarios written for the stack's daemon and
/// the rest, skipped with the reason. `bonded` is whether the stack declares
Expand Down
1 change: 1 addition & 0 deletions crates/coordinator/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(crate) mod recovery;
mod report;
pub mod timings;
mod world_execution;
pub use bond_gate::BOND_FAMILY;
pub use observer::{LiveObserver, ObserverFactory};
pub use report::RunSummary;
use report::finish;
Expand Down
83 changes: 83 additions & 0 deletions crates/coordinator/src/scenario_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
use std::collections::BTreeMap;

use mortsom_scenario_kit::registry::ScenarioDef;
use serde::Serialize;

use crate::run::BOND_FAMILY;
use crate::style::{self, Style};

/// Tags that label a scenario without naming its family; a scenario is
Expand Down Expand Up @@ -255,6 +257,87 @@ impl Row {
}
}

/// Version of the `mortsom list --json` document. Bumped on any change a
/// reader would have to handle: a removed or renamed field, a new meaning.
pub const CATALOG_SCHEMA: u32 = 1;

/// The registry as a machine reads it (`mortsom list --json`).
///
/// Pull request gates commit this document and select scenarios from it,
/// so it carries everything selection and skipping depend on and nothing
/// that is only layout.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct Catalog {
/// [`CATALOG_SCHEMA`].
pub schema: u32,
/// Version of the Mortsom that produced it.
pub mortsom_version: String,
/// Scenarios, in registry order.
pub scenarios: Vec<CatalogEntry>,
}

/// One scenario of the [`Catalog`].
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct CatalogEntry {
/// Name `mortsom run` takes.
pub name: String,
/// Family the scenario is grouped under.
pub family: String,
/// Every tag, in registry order (the family is not necessarily first);
/// `--tag` selects by any.
pub tags: Vec<String>,
/// True when the scenario moves sats.
pub moves_value: bool,
/// True when it needs a dispute solver registered with the daemon.
pub needs_solver: bool,
/// True when it drives the app's own connected wallet; a run whose
/// payer is a node Mortsom holds skips it.
pub needs_app_wallet: bool,
/// True when it is written for a daemon with anti-abuse bonds
/// (`stack up --bond`); every other scenario is skipped on one.
pub needs_bonded_daemon: bool,
/// Interruptions it causes outside the app; Linux and Web runs skip it.
pub needs: Vec<String>,
/// Capabilities the app profile must support.
pub requires: Vec<String>,
/// Deadline that aborts one attempt; not how long the scenario takes.
pub timeout_secs: u64,
}

impl Catalog {
/// Builds the catalog from registry definitions.
pub fn from_defs(defs: &[&'static ScenarioDef], mortsom_version: &str) -> Self {
let scenarios = defs
.iter()
.map(|def| CatalogEntry {
name: def.name.to_owned(),
family: family_of(def.tags).to_owned(),
tags: def.tags.iter().map(|t| (*t).to_owned()).collect(),
moves_value: def.moves_value,
needs_solver: def.needs_solver,
needs_app_wallet: def.needs_app_wallet,
needs_bonded_daemon: def.tags.contains(&BOND_FAMILY),
needs: def.needs.iter().map(|n| n.as_str().to_owned()).collect(),
requires: def.requires.iter().map(|c| c.as_str().to_owned()).collect(),
timeout_secs: def.timeout_secs,
})
.collect();
Self {
schema: CATALOG_SCHEMA,
mortsom_version: mortsom_version.to_owned(),
scenarios,
}
}

/// Pretty JSON with a trailing newline, so a committed copy diffs
/// cleanly.
pub fn to_json(&self) -> Result<String, serde_json::Error> {
let mut json = serde_json::to_string_pretty(self)?;
json.push('\n');
Ok(json)
}
}

/// The family a scenario belongs to: its first tag that names one.
fn family_of(tags: &[&'static str]) -> &'static str {
tags.iter()
Expand Down
Loading
Loading