|
| 1 | +// Static routing guards only: these do not establish live SSH/Peer/relay behavior. |
| 2 | +import assert from 'node:assert/strict'; |
| 3 | +import fs from 'node:fs'; |
| 4 | +import test from 'node:test'; |
| 5 | + |
| 6 | +const read = path => fs.readFileSync(new URL(`../${path}`, import.meta.url), 'utf8'); |
| 7 | +function between(source, start, end) { |
| 8 | + const from = source.indexOf(start); |
| 9 | + assert.notEqual(from, -1, `missing start marker: ${start}`); |
| 10 | + const to = source.indexOf(end, from + start.length); |
| 11 | + assert.notEqual(to, -1, `missing end marker: ${end}`); |
| 12 | + return source.slice(from, to); |
| 13 | +} |
| 14 | + |
| 15 | +for (const path of [ |
| 16 | + 'src/apps/desktop/src/api/terminal_api.rs', |
| 17 | + 'src/apps/cli/src/main.rs', |
| 18 | + 'src/apps/sdk-host/src/runtime.rs', |
| 19 | +]) { |
| 20 | + test(`static host PATH initialization routing: ${path}`, () => { |
| 21 | + const source = read(path); |
| 22 | + const policy = between(source, 'if let Ok(runtime_manager) = RuntimeManager::new()', 'TerminalApi::new('); |
| 23 | + const windows = between(policy, '#[cfg(windows)]', '#[cfg(not(windows))]'); |
| 24 | + assert.match(windows, /runtime_manager\.terminal_path_entries\(\)/); |
| 25 | + assert.match(windows, /set_session_path_entries\(/); |
| 26 | + assert.doesNotMatch(windows, /merged_path_env|std::env::var|\.env\.insert/); |
| 27 | + const other = policy.slice(policy.indexOf('#[cfg(not(windows))]')); |
| 28 | + assert.match(other, /std::env::var\("PATH"\)\.ok\(\)/); |
| 29 | + assert.match(other, /merged_path_env\(process_path\.as_deref\(\)\)/); |
| 30 | + assert.match(other, /\.env\.insert\("PATH"\.to_string\(\), path\)/); |
| 31 | + }); |
| 32 | +} |
| 33 | + |
| 34 | +test('static local builder routing keeps normalization Windows-only and reads baseline per create', () => { |
| 35 | + const source = read('src/crates/services/terminal/src/session/manager.rs'); |
| 36 | + const create = between(source, '// The OS PATH is read here', '// Inject shell integration'); |
| 37 | + assert.match(create, /#\[cfg\(windows\)\]\s*let baseline = session_path_baseline\(\)/); |
| 38 | + assert.match(create, /env: self\.build_session_env\(env, baseline\.as_deref\(\)\)/); |
| 39 | + const builder = between(source, ' fn build_session_env(', ' /// Inject shell integration scripts'); |
| 40 | + const windows = between(builder, '#[cfg(windows)]', '#[cfg(not(windows))]'); |
| 41 | + assert.match(windows, /request_path\.or\(config_path\)\.or_else/); |
| 42 | + assert.match(windows, /compose_session_path/); |
| 43 | + const other = builder.slice(builder.indexOf('#[cfg(not(windows))]')); |
| 44 | + assert.match(builder, /let mut session_env = self\.config\.env\.clone\(\)/); |
| 45 | + assert.match(other, /session_env\.extend\(request_env\)/); |
| 46 | + assert.doesNotMatch(other, /compose_session_path|to_string_lossy|take_session_path_entries/); |
| 47 | + assert.match(read('src/crates/services/terminal/src/config/mod.rs'), /#\[cfg\(windows\)\]\s*mod session_path;/); |
| 48 | +}); |
| 49 | + |
| 50 | +test('static desktop remote branch returns before local init and never forwards environment', () => { |
| 51 | + const source = read('src/apps/desktop/src/api/terminal_api.rs'); |
| 52 | + const create = between(source, 'pub async fn terminal_create(', 'pub async fn terminal_get('); |
| 53 | + const remote = between(create, 'if let Some(connection_id) = request', 'let api = state.get_or_init_api()'); |
| 54 | + assert.match(remote, /return spawn_remote_pty_session\(/); |
| 55 | + assert.doesNotMatch(remote, /request\.env|build_session_env|session_path_baseline|merged_path_env|set_session_path_entries/); |
| 56 | + const spawn = between(source, 'async fn spawn_remote_pty_session(', '#[tauri::command]'); |
| 57 | + assert.doesNotMatch(spawn, /request\.env|build_session_env|session_path_baseline|merged_path_env|set_session_path_entries/); |
| 58 | + assert.match(spawn, /terminal_manager\s*\.create_session\(/); |
| 59 | +}); |
| 60 | + |
| 61 | +test('static remote service ShellConfig keeps an empty local environment overlay', () => { |
| 62 | + const source = read('src/crates/services/services-integrations/src/remote_ssh/remote_terminal.rs'); |
| 63 | + const configs = [...source.matchAll(/let shell_config = ShellConfig\s*\{([\s\S]*?)\n\s*\};/g)]; |
| 64 | + assert.ok(configs.length > 0, 'remote PTY shell configuration must remain visible'); |
| 65 | + for (const [, config] of configs) assert.match(config, /env:\s*HashMap::new\(\)/); |
| 66 | + assert.doesNotMatch(source, /build_session_env|session_path_baseline|set_session_path_entries|terminal_path_entries|merged_path_env/); |
| 67 | +}); |
0 commit comments