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
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 44 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ version = "0.1.0"
rust-version = "1.85"

[workspace.dependencies]
anyhow = "1.0"
camino = { version = "1.1", features = ["serde1"] }
clap = { version = "4.5", features = ["derive"] }
once_cell = "1.19"
Expand All @@ -32,30 +33,71 @@ pedantic = { level = "warn", priority = -1 }
allow_attributes = "deny"
allow_attributes_without_reason = "deny"
blanket_clippy_restriction_lints = "deny"
cognitive_complexity = "deny"
needless_pass_by_value = "deny"
implicit_hasher = "deny"

# 2. debugging leftovers
dbg_macro = "deny"
print_stdout = "deny"
print_stderr = "deny"

# 3. panic-prone operations
# 2. panic-prone operations
unwrap_used = "deny"
expect_used = "deny"
indexing_slicing = "deny"
string_slice = "deny"
integer_division = "deny"
integer_division_remainder_used = "deny"
panic_in_result_fn = "deny"
unreachable = "deny"
Comment thread
leynos marked this conversation as resolved.
Resolved

# 4. portability
host_endian_bytes = "deny"
little_endian_bytes = "deny"
big_endian_bytes = "deny"

# 5. nursery idiom polish
let_underscore_must_use = "deny"
or_fun_call = "deny"
option_if_let_else = "deny"
use_self = "deny"
self_named_module_files = "deny"
shadow_reuse = "deny"
shadow_same = "deny"
shadow_unrelated = "deny"
str_to_string = "deny"
string_lit_as_bytes = "deny"
try_err = "deny"
unneeded_field_pattern = "deny"
use_self = "deny"

# 6. numerical foot-guns
float_arithmetic = "deny"
cast_possible_truncation = "deny"
cast_possible_wrap = "deny"
cast_precision_loss = "deny"
lossy_float_literal = "deny"

# 7. API ergonomics
missing_const_for_fn = "deny"
must_use_candidate = "deny"
unused_async = "deny"

# 8. Error handling
missing_panics_doc = "deny"
error_impl_error = "deny"
result_large_err = "deny"

[workspace.lints.rust]
unknown_lints = "deny"
renamed_and_removed_lints = "deny"
missing_docs = "deny"

[workspace.lints.rustdoc]
missing_crate_level_docs = "deny"
broken_intra_doc_links = "deny"
private_intra_doc_links = "deny"
bare_urls = "deny"
invalid_html_tags = "deny"
invalid_codeblock_attributes = "deny"
unescaped_backticks = "deny"
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ APP ?= weaver-cli
CARGO ?= cargo
BUILD_JOBS ?=
CLIPPY_FLAGS ?= --workspace --all-targets --all-features -- -D warnings
RUSTDOC_FLAGS ?= --cfg docsrs -D warnings
MDLINT ?= markdownlint
NIXIE ?= nixie

Expand All @@ -22,6 +23,7 @@ target/%/$(APP): ## Build binary in debug or release mode
$(CARGO) build $(BUILD_JOBS) $(if $(findstring release,$(@)),--release) --bin $(APP)

lint: ## Run Clippy with warnings denied
RUSTDOCFLAGS="$(RUSTDOC_FLAGS)" $(CARGO) doc --workspace --no-deps
$(CARGO) clippy $(CLIPPY_FLAGS)

fmt: ## Format Rust and Markdown sources
Expand Down
7 changes: 6 additions & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# Align with CodeScene’s ceiling
cognitive-complexity-threshold = 12 # default is 25
cognitive-complexity-threshold = 9 # default is 25
too-many-arguments-threshold = 4 # default is 7
too-many-lines-threshold = 70 # default is 100
excessive-nesting-threshold = 4 # default is off

allow-expect-in-tests = true
1 change: 1 addition & 0 deletions crates/weaver-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ thiserror = { workspace = true }
socket2 = { version = "0.5" }

[dev-dependencies]
anyhow = { workspace = true }
rstest = { workspace = true }
rstest-bdd = { workspace = true }
rstest-bdd-macros = { workspace = true }
Expand Down
55 changes: 30 additions & 25 deletions crates/weaver-cli/src/tests/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ use crate::EMPTY_LINE_LIMIT;

use std::cell::RefCell;

use anyhow::Result;
use rstest_bdd_macros::{given, scenario, then, when};

#[given("a running fake daemon")]
fn given_running_daemon(world: &RefCell<TestWorld>) {
world.borrow_mut().start_daemon();
fn given_running_daemon(world: &RefCell<TestWorld>) -> Result<()> {
world.borrow_mut().start_daemon()
}

#[given("capability overrides force python rename")]
Expand All @@ -21,81 +22,85 @@ fn given_capability_override(world: &RefCell<TestWorld>) {
}

#[given("a running fake daemon sending malformed json")]
fn given_malformed_daemon(world: &RefCell<TestWorld>) {
fn given_malformed_daemon(world: &RefCell<TestWorld>) -> Result<()> {
world
.borrow_mut()
.start_daemon_with_lines(vec![String::from("not valid json")]);
.start_daemon_with_lines(vec![String::from("not valid json")])
}

#[given("a running fake daemon that closes without exit")]
fn given_daemon_missing_exit(world: &RefCell<TestWorld>) {
fn given_daemon_missing_exit(world: &RefCell<TestWorld>) -> Result<()> {
world.borrow_mut().start_daemon_with_lines(vec![
"{\"kind\":\"stream\",\"stream\":\"stdout\",\"data\":\"partial\"}".to_string(),
]);
])
}

#[given("a running fake daemon that emits empty lines")]
fn given_daemon_with_empty_lines(world: &RefCell<TestWorld>) {
fn given_daemon_with_empty_lines(world: &RefCell<TestWorld>) -> Result<()> {
let mut lines = Vec::new();
for _ in 0..EMPTY_LINE_LIMIT {
lines.push(String::new());
}
world.borrow_mut().start_daemon_with_lines(lines);
world.borrow_mut().start_daemon_with_lines(lines)
}

#[when("the operator runs {command}")]
fn when_operator_runs(world: &RefCell<TestWorld>, command: String) {
world.borrow_mut().run(&command);
fn when_operator_runs(world: &RefCell<TestWorld>, command: String) -> Result<()> {
world.borrow_mut().run(&command)
}

#[then("the daemon receives {fixture}")]
fn then_daemon_receives(world: &RefCell<TestWorld>, fixture: String) {
world.borrow().assert_golden_request(&fixture);
fn then_daemon_receives(world: &RefCell<TestWorld>, fixture: String) -> Result<()> {
world.borrow().assert_golden_request(&fixture)
}

#[then("stdout is {expected}")]
fn then_stdout_is(world: &RefCell<TestWorld>, expected: String) {
fn then_stdout_is(world: &RefCell<TestWorld>, expected: String) -> Result<()> {
let world = world.borrow();
let expected = expected.trim_matches('"');
assert_eq!(world.stdout_text(), expected);
assert_eq!(world.stdout_text()?, expected);
Ok(())
}

#[then("stderr is {expected}")]
fn then_stderr_is(world: &RefCell<TestWorld>, expected: String) {
fn then_stderr_is(world: &RefCell<TestWorld>, expected: String) -> Result<()> {
let world = world.borrow();
let expected = expected.trim_matches('"');
assert_eq!(world.stderr_text(), expected);
assert_eq!(world.stderr_text()?, expected);
Ok(())
}

#[then("stderr contains {snippet}")]
fn then_stderr_contains(world: &RefCell<TestWorld>, snippet: String) {
fn then_stderr_contains(world: &RefCell<TestWorld>, snippet: String) -> Result<()> {
let world = world.borrow();
let stderr = world.stderr_text();
let stderr = world.stderr_text()?;
let snippet = snippet.trim_matches('"');
assert!(
stderr.contains(snippet),
"stderr {:?} did not contain {:?}",
stderr,
snippet
);
Ok(())
}

#[then("the CLI exits with code {status}")]
fn then_exit_code(world: &RefCell<TestWorld>, status: u8) {
world.borrow().assert_exit_code(status);
fn then_exit_code(world: &RefCell<TestWorld>, status: u8) -> Result<()> {
world.borrow().assert_exit_code(status)
}

#[then("the CLI fails")]
fn then_exit_failure(world: &RefCell<TestWorld>) {
world.borrow().assert_failure();
fn then_exit_failure(world: &RefCell<TestWorld>) -> Result<()> {
world.borrow().assert_failure()
}

#[then("capabilities output is {fixture}")]
fn then_capabilities(world: &RefCell<TestWorld>, fixture: String) {
world.borrow().assert_capabilities_output(&fixture);
fn then_capabilities(world: &RefCell<TestWorld>, fixture: String) -> Result<()> {
world.borrow().assert_capabilities_output(&fixture)
}

#[scenario(path = "tests/features/weaver_cli.feature")]
fn weaver_cli_behaviour(world: RefCell<TestWorld>) {
fn weaver_cli_behaviour(world: RefCell<TestWorld>) -> Result<()> {
let _ = world;
Ok(())
}
Loading