Keep run logs opaque and streamline transfers
This commit is contained in:
@@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
@@ -10,7 +11,7 @@ import (
|
||||
"browser.local/run/protocol"
|
||||
)
|
||||
|
||||
func TestPlatformClientArtifactMethodsPostJSONAndDecodeResponses(t *testing.T) {
|
||||
func TestPlatformClientArtifactMethodsUploadRawChunksAndDecodeResponses(t *testing.T) {
|
||||
seen := map[string]bool{}
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
seen[r.URL.Path] = true
|
||||
@@ -23,10 +24,16 @@ func TestPlatformClientArtifactMethodsPostJSONAndDecodeResponses(t *testing.T) {
|
||||
}
|
||||
writeTestJSON(t, w, validArtifactOpenResponse())
|
||||
case "/api/v1/run/artifacts/chunks":
|
||||
var request protocol.ArtifactChunkUploadRequest
|
||||
decodeTestRequest(t, r, &request)
|
||||
if request.TransferID != "transfer-1" || request.ChunkIndex != 0 || string(request.Payload) != "payload" {
|
||||
t.Fatalf("unexpected artifact chunk request: %+v", request)
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("read artifact chunk body: %v", err)
|
||||
}
|
||||
verifyRunRequestSignature(t, r, body, "run-local", "session-token")
|
||||
if r.Header.Get("Content-Type") != "application/octet-stream" || r.Header.Get("X-Run-Session-Token") != "session-token" {
|
||||
t.Fatalf("unexpected artifact chunk content headers: %+v", r.Header)
|
||||
}
|
||||
if r.Header.Get("X-Artifact-Transfer-Id") != "transfer-1" || r.Header.Get("X-Artifact-Chunk-Index") != "0" || string(body) != "payload" {
|
||||
t.Fatalf("unexpected artifact chunk request headers=%+v body=%q", r.Header, string(body))
|
||||
}
|
||||
writeTestJSON(t, w, protocol.ArtifactChunkUploadResponse{Accepted: true, TransferID: "transfer-1", ArtifactID: "artifact-1", ChunkIndex: 0, ReceivedChunkIndexes: []int{0}, NextMissingChunkIndex: 1, ServerTime: fixedClientTestTime()})
|
||||
case "/api/v1/run/artifacts/status":
|
||||
@@ -95,13 +102,13 @@ func TestPlatformClientArtifactMethodReturnsErrorForPlatformFailure(t *testing.T
|
||||
}
|
||||
}
|
||||
|
||||
func TestArtifactChunkPayloadUsesJSONBase64Encoding(t *testing.T) {
|
||||
func TestArtifactChunkPayloadIsNotJSONEncoded(t *testing.T) {
|
||||
encoded, err := json.Marshal(validClientArtifactChunk())
|
||||
if err != nil {
|
||||
t.Fatalf("marshal artifact chunk: %v", err)
|
||||
}
|
||||
if !json.Valid(encoded) || !containsJSONPayloadField(encoded) {
|
||||
t.Fatalf("expected JSON encoded payload field, got %s", string(encoded))
|
||||
if !json.Valid(encoded) || containsJSONPayloadField(encoded) {
|
||||
t.Fatalf("artifact chunk payload must stay out of JSON, got %s", string(encoded))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user