Implement the VLS roadmap on the native VBS build

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

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

No files matched your search

+642
View File
@@ -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