#!/usr/bin/env python3 """ testchannelvalidation.py - Channel validation tests Tests…
- User
#!/usr/bin/env python3 """ test_channel_validation.py - Channel validation tests Tests channel-specific validation rules (dev, experimental, fast, regular) Test Procedure: 1. Create test configurations for different channel formats 2. Set up main and PR module structures with version changes 3. Parse configurations and validate using StateValidator 4. Test channel-specific rules: - dev: allows any suffix (dev, rc, alpha, PR numbers, etc.) - experimental: allows only -experimental suffix or plain versions - fast: strict x.x.x versions only (no suffixes) - regular: strict x.x.x versions only (no suffixes) 5. Verify validation passes/fails according to channel rules 6. Check error messages contain appropriate channel information Expected Results: - dev channel accepts all version formats with any suffix - experimental channel rejects non-experimental suffixes (-dev, -rc, etc.) - fast/regular channels reject any suffixes - Invalid semver formats fail regardless of channel """ from pathlib import Path from validateversions import ModuleReleaseParser, StateValidator class TestDevChannelValidationRules: """Test channel-specific validation rules""" def test_dev_channel_allows_any_suffix(self, temp_module_structure, test_data_factory): """Test that dev channel allows any suffix Test Procedure: 1. Create main state with dev channel at version 1.0.0 2. Create PR state with dev channel at 1.1.0-dev-PR123 (custom suffix) 3. Parse both configurations using ModuleReleaseParser 4. Run validation through StateValidator 5. Verify validation passes (dev allows any suffix) Expected Result: - Validation should pass without errors - Dev channel accepts versions with any suffix format """ main_data = test_data_factory.format3_channels_global(dev_version="1.0.0") pr_data = test_data_factory.format3_channels_global(dev_version="1.1.0-dev-PR123") structure = temp_module_structure(main_data, pr_data) main_parser = ModuleReleaseParser(Path(structure['main_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "MAIN") pr_parser = ModuleReleaseParser(Path(structure['pr_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "PR") validator = StateValidator(main_parser, pr_parser) is_valid, errors = validator.validate() assert is_valid, f"Dev channel should allow any suffix, but got errors: {errors}" def test_dev_channel_allows_rc_suffix(self, temp_module_structure, test_data_factory): """Test that dev channel allows RC (Release Candidate) suffix Test Procedure: 1. Create main state with dev channel at version 1.0.0 2. Create PR state with dev channel at 1.1.0-rc.1 (RC suffix) 3. Parse both configurations using ModuleReleaseParser 4. Run validation through StateValidator 5. Verify validation passes (dev allows RC suffixes) Expected Result: - Validation should pass without errors - Dev channel accepts release candidate versions """ main_data = test_data_factory.format3_channels_global(dev_version="1.0.0") pr_data = test_data_factory.format3_channels_global(dev_version="1.1.0-rc.1") structure = temp_module_structure(main_data, pr_data) main_parser = ModuleReleaseParser(Path(structure['main_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "MAIN") pr_parser = ModuleReleaseParser(Path(structure['pr_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "PR") validator = StateValidator(main_parser, pr_parser) is_valid, errors = validator.validate() assert is_valid, f"Dev channel should allow RC suffix, but got errors: {errors}" def test_dev_channel_allows_alpha_suffix(self, temp_module_structure, test_data_factory): """Test that dev channel allows alpha pre-release suffix Test Procedure: 1. Create main state with dev channel at version 1.0.0 2. Create PR state with dev channel at 1.1.0-alpha.2 (alpha suffix) 3. Parse both configurations using ModuleReleaseParser 4. Run validation through StateValidator 5. Verify validation passes (dev allows alpha suffixes) Expected Result: - Validation should pass without errors - Dev channel accepts alpha pre-release versions """ main_data = test_data_factory.format3_channels_global(dev_version="1.0.0") pr_data = test_data_factory.format3_channels_global(dev_version="1.1.0-alpha.2") structure = temp_module_structure(main_data, pr_data) main_parser = ModuleReleaseParser(Path(structure['main_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "MAIN") pr_parser = ModuleReleaseParser(Path(structure['pr_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "PR") validator = StateValidator(main_parser, pr_parser) is_valid, errors = validator.validate() assert is_valid, f"Dev channel should allow alpha suffix, but got errors: {errors}" class TestExperimentalChannelValidation: """Test experimental channel validation rules""" def test_experimental_channel_allows_experimental_suffix(self, temp_module_structure, test_data_factory): """Test that experimental channel allows -experimental suffix Test Procedure: 1. Create main state with experimental channel at version 1.0.0 2. Create PR state with experimental channel at 1.1.0-experimental 3. Parse both configurations using ModuleReleaseParser 4. Run validation through StateValidator 5. Verify validation passes (experimental allows -experimental suffix) Expected Result: - Validation should pass without errors - Experimental channel accepts versions with -experimental suffix """ main_data = test_data_factory.format3_channels_global(experimental_version="1.0.0") pr_data = test_data_factory.format3_channels_global(experimental_version="1.1.0-experimental") structure = temp_module_structure(main_data, pr_data) main_parser = ModuleReleaseParser(Path(structure['main_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "MAIN") pr_parser = ModuleReleaseParser(Path(structure['pr_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "PR") validator = StateValidator(main_parser, pr_parser) is_valid, errors = validator.validate() assert is_valid, f"Experimental channel should allow -experimental suffix, but got errors: {errors}" def test_experimental_channel_allows_plain_version(self, temp_module_structure, test_data_factory): """Test that experimental channel allows plain semantic versions Test Procedure: 1. Create main state with experimental channel at version 1.0.0 2. Create PR state with experimental channel at 1.1.0 (no suffix) 3. Parse both configurations using ModuleReleaseParser 4. Run validation through StateValidator 5. Verify validation passes (experimental allows plain versions) Expected Result: - Validation should pass without errors - Experimental channel accepts plain x.x.x versions """ main_data = test_data_factory.format3_channels_global(experimental_version="1.0.0") pr_data = test_data_factory.format3_channels_global(experimental_version="1.1.0") structure = temp_module_structure(main_data, pr_data) main_parser = ModuleReleaseParser(Path(structure['main_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "MAIN") pr_parser = ModuleReleaseParser(Path(structure['pr_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "PR") validator = StateValidator(main_parser, pr_parser) is_valid, errors = validator.validate() assert is_valid, f"Experimental channel should allow plain versions, but got errors: {errors}" def test_experimental_channel_rejects_dev_suffix(self, temp_module_structure, test_data_factory): """Test that experimental channel rejects -dev suffix Test Procedure: 1. Create main state with experimental channel at version 1.0.0 2. Create PR state with experimental channel at 1.1.0-dev (invalid suffix) 3. Parse both configurations using ModuleReleaseParser 4. Run validation through StateValidator 5. Verify validation fails with appropriate error 6. Check error message contains 'experimental' channel reference Expected Result: - Validation should fail - Error message should reference experimental channel - Experimental channel only accepts -experimental suffix or plain versions """ main_data = test_data_factory.format3_channels_global(experimental_version="1.0.0") pr_data = test_data_factory.format3_channels_global(experimental_version="1.1.0-dev") structure = temp_module_structure(main_data, pr_data) main_parser = ModuleReleaseParser(Path(structure['main_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "MAIN") pr_parser = ModuleReleaseParser(Path(structure['pr_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "PR") validator = StateValidator(main_parser, pr_parser) is_valid, errors = validator.validate() assert not is_valid, "Experimental channel should reject -dev suffix" assert any("experimental" in error.lower() for error in errors), f"Should contain experimental channel error, got: {errors}" def test_experimental_channel_rejects_rc_suffix(self, temp_module_structure, test_data_factory): """Test that experimental channel rejects -rc suffix Test Procedure: 1. Create main state with experimental channel at version 1.0.0 2. Create PR state with experimental channel at 1.1.0-rc.1 (invalid suffix) 3. Parse both configurations using ModuleReleaseParser 4. Run validation through StateValidator 5. Verify validation fails with appropriate error 6. Check error message contains 'experimental' channel reference Expected Result: - Validation should fail - Error message should reference experimental channel - RC suffixes are not allowed in experimental channel """ main_data = test_data_factory.format3_channels_global(experimental_version="1.0.0") pr_data = test_data_factory.format3_channels_global(experimental_version="1.1.0-rc.1") structure = temp_module_structure(main_data, pr_data) main_parser = ModuleReleaseParser(Path(structure['main_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "MAIN") pr_parser = ModuleReleaseParser(Path(structure['pr_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "PR") validator = StateValidator(main_parser, pr_parser) is_valid, errors = validator.validate() assert not is_valid, "Experimental channel should reject -rc suffix" assert any("experimental" in error.lower() for error in errors), f"Should contain experimental channel error, got: {errors}" class TestFastChannelValidation: """Test fast channel validation rules""" def test_fast_channel_allows_strict_version(self, temp_module_structure, test_data_factory): """Test that fast channel allows strict x.x.x versions Test Procedure: 1. Create main state with fast channel at version 1.0.0 2. Create PR state with fast channel at 1.1.0 (strict version) 3. Parse both configurations using ModuleReleaseParser 4. Run validation through StateValidator 5. Verify validation passes (fast allows strict versions) Expected Result: - Validation should pass without errors - Fast channel accepts only strict semantic versions """ main_data = test_data_factory.format3_channels_global(fast_version="1.0.0") pr_data = test_data_factory.format3_channels_global(fast_version="1.1.0") structure = temp_module_structure(main_data, pr_data) main_parser = ModuleReleaseParser(Path(structure['main_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "MAIN") pr_parser = ModuleReleaseParser(Path(structure['pr_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "PR") validator = StateValidator(main_parser, pr_parser) is_valid, errors = validator.validate() assert is_valid, f"Fast channel should allow strict versions, but got errors: {errors}" def test_fast_channel_rejects_dev_suffix(self, temp_module_structure, test_data_factory): """Test that fast channel rejects -dev suffix Test Procedure: 1. Create main state with fast channel at version 1.0.0 2. Create PR state with fast channel at 1.1.0-dev (invalid suffix) 3. Parse both configurations using ModuleReleaseParser 4. Run validation through StateValidator 5. Verify validation fails with appropriate error 6. Check error message contains 'fast' channel reference Expected Result: - Validation should fail - Error message should reference fast channel - Fast channel does not accept any suffixes """ main_data = test_data_factory.format3_channels_global(fast_version="1.0.0") pr_data = test_data_factory.format3_channels_global(fast_version="1.1.0-dev") structure = temp_module_structure(main_data, pr_data) main_parser = ModuleReleaseParser(Path(structure['main_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "MAIN") pr_parser = ModuleReleaseParser(Path(structure['pr_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "PR") validator = StateValidator(main_parser, pr_parser) is_valid, errors = validator.validate() assert not is_valid, "Fast channel should reject suffixes" assert any("fast" in error.lower() for error in errors), f"Should contain fast channel error, got: {errors}" def test_fast_channel_rejects_experimental_suffix(self, temp_module_structure, test_data_factory): """Test that fast channel rejects -experimental suffix Test Procedure: 1. Create main state with fast channel at version 1.0.0 2. Create PR state with fast channel at 1.1.0-experimental (invalid suffix) 3. Parse both configurations using ModuleReleaseParser 4. Run validation through StateValidator 5. Verify validation fails with appropriate error 6. Check error message contains 'fast' channel reference Expected Result: - Validation should fail - Error message should reference fast channel - Experimental suffixes are not allowed in fast channel """ main_data = test_data_factory.format3_channels_global(fast_version="1.0.0") pr_data = test_data_factory.format3_channels_global(fast_version="1.1.0-experimental") structure = temp_module_structure(main_data, pr_data) main_parser = ModuleReleaseParser(Path(structure['main_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "MAIN") pr_parser = ModuleReleaseParser(Path(structure['pr_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "PR") validator = StateValidator(main_parser, pr_parser) is_valid, errors = validator.validate() assert not is_valid, "Fast channel should reject experimental suffix" assert any("fast" in error.lower() for error in errors), f"Should contain fast channel error, got: {errors}" class TestRegularChannelValidation: """Test regular channel validation rules""" def test_regular_channel_allows_strict_version(self, temp_module_structure, test_data_factory): """Test that regular channel allows strict x.x.x versions Test Procedure: 1. Create main state with regular channel at version 1.0.0 2. Create PR state with regular channel at 1.1.0 (strict version) 3. Parse both configurations using ModuleReleaseParser 4. Run validation through StateValidator 5. Verify validation passes (regular allows strict versions) Expected Result: - Validation should pass without errors - Regular channel accepts only strict semantic versions """ main_data = test_data_factory.format3_channels_global(regular_version="1.0.0") pr_data = test_data_factory.format3_channels_global(regular_version="1.1.0") structure = temp_module_structure(main_data, pr_data) main_parser = ModuleReleaseParser(Path(structure['main_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "MAIN") pr_parser = ModuleReleaseParser(Path(structure['pr_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "PR") validator = StateValidator(main_parser, pr_parser) is_valid, errors = validator.validate() assert is_valid, f"Regular channel should allow strict versions, but got errors: {errors}" def test_regular_channel_rejects_any_suffix(self, temp_module_structure, test_data_factory): """Test that regular channel rejects any suffix Test Procedure: 1. Create main state with regular channel at version 1.0.0 2. Create PR state with regular channel at 1.1.0-dev (invalid suffix) 3. Parse both configurations using ModuleReleaseParser 4. Run validation through StateValidator 5. Verify validation fails with appropriate error 6. Check error message contains 'regular' channel reference Expected Result: - Validation should fail - Error message should reference regular channel - Regular channel does not accept any suffixes """ main_data = test_data_factory.format3_channels_global(regular_version="1.0.0") pr_data = test_data_factory.format3_channels_global(regular_version="1.1.0-dev") structure = temp_module_structure(main_data, pr_data) main_parser = ModuleReleaseParser(Path(structure['main_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "MAIN") pr_parser = ModuleReleaseParser(Path(structure['pr_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "PR") validator = StateValidator(main_parser, pr_parser) is_valid, errors = validator.validate() assert not is_valid, "Regular channel should reject suffixes" assert any("regular" in error.lower() for error in errors), f"Should contain regular channel error, got: {errors}" class TestVersionFormatEdgeCases: """Test version format edge cases""" def test_pre_release_versions_in_dev(self, temp_module_structure, edge_case_data_factory): """Test pre-release version formats in dev channel Test Procedure: 1. Create main state with dev channel at version 1.0.0 2. Create PR state with dev channel at 1.1.0-alpha.1 (pre-release format) 3. Parse both configurations using ModuleReleaseParser 4. Run validation through StateValidator 5. Verify validation passes (dev allows pre-release versions) Expected Result: - Validation should pass without errors - Dev channel accepts any pre-release version format """ main_data = edge_case_data_factory.format3_channels_partial({'dev': '1.0.0'}) pr_data = edge_case_data_factory.format3_channels_partial({'dev': '1.1.0-alpha.1'}) structure = temp_module_structure(main_data, pr_data) main_parser = ModuleReleaseParser(Path(structure['main_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "MAIN") pr_parser = ModuleReleaseParser(Path(structure['pr_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "PR") validator = StateValidator(main_parser, pr_parser) is_valid, errors = validator.validate() assert is_valid, f"Pre-release version in dev channel should pass, but got errors: {errors}" def test_build_metadata_versions_in_dev(self, temp_module_structure, edge_case_data_factory): """Test version with build metadata in dev channel Test Procedure: 1. Create main state with dev channel at version 1.0.0 2. Create PR state with dev channel at 1.1.0+build.123 (build metadata) 3. Parse both configurations using ModuleReleaseParser 4. Run validation through StateValidator 5. Verify validation passes (dev allows build metadata) Expected Result: - Validation should pass without errors - Dev channel accepts versions with build metadata """ main_data = edge_case_data_factory.format3_channels_partial({'dev': '1.0.0'}) pr_data = edge_case_data_factory.format3_channels_partial({'dev': '1.1.0+build.123'}) structure = temp_module_structure(main_data, pr_data) main_parser = ModuleReleaseParser(Path(structure['main_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "MAIN") pr_parser = ModuleReleaseParser(Path(structure['pr_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "PR") validator = StateValidator(main_parser, pr_parser) is_valid, errors = validator.validate() assert is_valid, f"Build metadata version in dev channel should pass, but got errors: {errors}" def test_invalid_semver_format_in_fast(self, temp_module_structure, edge_case_data_factory): """Test invalid semantic version format in fast channel Test Procedure: 1. Create main state with fast channel at version 1.0.0 2. Create PR state with fast channel at 'invalid.version' (not valid semver) 3. Parse both configurations using ModuleReleaseParser 4. Run validation through StateValidator 5. Verify validation fails (invalid semver format) Expected Result: - Validation should fail - Invalid semver format should fail regardless of channel rules - Error should indicate version format issue """ main_data = edge_case_data_factory.format3_channels_partial({'fast': '1.0.0'}) pr_data = edge_case_data_factory.format3_channels_partial({'fast': 'invalid.version'}) structure = temp_module_structure(main_data, pr_data) main_parser = ModuleReleaseParser(Path(structure['main_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "MAIN") pr_parser = ModuleReleaseParser(Path(structure['pr_repo']) / "modules" / structure['module_name'] / "module-releases.yaml", "PR") validator = StateValidator(main_parser, pr_parser) is_valid, errors = validator.validate() assert not is_valid, "Invalid version format should fail validation" Popraw cały plik. Problem jest taki, że używamy na zmiane plain/strict i trzeba to wyrównac Zrób zmiany kompletne, nie pomijaj nic, tylko zmien z strict na plain wszedzie. jedynie tylko tyle. i zwroc caly plik gotowy.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.