Skip to content

[codex] Preserve raw log output for log operations#22

Merged
ChiragAgg5k merged 2 commits intomainfrom
codex/fix-log-operation-raw-text
Apr 2, 2026
Merged

[codex] Preserve raw log output for log operations#22
ChiragAgg5k merged 2 commits intomainfrom
codex/fix-log-operation-raw-text

Conversation

@ChiragAgg5k
Copy link
Copy Markdown
Member

Summary

Fix log operations to always return the raw response body instead of hydrating JSON-looking log payloads into resource objects.

Root Cause

runOperation(Operation::LOG, ...) stopped special-casing log responses and started routing them through the generic JSON hydration path. When a pod log body contained valid JSON, php-k8s would hydrate it into the current resource class, such as K8sPod, instead of returning the log text. That broke callers expecting logs() and containerLogs() to return strings.

Changes

  • restore raw-body handling for Operation::LOG in KubernetesCluster::runOperation()
  • add a regression test proving JSON log payloads are still returned as strings
  • add a companion assertion proving non-log JSON operations still hydrate normally

Validation

  • vendor/bin/phpunit --no-coverage tests/KubernetesClusterTest.php

Impact

This preserves the intended Kubernetes pod log semantics for callers that consume structured JSON logs while keeping normal resource hydration unchanged.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 2, 2026

Greptile Summary

This PR restores the intended raw-body semantics for Operation::LOG by short-circuiting it in runOperation() before the generic makeRequest() path, and updates a now-inaccurate comment in MakesHttpCalls. The fix is minimal, surgical, and well-tested.

  • src/KubernetesCluster.php: A new Operation::LOG arm in the match expression calls $this->call() directly and casts the response body to string, bypassing the JSON hydration in makeRequest(). HTTP errors are still properly propagated because call() already wraps ClientException into KubernetesAPIException.
  • src/Traits/Cluster/MakesHttpCalls.php: The comment on the !$json fallback branch is updated to remove the reference to pod logs, which no longer reach that code path.
  • tests/KubernetesClusterTest.php: Two focused unit tests using an anonymous subclass with a stubbed call() method — one covering the regression case (JSON log body returned as string) and one confirming that non-log JSON operations still hydrate into resource objects.

Confidence Score: 5/5

Safe to merge — targeted fix with no breaking changes and good regression coverage.

All three changed files are clean with no logic, syntax, or security issues. The fix is a minimal addition to an existing match expression, HTTP error propagation is unaffected, and two new unit tests directly validate both the fixed path and the unchanged hydration path. No P0 or P1 findings.

No files require special attention.

Important Files Changed

Filename Overview
src/KubernetesCluster.php Adds explicit Operation::LOG branch in runOperation() to return raw body string, bypassing JSON hydration — correctly mirrors how WATCH/WATCH_LOGS are already handled.
src/Traits/Cluster/MakesHttpCalls.php Comment-only update: removes now-inaccurate pod log example from the !$json fallback branch and replaces it with a more generic description.
tests/KubernetesClusterTest.php New unit test file with two targeted regression tests: one proving JSON log bodies are returned as raw strings, and one proving non-log JSON operations still hydrate into resource objects.

Reviews (2): Last reviewed commit: "fix: address review feedback" | Re-trigger Greptile

Comment thread tests/KubernetesClusterTest.php Outdated
Comment thread src/KubernetesCluster.php
@ChiragAgg5k ChiragAgg5k merged commit 3f84055 into main Apr 2, 2026
4 checks passed
@ChiragAgg5k ChiragAgg5k deleted the codex/fix-log-operation-raw-text branch April 2, 2026 10:11
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