Skip to content
Open
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: 2 additions & 0 deletions codecov-cli/codecov_cli/services/commit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import typing

from codecov_cli import __version__ as codecov_cli_version
from codecov_cli.helpers.config import CODECOV_INGEST_URL
from codecov_cli.helpers.encoder import encode_slug
from codecov_cli.helpers.request import (
Expand Down Expand Up @@ -75,6 +76,7 @@ def send_commit_data(
"commitid": commit_sha,
"parent_commit_id": parent_sha,
"pullid": pr,
"version": codecov_cli_version,
}

upload_url = enterprise_url or CODECOV_INGEST_URL
Expand Down
2 changes: 2 additions & 0 deletions codecov-cli/codecov_cli/services/empty_upload/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging

from codecov_cli import __version__ as codecov_cli_version
from codecov_cli.helpers.config import CODECOV_API_URL
from codecov_cli.helpers.encoder import encode_slug
from codecov_cli.helpers.request import (
Expand Down Expand Up @@ -32,6 +33,7 @@ def empty_upload_logic(
data={
"cli_args": args,
"should_force": should_force,
"version": codecov_cli_version,
},
)
log_warnings_and_errors_if_any(sending_result, "Empty Upload", fail_on_error)
Expand Down
5 changes: 3 additions & 2 deletions codecov-cli/codecov_cli/services/report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import time
import typing

import requests

from codecov_cli import __version__ as codecov_cli_version
from codecov_cli.helpers import request
from codecov_cli.helpers.config import CODECOV_API_URL, CODECOV_INGEST_URL
from codecov_cli.helpers.encoder import encode_slug
Expand Down Expand Up @@ -58,6 +57,7 @@ def send_create_report_request(
data = {
"cli_args": args,
"code": code,
"version": codecov_cli_version,
}
headers = get_token_header(token)
upload_url = enterprise_url or CODECOV_INGEST_URL
Expand Down Expand Up @@ -103,6 +103,7 @@ def send_reports_result_request(
):
data = {
"cli_args": args,
"version": codecov_cli_version,
}
headers = get_token_header(token)
upload_url = enterprise_url or CODECOV_API_URL
Expand Down
9 changes: 5 additions & 4 deletions codecov-cli/codecov_cli/services/upload/upload_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import json
import logging
import typing
import sys
import zlib
from typing import Any, Dict

Expand Down Expand Up @@ -92,11 +91,14 @@ def send_upload_data(
commit_sha,
report_code,
upload_coverage,
file_not_found=file_not_found,
Copy link
Copy Markdown
Contributor Author

@calvin-codecov calvin-codecov Apr 15, 2026

Choose a reason for hiding this comment

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

This seemed like a missed line from before. We weren't passing in the file_not_found value that is defined higher up at line 59/61 and self.get_url_and_possibly_update_data() takes it in with a default value of "False" so it would always just set `data['file_not_found'] to False

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Please review this in particular ^

)
# Data that goes to storage
reports_payload = self._generate_payload(
upload_data, env_vars, report_type
)
reports_payload_size = len(reports_payload)
data["report_payload_bytes"] = reports_payload_size

with sentry_sdk.start_span(name="upload_sender_storage_request"):
logger.debug("Sending upload request to Codecov")
Expand Down Expand Up @@ -126,9 +128,8 @@ def send_upload_data(
put_url = resp_json_obj["raw_upload_location"]

with sentry_sdk.start_span(name="upload_sender_storage") as storage_span:
payload_size = sys.getsizeof(reports_payload)
storage_span.set_data("payload_size", payload_size)
logger.info(f"Sending upload ({payload_size} bytes) to storage")
storage_span.set_data("payload_size", reports_payload_size)
logger.info(f"Sending upload ({reports_payload_size} bytes) to storage")
resp_from_storage = send_put_request(put_url, data=reports_payload)

return resp_from_storage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging

from codecov_cli import __version__ as codecov_cli_version
from codecov_cli.helpers.config import CODECOV_API_URL
from codecov_cli.helpers.encoder import encode_slug
from codecov_cli.helpers.request import (
Expand All @@ -27,6 +28,7 @@ def upload_completion_logic(
url = f"{upload_url}/upload/{git_service}/{encoded_slug}/commits/{commit_sha}/upload-complete"
data = {
"cli_args": args,
"version": codecov_cli_version,
}
sending_result = send_post_request(url=url, data=data, headers=headers)
log_warnings_and_errors_if_any(
Expand Down
71 changes: 54 additions & 17 deletions codecov-cli/tests/helpers/test_upload_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,51 @@
"ci_service": "ci_service",
"git_service": "github",
}


def _upload_ingest_post_json_base(*, file_not_found: bool) -> dict:
return {
"ci_service": "ci_service",
"ci_url": "build_url",
"cli_args": None,
"env": {},
"flags": "flags",
"job_code": "job_code",
"name": "name",
"version": codecov_cli_version,
"file_not_found": file_not_found,
}


_report_payload_bytes_coverage = len(
UploadSender()._generate_payload(
upload_collection, {}, ReportType.COVERAGE
)
)

request_data = {
"ci_service": "ci_service",
"ci_url": "build_url",
"cli_args": None,
"env": {},
"flags": "flags",
"job_code": "job_code",
"name": "name",
"version": codecov_cli_version,
"file_not_found": False,
**_upload_ingest_post_json_base(file_not_found=False),
"report_payload_bytes": _report_payload_bytes_coverage,
}


def _test_results_ingest_post_json(
upload_data: UploadCollectionResult, *, file_not_found: bool
) -> dict:
return {
**_upload_ingest_post_json_base(file_not_found=file_not_found),
"slug": encode_slug("org/repo"),
"branch": "branch",
"commit": random_sha,
"service": "github",
"report_payload_bytes": len(
UploadSender()._generate_payload(
upload_data, {}, ReportType.TEST_RESULTS
)
),
}


@pytest.fixture
def mocked_responses():
with responses.RequestsMock() as rsps:
Expand Down Expand Up @@ -266,18 +298,22 @@ def test_upload_sender_post_called_with_right_parameters_test_results(
):
headers = {"Authorization": f"token {random_token}"}

mocked_legacy_upload_endpoint.match = [
matchers.json_params_matcher(request_data),
matchers.header_matcher(headers),
]
Comment on lines -269 to -272
Copy link
Copy Markdown
Contributor Author

@calvin-codecov calvin-codecov Apr 15, 2026

Choose a reason for hiding this comment

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

This seems like it was incorrectly using the mocked_legacy_upload_endpoint even though this is a different endpoint. I think we want the mocked_test_results_endpoint (newly added below) which would match with the argument at line 295 and with the url designated in this function


ta_upload_collection = deepcopy(upload_collection)

test_path = tmp_path / "test_results.xml"
test_path.write_bytes(b"test_data")

ta_upload_collection.files = [UploadCollectionResultFile(test_path)]

mocked_test_results_endpoint.match = [
matchers.json_params_matcher(
_test_results_ingest_post_json(
ta_upload_collection, file_not_found=False
)
),
matchers.header_matcher(headers),
]

sending_result = UploadSender().send_upload_data(
ta_upload_collection,
random_sha,
Expand Down Expand Up @@ -309,10 +345,11 @@ def test_upload_sender_post_called_with_right_parameters_test_results_file_not_f
):
headers = {"Authorization": f"token {random_token}"}

req_data = deepcopy(request_data)
req_data["file_not_found"] = True
req_data = _test_results_ingest_post_json(
upload_collection, file_not_found=True
)

mocked_legacy_upload_endpoint.match = [
mocked_test_results_endpoint_file_not_found.match = [
matchers.json_params_matcher(req_data),
matchers.header_matcher(headers),
]
Expand Down
4 changes: 4 additions & 0 deletions codecov-cli/tests/services/commit/test_commit_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from click.testing import CliRunner

from codecov_cli import __version__ as codecov_cli_version
from codecov_cli.services.commit import create_commit_logic, send_commit_data
from codecov_cli.types import RequestError, RequestResult, RequestResultWarning
from tests.test_helpers import parse_outstreams_into_log_lines
Expand Down Expand Up @@ -171,6 +172,7 @@ def test_commit_sender_with_forked_repo(mocker):
"commitid": "commit_sha",
"parent_commit_id": "parent_sha",
"pullid": "1",
"version": codecov_cli_version,
},
headers=None,
)
Expand Down Expand Up @@ -201,6 +203,7 @@ def test_commit_without_token(mocker):
"commitid": "commit_sha",
"parent_commit_id": "parent_sha",
"pullid": "1",
"version": codecov_cli_version,
},
headers=None,
)
Expand Down Expand Up @@ -232,6 +235,7 @@ def test_commit_sender_with_forked_repo_bad_branch(mocker):
"commitid": "commit_sha",
"parent_commit_id": "parent_sha",
"pullid": "1",
"version": codecov_cli_version,
},
headers=None,
)
Loading