Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/sync-cloud-run-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion scripts/verify_cached_diagnostic_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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")

Expand Down
14 changes: 10 additions & 4 deletions tests/test_cached_diagnostic_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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()
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sync_cloud_run_env_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading