From dea3bcb0e422e62d7f23e60bccbfb66c2cf58bf1 Mon Sep 17 00:00:00 2001 From: kuddev Date: Wed, 16 Sep 2026 08:54:37 +0800 Subject: [PATCH] fix(ci): restore portable session recovery checks --- nebula_app/src/platform/pi_session.rs | 2 +- scripts/tests/test_pi_session_guest.py | 30 +++++++++++++++++--------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/nebula_app/src/platform/pi_session.rs b/nebula_app/src/platform/pi_session.rs index 9405bf0..05e4e58 100644 --- a/nebula_app/src/platform/pi_session.rs +++ b/nebula_app/src/platform/pi_session.rs @@ -123,7 +123,7 @@ pub(crate) fn resolve( { return resolve_in(Path::new(""), saved); } - let home = dirs::home_dir().ok_or(ResolveError::Unavailable)?; + let home = super::dirs::home_dir().ok_or(ResolveError::Unavailable)?; let cwd = Path::new(cwd); let config = std::env::var_os("PI_CODING_AGENT_DIR") .map(|path| expand_directory(Path::new(&path), cwd, &home)) diff --git a/scripts/tests/test_pi_session_guest.py b/scripts/tests/test_pi_session_guest.py index 944df98..2e2b8e6 100644 --- a/scripts/tests/test_pi_session_guest.py +++ b/scripts/tests/test_pi_session_guest.py @@ -1,7 +1,7 @@ """Execute the actual guest metadata script against isolated native-format files.""" import json import os -from pathlib import Path +from pathlib import Path, PurePosixPath import shutil import subprocess import tempfile @@ -16,14 +16,22 @@ class GuestSessionMetadataTests(unittest.TestCase): def setUp(self): self.temporary = tempfile.TemporaryDirectory() self.addCleanup(self.temporary.cleanup) - self.root = Path(self.temporary.name) + self.root = Path(self.temporary.name).resolve() + # The guest script consumes shell paths, including when the host is + # Windows. Resolve the shell's physical root once so macOS /var aliases + # and Git Bash mount paths also match the script's own PWD. + self.guest_root = PurePosixPath(subprocess.check_output( + ['sh', '-c', 'pwd -P'], cwd=self.root, text=True, timeout=4).strip()) self.cwd = self.root / 'work with spaces' self.cwd.mkdir() self.config = self.root / 'agent' self.config.mkdir() - self.env = {**os.environ, 'PI_CODING_AGENT_DIR': str(self.config)} + self.env = {**os.environ, 'PI_CODING_AGENT_DIR': self.guest_path(self.config)} self.env.pop('PI_CODING_AGENT_SESSION_DIR', None) + def guest_path(self, path): + return str(self.guest_root.joinpath(*Path(path).relative_to(self.root).parts)) + def native_file(self, root, name='arbitrary name.jsonl', session=SESSION): root.mkdir(parents=True, exist_ok=True) path = root / name @@ -32,17 +40,19 @@ class GuestSessionMetadataTests(unittest.TestCase): return path def run_script(self, exact=''): - result = subprocess.run(['sh', str(SCRIPT), SESSION, str(exact)], cwd=self.cwd, - env=self.env, capture_output=True, text=True, timeout=4) + exact = self.guest_path(exact) if exact else '' + result = subprocess.run(['sh', '-s', '--', SESSION, exact], cwd=self.cwd, + input=SCRIPT.read_text(encoding='utf-8'), env=self.env, + capture_output=True, text=True, timeout=4) self.assertNotIn('PRIVATE-FIXTURE-BODY', result.stdout + result.stderr) return result def test_exact_file_does_not_require_default_directory_or_json_parser(self): path = self.native_file(self.root / 'outside') - self.env['PI_CODING_AGENT_DIR'] = str(self.root / 'missing-config') + self.env['PI_CODING_AGENT_DIR'] = self.guest_path(self.root / 'missing-config') result = self.run_script(path) self.assertEqual(result.returncode, 0, result.stderr) - self.assertEqual(result.stdout.split('\t')[0], str(path)) + self.assertEqual(result.stdout.split('\t')[0], self.guest_path(path)) def test_relative_project_setting_overrides_global_setting(self): (self.config / 'settings.json').write_text('{"sessionDir":"missing"}', encoding='utf-8') @@ -52,17 +62,17 @@ class GuestSessionMetadataTests(unittest.TestCase): path = self.native_file(self.cwd / 'project sessions') result = self.run_script() self.assertEqual(result.returncode, 0, result.stderr) - self.assertEqual(result.stdout.split('\t')[0], str(path)) + self.assertEqual(result.stdout.split('\t')[0], self.guest_path(path)) def test_environment_override_and_missing_exact_path_search_native_headers(self): directory = self.root / 'overridden sessions' - self.env['PI_CODING_AGENT_SESSION_DIR'] = str(directory) + self.env['PI_CODING_AGENT_SESSION_DIR'] = self.guest_path(directory) path = self.native_file(directory) self.native_file(directory, 'unrelated.jsonl', 'aaaaaaaa-bbbb-4ccc-8ddd-eeeeeeeeeeee') result = self.run_script(self.root / 'old-location.jsonl') self.assertEqual(result.returncode, 0, result.stderr) self.assertEqual(len(result.stdout.splitlines()), 1) - self.assertEqual(result.stdout.split('\t')[0], str(path)) + self.assertEqual(result.stdout.split('\t')[0], self.guest_path(path)) def test_duplicate_native_ids_are_both_returned_for_ambiguity_detection(self): self.native_file(self.config / 'sessions', 'first.jsonl')