Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
run: cargo check --all-targets --all-features

- name: Run clippy with warnings denied
run: cargo clippy --all-targets --all-features -- -D warnings
run: cargo clippy --workspace --all-targets --all-features -- -D warnings

- name: Enforce Cargo.lock is up to date
shell: bash
Expand Down
3 changes: 0 additions & 3 deletions crates/jcode-sdk/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,6 @@ fn stop_global_stream(control: &GlobalEventControl, error: Option<Error>) {
drop(children);
}

/// A live subscription: (id, session filter, sink).
type Subscriber = (u64, Option<String>, Sender<ApiEvent>);

struct Inner {
writer: Mutex<Box<dyn Write + Send>>,
/// Requests waiting for their `reply_to` frame.
Expand Down
10 changes: 8 additions & 2 deletions crates/jcode-setup-hints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ mod windows_hotkeys;
mod windows_setup;
#[cfg(any(test, target_os = "macos"))]
use macos_launcher::{install_macos_app_launcher, should_refresh_macos_app_launcher};
#[cfg(any(test, target_os = "macos"))]
use macos_terminal::MacTerminalKind;
#[cfg(target_os = "macos")]
use macos_terminal::launch_script_for_macos_terminal;
#[cfg(target_os = "macos")]
Expand All @@ -53,8 +55,12 @@ use macos_terminal::load_preferred_macos_terminal;
use macos_terminal::paused_jcode_shell_command;
#[cfg(target_os = "macos")]
use macos_terminal::save_preferred_macos_terminal;
#[cfg(any(test, target_os = "macos"))]
use macos_terminal::{MacTerminalKind, effective_macos_terminal};
// `MacTerminalKind` is reachable from the `#[cfg(any(test, target_os = "macos"))]`
// notice helper and its tests, but every `effective_macos_terminal()` caller sits
// behind `#[cfg(target_os = "macos")]`. Keeping the two names on one gate left
// this import unused in a non-macOS `--all-targets` test build.
#[cfg(target_os = "macos")]
use macos_terminal::effective_macos_terminal;
#[cfg(windows)]
use windows_setup::{
create_windows_desktop_shortcut, maybe_show_windows_setup_hints, run_setup_hotkey_windows,
Expand Down
17 changes: 17 additions & 0 deletions crates/jcode-telemetry-core/src/delivery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@
//! failure path degrades to dropping the payload rather than panicking: a
//! host must never crash because an endpoint was unreachable.

// `telemetry_status_is_permanent`, `spawn_background_worker`, and
// `payload_is_breaker_exempt` are the only items the test module reaches for, so
// the live delivery surface below — and every import it alone needs — is compiled
// out of test builds instead of tripping `dead_code`/`unused_imports`.
#[cfg(not(test))]
use jcode_logging as logging;
#[cfg(not(test))]
use std::sync::OnceLock;
#[cfg(not(test))]
use std::sync::atomic::Ordering;
use std::sync::mpsc::{SyncSender, sync_channel};
#[cfg(not(test))]
use std::time::Duration;

use serde_json::Value;

#[cfg(not(test))]
use super::{
ASYNC_SEND_TIMEOUT, BACKGROUND_QUEUE_CAPACITY, TELEMETRY_BACKGROUND_SENDER, TELEMETRY_ENDPOINT,
TELEMETRY_HTTP_CLIENT, TELEMETRY_PERMANENTLY_REJECTED, TRANSCRIPT_BACKGROUND_SENDER,
Expand All @@ -20,6 +29,7 @@ use super::{

/// Lazily initialize and borrow the shared telemetry HTTP client. Returns `None`
/// when the builder fails, keeping telemetry optional rather than crashing.
#[cfg(not(test))]
pub(crate) fn http_client() -> Option<&'static reqwest::blocking::Client> {
TELEMETRY_HTTP_CLIENT
.get_or_init(|| {
Expand All @@ -37,6 +47,7 @@ pub(crate) fn http_client() -> Option<&'static reqwest::blocking::Client> {
.as_ref()
}

#[cfg(not(test))]
pub(crate) fn post_payload(payload: serde_json::Value, timeout: Duration) -> bool {
if TELEMETRY_PERMANENTLY_REJECTED.load(Ordering::Relaxed) {
return false;
Expand Down Expand Up @@ -74,6 +85,7 @@ pub(crate) fn post_payload(payload: serde_json::Value, timeout: Duration) -> boo
}
}

#[cfg(not(test))]
pub(crate) fn post_payload_with_retry(payload: serde_json::Value, timeout: Duration) -> bool {
const RETRY_DELAYS: [Duration; 2] = [Duration::from_millis(200), Duration::from_millis(800)];
if post_payload(payload.clone(), timeout) {
Expand All @@ -91,6 +103,7 @@ pub(crate) fn post_payload_with_retry(payload: serde_json::Value, timeout: Durat
false
}

#[cfg(not(test))]
pub(crate) fn post_transcript_payload(payload: serde_json::Value, timeout: Duration) -> bool {
let Some(client) = http_client() else {
logging::warn("telemetry HTTP client failed to build; dropping transcript");
Expand Down Expand Up @@ -142,6 +155,7 @@ where
/// Lazily start a telemetry background sender, returning `None` when the
/// worker thread cannot be spawned. The fallback lets callers drop payloads
/// rather than crash the host on thread-creation failure.
#[cfg(not(test))]
pub(crate) fn init_background_sender<F>(capacity: usize, deliver: F) -> Option<SyncSender<Value>>
where
F: FnMut(Value) + Send + 'static,
Expand All @@ -159,6 +173,7 @@ where

/// Shared shape for the telemetry and transcript background senders: lazily
/// initialize one OnceLock-held worker and borrow it.
#[cfg(not(test))]
pub(crate) fn sender<F>(
slot: &OnceLock<Option<SyncSender<Value>>>,
capacity: usize,
Expand All @@ -171,6 +186,7 @@ where
.as_ref()
}

#[cfg(not(test))]
pub(crate) fn background_sender() -> Option<&'static SyncSender<Value>> {
// A worker thread has no caller to report to: the delivery result is
// deliberately not inspected here, and both callees already log their
Expand All @@ -185,6 +201,7 @@ pub(crate) fn background_sender() -> Option<&'static SyncSender<Value>> {
)
}

#[cfg(not(test))]
pub(crate) fn transcript_background_sender() -> Option<&'static SyncSender<Value>> {
sender(&TRANSCRIPT_BACKGROUND_SENDER, 64, |payload| {
post_transcript_payload(payload, ASYNC_SEND_TIMEOUT);
Expand Down
23 changes: 21 additions & 2 deletions crates/jcode-telemetry-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ mod concurrency;
mod delivery;
mod lifecycle;
pub use concurrency::{ConcurrencySession, begin_concurrency_session};
// The live HTTP delivery path is inert under `cfg(test)`: payloads are captured
// into `TEST_EMITTED_PAYLOADS` instead of being queued or posted. Re-exporting
// these three unconditionally left the import unused in the `--all-targets`
// test build. Non-test builds are unaffected.
#[cfg(not(test))]
pub(crate) use delivery::{background_sender, post_payload, transcript_background_sender};
// Only the test module reaches for these two; re-exporting them unconditionally
// leaves production builds with unused-import warnings.
Expand All @@ -28,25 +33,37 @@ use lifecycle::emit_lifecycle_event;
use serde_json::Value;
use state_support::*;
use std::collections::HashSet;
use std::sync::Mutex;
#[cfg(not(test))]
use std::sync::OnceLock;
// Only the `#[cfg(not(test))]` delivery paths read the atomic flags and the
// non-blocking send errors; the test build asserts on fully-qualified paths.
#[cfg(not(test))]
use std::sync::atomic::{AtomicBool, Ordering};
#[cfg(not(test))]
use std::sync::mpsc::{SyncSender, TrySendError};
use std::sync::{Mutex, OnceLock};
use std::time::{Duration, Instant};

const TELEMETRY_ENDPOINT: &str = "https://telemetry.jcode.sh/v1/event";
const TRANSCRIPT_ENDPOINT: &str = "https://telemetry.jcode.sh/v1/transcript";
#[cfg(not(test))]
const ASYNC_SEND_TIMEOUT: Duration = Duration::from_secs(5);
#[cfg(not(test))]
const BACKGROUND_QUEUE_CAPACITY: usize = 2048;
const BLOCKING_INSTALL_TIMEOUT: Duration = Duration::from_millis(1200);
const BLOCKING_LIFECYCLE_TIMEOUT: Duration = Duration::from_millis(800);
const BLOCKING_FIRST_PROMPT_TIMEOUT: Duration = Duration::from_millis(500);
const TELEMETRY_SCHEMA_VERSION: u32 = 6;
const DEFAULT_DISCOVERY_ENDPOINT: &str = "https://api.jcode.sh/v1/discovery";
#[cfg(not(test))]
static TELEMETRY_PERMANENTLY_REJECTED: AtomicBool = AtomicBool::new(false);
#[cfg(not(test))]
static TELEMETRY_QUEUE_OVERFLOW_WARNED: AtomicBool = AtomicBool::new(false);
#[cfg(not(test))]
static TELEMETRY_BACKGROUND_SENDER: OnceLock<Option<SyncSender<Value>>> = OnceLock::new();
#[cfg(not(test))]
static TRANSCRIPT_BACKGROUND_SENDER: OnceLock<Option<SyncSender<Value>>> = OnceLock::new();
#[cfg(not(test))]
static TELEMETRY_HTTP_CLIENT: OnceLock<Option<reqwest::blocking::Client>> = OnceLock::new();
#[cfg(test)]
static TEST_EMITTED_PAYLOADS: Mutex<Vec<Value>> = Mutex::new(Vec::new());
Expand Down Expand Up @@ -1305,7 +1322,9 @@ fn send_transcript_payload(payload: Value) -> bool {
if let Ok(mut emitted) = TEST_EMITTED_PAYLOADS.lock() {
emitted.push(payload);
}
return true;
// Tail expression rather than `return true;`: this block is the function
// body in a test build, where `return` would be a needless return.
true
}
#[cfg(not(test))]
let Some(sender) = transcript_background_sender() else {
Expand Down
Loading