Skip to content

test: Fix invalid JSON payloads in actions workflow runs tests#4197

Merged
gmlewis merged 2 commits intogoogle:masterfrom
merchantmoh-debug:fix-json-tests
May 7, 2026
Merged

test: Fix invalid JSON payloads in actions workflow runs tests#4197
gmlewis merged 2 commits intogoogle:masterfrom
merchantmoh-debug:fix-json-tests

Conversation

@merchantmoh-debug
Copy link
Copy Markdown
Contributor

Fixes #4196

Description

Removes the invalid trailing }} braces from the mock HTTP server JSON payloads in actions_workflow_runs_test.go.

Motivation

This bug was silently masked by json.NewDecoder(). By correcting the test payloads, we ensure the tests are generating valid JSON, clearing the way for stricter memory-pooling and performance optimizations in the core client.

Verification

  • Validated JSON structure.

@gmlewis gmlewis changed the title test: fix invalid JSON payloads in actions workflow runs tests test: Fix invalid JSON payloads in actions workflow runs tests May 7, 2026
Copy link
Copy Markdown
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Awesome, thank you, @merchantmoh-debug!
LGTM.

I'm looking at the surrounding code and it is not obvious to me as to how we can prevent bugs like this in the future.
Do you have any ideas, @merchantmoh-debug - or should we just consider this to be a one-off bug fix?

I'm totally fine either way.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.71%. Comparing base (9c0ad62) to head (118da8c).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4197   +/-   ##
=======================================
  Coverage   93.71%   93.71%           
=======================================
  Files         209      209           
  Lines       19772    19772           
=======================================
  Hits        18529    18529           
  Misses       1046     1046           
  Partials      197      197           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@merchantmoh-debug
Copy link
Copy Markdown
Contributor Author

@gmlewis

We could actually eliminate this class of bugs entirely by introducing a simple testMockJSON(t, w, payload) helper.

Right now, the mock servers use fmt.Fprint(w, "...") which just treats the JSON as a raw, unvalidated string literal. Because it's just a string, Go has no way of knowing if the JSON is structurally sound until a strict parser trips over it.

If we use a testMockJSON helper instead, it could strictly enforce json.Valid([]byte(payload)) before writing to the ResponseWriter. That way, if a future developer accidentally hardcodes a typo or an extra brace, the mock server will instantly fail the test itself, rather than silently serving bad data to the client.

If you like the idea, I could write an AST script to automatically migrate all the intended JSON mock payloads across the test suite over to this new helper (intelligently skipping the tests that intentionally use invalid JSON for error checking).

It would be a pretty big diff touching a lot of files though, so if you'd rather avoid the noise, we can absolutely just consider this a one-off bug fix. I'm totally fine either way.

@gmlewis
Copy link
Copy Markdown
Collaborator

gmlewis commented May 7, 2026

It would be a pretty big diff touching a lot of files though, so if you'd rather avoid the noise, we can absolutely just consider this a one-off bug fix. I'm totally fine either way.

OK, excellent. Let's go ahead and get this in, and we can address the other ideas later if we decide it would be really beneficial.

@gmlewis gmlewis merged commit 5c3fa31 into google:master May 7, 2026
10 checks passed
@merchantmoh-debug merchantmoh-debug deleted the fix-json-tests branch May 7, 2026 16:34
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.

test: Actions GetWorkflowRun tests contain structurally invalid JSON payloads

2 participants