Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
79 changes: 75 additions & 4 deletions crates/forge-runner/src/package_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,20 @@ impl TestDetails {
}
}

// TODO: Remove in next PRs
#[derive(Debug, Clone)]
pub struct TestTarget<C> {
pub struct TestTargetDeprecated<C> {
pub tests_location: TestTargetLocation,
pub sierra_program: ProgramArtifact,
pub sierra_program_path: Arc<Utf8PathBuf>,
pub casm_program: Arc<RawCasmProgram>,
pub test_cases: Vec<TestCase<C>>,
}

impl TestTarget<TestCaseWithConfig> {
// TODO: Remove in next PRs
impl TestTargetDeprecated<TestCaseWithConfig> {
#[tracing::instrument(skip_all, level = "debug")]
pub fn from_raw(
pub fn from_raw_deprecated(
test_target_raw: TestTargetRaw,
tracked_resource: &ForgeTrackedResource,
) -> Result<TestTargetWithConfig> {
Expand Down Expand Up @@ -200,7 +202,7 @@ impl TestTarget<TestCaseWithConfig> {
test_cases,
sierra_program: test_target_raw.sierra_program,
sierra_program_path: test_target_raw.sierra_program_path.into(),
casm_program,
casm_program: casm_program,
})
}
}
Expand All @@ -211,3 +213,72 @@ pub struct TestCase<C> {
pub name: String,
pub config: C,
}

#[derive(Debug, Clone)]
pub struct TestTarget<T> {
pub tests_location: TestTargetLocation,
pub sierra_program: ProgramArtifact,
pub sierra_program_path: Arc<Utf8PathBuf>,
pub casm_program: Option<Arc<RawCasmProgram>>,
pub test_cases: Vec<T>,
}

impl TestTarget<TestCandidate> {
#[tracing::instrument(skip_all, level = "debug")]
pub fn from_raw(test_target_raw: TestTargetRaw) -> Result<TestTarget<TestCandidate>> {
Copy link
Contributor Author

@franciszekjob franciszekjob Nov 6, 2025

Choose a reason for hiding this comment

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

note: It's the same as from_raw_deprecated but:

  • we don't compile sierra to CASM
  • we don't perform config run

macro_rules! by_id {
($field:ident) => {{
let temp: HashMap<_, _> = test_target_raw
.sierra_program
.program
.$field
.iter()
.map(|f| (f.id.id, f))
.collect();

temp
}};
}
let funcs = by_id!(funcs);
let type_declarations = by_id!(type_declarations);

let sierra_program_registry =
ProgramRegistry::<CoreType, CoreLibfunc>::new(&test_target_raw.sierra_program.program)?;
let type_size_map = get_type_size_map(
&test_target_raw.sierra_program.program,
&sierra_program_registry,
)
.ok_or_else(|| anyhow!("can not get type size map"))?;

let default_executables = vec![];
let debug_info = test_target_raw.sierra_program.debug_info.clone();
let executables = debug_info
.as_ref()
.and_then(|info| info.executables.get("snforge_internal_test_executable"))
.unwrap_or(&default_executables);

let test_cases = executables
.par_iter()
.map(|case| {
let func = funcs[&case.id];
let name = case.debug_name.clone().unwrap().into();
let test_details = TestDetails::build(func, &type_declarations, &type_size_map);

Ok(TestCandidate { name, test_details })
})
.collect::<Result<_>>()?;

Ok(TestTarget {
tests_location: test_target_raw.tests_location,
test_cases,
sierra_program: test_target_raw.sierra_program,
sierra_program_path: test_target_raw.sierra_program_path.into(),
casm_program: None,
})
}
}

pub struct TestCandidate {
pub name: String,
pub test_details: TestDetails,
}
Comment on lines +281 to +284
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: We can easily add partition field which will be later used while filtering.

4 changes: 2 additions & 2 deletions crates/forge-runner/src/package_tests/with_config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{TestCase, TestTarget};
use super::{TestCase, TestTargetDeprecated};
use crate::{
TestCaseIsIgnored,
expected_result::{ExpectedPanicValue, ExpectedTestResult},
Expand All @@ -9,7 +9,7 @@ use cheatnet::runtime_extensions::forge_config_extension::config::{
};
use conversions::serde::serialize::SerializeToFeltVec;

pub type TestTargetWithConfig = TestTarget<TestCaseConfig>;
pub type TestTargetWithConfig = TestTargetDeprecated<TestCaseConfig>;

pub type TestCaseWithConfig = TestCase<TestCaseConfig>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{TestCase, TestTarget};
use super::{TestCase, TestTargetDeprecated};
use crate::{TestCaseIsIgnored, expected_result::ExpectedTestResult, package_tests::TestDetails};
use anyhow::Result;
use cairo_vm::types::program::Program;
Expand All @@ -9,7 +9,7 @@ use starknet_api::block::BlockNumber;
use universal_sierra_compiler_api::representation::RawCasmProgram;
use url::Url;

pub type TestTargetWithResolvedConfig = TestTarget<TestCaseResolvedConfig>;
pub type TestTargetWithResolvedConfig = TestTargetDeprecated<TestCaseResolvedConfig>;

pub type TestCaseWithResolvedConfig = TestCase<TestCaseResolvedConfig>;

Expand Down
5 changes: 3 additions & 2 deletions crates/forge/src/run_tests/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ use console::Style;
use forge_runner::{
forge_config::ForgeConfig,
package_tests::{
TestTarget, raw::TestTargetRaw, with_config_resolved::TestTargetWithResolvedConfig,
TestTargetDeprecated, raw::TestTargetRaw,
with_config_resolved::TestTargetWithResolvedConfig,
},
test_case_summary::AnyTestCaseSummary,
test_target_summary::TestTargetSummary,
Expand Down Expand Up @@ -144,7 +145,7 @@ async fn test_package_with_config_resolved(
let mut test_targets_with_resolved_config = Vec::with_capacity(test_targets.len());

for test_target in test_targets {
let test_target = TestTarget::from_raw(
let test_target = TestTargetDeprecated::from_raw_deprecated(
test_target,
&forge_config.test_runner_config.tracked_resource,
)?;
Expand Down
36 changes: 36 additions & 0 deletions crates/forge/src/run_tests/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@ use super::package::RunForPackageArgs;
use crate::run_tests::messages::latest_blocks_numbers::LatestBlocksNumbersMessage;
use crate::run_tests::messages::tests_failure_summary::TestsFailureSummaryMessage;
use crate::run_tests::messages::workspace_summary::WorkspaceSummaryMessage;
use crate::scarb::load_test_artifacts;
use crate::{
ExitStatus, TestArgs, block_number_map::BlockNumberMap, run_tests::package::run_for_package,
scarb::build_artifacts_with_scarb, shared_cache::FailedTestsCache,
};
use anyhow::{Context, Result};
use camino::Utf8PathBuf;
use forge_runner::package_tests::{TestCandidate, TestTarget};
use forge_runner::test_case_summary::AnyTestCaseSummary;
use forge_runner::{CACHE_DIR, test_target_summary::TestTargetSummary};
use foundry_ui::UI;
use scarb_api::{
metadata::{Metadata, PackageMetadata},
target_dir_for_workspace,
};
use scarb_metadata::PackageId;
use scarb_ui::args::PackagesFilter;
use shared::consts::SNFORGE_TEST_FILTER;
use std::collections::HashMap;
use std::env;
use std::sync::Arc;

Expand All @@ -42,6 +46,38 @@ impl WorkspaceDirs {
}
}

#[expect(dead_code)]
struct PackageData {
metadata: PackageMetadata,
test_targets: Vec<TestTarget<TestCandidate>>,
}

pub struct Workspace(HashMap<PackageId, PackageData>);

impl Workspace {
pub fn new(workspace_dirs: &WorkspaceDirs, packages: &[PackageMetadata]) -> Result<Self> {
let mut result = Workspace(HashMap::new());

for package in packages {
let test_targets_raw = load_test_artifacts(&workspace_dirs.artifacts_dir, &package)?;
let test_targets = test_targets_raw
.into_iter()
.map(|raw| TestTarget::from_raw(raw))
.collect::<Result<Vec<_>>>()?;

result.0.insert(
package.id.clone(),
PackageData {
metadata: package.clone(),
test_targets: test_targets,
},
);
}

Ok(result)
}
}

#[tracing::instrument(skip_all, level = "debug")]
pub async fn run_for_workspace(
scarb_metadata: &Metadata,
Expand Down
Loading