From c043bf225552837b2b0f61ba5198ee2edb1676d5 Mon Sep 17 00:00:00 2001 From: Alex Myers Date: Mon, 13 Nov 2023 15:58:54 -0600 Subject: [PATCH] reckless: properly remove entry from reckless sources Fixes a bug introduced in 61631384203fda2a3ef04407d88b53c1af589dde which avoided gratuitous rewrites of the lightningd config --- tests/test_reckless.py | 32 +++++++++++++++++++++++++++++++- tools/reckless | 6 +++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/tests/test_reckless.py b/tests/test_reckless.py index ac4f0db19..498fae982 100644 --- a/tests/test_reckless.py +++ b/tests/test_reckless.py @@ -101,7 +101,8 @@ def get_reckless_node(node_factory): def check_stderr(stderr): def output_okay(out): - for warning in ['[notice]', 'WARNING:', 'npm WARN', 'npm notice']: + for warning in ['[notice]', 'WARNING:', 'npm WARN', + 'npm notice', 'DEPRECATION:']: if out.startswith(warning): return True return False @@ -135,6 +136,35 @@ def test_sources(node_factory): n = get_reckless_node(node_factory) r = reckless(["source", "-h"], dir=n.lightning_dir) assert r.returncode == 0 + r = reckless(["source", "list"], dir=n.lightning_dir) + print(r.stdout) + assert r.returncode == 0 + print(n.lightning_dir) + reckless_dir = Path(n.lightning_dir) / 'reckless' + print(dir(reckless_dir)) + assert (reckless_dir / '.sources').exists() + print(os.listdir(reckless_dir)) + print(reckless_dir / '.sources') + r = reckless([f"--network={NETWORK}", "-v", "source", "add", + "tests/data/recklessrepo/lightningd/testplugfail"], + dir=n.lightning_dir) + r = reckless([f"--network={NETWORK}", "-v", "source", "add", + "tests/data/recklessrepo/lightningd/testplugpass"], + dir=n.lightning_dir) + with open(reckless_dir / '.sources') as sources: + contents = [c.strip() for c in sources.readlines()] + print('contents:', contents) + assert 'https://github.com/lightningd/plugins' in contents + assert "tests/data/recklessrepo/lightningd/testplugfail" in contents + assert "tests/data/recklessrepo/lightningd/testplugpass" in contents + r = reckless([f"--network={NETWORK}", "-v", "source", "remove", + "tests/data/recklessrepo/lightningd/testplugfail"], + dir=n.lightning_dir) + with open(reckless_dir / '.sources') as sources: + contents = [c.strip() for c in sources.readlines()] + print('contents:', contents) + assert "tests/data/recklessrepo/lightningd/testplugfail" not in contents + assert "tests/data/recklessrepo/lightningd/testplugpass" in contents def test_search(node_factory): diff --git a/tools/reckless b/tools/reckless index 531527da5..df283cabd 100755 --- a/tools/reckless +++ b/tools/reckless @@ -474,10 +474,10 @@ class Config(): # The white space is getting excessive. remove_these_lines.append(n) continue - if not addline: + if not addline and not write_required: return # No write necessary if addline is already in config. - if not write_required: + if addline and not write_required: for line in original: if line.strip() == addline.strip(): return @@ -490,7 +490,7 @@ class Config(): conf_write.write(f'\n{l.strip()}') else: conf_write.write(l.strip()) - if addline.strip() == l.strip(): + if addline and addline.strip() == l.strip(): # addline is idempotent line_exists = True if not line_exists: