Simplifies the active Windows build path around Boost.Beast/OpenSSL, fixes VS2017/clang-cl compatibility, and removes unused BearSSL/WinHTTP remnants so the project builds and tests cleanly. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
89 lines
2.8 KiB
C++
89 lines
2.8 KiB
C++
#include "dstalk/dstalk_api.h"
|
|
|
|
#include <cstring>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
int main()
|
|
{
|
|
const auto dir = std::filesystem::temp_directory_path() / "dstalk-smoke-test";
|
|
std::filesystem::create_directories(dir);
|
|
|
|
const auto config_path = dir / "config.toml";
|
|
{
|
|
std::ofstream config(config_path);
|
|
config << "[api]\n"
|
|
<< "provider = \"deepseek\"\n"
|
|
<< "base_url = \"https://api.deepseek.com/v1\"\n"
|
|
<< "api_key = \"test-key\"\n"
|
|
<< "model = \"deepseek-chat\"\n";
|
|
}
|
|
|
|
if (dstalk_init(config_path.string().c_str()) != 0) {
|
|
std::cerr << "dstalk_init failed\n";
|
|
return 1;
|
|
}
|
|
|
|
const auto file_path = dir / "sample.txt";
|
|
constexpr const char* sample_content = "hello dstalk\nquote=\"yes\" tab=\t slash=\\";
|
|
if (dstalk_file_write(file_path.string().c_str(), sample_content) != 0) {
|
|
std::cerr << "dstalk_file_write failed\n";
|
|
dstalk_destroy();
|
|
return 1;
|
|
}
|
|
|
|
char* content = nullptr;
|
|
if (dstalk_file_read(file_path.string().c_str(), &content) != 0 || !content) {
|
|
std::cerr << "dstalk_file_read failed\n";
|
|
dstalk_destroy();
|
|
return 1;
|
|
}
|
|
|
|
const bool ok = std::strcmp(content, sample_content) == 0;
|
|
dstalk_free_string(content);
|
|
if (!ok) {
|
|
std::cerr << "unexpected file content\n";
|
|
dstalk_destroy();
|
|
return 1;
|
|
}
|
|
|
|
const auto session_path = dir / "session.jsonl";
|
|
const auto saved_session_path = dir / "session-saved.jsonl";
|
|
constexpr const char* session_content =
|
|
"{\"role\":\"user\",\"content\":\"line\\n\\\"quote\\\"\\\\slash\"}\n"
|
|
"{\"role\":\"assistant\",\"content\":\"ok\\tready\"}\n";
|
|
if (dstalk_file_write(session_path.string().c_str(), session_content) != 0) {
|
|
std::cerr << "session fixture write failed\n";
|
|
dstalk_destroy();
|
|
return 1;
|
|
}
|
|
if (dstalk_session_load(session_path.string().c_str()) != 0) {
|
|
std::cerr << "dstalk_session_load failed\n";
|
|
dstalk_destroy();
|
|
return 1;
|
|
}
|
|
if (dstalk_session_save(saved_session_path.string().c_str()) != 0) {
|
|
std::cerr << "dstalk_session_save failed\n";
|
|
dstalk_destroy();
|
|
return 1;
|
|
}
|
|
|
|
char* saved_session = nullptr;
|
|
if (dstalk_file_read(saved_session_path.string().c_str(), &saved_session) != 0 || !saved_session) {
|
|
std::cerr << "saved session read failed\n";
|
|
dstalk_destroy();
|
|
return 1;
|
|
}
|
|
const bool session_ok = std::strcmp(saved_session, session_content) == 0;
|
|
dstalk_free_string(saved_session);
|
|
dstalk_destroy();
|
|
|
|
if (!session_ok) {
|
|
std::cerr << "unexpected saved session content\n";
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|