diff options
Diffstat (limited to 'tests/test_config.py')
| -rw-r--r-- | tests/test_config.py | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/test_config.py b/tests/test_config.py index 9a6bf89..b0dfac0 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -195,3 +195,77 @@ def test_rejects_empty_host(tmp_path: Path) -> None: ) with pytest.raises(ConfigError, match="host"): load_config(path, validate_paths=False) + + +def test_prompt_defaults_to_empty_when_omitted(tmp_path: Path) -> None: + path = tmp_path / "config.toml" + path.write_text( + f'[model]\nroot = "{tmp_path.as_posix()}"\ncheckpoint = "base.safetensors"\n', + encoding="utf-8", + ) + config = load_config(path, validate_paths=False) + assert config.prompt.positive == "" + assert config.prompt.negative == "" + + +def test_prompt_reads_files_from_root_prompts(tmp_path: Path) -> None: + root = tmp_path / "models" + (root / "checkpoints").mkdir(parents=True) + (root / "checkpoints" / "base.safetensors").touch() + (root / "prompts").mkdir() + (root / "prompts" / "positive.txt").write_text("masterpiece, best quality", encoding="utf-8") + (root / "prompts" / "negative.txt").write_text("low quality, blurry", encoding="utf-8") + path = tmp_path / "config.toml" + path.write_text( + f'[model]\nroot = "{root.as_posix()}"\ncheckpoint = "base.safetensors"\n' + '[prompt]\npositive_file = "positive.txt"\nnegative_file = "negative.txt"\n', + encoding="utf-8", + ) + config = load_config(path) + assert config.prompt.positive == "masterpiece, best quality" + assert config.prompt.negative == "low quality, blurry" + + +def test_prompt_rejects_path_traversal(tmp_path: Path) -> None: + root = tmp_path / "models" + (root / "checkpoints").mkdir(parents=True) + (root / "checkpoints" / "base.safetensors").touch() + path = tmp_path / "config.toml" + path.write_text( + f'[model]\nroot = "{root.as_posix()}"\ncheckpoint = "base.safetensors"\n' + '[prompt]\npositive_file = "../escape.txt"\n', + encoding="utf-8", + ) + with pytest.raises(ConfigError, match="file name"): + load_config(path, validate_paths=False) + + +def test_prompt_rejects_missing_file(tmp_path: Path) -> None: + root = tmp_path / "models" + (root / "checkpoints").mkdir(parents=True) + (root / "checkpoints" / "base.safetensors").touch() + path = tmp_path / "config.toml" + path.write_text( + f'[model]\nroot = "{root.as_posix()}"\ncheckpoint = "base.safetensors"\n' + '[prompt]\npositive_file = "absent.txt"\n', + encoding="utf-8", + ) + with pytest.raises(ConfigError, match="prompt file"): + load_config(path, validate_paths=False) + + +def test_prompt_accepts_only_positive(tmp_path: Path) -> None: + root = tmp_path / "models" + (root / "checkpoints").mkdir(parents=True) + (root / "checkpoints" / "base.safetensors").touch() + (root / "prompts").mkdir() + (root / "prompts" / "positive.txt").write_text("masterpiece", encoding="utf-8") + path = tmp_path / "config.toml" + path.write_text( + f'[model]\nroot = "{root.as_posix()}"\ncheckpoint = "base.safetensors"\n' + '[prompt]\npositive_file = "positive.txt"\n', + encoding="utf-8", + ) + config = load_config(path) + assert config.prompt.positive == "masterpiece" + assert config.prompt.negative == "" |
