- Added file upload handler to process both multipart and raw file uploads. - Implemented parsing logic for upload requests, including handling file metadata. - Introduced SaveFileDecodedInput structure for handling decoded file uploads. - Created unit tests for file upload parsing and validation. feat: add metadata retry configuration and functionality - Introduced MetadataRetryConfig to the application configuration. - Implemented MetadataRetryer to handle retrying metadata extraction for thoughts. - Added new tool for retrying failed metadata extractions. - Updated thought metadata structure to include status and timestamps for metadata processing. fix: enhance metadata normalization and error handling - Updated metadata normalization functions to track status and errors. - Improved handling of metadata extraction failures during thought updates and captures. - Ensured that metadata status is correctly set during various operations. refactor: streamline file saving logic in FilesTool - Refactored Save method in FilesTool to utilize new SaveDecoded method. - Simplified project and thought ID resolution logic during file saving.
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package app
|
|
|
|
import (
|
|
"bytes"
|
|
"mime/multipart"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseRawUploadRequiresName(t *testing.T) {
|
|
req := httptest.NewRequest(http.MethodPost, "/files", bytes.NewReader([]byte("hello")))
|
|
req.Header.Set("Content-Type", "application/octet-stream")
|
|
|
|
_, err := parseRawUpload(req)
|
|
if err == nil {
|
|
t.Fatal("expected error for missing name")
|
|
}
|
|
}
|
|
|
|
func TestParseMultipartUploadUsesFileMetadata(t *testing.T) {
|
|
var body bytes.Buffer
|
|
writer := multipart.NewWriter(&body)
|
|
|
|
part, err := writer.CreateFormFile("file", "note.txt")
|
|
if err != nil {
|
|
t.Fatalf("create form file: %v", err)
|
|
}
|
|
if _, err := part.Write([]byte("hello world")); err != nil {
|
|
t.Fatalf("write form file: %v", err)
|
|
}
|
|
_ = writer.WriteField("project", "amcs")
|
|
_ = writer.WriteField("kind", "document")
|
|
if err := writer.Close(); err != nil {
|
|
t.Fatalf("close writer: %v", err)
|
|
}
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/files", &body)
|
|
req.Header.Set("Content-Type", writer.FormDataContentType())
|
|
|
|
got, err := parseMultipartUpload(req)
|
|
if err != nil {
|
|
t.Fatalf("parse multipart upload: %v", err)
|
|
}
|
|
if got.Name != "note.txt" {
|
|
t.Fatalf("name = %q, want note.txt", got.Name)
|
|
}
|
|
if string(got.Content) != "hello world" {
|
|
t.Fatalf("content = %q, want hello world", string(got.Content))
|
|
}
|
|
if got.Project != "amcs" {
|
|
t.Fatalf("project = %q, want amcs", got.Project)
|
|
}
|
|
if got.Kind != "document" {
|
|
t.Fatalf("kind = %q, want document", got.Kind)
|
|
}
|
|
}
|