Skip to content

fix: agent artifact route to support filenames with slashes#7490

Open
devcatalin wants to merge 2 commits intomainfrom
devcatalin/fix/artifact-route
Open

fix: agent artifact route to support filenames with slashes#7490
devcatalin wants to merge 2 commits intomainfrom
devcatalin/fix/artifact-route

Conversation

@devcatalin
Copy link
Copy Markdown
Member

Companion fix to kubeshop/testkube-cloud-api#3489 - resolves the second layer of the artifact 410/408 bug.

  • Artifact filenames can contain subdirectory paths (e.g. results/junit.xml); the cloud API proxies these to the agent via NATS with %2F-encoded slashes
  • fasthttp's URI.Parse decodes %2F/ before Fiber routing, so :filename (single-segment) can't match multi-segment decoded paths — the agent silently drops the request, causing a 408 timeout at the cloud API
  • Change :filename:filename+ (Fiber greedy param) so the route matches filenames with slashes, matching the cloud API fix ({filename:.*})

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 8, 2026

Greptile Summary

Fixes a routing bug where artifact filenames containing subdirectory paths (e.g. results/junit.xml) would silently fail: fasthttp decodes %2F/ before Fiber routing, so the single-segment /:filename param couldn't match multi-segment paths, causing 408 timeouts at the cloud API. The fix changes /:filename/:filename+ (Fiber greedy param), and a new test validates routing end-to-end through the real handler and mock storage.

Confidence Score: 5/5

Safe to merge — targeted one-line routing fix with a solid test covering the exact failure scenario.

The change is minimal and correct: /:filename+ is the standard Fiber greedy param, the handler already reads c.Params("filename") which returns the full slash-joined path, and the new test validates simple, single-slash, and multi-slash cases end-to-end. No routing conflicts exist with adjacent routes, and no security or data-integrity concerns are introduced.

No files require special attention.

Vulnerabilities

No security concerns identified. The greedy param /:filename+ expands path matching but does not change authentication or authorization logic; the handler already relies on the execution lookup for access control.

Important Files Changed

Filename Overview
internal/app/api/v1/server.go Single-character change: :filename:filename+; correct and minimal, no routing conflicts with adjacent routes.
internal/app/api/v1/testworkflowexecutions_artifact_test.go New table-driven test covering simple filenames, one-level, and nested subdirectory paths through the real Fiber route + mock storage; verifies the greedy param fix end-to-end.

Sequence Diagram

sequenceDiagram
    participant CloudAPI as Cloud API
    participant NATS
    participant Agent as Agent (Fiber/fasthttp)
    participant Storage as Artifact Storage

    CloudAPI->>NATS: GET /artifacts/results%2Fjunit.xml
    NATS->>Agent: Forward request
    Note over Agent: fasthttp URI.Parse decodes<br/>%2F → / before routing
    Note over Agent: Path becomes /artifacts/results/junit.xml
    alt Before fix (/:filename)
        Agent-->>NATS: No route match → no response
        NATS-->>CloudAPI: 408 Timeout
    else After fix (/:filename+)
        Agent->>Agent: Greedy param captures results/junit.xml
        Agent->>Storage: DownloadFile("results/junit.xml", ...)
        Storage-->>Agent: File stream
        Agent-->>NATS: 200 OK + file content
        NATS-->>CloudAPI: 200 OK
    end
Loading

Reviews (1): Last reviewed commit: "fix: agent artifact route to support fil..." | Re-trigger Greptile

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the agent-side Fiber route for fetching test-workflow execution artifacts so that artifact filenames containing slashes (subdirectory paths like results/junit.xml) are routable after URL decoding, preventing proxy timeouts seen by the cloud API.

Changes:

  • Update the artifact download route to use Fiber’s greedy path param (:filename+) so multi-segment filenames match.
  • Add an end-to-end-style handler test that verifies artifacts can be fetched when the filename contains encoded slashes (%2F) that decode to /.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/app/api/v1/server.go Switch artifact route from single-segment :filename to greedy :filename+ to support slashed filenames.
internal/app/api/v1/testworkflowexecutions_artifact_test.go Add coverage ensuring the Fiber route + handler + storage call chain works for filenames containing /.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Change c.Params("filename") to c.Params("filename+") to match
  Fiber's greedy route naming convention for /:filename+ routes
- Add url.PathUnescape() to decode %2F back to / before storage lookup
- Increase reconnection test timeouts to prevent flaky failures
- Add artifact-subdirectory test workflow for manual reproduction
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.

3 participants