chore(release): promote 661be3ee to main

This commit is contained in:
imSp4rky
2026-11-23 19:20:21 -07:00
760 changed files with 74155 additions and 6855 deletions
+68
View File
@@ -0,0 +1,68 @@
from __future__ import annotations
import logging
from pathlib import Path
import pytest
from click.testing import CliRunner
from unshackle.commands import cfg as cfg_module
@pytest.fixture
def config_file(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
path = tmp_path / "unshackle.yaml"
monkeypatch.setattr(cfg_module, "get_config_path", lambda: path)
return path
def test_a_duplicate_key_logs_its_lines_once_and_names_no_key_or_value(
config_file: Path, caplog: pytest.LogCaptureFixture
) -> None:
config_file.write_text(
"theme: rainbow\ncredentials:\n EXAMPLE: first-secret\n OTHER: other\n EXAMPLE: second-secret\n"
"serve:\n users:\n key-secret: {tier: a}\n key-secret: {tier: b}\n",
encoding="utf-8",
)
with caplog.at_level(logging.WARNING, logger="config"):
result = CliRunner().invoke(cfg_module.cfg, ["theme"])
CliRunner().invoke(cfg_module.cfg, ["theme"])
assert isinstance(result.exception, SystemExit), result.exception
assert result.exit_code == 1
assert caplog.messages == [
f"{config_file}: duplicate key on lines 3 and 5, lines 8 and 9. Unshackle uses the later one."
]
assert "Error" not in result.output and "lines" not in result.output
for output in (result.output, caplog.text):
assert "secret" not in output and "EXAMPLE" not in output
def test_a_duplicate_key_blocks_a_write(config_file: Path) -> None:
original = "theme: rainbow\ncredentials:\n EXAMPLE: a\n EXAMPLE: b\n"
config_file.write_text(original, encoding="utf-8")
result = CliRunner().invoke(cfg_module.cfg, ["theme", "plain"])
assert result.exit_code == 1
assert config_file.read_text(encoding="utf-8") == original
def test_a_valid_config_still_reads_a_key(config_file: Path) -> None:
config_file.write_text("theme: rainbow\n", encoding="utf-8")
result = CliRunner().invoke(cfg_module.cfg, ["theme"])
assert result.exit_code == 0, result.output
assert "rainbow" in result.output
def test_a_duplicate_only_ruamel_sees_still_gives_its_line(config_file: Path, caplog: pytest.LogCaptureFixture) -> None:
config_file.write_text("a: 1\n1: x\n0x1: y\n", encoding="utf-8")
with caplog.at_level(logging.WARNING):
result = CliRunner().invoke(cfg_module.cfg, ["a"])
assert result.exit_code == 1
assert caplog.messages == [f"{config_file}: duplicate key on line 3. Unshackle uses the later one."]
def test_lowercase_true_and_false_are_written_as_booleans_and_no_stays_a_language(config_file: Path) -> None:
config_file.write_text("theme: rainbow\n", encoding="utf-8")
for key, value in (("wide_output", "false"), ("debug_requests", "TRUE"), ("lang", "no")):
assert CliRunner().invoke(cfg_module.cfg, [key, value]).exit_code == 0
text = config_file.read_text(encoding="utf-8")
assert "wide_output: false\n" in text and "debug_requests: true\n" in text and "lang: no\n" in text
+54
View File
@@ -0,0 +1,54 @@
from __future__ import annotations
from pathlib import Path
import pytest
from click.testing import CliRunner
from unshackle.commands import kv as kv_module
from unshackle.vaults.SQLite import SQLite
KID = "0" * 31 + "1"
KEY = "a" * 32
def test_kv_copy_moves_a_plain_tag_table_from_a_file_into_the_vault_tag_table(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
source = tmp_path / "key_store.db"
SQLite("seed", source).add_key("TESTSVC", KID, KEY)
dest = tmp_path / "local.db"
monkeypatch.setattr(kv_module.config, "key_vaults", [{"type": "SQLite", "name": "local", "path": str(dest)}])
monkeypatch.setattr(kv_module.Services, "get_vault_tag", lambda name: "Shared" if name == "TESTSVC" else name)
result = CliRunner().invoke(kv_module.kv, ["copy", "local", str(source), "-s", "TESTSVC"])
assert result.exit_code == 0, result.output
check = SQLite("check", dest)
assert check.get_key(KID, "Shared") == KEY
assert check.get_key(KID, "TESTSVC") is None
def test_kv_copy_rejects_a_name_that_is_neither_configured_nor_a_file(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(kv_module.config, "key_vaults", [])
result = CliRunner().invoke(kv_module.kv, ["copy", "local", "nowhere.db"])
assert result.exit_code != 0
assert "not defined in the config" in result.output
def test_kv_add_skips_a_null_key_line_and_adds_the_rest(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
keys = tmp_path / "keys.txt"
null_kid = "0" * 31 + "2"
keys.write_text(f"{KID}:{KEY}\n{null_kid}:{'0' * 32}\n", encoding="utf8")
dest = tmp_path / "local.db"
monkeypatch.setattr(kv_module.config, "key_vaults", [{"type": "SQLite", "name": "local", "path": str(dest)}])
monkeypatch.setattr(kv_module.Services, "get_vault_tag", lambda name: name)
result = CliRunner().invoke(kv_module.kv, ["add", str(keys), "TESTSVC", "local"])
assert result.exit_code == 0, result.output
check = SQLite("check", dest)
assert check.get_key(KID, "TESTSVC") == KEY
assert check.get_key(null_kid, "TESTSVC") is None