tests for steel in post request is fixed with all the errors found in the codebase

This commit is contained in:
filipriec
2025-07-08 22:04:11 +02:00
parent 2311fbaa3b
commit 26898d474f
3 changed files with 672 additions and 916 deletions

View File

@@ -1,4 +1,4 @@
// Updated src/steel/server/execution.rs
// src/steel/server/execution.rs
use steel::steel_vm::engine::Engine;
use steel::steel_vm::register_fn::RegisterFn;
use steel::rvals::SteelVal;
@@ -40,6 +40,10 @@ pub fn execute_script(
// Register all decimal math functions using the steel_decimal crate
register_decimal_math_functions(&mut vm);
// IMPORTANT: Register variables from the context with the Steel VM
// This makes the get-var function available with the actual variable values
FunctionRegistry::register_variables(&mut vm, context.row_data.clone());
// Execute script and process results
let results = vm.compile_and_run_raw_program(script)
.map_err(|e| ExecutionError::RuntimeError(e.to_string()))?;

View File

@@ -149,9 +149,27 @@ pub async fn post_table_data(
let expected_value = script_output.pop()
.ok_or_else(|| Status::internal("Script returned no values"))?;
if user_value != &expected_value {
// FIX: Compare as Decimal numbers, not strings!
// Parse the user's value into a Decimal
let user_decimal = Decimal::from_str(user_value).map_err(|_| {
Status::invalid_argument(format!(
"Invalid decimal format provided for column '{}': {}",
target_column, user_value
))
})?;
// Parse the script's calculated value into a Decimal
let expected_decimal = Decimal::from_str(&expected_value).map_err(|_| {
Status::internal(format!(
"Script for column '{}' produced an invalid decimal format: {}",
target_column, expected_value
))
})?;
// Now compare the actual numbers - this correctly sees that 76.5 == 76.50
if user_decimal != expected_decimal {
return Err(Status::invalid_argument(format!(
"Validation failed for column '{}': Expected '{}', Got '{}'",
"Validation failed for column '{}': Script calculated '{}', but user provided '{}'",
target_column, expected_value, user_value
)));
}