(&self)
| 1139 | |
| 1140 | impl Command for JournalRpcSelftest { |
| 1141 | fn run(&self) -> CliResult<()> { |
| 1142 | // This selftest exists to exercise the REACTOR journal transport |
| 1143 | // (D4 start-or-retry, wire chunking) — it must never start a |
| 1144 | // daemon in local mode. Refuse early, with the opt-in. |
| 1145 | if !matches!(crate::service::mode(), crate::service::Mode::Reactor) { |
| 1146 | return Err(CliError::InvalidArgument { |
| 1147 | message: "the journal RPC selftest exercises the reactor transport; \ |
| 1148 | set ATOMIC_SERVICE=reactor (it D4-starts the daemon when down)" |
| 1149 | .to_string(), |
| 1150 | }); |
| 1151 | } |
| 1152 | let root = crate::commands::find_repository_root_from(&self.repository)?; |
| 1153 | let Some(sink) = ProvenanceRpcSink::open(&root) else { |
| 1154 | return Err(CliError::InvalidArgument { |
| 1155 | message: "no reachable atomic daemon; the selftest exercises the RPC sink" |
| 1156 | .to_string(), |
| 1157 | }); |
| 1158 | }; |
| 1159 | let sink = Arc::new(sink); |
| 1160 | |
| 1161 | let now = 1_700_000_000i64; |
| 1162 | let reservation = sink |
| 1163 | .reserve_turn(&self.session_id, self.turn, now) |
| 1164 | .map_err(|reason| CliError::Internal(anyhow!("reserve failed: {reason}")))?; |
| 1165 | |
| 1166 | let mut envelopes = Vec::new(); |
| 1167 | for index in 0..self.envelopes { |
| 1168 | let event = atomic_agent::ProvenanceJournalEvent::Tool { |
| 1169 | phase: atomic_agent::ProvenanceToolPhase::After, |
| 1170 | tool_name: "selftest".to_string(), |
| 1171 | tool_call_id: Some(format!("selftest-{index}")), |
| 1172 | input: None, |
| 1173 | output: Some(serde_json::Value::String("x".repeat(self.envelope_bytes))), |
| 1174 | status: Some("completed".to_string()), |
| 1175 | duration_ms: Some(4), |
| 1176 | raw: None, |
| 1177 | }; |
| 1178 | envelopes.push(ProvenanceJournalEnvelope::new( |
| 1179 | format!("selftest-{index}"), |
| 1180 | &self.session_id, |
| 1181 | self.turn, |
| 1182 | reservation.generation, |
| 1183 | now * 1000 + index as i64, |
| 1184 | event, |
| 1185 | )); |
| 1186 | } |
| 1187 | let expected: Vec<Vec<u8>> = envelopes |
| 1188 | .iter() |
| 1189 | .map(|envelope| envelope.to_json_bytes().unwrap()) |
| 1190 | .collect(); |
| 1191 | // The same chunking the sink performs — reported so the test can |
| 1192 | // assert a multi-envelope batch really split. |
| 1193 | let wire: Vec<_> = envelopes |
| 1194 | .iter() |
| 1195 | .map(|envelope| pb::WireEnvelope { |
| 1196 | event_id: envelope.event_id.clone(), |
| 1197 | type_url: String::new(), |
| 1198 | envelope: envelope.to_json_bytes().unwrap(), |
nothing calls this directly
no test coverage detected