Skip to content

Commit 7dacceb

Browse files
committed
fix(test): 护栏矩阵不能把「本机是 Linux」当成前提;doctor 呈现降级 note
CI 的 macOS 与 Windows runner 上 RuntimeSearchClosure 两条红:它们用空 triple 断言 「拿得到 farm」,而空 triple 的意思是**本宿主的格式** —— 在 macOS/Windows 上那正是 「没有 ELF 搜索路径」,也就是这条护栏本身要表达的东西,不是它的例外。 改为:显式 Linux target 在任何 runner 上都断言拿得到(护栏读的是目标,不是 runner); 空 triple 那条按本机格式给期望值,并把理由写进断言消息。 顺带补上设计里承诺而没实现的一处:`mcpp why runtime` 现在呈现 binding 的 `declared` 与 `note`。只在发生那次构建里出现过一次的降级,是事后查不到的降级 —— 而「我的 verdict 为什么是 inconclusive」正是这个命令存在的理由。
1 parent 9a0333e commit 7dacceb

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

src/doctor.cppm

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,10 +592,19 @@ int print_stored_runtime_resolution() {
592592
std::println("runtime resolution: {}", path.string());
593593
if (auto binding = runtime->find("binding");
594594
binding != runtime->end() && binding->is_object()) {
595-
std::println("binding: {} via {} (contract {})",
596-
binding->value("runtime_id", "?"),
595+
const bool declared = binding->value("declared", true);
596+
std::println("binding: {} via {} (contract {}){}",
597+
declared ? binding->value("runtime_id", "?") : "(undeclared)",
597598
binding->value("provider_id", "?"),
598-
binding->value("contract_hash", "?"));
599+
binding->value("contract_hash", "?"),
600+
declared ? "" : " — this SubOS did not describe itself");
601+
// The note, when there is one. A degradation that only ever appeared
602+
// once during the build it happened in is a degradation nobody can look
603+
// up afterwards, and "why is my verdict inconclusive" is exactly the
604+
// question this command exists to answer.
605+
if (auto note = binding->value("note", std::string{}); !note.empty())
606+
for (auto line : std::views::split(note, '\n'))
607+
std::println(" {}", std::string_view(line));
599608
}
600609

601610
std::println("requirements:");

tests/unit/test_runtime_contract.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,18 @@ std::size_t farm_entries(const std::vector<mcpp::platform::search::Dir>& dirs) {
325325
} // namespace
326326

327327
TEST(RuntimeSearchClosure, HostTargetGetsTheFarm) {
328-
EXPECT_EQ(farm_entries(build::runtime_search_closure(
329-
plan_for(""), host_binding_with_farm())), 1u);
328+
// An EXPLICIT Linux target is a farm target from anywhere, including a
329+
// macOS or Windows runner: the guards read the target, not the runner.
330330
EXPECT_EQ(farm_entries(build::runtime_search_closure(
331331
plan_for("x86_64-linux-gnu"), host_binding_with_farm())), 1u);
332+
333+
// An EMPTY triple means "this host", so the answer is the host's format —
334+
// and that is the point of the ELF guard, not an exception to it. Asserting
335+
// 1 unconditionally is what failed on the macOS and Windows runners.
336+
const std::size_t expectedForHost = mcpp::platform::is_linux ? 1u : 0u;
337+
EXPECT_EQ(farm_entries(build::runtime_search_closure(
338+
plan_for(""), host_binding_with_farm())), expectedForHost)
339+
<< "an empty triple must resolve to this host's format";
332340
}
333341

334342
TEST(RuntimeSearchClosure, CrossTargetGetsNoFarm) {
@@ -355,7 +363,8 @@ TEST(RuntimeSearchClosure, UndeclaredBindingStillGetsItsOwnFarm) {
355363
auto b = host_binding_with_farm();
356364
b.declared = false;
357365
b.runtimeId.clear();
358-
EXPECT_EQ(farm_entries(build::runtime_search_closure(plan_for(""), b)), 1u);
366+
EXPECT_EQ(farm_entries(build::runtime_search_closure(
367+
plan_for("x86_64-linux-gnu"), b)), 1u);
359368
// …but the architecture guard still applies: unknown libc is not a licence
360369
// to ignore everything else.
361370
EXPECT_EQ(farm_entries(build::runtime_search_closure(

0 commit comments

Comments
 (0)