Skip to content

Conversation

@thcsomebody
Copy link
Contributor

Adds a 7-phase Web4 CLI functional test suite and orchestrator.

Files added:

  • zhtp-cli/scripts/run_web4_functional_tests.sh
  • zhtp-cli/tests/web4_functional/* (01..07, generate_test_site.sh, README.md)
  • zhtp-cli/tests/web4_functional_bug_report_template.md

Notes:

  • Scripts currently call the CLI via 'cargo run' placeholders. Update 'CARGO_RUN' to point at a built binary or install Rust to run in CI/local.
  • The suite writes temporary state under tmp/web4_functional/.

This PR implements the testing framework for issue #537 and requests review from the CLI and QA teams.

- Implement core DevelopmentGrants contract with fee collection and governance-controlled disbursements
- Add comprehensive type definitions: ProposalId, Amount, Recipient, Disbursement
- Enforce all 10 invariant sections:
  * Fee routing validation (F1, F2): Passive receiver with amount > 0 check
  * Account balance conservation (A1, A2, A3): balance = fees - disbursements, append-only ledger
  * Governance authority (G1, G2, G3): Governance-only, proposal binding, replay protection
  * State mutation (S1, S3): Deterministic, no reentrancy risk
  * Boundary conditions: Overflow/underflow checks, edge cases
  * Year-5 target (T2): Correctly non-enforceable at contract level
  * Upgrade compatibility (U1): Serializable state for persistence
  * Read-only registry (U2): No external contract calls
  * Failure modes: All errors halt execution explicitly
  * Security boundary: No arbitrary withdrawals, governance-only control
- Add 13 comprehensive unit tests covering all invariant classes
- All tests passing (100% pass rate)
…nts)

- Add comprehensive Web4 CLI functional test suite
- Implement 7-phase testing (Registration → Deployment → Persistence → Updates → Rollback → Deletion → Error Handling)
- Create automated test site generator with version tracking
- Add CLI command wrappers with proper parsing
- Implement state verification and persistence testing
- Add comprehensive error handling and edge case testing
- Include bug report template and test documentation
- Test manifest architecture (web4_manifest_cid vs manifest_cid)
- Validate persistence across node restarts (CRITICAL requirement)
- Test version rollback functionality
- Verify domain registration/deletion workflows
- All tests use proper CLI command execution and validation

Test Files:
- web4_functional.rs: 28+ test scenarios across 7 phases
- web4_functional/test_env.rs: Isolated test environment management
- web4_functional/cli_executor.rs: CLI command wrapper with parsing
- web4_functional/site_generator.rs: Automated test site creation
- web4_functional/state_verifier.rs: State verification utilities
- scripts/run_web4_functional_tests.sh: Automated test runner with reporting
- tests/WEB4_FUNCTIONAL_TESTING.md: Complete testing documentation
- tests/web4_functional_bug_report_template.md: Bug report template

Completes requirement: Test: Web4 CLI Complete Functional Testing (Domains & Deployments) #537
@thcsomebody thcsomebody force-pushed the feature/web4-cli-complete-functional-testing branch from 5416f2b to 3e8dcac Compare January 7, 2026 17:51
Resolved conflicts: kept development versions for dev_grants module and contracts mod
@umwelt umwelt requested a review from Copilot January 14, 2026 11:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a comprehensive 7-phase functional testing suite for the Web4 CLI's domain and deployment functionality, fulfilling requirement #537. The implementation includes 28+ test scenarios, supporting infrastructure modules (TestEnv, CliExecutor, SiteGenerator, StateVerifier), automated test execution scripts, and extensive documentation including a bug report template.

Changes:

  • Added complete Web4 CLI functional test suite with 7 testing phases covering the full lifecycle from registration through deletion
  • Implemented modular test infrastructure for environment isolation, CLI execution, test site generation, and state verification
  • Created automated test runner script with phase-based execution and comprehensive reporting

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
web4_functional.rs Main test suite with 28+ scenarios across 7 phases plus integration tests
web4_functional/mod.rs Module exports for test infrastructure components
web4_functional/test_env.rs Isolated test environment management with temp directories
web4_functional/cli_executor.rs CLI command execution wrapper with result parsing
web4_functional/site_generator.rs Automated test website generation utilities
web4_functional/state_verifier.rs State verification and assertion helpers
run_web4_functional_tests.sh Bash script for automated phase-based test execution
WEB4_FUNCTIONAL_TESTING.md Comprehensive 730-line testing guide with examples
IMPLEMENTATION_SUMMARY.md Executive summary of implementation details and status
TEST_FILES_INDEX.md Quick reference index for all test-related files
web4_functional_bug_report_template.md Structured bug reporting template

Comment on lines 52 to 60
let manifest = self.get_manifest(domain)?;

for field in required_fields {
if !manifest.contains_key(*field) {
return false;
}
}

true
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The manifest_has_fields method uses the ? operator on a method that returns Option<T>, but the method itself returns bool. This will cause a compilation error. Use match or if let instead to handle the Option properly.

Suggested change
let manifest = self.get_manifest(domain)?;
for field in required_fields {
if !manifest.contains_key(*field) {
return false;
}
}
true
if let Some(manifest) = self.get_manifest(domain) {
for field in required_fields {
if !manifest.contains_key(*field) {
return false;
}
}
true
} else {
false
}

Copilot uses AI. Check for mistakes.

/// Verify persistence: check if state is identical after restart
pub fn verify_persistence(&self, domain: &str, original_state: &serde_json::Map<String, Value>) -> bool {
let current_state = self.get_manifest(domain)?;
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The verify_persistence method uses the ? operator on a method that returns Option<T>, but the method itself returns bool. This will cause a compilation error. Use match or if let instead to handle the Option properly.

Suggested change
let current_state = self.get_manifest(domain)?;
let current_state = match self.get_manifest(domain) {
Some(state) => state,
None => return false,
};

Copilot uses AI. Check for mistakes.
Comment on lines 47 to 48
mod support;
use support::{TestEnv, CliExecutor, SiteGenerator, StateVerifier};
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The module name 'support' is ambiguous. Consider renaming to 'web4_functional' to match the directory name and make the purpose clearer.

Suggested change
mod support;
use support::{TestEnv, CliExecutor, SiteGenerator, StateVerifier};
#[path = "support.rs"]
mod web4_functional_support;
use web4_functional_support::{TestEnv, CliExecutor, SiteGenerator, StateVerifier};

Copilot uses AI. Check for mistakes.
Comment on lines 126 to 127
let result = cli.deploy_site("simple.web4.test", &site_path);
assert!(result.success, "Deployment failed: {}", result.output);
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

Variable name 'result' is reused multiple times in the same test. Consider using more descriptive names like 'deploy_result' or making the variable name unique for better clarity.

Suggested change
let result = cli.deploy_site("simple.web4.test", &site_path);
assert!(result.success, "Deployment failed: {}", result.output);
let deploy_result = cli.deploy_site("simple.web4.test", &site_path);
assert!(deploy_result.success, "Deployment failed: {}", deploy_result.output);

Copilot uses AI. Check for mistakes.
Comment on lines 126 to 127
let result = cli.deploy_site("simple.web4.test", &site_path);
assert!(result.success, "Deployment failed: {}", result.output);
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

Variable name 'result' is reused multiple times in the same test. Consider using more descriptive names like 'deploy_result' or making the variable name unique for better clarity.

Suggested change
let result = cli.deploy_site("simple.web4.test", &site_path);
assert!(result.success, "Deployment failed: {}", result.output);
let deploy_result = cli.deploy_site("simple.web4.test", &site_path);
assert!(deploy_result.success, "Deployment failed: {}", deploy_result.output);

Copilot uses AI. Check for mistakes.
log_success "All required dependencies found"
}

build_tests() {
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The variable BUILD_MODE is referenced but never initialized in the script before this point. It should be initialized at the top of the script or passed as a parameter to the function.

Copilot uses AI. Check for mistakes.
cd "$PROJECT_ROOT"

local build_cmd="cargo build --tests"
if [[ "$BUILD_MODE" == "release" ]]; then
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The variable BUILD_MODE is referenced but never initialized in the script before this point. It should be initialized at the top of the script or passed as a parameter to the function.

Copilot uses AI. Check for mistakes.
Comment on lines 126 to 127
let result = cli.deploy_site("simple.web4.test", &site_path);
assert!(result.success, "Deployment failed: {}", result.output);
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

In line 126, the variable is named 'result' but on line 122 in the same function a different operation also uses 'result'. Consider using 'deploy_result' to distinguish the deployment result from the registration result.

Suggested change
let result = cli.deploy_site("simple.web4.test", &site_path);
assert!(result.success, "Deployment failed: {}", result.output);
let deploy_result = cli.deploy_site("simple.web4.test", &site_path);
assert!(deploy_result.success, "Deployment failed: {}", deploy_result.output);

Copilot uses AI. Check for mistakes.
@umwelt
Copy link
Contributor

umwelt commented Jan 14, 2026

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Contributor

Copilot AI commented Jan 14, 2026

@umwelt I've opened a new pull request, #775, to work on those changes. Once the pull request is ready, I'll request review from you.

…tional tests (#775)

* Initial plan

* fix: Apply code review fixes for Web4 functional tests

- Fix compilation errors in state_verifier.rs (? operator in bool methods)
- Rename 'support' module to 'web4_functional_support' for clarity
- Improve variable naming (result -> deploy_result)
- Initialize BUILD_MODE variable in test runner script

Co-authored-by: umwelt <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: umwelt <[email protected]>
@sonarqubecloud
Copy link

@umwelt umwelt merged commit eb77821 into development Jan 14, 2026
5 checks passed
@umwelt umwelt deleted the feature/web4-cli-complete-functional-testing branch January 14, 2026 13:00
umwelt added a commit that referenced this pull request Jan 14, 2026
Merged latest development changes including:
- Phase 1: Complete All 5 Critical Blockchain Issues (#779)
- SOV Management CLI Commands (Issue #622) (#777)
- Web4 CLI Complete Functional Testing (#647)

Resolved conflicts:
- lib-blockchain/src/blockchain.rs: Kept both UTXO snapshots and fork recovery features
- lib-blockchain/src/fork_recovery.rs: Used improved version with better documentation
- lib-blockchain/src/contracts/economics/fee_router.rs: Used cleaner validation
- lib-blockchain/src/contracts/governance/governance.rs: Used checked arithmetic
- lib-blockchain/tests/blockchain_tests.rs: Used realistic 32-byte keys
- lib-consensus/src/engines/bft_engine.rs: Used better documented version
- zhtp-cli/src/commands/common.rs: Used const for MIN_IDENTITY_ID_LENGTH

All conflicts resolved by keeping improvements from development while preserving
our Phase 2 testnet blocker features (UTXO snapshots, cross-contract call depth limits).
umwelt added a commit that referenced this pull request Jan 14, 2026
Merged latest development changes including:
- Phase 2: Issues #6-8 - Fork Detection, UTXO Snapshots, Call Depth Limits (#781)
- Phase 1: Complete All 5 Critical Blockchain Issues (#779)
- SOV Management CLI Commands (Issue #622) (#777)
- Web4 CLI Complete Functional Testing (#647)

Resolved conflicts:
- lib-blockchain/src/blockchain.rs: Merged fork recovery with token persistence features
- lib-blockchain/src/fork_recovery.rs: Used improved version with better documentation
- lib-blockchain/src/contracts/economics/fee_router.rs: Used cleaner validation
- lib-blockchain/src/contracts/governance/governance.rs: Used checked arithmetic
- lib-blockchain/tests/blockchain_tests.rs: Used realistic 32-byte keys
- lib-consensus/src/engines/bft_engine.rs: Used better documented version
- zhtp-cli/src/commands/common.rs: Used const for MIN_IDENTITY_ID_LENGTH

All conflicts resolved by keeping improvements from development while preserving
our Phase 2 Issue #9 token persistence features.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants