From 6e64ee21e830c7c9dee581b566868164ac061ea8 Mon Sep 17 00:00:00 2001 From: Scott Roy Date: Fri, 2 Oct 2026 13:05:30 -0700 Subject: [PATCH] Make test hook setup safe across repeated runs Summary: Repeated GTest invocations and the XCTest bridge retain the process-global hook registry, so unconditional test-provider registration fails on subsequent suite setup. Register once per process while retaining the assertion that the initial registration succeeded. Add a regression for repeated setup without changing the production one-provider contract or duplicate-provider rejection coverage. Leave the disabled Xcode-staging configuration unchanged. Differential Revision: D123082075 --- extension/module/test/ptn_hooks_test.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/extension/module/test/ptn_hooks_test.cpp b/extension/module/test/ptn_hooks_test.cpp index 0fa1dd7b17d..a87b4005e09 100644 --- a/extension/module/test/ptn_hooks_test.cpp +++ b/extension/module/test/ptn_hooks_test.cpp @@ -127,9 +127,10 @@ class PtnHooksTest : public ::testing::Test { protected: static void SetUpTestSuite() { runtime::runtime_init(); - ASSERT_EQ( - native_module::internal::register_ptn_hooks(kFakeHooks), - runtime::Error::Ok); + // The registry survives repeated GTest runs, including the XCTest bridge. + static const auto registration_error = + native_module::internal::register_ptn_hooks(kFakeHooks); + ASSERT_EQ(registration_error, runtime::Error::Ok); } void SetUp() override { @@ -137,6 +138,14 @@ class PtnHooksTest : public ::testing::Test { } }; +TEST_F(PtnHooksTest, SuiteSetup_CanBeRepeated) { + ASSERT_NO_FATAL_FAILURE(SetUpTestSuite()); + ASSERT_NO_FATAL_FAILURE(SetUpTestSuite()); + const auto* hooks = native_module::internal::get_ptn_hooks(); + ASSERT_NE(hooks, nullptr); + EXPECT_EQ(hooks->load, load_fake_ptn); +} + TEST_F(PtnHooksTest, Load_PtnSource_DispatchesMetadataAndMethodState) { const std::array bytes{'P', 'K'}; auto loader = std::make_unique(bytes.data(), bytes.size());