Skip to content

test: staterc values are escaped and safe to source - #41

Open
EnzoItaliano wants to merge 8 commits into
HyDE-Project:mainfrom
EnzoItaliano:test/staterc-quoting
Open

EnzoItaliano wants to merge 8 commits into
HyDE-Project:mainfrom
EnzoItaliano:test/staterc-quoting

Conversation

@EnzoItaliano

@EnzoItaliano EnzoItaliano commented Oct 11, 2026 •

Copy link
Copy Markdown

Description

Tests for HyDE-Project/HyDE#2197. staterc is read with source, but its writers didn't escape values: a $(...) or backtick in a value (for example a theme's directory name, saved as HYDE_THEME) ran as a command, and a " broke the file. The companion HyDE PR writes KEY="value" with \ " $ and the backtick escaped everywhere, and the Lua and Python readers undo it.

  1. test_staterc.sh, case 13 (staterc.sh):

    • a"b, $(touch …), a backtick command, a\b, \, a\, ", $HOME, x\$y and an empty value each read back unchanged by source, and neither command runs;
    • an ordinary value (Gruvbox Retro) is written exactly as before;
    • a value with a newline or carriage return exits 2 and leaves the file untouched.

    Case 9 (set_conf() with a backslash) now expects the escaped line, and also checks that source reads it back as back\slash.

  2. lua/staterc_harness.lua, cases 4–6 (staterc_get()):

    • the same values round-trip through staterc_set() and staterc_get(), and a newline is refused;
    • an old raw line K="back\slash" reads as source reads it;
    • an unquoted line reads as-is.
  3. check_staterc_waybar.py (waybar.py):

    • expected lines switch to the quoted form; a line seeded in the old unquoted form is kept as it was;
    • case 10: values round-trip through set_state_value() and get_state_value(), an old unquoted path with a space still reads, a newline raises ValueError and leaves the file untouched, and _add_missing_state_values() escapes too;
    • case 11: what waybar.py writes is read back by source without running anything, and what staterc.sh writes is read back by waybar.py.

On HyDE dev @ 90bffa6d this fails: the commands run, a " breaks sourcing, and waybar.py writes unquoted lines. With the companion PR it passes.

This branch builds on #40 (the staterc lock tests, still open), so until #40 is merged its commits show here too. It merges cleanly with main; the full suite on main plus this branch, against the HyDE PR, is 60 cases, 0 failed.

Companion HyDE PR: HyDE-Project/HyDE#2198

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (non-breaking change; modified files are limited to the documentations)
  • Technical debt (a code change that does not fix a bug or add a feature but makes something clearer for devs)
  • Other (provide details below)

Checklist

  • I have read the CONTRIBUTING document.
  • My commit message follows the commit guidelines.
  • I have tested my code locally and it works as expected.

Covers staterc.sh and set_conf(): fresh install, replace in place,
duplicate keys collapsed, literal values (/, &, |, backslash, %), usage
errors, 40 concurrent writers losing nothing, mode kept, a failed write
leaving staterc unchanged, and set_conf() going through the helper.
check_staterc_waybar.py runs 20 Python and 20 bash writers at once and
checks nothing is lost, plus a fresh install, duplicate keys, a failed
replace leaving staterc intact, ensure_state_file() not deadlocking on the
lock, and the file mode being kept. test_staterc.sh runs it.
staterc_harness.lua checks staterc_set() on a fresh install, a value
with a quote, slash, ampersand and backslash, and a refused key leaving
staterc untouched. test_staterc.sh runs it, then 10 Lua and 10 bash
writers at once, and skips when lua or lfs is unavailable.
test_staterc.sh holds staterc.lock and checks that staterc.sh prints its
timeout warning and writes; check_staterc_waybar.py makes staterc.lock
unopenable and checks that set_state_value() still writes.
…urrent ones

Case 8: with only WAYBAR_LAYOUT_PATH in staterc, the name and style are
filled in from it. Case 9: a layout another writer sets while
ensure_state_file() works out its values is not overwritten.
@coderabbitai

coderabbitai Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d688004d-c738-4c53-ba6f-96a10502e616

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant