diff --git a/.github/workflows/release-checks.yml b/.github/workflows/release-checks.yml index 912e1f529..58143f704 100644 --- a/.github/workflows/release-checks.yml +++ b/.github/workflows/release-checks.yml @@ -123,10 +123,11 @@ jobs: PYTEST_MARK_EXPRESSION: ${{ inputs.python-mark-expression }} PYTHON_SHARD: ${{ matrix.shard }} run: | + shard_list="$(python scripts/ci/check_test_layers.py --list-shard "$PYTHON_SHARD")" files=() while IFS= read -r path; do if [ -n "$path" ]; then files+=("$path"); fi - done < <(python scripts/ci/check_test_layers.py --list-shard "$PYTHON_SHARD") + done <<< "$shard_list" python -m pytest "${files[@]}" -q -ra -m "cpu${PYTEST_MARK_EXPRESSION:+ and ($PYTEST_MARK_EXPRESSION)}" --durations=50 --junitxml="test-results/python-${PYTHON_SHARD}.xml" --ci-profile="test-results/python-${PYTHON_SHARD}.json" - name: Upload Python timing evidence / 上传 Python 耗时证据 if: always() && steps.install.outcome == 'success' diff --git a/scripts/ci/check_test_layers.py b/scripts/ci/check_test_layers.py index 61e38b5c5..823b49ea6 100644 --- a/scripts/ci/check_test_layers.py +++ b/scripts/ci/check_test_layers.py @@ -9,13 +9,22 @@ LAYERS = {'ready', 'merge', 'nightly'} -def load_shards_manifest(manifest): +def discover_test_files(root=ROOT): + return sorted(f'tests/{path.name}' for path in (Path(root) / 'tests').glob('test_*.py')) + + +def load_shards_manifest(manifest, *, test_files=None): if manifest.get('schema_version') != 1 or not isinstance(manifest.get('shards'), dict) or not manifest['shards']: raise ValueError('Unsupported or empty Python shards manifest') + default_shard = manifest.get('default_shard') + if default_shard is not None and (not isinstance(default_shard, str) or default_shard not in manifest['shards']): + raise ValueError('Invalid default shard: ' + str(default_shard)) shards = {} seen = set() for name, files in manifest['shards'].items(): - if not isinstance(name, str) or not name or not isinstance(files, list) or not files: + if not isinstance(name, str) or not name or not isinstance(files, list): + raise ValueError('Invalid shard entry: ' + str(name)) + if not files and name != default_shard: raise ValueError('Invalid shard entry: ' + str(name)) if any(not isinstance(path, str) or not path.startswith('tests/') for path in files): raise ValueError('Invalid test path in shard: ' + name) @@ -26,6 +35,15 @@ def load_shards_manifest(manifest): raise ValueError('Test path listed in multiple shards: ' + ', '.join(sorted(overlap))) seen.update(files) shards[name] = list(files) + if default_shard is not None: + discovered = sorted(set(discover_test_files() if test_files is None else test_files)) + missing = sorted(seen - set(discovered)) + if missing: + raise ValueError('Shard manifest references missing test files: ' + ', '.join(missing[:5])) + remainder = [path for path in discovered if path not in seen] + shards[default_shard] = sorted(set(shards[default_shard]).union(remainder)) + if not shards[default_shard]: + raise ValueError('Default shard resolved to no test files: ' + default_shard) return shards @@ -85,9 +103,12 @@ def audit(profile, contract, manifest, *, require_executed=False): } -def audit_shards(inventory, shard_profiles, shards_manifest, contract, manifest, *, require_executed=False): +def audit_shards( + inventory, shard_profiles, shards_manifest, contract, manifest, + *, require_executed=False, test_files=None, +): audit(inventory, contract, manifest, require_executed=False) - shards = load_shards_manifest(shards_manifest) + shards = load_shards_manifest(shards_manifest, test_files=test_files) if len(shard_profiles) != len(shards): raise ValueError(f'Expected {len(shards)} shard profiles, got {len(shard_profiles)}') expected_selection = inventory['metadata'].get('selection', '') diff --git a/scripts/ci/python_shards.json b/scripts/ci/python_shards.json index d137fb1b9..56d52ff47 100644 --- a/scripts/ci/python_shards.json +++ b/scripts/ci/python_shards.json @@ -1,116 +1,8 @@ { "schema_version": 1, + "default_shard": "core", "shards": { - "core": [ - "tests/test_a2_repros.py", - "tests/test_app_settings.py", - "tests/test_ark_availability.py", - "tests/test_ark_plan_models.py", - "tests/test_asset_names.py", - "tests/test_atlascloud.py", - "tests/test_bench_creation_projects.py", - "tests/test_bench_turn_timing.py", - "tests/test_bigmodel_image.py", - "tests/test_bigmodel_video.py", - "tests/test_blockout.py", - "tests/test_canvas_sources.py", - "tests/test_canvas_text_cli.py", - "tests/test_capability_acceptance.py", - "tests/test_capability_contract.py", - "tests/test_capability_contract_integration.py", - "tests/test_capability_freshness.py", - "tests/test_capability_identity.py", - "tests/test_capability_input_projection.py", - "tests/test_ci_hardware.py", - "tests/test_ci_layers.py", - "tests/test_ci_profile.py", - "tests/test_ci_scope.py", - "tests/test_ci_security.py", - "tests/test_ci_summary.py", - "tests/test_command_version_contract.py", - "tests/test_continuation_availability.py", - "tests/test_creation_api.py", - "tests/test_creation_artifacts.py", - "tests/test_creation_assembly.py", - "tests/test_creation_assets.py", - "tests/test_creation_canvas_service.py", - "tests/test_creation_contracts.py", - "tests/test_creation_generation_service.py", - "tests/test_creation_history_service.py", - "tests/test_creation_layers.py", - "tests/test_creation_node_versions.py", - "tests/test_creation_parameters.py", - "tests/test_creation_reference_editor.py", - "tests/test_creation_storage.py", - "tests/test_creation_tool_drafts.py", - "tests/test_creation_workflow.py", - "tests/test_cutout_capability_acceptance.py", - "tests/test_daily_benchmark.py", - "tests/test_desktop_host.py", - "tests/test_directory_links.py", - "tests/test_endpoint_closure.py", - "tests/test_execution_files.py", - "tests/test_fasth3_capability_acceptance.py", - "tests/test_fasth3_continuation.py", - "tests/test_fasth3_inputs.py", - "tests/test_fasth3_video_edit.py", - "tests/test_ffmpeg_frame_sync.py", - "tests/test_generation_errors.py", - "tests/test_generation_recovery.py", - "tests/test_h3_keyframes.py", - "tests/test_hidden_reference_roundtrip.py", - "tests/test_higgsfield_open.py", - "tests/test_image_input_policy.py", - "tests/test_image_quality_test.py", - "tests/test_installation.py", - "tests/test_kling_video.py", - "tests/test_launcher.py", - "tests/test_layer_boundary.py", - "tests/test_library.py", - "tests/test_local_json.py", - "tests/test_localization.py", - "tests/test_minimax_image.py", - "tests/test_minimax_speech.py", - "tests/test_minimax_video.py", - "tests/test_model_availability.py", - "tests/test_model_catalog.py", - "tests/test_model_configs.py", - "tests/test_model_gateway.py", - "tests/test_model_http_logging.py", - "tests/test_model_reasoning_trace.py", - "tests/test_moss.py", - "tests/test_multimodal_references.py", - "tests/test_nightly_perf_artifact.py", - "tests/test_omni_exported_video_capabilities.py", - "tests/test_openai_images.py", - "tests/test_owner_rights.py", - "tests/test_owner_rights_journal.py", - "tests/test_owner_rights_lifecycle.py", - "tests/test_owner_rights_resume.py", - "tests/test_pipeline.py", - "tests/test_posix_execution_files.py", - "tests/test_process_helpers.py", - "tests/test_prompt_optimization.py", - "tests/test_public_target.py", - "tests/test_query_guidance.py", - "tests/test_rename.py", - "tests/test_request_capability_acceptance.py", - "tests/test_result_download_security.py", - "tests/test_retired_entry.py", - "tests/test_rule_facts.py", - "tests/test_runtime_catalog.py", - "tests/test_runtime_readiness.py", - "tests/test_self_hosted.py", - "tests/test_self_hosted_proxy.py", - "tests/test_self_hosted_queue.py", - "tests/test_structure_reference.py", - "tests/test_vllm_omni_h3.py", - "tests/test_vllm_omni_image.py", - "tests/test_voice_library.py", - "tests/test_windows_git_control_pipe.py", - "tests/test_windows_powershell.py", - "tests/test_zhipu.py" - ], + "core": [], "agent-cli": [ "tests/test_agent_artifacts.py", "tests/test_agent_citations.py", diff --git a/tests/test_ci_layers.py b/tests/test_ci_layers.py index 18e739d21..2f01249c3 100644 --- a/tests/test_ci_layers.py +++ b/tests/test_ci_layers.py @@ -195,11 +195,38 @@ def test_audit_shards_rejects_incomplete_shard_or_skipped_representative(evidenc ) +def test_default_shard_automatically_absorbs_new_test_modules(evidence): + inventory, shard_profiles, _, contract, manifest = _shard_fixture(evidence) + shards_manifest = { + 'schema_version': 1, + 'default_shard': 'core', + 'shards': {'core': [], 'media': ['tests/test_media.py']}, + } + shard_profiles[0]['metadata']['paths'] = ['tests/test_core.py', 'tests/test_new_feature.py'] + result = audit_module.audit_shards( + inventory, shard_profiles, shards_manifest, contract, manifest, + require_executed=True, + test_files=['tests/test_core.py', 'tests/test_media.py', 'tests/test_new_feature.py'], + ) + assert result['shards'] == {'core': 1, 'media': 1} + + +def test_default_shard_rejects_missing_explicit_module(): + shards_manifest = { + 'schema_version': 1, + 'default_shard': 'core', + 'shards': {'core': [], 'media': ['tests/test_deleted.py']}, + } + with pytest.raises(ValueError, match='missing test files'): + audit_module.load_shards_manifest(shards_manifest, test_files=['tests/test_core.py']) + + def test_repo_python_shards_manifest_covers_every_test_module_once(): import json root = Path(__file__).resolve().parents[1] manifest = json.loads((root / 'scripts/ci/python_shards.json').read_text(encoding='utf-8')) - shards = audit_module.load_shards_manifest(manifest) + assert manifest['default_shard'] == 'core' + on_disk = audit_module.discover_test_files(root) + shards = audit_module.load_shards_manifest(manifest, test_files=on_disk) listed = {path for files in shards.values() for path in files} - on_disk = {f'tests/{path.name}' for path in (root / 'tests').glob('test_*.py')} - assert listed == on_disk + assert listed == set(on_disk)