Preserve staged resource identities and expose upload receipts
This commit is contained in:
@@ -495,7 +495,7 @@ func TestOnboardingAndSharing(t *testing.T) {
|
||||
if err := png.Encode(&assetPNG, image.NewRGBA(image.Rect(0, 0, 3, 2))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
upload := func(encoded []byte, key string, status int) response {
|
||||
upload := func(encoded []byte, key string, status int, resourceIDs ...string) response {
|
||||
t.Helper()
|
||||
var body bytes.Buffer
|
||||
writer := multipart.NewWriter(&body)
|
||||
@@ -509,6 +509,9 @@ func TestOnboardingAndSharing(t *testing.T) {
|
||||
request.Header.Set("Authorization", "Bearer "+tokens[0])
|
||||
request.Header.Set("Content-Type", writer.FormDataContentType())
|
||||
request.Header.Set("Idempotency-Key", key)
|
||||
if len(resourceIDs) > 0 {
|
||||
request.Header.Set("X-Resource-Id", resourceIDs[0])
|
||||
}
|
||||
result := httptest.NewRecorder()
|
||||
mux.ServeHTTP(result, request)
|
||||
if result.Code != status {
|
||||
@@ -525,6 +528,33 @@ func TestOnboardingAndSharing(t *testing.T) {
|
||||
if uploaded["id"] != retriedAsset["id"] || uploaded["mime_type"] != "image/png" {
|
||||
t.Fatal("asset idempotency or actual MIME detection")
|
||||
}
|
||||
// New uploads keep the resource identity allocated in the frontend durable cut.
|
||||
resourceID, resourceKey := modelTestID(9100), modelTestID(9101)
|
||||
managed := upload(assetPNG.Bytes(), resourceKey, 201, resourceID)
|
||||
if managed["protocol_version"] != float64(2) || managed["request_id"] != resourceKey || managed["asset"].(map[string]any)["id"] != resourceID {
|
||||
t.Fatal("upload did not retain client resource identity")
|
||||
}
|
||||
repeated := upload(assetPNG.Bytes(), resourceKey, 201, resourceID)
|
||||
if !modelEqual(managed, repeated) {
|
||||
t.Fatal("resource retry changed receipt")
|
||||
}
|
||||
lookup := call("GET", workspacePath+"/assets/operations/"+resourceKey, tokens[0], nil, 200)
|
||||
if lookup["status"] != "applied" || !modelEqual(lookup["asset"], managed["asset"]) {
|
||||
t.Fatal("lost upload acknowledgment cannot be recovered")
|
||||
}
|
||||
unknown := call("GET", workspacePath+"/assets/operations/"+modelTestID(9102), tokens[0], nil, 404)
|
||||
if unknown["status"] != "unknown" || unknown["terminal"] == true {
|
||||
t.Fatal("missing asset receipt misreported zero-write")
|
||||
}
|
||||
call("GET", workspacePath+"/assets/operations/"+resourceKey, tokens[2], nil, 404)
|
||||
upload(assetPNG.Bytes(), resourceKey, 409, modelTestID(9103))
|
||||
upload(assetPNG.Bytes(), modelTestID(9104), 409, resourceID)
|
||||
var alternatePNG bytes.Buffer
|
||||
if err := png.Encode(&alternatePNG, image.NewRGBA(image.Rect(0, 0, 4, 4))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
upload(alternatePNG.Bytes(), resourceKey, 409, resourceID)
|
||||
upload(assetPNG.Bytes(), modelTestID(9105), 400, "invalid-resource")
|
||||
download := func(token string, status int) {
|
||||
t.Helper()
|
||||
request := httptest.NewRequest("GET", workspacePath+"/assets/"+uploaded["id"].(string), nil)
|
||||
|
||||
Reference in New Issue
Block a user