Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test suite page #68

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
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
30 changes: 16 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[workspace]
name = "orca"
members=[
members = [
"crates/libs/cerium",
"crates/libs/entity",
"crates/libs/migration",
Expand All @@ -12,7 +12,7 @@ members=[
]

[workspace.package]
authors = [ "Vasanth Kumar <mail@itsparser.in>" ]
authors = ["Vasanth Kumar <mail@itsparser.in>"]
edition = "2021"
version = "0.1.0"
license = "MIT OR Apache-2.0"
Expand All @@ -28,14 +28,14 @@ entity = { path = "crates/libs/entity", default-features = true }
migration = { path = "crates/libs/migration", default-features = true }
engine = { path = "crates/services/engine", default-features = true }
api = { path = "crates/services/api", default-features = true }
chrome = { path = "crates/workshop/chrome", default-features = true }
#chrome = { path = "crates/workshop/chrome", default-features = true }
entity_macro = { path = "crates/macro/entity-macro", default-features = true }

thiserror = "1.0.31"
jsonwebtoken = "9.2.0"
serde = { version = "1.0.147"}
serde = { version = "1.0.147" }
serde_json = "1.0.87"
chrono = { version = "0.4.31"}
chrono = { version = "0.4.31" }
tracing = "0.1.37"
tracing-subscriber = "0.3.16"
uuid = { version = "1.6.1", features = ["serde", "v4"] }
Expand All @@ -47,28 +47,30 @@ rust_decimal = "1.14.3"
cross-test = "0.1.6"

sea-query = "0.30.5"
sea-orm = { version = "0.12.3", features = [
"macros",
"debug-print",
"runtime-async-std-native-tls",
"sqlx-postgres",
sea-orm = { version = "0.12.3", features = [
"macros",
"debug-print",
"runtime-async-std-native-tls",
"sqlx-postgres",
] }
sea-orm-migration = {version = "0.12.3", features = ["sqlx-postgres"]}
sea-orm-migration = { version = "0.12.3", features = ["sqlx-postgres"] }

axum = "0.7.1"
axum-extra = "0.9.1"
tokio = { version = "1.34.0", features = ["full"] }
tower = "0.4.13"
tower-http = { version = "0.5.0", default-features = true, features = ["uuid", "cors", "trace", "compression-br", "catch-panic", "request-id"] }
#tower_governor = "0.3.2"


rust-s3 = "0.33.0"

thirtyfour = "0.31.0"

geckodriver="0.34.0"
geckodriver = "0.34.0"


[patch.crates-io]
sea-orm = { git="https://github.com/itsparser/sea-orm", branch = "master" }
sea-orm-migration = { git="https://github.com/itsparser/sea-orm", branch = "master" }
sea-orm = { git = "https://github.com/itsparser/sea-orm", branch = "master" }
sea-orm-migration = { git = "https://github.com/itsparser/sea-orm", branch = "master" }

39 changes: 20 additions & 19 deletions crates/libs/cerium/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,30 @@ default = []
#axum = ["dep:axum"]

[dependencies]
entity.workspace=true

tracing.workspace=true
tracing-subscriber.workspace=true
tokio.workspace=true
axum.workspace=true
axum-extra.workspace=true
tower.workspace=true
tower-http.workspace=true
config.workspace=true
sea-orm.workspace=true
sea-query.workspace=true
thirtyfour.workspace=true
chrono.workspace=true
jsonwebtoken.workspace=true
thiserror.workspace=true
serde.workspace=true
serde_json.workspace=true
rust-s3.workspace=true
entity.workspace = true

tracing.workspace = true
tracing-subscriber.workspace = true
tokio.workspace = true
axum.workspace = true
axum-extra.workspace = true
tower.workspace = true
tower-http.workspace = true
config.workspace = true
sea-orm.workspace = true
sea-query.workspace = true
thirtyfour.workspace = true
chrono.workspace = true
jsonwebtoken.workspace = true
thiserror.workspace = true
serde.workspace = true
serde_json.workspace = true
rust-s3.workspace = true

lazy_static = "1.4.0"
async_once = "0.2.6"
rand = { version = "0.8.5", default-features = false, features = ["std"] }
log = "0.4.20"
backtrace = "0.3.71"


7 changes: 4 additions & 3 deletions crates/libs/cerium/src/client/driver/web.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use thirtyfour::{CapabilitiesHelper, WebDriver as TFWebDriver};
use thirtyfour::{By, CapabilitiesHelper, DesiredCapabilities, WebElement};
use thirtyfour::WebDriver as TFWebDriver;

use crate::error::CeriumResult;
use thirtyfour::{By, DesiredCapabilities, WebElement};

#[derive(Clone)]
pub struct WebDriver {
Expand Down Expand Up @@ -30,13 +30,14 @@ impl WebDriver {
let helper = WebDriver { driver };
Ok(helper)
}

pub async fn session_id(&self) -> CeriumResult<String> {
Ok(self.driver.session_id().await?.clone().to_string())
}

pub async fn default() -> CeriumResult<Self> {
let mut caps = DesiredCapabilities::firefox();
caps.set_headless()?;
caps.add("se:recordVideo", true)?;
let driver = TFWebDriver::new("http://localhost:4444/wd/hub/session", caps).await?;
Self::new(driver)
Expand Down
10 changes: 7 additions & 3 deletions crates/libs/cerium/src/error/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use std::backtrace::Backtrace;

use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use axum::Json;
use axum::response::{IntoResponse, Response};
use s3::creds::error::CredentialsError;
use s3::error::S3Error;
use sea_orm::DbErr;
use serde_json::{json, Error as SerdeJsonError};
use serde_json::{Error as SerdeJsonError, json};
use thirtyfour::error::WebDriverError;
use thiserror::Error;
use tracing::error;

// pub use cerium::{CeriumError as OtherCeriumError, CeriumResult, ErrorResponse};
pub type CeriumResult<T> = Result<T, CeriumError>;
Expand All @@ -29,7 +32,6 @@ pub enum CeriumError {
#[error("CredentialsError error: {0}")]
S3Error(#[from] S3Error),


}

impl IntoResponse for CeriumError {
Expand All @@ -45,6 +47,8 @@ impl IntoResponse for CeriumError {
),
};

error!("Error: {}", Backtrace::force_capture());
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider logging backtraces conditionally to avoid potential performance issues. For example, you might only want to log backtraces for critical errors or when running in a debug environment.

- error!("Error: {}", Backtrace::force_capture());
+ if cfg!(debug_assertions) || matches!(self, CeriumError::CriticalError(_)) {
+     error!("Error: {}", Backtrace::force_capture());
+ }

This change helps to balance the need for detailed error information with the potential performance impact of capturing backtraces.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
error!("Error: {}", Backtrace::force_capture());
if cfg!(debug_assertions) || matches!(self, CeriumError::CriticalError(_)) {
error!("Error: {}", Backtrace::force_capture());
}


let body = Json(json!({
"error": error_message,
}));
Expand Down
33 changes: 28 additions & 5 deletions crates/libs/cerium/src/server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::sync::{Arc, Mutex};
use std::time::Duration;

use axum::{Router, serve};
use axum::http::{HeaderName, Method};
Expand All @@ -9,11 +10,13 @@ use tower_http::{
compression::CompressionLayer,
cors::{Any, CorsLayer},
};
use tower_http::classify::ServerErrorsFailureClass;
use tower_http::request_id::{PropagateRequestIdLayer, SetRequestIdLayer};
use tower_http::trace::TraceLayer;
use tracing::{info, Level};
use tracing_subscriber::fmt;
use tracing::{error, info, Level, Span};
use tracing_subscriber::{filter, fmt};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;

use crate::client::Client;
use crate::server::request_id::OrcaRequestId;
Expand Down Expand Up @@ -69,8 +72,19 @@ impl App {
/// let app = App::new("my_app", client);
/// app.set_logger(Level::INFO);
///
pub fn set_logger(&self, filter: Level) {
fmt().with_max_level(filter).init()
pub fn set_logger(&self, level: Level) {
let filter = filter::Targets::new()
.with_target("tower_http::trace::on_response", Level::TRACE)
.with_target("tower_http::trace::on_request", Level::TRACE)
.with_target("tower_http::trace::on_failure", Level::TRACE)
.with_target("tower_http::trace::make_span", Level::DEBUG)
.with_default(level);
let tracing_layer = tracing_subscriber::fmt::layer();

tracing_subscriber::registry()
.with(tracing_layer)
.with(filter)
.init();
// .with(tracing_subscriber::fmt::layer())
// .with_target(true)
// .with_timer(tracing_subscriber::fmt::time::uptime())
Expand Down Expand Up @@ -102,7 +116,16 @@ impl App {
.layer(cors)
.layer(CompressionLayer::new())
.layer(CatchPanicLayer::new())
.layer(TraceLayer::new_for_http());
.layer(
TraceLayer::new_for_http()
// .on_failure(|error: ServerErrorsFailureClass, latency: Duration, _span: &Span| {
// let mut error_msg = format!("something went wrong: {:?}", error);
// let backtrace = backtrace::Backtrace::new();
// error_msg.push_str("\nBacktrace:\n");
// // error_msg.push_str(&backtrace);
// error!("{:?} - {:?} - {:#?}", error_msg, latency, backtrace);
// })
);
Comment on lines +119 to +128
Copy link
Contributor

Choose a reason for hiding this comment

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

Finalize the error handling code in the TraceLayer or remove the commented-out sections if they are not intended for use.

- // .on_failure(|error: ServerErrorsFailureClass, latency: Duration, _span: &Span| {
- //     let mut error_msg = format!("something went wrong: {:?}", error);
- //     let backtrace = backtrace::Backtrace::new();
- //     error_msg.push_str("\nBacktrace:\n");
- //     // error_msg.push_str(&backtrace);
- //     error!("{:?} - {:?} - {:#?}", error_msg, latency, backtrace);
- // })

Leaving commented-out code can lead to confusion and clutter. If this code is part of an experimental feature or future implementation, consider adding a comment explaining its purpose.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
.layer(
TraceLayer::new_for_http()
// .on_failure(|error: ServerErrorsFailureClass, latency: Duration, _span: &Span| {
// let mut error_msg = format!("something went wrong: {:?}", error);
// let backtrace = backtrace::Backtrace::new();
// error_msg.push_str("\nBacktrace:\n");
// // error_msg.push_str(&backtrace);
// error!("{:?} - {:?} - {:#?}", error_msg, latency, backtrace);
// })
);
.layer(
TraceLayer::new_for_http()
);

self.router = router
}

Expand Down
11 changes: 7 additions & 4 deletions crates/libs/entity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ rust-version.workspace = true
[dependencies]
serde.workspace = true
serde_json.workspace = true
sea-orm.workspace=true
sea-query.workspace=true
chrono.workspace=true
entity_macro.workspace = true
sea-orm.workspace = true
sea-query.workspace = true
chrono.workspace = true
entity_macro.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
thiserror.workspace = true
43 changes: 40 additions & 3 deletions crates/libs/entity/src/admin/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,52 @@ use serde::{Deserialize, Serialize};
pub struct Model {
#[serde(skip_deserializing)]
#[sea_orm(primary_key)]
pub id: i32,
pub id: String,
pub name: String,
pub first_name: String,
pub last_name: Option<String>,
#[sea_orm(unique_key)]
pub email: String,
pub profile_url: String,
pub profile_url: Option<String>,

pub created_at: DateTimeWithTimeZone,
pub updated_at: DateTimeWithTimeZone,
pub deleted_at: Option<DateTimeWithTimeZone>,
pub created_by: Option<String>,
pub updated_by: Option<String>,

}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
pub enum Relation {
#[sea_orm(belongs_to = "Entity", from = "Column::CreatedBy", to = "Column::Id")]
CSelfReferencing,
#[sea_orm(belongs_to = "Entity", from = "Column::UpdatedBy", to = "Column::Id")]
USelfReferencing,
}

pub struct SelfReferencingLink;

impl Linked for SelfReferencingLink {
type FromEntity = Entity;

type ToEntity = Entity;

fn link(&self) -> Vec<RelationDef> {
vec![Relation::CSelfReferencing.def()]
}
}

pub struct USelfReferencingLink;

impl Linked for USelfReferencingLink {
type FromEntity = Entity;

type ToEntity = Entity;

fn link(&self) -> Vec<RelationDef> {
vec![Relation::USelfReferencing.def()]
}
}

impl ActiveModelBehavior for ActiveModel {}
16 changes: 3 additions & 13 deletions crates/libs/entity/src/app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,13 @@ pub struct Model {
pub id: Uuid,
pub name: String,
pub description: Option<String>,
// pub created_by: Uuid,
// pub updated_by: Uuid,

// pub created_by: String,
// pub updated_by: String,
// pub created_at: DateTimeWithTimeZone,
// pub updated_at: DateTimeWithTimeZone,
}

// impl ActiveModelBehavior for ActiveModel {
// async fn before_save<C>(mut self, _db: &C, _insert: bool) -> Result<Self, DbErr>
// where
// C: ConnectionTrait,
// {
// self.updated_at = Set(Utc::now().into());
// Ok(self)
// }
//
// }

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

Expand Down
3 changes: 3 additions & 0 deletions crates/libs/entity/src/ctx/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub trait RequestCtx {
fn get_user_id(&self) -> i32;
}
10 changes: 10 additions & 0 deletions crates/libs/entity/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use sea_orm::DbErr;
use thiserror::Error;

pub type EntityResult<T> = Result<T, EntityError>;

#[derive(Error, Debug)]
pub enum EntityError {
#[error("Failed to convert Active Model : {0}")]
FailedActiveModelConvert(DbErr),
}
3 changes: 3 additions & 0 deletions crates/libs/entity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ pub mod prelude;
pub mod test;
pub mod account;
pub mod api;
mod session;
mod error;
mod ctx;
Loading