@@ -39,13 +39,16 @@ typedef struct {
3939typedef struct {
4040 frontend_maintenance_fixture_t maintenance ;
4141 char conflict_log [FRONTEND_TEST_PATH_CAP ];
42+ char build_fingerprint [CBM_DAEMON_BUILD_FINGERPRINT_SIZE ];
43+ cbm_daemon_build_identity_t identity ;
4244 cbm_daemon_runtime_service_t * service ;
4345 cbm_daemon_runtime_client_t * client ;
4446} frontend_idle_fixture_t ;
4547
4648typedef struct {
4749 cbm_daemon_runtime_client_t * client ;
4850 cbm_version_cohort_manager_t * manager ;
51+ const cbm_daemon_frontend_session_config_t * session ;
4952 FILE * input ;
5053 FILE * output ;
5154 int result ;
@@ -99,22 +102,22 @@ static cbm_daemon_runtime_application_status_t frontend_idle_request(
99102 return CBM_DAEMON_RUNTIME_APPLICATION_OK ;
100103}
101104
102- static void frontend_idle_request_cancel (
103- void * context , cbm_daemon_runtime_application_session_t * session ,
104- cbm_daemon_runtime_application_token_t request_token ) {
105+ static void frontend_idle_request_cancel (void * context ,
106+ cbm_daemon_runtime_application_session_t * session ,
107+ cbm_daemon_runtime_application_token_t request_token ) {
105108 (void )context ;
106109 (void )session ;
107110 (void )request_token ;
108111}
109112
110- static void frontend_idle_session_cancel (
111- void * context , cbm_daemon_runtime_application_session_t * session ) {
113+ static void frontend_idle_session_cancel (void * context ,
114+ cbm_daemon_runtime_application_session_t * session ) {
112115 (void )context ;
113116 (void )session ;
114117}
115118
116- static void frontend_idle_session_close (
117- void * context , cbm_daemon_runtime_application_session_t * session ) {
119+ static void frontend_idle_session_close (void * context ,
120+ cbm_daemon_runtime_application_session_t * session ) {
118121 (void )context ;
119122 (void )session ;
120123}
@@ -128,22 +131,21 @@ static uint64_t frontend_test_process_id(void) {
128131}
129132
130133static bool frontend_idle_fixture_start (frontend_idle_fixture_t * fixture ) {
131- static const char cache [] =
132- "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" ;
134+ static const char cache [] = "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" ;
133135 memset (fixture , 0 , sizeof (* fixture ));
134136 if (!frontend_maintenance_fixture_start (& fixture -> maintenance , "idle-observer" )) {
135137 return false;
136138 }
137- char build [CBM_DAEMON_BUILD_FINGERPRINT_SIZE ];
138139 int log_written = snprintf (fixture -> conflict_log , sizeof (fixture -> conflict_log ),
139140 "%s/conflicts.ndjson" , fixture -> maintenance .parent );
140141 if (log_written <= 0 || log_written >= (int )sizeof (fixture -> conflict_log ) ||
141- !cbm_daemon_runtime_process_build_fingerprint (frontend_test_process_id (), build )) {
142+ !cbm_daemon_runtime_process_build_fingerprint (frontend_test_process_id (),
143+ fixture -> build_fingerprint )) {
142144 return false;
143145 }
144- cbm_daemon_build_identity_t identity = {
146+ fixture -> identity = ( cbm_daemon_build_identity_t ) {
145147 .semantic_version = "2.4.0" ,
146- .build_fingerprint = build ,
148+ .build_fingerprint = fixture -> build_fingerprint ,
147149 .cache_fingerprint = cache ,
148150 .protocol_abi = 3 ,
149151 .store_abi = 11 ,
@@ -159,7 +161,7 @@ static bool frontend_idle_fixture_start(frontend_idle_fixture_t *fixture) {
159161 };
160162 cbm_daemon_runtime_service_config_t config = {
161163 .endpoint = fixture -> maintenance .endpoint ,
162- .identity = identity ,
164+ .identity = fixture -> identity ,
163165 .conflict_log_path = fixture -> conflict_log ,
164166 .conflict_log_cap_bytes = 64U * 1024U ,
165167 .max_clients = 2 ,
@@ -170,10 +172,11 @@ static bool frontend_idle_fixture_start(frontend_idle_fixture_t *fixture) {
170172 };
171173 fixture -> service = cbm_daemon_runtime_service_start (& config );
172174 cbm_daemon_runtime_connect_result_t connect_result = {0 };
173- fixture -> client = fixture -> service
174- ? cbm_daemon_runtime_client_connect (fixture -> maintenance .endpoint , & identity ,
175- 30000 , & connect_result )
176- : NULL ;
175+ fixture -> client =
176+ fixture -> service
177+ ? cbm_daemon_runtime_client_connect (fixture -> maintenance .endpoint , & fixture -> identity ,
178+ 30000 , & connect_result )
179+ : NULL ;
177180 return fixture -> client && connect_result .status == CBM_DAEMON_RUNTIME_CONNECT_ACCEPTED ;
178181}
179182
@@ -213,8 +216,8 @@ static int frontend_test_close_fd(int fd) {
213216
214217static void * frontend_idle_run (void * opaque ) {
215218 frontend_idle_run_t * run = opaque ;
216- run -> result =
217- cbm_daemon_frontend_mcp_run ( run -> client , run -> manager , run -> input , run -> output );
219+ run -> result = cbm_daemon_frontend_mcp_run ( run -> client , run -> manager , run -> session , run -> input ,
220+ run -> output );
218221 return NULL ;
219222}
220223#endif
@@ -479,11 +482,13 @@ static void *frontend_eof_writer(void *opaque) {
479482
480483static const char frontend_recovery_request [] =
481484 "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/list\",\"params\":{}}\n" ;
485+ #if defined(CBM_ENABLE_TEST_SEAMS ) && CBM_ENABLE_TEST_SEAMS
482486static const char frontend_recovery_cancel [] =
483487 "{\"jsonrpc\":\"2.0\",\"method\":\"notifications/cancelled\","
484488 "\"params\":{\"requestId\":1}}\n" ;
485489static const char frontend_recovery_followup [] =
486490 "{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"tools/list\",\"params\":{}}\n" ;
491+ #endif
487492
488493static void * frontend_recovery_writer (void * opaque ) {
489494 frontend_eof_writer_t * writer = opaque ;
@@ -500,16 +505,24 @@ static void *frontend_recovery_writer(void *opaque) {
500505 ok = ok && atomic_load_explicit (& writer -> application -> first_request_started ,
501506 memory_order_acquire );
502507 }
508+ #if defined(CBM_ENABLE_TEST_SEAMS ) && CBM_ENABLE_TEST_SEAMS
503509 if (writer -> recovery_mode == FRONTEND_RECOVERY_CANCEL ) {
510+ uint64_t cancellations = cbm_daemon_frontend_test_routed_cancellations ();
504511 ok = ok && frontend_eof_write_all (writer -> fd , frontend_recovery_cancel ,
505512 sizeof (frontend_recovery_cancel ) - 1U );
506513 /* Keep context blocked until the reader routes the cancellation. */
507- cbm_usleep (100000 );
514+ while (ok && cbm_daemon_frontend_test_routed_cancellations () == cancellations &&
515+ cbm_now_ms () < deadline ) {
516+ cbm_usleep (1000 );
517+ }
518+ ok = ok && cbm_daemon_frontend_test_routed_cancellations () > cancellations ;
508519 atomic_store_explicit (& writer -> application -> release_first_request , true,
509520 memory_order_release );
510521 ok = ok && frontend_eof_write_all (writer -> fd , frontend_recovery_followup ,
511522 sizeof (frontend_recovery_followup ) - 1U );
512- } else if (writer -> recovery_mode == FRONTEND_RECOVERY_CLEAN_EOF ) {
523+ }
524+ #endif
525+ if (writer -> recovery_mode == FRONTEND_RECOVERY_CLEAN_EOF ) {
513526 ok = close (writer -> fd ) == 0 && ok ;
514527 writer -> fd = -1 ;
515528 cbm_usleep (FRONTEND_RECOVERY_EOF_RELEASE_MS * 1000U );
@@ -1537,9 +1550,20 @@ TEST(daemon_frontend_idle_uses_one_maintenance_observer) {
15371550 bool pipe_ready = fixture_ready && cbm_pipe (input_pipe ) == 0 ;
15381551 FILE * input = pipe_ready ? frontend_test_fdopen_read (input_pipe [0 ]) : NULL ;
15391552 FILE * output = input ? tmpfile () : NULL ;
1553+ cbm_daemon_frontend_session_config_t session = {
1554+ .bootstrap = {.role = CBM_DAEMON_PROCESS_MCP_CLIENT ,
1555+ .endpoint = fixture .maintenance .endpoint ,
1556+ .identity = & fixture .identity ,
1557+ .executable_path = "unused" ,
1558+ .connect_timeout_ms = 30000 ,
1559+ .startup_timeout_ms = 30000 },
1560+ .session_root = fixture .maintenance .parent ,
1561+ .tool_profile = CBM_MCP_TOOL_PROFILE_ALL ,
1562+ };
15401563 frontend_idle_run_t run = {
15411564 .client = fixture .client ,
15421565 .manager = fixture .maintenance .manager ,
1566+ .session = & session ,
15431567 .input = input ,
15441568 .output = output ,
15451569 .result = -1 ,
@@ -1859,10 +1883,12 @@ TEST(daemon_frontend_recovers_one_unsent_request_after_daemon_replacement) {
18591883}
18601884
18611885/* Context-replay cancellation must not strand a token or break the next request. */
1886+ #if defined(CBM_ENABLE_TEST_SEAMS ) && CBM_ENABLE_TEST_SEAMS
18621887TEST (daemon_frontend_recovery_cancellation_preserves_next_request ) {
18631888 ASSERT_TRUE (frontend_recovery_run_isolated (FRONTEND_RECOVERY_CANCEL ));
18641889 PASS ();
18651890}
1891+ #endif
18661892
18671893/* Clean EOF during context replay must preserve worker-owned client cleanup. */
18681894TEST (daemon_frontend_clean_eof_during_recovery_preserves_client_ownership ) {
@@ -1928,7 +1954,9 @@ SUITE(daemon_frontend) {
19281954 RUN_TEST (daemon_local_participant_monitor_allows_supervisor_containment_window );
19291955 RUN_TEST (daemon_frontend_over_capacity_input_backpressures_without_loss );
19301956 RUN_TEST (daemon_frontend_recovers_one_unsent_request_after_daemon_replacement );
1957+ #if defined(CBM_ENABLE_TEST_SEAMS ) && CBM_ENABLE_TEST_SEAMS
19311958 RUN_TEST (daemon_frontend_recovery_cancellation_preserves_next_request );
1959+ #endif
19321960 RUN_TEST (daemon_frontend_clean_eof_during_recovery_preserves_client_ownership );
19331961 RUN_TEST (daemon_frontend_eof_drain_timeout_cancels_and_returns_success );
19341962 RUN_TEST (daemon_frontend_stdout_backpressure_eof_fail_stops_and_cancels_session );
0 commit comments