Skip to content

Commit 2efc501

Browse files
committed
Fix CI: formatting, git config in tests, case-sensitive policy test
1 parent 498996c commit 2efc501

8 files changed

Lines changed: 46 additions & 51 deletions

File tree

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Sorcery
22

3-
Hyperlinks for your editor (or IDE) that open on the right line. That's *Sorcery!*
3+
Editor/IDE hyperlinks that open to the line. That's *Sorcery!*
44

5-
# Sorcery enables:
5+
# Overview
6+
7+
Sorcery Desktop is a system tray app that enables srcuri (Sorcery) protocol links. The srcuri
8+
protocol makes links to files/lines work.
69

710
* Share editor links with other developers that open in their editor, on the correct line
811
* Command-Click a file-path in your terminal--it opens in your editor/IDE

src-tauri/src/commands/mod.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,12 +1275,7 @@ pub async fn rename_workspace(
12751275
new_name: String,
12761276
settings_manager: State<'_, Arc<SettingsManager>>,
12771277
) -> Result<(), String> {
1278-
rename_workspace_impl(
1279-
settings_manager.inner().as_ref(),
1280-
&name,
1281-
&new_name,
1282-
)
1283-
.await
1278+
rename_workspace_impl(settings_manager.inner().as_ref(), &name, &new_name).await
12841279
}
12851280

12861281
async fn rename_workspace_impl(
@@ -1649,8 +1644,7 @@ fn workspace_matches_lookup_name(
16491644
workspace: &crate::settings::WorkspaceConfig,
16501645
lookup_key: &str,
16511646
) -> bool {
1652-
identity::canonical_name_for_lookup(&identity::derive_workspace_name(workspace))
1653-
== lookup_key
1647+
identity::canonical_name_for_lookup(&identity::derive_workspace_name(workspace)) == lookup_key
16541648
}
16551649

16561650
async fn enrich_clone_dialog_data(
@@ -1667,9 +1661,7 @@ async fn enrich_clone_dialog_data(
16671661
let name_matches: Vec<_> = settings
16681662
.workspaces
16691663
.iter()
1670-
.filter(|workspace| {
1671-
identity::canonical_name_for_lookup(&workspace.name) == desired_lookup
1672-
})
1664+
.filter(|workspace| identity::canonical_name_for_lookup(&workspace.name) == desired_lookup)
16731665
.collect();
16741666

16751667
let same_remote_name_exists = normalized_remote.as_ref().is_some_and(|remote| {
@@ -1706,12 +1698,11 @@ async fn enrich_clone_dialog_data(
17061698

17071699
if different_remote_name_exists {
17081700
let suggested = derive_workspace_name_from_path(&target_path, &data.workspace_name);
1709-
let suggested =
1710-
if identity::canonical_name_for_lookup(&suggested) == desired_lookup {
1711-
format!("{suggested}-clone")
1712-
} else {
1713-
suggested
1714-
};
1701+
let suggested = if identity::canonical_name_for_lookup(&suggested) == desired_lookup {
1702+
format!("{suggested}-clone")
1703+
} else {
1704+
suggested
1705+
};
17151706

17161707
data.suggested_name = Some(suggested.clone());
17171708
data.clone_validation_message = Some(format!(
@@ -2054,9 +2045,8 @@ pub fn detect_browsers() -> Vec<crate::browser_detection::BrowserInfo> {
20542045
#[cfg(test)]
20552046
mod tests {
20562047
use super::{
2057-
change_workspace_folder_impl, ensure_workspace_policy_allows_path,
2058-
promote_workspace_impl, remove_workspace_impl, rename_workspace_impl,
2059-
resolve_conflict_open_target_path,
2048+
change_workspace_folder_impl, ensure_workspace_policy_allows_path, promote_workspace_impl,
2049+
remove_workspace_impl, rename_workspace_impl, resolve_conflict_open_target_path,
20602050
};
20612051
use crate::settings::{
20622052
Settings, SettingsManager, WorkspaceConfig, WorkspaceKind, WorkspaceState,

src-tauri/src/config_paths.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const APP_CONFIG_DIR: &str = "sorcery-desktop";
66
pub fn canonical_config_dir() -> Result<PathBuf> {
77
let config_dir = dirs::config_dir().context("Could not find config directory")?;
88
let sorcery_dir = config_dir.join(APP_CONFIG_DIR);
9-
std::fs::create_dir_all(&sorcery_dir).context("Failed to create sorcery-desktop config directory")?;
9+
std::fs::create_dir_all(&sorcery_dir)
10+
.context("Failed to create sorcery-desktop config directory")?;
1011
Ok(sorcery_dir)
1112
}

src-tauri/src/protocol_handler/git.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,14 @@ mod tests {
687687
let work = temp.path().join("work");
688688
std::fs::create_dir(&work).expect("create work dir");
689689
run(Command::new("git").arg("init"), &work);
690+
run(
691+
Command::new("git").args(["config", "user.email", "test@test.com"]),
692+
&work,
693+
);
694+
run(
695+
Command::new("git").args(["config", "user.name", "Test"]),
696+
&work,
697+
);
690698
std::fs::write(work.join("README.md"), "hello").expect("write README");
691699
run(Command::new("git").args(["add", "README.md"]), &work);
692700
run(Command::new("git").args(["commit", "-m", "init"]), &work);

src-tauri/src/protocol_handler/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,7 @@ impl ProtocolHandler {
236236
.and_then(|workspace| workspace.normalized_path)
237237
}
238238

239-
async fn resolve_workspace(
240-
&self,
241-
name: &str,
242-
remote: Option<&str>,
243-
) -> WorkspaceResolution {
239+
async fn resolve_workspace(&self, name: &str, remote: Option<&str>) -> WorkspaceResolution {
244240
let (remote_matches, key_matches) = self
245241
.settings_manager
246242
.resolve_workspace_by_name(name, remote)

src-tauri/src/settings/manager.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,7 @@ impl SettingsManager {
409409
PolicyDecision::Allowed => {}
410410
PolicyDecision::AdvisoryViolation(violation) => {
411411
let name = identity::derive_workspace_name(workspace);
412-
warn!(
413-
"Policy advisory for workspace '{}': {}",
414-
name, violation
415-
);
412+
warn!("Policy advisory for workspace '{}': {}", name, violation);
416413
}
417414
PolicyDecision::EnforcedViolation(violation) => {
418415
let name = identity::derive_workspace_name(workspace);
@@ -535,9 +532,8 @@ impl SettingsManager {
535532

536533
let mut key_to_indices: HashMap<String, Vec<usize>> = HashMap::new();
537534
for (index, workspace) in settings.workspaces.iter().enumerate() {
538-
let key = identity::canonical_name_for_lookup(
539-
&identity::derive_workspace_name(workspace),
540-
);
535+
let key =
536+
identity::canonical_name_for_lookup(&identity::derive_workspace_name(workspace));
541537
key_to_indices.entry(key).or_default().push(index);
542538
}
543539

@@ -637,8 +633,7 @@ impl SettingsManager {
637633
let canonical = identity::canonical_name_for_lookup(&name);
638634
let path = workspace.path.clone();
639635

640-
if let Some(existing_path) = seen_names.insert(canonical.clone(), path.clone())
641-
{
636+
if let Some(existing_path) = seen_names.insert(canonical.clone(), path.clone()) {
642637
return Err(SettingsValidationError::DuplicateWorkspaceName {
643638
workspace_name: canonical,
644639
first_path: existing_path,
@@ -658,9 +653,7 @@ impl SettingsManager {
658653
}
659654

660655
let name = identity::derive_workspace_name(workspace);
661-
if let Some(existing_name) =
662-
normalized_paths.insert(path.clone(), name.clone())
663-
{
656+
if let Some(existing_name) = normalized_paths.insert(path.clone(), name.clone()) {
664657
return Err(SettingsValidationError::DuplicateWorkspacePath {
665658
workspace_path: path.to_string_lossy().to_string(),
666659
first_workspace_name: existing_name,

src-tauri/src/settings/policy.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ impl WorkspacePolicy {
116116
.insert(key.clone(), PolicyMappingRule { expected_remote })
117117
.is_some()
118118
{
119-
return Err(PolicyBuildError::DuplicateWorkspaceName { workspace_name: key });
119+
return Err(PolicyBuildError::DuplicateWorkspaceName {
120+
workspace_name: key,
121+
});
120122
}
121123
}
122124

@@ -191,13 +193,13 @@ impl WorkspacePolicy {
191193
}
192194

193195
fn workspace_violation(&self, workspace: &WorkspaceConfig) -> Option<PolicyViolation> {
194-
let name = identity::canonical_name_for_lookup(
195-
&identity::derive_workspace_name(workspace),
196-
);
196+
let name = identity::canonical_name_for_lookup(&identity::derive_workspace_name(workspace));
197197

198198
if !self.mappings.is_empty() {
199199
let Some(rule) = self.mappings.get(&name) else {
200-
return Some(PolicyViolation::WorkspaceNameNotAllowed { workspace_name: name });
200+
return Some(PolicyViolation::WorkspaceNameNotAllowed {
201+
workspace_name: name,
202+
});
201203
};
202204

203205
if let Some(expected_remote) = rule.expected_remote.as_deref() {
@@ -230,7 +232,9 @@ impl WorkspacePolicy {
230232

231233
let Some(repo_identity) = workspace.repo_identity.as_ref() else {
232234
if workspace.workspace_kind == WorkspaceKind::Git {
233-
return Some(PolicyViolation::RemoteRequiredForWorkspace { workspace_name: name });
235+
return Some(PolicyViolation::RemoteRequiredForWorkspace {
236+
workspace_name: name,
237+
});
234238
}
235239
return None;
236240
};
@@ -461,7 +465,7 @@ mod tests {
461465
remote: Some("github.com/rails/rails".to_string()),
462466
},
463467
super::super::models::WorkspacePolicyMapping {
464-
name: "Rails".to_string(),
468+
name: "rails".to_string(),
465469
remote: Some("github.com/company/rails".to_string()),
466470
},
467471
],

src-tauri/tests/frontend_security_regression_tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ use std::path::PathBuf;
55

66
fn read_workspace_file(relative: &str) -> String {
77
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
8-
let base = manifest_dir
9-
.parent()
10-
.expect("workspace root");
8+
let base = manifest_dir.parent().expect("workspace root");
119
fs::read_to_string(base.join(relative)).expect("read file")
1210
}
1311

@@ -30,7 +28,9 @@ fn workspace_conflict_escapes_untrusted_fields_and_uses_bound_handlers() {
3028
assert!(html.contains("function escapeHtml(value)"));
3129
assert!(html.contains("const name = escapeHtml(candidate.name);"));
3230
assert!(html.contains("const workspacePath = escapeHtml(candidate.workspace_path);"));
33-
assert!(html.contains("const primaryRemote = escapeHtml(candidate.primary_remote || 'remote: not available');"));
31+
assert!(html.contains(
32+
"const primaryRemote = escapeHtml(candidate.primary_remote || 'remote: not available');"
33+
));
3434
assert!(html.contains("bindEvents();"));
3535
assert!(!html.contains("onclick=\""));
3636
assert!(!html.contains("onchange=\""));

0 commit comments

Comments
 (0)