magmascript 3.2.3__tar.gz → 3.3.0__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 (101) hide show
  1. {magmascript-3.2.3 → magmascript-3.3.0}/PKG-INFO +22 -23
  2. {magmascript-3.2.3 → magmascript-3.3.0}/README.md +20 -19
  3. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/__init__.py +10 -1
  4. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/cli.py +17 -2
  5. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/archive/client.py +1 -1
  6. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/mc1/client.py +103 -14
  7. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/mcp/client.py +11 -3
  8. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript.egg-info/PKG-INFO +22 -23
  9. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript.egg-info/SOURCES.txt +1 -0
  10. {magmascript-3.2.3 → magmascript-3.3.0}/pyproject.toml +14 -4
  11. {magmascript-3.2.3 → magmascript-3.3.0}/tests/test_cli.py +17 -0
  12. magmascript-3.3.0/tests/test_cli_regressions.py +99 -0
  13. {magmascript-3.2.3 → magmascript-3.3.0}/tests/test_mc1.py +122 -0
  14. {magmascript-3.2.3 → magmascript-3.3.0}/LICENSE +0 -0
  15. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/codegen/__init__.py +0 -0
  16. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/codegen/c.py +0 -0
  17. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/core/__init__.py +0 -0
  18. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/core/cache.py +0 -0
  19. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/core/command_registry.py +0 -0
  20. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/core/commands.py +0 -0
  21. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/core/config.py +0 -0
  22. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/core/exceptions.py +0 -0
  23. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/core/github.py +0 -0
  24. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/core/output.py +0 -0
  25. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/core/registry.py +0 -0
  26. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/core/rpc.py +0 -0
  27. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/core/runner.py +0 -0
  28. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/__init__.py +0 -0
  29. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/archive/__init__.py +0 -0
  30. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/gh/__init__.py +0 -0
  31. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/gh/client.py +0 -0
  32. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/gh/tools.py +0 -0
  33. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/lastfm/__init__.py +0 -0
  34. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/lastfm/client.py +0 -0
  35. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/mac/__init__.py +0 -0
  36. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/mac/client.py +0 -0
  37. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/mac/tools.py +0 -0
  38. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/mb/__init__.py +0 -0
  39. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/mb/client.py +0 -0
  40. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/mc1/__init__.py +0 -0
  41. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/mc1/tools.py +0 -0
  42. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/mcp/__init__.py +0 -0
  43. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/mcp/tools.py +0 -0
  44. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/media/__init__.py +0 -0
  45. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/media/client.py +0 -0
  46. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/media/providers/__init__.py +0 -0
  47. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/media/providers/archive.py +0 -0
  48. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/media/providers/met_museum.py +0 -0
  49. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/media/providers/openverse.py +0 -0
  50. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/media/providers/pexels.py +0 -0
  51. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/media/providers/pixabay.py +0 -0
  52. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/media/providers/smithsonian.py +0 -0
  53. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/media/tools.py +0 -0
  54. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/pi/__init__.py +0 -0
  55. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/pi/client.py +0 -0
  56. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/pi/tools.py +0 -0
  57. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/rights/__init__.py +0 -0
  58. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/rights/client.py +0 -0
  59. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/rights/tools.py +0 -0
  60. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/scores/__init__.py +0 -0
  61. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/scores/client.py +0 -0
  62. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/scores/tools.py +0 -0
  63. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/search/__init__.py +0 -0
  64. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/domains/search/client.py +0 -0
  65. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/lang/__init__.py +0 -0
  66. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/lang/ast_nodes.py +0 -0
  67. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/lang/astheno/__init__.py +0 -0
  68. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/lang/astheno/arena.py +0 -0
  69. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/lang/astheno/dump.py +0 -0
  70. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/lang/astheno/floorplan.py +0 -0
  71. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/lang/astheno/numeric.py +0 -0
  72. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/lang/builtins.py +0 -0
  73. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/lang/domain_bridge.py +0 -0
  74. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/lang/environment.py +0 -0
  75. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/lang/hypnagogia.py +0 -0
  76. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/lang/interpreter.py +0 -0
  77. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/lang/lexer.py +0 -0
  78. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/lang/parser.py +0 -0
  79. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/lang/pretty.py +0 -0
  80. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/lang/pygments_mgs.py +0 -0
  81. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/lang/tokens.py +0 -0
  82. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/lang/util.py +0 -0
  83. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/lang/visitor.py +0 -0
  84. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/repl.py +0 -0
  85. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript/scaffold/__init__.py +0 -0
  86. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript.egg-info/dependency_links.txt +0 -0
  87. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript.egg-info/entry_points.txt +0 -0
  88. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript.egg-info/requires.txt +0 -0
  89. {magmascript-3.2.3 → magmascript-3.3.0}/magmascript.egg-info/top_level.txt +0 -0
  90. {magmascript-3.2.3 → magmascript-3.3.0}/setup.cfg +0 -0
  91. {magmascript-3.2.3 → magmascript-3.3.0}/tests/test_astheno.py +0 -0
  92. {magmascript-3.2.3 → magmascript-3.3.0}/tests/test_cache.py +0 -0
  93. {magmascript-3.2.3 → magmascript-3.3.0}/tests/test_classes.py +0 -0
  94. {magmascript-3.2.3 → magmascript-3.3.0}/tests/test_commands.py +0 -0
  95. {magmascript-3.2.3 → magmascript-3.3.0}/tests/test_domain_bridge.py +0 -0
  96. {magmascript-3.2.3 → magmascript-3.3.0}/tests/test_import.py +0 -0
  97. {magmascript-3.2.3 → magmascript-3.3.0}/tests/test_lang.py +0 -0
  98. {magmascript-3.2.3 → magmascript-3.3.0}/tests/test_mac.py +0 -0
  99. {magmascript-3.2.3 → magmascript-3.3.0}/tests/test_mcp_client.py +0 -0
  100. {magmascript-3.2.3 → magmascript-3.3.0}/tests/test_rpc.py +0 -0
  101. {magmascript-3.2.3 → magmascript-3.3.0}/tests/test_try_catch.py +0 -0
@@ -1,13 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: magmascript
3
- Version: 3.2.3
3
+ Version: 3.3.0
4
4
  Summary: Scripting toolkit with domain-first subcommands
5
5
  Author: Jake McCoy
6
6
  License-Expression: MIT
7
7
  Project-URL: Homepage, https://magmacrunch.com/ware/magmascript/
8
- Project-URL: Documentation, https://github.com/magmacrunch-media/magmascript/wiki
9
- Project-URL: Repository, https://github.com/magmacrunch-media/magmascript
10
- Project-URL: Changelog, https://github.com/magmacrunch-media/magmascript/blob/main/CHANGELOG.md
8
+ Project-URL: Documentation, https://magmacrunch.com/ware/magmascript/
11
9
  Project-URL: Funding, https://github.com/sponsors/magmacrunch-media
12
10
  Keywords: mcp,scripting,cli,magmacrunch
13
11
  Classifier: Development Status :: 3 - Alpha
@@ -421,7 +419,7 @@ this ground was scorched at line 3 (garrisoned at line 1)
421
419
 
422
420
  `floorplan` is the only new reserved word; everything else is a shadowable
423
421
  builtin, so existing scripts are unaffected. Full reference on the
424
- [Asthenosphere wiki page](https://github.com/magmacrunch-media/magmascript/wiki/Asthenosphere).
422
+ [Asthenosphere wiki page](wiki/Asthenosphere.md).
425
423
 
426
424
  ### REPL
427
425
 
@@ -678,30 +676,31 @@ gh_workflows # GitHub commands
678
676
 
679
677
  ## Documentation
680
678
 
681
- Full documentation on the [Wiki](https://github.com/magmacrunch-media/magmascript/wiki):
682
- - [MagmaScript Language](https://github.com/magmacrunch-media/magmascript/wiki/MagmaScript-Language)
683
- - [Configuration](https://github.com/magmacrunch-media/magmascript/wiki/Configuration)
684
- - [MCP Domain](https://github.com/magmacrunch-media/magmascript/wiki/MCP-Domain)
685
- - [Pi Domain](https://github.com/magmacrunch-media/magmascript/wiki/Pi-Domain)
686
- - [MC1 Domain](https://github.com/magmacrunch-media/magmascript/wiki/MC1-Domain)
687
- - [Mac Domain](https://github.com/magmacrunch-media/magmascript/wiki/Mac-Domain)
688
- - [GitHub Domain](https://github.com/magmacrunch-media/magmascript/wiki/GitHub-Domain)
689
- - [Scores Domain](https://github.com/magmacrunch-media/magmascript/wiki/Scores-Domain)
690
- - [Rights Domain](https://github.com/magmacrunch-media/magmascript/wiki/Rights-Domain)
691
- - [Archive Domain](https://github.com/magmacrunch-media/magmascript/wiki/Archive-Domain)
692
- - [Last.fm Domain](https://github.com/magmacrunch-media/magmascript/wiki/Last.fm-Domain)
693
- - [MusicBrainz Domain](https://github.com/magmacrunch-media/magmascript/wiki/MusicBrainz-Domain)
694
- - [Search Domain](https://github.com/magmacrunch-media/magmascript/wiki/Search-Domain)
695
- - [Media Domain](https://github.com/magmacrunch-media/magmascript/wiki/Media-Domain)
696
- - [Example Scripts](https://github.com/magmacrunch-media/magmascript/wiki/Example-Scripts)
697
- - [Asthenosphere](https://github.com/magmacrunch-media/magmascript/wiki/Asthenosphere)
698
- - [Architecture](https://github.com/magmacrunch-media/magmascript/wiki/Architecture)
679
+ Full documentation on the [Wiki](wiki/):
680
+ - [MagmaScript Language](wiki/MagmaScript-Language.md)
681
+ - [Configuration](wiki/Configuration.md)
682
+ - [MCP Domain](wiki/MCP-Domain.md)
683
+ - [Pi Domain](wiki/Pi-Domain.md)
684
+ - [MC1 Domain](wiki/MC1-Domain.md)
685
+ - [Mac Domain](wiki/Mac-Domain.md)
686
+ - [GitHub Domain](wiki/GitHub-Domain.md)
687
+ - [Scores Domain](wiki/Scores-Domain.md)
688
+ - [Rights Domain](wiki/Rights-Domain.md)
689
+ - [Archive Domain](wiki/Archive-Domain.md)
690
+ - [Last.fm Domain](wiki/Last.fm-Domain.md)
691
+ - [MusicBrainz Domain](wiki/MusicBrainz-Domain.md)
692
+ - [Search Domain](wiki/Search-Domain.md)
693
+ - [Media Domain](wiki/Media-Domain.md)
694
+ - [Example Scripts](wiki/Example-Scripts.md)
695
+ - [Asthenosphere](wiki/Asthenosphere.md)
696
+ - [Architecture](wiki/Architecture.md)
699
697
 
700
698
  ## Support This Project
701
699
 
702
700
  If you find magmascript useful, consider supporting its development:
703
701
 
704
702
  [![Sponsor](https://img.shields.io/badge/%E2%9D%A4_Sponsor-pink)](https://github.com/sponsors/magmacrunch-media)
703
+ [![PayPal](https://img.shields.io/badge/Donate-PayPal-blue)](https://www.paypal.biz/magmacrunchmedia)
705
704
 
706
705
  ## License
707
706
 
@@ -383,7 +383,7 @@ this ground was scorched at line 3 (garrisoned at line 1)
383
383
 
384
384
  `floorplan` is the only new reserved word; everything else is a shadowable
385
385
  builtin, so existing scripts are unaffected. Full reference on the
386
- [Asthenosphere wiki page](https://github.com/magmacrunch-media/magmascript/wiki/Asthenosphere).
386
+ [Asthenosphere wiki page](wiki/Asthenosphere.md).
387
387
 
388
388
  ### REPL
389
389
 
@@ -640,30 +640,31 @@ gh_workflows # GitHub commands
640
640
 
641
641
  ## Documentation
642
642
 
643
- Full documentation on the [Wiki](https://github.com/magmacrunch-media/magmascript/wiki):
644
- - [MagmaScript Language](https://github.com/magmacrunch-media/magmascript/wiki/MagmaScript-Language)
645
- - [Configuration](https://github.com/magmacrunch-media/magmascript/wiki/Configuration)
646
- - [MCP Domain](https://github.com/magmacrunch-media/magmascript/wiki/MCP-Domain)
647
- - [Pi Domain](https://github.com/magmacrunch-media/magmascript/wiki/Pi-Domain)
648
- - [MC1 Domain](https://github.com/magmacrunch-media/magmascript/wiki/MC1-Domain)
649
- - [Mac Domain](https://github.com/magmacrunch-media/magmascript/wiki/Mac-Domain)
650
- - [GitHub Domain](https://github.com/magmacrunch-media/magmascript/wiki/GitHub-Domain)
651
- - [Scores Domain](https://github.com/magmacrunch-media/magmascript/wiki/Scores-Domain)
652
- - [Rights Domain](https://github.com/magmacrunch-media/magmascript/wiki/Rights-Domain)
653
- - [Archive Domain](https://github.com/magmacrunch-media/magmascript/wiki/Archive-Domain)
654
- - [Last.fm Domain](https://github.com/magmacrunch-media/magmascript/wiki/Last.fm-Domain)
655
- - [MusicBrainz Domain](https://github.com/magmacrunch-media/magmascript/wiki/MusicBrainz-Domain)
656
- - [Search Domain](https://github.com/magmacrunch-media/magmascript/wiki/Search-Domain)
657
- - [Media Domain](https://github.com/magmacrunch-media/magmascript/wiki/Media-Domain)
658
- - [Example Scripts](https://github.com/magmacrunch-media/magmascript/wiki/Example-Scripts)
659
- - [Asthenosphere](https://github.com/magmacrunch-media/magmascript/wiki/Asthenosphere)
660
- - [Architecture](https://github.com/magmacrunch-media/magmascript/wiki/Architecture)
643
+ Full documentation on the [Wiki](wiki/):
644
+ - [MagmaScript Language](wiki/MagmaScript-Language.md)
645
+ - [Configuration](wiki/Configuration.md)
646
+ - [MCP Domain](wiki/MCP-Domain.md)
647
+ - [Pi Domain](wiki/Pi-Domain.md)
648
+ - [MC1 Domain](wiki/MC1-Domain.md)
649
+ - [Mac Domain](wiki/Mac-Domain.md)
650
+ - [GitHub Domain](wiki/GitHub-Domain.md)
651
+ - [Scores Domain](wiki/Scores-Domain.md)
652
+ - [Rights Domain](wiki/Rights-Domain.md)
653
+ - [Archive Domain](wiki/Archive-Domain.md)
654
+ - [Last.fm Domain](wiki/Last.fm-Domain.md)
655
+ - [MusicBrainz Domain](wiki/MusicBrainz-Domain.md)
656
+ - [Search Domain](wiki/Search-Domain.md)
657
+ - [Media Domain](wiki/Media-Domain.md)
658
+ - [Example Scripts](wiki/Example-Scripts.md)
659
+ - [Asthenosphere](wiki/Asthenosphere.md)
660
+ - [Architecture](wiki/Architecture.md)
661
661
 
662
662
  ## Support This Project
663
663
 
664
664
  If you find magmascript useful, consider supporting its development:
665
665
 
666
666
  [![Sponsor](https://img.shields.io/badge/%E2%9D%A4_Sponsor-pink)](https://github.com/sponsors/magmacrunch-media)
667
+ [![PayPal](https://img.shields.io/badge/Donate-PayPal-blue)](https://www.paypal.biz/magmacrunchmedia)
667
668
 
668
669
  ## License
669
670
 
@@ -1,6 +1,15 @@
1
1
  """magmascript — a scripting toolkit with domain-first subcommands."""
2
2
 
3
- __version__ = "3.2.2"
3
+ # The version lives in pyproject.toml alone. It was also a literal here, and the
4
+ # two drifted: 3.2.3 shipped reporting itself as 3.2.2, in the REPL banner and
5
+ # in the MCP client's User-Agent.
6
+ from importlib.metadata import PackageNotFoundError as _PackageNotFoundError
7
+ from importlib.metadata import version as _version
8
+
9
+ try:
10
+ __version__ = _version("magmascript")
11
+ except _PackageNotFoundError: # running from a source tree that was never installed
12
+ __version__ = "0+unknown"
4
13
 
5
14
  from magmascript.core.config import Config, GHConfig, MediaConfig, MC1Config, PIConfig, get_config, load_config, set_config
6
15
  from magmascript.core.registry import get_domain, list_domains, register_domain
@@ -11,6 +11,7 @@ from __future__ import annotations
11
11
 
12
12
  import json
13
13
  import sys
14
+ from datetime import datetime
14
15
  from functools import wraps
15
16
  from typing import Callable
16
17
 
@@ -66,7 +67,12 @@ def _generate_channels_js(channels: list[dict]) -> str:
66
67
 
67
68
  # -- register domain commands --------------------------------------------
68
69
 
70
+ _DOMAINS_REGISTERED = False
71
+
72
+
69
73
  def _register_domains():
74
+ global _DOMAINS_REGISTERED
75
+
70
76
  from magmascript.domains.mcp import MCPClient
71
77
  from magmascript.domains.pi import PIClient
72
78
  from magmascript.domains.mac import MacClient
@@ -138,6 +144,8 @@ def _register_domains():
138
144
 
139
145
  register("search", "Site search index builder")(_search_handler)
140
146
 
147
+ _DOMAINS_REGISTERED = True
148
+
141
149
 
142
150
  # -- register built-in meta commands ------------------------------------
143
151
 
@@ -437,8 +445,15 @@ def main():
437
445
  no_cache = True
438
446
  rest.remove("--no-cache")
439
447
 
440
- # Register domain commands (lazy, on first use)
441
- if not COMMANDS:
448
+ # Register domain commands (lazy, on first use).
449
+ #
450
+ # This was `if not COMMANDS:`, which assumed the table starts empty. It did
451
+ # until 3.2.2 registered the built-in commands (run, repl, cache, ...) with
452
+ # @register at import. From then on COMMANDS was never empty, this never
453
+ # ran, and every domain command -- archive, mb, lastfm, scores, search and
454
+ # the rest -- failed as "Unknown domain" in 3.2.2 and 3.2.3. A flag says
455
+ # what is actually meant: have the domains been registered yet.
456
+ if not _DOMAINS_REGISTERED:
442
457
  _register_domains()
443
458
 
444
459
  try:
@@ -98,7 +98,7 @@ class ArchiveClient:
98
98
  "events": "c-events",
99
99
  "games": "c-games",
100
100
  "links": "c-links",
101
- "music videos": "c-music-videos",
101
+ "videos": "c-videos",
102
102
  "network": "c-network",
103
103
  "documentary": "c-documentary",
104
104
  "personnel": "c-personnel",
@@ -5,9 +5,11 @@ Supports SSH (remote) execution mode for managing MC1.
5
5
 
6
6
  from __future__ import annotations
7
7
 
8
+ import re
8
9
  import subprocess
9
10
 
10
11
  from magmascript.core.config import Config, get_config
12
+ from magmascript.core.exceptions import MagmascriptError, SSHError
11
13
  from magmascript.core.runner import CommandRunner
12
14
  from magmascript.domains.mc1.tools import (
13
15
  MC1PowerSettings,
@@ -18,6 +20,8 @@ from magmascript.domains.mc1.tools import (
18
20
  parse_system_info,
19
21
  )
20
22
 
23
+ _MAC_RE = re.compile(r"^[0-9A-Fa-f]{2}(?::[0-9A-Fa-f]{2}){5}$")
24
+
21
25
 
22
26
  class MC1Client:
23
27
  """Direct client for MC1 Windows PC management.
@@ -32,6 +36,10 @@ class MC1Client:
32
36
  self._user = cfg.mc1.user
33
37
  self._local = local
34
38
  self._runner = CommandRunner(cfg.mc1.host, cfg.mc1.user, local=local)
39
+ # Wake-on-LAN relays through the Pi, which shares MC1's broadcast
40
+ # domain. See wake_on_lan for why that is not optional.
41
+ self._pi_host = cfg.pi.host
42
+ self._pi_user = cfg.pi.user
35
43
 
36
44
  # ------------------------------------------------------------------
37
45
  # Service management
@@ -141,26 +149,107 @@ class MC1Client:
141
149
  # Wake-on-LAN
142
150
  # ------------------------------------------------------------------
143
151
 
144
- def wake_on_lan(self, mac_address: str) -> str:
145
- """Send Wake-on-LAN magic packet to MC1.
152
+ def wake_on_lan(self, mac_address: str, *, relay: bool = True) -> str:
153
+ """Send Wake-on-LAN magic packets to MC1 by every available route.
154
+
155
+ A magic packet is addressed to 255.255.255.255:9, which is **never
156
+ routed**, so a direct send reaches MC1 only from MC1's own subnet and
157
+ silently reaches nothing from anywhere else. The Pi is always on that
158
+ subnet and is reachable over the tailnet from anywhere, so it is used as
159
+ a relay as well. Both are sent rather than guessing which network this
160
+ machine is on, because the loser costs about a second and there is no
161
+ location test to get wrong.
162
+
163
+ This is the same fix the Mac's ~/bin/wake-mc1 got on 2026-10-09, after
164
+ being direct-only meant waking MC1 from away did nothing while the same
165
+ command worked at home.
146
166
 
147
- This runs the `wakeonlan` command on the Pi (or local machine).
148
- The MAC address should be MC1's ethernet adapter MAC.
167
+ Note `wakeonlan` exits 0 whenever the datagram left the host, which says
168
+ nothing about where it went. So this reports the routes that ACCEPTED a
169
+ packet and never claims MC1 is awake. It does not poll; nothing here can
170
+ confirm a wake.
149
171
 
150
172
  Args:
151
- mac_address: Ethernet MAC address (e.g. "A0:AD:9F:A4:72:97" or "A0-AD-9F-A4-72-97")
173
+ mac_address: Ethernet MAC, ":" or "-" separated
174
+ (e.g. "A0:AD:9F:A4:72:97" or "A0-AD-9F-A4-72-97").
175
+ relay: Set False to send direct only and skip the Pi.
152
176
 
153
177
  Returns:
154
- Success message
178
+ A message naming each route tried and whether it took the packet.
179
+
180
+ Raises:
181
+ ValueError: if mac_address is not six hex octets.
182
+ MagmascriptError: if no route accepted the packet.
155
183
  """
156
- # Normalize MAC address format (wakeonlan accepts both : and - separators)
157
- normalized_mac = mac_address.replace("-", ":")
158
- subprocess.run(
159
- ["wakeonlan", normalized_mac],
160
- capture_output=True,
161
- timeout=10,
162
- )
163
- return f"✓ Wake-on-LAN packet sent to {normalized_mac}"
184
+ # wakeonlan accepts both separators, so normalise before validating.
185
+ mac = mac_address.replace("-", ":")
186
+ if not _MAC_RE.match(mac):
187
+ raise ValueError(
188
+ f"not a MAC address: {mac_address!r} "
189
+ "(expected six hex octets, e.g. A0:AD:9F:A4:72:97)"
190
+ )
191
+
192
+ lines: list[str] = []
193
+ accepted = 0
194
+
195
+ if self._wol_direct(mac):
196
+ lines.append(" direct broadcast sent (reaches MC1 only from its own subnet)")
197
+ accepted += 1
198
+ else:
199
+ lines.append(" direct broadcast FAILED (is wakeonlan installed here?)")
200
+
201
+ if relay:
202
+ if not self._pi_host:
203
+ lines.append(
204
+ " relay SKIPPED: no [pi] host configured, so this is "
205
+ "home-only. Set pi.host in ~/.config/magmascript/config.toml"
206
+ )
207
+ elif self._wol_relay(mac):
208
+ lines.append(
209
+ f" relayed via {self._pi_host} (reaches MC1 from any network)"
210
+ )
211
+ accepted += 1
212
+ else:
213
+ lines.append(f" relay via {self._pi_host} FAILED")
214
+
215
+ report = "\n".join(lines)
216
+ if not accepted:
217
+ raise MagmascriptError(
218
+ f"no route accepted a Wake-on-LAN packet for {mac}:\n{report}"
219
+ )
220
+ return f"Wake-on-LAN packet for {mac}:\n{report}"
221
+
222
+ @staticmethod
223
+ def _wol_direct(mac: str) -> bool:
224
+ """Broadcast on this machine's own subnet.
225
+
226
+ False rather than raising when `wakeonlan` is missing, which it is on
227
+ Windows, so the relay can still carry the packet.
228
+ """
229
+ try:
230
+ result = subprocess.run(
231
+ ["wakeonlan", mac],
232
+ capture_output=True,
233
+ timeout=10,
234
+ check=False, # the exit status is the return value, not an error
235
+ )
236
+ except (OSError, subprocess.SubprocessError):
237
+ return False
238
+ return result.returncode == 0
239
+
240
+ def _wol_relay(self, mac: str) -> bool:
241
+ """Run `wakeonlan` on the Pi, which shares MC1's broadcast domain.
242
+
243
+ `mac` is interpolated into a command a remote shell parses, so it must
244
+ already have passed _MAC_RE.
245
+ """
246
+ try:
247
+ CommandRunner(self._pi_host, self._pi_user).run(
248
+ f"wakeonlan {mac}", timeout=15
249
+ )
250
+ except SSHError:
251
+ return False
252
+ return True
164
253
 
165
254
  # ------------------------------------------------------------------
166
255
  # Power management
@@ -43,6 +43,14 @@ from magmascript.domains.mcp.tools import (
43
43
  )
44
44
 
45
45
 
46
+ def _user_agent() -> str:
47
+ # Imported here, not at module level: magmascript/__init__.py imports this
48
+ # module. It was a literal "magmascript/3.2.2", still sent by 3.2.3.
49
+ from magmascript import __version__
50
+
51
+ return f"magmascript/{__version__} (https://github.com/magmacrunch-media/magmascript)"
52
+
53
+
46
54
  def _wrap_mcp_error(e: Exception, context: str = "") -> Exception:
47
55
  """Wrap RPC and HTTP exceptions into typed magmascript errors."""
48
56
  if isinstance(e, RPCError):
@@ -262,7 +270,7 @@ class MCPClient:
262
270
  """Search MusicBrainz for releases by query string."""
263
271
  url = "https://musicbrainz.org/ws/2/release/"
264
272
  params = {"query": query, "fmt": "json", "limit": limit}
265
- headers = {"User-Agent": "magmascript/3.2.2 (https://github.com/magmacrunch-media/magmascript)"}
273
+ headers = {"User-Agent": _user_agent()}
266
274
  try:
267
275
  resp = httpx.get(url, params=params, headers=headers, timeout=10.0)
268
276
  resp.raise_for_status()
@@ -275,7 +283,7 @@ class MCPClient:
275
283
  """Get full release details including track list with recordings."""
276
284
  url = f"https://musicbrainz.org/ws/2/release/{mbid}"
277
285
  params = {"fmt": "json", "inc": "artist-credits+recordings"}
278
- headers = {"User-Agent": "magmascript/3.2.2 (https://github.com/magmacrunch-media/magmascript)"}
286
+ headers = {"User-Agent": _user_agent()}
279
287
  try:
280
288
  resp = httpx.get(url, params=params, headers=headers, timeout=10.0)
281
289
  resp.raise_for_status()
@@ -288,7 +296,7 @@ class MCPClient:
288
296
  """Get recording details including ISRCs and work relationships."""
289
297
  url = f"https://musicbrainz.org/ws/2/recording/{mbid}"
290
298
  params = {"fmt": "json", "inc": "artist-credits+isrcs+work-rels"}
291
- headers = {"User-Agent": "magmascript/3.2.2 (https://github.com/magmacrunch-media/magmascript)"}
299
+ headers = {"User-Agent": _user_agent()}
292
300
  try:
293
301
  resp = httpx.get(url, params=params, headers=headers, timeout=10.0)
294
302
  resp.raise_for_status()
@@ -1,13 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: magmascript
3
- Version: 3.2.3
3
+ Version: 3.3.0
4
4
  Summary: Scripting toolkit with domain-first subcommands
5
5
  Author: Jake McCoy
6
6
  License-Expression: MIT
7
7
  Project-URL: Homepage, https://magmacrunch.com/ware/magmascript/
8
- Project-URL: Documentation, https://github.com/magmacrunch-media/magmascript/wiki
9
- Project-URL: Repository, https://github.com/magmacrunch-media/magmascript
10
- Project-URL: Changelog, https://github.com/magmacrunch-media/magmascript/blob/main/CHANGELOG.md
8
+ Project-URL: Documentation, https://magmacrunch.com/ware/magmascript/
11
9
  Project-URL: Funding, https://github.com/sponsors/magmacrunch-media
12
10
  Keywords: mcp,scripting,cli,magmacrunch
13
11
  Classifier: Development Status :: 3 - Alpha
@@ -421,7 +419,7 @@ this ground was scorched at line 3 (garrisoned at line 1)
421
419
 
422
420
  `floorplan` is the only new reserved word; everything else is a shadowable
423
421
  builtin, so existing scripts are unaffected. Full reference on the
424
- [Asthenosphere wiki page](https://github.com/magmacrunch-media/magmascript/wiki/Asthenosphere).
422
+ [Asthenosphere wiki page](wiki/Asthenosphere.md).
425
423
 
426
424
  ### REPL
427
425
 
@@ -678,30 +676,31 @@ gh_workflows # GitHub commands
678
676
 
679
677
  ## Documentation
680
678
 
681
- Full documentation on the [Wiki](https://github.com/magmacrunch-media/magmascript/wiki):
682
- - [MagmaScript Language](https://github.com/magmacrunch-media/magmascript/wiki/MagmaScript-Language)
683
- - [Configuration](https://github.com/magmacrunch-media/magmascript/wiki/Configuration)
684
- - [MCP Domain](https://github.com/magmacrunch-media/magmascript/wiki/MCP-Domain)
685
- - [Pi Domain](https://github.com/magmacrunch-media/magmascript/wiki/Pi-Domain)
686
- - [MC1 Domain](https://github.com/magmacrunch-media/magmascript/wiki/MC1-Domain)
687
- - [Mac Domain](https://github.com/magmacrunch-media/magmascript/wiki/Mac-Domain)
688
- - [GitHub Domain](https://github.com/magmacrunch-media/magmascript/wiki/GitHub-Domain)
689
- - [Scores Domain](https://github.com/magmacrunch-media/magmascript/wiki/Scores-Domain)
690
- - [Rights Domain](https://github.com/magmacrunch-media/magmascript/wiki/Rights-Domain)
691
- - [Archive Domain](https://github.com/magmacrunch-media/magmascript/wiki/Archive-Domain)
692
- - [Last.fm Domain](https://github.com/magmacrunch-media/magmascript/wiki/Last.fm-Domain)
693
- - [MusicBrainz Domain](https://github.com/magmacrunch-media/magmascript/wiki/MusicBrainz-Domain)
694
- - [Search Domain](https://github.com/magmacrunch-media/magmascript/wiki/Search-Domain)
695
- - [Media Domain](https://github.com/magmacrunch-media/magmascript/wiki/Media-Domain)
696
- - [Example Scripts](https://github.com/magmacrunch-media/magmascript/wiki/Example-Scripts)
697
- - [Asthenosphere](https://github.com/magmacrunch-media/magmascript/wiki/Asthenosphere)
698
- - [Architecture](https://github.com/magmacrunch-media/magmascript/wiki/Architecture)
679
+ Full documentation on the [Wiki](wiki/):
680
+ - [MagmaScript Language](wiki/MagmaScript-Language.md)
681
+ - [Configuration](wiki/Configuration.md)
682
+ - [MCP Domain](wiki/MCP-Domain.md)
683
+ - [Pi Domain](wiki/Pi-Domain.md)
684
+ - [MC1 Domain](wiki/MC1-Domain.md)
685
+ - [Mac Domain](wiki/Mac-Domain.md)
686
+ - [GitHub Domain](wiki/GitHub-Domain.md)
687
+ - [Scores Domain](wiki/Scores-Domain.md)
688
+ - [Rights Domain](wiki/Rights-Domain.md)
689
+ - [Archive Domain](wiki/Archive-Domain.md)
690
+ - [Last.fm Domain](wiki/Last.fm-Domain.md)
691
+ - [MusicBrainz Domain](wiki/MusicBrainz-Domain.md)
692
+ - [Search Domain](wiki/Search-Domain.md)
693
+ - [Media Domain](wiki/Media-Domain.md)
694
+ - [Example Scripts](wiki/Example-Scripts.md)
695
+ - [Asthenosphere](wiki/Asthenosphere.md)
696
+ - [Architecture](wiki/Architecture.md)
699
697
 
700
698
  ## Support This Project
701
699
 
702
700
  If you find magmascript useful, consider supporting its development:
703
701
 
704
702
  [![Sponsor](https://img.shields.io/badge/%E2%9D%A4_Sponsor-pink)](https://github.com/sponsors/magmacrunch-media)
703
+ [![PayPal](https://img.shields.io/badge/Donate-PayPal-blue)](https://www.paypal.biz/magmacrunchmedia)
705
704
 
706
705
  ## License
707
706
 
@@ -87,6 +87,7 @@ tests/test_astheno.py
87
87
  tests/test_cache.py
88
88
  tests/test_classes.py
89
89
  tests/test_cli.py
90
+ tests/test_cli_regressions.py
90
91
  tests/test_commands.py
91
92
  tests/test_domain_bridge.py
92
93
  tests/test_import.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "magmascript"
7
- version = "3.2.3"
7
+ version = "3.3.0"
8
8
  description = "Scripting toolkit with domain-first subcommands"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -48,10 +48,20 @@ all = [
48
48
  magmascript = "magmascript.cli:main"
49
49
 
50
50
  [project.urls]
51
+ # EVERY LINK HERE HAS TO BE PUBLIC, because this is what PyPI puts on the
52
+ # project page for anyone who finds the package. The repository went private on
53
+ # 2026-10-03, which 404'd three of the five: Documentation (it pointed at the
54
+ # wiki, and a private repo's wiki is turned off entirely), Repository, and
55
+ # Changelog, which was a blob link into the repo.
56
+ #
57
+ # They are removed rather than repointed. There is no public repository or
58
+ # changelog to send anyone to, and an absent link is better than one that 404s
59
+ # from the package's own front page.
60
+ #
61
+ # NOTE a published release's metadata is frozen. Fixing this file only affects
62
+ # the NEXT release; the pages for 3.2.4 and earlier keep the dead links.
51
63
  Homepage = "https://magmacrunch.com/ware/magmascript/"
52
- Documentation = "https://github.com/magmacrunch-media/magmascript/wiki"
53
- Repository = "https://github.com/magmacrunch-media/magmascript"
54
- Changelog = "https://github.com/magmacrunch-media/magmascript/blob/main/CHANGELOG.md"
64
+ Documentation = "https://magmacrunch.com/ware/magmascript/"
55
65
  Funding = "https://github.com/sponsors/magmacrunch-media"
56
66
 
57
67
  [tool.setuptools.packages.find]
@@ -5,9 +5,26 @@ from unittest.mock import MagicMock, patch
5
5
 
6
6
  import pytest
7
7
 
8
+ from magmascript import cli
8
9
  from magmascript.cli import main
9
10
 
10
11
 
12
+ @pytest.fixture(autouse=True)
13
+ def fresh_domain_registration():
14
+ """Register the domains again inside each test.
15
+
16
+ Registration binds each domain's client class once, at first use, so the
17
+ first test to reach it would fix its own patched MCPClient in place for
18
+ every later test -- test_scoreboards_action then asserts against a mock the
19
+ handler never calls. This order dependence was hidden while registration
20
+ never ran at all (3.2.2 and 3.2.3, where these tests failed as "Unknown
21
+ domain" instead).
22
+ """
23
+ cli._DOMAINS_REGISTERED = False
24
+ yield
25
+ cli._DOMAINS_REGISTERED = False
26
+
27
+
11
28
  class TestCLI:
12
29
  def test_help_exits(self):
13
30
  with pytest.raises(SystemExit) as exc_info:
@@ -0,0 +1,99 @@
1
+ """Regression tests for the three faults fixed in 3.2.4.
2
+
3
+ Each of these shipped. The first two broke the website's bots and CI. The third
4
+ left `archive check-format` blind to the site's "videos" buttons: a label
5
+ missing from its map is not checked at all, so a wrong class there passed.
6
+ """
7
+
8
+ from unittest.mock import MagicMock, patch
9
+
10
+ import pytest
11
+
12
+ from magmascript import cli
13
+ from magmascript.cli import COMMANDS, main
14
+ from magmascript.domains.archive import ArchiveClient
15
+ from magmascript.domains.scores.tools import PlayerStats, ScoresReport
16
+
17
+
18
+ class TestDomainRegistration:
19
+ """3.2.2 and 3.2.3: every domain command was "Unknown domain".
20
+
21
+ Registration ran only `if not COMMANDS`, and the built-in commands had
22
+ started registering themselves at import, so the table was never empty.
23
+ """
24
+
25
+ def test_builtins_are_registered_at_import(self):
26
+ # The precondition that exposed the bug. If this stops holding, the
27
+ # test below no longer exercises it.
28
+ assert "run" in COMMANDS
29
+
30
+ @pytest.mark.parametrize("domain", ["archive", "mb", "lastfm", "scores", "search"])
31
+ def test_domain_commands_are_reachable(self, domain, capsys):
32
+ with patch("sys.argv", ["magmascript", domain, "--help"]):
33
+ try:
34
+ main()
35
+ except SystemExit:
36
+ pass
37
+ assert "Unknown domain" not in capsys.readouterr().err
38
+ assert domain in COMMANDS
39
+ assert cli._DOMAINS_REGISTERED
40
+
41
+
42
+ class TestScoresReportPostDiscussion:
43
+ """Every release: `scores report --post-discussion` raised NameError.
44
+
45
+ cli.py called datetime.now() without importing datetime, so the report
46
+ printed and the Discussion was never posted.
47
+ """
48
+
49
+ def test_posts_with_a_dated_title(self, capsys):
50
+ client = MagicMock()
51
+ client.report.return_value = ScoresReport(
52
+ generated_at="September 16, 2026",
53
+ total_games=0,
54
+ total_scores=0,
55
+ scoreboards=[],
56
+ player_stats=[PlayerStats(name="JAM", total_entries=1, games_played=1)],
57
+ )
58
+ gh = MagicMock()
59
+ gh.create_discussion.return_value = "https://example.invalid/discussions/1"
60
+
61
+ with patch("magmascript.core.config.get_config"), \
62
+ patch("magmascript.domains.gh.GHClient", return_value=gh):
63
+ cli._dispatch_scores("report", ["--post-discussion"], client, "table")
64
+
65
+ title, body, category = gh.create_discussion.call_args.args
66
+ assert title.startswith("Weekly High Scores — 20")
67
+ assert "# Weekly High Scores" in body
68
+ assert category == "high-scores"
69
+ gh.close.assert_called_once()
70
+
71
+
72
+ class TestArchiveVideosLabel:
73
+ """The site renamed the artist "music videos" pages to "videos" (website
74
+ 53dc9606). With the old map, "videos" was not a known label, so the checker
75
+ skipped those buttons -- 34 of them on the site at the time -- and the
76
+ mismatch below went unreported."""
77
+
78
+ CSS = ".nav-card.c-videos { color: red; }\n.nav-card.c-music-videos { color: red; }\n"
79
+
80
+ def _page(self, tmp_path, cls):
81
+ artist = tmp_path / "archive" / "by-artist" / "someone"
82
+ artist.mkdir(parents=True)
83
+ (artist / "someone-shared.css").write_text(self.CSS, encoding="utf-8")
84
+ (artist / "about.html").write_text(
85
+ '<div class="sub-nav">\n'
86
+ ' <a href="./" class="nav-card c-back">← back</a>\n'
87
+ f' <a href="videos.html" class="nav-card {cls}">videos</a>\n'
88
+ '</div>\n',
89
+ encoding="utf-8",
90
+ )
91
+ return ArchiveClient(project_root=tmp_path)
92
+
93
+ def test_videos_link_with_videos_class_is_clean(self, tmp_path):
94
+ assert self._page(tmp_path, "c-videos").check_format() == []
95
+
96
+ def test_videos_link_with_old_class_warns(self, tmp_path):
97
+ warnings = self._page(tmp_path, "c-music-videos").check_format()
98
+ assert len(warnings) == 1
99
+ assert "expected c-videos" in warnings[0].msg
@@ -156,3 +156,125 @@ class TestRegistration:
156
156
  from magmascript.core.config import load_config
157
157
 
158
158
  assert load_config().mc1.host == "9.9.9.9"
159
+
160
+
161
+ class TestWakeOnLan:
162
+ """`mc1 wake` sends by BOTH routes.
163
+
164
+ A magic packet goes to 255.255.255.255:9, which is never routed, so a
165
+ direct send reaches MC1 only from MC1's own subnet. Direct-only is what
166
+ made the Mac's wake-mc1 silently do nothing from off that subnet, and
167
+ these are the checks that would have caught it.
168
+ """
169
+
170
+ def _client(self, *, pi_host="10.0.0.9", pi_user="jake"):
171
+ from magmascript.core.config import Config, MC1Config, PIConfig
172
+ from magmascript.domains.mc1 import MC1Client
173
+
174
+ return MC1Client(
175
+ Config(
176
+ mc1=MC1Config(host="1.2.3.4", user="someone"),
177
+ pi=PIConfig(host=pi_host, user=pi_user),
178
+ )
179
+ )
180
+
181
+ def _stub(self, monkeypatch, client, *, direct, relay):
182
+ """Record calls and report the given per-route outcomes."""
183
+ calls = []
184
+ monkeypatch.setattr(
185
+ type(client),
186
+ "_wol_direct",
187
+ staticmethod(lambda mac: (calls.append(("direct", mac)), direct)[1]),
188
+ )
189
+ monkeypatch.setattr(
190
+ type(client),
191
+ "_wol_relay",
192
+ lambda self, mac: (calls.append(("relay", mac)), relay)[1],
193
+ )
194
+ return calls
195
+
196
+ def test_sends_both_routes(self, monkeypatch):
197
+ client = self._client()
198
+ calls = self._stub(monkeypatch, client, direct=True, relay=True)
199
+ out = client.wake_on_lan("A0:AD:9F:A4:72:97")
200
+ assert [c[0] for c in calls] == ["direct", "relay"]
201
+ assert "direct broadcast sent" in out
202
+ assert "relayed via 10.0.0.9" in out
203
+
204
+ def test_relay_carries_it_when_direct_fails(self, monkeypatch):
205
+ """The off-LAN case: no local wakeonlan, Pi still delivers."""
206
+ client = self._client()
207
+ self._stub(monkeypatch, client, direct=False, relay=True)
208
+ out = client.wake_on_lan("A0:AD:9F:A4:72:97")
209
+ assert "direct broadcast FAILED" in out
210
+ assert "relayed via 10.0.0.9" in out
211
+
212
+ def test_direct_carries_it_when_relay_fails(self, monkeypatch):
213
+ client = self._client()
214
+ self._stub(monkeypatch, client, direct=True, relay=False)
215
+ out = client.wake_on_lan("A0:AD:9F:A4:72:97")
216
+ assert "direct broadcast sent" in out
217
+ assert "relay via 10.0.0.9 FAILED" in out
218
+
219
+ def test_raises_when_no_route_accepts(self, monkeypatch):
220
+ from magmascript.core.exceptions import MagmascriptError
221
+
222
+ client = self._client()
223
+ self._stub(monkeypatch, client, direct=False, relay=False)
224
+ try:
225
+ client.wake_on_lan("A0:AD:9F:A4:72:97")
226
+ except MagmascriptError as e:
227
+ assert "no route accepted" in str(e)
228
+ else:
229
+ raise AssertionError("expected MagmascriptError when both routes fail")
230
+
231
+ def test_unconfigured_pi_is_named_not_silently_skipped(self, monkeypatch):
232
+ """A missing [pi] host makes this home-only, so it must say so."""
233
+ client = self._client(pi_host="", pi_user="")
234
+ calls = self._stub(monkeypatch, client, direct=True, relay=True)
235
+ out = client.wake_on_lan("A0:AD:9F:A4:72:97")
236
+ assert [c[0] for c in calls] == ["direct"]
237
+ assert "relay SKIPPED" in out
238
+ assert "home-only" in out
239
+
240
+ def test_relay_false_skips_the_pi(self, monkeypatch):
241
+ client = self._client()
242
+ calls = self._stub(monkeypatch, client, direct=True, relay=True)
243
+ client.wake_on_lan("A0:AD:9F:A4:72:97", relay=False)
244
+ assert [c[0] for c in calls] == ["direct"]
245
+
246
+ def test_hyphens_are_normalised(self, monkeypatch):
247
+ client = self._client()
248
+ calls = self._stub(monkeypatch, client, direct=True, relay=True)
249
+ client.wake_on_lan("A0-AD-9F-A4-72-97")
250
+ assert {c[1] for c in calls} == {"A0:AD:9F:A4:72:97"}
251
+
252
+ def test_rejects_a_non_mac(self, monkeypatch):
253
+ client = self._client()
254
+ calls = self._stub(monkeypatch, client, direct=True, relay=True)
255
+ for bad in ("", "nope", "A0:AD:9F:A4:72", "A0:AD:9F:A4:72:97:FF", "ZZ:..."):
256
+ try:
257
+ client.wake_on_lan(bad)
258
+ except ValueError:
259
+ pass
260
+ else:
261
+ raise AssertionError(f"expected ValueError for {bad!r}")
262
+ assert calls == [], "nothing may be sent for a malformed MAC"
263
+
264
+ def test_rejects_shell_injection_before_sending(self, monkeypatch):
265
+ """The relay interpolates the MAC into a command a remote shell parses."""
266
+ client = self._client()
267
+ calls = self._stub(monkeypatch, client, direct=True, relay=True)
268
+ for bad in (
269
+ "A0:AD:9F:A4:72:97; touch /tmp/pwned",
270
+ "A0:AD:9F:A4:72:97 && reboot",
271
+ "$(reboot)",
272
+ "`reboot`",
273
+ ):
274
+ try:
275
+ client.wake_on_lan(bad)
276
+ except ValueError:
277
+ pass
278
+ else:
279
+ raise AssertionError(f"expected ValueError for {bad!r}")
280
+ assert calls == []
File without changes
File without changes