secretshield 0.8.0__tar.gz → 0.9.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. {secretshield-0.8.0/secretshield.egg-info → secretshield-0.9.0}/PKG-INFO +1 -1
  2. {secretshield-0.8.0 → secretshield-0.9.0}/pyproject.toml +1 -1
  3. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/__init__.py +1 -1
  4. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/cli.py +81 -3
  5. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/color.py +13 -0
  6. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/ignorefile.py +26 -0
  7. {secretshield-0.8.0 → secretshield-0.9.0/secretshield.egg-info}/PKG-INFO +1 -1
  8. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield.egg-info/SOURCES.txt +2 -1
  9. secretshield-0.9.0/tests/test_v090_cli_additions.py +275 -0
  10. {secretshield-0.8.0 → secretshield-0.9.0}/LICENSE +0 -0
  11. {secretshield-0.8.0 → secretshield-0.9.0}/README.md +0 -0
  12. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/autofix/__init__.py +0 -0
  13. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/autofix/env.py +0 -0
  14. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/autofix/fixer.py +0 -0
  15. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/autofix/gitignore.py +0 -0
  16. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/autofix/javascript.py +0 -0
  17. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/autofix/python.py +0 -0
  18. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/baseline.py +0 -0
  19. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/config.py +0 -0
  20. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/custom_rules.py +0 -0
  21. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/detector.py +0 -0
  22. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/git/__init__.py +0 -0
  23. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/git/hooks.py +0 -0
  24. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/github/__init__.py +0 -0
  25. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/github/actions.py +0 -0
  26. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/guardian.py +0 -0
  27. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/notifications.py +0 -0
  28. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/patterns.py +0 -0
  29. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/project_config.py +0 -0
  30. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield/redactor.py +0 -0
  31. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield.egg-info/dependency_links.txt +0 -0
  32. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield.egg-info/entry_points.txt +0 -0
  33. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield.egg-info/requires.txt +0 -0
  34. {secretshield-0.8.0 → secretshield-0.9.0}/secretshield.egg-info/top_level.txt +0 -0
  35. {secretshield-0.8.0 → secretshield-0.9.0}/setup.cfg +0 -0
  36. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_autofix.py +0 -0
  37. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_baseline.py +0 -0
  38. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_color.py +0 -0
  39. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_color_cli_integration.py +0 -0
  40. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_custom_rules.py +0 -0
  41. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_custom_rules_cli_integration.py +0 -0
  42. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_detector.py +0 -0
  43. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_git_hooks.py +0 -0
  44. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_github_action.py +0 -0
  45. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_ignorefile.py +0 -0
  46. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_ignorefile_cli_integration.py +0 -0
  47. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_javascript_autofix.py +0 -0
  48. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_logging.py +0 -0
  49. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_project_config.py +0 -0
  50. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_redactor.py +0 -0
  51. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_scan.py +0 -0
  52. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_ss_alias_and_creator.py +0 -0
  53. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_stdout.py +0 -0
  54. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_v030_cli_integration.py +0 -0
  55. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_v040_cli_integration.py +0 -0
  56. {secretshield-0.8.0 → secretshield-0.9.0}/tests/test_v080_self_detection_fix.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: secretshield
3
- Version: 0.8.0
3
+ Version: 0.9.0
4
4
  Summary: Stop secrets before they leak -- runtime redaction, multi-language scanning, auto-fix, Git hooks, and CI, all in one CLI.
5
5
  Author: Samarth Chugh (Sam3360)
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "secretshield"
7
- version = "0.8.0"
7
+ version = "0.9.0"
8
8
  description = "Stop secrets before they leak -- runtime redaction, multi-language scanning, auto-fix, Git hooks, and CI, all in one CLI."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -23,7 +23,7 @@ from .detector import Match, detect
23
23
  from .guardian import disable, enable, is_enabled
24
24
  from .redactor import redact
25
25
 
26
- __version__ = "0.8.0"
26
+ __version__ = "0.9.0"
27
27
 
28
28
  __all__ = [
29
29
  "__version__",
@@ -27,7 +27,7 @@ import sys
27
27
  from pathlib import Path
28
28
 
29
29
  from . import __version__, disable, enable, is_enabled
30
- from .color import green, red, supports_color
30
+ from .color import green, hyperlink, red, supports_color
31
31
  from .detector import detect
32
32
 
33
33
  # --- File type support -----------------------------------------------------
@@ -801,6 +801,18 @@ def _cmd_init(args: argparse.Namespace) -> int:
801
801
  else:
802
802
  print(f"{green(chr(0x2713), use_color)} {path.relative_to(project_root)} already exists, leaving it unchanged")
803
803
 
804
+ # .secretshieldignore is created unconditionally (no extra prompt --
805
+ # it's a tiny, harmless starter file), the same helper --ignore-file
806
+ # uses, and it's always safe: an existing file is left untouched.
807
+ from .ignorefile import create_default_ignore_file
808
+
809
+ ignore_created, ignore_path = create_default_ignore_file(project_root)
810
+ if ignore_created:
811
+ print(f"{green(chr(0x2713), use_color)} Created {ignore_path.name}")
812
+ created.append(ignore_path.name)
813
+ else:
814
+ print(f"{green(chr(0x2713), use_color)} {ignore_path.name} already exists, leaving it unchanged")
815
+
804
816
  print("\nSecretShield is ready.")
805
817
  return 0
806
818
 
@@ -977,18 +989,74 @@ def _cmd_rule_test(args: argparse.Namespace) -> int:
977
989
 
978
990
 
979
991
  CREATOR_MESSAGE = "SecretShield\nCreated by Samarth Chugh (Sam3360)\ngithub.com/Sam3360"
992
+ CREATOR_GITHUB_URL = "https://github.com/Sam3360"
993
+
994
+ USAGE_URL = "https://github.com/Sam3360/secretshield/blob/main/USAGE.md"
980
995
 
981
996
 
982
997
  class _CreatorAction(argparse.Action):
983
998
  """Prints creator info and exits -- mirrors argparse's built-in
984
999
  `action="version"` behavior so `--creator` works the same way
985
- `--version` does, with no subcommand required."""
1000
+ `--version` does, with no subcommand required.
1001
+
1002
+ The GitHub line is wrapped in a standard OSC 8 terminal hyperlink
1003
+ (so supported terminals can Ctrl+Click it) only when connected to a
1004
+ real terminal; piped/non-interactive output gets the same plain
1005
+ text CREATOR_MESSAGE always had, with no escape codes.
1006
+ """
1007
+
1008
+ def __init__(self, option_strings, dest, nargs=0, **kwargs):
1009
+ super().__init__(option_strings, dest, nargs=nargs, **kwargs)
1010
+
1011
+ def __call__(self, parser, namespace, values, option_string=None):
1012
+ link_text = "github.com/Sam3360"
1013
+ link = hyperlink(link_text, CREATOR_GITHUB_URL, supports_color(sys.stdout))
1014
+ print(f"SecretShield\nCreated by Samarth Chugh (Sam3360)\n{link}")
1015
+ parser.exit()
1016
+
1017
+
1018
+ class _UsageAction(argparse.Action):
1019
+ """Prompts, then opens the USAGE.md documentation in the system's
1020
+ default browser on Enter -- never before the user confirms. Ctrl+C
1021
+ and EOF are handled cleanly, with no traceback and no browser
1022
+ launch."""
1023
+
1024
+ def __init__(self, option_strings, dest, nargs=0, **kwargs):
1025
+ super().__init__(option_strings, dest, nargs=nargs, **kwargs)
1026
+
1027
+ def __call__(self, parser, namespace, values, option_string=None):
1028
+ print("SecretShield\n")
1029
+ print("Press Enter to open the USAGE documentation.")
1030
+ print("Ctrl+C to cancel.")
1031
+ try:
1032
+ input()
1033
+ except (KeyboardInterrupt, EOFError):
1034
+ print()
1035
+ parser.exit()
1036
+ return
1037
+ import webbrowser
1038
+
1039
+ webbrowser.open(USAGE_URL)
1040
+ parser.exit()
1041
+
1042
+
1043
+ class _IgnoreFileAction(argparse.Action):
1044
+ """Creates a starter .secretshieldignore in the current directory,
1045
+ reusing the same helper `secretshield init` uses -- never
1046
+ overwrites an existing file."""
986
1047
 
987
1048
  def __init__(self, option_strings, dest, nargs=0, **kwargs):
988
1049
  super().__init__(option_strings, dest, nargs=nargs, **kwargs)
989
1050
 
990
1051
  def __call__(self, parser, namespace, values, option_string=None):
991
- print(CREATOR_MESSAGE)
1052
+ from .ignorefile import create_default_ignore_file
1053
+
1054
+ created, path = create_default_ignore_file(Path.cwd())
1055
+ use_color = supports_color(sys.stdout)
1056
+ if created:
1057
+ print(f"{green(chr(0x2713), use_color)} Created {path.name}")
1058
+ else:
1059
+ print(f"{path.name} already exists.")
992
1060
  parser.exit()
993
1061
 
994
1062
 
@@ -1006,6 +1074,16 @@ def build_parser() -> argparse.ArgumentParser:
1006
1074
  parser.add_argument(
1007
1075
  "--creator", action=_CreatorAction, help="Show who made this and exit."
1008
1076
  )
1077
+ parser.add_argument(
1078
+ "--usage",
1079
+ action=_UsageAction,
1080
+ help="Open the USAGE.md documentation in your browser (asks for confirmation first).",
1081
+ )
1082
+ parser.add_argument(
1083
+ "--ignore-file",
1084
+ action=_IgnoreFileAction,
1085
+ help="Create a starter .secretshieldignore in the current directory.",
1086
+ )
1009
1087
 
1010
1088
  subparsers = parser.add_subparsers(dest="command")
1011
1089
 
@@ -40,3 +40,16 @@ def red(text: str, enabled: bool) -> str:
40
40
 
41
41
  def green(text: str, enabled: bool) -> str:
42
42
  return f"{_GREEN}{text}{_RESET}" if enabled else text
43
+
44
+
45
+ def hyperlink(text: str, url: str, enabled: bool) -> str:
46
+ """
47
+ Wrap `text` in a standard OSC 8 terminal hyperlink escape sequence
48
+ pointing at `url`, so supported terminals can Ctrl+Click it --
49
+ while the *visible* text stays exactly `text`. Falls back to plain
50
+ `text` (no escape codes at all) when `enabled` is False, so
51
+ terminals that don't understand OSC 8 never see raw escape junk.
52
+ """
53
+ if not enabled:
54
+ return text
55
+ return f"\033]8;;{url}\033\\{text}\033]8;;\033\\"
@@ -10,6 +10,32 @@ from pathlib import Path
10
10
 
11
11
  IGNORE_FILENAME = ".secretshieldignore"
12
12
 
13
+ DEFAULT_IGNORE_CONTENT = (
14
+ "# Add files, directories, or patterns here that SecretShield should ignore.\n"
15
+ )
16
+
17
+
18
+ def ignore_file_path(root: Path) -> Path:
19
+ return root / IGNORE_FILENAME
20
+
21
+
22
+ def create_default_ignore_file(root: Path | None = None) -> tuple[bool, Path]:
23
+ """
24
+ Create a starter `.secretshieldignore` in `root` (default: current
25
+ directory) with a short explanatory comment, if one doesn't already
26
+ exist. Never overwrites an existing file -- shared by both the
27
+ `--ignore-file` CLI option and `secretshield init`, so there's only
28
+ one place that generates this starter content.
29
+
30
+ Returns `(created, path)`: `created` is False if the file was
31
+ already there (nothing was touched).
32
+ """
33
+ path = ignore_file_path(root or Path.cwd())
34
+ if path.exists():
35
+ return False, path
36
+ path.write_text(DEFAULT_IGNORE_CONTENT, encoding="utf-8")
37
+ return True, path
38
+
13
39
 
14
40
  def ignore_file_path(root: Path) -> Path:
15
41
  return root / IGNORE_FILENAME
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: secretshield
3
- Version: 0.8.0
3
+ Version: 0.9.0
4
4
  Summary: Stop secrets before they leak -- runtime redaction, multi-language scanning, auto-fix, Git hooks, and CI, all in one CLI.
5
5
  Author: Samarth Chugh (Sam3360)
6
6
  License-Expression: MIT
@@ -50,4 +50,5 @@ tests/test_ss_alias_and_creator.py
50
50
  tests/test_stdout.py
51
51
  tests/test_v030_cli_integration.py
52
52
  tests/test_v040_cli_integration.py
53
- tests/test_v080_self_detection_fix.py
53
+ tests/test_v080_self_detection_fix.py
54
+ tests/test_v090_cli_additions.py
@@ -0,0 +1,275 @@
1
+ """
2
+ Tests for v0.9.0: `--usage`, the OSC 8 hyperlink in `--creator`,
3
+ `--ignore-file`, and `init` now creating `.secretshieldignore`.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import subprocess
9
+
10
+ import pytest
11
+
12
+ from secretshield.cli import CREATOR_GITHUB_URL, USAGE_URL, build_parser, main
13
+ from secretshield.color import hyperlink
14
+ from secretshield.ignorefile import DEFAULT_IGNORE_CONTENT, create_default_ignore_file
15
+
16
+
17
+ def _init_repo(path):
18
+ subprocess.run(["git", "init", "-q"], cwd=path, check=True)
19
+ subprocess.run(["git", "config", "user.email", "t@t.com"], cwd=path, check=True)
20
+ subprocess.run(["git", "config", "user.name", "T"], cwd=path, check=True)
21
+
22
+
23
+ # --- --usage ------------------------------------------------------------
24
+
25
+
26
+ def test_usage_option_exists_in_parser():
27
+ parser = build_parser()
28
+ # Should not raise / should be recognized (will exit via the action
29
+ # once input() is reached -- exercised properly in the tests below).
30
+ assert any("--usage" in opt.option_strings for opt in parser._actions)
31
+
32
+
33
+ def test_usage_enter_opens_browser_with_correct_url(monkeypatch, capsys):
34
+ monkeypatch.setattr("builtins.input", lambda: "")
35
+ opened = {}
36
+
37
+ def fake_open(url):
38
+ opened["url"] = url
39
+
40
+ monkeypatch.setattr("webbrowser.open", fake_open)
41
+
42
+ with pytest.raises(SystemExit):
43
+ main(["--usage"])
44
+
45
+ assert opened.get("url") == USAGE_URL
46
+ assert USAGE_URL == "https://github.com/Sam3360/secretshield/blob/main/USAGE.md"
47
+
48
+
49
+ def test_usage_ctrl_c_does_not_open_browser(monkeypatch, capsys):
50
+ def raise_interrupt():
51
+ raise KeyboardInterrupt
52
+
53
+ monkeypatch.setattr("builtins.input", lambda: raise_interrupt())
54
+ opened = {"called": False}
55
+ monkeypatch.setattr("webbrowser.open", lambda url: opened.update(called=True))
56
+
57
+ with pytest.raises(SystemExit) as exc_info:
58
+ main(["--usage"])
59
+
60
+ assert opened["called"] is False
61
+ assert exc_info.value.code in (0, None)
62
+
63
+
64
+ def test_usage_eof_does_not_open_browser(monkeypatch, capsys):
65
+ def raise_eof():
66
+ raise EOFError
67
+
68
+ monkeypatch.setattr("builtins.input", lambda: raise_eof())
69
+ opened = {"called": False}
70
+ monkeypatch.setattr("webbrowser.open", lambda url: opened.update(called=True))
71
+
72
+ with pytest.raises(SystemExit) as exc_info:
73
+ main(["--usage"])
74
+
75
+ assert opened["called"] is False
76
+ assert exc_info.value.code in (0, None)
77
+
78
+
79
+ def test_usage_prompt_text_shown(monkeypatch, capsys):
80
+ monkeypatch.setattr("builtins.input", lambda: "")
81
+ monkeypatch.setattr("webbrowser.open", lambda url: None)
82
+
83
+ with pytest.raises(SystemExit):
84
+ main(["--usage"])
85
+
86
+ out = capsys.readouterr().out
87
+ assert "Press Enter to open the USAGE documentation." in out
88
+ assert "Ctrl+C to cancel." in out
89
+
90
+
91
+ # --- --creator hyperlink -----------------------------------------------
92
+
93
+
94
+ def test_creator_visible_text_still_correct(monkeypatch, capsys):
95
+ monkeypatch.setattr("sys.stdout.isatty", lambda: False) # plain output
96
+ with pytest.raises(SystemExit):
97
+ main(["--creator"])
98
+ out = capsys.readouterr().out
99
+ assert "Samarth Chugh (Sam3360)" in out
100
+ assert "github.com/Sam3360" in out
101
+
102
+
103
+ def test_creator_github_url_constant_correct():
104
+ assert CREATOR_GITHUB_URL == "https://github.com/Sam3360"
105
+
106
+
107
+ def test_hyperlink_osc8_format_correct():
108
+ link = hyperlink("github.com/Sam3360", CREATOR_GITHUB_URL, True)
109
+ assert link == "\033]8;;https://github.com/Sam3360\033\\github.com/Sam3360\033]8;;\033\\"
110
+
111
+
112
+ def test_hyperlink_visible_text_unchanged():
113
+ import re
114
+
115
+ link = hyperlink("github.com/Sam3360", CREATOR_GITHUB_URL, True)
116
+ # Parse the OSC 8 structure properly: \x1b]8;;URL\x1b\TEXT\x1b]8;;\x1b\
117
+ match = re.match(r"\x1b\]8;;(?P<url>[^\x1b]*)\x1b\\(?P<text>.*)\x1b\]8;;\x1b\\$", link)
118
+ assert match is not None
119
+ assert match.group("text") == "github.com/Sam3360"
120
+ assert match.group("url") == CREATOR_GITHUB_URL
121
+
122
+
123
+ def test_hyperlink_falls_back_to_plain_text_when_disabled():
124
+ link = hyperlink("github.com/Sam3360", CREATOR_GITHUB_URL, False)
125
+ assert link == "github.com/Sam3360"
126
+ assert "\033" not in link
127
+
128
+
129
+ def test_creator_output_has_no_escape_codes_when_not_a_tty(monkeypatch, capsys):
130
+ monkeypatch.setattr("sys.stdout.isatty", lambda: False)
131
+ with pytest.raises(SystemExit):
132
+ main(["--creator"])
133
+ out = capsys.readouterr().out
134
+ assert "\033" not in out
135
+
136
+
137
+ def test_creator_output_has_hyperlink_when_tty(monkeypatch, capsys):
138
+ monkeypatch.setattr("sys.stdout.isatty", lambda: True)
139
+ monkeypatch.delenv("NO_COLOR", raising=False)
140
+ monkeypatch.delenv("FORCE_COLOR", raising=False)
141
+ with pytest.raises(SystemExit):
142
+ main(["--creator"])
143
+ out = capsys.readouterr().out
144
+ assert "\033]8;;https://github.com/Sam3360\033\\" in out
145
+
146
+
147
+ # --- --ignore-file --------------------------------------------------------
148
+
149
+
150
+ def test_ignore_file_creates_file(tmp_path, monkeypatch):
151
+ monkeypatch.chdir(tmp_path)
152
+ with pytest.raises(SystemExit):
153
+ main(["--ignore-file"])
154
+ assert (tmp_path / ".secretshieldignore").exists()
155
+
156
+
157
+ def test_ignore_file_contains_starter_comment(tmp_path, monkeypatch):
158
+ monkeypatch.chdir(tmp_path)
159
+ with pytest.raises(SystemExit):
160
+ main(["--ignore-file"])
161
+ content = (tmp_path / ".secretshieldignore").read_text()
162
+ assert content == DEFAULT_IGNORE_CONTENT
163
+ assert content.strip().startswith("#")
164
+
165
+
166
+ def test_ignore_file_does_not_overwrite_existing(tmp_path, monkeypatch, capsys):
167
+ monkeypatch.chdir(tmp_path)
168
+ (tmp_path / ".secretshieldignore").write_text("my custom rules\n")
169
+ with pytest.raises(SystemExit):
170
+ main(["--ignore-file"])
171
+ assert (tmp_path / ".secretshieldignore").read_text() == "my custom rules\n"
172
+ out = capsys.readouterr().out
173
+ assert "already exists" in out
174
+
175
+
176
+ def test_ignore_file_exits_successfully(tmp_path, monkeypatch):
177
+ monkeypatch.chdir(tmp_path)
178
+ with pytest.raises(SystemExit) as exc_info:
179
+ main(["--ignore-file"])
180
+ assert exc_info.value.code in (0, None)
181
+
182
+
183
+ def test_ignore_file_works_through_normal_cli(tmp_path, monkeypatch):
184
+ monkeypatch.chdir(tmp_path)
185
+ with pytest.raises(SystemExit):
186
+ main(["--ignore-file"])
187
+ assert (tmp_path / ".secretshieldignore").exists()
188
+
189
+
190
+ def test_create_default_ignore_file_helper_directly(tmp_path):
191
+ created, path = create_default_ignore_file(tmp_path)
192
+ assert created is True
193
+ assert path.exists()
194
+ created2, path2 = create_default_ignore_file(tmp_path)
195
+ assert created2 is False
196
+ assert path2 == path
197
+
198
+
199
+ # --- init creates .secretshieldignore ---------------------------------------
200
+
201
+
202
+ def test_init_creates_secretshieldignore(tmp_path, monkeypatch):
203
+ monkeypatch.chdir(tmp_path)
204
+ monkeypatch.setattr("sys.stdin.isatty", lambda: True)
205
+ # Not a git repo, so the hook question is skipped entirely (no
206
+ # prompt consumed for it) -- only config, actions, and apply remain.
207
+ answers = iter(["y", "n", "y"])
208
+ monkeypatch.setattr("builtins.input", lambda prompt="": next(answers))
209
+
210
+ main(["init"])
211
+ assert (tmp_path / ".secretshieldignore").exists()
212
+
213
+
214
+ def test_init_preserves_existing_secretshieldignore(tmp_path, monkeypatch):
215
+ monkeypatch.chdir(tmp_path)
216
+ (tmp_path / ".secretshieldignore").write_text("existing content\n")
217
+ monkeypatch.setattr("sys.stdin.isatty", lambda: True)
218
+ answers = iter(["n", "n", "y"])
219
+ monkeypatch.setattr("builtins.input", lambda prompt="": next(answers))
220
+
221
+ main(["init"])
222
+ assert (tmp_path / ".secretshieldignore").read_text() == "existing content\n"
223
+
224
+
225
+ def test_init_twice_does_not_duplicate_or_overwrite(tmp_path, monkeypatch):
226
+ monkeypatch.chdir(tmp_path)
227
+ monkeypatch.setattr("sys.stdin.isatty", lambda: True)
228
+
229
+ answers1 = iter(["n", "n", "y"])
230
+ monkeypatch.setattr("builtins.input", lambda prompt="": next(answers1))
231
+ main(["init"])
232
+ first_content = (tmp_path / ".secretshieldignore").read_text()
233
+
234
+ answers2 = iter(["n", "n", "y"])
235
+ monkeypatch.setattr("builtins.input", lambda prompt="": next(answers2))
236
+ main(["init"])
237
+ second_content = (tmp_path / ".secretshieldignore").read_text()
238
+
239
+ assert first_content == second_content == DEFAULT_IGNORE_CONTENT
240
+
241
+
242
+ def test_init_still_creates_everything_else(tmp_path, monkeypatch):
243
+ monkeypatch.chdir(tmp_path)
244
+ _init_repo(tmp_path)
245
+ monkeypatch.setattr("sys.stdin.isatty", lambda: True)
246
+ answers = iter(["y", "y", "y", "y"])
247
+ monkeypatch.setattr("builtins.input", lambda prompt="": next(answers))
248
+
249
+ main(["init"])
250
+ assert (tmp_path / "secretshield.toml").exists()
251
+ assert (tmp_path / ".git" / "hooks" / "pre-commit").exists()
252
+ assert (tmp_path / ".github" / "workflows" / "secretshield.yml").exists()
253
+ assert (tmp_path / ".secretshieldignore").exists()
254
+
255
+
256
+ def test_init_non_interactive_still_refuses_cleanly(tmp_path, monkeypatch):
257
+ monkeypatch.chdir(tmp_path)
258
+ exit_code = main(["init"])
259
+ assert exit_code == 1
260
+ assert not (tmp_path / ".secretshieldignore").exists()
261
+
262
+
263
+ # --- ss alias covers all new flags too --------------------------------------
264
+
265
+
266
+ def test_ss_entry_point_supports_new_flags():
267
+ import tomllib
268
+
269
+ with open("pyproject.toml", "rb") as f:
270
+ data = tomllib.load(f)
271
+ scripts = data["project"]["scripts"]
272
+ # Both commands point at the same entry point, so any flag added to
273
+ # the shared parser automatically works for both -- confirm the
274
+ # wiring is still single-entry-point, not duplicated.
275
+ assert scripts["secretshield"] == scripts["ss"] == "secretshield.cli:main"
File without changes
File without changes
File without changes