fix(tests): use the per-variant config dir so the lite ctest doesn't segfault

testAddressBookScope hardcoded ".config/ObsidianDragon" for its
pre-scoping addressbook.json, but AddressBook::load() reads the
per-variant config dir (Lite -> ObsidianDragonLite/). In a --lite build
the write and read diverged, so load() found nothing, size()==0, and the
following entries()[0] read out of bounds -> SIGSEGV, taking the whole
suite down.

Write to dragonx::util::Platform::getConfigDir() (the same path load()
uses, resolved under the test's temp HOME) and guard the entries()[0]
access so a non-aborting EXPECT can never SIGSEGV the suite. Verified:
ctest now passes 100% in BOTH the full-node and --lite builds.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-19 12:28:04 -05:00
parent 5c570613c8
commit bef3c0c47d

View File

@@ -6357,8 +6357,11 @@ void testAddressBookScope()
fs::create_directories(tmp);
setenv("HOME", tmp.string().c_str(), 1);
// A pre-scoping addressbook.json (no "scope" field) migrates to global on load.
fs::path cfg = tmp / ".config" / "ObsidianDragon";
// A pre-scoping addressbook.json (no "scope" field) migrates to global on load. Write to the
// SAME per-variant config dir AddressBook::load() reads from (Lite -> ObsidianDragonLite/),
// resolved under the temp HOME set above. Hardcoding ".config/ObsidianDragon" made the lite-build
// ctest write where load() never looks -> 0 entries -> the entries()[0] below segfaulted.
fs::path cfg = dragonx::util::Platform::getConfigDir();
fs::create_directories(cfg);
std::ofstream(cfg / "addressbook.json")
<< R"({"entries":[{"label":"Legacy","address":"zs1legacy","notes":""}]})";
@@ -6366,7 +6369,9 @@ void testAddressBookScope()
AddressBook book;
EXPECT_TRUE(book.load());
EXPECT_EQ(book.size(), (size_t)1);
EXPECT_TRUE(book.entries()[0].isGlobal()); // migrated -> global
// Guard the [0] access — EXPECT_EQ doesn't abort this harness, so an empty book here must not
// SIGSEGV the whole suite (it would take every later test down with it).
EXPECT_TRUE(!book.entries().empty() && book.entries()[0].isGlobal()); // migrated -> global
}
// Same address may be a contact in two DIFFERENT wallets, but not twice in one; and a global