Skip to content

Commit b97c445

Browse files
committed
refactor(theme): derive iris-specific styles locally
1 parent e0548b1 commit b97c445

File tree

5 files changed

+98
-9
lines changed

5 files changed

+98
-9
lines changed

src/studio/theme.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use crate::theme;
1111
use crate::theme::names::{gradients, styles, tokens};
1212
use crate::theme::{
1313
STYLE_AUTHOR, STYLE_COMMIT_HASH, STYLE_DIFF_ADDED, STYLE_DIFF_CONTEXT, STYLE_DIFF_HUNK,
14-
STYLE_DIFF_REMOVED, STYLE_FILE_PATH, STYLE_GIT_DELETED, STYLE_GIT_MODIFIED,
15-
STYLE_GIT_STAGED, STYLE_GIT_UNTRACKED, STYLE_MODE_INACTIVE, STYLE_TIMESTAMP,
14+
STYLE_DIFF_REMOVED, STYLE_FILE_PATH, STYLE_GIT_DELETED, STYLE_GIT_MODIFIED, STYLE_GIT_STAGED,
15+
STYLE_GIT_UNTRACKED, STYLE_MODE_INACTIVE, STYLE_TIMESTAMP,
1616
};
1717

1818
// ═══════════════════════════════════════════════════════════════════════════════

src/theme.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,26 @@ fn derive_iris_theme(theme: &mut Theme) {
5353
theme.register_default_token(TOKEN_CODE_HASH, theme.color(tokens::ACCENT_TERTIARY));
5454
theme.register_default_token(TOKEN_CODE_PATH, theme.color(tokens::ACCENT_SECONDARY));
5555

56-
theme.register_default_style(STYLE_COMMIT_HASH, OpalineStyle::fg(theme.color(TOKEN_CODE_HASH)));
57-
theme.register_default_style(STYLE_FILE_PATH, OpalineStyle::fg(theme.color(TOKEN_CODE_PATH)));
58-
theme.register_default_style(STYLE_TIMESTAMP, OpalineStyle::fg(theme.color(tokens::WARNING)));
59-
theme.register_default_style(STYLE_AUTHOR, OpalineStyle::fg(theme.color(tokens::TEXT_PRIMARY)));
60-
theme.register_default_style(STYLE_GIT_STAGED, OpalineStyle::fg(theme.color(TOKEN_GIT_STAGED)));
56+
theme.register_default_style(
57+
STYLE_COMMIT_HASH,
58+
OpalineStyle::fg(theme.color(TOKEN_CODE_HASH)),
59+
);
60+
theme.register_default_style(
61+
STYLE_FILE_PATH,
62+
OpalineStyle::fg(theme.color(TOKEN_CODE_PATH)),
63+
);
64+
theme.register_default_style(
65+
STYLE_TIMESTAMP,
66+
OpalineStyle::fg(theme.color(tokens::WARNING)),
67+
);
68+
theme.register_default_style(
69+
STYLE_AUTHOR,
70+
OpalineStyle::fg(theme.color(tokens::TEXT_PRIMARY)),
71+
);
72+
theme.register_default_style(
73+
STYLE_GIT_STAGED,
74+
OpalineStyle::fg(theme.color(TOKEN_GIT_STAGED)),
75+
);
6176
theme.register_default_style(
6277
STYLE_GIT_MODIFIED,
6378
OpalineStyle::fg(theme.color(TOKEN_GIT_MODIFIED)),
@@ -70,12 +85,18 @@ fn derive_iris_theme(theme: &mut Theme) {
7085
STYLE_GIT_DELETED,
7186
OpalineStyle::fg(theme.color(TOKEN_GIT_DELETED)),
7287
);
73-
theme.register_default_style(STYLE_DIFF_ADDED, OpalineStyle::fg(theme.color(TOKEN_DIFF_ADDED)));
88+
theme.register_default_style(
89+
STYLE_DIFF_ADDED,
90+
OpalineStyle::fg(theme.color(TOKEN_DIFF_ADDED)),
91+
);
7492
theme.register_default_style(
7593
STYLE_DIFF_REMOVED,
7694
OpalineStyle::fg(theme.color(TOKEN_DIFF_REMOVED)),
7795
);
78-
theme.register_default_style(STYLE_DIFF_HUNK, OpalineStyle::fg(theme.color(TOKEN_DIFF_HUNK)));
96+
theme.register_default_style(
97+
STYLE_DIFF_HUNK,
98+
OpalineStyle::fg(theme.color(TOKEN_DIFF_HUNK)),
99+
);
79100
theme.register_default_style(
80101
STYLE_DIFF_CONTEXT,
81102
OpalineStyle::fg(theme.color(TOKEN_DIFF_CONTEXT)),

tests/agent_tests.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ use git_iris::{
1212
git::GitRepo,
1313
};
1414
use std::env;
15+
use std::sync::{Mutex, MutexGuard, OnceLock};
1516
use tempfile::TempDir;
1617

18+
fn cwd_lock() -> MutexGuard<'static, ()> {
19+
static LOCK: OnceLock<Mutex<()>> = OnceLock::new();
20+
LOCK.get_or_init(|| Mutex::new(())).lock().expect("lock")
21+
}
22+
1723
fn create_test_context() -> (AgentContext, TempDir) {
1824
let temp_dir = TempDir::new().expect("Failed to create temporary directory");
1925
let repo_path = temp_dir.path().to_path_buf();
@@ -141,6 +147,7 @@ async fn test_agent_setup_service_creation() {
141147

142148
#[tokio::test]
143149
async fn test_agent_setup_service_from_temp_dir() {
150+
let _guard = cwd_lock();
144151
let temp_dir = TempDir::new().expect("Failed to create temporary directory");
145152
let repo_path = temp_dir.path().to_path_buf();
146153

@@ -199,6 +206,7 @@ async fn test_complete_agent_setup_workflow() {
199206
return;
200207
}
201208

209+
let _guard = cwd_lock();
202210
let temp_dir = TempDir::new().expect("Failed to create temporary directory");
203211
let repo_path = temp_dir.path().to_path_buf();
204212

tests/config_tests.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ use std::env;
66
use std::fs;
77
use std::path::Path;
88
use std::process::Command;
9+
use std::sync::{Mutex, MutexGuard, OnceLock};
910

1011
// Use our centralized test infrastructure
1112
#[path = "test_utils.rs"]
1213
mod test_utils;
1314
use test_utils::{MockDataBuilder, setup_git_repo};
1415

16+
fn cwd_lock() -> MutexGuard<'static, ()> {
17+
static LOCK: OnceLock<Mutex<()>> = OnceLock::new();
18+
LOCK.get_or_init(|| Mutex::new(())).lock().expect("lock")
19+
}
20+
1521
// Helper to verify git repo status
1622
fn is_git_repo(dir: &Path) -> bool {
1723
let status = Command::new("git")
@@ -25,6 +31,7 @@ fn is_git_repo(dir: &Path) -> bool {
2531

2632
#[test]
2733
fn test_project_config_security() {
34+
let _guard = cwd_lock();
2835
// Set up a git repository using our centralized infrastructure
2936
let (temp_dir, _git_repo) = setup_git_repo();
3037

tests/theme_tests.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use std::sync::{Mutex, MutexGuard, OnceLock};
2+
3+
use git_iris::theme;
4+
use opaline::{OpalineColor, Theme};
5+
6+
fn theme_lock() -> MutexGuard<'static, ()> {
7+
static LOCK: OnceLock<Mutex<()>> = OnceLock::new();
8+
LOCK.get_or_init(|| Mutex::new(())).lock().expect("lock")
9+
}
10+
11+
fn base_theme() -> Theme {
12+
Theme::builder("Derived Test")
13+
.token("text.primary", OpalineColor::new(240, 240, 240))
14+
.token("text.muted", OpalineColor::new(120, 120, 120))
15+
.token("text.dim", OpalineColor::new(90, 90, 90))
16+
.token("accent.primary", OpalineColor::new(225, 53, 255))
17+
.token("accent.secondary", OpalineColor::new(128, 255, 234))
18+
.token("accent.tertiary", OpalineColor::new(255, 106, 193))
19+
.token("success", OpalineColor::new(80, 250, 123))
20+
.token("warning", OpalineColor::new(241, 250, 140))
21+
.token("error", OpalineColor::new(255, 99, 99))
22+
.token("info", OpalineColor::new(100, 200, 255))
23+
.build()
24+
}
25+
26+
#[test]
27+
fn theme_wrapper_derives_iris_specific_tokens_and_styles() {
28+
let _guard = theme_lock();
29+
let previous = theme::current();
30+
31+
theme::set_theme(base_theme());
32+
let current = theme::current();
33+
34+
assert_eq!(
35+
current.color("git.staged"),
36+
current.color(theme::names::tokens::SUCCESS)
37+
);
38+
assert_eq!(
39+
current.color("code.hash"),
40+
current.color(theme::names::tokens::ACCENT_TERTIARY)
41+
);
42+
assert_eq!(
43+
current.color("mode.inactive"),
44+
current.color(theme::names::tokens::TEXT_MUTED)
45+
);
46+
assert!(current.has_style("git_staged"));
47+
assert!(current.has_style("diff_removed"));
48+
assert!(current.has_style("commit_hash"));
49+
assert!(current.has_style("file_path"));
50+
assert!(current.has_style("mode_inactive"));
51+
52+
theme::set_theme((*previous).clone());
53+
}

0 commit comments

Comments
 (0)