Skip to content

Commit 1b9db17

Browse files
committed
cleanup ugly codex impl
1 parent ac1c742 commit 1b9db17

File tree

6 files changed

+57
-76
lines changed

6 files changed

+57
-76
lines changed

crates/sdk-core/src/abstractions.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,11 @@ macro_rules! dbg_panic {
427427
($($arg:tt)*) => {{
428428
let message = format!($($arg)*);
429429
error!("{}", message);
430-
crate::antithesis::assert_always_failure!(
430+
crate::antithesis::assert_always!(
431+
false,
431432
"dbg_panic invariant triggered",
432433
::serde_json::json!({
433-
"message": message.clone(),
434+
"message": message,
434435
"file": file!(),
435436
"line": line!(),
436437
"module": module_path!(),

crates/sdk-core/src/antithesis.rs

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,62 @@
1-
#[cfg(feature = "antithesis_assertions")]
2-
use std::sync::OnceLock;
1+
//! Antithesis SDK integration for invariant testing.
2+
//!
3+
//! This module provides assertion macros that integrate with the Antithesis
4+
//! testing platform to detect invariant violations during fuzz testing.
5+
//!
6+
//! When the `antithesis_assertions` feature is disabled, assertions compile
7+
//! to no-ops.
38
4-
/// Ensure Antithesis is initialized exactly once.
59
#[cfg(feature = "antithesis_assertions")]
6-
pub(crate) fn ensure_init() {
7-
static INIT: OnceLock<()> = OnceLock::new();
8-
INIT.get_or_init(|| {
9-
::antithesis_sdk::antithesis_init();
10-
});
11-
}
10+
mod enabled {
11+
use std::sync::OnceLock;
1212

13-
#[cfg(not(feature = "antithesis_assertions"))]
14-
#[inline]
15-
pub(crate) fn ensure_init() {}
13+
/// Ensure Antithesis is initialized exactly once.
14+
pub(crate) fn ensure_init() {
15+
static INIT: OnceLock<()> = OnceLock::new();
16+
INIT.get_or_init(|| {
17+
::antithesis_sdk::antithesis_init();
18+
});
19+
}
1620

17-
#[cfg(feature = "antithesis_assertions")]
18-
macro_rules! assert_always {
19-
($message:literal, $condition:expr, $details:expr) => {{
20-
$crate::antithesis::ensure_init();
21-
let details: ::serde_json::Value = $details;
22-
::antithesis_sdk::assert_always!($condition, $message, &details);
23-
}};
24-
($message:literal, $condition:expr) => {{
25-
$crate::antithesis::ensure_init();
26-
::antithesis_sdk::assert_always!($condition, $message);
27-
}};
21+
/// Assert that a condition is always true during Antithesis fuzz testing.
22+
/// Use `false` as the condition to log an invariant violation.
23+
macro_rules! assert_always {
24+
($condition:expr, $message:literal, $details:expr) => {{
25+
$crate::antithesis::ensure_init();
26+
let details: ::serde_json::Value = $details;
27+
::antithesis_sdk::assert_always!($condition, $message, &details);
28+
}};
29+
($condition:expr, $message:literal) => {{
30+
$crate::antithesis::ensure_init();
31+
::antithesis_sdk::assert_always!($condition, $message);
32+
}};
33+
}
34+
35+
pub(crate) use assert_always;
2836
}
2937

3038
#[cfg(not(feature = "antithesis_assertions"))]
31-
macro_rules! assert_always {
32-
($message:literal, $condition:expr, $details:expr) => {{
33-
let _ = ($message, $condition);
34-
let _ = $details;
35-
}};
36-
($message:literal, $condition:expr) => {{
37-
let _ = ($message, $condition);
38-
}};
39+
mod disabled {
40+
/// No-op when feature is disabled.
41+
#[inline(always)]
42+
pub(crate) fn ensure_init() {}
43+
44+
/// No-op assertion when feature is disabled.
45+
macro_rules! assert_always {
46+
($condition:expr, $message:literal, $details:expr) => {{
47+
let _ = ($condition, $message);
48+
let _ = $details;
49+
}};
50+
($condition:expr, $message:literal) => {{
51+
let _ = ($condition, $message);
52+
}};
53+
}
54+
55+
pub(crate) use assert_always;
3956
}
4057

4158
#[cfg(feature = "antithesis_assertions")]
42-
macro_rules! assert_always_failure {
43-
($message:literal, $details:expr) => {{
44-
$crate::antithesis::assert_always!($message, false, $details);
45-
}};
46-
}
59+
pub(crate) use enabled::*;
4760

4861
#[cfg(not(feature = "antithesis_assertions"))]
49-
macro_rules! assert_always_failure {
50-
($message:literal, $details:expr) => {{
51-
let _ = $message;
52-
let _ = $details;
53-
}};
54-
}
55-
56-
pub(crate) use assert_always;
57-
pub(crate) use assert_always_failure;
62+
pub(crate) use disabled::*;

crates/sdk-core/src/lib.rs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
#![allow(clippy::upper_case_acronyms)]
33

44
//! This crate provides a basis for creating new Temporal SDKs without completely starting from
5-
//! scratch.
6-
//!
7-
//! ## Optional features
8-
//! - `antithesis_assertions`: Enables integration with Antithesis' Rust SDK. When active, core
9-
//! initialization calls `antithesis_sdk::antithesis_init` and critical invariants emit
10-
//! Antithesis assertions to aid fuzzing campaigns.
5+
//! scratch
116
127
#[cfg(test)]
138
#[macro_use]
@@ -92,17 +87,8 @@ pub fn init_worker<CT>(
9287
where
9388
CT: Into<sealed::AnyClient>,
9489
{
95-
crate::antithesis::ensure_init();
9690
let namespace = worker_config.namespace.clone();
9791
if namespace.is_empty() {
98-
crate::antithesis::assert_always_failure!(
99-
"worker namespace must not be empty",
100-
::serde_json::json!({
101-
"namespace": namespace.clone(),
102-
"task_queue": worker_config.task_queue.clone(),
103-
"has_identity_override": worker_config.client_identity_override.is_some(),
104-
})
105-
);
10692
bail!("Worker namespace cannot be empty");
10793
}
10894

@@ -118,13 +104,6 @@ where
118104
let sticky_q = sticky_q_name_for_worker(&client_ident, worker_config.max_cached_workflows);
119105

120106
if client_ident.is_empty() {
121-
crate::antithesis::assert_always_failure!(
122-
"client identity must not be empty",
123-
::serde_json::json!({
124-
"namespace": namespace.clone(),
125-
"task_queue": worker_config.task_queue.clone(),
126-
})
127-
);
128107
bail!("Client identity cannot be empty. Either lang or user should be setting this value");
129108
}
130109

@@ -154,7 +133,6 @@ pub fn init_replay_worker<I>(rwi: ReplayWorkerInput<I>) -> Result<Worker, anyhow
154133
where
155134
I: Stream<Item = HistoryForReplay> + Send + 'static,
156135
{
157-
crate::antithesis::ensure_init();
158136
info!(
159137
task_queue = rwi.config.task_queue.as_str(),
160138
"Registering replay worker"
@@ -313,7 +291,6 @@ impl CoreRuntime {
313291
where
314292
F: Fn() + Send + Sync + 'static,
315293
{
316-
crate::antithesis::ensure_init();
317294
let telemetry = telemetry_init(runtime_options.telemetry_options)?;
318295
let subscriber = telemetry.trace_subscriber();
319296
let runtime = tokio_builder
@@ -341,7 +318,6 @@ impl CoreRuntime {
341318
/// # Panics
342319
/// If there is no currently active Tokio runtime
343320
pub fn new_assume_tokio(runtime_options: RuntimeOptions) -> Result<Self, anyhow::Error> {
344-
crate::antithesis::ensure_init();
345321
let telemetry = telemetry_init(runtime_options.telemetry_options)?;
346322
Ok(Self::new_assume_tokio_initialized_telem(
347323
telemetry,
@@ -358,7 +334,6 @@ impl CoreRuntime {
358334
telemetry: TelemetryInstance,
359335
heartbeat_interval: Option<Duration>,
360336
) -> Self {
361-
crate::antithesis::ensure_init();
362337
let runtime_handle = tokio::runtime::Handle::current();
363338
if let Some(sub) = telemetry.trace_subscriber() {
364339
set_trace_subscriber_for_current_thread(sub);

crates/sdk-core/src/worker/workflow/machines/activity_state_machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ impl ActivityMachine {
195195
}
196196
x => {
197197
crate::antithesis::assert_always!(
198-
"activity cancel yields supported command",
199198
false,
199+
"activity cancel yields supported command",
200200
::serde_json::json!({
201201
"activity_seq": self.shared_state.attrs.seq,
202202
"unexpected_command": format!("{x:?}"),

crates/sdk-core/src/worker/workflow/machines/child_workflow_state_machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,8 @@ impl ChildWorkflowMachine {
498498
}
499499
x => {
500500
crate::antithesis::assert_always!(
501-
"child workflow cancel yields supported command",
502501
false,
502+
"child workflow cancel yields supported command",
503503
::serde_json::json!({
504504
"workflow_id": self.shared_state.workflow_id.clone(),
505505
"run_id": self.shared_state.run_id.clone(),

crates/sdk-core/src/worker/workflow/machines/complete_workflow_state_machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ pub(super) fn complete_workflow(attribs: CompleteWorkflowExecution) -> NewMachin
4343
Some(CompleteWFCommand::AddCommand(c)) => c,
4444
unexpected => {
4545
crate::antithesis::assert_always!(
46-
"complete workflow scheduling yields command",
4746
false,
47+
"complete workflow scheduling yields command",
4848
::serde_json::json!({
4949
"unexpected": format!("{unexpected:?}"),
5050
})

0 commit comments

Comments
 (0)