Files
moloapp/tests/src/vendors/cohere/support.h
T

52 lines
1.7 KiB
C++
Raw Normal View History

#pragma once
// Shared rig for the Cohere tests: a Platform over a MockTransport with a fake
// key. The mock only records the requests the real client builds; replies are
// the spec's documented examples (fixtures.h, verbatim) or minimal documents
// shaped from the OpenAPI schemas and labelled SHAPE where they appear. Nothing
// here verifies vendor behavior (see src/vendors/cohere/SPEC.md ## Unverified).
#include <memory>
#include <string>
#include "clients/transports/mock_transport.h"
#include "fixtures.h"
#include "framework.h"
#include "vendors/cohere/platform.h"
namespace cohere_test {
using molo::clients::ClientResponse;
using molo::clients::HeaderMap;
using molo::clients::Method;
using molo::clients::transports::MockExpectation;
using molo::clients::transports::MockTransport;
using Json = molo::clients::body::Json;
inline ClientResponse reply(const std::string& body, int status = 200,
const std::string& type = "application/json") {
HeaderMap h;
h.set("Content-Type", type);
return ClientResponse(status, h, body);
}
inline ClientResponse sse(const std::string& body) { return reply(body, 200, "text/event-stream"); }
inline bool has(const std::string& hay, const std::string& needle) { return hay.find(needle) != std::string::npos; }
inline const char* kKey = "co-TESTKEY-DO-NOT-LEAK";
struct Rig {
MockTransport* mock = nullptr;
molo::cohere::Platform platform;
explicit Rig(const std::string& key = kKey) {
auto t = std::make_unique<MockTransport>();
mock = t.get();
platform = molo::cohere::Platform::with(std::move(t), key);
}
std::shared_ptr<molo::llm::ApiClient> client() const { return platform.client; }
};
} // namespace cohere_test