claude-dev-env 7.5.0 → 7.6.0
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.
- package/.agents/skills/everything-search/scripts/everything_search.py +11 -0
- package/.agents/skills/everything-search/scripts/test_everything_search.py +1 -0
- package/.agents/skills/fresh-branch/SKILL.md +1 -0
- package/.agents/skills/fresh-branch/scripts/fresh_branch_git_commands.py +3 -0
- package/.agents/skills/fresh-branch/scripts/subprocess_window_access.py +43 -0
- package/.agents/skills/syncing-submodules/SKILL.md +1 -0
- package/.agents/skills/syncing-submodules/scripts/submodule_sync.py +4 -0
- package/.agents/skills/syncing-submodules/scripts/subprocess_window_access.py +43 -0
- package/.agents/skills/test-runner/SKILL.md +1 -0
- package/.agents/skills/test-runner/scripts/preflight_checks.py +5 -0
- package/.agents/skills/test-runner/scripts/run_tests.py +11 -0
- package/.agents/skills/test-runner/scripts/subprocess_window_access.py +43 -0
- package/.agents/skills/test-runner/scripts/test_run_tests.py +9 -7
- package/_shared/pr-loop/scripts/check_bugbot_ci.py +3 -0
- package/_shared/pr-loop/scripts/check_convergence_gates.py +3 -0
- package/_shared/pr-loop/scripts/check_pending_reviews.py +3 -0
- package/_shared/pr-loop/scripts/code_rules_gate_parts/added_line_maps.py +3 -0
- package/_shared/pr-loop/scripts/code_rules_gate_parts/baseline_import_isolation.py +3 -0
- package/_shared/pr-loop/scripts/code_rules_gate_parts/git_blob_readers.py +5 -0
- package/_shared/pr-loop/scripts/code_rules_gate_parts/git_file_sets.py +4 -0
- package/_shared/pr-loop/scripts/code_rules_gate_parts/staged_test_regression.py +3 -0
- package/_shared/pr-loop/scripts/code_rules_gate_parts/staged_test_running.py +3 -0
- package/_shared/pr-loop/scripts/codex_usage_probe.py +3 -0
- package/_shared/pr-loop/scripts/copilot_quota.py +3 -0
- package/_shared/pr-loop/scripts/fetch_copilot_reviews.py +3 -0
- package/_shared/pr-loop/scripts/fix_hookspath.py +7 -0
- package/_shared/pr-loop/scripts/post_fix_reply.py +4 -0
- package/_shared/pr-loop/scripts/preflight.py +7 -0
- package/_shared/pr-loop/scripts/preflight_self_heal.py +5 -0
- package/_shared/pr-loop/scripts/run_codex_review.py +3 -0
- package/_shared/pr-loop/scripts/subprocess_window_access.py +41 -0
- package/_shared/pr-loop/scripts/terminology_sweep.py +5 -0
- package/_shared/process-tree/scripts/process_tree_kill.py +3 -0
- package/_shared/process-tree/scripts/subprocess_window_access.py +41 -0
- package/bin/install-constants.mjs +4 -2
- package/bin/install.cursor-rules.test.mjs +57 -15
- package/bin/install.mjs +10 -15
- package/bin/pstack-model-preferences.claude.json +23 -0
- package/hooks/advisory/pr_done_reminder.py +7 -0
- package/hooks/advisory/refactor_guard.py +8 -0
- package/hooks/advisory/test_pr_done_reminder.py +21 -0
- package/hooks/advisory/test_refactor_guard.py +40 -0
- package/hooks/blocking/block_main_commit.py +4 -0
- package/hooks/blocking/code_rules_comments.py +39 -5
- package/hooks/blocking/pii_prevention_blocker_parts/repository_exemption.py +3 -0
- package/hooks/blocking/precommit_code_rules_gate.py +3 -0
- package/hooks/blocking/tdd_enforcer_parts/content_analysis.py +19 -3
- package/hooks/blocking/tdd_enforcer_parts/git_tracking.py +4 -0
- package/hooks/blocking/tdd_enforcer_parts/tests/test_content_analysis.py +25 -0
- package/hooks/blocking/test_code_rules_enforcer_comment_string_awareness.py +27 -0
- package/hooks/blocking/test_code_rules_enforcer_exempt_marker_chained.py +10 -0
- package/hooks/git-hooks/git_hooks_constants/verification_notice_constants.py +0 -2
- package/hooks/git-hooks/pull_request_handoff.py +3 -0
- package/hooks/git-hooks/subprocess_window_access.py +41 -0
- package/hooks/git-hooks/test_verification_start.py +4 -0
- package/hooks/git-hooks/verification_notice_context.py +3 -0
- package/hooks/git-hooks/verification_start.py +7 -8
- package/hooks/hooks_constants/code_rules_enforcer_constants.py +2 -0
- package/hooks/hooks_constants/subprocess_window.py +141 -0
- package/hooks/hooks_constants/subprocess_window_constants.py +9 -0
- package/hooks/hooks_constants/test_code_rules_enforcer_constants.py +6 -0
- package/hooks/hooks_constants/test_subprocess_window.py +128 -0
- package/hooks/lifecycle/enter_worktree_origin_prefetch.py +3 -0
- package/hooks/validation/mypy_validator.py +4 -0
- package/hooks/validators/README.md +1 -0
- package/hooks/validators/git_checks.py +4 -0
- package/hooks/validators/health_check.py +3 -0
- package/hooks/validators/hook_timing_harness.py +3 -0
- package/hooks/validators/mypy_integration.py +4 -0
- package/hooks/validators/ruff_integration.py +6 -0
- package/hooks/validators/run_all_validators.py +7 -0
- package/hooks/validators/subprocess_window_access.py +41 -0
- package/hooks/workflow/auto_formatter.py +8 -0
- package/hooks/workflow/test_auto_formatter.py +39 -0
- package/package.json +1 -1
- package/rules/pstack-models.md +4 -3
- package/scripts/automatic_advisory/checkout.py +8 -1
- package/scripts/automatic_advisory/cli.py +9 -3
- package/scripts/automatic_advisory/config/constants.py +0 -2
- package/scripts/automatic_advisory/execution.py +7 -1
- package/scripts/automatic_advisory/git.py +9 -1
- package/scripts/automatic_advisory/process_host.py +3 -0
- package/scripts/claude_chain_runner.py +3 -0
- package/scripts/gh_artifact_upload.py +3 -0
- package/scripts/grok_headless_runner.py +3 -0
- package/scripts/grok_patch_artifacts.py +4 -0
- package/scripts/grok_worker_preflight.py +3 -0
- package/scripts/invoke_code_review.py +3 -0
- package/scripts/local_verification/command_runner.py +3 -0
- package/scripts/local_verification/git_state.py +3 -0
- package/scripts/policy_lint/adapter_detectors.py +48 -2
- package/scripts/policy_lint/adapter_pairing.py +150 -2
- package/scripts/policy_lint/adapters.py +46 -4
- package/scripts/policy_lint/config/approved_test_pairs.py +25 -9
- package/scripts/policy_lint/config/constants.py +3 -0
- package/scripts/policy_lint/registry.py +1 -1
- package/scripts/policy_lint/selection_git.py +11 -0
- package/scripts/repository_checks/config/constants.py +5 -0
- package/scripts/repository_checks/config/policy_document.py +19 -0
- package/scripts/repository_checks/email_exemptions.py +14 -71
- package/scripts/repository_checks/path_exemptions.py +35 -0
- package/scripts/repository_checks/policy_document.py +120 -0
- package/scripts/repository_checks/tracked_secrets.py +27 -4
- package/scripts/setup_project_paths.py +3 -0
- package/scripts/spawn_grok_batch.py +3 -0
- package/scripts/subprocess_window_access.py +41 -0
- package/scripts/test_dispatcher_profile_import.py +4 -0
- package/scripts/tests/test_automatic_advisory_window_flags.py +17 -11
- package/scripts/tests/test_email_exemptions.py +37 -0
- package/scripts/tests/test_path_exemptions.py +164 -0
- package/scripts/tests/test_policy_document.py +104 -0
- package/scripts/tests/test_policy_lint_rules_function_length_scope.py +101 -0
- package/scripts/tests/test_policy_lint_rules_pairing.py +375 -0
- package/scripts/tests/test_policy_lint_rules_registry.py +116 -0
- package/scripts/tests/test_policy_lint_selection.py +34 -0
- package/scripts/tests/test_subprocess_window_access.py +118 -0
- package/scripts/tests/test_tracked_secrets.py +79 -0
- package/scripts/validate_instruction_pairs.py +3 -0
- package/scripts/verify_installable_package.py +5 -0
- package/scripts/automatic_advisory/window_flags.py +0 -41
- package/scripts/repository_checks/config/email_exemptions.py +0 -10
|
@@ -2,21 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
import json
|
|
6
5
|
from pathlib import Path
|
|
7
6
|
|
|
8
|
-
from repository_checks.config.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
from repository_checks.config.policy_document import (
|
|
8
|
+
EMAIL_CATEGORY,
|
|
9
|
+
EMAIL_EXEMPTION_SUBJECT,
|
|
10
|
+
EMAIL_EXEMPTIONS_FIELD,
|
|
11
|
+
)
|
|
12
|
+
from repository_checks.policy_document import (
|
|
13
|
+
PolicyConfigurationRunFatal,
|
|
14
|
+
entry_path_and_digest,
|
|
15
|
+
read_policy_entries,
|
|
15
16
|
)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class PolicyConfigurationRunFatal(ValueError):
|
|
19
|
-
"""Reject the entire policy run when exception configuration is invalid."""
|
|
20
17
|
|
|
21
18
|
|
|
22
19
|
def load_email_exemptions(repository_root: Path) -> frozenset[tuple[str, str, str]]:
|
|
@@ -31,66 +28,12 @@ def load_email_exemptions(repository_root: Path) -> frozenset[tuple[str, str, st
|
|
|
31
28
|
OSError: Configuration cannot be read.
|
|
32
29
|
"""
|
|
33
30
|
exemptions: set[tuple[str, str, str]] = set()
|
|
34
|
-
for each_entry in
|
|
35
|
-
|
|
31
|
+
for each_entry in read_policy_entries(repository_root, EMAIL_EXEMPTIONS_FIELD):
|
|
32
|
+
relative_path, digest = entry_path_and_digest(
|
|
33
|
+
each_entry, EMAIL_EXEMPTION_SUBJECT
|
|
34
|
+
)
|
|
35
|
+
identity = (relative_path, EMAIL_CATEGORY, digest)
|
|
36
36
|
if identity in exemptions:
|
|
37
37
|
raise PolicyConfigurationRunFatal("Duplicate repository email exemption")
|
|
38
38
|
exemptions.add(identity)
|
|
39
39
|
return frozenset(exemptions)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def _read_entries(repository_root: Path) -> list[object]:
|
|
43
|
-
config_path = repository_root / CONFIG_RELATIVE_PATH
|
|
44
|
-
if not config_path.exists() and not config_path.is_symlink():
|
|
45
|
-
return []
|
|
46
|
-
if not config_path.resolve().is_relative_to(repository_root.resolve()):
|
|
47
|
-
raise ValueError(
|
|
48
|
-
"Repository policy configuration must remain inside the repository"
|
|
49
|
-
)
|
|
50
|
-
document = json.loads(
|
|
51
|
-
config_path.read_text(encoding="utf-8"), object_pairs_hook=_unique_fields
|
|
52
|
-
)
|
|
53
|
-
if (
|
|
54
|
-
not isinstance(document, dict)
|
|
55
|
-
or set(document) != {"version", "email_exemptions"}
|
|
56
|
-
or type(document["version"]) is not int
|
|
57
|
-
or document["version"] != 1
|
|
58
|
-
or not isinstance(document["email_exemptions"], list)
|
|
59
|
-
):
|
|
60
|
-
raise ValueError("Invalid repository policy configuration schema")
|
|
61
|
-
return document["email_exemptions"]
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
def _unique_fields(all_pairs: list[tuple[str, object]]) -> dict[str, object]:
|
|
65
|
-
fields: dict[str, object] = {}
|
|
66
|
-
for each_key, each_content in all_pairs:
|
|
67
|
-
if each_key in fields:
|
|
68
|
-
raise PolicyConfigurationRunFatal("Duplicate repository policy field")
|
|
69
|
-
fields[each_key] = each_content
|
|
70
|
-
return fields
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
def _entry_identity(entry: object) -> tuple[str, str, str]:
|
|
74
|
-
if not isinstance(entry, dict) or set(entry) != ALL_ENTRY_FIELDS:
|
|
75
|
-
raise ValueError("Email exemptions require path, sha256, and reason")
|
|
76
|
-
relative_path, digest, reason = entry["path"], entry["sha256"], entry["reason"]
|
|
77
|
-
if not isinstance(relative_path, str) or not relative_path:
|
|
78
|
-
raise ValueError("Email exemption path must name one repository file")
|
|
79
|
-
if (
|
|
80
|
-
any(character in FORBIDDEN_PATH_CHARACTERS for character in relative_path)
|
|
81
|
-
or any(
|
|
82
|
-
segment in ALL_FORBIDDEN_PATH_SEGMENTS
|
|
83
|
-
for segment in relative_path.split("/")
|
|
84
|
-
)
|
|
85
|
-
or any(
|
|
86
|
-
ord(character) < FIRST_PRINTABLE_CODEPOINT for character in relative_path
|
|
87
|
-
)
|
|
88
|
-
):
|
|
89
|
-
raise ValueError("Email exemption path must be a literal relative file path")
|
|
90
|
-
if not isinstance(digest, str) or DIGEST_PATTERN.fullmatch(digest) is None:
|
|
91
|
-
raise ValueError("Email exemption sha256 must contain 64 lowercase hex digits")
|
|
92
|
-
if not isinstance(reason, str) or not reason.strip():
|
|
93
|
-
raise ValueError(
|
|
94
|
-
"Email exemption reason must explain its public contact purpose"
|
|
95
|
-
)
|
|
96
|
-
return relative_path, "email", digest
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Load frozen-file path exceptions owned by a repository."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from repository_checks.config.policy_document import (
|
|
8
|
+
PATH_EXEMPTION_SUBJECT,
|
|
9
|
+
PATH_EXEMPTIONS_FIELD,
|
|
10
|
+
)
|
|
11
|
+
from repository_checks.policy_document import (
|
|
12
|
+
PolicyConfigurationRunFatal,
|
|
13
|
+
entry_path_and_digest,
|
|
14
|
+
read_policy_entries,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def load_path_exemptions(repository_root: Path) -> frozenset[tuple[str, str]]:
|
|
19
|
+
"""Read validated frozen-file path exceptions.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
repository_root: Repository containing the optional policy configuration.
|
|
23
|
+
Returns:
|
|
24
|
+
Exact path and recorded file-content digest identities.
|
|
25
|
+
Raises:
|
|
26
|
+
ValueError: Configuration contains invalid JSON or schema fields.
|
|
27
|
+
OSError: Configuration cannot be read.
|
|
28
|
+
"""
|
|
29
|
+
exemptions: set[tuple[str, str]] = set()
|
|
30
|
+
for each_entry in read_policy_entries(repository_root, PATH_EXEMPTIONS_FIELD):
|
|
31
|
+
identity = entry_path_and_digest(each_entry, PATH_EXEMPTION_SUBJECT)
|
|
32
|
+
if identity in exemptions:
|
|
33
|
+
raise PolicyConfigurationRunFatal("Duplicate repository path exemption")
|
|
34
|
+
exemptions.add(identity)
|
|
35
|
+
return frozenset(exemptions)
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""Read and validate the repository policy document."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from repository_checks.config.policy_document import (
|
|
9
|
+
ALL_DOCUMENT_FIELDS,
|
|
10
|
+
ALL_ENTRY_FIELDS,
|
|
11
|
+
ALL_EXEMPTION_FIELDS,
|
|
12
|
+
ALL_FORBIDDEN_PATH_SEGMENTS,
|
|
13
|
+
CONFIG_RELATIVE_PATH,
|
|
14
|
+
DIGEST_PATTERN,
|
|
15
|
+
FIRST_PRINTABLE_CODEPOINT,
|
|
16
|
+
FORBIDDEN_PATH_CHARACTERS,
|
|
17
|
+
SUPPORTED_DOCUMENT_VERSION,
|
|
18
|
+
VERSION_FIELD,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class PolicyConfigurationRunFatal(ValueError):
|
|
23
|
+
"""Reject the entire policy run when exception configuration is invalid."""
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def read_policy_entries(repository_root: Path, field_name: str) -> list[object]:
|
|
27
|
+
"""Read one exception list from the validated policy document.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
repository_root: Repository containing the optional policy configuration.
|
|
31
|
+
field_name: Top-level document field holding the exception list.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
Raw entries recorded under the requested field.
|
|
35
|
+
|
|
36
|
+
Raises:
|
|
37
|
+
ValueError: Configuration contains invalid JSON or schema fields.
|
|
38
|
+
OSError: Configuration cannot be read.
|
|
39
|
+
"""
|
|
40
|
+
config_path = repository_root / CONFIG_RELATIVE_PATH
|
|
41
|
+
if not config_path.exists() and not config_path.is_symlink():
|
|
42
|
+
return []
|
|
43
|
+
if not config_path.resolve().is_relative_to(repository_root.resolve()):
|
|
44
|
+
raise ValueError(
|
|
45
|
+
"Repository policy configuration must remain inside the repository"
|
|
46
|
+
)
|
|
47
|
+
document = json.loads(
|
|
48
|
+
config_path.read_text(encoding="utf-8"), object_pairs_hook=_unique_fields
|
|
49
|
+
)
|
|
50
|
+
_require_valid_document(document)
|
|
51
|
+
return document.get(field_name, [])
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def entry_path_and_digest(entry: object, subject: str) -> tuple[str, str]:
|
|
55
|
+
"""Return the validated path and digest of one exception entry.
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
entry: Raw entry read from the policy document.
|
|
59
|
+
subject: Exception family named in each rejection message.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
Repository-relative path and its recorded sha256 digest.
|
|
63
|
+
|
|
64
|
+
Raises:
|
|
65
|
+
ValueError: The entry omits a field or carries an invalid value.
|
|
66
|
+
"""
|
|
67
|
+
if not isinstance(entry, dict) or set(entry) != ALL_ENTRY_FIELDS:
|
|
68
|
+
raise ValueError(f"{subject}s require path, sha256, and reason")
|
|
69
|
+
relative_path, digest, reason = entry["path"], entry["sha256"], entry["reason"]
|
|
70
|
+
if not isinstance(relative_path, str) or not relative_path:
|
|
71
|
+
raise ValueError(f"{subject} path must name one repository file")
|
|
72
|
+
if _is_nonliteral_relative_path(relative_path):
|
|
73
|
+
raise ValueError(f"{subject} path must be a literal relative file path")
|
|
74
|
+
if not isinstance(digest, str) or DIGEST_PATTERN.fullmatch(digest) is None:
|
|
75
|
+
raise ValueError(f"{subject} sha256 must contain 64 lowercase hex digits")
|
|
76
|
+
if not isinstance(reason, str) or not reason.strip():
|
|
77
|
+
raise ValueError(f"{subject} reason must explain why the exception is owned")
|
|
78
|
+
return relative_path, digest
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _require_valid_document(document: object) -> None:
|
|
82
|
+
if (
|
|
83
|
+
not isinstance(document, dict)
|
|
84
|
+
or not set(document) <= ALL_DOCUMENT_FIELDS
|
|
85
|
+
or VERSION_FIELD not in document
|
|
86
|
+
or type(document[VERSION_FIELD]) is not int
|
|
87
|
+
or document[VERSION_FIELD] != SUPPORTED_DOCUMENT_VERSION
|
|
88
|
+
or not _has_only_list_exemption_fields(document)
|
|
89
|
+
):
|
|
90
|
+
raise ValueError("Invalid repository policy configuration schema")
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _has_only_list_exemption_fields(all_document_fields: dict[str, object]) -> bool:
|
|
94
|
+
return all(
|
|
95
|
+
isinstance(all_document_fields[each_field], list)
|
|
96
|
+
for each_field in ALL_EXEMPTION_FIELDS
|
|
97
|
+
if each_field in all_document_fields
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _is_nonliteral_relative_path(relative_path: str) -> bool:
|
|
102
|
+
return (
|
|
103
|
+
any(character in FORBIDDEN_PATH_CHARACTERS for character in relative_path)
|
|
104
|
+
or any(
|
|
105
|
+
segment in ALL_FORBIDDEN_PATH_SEGMENTS
|
|
106
|
+
for segment in relative_path.split("/")
|
|
107
|
+
)
|
|
108
|
+
or any(
|
|
109
|
+
ord(character) < FIRST_PRINTABLE_CODEPOINT for character in relative_path
|
|
110
|
+
)
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _unique_fields(all_pairs: list[tuple[str, object]]) -> dict[str, object]:
|
|
115
|
+
fields: dict[str, object] = {}
|
|
116
|
+
for each_key, each_content in all_pairs:
|
|
117
|
+
if each_key in fields:
|
|
118
|
+
raise PolicyConfigurationRunFatal("Duplicate repository policy field")
|
|
119
|
+
fields[each_key] = each_content
|
|
120
|
+
return fields
|
|
@@ -13,6 +13,7 @@ from repository_checks.config import constants as repository_constants
|
|
|
13
13
|
from repository_checks.email_exemptions import load_email_exemptions
|
|
14
14
|
from repository_checks.hook_modules import load_hooks_module
|
|
15
15
|
from repository_checks.models import RepositoryFinding
|
|
16
|
+
from repository_checks.path_exemptions import load_path_exemptions
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
def collect_tracked_secret_findings(
|
|
@@ -32,6 +33,7 @@ def collect_tracked_secret_findings(
|
|
|
32
33
|
all_allowlisted_literals = exemption.repository_allowlisted_values(repository_root)
|
|
33
34
|
all_exact_exemptions = load_email_exemptions(repository_root)
|
|
34
35
|
all_exact_exemptions |= repository_constants.ALL_TRACKED_SECRET_EXACT_EXEMPTIONS
|
|
36
|
+
all_path_exemptions = load_path_exemptions(repository_root)
|
|
35
37
|
all_findings: list[RepositoryFinding] = []
|
|
36
38
|
for each_relative_path in all_tracked_paths:
|
|
37
39
|
all_findings.extend(
|
|
@@ -41,6 +43,7 @@ def collect_tracked_secret_findings(
|
|
|
41
43
|
scanner,
|
|
42
44
|
all_allowlisted_literals,
|
|
43
45
|
all_exact_exemptions,
|
|
46
|
+
all_path_exemptions,
|
|
44
47
|
)
|
|
45
48
|
)
|
|
46
49
|
return all_findings
|
|
@@ -52,6 +55,7 @@ def _find_secrets_for_path(
|
|
|
52
55
|
scanner: ModuleType,
|
|
53
56
|
all_allowlisted_literals: frozenset[str],
|
|
54
57
|
all_exact_exemptions: frozenset[tuple[str, str, str]],
|
|
58
|
+
all_path_exemptions: frozenset[tuple[str, str]],
|
|
55
59
|
) -> list[RepositoryFinding]:
|
|
56
60
|
posix_relative_path = relative_path.replace(
|
|
57
61
|
repository_constants.WINDOWS_PATH_SEPARATOR,
|
|
@@ -59,12 +63,12 @@ def _find_secrets_for_path(
|
|
|
59
63
|
)
|
|
60
64
|
if scanner.is_path_exempt_from_pii_scan(posix_relative_path):
|
|
61
65
|
return []
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
repository_root / relative_path,
|
|
65
|
-
)
|
|
66
|
+
absolute_path = repository_root / relative_path
|
|
67
|
+
maybe_content = _read_utf8_text(repository_root, absolute_path)
|
|
66
68
|
if maybe_content is None:
|
|
67
69
|
return []
|
|
70
|
+
if _is_frozen_file_exempt(absolute_path, posix_relative_path, all_path_exemptions):
|
|
71
|
+
return []
|
|
68
72
|
return _find_secret_matches(
|
|
69
73
|
posix_relative_path,
|
|
70
74
|
maybe_content,
|
|
@@ -147,6 +151,25 @@ def _should_report_match(
|
|
|
147
151
|
return matched_text not in all_allowlisted_literals
|
|
148
152
|
|
|
149
153
|
|
|
154
|
+
def _is_frozen_file_exempt(
|
|
155
|
+
absolute_path: Path,
|
|
156
|
+
posix_relative_path: str,
|
|
157
|
+
all_path_exemptions: frozenset[tuple[str, str]],
|
|
158
|
+
) -> bool:
|
|
159
|
+
all_recorded_digests = {
|
|
160
|
+
each_digest
|
|
161
|
+
for each_exempt_path, each_digest in all_path_exemptions
|
|
162
|
+
if each_exempt_path == posix_relative_path
|
|
163
|
+
}
|
|
164
|
+
if not all_recorded_digests:
|
|
165
|
+
return False
|
|
166
|
+
return _file_digest(absolute_path) in all_recorded_digests
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def _file_digest(absolute_path: Path) -> str:
|
|
170
|
+
return hashlib.sha256(absolute_path.read_bytes()).hexdigest()
|
|
171
|
+
|
|
172
|
+
|
|
150
173
|
def _secret_digest(matched_text: str) -> str:
|
|
151
174
|
return hashlib.sha256(
|
|
152
175
|
matched_text.encode(policy_constants.UTF8_ENCODING)
|
|
@@ -38,6 +38,8 @@ from hooks_constants.setup_project_paths_constants import ( # noqa: E402
|
|
|
38
38
|
WROTE_ENTRIES_STATUS_TEMPLATE,
|
|
39
39
|
)
|
|
40
40
|
|
|
41
|
+
from subprocess_window_access import hidden_window_creation_flags
|
|
42
|
+
|
|
41
43
|
|
|
42
44
|
class SchemaMismatchError(Exception):
|
|
43
45
|
"""Raised when the on-disk config declares a schema newer than this script supports."""
|
|
@@ -238,6 +240,7 @@ def _run_es_exe_folders_query() -> list[str]:
|
|
|
238
240
|
text=True,
|
|
239
241
|
encoding=UTF8_ENCODING,
|
|
240
242
|
check=False,
|
|
243
|
+
creationflags=hidden_window_creation_flags(),
|
|
241
244
|
)
|
|
242
245
|
if completion.returncode != 0:
|
|
243
246
|
truncated_stderr = completion.stderr[:STDERR_TRUNCATION_LENGTH].strip()
|
|
@@ -117,6 +117,8 @@ from dev_env_scripts_constants.timing import WORKER_STAGGER_SECONDS
|
|
|
117
117
|
from grok_headless_runner import GrokRunnerOutcome, run_headless_worker
|
|
118
118
|
from grok_worker_preflight import PreflightOutcome, run_preflight
|
|
119
119
|
|
|
120
|
+
from subprocess_window_access import hidden_window_creation_flags
|
|
121
|
+
|
|
120
122
|
class AdvisorFailureError(ValueError):
|
|
121
123
|
"""Raised when an advisor bind, resume, or launcher call fails closed."""
|
|
122
124
|
|
|
@@ -263,6 +265,7 @@ def invoke_advisor_launcher(
|
|
|
263
265
|
encoding=UTF8_ENCODING,
|
|
264
266
|
check=False,
|
|
265
267
|
timeout=MAXIMUM_ADVISOR_TIMEOUT_SECONDS,
|
|
268
|
+
creationflags=hidden_window_creation_flags(),
|
|
266
269
|
)
|
|
267
270
|
except FileNotFoundError as missing_launcher:
|
|
268
271
|
raise AdvisorFailureError(
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Reach the hidden-window helpers from the scripts this directory deploys.
|
|
2
|
+
|
|
3
|
+
The installer copies this directory into a profile that holds no installed
|
|
4
|
+
Python distribution, and this repository's own tests run the deployed scripts
|
|
5
|
+
under ``python -S -E``, which hides every installed package from the child
|
|
6
|
+
process. On both routes ``hooks_constants`` is reachable only through the
|
|
7
|
+
deployed ``hooks`` directory, so this module puts that directory on
|
|
8
|
+
``sys.path`` and re-exports the helpers a caller asks for::
|
|
9
|
+
|
|
10
|
+
from subprocess_window_access import hidden_window_creation_flags
|
|
11
|
+
|
|
12
|
+
The directory goes on the end of ``sys.path``. ``PathFinder`` runs ahead of
|
|
13
|
+
every editable-install finder, so a trailing entry still selects the deployed
|
|
14
|
+
copy, and the head of ``sys.path`` stays exactly as the caller left it. A
|
|
15
|
+
caller that prepended its own roots keeps them first.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import sys
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
|
|
23
|
+
_subprocess_window_hooks_directory = str(
|
|
24
|
+
Path(__file__).resolve().parents[1] / "hooks"
|
|
25
|
+
)
|
|
26
|
+
if _subprocess_window_hooks_directory not in sys.path:
|
|
27
|
+
sys.path.append(_subprocess_window_hooks_directory)
|
|
28
|
+
|
|
29
|
+
from hooks_constants.subprocess_window import (
|
|
30
|
+
HiddenWindowStartupInfo,
|
|
31
|
+
detached_hidden_window_creation_flags,
|
|
32
|
+
hidden_window_creation_flags,
|
|
33
|
+
inherited_stream_startup_info,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
__all__ = [
|
|
37
|
+
"HiddenWindowStartupInfo",
|
|
38
|
+
"detached_hidden_window_creation_flags",
|
|
39
|
+
"hidden_window_creation_flags",
|
|
40
|
+
"inherited_stream_startup_info",
|
|
41
|
+
]
|
|
@@ -28,6 +28,10 @@ def _stage_profile_tree(
|
|
|
28
28
|
target_profile_directory / "_shared" / each_shared_name
|
|
29
29
|
)
|
|
30
30
|
shutil.copytree(source_shared_directory, target_shared_directory)
|
|
31
|
+
shutil.copytree(
|
|
32
|
+
source_package_directory / "hooks" / "hooks_constants",
|
|
33
|
+
target_profile_directory / "hooks" / "hooks_constants",
|
|
34
|
+
)
|
|
31
35
|
return target_scripts_directory
|
|
32
36
|
|
|
33
37
|
|
|
@@ -15,7 +15,13 @@ if str(TESTS_DIRECTORY) not in sys.path:
|
|
|
15
15
|
sys.path.insert(0, str(TESTS_DIRECTORY))
|
|
16
16
|
|
|
17
17
|
import test_automatic_advisory as support
|
|
18
|
-
from automatic_advisory import checkout, cli, execution, git
|
|
18
|
+
from automatic_advisory import checkout, cli, execution, git
|
|
19
|
+
|
|
20
|
+
_subprocess_window_hooks_directory = str(Path(__file__).resolve().parents[3] / "hooks")
|
|
21
|
+
if _subprocess_window_hooks_directory not in sys.path:
|
|
22
|
+
sys.path.append(_subprocess_window_hooks_directory)
|
|
23
|
+
|
|
24
|
+
from hooks_constants import subprocess_window
|
|
19
25
|
|
|
20
26
|
WINDOWS_ONLY = pytest.mark.skipif(
|
|
21
27
|
sys.platform != "win32", reason="Windows console flags"
|
|
@@ -41,19 +47,19 @@ Path(sys.argv[1]).write_text(completed.stdout, encoding="utf-8")
|
|
|
41
47
|
|
|
42
48
|
|
|
43
49
|
def test_flags_are_zero_off_windows(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
44
|
-
monkeypatch.setattr(
|
|
45
|
-
assert
|
|
46
|
-
assert
|
|
50
|
+
monkeypatch.setattr(subprocess_window.sys, "platform", "linux")
|
|
51
|
+
assert subprocess_window.hidden_window_creation_flags() == 0
|
|
52
|
+
assert subprocess_window.detached_hidden_window_creation_flags() == 0
|
|
47
53
|
|
|
48
54
|
|
|
49
55
|
@WINDOWS_ONLY
|
|
50
56
|
def test_hidden_window_creation_flags_is_create_no_window() -> None:
|
|
51
|
-
assert
|
|
57
|
+
assert subprocess_window.hidden_window_creation_flags() == subprocess.CREATE_NO_WINDOW
|
|
52
58
|
|
|
53
59
|
|
|
54
60
|
@WINDOWS_ONLY
|
|
55
61
|
def test_poller_flags_keep_a_hidden_console_instead_of_none() -> None:
|
|
56
|
-
poller_flags =
|
|
62
|
+
poller_flags = subprocess_window.detached_hidden_window_creation_flags()
|
|
57
63
|
assert poller_flags & subprocess.DETACHED_PROCESS == 0
|
|
58
64
|
assert poller_flags & subprocess.CREATE_NO_WINDOW
|
|
59
65
|
assert poller_flags & subprocess.CREATE_NEW_PROCESS_GROUP
|
|
@@ -71,7 +77,7 @@ def test_poller_grandchild_gets_no_visible_console(tmp_path: Path) -> None:
|
|
|
71
77
|
stdin=subprocess.DEVNULL,
|
|
72
78
|
stdout=subprocess.DEVNULL,
|
|
73
79
|
stderr=subprocess.DEVNULL,
|
|
74
|
-
creationflags=
|
|
80
|
+
creationflags=subprocess_window.detached_hidden_window_creation_flags(),
|
|
75
81
|
)
|
|
76
82
|
assert _read_probe_report(report_path) == {"visible": False}
|
|
77
83
|
|
|
@@ -102,7 +108,7 @@ def test_git_fetch_hides_its_window(
|
|
|
102
108
|
|
|
103
109
|
assert git._fetch_base(registration, candidate) is True
|
|
104
110
|
assert (
|
|
105
|
-
captured_options["creationflags"] ==
|
|
111
|
+
captured_options["creationflags"] == subprocess_window.hidden_window_creation_flags()
|
|
106
112
|
)
|
|
107
113
|
|
|
108
114
|
|
|
@@ -122,7 +128,7 @@ def test_checkout_inspection_hides_its_window(
|
|
|
122
128
|
local_checkout = checkout.read_local_checkout(tmp_path)
|
|
123
129
|
|
|
124
130
|
assert local_checkout.head_sha == "abc123"
|
|
125
|
-
assert all_captured_flags == [
|
|
131
|
+
assert all_captured_flags == [subprocess_window.hidden_window_creation_flags()] * 2
|
|
126
132
|
|
|
127
133
|
|
|
128
134
|
def test_windows_process_host_spawn_hides_its_window(
|
|
@@ -139,7 +145,7 @@ def test_windows_process_host_spawn_hides_its_window(
|
|
|
139
145
|
|
|
140
146
|
execution._spawn_windows_process_host(("python", "-c", "pass"), registration, {})
|
|
141
147
|
|
|
142
|
-
expected_flags =
|
|
148
|
+
expected_flags = subprocess_window.hidden_window_creation_flags() | getattr(
|
|
143
149
|
subprocess, "BELOW_NORMAL_PRIORITY_CLASS", 0
|
|
144
150
|
)
|
|
145
151
|
assert captured_options["creationflags"] == expected_flags
|
|
@@ -159,5 +165,5 @@ def test_start_polling_launches_with_the_poller_flags(
|
|
|
159
165
|
assert cli.start_polling(tmp_path / "settings.json") == 0
|
|
160
166
|
assert (
|
|
161
167
|
captured_options["creationflags"]
|
|
162
|
-
==
|
|
168
|
+
== subprocess_window.detached_hidden_window_creation_flags()
|
|
163
169
|
)
|
|
@@ -119,3 +119,40 @@ def test_malformed_config_stops_scanning(tmp_path: Path, content: str) -> None:
|
|
|
119
119
|
|
|
120
120
|
def test_missing_config_has_no_exemptions(tmp_path: Path) -> None:
|
|
121
121
|
assert load_email_exemptions(tmp_path) == frozenset()
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@pytest.mark.parametrize(
|
|
125
|
+
"document",
|
|
126
|
+
[
|
|
127
|
+
{"version": 1},
|
|
128
|
+
{
|
|
129
|
+
"version": 1,
|
|
130
|
+
"path_exemptions": [
|
|
131
|
+
{
|
|
132
|
+
"path": "evidence/manifest.json",
|
|
133
|
+
"sha256": DIGEST,
|
|
134
|
+
"reason": "Frozen evidence file pinned by its consumers",
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
)
|
|
140
|
+
def test_document_without_the_email_list_loads_no_email_exemptions(
|
|
141
|
+
tmp_path: Path, document: dict[str, object]
|
|
142
|
+
) -> None:
|
|
143
|
+
"""A document may carry the other family, or no exception list at all."""
|
|
144
|
+
(tmp_path / "config").mkdir()
|
|
145
|
+
(tmp_path / "config" / "repository-policy.json").write_text(
|
|
146
|
+
json.dumps(document), encoding="utf-8"
|
|
147
|
+
)
|
|
148
|
+
assert load_email_exemptions(tmp_path) == frozenset()
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def test_reason_rejection_names_the_ownership_requirement(tmp_path: Path) -> None:
|
|
152
|
+
_write_config(tmp_path, [_entry(reason=" ")])
|
|
153
|
+
with pytest.raises(ValueError) as rejection:
|
|
154
|
+
load_email_exemptions(tmp_path)
|
|
155
|
+
assert (
|
|
156
|
+
str(rejection.value)
|
|
157
|
+
== "Email exemption reason must explain why the exception is owned"
|
|
158
|
+
)
|