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.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374"""Frames whose text JSON cannot carry as the daemon reads it.
A path decoded with surrogateescape holds a lone surrogate, and a float canbe NaN or infinite. The daemon's JSON reader refuses both, so the kernel'slink refuses to send them rather than have its kernel abandoned. A framethat only shows text (a file-change trace, an error) must still arrive, anda remote call's result must still reach its caller, exactly when it is avalue. Before this, the trace was dropped with an encoder error in thecell's output, and a remote invoke never got its reply. These need a realkernel's frames, with no daemon."""
import mathimport sysfrom typing import castimport unittest
from kernel_owner_support import ROOT, Kernel
sys.path.insert(0, str(ROOT / "python"))import albedo_values # noqa: E402
FUNCTIONS = """import osdef nan(): return float("nan")def infinities(): return [float("inf"), {"low": float("-inf")}]def lone(): return os.fsdecode(b"/tmp/x\\xff")def fails(): raise FileNotFoundError(os.fsdecode(b"/nowhere/\\xff"))"""
class KernelFrameTextTest(unittest.TestCase): def setUp(self) -> None: self.kernel = Kernel(["run", "files"]) self.addCleanup(self.kernel.close)
def test_a_trace_naming_an_undecodable_path_is_delivered(self) -> None: done = self.kernel.execute( "import os\n" "try:\n" " open(os.fsdecode(b'/nonexistent/\\xff'))\n" "except FileNotFoundError:\n" " pass\n" ) self.assertEqual(done["status"], "ok", done) self.assertNotIn("not delivered", done["output"]) [trace] = [f for f in self.kernel.observed("trace") if f["id"] == done["id"]] targets = [a["target"] for a in trace["trace"]["activities"]] self.assertIn("/nonexistent/\ufffd", targets)
def test_a_remote_result_holding_nan_or_a_lone_surrogate_is_answered(self): self.assertEqual(self.kernel.execute(FUNCTIONS)["status"], "ok") nan = self.kernel.invoke("nan", name="nan") self.assertTrue(nan["ok"], nan) self.assertTrue(math.isnan(cast(float, albedo_values.decode(nan["value"])))) infinities = self.kernel.invoke("inf", name="infinities") self.assertEqual( albedo_values.decode(infinities["value"]), [math.inf, {"low": -math.inf}], ) lone = self.kernel.invoke("lone", name="lone") self.assertEqual(albedo_values.decode(lone["value"]), "/tmp/x\udcff") failed = self.kernel.invoke("fails", name="fails") self.assertFalse(failed["ok"]) self.assertEqual(failed["error"]["ename"], "FileNotFoundError")
if __name__ == "__main__": unittest.main()