Files
clice/tests/unit/server/pch_worker_tests.cpp
ykiko 418e190fa0 chore(deps): migrate from eventide to kotatsu (#428)
## Summary

- The `eventide` dep was renamed to
[kotatsu](https://github.com/clice-io/kotatsu) with a broad rename of
CMake identifiers, namespaces, header paths, and a few module reorgs
(`serde` → `codec`, `reflection` → `meta`, `common` → `support`). Align
clice to the new names.
- CMake: FetchContent target, option prefix (`ETD_*` → `KOTA_*`,
`ETD_SERDE_*` → `KOTA_CODEC_*`), target names
(`eventide::{ipc::lsp,serde::toml,deco,zest}` →
`kota::{ipc::lsp,codec::toml,deco,zest}`).
- Namespaces: `eventide::` → `kota::`, `eventide::serde::` →
`kota::codec::`, `eventide::refl::` → `kota::meta::`. The short `et`
alias is dropped — all usages now spell `kota::` directly.
- Headers: `eventide/*` → `kota/*`, including special cases
`serde/serde/raw_value.h` → `codec/raw_value.h`, `ipc/json_codec.h` →
`ipc/codec/json.h`, `common/meta.h` → `support/type_traits.h`,
`common/ranges.h` → `support/ranges.h`.
- Kotatsu split `JsonPeer` / `BincodePeer` out of `ipc/peer.h` into the
codec-specific headers; added `kota/ipc/codec/{json,bincode}.h` includes
where those types are used.
- Depends on clice-io/kotatsu#110 (already merged) to prevent `-Wall
-Wextra -Werror` from transitively propagating out of
`kota::project_options`.

## Test plan

- [x] `pixi run unit-test RelWithDebInfo` — 518/518 pass (9 skipped,
unchanged from main)
- [x] `pixi run integration-test RelWithDebInfo` — 119/119 pass
- [x] `pixi run smoke-test RelWithDebInfo` — 2/2 pass
- [x] `pixi run format` clean

## Notes

- `tests/smoke/rapid_edit.jsonl` was intentionally left untouched: the
embedded `#include "eventide/..."` strings are frozen snapshots of file
contents the client sent at record time, not clice source.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Chores**
* Updated internal dependencies from `eventide` to `kota`, including
async runtime, IPC transport, serialization codec, and metadata
libraries.
* Updated build configuration and CMake variables to align with the new
dependency.

* **Refactor**
* Migrated internal implementation to use `kota` namespace and APIs
throughout the codebase.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 13:49:07 +08:00

154 lines
4.4 KiB
C++

#include <string>
#include <vector>
#include "test/test.h"
#include "server/protocol.h"
#include "server/worker_test_helpers.h"
#include "syntax/scan.h"
namespace clice::testing {
namespace {
// ============================================================================
// End-to-end PCH compilation through real workers:
// 1. Stateless worker builds PCH for preamble headers
// 2. Stateful worker compiles a file using the PCH
// ============================================================================
TEST_SUITE(PCHWorker) {
TEST_CASE(BuildPCHThenCompile) {
TempDir tmp;
tmp.touch("common.h", R"cpp(struct Point { int x, y; };)cpp" "\n");
auto header = tmp.path("common.h");
std::string main_text = "#include \"common.h\"\nPoint p{1,2};\n";
tmp.touch("main.cpp", main_text);
auto main_file = tmp.path("main.cpp");
auto dir = std::string(tmp.root);
// --- Phase 1: Build PCH via stateless worker ---
WorkerHandle sl;
ASSERT_TRUE(sl.spawn("stateless-worker"));
std::string pch_path;
bool phase1_done = false;
sl.run([&]() -> kota::task<> {
worker::BuildParams params;
params.kind = worker::BuildKind::BuildPCH;
params.file = main_file;
params.directory = dir;
params.arguments = {"clang++",
"-resource-dir",
std::string(resource_dir()),
"-x",
"c++-header",
"-I",
dir,
main_file};
params.text = main_text;
params.output_path = tmp.path("preamble.pch");
auto result = co_await sl.peer->send_request(params);
CO_ASSERT_TRUE(result.has_value());
CO_ASSERT_TRUE(result.value().success);
pch_path = result.value().output_path;
EXPECT_FALSE(pch_path.empty());
phase1_done = true;
sl.peer->close_output();
});
ASSERT_TRUE(phase1_done);
ASSERT_FALSE(pch_path.empty());
// Verify the PCH file exists on disk.
ASSERT_TRUE(llvm::sys::fs::exists(pch_path));
// --- Phase 2: Compile with PCH via stateful worker ---
WorkerHandle sf;
ASSERT_TRUE(sf.spawn("stateful-worker"));
bool phase2_done = false;
auto preamble_bound = compute_preamble_bound(main_text);
sf.run([&]() -> kota::task<> {
worker::CompileParams params;
params.path = main_file;
params.version = 1;
params.text = main_text;
params.directory = dir;
params.arguments = {"clang++",
"-resource-dir",
std::string(resource_dir()),
"-fsyntax-only",
"-I",
dir,
main_file};
params.pch = {pch_path, preamble_bound};
auto result = co_await sf.peer->send_request(params);
CO_ASSERT_TRUE(result.has_value());
EXPECT_EQ(result.value().version, 1);
phase2_done = true;
sf.peer->close_output();
});
ASSERT_TRUE(phase2_done);
// Cleanup PCH temp file.
std::remove(pch_path.c_str());
}
TEST_CASE(CompileWithoutPCHStillWorks) {
TempDir tmp;
tmp.touch("common.h", R"cpp(struct Point { int x, y; };)cpp" "\n");
std::string main_text = "#include \"common.h\"\nPoint p{1,2};\n";
tmp.touch("main.cpp", main_text);
auto main_file = tmp.path("main.cpp");
auto dir = std::string(tmp.root);
WorkerHandle sf;
ASSERT_TRUE(sf.spawn("stateful-worker"));
bool compile_done = false;
sf.run([&]() -> kota::task<> {
worker::CompileParams params;
params.path = main_file;
params.version = 1;
params.text = main_text;
params.directory = dir;
params.arguments = {"clang++",
"-resource-dir",
std::string(resource_dir()),
"-fsyntax-only",
"-I",
dir,
main_file};
// pch left as default (empty path, 0 bound).
auto result = co_await sf.peer->send_request(params);
CO_ASSERT_TRUE(result.has_value());
EXPECT_EQ(result.value().version, 1);
compile_done = true;
sf.peer->close_output();
});
ASSERT_TRUE(compile_done);
}
}; // TEST_SUITE(PCHWorker)
} // namespace
} // namespace clice::testing