flyshell 1.5.2__tar.gz → 1.5.4__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.2/src/flyshell.egg-info → flyshell-1.5.4}/PKG-INFO +6 -5
  2. {flyshell-1.5.2 → flyshell-1.5.4}/README.md +5 -4
  3. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/abstract/base_plugin.py +10 -0
  4. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/constants.py +3 -3
  5. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/core/data.py +11 -0
  6. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/core/directory.py +6 -3
  7. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/main.py +2 -0
  8. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/startup/loader.py +25 -6
  9. {flyshell-1.5.2 → flyshell-1.5.4/src/flyshell.egg-info}/PKG-INFO +6 -5
  10. flyshell-1.5.4/tests/test_loader.py +157 -0
  11. flyshell-1.5.2/tests/test_loader.py +0 -55
  12. {flyshell-1.5.2 → flyshell-1.5.4}/LICENSE +0 -0
  13. {flyshell-1.5.2 → flyshell-1.5.4}/MANIFEST.in +0 -0
  14. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/diskops.c +0 -0
  15. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/posix/cat.c +0 -0
  16. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/posix/cp.c +0 -0
  17. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/posix/dir.c +0 -0
  18. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/posix/mkdir.c +0 -0
  19. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/posix/mv.c +0 -0
  20. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/posix/rename.c +0 -0
  21. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/posix/rm.c +0 -0
  22. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/posix/rmdir.c +0 -0
  23. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/posix/touch.c +0 -0
  24. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/shared/dir_types.c +0 -0
  25. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/shared/dir_types.h +0 -0
  26. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/shared/native_errors.h +0 -0
  27. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/shared/win32_utf.h +0 -0
  28. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/win32/cat.c +0 -0
  29. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/win32/cp.c +0 -0
  30. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/win32/dir.c +0 -0
  31. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/win32/mkdir.c +0 -0
  32. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/win32/mv.c +0 -0
  33. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/win32/rename.c +0 -0
  34. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/win32/rm.c +0 -0
  35. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/win32/rmdir.c +0 -0
  36. {flyshell-1.5.2 → flyshell-1.5.4}/c_src/diskops/win32/touch.c +0 -0
  37. {flyshell-1.5.2 → flyshell-1.5.4}/pyproject.toml +0 -0
  38. {flyshell-1.5.2 → flyshell-1.5.4}/setup.cfg +0 -0
  39. {flyshell-1.5.2 → flyshell-1.5.4}/setup.py +0 -0
  40. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/__init__.py +0 -0
  41. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/abstract/__init__.py +0 -0
  42. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/abstract/base_cmd.py +0 -0
  43. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/abstract/parent_cmd.py +0 -0
  44. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/accounts/__init__.py +0 -0
  45. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/accounts/auth.py +0 -0
  46. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/bin/__init__.py +0 -0
  47. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/builtin/__init__.py +0 -0
  48. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/builtin/fs.py +0 -0
  49. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/builtin/pkg.py +0 -0
  50. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/builtin/system.py +0 -0
  51. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/builtin/utils.py +0 -0
  52. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/core/__init__.py +0 -0
  53. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/core/console.py +0 -0
  54. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/native/__init__.py +0 -0
  55. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/native/diskops_bridge.py +0 -0
  56. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/native/diskops_handler.py +0 -0
  57. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/native/legacy/__init__.py +0 -0
  58. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/native/legacy/diskops.py +0 -0
  59. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/startup/__init__.py +0 -0
  60. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/startup/deps.py +0 -0
  61. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell/startup/env.py +0 -0
  62. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell.egg-info/SOURCES.txt +0 -0
  63. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell.egg-info/dependency_links.txt +0 -0
  64. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell.egg-info/entry_points.txt +0 -0
  65. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell.egg-info/requires.txt +0 -0
  66. {flyshell-1.5.2 → flyshell-1.5.4}/src/flyshell.egg-info/top_level.txt +0 -0
  67. {flyshell-1.5.2 → flyshell-1.5.4}/tests/test_auth.py +0 -0
  68. {flyshell-1.5.2 → flyshell-1.5.4}/tests/test_data.py +0 -0
  69. {flyshell-1.5.2 → flyshell-1.5.4}/tests/test_deps.py +0 -0
  70. {flyshell-1.5.2 → flyshell-1.5.4}/tests/test_directory.py +0 -0
  71. {flyshell-1.5.2 → flyshell-1.5.4}/tests/test_diskops_ext.py +0 -0
  72. {flyshell-1.5.2 → flyshell-1.5.4}/tests/test_diskops_lgc.py +0 -0
  73. {flyshell-1.5.2 → flyshell-1.5.4}/tests/test_env.py +0 -0
  74. {flyshell-1.5.2 → flyshell-1.5.4}/tests/test_fs.py +0 -0
  75. {flyshell-1.5.2 → flyshell-1.5.4}/tests/test_pkg.py +0 -0
  76. {flyshell-1.5.2 → flyshell-1.5.4}/tests/test_security.py +0 -0
  77. {flyshell-1.5.2 → flyshell-1.5.4}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flyshell
3
- Version: 1.5.2
3
+ Version: 1.5.4
4
4
  Summary: A modular, zero-dependency command-line environment in Python.
5
5
  License-Expression: MIT
6
6
  Requires-Python: >=3.10
@@ -23,7 +23,7 @@ Dynamic: license-file
23
23
  ![Dependencies](https://img.shields.io/badge/dependencies-zero-brightgreen.svg)
24
24
  ![Tests](https://github.com/kianodev/flyshell/actions/workflows/ci.yml/badge.svg)
25
25
 
26
- > Documentation last updated: v1.5.1
26
+ > Documentation last updated: v1.5.3
27
27
 
28
28
  A modular, zero-dependency command-line environment and extensible runtime interface built in Python with compiled C-extensions.
29
29
 
@@ -208,9 +208,10 @@ Additional functions are available for you to use:
208
208
 
209
209
  1. `get_data(key, default=None)`: Retrieves a value from local plugin memory.
210
210
  2. `set_data(key, value)`: Updates a key in local memory and automatically persists it to SQLite via `save_storage()`.
211
- 3. `load_storage()`: Reloads fresh key-value pairs directly from SQLite into `self.storage`.
212
- 4. `save_storage()`: Writes all in-memory key-value pairs in `self.storage` back to SQLite.
213
- 5. `get_api_key(key, default=None)`: Fetches the specified API key from `flyshell_keys.env`.
211
+ 3. `delete_data(key)`: Deletes the specified key and automatically persists it to SQLite, returning **True** if found and **False** if not found.
212
+ 4. `load_storage()`: Reloads fresh key-value pairs directly from SQLite into `self.storage`.
213
+ 5. `save_storage()`: Writes all in-memory key-value pairs in `self.storage` back to SQLite.
214
+ 6. `get_api_key(key, default=None)`: Fetches the specified API key from `flyshell_keys.env`.
214
215
 
215
216
  Plugins save automatically on shut-down.
216
217
 
@@ -6,7 +6,7 @@
6
6
  ![Dependencies](https://img.shields.io/badge/dependencies-zero-brightgreen.svg)
7
7
  ![Tests](https://github.com/kianodev/flyshell/actions/workflows/ci.yml/badge.svg)
8
8
 
9
- > Documentation last updated: v1.5.1
9
+ > Documentation last updated: v1.5.3
10
10
 
11
11
  A modular, zero-dependency command-line environment and extensible runtime interface built in Python with compiled C-extensions.
12
12
 
@@ -191,9 +191,10 @@ Additional functions are available for you to use:
191
191
 
192
192
  1. `get_data(key, default=None)`: Retrieves a value from local plugin memory.
193
193
  2. `set_data(key, value)`: Updates a key in local memory and automatically persists it to SQLite via `save_storage()`.
194
- 3. `load_storage()`: Reloads fresh key-value pairs directly from SQLite into `self.storage`.
195
- 4. `save_storage()`: Writes all in-memory key-value pairs in `self.storage` back to SQLite.
196
- 5. `get_api_key(key, default=None)`: Fetches the specified API key from `flyshell_keys.env`.
194
+ 3. `delete_data(key)`: Deletes the specified key and automatically persists it to SQLite, returning **True** if found and **False** if not found.
195
+ 4. `load_storage()`: Reloads fresh key-value pairs directly from SQLite into `self.storage`.
196
+ 5. `save_storage()`: Writes all in-memory key-value pairs in `self.storage` back to SQLite.
197
+ 6. `get_api_key(key, default=None)`: Fetches the specified API key from `flyshell_keys.env`.
197
198
 
198
199
  Plugins save automatically on shut-down.
199
200
 
@@ -83,6 +83,13 @@ class BasePlugin:
83
83
  self.storage[key] = value
84
84
  self.save_storage()
85
85
 
86
+ def delete_data(self, key: str) -> bool:
87
+ if key in self.storage:
88
+ del self.storage[key]
89
+ self.save_storage()
90
+ return True
91
+ return False
92
+
86
93
  def load_storage(self) -> dict:
87
94
  fresh_data = data.get_all_plugin_data(self.plugin_name)
88
95
  self.storage = fresh_data
@@ -90,6 +97,9 @@ class BasePlugin:
90
97
  return self.storage
91
98
 
92
99
  def save_storage(self):
100
+ existing_keys = set(data.get_all_plugin_data(self.plugin_name).keys())
101
+ for stale_key in existing_keys - set(self.storage.keys()):
102
+ data.delete_plugin_data(self.plugin_name, stale_key)
93
103
  for k, v in self.storage.items():
94
104
  data.set_plugin_data(self.plugin_name, k, v)
95
105
  self.context["storage"] = self.storage
@@ -5,9 +5,9 @@ import os
5
5
  import platform
6
6
  import time
7
7
 
8
- BUILD = 173
9
- VERFULL = "1.5.2d"
10
- VERSION = "1.5.2"
8
+ BUILD = 182
9
+ VERFULL = "1.5.4e"
10
+ VERSION = "1.5.4"
11
11
 
12
12
 
13
13
  def _resolve_app_dir() -> Path:
@@ -262,3 +262,14 @@ def purge_all_plugin_data(filename=c.FILE_PATH) -> bool:
262
262
  conn.execute("DELETE FROM plugin_kv")
263
263
  conn.execute("DELETE FROM plugins")
264
264
  return True
265
+
266
+
267
+ def delete_plugin_data(plugin_name: str, key: str, filename=c.FILE_PATH) -> bool:
268
+ initialise(filename)
269
+ with _get_connection(filename) as conn:
270
+ with conn:
271
+ cursor = conn.execute(
272
+ "DELETE FROM plugin_kv WHERE plugin_name = ? AND key = ?",
273
+ (plugin_name, key),
274
+ )
275
+ return cursor.rowcount > 0
@@ -10,6 +10,7 @@ from flyshell.native import diskops_handler as diskops
10
10
  from flyshell.startup import deps
11
11
 
12
12
  from datetime import datetime, timezone
13
+ import copy
13
14
  import shlex
14
15
  import sys
15
16
 
@@ -182,6 +183,7 @@ def _execute_single(raw_cmd: str) -> int:
182
183
  )
183
184
  print(f"Please run 'sys pip install {' '.join(missing_deps)}'\n")
184
185
  return 1
186
+ storage_before = copy.deepcopy(getattr(plugin, "storage", {}))
185
187
  try:
186
188
  result = plugin.execute(args)
187
189
  return result if isinstance(result, int) else 0
@@ -196,9 +198,10 @@ def _execute_single(raw_cmd: str) -> int:
196
198
  print("Returning to main Flyshell interface...\n")
197
199
  return 1
198
200
  finally:
199
- if hasattr(plugin, "on_unload"):
200
- plugin.on_unload()
201
- if hasattr(plugin, "save_storage"):
201
+ if (
202
+ hasattr(plugin, "save_storage")
203
+ and getattr(plugin, "storage", {}) != storage_before
204
+ ):
202
205
  plugin.save_storage()
203
206
  else:
204
207
  print(
@@ -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__":
@@ -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.2
3
+ Version: 1.5.4
4
4
  Summary: A modular, zero-dependency command-line environment in Python.
5
5
  License-Expression: MIT
6
6
  Requires-Python: >=3.10
@@ -23,7 +23,7 @@ Dynamic: license-file
23
23
  ![Dependencies](https://img.shields.io/badge/dependencies-zero-brightgreen.svg)
24
24
  ![Tests](https://github.com/kianodev/flyshell/actions/workflows/ci.yml/badge.svg)
25
25
 
26
- > Documentation last updated: v1.5.1
26
+ > Documentation last updated: v1.5.3
27
27
 
28
28
  A modular, zero-dependency command-line environment and extensible runtime interface built in Python with compiled C-extensions.
29
29
 
@@ -208,9 +208,10 @@ Additional functions are available for you to use:
208
208
 
209
209
  1. `get_data(key, default=None)`: Retrieves a value from local plugin memory.
210
210
  2. `set_data(key, value)`: Updates a key in local memory and automatically persists it to SQLite via `save_storage()`.
211
- 3. `load_storage()`: Reloads fresh key-value pairs directly from SQLite into `self.storage`.
212
- 4. `save_storage()`: Writes all in-memory key-value pairs in `self.storage` back to SQLite.
213
- 5. `get_api_key(key, default=None)`: Fetches the specified API key from `flyshell_keys.env`.
211
+ 3. `delete_data(key)`: Deletes the specified key and automatically persists it to SQLite, returning **True** if found and **False** if not found.
212
+ 4. `load_storage()`: Reloads fresh key-value pairs directly from SQLite into `self.storage`.
213
+ 5. `save_storage()`: Writes all in-memory key-value pairs in `self.storage` back to SQLite.
214
+ 6. `get_api_key(key, default=None)`: Fetches the specified API key from `flyshell_keys.env`.
214
215
 
215
216
  Plugins save automatically on shut-down.
216
217
 
@@ -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
@@ -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