From d5bd9be70cff740047bf329c81f4d0629ffe2cfc Mon Sep 17 00:00:00 2001 From: Pigbibi <20649888+Pigbibi@users.noreply.github.com> Date: Fri, 2 Oct 2026 21:55:11 +0800 Subject: [PATCH] fix: satisfy Cloud Run traffic tag minimum length Co-Authored-By: Codex --- .github/workflows/sync-cloud-run-env.yml | 2 +- scripts/verify_cached_diagnostic_stage.py | 5 ++++- tests/test_cached_diagnostic_stage.py | 14 ++++++++++---- tests/test_sync_cloud_run_env_workflow.py | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/workflows/sync-cloud-run-env.yml b/.github/workflows/sync-cloud-run-env.yml index 8c9190f..20fc1ba 100644 --- a/.github/workflows/sync-cloud-run-env.yml +++ b/.github/workflows/sync-cloud-run-env.yml @@ -69,7 +69,7 @@ jobs: GCP_ARTIFACT_REGISTRY_REPOSITORY: cloud-run-source-deploy CACHED_DIAGNOSTIC_SOURCE_SHA: 3317c0282ca5e70a55b97084572e5013a8eeae3f EXPECTED_SERVING_SOURCE_SHA: e0043ca860a36c1790ddbb866cb848e298a3d3c7 - CACHED_DIAGNOSTIC_TAG: cb + CACHED_DIAGNOSTIC_TAG: cbd steps: - name: Validate isolated stage inputs env: diff --git a/scripts/verify_cached_diagnostic_stage.py b/scripts/verify_cached_diagnostic_stage.py index d7800b2..563c8f8 100644 --- a/scripts/verify_cached_diagnostic_stage.py +++ b/scripts/verify_cached_diagnostic_stage.py @@ -13,7 +13,8 @@ DIAGNOSTIC_GATE = "FIRSTRADE_CACHED_BALANCE_DIAGNOSTIC_ON_HTTP" RUNTIME_TARGET_KEYS = ("QSL_RUNTIME_TARGET_JSON", "RUNTIME_TARGET_JSON") -DIAGNOSTIC_TAG = "cb" +DIAGNOSTIC_TAG = "cbd" +MIN_TRAFFIC_TAG_LENGTH = 3 MAX_SERVICE_AND_TRAFFIC_TAG_LENGTH = 46 EXPECTED_PLATFORM_ID = "firstrade" GENERATED_TEMPLATE_ANNOTATIONS = { @@ -66,6 +67,8 @@ def _validate_diagnostic_tag_budget(service_name: str, tag: str) -> None: raise ValueError("diagnostic_service_name_missing") if tag != DIAGNOSTIC_TAG: raise ValueError("diagnostic_tag_mismatch") + if len(tag) < MIN_TRAFFIC_TAG_LENGTH: + raise ValueError("diagnostic_tag_too_short") if len(service_name) + len(tag) > MAX_SERVICE_AND_TRAFFIC_TAG_LENGTH: raise ValueError("diagnostic_tag_name_budget_exceeded") diff --git a/tests/test_cached_diagnostic_stage.py b/tests/test_cached_diagnostic_stage.py index 99a0b6f..573d35d 100644 --- a/tests/test_cached_diagnostic_stage.py +++ b/tests/test_cached_diagnostic_stage.py @@ -35,7 +35,7 @@ def test_container_difference_categories_keep_private_details_closed(): @pytest.mark.parametrize( ("service_name_length", "error"), - [(44, None), (45, "diagnostic_tag_name_budget_exceeded")], + [(43, None), (44, "diagnostic_tag_name_budget_exceeded")], ) def test_diagnostic_traffic_tag_budget_is_checked_without_exposing_name(service_name_length, error): service_name = "s" * service_name_length @@ -46,6 +46,12 @@ def test_diagnostic_traffic_tag_budget_is_checked_without_exposing_name(service_ stage._validate_diagnostic_tag_budget(service_name, stage.DIAGNOSTIC_TAG) +def test_diagnostic_traffic_tag_rejects_short_fixed_tag(monkeypatch): + monkeypatch.setattr(stage, "DIAGNOSTIC_TAG", "cb") + with pytest.raises(ValueError, match="diagnostic_tag_too_short"): + stage._validate_diagnostic_tag_budget("service-placeholder", "cb") + + def test_diagnostic_traffic_tag_budget_rejects_a_different_tag(): with pytest.raises(ValueError, match="diagnostic_tag_mismatch"): stage._validate_diagnostic_tag_budget("service-placeholder", "long-tag") @@ -55,7 +61,7 @@ def test_tag_budget_cli_reports_only_closed_result(monkeypatch, capsys): monkeypatch.setattr( stage.sys, "argv", - ["verify_cached_diagnostic_stage.py", "tag-budget", "--expected-service", "private-service", "--tag", "cb"], + ["verify_cached_diagnostic_stage.py", "tag-budget", "--expected-service", "private-service", "--tag", "cbd"], ) assert stage.main() == 0 output = capsys.readouterr() @@ -64,11 +70,11 @@ def test_tag_budget_cli_reports_only_closed_result(monkeypatch, capsys): def test_tag_budget_cli_rejects_long_name_without_echoing_it(monkeypatch, capsys): - service_name = "s" * 45 + service_name = "s" * 44 monkeypatch.setattr( stage.sys, "argv", - ["verify_cached_diagnostic_stage.py", "tag-budget", "--expected-service", service_name, "--tag", "cb"], + ["verify_cached_diagnostic_stage.py", "tag-budget", "--expected-service", service_name, "--tag", "cbd"], ) assert stage.main() == 1 output = capsys.readouterr() diff --git a/tests/test_sync_cloud_run_env_workflow.py b/tests/test_sync_cloud_run_env_workflow.py index a03ccc1..d382156 100644 --- a/tests/test_sync_cloud_run_env_workflow.py +++ b/tests/test_sync_cloud_run_env_workflow.py @@ -259,7 +259,7 @@ def test_cached_balance_diagnostic_stage_is_opt_in_and_separate_from_deploy_and_ assert "verify_cached_diagnostic_stage.py active-revision" in stage_job assert "verify_cached_diagnostic_stage.py scheduler-hash" in stage_job assert "--no-traffic --tag=\"${CACHED_DIAGNOSTIC_TAG}\"" in stage_job - assert "CACHED_DIAGNOSTIC_TAG: cb" in stage_job + assert "CACHED_DIAGNOSTIC_TAG: cbd\n" in stage_job budget_check = stage_job.index("Validate fixed diagnostic traffic tag budget") image_build = stage_job.index("Build and push the fixed diagnostic image") assert budget_check < image_build