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,556 @@
|
||||
#include <vls/WorkspaceSession.hpp>
|
||||
|
||||
#include <Void/LanguageServer/Documents/Uri.hpp>
|
||||
#include <Void/System/TempDir.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <future>
|
||||
#include <semaphore>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
namespace {
|
||||
namespace fs = std::filesystem;
|
||||
namespace Workspace = Void::LanguageServer::Workspace;
|
||||
namespace Docs = Void::LanguageServer::Documents;
|
||||
namespace Protocol = Void::LanguageServer::Protocol;
|
||||
using Protocol::Json;
|
||||
using Void::Testing::expect;
|
||||
using Void::Testing::require;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
Json str(std::string_view value) { return Json{std::string{value}}; }
|
||||
Json integer(std::int64_t value) { return Json{value}; }
|
||||
Json object(Json::Object fields = {}) { return Json{std::move(fields)}; }
|
||||
Json uri(const fs::path &path) { return Json{Docs::path_to_file_uri(path)}; }
|
||||
|
||||
const Json *field(const Json &value, std::string_view name) {
|
||||
const auto *fields = Protocol::as_object(&value);
|
||||
return fields ? Protocol::find_member(*fields, name) : nullptr;
|
||||
}
|
||||
|
||||
std::string read_string(const Json &value, std::string_view name) {
|
||||
const auto *text = Protocol::as_string(field(value, name));
|
||||
require(text != nullptr);
|
||||
return *text;
|
||||
}
|
||||
|
||||
const Json &nested(const Json &value, std::string_view name) {
|
||||
const auto *entry = field(value, name);
|
||||
require(entry != nullptr);
|
||||
return *entry;
|
||||
}
|
||||
|
||||
std::string issue(const Json &value) {
|
||||
const auto *issues = Protocol::as_array(field(value, "issues"));
|
||||
require(issues && !issues->empty());
|
||||
return read_string(issues->front(), "code");
|
||||
}
|
||||
|
||||
Json folder(const fs::path &root) { return object({{"uri", uri(root)}, {"name", str("C++")}}); }
|
||||
|
||||
Json initialize(Json::Array roots, Json settings = object()) {
|
||||
return object(
|
||||
{{"workspaceFolders", Json{std::move(roots)}},
|
||||
{"initializationOptions", object({{"voidLanguageServer", std::move(settings)}})}});
|
||||
}
|
||||
|
||||
Json change(Json::Array added, Json::Array removed) {
|
||||
auto event = object({{"added", Json{std::move(added)}}, {"removed", Json{std::move(removed)}}});
|
||||
return object({{"event", std::move(event)}});
|
||||
}
|
||||
|
||||
Json configuration(Json::Object entries) {
|
||||
return object({{"settings", object({{"voidLanguageServer", object(std::move(entries))}})}});
|
||||
}
|
||||
|
||||
Json query(const fs::path &root = {}, const fs::path &file = {}) {
|
||||
Json::Object params;
|
||||
if (!root.empty())
|
||||
params.emplace("workspaceUri", uri(root));
|
||||
if (!file.empty())
|
||||
params.emplace("textDocument", object({{"uri", uri(file)}}));
|
||||
return object(std::move(params));
|
||||
}
|
||||
|
||||
Json status(vls::WorkspaceSession &session, const Json ¶ms = object()) {
|
||||
auto result = session.provider_status(¶ms);
|
||||
require(result.has_value());
|
||||
auto wire = Protocol::serialize_json(*result);
|
||||
require(wire.has_value());
|
||||
expect(wire->size() < 512 * 1024);
|
||||
return std::move(*result);
|
||||
}
|
||||
|
||||
void write(const fs::path &path, std::string_view text) {
|
||||
fs::create_directories(path.parent_path());
|
||||
std::ofstream file{path, std::ios::binary};
|
||||
file << text;
|
||||
file.close();
|
||||
require(file.good());
|
||||
}
|
||||
|
||||
void write_json(const fs::path &path, const Json &value) {
|
||||
auto text = Protocol::serialize_json(value);
|
||||
require(text.has_value());
|
||||
write(path, *text);
|
||||
}
|
||||
|
||||
struct Fixture {
|
||||
Void::FileSystem::TempDir temp{"vls_provider_session_"};
|
||||
fs::path base = fs::canonical(temp.path());
|
||||
fs::path one = base / "one", two = base / "one-more", external = base / "external";
|
||||
Fixture() {
|
||||
write(one / "main.cpp", "int one;\n");
|
||||
write(two / "main.cpp", "int two;\n");
|
||||
fs::create_directories(external);
|
||||
}
|
||||
|
||||
static void compdb(const fs::path &root, const fs::path &path, unsigned count = 1,
|
||||
std::string_view compiler = "g++") {
|
||||
Json::Array records;
|
||||
for (auto i = 0U; i < count; ++i) {
|
||||
records.push_back(
|
||||
object({{"directory", Json{root.native()}},
|
||||
{"file", str("main.cpp")},
|
||||
{"arguments", Json{Json::Array{str(compiler), str("-c"), str("main.cpp"),
|
||||
Json{"-DCASE=" + std::to_string(i)}}}}}));
|
||||
}
|
||||
write_json(path, Json{std::move(records)});
|
||||
}
|
||||
|
||||
static fs::path native(const fs::path &root, const fs::path &build, unsigned count = 1,
|
||||
const fs::path &selector = {}) {
|
||||
constexpr std::string_view id = "0123456789abcdef";
|
||||
const auto editor = build / "profiles/debug/editor";
|
||||
const auto database = editor / "generations" / id / "compile_commands.json";
|
||||
compdb(root, database, count);
|
||||
write_json(editor / "status.json", object({{"schema_version", integer(1)},
|
||||
{"profile", str("debug")},
|
||||
{"status", str("valid")},
|
||||
{"diagnostic", str("")},
|
||||
{"generation_id", str(id)},
|
||||
{"compdb_path", Json{database.native()}},
|
||||
{"entry_count", integer(count)},
|
||||
{"readiness_warnings", Json{Json::Array{}}}}));
|
||||
write_json(selector.empty() ? root / ".vbs/editor_selection.json" : selector,
|
||||
object({{"schema_version", integer(1)},
|
||||
{"ticket", integer(7)},
|
||||
{"selected_profile", str("debug")},
|
||||
{"selected_build_root", Json{build.native()}},
|
||||
{"selected_generation_id", str(id)},
|
||||
{"selected_compdb_path", Json{database.native()}}}));
|
||||
return database;
|
||||
}
|
||||
};
|
||||
|
||||
struct PauseObservation {
|
||||
std::atomic_bool pause_next{};
|
||||
std::binary_semaphore paused{0}, resume{0};
|
||||
|
||||
void hook() {
|
||||
if (pause_next.exchange(false)) {
|
||||
paused.release();
|
||||
resume.acquire();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
Json run(vls::WorkspaceSession &session, F action, const Json ¶ms = object()) {
|
||||
pause_next = true;
|
||||
auto old = std::async(std::launch::async, [&] { return status(session, params); });
|
||||
{
|
||||
struct Resume {
|
||||
std::binary_semaphore &gate;
|
||||
~Resume() { gate.release(); }
|
||||
} release{resume};
|
||||
require(paused.try_acquire_for(5s));
|
||||
action();
|
||||
}
|
||||
return old.get();
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
VOID_TEST(ProviderSession, workspace_folders_precedence_and_legacy_root) {
|
||||
Fixture f;
|
||||
vls::WorkspaceSession absent, empty, explicit_null, legacy, invalid;
|
||||
require(absent.initialize(object()).has_value());
|
||||
require(empty
|
||||
.initialize(object({{"workspaceFolders", Json{Json::Array{}}},
|
||||
{"rootUri", str("invalid but unused")}}))
|
||||
.has_value());
|
||||
require(explicit_null
|
||||
.initialize(object({{"workspaceFolders", Json{nullptr}}, {"rootUri", uri(f.one)}}))
|
||||
.has_value());
|
||||
for (auto *session : {&absent, &empty, &explicit_null})
|
||||
expect(read_string(status(*session), "state") == "documentOnly");
|
||||
require(legacy.initialize(object({{"rootUri", uri(f.one)}})).has_value());
|
||||
const auto legacy_status = status(legacy);
|
||||
expect(read_string(legacy_status, "workspaceUri") == Docs::path_to_file_uri(f.one));
|
||||
expect(read_string(legacy_status, "state") == "missing");
|
||||
expect(!invalid.initialize(object({{"rootUri", str("file://remote/tmp")}})));
|
||||
expect(!invalid.initialize(initialize({folder(f.one / "main.cpp")})));
|
||||
expect(!invalid.initialize(initialize({folder(f.base / "absent" / ".." / "one")})));
|
||||
expect(!invalid.initialize(initialize(Json::Array(65, folder(f.one)))));
|
||||
fs::create_directory_symlink(f.one, f.base / "alias");
|
||||
expect(!invalid.initialize(initialize({folder(f.one), folder(f.base / "alias")})));
|
||||
require(invalid.initialize(initialize({folder(f.base / "alias")})).has_value());
|
||||
expect(read_string(status(invalid, query(f.base / "alias")), "workspaceUri") ==
|
||||
Docs::path_to_file_uri(f.one));
|
||||
fs::remove(f.base / "alias");
|
||||
fs::create_directory(f.base / "alias");
|
||||
fs::create_directory_symlink(f.base / "alias", f.base / "other-alias");
|
||||
auto colliding = change({folder(f.base / "other-alias")}, {});
|
||||
expect(!invalid.update_folders(&colliding));
|
||||
expect(read_string(status(invalid, query(f.base / "alias")), "workspaceUri") ==
|
||||
Docs::path_to_file_uri(f.one));
|
||||
const auto virtual_query =
|
||||
object({{"textDocument", object({{"uri", str("untitled:buffer")}})}});
|
||||
expect(read_string(status(invalid, virtual_query), "state") == "documentOnly");
|
||||
}
|
||||
|
||||
VOID_TEST(ProviderSession, independent_roots_and_deterministic_contexts) {
|
||||
Fixture f;
|
||||
f.native(f.one, f.one / "build", 20);
|
||||
f.compdb(f.two, f.two / "editor/build.json", 2);
|
||||
const auto settings =
|
||||
object({{"selectedProfile", str("debug")},
|
||||
{"workspaces", object({{Docs::path_to_file_uri(f.two),
|
||||
object({{"provider", str("compdb")},
|
||||
{"compdbPath", str("editor/build.json")}})}})}});
|
||||
vls::WorkspaceSession session;
|
||||
require(session.initialize(initialize({folder(f.one), folder(f.two)}, settings)).has_value());
|
||||
expect(!session.provider_status(nullptr));
|
||||
const auto first = status(session, query({}, f.one / "main.cpp"));
|
||||
const auto second = status(session, query({}, f.two / "main.cpp"));
|
||||
expect(read_string(first, "provider") == "vbs" && read_string(first, "state") == "ready");
|
||||
expect(read_string(first, "nativeGeneration") == "0123456789abcdef");
|
||||
expect(Protocol::as_int64(field(first, "ticket")) == 7);
|
||||
expect(Protocol::as_int64(field(first, "contextCount")) == 20);
|
||||
expect(Protocol::as_bool(field(first, "alternativesTruncated")) == true);
|
||||
expect(read_string(nested(first, "selected"), "profile") == "debug");
|
||||
expect(read_string(nested(first, "selected"), "owningTu") ==
|
||||
Docs::path_to_file_uri(f.one / "main.cpp"));
|
||||
expect(read_string(second, "provider") == "compdb" && read_string(second, "state") == "ready");
|
||||
expect(read_string(first, "incarnation") != read_string(second, "incarnation"));
|
||||
const auto *alternatives = Protocol::as_array(field(second, "alternatives"));
|
||||
require(alternatives && alternatives->size() == 2);
|
||||
const auto selected = read_string(nested(second, "selected"), "alternative");
|
||||
expect(selected == read_string(alternatives->front(), "alternative"));
|
||||
const auto again = status(session, query(f.two, f.two / "main.cpp"));
|
||||
expect(read_string(nested(again, "selected"), "alternative") == selected);
|
||||
|
||||
fs::create_directories(f.one / "nested");
|
||||
auto added = change({folder(f.one / "nested")}, {});
|
||||
require(session.update_folders(&added).has_value());
|
||||
auto ambiguous = query({}, f.one / "nested/main.cpp");
|
||||
expect(!session.provider_status(&ambiguous));
|
||||
expect(read_string(status(session, query(f.one, f.one / "nested/main.cpp")), "state") ==
|
||||
"ready");
|
||||
}
|
||||
|
||||
VOID_TEST(ProviderSession, malformed_updates_preserve_roots_settings_and_history) {
|
||||
Fixture f;
|
||||
const auto database = f.one / "compile_commands.json";
|
||||
f.compdb(f.one, database);
|
||||
vls::WorkspaceSession session;
|
||||
require(session.initialize(initialize({folder(f.one), folder(f.two)})).has_value());
|
||||
const auto valid = status(session, query(f.one));
|
||||
auto bad_configuration = configuration(
|
||||
{{"provider", str("none")},
|
||||
{"workspaces",
|
||||
object({{Docs::path_to_file_uri(f.two), object({{"selectedProfile", integer(2)}})}})}});
|
||||
expect(!session.configure(&bad_configuration));
|
||||
auto bad_folders = change({folder(f.external / "absent")}, {folder(f.one)});
|
||||
expect(!session.update_folders(&bad_folders));
|
||||
auto malformed = object({{"workspaceUri", integer(5)}});
|
||||
expect(!session.provider_status(&malformed));
|
||||
write(database, "invalid");
|
||||
const auto degraded = status(session, query(f.one));
|
||||
expect(read_string(degraded, "state") == "degraded");
|
||||
expect(read_string(degraded, "incarnation") == read_string(valid, "incarnation"));
|
||||
expect(read_string(nested(degraded, "lastGood"), "generation") ==
|
||||
read_string(valid, "generation"));
|
||||
expect(!field(degraded, "generation"));
|
||||
|
||||
auto disable_two = configuration(
|
||||
{{"workspaces",
|
||||
object({{Docs::path_to_file_uri(f.two), object({{"provider", str("none")}})}})}});
|
||||
require(session.configure(&disable_two).has_value());
|
||||
expect(read_string(status(session, query(f.two)), "state") == "disabled");
|
||||
expect(read_string(status(session, query(f.one)), "state") == "degraded");
|
||||
}
|
||||
|
||||
VOID_TEST(ProviderSession, broken_native_authority_suppresses_automatic_fallback) {
|
||||
Fixture f;
|
||||
f.compdb(f.one, f.one / "compile_commands.json");
|
||||
const auto selector = f.one / ".vbs/editor_selection.json";
|
||||
vls::WorkspaceSession session;
|
||||
require(session.initialize(initialize({folder(f.one)})).has_value());
|
||||
expect(read_string(status(session), "provider") == "compdb");
|
||||
|
||||
auto vbs = configuration({{"provider", str("vbs")}});
|
||||
require(session.configure(&vbs).has_value());
|
||||
const auto missing = status(session);
|
||||
expect(read_string(missing, "provider") == "vbs" && read_string(missing, "state") == "missing");
|
||||
auto automatic = configuration({});
|
||||
require(session.configure(&automatic).has_value());
|
||||
fs::create_directories(selector.parent_path());
|
||||
fs::create_symlink(f.one / "absent.json", selector);
|
||||
const auto denied = status(session);
|
||||
expect(read_string(denied, "provider") == "vbs" && issue(denied) == "outside_scope");
|
||||
fs::remove(selector);
|
||||
write(selector, "{");
|
||||
const auto corrupt = status(session);
|
||||
expect(read_string(corrupt, "provider") == "vbs" && issue(corrupt) == "invalid_metadata");
|
||||
const auto build = f.one / "build";
|
||||
const auto db = f.native(f.one, build);
|
||||
auto status_path = build / "profiles/debug/editor/status.json";
|
||||
fs::remove(status_path);
|
||||
const auto unavailable = status(session);
|
||||
expect(read_string(unavailable, "provider") == "vbs" &&
|
||||
issue(unavailable) == "missing_reference");
|
||||
f.native(f.one, build);
|
||||
const auto ready = status(session);
|
||||
write_json(status_path, object({{"schema_version", integer(1)},
|
||||
{"profile", str("debug")},
|
||||
{"status", str("valid")},
|
||||
{"diagnostic", str("")},
|
||||
{"generation_id", str("1123456789abcdef")},
|
||||
{"compdb_path", Json{db.native()}},
|
||||
{"entry_count", integer(1)},
|
||||
{"readiness_warnings", Json{Json::Array{}}}}));
|
||||
const auto mismatch = status(session);
|
||||
expect(read_string(mismatch, "state") == "stale" && issue(mismatch) == "generation_mismatch");
|
||||
write_json(status_path, object({{"schema_version", integer(1)},
|
||||
{"profile", str("debug")},
|
||||
{"status", str("stale")},
|
||||
{"diagnostic", str("build failed")}}));
|
||||
const auto stale = status(session);
|
||||
expect(read_string(stale, "state") == "stale" && issue(stale) == "vbs_stale");
|
||||
expect(read_string(nested(stale, "lastGood"), "generation") ==
|
||||
read_string(ready, "generation"));
|
||||
fs::remove(db);
|
||||
auto compdb = configuration({{"provider", str("compdb")}});
|
||||
require(session.configure(&compdb).has_value());
|
||||
expect(read_string(status(session), "provider") == "compdb");
|
||||
}
|
||||
|
||||
VOID_TEST(ProviderSession, managed_native_aliases_are_ineligible_for_automatic_compdb) {
|
||||
Fixture f;
|
||||
const auto build = f.one / "out";
|
||||
const auto generation = f.native(f.one, build);
|
||||
fs::remove(f.one / ".vbs/editor_selection.json");
|
||||
vls::WorkspaceSession session;
|
||||
require(session.initialize(initialize({folder(f.one)})).has_value());
|
||||
for (const auto *relative : {"compile_commands.json", "out/compile_commands.json",
|
||||
"out/profiles/debug/editor/compile_commands.json"}) {
|
||||
fs::create_symlink(generation, f.one / relative);
|
||||
auto config = configuration({{"compdbPath", str(relative)}});
|
||||
require(session.configure(&config).has_value());
|
||||
const auto result = status(session);
|
||||
expect(read_string(result, "state") == "degraded" && issue(result) == "vbs_managed_alias");
|
||||
expect(!field(result, "generation"));
|
||||
}
|
||||
auto manual = configuration(
|
||||
{{"provider", str("compdb")}, {"compdbPath", str("out/compile_commands.json")}});
|
||||
require(session.configure(&manual).has_value());
|
||||
expect(read_string(status(session), "state") == "ready");
|
||||
}
|
||||
|
||||
VOID_TEST(ProviderSession, passive_commands_never_execute_and_launcher_grants_stay_root_bound) {
|
||||
Fixture f;
|
||||
const auto tool = f.one / "marker-tool";
|
||||
const auto marker = f.one / "ran";
|
||||
write(tool, "#!/bin/sh\n: > '" + marker.native() + "'\n");
|
||||
fs::permissions(tool, fs::perms::owner_read | fs::perms::owner_write | fs::perms::owner_exec);
|
||||
const auto database = f.external / "selected.json";
|
||||
f.compdb(f.one, database, 1, tool.native());
|
||||
Workspace::SettingsOverrides flags;
|
||||
flags.compdb_path = database;
|
||||
flags.tool_approvals = {{f.one, Workspace::AuthorityLevel::compiler_use, tool}};
|
||||
vls::WorkspaceSession session(
|
||||
{.root = f.one, .cli_settings = Workspace::settings_from_cli(flags, f.base)});
|
||||
auto settings = object({{"provider", str("compdb")},
|
||||
{"compdbPath", Json{database.native()}},
|
||||
{"allowExplicitBuildActions", Json{true}}});
|
||||
require(session.initialize(initialize({folder(f.one), folder(f.two)}, settings)).has_value());
|
||||
expect(read_string(status(session, query(f.one)), "state") == "ready");
|
||||
const auto denied = status(session, query(f.two));
|
||||
expect(read_string(denied, "state") == "degraded" && issue(denied) == "outside_scope");
|
||||
expect(!fs::exists(marker));
|
||||
}
|
||||
|
||||
VOID_TEST(ProviderSession, launcher_anchors_survive_configuration_and_root_readdition) {
|
||||
Fixture f;
|
||||
const auto database = f.external / "chosen.json";
|
||||
f.compdb(f.one, database);
|
||||
Workspace::SettingsOverrides flags{.provider = Workspace::ProviderPreference::compdb,
|
||||
.compdb_path = database};
|
||||
vls::WorkspaceSession session(
|
||||
{.root = f.one, .cli_settings = Workspace::settings_from_cli(flags, f.base)});
|
||||
require(session.initialize(initialize({folder(f.one)})).has_value());
|
||||
const auto initial = status(session);
|
||||
auto replacement = database.parent_path() / "replacement.json";
|
||||
f.compdb(f.one, replacement, 2);
|
||||
fs::rename(replacement, database);
|
||||
const auto good = status(session);
|
||||
expect(read_string(good, "generation") != read_string(initial, "generation"));
|
||||
|
||||
// The next launcher receives exactly this directory, which will be replaced before init.
|
||||
vls::WorkspaceSession before_init(
|
||||
{.root = f.one, .cli_settings = Workspace::settings_from_cli(flags, f.base)});
|
||||
fs::rename(f.external, f.base / "retired-external");
|
||||
f.compdb(f.one, database, 3);
|
||||
auto config = configuration({{"selectedProfile", str("debug")}});
|
||||
require(session.configure(&config).has_value());
|
||||
const auto replaced = status(session);
|
||||
expect(read_string(replaced, "state") == "stale" && !field(replaced, "generation"));
|
||||
expect(read_string(nested(replaced, "lastGood"), "generation") ==
|
||||
read_string(good, "generation"));
|
||||
auto reincarnate = change({folder(f.one)}, {folder(f.one)});
|
||||
require(session.update_folders(&reincarnate).has_value());
|
||||
const auto readded = status(session);
|
||||
expect(read_string(readded, "state") == "stale" && issue(readded) == "changed");
|
||||
expect(read_string(readded, "incarnation") != read_string(good, "incarnation"));
|
||||
expect(!field(readded, "lastGood") && !field(readded, "generation"));
|
||||
require(before_init.initialize(initialize({folder(f.one)})).has_value());
|
||||
const auto initially_replaced = status(before_init);
|
||||
expect(read_string(initially_replaced, "state") == "stale" &&
|
||||
issue(initially_replaced) == "changed");
|
||||
expect(!field(initially_replaced, "generation") && !field(initially_replaced, "lastGood"));
|
||||
}
|
||||
|
||||
VOID_TEST(ProviderSession, selector_appearance_invalidates_successful_fallback) {
|
||||
Fixture f;
|
||||
f.compdb(f.one, f.one / "compile_commands.json");
|
||||
PauseObservation gate;
|
||||
vls::WorkspaceSession session({}, [&] { gate.hook(); });
|
||||
require(session.initialize(initialize({folder(f.one)})).has_value());
|
||||
const auto discarded = gate.run(session, [&] { f.native(f.one, f.one / "native"); });
|
||||
expect(read_string(discarded, "state") == "stale" && issue(discarded) == "inputs_changed");
|
||||
expect(!field(discarded, "generation") && !field(discarded, "lastGood"));
|
||||
const auto ready = status(session);
|
||||
expect(read_string(ready, "provider") == "vbs" && read_string(ready, "state") == "ready");
|
||||
}
|
||||
|
||||
VOID_TEST(ProviderSession, appearing_native_status_and_replaced_db_invalidate_old_reads) {
|
||||
Fixture f;
|
||||
auto build = f.one / "native";
|
||||
auto database = f.native(f.one, build);
|
||||
const auto profile_status = build / "profiles/debug/editor/status.json";
|
||||
fs::rename(profile_status, f.base / "saved.json");
|
||||
PauseObservation gate;
|
||||
vls::WorkspaceSession session({}, [&] { gate.hook(); });
|
||||
require(session.initialize(initialize({folder(f.one)})).has_value());
|
||||
auto stale = gate.run(session, [&] { fs::rename(f.base / "saved.json", profile_status); });
|
||||
expect(issue(stale) == "inputs_changed");
|
||||
const auto ready = status(session);
|
||||
expect(read_string(ready, "state") == "ready");
|
||||
stale = gate.run(session, [&] { write(database, "invalid"); });
|
||||
expect(issue(stale) == "inputs_changed" && !field(stale, "generation"));
|
||||
expect(read_string(nested(stale, "lastGood"), "generation") ==
|
||||
read_string(ready, "generation"));
|
||||
}
|
||||
|
||||
VOID_TEST(ProviderSession, changing_the_queried_alias_invalidates_an_inflight_selection) {
|
||||
Fixture f;
|
||||
f.compdb(f.one, f.one / "compile_commands.json");
|
||||
const auto alias = f.one / "alias.cpp";
|
||||
write(f.one / "other.cpp", "int other;\n");
|
||||
fs::create_symlink("main.cpp", alias);
|
||||
PauseObservation gate;
|
||||
vls::WorkspaceSession session({}, [&] { gate.hook(); });
|
||||
require(session.initialize(initialize({folder(f.one)})).has_value());
|
||||
const auto params = query(f.one, alias);
|
||||
const auto initial = status(session, params);
|
||||
expect(read_string(nested(initial, "selected"), "owningTu") ==
|
||||
Docs::path_to_file_uri(f.one / "main.cpp"));
|
||||
const auto stale = gate.run(
|
||||
session,
|
||||
[&] {
|
||||
fs::remove(alias);
|
||||
fs::create_symlink("other.cpp", alias);
|
||||
},
|
||||
params);
|
||||
expect(issue(stale) == "inputs_changed" && !field(stale, "generation"));
|
||||
expect(
|
||||
std::holds_alternative<std::nullptr_t>(nested(status(session, params), "selected").value));
|
||||
}
|
||||
|
||||
VOID_TEST(ProviderSession, newer_success_and_failure_displace_older_observations) {
|
||||
Fixture f;
|
||||
const auto database = f.one / "compile_commands.json";
|
||||
f.compdb(f.one, database);
|
||||
PauseObservation gate;
|
||||
vls::WorkspaceSession session({}, [&] { gate.hook(); });
|
||||
require(session.initialize(initialize({folder(f.one)})).has_value());
|
||||
const auto first = status(session);
|
||||
// Both snapshots are good and use the same file identities. Sequence alone displaces the first.
|
||||
auto stale =
|
||||
gate.run(session, [&] { expect(read_string(status(session), "state") == "ready"); });
|
||||
expect(issue(stale) == "superseded");
|
||||
|
||||
f.compdb(f.one, database, 2);
|
||||
stale = gate.run(session, [&] {
|
||||
write(database, "invalid");
|
||||
expect(read_string(status(session), "state") == "degraded");
|
||||
});
|
||||
expect(issue(stale) == "superseded");
|
||||
expect(read_string(nested(status(session), "lastGood"), "generation") ==
|
||||
read_string(first, "generation"));
|
||||
|
||||
stale = gate.run(session, [&] {
|
||||
f.compdb(f.one, database, 3);
|
||||
expect(read_string(status(session), "state") == "ready");
|
||||
});
|
||||
expect(issue(stale) == "superseded");
|
||||
const auto last = status(session);
|
||||
write(database, "invalid");
|
||||
expect(read_string(nested(status(session), "lastGood"), "generation") ==
|
||||
read_string(last, "generation"));
|
||||
}
|
||||
|
||||
VOID_TEST(ProviderSession, configuration_revocation_and_incarnation_reject_late_work) {
|
||||
Fixture f;
|
||||
f.compdb(f.one, f.one / "compile_commands.json");
|
||||
f.compdb(f.one, f.one / "different.json", 2);
|
||||
Workspace::SettingsOverrides flags;
|
||||
flags.tool_approvals = {
|
||||
{f.one, Workspace::AuthorityLevel::compiler_use, f.one / "marker-tool"}};
|
||||
PauseObservation gate;
|
||||
vls::WorkspaceSession session(
|
||||
{.root = f.one, .cli_settings = Workspace::settings_from_cli(flags, f.base)},
|
||||
[&] { gate.hook(); });
|
||||
require(session.initialize(initialize({folder(f.one)})).has_value());
|
||||
|
||||
auto stale = gate.run(session, [&] {
|
||||
auto config = configuration({{"compdbPath", str("different.json")}});
|
||||
require(session.configure(&config).has_value());
|
||||
});
|
||||
expect(issue(stale) == "superseded" && !field(stale, "lastGood"));
|
||||
const auto ready = status(session);
|
||||
expect(Protocol::as_int64(field(ready, "contextCount")) == 2);
|
||||
|
||||
stale = gate.run(session, [&] { session.revoke_root_authority(f.one); });
|
||||
expect(issue(stale) == "superseded" && !field(stale, "generation"));
|
||||
|
||||
std::string new_incarnation;
|
||||
stale = gate.run(session, [&] {
|
||||
auto removed = change({}, {folder(f.one)});
|
||||
require(session.update_folders(&removed).has_value());
|
||||
expect(read_string(status(session), "state") == "documentOnly");
|
||||
auto added = change({folder(f.one)}, {});
|
||||
require(session.update_folders(&added).has_value());
|
||||
new_incarnation = read_string(status(session), "incarnation");
|
||||
});
|
||||
expect(issue(stale) == "superseded" && !field(stale, "lastGood"));
|
||||
expect(read_string(stale, "incarnation") == read_string(ready, "incarnation"));
|
||||
expect(read_string(stale, "incarnation") != new_incarnation);
|
||||
expect(read_string(status(session), "incarnation") == new_incarnation);
|
||||
}
|
||||
@@ -0,0 +1,589 @@
|
||||
#include <vls/WorkspaceSession.hpp>
|
||||
|
||||
#include <Void/LanguageServer/Documents/Uri.hpp>
|
||||
#include <Void/System/TempDir.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <future>
|
||||
#include <semaphore>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
namespace fs = std::filesystem;
|
||||
namespace Build = Void::LanguageServer::Build;
|
||||
namespace Docs = Void::LanguageServer::Documents;
|
||||
namespace Protocol = Void::LanguageServer::Protocol;
|
||||
namespace Workspace = Void::LanguageServer::Workspace;
|
||||
using Protocol::Json;
|
||||
using vls::SemanticContextIssue;
|
||||
using vls::SemanticContextLease;
|
||||
using vls::SemanticDriver;
|
||||
using vls::WorkspaceSession;
|
||||
using Void::Testing::expect;
|
||||
using Void::Testing::require;
|
||||
using Strings = std::vector<std::string>;
|
||||
using namespace std::chrono_literals;
|
||||
using namespace std::string_view_literals;
|
||||
|
||||
template <typename T, typename E> T take(std::expected<T, E> result) {
|
||||
require(result.has_value());
|
||||
return std::move(*result);
|
||||
}
|
||||
|
||||
void write_file(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());
|
||||
}
|
||||
|
||||
void write_json(const fs::path &path, const Json &json) {
|
||||
write_file(path, take(Protocol::serialize_json(json)));
|
||||
}
|
||||
|
||||
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 text(const Json &json, std::string_view key) {
|
||||
const auto *value = Protocol::as_string(&field(json, key));
|
||||
require(value != nullptr);
|
||||
return *value;
|
||||
}
|
||||
|
||||
Json object(Json::Object fields) { return Json{std::move(fields)}; }
|
||||
Json str(std::string_view value) { return Json{std::string{value}}; }
|
||||
Json folder(const fs::path &root) { return object({{"uri", str(Docs::path_to_file_uri(root))}}); }
|
||||
|
||||
void initialize(WorkspaceSession &session, const fs::path &root, Json settings = object({})) {
|
||||
auto params =
|
||||
object({{"workspaceFolders", Json{Json::Array{folder(root)}}},
|
||||
{"initializationOptions", object({{"voidLanguageServer", std::move(settings)}})}});
|
||||
require(session.initialize(params).has_value());
|
||||
}
|
||||
|
||||
void update(WorkspaceSession &session, Json::Array add, Json::Array remove) {
|
||||
auto event = object({{"added", Json{std::move(add)}}, {"removed", Json{std::move(remove)}}});
|
||||
auto params = object({{"event", std::move(event)}});
|
||||
require(session.update_folders(¶ms).has_value());
|
||||
}
|
||||
|
||||
Json status(WorkspaceSession &session, const fs::path &root, const fs::path &file) {
|
||||
const auto params = object(
|
||||
{{"workspaceUri", str(Docs::path_to_file_uri(root))}, {"textDocument", folder(file)}});
|
||||
return take(session.provider_status(¶ms));
|
||||
}
|
||||
|
||||
auto acquire(WorkspaceSession &session, const fs::path &file, const SemanticDriver &driver,
|
||||
const fs::path &workspace = {}) {
|
||||
const auto uri = Docs::path_to_file_uri(workspace);
|
||||
return session.acquire_semantic_context(
|
||||
Docs::path_to_file_uri(file),
|
||||
workspace.empty() ? std::nullopt : std::optional<std::string_view>{uri}, driver);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void fails(const std::expected<T, vls::SemanticContextError> &result, SemanticContextIssue issue) {
|
||||
require(!result.has_value());
|
||||
expect(result.error().issue == issue);
|
||||
expect(!result.error().message.empty());
|
||||
}
|
||||
|
||||
struct Gate {
|
||||
std::atomic_bool armed{};
|
||||
std::binary_semaphore entered{0}, resume{0};
|
||||
|
||||
void hook() {
|
||||
if (armed.exchange(false)) {
|
||||
entered.release();
|
||||
resume.acquire();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Operation, typename Mutation>
|
||||
auto during(Operation operation, Mutation mutation) {
|
||||
armed = true;
|
||||
auto pending = std::async(std::launch::async, std::move(operation));
|
||||
{
|
||||
struct Release {
|
||||
std::binary_semaphore &semaphore;
|
||||
~Release() { semaphore.release(); }
|
||||
} release{resume};
|
||||
require(entered.try_acquire_for(5s));
|
||||
mutation();
|
||||
}
|
||||
return pending.get();
|
||||
}
|
||||
};
|
||||
|
||||
struct Fixture {
|
||||
Void::FileSystem::TempDir temporary{"vls_semantic_lease_"};
|
||||
fs::path base = fs::canonical(temporary.path()), root = base / "workspace";
|
||||
fs::path a = root / "src/a.cpp", b = root / "src/b.cpp";
|
||||
fs::path database = root / "compile_commands.json",
|
||||
selector = root / ".vbs/editor_selection.json";
|
||||
SemanticDriver gcc{base / "g++", Workspace::CompilerDriver::gcc};
|
||||
SemanticDriver clang{base / "clang++", Workspace::CompilerDriver::clang};
|
||||
fs::path marker = base / "executed";
|
||||
|
||||
Fixture() {
|
||||
write_file(a, "int a;\n");
|
||||
write_file(b, "int b;\n");
|
||||
executable(gcc.executable, "first");
|
||||
executable(clang.executable, "second");
|
||||
}
|
||||
|
||||
void executable(const fs::path &path, std::string_view label) const {
|
||||
write_file(path,
|
||||
"#!/bin/sh\n# " + std::string{label} + "\ntouch '" + marker.native() + "'\n");
|
||||
fs::permissions(path, fs::perms::owner_all);
|
||||
}
|
||||
|
||||
vls::WorkspaceLaunch launch(bool authorized = true) const {
|
||||
Workspace::SettingsOverrides settings;
|
||||
if (authorized)
|
||||
settings.tool_approvals = {
|
||||
{root, Workspace::AuthorityLevel::compiler_use, gcc.executable},
|
||||
{root, Workspace::AuthorityLevel::compiler_use, clang.executable}};
|
||||
return {.root = root,
|
||||
.cli_settings = Workspace::settings_from_cli(std::move(settings), base)};
|
||||
}
|
||||
|
||||
Json row(const fs::path &file, const SemanticDriver &driver, Strings flags = {}) const {
|
||||
Json::Array argv{str(driver.executable.native())};
|
||||
for (const auto &flag : flags)
|
||||
argv.push_back(str(flag));
|
||||
argv.push_back(str("-c"));
|
||||
const auto relative = file.lexically_relative(root).native();
|
||||
argv.push_back(str(relative));
|
||||
return object({{"file", str(relative)},
|
||||
{"directory", str(root.native())},
|
||||
{"arguments", Json{std::move(argv)}}});
|
||||
}
|
||||
|
||||
fs::path native_database() const {
|
||||
return root /
|
||||
"out/profiles/debug/editor/generations/0123456789abcdef/compile_commands.json";
|
||||
}
|
||||
|
||||
void select_native(int ticket) const {
|
||||
write_json(selector, object({{"schema_version", Json{std::int64_t{1}}},
|
||||
{"ticket", Json{std::int64_t{ticket}}},
|
||||
{"selected_profile", str("debug")},
|
||||
{"selected_build_root", str((root / "out").native())},
|
||||
{"selected_generation_id", str("0123456789abcdef")},
|
||||
{"selected_compdb_path", str(native_database().native())}}));
|
||||
}
|
||||
|
||||
void native_status(std::string_view health) const {
|
||||
write_json(root / "out/profiles/debug/editor/status.json",
|
||||
object({{"schema_version", Json{std::int64_t{1}}},
|
||||
{"profile", str("debug")},
|
||||
{"status", str(health)},
|
||||
{"diagnostic", str("")},
|
||||
{"generation_id", str("0123456789abcdef")},
|
||||
{"compdb_path", str(native_database().native())},
|
||||
{"entry_count", Json{std::int64_t{2}}},
|
||||
{"readiness_warnings", Json{Json::Array{}}}}));
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
VOID_TEST(SemanticLease, checked_compdb_command_and_selection_survive_unchanged_status) {
|
||||
Fixture f;
|
||||
const auto command = "ccache " + f.gcc.executable.native() +
|
||||
" -DORDER=1 -freflection -freflection -o unit.o -c src/a.cpp";
|
||||
const auto first = object({{"directory", str(f.root.native())},
|
||||
{"file", str("src/a.cpp")},
|
||||
{"command", str(command)},
|
||||
{"output", str("unit.o")}});
|
||||
write_json(f.database, Json{Json::Array{first, f.row(f.b, f.gcc)}});
|
||||
WorkspaceSession session{f.launch()};
|
||||
initialize(session, f.root);
|
||||
const auto lease = take(acquire(session, f.a, f.gcc));
|
||||
const auto &selection = lease.selection();
|
||||
require(selection->selected != nullptr);
|
||||
const auto &context = *selection->selected;
|
||||
expect(selection->generation->identity().provider == "compdb");
|
||||
expect(selection->generation->contexts().size() == 2);
|
||||
expect(selection->scope->file == f.a && context.key.owning_tu == f.a);
|
||||
expect(lease.document_uri() == Docs::path_to_file_uri(f.a));
|
||||
expect(lease.selection_state().scope() == selection->scope);
|
||||
expect(context.working_directory == f.root && context.source_language == "c++");
|
||||
expect(context.original && context.original->command == command);
|
||||
expect(context.semantic_arguments == Strings{f.gcc.executable.native(), "-DORDER=1",
|
||||
"-freflection", "-freflection", "-c",
|
||||
f.a.native()});
|
||||
expect(!context.prerequisites && !context.standard_library);
|
||||
expect(lease.driver().tool.operation == Workspace::AuthorityLevel::compiler_use);
|
||||
expect(lease.driver().tool.identity.content_hash_hex.size() == 64);
|
||||
expect(lease.driver().tool.selection_origin.layer == Workspace::ConfigLayer::cli);
|
||||
expect(text(status(session, f.root, f.b), "state") == "ready");
|
||||
const auto again = take(acquire(session, f.a, f.gcc));
|
||||
expect(again.selection() == selection && &again.selection_state() == &lease.selection_state());
|
||||
const auto explicit_root = take(acquire(session, f.a, f.gcc, f.root));
|
||||
expect(explicit_root.selection() == selection &&
|
||||
&explicit_root.selection_state() == &lease.selection_state());
|
||||
expect(again.configuration_generation() == lease.configuration_generation());
|
||||
expect(session.validate_semantic_context(lease).has_value());
|
||||
expect(!fs::exists(f.marker));
|
||||
}
|
||||
|
||||
VOID_TEST(SemanticLease, native_ticket_and_stale_status_fence_the_immutable_row) {
|
||||
Fixture f;
|
||||
const auto rows = Json{Json::Array{f.row(f.a, f.gcc, {"-DNATIVE=7"}), f.row(f.b, f.gcc)}};
|
||||
write_json(f.native_database(), rows);
|
||||
f.native_status("valid");
|
||||
f.select_native(7);
|
||||
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc, {"-DFALLBACK"})}});
|
||||
WorkspaceSession session{f.launch()};
|
||||
initialize(session, f.root);
|
||||
const auto first = take(acquire(session, f.a, f.gcc));
|
||||
expect(first.selection()->generation->contexts().size() == 2);
|
||||
expect(first.selection()->generation->identity().provider == "vbs");
|
||||
expect(first.selection()->selected->original->metadata_file == f.native_database());
|
||||
expect(std::ranges::contains(*first.selection()->selected->semantic_arguments, "-DNATIVE=7"sv));
|
||||
f.select_native(8);
|
||||
const auto next = take(acquire(session, f.a, f.gcc));
|
||||
expect(first.selection()->generation->identity().revision ==
|
||||
next.selection()->generation->identity().revision);
|
||||
expect(first.selection() != next.selection());
|
||||
fails(session.validate_semantic_context(first), SemanticContextIssue::superseded);
|
||||
f.native_status("stale");
|
||||
expect(text(status(session, f.root, f.a), "state") == "stale");
|
||||
fails(acquire(session, f.a, f.gcc), SemanticContextIssue::unavailable);
|
||||
fails(session.validate_semantic_context(next), SemanticContextIssue::superseded);
|
||||
f.native_status("valid");
|
||||
expect(acquire(session, f.a, f.gcc).has_value());
|
||||
expect(!fs::exists(f.marker));
|
||||
}
|
||||
|
||||
VOID_TEST(SemanticLease, passive_status_does_not_pin_and_workspace_settings_cannot_grant) {
|
||||
Fixture f;
|
||||
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc)}});
|
||||
WorkspaceSession session{f.launch()};
|
||||
initialize(session, f.root);
|
||||
expect(text(status(session, f.root, f.a), "state") == "ready");
|
||||
const auto replacement = f.base / "new-driver";
|
||||
f.executable(replacement, "selected after passive status");
|
||||
fs::rename(replacement, f.gcc.executable);
|
||||
expect(acquire(session, f.a, f.gcc).has_value());
|
||||
fails(acquire(session, f.a, f.clang), SemanticContextIssue::wrong_command);
|
||||
fails(acquire(session, f.a, {f.gcc.executable, Workspace::CompilerDriver::clang}),
|
||||
SemanticContextIssue::wrong_command);
|
||||
auto settings =
|
||||
object({{"toolApprovals",
|
||||
Json{Json::Array{object({{"root", str(f.root.native())},
|
||||
{"operation", str("compilerUse")},
|
||||
{"executable", str(f.gcc.executable.native())}})}}}});
|
||||
WorkspaceSession unapproved{f.launch(false)};
|
||||
initialize(unapproved, f.root, settings);
|
||||
expect(text(status(unapproved, f.root, f.a), "state") == "ready");
|
||||
fails(acquire(unapproved, f.a, f.gcc), SemanticContextIssue::unavailable);
|
||||
WorkspaceSession passive;
|
||||
initialize(passive, f.root);
|
||||
fails(acquire(passive, f.a, f.gcc), SemanticContextIssue::disabled);
|
||||
const auto other = f.base / "other";
|
||||
fs::create_directory(other);
|
||||
update(session, {folder(other)}, {});
|
||||
fails(acquire(session, other / "a.cpp", f.gcc), SemanticContextIssue::disabled);
|
||||
expect(!fs::exists(f.marker));
|
||||
}
|
||||
|
||||
VOID_TEST(SemanticLease, selection_precedes_checked_driver_admission) {
|
||||
Fixture f;
|
||||
write_json(f.database,
|
||||
Json{Json::Array{f.row(f.a, f.clang, {"-DCLANG"}), f.row(f.a, f.gcc, {"-DGCC"})}});
|
||||
WorkspaceSession session{f.launch()};
|
||||
initialize(session, f.root);
|
||||
const auto passive_key = text(field(status(session, f.root, f.a), "selected"), "alternative");
|
||||
const auto gcc = acquire(session, f.a, f.gcc);
|
||||
const auto clang = acquire(session, f.a, f.clang);
|
||||
require(gcc.has_value() != clang.has_value());
|
||||
const auto &selected = (gcc ? *gcc : *clang).selection();
|
||||
fails(gcc ? clang : gcc, SemanticContextIssue::wrong_command);
|
||||
expect(selected->alternatives().size() == 2);
|
||||
expect(selected->selected->key.alternative == passive_key);
|
||||
expect(std::ranges::contains(*selected->selected->semantic_arguments,
|
||||
gcc ? "-DGCC"sv : "-DCLANG"sv));
|
||||
}
|
||||
|
||||
VOID_TEST(SemanticLease, identical_database_replacement_requires_a_new_capture) {
|
||||
Fixture f;
|
||||
const auto rows = Json{Json::Array{f.row(f.a, f.gcc)}};
|
||||
write_json(f.database, rows);
|
||||
WorkspaceSession session{f.launch()};
|
||||
initialize(session, f.root);
|
||||
const auto original = take(acquire(session, f.a, f.gcc));
|
||||
const auto old_file = f.root / "first.json";
|
||||
fs::rename(f.database, old_file);
|
||||
write_json(f.database, rows);
|
||||
const auto replacement = take(acquire(session, f.a, f.gcc));
|
||||
expect(replacement.selection() != original.selection());
|
||||
expect(replacement.selection()->generation->identity().revision ==
|
||||
original.selection()->generation->identity().revision);
|
||||
expect(session.validate_semantic_context(replacement).has_value());
|
||||
fails(session.validate_semantic_context(original), SemanticContextIssue::superseded);
|
||||
fs::rename(old_file, f.database);
|
||||
fails(session.validate_semantic_context(replacement), SemanticContextIssue::superseded);
|
||||
fails(session.validate_semantic_context(original), SemanticContextIssue::superseded);
|
||||
expect(acquire(session, f.a, f.gcc).has_value());
|
||||
}
|
||||
|
||||
VOID_TEST(SemanticLease, observed_native_precedence_cannot_restore_an_old_fallback_lease) {
|
||||
Fixture f;
|
||||
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc)}});
|
||||
WorkspaceSession session{f.launch()};
|
||||
initialize(session, f.root);
|
||||
const auto original = take(acquire(session, f.a, f.gcc));
|
||||
write_file(f.selector, "{");
|
||||
const auto invalid = status(session, f.root, f.a);
|
||||
expect(text(invalid, "provider") == "vbs" && text(invalid, "state") == "degraded");
|
||||
fs::remove(f.selector);
|
||||
// The original database, TU, driver and selector absence all match again.
|
||||
fails(session.validate_semantic_context(original), SemanticContextIssue::superseded);
|
||||
const auto fresh = take(acquire(session, f.a, f.gcc));
|
||||
expect(fresh.selection() != original.selection());
|
||||
expect(session.validate_semantic_context(fresh).has_value());
|
||||
}
|
||||
|
||||
VOID_TEST(SemanticLease, failed_final_status_check_permanently_expires_a_fallback_lease) {
|
||||
Fixture f;
|
||||
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc)}});
|
||||
Gate gate;
|
||||
WorkspaceSession session{f.launch(), [&] { gate.hook(); }};
|
||||
initialize(session, f.root);
|
||||
const auto fallback = take(acquire(session, f.a, f.gcc));
|
||||
const auto discarded = gate.during([&] { return status(session, f.root, f.b); },
|
||||
[&] { write_file(f.selector, "{"); });
|
||||
expect(text(discarded, "state") == "stale");
|
||||
fs::remove(f.selector);
|
||||
fails(session.validate_semantic_context(fallback), SemanticContextIssue::superseded);
|
||||
expect(acquire(session, f.a, f.gcc).has_value());
|
||||
}
|
||||
|
||||
VOID_TEST(SemanticLease, disproved_selector_absence_retires_both_checked_driver_imports) {
|
||||
Fixture f;
|
||||
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc), f.row(f.b, f.clang)}});
|
||||
WorkspaceSession session{f.launch()};
|
||||
initialize(session, f.root);
|
||||
const auto a = take(acquire(session, f.a, f.gcc));
|
||||
const auto b = take(acquire(session, f.b, f.clang));
|
||||
write_file(f.selector, "{");
|
||||
fails(session.validate_semantic_context(a), SemanticContextIssue::superseded);
|
||||
fs::remove(f.selector);
|
||||
fails(session.validate_semantic_context(b), SemanticContextIssue::superseded);
|
||||
expect(acquire(session, f.b, f.clang).has_value());
|
||||
}
|
||||
|
||||
VOID_TEST(SemanticLease, changed_pin_revokes_old_work_and_preserves_the_other_approved_driver) {
|
||||
Fixture f;
|
||||
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc), f.row(f.b, f.clang)}});
|
||||
WorkspaceSession session{f.launch()};
|
||||
initialize(session, f.root);
|
||||
const auto a = take(acquire(session, f.a, f.gcc));
|
||||
const auto b = take(acquire(session, f.b, f.clang));
|
||||
expect(a.driver().tool.trust_generation == b.driver().tool.trust_generation);
|
||||
auto former = f.base / "former-driver";
|
||||
fs::rename(f.gcc.executable, former);
|
||||
f.executable(f.gcc.executable, "replacement");
|
||||
fails(session.validate_semantic_context(a), SemanticContextIssue::superseded);
|
||||
fails(session.validate_semantic_context(b), SemanticContextIssue::superseded);
|
||||
const auto recovered = take(acquire(session, f.b, f.clang));
|
||||
expect(recovered.driver().tool.trust_generation > b.driver().tool.trust_generation);
|
||||
expect(recovered.configuration_generation() == b.configuration_generation());
|
||||
expect(text(status(session, f.root, f.b), "state") == "ready");
|
||||
fs::rename(former, f.gcc.executable);
|
||||
fails(acquire(session, f.a, f.gcc), SemanticContextIssue::unavailable);
|
||||
expect(session.validate_semantic_context(recovered).has_value());
|
||||
expect(!fs::exists(f.marker));
|
||||
}
|
||||
|
||||
VOID_TEST(SemanticLease, nested_folder_fences_implicit_acquisition_and_validation_only) {
|
||||
Fixture f;
|
||||
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc)}});
|
||||
Gate gate;
|
||||
WorkspaceSession session{f.launch(), [&] { gate.hook(); }};
|
||||
initialize(session, f.root);
|
||||
const auto explicit_outer = take(acquire(session, f.a, f.gcc, f.root));
|
||||
const auto inner = folder(f.a.parent_path());
|
||||
auto late = gate.during([&] { return acquire(session, f.a, f.gcc); },
|
||||
[&] { update(session, {inner}, {}); });
|
||||
fails(late, SemanticContextIssue::superseded);
|
||||
fails(acquire(session, f.a, f.gcc), SemanticContextIssue::unavailable);
|
||||
expect(session.validate_semantic_context(explicit_outer).has_value());
|
||||
update(session, {}, {inner});
|
||||
const auto implicit = take(acquire(session, f.a, f.gcc));
|
||||
auto stale = gate.during([&] { return session.validate_semantic_context(implicit); },
|
||||
[&] {
|
||||
update(session, {inner}, {});
|
||||
update(session, {}, {inner});
|
||||
});
|
||||
fails(stale, SemanticContextIssue::superseded);
|
||||
expect(session.validate_semantic_context(explicit_outer).has_value());
|
||||
fails(session.validate_semantic_context(implicit), SemanticContextIssue::superseded);
|
||||
expect(acquire(session, f.a, f.gcc).has_value());
|
||||
}
|
||||
|
||||
VOID_TEST(SemanticLease, independent_cold_document_observations_and_status_can_complete) {
|
||||
Fixture f;
|
||||
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc), f.row(f.b, f.gcc)}});
|
||||
Gate gate;
|
||||
WorkspaceSession session{f.launch(), [&] { gate.hook(); }};
|
||||
initialize(session, f.root);
|
||||
std::optional<SemanticContextLease> b;
|
||||
const auto a =
|
||||
take(gate.during([&] { return acquire(session, f.a, f.gcc); },
|
||||
[&] {
|
||||
b = take(acquire(session, f.b, f.gcc));
|
||||
expect(text(status(session, f.root, f.b), "state") == "ready");
|
||||
}));
|
||||
require(b.has_value());
|
||||
expect(a.selection()->selected->key.owning_tu == f.a);
|
||||
expect(b->selection()->selected->key.owning_tu == f.b);
|
||||
expect(session.validate_semantic_context(a).has_value());
|
||||
expect(session.validate_semantic_context(*b).has_value());
|
||||
expect(take(acquire(session, f.a, f.gcc)).selection() == a.selection());
|
||||
}
|
||||
|
||||
VOID_TEST(SemanticLease, newest_document_request_fences_older_success_and_failure) {
|
||||
Fixture f;
|
||||
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc)}});
|
||||
Gate gate;
|
||||
WorkspaceSession session{f.launch(), [&] { gate.hook(); }};
|
||||
initialize(session, f.root);
|
||||
std::optional<SemanticContextLease> accepted;
|
||||
const auto late_failure = gate.during([&] { return acquire(session, f.a, f.clang); },
|
||||
[&] { accepted = take(acquire(session, f.a, f.gcc)); });
|
||||
fails(late_failure, SemanticContextIssue::superseded);
|
||||
require(accepted.has_value());
|
||||
expect(session.validate_semantic_context(*accepted).has_value());
|
||||
const auto late_success = gate.during(
|
||||
[&] { return acquire(session, f.a, f.gcc); },
|
||||
[&] { fails(acquire(session, f.a, f.clang), SemanticContextIssue::wrong_command); });
|
||||
fails(late_success, SemanticContextIssue::superseded);
|
||||
fails(session.validate_semantic_context(*accepted), SemanticContextIssue::superseded);
|
||||
}
|
||||
|
||||
VOID_TEST(SemanticLease, explicit_revocation_between_observation_and_installation) {
|
||||
Fixture f;
|
||||
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc), f.row(f.b, f.gcc)}});
|
||||
Gate gate;
|
||||
WorkspaceSession session{f.launch(), [&] { gate.hook(); }};
|
||||
initialize(session, f.root);
|
||||
const auto accepted = take(acquire(session, f.a, f.gcc));
|
||||
const auto late = gate.during([&] { return acquire(session, f.b, f.gcc); },
|
||||
[&] { session.revoke_root_authority(f.root); });
|
||||
fails(late, SemanticContextIssue::superseded);
|
||||
fails(session.validate_semantic_context(accepted), SemanticContextIssue::superseded);
|
||||
fails(acquire(session, f.b, f.gcc), SemanticContextIssue::unavailable);
|
||||
expect(text(status(session, f.root, f.a), "state") == "ready");
|
||||
}
|
||||
|
||||
VOID_TEST(SemanticLease, superseded_native_failure_cannot_retire_a_newer_fallback_selection) {
|
||||
Fixture f;
|
||||
const auto rows = Json{Json::Array{f.row(f.a, f.gcc), f.row(f.b, f.clang)}};
|
||||
write_json(f.database, rows);
|
||||
write_json(f.native_database(), rows);
|
||||
f.native_status("valid");
|
||||
Gate gate;
|
||||
WorkspaceSession session{f.launch(), [&] { gate.hook(); }};
|
||||
initialize(session, f.root);
|
||||
auto latest = take(acquire(session, f.a, f.gcc));
|
||||
f.select_native(9);
|
||||
auto stale = gate.during([&] { return acquire(session, f.a, f.clang); },
|
||||
[&] {
|
||||
fs::remove(f.selector);
|
||||
latest = take(acquire(session, f.a, f.gcc));
|
||||
});
|
||||
fails(stale, SemanticContextIssue::superseded);
|
||||
expect(session.validate_semantic_context(latest).has_value());
|
||||
}
|
||||
|
||||
VOID_TEST(SemanticLease, negative_response_lookup_and_editor_alias_retarget_expire_leases) {
|
||||
Fixture f;
|
||||
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc), f.row(f.b, f.gcc, {"@later.rsp"})}});
|
||||
const auto alias = f.root / "alias.cpp";
|
||||
fs::create_symlink("src/a.cpp", alias);
|
||||
WorkspaceSession session{f.launch()};
|
||||
initialize(session, f.root);
|
||||
const auto a = take(acquire(session, alias, f.gcc));
|
||||
expect(a.selection()->scope->file == f.a);
|
||||
fails(acquire(session, f.b, f.gcc), SemanticContextIssue::wrong_command);
|
||||
write_file(f.root / "later.rsp", "-DRESPONSE");
|
||||
fails(session.validate_semantic_context(a), SemanticContextIssue::superseded);
|
||||
const auto b = take(acquire(session, f.b, f.gcc));
|
||||
expect(std::ranges::contains(*b.selection()->selected->semantic_arguments, "-DRESPONSE"sv));
|
||||
const auto alias_a = take(acquire(session, alias, f.gcc));
|
||||
const auto saved = f.root / "alias-saved.cpp";
|
||||
fs::rename(alias, saved);
|
||||
fs::create_symlink("src/b.cpp", alias);
|
||||
fails(session.validate_semantic_context(alias_a), SemanticContextIssue::superseded);
|
||||
const auto alias_b = take(acquire(session, alias, f.gcc));
|
||||
expect(alias_b.selection()->scope->file == f.b &&
|
||||
session.validate_semantic_context(b).has_value());
|
||||
fs::rename(saved, alias);
|
||||
fails(session.validate_semantic_context(alias_b), SemanticContextIssue::superseded);
|
||||
fails(session.validate_semantic_context(alias_a), SemanticContextIssue::superseded);
|
||||
}
|
||||
|
||||
VOID_TEST(SemanticLease, settings_and_root_incarnation_are_stable_only_for_their_lifetimes) {
|
||||
Fixture f;
|
||||
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc)}});
|
||||
Gate gate;
|
||||
WorkspaceSession session{f.launch(), [&] { gate.hook(); }};
|
||||
initialize(session, f.root);
|
||||
const auto first = take(acquire(session, f.a, f.gcc));
|
||||
auto config =
|
||||
object({{"settings",
|
||||
object({{"voidLanguageServer", object({{"selectedProfile", str("debug")}})}})}});
|
||||
const auto late = gate.during([&] { return acquire(session, f.a, f.gcc); },
|
||||
[&] { require(session.configure(&config).has_value()); });
|
||||
fails(late, SemanticContextIssue::superseded);
|
||||
fails(session.validate_semantic_context(first), SemanticContextIssue::superseded);
|
||||
const auto second = take(acquire(session, f.a, f.gcc));
|
||||
expect(second.configuration_generation() > first.configuration_generation());
|
||||
require(session.configure(&config).has_value());
|
||||
expect(take(acquire(session, f.a, f.gcc)).selection() == second.selection());
|
||||
const auto old_incarnation = second.selection()->scope->workspace.session;
|
||||
const auto removed = gate.during([&] { return session.validate_semantic_context(second); },
|
||||
[&] { update(session, {folder(f.root)}, {folder(f.root)}); });
|
||||
fails(removed, SemanticContextIssue::superseded);
|
||||
expect(text(status(session, f.root, f.a), "incarnation") != old_incarnation);
|
||||
fails(acquire(session, f.a, f.gcc), SemanticContextIssue::unavailable);
|
||||
}
|
||||
|
||||
VOID_TEST(SemanticLease, cache_eviction_and_session_shutdown_leave_immutable_inputs_readable) {
|
||||
Fixture f;
|
||||
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc)}});
|
||||
std::optional<SemanticContextLease> retained;
|
||||
{
|
||||
WorkspaceSession session{f.launch()};
|
||||
initialize(session, f.root);
|
||||
retained = take(acquire(session, f.a, f.gcc));
|
||||
for (int i = 0; i < 32; ++i)
|
||||
fails(acquire(session, f.root / ("new-" + std::to_string(i) + ".cpp"), f.gcc),
|
||||
SemanticContextIssue::no_command);
|
||||
fails(session.validate_semantic_context(*retained), SemanticContextIssue::superseded);
|
||||
retained = take(acquire(session, f.a, f.gcc));
|
||||
WorkspaceSession other{f.launch()};
|
||||
initialize(other, f.root);
|
||||
fails(other.validate_semantic_context(*retained), SemanticContextIssue::superseded);
|
||||
expect(session.validate_semantic_context(*retained).has_value());
|
||||
}
|
||||
require(retained.has_value());
|
||||
expect(retained->selection()->selected->original->arguments->front() ==
|
||||
f.gcc.executable.native());
|
||||
expect(retained->selection_state().scope()->file == f.a);
|
||||
expect(!fs::exists(f.marker));
|
||||
}
|
||||
@@ -0,0 +1,611 @@
|
||||
#include <Void/LanguageServer/Workspace/Trust.hpp>
|
||||
|
||||
#include <Void/System/TempDir.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <barrier>
|
||||
#include <fstream>
|
||||
#include <future>
|
||||
#include <poll.h>
|
||||
#include <sys/inotify.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
namespace {
|
||||
using namespace Void::LanguageServer::Workspace;
|
||||
using Void::Testing::expect;
|
||||
using Void::Testing::require;
|
||||
using enum AuthorityLevel;
|
||||
namespace fs = std::filesystem;
|
||||
namespace Protocol = Void::LanguageServer::Protocol;
|
||||
|
||||
void write(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());
|
||||
}
|
||||
|
||||
void make_tool(const fs::path &path, std::string_view bytes = "abc") {
|
||||
write(path, bytes);
|
||||
fs::permissions(path, fs::perms::owner_read | fs::perms::owner_write | fs::perms::owner_exec);
|
||||
}
|
||||
|
||||
PartialWorkspaceSettings workspace(const fs::path &root, std::string_view json = "{}") {
|
||||
auto payload = Protocol::parse_json(json);
|
||||
require(payload.has_value());
|
||||
return parse_workspace_settings(*payload, root);
|
||||
}
|
||||
|
||||
MergedConfiguration selected(const fs::path &root, std::vector<ToolSelection> selections) {
|
||||
SettingsOverrides flags;
|
||||
flags.tool_approvals = std::move(selections);
|
||||
auto cli = settings_from_cli(std::move(flags), root);
|
||||
return merge_configuration(workspace(root), nullptr, &cli);
|
||||
}
|
||||
|
||||
bool diagnosed(const MergedConfiguration &merged, std::string_view key, ConfigIssue code) {
|
||||
return std::ranges::any_of(merged.diagnostics(),
|
||||
[&](const auto &d) { return d.key == key && d.issue == code; });
|
||||
}
|
||||
|
||||
template <typename T> bool refused(const std::expected<T, TrustError> &value, TrustError error) {
|
||||
return !value && value.error() == error;
|
||||
}
|
||||
|
||||
struct Fixture {
|
||||
Void::FileSystem::TempDir temp{"vls_workspace_"};
|
||||
fs::path root = temp.path() / "one", other = temp.path() / "one-more";
|
||||
fs::path tool = temp.path() / "g++";
|
||||
Fixture() {
|
||||
fs::create_directories(root / "out");
|
||||
fs::create_directories(other);
|
||||
make_tool(tool);
|
||||
}
|
||||
std::uint64_t install(TrustPolicy &policy, AuthorityLevel purpose) const {
|
||||
auto version = policy.replace_configuration(selected(root, {{root, purpose, tool}}));
|
||||
require(version.has_value());
|
||||
auto pin = policy.pin_approved_tool(root, purpose, tool);
|
||||
require(pin.has_value());
|
||||
return *version;
|
||||
}
|
||||
BuildInvocation action(std::uint64_t gen) const {
|
||||
return {root,
|
||||
tool,
|
||||
root / "out",
|
||||
{"build", "demo"},
|
||||
"provider:1/inputs:a",
|
||||
"environment:default",
|
||||
gen};
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
VOID_TEST(WorkspaceTests, precedence_origins_and_owning_bases) {
|
||||
Fixture f;
|
||||
write(f.temp.path() / "user.json", R"({"voidLanguageServer":{
|
||||
"provider":"compdb","compdbPath":"user-db","enableBackgroundIndexing":false,
|
||||
"toolApprovals":[{"root":"one","operation":"compilerUse","executable":"g++"},
|
||||
{"root":"one-more","operation":"metadataRefresh","executable":"g++"}]}})");
|
||||
auto user = read_user_settings(f.temp.path() / "user.json");
|
||||
require(user.has_value());
|
||||
expect(user->origin().layer == ConfigLayer::user_runtime &&
|
||||
user->origin().selected_file == f.temp.path() / "user.json");
|
||||
auto local = workspace(
|
||||
f.root,
|
||||
R"({"provider":"vbs","vbsManifestPath":"local/export.json","compdbPath":"local-db"})");
|
||||
SettingsOverrides flags;
|
||||
flags.provider = ProviderPreference::none;
|
||||
flags.selected_profile = "release";
|
||||
flags.vbs_manifest_path = "cli/export.json";
|
||||
auto cli = settings_from_cli(flags, f.other);
|
||||
auto lower = merge_configuration(local, &*user);
|
||||
expect(lower.effective().provider == ProviderPreference::compdb);
|
||||
expect(lower.effective().vbs_manifest_path == f.root / "local/export.json");
|
||||
auto merged = merge_configuration(local, &*user, &cli);
|
||||
const auto &s = merged.effective();
|
||||
expect(s.provider == ProviderPreference::none && !s.enable_background_indexing);
|
||||
expect(s.compdb_path == f.temp.path() / "user-db" &&
|
||||
s.vbs_manifest_path == f.other / "cli/export.json");
|
||||
expect(s.compdb_origin.layer == ConfigLayer::user_runtime &&
|
||||
s.compdb_origin.selected_file == f.temp.path() / "user.json");
|
||||
expect(s.vbs_manifest_origin.layer == ConfigLayer::cli &&
|
||||
s.vbs_manifest_origin.base == f.other);
|
||||
expect(merge_configuration(local).effective().compdb_origin.layer ==
|
||||
ConfigLayer::workspace_local);
|
||||
expect(s.selected_profile == "release");
|
||||
expect(s.tool_approvals_origin.layer == ConfigLayer::user_runtime);
|
||||
expect(s.tool_approvals_origin.selected_file == f.temp.path() / "user.json");
|
||||
require(s.tool_approvals.size() == 1);
|
||||
expect(s.tool_approvals[0] == ToolSelection{f.root, compiler_use, f.tool});
|
||||
TrustPolicy policy;
|
||||
require(policy.replace_configuration(merged).has_value());
|
||||
const auto observed = policy.pin_approved_tool(f.root, compiler_use, f.tool);
|
||||
require(observed.has_value());
|
||||
expect(observed->selection_origin.selected_file == s.tool_approvals_origin.selected_file);
|
||||
auto second = merge_configuration(workspace(f.other), &*user);
|
||||
require(second.effective().tool_approvals.size() == 1);
|
||||
expect(second.effective().tool_approvals[0] ==
|
||||
ToolSelection{f.other, trusted_metadata_refresh, f.tool});
|
||||
}
|
||||
|
||||
VOID_TEST(WorkspaceTests, workspace_cannot_relabel_or_grant_authority) {
|
||||
Fixture f;
|
||||
auto local = workspace(
|
||||
f.root, R"({"trustedRoots":["."],"approvedCompilers":["g++"],"approvedWrappers":["custom"],
|
||||
"allowMetadataRefresh":true,"allowExplicitBuildActions":true,"allowCompilerPlugins":true,
|
||||
"toolApprovals":[{"root":".","operation":"compilerUse","executable":"g++"}]})");
|
||||
auto merged = merge_configuration(local, &local, &local);
|
||||
for (auto key :
|
||||
{"trustedRoots", "approvedCompilers", "approvedWrappers", "allowMetadataRefresh",
|
||||
"allowExplicitBuildActions", "allowCompilerPlugins", "toolApprovals"})
|
||||
expect(diagnosed(merged, key, ConfigIssue::untrusted_setting));
|
||||
expect(diagnosed(merged, "", ConfigIssue::invalid_origin));
|
||||
expect(merged.effective().tool_approvals.empty());
|
||||
expect(!merged.effective().allow_metadata_refresh &&
|
||||
!merged.effective().allow_explicit_build_actions);
|
||||
TrustPolicy policy;
|
||||
require(policy.replace_configuration(merged).has_value());
|
||||
expect(refused(policy.pin_approved_tool(f.root, compiler_use, f.tool),
|
||||
TrustError::untrusted_root));
|
||||
write(f.temp.path() / "legacy.json",
|
||||
R"({"trustedRoots":["one"],"approvedCompilers":["g++"],"allowMetadataRefresh":true})");
|
||||
auto legacy = read_user_settings(f.temp.path() / "legacy.json");
|
||||
require(legacy.has_value());
|
||||
require(policy.replace_configuration(merge_configuration(local, &*legacy)).has_value());
|
||||
expect(refused(policy.pin_approved_tool(f.root, trusted_metadata_refresh, f.tool),
|
||||
TrustError::untrusted_root));
|
||||
}
|
||||
|
||||
VOID_TEST(WorkspaceTests, malformed_fields_and_resource_ceilings) {
|
||||
Fixture f;
|
||||
const auto bad =
|
||||
merge_configuration(workspace(f.root, R"({"provider":false,"vbsManifestPath":"",
|
||||
"compdbPath":2,"enableBackgroundIndexing":"yes","selectedProfile":null,"workerMemoryLimitMib":0,
|
||||
"maxSemanticWorkers":2.0,"maxResponseFileDepth":-1,"maxCompdbBytes":2147483649,
|
||||
"maxManifestBytes":"100","maxResponseFileBytes":null,"unknownSetting":1})"));
|
||||
for (auto key :
|
||||
{"provider", "vbsManifestPath", "compdbPath", "enableBackgroundIndexing",
|
||||
"selectedProfile", "workerMemoryLimitMib", "maxSemanticWorkers", "maxResponseFileDepth",
|
||||
"maxCompdbBytes", "maxManifestBytes", "maxResponseFileBytes"})
|
||||
expect(diagnosed(bad, key, ConfigIssue::invalid_value));
|
||||
expect(diagnosed(bad, "unknownSetting", ConfigIssue::unsupported));
|
||||
const auto local = workspace(f.root, R"({"maxSemanticWorkers":64,"workerMemoryLimitMib":65536,
|
||||
"maxResponseFileDepth":32,"maxResponseFileBytes":16777216,"maxCompdbBytes":1073741824,"maxManifestBytes":1024})");
|
||||
auto merged = merge_configuration(local);
|
||||
for (auto key : {"maxSemanticWorkers", "workerMemoryLimitMib", "maxResponseFileDepth",
|
||||
"maxResponseFileBytes", "maxCompdbBytes"})
|
||||
expect(diagnosed(merged, key, ConfigIssue::resource_limit));
|
||||
expect(merged.effective().limits.max_semantic_workers ==
|
||||
ResourceLimitsConfig{}.max_semantic_workers);
|
||||
expect(merged.effective().limits.max_manifest_bytes == 1024);
|
||||
SettingsOverrides flags;
|
||||
flags.max_semantic_workers = 8;
|
||||
flags.worker_memory_limit_mib = 512;
|
||||
flags.allow_compiler_plugins = true;
|
||||
auto cli = settings_from_cli(flags, f.root);
|
||||
auto runtime = merge_configuration(local, nullptr, &cli);
|
||||
expect(runtime.effective().limits.max_semantic_workers == 8 &&
|
||||
runtime.effective().limits.worker_memory_limit_mib == 512);
|
||||
expect(!runtime.effective().allow_compiler_plugins &&
|
||||
diagnosed(runtime, "allowCompilerPlugins", ConfigIssue::unsupported));
|
||||
auto nested =
|
||||
merge_configuration(workspace(f.root, R"({"voidLanguageServer":false,"provider":"none"})"));
|
||||
expect(diagnosed(nested, "", ConfigIssue::invalid_value) &&
|
||||
nested.effective().provider == ProviderPreference::auto_detect);
|
||||
expect(diagnosed(merge_configuration(workspace("relative")), "", ConfigIssue::invalid_origin));
|
||||
}
|
||||
|
||||
VOID_TEST(WorkspaceTests, trusted_replacements_are_all_or_nothing) {
|
||||
Fixture f;
|
||||
const auto file = f.temp.path() / "settings";
|
||||
write(file,
|
||||
R"({"toolApprovals":[{"root":"one","operation":"metadataRefresh","executable":"g++"}]})");
|
||||
auto user = read_user_settings(file);
|
||||
require(user.has_value());
|
||||
const auto local = workspace(f.root);
|
||||
SettingsOverrides flags;
|
||||
flags.tool_approvals = std::vector<ToolSelection>{
|
||||
{f.root, compiler_use, f.tool}, {f.temp.path() / "missing", compiler_use, f.tool}};
|
||||
auto invalid = settings_from_cli(flags, f.root);
|
||||
auto rejected = merge_configuration(local, &*user, &invalid);
|
||||
expect(diagnosed(rejected, "toolApprovals", ConfigIssue::invalid_value));
|
||||
expect(rejected.effective().tool_approvals.empty());
|
||||
flags = {};
|
||||
flags.allow_metadata_refresh = false;
|
||||
auto veto = settings_from_cli(flags, f.root);
|
||||
expect(merge_configuration(local, &*user, &veto).effective().tool_approvals.empty());
|
||||
write(
|
||||
file,
|
||||
R"({"allowExplicitBuildActions":"yes","approvedWrappers":["unknown"],"allowCompilerPlugins":5,
|
||||
"toolApprovals":[{"root":"one","operation":"compilerUse","executable":"g++"},{"operation":"shell"}]})");
|
||||
user = read_user_settings(file);
|
||||
require(user.has_value());
|
||||
rejected = merge_configuration(local, &*user);
|
||||
for (auto key :
|
||||
{"allowExplicitBuildActions", "approvedWrappers", "allowCompilerPlugins", "toolApprovals"})
|
||||
expect(diagnosed(rejected, key, ConfigIssue::invalid_value));
|
||||
expect(rejected.effective().tool_approvals.empty() &&
|
||||
rejected.effective().approved_wrappers.empty());
|
||||
}
|
||||
|
||||
VOID_TEST(WorkspaceTests, explicit_user_file_and_executable_read_bounds) {
|
||||
Fixture f;
|
||||
expect(!read_user_settings("relative/settings"));
|
||||
expect(!read_user_settings(f.root));
|
||||
expect(refused(inspect_tool_identity(f.root), TrustError::not_regular));
|
||||
expect(refused(inspect_tool_identity("g++"), TrustError::invalid_path));
|
||||
expect(refused(inspect_tool_identity(f.root / "missing"), TrustError::unavailable_file));
|
||||
const auto fifo = f.root / "pipe";
|
||||
require(::mkfifo(fifo.c_str(), 0700) == 0);
|
||||
expect(refused(inspect_tool_identity(fifo), TrustError::not_regular));
|
||||
expect(!read_user_settings(fifo));
|
||||
write(f.root / "settings", "{");
|
||||
expect(!read_user_settings(f.root / "settings"));
|
||||
fs::resize_file(f.root / "settings", 1024 * 1024 + 1);
|
||||
expect(!read_user_settings(f.root / "settings"));
|
||||
fs::resize_file(f.tool, max_tool_bytes + 1);
|
||||
expect(refused(inspect_tool_identity(f.tool), TrustError::too_large));
|
||||
}
|
||||
|
||||
VOID_TEST(WorkspaceTests, hash_revalidated_with_identical_length_and_mtime) {
|
||||
Fixture f;
|
||||
TrustPolicy policy;
|
||||
const auto generation = f.install(policy, compiler_use);
|
||||
const auto pinned = policy.check_tool(f.root, compiler_use, f.tool, generation);
|
||||
require(pinned.has_value());
|
||||
expect(pinned->identity.content_hash_hex ==
|
||||
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
|
||||
auto incomplete = pinned->identity;
|
||||
incomplete.content_hash_hex.clear();
|
||||
expect(refused(revalidate_tool_identity(incomplete), TrustError::digest_unavailable));
|
||||
const auto mtime = fs::last_write_time(f.tool);
|
||||
write(f.tool, "abd");
|
||||
fs::last_write_time(f.tool, mtime);
|
||||
expect(refused(policy.check_tool(f.root, compiler_use, f.tool, generation),
|
||||
TrustError::identity_changed));
|
||||
expect(policy.generation(f.root) != generation);
|
||||
write(f.tool, "abc");
|
||||
expect(!policy.pin_approved_tool(f.root, compiler_use, f.tool));
|
||||
expect(f.install(policy, compiler_use) > generation);
|
||||
}
|
||||
|
||||
VOID_TEST(WorkspaceTests, selected_symlink_permission_and_replacement_identity) {
|
||||
Fixture f;
|
||||
auto first = f.tool;
|
||||
auto second = f.temp.path() / "same-bytes";
|
||||
fs::create_hard_link(first, second);
|
||||
f.tool = f.root / "compiler";
|
||||
fs::create_symlink(first, f.tool);
|
||||
TrustPolicy policy;
|
||||
auto gen = f.install(policy, compiler_use);
|
||||
auto pin = policy.check_tool(f.root, compiler_use, f.tool, gen);
|
||||
require(pin.has_value());
|
||||
expect(pin->identity.selected_path == f.tool && pin->identity.canonical_path == first);
|
||||
fs::remove(f.tool);
|
||||
fs::create_symlink(second, f.tool);
|
||||
expect(refused(policy.check_tool(f.root, compiler_use, f.tool, gen),
|
||||
TrustError::identity_changed));
|
||||
gen = f.install(policy, compiler_use);
|
||||
fs::permissions(second, fs::perms::group_exec, fs::perm_options::add);
|
||||
expect(refused(policy.check_tool(f.root, compiler_use, f.tool, gen),
|
||||
TrustError::identity_changed));
|
||||
gen = f.install(policy, compiler_use);
|
||||
fs::permissions(second, fs::perms::owner_read);
|
||||
expect(
|
||||
refused(policy.check_tool(f.root, compiler_use, f.tool, gen), TrustError::not_executable));
|
||||
fs::permissions(second, fs::perms::owner_read | fs::perms::owner_write | fs::perms::owner_exec);
|
||||
gen = f.install(policy, compiler_use);
|
||||
make_tool(f.root / "replacement");
|
||||
fs::rename(f.root / "replacement", second);
|
||||
expect(refused(policy.check_tool(f.root, compiler_use, f.tool, gen),
|
||||
TrustError::identity_changed));
|
||||
}
|
||||
|
||||
VOID_TEST(WorkspaceTests, exact_roots_and_operation_specific_pins) {
|
||||
Fixture f;
|
||||
const auto nested = f.root / "out";
|
||||
const auto alternate = f.other / "g++";
|
||||
make_tool(alternate);
|
||||
const std::vector<ToolSelection> selections{{f.root, compiler_use, f.tool},
|
||||
{f.root, trusted_metadata_refresh, alternate},
|
||||
{f.other, trusted_metadata_refresh, f.tool}};
|
||||
TrustPolicy policy;
|
||||
auto a = policy.replace_configuration(selected(f.root, selections));
|
||||
auto b = policy.replace_configuration(selected(f.other, selections));
|
||||
require(a.has_value() && b.has_value());
|
||||
expect(
|
||||
refused(policy.check_tool(f.root, compiler_use, f.tool, *a), TrustError::tool_not_pinned));
|
||||
require(policy.pin_approved_tool(f.root, compiler_use, f.tool).has_value());
|
||||
const auto alternate_spelling =
|
||||
f.tool.parent_path().native() + "//" + f.tool.filename().native();
|
||||
expect(refused(policy.check_tool(f.root, compiler_use, alternate_spelling, *a),
|
||||
TrustError::tool_not_approved));
|
||||
require(policy.pin_approved_tool(f.other, trusted_metadata_refresh, f.tool).has_value());
|
||||
expect(refused(policy.pin_approved_tool(f.other, compiler_use, f.tool),
|
||||
TrustError::operation_not_approved));
|
||||
expect(refused(policy.pin_approved_tool(f.root, trusted_metadata_refresh, f.tool),
|
||||
TrustError::tool_not_approved));
|
||||
expect(refused(policy.pin_approved_tool(nested, compiler_use, f.tool),
|
||||
TrustError::untrusted_root));
|
||||
expect(refused(policy.pin_approved_tool(f.root, passive_read, f.tool),
|
||||
TrustError::operation_not_approved));
|
||||
expect(refused(policy.check_tool(f.root, explicit_build_action, f.tool, *a),
|
||||
TrustError::explicit_action_required));
|
||||
policy.revoke_root_authority(f.root);
|
||||
expect(policy.generation(f.other) == *b &&
|
||||
policy.check_tool(f.other, trusted_metadata_refresh, f.tool, *b).has_value());
|
||||
require(policy.replace_configuration(selected(f.root, selections)).has_value());
|
||||
require(policy.pin_approved_tool(f.root, compiler_use, f.tool).has_value());
|
||||
expect(
|
||||
refused(policy.check_tool(f.root, compiler_use, f.tool, *a), TrustError::stale_generation));
|
||||
}
|
||||
|
||||
VOID_TEST(WorkspaceTests, relative_tool_selection_keeps_symlink_traversal) {
|
||||
Fixture f;
|
||||
fs::create_directory(f.other / "deep");
|
||||
fs::create_directory_symlink(f.other / "deep", f.temp.path() / "links");
|
||||
make_tool(f.other / "g++", "selected");
|
||||
make_tool(f.root / "g++", "selected");
|
||||
write(
|
||||
f.temp.path() / "user",
|
||||
R"({"toolApprovals":[{"root":"one","operation":"compilerUse","executable":"links/../g++"}]})");
|
||||
auto user = read_user_settings(f.temp.path() / "user");
|
||||
require(user.has_value());
|
||||
TrustPolicy policy;
|
||||
auto gen = policy.replace_configuration(merge_configuration(workspace(f.root), &*user));
|
||||
require(gen.has_value());
|
||||
const auto spelling = f.temp.path() / "links/../g++";
|
||||
auto pin = policy.pin_approved_tool(f.root, compiler_use, spelling);
|
||||
require(pin.has_value());
|
||||
expect(pin->identity.selected_path.native() == spelling.native() &&
|
||||
pin->identity.canonical_path == f.other / "g++");
|
||||
fs::remove(f.temp.path() / "links");
|
||||
fs::create_directory_symlink(f.root / "out", f.temp.path() / "links");
|
||||
expect(refused(policy.check_tool(f.root, compiler_use, spelling, *gen),
|
||||
TrustError::identity_changed));
|
||||
}
|
||||
|
||||
VOID_TEST(WorkspaceTests, replacing_workspace_directory_revokes_its_pins) {
|
||||
Fixture f;
|
||||
TrustPolicy policy;
|
||||
const auto gen = f.install(policy, compiler_use);
|
||||
fs::rename(f.root, f.temp.path() / "previous");
|
||||
fs::create_directory(f.root);
|
||||
expect(
|
||||
refused(policy.check_tool(f.root, compiler_use, f.tool, gen), TrustError::untrusted_root));
|
||||
expect(policy.generation(f.root) > gen);
|
||||
expect(!policy.pin_approved_tool(f.root, compiler_use, f.tool));
|
||||
}
|
||||
|
||||
VOID_TEST(WorkspaceTests, cached_settings_cannot_rearm_revoked_pins) {
|
||||
Fixture f;
|
||||
const auto file = f.temp.path() / "selected.json";
|
||||
write(file,
|
||||
R"({"toolApprovals":[{"root":"one","operation":"compilerUse","executable":"g++"}]})");
|
||||
auto user = read_user_settings(file);
|
||||
require(user.has_value());
|
||||
auto merged = merge_configuration(workspace(f.root), &*user);
|
||||
TrustPolicy policy;
|
||||
auto gen = policy.replace_configuration(merged);
|
||||
require(gen.has_value() && policy.pin_approved_tool(f.root, compiler_use, f.tool).has_value());
|
||||
auto changed_workspace =
|
||||
merge_configuration(workspace(f.root, R"({"provider":"compdb"})"), &*user);
|
||||
expect(policy.replace_configuration(changed_workspace) == gen);
|
||||
require(policy.check_tool(f.root, compiler_use, f.tool, *gen).has_value());
|
||||
// This trusted input was read before revocation, even though delivery to the policy is later.
|
||||
auto delayed = read_user_settings(file);
|
||||
require(delayed.has_value());
|
||||
write(f.tool, "abd");
|
||||
require(refused(policy.check_tool(f.root, compiler_use, f.tool, *gen),
|
||||
TrustError::identity_changed));
|
||||
expect(refused(policy.replace_configuration(changed_workspace), TrustError::stale_generation));
|
||||
expect(refused(policy.replace_configuration(merge_configuration(workspace(f.root), &*delayed)),
|
||||
TrustError::stale_generation));
|
||||
expect(!policy.pin_approved_tool(f.root, compiler_use, f.tool));
|
||||
auto fresh = read_user_settings(file);
|
||||
require(fresh.has_value());
|
||||
gen = policy.replace_configuration(merge_configuration(workspace(f.root), &*fresh));
|
||||
require(gen.has_value() && policy.pin_approved_tool(f.root, compiler_use, f.tool).has_value());
|
||||
policy.revoke_root_authority(f.root);
|
||||
expect(refused(policy.replace_configuration(merge_configuration(workspace(f.root), &*fresh)),
|
||||
TrustError::stale_generation));
|
||||
}
|
||||
|
||||
VOID_TEST(WorkspaceTests, revocation_during_revalidation_commits_before_callback) {
|
||||
Fixture f;
|
||||
fs::resize_file(f.tool, 8 * 1024 * 1024);
|
||||
std::uint64_t seen = 0;
|
||||
TrustPolicy policy([&](const fs::path &root, std::uint64_t gen) noexcept {
|
||||
if (policy.generation(root) == gen) {
|
||||
seen = gen; // callback reenters the policy
|
||||
policy.revoke_root_authority(root);
|
||||
}
|
||||
});
|
||||
const auto gen = f.install(policy, compiler_use);
|
||||
Void::System::OwnedFd watch{::inotify_init1(IN_NONBLOCK | IN_CLOEXEC)};
|
||||
require(watch.valid() && ::inotify_add_watch(watch.get(), f.tool.c_str(), IN_ACCESS) >= 0);
|
||||
auto work = std::async(std::launch::async,
|
||||
[&] { return policy.check_tool(f.root, compiler_use, f.tool, gen); });
|
||||
pollfd event{watch.get(), POLLIN, 0};
|
||||
require(::poll(&event, 1, 5000) == 1);
|
||||
policy.revoke_root_authority(f.root);
|
||||
const auto result = work.get();
|
||||
expect(seen > gen && seen == policy.generation(f.root));
|
||||
// If the reader won scheduling, its completed report still carries the superseded generation.
|
||||
expect(result ? result->trust_generation != seen
|
||||
: result.error() == TrustError::stale_generation);
|
||||
expect(!policy.check_tool(f.root, compiler_use, f.tool, gen));
|
||||
}
|
||||
|
||||
VOID_TEST(WorkspaceTests, build_approval_binds_every_invocation_field) {
|
||||
Fixture f;
|
||||
TrustPolicy policy;
|
||||
auto request = f.action(f.install(policy, explicit_build_action));
|
||||
auto ticket = policy.approve_build_action(request);
|
||||
require(ticket.has_value());
|
||||
expect(refused(policy.approve_build_action(request), TrustError::action_pending));
|
||||
auto mismatch = [&](auto edit) {
|
||||
auto different = request;
|
||||
edit(different);
|
||||
expect(refused(policy.consume_build_action(*ticket, different),
|
||||
TrustError::invocation_mismatch));
|
||||
};
|
||||
mismatch([&](auto &v) { v.root = f.other; });
|
||||
mismatch([&](auto &v) { v.working_directory = f.root; });
|
||||
mismatch([&](auto &v) { v.executable = f.root / "other-tool"; });
|
||||
mismatch([&](auto &v) {
|
||||
v.executable = f.tool.parent_path().native() + "//" + f.tool.filename().native();
|
||||
});
|
||||
mismatch([](auto &v) { std::ranges::reverse(v.arguments); });
|
||||
mismatch([](auto &v) { v.input_identity += "2"; });
|
||||
mismatch([](auto &v) { v.environment_identity += "2"; });
|
||||
mismatch([](auto &v) { ++v.trust_generation; });
|
||||
TrustPolicy other;
|
||||
(void)f.install(other, explicit_build_action);
|
||||
require(other.approve_build_action(request).has_value());
|
||||
expect(refused(other.consume_build_action(*ticket, request), TrustError::action_not_current));
|
||||
require(policy.consume_build_action(*ticket, request).has_value());
|
||||
expect(refused(policy.consume_build_action(*ticket, request), TrustError::action_not_current));
|
||||
ticket = policy.approve_build_action(request);
|
||||
require(ticket.has_value());
|
||||
expect(policy.cancel_build_action(*ticket) && !policy.cancel_build_action(*ticket));
|
||||
expect(!policy.consume_build_action(*ticket, request));
|
||||
}
|
||||
|
||||
VOID_TEST(WorkspaceTests, build_scope_changes_and_revocation_invalidate_pending_action) {
|
||||
Fixture f;
|
||||
TrustPolicy policy;
|
||||
auto action = f.action(f.install(policy, explicit_build_action));
|
||||
auto invalid = action;
|
||||
invalid.working_directory = f.other;
|
||||
expect(refused(policy.approve_build_action(invalid), TrustError::invalid_invocation));
|
||||
fs::create_directory_symlink(f.other, f.root / "alias");
|
||||
invalid.working_directory = f.root / "alias";
|
||||
expect(refused(policy.approve_build_action(invalid), TrustError::invalid_invocation));
|
||||
invalid = action;
|
||||
invalid.arguments.emplace_back("test\0tail", 9);
|
||||
expect(refused(policy.approve_build_action(invalid), TrustError::invalid_invocation));
|
||||
invalid = action;
|
||||
invalid.input_identity.clear();
|
||||
expect(refused(policy.approve_build_action(invalid), TrustError::invalid_invocation));
|
||||
auto ticket = policy.approve_build_action(action);
|
||||
require(ticket.has_value());
|
||||
fs::rename(action.working_directory, f.root / "retired");
|
||||
fs::create_directory(action.working_directory);
|
||||
expect(refused(policy.consume_build_action(*ticket, action), TrustError::invalid_invocation));
|
||||
ticket = policy.approve_build_action(action);
|
||||
require(ticket.has_value());
|
||||
policy.revoke_root_authority(f.root);
|
||||
expect(!policy.consume_build_action(*ticket, action));
|
||||
action.trust_generation = f.install(policy, explicit_build_action);
|
||||
ticket = policy.approve_build_action(action);
|
||||
require(ticket.has_value());
|
||||
write(f.tool, "new");
|
||||
expect(refused(policy.consume_build_action(*ticket, action), TrustError::identity_changed));
|
||||
expect(!policy.consume_build_action(*ticket, action));
|
||||
}
|
||||
|
||||
VOID_TEST(WorkspaceTests, concurrent_build_ticket_has_one_consumer) {
|
||||
Fixture f;
|
||||
TrustPolicy policy;
|
||||
auto request = f.action(f.install(policy, explicit_build_action));
|
||||
auto ticket = policy.approve_build_action(request);
|
||||
require(ticket.has_value());
|
||||
std::barrier start(2);
|
||||
auto consume = [&] {
|
||||
start.arrive_and_wait();
|
||||
return policy.consume_build_action(*ticket, request).has_value();
|
||||
};
|
||||
auto other = std::async(std::launch::async, consume);
|
||||
const bool first = consume();
|
||||
expect(first != other.get());
|
||||
}
|
||||
|
||||
VOID_TEST(WorkspaceTests, supported_compiler_and_wrappers_are_only_data) {
|
||||
Fixture f;
|
||||
const std::string marker_tool = "#!/bin/sh\nprintf 'unexpected launch' >> \"${0%/*}/marker\"\n";
|
||||
make_tool(f.tool, marker_tool);
|
||||
make_tool(f.temp.path() / "ccache", marker_tool);
|
||||
make_tool(f.temp.path() / "plugin-marker", marker_tool);
|
||||
write(f.temp.path() / "marker", "untouched");
|
||||
TrustPolicy policy;
|
||||
const auto gen = f.install(policy, compiler_use);
|
||||
auto checked = policy.check_tool(f.root, compiler_use, f.tool, gen);
|
||||
require(checked.has_value());
|
||||
const std::vector<std::string> wrappers{"ccache", "sccache"};
|
||||
const std::vector<std::string> command{f.tool.string(),
|
||||
"-c",
|
||||
"-std=c++26",
|
||||
"-freflection",
|
||||
"-D",
|
||||
"WITH_SPACES=a b",
|
||||
"-UUNUSED",
|
||||
"-I" + f.root.string(),
|
||||
"-isystem",
|
||||
f.other.string(),
|
||||
"-x",
|
||||
"c++",
|
||||
(f.root / "some source.cpp").string()};
|
||||
auto report =
|
||||
classify_and_unwrap_command(command, wrappers, checked->identity, CompilerDriver::gcc);
|
||||
expect(report.allowed && report.classification == FlagClassification::safe &&
|
||||
report.unwrapped_argv == command);
|
||||
auto wrapped = command;
|
||||
wrapped.insert(wrapped.begin(), {(f.temp.path() / "ccache").string(), "sccache"});
|
||||
report = classify_and_unwrap_command(wrapped, wrappers, checked->identity, CompilerDriver::gcc);
|
||||
expect(report.allowed && report.classification == FlagClassification::transparent_wrapper);
|
||||
expect(report.unwrapped_argv == command &&
|
||||
report.unwrapped_wrappers == std::vector<std::string>{wrapped[0], wrapped[1]});
|
||||
wrapped.push_back("-fplugin=" + (f.temp.path() / "plugin-marker").string());
|
||||
report = classify_and_unwrap_command(wrapped, wrappers, checked->identity, CompilerDriver::gcc);
|
||||
expect(!report.allowed &&
|
||||
report.classification == FlagClassification::execution_bearing_plugin);
|
||||
std::ifstream marker(f.temp.path() / "marker");
|
||||
std::string contents;
|
||||
std::getline(marker, contents);
|
||||
expect(contents == "untouched");
|
||||
}
|
||||
|
||||
VOID_TEST(WorkspaceTests, unresolved_or_execution_bearing_argv_is_refused) {
|
||||
Fixture f;
|
||||
auto identity = inspect_tool_identity(f.tool);
|
||||
require(identity.has_value());
|
||||
const std::vector<std::string> wrappers{"ccache", "custom-wrapper"};
|
||||
auto classify = [&](std::vector<std::string> argv,
|
||||
CompilerDriver driver = CompilerDriver::gcc) {
|
||||
return classify_and_unwrap_command(argv, wrappers, *identity, driver);
|
||||
};
|
||||
using enum FlagClassification;
|
||||
auto blocked = [&](std::vector<std::string> middle, FlagClassification reason) {
|
||||
std::vector<std::string> cmd{f.tool.string(), "-c"};
|
||||
cmd.insert(cmd.end(), middle.begin(), middle.end());
|
||||
cmd.push_back((f.root / "a.cpp").string());
|
||||
auto report = classify(cmd);
|
||||
expect(!report.allowed && report.classification == reason &&
|
||||
report.unwrapped_argv.empty() && !report.reason.empty());
|
||||
};
|
||||
for (auto flag : {"-fplugin=marker", "-fpass-plugin=marker", "-load"})
|
||||
blocked({flag}, execution_bearing_plugin);
|
||||
for (auto flag : {"-Xclang", "-Wp,marker", "-Wa,marker", "-Wl,marker", "-B/tools",
|
||||
"-specs=marker", "--config=marker"})
|
||||
blocked({flag}, suspicious_toolchain_override);
|
||||
blocked({"-wrapper=marker"}, execution_bearing_wrapper);
|
||||
blocked({"@nested.rsp"}, unresolved_response_file);
|
||||
blocked({"-I", "@include.rsp"}, unresolved_response_file);
|
||||
blocked({"-isystem", "-fplugin=marker"}, unsupported_operand);
|
||||
blocked({"-x", "assembler"}, unsupported_operand);
|
||||
blocked({"-D", "-Xclang"}, unsupported_operand);
|
||||
for (auto flag : {"-finvented-mode", "-o", "--", "-cc1", "-mllvm", "--target=elsewhere"})
|
||||
blocked({flag}, unsupported_option);
|
||||
blocked({"relative.cpp"}, unsupported_operand);
|
||||
blocked({std::string("a\0b", 3)}, invalid_command);
|
||||
expect(classify({"g++", "-c", (f.root / "a.cpp").string()}).classification ==
|
||||
unapproved_compiler_path);
|
||||
expect(classify({"custom-wrapper", f.tool.string(), "-c", (f.root / "a.cpp").string()})
|
||||
.classification == execution_bearing_wrapper);
|
||||
expect(classify({f.tool.string(), "-c", (f.root / "a.cpp").string()}, CompilerDriver::unknown)
|
||||
.classification == unsupported_driver);
|
||||
expect(!classify({f.tool.string(), (f.root / "a.cpp").string()}).allowed);
|
||||
}
|
||||
Reference in new issue
Block a user