Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283"""Host resources in a VM that installed none, as a sealing or helper VM is.
Every entry point that reads albedo's shipped files or starts its Pythonhelpers installs the host resources first (robot-docs/runtime.md, "Hostresources"). A VM that skipped it must get typed errors rather than a crash,and the sealing VM, which installs nothing, must build the same extensiondeclarations a daemon does. Neither shows in a daemon scenario: every daemoninstalls before it does anything else."""
import osfrom pathlib import Pathimport subprocessimport unittest
ROOT = Path(__file__).resolve().parents[2]
def ebins() -> list[str]: # The gate's sealed snapshot when there is one: `gleam test` may be # rebuilding build/dev while this runs. snapshot = os.environ.get("ALBEDO_TEST_DAEMON") root = Path(snapshot).parent if snapshot else ROOT / "apps/albedo/build/dev/erlang" found = sorted(str(path) for path in root.glob("*/ebin")) if not found: raise RuntimeError(f"no compiled applications under {root}") return found
def fresh_vm(expression: str) -> subprocess.CompletedProcess[str]: return subprocess.run( ["erl", "+S", "2:2", "-noshell", "-pa", *ebins(), "-eval", expression], capture_output=True, text=True, timeout=120, )
class HostResourcesTest(unittest.TestCase): def run_vm(self, expression: str) -> None: result = fresh_vm(expression + ' io:put_chars(<<"ok">>), halt().') self.assertEqual( (result.returncode, result.stdout[-2:]), (0, "ok"), result.stdout + result.stderr, )
def test_a_vm_without_an_install_gets_typed_errors(self): self.run_vm( "none = 'albedo_sdk@host_resources':assets()," " {error, nil} = 'albedo_sdk@priv':directory()," " none = 'albedo_sdk@priv':shipped(<<\"skills\">>)," # No roots, so a TLS client fails its certificate check rather # than trusting roots albedo's policy would leave out. " [] = 'albedo_sdk@host_resources':trusted_roots()," ' Script = {python_script, <<"albedo_discord.py">>, <<"probe">>, [], []},' " {error, not_installed} =" " 'albedo_sdk@host_resources':open_python(Script)," " {error, not_installed} =" " 'albedo_sdk@host_resources':open_kernel_script(Script)," ' {start_failed, <<"albedo\'s host resources are not installed">>} =' " 'albedo_sdk@helper':run(<<\"albedo_hook_command.py\">>," ' <<"probe">>, <<"{}">>, 1000),' )
def test_sealed_declarations_do_not_depend_on_an_install(self): # What build_identity.seal_build caches, built before and after an # install in one VM, as the sealing VM and the daemon would. self.run_vm( "{ok, _} = application:ensure_all_started(crypto)," " Before = 'albedo@composition@extensions':declared()," " nil = 'albedo@lifecycle@host_install':install()," " After = 'albedo@composition@extensions':declared()," " true = Before =:= After," " {some, Assets} = 'albedo_sdk@host_resources':assets()," " {ok, Assets} = 'albedo_sdk@priv':directory()," " true = filelib:is_dir(Assets)," )
if __name__ == "__main__": unittest.main()