flyshell 1.5.3__tar.gz → 1.5.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. {flyshell-1.5.3/src/flyshell.egg-info → flyshell-1.5.5}/PKG-INFO +1 -1
  2. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/__init__.py +0 -1
  3. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/builtin/utils.py +11 -1
  4. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/constants.py +3 -3
  5. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/core/directory.py +0 -2
  6. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/main.py +2 -0
  7. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/native/diskops_bridge.py +1 -1
  8. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/startup/loader.py +25 -6
  9. {flyshell-1.5.3 → flyshell-1.5.5/src/flyshell.egg-info}/PKG-INFO +1 -1
  10. flyshell-1.5.5/tests/test_loader.py +157 -0
  11. {flyshell-1.5.3 → flyshell-1.5.5}/tests/test_utils.py +7 -0
  12. flyshell-1.5.3/tests/test_loader.py +0 -55
  13. {flyshell-1.5.3 → flyshell-1.5.5}/LICENSE +0 -0
  14. {flyshell-1.5.3 → flyshell-1.5.5}/MANIFEST.in +0 -0
  15. {flyshell-1.5.3 → flyshell-1.5.5}/README.md +0 -0
  16. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/diskops.c +0 -0
  17. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/posix/cat.c +0 -0
  18. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/posix/cp.c +0 -0
  19. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/posix/dir.c +0 -0
  20. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/posix/mkdir.c +0 -0
  21. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/posix/mv.c +0 -0
  22. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/posix/rename.c +0 -0
  23. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/posix/rm.c +0 -0
  24. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/posix/rmdir.c +0 -0
  25. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/posix/touch.c +0 -0
  26. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/shared/dir_types.c +0 -0
  27. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/shared/dir_types.h +0 -0
  28. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/shared/native_errors.h +0 -0
  29. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/shared/win32_utf.h +0 -0
  30. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/win32/cat.c +0 -0
  31. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/win32/cp.c +0 -0
  32. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/win32/dir.c +0 -0
  33. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/win32/mkdir.c +0 -0
  34. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/win32/mv.c +0 -0
  35. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/win32/rename.c +0 -0
  36. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/win32/rm.c +0 -0
  37. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/win32/rmdir.c +0 -0
  38. {flyshell-1.5.3 → flyshell-1.5.5}/c_src/diskops/win32/touch.c +0 -0
  39. {flyshell-1.5.3 → flyshell-1.5.5}/pyproject.toml +0 -0
  40. {flyshell-1.5.3 → flyshell-1.5.5}/setup.cfg +0 -0
  41. {flyshell-1.5.3 → flyshell-1.5.5}/setup.py +0 -0
  42. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/abstract/__init__.py +0 -0
  43. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/abstract/base_cmd.py +0 -0
  44. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/abstract/base_plugin.py +0 -0
  45. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/abstract/parent_cmd.py +0 -0
  46. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/accounts/__init__.py +0 -0
  47. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/accounts/auth.py +0 -0
  48. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/bin/__init__.py +0 -0
  49. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/builtin/__init__.py +0 -0
  50. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/builtin/fs.py +0 -0
  51. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/builtin/pkg.py +0 -0
  52. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/builtin/system.py +0 -0
  53. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/core/__init__.py +0 -0
  54. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/core/console.py +0 -0
  55. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/core/data.py +0 -0
  56. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/native/__init__.py +0 -0
  57. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/native/diskops_handler.py +0 -0
  58. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/native/legacy/__init__.py +0 -0
  59. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/native/legacy/diskops.py +0 -0
  60. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/startup/__init__.py +0 -0
  61. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/startup/deps.py +0 -0
  62. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell/startup/env.py +0 -0
  63. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell.egg-info/SOURCES.txt +0 -0
  64. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell.egg-info/dependency_links.txt +0 -0
  65. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell.egg-info/entry_points.txt +0 -0
  66. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell.egg-info/requires.txt +0 -0
  67. {flyshell-1.5.3 → flyshell-1.5.5}/src/flyshell.egg-info/top_level.txt +0 -0
  68. {flyshell-1.5.3 → flyshell-1.5.5}/tests/test_auth.py +0 -0
  69. {flyshell-1.5.3 → flyshell-1.5.5}/tests/test_data.py +0 -0
  70. {flyshell-1.5.3 → flyshell-1.5.5}/tests/test_deps.py +0 -0
  71. {flyshell-1.5.3 → flyshell-1.5.5}/tests/test_directory.py +0 -0
  72. {flyshell-1.5.3 → flyshell-1.5.5}/tests/test_diskops_ext.py +0 -0
  73. {flyshell-1.5.3 → flyshell-1.5.5}/tests/test_diskops_lgc.py +0 -0
  74. {flyshell-1.5.3 → flyshell-1.5.5}/tests/test_env.py +0 -0
  75. {flyshell-1.5.3 → flyshell-1.5.5}/tests/test_fs.py +0 -0
  76. {flyshell-1.5.3 → flyshell-1.5.5}/tests/test_pkg.py +0 -0
  77. {flyshell-1.5.3 → flyshell-1.5.5}/tests/test_security.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flyshell
3
- Version: 1.5.3
3
+ Version: 1.5.5
4
4
  Summary: A modular, zero-dependency command-line environment in Python.
5
5
  License-Expression: MIT
6
6
  Requires-Python: >=3.10
@@ -7,7 +7,6 @@ try:
7
7
  except ImportError:
8
8
  BasePlugin = None
9
9
  __all__ = []
10
- pass
11
10
 
12
11
 
13
12
  try:
@@ -4,7 +4,9 @@ from flyshell import constants as c
4
4
  from flyshell.abstract.base_cmd import BaseCmd
5
5
  from flyshell.core import data
6
6
 
7
+ import codecs
7
8
  import os
9
+ import re
8
10
  import signal
9
11
  import subprocess
10
12
  import sys
@@ -22,6 +24,11 @@ class Clear(BaseCmd):
22
24
  return (0, c.CLEAR_SCREEN)
23
25
 
24
26
 
27
+ _ESCAPE_SEQ_RE = re.compile(
28
+ r"\\(n|r|t|b|f|a|v|\\|'|\"|[0-7]{1,3}|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})"
29
+ )
30
+
31
+
25
32
  class Echo(BaseCmd):
26
33
  name = "echo"
27
34
  description = "Print arguments to terminal"
@@ -32,7 +39,10 @@ class Echo(BaseCmd):
32
39
  def execute(self, args):
33
40
  text = " ".join(args)
34
41
  try:
35
- text = text.encode("utf-8").decode("unicode_escape")
42
+ text = _ESCAPE_SEQ_RE.sub(
43
+ lambda m: codecs.decode(m.group(0), "unicode_escape"),
44
+ text,
45
+ )
36
46
  except Exception:
37
47
  pass
38
48
  return (0, f"\n{text}\n")
@@ -5,9 +5,9 @@ import os
5
5
  import platform
6
6
  import time
7
7
 
8
- BUILD = 177
9
- VERFULL = "1.5.3d"
10
- VERSION = "1.5.3"
8
+ BUILD = 186
9
+ VERFULL = "1.5.5d"
10
+ VERSION = "1.5.5"
11
11
 
12
12
 
13
13
  def _resolve_app_dir() -> Path:
@@ -198,8 +198,6 @@ def _execute_single(raw_cmd: str) -> int:
198
198
  print("Returning to main Flyshell interface...\n")
199
199
  return 1
200
200
  finally:
201
- if hasattr(plugin, "on_unload"):
202
- plugin.on_unload()
203
201
  if (
204
202
  hasattr(plugin, "save_storage")
205
203
  and getattr(plugin, "storage", {}) != storage_before
@@ -131,6 +131,8 @@ def main():
131
131
  print(f"Line: {last_frame[1]}")
132
132
  print(f"Exception message: '{e}'")
133
133
  sys.exit(1)
134
+ finally:
135
+ loader.unload_plugins()
134
136
 
135
137
 
136
138
  if __name__ == "__main__":
@@ -46,4 +46,4 @@ def translate_error(code: int, target: str = "") -> tuple[int, str]:
46
46
  target_str = f"for '{target}'" if target else ""
47
47
  if target_str:
48
48
  return (1, f"\n{category}: {default_msg} {target_str}\n")
49
- return (1, f"\n{category}: {default_msg}.")
49
+ return (1, f"\n{category}: {default_msg}.\n")
@@ -50,7 +50,11 @@ def scan_plugins(plugin_folder=None):
50
50
  module = importlib.util.module_from_spec(spec)
51
51
  spec.loader.exec_module(module)
52
52
  for _, obj in inspect.getmembers(module, inspect.isclass):
53
- if issubclass(obj, BasePlugin) and obj is not BasePlugin:
53
+ if (
54
+ issubclass(obj, BasePlugin)
55
+ and obj is not BasePlugin
56
+ and obj.__module__ == module.__name__
57
+ ):
54
58
  resolved_name = getattr(obj, "identifier", None) or default_name
55
59
  if resolved_name in RESERVED_NAMES:
56
60
  print(
@@ -73,9 +77,8 @@ def scan_plugins(plugin_folder=None):
73
77
  for mk in missing_keys:
74
78
  print(f"{default_name}_{mk}=<your_key>")
75
79
  print("You can do this once Flyshell has booted.")
76
- instance = obj(ctx)
77
80
  candidates.setdefault(resolved_name, []).append(
78
- (instance, file_path)
81
+ (obj, ctx, file_path)
79
82
  )
80
83
  break
81
84
  except Exception as e:
@@ -85,7 +88,7 @@ def scan_plugins(plugin_folder=None):
85
88
  first_print = True
86
89
  for name, entries in candidates.items():
87
90
  if len(entries) > 1:
88
- paths = "\n - ".join(str(path) for _, path in entries)
91
+ paths = "\n - ".join(str(path) for _, _, path in entries)
89
92
  print(
90
93
  f"\n⚠️ Collision Error - Multiple plugins named '{name}' detected: {paths}"
91
94
  )
@@ -93,7 +96,13 @@ def scan_plugins(plugin_folder=None):
93
96
  "The above plugins will not be loaded. Please rename them to unique names."
94
97
  )
95
98
  continue
96
- instance, _ = entries[0]
99
+ obj, ctx, _ = entries[0]
100
+ try:
101
+ instance = obj(ctx)
102
+ except Exception as e:
103
+ print(f"\n⚠️ Plugin Failure - Failed to initialise '{name}'")
104
+ print(f"Exception code: {e}, Flyshell will still launch.")
105
+ continue
97
106
  c.PLUGINS[name] = instance
98
107
  if first_print:
99
108
  print("\nInstalled Plugins:")
@@ -106,7 +115,7 @@ def scan_plugins(plugin_folder=None):
106
115
  print("\nNo plugins loaded.")
107
116
 
108
117
 
109
- def build_context(plugin_name, default_name, file_path=None):
118
+ def build_context(plugin_name, default_name, file_path=None) -> dict:
110
119
  plugin_storage = data.get_all_plugin_data(plugin_name)
111
120
  api_keys = env.get_plugin_api_keys(str(default_name))
112
121
  context = {
@@ -175,3 +184,13 @@ def check_all_plugin_dependencies() -> Dict[str, List[str]]:
175
184
  if not plugins_with_deps:
176
185
  print("✅ No third-party dependencies required for any loaded plugins.")
177
186
  return all_missing
187
+
188
+
189
+ def unload_plugins():
190
+ for identifier, plugin in list(c.PLUGINS.items()):
191
+ try:
192
+ if hasattr(plugin, "on_unload"):
193
+ plugin.on_unload()
194
+ except Exception as e:
195
+ print(f"\n⚠️ Plugin Unload Error - '{identifier}': {e}")
196
+ c.PLUGINS.clear()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flyshell
3
- Version: 1.5.3
3
+ Version: 1.5.5
4
4
  Summary: A modular, zero-dependency command-line environment in Python.
5
5
  License-Expression: MIT
6
6
  Requires-Python: >=3.10
@@ -0,0 +1,157 @@
1
+ # tests/test_loader.py
2
+
3
+ from flyshell import constants as c
4
+ from flyshell.abstract.base_plugin import BasePlugin
5
+ from flyshell.core import directory
6
+ from flyshell.startup import loader
7
+
8
+
9
+ def test_loader_rejects_command_name_collision(tmp_path, monkeypatch):
10
+ bad_plugin = tmp_path / "sys.py"
11
+ bad_plugin.write_text(
12
+ "from flyshell.core.base_plugin import BasePlugin\n"
13
+ "class SysPlugin(BasePlugin):\n"
14
+ " def execute(self, args): pass\n"
15
+ )
16
+ monkeypatch.setattr(c, "USER_PLUGIN_DIR", tmp_path)
17
+ loader.scan_plugins(plugin_folder=tmp_path)
18
+ assert "sys" not in c.PLUGINS
19
+
20
+
21
+ def test_loader_discovers_and_instantiates_valid_plugin(tmp_path, monkeypatch):
22
+ valid_plugin = tmp_path / "sample.py"
23
+ valid_plugin.write_text(
24
+ "from flyshell.abstract.base_plugin import BasePlugin\n"
25
+ "class SamplePlugin(BasePlugin):\n"
26
+ " name = 'Sample Tool'\n"
27
+ " description = 'Testing tool'\n"
28
+ " def execute(self, args):\n"
29
+ " return (0, 'done')\n"
30
+ )
31
+ monkeypatch.setattr(c, "USER_PLUGIN_DIR", tmp_path)
32
+ loader.scan_plugins(plugin_folder=tmp_path)
33
+ assert "sample" in c.PLUGINS
34
+ plugin_instance = c.PLUGINS["sample"]
35
+ assert isinstance(plugin_instance, BasePlugin)
36
+ assert plugin_instance.name == "Sample Tool"
37
+
38
+
39
+ def test_loader_handles_broken_plugin_gracefully(tmp_path, monkeypatch):
40
+ broken_plugin = tmp_path / "broken.py"
41
+ broken_plugin.write_text("import non_existent_library_12345\n")
42
+ monkeypatch.setattr(c, "USER_PLUGIN_DIR", tmp_path)
43
+ loader.scan_plugins(plugin_folder=tmp_path)
44
+ assert "broken" not in c.PLUGINS
45
+
46
+
47
+ def test_loader_does_not_execute_code_in_reserved_plugin(tmp_path, monkeypatch):
48
+ sentinel = tmp_path / "sentinel.txt"
49
+ bad_plugin = tmp_path / "cd.py"
50
+ bad_plugin.write_text(
51
+ f"from pathlib import Path\nPath('{sentinel.as_posix()}').write_text('executed')\n"
52
+ )
53
+ monkeypatch.setattr(c, "USER_PLUGIN_DIR", tmp_path)
54
+ loader.scan_plugins(plugin_folder=tmp_path)
55
+ assert "cd" not in c.PLUGINS
56
+ assert not sentinel.exists()
57
+
58
+
59
+ def test_loader_does_not_call_on_load_for_duplicate_plugins(tmp_path, monkeypatch):
60
+ sentinel = tmp_path / "on_load_called.txt"
61
+ for fname in ("plug_a.py", "plug_b.py"):
62
+ (tmp_path / fname).write_text(
63
+ "from pathlib import Path\n"
64
+ "from flyshell.abstract.base_plugin import BasePlugin\n"
65
+ "class DupPlugin(BasePlugin):\n"
66
+ " identifier = 'shared_id'\n"
67
+ " def on_load(self):\n"
68
+ f" Path('{sentinel.as_posix()}').write_text('called')\n"
69
+ " def execute(self, args): pass\n"
70
+ )
71
+ monkeypatch.setattr(c, "USER_PLUGIN_DIR", tmp_path)
72
+ loader.scan_plugins(plugin_folder=tmp_path)
73
+ assert "shared_id" not in c.PLUGINS
74
+ assert not sentinel.exists()
75
+
76
+
77
+ def test_execute_single_does_not_unload_plugin(monkeypatch):
78
+ events = []
79
+
80
+ class LifecyclePlugin(BasePlugin):
81
+ def on_load(self):
82
+ events.append("load")
83
+
84
+ def execute(self, args):
85
+ events.append("execute")
86
+ return 0
87
+
88
+ def on_unload(self):
89
+ events.append("unload")
90
+
91
+ monkeypatch.setattr(directory, "log", lambda cmd: None)
92
+ plugin = LifecyclePlugin({"plugin_name": "life"})
93
+ monkeypatch.setattr(c, "PLUGINS", {"life": plugin})
94
+ code = directory._execute_single("life")
95
+ assert code == 0
96
+ assert events == ["load", "execute"]
97
+
98
+
99
+ def test_unload_plugins_calls_on_unload_and_clears_registry(monkeypatch):
100
+ unloaded = []
101
+
102
+ class BrokenUnloadPlugin(BasePlugin):
103
+ def execute(self, args):
104
+ return 0
105
+
106
+ def on_unload(self):
107
+ unloaded.append("broken")
108
+ raise RuntimeError("cleanup failed")
109
+
110
+ class HealthyUnloadPlugin(BasePlugin):
111
+ def execute(self, args):
112
+ return 0
113
+
114
+ def on_unload(self):
115
+ unloaded.append("healthy")
116
+
117
+ p1 = BrokenUnloadPlugin({"plugin_name": "p1"})
118
+ p2 = HealthyUnloadPlugin({"plugin_name": "p2"})
119
+ monkeypatch.setattr(c, "PLUGINS", {"p1": p1, "p2": p2})
120
+ loader.unload_plugins()
121
+ assert unloaded == ["broken", "healthy"]
122
+ assert c.PLUGINS == {}
123
+
124
+
125
+ def test_loader_ignores_imported_plugin_subclasses(tmp_path, monkeypatch):
126
+ helper_file = tmp_path / "_helper.py"
127
+ helper_file.write_text(
128
+ "from flyshell.abstract.base_plugin import BasePlugin\n"
129
+ "class ImportedPlugin(BasePlugin):\n"
130
+ " identifier = 'imported_one'\n"
131
+ " def execute(self, args): pass\n"
132
+ )
133
+ main_file = tmp_path / "real_plug.py"
134
+ main_file.write_text(
135
+ "from _helper import ImportedPlugin\n"
136
+ "class RealPlugin(ImportedPlugin):\n"
137
+ " identifier = 'real_one'\n"
138
+ " def execute(self, args): pass\n"
139
+ )
140
+ monkeypatch.setattr(c, "USER_PLUGIN_DIR", tmp_path)
141
+ loader.scan_plugins(plugin_folder=tmp_path)
142
+ assert "real_one" in c.PLUGINS
143
+ assert "imported_one" not in c.PLUGINS
144
+
145
+
146
+ def test_loader_handles_on_load_exception_gracefully(tmp_path, monkeypatch):
147
+ crashing_plugin = tmp_path / "crash_init.py"
148
+ crashing_plugin.write_text(
149
+ "from flyshell.abstract.base_plugin import BasePlugin\n"
150
+ "class CrashInitPlugin(BasePlugin):\n"
151
+ " def on_load(self):\n"
152
+ " raise RuntimeError('boom in on_load')\n"
153
+ " def execute(self, args): pass\n"
154
+ )
155
+ monkeypatch.setattr(c, "USER_PLUGIN_DIR", tmp_path)
156
+ loader.scan_plugins(plugin_folder=tmp_path)
157
+ assert "crash_init" not in c.PLUGINS
@@ -14,6 +14,13 @@ def test_echo_output_and_escape_characters():
14
14
  assert "Line1\nLine2" in msg
15
15
 
16
16
 
17
+ def test_echo_non_ascii_characters():
18
+ cmd = utils.Echo()
19
+ code, msg = cmd.execute([r"héllo 🚀\nworld"])
20
+ assert code == 0
21
+ assert "héllo 🚀\nworld" in msg
22
+
23
+
17
24
  def test_clear_returns_escape_code():
18
25
  cmd = utils.Clear()
19
26
  code, msg = cmd.execute([])
@@ -1,55 +0,0 @@
1
- # tests/test_loader.py
2
-
3
- from flyshell import constants as c
4
- from flyshell.abstract.base_plugin import BasePlugin
5
- from flyshell.startup import loader
6
-
7
-
8
- def test_loader_rejects_command_name_collision(tmp_path, monkeypatch):
9
- bad_plugin = tmp_path / "sys.py"
10
- bad_plugin.write_text(
11
- "from flyshell.core.base_plugin import BasePlugin\n"
12
- "class SysPlugin(BasePlugin):\n"
13
- " def execute(self, args): pass\n"
14
- )
15
- monkeypatch.setattr(c, "USER_PLUGIN_DIR", tmp_path)
16
- loader.scan_plugins(plugin_folder=tmp_path)
17
- assert "sys" not in c.PLUGINS
18
-
19
-
20
- def test_loader_discovers_and_instantiates_valid_plugin(tmp_path, monkeypatch):
21
- valid_plugin = tmp_path / "sample.py"
22
- valid_plugin.write_text(
23
- "from flyshell.abstract.base_plugin import BasePlugin\n"
24
- "class SamplePlugin(BasePlugin):\n"
25
- " name = 'Sample Tool'\n"
26
- " description = 'Testing tool'\n"
27
- " def execute(self, args):\n"
28
- " return (0, 'done')\n"
29
- )
30
- monkeypatch.setattr(c, "USER_PLUGIN_DIR", tmp_path)
31
- loader.scan_plugins(plugin_folder=tmp_path)
32
- assert "sample" in c.PLUGINS
33
- plugin_instance = c.PLUGINS["sample"]
34
- assert isinstance(plugin_instance, BasePlugin)
35
- assert plugin_instance.name == "Sample Tool"
36
-
37
-
38
- def test_loader_handles_broken_plugin_gracefully(tmp_path, monkeypatch):
39
- broken_plugin = tmp_path / "broken.py"
40
- broken_plugin.write_text("import non_existent_library_12345\n")
41
- monkeypatch.setattr(c, "USER_PLUGIN_DIR", tmp_path)
42
- loader.scan_plugins(plugin_folder=tmp_path)
43
- assert "broken" not in c.PLUGINS
44
-
45
-
46
- def test_loader_does_not_execute_code_in_reserved_plugin(tmp_path, monkeypatch):
47
- sentinel = tmp_path / "sentinel.txt"
48
- bad_plugin = tmp_path / "cd.py"
49
- bad_plugin.write_text(
50
- f"from pathlib import Path\nPath('{sentinel.as_posix()}').write_text('executed')\n"
51
- )
52
- monkeypatch.setattr(c, "USER_PLUGIN_DIR", tmp_path)
53
- loader.scan_plugins(plugin_folder=tmp_path)
54
- assert "cd" not in c.PLUGINS
55
- assert not sentinel.exists()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes