Skip to content

Commit ab5b95d

Browse files
committed
chore: add rust debug
1 parent f6aa17f commit ab5b95d

File tree

3 files changed

+54
-11
lines changed

3 files changed

+54
-11
lines changed

.github/workflows/_ci-e2e-tauri.reusable.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,18 @@ jobs:
263263
pnpm run ${{ steps.gen-test.outputs.result }}
264264
fi
265265
266+
# Show Rust debug logs
267+
- name: 🔍 Show Rust Debug Logs
268+
if: always()
269+
shell: bash
270+
run: |
271+
echo "=== Rust Debug Log ==="
272+
if [ -f /tmp/tauri-debug.log ]; then
273+
cat /tmp/tauri-debug.log
274+
else
275+
echo "No Rust debug log found at /tmp/tauri-debug.log"
276+
fi
277+
266278
# Show comprehensive debug information on failure
267279
- name: 🐛 Debug Information on Failure
268280
if: failure()

e2e/test/tauri/api.spec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@ describe('Tauri API', () => {
2020
});
2121

2222
it('should execute commands with parameters', async () => {
23+
// First, check the current working directory
24+
console.log('🔍 Testing get_current_dir command');
25+
const dirResult = await browser.tauri.execute('get_current_dir');
26+
console.log('🔍 get_current_dir result:', JSON.stringify(dirResult, null, 2));
27+
expect(dirResult.success).to.be.true;
28+
console.log('🔍 Current working directory:', dirResult.data);
29+
2330
// Test file write command with parameters
24-
// Use a path in the current working directory instead of /tmp
25-
const testPath = `./tauri-test-${Date.now()}.txt`;
31+
// Use an absolute path to avoid working directory issues
32+
const testPath = `/tmp/tauri-test-${Date.now()}.txt`;
2633
const testContent = 'Hello, Tauri!';
2734

2835
console.log('🔍 Testing write_file command with path:', testPath);

fixtures/tauri-apps/basic/src-tauri/src/main.rs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,42 +108,63 @@ async fn take_screenshot(_options: Option<ScreenshotOptions>) -> Result<String,
108108

109109
#[tauri::command]
110110
async fn read_file(path: String, _options: Option<FileOperationOptions>) -> Result<String, String> {
111-
println!("🔍 Rust: read_file called with path: '{}'", path);
111+
let log_msg = format!("🔍 Rust: read_file called with path: '{}'\n", path);
112+
let _ = std::fs::write("/tmp/tauri-debug.log", log_msg.as_bytes());
113+
112114
let result = std::fs::read_to_string(&path).map_err(|e| {
113115
let error_msg = format!("Failed to read file '{}': {}", path, e);
114-
println!("🔍 Rust: read_file error: {}", error_msg);
116+
let log_msg = format!("🔍 Rust: read_file error: {}\n", error_msg);
117+
let _ = std::fs::write("/tmp/tauri-debug.log", log_msg.as_bytes());
115118
error_msg
116119
});
117120
if result.is_ok() {
118-
println!("🔍 Rust: read_file succeeded for path: '{}', content length: {}", path, result.as_ref().unwrap().len());
121+
let log_msg = format!("🔍 Rust: read_file succeeded for path: '{}', content length: {}\n", path, result.as_ref().unwrap().len());
122+
let _ = std::fs::write("/tmp/tauri-debug.log", log_msg.as_bytes());
119123
}
120124
result
121125
}
122126

123127
#[tauri::command]
124128
async fn write_file(path: String, contents: String, _options: Option<FileOperationOptions>) -> Result<(), String> {
125-
println!("🔍 Rust: write_file called with path: '{}', contents length: {}", path, contents.len());
129+
let log_msg = format!("🔍 Rust: write_file called with path: '{}', contents length: {}\n", path, contents.len());
130+
let _ = std::fs::write("/tmp/tauri-debug.log", log_msg.as_bytes());
131+
126132
std::fs::write(&path, contents).map_err(|e| {
127133
let error_msg = format!("Failed to write file '{}': {}", path, e);
128-
println!("🔍 Rust: write_file error: {}", error_msg);
134+
let log_msg = format!("🔍 Rust: write_file error: {}\n", error_msg);
135+
let _ = std::fs::write("/tmp/tauri-debug.log", log_msg.as_bytes());
129136
error_msg
130137
})?;
131-
println!("🔍 Rust: write_file succeeded for path: '{}'", path);
138+
139+
let log_msg = format!("🔍 Rust: write_file succeeded for path: '{}'\n", path);
140+
let _ = std::fs::write("/tmp/tauri-debug.log", log_msg.as_bytes());
132141
Ok(())
133142
}
134143

135144
#[tauri::command]
136145
async fn delete_file(path: String) -> Result<(), String> {
137-
println!("🔍 Rust: delete_file called with path: '{}'", path);
146+
let log_msg = format!("🔍 Rust: delete_file called with path: '{}'\n", path);
147+
let _ = std::fs::write("/tmp/tauri-debug.log", log_msg.as_bytes());
148+
138149
std::fs::remove_file(&path).map_err(|e| {
139150
let error_msg = format!("Failed to delete file '{}': {}", path, e);
140-
println!("🔍 Rust: delete_file error: {}", error_msg);
151+
let log_msg = format!("🔍 Rust: delete_file error: {}\n", error_msg);
152+
let _ = std::fs::write("/tmp/tauri-debug.log", log_msg.as_bytes());
141153
error_msg
142154
})?;
143-
println!("🔍 Rust: delete_file succeeded for path: '{}'", path);
155+
156+
let log_msg = format!("🔍 Rust: delete_file succeeded for path: '{}'\n", path);
157+
let _ = std::fs::write("/tmp/tauri-debug.log", log_msg.as_bytes());
144158
Ok(())
145159
}
146160

161+
#[tauri::command]
162+
async fn get_current_dir() -> Result<String, String> {
163+
std::env::current_dir()
164+
.map(|path| path.to_string_lossy().to_string())
165+
.map_err(|e| e.to_string())
166+
}
167+
147168
#[tauri::command]
148169
async fn get_platform_info() -> Result<PlatformInfo, String> {
149170
let mut sys = System::new_all();
@@ -190,6 +211,8 @@ async fn write_clipboard(content: String) -> Result<(), String> {
190211
}
191212

192213
fn main() {
214+
let _ = std::fs::write("/tmp/tauri-debug.log", "🔍 Rust: Tauri app starting...\n");
215+
193216
tauri::Builder::default()
194217
.invoke_handler(tauri::generate_handler![
195218
get_window_bounds,
@@ -202,6 +225,7 @@ fn main() {
202225
read_file,
203226
write_file,
204227
delete_file,
228+
get_current_dir,
205229
get_platform_info,
206230
read_clipboard,
207231
write_clipboard

0 commit comments

Comments
 (0)