Skip to content

Commit

Permalink
Proposed fix: configuring and formatting project. (#229)
Browse files Browse the repository at this point in the history
* Adding .editorconfig and rustfmt.toml

* Formatting workspace with 'cargo fmt'

* Revert "Formatting workspace with 'cargo fmt'"

This reverts commit c96323d.

* Adding @generated annotation to generator.rs

* Re-generating files to add annotation

* Adding `cargo fmt` alias

* Refactoring rustfmt.toml and .editorconfig

* Configuring Rust CI

* Merging clippy.yml workflow into rust.yml

* Formatting workspace
  • Loading branch information
oestradiol authored Sep 19, 2024
1 parent 0fba093 commit 3de9048
Show file tree
Hide file tree
Showing 283 changed files with 744 additions and 1,676 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[alias]
fmt-no-gen = "fmt -- --config format_generated_files=false"
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
max_line_length = 100

[*.md]
indent_size = 2

[*.{yml, yaml}]
indent_size = 2
33 changes: 33 additions & 0 deletions .github/rust.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"problemMatcher": [
{
"owner": "rustfmt",
"severity": "warning",
"pattern": [
{
"regexp": "^(Diff in (.+)) at line (\\d+):$",
"message": 1,
"file": 2,
"line": 3
}
]
},
{
"owner": "clippy",
"pattern": [
{
"regexp": "^(?:\\x1b\\[[\\d;]+m)*(warning|warn|error)(?:\\x1b\\[[\\d;]+m)*(\\[(.*)\\])?(?:\\x1b\\[[\\d;]+m)*:(?:\\x1b\\[[\\d;]+m)* ([^\\x1b]*)(?:\\x1b\\[[\\d;]+m)*$",
"severity": 1,
"message": 4,
"code": 3
},
{
"regexp": "^(?:\\x1b\\[[\\d;]+m)*\\s*(?:\\x1b\\[[\\d;]+m)*\\s*--> (?:\\x1b\\[[\\d;]+m)*(.*):(\\d*):(\\d*)(?:\\x1b\\[[\\d;]+m)*$",
"file": 1,
"line": 2,
"column": 3
}
]
}
]
}
18 changes: 0 additions & 18 deletions .github/workflows/clippy.yml

This file was deleted.

39 changes: 35 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Rust
name: Rust CI

on:
push:
Expand All @@ -8,11 +8,42 @@ on:

env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
RUSTUP_MAX_RETRIES: 10
RUST_BACKTRACE: short
RUSTFLAGS: "-D warnings"

jobs:
build:
rust:
name: Rust
runs-on: ubuntu-latest

strategy:
fail-fast: false

steps:
- uses: actions/checkout@v4
- name: Build
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1

# https://github.com/actions-rust-lang/setup-rust-toolchain/blob/main/rust.json
- name: Install Rust Problem Matcher
run: echo "::add-matcher::.github/rust.json"

- name: Bump opt-level
run: sed -i '/\[profile.dev]/a opt-level=1' Cargo.toml

- name: Compile (rust-analyzer)
run: cargo build --verbose

- name: Lint (clippy)
uses: giraffate/clippy-action@v1
with:
reporter: "github-pr-check"
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Format (rustfmt)
run: cargo fmt-no-gen --check
75 changes: 18 additions & 57 deletions atrium-api/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,12 @@ mod tests {
}
}
if body.is_empty() {
Ok(builder
.status(http::StatusCode::UNAUTHORIZED)
.body(serde_json::to_vec(
&atrium_xrpc::error::ErrorResponseBody {
error: Some(String::from("AuthenticationRequired")),
message: Some(String::from("Invalid identifier or password")),
},
)?)?)
Ok(builder.status(http::StatusCode::UNAUTHORIZED).body(serde_json::to_vec(
&atrium_xrpc::error::ErrorResponseBody {
error: Some(String::from("AuthenticationRequired")),
message: Some(String::from("Invalid identifier or password")),
},
)?)?)
} else {
Ok(builder.status(http::StatusCode::OK).body(body)?)
}
Expand Down Expand Up @@ -320,25 +318,17 @@ mod tests {
..Default::default()
};
let agent = AtpAgent::new(client, MemorySessionStore::default());
agent
.login("test", "pass")
.await
.expect("login should be succeeded");
agent.login("test", "pass").await.expect("login should be succeeded");
assert_eq!(agent.get_session().await, Some(session_data.into()));
}
// failure with `createSession` error
{
let client = MockClient {
responses: MockResponses {
..Default::default()
},
responses: MockResponses { ..Default::default() },
..Default::default()
};
let agent = AtpAgent::new(client, MemorySessionStore::default());
agent
.login("test", "bad")
.await
.expect_err("login should be failed");
agent.login("test", "bad").await.expect_err("login should be failed");
assert_eq!(agent.get_session().await, None);
}
}
Expand Down Expand Up @@ -409,11 +399,7 @@ mod tests {
.expect("get session should be succeeded");
assert_eq!(output.did.as_str(), "did:web:example.com");
assert_eq!(
agent
.store
.get_session()
.await
.map(|session| session.data.access_jwt),
agent.store.get_session().await.map(|session| session.data.access_jwt),
Some("access".into())
);
}
Expand Down Expand Up @@ -456,11 +442,7 @@ mod tests {
assert_eq!(output.did.as_str(), "did:web:example.com");
}
assert_eq!(
agent
.store
.get_session()
.await
.map(|session| session.data.access_jwt),
agent.store.get_session().await.map(|session| session.data.access_jwt),
Some("access".into())
);
assert_eq!(
Expand Down Expand Up @@ -511,9 +493,7 @@ mod tests {
// failure with `getSession` error
{
let client = MockClient {
responses: MockResponses {
..Default::default()
},
responses: MockResponses { ..Default::default() },
..Default::default()
};
let agent = AtpAgent::new(client, MemorySessionStore::default());
Expand Down Expand Up @@ -549,11 +529,7 @@ mod tests {
let agent = AtpAgent::new(client, MemorySessionStore::default());
agent
.resume_session(
OutputData {
access_jwt: "expired".into(),
..session_data.clone()
}
.into(),
OutputData { access_jwt: "expired".into(), ..session_data.clone() }.into(),
)
.await
.expect("resume_session should be succeeded");
Expand Down Expand Up @@ -599,15 +575,9 @@ mod tests {
..Default::default()
};
let agent = AtpAgent::new(client, MemorySessionStore::default());
agent
.login("test", "pass")
.await
.expect("login should be succeeded");
agent.login("test", "pass").await.expect("login should be succeeded");
assert_eq!(agent.get_endpoint().await, "https://bsky.social");
assert_eq!(
agent.api.com.atproto.server.xrpc.base_uri(),
"https://bsky.social"
);
assert_eq!(agent.api.com.atproto.server.xrpc.base_uri(), "https://bsky.social");
}
// invalid services
{
Expand Down Expand Up @@ -640,16 +610,10 @@ mod tests {
..Default::default()
};
let agent = AtpAgent::new(client, MemorySessionStore::default());
agent
.login("test", "pass")
.await
.expect("login should be succeeded");
agent.login("test", "pass").await.expect("login should be succeeded");
// not updated
assert_eq!(agent.get_endpoint().await, "http://localhost:8080");
assert_eq!(
agent.api.com.atproto.server.xrpc.base_uri(),
"http://localhost:8080"
);
assert_eq!(agent.api.com.atproto.server.xrpc.base_uri(), "http://localhost:8080");
}
}

Expand Down Expand Up @@ -712,10 +676,7 @@ mod tests {

assert_eq!(
agent.get_labelers_header().await,
Some(vec![
String::from("did:plc:test1;redact"),
String::from("did:plc:test2")
])
Some(vec![String::from("did:plc:test1;redact"), String::from("did:plc:test2")])
);
}

Expand Down
Loading

0 comments on commit 3de9048

Please sign in to comment.