Implement the VLS roadmap on the native VBS build

Native VBS and CMake builds of the server and every registered suite:
protocol and document sync, VBS/compdb providers, stock GCC diagnostics
(including in-process default profile preparation), the stock occurrence
observer and hover/definition, the bounded Scheduler, C++ module graph,
scan and artifact cache with real CMI production, the context-aware
symbol index with schema-2 snapshot migration, navigation and guarded
rename, reflection provenance with splice-origin extraction, index-backed
completion and signature help, live GCC worker control with a registered
DAP suite, and the Neovim and VS Code clients.

VoidLibrary follows main. The private GCC 16.2.0 frontend is reproduced
from the versioned patches and verified stepping reflection/template code
with projected values 17/34 and 41/82.
This commit is contained in:
faumaray committed 2026-12-05 14:06:50 +03:00
1 parent ca04975d54
commit da8003f6d4
310 files changed
+47552 -480

No files matched your search

+354
View File
@@ -0,0 +1,354 @@
#include "Trace.hpp"
#include <Void/LanguageServer/Protocol/Framing.hpp>
#include <Void/System/Process.hpp>
#include <Void/System/TempDir.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <vls/debug/inspection/ReplaySession.hpp>
#include <algorithm>
#include <chrono>
#include <cstdint>
#include <filesystem>
#include <format>
#include <initializer_list>
#include <sstream>
#include <string>
#include <string_view>
#include <type_traits>
#include <vector>
namespace {
namespace protocol = Void::LanguageServer::Protocol;
using protocol::Json;
using Void::Testing::expect;
using Void::Testing::expect_eq;
using Void::Testing::require;
using namespace std::chrono_literals;
using namespace std::string_view_literals;
std::filesystem::path adapter_executable() {
#ifdef VLS_DAP_EXECUTABLE
return VLS_DAP_EXECUTABLE;
#else
return std::filesystem::read_symlink("/proc/self/exe").parent_path() / "vls-dap";
#endif
}
const Json *member(const Json &value, std::string_view key) {
const auto *object = protocol::as_object(&value);
require(object != nullptr);
return protocol::find_member(*object, key);
}
const Json &field(const Json &value, std::string_view key) {
const auto *entry = member(value, key);
require(entry != nullptr);
return *entry;
}
const Json::Array &array(const Json &value, std::string_view key) {
const auto *entries = protocol::as_array(member(value, key));
require(entries != nullptr);
return *entries;
}
std::string_view text(const Json &value, std::string_view key) {
const auto *entry = protocol::as_string(member(value, key));
require(entry != nullptr);
return *entry;
}
std::int64_t integer(const Json &value, std::string_view key) {
const auto *entry = std::get_if<std::int64_t>(&field(value, key).value);
require(entry != nullptr);
return *entry;
}
struct Request {
std::string_view command;
std::string_view arguments{"{}"};
};
constexpr Request initialize{"initialize", R"({"adapterID":"vls"})"};
constexpr Request continue_thread{"continue", R"({"threadId":1})"};
constexpr Request stack_trace{"stackTrace", R"({"threadId":1})"};
struct Transcript {
std::vector<Json> messages;
const Json &response(int sequence, std::string_view command, bool success = true) const {
const auto matches = [sequence](const Json &message) {
return text(message, "type") == "response" &&
integer(message, "request_seq") == sequence;
};
const auto found = std::ranges::find_if(messages, matches);
require(found != messages.end());
expect_eq(std::ranges::count_if(messages, matches), std::ptrdiff_t{1});
expect_eq(text(*found, "command"), command);
expect(protocol::as_bool(member(*found, "success")) == success);
return *found;
}
std::vector<const Json *> events(std::string_view name) const {
std::vector<const Json *> result;
for (const auto &message : messages) {
if (text(message, "type") == "event" && text(message, "event") == name)
result.push_back(&message);
}
return result;
}
};
Transcript
run(std::initializer_list<Request> requests,
const std::filesystem::path &fixture = std::filesystem::path{__FILE__}.parent_path() /
"fixtures" / "integral-17.vls",
std::size_t output_limit = 128 * 1024) {
std::ostringstream input;
int client_sequence = 0;
for (const auto &request : requests) {
const auto body =
std::format(R"({{"seq":{},"type":"request","command":"{}","arguments":{}}})",
++client_sequence, request.command, request.arguments);
require(protocol::write_frame(input, body).has_value());
}
require(fixture.is_absolute());
Void::Process::SpawnOptions options;
options.executable = adapter_executable();
require(options.executable.is_absolute());
options.arguments = {"--replay", fixture.string()};
options.search_path = false;
options.environment.mode = Void::Process::EnvMode::explicit_only;
options.environment.set_vars = {{"LC_ALL", "C"}, {"PATH", ""}};
options.kill_grace = 100ms;
auto child = Void::Process::spawn(options);
require(child.has_value());
Void::Process::CaptureLimits limits;
limits.max_stdin_bytes = 8192;
limits.max_stdout_bytes = output_limit;
limits.max_line_bytes = output_limit;
limits.max_stderr_bytes = 8192;
const auto output = Void::Process::communicate_blocking(*child, input.str(), limits, 4s);
require(output.has_value());
require(!output->timed_out && !output->cancelled && !output->overflowed);
require(output->status.exited);
expect_eq(output->status.code, 0);
expect_eq(output->err, std::string{});
Transcript transcript;
std::istringstream replies{output->out};
std::int64_t adapter_sequence = 0;
for (;;) {
const auto frame = protocol::read_frame(replies, {.body_bytes = limits.max_stdout_bytes});
require(frame.has_value());
if (!*frame)
break;
auto message = protocol::parse_json(**frame);
require(message.has_value());
expect_eq(integer(*message, "seq"), ++adapter_sequence);
const auto type = text(*message, "type");
require(type == "event" || type == "response");
if (type == "response") {
const auto request_sequence = integer(*message, "request_seq");
expect(request_sequence >= 1 && request_sequence <= client_sequence);
} else {
expect(text(*message, "event") != "exited");
}
transcript.messages.push_back(std::move(*message));
}
return transcript;
}
void write_manifest(const std::filesystem::path &path, std::string_view source) {
auto trace =
vls::gcc::Trace::create(path, source, std::string(64, 'a'), std::string(32, 'b'), 1234);
require(trace.has_value());
}
void expect_before(const Json &first, const Json &second) {
expect(integer(first, "seq") < integer(second, "seq"));
}
void expect_stack(const Json &reply, std::initializer_list<std::string_view> names) {
const auto &frames = array(field(reply, "body"), "stackFrames");
require(frames.size() == names.size());
auto name = names.begin();
for (const auto &frame : frames) {
expect_eq(text(frame, "name"), *name++);
expect(integer(frame, "id") > 0);
expect(member(frame, "source") == nullptr);
expect_eq(integer(frame, "line"), std::int64_t{0});
expect_eq(integer(frame, "column"), std::int64_t{0});
}
}
} // namespace
VOID_TEST(DapReplay, deferred_launch_finishes_after_configuration_done) {
const auto dap =
run({initialize,
{"launch"},
{"setBreakpoints",
R"({"source":{"name":"input.cpp"},"breakpoints":[{"line":5},{"line":10}]})"},
{"setExceptionBreakpoints", R"({"filters":[]})"},
{"configurationDone"},
{"threads"},
stack_trace,
continue_thread,
stack_trace,
{"disconnect"}});
const auto &init = dap.response(1, "initialize");
const auto initialized = dap.events("initialized");
require(initialized.size() == 1);
expect_eq(integer(init, "seq"), std::int64_t{1});
expect_before(init, *initialized.front());
const auto &capabilities = field(init, "body");
for (const auto name : {"supportsConfigurationDoneRequest", "supportsLoadedSourcesRequest",
"supportsTerminateRequest"}) {
expect(protocol::as_bool(member(capabilities, name)) == true);
}
for (const auto name : {"supportsStepBack", "supportsSteppingGranularity",
"supportsRestartFrame", "supportsDisassembleRequest"}) {
expect(protocol::as_bool(member(capabilities, name)) != true);
}
const auto &breakpoint_reply = dap.response(3, "setBreakpoints");
const auto &breakpoints = array(field(breakpoint_reply, "body"), "breakpoints");
require(breakpoints.size() == 2);
for (const auto &breakpoint : breakpoints)
expect(protocol::as_bool(member(breakpoint, "verified")) == false);
dap.response(4, "setExceptionBreakpoints");
const auto &configured = dap.response(5, "configurationDone");
const auto &launch = dap.response(2, "launch");
const auto stopped = dap.events("stopped");
require(stopped.size() == 2);
expect_before(*initialized.front(), configured);
expect_before(configured, launch);
expect_before(launch, *stopped[0]);
expect_before(dap.response(8, "continue"), *stopped[1]);
for (const auto *stop : stopped) {
const auto &body = field(*stop, "body");
expect_eq(integer(body, "threadId"), std::int64_t{1});
expect(!text(body, "reason").empty());
}
const auto &threads = array(field(dap.response(6, "threads"), "body"), "threads");
require(threads.size() == 1);
expect_eq(integer(threads.front(), "id"), std::int64_t{1});
expect_stack(dap.response(7, "stackTrace"), {"reflected_value", "twice"});
expect_stack(dap.response(9, "stackTrace"), {"twice"});
dap.response(10, "disconnect");
}
VOID_TEST(DapReplay, configuration_done_can_precede_launch_and_terminate) {
const auto dap =
run({initialize, {"configurationDone"}, {"launch"}, {"terminate"}, {"disconnect"}});
const auto &configured = dap.response(2, "configurationDone");
const auto &launch = dap.response(3, "launch");
const auto stopped = dap.events("stopped");
const auto terminated = dap.events("terminated");
require(stopped.size() == 1);
require(terminated.size() == 1);
expect_before(configured, launch);
expect_before(launch, *stopped.front());
expect_before(*stopped.front(), dap.response(4, "terminate"));
expect_before(dap.response(4, "terminate"), *terminated.front());
dap.response(5, "disconnect");
}
VOID_TEST(DapReplay, disconnect_settles_a_deferred_launch) {
const auto dap = run({initialize, {"launch"}, {"disconnect"}});
dap.response(1, "initialize");
dap.response(2, "launch", false);
dap.response(3, "disconnect");
expect(dap.events("stopped").empty());
}
VOID_TEST(DapReplay, one_session_identity_has_one_cursor_and_finishes_once) {
using vls::debug::ReplaySession;
static_assert(!std::is_copy_constructible_v<ReplaySession>);
static_assert(!std::is_copy_assignable_v<ReplaySession>);
const auto recording =
std::filesystem::path{__FILE__}.parent_path() / "fixtures" / "integral-17.vls";
auto opened = ReplaySession::open(recording);
require(opened.has_value());
auto session = std::move(*opened);
require(session.seek(6).has_value());
const auto stopped = session.identity();
session.finish();
const auto done = session.identity();
expect(!session.matches(stopped));
expect(!session.seek(10));
expect(!session.move_to_value(true));
expect(!session.initial_position());
expect(!session.paused());
session.finish();
expect(session.matches(done));
}
VOID_TEST(DapReplay, binary_source_keeps_its_digest_and_has_no_text_reference) {
Void::FileSystem::TempDir dir{"vls_dap_source_"};
const auto path = dir / "binary.vls";
write_manifest(path, "a\0\xffz"sv);
const auto dap = run({initialize,
{"launch"},
{"configurationDone"},
{"vls/session"},
{"loadedSources"},
{"source", R"({"sourceReference":1})"},
{"disconnect"}},
path);
const auto &state = field(dap.response(4, "vls/session"), "body");
expect(protocol::as_bool(member(state, "sourceAvailable")) == false);
expect_eq(integer(state, "sourceByteLength"), std::int64_t{4});
expect_eq(text(state, "sourceSha256").size(), std::size_t{64});
expect(member(state, "sourceReference") == nullptr);
expect(array(field(dap.response(5, "loadedSources"), "body"), "sources").empty());
dap.response(6, "source", false);
expect(dap.events("stopped").empty());
}
VOID_TEST(DapReplay, full_size_control_filled_source_round_trips_as_exact_text) {
Void::FileSystem::TempDir dir{"vls_dap_source_"};
const auto path = dir / "controls.vls";
std::string source(1024 * 1024, '\0');
source.back() = '\x1f';
write_manifest(path, source);
const auto dap = run({initialize,
{"configurationDone"},
{"launch"},
{"source", R"({"sourceReference":1})"},
{"disconnect"}},
path, 8 * 1024 * 1024);
const auto &body = field(dap.response(4, "source"), "body");
expect(text(body, "content") == source);
expect(dap.events("stopped").empty());
}
VOID_TEST(DapReplay, unsupported_or_unreachable_controls_fail_without_moving) {
const auto dap = run({initialize,
continue_thread,
{"launch"},
{"configurationDone"},
{"next", R"({"threadId":1})"},
{"stepBack", R"({"threadId":1})"},
{"continue", R"({"threadId":2})"},
stack_trace,
{"disconnect"}});
dap.response(2, "continue", false);
dap.response(3, "launch");
dap.response(4, "configurationDone");
dap.response(5, "next", false);
dap.response(6, "stepBack", false);
dap.response(7, "continue", false);
expect_stack(dap.response(8, "stackTrace"), {"reflected_value", "twice"});
dap.response(9, "disconnect");
expect(dap.events("stopped").size() == 1);
}
+199
View File
@@ -0,0 +1,199 @@
#include <Void/LanguageServer/Protocol/Json.hpp>
#include <Void/System/Process.hpp>
#include <Void/System/TempDir.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <cerrno>
#include <chrono>
#include <cstdint>
#include <cstdio>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <poll.h>
#include <string>
#include <string_view>
#include <unistd.h>
namespace {
namespace fs = std::filesystem;
namespace P = Void::LanguageServer::Protocol;
using Json = P::Json;
using Void::Testing::expect;
using Void::Testing::require;
using namespace std::chrono_literals;
fs::path sibling(std::string_view name) {
const auto directory = fs::canonical("/proc/self/exe").parent_path();
// VBS keeps every executable in one directory; CMake puts the server tools
// at the build root and the test executables under tests/.
if (fs::exists(directory / name))
return directory / name;
return directory.parent_path() / name;
}
void write_frame(int fd, const Json &message) {
auto body = P::serialize_json(message);
require(body.has_value());
const std::string header = "Content-Length: " + std::to_string(body->size()) + "\r\n\r\n";
for (const std::string_view part : {std::string_view{header}, std::string_view{*body}}) {
std::size_t done{};
while (done != part.size()) {
const auto written = ::write(fd, part.data() + done, part.size() - done);
require(written > 0);
done += static_cast<std::size_t>(written);
}
}
}
std::optional<Json> read_frame(int fd, std::string &buffer) {
const auto deadline = std::chrono::steady_clock::now() + 20s;
while (true) {
const auto header = buffer.find("\r\n\r\n");
if (header != std::string::npos) {
const auto marker = buffer.find("Content-Length: ");
require(marker != std::string::npos);
const auto length = std::stoul(buffer.substr(marker + 16));
if (buffer.size() >= header + 4 + length) {
const auto body = buffer.substr(header + 4, length);
buffer.erase(0, header + 4 + length);
auto parsed = P::parse_json(body, 8);
require(parsed.has_value());
return *parsed;
}
}
if (std::chrono::steady_clock::now() >= deadline)
return std::nullopt;
pollfd pipe{fd, POLLIN, 0};
if (::poll(&pipe, 1, 100) <= 0)
continue;
char bytes[8192];
const auto read = ::read(fd, bytes, sizeof bytes);
if (read <= 0)
return std::nullopt;
buffer.append(bytes, static_cast<std::size_t>(read));
}
}
Json wait_response(int fd, std::string &buffer, std::int64_t sequence) {
while (true) {
auto message = read_frame(fd, buffer);
require(message.has_value());
const auto *fields = P::as_object(&*message);
require(fields);
const auto *type = P::as_string(P::find_member(*fields, "type"));
const auto *request = P::find_member(*fields, "request_seq");
if (type && *type == "response" && request)
if (const auto *value = std::get_if<std::int64_t>(&request->value);
value && *value == sequence)
return *message;
}
}
Json wait_event(int fd, std::string &buffer, std::string_view name) {
while (true) {
auto message = read_frame(fd, buffer);
require(message.has_value());
const auto *fields = P::as_object(&*message);
require(fields);
const auto *type = P::as_string(P::find_member(*fields, "type"));
const auto *event = P::as_string(P::find_member(*fields, "event"));
if (type && event && *type == "event" && *event == name)
return *message;
}
}
} // namespace
VOID_TEST(LiveDap, breakpoints_and_typed_inspection_over_the_adapter) {
Void::FileSystem::TempDir temp{"vls_live_dap_"};
const auto source = temp.path() / "normal.cpp";
std::ofstream{source} << "int value = 17;\n";
const auto trace = temp.path() / "session.vls";
Void::Process::SpawnOptions spawn;
spawn.executable = sibling("vls-dap");
spawn.arguments = {"--live", sibling("vls_live_worker_fixture").native(),
"/private/cc1plus", std::string(64, 'a'),
source.native(), trace.native()};
spawn.search_path = false;
auto child = Void::Process::spawn(spawn);
require(child.has_value());
const int input = child->stdin_fd(), output = child->stdout_fd();
std::string buffer;
std::int64_t sequence{};
auto request = [&](std::string_view command, Json::Object arguments) {
write_frame(input, Json{Json::Object{{"seq", Json{++sequence}},
{"type", Json{std::string{"request"}}},
{"command", Json{std::string{command}}},
{"arguments", Json{std::move(arguments)}}}});
return sequence;
};
const auto object_of = [](const Json &value) {
const auto *fields = P::as_object(&value);
require(fields != nullptr);
return fields;
};
const auto bool_of = [](const Json &value, std::string_view name) {
const auto *fields = P::as_object(&value);
require(fields != nullptr);
return P::as_bool(P::find_member(*fields, name)).value_or(false);
};
request("initialize", {{"adapterID", Json{std::string{"vls"}}}});
expect(bool_of(wait_response(output, buffer, sequence), "success"));
wait_event(output, buffer, "initialized");
request("launch", {});
request("configurationDone", {});
wait_event(output, buffer, "stopped");
// Typed value projection from the live inspection snapshot. The reply
// objects must outlive the pointers into them, so each is kept in a local.
request("stackTrace", {{"threadId", Json{std::int64_t{1}}}});
const Json stack_reply = wait_response(output, buffer, sequence);
const auto *stack_body = P::as_object(P::find_member(*object_of(stack_reply), "body"));
require(stack_body);
const auto *frames = P::as_array(P::find_member(*stack_body, "stackFrames"));
require(frames && !frames->empty());
const auto *frame = P::as_object(&frames->front());
require(frame);
const auto *handle = P::find_member(*frame, "id");
require(handle);
request("scopes", {{"frameId", *handle}});
const Json scopes_reply = wait_response(output, buffer, sequence);
const auto *scopes_body = P::as_object(P::find_member(*object_of(scopes_reply), "body"));
require(scopes_body);
const auto *scope_list = P::as_array(P::find_member(*scopes_body, "scopes"));
require(scope_list && !scope_list->empty());
const auto *scope = P::as_object(&scope_list->front());
require(scope);
const auto *reference = P::find_member(*scope, "variablesReference");
require(reference);
request("variables", {{"variablesReference", *reference}});
const Json values_reply = wait_response(output, buffer, sequence);
const auto *values_body = P::as_object(P::find_member(*object_of(values_reply), "body"));
require(values_body);
const auto *variables = P::as_array(P::find_member(*values_body, "variables"));
require(variables);
bool projected{}, reflected{};
for (const auto &value : *variables) {
const auto *fields = P::as_object(&value);
const auto *name = fields ? P::as_string(P::find_member(*fields, "name")) : nullptr;
const auto *text = fields ? P::as_string(P::find_member(*fields, "value")) : nullptr;
if (name && text && *name == "Result" && *text == "17")
projected = true;
if (name && text && *name == "Ready" && text->find("input.cpp:1:20") != std::string::npos &&
text->find("input.cpp:4:31") != std::string::npos)
reflected = true;
}
expect(projected);
expect(reflected);
// Detailed frame, breakpoint and typed-value projection is covered by the
// real DAP transcript in tests/native/LiveDap.py; this suite registers the
// live control path in the C++ build.
request("continue", {{"threadId", Json{std::int64_t{1}}}});
wait_response(output, buffer, sequence);
wait_event(output, buffer, "terminated");
request("disconnect", {});
wait_response(output, buffer, sequence);
static_cast<void>(child->terminate(1s));
}
+112
View File
@@ -0,0 +1,112 @@
#include <vls/debug/live/LiveSession.hpp>
#include <Void/System/TempDir.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <chrono>
#include <csignal>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <string>
namespace {
namespace fs = std::filesystem;
// A worker may exit while the session still owns its stdin pipe.
struct IgnoreSigpipe {
IgnoreSigpipe() { std::signal(SIGPIPE, SIG_IGN); }
} ignore_sigpipe;
using namespace vls::debug::live;
using namespace std::chrono_literals;
using Void::Testing::expect;
using Void::Testing::require;
struct Fixture {
Void::FileSystem::TempDir temp{"vls_live_session_"};
fs::path source;
fs::path trace;
Options options;
explicit Fixture(std::string name = "normal.cpp", std::chrono::milliseconds deadline = 5s) {
source = temp.path() / name;
std::ofstream{source} << "int value = 17;\n";
trace = temp.path() / "session.vls";
const auto worker =
fs::canonical("/proc/self/exe").parent_path() / "vls_live_worker_fixture";
options = Options{worker, "/private/cc1plus", std::string(64, 'a'), source, trace, true,
deadline, 64 * 1024};
}
};
} // namespace
VOID_TEST(LiveSession, steps_through_stops_and_inspects_each_generation) {
Fixture fixture;
LiveSession session{fixture.options};
const auto first = session.start();
if (!first.has_value())
std::cerr << "start error: " << first.error() << '\n';
require(first.has_value());
expect(first->generation == 1 && first->sequence == 1);
expect(session.state() == State::stopped);
const auto first_snapshot = session.inspect();
require(first_snapshot.has_value());
const auto first_json = Void::LanguageServer::Protocol::serialize_json(*first_snapshot);
require(first_json.has_value());
expect(first_json->find("\"17\"") != std::string::npos);
const auto second = session.step();
require(second.has_value() && second->has_value());
expect((*second)->generation == 2 && (*second)->sequence == 2);
const auto second_snapshot = session.inspect();
require(second_snapshot.has_value());
const auto second_json = Void::LanguageServer::Protocol::serialize_json(*second_snapshot);
require(second_json.has_value());
expect(second_json->find("\"34\"") != std::string::npos);
require(session.step().has_value());
const auto done = session.step();
require(done.has_value());
expect(!done->has_value());
expect(session.state() == State::completed && session.outcome() == "completed");
}
VOID_TEST(LiveSession, continue_finishes_the_session) {
Fixture fixture;
LiveSession session{fixture.options};
require(session.start().has_value());
const auto done = session.continue_run();
require(done.has_value());
expect(!done->has_value() && session.state() == State::completed);
expect(session.stop() == std::nullopt);
}
VOID_TEST(LiveSession, cancel_terminates_at_a_stop) {
Fixture fixture;
LiveSession session{fixture.options};
require(session.start().has_value());
require(session.cancel().has_value());
expect(session.state() == State::cancelled);
}
VOID_TEST(LiveSession, refuses_movement_without_a_stop) {
Fixture fixture;
LiveSession session{fixture.options};
expect(!session.step().has_value());
expect(!session.inspect().has_value());
expect(!session.cancel().has_value());
}
VOID_TEST(LiveSession, rejects_malformed_worker_output) {
Fixture fixture{"malformed.cpp"};
LiveSession session{fixture.options};
const auto started = session.start();
require(!started.has_value());
expect(started.error().contains("bound") || started.error().contains("JSON"));
}
VOID_TEST(LiveSession, enforces_the_notice_deadline) {
Fixture fixture{"silent.cpp", 200ms};
LiveSession session{fixture.options};
const auto started = session.start();
require(!started.has_value());
expect(started.error().contains("deadline"));
}
+79
View File
@@ -0,0 +1,79 @@
// Scripted private-compiler worker for the LiveSession suite. It speaks the
// same notice/control protocol as vls_gcc_probe without running a compiler.
#include <chrono>
#include <filesystem>
#include <iostream>
#include <sstream>
#include <string>
#include <thread>
namespace {
constexpr std::string_view nonce = "0123456789abcdef0123456789abcdef";
void notice(const std::string &line) { std::cout << line << '\n' << std::flush; }
void stopped(unsigned sequence) {
notice(R"({"kind":"stopped","nonce":")" + std::string{nonce} + R"(","stop":)" +
std::to_string(sequence) + "}");
}
void finished(std::string_view outcome) {
notice(R"({"kind":"finished","nonce":")" + std::string{nonce} + R"(","outcome":")" +
std::string{outcome} + R"(","exitCode":0,"reason":""})");
}
} // namespace
int main(int argc, char **argv) {
if (argc < 6 || std::string_view(argv[1]) != "run")
return 2;
const std::string scenario = std::filesystem::path(argv[4]).filename().string();
notice(R"({"kind":"started","nonce":")" + std::string{nonce} + R"(","pid":1})");
if (scenario == "silent.cpp") {
std::this_thread::sleep_for(std::chrono::seconds(60));
return 0;
}
if (scenario == "malformed.cpp") {
std::cout << std::string(70000, 'x') << '\n' << std::flush;
return 0;
}
unsigned sequence = 1;
stopped(sequence);
std::string line;
while (std::getline(std::cin, line)) {
std::istringstream fields{line};
std::string received, action;
unsigned requested = 0;
fields >> received >> requested >> action;
if (received != nonce) {
notice(R"({"kind":"rejected"})");
continue;
}
if (action == "inspect") {
notice(
R"({"kind":"inspection","snapshot":{"schemaVersion":1,"sessionId":"live-fixture","generation":)" +
std::to_string(requested) + R"(,"eventSequence":)" + std::to_string(requested) +
R"(,"frames":[{"name":")" +
std::string(requested == 1 ? "reflected_value"
: requested == 2 ? "twice<State>"
: "twice<int>") +
R"(","line":)" + std::to_string(requested) +
R"(,"source":"input.cpp","depth":0,"cached":false}],"values":[{"name":"Result","value":")" +
std::to_string(requested * 17) +
R"("}],"origins":[{"source":"input.cpp","line":4,"byteColumn":31,"targetKind":"declaration","targetName":"Ready","targetSource":"input.cpp","targetLine":1,"targetByteColumn":20}]}})");
} else if (action == "step") {
if (sequence < 3) {
stopped(++sequence);
} else {
finished("completed");
return 0;
}
} else if (action == "continue") {
finished("completed");
return 0;
} else if (action == "cancel") {
finished("cancelled");
return 125;
}
}
return 0;
}
+506
View File
@@ -0,0 +1,506 @@
#include "../../experiments/frontend/gcc-worker/Trace.hpp"
#include <Void/Crypto/Crypto.hpp>
#include <Void/System/TempDir.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <array>
#include <atomic>
#include <barrier>
#include <filesystem>
#include <format>
#include <fstream>
#include <iterator>
#include <limits>
#include <source_location>
#include <thread>
#include <vector>
namespace {
namespace fs = std::filesystem;
namespace protocol = Void::LanguageServer::Protocol;
using protocol::Json;
using vls::gcc::ReplayRecording;
using vls::gcc::ReplayValuePoint;
using vls::gcc::Trace;
using Void::Testing::expect;
using Void::Testing::expect_eq;
using Void::Testing::require;
using namespace std::string_view_literals;
constexpr auto nonce = "00112233445566778899aabbccddeeff"sv;
constexpr auto digest = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"sv;
constexpr std::int64_t pid = 4321;
template <class T>
T checked(std::expected<T, std::string> result,
std::source_location at = std::source_location::current()) {
expect_eq(result ? ""sv : std::string_view{result.error()}, ""sv, at);
require(result.has_value(), at);
return *std::move(result);
}
std::string wire(std::uint32_t seq, std::string_view kind, std::string_view fields = {}) {
return std::format(R"({{"v":1,"nonce":"{}","seq":{},"kind":"{}"{}}})", nonce, seq, kind,
fields);
}
struct Writer {
explicit Writer(const fs::path &path, std::string_view source = "int answer = 17;\n")
: trace(checked(Trace::create(path, source, digest, nonce, pid))) {}
void event(std::string_view kind, std::string_view fields = {}) {
checked(trace->event(wire(sequence++, kind, fields)));
}
void hello() {
event(
"hello",
R"(,"backend":"gcc-16.2.0/vls-eval-1","pid":4321,"capabilities":["integralReturn","cooperativeStep"],"kinds":["hello","enter","body","value","cached","stopped","resumed","leave","terminal","frontendEnd"])");
}
void frame(std::string_view kind, std::uint32_t id, std::optional<std::uint32_t> parent,
std::string_view fields = {}) {
event(kind, std::format(R"(,"frame":{},"parent":{}{})", id,
parent ? std::to_string(*parent) : "null", fields));
}
void enter(std::optional<std::uint32_t> parent, std::string_view name) {
frame(
"enter", sequence, parent,
std::format(
R"(,"name":"{}","sourceKind":"logicalDeclaration","source":"input.cpp","line":5,"byteColumn":17)",
name));
}
void integer(std::uint32_t id, std::optional<std::uint32_t> parent, unsigned value) {
frame(
"value", id, parent,
std::format(
R"(,"value":{{"kind":"integer","precision":32,"signed":true,"bitsHex":"{:08x}"}})",
value));
}
void inner_stop(unsigned value) {
hello();
enter({}, "twice");
frame("body", 1, {});
enter(1, "reflected_value");
frame("body", 3, 1);
integer(3, 1, value);
frame("stopped", 3, 1);
}
void outer_stop(unsigned value) {
checked(trace->authorize(6, "step"));
frame("resumed", 3, 1, R"(,"stop":6,"action":"step")");
frame("leave", 3, 1, R"(,"outcome":"returned")");
integer(1, {}, value);
frame("stopped", 1, {});
}
void finish_pair(std::string_view action = "continue") {
checked(trace->authorize(10, action));
frame("resumed", 1, {}, std::format(R"(,"stop":10,"action":"{}")", action));
frame("leave", 1, {}, R"(,"outcome":"returned")");
event("frontendEnd");
checked(trace->finish("completed", 0, ""));
}
std::unique_ptr<Trace> trace;
std::uint32_t sequence{};
};
void write_pair(const fs::path &path, unsigned inner, std::string_view action = "continue") {
Writer writer{path, std::format("int answer = {};\n", inner)};
writer.inner_stop(inner);
writer.outer_stop(inner * 2);
writer.finish_pair(action);
}
const Json *member(const Json &json, std::string_view key) {
const auto *object = protocol::as_object(&json);
return object ? protocol::find_member(*object, key) : nullptr;
}
const Json &field(const Json &json, std::string_view key) {
const auto *value = member(json, key);
require(value != nullptr);
return *value;
}
std::string_view text(const Json &json, std::string_view key) {
const auto *string = protocol::as_string(&field(json, key));
require(string != nullptr);
return *string;
}
const Json::Array &frames(const Json &json) {
return std::get<Json::Array>(field(json, "frames").value);
}
std::string_view value_bits(const Json &frame) { return text(field(frame, "value"), "bitsHex"); }
void expect_active_value(const ReplayRecording &recording, std::uint32_t seq,
std::string_view bits) {
auto cursor = checked(recording.cursor_at(seq));
require(!frames(cursor).empty());
expect_eq(value_bits(frames(cursor).back()), bits);
}
void expect_point(std::expected<std::optional<ReplayValuePoint>, std::string> result,
std::uint32_t value, std::optional<std::uint32_t> stop) {
const auto point = checked(std::move(result));
require(point.has_value());
expect_eq(point->value_sequence, value);
expect_eq(point->stop_sequence, stop);
}
std::string read_bytes(const fs::path &path) {
std::ifstream in(path, std::ios::binary);
require(in.good());
return {std::istreambuf_iterator<char>{in}, std::istreambuf_iterator<char>{}};
}
void write_bytes(const fs::path &path, std::string_view data,
std::ios::openmode mode = std::ios::trunc) {
std::ofstream out(path, mode | std::ios::binary);
out.write(data.data(), static_cast<std::streamsize>(data.size()));
out.close();
require(out.good());
}
// Produce a checksum-valid suffix the real writer would reject. Keep hash failure distinct
// from transcript failure when testing the immutable reader's verified prefix.
void append_hashed_event(const fs::path &path, std::size_t previous_record,
std::string_view event) {
const auto bytes = read_bytes(path);
const auto previous_digest = bytes.substr(previous_record + 5, 32);
require(previous_digest.size() == 32);
const auto size = event.size();
const std::array header{'E', static_cast<char>(size >> 24), static_cast<char>(size >> 16),
static_cast<char>(size >> 8), static_cast<char>(size)};
auto preimage = previous_digest;
preimage.append(header.data(), header.size()).append(event);
const auto hash = Void::Crypto::sha256(preimage);
require(hash && hash->size() == 32);
std::string record{header.data(), header.size()};
record.append(reinterpret_cast<const char *>(hash->data()), hash->size()).append(event);
write_bytes(path, record, std::ios::app);
}
} // namespace
VOID_TEST(RecordingTests, retains_values_and_source_across_overwrite_replacement_and_unlink) {
Void::FileSystem::TempDir dir{"vls_recording_"};
const auto path = dir / "selected";
const auto edited = dir / "edited";
write_pair(path, 17);
write_pair(edited, 41);
const auto old = checked(ReplayRecording::open(path));
const auto old_page = checked(old->event_page(5, 2));
const auto saved_source = old->source_bytes();
require(fs::copy_file(edited, path, fs::copy_options::overwrite_existing));
const auto newer = checked(ReplayRecording::open(path));
expect_active_value(*old, 6, "00000011");
expect_active_value(*newer, 6, "00000029");
const auto replacement = dir / "replacement";
write_pair(replacement, 17, "step");
fs::rename(replacement, path);
const auto replaced = checked(ReplayRecording::open(path));
require(fs::remove(path));
expect(!ReplayRecording::open(path));
expect_active_value(*old, 10, "00000022");
expect_active_value(*newer, 10, "00000052");
expect_eq(saved_source, "int answer = 17;\n"sv);
expect_eq(newer->source_bytes(), "int answer = 41;\n"sv);
expect(old->metadata().source_sha256 != newer->metadata().source_sha256);
expect_eq(old->metadata().compiler_sha256, digest);
expect_eq(old->metadata().pid, pid);
expect_eq(old_page[1].kind, "stopped"sv);
expect_eq(checked(replaced->event_page(11, 1))[0].acknowledged_action, std::optional{"step"sv});
}
VOID_TEST(RecordingTests, separates_event_time_authorization_acknowledgement_and_wait) {
Void::FileSystem::TempDir dir{"vls_recording_"};
const auto path = dir / "selected";
Writer writer{path};
const auto before_hello = checked(ReplayRecording::open(path));
writer.inner_stop(17);
checked(writer.trace->authorize(6, "step"));
const auto pending = checked(ReplayRecording::open(path));
writer.frame("resumed", 3, 1, R"(,"stop":6,"action":"step")");
writer.frame("leave", 3, 1, R"(,"outcome":"returned")");
writer.integer(1, {}, 34);
writer.frame("stopped", 1, {});
writer.finish_pair("step");
const auto step = checked(ReplayRecording::open(path));
write_pair(dir / "continue", 17);
const auto continued = checked(ReplayRecording::open(dir / "continue"));
expect_eq(before_hello->event_count(), std::size_t{0});
expect(!before_hello->cursor_at(0));
expect(!checked(before_hello->next_value()));
expect(std::holds_alternative<std::nullptr_t>(
field(before_hello->final_cursor(), "sequence").value));
expect(before_hello->metadata().partial && !before_hello->metadata().corrupt);
expect(!before_hello->metadata().outcome && !before_hello->metadata().journal_error);
expect_eq(pending->event_count(), std::size_t{7});
const auto paused_cursor = checked(pending->cursor_at(6));
expect_eq(protocol::as_uint32(member(paused_cursor, "stop")), std::optional<std::uint32_t>{6});
expect(std::holds_alternative<std::nullptr_t>(field(paused_cursor, "pendingAction").value));
const auto authorized = pending->final_cursor();
expect_eq(text(authorized, "pendingAction"), "step"sv);
expect(std::holds_alternative<std::nullptr_t>(field(authorized, "stop").value));
expect(!pending->cursor_at(7));
expect(!checked(pending->event_page(6, 1))[0].acknowledged_action);
expect(!pending->metadata().outcome);
for (const auto &recording : {step, continued}) {
const auto summary = checked(recording->event_page(11, 1))[0];
expect_eq(summary.kind, "resumed"sv);
expect_eq(summary.frame, std::optional<std::uint32_t>{1});
expect(!summary.parent);
expect_eq(summary.acknowledged_stop, std::optional<std::uint32_t>{10});
expect_eq(summary.acknowledged_action,
std::optional{recording == step ? "step"sv : "continue"sv});
const auto historical = checked(recording->cursor_at(6));
expect(member(historical, "outcome") == nullptr && member(historical, "source") == nullptr);
expect(member(historical, "diagnostics") == nullptr &&
member(historical, "partial") == nullptr);
expect_eq(text(historical, "nonce"), nonce);
expect_eq(text(frames(historical).back(), "sourceKind"), "logicalDeclaration"sv);
expect_eq(recording->metadata().outcome, std::optional{"completed"sv});
expect_eq(recording->metadata().exit_code, std::optional{0});
expect(!recording->metadata().partial);
}
}
VOID_TEST(RecordingTests, navigates_observed_integer_values_and_optional_stops_in_both_directions) {
Void::FileSystem::TempDir dir{"vls_recording_"};
const auto path = dir / "selected";
Writer writer{path};
writer.inner_stop(17);
writer.outer_stop(34);
checked(writer.trace->authorize(10, "continue"));
writer.frame("resumed", 1, {}, R"(,"stop":10,"action":"continue")");
writer.frame("leave", 1, {}, R"(,"outcome":"returned")");
writer.enter({}, "unavailable");
writer.frame("body", 13, {});
writer.frame("value", 13, {},
R"(,"value":{"kind":"unavailable","reason":"unsupportedScalar"})");
writer.frame("leave", 13, {}, R"(,"outcome":"returned")");
writer.enter({}, "unattended");
writer.frame("body", 17, {});
writer.integer(17, {}, 22);
writer.frame("leave", 17, {}, R"(,"outcome":"returned")");
writer.event("frontendEnd");
const auto recording = checked(ReplayRecording::open(path));
expect_point(recording->next_value(), 5, 6);
expect_point(recording->next_value(5), 9, 10);
expect_point(recording->next_value(6), 9, 10);
expect_point(recording->next_value(10), 19, {});
expect_point(recording->previous_value(), 19, {});
expect_point(recording->previous_value(19), 9, 10);
expect_point(recording->previous_value(10), 5, 6);
expect_point(recording->previous_value(9), 5, 6);
expect(!checked(recording->previous_value(6)));
expect(!checked(recording->next_value(19)));
expect(!recording->previous_value(22));
expect(!recording->next_value(std::numeric_limits<std::uint32_t>::max()));
expect_eq(recording->event_count(), std::size_t{22});
const auto page = checked(recording->event_page(3, 3));
require(page.size() == 3);
expect_eq(page[0].sequence, 3u);
expect_eq(page[2].kind, "value"sv);
expect_eq(page[2].parent, std::optional<std::uint32_t>{1});
expect(&page[2] == checked(recording->event_page(5, 1)).data());
expect(checked(recording->event_page(22, 256)).empty());
expect(checked(recording->event_page(8, 0)).empty());
expect_eq(checked(recording->event_page(21, 256)).size(), std::size_t{1});
expect(!recording->event_page(23, 0));
expect(!recording->event_page(0, ReplayRecording::max_page_size + 1));
expect(!recording->event_page(std::numeric_limits<std::size_t>::max(), 1));
expect(recording->metadata().partial && !recording->metadata().exit_code);
expect(std::get<bool>(field(recording->final_cursor(), "frontendEnded").value));
}
VOID_TEST(RecordingTests, preserves_provisional_value_failed_leave_and_raw_binary_bytes) {
Void::FileSystem::TempDir dir{"vls_recording_"};
const auto path = dir / "selected";
constexpr auto source = "a\0\xffz"sv;
constexpr auto diagnostics = "err\0\xfe"sv;
Writer writer{path, source};
writer.hello();
writer.enter({}, "cleanup");
writer.frame("body", 1, {});
writer.integer(1, {}, 9);
writer.frame("leave", 1, {}, R"(,"outcome":"failed")");
writer.event("frontendEnd");
const auto before_wait = checked(ReplayRecording::open(path));
checked(writer.trace->finish("failed", 1, diagnostics));
const auto recording = checked(ReplayRecording::open(path));
const auto prior = checked(recording->cursor_at(2));
expect(member(frames(prior).back(), "value") == nullptr);
const auto produced = checked(recording->cursor_at(3));
expect_eq(value_bits(frames(produced).back()), "00000009"sv);
expect(std::get<bool>(field(frames(produced).back(), "valueProvisional").value));
expect(member(frames(produced).back(), "outcome") == nullptr);
const auto later = checked(recording->cursor_at(4));
expect(frames(later).empty());
const auto &leave = field(later, "lastLeave");
expect_eq(value_bits(leave), "00000009"sv);
expect_eq(text(leave, "outcome"), "failed"sv);
expect(std::get<bool>(field(leave, "valueProvisional").value));
expect(!before_wait->diagnostic_bytes());
expect(!before_wait->metadata().outcome);
expect_eq(recording->source_bytes(), source);
expect_eq(recording->diagnostic_bytes(), std::optional{diagnostics});
expect_eq(recording->metadata().outcome, std::optional{"failed"sv});
expect_eq(recording->metadata().exit_code, std::optional{1});
expect(!recording->metadata().partial);
}
VOID_TEST(RecordingTests, separates_truncated_corrupt_and_unverified_outcome_tails) {
Void::FileSystem::TempDir dir{"vls_recording_"};
const auto path = dir / "selected";
write_pair(path, 17);
const auto original = read_bytes(path);
fs::resize_file(path, original.size() - 1);
const auto torn = checked(ReplayRecording::open(path));
expect(torn->metadata().partial && !torn->metadata().corrupt);
require(torn->metadata().journal_error.has_value());
expect_eq(*torn->metadata().journal_error, "truncated trace journal record"sv);
expect_eq(torn->event_count(), std::size_t{14});
expect(!torn->metadata().outcome && !torn->diagnostic_bytes());
expect_active_value(*torn, 6, "00000011");
expect(!torn->cursor_at(14));
write_bytes(path, original + "x");
const auto extra = checked(ReplayRecording::open(path));
expect(extra->metadata().partial && extra->metadata().corrupt);
expect(!extra->metadata().outcome && !extra->diagnostic_bytes());
expect_eq(extra->event_count(), torn->event_count());
expect_eq(extra->metadata().journal_error,
std::optional{"trace journal has data after its process outcome"sv});
auto corrupt = original;
const auto offset = corrupt.find("reflected_value");
require(offset != corrupt.npos);
corrupt[offset] = 'X';
write_bytes(path, corrupt);
const auto prefix = checked(ReplayRecording::open(path));
expect(prefix->metadata().corrupt);
expect_eq(prefix->event_count(), std::size_t{3});
expect(!prefix->cursor_at(3) && !checked(prefix->next_value()));
expect_eq(frames(prefix->final_cursor()).size(), std::size_t{1});
write_bytes(path, original.substr(0, 12));
expect(!ReplayRecording::open(path));
expect(!ReplayRecording::open(path.filename()));
expect(!ReplayRecording::open(dir.path()));
}
VOID_TEST(RecordingTests, rejects_checksum_valid_duplicate_skipped_and_invalid_frame_events) {
Void::FileSystem::TempDir dir{"vls_recording_"};
const auto path = dir / "selected";
Writer writer{path};
const auto hello_offset = fs::file_size(path);
writer.hello();
const auto good = read_bytes(path);
for (const auto &event : {wire(0, "frontendEnd"), wire(2, "frontendEnd"),
wire(1, "body", R"(,"frame":1,"parent":null)")}) {
write_bytes(path, good);
append_hashed_event(path, hello_offset, event);
const auto recording = checked(ReplayRecording::open(path));
expect_eq(recording->event_count(), std::size_t{1});
expect(recording->metadata().corrupt && recording->metadata().partial);
expect(!recording->cursor_at(1));
require(recording->metadata().journal_error.has_value());
expect(recording->metadata().journal_error->starts_with("invalid compiler trace"));
const auto first = checked(recording->event_page(0, 1))[0];
expect_eq(first.kind, "hello"sv);
expect(!first.frame && !first.parent && !first.acknowledged_stop);
}
// The reader must bound allocation by verified record lengths even for a huge sparse file.
write_bytes(path, good);
fs::resize_file(path, 1ull << 30);
const auto sparse = checked(ReplayRecording::open(path));
expect(sparse->metadata().corrupt && sparse->event_count() == 1);
}
VOID_TEST(RecordingTests, seeks_and_pages_at_the_event_limit_with_deep_nesting) {
Void::FileSystem::TempDir dir{"vls_recording_"};
const auto path = dir / "selected";
Writer writer{path};
constexpr std::uint32_t depth = 2047;
writer.hello();
for (std::uint32_t id = 1; id <= depth; ++id) {
writer.enter(id == 1 ? std::nullopt : std::optional{id - 1}, "nested");
}
for (auto id = depth; id > 0; --id) {
writer.frame("leave", id, id == 1 ? std::nullopt : std::optional{id - 1},
R"(,"outcome":"returned")");
}
writer.event("frontendEnd");
checked(writer.trace->finish("completed", 0, ""));
const auto recording = checked(ReplayRecording::open(path));
expect_eq(recording->event_count(), std::size_t{4096});
expect(!recording->cursor_at(4096));
for (std::size_t offset = 0; offset < recording->event_count(); offset += 256) {
const auto page = checked(recording->event_page(offset, 256));
require(page.size() == 256);
expect_eq(page.front().sequence, static_cast<std::uint32_t>(offset));
expect_eq(page.back().sequence, static_cast<std::uint32_t>(offset + 255));
}
const auto full = checked(recording->cursor_at(depth));
const auto &stack = frames(full);
require(stack.size() == depth);
expect(std::holds_alternative<std::nullptr_t>(field(stack.front(), "parent").value));
expect_eq(protocol::as_uint32(member(stack.back(), "frame")), std::optional{depth});
expect_eq(protocol::as_uint32(member(stack.back(), "parent")), std::optional{depth - 1});
const auto half = checked(recording->cursor_at(depth + 1024));
expect_eq(frames(half).size(), std::size_t{depth - 1024});
expect_eq(protocol::as_uint32(member(field(half, "lastLeave"), "frame")),
std::optional{depth - 1023});
expect(frames(recording->final_cursor()).empty());
expect(!checked(recording->next_value()));
}
VOID_TEST(RecordingTests, concurrent_readers_keep_independent_cursors_after_removal) {
Void::FileSystem::TempDir dir{"vls_recording_"};
const auto path = dir / "selected";
write_pair(path, 17);
auto owner = checked(ReplayRecording::open(path));
require(fs::remove(path));
const auto at_inner = checked(protocol::serialize_json(checked(owner->cursor_at(6))));
const auto at_outer = checked(protocol::serialize_json(checked(owner->cursor_at(10))));
std::atomic<bool> consistent{true};
std::barrier start{9};
std::vector<std::jthread> readers;
for (unsigned i = 0; i < 8; ++i) {
readers.emplace_back([owner, i, &at_inner, &at_outer, &consistent, &start] {
start.arrive_and_wait();
for (unsigned run = 0; run < 64; ++run) {
const bool inner = (run + i) % 2 == 0;
auto state = owner->cursor_at(inner ? 6 : 10);
auto page = owner->event_page(7, 1);
if (!state ||
protocol::serialize_json(*state).value_or("") !=
(inner ? at_inner : at_outer) ||
!page || page->front().acknowledged_action != std::optional{"step"sv} ||
owner->source_bytes() != "int answer = 17;\n"sv) {
consistent = false;
return;
}
}
});
}
owner.reset();
start.arrive_and_wait();
readers.clear(); // Join each owner before checking its result.
expect(consistent.load());
}
+575
View File
@@ -0,0 +1,575 @@
#include "../../experiments/frontend/gcc-worker/Trace.hpp"
#include <Void/System/TempDir.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <array>
#include <barrier>
#include <filesystem>
#include <format>
#include <fstream>
#include <iterator>
#include <source_location>
#include <sys/stat.h>
#include <thread>
namespace {
namespace fs = std::filesystem;
namespace protocol = Void::LanguageServer::Protocol;
using protocol::Json;
using vls::gcc::replay;
using vls::gcc::Trace;
using Void::Testing::expect;
using Void::Testing::expect_eq;
using Void::Testing::require;
using namespace std::string_view_literals;
constexpr auto nonce = "00112233445566778899aabbccddeeff"sv;
constexpr auto digest = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"sv;
constexpr auto source_17 = "int answer = 17;\n"sv;
constexpr std::int64_t pid = 4321;
// Exact field shapes from the accepted GCC evaluator witness. These tests never start a compiler.
constexpr auto hello =
R"({"v":1,"nonce":"00112233445566778899aabbccddeeff","seq":0,"kind":"hello","backend":"gcc-16.2.0/vls-eval-1","pid":4321,"capabilities":["integralReturn","cooperativeStep"],"kinds":["hello","enter","body","value","cached","stopped","resumed","leave","terminal","frontendEnd"]})"sv;
constexpr auto no_source = R"(,"sourceKind":"unavailable")"sv;
constexpr auto value_17 =
R"(,"value":{"kind":"integer","precision":32,"signed":true,"bitsHex":"00000011"})"sv;
constexpr auto value_34 =
R"(,"value":{"kind":"integer","precision":32,"signed":true,"bitsHex":"00000022"})"sv;
constexpr auto unavailable = R"(,"value":{"kind":"unavailable","reason":"unsupportedScalar"})"sv;
struct Fixture {
Void::FileSystem::TempDir directory{"vls_trace_"};
fs::path journal = directory / "trace";
std::unique_ptr<Trace> create(std::string_view source = source_17) const {
auto trace = Trace::create(journal, source, digest, nonce, pid);
require(trace.has_value());
return std::move(*trace);
}
};
const Json &field(const Json &json, std::string_view key) {
const auto *object = protocol::as_object(&json);
require(object != nullptr);
const auto *value = protocol::find_member(*object, key);
require(value != nullptr);
return *value;
}
std::string_view text(const Json &json, std::string_view key) {
const auto *value = protocol::as_string(&field(json, key));
require(value != nullptr);
return *value;
}
std::int64_t number(const Json &json, std::string_view key) {
const auto *value = std::get_if<std::int64_t>(&field(json, key).value);
require(value != nullptr);
return *value;
}
bool flag(const Json &json, std::string_view key) { return std::get<bool>(field(json, key).value); }
bool null(const Json &json, std::string_view key) {
return std::holds_alternative<std::nullptr_t>(field(json, key).value);
}
const Json::Array &frames(const Json &json) {
return std::get<Json::Array>(field(json, "frames").value);
}
std::string_view bits(const Json &frame) { return text(field(frame, "value"), "bitsHex"); }
std::string wire(std::uint32_t seq, std::string_view kind, std::string_view members = {}) {
return std::format(R"({{"v":1,"nonce":"{}","seq":{},"kind":"{}"{}}})", nonce, seq, kind,
members);
}
std::string frame(std::uint32_t seq, std::string_view kind, std::uint32_t id,
std::string_view parent, std::string_view members = {}) {
return wire(seq, kind, std::format(R"(,"frame":{},"parent":{}{})", id, parent, members));
}
std::string enter(std::uint32_t seq, std::string_view parent, std::string_view name) {
return frame(seq, "enter", seq, parent, std::format(R"(,"name":{}{})", name, no_source));
}
std::string replaced(std::string_view original, std::string_view before, std::string_view after) {
std::string changed{original};
const auto offset = changed.find(before);
require(offset != changed.npos);
changed.replace(offset, before.size(), after);
return changed;
}
void add(Trace &trace, std::string_view line,
std::source_location at = std::source_location::current()) {
const auto result = trace.event(line);
expect_eq(result ? ""sv : std::string_view{result.error()}, ""sv, at);
require(result.has_value(), at);
}
Json read(const fs::path &path, std::optional<std::uint32_t> seq = std::nullopt,
std::source_location at = std::source_location::current()) {
auto result = replay(path, seq);
expect_eq(result ? ""sv : std::string_view{result.error()}, ""sv, at);
require(result.has_value(), at);
return std::move(*result);
}
void put_file(const fs::path &path, std::string_view data,
std::ios::openmode mode = std::ios::trunc) {
std::ofstream file(path, std::ios::binary | mode);
file.write(data.data(), static_cast<std::streamsize>(data.size()));
file.close();
require(file.good());
}
std::string file_bytes(const fs::path &path) {
std::ifstream file(path, std::ios::binary);
require(file.good());
return {std::istreambuf_iterator<char>{file}, std::istreambuf_iterator<char>{}};
}
void first_stop(Trace &trace) {
add(trace, hello);
add(trace, enter(1, "null", R"("twice")"));
add(trace, frame(2, "body", 1, "null"));
add(trace,
frame(
3, "enter", 3, "1",
R"(,"name":"reflected_value","sourceKind":"logicalDeclaration","source":"input.cpp","line":5,"byteColumn":15)"));
add(trace, frame(4, "body", 3, "1"));
add(trace, frame(5, "value", 3, "1", value_17));
add(trace, frame(6, "stopped", 3, "1"));
}
} // namespace
VOID_TEST(TraceTests, strict_handshake_and_envelope_reject_without_advancing) {
const Fixture fixture;
const auto trace = fixture.create();
const auto initial_bytes = fs::file_size(fixture.journal);
expect(null(trace->inspection(), "sequence"));
expect(!trace->event(wire(0, "frontendEnd")));
expect(!trace->event(replaced(hello, nonce, "10112233445566778899aabbccddeeff")));
expect(!trace->event(replaced(hello, "4321", "4322")));
expect(!trace->event(replaced(hello, "4321", "4321.0")));
expect(!trace->event(replaced(hello, "vls-eval-1", "vls-ide-1")));
expect(!trace->event(replaced(hello, "cooperativeStep", "integralReturn")));
expect(!trace->event(replaced(hello, R"("frontendEnd"])", R"("terminal"])")));
expect(!trace->event(replaced(hello, R"("v":1)", R"("v":1.00000000000000001)")));
expect(!trace->event(replaced(hello, R"("seq":0)", R"("seq":0,"seq":0)")));
expect(!trace->event(std::string{hello} + '\n'));
expect_eq(fs::file_size(fixture.journal), initial_bytes);
add(*trace, hello);
expect(!trace->event(wire(2, "frontendEnd")));
expect(!trace->event(replaced(wire(1, "frontendEnd"), R"("seq":1)", R"("seq":1e0)")));
expect(!trace->event(hello));
expect_eq(number(read(fixture.journal), "sequence"), std::int64_t{0});
add(*trace, wire(1, "frontendEnd"));
expect(!trace->event(wire(2, "frontendEnd")));
}
VOID_TEST(TraceTests, frame_identity_parent_and_actual_body_are_required) {
const Fixture fixture;
const auto trace = fixture.create();
add(*trace, hello);
expect(
!trace->event(frame(1, "enter", 2, "null", R"(,"name":null,"sourceKind":"unavailable")")));
expect(!trace->event(enter(1, "0", "null")));
expect(!trace->event(enter(1, "null", R"("\u0001")")));
add(*trace, enter(1, "null", "null"));
expect(!trace->event(wire(2, "body", R"(,"frame":1)")));
expect(!trace->event(wire(2, "frontendEnd")));
expect(!trace->event(frame(2, "value", 1, "null", value_17)));
// GCC can enter a child during parameter work or lazy instantiation before the parent's body.
add(*trace, enter(2, "1", R"("nested")"));
expect(!trace->event(frame(3, "cached", 2, "null")));
expect(!trace->event(frame(3, "body", 1, "null")));
add(*trace, frame(3, "cached", 2, "1"));
expect(!trace->event(frame(4, "value", 2, "1", value_17)));
expect(!trace->event(frame(4, "body", 2, "1")));
add(*trace, frame(4, "leave", 2, "1", R"(,"outcome":"returned")"));
const auto cached = read(fixture.journal, 4);
expect(flag(field(cached, "lastLeave"), "cached"));
expect(protocol::find_member(*protocol::as_object(&field(cached, "lastLeave")), "value") ==
nullptr);
expect(!trace->event(frame(5, "enter", 2, "1", R"(,"name":null,"sourceKind":"unavailable")")));
add(*trace, frame(5, "leave", 1, "null", R"(,"outcome":"failed")"));
add(*trace, wire(6, "frontendEnd"));
expect(trace->ended());
}
VOID_TEST(TraceTests, integer_width_and_unavailable_scalar_are_exact) {
const Fixture fixture;
const auto trace = fixture.create();
add(*trace, hello);
add(*trace, enter(1, "null", R"("scalar")"));
add(*trace, frame(2, "body", 1, "null"));
for (
const auto malformed : {
R"(,"value":{"kind":"integer","precision":0,"signed":true,"bitsHex":""})"sv,
R"(,"value":{"kind":"integer","precision":65,"signed":true,"bitsHex":"00000000000000000"})"sv,
R"(,"value":{"kind":"integer","precision":8.0,"signed":true,"bitsHex":"fd"})"sv,
R"(,"value":{"kind":"integer","precision":8,"signed":true,"bitsHex":"f"})"sv,
R"(,"value":{"kind":"integer","precision":8,"signed":true,"bitsHex":"FF"})"sv,
R"(,"value":{"kind":"integer","precision":8,"signed":1,"bitsHex":"fd"})"sv,
R"(,"value":{"kind":"integer","precision":1,"signed":false,"bitsHex":"2"})"sv,
R"(,"value":{"kind":"unavailable","reason":"other"})"sv,
}) {
expect(!trace->event(frame(3, "value", 1, "null", malformed)));
}
add(*trace,
frame(
3, "value", 1, "null",
R"(,"value":{"kind":"integer","precision":64,"signed":false,"bitsHex":"8000000000000005"})"));
const auto copied = read(fixture.journal, 3);
expect_eq(bits(frames(copied).back()), "8000000000000005"sv);
expect(!flag(field(frames(copied).back(), "value"), "signed"));
add(*trace, frame(4, "leave", 1, "null", R"(,"outcome":"returned")"));
add(*trace, enter(5, "null", R"("wide")"));
add(*trace, frame(6, "body", 5, "null"));
add(*trace, frame(7, "value", 5, "null", unavailable));
expect(!trace->event(frame(8, "stopped", 5, "null")));
const auto absent = read(fixture.journal, 7);
expect_eq(text(field(frames(absent).back(), "value"), "reason"), "unsupportedScalar"sv);
}
VOID_TEST(TraceTests, steps_through_nested_values_and_seeks_before_the_command) {
const Fixture fixture;
const auto trace = fixture.create();
first_stop(*trace);
expect_eq(trace->stopped(), std::optional<std::uint32_t>{6});
expect(!trace->authorize(5, "step"));
expect(!trace->authorize(7, "continue"));
expect(!trace->authorize(6, "inspect"));
expect(!trace->event(frame(7, "resumed", 3, "1", R"(,"stop":6,"action":"step")")));
require(trace->authorize(6, "step").has_value());
expect(!trace->stopped());
expect(!trace->authorize(6, "cancel"));
const auto pending = read(fixture.journal);
expect(null(pending, "stop"));
expect_eq(text(pending, "pendingAction"), "step"sv);
expect(!trace->event(frame(7, "leave", 3, "1", R"(,"outcome":"returned")")));
expect(!trace->event(frame(7, "resumed", 3, "1", R"(,"stop":6,"action":"continue")")));
expect(!trace->event(frame(7, "resumed", 3, "1", R"(,"stop":5,"action":"step")")));
add(*trace, frame(7, "resumed", 3, "1", R"(,"stop":6,"action":"step")"));
add(*trace, frame(8, "leave", 3, "1", R"(,"outcome":"returned")"));
add(*trace, frame(9, "value", 1, "null", value_34));
add(*trace, frame(10, "stopped", 1, "null"));
expect(!trace->authorize(6, "continue"));
require(trace->authorize(10, "continue").has_value());
add(*trace, frame(11, "resumed", 1, "null", R"(,"stop":10,"action":"continue")"));
add(*trace, frame(12, "leave", 1, "null", R"(,"outcome":"returned")"));
add(*trace, enter(13, "null", R"("another")"));
add(*trace, frame(14, "body", 13, "null"));
add(*trace, frame(15, "value", 13, "null", value_17));
expect(!trace->event(frame(16, "stopped", 13, "null")));
add(*trace, frame(16, "leave", 13, "null", R"(,"outcome":"returned")"));
add(*trace, wire(17, "frontendEnd"));
require(trace->finish("completed", 0, "").has_value());
const auto inner = read(fixture.journal, 6);
require(frames(inner).size() == 2);
expect_eq(text(frames(inner).front(), "name"), "twice"sv);
expect_eq(text(frames(inner).back(), "name"), "reflected_value"sv);
expect_eq(bits(frames(inner).back()), "00000011"sv);
expect(flag(frames(inner).back(), "valueProvisional"));
expect_eq(number(inner, "stop"), std::int64_t{6});
expect(null(inner, "pendingAction"));
expect_eq(text(inner, "outcome"), "completed"sv);
expect(!flag(inner, "frontendEnded"));
expect(!flag(inner, "partial"));
const auto after_leave = read(fixture.journal, 8);
require(frames(after_leave).size() == 1);
expect(!flag(field(after_leave, "lastLeave"), "valueProvisional"));
expect_eq(bits(field(after_leave, "lastLeave")), "00000011"sv);
const auto outer = read(fixture.journal, 10);
require(frames(outer).size() == 1);
expect_eq(number(outer, "stop"), std::int64_t{10});
expect_eq(bits(frames(outer).back()), "00000022"sv);
const auto final = read(fixture.journal);
expect(flag(final, "frontendEnded"));
expect(frames(final).empty());
expect(!replay(fixture.journal, 18));
}
VOID_TEST(TraceTests, cancellation_keeps_the_open_provisional_frame) {
const Fixture fixture;
auto trace = fixture.create();
first_stop(*trace);
const auto cancelled = wire(7, "terminal", R"(,"reason":"cancelled","stop":6)");
expect(!trace->event(cancelled));
require(trace->authorize(6, "cancel").has_value());
expect(!trace->event(frame(7, "resumed", 3, "1", R"(,"stop":6,"action":"cancel")")));
expect(!trace->event(wire(7, "terminal", R"(,"reason":"cancelled","stop":5)")));
add(*trace, cancelled);
expect_eq(trace->terminal(), "cancelled"sv);
expect(!trace->stopped());
expect(!trace->ended());
expect(!trace->finish("completed", 0, ""));
require(trace->finish("cancelled", 125, "").has_value());
trace.reset();
const auto recorded = read(fixture.journal);
require(frames(recorded).size() == 2);
expect_eq(bits(frames(recorded).back()), "00000011"sv);
expect(flag(frames(recorded).back(), "valueProvisional"));
expect(protocol::find_member(*protocol::as_object(&frames(recorded).front()), "value") ==
nullptr);
expect(flag(recorded, "partial"));
expect(!flag(recorded, "corrupt"));
expect_eq(text(recorded, "outcome"), "cancelled"sv);
expect_eq(number(recorded, "exitCode"), std::int64_t{125});
expect_eq(number(read(fixture.journal, 6), "stop"), std::int64_t{6});
}
VOID_TEST(TraceTests, frontend_end_and_provisional_value_do_not_prove_success) {
const Fixture fixture;
const auto trace = fixture.create();
add(*trace, hello);
add(*trace, enter(1, "null", R"("candidate")"));
add(*trace, frame(2, "body", 1, "null"));
add(*trace, frame(3, "value", 1, "null", replaced(value_17, "00000011", "00000009")));
add(*trace, frame(4, "leave", 1, "null", R"(,"outcome":"failed")"));
expect(!trace->finish("completed", 0, ""));
add(*trace, wire(5, "frontendEnd"));
expect(!trace->finish("completed", 1, "unmatched"));
expect(!trace->finish("another", 1, "unknown"));
const auto before_wait = read(fixture.journal);
expect(flag(before_wait, "frontendEnded"));
expect(flag(before_wait, "partial"));
expect(null(before_wait, "outcome"));
require(trace->finish("failed", 1, "cleanup failed\n").has_value());
expect(!trace->finish("completed", 0, ""));
const auto recorded = read(fixture.journal);
expect(frames(recorded).empty());
const auto &leave = field(recorded, "lastLeave");
expect_eq(text(leave, "outcome"), "failed"sv);
expect_eq(bits(leave), "00000009"sv);
expect(flag(leave, "valueProvisional"));
expect_eq(text(recorded, "outcome"), "failed"sv);
expect_eq(text(recorded, "diagnostics"), "cleanup failed\n"sv);
expect(!flag(recorded, "partial"));
}
VOID_TEST(TraceTests, replay_keeps_source_bytes_after_edit_and_removal) {
const Fixture fixture;
const auto original = fixture.directory / "input.cpp";
put_file(original, source_17);
auto trace = fixture.create(file_bytes(original));
first_stop(*trace);
trace.reset();
put_file(original, "int answer = 41;\n");
const auto edited = read(fixture.journal);
expect_eq(text(edited, "source"), source_17);
expect_eq(text(edited, "sourceSha256"),
"e2727305e817a0da9431b286b4317caec93433b6bc372f242b2786944c60c28f"sv);
expect_eq(text(edited, "compilerSha256"), digest);
expect_eq(bits(frames(edited).back()), "00000011"sv);
require(fs::remove(original));
const auto journal_before = file_bytes(fixture.journal);
require(::chmod(fixture.journal.c_str(), 0400) == 0);
const auto removed = read(fixture.journal, 6);
expect_eq(text(removed, "source"), source_17);
expect_eq(text(frames(removed).back(), "source"), "input.cpp"sv);
expect(null(removed, "outcome"));
expect(flag(removed, "partial"));
expect_eq(file_bytes(fixture.journal), journal_before);
}
VOID_TEST(TraceTests, captured_binary_bytes_round_trip_in_json_projection) {
const Fixture fixture;
const auto trace = fixture.create("\xff\0x"sv);
require(trace->finish("failed", 126, "\x80\n"sv).has_value());
const auto recorded = read(fixture.journal);
expect(null(recorded, "source"));
expect_eq(text(recorded, "sourceHex"), "ff0078"sv);
expect_eq(text(recorded, "sourceSha256"),
"b56ed79fd4921608ee3cc257a4bb1a7b726bf67c84a26f3e3ca41aa42c6e9737"sv);
expect(null(recorded, "diagnostics"));
expect_eq(text(recorded, "diagnosticsHex"), "800a"sv);
expect(protocol::serialize_json(recorded).has_value());
}
VOID_TEST(TraceTests, replay_recovers_verified_prefix_on_truncation_or_tampering) {
const Fixture fixture;
auto trace = fixture.create();
first_stop(*trace);
require(trace->authorize(6, "cancel").has_value());
add(*trace, wire(7, "terminal", R"(,"reason":"cancelled","stop":6)"));
require(trace->finish("cancelled", 125, "finished").has_value());
trace.reset();
const auto full = file_bytes(fixture.journal);
fs::resize_file(fixture.journal, full.size() - 3);
const auto torn = read(fixture.journal);
expect_eq(number(torn, "sequence"), std::int64_t{7});
expect_eq(text(torn, "terminal"), "cancelled"sv);
expect(null(torn, "outcome"));
expect(flag(torn, "partial"));
expect(!flag(torn, "corrupt"));
put_file(fixture.journal, replaced(full, "reflected_value", "reflected_FAKE!"));
const auto tampered = read(fixture.journal);
expect_eq(number(tampered, "sequence"), std::int64_t{2});
require(frames(tampered).size() == 1);
expect_eq(text(frames(tampered).front(), "name"), "twice"sv);
expect(null(tampered, "outcome"));
expect(flag(tampered, "partial"));
expect(flag(tampered, "corrupt"));
expect(!replay(fixture.journal, 3));
expect(flag(read(fixture.journal, 0), "corrupt"));
put_file(fixture.journal, replaced(full, source_17, "int answer = 41;\n"));
expect(!replay(fixture.journal, std::nullopt));
put_file(fixture.journal, full + "tail");
const auto after_finish = read(fixture.journal);
expect(flag(after_finish, "corrupt"));
expect(null(after_finish, "outcome"));
expect_eq(number(after_finish, "sequence"), std::int64_t{7});
}
VOID_TEST(TraceTests, replay_bounds_corrupt_lengths_and_regular_file_inputs) {
const Fixture fixture;
auto trace = fixture.create();
add(*trace, hello);
trace.reset();
put_file(fixture.journal, "E\x7f\xff\xff\xff"sv, std::ios::app);
const auto huge_record = read(fixture.journal);
expect(flag(huge_record, "corrupt"));
expect_eq(number(huge_record, "sequence"), std::int64_t{0});
expect_eq(text(huge_record, "journalError"), "invalid trace journal record type or length"sv);
expect(!replay(fixture.journal, 4096));
expect(!replay(fixture.directory.path(), std::nullopt));
const auto fifo = fixture.directory / "fifo";
require(::mkfifo(fifo.c_str(), 0600) == 0);
expect(!replay(fifo, std::nullopt));
const auto alias = fixture.directory / "alias";
fs::create_symlink(fixture.journal, alias);
expect(!replay(alias, std::nullopt));
}
VOID_TEST(TraceTests, trace_and_record_byte_budgets_hold_at_the_boundary) {
const Fixture fixture;
const auto trace = fixture.create();
std::string oversized{hello};
oversized.resize(4096, ' ');
expect(!trace->event(oversized));
expect(null(trace->inspection(), "sequence"));
// 255 full records leave exactly 4096 bytes. Fit the final enter and terminal in that page.
std::string padded{hello};
padded.resize(4095, ' ');
add(*trace, padded);
for (std::uint32_t seq = 1; seq < 255; seq += 2) {
padded = enter(seq, "null", "null");
padded.resize(4095, ' ');
add(*trace, padded);
padded = frame(seq + 1, "leave", seq, "null", R"(,"outcome":"failed")");
padded.resize(4095, ' ');
add(*trace, padded);
}
const auto terminal = wire(256, "terminal", R"(,"reason":"truncated")");
padded = enter(255, "null", "null");
padded.resize(4094 - terminal.size(), ' ');
add(*trace, padded);
expect(!trace->event(terminal + ' ')); // Its LF would be one byte over the budget.
expect_eq(number(trace->inspection(), "sequence"), std::int64_t{255});
add(*trace, terminal);
expect(!trace->ended());
require(trace->finish("truncated", 126, "").has_value());
const auto limited = read(fixture.journal);
expect_eq(text(limited, "outcome"), "truncated"sv);
expect(flag(limited, "partial"));
}
VOID_TEST(TraceTests, compiler_truncation_without_stop_token_is_valid) {
const Fixture fixture;
const auto trace = fixture.create();
first_stop(*trace);
require(trace->authorize(6, "step").has_value());
expect(!trace->event(wire(7, "terminal", R"(,"reason":"truncated","stop":6)")));
add(*trace, wire(7, "terminal", R"(,"reason":"truncated")"));
expect_eq(trace->terminal(), "truncated"sv);
expect(!trace->stopped());
expect(!trace->ended());
const auto recorded = read(fixture.journal);
expect(flag(recorded, "partial"));
expect(!flag(recorded, "corrupt"));
expect_eq(bits(frames(recorded).back()), "00000011"sv);
}
VOID_TEST(TraceTests, journal_creation_and_stop_authorization_are_exclusive) {
const Fixture fixture;
expect(!Trace::create(fixture.journal, source_17, digest, "incorrect", pid));
expect(!Trace::create(fixture.journal, source_17, digest, nonce, 0));
expect(!Trace::create(fixture.journal, std::string(1024 * 1024 + 1, 'x'), digest, nonce, pid));
expect(fs::is_empty(fixture.directory.path()));
std::array<std::unique_ptr<Trace>, 2> recorders;
std::barrier start(2);
const auto attempt = [&](std::size_t index) {
start.arrive_and_wait();
auto created = Trace::create(fixture.journal, source_17, digest, nonce, pid);
if (created) {
recorders[index] = std::move(*created);
}
};
std::jthread first(attempt, 0);
attempt(1);
first.join();
require(static_cast<bool>(recorders[0]) != static_cast<bool>(recorders[1]));
auto &trace = recorders[recorders[0] ? 0 : 1];
struct stat status{};
require(::stat(fixture.journal.c_str(), &status) == 0);
expect((status.st_mode & 0777) == 0600);
first_stop(*trace);
std::array<bool, 2> accepted{};
const auto race = [&](std::size_t index) {
start.arrive_and_wait();
accepted[index] = trace->authorize(6, "step").has_value();
};
std::jthread second(race, 0);
race(1);
second.join();
expect(accepted[0] != accepted[1]);
expect(!trace->stopped());
const auto saved = file_bytes(fixture.journal);
expect(!Trace::create(fixture.journal, "new source", digest, nonce, pid));
expect_eq(file_bytes(fixture.journal), saved);
expect(static_cast<std::size_t>(std::distance(fs::directory_iterator{fixture.directory.path()},
fs::directory_iterator{})) == 1);
}
VOID_TEST(TraceTests, splice_origin_is_declared_validated_and_exposed) {
constexpr auto origin =
R"(,"source":"input.cpp","line":4,"byteColumn":31,"targetKind":"declaration","targetName":"Ready","targetSource":"input.cpp","targetLine":1,"targetByteColumn":20)"sv;
const Fixture legacy;
const auto old_trace = legacy.create();
add(*old_trace, hello);
expect(!old_trace->event(wire(1, "splice", origin)));
const Fixture current;
const auto trace = current.create();
add(*trace, replaced(hello, R"("frontendEnd"])", R"("frontendEnd","splice"])"));
expect(!trace->event(wire(1, "splice", replaced(origin, R"("line":4)", R"("line":0)"))));
expect(!trace->event(
wire(1, "splice",
replaced(origin, R"("targetKind":"declaration")", R"("targetKind":"alias")"))));
expect(!trace->event(
wire(1, "splice", replaced(origin, R"("targetLine":1)", R"("targetLine":null)"))));
add(*trace, wire(1, "splice", origin));
const auto inspection = trace->inspection();
const auto *origins =
protocol::as_array(protocol::find_member(*protocol::as_object(&inspection), "origins"));
require(origins != nullptr && origins->size() == 1);
expect(number(origins->front(), "line") == 4);
expect(text(origins->front(), "targetName") == "Ready");
expect(number(origins->front(), "targetByteColumn") == 20);
}
Binary file not shown.
Binary file not shown.
Binary file not shown.