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:
1 parent
ca04975d54
commit
da8003f6d4
310 files changed
+47552
-480
No files matched your search
@@ -0,0 +1,605 @@
|
||||
#include <Void/LanguageServer/Build/Providers.hpp>
|
||||
#include <Void/LanguageServer/Protocol/Json.hpp>
|
||||
|
||||
#include <Void/System/TempDir.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <poll.h>
|
||||
#include <sys/inotify.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace {
|
||||
using namespace Void::LanguageServer::Build;
|
||||
using namespace std::string_view_literals;
|
||||
namespace Workspace = Void::LanguageServer::Workspace;
|
||||
namespace Protocol = Void::LanguageServer::Protocol;
|
||||
namespace fs = std::filesystem;
|
||||
using Protocol::Json;
|
||||
using Strings = std::vector<std::string>;
|
||||
using Void::Testing::expect;
|
||||
using Void::Testing::require;
|
||||
|
||||
void write_file(const fs::path &path, std::string_view bytes) {
|
||||
std::ofstream output(path, std::ios::binary);
|
||||
output.write(bytes.data(), static_cast<std::streamsize>(bytes.size()));
|
||||
output.close();
|
||||
require(output.good());
|
||||
}
|
||||
|
||||
std::string encode(const Json &value) {
|
||||
auto encoded = Protocol::serialize_json(value);
|
||||
require(encoded.has_value());
|
||||
return *encoded;
|
||||
}
|
||||
|
||||
std::string command_row(std::string command, std::string file = "unit.cpp") {
|
||||
return encode(Json{Json::Object{{"directory", Json{std::string{"."}}},
|
||||
{"file", Json{std::move(file)}},
|
||||
{"command", Json{std::move(command)}}}});
|
||||
}
|
||||
|
||||
std::string argv_row(const Strings &argv, std::string file = "unit.cpp", std::string cwd = ".",
|
||||
std::optional<std::string> output = {}, std::optional<std::string> command = {}) {
|
||||
Json::Array array;
|
||||
for (const auto &arg : argv)
|
||||
array.push_back(Json{arg});
|
||||
Json::Object row{{"directory", Json{std::move(cwd)}}, {"file", Json{std::move(file)}},
|
||||
{"arguments", Json{std::move(array)}}};
|
||||
if (output)
|
||||
row["output"] = Json{*output};
|
||||
if (command)
|
||||
row["command"] = Json{*command};
|
||||
return encode(Json{std::move(row)});
|
||||
}
|
||||
|
||||
ProviderScope bind(const fs::path &root) {
|
||||
auto scope = bind_provider_scope({.workspace = {root, "rows-test"}});
|
||||
require(scope.has_value());
|
||||
return *scope;
|
||||
}
|
||||
|
||||
struct Fixture {
|
||||
Void::FileSystem::TempDir temp{"vls_rows_"};
|
||||
fs::path root = temp.path() / "work";
|
||||
fs::path base = root / "metadata", database = base / "compile_commands.json";
|
||||
fs::path gcc = temp.path() / "g++", clang = temp.path() / "clang++";
|
||||
ProviderScope scope;
|
||||
|
||||
Fixture() {
|
||||
fs::create_directories(base);
|
||||
scope = bind(root);
|
||||
for (const auto &tool : {gcc, clang}) {
|
||||
write_file(tool, "compiler identity fixture");
|
||||
fs::permissions(tool, fs::perms::owner_read | fs::perms::owner_exec);
|
||||
}
|
||||
}
|
||||
|
||||
// Acquire real filesystem identities through the launcher's settings and pinning API.
|
||||
DriverInput pin(Workspace::CompilerDriver dialect = Workspace::CompilerDriver::gcc,
|
||||
Workspace::AuthorityLevel purpose = Workspace::AuthorityLevel::compiler_use,
|
||||
const fs::path &workspace = {}) const {
|
||||
const auto &owner = workspace.empty() ? root : workspace;
|
||||
const auto &tool = dialect == Workspace::CompilerDriver::clang ? clang : gcc;
|
||||
Workspace::SettingsOverrides overrides;
|
||||
overrides.tool_approvals = std::vector<Workspace::ToolSelection>{{owner, purpose, tool}};
|
||||
auto flags = Workspace::settings_from_cli(std::move(overrides), owner);
|
||||
auto local = Workspace::parse_workspace_settings(Json{Json::Object{}}, owner);
|
||||
Workspace::TrustPolicy policy;
|
||||
auto generation = policy.replace_configuration(Workspace::merge_configuration(local, nullptr, &flags));
|
||||
require(generation.has_value());
|
||||
require(policy.pin_approved_tool(owner, purpose, tool).has_value());
|
||||
auto checked = policy.check_tool(owner, purpose, tool, *generation);
|
||||
require(checked.has_value());
|
||||
return {std::move(*checked), dialect, {"ccache"}};
|
||||
}
|
||||
|
||||
std::expected<ImportedCommands, ProviderIssue>
|
||||
import(std::string_view bytes, const std::optional<DriverInput> &driver = {},
|
||||
const std::optional<std::string> &profile = {}) const {
|
||||
write_file(database, bytes);
|
||||
auto acquired = read_provider_file(scope, database, FilePurpose::database, scope.limits.max_compdb_bytes);
|
||||
if (!acquired)
|
||||
return std::unexpected(acquired.error());
|
||||
return import_commands({scope, *acquired, profile, driver});
|
||||
}
|
||||
ImportedCommands rows(std::initializer_list<std::string> records,
|
||||
const std::optional<DriverInput> &driver = {},
|
||||
const std::optional<std::string> &profile = {}) const {
|
||||
std::string bytes = "[\n";
|
||||
for (const auto &record : records) {
|
||||
if (bytes.size() > 2)
|
||||
bytes += ",\n";
|
||||
bytes += record;
|
||||
}
|
||||
auto imported = import(bytes + "\n]", driver, profile);
|
||||
require(imported.has_value());
|
||||
require(imported->contexts.size() == records.size());
|
||||
return std::move(*imported);
|
||||
}
|
||||
};
|
||||
|
||||
bool limited(const BuildContext &context, std::string_view fragment = {}) {
|
||||
return !context.semantic_arguments && std::ranges::any_of(context.limitations, [&](const auto &reason) {
|
||||
return reason.contains(fragment);
|
||||
});
|
||||
}
|
||||
|
||||
const Strings &semantic(const BuildContext &context) {
|
||||
require(context.semantic_arguments.has_value());
|
||||
expect(context.limitations.empty());
|
||||
return *context.semantic_arguments;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
VOID_TEST(CommandImport, passive_rows_retain_exact_json_and_unknown_provenance) {
|
||||
Fixture f;
|
||||
const std::string raw = R"json({ "directory":"dir été", "file":"u\"{x}.cpp",
|
||||
"arguments":["g++","-c","u\"{x}.cpp"], "vendor":{"nested":[true,{"x":"\\\"}]"}],"n":2.5} })json";
|
||||
const auto result = f.rows({raw}, {}, "debug");
|
||||
const auto &row = result.contexts.front();
|
||||
require(row.original && row.original->arguments);
|
||||
expect(row.original->original_record == raw && row.original->metadata_file == f.database);
|
||||
expect(!row.original->command && row.original->arguments->at(2) == "u\"{x}.cpp");
|
||||
expect(row.key.profile == "debug" && !row.key.target && row.key.role == ContextRole::unknown);
|
||||
expect(row.key.owning_tu == f.base / "dir été" / "u\"{x}.cpp");
|
||||
expect(limited(row, "checked compiler") && !row.source_language);
|
||||
require(row.sources.size() == 1);
|
||||
expect(row.sources.front().source_path == row.key.owning_tu && !row.sources.front().compiler_path);
|
||||
expect(row.sources.front().origin == SourceOrigin::unknown &&
|
||||
row.sources.front().editability == Editability::unknown);
|
||||
expect(!row.toolchain && !row.standard_library && !row.environment && !row.prerequisites && !row.artifacts);
|
||||
expect(result.dependencies.empty() && !result.revision.empty());
|
||||
expect(BuildGeneration::create({f.scope.workspace, "compdb", result.revision}, result.contexts).has_value());
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, malformed_structure_rejects_the_entire_database) {
|
||||
Fixture f;
|
||||
const auto good = argv_row({"c++", "-c", "a.cpp"}, "a.cpp");
|
||||
for (const auto &bad : {"null", "[]", "{}", R"({"directory":".","file":"b.cpp"})",
|
||||
R"({"directory":2,"file":"b.cpp","arguments":[]})",
|
||||
R"({"directory":".","file":"b.cpp","arguments":null,"command":"c++ -c b.cpp"})",
|
||||
R"({"directory":".","file":"b.cpp","arguments":["c++",1],"command":"c++ -c b.cpp"})",
|
||||
R"({"directory":".","file":"b.cpp","command":42,"arguments":["ok"]})",
|
||||
R"({"directory":".","file":"b.cpp","arguments":[],"command":"c++ -c b.cpp"})",
|
||||
R"({"directory":".","file":"b.cpp","output":false,"arguments":["cc"]})",
|
||||
R"({"directory":".","file":"b.cpp","file":"c.cpp","command":""})",
|
||||
R"({"directory":".","file":"b.cpp","arguments":["nul\u0000arg"]})",
|
||||
R"({"directory":".","file":"\ud800","arguments":["cc"]})", R"({"x":[})"}) {
|
||||
auto result = f.import("[" + good + "," + bad + "]");
|
||||
expect(!result.has_value());
|
||||
}
|
||||
for (const auto &bad : {"", "{}", "[,]", "[{} ,]", "[]x", "[[]", "[\v]", "[\xff]"})
|
||||
expect(!f.import(bad));
|
||||
auto empty = f.import(" [ ]\t\n");
|
||||
require(empty.has_value());
|
||||
expect(empty->contexts.empty());
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, command_quoting_and_typed_arguments_precedence) {
|
||||
Fixture f;
|
||||
const auto checked = f.pin();
|
||||
const auto command = f.gcc.native() +
|
||||
R"( -DNAME="has spaces and \"quotes\"" -I'include folder' -x c++ -c café\ source.cpp)";
|
||||
auto command_only = f.rows({command_row(command, "café source.cpp")}, checked);
|
||||
const auto &c = command_only.contexts.front();
|
||||
expect(semantic(c) == Strings{f.gcc.native(), "-DNAME=has spaces and \"quotes\"",
|
||||
"-I" + (f.base / "include folder").native(), "-x", "c++", "-c", (f.base / "café source.cpp").native()});
|
||||
expect(c.source_language == "c++" && c.original->command == command && !c.original->arguments);
|
||||
const Strings typed{f.gcc.native(), "-DEXACT=$literal", "-c", "unit.cpp"};
|
||||
const auto secondary = "ignored && touch " + (f.temp.path() / "marker").native();
|
||||
auto both = f.rows({argv_row(typed, "unit.cpp", ".", {}, secondary)}, checked);
|
||||
const auto &row = both.contexts.front();
|
||||
expect(semantic(row)[1] == typed[1] && row.original->arguments == typed && row.original->command == secondary);
|
||||
expect(!fs::exists(f.temp.path() / "marker"));
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, checked_driver_uses_the_language_of_the_actual_input_operand) {
|
||||
Fixture f;
|
||||
write_file(f.base / "generated.inc", "int value;\n");
|
||||
fs::create_symlink("generated.inc", f.base / "alias.cpp");
|
||||
for (const auto dialect : {Workspace::CompilerDriver::gcc, Workspace::CompilerDriver::clang}) {
|
||||
const auto driver = f.pin(dialect);
|
||||
const auto &tool = driver.tool.identity.selected_path.native();
|
||||
auto imported = f.rows({argv_row({tool, "-c", "alias.cpp"}, "generated.inc"),
|
||||
argv_row({tool, "-xc", "-c", "unit.cpp"}),
|
||||
argv_row({tool, "-c", "unit.cpp", "-x", "c"}),
|
||||
argv_row({tool, "-c", "ordinary.h"}, "ordinary.h")}, driver);
|
||||
const auto &rows = imported.contexts;
|
||||
require(rows.size() == 4);
|
||||
expect(rows[0].key.owning_tu == f.base / "generated.inc" &&
|
||||
rows[0].source_language == "c++");
|
||||
expect(rows[1].source_language == "c");
|
||||
expect(rows[2].source_language == "c++");
|
||||
expect(rows[3].semantic_arguments.has_value() && !rows[3].source_language);
|
||||
}
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, shell_constructs_and_incomplete_quoting_remain_passive) {
|
||||
Fixture f;
|
||||
const auto pin = f.pin();
|
||||
const auto marker = f.temp.path() / "marker";
|
||||
for (const std::string tail : {" && touch " + marker.native(), " -DA=$(touch " + marker.native() + ")",
|
||||
std::string{" *.cpp"}, std::string{" > file"}, std::string{" -DNAME=\"$HOME\""},
|
||||
std::string{" -DNAME='broken"}, std::string{" \\"}}) {
|
||||
const auto command = f.gcc.native() + " -c unit.cpp" + tail;
|
||||
const auto result = f.rows({command_row(command)}, pin);
|
||||
const auto &row = result.contexts.front();
|
||||
expect(limited(row) && row.original->command == command);
|
||||
}
|
||||
expect(!fs::exists(marker));
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, duplicate_and_conflicting_alternatives_survive_reordering) {
|
||||
Fixture f;
|
||||
const auto a = argv_row({"g++", "-c", "unit.cpp"});
|
||||
const auto b = argv_row({"g++", "-DOTHER", "-c", "unit.cpp"});
|
||||
const std::string extension = a.substr(0, a.size()-1) + ",\"mode\":\"vendor\"}";
|
||||
const auto ordered = f.rows({a, b, a, extension});
|
||||
const auto changed = f.rows({extension, a, a, b});
|
||||
auto alternatives = [](const auto &result) {
|
||||
std::map<std::string, std::string> values;
|
||||
for (const auto &row : result.contexts)
|
||||
expect(values.emplace(row.key.alternative, *row.original->original_record).second &&
|
||||
row.key.alternative == row.original->record_id);
|
||||
return values;
|
||||
};
|
||||
expect(alternatives(ordered) == alternatives(changed));
|
||||
const auto gen = BuildGeneration::create({f.scope.workspace, "compdb", ordered.revision}, ordered.contexts);
|
||||
require(gen.has_value());
|
||||
expect((*gen)->candidates(f.base / "unit.cpp").size() == 4);
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, relative_paths_use_logical_database_parent) {
|
||||
Fixture f;
|
||||
const auto actual = f.root / "actual";
|
||||
fs::create_directory(actual);
|
||||
fs::create_symlink(actual / "commands.json", f.database);
|
||||
const auto checked = f.pin();
|
||||
const auto row = argv_row({f.gcc.native(), "-c", "源.cpp", "-o", "obj/x.o"}, "源.cpp", "./build",
|
||||
(f.base / "build/obj/x.o").native());
|
||||
const auto result = f.rows({row}, checked);
|
||||
const auto &context = result.contexts.front();
|
||||
expect(context.working_directory == f.base / "build" && context.key.owning_tu == f.base / "build/源.cpp");
|
||||
expect(semantic(context) == Strings{f.gcc.native(), "-c", (f.base / "build/源.cpp").native()});
|
||||
expect(context.original->metadata_file == f.database);
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, repeated_native_flags_and_cmake_output_are_preserved) {
|
||||
Fixture f;
|
||||
const auto pin = f.pin();
|
||||
const auto obj = (f.base / "obj/unit.cpp.o").native();
|
||||
const Strings native{f.gcc.native(), "-std=c++26", "-I", f.root.native(), "-I", f.root.native(),
|
||||
"-O0", "-g", "-freflection", "-freflection", "-freflection", "-c", "unit.cpp", "-o", obj};
|
||||
const auto cmake = f.gcc.native() + " -I" + f.root.native() +
|
||||
" -g -std=c++26 -Wall -Wextra -Wpedantic -freflection -o obj/unit.cpp.o -c unit.cpp";
|
||||
const auto named = argv_row(native, "unit.cpp", ".", obj);
|
||||
auto cmake_row = command_row(cmake);
|
||||
cmake_row.insert(cmake_row.size()-1, ",\"output\":" + encode(Json{obj}));
|
||||
const auto result = f.rows({named, cmake_row}, pin);
|
||||
expect(result.contexts[0].original->arguments == native && result.contexts[1].original->command == cmake);
|
||||
expect(std::ranges::count(semantic(result.contexts[0]), "-freflection"sv) == 3);
|
||||
for (const auto &row : result.contexts) {
|
||||
expect(!std::ranges::contains(semantic(row), "-o"sv));
|
||||
expect(semantic(row).back() == (f.base / "unit.cpp").native());
|
||||
}
|
||||
const auto passive = f.rows({named, cmake_row});
|
||||
expect(std::ranges::all_of(passive.contexts, [](const auto &row) { return limited(row); }));
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, output_pair_requires_the_correct_option_boundary) {
|
||||
Fixture f;
|
||||
const auto pin = f.pin();
|
||||
const auto include = f.rows({argv_row({f.gcc.native(), "-I", "-o", "-c", "unit.cpp"})}, pin);
|
||||
expect(semantic(include.contexts.front()) ==
|
||||
Strings{f.gcc.native(), "-I", (f.base / "-o").native(), "-c", (f.base / "unit.cpp").native()});
|
||||
const auto rejected = f.rows({
|
||||
argv_row({f.gcc.native(), "-D", "-o", "-c", "unit.cpp"}),
|
||||
argv_row({f.gcc.native(), "-o", "x.o", "-c", "unit.cpp"}, "unit.cpp", ".", "other.o"),
|
||||
argv_row({f.gcc.native(), "-o", "x.o", "-o", "y.o", "-c", "unit.cpp"}),
|
||||
argv_row({f.gcc.native(), "-fsyntax-only", "-o", "x.o", "unit.cpp"}),
|
||||
argv_row({f.gcc.native(), "-c", "unit.cpp", "-o"})}, pin);
|
||||
expect(std::ranges::all_of(rejected.contexts, [](const auto &row) { return limited(row); }));
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, unsupported_options_and_different_owning_tu_are_retained) {
|
||||
Fixture f;
|
||||
const auto pin = f.pin();
|
||||
for (const Strings args : {Strings{f.gcc.native(), "-c", "other.cpp"},
|
||||
Strings{f.gcc.native(), "-c", "other.cpp", "unit.cpp"},
|
||||
Strings{f.gcc.native(), "-include", "forced.h", "-c", "unit.cpp"},
|
||||
Strings{f.gcc.native(), "-include", "-o", "-c", "unit.cpp"},
|
||||
Strings{f.gcc.native(), "-fplugin=marker", "-c", "unit.cpp"},
|
||||
Strings{f.gcc.native(), "-Xclang", "-load", "-c", "unit.cpp"},
|
||||
Strings{f.gcc.native(), "-I=target-root", "-c", "unit.cpp"},
|
||||
Strings{f.gcc.native(), "-isystem", "$SYSROOT/inc", "-c", "unit.cpp"},
|
||||
Strings{f.gcc.native(), "-I-", "-c", "unit.cpp"}}) {
|
||||
const auto result = f.rows({argv_row(args)}, pin);
|
||||
const auto &row = result.contexts.front();
|
||||
expect(limited(row) && row.key.owning_tu == f.base / "unit.cpp");
|
||||
expect(row.original->arguments == args && !row.sources.front().compiler_path);
|
||||
}
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, wrong_driver_root_purpose_or_wrapper_never_reads_responses) {
|
||||
Fixture f;
|
||||
write_file(f.base / "ok.rsp", "-DFROM_RESPONSE");
|
||||
const int watcher = ::inotify_init1(IN_CLOEXEC | IN_NONBLOCK);
|
||||
require(watcher >= 0);
|
||||
require(::inotify_add_watch(watcher, (f.base / "ok.rsp").c_str(), IN_ACCESS) >= 0);
|
||||
pollfd events{watcher, POLLIN, 0};
|
||||
const auto checked = f.pin();
|
||||
const auto row = argv_row({f.gcc.native(), "@ok.rsp", "-c", "unit.cpp"});
|
||||
fs::create_directory(f.temp.path() / "other");
|
||||
const auto other = f.pin(Workspace::CompilerDriver::gcc, Workspace::AuthorityLevel::compiler_use,
|
||||
f.temp.path() / "other");
|
||||
const auto purpose = f.pin(Workspace::CompilerDriver::gcc, Workspace::AuthorityLevel::trusted_metadata_refresh);
|
||||
auto unknown = checked;
|
||||
unknown.driver = Workspace::CompilerDriver::unknown;
|
||||
auto wrong_dialect = checked;
|
||||
wrong_dialect.driver = Workspace::CompilerDriver::clang;
|
||||
for (const auto &pin : {other, purpose, unknown, wrong_dialect}) {
|
||||
const auto result = f.rows({row}, pin);
|
||||
expect(limited(result.contexts.front()) && result.dependencies.empty());
|
||||
}
|
||||
for (const auto &args : {Strings{"g++", "@ok.rsp", "-c", "unit.cpp"},
|
||||
Strings{f.clang.native(), "@ok.rsp", "-c", "unit.cpp"},
|
||||
Strings{"wrapper", f.gcc.native(), "@ok.rsp", "-c", "unit.cpp"},
|
||||
Strings{"ccache", "unselected", "@ok.rsp", f.gcc.native(), "-c", "unit.cpp"},
|
||||
Strings{f.gcc.native(), "--rsp-quoting=windows", "@ok.rsp", "-c", "unit.cpp"}}) {
|
||||
const auto result = f.rows({argv_row(args)}, checked);
|
||||
expect(limited(result.contexts.front()) && result.dependencies.empty());
|
||||
}
|
||||
expect(f.rows({row}).dependencies.empty());
|
||||
expect(::poll(&events, 1, 0) == 0);
|
||||
const auto ok = f.rows({argv_row({"ccache", f.gcc.native(), "@ok.rsp", "-c", "unit.cpp"})}, checked);
|
||||
expect(semantic(ok.contexts.front()).front() == f.gcc.native() && ok.dependencies.size() == 1);
|
||||
expect(::poll(&events, 1, 0) == 1);
|
||||
::close(watcher);
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, ambiguous_parent_steps_and_external_routes_stay_passive) {
|
||||
Fixture f;
|
||||
fs::create_directory_symlink(f.temp.path(), f.base / "link");
|
||||
write_file(f.base / "in.rsp", "-DLOCAL");
|
||||
write_file(f.temp.path() / "out.rsp", "-DEXTERNAL");
|
||||
const auto pin = f.pin();
|
||||
auto result = f.rows({
|
||||
argv_row({f.gcc.native(), "@in.rsp", "-c", "unit.cpp"}, "unit.cpp", "link/.."),
|
||||
argv_row({f.gcc.native(), "@in.rsp", "-c", "unit.cpp"}, "link/../unit.cpp"),
|
||||
argv_row({f.gcc.native(), "@in.rsp", "-c", "unit.cpp"}, (f.temp.path() / "unit.cpp").native()),
|
||||
argv_row({f.gcc.native(), "@link/../in.rsp", "-c", "unit.cpp"}),
|
||||
argv_row({f.gcc.native(), "@" + (f.temp.path() / "out.rsp").native(), "-c", "unit.cpp"}),
|
||||
argv_row({f.gcc.native(), "-Ilink/../headers", "-c", "unit.cpp"}),
|
||||
argv_row({f.gcc.native(), "-I", f.temp.path().native(), "-c", "unit.cpp"}),
|
||||
argv_row({f.gcc.native(), "-o", "link/../x.o", "-c", "unit.cpp"})}, pin);
|
||||
expect(result.dependencies.empty());
|
||||
expect(std::ranges::all_of(result.contexts, [](const auto &row) { return limited(row); }));
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, gcc_and_clang_response_dialects_use_the_invocation_cwd) {
|
||||
Fixture f;
|
||||
fs::create_directory(f.base / "sub");
|
||||
write_file(f.base / "sub" / "first.rsp", R"('-DSINGLE=a\b' "-DDOUBLE=c\q" @second.rsp)");
|
||||
write_file(f.base / "sub" / "second.rsp", "-DWRONG");
|
||||
write_file(f.base / "second.rsp", "-I\"include path\" -c 'unit café.cpp'");
|
||||
for (auto dialect : {Workspace::CompilerDriver::gcc, Workspace::CompilerDriver::clang}) {
|
||||
const auto checked = f.pin(dialect);
|
||||
const auto exe = checked.tool.identity.selected_path.native();
|
||||
const auto result = f.rows({argv_row({exe, "@sub/first.rsp"}, "unit café.cpp")}, checked);
|
||||
const bool gcc = dialect == Workspace::CompilerDriver::gcc;
|
||||
expect(semantic(result.contexts.front()) ==
|
||||
Strings{exe, gcc ? "-DSINGLE=a\\b" : "-DSINGLE=ab", gcc ? "-DDOUBLE=c\\q" : "-DDOUBLE=cq",
|
||||
"-I" + (f.base / "include path").native(), "-c", (f.base / "unit café.cpp").native()});
|
||||
require(result.dependencies.size() == 2);
|
||||
expect(result.dependencies[0].logical_path == f.base / "sub/first.rsp" &&
|
||||
result.dependencies[1].logical_path == f.base / "second.rsp");
|
||||
}
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, response_cycles_use_active_physical_objects) {
|
||||
Fixture f;
|
||||
const auto pin = f.pin();
|
||||
const auto row = argv_row({f.gcc.native(), "@one", "-c", "unit.cpp"});
|
||||
f.scope.limits.max_response_file_depth = 2;
|
||||
write_file(f.base / "one", "@one");
|
||||
expect(limited(f.rows({row}, pin).contexts.front(), "recursive"));
|
||||
write_file(f.base / "one", "@two");
|
||||
fs::create_hard_link(f.base / "one", f.base / "two");
|
||||
const auto aliased = f.rows({row}, pin);
|
||||
expect(limited(aliased.contexts.front(), "recursive"));
|
||||
require(aliased.dependencies.size() == 2);
|
||||
expect(same_provider_object(aliased.dependencies[0], aliased.dependencies[1]));
|
||||
fs::remove(f.base / "two");
|
||||
write_file(f.base / "two", "@one");
|
||||
f.scope.limits.max_response_file_depth = 3;
|
||||
expect(limited(f.rows({row}, pin).contexts.front(), "recursive"));
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, repeated_response_expansions_retain_each_logical_name) {
|
||||
Fixture f;
|
||||
const auto checked = f.pin();
|
||||
write_file(f.base / "flags", "-DFROM=1");
|
||||
fs::create_hard_link(f.base / "flags", f.base / "alias");
|
||||
const auto row = argv_row({f.gcc.native(), "@flags", "@alias", "@flags", "-c", "unit.cpp"});
|
||||
const auto first = f.rows({row}, checked);
|
||||
expect(std::ranges::count(semantic(first.contexts.front()), "-DFROM=1"sv) == 3);
|
||||
require(first.dependencies.size() == 2);
|
||||
expect(first.dependencies[0].logical_path != first.dependencies[1].logical_path);
|
||||
write_file(f.base / "replacement", "-DFROM=2");
|
||||
fs::rename(f.base / "replacement", f.base / "alias");
|
||||
expect(!provider_file_current(f.scope, first.dependencies[1]));
|
||||
const auto second = f.rows({row}, checked);
|
||||
expect(first.revision != second.revision);
|
||||
expect(first.contexts.front().key == second.contexts.front().key);
|
||||
expect(*first.dependencies[1].bytes == "-DFROM=1");
|
||||
expect(std::ranges::count(semantic(second.contexts.front()), "-DFROM=2"sv) == 1);
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, response_depth_bytes_token_and_encoding_limits) {
|
||||
Fixture f;
|
||||
const auto pin = f.pin();
|
||||
const auto row = argv_row({f.gcc.native(), "@one", "-c", "unit.cpp"});
|
||||
write_file(f.base / "one", "@two");
|
||||
write_file(f.base / "two", "-DMODE");
|
||||
f.scope.limits.max_response_file_depth = 1;
|
||||
expect(limited(f.rows({row}, pin).contexts.front(), "nesting"));
|
||||
f.scope.limits.max_response_file_depth = 2;
|
||||
f.scope.limits.max_response_file_bytes = 9;
|
||||
expect(limited(f.rows({row}, pin).contexts.front()));
|
||||
f.scope.limits.max_response_file_bytes = 10;
|
||||
expect(std::ranges::contains(semantic(f.rows({row}, pin).contexts.front()), "-DMODE"sv));
|
||||
write_file(f.base / "one", "@two @two");
|
||||
f.scope.limits.max_response_file_bytes = 16;
|
||||
expect(limited(f.rows({row}, pin).contexts.front(), "byte limit"));
|
||||
f.scope.limits.max_response_file_bytes = 1024 * 1024;
|
||||
std::string many;
|
||||
for (std::size_t i = 0; i < 4096; ++i)
|
||||
many += "-g ";
|
||||
write_file(f.base / "one", many);
|
||||
expect(limited(f.rows({row}, pin).contexts.front(), "argument limit"));
|
||||
for (const std::string invalid : {std::string{"-D\xff"}, std::string{"x\0y", 3},
|
||||
std::string{"'bad"}, std::string{"\xef\xbb\xbf-DNAME"}}) {
|
||||
write_file(f.base / "one", invalid);
|
||||
expect(limited(f.rows({row}, pin).contexts.front()));
|
||||
}
|
||||
fs::remove(f.base / "one");
|
||||
expect(limited(f.rows({row}, pin).contexts.front(), "response file"));
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, oversized_json_argv_and_database_are_rejected_atomically) {
|
||||
Fixture f;
|
||||
const auto valid = argv_row({"cc", "-c", "unit.cpp"});
|
||||
std::string prefix = "[" + valid + "," + valid.substr(0, valid.size()-1) + ",\"extra\":";
|
||||
expect(!f.import(prefix + std::string(32, '[') + "0" + std::string(32, ']') + "}]"));
|
||||
expect(!f.import(prefix + "\"" + std::string(2 * 1024 * 1024, 'x') + "\"}]"));
|
||||
std::string dense{"["};
|
||||
for (int i = 0; i < 20000; ++i)
|
||||
dense += "0,";
|
||||
expect(!f.import(prefix + dense + "0]}]"));
|
||||
expect(!f.import("[" + argv_row(Strings(4097, "x")) + "]"));
|
||||
expect(!f.import("[" + argv_row({std::string(64 * 1024 + 1, 'x')}) + "]"));
|
||||
write_file(f.database, "[" + valid + "]");
|
||||
auto acquired = read_provider_file(f.scope, f.database, FilePurpose::database, f.scope.limits.max_compdb_bytes);
|
||||
require(acquired.has_value());
|
||||
f.scope.limits.max_compdb_bytes = 1;
|
||||
expect(!import_commands({f.scope, *acquired, {}, {}}));
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, database_must_match_the_current_scope_binding) {
|
||||
Fixture f;
|
||||
write_file(f.database, "[]");
|
||||
auto file = read_provider_file(f.scope, f.database, FilePurpose::database, 2);
|
||||
require(file.has_value());
|
||||
auto rebound = bind(f.root);
|
||||
expect(!import_commands({rebound, *file, {}, {}}));
|
||||
write_file(f.base / "new", "[]");
|
||||
fs::rename(f.base / "new", f.database);
|
||||
auto stale = import_commands({f.scope, *file, {}, {}});
|
||||
expect(!stale && stale.error().code == "changed");
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, physical_owners_follow_links_before_parent_components) {
|
||||
Fixture f;
|
||||
for (const auto *name : {"real", "other"}) {
|
||||
fs::create_directories(f.base / name / "sub");
|
||||
write_file(f.base / name / "x.cpp", "int real;\n");
|
||||
}
|
||||
write_file(f.base / "x.cpp", "int innocent;\n");
|
||||
fs::create_directory_symlink("real/sub", f.base / "link");
|
||||
fs::create_symlink("real/x.cpp", f.base / "alias.cpp");
|
||||
const auto linked = argv_row({"c++", "-c", "link/../x.cpp"}, "link/../x.cpp");
|
||||
const auto cwd = argv_row({"c++", "-c", "x.cpp"}, "x.cpp", "link/..");
|
||||
const auto alias = argv_row({"c++", "-c", "alias.cpp"}, "alias.cpp");
|
||||
write_file(f.database, "[" + linked + "," + cwd + "," + alias + "]");
|
||||
const auto original = observe_compdb(f.scope, f.database);
|
||||
require(original.health == ProviderHealth::ready && original.generation);
|
||||
expect(original.generation->candidates(f.base / "x.cpp").empty());
|
||||
expect(original.generation->candidates(f.base / "real/x.cpp").size() == 3);
|
||||
expect(!changed_provider_input(f.scope, original));
|
||||
|
||||
fs::remove(f.base / "link");
|
||||
fs::create_directory_symlink("other/sub", f.base / "link");
|
||||
expect(changed_provider_input(f.scope, original).has_value());
|
||||
const auto latest = observe_compdb(f.scope, f.database);
|
||||
require(latest.health == ProviderHealth::ready && latest.generation);
|
||||
expect(latest.generation->candidates(f.base / "x.cpp").empty());
|
||||
expect(latest.generation->candidates(f.base / "real/x.cpp").size() == 1);
|
||||
expect(latest.generation->candidates(f.base / "other/x.cpp").size() == 2);
|
||||
expect(!changed_provider_input(f.scope, latest));
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, command_and_argv_preserve_a_quoted_literal_backslash) {
|
||||
Fixture f;
|
||||
const auto result = f.rows({command_row(f.gcc.native() + R"( -I"inc\q" -c unit.cpp)"),
|
||||
argv_row({f.gcc.native(), R"(-Iinc\q)", "-c", "unit.cpp"})},
|
||||
f.pin());
|
||||
const auto &words = semantic(result.contexts.front());
|
||||
expect(words == semantic(result.contexts.back()));
|
||||
expect(std::ranges::contains(words, "-I" + (f.base / R"(inc\q)").native()));
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, creating_a_missing_response_invalidates_the_observation) {
|
||||
Fixture f;
|
||||
const auto driver = f.pin();
|
||||
write_file(f.database, "[" + argv_row({f.gcc.native(), "@later.rsp", "-c", "unit.cpp"}) + "]");
|
||||
const auto missing = observe_compdb(f.scope, f.database, driver);
|
||||
require(missing.health == ProviderHealth::ready && missing.generation);
|
||||
expect(limited(missing.generation->contexts().front(), "missing"));
|
||||
expect(!changed_provider_input(f.scope, missing));
|
||||
|
||||
const auto response = f.base / "later.rsp";
|
||||
write_file(response, "-DFROM_LATER");
|
||||
expect(changed_provider_input(f.scope, missing) == response);
|
||||
const auto present = observe_compdb(f.scope, f.database, driver);
|
||||
require(present.health == ProviderHealth::ready && present.generation);
|
||||
expect(
|
||||
std::ranges::contains(semantic(present.generation->contexts().front()), "-DFROM_LATER"sv));
|
||||
expect(present.inputs.size() == 2 && !changed_provider_input(f.scope, present));
|
||||
fs::remove(response);
|
||||
expect(changed_provider_input(f.scope, present) == response);
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, search_directory_authority_follows_the_bound_link_target) {
|
||||
Fixture f;
|
||||
const auto driver = f.pin();
|
||||
const auto include = f.base / "include-alias";
|
||||
fs::create_directories(f.temp.path() / "outside");
|
||||
fs::create_directory_symlink(f.temp.path() / "outside", include);
|
||||
write_file(f.database,
|
||||
"[" + argv_row({f.gcc.native(), "-Iinclude-alias", "-c", "unit.cpp"}) + "]");
|
||||
const auto external = observe_compdb(f.scope, f.database, driver);
|
||||
require(external.health == ProviderHealth::ready && external.generation);
|
||||
expect(limited(external.generation->contexts().front()));
|
||||
expect(!changed_provider_input(f.scope, external));
|
||||
fs::create_directory(f.base / "inside");
|
||||
fs::remove(include);
|
||||
fs::create_directory_symlink("inside", include);
|
||||
expect(changed_provider_input(f.scope, external) == include);
|
||||
const auto internal = observe_compdb(f.scope, f.database, driver);
|
||||
require(internal.health == ProviderHealth::ready && internal.generation);
|
||||
expect(std::ranges::contains(semantic(internal.generation->contexts().front()),
|
||||
"-I" + include.native()));
|
||||
expect(!changed_provider_input(f.scope, internal));
|
||||
}
|
||||
|
||||
VOID_TEST(CommandImport, bounded_response_names_apply_across_the_whole_generation) {
|
||||
Fixture f;
|
||||
const auto checked = f.pin();
|
||||
std::string rows = "[" + argv_row({f.gcc.native(), "-c", "unit.cpp"});
|
||||
for (unsigned i = 0; i < 256; ++i) {
|
||||
rows += "," + argv_row({f.gcc.native(), "@missing-" + std::to_string(i), "-c", "unit.cpp"});
|
||||
}
|
||||
auto within = f.import(rows + "]", checked);
|
||||
require(within.has_value());
|
||||
expect(within->contexts.size() == 257 && within->contexts.front().semantic_arguments &&
|
||||
limited(within->contexts.back(), "missing"));
|
||||
const auto repeated = argv_row({f.gcc.native(), "@missing-0", "-c", "unit.cpp"});
|
||||
auto reuse = f.import(rows + "," + repeated + "]", checked);
|
||||
expect(reuse && reuse->contexts.size() == 258);
|
||||
const auto extra = argv_row({f.gcc.native(), "@extra", "-c", "unit.cpp"});
|
||||
expect(!f.import(rows + "," + extra + "]", checked));
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#include "ProviderFixture.hpp"
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
namespace {
|
||||
using namespace provider_test;
|
||||
using namespace provider_test::Build;
|
||||
using Void::Testing::expect;
|
||||
using Void::Testing::require;
|
||||
|
||||
VOID_TEST(CompdbProvider, passive_database_survives_atomic_replacement_and_keeps_old_generation) {
|
||||
Fixture f;
|
||||
f.bind();
|
||||
write_json(f.compdb, Json{f.rows()});
|
||||
auto first = observe_compdb(f.scope, f.compdb);
|
||||
require(first.generation != nullptr);
|
||||
expect(first.health == ProviderHealth::ready &&
|
||||
first.generation->candidates(f.source).size() == 2);
|
||||
auto temporary = f.root / "next.json";
|
||||
write_json(temporary, Json{Json::Array{}});
|
||||
fs::rename(temporary, f.compdb);
|
||||
auto second = observe_compdb(f.scope, f.compdb);
|
||||
require(second.generation != nullptr);
|
||||
expect(second.generation->contexts().empty());
|
||||
expect(first.generation->identity().revision != second.generation->identity().revision);
|
||||
expect(!provider_file_current(f.scope, first.inputs.front()));
|
||||
expect(first.generation->contexts().size() == 2);
|
||||
}
|
||||
|
||||
VOID_TEST(CompdbProvider, invalid_or_deleted_databases_produce_distinct_status) {
|
||||
Fixture f;
|
||||
f.bind();
|
||||
write_bytes(f.compdb, "[{");
|
||||
auto invalid = observe_compdb(f.scope, f.compdb);
|
||||
expect(invalid.health == ProviderHealth::invalid && !invalid.generation);
|
||||
fs::remove(f.compdb);
|
||||
auto missing = observe_compdb(f.scope, f.compdb);
|
||||
expect(missing.health == ProviderHealth::missing && !missing.generation);
|
||||
}
|
||||
} // namespace
|
||||
@@ -0,0 +1,642 @@
|
||||
#include <Void/LanguageServer/Build/Model.hpp>
|
||||
#include <Void/LanguageServer/Documents/DocumentStore.hpp>
|
||||
|
||||
#include <Void/System/TempDir.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <barrier>
|
||||
#include <fstream>
|
||||
#include <thread>
|
||||
|
||||
namespace {
|
||||
namespace fs = std::filesystem;
|
||||
namespace Docs = Void::LanguageServer::Documents;
|
||||
using namespace Void::LanguageServer::Build;
|
||||
using Void::Testing::expect;
|
||||
using Void::Testing::require;
|
||||
|
||||
template <class T, class E> T take(std::expected<T, E> value) {
|
||||
require(value.has_value());
|
||||
return std::move(*value);
|
||||
}
|
||||
|
||||
void write(const fs::path &path, std::string_view content) {
|
||||
std::ofstream output(path, std::ios::binary);
|
||||
output << content;
|
||||
output.close();
|
||||
require(output.good());
|
||||
}
|
||||
|
||||
struct Fixture {
|
||||
Void::FileSystem::TempDir directory{"vls_build_model_"};
|
||||
const fs::path root{fs::canonical(directory.path())};
|
||||
const fs::path header{root / "api.hpp"}, source{root / "main.cpp"}, other{root / "other.cpp"},
|
||||
module{root / "core.cppm"};
|
||||
WorkspaceIdentity workspace{root, "editor-session"};
|
||||
Docs::DocumentStore documents;
|
||||
SelectionState selection{workspace, header};
|
||||
|
||||
Fixture() {
|
||||
write(header, "int api();");
|
||||
write(source, "#include \"api.hpp\"");
|
||||
write(other, "#include \"api.hpp\"\nimport core;");
|
||||
write(module, "export module core;");
|
||||
}
|
||||
|
||||
BuildContext record(std::string profile = "debug", std::string target = "app",
|
||||
fs::path tu = {}) const {
|
||||
if (tu.empty()) {
|
||||
tu = source;
|
||||
}
|
||||
auto argv = std::vector<std::string>{"g++", "-DNAME=" + target, tu.string()};
|
||||
return {
|
||||
.key = {profile, target, ContextRole::target, "main-command", tu},
|
||||
.source_language = "c++",
|
||||
.original = OriginalCommand{root / "commands.json", "record-" + target, argv, {}, {}},
|
||||
.semantic_arguments = argv,
|
||||
.working_directory = root,
|
||||
.toolchain = "gcc-16/toolchain-inputs",
|
||||
.standard_library = "libstdc++/inputs",
|
||||
.environment = "selected-environment",
|
||||
.sources = {{tu, tu, SourceOrigin::workspace, Editability::editable, "source-record"},
|
||||
{header, header, SourceOrigin::workspace, Editability::editable,
|
||||
"include-record"}},
|
||||
.prerequisites = std::vector<Prerequisite>{},
|
||||
.artifacts = std::vector<Artifact>{},
|
||||
.limitations = {}};
|
||||
}
|
||||
|
||||
Generation generation(std::vector<BuildContext> records,
|
||||
std::string revision = "provider-revision",
|
||||
std::shared_ptr<const ArtifactLease> lease = {}) const {
|
||||
return take(BuildGeneration::create({workspace, "fixture-provider", std::move(revision)},
|
||||
std::move(records), std::move(lease)));
|
||||
}
|
||||
Selection select() { return take(selection.update(generation({record()}))); }
|
||||
Snapshot read(const fs::path &path) { return take(documents.resolve_content(path)); }
|
||||
AnalysisInputs inputs(const Selection &selected) {
|
||||
return {.document = read(selected->scope->file),
|
||||
.translation_unit =
|
||||
selected->selected ? read(selected->selected->key.owning_tu) : Snapshot{},
|
||||
.dependencies = std::vector<DependencyInput>{},
|
||||
.lookup_epoch = 10,
|
||||
.configuration_generation = 20,
|
||||
.trust_generation = 30,
|
||||
.backend = BackendIdentity{"fixture", "v3", "worker-v1"},
|
||||
.rename = {}};
|
||||
}
|
||||
FileOverride override_for(const ContextKey &key) const {
|
||||
return {root, header, "fixture-provider", key};
|
||||
}
|
||||
RenameCoverage coverage(const Selection &selected) const {
|
||||
std::vector<ContextProof> checked;
|
||||
for (const auto *candidate : selected->alternatives()) {
|
||||
checked.push_back({selected->generation, candidate->key, "verified-input-closure"});
|
||||
}
|
||||
return {{root}, std::move(checked), "verified-edit-locations"};
|
||||
}
|
||||
};
|
||||
|
||||
Revision capture(const Selection &selection, AnalysisInputs inputs) {
|
||||
return take(AnalysisRevision::capture(selection, std::move(inputs)));
|
||||
}
|
||||
|
||||
bool mentions(const Readiness &readiness, InputIssue issue) {
|
||||
return std::ranges::contains(readiness.issues, issue);
|
||||
}
|
||||
|
||||
VOID_TEST(BuildModel, selection_preserves_conflicting_commands_and_follows_precedence) {
|
||||
Fixture f;
|
||||
auto app = f.record();
|
||||
auto tests = f.record("release", "tests");
|
||||
auto generation = f.generation({tests, app});
|
||||
SelectionState source_selection{f.workspace, f.source};
|
||||
expect(take(source_selection.update(generation))->alternatives().size() == 2);
|
||||
auto fallback = take(f.selection.update(generation));
|
||||
require(fallback->alternatives().size() == 2 && fallback->selected);
|
||||
expect(fallback->reason == SelectionReason::fallback && fallback->selected->key == app.key);
|
||||
expect(fallback->alternatives()[0]->semantic_arguments !=
|
||||
fallback->alternatives()[1]->semantic_arguments);
|
||||
|
||||
EditorSelection editor{f.root, generation->identity().provider, "release", "tests", {}, {}};
|
||||
auto chosen = take(f.selection.update(generation, {}, editor));
|
||||
expect(chosen->reason == SelectionReason::editor && chosen->selected->key == tests.key);
|
||||
auto overridden = take(f.selection.update(generation, f.override_for(app.key), editor));
|
||||
expect(overridden->reason == SelectionReason::file_override &&
|
||||
overridden->selected->key == app.key);
|
||||
expect(overridden == take(f.selection.update(generation, f.override_for(app.key), editor)));
|
||||
auto cleared = take(f.selection.update(generation, {}, editor));
|
||||
expect(cleared->selected->key == tests.key && cleared->revision > overridden->revision);
|
||||
}
|
||||
|
||||
VOID_TEST(BuildModel, missing_override_is_retained_until_cleared_or_resolved) {
|
||||
Fixture f;
|
||||
auto old = f.record();
|
||||
auto remaining = f.record("release", "other");
|
||||
auto key = f.override_for(old.key);
|
||||
auto generation = f.generation({remaining});
|
||||
EditorSelection editor{f.root, "fixture-provider", "release", {}, {}, {}};
|
||||
auto missing = take(f.selection.update(generation, key, editor));
|
||||
expect(missing->reason == SelectionReason::missing_override && !missing->selected);
|
||||
expect(missing->file_override == key && missing->alternatives().size() == 1);
|
||||
auto missing_inputs = capture(missing, f.inputs(missing));
|
||||
expect(mentions(missing_inputs->readiness(Operation::status), InputIssue::context));
|
||||
expect(missing_inputs->readiness(Operation::diagnostics).level == ReadinessLevel::unavailable);
|
||||
auto restored = take(f.selection.update(f.generation({old, remaining}), key, editor));
|
||||
expect(restored->selected->key == old.key);
|
||||
key.provider = "a-different-provider";
|
||||
expect(take(f.selection.update(generation, key))->reason == SelectionReason::missing_override);
|
||||
auto cleared = take(f.selection.update(generation, {}, editor));
|
||||
expect(cleared->reason == SelectionReason::editor && !cleared->file_override);
|
||||
SelectionState unowned{f.workspace, f.root / "absent.hpp"};
|
||||
auto absent = take(unowned.update(generation));
|
||||
expect(absent->reason == SelectionReason::no_owner && absent->alternatives().empty());
|
||||
}
|
||||
|
||||
VOID_TEST(BuildModel, fallback_is_order_independent_and_keeps_host_and_tu_roles) {
|
||||
Fixture f;
|
||||
auto app = f.record();
|
||||
auto host = app;
|
||||
host.key.role = ContextRole::host_description;
|
||||
auto other = f.record("debug", "app", f.other);
|
||||
auto first = take(f.selection.update(f.generation({host, other, app})));
|
||||
auto second = take(f.selection.update(f.generation({app, other, host})));
|
||||
require(first->alternatives().size() == 3 && second->alternatives().size() == 3);
|
||||
for (std::size_t i = 0; i < 3; ++i) {
|
||||
expect(first->alternatives()[i]->key == second->alternatives()[i]->key);
|
||||
}
|
||||
expect(first->selected->key == second->selected->key);
|
||||
auto selected_host = take(f.selection.update(second->generation, f.override_for(host.key)));
|
||||
auto selected_other = take(f.selection.update(second->generation, f.override_for(other.key)));
|
||||
expect(selected_host->selected->key.role == ContextRole::host_description);
|
||||
auto revision = capture(selected_other, f.inputs(selected_other));
|
||||
expect(revision->inputs.document->identity.canonical_path == f.header);
|
||||
expect(revision->inputs.translation_unit->identity.canonical_path == f.other);
|
||||
expect(revision->selection->selected->source_language == "c++");
|
||||
}
|
||||
|
||||
VOID_TEST(BuildModel, invalid_keys_mappings_and_foreign_scopes_are_rejected) {
|
||||
Fixture f;
|
||||
const GenerationIdentity id{f.workspace, "fixture-provider", "r1"};
|
||||
auto ctx = f.record();
|
||||
expect(BuildGeneration::create(id, {ctx, ctx}) ==
|
||||
std::unexpected{ModelError::duplicate_context});
|
||||
auto invalid = ctx;
|
||||
invalid.key.alternative.clear();
|
||||
expect(BuildGeneration::create(id, {invalid}) == std::unexpected{ModelError::invalid_context});
|
||||
invalid = ctx;
|
||||
invalid.sources.push_back(invalid.sources.front());
|
||||
expect(BuildGeneration::create(id, {invalid}) == std::unexpected{ModelError::invalid_mapping});
|
||||
invalid = ctx;
|
||||
invalid.sources.erase(invalid.sources.begin());
|
||||
expect(BuildGeneration::create(id, {invalid}) == std::unexpected{ModelError::invalid_mapping});
|
||||
invalid = ctx;
|
||||
invalid.sources.back().source_path = f.root.string() + "-unrelated/api.hpp";
|
||||
expect(BuildGeneration::create(id, {invalid}) == std::unexpected{ModelError::invalid_mapping});
|
||||
auto generation = f.generation({ctx});
|
||||
auto key = f.override_for(ctx.key);
|
||||
key.file = f.other;
|
||||
expect(f.selection.update(generation, key) == std::unexpected{ModelError::wrong_scope});
|
||||
SelectionState other_session{{f.root, "another-session"}, f.header};
|
||||
expect(other_session.update(generation) == std::unexpected{ModelError::wrong_scope});
|
||||
auto bad_root = id;
|
||||
bad_root.workspace.root = "relative";
|
||||
expect(BuildGeneration::create(bad_root, {ctx}) ==
|
||||
std::unexpected{ModelError::invalid_identity});
|
||||
}
|
||||
|
||||
VOID_TEST(BuildModel, argv_boundaries_original_command_and_unknown_fields_survive) {
|
||||
Fixture f;
|
||||
auto a = f.record();
|
||||
a.key.profile.reset();
|
||||
a.key.target.reset();
|
||||
a.original->arguments = {"gcc", "-DX=a b", "-Iinc", "-Iinc", ""};
|
||||
a.original->command = "gcc '-DX=a b' -Iinc -Iinc ''";
|
||||
a.original->original_record = "{opaque provider extension}";
|
||||
a.semantic_arguments = {"/tool/gcc", "-DX=a b", "-I/selected/inc", "-I/selected/inc", ""};
|
||||
auto b = a;
|
||||
b.key.alternative = "other-command";
|
||||
b.original->arguments = {"gcc", "-DX=a", "b", "-Iinc", "-Iinc", ""};
|
||||
b.semantic_arguments = {"/tool/gcc", "-DX=a", "b", "-I/selected/inc", "-I/selected/inc", ""};
|
||||
b.artifacts.reset();
|
||||
auto generation = f.generation({b, a});
|
||||
const auto *left = generation->find(a.key);
|
||||
const auto *right = generation->find(b.key);
|
||||
require(left && right && left != right);
|
||||
expect(left->original->arguments == a.original->arguments &&
|
||||
left->original->command == a.original->command);
|
||||
expect(left->original->original_record == a.original->original_record);
|
||||
expect(left->semantic_arguments == a.semantic_arguments &&
|
||||
left->semantic_arguments != right->semantic_arguments);
|
||||
expect(!left->key.target && !left->key.profile && left->artifacts->empty() &&
|
||||
!right->artifacts);
|
||||
std::vector<BuildContext> supplied{a};
|
||||
auto &provider_argv = *supplied.front().semantic_arguments;
|
||||
auto frozen = take(BuildGeneration::create(generation->identity(), std::move(supplied)));
|
||||
provider_argv.clear();
|
||||
expect(frozen->contexts().front().semantic_arguments == a.semantic_arguments);
|
||||
}
|
||||
|
||||
VOID_TEST(BuildModel, identical_disk_rereads_complete_and_changed_bytes_invalidate) {
|
||||
Fixture f;
|
||||
auto selected = f.select();
|
||||
auto first = capture(selected, f.inputs(selected));
|
||||
PublicationSlot slot{f.selection, Operation::semantic};
|
||||
require(slot.replace_inputs(1, first).has_value());
|
||||
auto ticket = take(slot.issue());
|
||||
auto reread = capture(selected, f.inputs(selected));
|
||||
expect(first->inputs.document->revision_id != reread->inputs.document->revision_id);
|
||||
expect(first->same_input_as(*reread));
|
||||
require(slot.replace_inputs(2, reread).has_value());
|
||||
std::string payload(64, 'x');
|
||||
payload[32] = '\0';
|
||||
const auto expected = payload;
|
||||
char *worker_buffer = payload.data();
|
||||
require(slot.publish(ticket, std::move(payload)));
|
||||
worker_buffer[0] = 'y';
|
||||
auto historical = slot.current();
|
||||
require(historical && historical->payload == expected);
|
||||
auto next = take(slot.issue());
|
||||
write(f.header, "int api(long);");
|
||||
auto changed = capture(selected, f.inputs(selected));
|
||||
expect(!reread->same_input_as(*changed));
|
||||
require(slot.replace_inputs(3, changed).has_value());
|
||||
expect(!slot.current() && !slot.publish(next, "obsolete") && historical->payload == expected);
|
||||
}
|
||||
|
||||
VOID_TEST(BuildModel, same_text_overlay_reopen_and_changed_owning_tu_reject_old_work) {
|
||||
Fixture f;
|
||||
auto selected = f.select();
|
||||
const auto uri = Docs::path_to_file_uri(f.header);
|
||||
auto first_open = take(f.documents.open(uri, "cpp", 1, "int api();"));
|
||||
auto inputs = f.inputs(selected);
|
||||
require(inputs.document == first_open);
|
||||
auto first = capture(selected, inputs);
|
||||
PublicationSlot slot{f.selection, Operation::diagnostics};
|
||||
require(slot.replace_inputs(1, first).has_value());
|
||||
auto old = take(slot.issue());
|
||||
require(f.documents.close(uri).has_value());
|
||||
inputs.document = take(f.documents.open(uri, "cpp", 1, "int api();"));
|
||||
auto reopened = capture(selected, inputs);
|
||||
expect(inputs.document->text == first_open->text &&
|
||||
inputs.document->version == first_open->version);
|
||||
expect(!first->same_input_as(*reopened));
|
||||
require(slot.replace_inputs(2, reopened).has_value());
|
||||
expect(!slot.publish(old, "obsolete incarnation"));
|
||||
auto for_old_tu = take(slot.issue());
|
||||
write(f.source, "#define REDIRECT\n#include \"api.hpp\"");
|
||||
inputs.translation_unit = f.read(f.source);
|
||||
require(slot.replace_inputs(3, capture(selected, inputs)).has_value());
|
||||
expect(!slot.publish(for_old_tu, "obsolete translation unit"));
|
||||
}
|
||||
|
||||
VOID_TEST(BuildModel, negative_lookup_and_ordered_import_inputs_invalidate) {
|
||||
Fixture f;
|
||||
auto selected = f.select();
|
||||
auto inputs = f.inputs(selected);
|
||||
inputs.dependencies->push_back({DependencyKind::import, "core", f.module, f.read(f.module)});
|
||||
inputs.dependencies->push_back({DependencyKind::include, "api.hpp", f.header, inputs.document});
|
||||
auto initial = capture(selected, inputs);
|
||||
auto observed = inputs;
|
||||
auto &producer_name = observed.dependencies->front().name;
|
||||
auto frozen = take(AnalysisRevision::capture(selected, std::move(observed)));
|
||||
producer_name = "other";
|
||||
expect(frozen->inputs.dependencies->front().name == "core");
|
||||
PublicationSlot slot{f.selection, Operation::semantic};
|
||||
require(slot.replace_inputs(1, initial).has_value());
|
||||
auto old = take(slot.issue());
|
||||
const auto higher_priority = f.root / "earlier";
|
||||
fs::create_directory(higher_priority);
|
||||
require(!fs::exists(higher_priority / "api.hpp"));
|
||||
write(higher_priority / "api.hpp", "int different_api();");
|
||||
// The owner observed creation on an earlier search root; all former positive inputs still
|
||||
// match.
|
||||
++*inputs.lookup_epoch;
|
||||
auto shadowed = capture(selected, inputs);
|
||||
require(slot.replace_inputs(2, shadowed).has_value());
|
||||
expect(!slot.publish(old, "obsolete search"));
|
||||
std::ranges::reverse(*inputs.dependencies);
|
||||
auto reordered = capture(selected, inputs);
|
||||
expect(!shadowed->same_input_as(*reordered));
|
||||
auto &import = inputs.dependencies->back();
|
||||
import.name = "core:partition";
|
||||
auto renamed = capture(selected, inputs);
|
||||
expect(!renamed->same_input_as(*reordered));
|
||||
write(f.module, "export module core;\nexport int n;");
|
||||
import.source = f.read(f.module);
|
||||
expect(!renamed->same_input_as(*capture(selected, inputs)));
|
||||
}
|
||||
|
||||
VOID_TEST(BuildModel, mapping_environment_language_and_backend_identify_revisions) {
|
||||
Fixture f;
|
||||
auto ctx = f.record();
|
||||
auto first_selection = take(f.selection.update(f.generation({ctx})));
|
||||
auto inputs = f.inputs(first_selection);
|
||||
auto first = capture(first_selection, inputs);
|
||||
auto change = [&](BuildContext next) {
|
||||
auto selected = take(f.selection.update(f.generation({next})));
|
||||
expect(selected->generation->identity().revision ==
|
||||
first_selection->generation->identity().revision);
|
||||
expect(!first->same_input_as(*capture(selected, inputs)));
|
||||
return selected;
|
||||
};
|
||||
auto mapped = ctx;
|
||||
mapped.sources.back().compiler_path = f.root / "generated" / "api.hpp";
|
||||
auto mapped_selection = change(mapped);
|
||||
expect(mapped_selection->selected->mapping_for(f.header)->compiler_path ==
|
||||
mapped.sources.back().compiler_path);
|
||||
auto env = ctx;
|
||||
env.environment = "changed-environment";
|
||||
expect(change(env)->selected->environment == env.environment);
|
||||
auto language = ctx;
|
||||
language.source_language = "c";
|
||||
expect(change(language)->selected->source_language == language.source_language);
|
||||
auto backend = inputs;
|
||||
backend.backend->protocol = "worker-v2";
|
||||
expect(!first->same_input_as(*capture(first_selection, backend)));
|
||||
backend = inputs;
|
||||
backend.backend->version = "different-build";
|
||||
expect(!first->same_input_as(*capture(first_selection, backend)));
|
||||
}
|
||||
|
||||
VOID_TEST(BuildModel, mismatched_source_owner_and_inconsistent_dependency_fail_capture) {
|
||||
Fixture f;
|
||||
auto selected = f.select();
|
||||
auto inputs = f.inputs(selected);
|
||||
auto wrong = inputs;
|
||||
wrong.document = f.read(f.source);
|
||||
expect(AnalysisRevision::capture(selected, wrong) == std::unexpected{ModelError::wrong_scope});
|
||||
wrong = inputs;
|
||||
wrong.translation_unit = f.read(f.other);
|
||||
expect(AnalysisRevision::capture(selected, wrong) == std::unexpected{ModelError::wrong_scope});
|
||||
write(f.header, "int changed;");
|
||||
inputs.dependencies->push_back(
|
||||
{DependencyKind::include, "api.hpp", f.header, f.read(f.header)});
|
||||
expect(AnalysisRevision::capture(selected, inputs) ==
|
||||
std::unexpected{ModelError::invalid_input});
|
||||
auto other_inputs = f.inputs(selected);
|
||||
other_inputs.backend->version.clear();
|
||||
expect(AnalysisRevision::capture(selected, other_inputs) ==
|
||||
std::unexpected{ModelError::invalid_identity});
|
||||
}
|
||||
|
||||
VOID_TEST(BuildModel, partial_metadata_allows_evidenced_diagnostics_and_status) {
|
||||
Fixture f;
|
||||
auto ctx = f.record();
|
||||
ctx.environment.reset();
|
||||
ctx.prerequisites = std::vector<Prerequisite>{{"module", {}, Availability::missing}};
|
||||
ctx.artifacts.reset();
|
||||
ctx.limitations.push_back("unsupported driver operand");
|
||||
auto selected = take(f.selection.update(f.generation({ctx})));
|
||||
auto inputs = f.inputs(selected);
|
||||
inputs.lookup_epoch.reset();
|
||||
inputs.dependencies.reset();
|
||||
auto revision = capture(selected, inputs);
|
||||
for (auto operation : {Operation::status, Operation::diagnostics}) {
|
||||
const auto &readiness = revision->readiness(operation);
|
||||
expect(readiness.level == ReadinessLevel::degraded);
|
||||
expect(mentions(readiness, InputIssue::prerequisites) &&
|
||||
mentions(readiness, InputIssue::lookup_coverage));
|
||||
PublicationSlot slot{f.selection, operation};
|
||||
require(slot.replace_inputs(1, revision).has_value());
|
||||
expect(slot.publish(take(slot.issue()), "partial"));
|
||||
}
|
||||
for (auto operation : {Operation::semantic, Operation::rename}) {
|
||||
PublicationSlot slot{f.selection, operation};
|
||||
require(slot.replace_inputs(1, revision).has_value());
|
||||
expect(slot.issue() == std::unexpected{ModelError::operation_unavailable});
|
||||
}
|
||||
inputs.translation_unit.reset();
|
||||
expect(capture(selected, inputs)->readiness(Operation::diagnostics).level ==
|
||||
ReadinessLevel::unavailable);
|
||||
}
|
||||
|
||||
VOID_TEST(BuildModel, rename_requires_all_affected_contexts_and_editable_origins) {
|
||||
Fixture f;
|
||||
auto generation = f.generation({f.record(), f.record("release", "tests", f.other)});
|
||||
auto selected = take(f.selection.update(generation));
|
||||
auto inputs = f.inputs(selected);
|
||||
auto revision = capture(selected, inputs);
|
||||
expect(revision->readiness(Operation::semantic).level == ReadinessLevel::ready);
|
||||
expect(revision->readiness(Operation::rename).level == ReadinessLevel::unavailable);
|
||||
inputs.rename = f.coverage(selected);
|
||||
auto full = capture(selected, inputs);
|
||||
expect(full->readiness(Operation::rename).level == ReadinessLevel::ready);
|
||||
PublicationSlot slot{f.selection, Operation::rename};
|
||||
require(slot.replace_inputs(1, full).has_value());
|
||||
auto pending = take(slot.issue());
|
||||
auto partial = inputs;
|
||||
partial.rename->contexts->pop_back();
|
||||
auto missing = capture(selected, partial);
|
||||
expect(mentions(missing->readiness(Operation::rename), InputIssue::affected_contexts));
|
||||
require(slot.replace_inputs(2, missing).has_value());
|
||||
expect(!slot.publish(pending, "obsolete complete proof") && !slot.issue().has_value());
|
||||
partial = inputs;
|
||||
partial.rename->contexts->back().verification.reset();
|
||||
expect(capture(selected, partial)->readiness(Operation::rename).level ==
|
||||
ReadinessLevel::unavailable);
|
||||
partial = inputs;
|
||||
partial.rename->editable_spelling_proof.reset();
|
||||
expect(mentions(capture(selected, partial)->readiness(Operation::rename),
|
||||
InputIssue::edit_provenance));
|
||||
auto read_only = f.record();
|
||||
read_only.sources.back().editability = Editability::read_only;
|
||||
selected = take(f.selection.update(f.generation({read_only})));
|
||||
inputs.rename = f.coverage(selected);
|
||||
expect(capture(selected, inputs)->readiness(Operation::rename).level ==
|
||||
ReadinessLevel::unavailable);
|
||||
auto inactive = f.record("release", "tests", f.other);
|
||||
inactive.prerequisites.reset();
|
||||
selected = take(f.selection.update(f.generation({f.record(), inactive})));
|
||||
inputs.rename = f.coverage(selected);
|
||||
auto incomplete = capture(selected, inputs);
|
||||
expect(incomplete->readiness(Operation::semantic).level == ReadinessLevel::ready);
|
||||
expect(mentions(incomplete->readiness(Operation::rename), InputIssue::affected_contexts));
|
||||
}
|
||||
|
||||
VOID_TEST(BuildModel, cross_root_rename_proofs_bind_declared_roots_sessions_and_generations) {
|
||||
Fixture f, sibling;
|
||||
auto selected = f.select();
|
||||
auto inputs = f.inputs(selected);
|
||||
inputs.rename = f.coverage(selected);
|
||||
auto other = sibling.generation({sibling.record()});
|
||||
inputs.rename->contexts->push_back({other, other->contexts().front().key, "sibling-checked"});
|
||||
expect(AnalysisRevision::capture(selected, inputs) == std::unexpected{ModelError::wrong_scope});
|
||||
inputs.rename->workspace_roots.push_back(sibling.root);
|
||||
auto revision = capture(selected, inputs);
|
||||
expect(revision->readiness(Operation::rename).level == ReadinessLevel::ready);
|
||||
PublicationSlot slot{f.selection, Operation::rename};
|
||||
require(slot.replace_inputs(1, revision).has_value());
|
||||
auto ticket = take(slot.issue());
|
||||
// The session owner invalidates the proof when its sibling workspace changes.
|
||||
require(slot.replace_inputs(2, {}).has_value());
|
||||
expect(!slot.publish(ticket, "obsolete sibling evidence"));
|
||||
sibling.workspace.session = "foreign-session";
|
||||
inputs.rename->contexts->back().generation = sibling.generation({sibling.record()});
|
||||
expect(AnalysisRevision::capture(selected, inputs) == std::unexpected{ModelError::wrong_scope});
|
||||
inputs.rename = f.coverage(selected);
|
||||
auto repeated = inputs.rename->contexts->front();
|
||||
inputs.rename->contexts->push_back(repeated);
|
||||
expect(AnalysisRevision::capture(selected, inputs) ==
|
||||
std::unexpected{ModelError::invalid_input});
|
||||
inputs.rename->contexts->back().generation = f.generation({f.record()});
|
||||
expect(AnalysisRevision::capture(selected, inputs) ==
|
||||
std::unexpected{ModelError::invalid_input});
|
||||
}
|
||||
|
||||
VOID_TEST(BuildModel, retained_generation_owns_artifacts_until_the_last_ticket_releases) {
|
||||
Fixture f;
|
||||
auto ctx = f.record();
|
||||
ctx.artifacts =
|
||||
std::vector<Artifact>{{f.root / "core.bmi", "immutable-bmi", Availability::ready}};
|
||||
auto unretained = take(f.selection.update(f.generation({ctx})));
|
||||
expect(mentions(capture(unretained, f.inputs(unretained))->readiness(Operation::semantic),
|
||||
InputIssue::artifacts));
|
||||
PublicationSlot slot{f.selection, Operation::semantic};
|
||||
std::weak_ptr<const ArtifactLease> old_lease;
|
||||
std::weak_ptr<const BuildGeneration> old_generation;
|
||||
Ticket outstanding;
|
||||
{
|
||||
auto lease = std::make_shared<ArtifactLease>();
|
||||
auto generation = f.generation({ctx}, "retained", lease);
|
||||
old_lease = lease;
|
||||
old_generation = generation;
|
||||
auto selected = take(f.selection.update(generation));
|
||||
auto revision = capture(selected, f.inputs(selected));
|
||||
require(slot.replace_inputs(1, revision).has_value());
|
||||
outstanding = take(slot.issue());
|
||||
}
|
||||
auto fresh = f.select();
|
||||
require(slot.replace_inputs(2, capture(fresh, f.inputs(fresh))).has_value());
|
||||
expect(!old_lease.expired() && !old_generation.expired());
|
||||
expect(!slot.publish(outstanding, "superseded") &&
|
||||
outstanding->revision->selection->generation->retains_artifacts());
|
||||
outstanding.reset();
|
||||
expect(old_lease.expired() && old_generation.expired());
|
||||
|
||||
struct ObservedLease final : ArtifactLease {
|
||||
ObservedLease(PublicationSlot &slot, bool &released) : slot(slot), released(released) {}
|
||||
~ObservedLease() override { released = !slot.current(); }
|
||||
PublicationSlot &slot;
|
||||
bool &released;
|
||||
};
|
||||
bool released = false;
|
||||
{
|
||||
auto lease = std::make_shared<ObservedLease>(slot, released);
|
||||
auto selected = take(f.selection.update(f.generation({ctx}, "observed", lease)));
|
||||
require(slot.replace_inputs(3, capture(selected, f.inputs(selected))).has_value());
|
||||
require(slot.publish(take(slot.issue()), "retained"));
|
||||
}
|
||||
(void)f.select();
|
||||
require(slot.replace_inputs(4, {}).has_value());
|
||||
expect(released);
|
||||
}
|
||||
|
||||
VOID_TEST(BuildModel, selection_aba_and_reordered_observations_cannot_resurrect_results) {
|
||||
Fixture f;
|
||||
auto a = f.record();
|
||||
auto b = f.record("release", "tests");
|
||||
auto generation = f.generation({a, b});
|
||||
auto first = take(f.selection.update(generation, f.override_for(a.key)));
|
||||
auto inputs = f.inputs(first);
|
||||
auto initial = capture(first, inputs);
|
||||
PublicationSlot slot{f.selection, Operation::semantic};
|
||||
require(slot.replace_inputs(1, initial).has_value());
|
||||
auto obsolete = take(slot.issue());
|
||||
auto second = take(f.selection.update(generation, f.override_for(b.key)));
|
||||
require(slot.replace_inputs(2, capture(second, inputs)).has_value());
|
||||
require(slot.publish(take(slot.issue()), "B"));
|
||||
auto again = take(f.selection.update(generation, f.override_for(a.key)));
|
||||
expect(first->selected == again->selected && first->revision < second->revision &&
|
||||
second->revision < again->revision);
|
||||
require(slot.replace_inputs(3, capture(again, inputs)).has_value());
|
||||
expect(!slot.current() && !slot.publish(obsolete, "obsolete A"));
|
||||
auto newest = take(slot.issue());
|
||||
expect(slot.replace_inputs(2, {}) == std::unexpected{ModelError::superseded});
|
||||
expect(slot.publish(newest, "current A"));
|
||||
expect(slot.replace_inputs(4, initial) == std::unexpected{ModelError::superseded});
|
||||
expect(!slot.current());
|
||||
}
|
||||
|
||||
VOID_TEST(BuildModel, overlapping_requests_cancel_replay_and_retire_without_history) {
|
||||
Fixture f;
|
||||
auto selected = f.select();
|
||||
auto revision = capture(selected, f.inputs(selected));
|
||||
PublicationSlot slot{f.selection, Operation::diagnostics},
|
||||
other{f.selection, Operation::diagnostics};
|
||||
require(slot.replace_inputs(1, revision).has_value() &&
|
||||
other.replace_inputs(1, revision).has_value());
|
||||
auto older = take(slot.issue());
|
||||
auto foreign = take(other.issue());
|
||||
expect(older->id == foreign->id && !slot.publish(foreign, "foreign"));
|
||||
auto latest = take(slot.issue());
|
||||
expect(!slot.cancel(older));
|
||||
require(slot.publish(latest, "latest"));
|
||||
expect(!slot.publish(older, "older") && !slot.publish(latest, "replayed"));
|
||||
expect(slot.current()->payload == "latest");
|
||||
std::weak_ptr<const AnalysisRequest> previous;
|
||||
for (int i = 0; i < 128; ++i) {
|
||||
auto pending = take(slot.issue());
|
||||
expect(previous.expired());
|
||||
previous = pending;
|
||||
}
|
||||
auto cancelled = previous.lock();
|
||||
require(cancelled && slot.cancel(cancelled));
|
||||
expect(!slot.publish(cancelled, "cancelled") && !slot.cancel(cancelled));
|
||||
cancelled.reset();
|
||||
expect(previous.expired());
|
||||
require(slot.replace_inputs(2, {}).has_value());
|
||||
expect(!slot.current() && slot.issue() == std::unexpected{ModelError::no_inputs});
|
||||
}
|
||||
|
||||
VOID_TEST(BuildModel, revocation_and_configuration_floors_survive_empty_state) {
|
||||
Fixture f;
|
||||
auto selected = f.select();
|
||||
auto inputs = f.inputs(selected);
|
||||
auto old = capture(selected, inputs);
|
||||
PublicationSlot slot{f.selection, Operation::semantic};
|
||||
require(slot.replace_inputs(1, old).has_value());
|
||||
require(slot.publish(take(slot.issue()), "initial"));
|
||||
auto pending = take(slot.issue());
|
||||
slot.revoke_trust({f.root, "other-session"}, 31);
|
||||
expect(slot.current() != nullptr);
|
||||
slot.revoke_trust(f.workspace, 31);
|
||||
expect(!slot.current() && !slot.publish(pending, "revoked"));
|
||||
expect(slot.replace_inputs(2, old) == std::unexpected{ModelError::superseded});
|
||||
inputs.trust_generation = 31;
|
||||
inputs.configuration_generation = 21;
|
||||
auto fresh = capture(selected, inputs);
|
||||
require(slot.replace_inputs(3, fresh).has_value());
|
||||
auto current = take(slot.issue());
|
||||
slot.revoke_trust(f.workspace, 30);
|
||||
expect(slot.publish(current, "fresh"));
|
||||
require(slot.replace_inputs(4, {}).has_value());
|
||||
inputs.configuration_generation = 20;
|
||||
expect(slot.replace_inputs(5, capture(selected, inputs)) ==
|
||||
std::unexpected{ModelError::superseded});
|
||||
expect(slot.issue() == std::unexpected{ModelError::no_inputs});
|
||||
}
|
||||
|
||||
VOID_TEST(BuildModel, racing_revocation_and_completion_leave_no_stale_publication) {
|
||||
Fixture f;
|
||||
auto selected = f.select();
|
||||
auto inputs = f.inputs(selected);
|
||||
PublicationSlot slot{f.selection, Operation::semantic};
|
||||
for (std::uint64_t step = 1; step <= 24; ++step) {
|
||||
inputs.trust_generation = step;
|
||||
require(slot.replace_inputs(step, capture(selected, inputs)).has_value());
|
||||
auto ticket = take(slot.issue());
|
||||
std::barrier start{2};
|
||||
std::jthread worker{[&] {
|
||||
start.arrive_and_wait();
|
||||
(void)slot.publish(ticket, "result");
|
||||
}};
|
||||
start.arrive_and_wait();
|
||||
slot.revoke_trust(f.workspace, step + 1);
|
||||
worker.join();
|
||||
expect(!slot.current() && !slot.publish(ticket, "late") && !slot.issue().has_value());
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
@@ -0,0 +1,202 @@
|
||||
#include <Void/LanguageServer/Build/Providers.hpp>
|
||||
#include <Void/System/TempDir.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
|
||||
namespace {
|
||||
namespace fs = std::filesystem;
|
||||
using namespace Void::LanguageServer::Build;
|
||||
using Void::Testing::expect;
|
||||
using Void::Testing::require;
|
||||
|
||||
struct Files {
|
||||
Void::FileSystem::TempDir directory{"vls_provider_files_"};
|
||||
const fs::path root = fs::canonical(directory.path()) / "workspace";
|
||||
const fs::path other = root.parent_path() / "external";
|
||||
ProviderScope scope{.workspace = {root, "one"}};
|
||||
Files() {
|
||||
fs::create_directories(root);
|
||||
fs::create_directories(other);
|
||||
}
|
||||
void bind() {
|
||||
auto bound = bind_provider_scope(scope);
|
||||
require(bound.has_value());
|
||||
scope = std::move(*bound);
|
||||
}
|
||||
static void write(const fs::path &path, std::string_view bytes) {
|
||||
fs::create_directories(path.parent_path());
|
||||
std::ofstream file{path, std::ios::binary};
|
||||
file << bytes;
|
||||
file.close();
|
||||
require(file.good());
|
||||
}
|
||||
auto read(const fs::path &path, FilePurpose purpose = FilePurpose::database,
|
||||
std::size_t limit = 1024) const {
|
||||
return read_provider_file(scope, path, purpose, limit);
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
VOID_TEST(ProviderFiles, hashes_and_revalidates_a_stable_regular_file) {
|
||||
Files f;
|
||||
f.bind();
|
||||
auto path = f.root / "compile_commands.json";
|
||||
Files::write(path, "abc");
|
||||
auto captured = f.read(path);
|
||||
require(captured.has_value());
|
||||
expect(*captured->bytes == "abc");
|
||||
expect(captured->content_id ==
|
||||
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
|
||||
expect(captured->logical_path == path && captured->canonical_path == path);
|
||||
Files::write(f.root / "unrelated", "data");
|
||||
expect(provider_file_current(f.scope, *captured));
|
||||
Files::write(path, "abcd");
|
||||
expect(!provider_file_current(f.scope, *captured));
|
||||
expect(*captured->bytes == "abc");
|
||||
}
|
||||
|
||||
VOID_TEST(ProviderFiles, root_pins_survive_as_identifiers_and_reject_replacement) {
|
||||
Files f;
|
||||
auto path = f.other / "selected.json";
|
||||
f.scope.exact_database = path;
|
||||
f.bind();
|
||||
fs::rename(f.other, f.other.string() + "-old");
|
||||
Files::write(path, "new");
|
||||
auto result = f.read(path);
|
||||
require(!result);
|
||||
expect(result.error().code == "changed");
|
||||
fs::rename(f.root, f.root.string() + "-old");
|
||||
Files::write(f.root / "x", "x");
|
||||
auto replaced = f.read(f.root / "x");
|
||||
require(!replaced);
|
||||
expect(replaced.error().code == "changed");
|
||||
}
|
||||
|
||||
VOID_TEST(ProviderFiles, new_incarnation_keeps_the_granted_directories_and_retires_old_evidence) {
|
||||
Files f;
|
||||
const auto db = f.other / "selected.json";
|
||||
f.scope.exact_database = db;
|
||||
f.bind();
|
||||
Files::write(db, "original");
|
||||
const auto first = f.read(db);
|
||||
require(first.has_value());
|
||||
|
||||
auto second = reuse_provider_scope(f.scope, "two");
|
||||
require(second.has_value());
|
||||
auto next = read_provider_file(*second, db, FilePurpose::database, 1024);
|
||||
require(next.has_value());
|
||||
expect(same_provider_object(*first, *next));
|
||||
expect(!provider_file_current(*second, *first));
|
||||
|
||||
fs::rename(f.other, f.other.string() + "-first");
|
||||
Files::write(db, "replacement");
|
||||
expect(!provider_file_current(*second, *next));
|
||||
auto third = reuse_provider_scope(f.scope, "three");
|
||||
require(third.has_value());
|
||||
auto replaced = read_provider_file(*third, db, FilePurpose::database, 1024);
|
||||
require(!replaced);
|
||||
expect(replaced.error().code == "changed");
|
||||
Files::write(f.root / "inside", "valid");
|
||||
expect(read_provider_file(*third, f.root / "inside", FilePurpose::database, 1024).has_value());
|
||||
}
|
||||
|
||||
VOID_TEST(ProviderFiles, external_file_grants_are_exact_and_purpose_bound) {
|
||||
Files f;
|
||||
const auto db = f.other / "compile_commands.json", neighbor = f.other / "flags.rsp";
|
||||
f.scope.exact_database = db;
|
||||
f.bind();
|
||||
Files::write(db, "[]");
|
||||
Files::write(neighbor, "-DOUTSIDE");
|
||||
require(f.read(db).has_value());
|
||||
expect(!f.read(db, FilePurpose::selection));
|
||||
expect(!f.read(neighbor));
|
||||
expect(!f.read(neighbor, FilePurpose::response));
|
||||
auto tampered = f.scope;
|
||||
tampered.exact_database = neighbor;
|
||||
expect(!read_provider_file(tampered, neighbor, FilePurpose::database, 1024));
|
||||
fs::remove(db);
|
||||
fs::create_symlink(neighbor, db);
|
||||
expect(!f.read(db));
|
||||
}
|
||||
|
||||
VOID_TEST(ProviderFiles, native_build_roots_admit_only_editor_metadata_shapes) {
|
||||
Files f;
|
||||
f.scope.build_root = f.other;
|
||||
f.bind();
|
||||
const auto editor = f.other / "profiles/debug/editor";
|
||||
const auto db = editor / "generations/0123456789abcdef/compile_commands.json";
|
||||
Files::write(editor / "status.json", "{}");
|
||||
Files::write(db, "[]");
|
||||
Files::write(f.other / "compile_commands.json", "alias");
|
||||
expect(f.read(editor / "status.json", FilePurpose::status).has_value());
|
||||
expect(f.read(db, FilePurpose::native_database).has_value());
|
||||
expect(!f.read(db) && !f.read(db, FilePurpose::response));
|
||||
expect(!f.read(f.other / "compile_commands.json", FilePurpose::native_database));
|
||||
expect(!f.read(editor / "generations/not-an-id/compile_commands.json",
|
||||
FilePurpose::native_database));
|
||||
}
|
||||
|
||||
VOID_TEST(ProviderFiles, ordinary_workspace_link_retains_logical_and_physical_identity) {
|
||||
Files f;
|
||||
f.bind();
|
||||
const auto actual = f.root / "data/db", alias = f.root / "editor/compile_commands.json";
|
||||
Files::write(actual, "[]");
|
||||
fs::create_directories(alias.parent_path());
|
||||
fs::create_symlink("../data/db", alias);
|
||||
auto first = f.read(alias);
|
||||
require(first.has_value());
|
||||
expect(first->logical_path == alias && first->canonical_path == actual);
|
||||
auto hard = f.root / "also.db";
|
||||
fs::create_hard_link(actual, hard);
|
||||
auto via_alias = f.read(alias), via_hard = f.read(hard);
|
||||
require(via_alias && via_hard);
|
||||
expect(same_provider_object(*via_alias, *via_hard));
|
||||
fs::remove(alias);
|
||||
fs::create_symlink(hard, alias);
|
||||
expect(!provider_file_current(f.scope, *via_alias));
|
||||
Files::write(f.root / "replacement", "[]");
|
||||
fs::rename(f.root / "replacement", actual);
|
||||
auto replacement = f.read(actual);
|
||||
require(replacement.has_value());
|
||||
expect(!same_provider_object(*replacement, *via_hard));
|
||||
}
|
||||
|
||||
VOID_TEST(ProviderFiles, missing_selection_is_distinct_from_dangling_link_or_reference) {
|
||||
Files f;
|
||||
f.bind();
|
||||
const auto selector = f.root / ".vbs/editor_selection.json";
|
||||
auto missing = f.read(selector, FilePurpose::selection);
|
||||
require(!missing);
|
||||
expect(missing.error().code == "missing");
|
||||
fs::create_directories(selector.parent_path());
|
||||
fs::create_symlink(f.other / "not-present", selector);
|
||||
auto dangling = f.read(selector, FilePurpose::selection);
|
||||
require(!dangling);
|
||||
expect(dangling.error().code != "missing");
|
||||
auto status = f.read(f.root / "out/profiles/debug/editor/status.json", FilePurpose::status);
|
||||
require(!status);
|
||||
expect(status.error().code == "missing_reference");
|
||||
}
|
||||
|
||||
VOID_TEST(ProviderFiles, bounds_and_file_kinds_are_checked_before_payload_reads) {
|
||||
Files f;
|
||||
f.scope.limits.max_response_file_bytes = 2;
|
||||
f.bind();
|
||||
const auto path = f.root / "flags.rsp";
|
||||
Files::write(path, "abc");
|
||||
auto too_large = f.read(path, FilePurpose::response);
|
||||
require(!too_large);
|
||||
expect(too_large.error().code == "too_large");
|
||||
f.scope.limits.max_response_file_bytes = 1024;
|
||||
expect(!f.read(path, FilePurpose::response));
|
||||
const auto fifo = f.root / "pipe";
|
||||
require(::mkfifo(fifo.c_str(), 0600) == 0);
|
||||
auto nonregular = f.read(fifo);
|
||||
require(!nonregular);
|
||||
expect(nonregular.error().code == "not_regular");
|
||||
fs::create_symlink(f.other, f.root / "escape");
|
||||
expect(!f.read(f.root / "escape/flags.rsp", FilePurpose::response));
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/LanguageServer/Build/Providers.hpp>
|
||||
#include <Void/System/TempDir.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace provider_test {
|
||||
namespace fs = std::filesystem;
|
||||
namespace Build = Void::LanguageServer::Build;
|
||||
namespace Protocol = Void::LanguageServer::Protocol;
|
||||
using Protocol::Json;
|
||||
|
||||
inline Json str(std::string_view text) { return Json{std::string{text}}; }
|
||||
|
||||
inline void write_bytes(const fs::path &path, std::string_view bytes) {
|
||||
fs::create_directories(path.parent_path());
|
||||
std::ofstream file(path, std::ios::binary);
|
||||
file << bytes;
|
||||
file.close();
|
||||
Void::Testing::require(file.good());
|
||||
}
|
||||
|
||||
inline void write_json(const fs::path &path, const Json &json) {
|
||||
auto bytes = Protocol::serialize_json(json);
|
||||
Void::Testing::require(bytes.has_value());
|
||||
write_bytes(path, *bytes);
|
||||
}
|
||||
|
||||
struct Fixture {
|
||||
Void::FileSystem::TempDir tmp{"vls_build_provider_"};
|
||||
fs::path root = fs::canonical(tmp.path());
|
||||
fs::path build = root / "out", selector = root / ".vbs/editor_selection.json";
|
||||
fs::path source = root / "main.cpp", compdb = root / "compile_commands.json";
|
||||
Build::ProviderScope scope{.workspace = {root, "test-editor"}};
|
||||
static constexpr std::string_view first = "0123456789abcdef", second = "fedcba9876543210";
|
||||
|
||||
Fixture() {
|
||||
fs::create_directories(build);
|
||||
write_bytes(source, "int main() {}\n");
|
||||
}
|
||||
void bind() {
|
||||
auto pinned = Build::bind_provider_scope(scope);
|
||||
Void::Testing::require(pinned.has_value());
|
||||
scope = std::move(*pinned);
|
||||
}
|
||||
Json::Array rows() const {
|
||||
Json::Array entries;
|
||||
for (auto flag : {"-DVALUE=1", "-DVALUE=2"}) {
|
||||
entries.push_back(Json{Json::Object{
|
||||
{"directory", str(root.string())},
|
||||
{"file", str("main.cpp")},
|
||||
{"output", str("main.o")},
|
||||
{"arguments", Json{Json::Array{str("c++"), str("-std=c++26"), str(flag), str("-c"),
|
||||
str("main.cpp"), str("-o"), str("main.o")}}}}});
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
fs::path editor(std::string_view slug = "debug") const {
|
||||
return build / "profiles" / slug / "editor";
|
||||
}
|
||||
fs::path database(std::string_view id = first, std::string_view slug = "debug") const {
|
||||
return editor(slug) / "generations" / id / "compile_commands.json";
|
||||
}
|
||||
Json::Object selection(std::string_view id = first, std::string_view profile = "debug") const {
|
||||
return {{"schema_version", Json{std::int64_t{1}}},
|
||||
{"ticket", Json{std::int64_t{7}}},
|
||||
{"selected_profile", str(profile)},
|
||||
{"selected_build_root", str(build.string())},
|
||||
{"selected_generation_id", str(id)},
|
||||
{"selected_compdb_path", str(database(id).string())},
|
||||
{"managed_root_alias_active", Json{false}},
|
||||
{"root_alias_warning", str("")}};
|
||||
}
|
||||
Json::Object valid_status(std::string_view id = first,
|
||||
std::string_view profile = "debug") const {
|
||||
return {{"schema_version", Json{std::int64_t{1}}},
|
||||
{"profile", str(profile)},
|
||||
{"generation_id", str(id)},
|
||||
{"status", str("valid")},
|
||||
{"diagnostic", str("")},
|
||||
{"compdb_path", str(database(id).string())},
|
||||
{"entry_count", Json{std::int64_t{2}}},
|
||||
{"readiness_warnings", Json{Json::Array{str("generated input pending")}}}};
|
||||
}
|
||||
void publish(std::string_view id = first) const {
|
||||
write_json(database(id), Json{rows()});
|
||||
write_json(editor() / "status.json", Json{valid_status(id)});
|
||||
write_json(selector, Json{selection(id)});
|
||||
}
|
||||
};
|
||||
} // namespace provider_test
|
||||
@@ -0,0 +1,185 @@
|
||||
#include "ProviderFixture.hpp"
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
namespace {
|
||||
using namespace provider_test;
|
||||
using namespace provider_test::Build;
|
||||
using Void::Testing::expect;
|
||||
using Void::Testing::require;
|
||||
|
||||
VOID_TEST(VbsProvider, selects_immutable_generation_with_real_alternatives_and_warnings) {
|
||||
Fixture f;
|
||||
f.bind();
|
||||
f.publish();
|
||||
write_bytes(f.compdb, "unrelated root alias");
|
||||
write_bytes(f.build / "compile_commands.json", "wrong build alias");
|
||||
auto result = observe_vbs(f.scope, f.selector);
|
||||
require(result.health == ProviderHealth::ready && result.generation);
|
||||
expect(result.profile == "debug" && result.native_generation == Fixture::first);
|
||||
expect(result.selection_ticket == 7 && result.generation->identity().provider == "vbs");
|
||||
expect(result.generation->candidates(f.source).size() == 2);
|
||||
expect(result.warnings.size() == 1 && result.warnings[0].code == "readiness_warning");
|
||||
expect(!result.generation->retains_artifacts());
|
||||
for (const auto &context : result.generation->contexts()) {
|
||||
expect(!context.key.target && context.key.role == ContextRole::unknown);
|
||||
expect(context.original && context.original->metadata_file == f.database());
|
||||
}
|
||||
}
|
||||
|
||||
VOID_TEST(VbsProvider, accepts_changed_generation_at_same_ticket_and_retains_old_observation) {
|
||||
Fixture f;
|
||||
f.bind();
|
||||
f.publish();
|
||||
auto old = observe_vbs(f.scope, f.selector);
|
||||
require(old.generation != nullptr);
|
||||
f.publish(Fixture::second);
|
||||
auto current = observe_vbs(f.scope, f.selector);
|
||||
require(current.generation != nullptr);
|
||||
expect(current.selection_ticket == old.selection_ticket);
|
||||
expect(current.generation->identity().revision != old.generation->identity().revision);
|
||||
expect(!provider_file_current(f.scope, old.inputs[0]));
|
||||
expect(old.generation->contexts().size() == 2 && fs::exists(f.database()));
|
||||
}
|
||||
|
||||
VOID_TEST(VbsProvider, reserved_ticket_can_be_pending_or_retain_its_previous_tuple) {
|
||||
Fixture f;
|
||||
f.bind();
|
||||
auto record = f.selection();
|
||||
record["selected_generation_id"] = str("");
|
||||
record["selected_compdb_path"] = str("");
|
||||
write_json(f.selector, Json{record});
|
||||
auto pending = observe_vbs(f.scope, f.selector);
|
||||
require(!pending.issues.empty());
|
||||
expect(!pending.generation && pending.issues.front().code == "selection_pending");
|
||||
f.publish();
|
||||
record = f.selection();
|
||||
record["ticket"] = Json{std::int64_t{8}};
|
||||
write_json(f.selector, Json{record});
|
||||
auto selected = observe_vbs(f.scope, f.selector);
|
||||
expect(selected.selection_ticket == 8 && selected.generation != nullptr);
|
||||
}
|
||||
|
||||
VOID_TEST(VbsProvider, stale_and_invalid_status_cannot_reactivate_a_readable_database) {
|
||||
Fixture f;
|
||||
f.bind();
|
||||
f.publish();
|
||||
auto status = f.valid_status();
|
||||
status.erase("readiness_warnings");
|
||||
status.erase("entry_count");
|
||||
status["diagnostic"] = str("build is incomplete");
|
||||
for (auto state : {"stale", "invalid"}) {
|
||||
status["status"] = str(state);
|
||||
write_json(f.editor() / "status.json", Json{status});
|
||||
auto result = observe_vbs(f.scope, f.selector);
|
||||
expect(!result.generation && result.inputs.size() == 2);
|
||||
require(!result.issues.empty());
|
||||
expect(result.issues[0].message == "build is incomplete");
|
||||
}
|
||||
}
|
||||
|
||||
VOID_TEST(VbsProvider, directory_spellings_apply_only_to_the_build_root) {
|
||||
Fixture f;
|
||||
f.bind();
|
||||
f.publish();
|
||||
auto selector = f.selection();
|
||||
selector["selected_build_root"] = str(f.build.string() + "/.");
|
||||
write_json(f.selector, Json{selector});
|
||||
require(observe_vbs(f.scope, f.selector).generation != nullptr);
|
||||
for (const auto ending : {"/", "/.", "/.."}) {
|
||||
auto bad = selector;
|
||||
bad["selected_compdb_path"] = str(f.database().string() + ending);
|
||||
write_json(f.selector, Json{bad});
|
||||
expect(!observe_vbs(f.scope, f.selector).generation);
|
||||
write_json(f.selector, Json{selector});
|
||||
auto status = f.valid_status();
|
||||
status["compdb_path"] = str(f.database().string() + ending);
|
||||
write_json(f.editor() / "status.json", Json{status});
|
||||
expect(!observe_vbs(f.scope, f.selector).generation);
|
||||
write_json(f.editor() / "status.json", Json{f.valid_status()});
|
||||
}
|
||||
}
|
||||
|
||||
VOID_TEST(VbsProvider, rejects_disagreeing_profile_generation_count_and_alias_paths) {
|
||||
Fixture f;
|
||||
f.bind();
|
||||
f.publish();
|
||||
for (auto key : {"profile", "generation_id", "entry_count", "compdb_path", "schema_version"}) {
|
||||
auto status = f.valid_status();
|
||||
const std::string_view field = key;
|
||||
if (field == "profile")
|
||||
status[key] = str("release");
|
||||
else if (field == "generation_id")
|
||||
status[key] = str(Fixture::second);
|
||||
else if (field == "compdb_path")
|
||||
status[key] = str(f.compdb.string());
|
||||
else
|
||||
status[key] = Json{std::int64_t{9}};
|
||||
write_json(f.editor() / "status.json", Json{status});
|
||||
expect(!observe_vbs(f.scope, f.selector).generation);
|
||||
}
|
||||
}
|
||||
|
||||
VOID_TEST(VbsProvider, distinguishes_missing_selector_from_missing_selected_generation) {
|
||||
Fixture f;
|
||||
f.bind();
|
||||
expect(observe_vbs(f.scope, f.selector).health == ProviderHealth::missing);
|
||||
f.publish();
|
||||
fs::remove(f.database());
|
||||
auto missing_db = observe_vbs(f.scope, f.selector);
|
||||
expect(missing_db.health != ProviderHealth::missing && !missing_db.generation);
|
||||
fs::remove(f.editor() / "status.json");
|
||||
expect(observe_vbs(f.scope, f.selector).health != ProviderHealth::missing);
|
||||
write_bytes(f.selector, "{");
|
||||
expect(observe_vbs(f.scope, f.selector).health == ProviderHealth::invalid);
|
||||
}
|
||||
|
||||
VOID_TEST(VbsProvider, relative_locators_require_a_producer_base_or_explicit_build_root) {
|
||||
Fixture f;
|
||||
f.publish();
|
||||
auto selection = f.selection(), status = f.valid_status();
|
||||
auto relative_db = f.database().lexically_relative(f.root).string();
|
||||
selection["selected_build_root"] = str("out");
|
||||
selection["selected_compdb_path"] = str(relative_db);
|
||||
status["compdb_path"] = str(relative_db);
|
||||
write_json(f.selector, Json{selection});
|
||||
write_json(f.editor() / "status.json", Json{status});
|
||||
auto requested = f.scope;
|
||||
f.bind();
|
||||
auto ambiguous = observe_vbs(f.scope, f.selector);
|
||||
require(!ambiguous.issues.empty());
|
||||
expect(ambiguous.issues[0].code == "ambiguous_locator");
|
||||
requested.producer_cwd = f.root;
|
||||
auto known = bind_provider_scope(requested);
|
||||
require(known.has_value());
|
||||
expect(observe_vbs(*known, f.selector).generation != nullptr);
|
||||
requested.producer_cwd.reset();
|
||||
requested.build_root = f.build;
|
||||
auto explicit_root = bind_provider_scope(requested);
|
||||
require(explicit_root.has_value());
|
||||
expect(observe_vbs(*explicit_root, f.selector).generation != nullptr);
|
||||
selection["selected_compdb_path"] = str("elsewhere/" + relative_db);
|
||||
write_json(f.selector, Json{selection});
|
||||
expect(!observe_vbs(*explicit_root, f.selector).generation);
|
||||
}
|
||||
|
||||
VOID_TEST(VbsProvider, refuses_dot_profiles_and_sanitized_component_collisions) {
|
||||
Fixture f;
|
||||
f.bind();
|
||||
f.publish();
|
||||
for (auto profile : {".", ".."}) {
|
||||
write_json(f.selector, Json{f.selection(Fixture::first, profile)});
|
||||
expect(!observe_vbs(f.scope, f.selector).generation);
|
||||
}
|
||||
const auto db = f.database(Fixture::first, "a_b");
|
||||
auto select = f.selection(Fixture::first, "a/b"),
|
||||
status = f.valid_status(Fixture::first, "a?b");
|
||||
select["selected_compdb_path"] = str(db.string());
|
||||
status["compdb_path"] = str(db.string());
|
||||
write_json(f.selector, Json{select});
|
||||
write_json(f.editor("a_b") / "status.json", Json{status});
|
||||
write_json(db, Json{f.rows()});
|
||||
auto mismatch = observe_vbs(f.scope, f.selector);
|
||||
require(!mismatch.issues.empty());
|
||||
expect(!mismatch.generation && mismatch.issues[0].code == "invalid_status");
|
||||
}
|
||||
} // namespace
|
||||
Reference in new issue
Block a user