Skip to content

test: monitor Cloudflare endpoint contract - #5

Merged
mktbsh merged 2 commits into
mainfrom
agent/cloudflare-contract-monitoring
Aug 11, 2026
Merged

mktbsh merged 2 commits into
mainfrom
agent/cloudflare-contract-monitoring

Conversation

@mktbsh

@mktbsh mktbsh commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add an opt-in live contract test for Cloudflare __down, __up, and /meta.
  • Run the live contract test daily and on demand through GitHub Actions.
  • Record client-timing fallback capability detection in runtime warnings instead of silently degrading.

Why

Cloudflare's public speed-test response shape can change independently of this repository. The normal unit tests use mocked HTTP responses and cannot detect that drift. This stacked PR adds an external contract check without making ordinary PR CI depend on the public service.

Runtime behavior

Missing cfRequestDuration remains non-fatal. The CLI uses client timing and reports the fallback count in JSON warnings, while the live contract job alerts us to changes in response status, body size, upload acknowledgement, metadata fields, and key response headers.

Validation

  • go test ./... (70 tests passed)
  • go test -count=1 -tags=cloudflare_live ./internal/cloudflare -run '^TestCloudflareLiveContract$' -v (4 tests passed)
  • go vet ./...
  • go mod verify
  • go build -trimpath -ldflags='-s -w' -o dist/unispeedtest ./cmd/unispeedtest
  • Built binary -json run completed with positive upload throughput and JSON-only stdout.

Stack

This PR targets agent/fix-upload-speed-measurement and should be merged after the parent fix PR.

Summary by CodeRabbit

  • Bug Fixes

    • Improved latency reporting when server timing data is unavailable or cannot be parsed, while preserving client-side measurements.
    • Added warnings to distinguish timing fallbacks from measurement failures.
  • Tests

    • Added live contract coverage for Cloudflare downloads, uploads, metadata, status codes, and timing data.
    • Added automated daily and on-demand validation of Cloudflare integrations.

@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 31f05a17-b4a3-4049-8ca1-eeaebc743aab

📥 Commits

Reviewing files that changed from the base of the PR and between 9d8b724 and 349a9ac.

📒 Files selected for processing (3)
  • .github/workflows/cloudflare-contract.yml
  • internal/cloudflare/measure.go
  • internal/cloudflare/upload_test.go

📝 Walkthrough

Walkthrough

The PR adds a scheduled and manually triggered Cloudflare live contract test. It also tracks client-timing fallbacks separately from latency measurement failures and reports them during loaded and unloaded measurements.

Changes

Latency fallback reporting

Layer / File(s) Summary
Timing sampling and fallback detection
internal/cloudflare/measure.go, internal/cloudflare/upload_test.go
latencySample reports client-timing fallback usage when server-timing parsing fails. The test validates the fallback indicator.
Fallback propagation and phase warnings
internal/cloudflare/measure.go
Latency monitors track fallback samples separately from failures and add fallback warnings to phase results.

Cloudflare live contract validation

Layer / File(s) Summary
Live contract test execution
internal/cloudflare/contract_live_test.go, .github/workflows/cloudflare-contract.yml
The build-tagged test validates Cloudflare download, upload, and metadata responses. The workflow runs it daily and on manual dispatch with Go caching and a five-minute timeout.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CloudflareContractWorkflow
  participant TestCloudflareLiveContract
  participant CloudflareEndpoints
  CloudflareContractWorkflow->>TestCloudflareLiveContract: run live contract test
  TestCloudflareLiveContract->>CloudflareEndpoints: request download, upload, and metadata endpoints
  CloudflareEndpoints-->>TestCloudflareLiveContract: return HTTP responses and metadata
  TestCloudflareLiveContract-->>CloudflareContractWorkflow: report contract assertions
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the added Cloudflare endpoint contract test and monitoring workflow.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/cloudflare-contract-monitoring

Comment @coderabbitai help to get the list of available commands.

@mktbsh
mktbsh marked this pull request as ready for review August 8, 2026 13:11

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
.github/workflows/cloudflare-contract.yml (1)

16-17: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Disable persisted checkout credentials.

Set persist-credentials: false on actions/checkout@v4. The go test step does not need Git credentials, so this prevents it from accessing the workflow token.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/cloudflare-contract.yml around lines 16 - 17, Update the
actions/checkout@v4 step to set persist-credentials to false, ensuring the
subsequent go test step cannot access persisted GitHub workflow credentials.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/cloudflare/measure.go`:
- Around line 67-69: Resolve the nilerr lint warning in the ParseServerTiming
error branch without changing its non-fatal client-timing fallback behavior:
either add a narrowly scoped nolint:nilerr annotation with a reason or
restructure the branch so successful parsing proceeds normally and errors fall
through to the existing fallback. Keep the return values and surrounding measure
logic unchanged.

---

Nitpick comments:
In @.github/workflows/cloudflare-contract.yml:
- Around line 16-17: Update the actions/checkout@v4 step to set
persist-credentials to false, ensuring the subsequent go test step cannot access
persisted GitHub workflow credentials.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cc88e578-a617-4a6c-8049-cb26cde1ec3f

📥 Commits

Reviewing files that changed from the base of the PR and between fef5618 and 9d8b724.

📒 Files selected for processing (4)
  • .github/workflows/cloudflare-contract.yml
  • internal/cloudflare/contract_live_test.go
  • internal/cloudflare/measure.go
  • internal/cloudflare/upload_test.go

Comment thread internal/cloudflare/measure.go Outdated
@mktbsh
mktbsh force-pushed the agent/cloudflare-contract-monitoring branch from 9d8b724 to 0ec648a Compare August 11, 2026 14:58
Base automatically changed from agent/fix-upload-speed-measurement to main August 11, 2026 15:01
@mktbsh
mktbsh merged commit 0b636aa into main Aug 11, 2026
1 check passed
@mktbsh
mktbsh deleted the agent/cloudflare-contract-monitoring branch August 11, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant