refactor(tests): adding KMS test material generator with isolated tests infrastructure#270
Draft
refactor(tests): adding KMS test material generator with isolated tests infrastructure#270
Conversation
4054c6c to
8b35898
Compare
Consolidated Tests Results 2026-01-07 - 12:57:24Test ResultsDetails
test-reporter: Run #2211
❌ Some tests failed!
TestsView All Tests
🍂 No flaky tests in this run. Github Test Reporter by CTRF 💚 🔄 This comment has been updated |
9e041b2 to
61e950c
Compare
Contributor
Author
|
I temporarily triggered nightly k8s tests in chore(ci): temporary enable k8s tests which will be reverted once I see that these tests successfully executed within this PR |
…arty resharing test
15 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Description
This PR replaces Docker Compose-based integration tests with native isolated tests that run directly without Docker, improving test speed, reliability, and developer experience.
What Changed
Test Migration - Complete List
Migrates all Docker-based tests to native isolated execution:
1. Core Service Library Tests (
core/service/src/client/tests/)Centralized Isolated Tests (6 tests):
test_central_health_endpoint_availability_isolated- Health endpoint verificationtest_central_close_after_drop_isolated- Server shutdown on droptest_largecipher_isolated- Large ciphertext handling (slow_tests)test_insecure_central_dkg_backup_isolated- DKG backup/restoretest_insecure_central_autobackup_after_deletion_isolated- Auto-backup after deletionnightly_test_insecure_central_crs_backup_isolated- CRS backup/restore (nightly)Threshold Isolated Tests (14 tests):
test_insecure_dkg_isolated- Insecure DKG with Test params (4 parties)default_insecure_dkg_isolated- Insecure DKG with Default params (4 parties)secure_threshold_keygen_isolated- Secure keygen with preprocessing (PRSS)secure_threshold_keygen_crash_online_isolated- Crash recovery during online phasesecure_threshold_keygen_crash_preprocessing_isolated- Crash recovery during preprocessingtest_insecure_threshold_decompression_keygen_isolated- Decompression key generationtest_threshold_health_endpoint_availability_isolated- Health endpoint verificationtest_threshold_close_after_drop_isolated- Server shutdown on droptest_threshold_shutdown_isolated- Graceful shutdownnightly_test_insecure_threshold_dkg_backup_isolated- DKG backup/restore (nightly)nightly_test_insecure_threshold_autobackup_after_deletion_isolated- Auto-backup after deletion (nightly)test_insecure_threshold_crs_backup_isolated- CRS backup/restoretest_threshold_restore_from_backup_isolated- Threshold backup/restoretest_threshold_restore_from_backup_with_custodian_isolated- Custodian-based restoreExample Tests (4 tests):
test_centralized_isolated_example- Centralized test pattern demotest_threshold_isolated_example- Threshold test pattern demo (4 parties)test_different_material_types- Material type validationtest_material_validation- Material existence validation2. CLI Integration Tests (
core-client/tests/integration_tests.rs)Centralized CLI Tests (4 tests):
test_centralized_insecure- Keygen + decryption workflowtest_centralized_crsgen_secure- CRS generationtest_centralized_restore_from_backup- Backup/restore flowtest_centralized_custodian_backup- Custodian backup (5 custodians)Threshold CLI Tests (11 tests):
test_threshold_insecure- Insecure keygen + decryption with Default FHE params (4 parties, k8s_tests)test_threshold_concurrent_crs- Concurrent CRS generation (4 parties)nightly_tests_threshold_sequential_crs- Sequential CRS generation with Default FHE params (4 parties)test_threshold_restore_from_backup- Backup/restore flow (4 parties)test_threshold_custodian_backup- Custodian backup (5 custodians, 4 parties)nightly_tests_threshold_sequential_preproc_keygen- Sequential preprocessing with Test FHE params (PRSS, 4 parties, k8s_tests)test_threshold_concurrent_preproc_keygen- Concurrent preprocessing (PRSS, 4 parties, k8s_tests)full_gen_tests_default_threshold_sequential_preproc_keygen- Full keygen with Default FHE params (PRSS, 4 parties, k8s_tests)full_gen_tests_default_threshold_sequential_crs- Full CRS with Default FHE params (4 parties)test_threshold_mpc_context_init- MPC context initialization (4 parties, k8s_tests)test_threshold_mpc_context_switch_6- MPC context switching (6 parties, k8s_tests)Test Migration - Key Generation
Migrated all 6 threshold key generation tests to isolated infrastructure:
Migrated Tests:
test_insecure_dkg→test_insecure_dkg_isolateddefault_insecure_dkg→default_insecure_dkg_isolatedsecure_threshold_keygen_test→secure_threshold_keygen_isolatedsecure_threshold_keygen_test_crash_online→secure_threshold_keygen_crash_online_isolatedsecure_threshold_keygen_test_crash_preprocessing→secure_threshold_keygen_crash_preprocessing_isolatedtest_insecure_threshold_decompression_keygen→test_insecure_threshold_decompression_keygen_isolatedFile Reorganization:
key_gen_tests.rs→key_gen_helpers.rs(renamed to reflect purpose as helper library)#[ignore]with migration notesKey Features:
run_prss: trueKeySetConfigandKeySetAddedInfofor decompression keysFile Changes
Core Changes:
core-client/tests/integration_test.rs- Deleted (Docker-based)core-client/tests/integration_tests.rs- Added (Native isolated, 15 CLI tests)core/service/src/client/tests/centralized/*_isolated.rs- Added (5 tests)core/service/src/client/tests/threshold/key_gen_tests_isolated.rs- Added (6 keygen tests)core/service/src/client/tests/threshold/key_gen_helpers.rs- Renamed fromkey_gen_tests.rs(helper functions only)core/service/src/client/tests/threshold/misc_tests_isolated.rs- Added (3 tests)core/service/src/client/tests/threshold/restore_from_backup_tests_isolated.rs- Added (2 tests)core/service/src/client/tests/threshold/misc_tests.rs- Updated (removed 2 redundant tests)core/service/src/client/tests/threshold/restore_from_backup_tests.rs- Deleted (all tests redundant)core/service/src/client/tests/threshold/mod.rs- Updated (module declarations)core/service/src/client/tests/threshold/common.rs- Addedthreshold_key_gen_secure_isolatedhelpercore/service/src/client/tests/isolated_test_example.rs- Added (4 example tests)Testing Infrastructure:
core/service/src/testing/- New consolidated testing modulemod.rs- Module exports and preludeprelude.rs- Convenient imports for testssetup/centralized.rs-CentralizedTestEnvbuilder with.with_backup_vault()and.with_custodian_keychain()setup/threshold.rs-ThresholdTestEnvbuilder with helper methods and backup/custodian supportmaterial/manager.rs- Test material managementmaterial/spec.rs- Material specifications (TestMaterialSpec,MaterialType,KeyType)utils.rs- Test utility functions (health checks, encryption helpers, backup utilities)helpers.rs- Additional test helpers (domain_to_msg,create_test_material_manager)types.rs- Common test types (ServerHandle,TestResult)core/service/src/util/key_setup/mod.rs- Backward-compatible re-exports for legacy testscore/service/src/client/test_tools.rs- Legacy test infrastructure (marked for future refactoring)tools/generate-test-material/- Complete pre-generation tool with CLICI/CD Changes:
.github/workflows/main.yml- Updated test matrix with required features.github/workflows/common-testing.yml- Added test material generation + kms-custodian buildMakefile- Added test material generation and isolated test targets:generate-test-material-all- Generate all material (testing + default)generate-test-material-testing- Generate fast testing material onlygenerate-test-material-default- Generate production-like materialvalidate-test-material- Validate existing materialclean-test-material- Clean generated materialtest-isolated- Run all isolated teststest-isolated-centralized- Run centralized tests onlytest-isolated-threshold- Run threshold tests onlytest-isolated-integration- Run CLI integration testsbackward-compatibility/generate-v0.13.0/Cargo.toml- Updated to current branch commitHow It Works
Test Execution Flow
Native isolated tests run KMS servers as in-process native Rust processes (no Docker), with automatic lifecycle management:
Key Points:
Test Architecture
We have two complementary test architectures:
1. CLI Integration Tests (
core-client/tests/integration_tests.rs)Tests the actual CLI binary by spawning KMS servers and running CLI commands:
Use case: Testing CLI functionality end-to-end (binary + server interaction)
2. Library Tests (
core/service/src/client/tests/)Tests the KMS library directly using the builder pattern and gRPC clients:
Use case: Testing library functionality, crash scenarios, and complex multi-party protocols
Builder Features:
.with_backup_vault()- Creates backup storage for all parties.with_custodian_keychain()- Enables custodian-based key recovery.with_prss()- Enables PRSS for secure distributed operations.with_party_count(n)- Configures number of threshold parties.with_threshold(t)- Sets threshold value for reconstructionKey Features (Both Approaches):
Threshold Tests (Multi-Party):
For threshold tests, the setup returns a
HashMap<u32, ServerHandle>instead of a singleServerHandle:Each party runs as a separate native process with its own ports, simulating a real distributed threshold setup.
Test Material Generation
The test infrastructure includes a comprehensive pre-generation system that creates all cryptographic material needed for tests.
Test Material Tool (
tools/generate-test-material/)A standalone CLI tool that generates cryptographic material for isolated tests:
Key Features:
Material Types:
testing- Fast generation with Test parameters (default for local dev)default- Production-like generation with Default parameters (slower, for comprehensive testing)all- Generates both testing and default materialKey Types Generated:
ClientKeys- FHE client keysSigningKeys- Client signing keysServerSigningKeys- Server signing keysFheKeys- Complete FHE key setsCrsKeys- Common Reference String keysPublicKeys- Public key componentsDecompressionKeys- Decompression keys (slow_tests only)Note: PRSS (Pseudo-Random Secret Sharing) setup is not pre-generated. It's created at runtime when KMS servers start with
run_prss: truein the test configuration.Makefile Targets
Tool Usage
CI Integration
CI generates test material before running tests to avoid generation overhead:
Material Structure
Note: PRSS setup is not stored in test-material. It's generated at runtime by KMS servers when tests configure
run_prss: true.Testing Infrastructure Architecture
core/service/src/testing/- Test Infrastructurekmscratesetup/centralized.rs-CentralizedTestEnvbuilder with backup vault and custodian keychain supportsetup/threshold.rs-ThresholdTestEnvbuilder with helper methods:all_clients()- Iterate all clientsall_clients_except(party)- Exclude parties for crash simulationall_servers(),into_servers()- Server iteration and consumptionclient(party_id),server(party_id)- Access specific partiesmaterial/manager.rs- Test material copying and managementmaterial/spec.rs- Material specificationsutils.rs- Test helper functionshelpers.rs- Additional test helperstypes.rs- Common test typesprelude.rs- Convenient imports for tests#[cfg(all(feature = "non-wasm", any(test, feature = "testing")))]use kms_lib::testing::prelude::*;Example:
CI Configuration
Updated test matrix to include required features and proper test filtering:
Integration Tests (2 parallel jobs):
Feature Flags Explained:
k8s_tests- PRSS Test Gating#[cfg_attr(not(feature = "k8s_tests"), ignore)]on PRSS teststesting- Test Helper Functions#[cfg(any(test, feature = "testing"))]on helper modulesTestMaterialManager,setup_isolated_*functions, test material generationnon-wasm- Non-WebAssembly Buildstestingmodule uses tokio, tonic, file I/O (not available in WASM)#[cfg(all(feature = "non-wasm", any(test, feature = "testing")))]wasm32-unknown-unknowntarget)Feature flags - Two scenarios:
Scenario A: Run all tests (including PRSS):
k8s_tests: Enables PRSS tests (5 tests with network coordination)testing: Compiles test helper functions--test-threads=1: Sequential execution for PRSS testsScenario B: Run non-PRSS tests only:
k8s_tests)Why both features?
testing: Test code won't compile (helper functions are feature-gated)k8s_tests: PRSS tests will be ignored (safe for local development)Party counts: Most tests use 4 parties, one test uses 6 parties (MPC context switch)
Other Skips:
isolated_test_example- Demonstration tests (not part of test suite)k8s_- Kubernetes cluster tests (run separately inkind-testing.yml)nightly- Slow comprehensive tests (run only in scheduled builds)full_gen_tests- Full parameter tests (run only in scheduled builds)Unit Tests:
--features k8s_tests,testing -- --skip centralized --skip threshold --skip isolated_test_example --skip k8s_Nightly Tests (comprehensive, scheduled only):
--features k8s_tests,testing -- --skip k8s_ --skip isolated_test_examplenightly_*andfull_gen_tests_*Running Tests
Local Development
Developer Guide
Writing New Tests
Centralized Test:
Threshold Test:
PRSS Test (Sequential, K8s CI Only):
Library Test (Direct API, No CLI):
Issue ticket number and link
PR Checklist
I attest that all checked items are satisfied. Any deviation is clearly justified above.
chore: ...).TODO(#issue).unwrap/expect/paniconly in tests or for invariant bugs (documented if present).devopslabel + infra notified + infra-team reviewer assigned.!and affected teams notified.Zeroize+ZeroizeOnDropimplemented.unsafe; if unavoidable: minimal, justified, documented, and test/fuzz covered.Dependency Update Questionnaire (only if deps changed or added)
Answer in the
Cargo.tomlnext to the dependency (or here if updating):More details and explanations for the checklist and dependency updates can be found in CONTRIBUTING.md