api, cli, web, tsting env and some rust fixes

This commit is contained in:
dal 2025-04-29 10:37:37 -06:00
parent 0c5c9eafff
commit 19eea365a4
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
6 changed files with 69 additions and 61 deletions

View File

@ -13,6 +13,7 @@ on:
jobs: jobs:
test: test:
runs-on: blacksmith-16vcpu-ubuntu-2204 runs-on: blacksmith-16vcpu-ubuntu-2204
environment: testing
# Service container for Redis (needed by the setup action) # Service container for Redis (needed by the setup action)
services: services:
@ -42,9 +43,9 @@ jobs:
# Use hardcoded default values and secrets # Use hardcoded default values and secrets
DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres
REDIS_URL: redis://localhost:6379 # Connect to the Redis service container REDIS_URL: redis://localhost:6379 # Connect to the Redis service container
JWT_SECRET: ${{ secrets.GH_ACTIONS_SUPABASE_JWT_SECRET }} # Use secret JWT_SECRET: 'super-secret-jwt-token-with-at-least-32-characters-long' # Use default local value
SUPABASE_URL: http://127.0.0.1:54321 # Default local URL SUPABASE_URL: http://127.0.0.1:54321 # Default local URL
SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.GH_ACTIONS_SUPABASE_SERVICE_ROLE_KEY }} # Use secret SUPABASE_SERVICE_ROLE_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MjM0MzA5Nn0.EGgMpd9zvvHPCOq4DJRLwzJ1iS3GV4AEyzguXGcbEIY' # Use default local value
RUST_LOG: debug # Or adjust as needed RUST_LOG: debug # Or adjust as needed
# Sensitive values from Secrets # Sensitive values from Secrets

View File

@ -13,6 +13,7 @@ on:
jobs: jobs:
test: test:
runs-on: blacksmith-16vcpu-ubuntu-2204 # Using a powerful runner as requested runs-on: blacksmith-16vcpu-ubuntu-2204 # Using a powerful runner as requested
environment: testing # Add the environment key
# Service container for Redis (needed by the setup action) # Service container for Redis (needed by the setup action)
services: services:
@ -42,9 +43,9 @@ jobs:
# Use hardcoded default values and secrets # Use hardcoded default values and secrets
DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres
REDIS_URL: redis://localhost:6379 # Connect to the Redis service container REDIS_URL: redis://localhost:6379 # Connect to the Redis service container
JWT_SECRET: ${{ secrets.GH_ACTIONS_SUPABASE_JWT_SECRET }} # Use secret JWT_SECRET: 'super-secret-jwt-token-with-at-least-32-characters-long' # Use default local value
SUPABASE_URL: http://127.0.0.1:54321 # Default local URL SUPABASE_URL: http://127.0.0.1:54321 # Default local URL
SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.GH_ACTIONS_SUPABASE_SERVICE_ROLE_KEY }} # Use secret SUPABASE_SERVICE_ROLE_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MjM0MzA5Nn0.EGgMpd9zvvHPCOq4DJRLwzJ1iS3GV4AEyzguXGcbEIY' # Use default local value
RUST_LOG: debug # Or adjust as needed RUST_LOG: debug # Or adjust as needed
# Add any other environment variables your CLI tests might require # Add any other environment variables your CLI tests might require

View File

@ -13,6 +13,7 @@ on:
jobs: jobs:
test: test:
runs-on: blacksmith-16vcpu-ubuntu-2204 runs-on: blacksmith-16vcpu-ubuntu-2204
environment: testing
# Service container for Redis (needed by the setup action and potentially API) # Service container for Redis (needed by the setup action and potentially API)
services: services:
@ -56,9 +57,9 @@ jobs:
DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres
POOLER_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres # Assuming pooler uses same DB POOLER_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres # Assuming pooler uses same DB
REDIS_URL: redis://localhost:6379 # Use localhost as it runs on the runner accessing the service REDIS_URL: redis://localhost:6379 # Use localhost as it runs on the runner accessing the service
JWT_SECRET: ${{ secrets.GH_ACTIONS_SUPABASE_JWT_SECRET }} # Use secret JWT_SECRET: 'super-secret-jwt-token-with-at-least-32-characters-long' # Use default local value
SUPABASE_URL: http://127.0.0.1:54321 # Default local URL SUPABASE_URL: http://127.0.0.1:54321 # Default local URL
SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.GH_ACTIONS_SUPABASE_SERVICE_ROLE_KEY }} # Use secret SUPABASE_SERVICE_ROLE_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MjM0MzA5Nn0.EGgMpd9zvvHPCOq4DJRLwzJ1iS3GV4AEyzguXGcbEIY' # Use default local value
# Non-sensitive / Default values # Non-sensitive / Default values
ENVIRONMENT: development ENVIRONMENT: development
@ -104,7 +105,7 @@ jobs:
NEXT_PUBLIC_URL: http://localhost:3000 # Assuming default URL for the app itself NEXT_PUBLIC_URL: http://localhost:3000 # Assuming default URL for the app itself
# Use Supabase details - default URL and secret anon key # Use Supabase details - default URL and secret anon key
NEXT_PUBLIC_SUPABASE_URL: http://127.0.0.1:54321 # Default local URL NEXT_PUBLIC_SUPABASE_URL: http://127.0.0.1:54321 # Default local URL
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.GH_ACTIONS_SUPABASE_ANON_KEY }} # Use secret NEXT_PUBLIC_SUPABASE_ANON_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODIzNDMwOTZ9.7UIsMFfHYKxH7bUJCRfxd6lr7CSXGF7UxtZQO10FMMo' # Use default local value
NEXT_PUBLIC_WEB_SOCKET_URL: ws://localhost:3001 # Assuming WS connects to API NEXT_PUBLIC_WEB_SOCKET_URL: ws://localhost:3001 # Assuming WS connects to API
# Pass any other required NEXT_PUBLIC_ variables # Pass any other required NEXT_PUBLIC_ variables

View File

@ -3,12 +3,14 @@ use chrono::Utc;
use database::enums::{AssetPermissionRole, AssetType, Verification}; use database::enums::{AssetPermissionRole, AssetType, Verification};
use database::models::{Chat, Collection, DashboardFile, MetricFile}; use database::models::{Chat, Collection, DashboardFile, MetricFile};
use database::schema::{chats, collections, dashboard_files, metric_files}; use database::schema::{chats, collections, dashboard_files, metric_files};
use database::types::metric_yml::{
BarAndLineAxis, BarLineChartConfig, BaseChartConfig, ChartConfig,
};
use database::types::{DashboardYml, MetricYml, VersionHistory}; use database::types::{DashboardYml, MetricYml, VersionHistory};
use database::types::metric_yml::{BaseChartConfig, BarAndLineAxis, BarLineChartConfig, ChartConfig};
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use indexmap; use indexmap;
use uuid::Uuid;
use std::collections::HashMap; use std::collections::HashMap;
use uuid::Uuid;
use crate::common::db::TestDb; use crate::common::db::TestDb;
use crate::common::permissions::PermissionTestHelpers; use crate::common::permissions::PermissionTestHelpers;
@ -18,10 +20,7 @@ pub struct AssetTestHelpers;
impl AssetTestHelpers { impl AssetTestHelpers {
/// Creates a test metric file /// Creates a test metric file
pub async fn create_test_metric( pub async fn create_test_metric(test_db: &TestDb, name: &str) -> Result<MetricFile> {
test_db: &TestDb,
name: &str,
) -> Result<MetricFile> {
let mut conn = test_db.diesel_conn().await?; let mut conn = test_db.diesel_conn().await?;
let metric_id = Uuid::new_v4(); let metric_id = Uuid::new_v4();
@ -38,7 +37,11 @@ impl AssetTestHelpers {
let metric_file = MetricFile { let metric_file = MetricFile {
id: metric_id, id: metric_id,
name: format!("{}-{}", test_db.test_id, name), name: format!("{}-{}", test_db.test_id, name),
file_name: format!("{}-{}.yml", test_db.test_id, name.to_lowercase().replace(" ", "_")), file_name: format!(
"{}-{}.yml",
test_db.test_id,
name.to_lowercase().replace(" ", "_")
),
content, content,
verification: Verification::Verified, verification: Verification::Verified,
evaluation_obj: None, evaluation_obj: None,
@ -66,10 +69,7 @@ impl AssetTestHelpers {
} }
/// Creates a test dashboard file /// Creates a test dashboard file
pub async fn create_test_dashboard( pub async fn create_test_dashboard(test_db: &TestDb, name: &str) -> Result<DashboardFile> {
test_db: &TestDb,
name: &str,
) -> Result<DashboardFile> {
let mut conn = test_db.diesel_conn().await?; let mut conn = test_db.diesel_conn().await?;
let dashboard_id = Uuid::new_v4(); let dashboard_id = Uuid::new_v4();
@ -83,7 +83,11 @@ impl AssetTestHelpers {
let dashboard_file = DashboardFile { let dashboard_file = DashboardFile {
id: dashboard_id, id: dashboard_id,
name: format!("{}-{}", test_db.test_id, name), name: format!("{}-{}", test_db.test_id, name),
file_name: format!("{}-{}.yml", test_db.test_id, name.to_lowercase().replace(" ", "_")), file_name: format!(
"{}-{}.yml",
test_db.test_id,
name.to_lowercase().replace(" ", "_")
),
content, content,
filter: None, filter: None,
organization_id: test_db.organization_id, organization_id: test_db.organization_id,
@ -107,10 +111,7 @@ impl AssetTestHelpers {
} }
/// Creates a test collection /// Creates a test collection
pub async fn create_test_collection( pub async fn create_test_collection(test_db: &TestDb, name: &str) -> Result<Collection> {
test_db: &TestDb,
name: &str,
) -> Result<Collection> {
let mut conn = test_db.diesel_conn().await?; let mut conn = test_db.diesel_conn().await?;
let collection_id = Uuid::new_v4(); let collection_id = Uuid::new_v4();
@ -135,10 +136,7 @@ impl AssetTestHelpers {
} }
/// Creates a test chat /// Creates a test chat
pub async fn create_test_chat( pub async fn create_test_chat(test_db: &TestDb, title: &str) -> Result<Chat> {
test_db: &TestDb,
title: &str,
) -> Result<Chat> {
let mut conn = test_db.diesel_conn().await?; let mut conn = test_db.diesel_conn().await?;
let chat_id = Uuid::new_v4(); let chat_id = Uuid::new_v4();
@ -156,6 +154,7 @@ impl AssetTestHelpers {
public_expiry_date: None, public_expiry_date: None,
most_recent_file_id: None, most_recent_file_id: None,
most_recent_file_type: None, most_recent_file_type: None,
most_recent_version_number: None,
}; };
diesel::insert_into(chats::table) diesel::insert_into(chats::table)
@ -182,7 +181,8 @@ impl AssetTestHelpers {
AssetType::MetricFile, AssetType::MetricFile,
user_id, user_id,
role, role,
).await?; )
.await?;
Ok(metric) Ok(metric)
} }
@ -203,7 +203,8 @@ impl AssetTestHelpers {
AssetType::DashboardFile, AssetType::DashboardFile,
user_id, user_id,
role, role,
).await?; )
.await?;
Ok(dashboard) Ok(dashboard)
} }
@ -224,7 +225,8 @@ impl AssetTestHelpers {
AssetType::Collection, AssetType::Collection,
user_id, user_id,
role, role,
).await?; )
.await?;
Ok(collection) Ok(collection)
} }
@ -245,7 +247,8 @@ impl AssetTestHelpers {
AssetType::Chat, AssetType::Chat,
user_id, user_id,
role, role,
).await?; )
.await?;
Ok(chat) Ok(chat)
} }

View File

@ -93,6 +93,7 @@ impl TestDb {
created_at: Utc::now(), created_at: Utc::now(),
updated_at: Utc::now(), updated_at: Utc::now(),
deleted_at: None, deleted_at: None,
payment_required: false,
}; };
let mut conn = self.diesel_conn().await?; let mut conn = self.diesel_conn().await?;

View File

@ -41,6 +41,7 @@ impl TestSetup {
created_at: chrono::Utc::now(), created_at: chrono::Utc::now(),
updated_at: chrono::Utc::now(), updated_at: chrono::Utc::now(),
deleted_at: None, deleted_at: None,
payment_required: false,
}; };
// Create user with specified role // Create user with specified role