Test missing cases for fast_forward or backward (#714)
What changed, and why it matters
This commit is a routine test and build-tool update. It adds automated tests for fast-forward and fast-backward button navigation in several user-interface screens, and expands the project's flashing/erase commands in the build script and pyproject.toml. There is no change to how the device handles secrets, cryptography, or user data, and no security bug is being fixed.
No security action required. Treat as normal development/test coverage commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff is almost entirely new unit tests in tests/pages/ for DatumTool, Keypad, Stackbit, and TinySeed that exercise the turbo/fast-scroll button paths (FAST_FORWARD/FAST_BACKWARD/PRESSED). It also updates the krux shell script and pyproject.toml to support an ‘erase’ subcommand and additional ktool-based tasks (boot, terminal, erase). No runtime code under test is modified, and no security-sensitive logic is changed.
Changed components
tests/pages/test_datum_tool.pytests/pages/test_keypads.pytests/pages/test_stackbit.pytests/pages/test_tiny_seed.pykrux build scriptpyproject.tomlInspect captured patch +89 / −5
diff --git a/krux b/krux
index 6a09aae..82801bf 100755
--- a/krux
+++ b/krux
@@ -86,11 +86,13 @@ if [ "$1" == "build" ]; then
echo "Wrong or unsupported device name, use maixpy_devicename"
fi
fi
-elif [ "$1" == "flash" -o "$1" == "boot" ]; then
+elif [ "$1" == "flash" -o "$1" == "boot" -o "$1" == "erase" ]; then
if [ "$1" == "flash" ]; then
CMD_SUFFIX="kboot.kfpkg"
- else
+ elif [ "$1" == "boot" ]; then
CMD_SUFFIX="-s firmware.bin"
+ else
+ CMD_SUFFIX="-E"
fi
device="$2"
if [ -z "$device" ]; then
diff --git a/pyproject.toml b/pyproject.toml
index 16bfe90..be18000 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -133,10 +133,17 @@ git-update = "git submodule update --init --recursive"
git-pull = "git pull git@github.com:selfcustody/krux.git"
git-pull-https = "git pull https://github.com/selfcustody/krux.git"
-# flash tasks
-flash-cmd = "python firmware/Kboot/build/ktool.py -b 2000000 build/kboot.kfpkg"
+# ktool tasks
+ktool-cmd = "python firmware/Kboot/build/ktool.py -b 2000000"
+flash-cmd.ref = "ktool-cmd build/kboot.kfpkg"
flash.ref = "flash-cmd -B goE"
flash-dock.ref = "flash-cmd -B dan"
+boot-cmd.ref = "ktool-cmd -s build/firmware.bin"
+boot.ref = "boot-cmd -B goE"
+boot-dock.ref = "boot-cmd -B dan"
+terminal.ref = "ktool-cmd -T" # for yahboom add param: --reset
+erase.ref = "ktool-cmd -B goE -E"
+erase-dock.ref = "ktool-cmd -B dan -E"
# task for bdftokff font glyphs update
update-glyphs = "python ./firmware/font/bdftokff.py True"
diff --git a/tests/pages/test_datum_tool.py b/tests/pages/test_datum_tool.py
index f5cd574..aec716a 100644
--- a/tests/pages/test_datum_tool.py
+++ b/tests/pages/test_datum_tool.py
@@ -1047,3 +1047,30 @@ def test_datumtool_view_contents(m5stickv, mocker, mock_file_operations):
page.contents = some_bytes
page.view_contents()
assert ctx.input.wait_for_button.call_count == len(BTN_SEQUENCE)
+
+
+def test_datumtool_show_contents_button_turbo(mocker, m5stickv):
+ from krux.pages.datum_tool import DatumTool
+ from krux.input import PRESSED, BUTTON_ENTER, KEY_REPEAT_DELAY_MS
+ import time
+
+ ctx = create_ctx(mocker, [BUTTON_ENTER, BUTTON_ENTER])
+ datum = DatumTool(ctx)
+ datum.contents = "testing 123 " * 250
+
+ mocker.patch("time.sleep_ms", new=mocker.MagicMock())
+
+ # fast forward
+ ctx.input.page_value = mocker.MagicMock(side_effect=[PRESSED, None])
+
+ datum._show_contents()
+
+ time.sleep_ms.assert_called_with(KEY_REPEAT_DELAY_MS)
+
+ # fast backward
+ ctx.input.page_value = mocker.MagicMock(return_value=None)
+ ctx.input.page_prev_value = mocker.MagicMock(side_effect=[PRESSED, None])
+
+ datum._show_contents()
+
+ time.sleep_ms.assert_called_with(KEY_REPEAT_DELAY_MS)
diff --git a/tests/pages/test_keypads.py b/tests/pages/test_keypads.py
new file mode 100644
index 0000000..c544f5e
--- /dev/null
+++ b/tests/pages/test_keypads.py
@@ -0,0 +1,21 @@
+from . import create_ctx
+import pytest
+
+
+def test_button_turbo(mocker, m5stickv):
+ from krux.pages.keypads import Keypad
+ from krux.input import FAST_FORWARD, FAST_BACKWARD, PRESSED
+
+ ctx = create_ctx(mocker, [])
+ keypad = Keypad(ctx, "abc")
+ mocker.spy(keypad, "_next_key")
+ mocker.spy(keypad, "_previous_key")
+ ctx.input.page_value = mocker.MagicMock(side_effect=[PRESSED, None])
+
+ keypad.navigate(FAST_FORWARD)
+ keypad._next_key.assert_called()
+
+ ctx.input.page_value = mocker.MagicMock(side_effect=None)
+ ctx.input.page_prev_value = mocker.MagicMock(side_effect=[PRESSED, None])
+ keypad.navigate(FAST_BACKWARD)
+ keypad._previous_key.assert_called()
diff --git a/tests/pages/test_stackbit.py b/tests/pages/test_stackbit.py
index 2ca8745..87657a3 100644
--- a/tests/pages/test_stackbit.py
+++ b/tests/pages/test_stackbit.py
@@ -151,3 +151,30 @@ def test_esc_entering_stackbit(amigo, mocker):
assert ctx.input.wait_for_button.call_count == len(BTN_SEQUENCE)
assert words == None
+
+
+def test_entering_stackbit_buttons_turbo(mocker, m5stickv):
+ from krux.pages.stack_1248 import Stackbit
+ from krux.input import PRESSED, FAST_FORWARD, FAST_BACKWARD
+ import pytest
+
+ ctx = create_ctx(mocker, [])
+ stackbit = Stackbit(ctx)
+ stackbit.index = mocker.MagicMock(side_effect=ValueError)
+
+ # fast forward
+ ctx.input.page_value = mocker.MagicMock(return_value=PRESSED)
+
+ with pytest.raises(ValueError):
+ stackbit.enter_1248()
+
+ stackbit.index.assert_called_with(0, FAST_FORWARD)
+
+ # fast backward
+ ctx.input.page_value = mocker.MagicMock(return_value=None)
+ ctx.input.page_prev_value = mocker.MagicMock(return_value=PRESSED)
+
+ with pytest.raises(ValueError):
+ stackbit.enter_1248()
+
+ stackbit.index.assert_called_with(0, FAST_BACKWARD)
diff --git a/tests/pages/test_tiny_seed.py b/tests/pages/test_tiny_seed.py
index 82f20fb..1582023 100644
--- a/tests/pages/test_tiny_seed.py
+++ b/tests/pages/test_tiny_seed.py
@@ -101,10 +101,10 @@ def test_enter_tiny_seed_button_turbo(mocker, m5stickv):
ctx = create_ctx(mocker, [])
tiny_seed = TinySeed(ctx)
+ tiny_seed._new_index = mocker.MagicMock(side_effect=ValueError)
# fast forward
ctx.input.page_value = mocker.MagicMock(return_value=PRESSED)
- tiny_seed._new_index = mocker.MagicMock(side_effect=ValueError)
with pytest.raises(ValueError):
tiny_seed.enter_tiny_seed()
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.