claude-dev-env 8.75.1 → 8.75.3
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/context-audit/scripts/context_audit_constants/config/test_constants.py +35 -0
- package/.agents/skills/context-audit/scripts/test_context_inventory.py +109 -0
- package/.agents/skills/context-audit/scripts/test_context_report.py +123 -0
- package/.agents/skills/context-audit/scripts/test_context_sources.py +118 -0
- package/bin/ever-shipped-skills.test.mjs +4 -0
- package/package.json +1 -1
- package/scripts/account_broker_support.py +44 -17
- package/scripts/dev_env_scripts_constants/account_broker_constants.py +4 -0
- package/scripts/policy_lint/adapter_pairing.py +4 -0
- package/scripts/policy_lint/config/constants.py +1 -0
- package/scripts/test_account_broker.py +3 -1
- package/scripts/test_account_broker_support.py +91 -18
- package/scripts/tests/test_policy_lint_rules_pairing.py +38 -0
- package/scripts/tests/test_runner.py +42 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
from context_audit_constants.config import constants
|
|
4
|
+
from context_audit_constants.config.constants import CapKey, RowKind, Trigger
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_every_cap_key_has_a_line_cap() -> None:
|
|
8
|
+
assert set(constants.ALL_LINE_CAP_BY_KEY) == set(CapKey)
|
|
9
|
+
assert constants.ALL_LINE_CAP_BY_KEY[CapKey.ROOT_INSTRUCTIONS] == 20
|
|
10
|
+
assert constants.ALL_LINE_CAP_BY_KEY[CapKey.SKILL_BODY] == 200
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_trigger_values_match_the_report_labels() -> None:
|
|
14
|
+
assert [each_trigger.value for each_trigger in Trigger] == [
|
|
15
|
+
"session-start",
|
|
16
|
+
"folder-enter",
|
|
17
|
+
"path-match",
|
|
18
|
+
"skill-invoke",
|
|
19
|
+
"on-link",
|
|
20
|
+
"file-open",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_stub_kinds_cover_instruction_files_only() -> None:
|
|
25
|
+
assert constants.ALL_STUB_KINDS == {
|
|
26
|
+
RowKind.INSTRUCTIONS,
|
|
27
|
+
RowKind.IMPORT,
|
|
28
|
+
RowKind.RULE,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_link_pattern_drops_the_anchor_from_a_target() -> None:
|
|
33
|
+
assert re.findall(constants.LINK_PATTERN, "[a](guide.md#setup) [b](x y)") == [
|
|
34
|
+
"guide.md"
|
|
35
|
+
]
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""Behavior tests for walking a checkout into context rows."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
scripts_directory = str(Path(__file__).resolve().parent)
|
|
10
|
+
if scripts_directory not in sys.path:
|
|
11
|
+
sys.path.insert(0, scripts_directory)
|
|
12
|
+
|
|
13
|
+
from context_audit_constants.config.constants import DepthMode, RowKind, Trigger
|
|
14
|
+
from context_inventory import ContextInventory, audit_checkout
|
|
15
|
+
from context_sources import ContextRow
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _tracked_checkout(root: Path, text_by_relative_path: dict[str, str]) -> Path:
|
|
19
|
+
for each_relative_path, each_text in text_by_relative_path.items():
|
|
20
|
+
path = root / each_relative_path
|
|
21
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
22
|
+
path.write_text(each_text, encoding="utf-8")
|
|
23
|
+
subprocess.run(["git", "init", "-q"], cwd=root, check=True)
|
|
24
|
+
subprocess.run(["git", "add", "-A"], cwd=root, check=True)
|
|
25
|
+
return root.resolve()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _row_by_key(all_rows: list[ContextRow]) -> dict[tuple[str, RowKind], ContextRow]:
|
|
29
|
+
return {(each_row.path, each_row.kind): each_row for each_row in all_rows}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_should_mark_installed_rules_global_unless_path_scoped(tmp_path: Path) -> None:
|
|
33
|
+
root = _tracked_checkout(
|
|
34
|
+
tmp_path / "repo",
|
|
35
|
+
{
|
|
36
|
+
"rules/everywhere.md": "Always.\n",
|
|
37
|
+
"rules/scoped.md": "---\npaths:\n - src/**\n---\nScoped.\n",
|
|
38
|
+
},
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
row_by_key = _row_by_key(audit_checkout(root, root / "rules", None, ()))
|
|
42
|
+
|
|
43
|
+
everywhere_row = row_by_key[("rules/everywhere.md", RowKind.RULE)]
|
|
44
|
+
scoped_row = row_by_key[("rules/scoped.md", RowKind.RULE)]
|
|
45
|
+
assert (everywhere_row.trigger, everywhere_row.note) == (
|
|
46
|
+
Trigger.SESSION_START,
|
|
47
|
+
"installed rule: loads in every project",
|
|
48
|
+
)
|
|
49
|
+
assert (scoped_row.trigger, scoped_row.note) == (Trigger.PATH_MATCH, "")
|
|
50
|
+
assert everywhere_row.loader == "Claude Code harness, installed rules folder"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_should_skip_rule_folders_that_are_not_installed(tmp_path: Path) -> None:
|
|
54
|
+
root = _tracked_checkout(tmp_path / "repo", {"rules/everywhere.md": "Always.\n"})
|
|
55
|
+
|
|
56
|
+
assert audit_checkout(root, None, None, ()) == []
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_should_list_installed_and_plugin_skills_at_session_start(
|
|
60
|
+
tmp_path: Path,
|
|
61
|
+
) -> None:
|
|
62
|
+
long_description = "x" * 1600
|
|
63
|
+
root = _tracked_checkout(
|
|
64
|
+
tmp_path / "repo",
|
|
65
|
+
{
|
|
66
|
+
"pack/skills/tidy/SKILL.md": "---\ndescription: Tidy up.\n---\nBody.\n",
|
|
67
|
+
"plugins/kit/skills/wide/SKILL.md": (
|
|
68
|
+
f"---\ndescription: {long_description}\n---\nBody.\n"
|
|
69
|
+
),
|
|
70
|
+
},
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
row_by_key = _row_by_key(audit_checkout(root, None, root / "pack" / "skills", ()))
|
|
74
|
+
|
|
75
|
+
installed_row = row_by_key[("pack/skills/tidy/SKILL.md", RowKind.SKILL_DESCRIPTION)]
|
|
76
|
+
plugin_row = row_by_key[
|
|
77
|
+
("plugins/kit/skills/wide/SKILL.md", RowKind.SKILL_DESCRIPTION)
|
|
78
|
+
]
|
|
79
|
+
assert installed_row.loader == "skill listing, installed skills folder"
|
|
80
|
+
assert installed_row.trigger == Trigger.SESSION_START
|
|
81
|
+
assert installed_row.depth_mode == DepthMode.POINTS
|
|
82
|
+
assert plugin_row.loader == "skill listing, plugin skills folder"
|
|
83
|
+
assert (plugin_row.bytes, plugin_row.depth_mode) == (1536, DepthMode.CARRIES)
|
|
84
|
+
assert plugin_row.note == (
|
|
85
|
+
"loads when the plugin is installed; listing truncates at 1,536 characters"
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def test_should_name_how_codex_and_claude_reach_an_agents_file(tmp_path: Path) -> None:
|
|
90
|
+
root = _tracked_checkout(
|
|
91
|
+
tmp_path / "repo",
|
|
92
|
+
{
|
|
93
|
+
"AGENTS.md": "Root rules.\n",
|
|
94
|
+
"pkg/AGENTS.md": "Package rules.\n",
|
|
95
|
+
"pkg/CLAUDE.md": "Claude rules.\n",
|
|
96
|
+
},
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
row_by_key = _row_by_key(ContextInventory(root, None, None).collect(()))
|
|
100
|
+
|
|
101
|
+
assert row_by_key[("AGENTS.md", RowKind.INSTRUCTIONS)].loader == (
|
|
102
|
+
"Claude Code native AGENTS.md read; Codex reads it"
|
|
103
|
+
)
|
|
104
|
+
assert row_by_key[("pkg/AGENTS.md", RowKind.INSTRUCTIONS)].loader == (
|
|
105
|
+
"not read by Claude Code (sibling CLAUDE.md, no import); Codex reads it"
|
|
106
|
+
)
|
|
107
|
+
assert row_by_key[("pkg/AGENTS.md", RowKind.INSTRUCTIONS)].trigger == (
|
|
108
|
+
Trigger.FOLDER_ENTER
|
|
109
|
+
)
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""Behavior tests for formatting inventory rows as a markdown report."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
scripts_directory = str(Path(__file__).resolve().parent)
|
|
9
|
+
if scripts_directory not in sys.path:
|
|
10
|
+
sys.path.insert(0, scripts_directory)
|
|
11
|
+
|
|
12
|
+
from context_audit_constants.config.constants import DepthMode, RowKind, Trigger
|
|
13
|
+
from context_report import (
|
|
14
|
+
format_carries_section,
|
|
15
|
+
format_cleanup_list,
|
|
16
|
+
format_report,
|
|
17
|
+
format_split_section,
|
|
18
|
+
format_stub_section,
|
|
19
|
+
format_trigger_table,
|
|
20
|
+
)
|
|
21
|
+
from context_sources import ContextRow
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _row(
|
|
25
|
+
path: str,
|
|
26
|
+
kind: RowKind,
|
|
27
|
+
trigger: Trigger,
|
|
28
|
+
depth_mode: DepthMode,
|
|
29
|
+
lines: int,
|
|
30
|
+
est_tokens: int,
|
|
31
|
+
) -> ContextRow:
|
|
32
|
+
return ContextRow(
|
|
33
|
+
path=path,
|
|
34
|
+
kind=kind,
|
|
35
|
+
loader="harness",
|
|
36
|
+
trigger=trigger,
|
|
37
|
+
bytes=est_tokens * 4,
|
|
38
|
+
lines=lines,
|
|
39
|
+
est_tokens=est_tokens,
|
|
40
|
+
links_out=0,
|
|
41
|
+
depth_mode=depth_mode,
|
|
42
|
+
cap=20,
|
|
43
|
+
note="",
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
_ROOT_ROW = _row(
|
|
48
|
+
"AGENTS.md", RowKind.INSTRUCTIONS, Trigger.SESSION_START, DepthMode.CARRIES, 30, 300
|
|
49
|
+
)
|
|
50
|
+
_RULE_ROW = _row(
|
|
51
|
+
"rules/big.md", RowKind.RULE, Trigger.SESSION_START, DepthMode.CARRIES, 40, 500
|
|
52
|
+
)
|
|
53
|
+
_STUB_ROW = _row(
|
|
54
|
+
"pkg/CLAUDE.md", RowKind.INSTRUCTIONS, Trigger.FOLDER_ENTER, DepthMode.EMPTY, 0, 0
|
|
55
|
+
)
|
|
56
|
+
_SKILL_ROW = _row(
|
|
57
|
+
"skills/x/SKILL.md",
|
|
58
|
+
RowKind.SKILL_BODY,
|
|
59
|
+
Trigger.SKILL_INVOKE,
|
|
60
|
+
DepthMode.CARRIES,
|
|
61
|
+
250,
|
|
62
|
+
900,
|
|
63
|
+
)
|
|
64
|
+
_EMPTY_DOCSTRING_ROW = _row(
|
|
65
|
+
"src/mod.py", RowKind.DOCSTRING, Trigger.FILE_OPEN, DepthMode.EMPTY, 0, 0
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_should_total_each_present_trigger_in_enum_order() -> None:
|
|
70
|
+
all_lines = format_trigger_table([_STUB_ROW, _ROOT_ROW, _RULE_ROW])
|
|
71
|
+
|
|
72
|
+
assert all_lines[4:] == [
|
|
73
|
+
"| session-start | 2 | 70 | 800 |",
|
|
74
|
+
"| folder-enter | 1 | 0 | 0 |",
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def test_should_list_carries_rows_or_say_none() -> None:
|
|
79
|
+
assert format_carries_section([])[-1] == "None."
|
|
80
|
+
assert format_carries_section([_RULE_ROW])[-1] == (
|
|
81
|
+
"| rules/big.md | rule | session-start | 40 | 20 | 500 |"
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_should_list_stub_rows_or_say_none() -> None:
|
|
86
|
+
assert format_stub_section([])[-1] == "None."
|
|
87
|
+
assert format_stub_section([_STUB_ROW])[-1] == "- pkg/CLAUDE.md (instructions)"
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def test_should_list_long_skills_or_say_none() -> None:
|
|
91
|
+
assert format_split_section([])[-1] == "None."
|
|
92
|
+
assert format_split_section([_SKILL_ROW])[-1] == (
|
|
93
|
+
"| skills/x/SKILL.md | 250 | 20 | 900 |"
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def test_should_sort_cleanup_rows_largest_first_and_route_each_kind() -> None:
|
|
98
|
+
all_lines = format_cleanup_list(
|
|
99
|
+
[_ROOT_ROW, _RULE_ROW, _STUB_ROW, _SKILL_ROW, _EMPTY_DOCSTRING_ROW]
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
carries_start = all_lines.index("## Carries depth over cap")
|
|
103
|
+
stubs_start = all_lines.index("## Empty instruction stubs")
|
|
104
|
+
all_carries_rows = all_lines[carries_start + 4 : stubs_start - 1]
|
|
105
|
+
assert all_carries_rows == [
|
|
106
|
+
"| rules/big.md | rule | session-start | 40 | 20 | 500 |",
|
|
107
|
+
"| AGENTS.md | instructions | session-start | 30 | 20 | 300 |",
|
|
108
|
+
]
|
|
109
|
+
assert "- pkg/CLAUDE.md (instructions)" in all_lines
|
|
110
|
+
assert not any("src/mod.py" in each_line for each_line in all_lines)
|
|
111
|
+
assert "| skills/x/SKILL.md | 250 | 20 | 900 |" in all_lines
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_should_summarize_session_start_load_in_the_report() -> None:
|
|
115
|
+
report = format_report("demo", [_ROOT_ROW, _RULE_ROW, _STUB_ROW])
|
|
116
|
+
|
|
117
|
+
assert report.startswith(
|
|
118
|
+
"# Context audit: demo\n\n"
|
|
119
|
+
"3 loaded files. Startup loads 70 lines, about 800 tokens, from 2 files.\n"
|
|
120
|
+
)
|
|
121
|
+
assert report.endswith(
|
|
122
|
+
"- pkg/CLAUDE.md (instructions)\n\n## Long skills to split\n\nNone.\n"
|
|
123
|
+
)
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""Behavior tests for reading checkout files and measuring context rows."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
scripts_directory = str(Path(__file__).resolve().parent)
|
|
10
|
+
if scripts_directory not in sys.path:
|
|
11
|
+
sys.path.insert(0, scripts_directory)
|
|
12
|
+
|
|
13
|
+
from context_audit_constants.config.constants import DepthMode, RowKind, Trigger
|
|
14
|
+
from context_sources import (
|
|
15
|
+
RowSource,
|
|
16
|
+
classify_depth,
|
|
17
|
+
count_lines,
|
|
18
|
+
find_import_targets,
|
|
19
|
+
find_relative_links,
|
|
20
|
+
list_tracked_files,
|
|
21
|
+
measure_row,
|
|
22
|
+
parse_frontmatter,
|
|
23
|
+
read_text,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _write(root: Path, relative_path: str, text: str) -> Path:
|
|
28
|
+
path = root / relative_path
|
|
29
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
30
|
+
path.write_text(text, encoding="utf-8")
|
|
31
|
+
return path
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_should_list_tracked_files_without_cache_folders_or_untracked_files(
|
|
35
|
+
tmp_path: Path,
|
|
36
|
+
) -> None:
|
|
37
|
+
subprocess.run(["git", "init", "-q"], cwd=tmp_path, check=True)
|
|
38
|
+
_write(tmp_path, "AGENTS.md", "# Root\n")
|
|
39
|
+
_write(tmp_path, "node_modules/pkg/README.md", "vendored\n")
|
|
40
|
+
_write(tmp_path, "notes.md", "untracked\n")
|
|
41
|
+
subprocess.run(
|
|
42
|
+
["git", "add", "-f", "AGENTS.md", "node_modules/pkg/README.md"],
|
|
43
|
+
cwd=tmp_path,
|
|
44
|
+
check=True,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
assert list_tracked_files(tmp_path) == [tmp_path / "AGENTS.md"]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_should_read_text_and_return_empty_for_a_missing_file(tmp_path: Path) -> None:
|
|
51
|
+
present_path = _write(tmp_path, "rule.md", "line one\n")
|
|
52
|
+
|
|
53
|
+
assert read_text(present_path) == "line one\n"
|
|
54
|
+
assert read_text(tmp_path / "absent.md") == ""
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_should_parse_frontmatter_and_join_continuation_lines() -> None:
|
|
58
|
+
text = "---\nname: demo\npaths:\n - src/**\n---\n# Body\n"
|
|
59
|
+
|
|
60
|
+
assert parse_frontmatter(text) == {"name": "demo", "paths": "- src/**"}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_should_return_no_frontmatter_when_the_fence_never_closes() -> None:
|
|
64
|
+
assert parse_frontmatter("---\nname: demo\n# Body\n") == {}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_should_find_links_inside_the_checkout_only(tmp_path: Path) -> None:
|
|
68
|
+
source = _write(tmp_path, "docs/index.md", "")
|
|
69
|
+
guide = _write(tmp_path, "docs/guide.md", "guide\n")
|
|
70
|
+
text = (
|
|
71
|
+
"[guide](guide.md#setup) [web](https://example.com/page.md)"
|
|
72
|
+
" [missing](absent.md)"
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
assert find_relative_links(source, text, tmp_path.resolve()) == [guide.resolve()]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def test_should_find_import_targets_that_exist(tmp_path: Path) -> None:
|
|
79
|
+
source = _write(tmp_path, "CLAUDE.md", "")
|
|
80
|
+
agents = _write(tmp_path, "AGENTS.md", "rules\n")
|
|
81
|
+
|
|
82
|
+
all_targets = find_import_targets(
|
|
83
|
+
source, "\n".join(["@AGENTS.md", "@missing.md", ""]), tmp_path.resolve()
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
assert all_targets == [agents.resolve()]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def test_should_classify_each_depth_mode() -> None:
|
|
90
|
+
assert classify_depth(20, 0, 0, 0) == DepthMode.EMPTY
|
|
91
|
+
assert classify_depth(None, 900, 30, 0) == DepthMode.REFERENCE
|
|
92
|
+
assert classify_depth(20, 4000, 64, 2) == DepthMode.CARRIES
|
|
93
|
+
assert classify_depth(20, 2500, 10, 0) == DepthMode.CARRIES
|
|
94
|
+
assert classify_depth(20, 600, 12, 3) == DepthMode.POINTS
|
|
95
|
+
assert classify_depth(20, 600, 12, 0) == DepthMode.LEAN
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def test_should_count_an_unterminated_final_line() -> None:
|
|
99
|
+
assert count_lines("") == 0
|
|
100
|
+
assert count_lines("one\ntwo\n") == 2
|
|
101
|
+
assert count_lines("one\ntwo") == 2
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def test_should_measure_a_row_from_its_text() -> None:
|
|
105
|
+
source = RowSource(
|
|
106
|
+
"rules/plain.md", RowKind.RULE, "harness", Trigger.SESSION_START, "note"
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
row = measure_row(source, "a" * 39 + "\n", 20, 1)
|
|
110
|
+
|
|
111
|
+
assert (row.path, row.kind, row.trigger, row.note) == (
|
|
112
|
+
"rules/plain.md",
|
|
113
|
+
RowKind.RULE,
|
|
114
|
+
Trigger.SESSION_START,
|
|
115
|
+
"note",
|
|
116
|
+
)
|
|
117
|
+
assert (row.bytes, row.lines, row.est_tokens, row.links_out) == (40, 1, 10, 1)
|
|
118
|
+
assert (row.depth_mode, row.cap) == (DepthMode.POINTS, 20)
|
|
@@ -53,6 +53,10 @@ test('EVER_SHIPPED_SKILL_NAMES includes the windows scheduled task skill', () =>
|
|
|
53
53
|
assert.equal(EVER_SHIPPED_SKILL_NAMES.has('windows-scheduled-task'), true);
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
+
test('EVER_SHIPPED_SKILL_NAMES includes the mod playbooks skill', () => {
|
|
57
|
+
assert.equal(EVER_SHIPPED_SKILL_NAMES.has('mod-playbooks'), true);
|
|
58
|
+
});
|
|
59
|
+
|
|
56
60
|
test('build-eval ships under its matching name without the retired active directory', () => {
|
|
57
61
|
const sourceSkillsDirectory = join(
|
|
58
62
|
PACKAGE_DIRECTORY,
|
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@ import subprocess
|
|
|
12
12
|
import sys
|
|
13
13
|
import tempfile
|
|
14
14
|
import threading
|
|
15
|
+
import time
|
|
15
16
|
from contextlib import contextmanager
|
|
16
17
|
from datetime import datetime, timezone
|
|
17
18
|
from pathlib import Path, PureWindowsPath
|
|
@@ -37,6 +38,10 @@ from dev_env_scripts_constants.account_broker_constants import (
|
|
|
37
38
|
CMD_SHELL_METACHARACTERS,
|
|
38
39
|
Decision,
|
|
39
40
|
JobOutcome,
|
|
41
|
+
METER_READ_ATTEMPTS,
|
|
42
|
+
METER_READ_DELAY_FACTOR,
|
|
43
|
+
METER_READ_FIRST_DELAY_SECONDS,
|
|
44
|
+
METER_READ_MAX_DELAY_SECONDS,
|
|
40
45
|
Meters,
|
|
41
46
|
Product,
|
|
42
47
|
ProductAdapter,
|
|
@@ -210,12 +215,13 @@ def read_claude_meters(account: Account) -> Meters | None:
|
|
|
210
215
|
account: Account whose meter is read.
|
|
211
216
|
|
|
212
217
|
Returns:
|
|
213
|
-
Its meters
|
|
218
|
+
Its meters.
|
|
219
|
+
|
|
220
|
+
Raises:
|
|
221
|
+
WeeklyUtilizationProbeError: The usage meters could not be measured.
|
|
222
|
+
OSError: The credentials file could not be read.
|
|
214
223
|
"""
|
|
215
|
-
|
|
216
|
-
usage = probe_account_meters(account.home / CREDENTIALS_FILE_NAME)
|
|
217
|
-
except (WeeklyUtilizationProbeError, OSError):
|
|
218
|
-
return None
|
|
224
|
+
usage = probe_account_meters(account.home / CREDENTIALS_FILE_NAME)
|
|
219
225
|
return Meters(
|
|
220
226
|
FULL_PERCENT - usage.session_utilization if usage.session_utilization is not None else None,
|
|
221
227
|
usage.session_resets_at,
|
|
@@ -231,17 +237,14 @@ def read_codex_account_meters(account: Account) -> Meters:
|
|
|
231
237
|
account: Account whose meter is read.
|
|
232
238
|
|
|
233
239
|
Returns:
|
|
234
|
-
Its meters
|
|
240
|
+
Its meters.
|
|
235
241
|
|
|
236
242
|
Raises:
|
|
237
|
-
CodexMeterUnreadError:
|
|
243
|
+
CodexMeterUnreadError: The meter read failed.
|
|
238
244
|
OSError: No Codex executable was found.
|
|
239
245
|
"""
|
|
240
246
|
codex_path = codex_account_meters.resolve_codex_path(None)
|
|
241
|
-
|
|
242
|
-
usage = codex_account_meters.read_codex_meters(codex_path, account.home)
|
|
243
|
-
except codex_account_meters.CodexMeterUnreadError:
|
|
244
|
-
usage = codex_account_meters.read_codex_meters(codex_path, account.home)
|
|
247
|
+
usage = codex_account_meters.read_codex_meters(codex_path, account.home)
|
|
245
248
|
weekly = [window for window in usage.all_windows if window.duration_minutes is None or window.duration_minutes >= WEEKLY_WINDOW_MINUTES]
|
|
246
249
|
short = [window for window in usage.all_windows if window.duration_minutes is not None and window.duration_minutes < WEEKLY_WINDOW_MINUTES]
|
|
247
250
|
weekly_window = max(weekly, key=lambda window: window.used_percent) if weekly else None
|
|
@@ -254,6 +257,35 @@ def read_codex_account_meters(account: Account) -> Meters:
|
|
|
254
257
|
)
|
|
255
258
|
|
|
256
259
|
|
|
260
|
+
def read_meters_with_backoff(read_meters: Callable[[Account], Meters | None], account: Account) -> tuple[Meters | None, str | None]:
|
|
261
|
+
"""Read one account's meters, retrying a failed read with exponential backoff.
|
|
262
|
+
|
|
263
|
+
Args:
|
|
264
|
+
read_meters: The product's meter reader.
|
|
265
|
+
account: Account whose meter is read.
|
|
266
|
+
|
|
267
|
+
Returns:
|
|
268
|
+
The meters from the first read that succeeds, or None with the last
|
|
269
|
+
failure text once every attempt failed.
|
|
270
|
+
"""
|
|
271
|
+
unread_reason = None
|
|
272
|
+
for each_attempt in range(METER_READ_ATTEMPTS):
|
|
273
|
+
if each_attempt:
|
|
274
|
+
time.sleep(min(METER_READ_FIRST_DELAY_SECONDS * METER_READ_DELAY_FACTOR ** (each_attempt - 1), METER_READ_MAX_DELAY_SECONDS))
|
|
275
|
+
try:
|
|
276
|
+
return read_meters(account), None
|
|
277
|
+
except (
|
|
278
|
+
codex_account_meters.CodexMeterUnreadError,
|
|
279
|
+
WeeklyUtilizationProbeError,
|
|
280
|
+
OSError,
|
|
281
|
+
ValueError,
|
|
282
|
+
RuntimeError,
|
|
283
|
+
subprocess.SubprocessError,
|
|
284
|
+
) as error:
|
|
285
|
+
unread_reason = str(error) or type(error).__name__
|
|
286
|
+
return None, unread_reason
|
|
287
|
+
|
|
288
|
+
|
|
257
289
|
all_product_adapters = {
|
|
258
290
|
Product.CLAUDE: ProductAdapter(load_claude_accounts, read_claude_meters, CLAUDE_CONFIG_DIR_ENV_VAR, ALL_USAGE_LIMIT_SIGNATURES),
|
|
259
291
|
Product.CODEX: ProductAdapter(load_codex_accounts, read_codex_account_meters, CODEX_HOME_ENVIRONMENT_VARIABLE, codex_usage_limit_signatures()),
|
|
@@ -409,12 +441,7 @@ def _read_one_account(account: Account, adapter: ProductAdapter, all_cache: dict
|
|
|
409
441
|
if isinstance(cached, dict) and isinstance(cached.get("read_at"), (int, float)) and 0 <= now.timestamp() - cached["read_at"] < 60:
|
|
410
442
|
cached_reason = cached.get("unread_reason")
|
|
411
443
|
return Reading(account, _meters_from_payload(cached.get("meters")), cached_reason if isinstance(cached_reason, str) else None), False
|
|
412
|
-
unread_reason =
|
|
413
|
-
try:
|
|
414
|
-
meters = adapter.read_meters(account)
|
|
415
|
-
except (codex_account_meters.CodexMeterUnreadError, OSError, ValueError, RuntimeError, subprocess.SubprocessError) as error:
|
|
416
|
-
meters = None
|
|
417
|
-
unread_reason = str(error) or type(error).__name__
|
|
444
|
+
meters, unread_reason = read_meters_with_backoff(adapter.read_meters, account)
|
|
418
445
|
all_cache[key] = {"read_at": now.timestamp(), "meters": _meter_payload(meters), "unread_reason": unread_reason}
|
|
419
446
|
return Reading(account, meters, unread_reason), True
|
|
420
447
|
|
|
@@ -48,6 +48,10 @@ ALL_CODEX_FLOORS = {
|
|
|
48
48
|
"luna_short_minimum_left": LUNA_TIER_SHORT_WINDOW_MINIMUM_PERCENT_LEFT,
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
METER_READ_ATTEMPTS = 3
|
|
52
|
+
METER_READ_FIRST_DELAY_SECONDS = 1.0
|
|
53
|
+
METER_READ_DELAY_FACTOR = 2.0
|
|
54
|
+
METER_READ_MAX_DELAY_SECONDS = 8.0
|
|
51
55
|
WAIT_EXIT_CODE = 3
|
|
52
56
|
COMMAND_MISSING_EXIT_CODE = 127
|
|
53
57
|
TIMEOUT_EXIT_CODE = 124
|
|
@@ -300,6 +300,10 @@ def _is_unpaired_production(
|
|
|
300
300
|
return False
|
|
301
301
|
if _is_test_path(production_path):
|
|
302
302
|
return False
|
|
303
|
+
if production_path.name in constants.ALL_PAIRING_EXEMPT_FILE_NAMES:
|
|
304
|
+
return False
|
|
305
|
+
if not production_document.text.strip():
|
|
306
|
+
return False
|
|
303
307
|
if _is_constants_only_python_document(production_document, load_module):
|
|
304
308
|
return False
|
|
305
309
|
if _is_docstring_only_python_document(production_document):
|
|
@@ -198,6 +198,7 @@ ALL_INVENTORY_FILE_NAMES = frozenset(
|
|
|
198
198
|
{"CHANGELOG.md", "README.md", "ever-shipped-skills.mjs"}
|
|
199
199
|
)
|
|
200
200
|
ALL_UNCALLED_EXEMPT_FILE_NAMES = frozenset({"__init__.py", "conftest.py"})
|
|
201
|
+
ALL_PAIRING_EXEMPT_FILE_NAMES = frozenset({"conftest.py"})
|
|
201
202
|
CALLER_NAME_PATTERN_TEMPLATE = r"(?<![\w-]){name}(?![\w-])"
|
|
202
203
|
|
|
203
204
|
CONTEXT_BUDGET_RULE_ID = "context-budget"
|
|
@@ -10,6 +10,7 @@ from pathlib import Path
|
|
|
10
10
|
import pytest
|
|
11
11
|
|
|
12
12
|
import account_broker
|
|
13
|
+
import account_broker_support
|
|
13
14
|
import claude_account_worker
|
|
14
15
|
from account_broker import (
|
|
15
16
|
Account,
|
|
@@ -75,7 +76,8 @@ def _adapter(accounts: tuple[Account, ...], meters: dict[str, Meters | None]) ->
|
|
|
75
76
|
)
|
|
76
77
|
|
|
77
78
|
|
|
78
|
-
def test_should_name_the_unread_account_and_its_reason_when_no_account_has_room() -> None:
|
|
79
|
+
def test_should_name_the_unread_account_and_its_reason_when_no_account_has_room(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
80
|
+
monkeypatch.setattr(account_broker_support.time, "sleep", lambda _: None)
|
|
79
81
|
codex_3 = _account("codex-3")
|
|
80
82
|
codex_4 = _account("codex-4")
|
|
81
83
|
|
|
@@ -154,40 +154,113 @@ def _codex_meter_reads(
|
|
|
154
154
|
return all_homes_read
|
|
155
155
|
|
|
156
156
|
|
|
157
|
-
def
|
|
157
|
+
def _claude_meter_reads(monkeypatch: pytest.MonkeyPatch, all_outcomes: list[object]) -> list[Path]:
|
|
158
|
+
all_paths_read: list[Path] = []
|
|
159
|
+
|
|
160
|
+
def probe_account_meters(credentials_path: Path) -> object:
|
|
161
|
+
all_paths_read.append(credentials_path)
|
|
162
|
+
outcome = all_outcomes.pop(0)
|
|
163
|
+
if isinstance(outcome, Exception):
|
|
164
|
+
raise outcome
|
|
165
|
+
return outcome
|
|
166
|
+
|
|
167
|
+
monkeypatch.setattr(support, "probe_account_meters", probe_account_meters)
|
|
168
|
+
return all_paths_read
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _recorded_sleeps(monkeypatch: pytest.MonkeyPatch) -> list[float]:
|
|
172
|
+
all_delays: list[float] = []
|
|
173
|
+
monkeypatch.setattr(support.time, "sleep", all_delays.append)
|
|
174
|
+
return all_delays
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def _first_reading(monkeypatch: pytest.MonkeyPatch, tmp_path: Path, account: Account, read_meters: object) -> object:
|
|
178
|
+
monkeypatch.setattr(support, "broker_state_path", lambda: tmp_path / "broker" / "state.json")
|
|
179
|
+
adapter = ProductAdapter(lambda: (account,), read_meters, "HOME", ())
|
|
180
|
+
state = support._load_state(support.broker_state_path())
|
|
181
|
+
now = datetime(2026, 10, 3, tzinfo=timezone.utc)
|
|
182
|
+
return support.read_accounts(account.product, adapter, all_state=state, now=now)[0], adapter, state, now
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def test_should_read_claude_meters_after_transient_failures_with_growing_delays(
|
|
186
|
+
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
187
|
+
) -> None:
|
|
188
|
+
usage = SimpleNamespace(session_utilization=20.0, session_resets_at=None, weekly_utilization=30.0, weekly_resets_at=None)
|
|
189
|
+
unread = support.WeeklyUtilizationProbeError("usage endpoint timed out")
|
|
190
|
+
all_paths_read = _claude_meter_reads(monkeypatch, [unread, unread, usage])
|
|
191
|
+
all_delays = _recorded_sleeps(monkeypatch)
|
|
192
|
+
|
|
193
|
+
reading = _first_reading(monkeypatch, tmp_path, Account(Product.CLAUDE, "org-jon", tmp_path), support.read_claude_meters)[0]
|
|
194
|
+
|
|
195
|
+
assert reading.meters is not None
|
|
196
|
+
assert reading.meters.weekly_percent_left == 70.0
|
|
197
|
+
assert reading.unread_reason is None
|
|
198
|
+
assert len(all_paths_read) == 3
|
|
199
|
+
assert all_delays == [1.0, 2.0]
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def test_should_read_codex_meters_after_transient_failures_with_growing_delays(
|
|
158
203
|
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
159
204
|
) -> None:
|
|
160
205
|
weekly = SimpleNamespace(duration_minutes=10080, used_percent=30.0, resets_at=None)
|
|
161
206
|
usage = SimpleNamespace(all_windows=(weekly,), short_window_percent_left=None)
|
|
162
207
|
unread = support.codex_account_meters.CodexMeterUnreadError("codex app-server sent no rate-limit reply")
|
|
163
|
-
all_homes_read = _codex_meter_reads(monkeypatch, tmp_path, [unread, usage])
|
|
208
|
+
all_homes_read = _codex_meter_reads(monkeypatch, tmp_path, [unread, unread, usage])
|
|
209
|
+
all_delays = _recorded_sleeps(monkeypatch)
|
|
164
210
|
|
|
165
|
-
|
|
211
|
+
reading = _first_reading(monkeypatch, tmp_path, Account(Product.CODEX, "one", tmp_path), support.read_codex_account_meters)[0]
|
|
166
212
|
|
|
167
|
-
assert meters is not None
|
|
168
|
-
assert meters.weekly_percent_left == 70.0
|
|
169
|
-
assert all_homes_read == [tmp_path, tmp_path]
|
|
213
|
+
assert reading.meters is not None
|
|
214
|
+
assert reading.meters.weekly_percent_left == 70.0
|
|
215
|
+
assert all_homes_read == [tmp_path, tmp_path, tmp_path]
|
|
216
|
+
assert all_delays == [1.0, 2.0]
|
|
170
217
|
|
|
171
218
|
|
|
172
|
-
def
|
|
219
|
+
def test_should_keep_the_unread_reason_after_every_claude_read_fails(
|
|
220
|
+
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
221
|
+
) -> None:
|
|
222
|
+
all_failures = [support.WeeklyUtilizationProbeError(f"usage endpoint failed {each_number}") for each_number in range(3)]
|
|
223
|
+
all_paths_read = _claude_meter_reads(monkeypatch, all_failures)
|
|
224
|
+
all_delays = _recorded_sleeps(monkeypatch)
|
|
225
|
+
|
|
226
|
+
reading, adapter, state, now = _first_reading(monkeypatch, tmp_path, Account(Product.CLAUDE, "org-jon", tmp_path), support.read_claude_meters)
|
|
227
|
+
cached_reading = support.read_accounts(Product.CLAUDE, adapter, all_state=state, now=now)[0]
|
|
228
|
+
|
|
229
|
+
assert reading.meters is None
|
|
230
|
+
assert reading.unread_reason == "usage endpoint failed 2"
|
|
231
|
+
assert cached_reading.unread_reason == "usage endpoint failed 2"
|
|
232
|
+
assert len(all_paths_read) == 3
|
|
233
|
+
assert all_delays == [1.0, 2.0]
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def test_should_keep_the_unread_reason_after_every_codex_read_fails(
|
|
173
237
|
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
174
238
|
) -> None:
|
|
175
|
-
monkeypatch.setattr(support, "broker_state_path", lambda: tmp_path / "broker" / "state.json")
|
|
176
239
|
first_unread = support.codex_account_meters.CodexMeterUnreadError("codex app-server failed: timed out")
|
|
177
|
-
|
|
178
|
-
all_homes_read = _codex_meter_reads(monkeypatch, tmp_path, [first_unread,
|
|
179
|
-
|
|
180
|
-
adapter = ProductAdapter(lambda: (account,), support.read_codex_account_meters, "CODEX_HOME", ())
|
|
181
|
-
state = support._load_state(support.broker_state_path())
|
|
182
|
-
now = datetime(2026, 10, 3, tzinfo=timezone.utc)
|
|
240
|
+
last_unread = support.codex_account_meters.CodexMeterUnreadError("codex app-server sent no rate-limit reply")
|
|
241
|
+
all_homes_read = _codex_meter_reads(monkeypatch, tmp_path, [first_unread, first_unread, last_unread])
|
|
242
|
+
_recorded_sleeps(monkeypatch)
|
|
183
243
|
|
|
184
|
-
|
|
244
|
+
reading, adapter, state, now = _first_reading(monkeypatch, tmp_path, Account(Product.CODEX, "codex-3", tmp_path), support.read_codex_account_meters)
|
|
185
245
|
cached_reading = support.read_accounts(Product.CODEX, adapter, all_state=state, now=now)[0]
|
|
186
246
|
|
|
187
|
-
assert
|
|
188
|
-
assert
|
|
247
|
+
assert reading.meters is None
|
|
248
|
+
assert reading.unread_reason == "codex app-server sent no rate-limit reply"
|
|
189
249
|
assert cached_reading.unread_reason == "codex app-server sent no rate-limit reply"
|
|
190
|
-
assert all_homes_read == [tmp_path, tmp_path]
|
|
250
|
+
assert all_homes_read == [tmp_path, tmp_path, tmp_path]
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def test_should_cap_the_meter_read_delay(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
|
|
254
|
+
monkeypatch.setattr(support, "METER_READ_ATTEMPTS", 6)
|
|
255
|
+
all_delays = _recorded_sleeps(monkeypatch)
|
|
256
|
+
all_failures = [support.WeeklyUtilizationProbeError("down") for _ in range(6)]
|
|
257
|
+
_claude_meter_reads(monkeypatch, all_failures)
|
|
258
|
+
|
|
259
|
+
meters, unread_reason = support.read_meters_with_backoff(support.read_claude_meters, Account(Product.CLAUDE, "one", tmp_path))
|
|
260
|
+
|
|
261
|
+
assert meters is None
|
|
262
|
+
assert unread_reason == "down"
|
|
263
|
+
assert all_delays == [1.0, 2.0, 4.0, 8.0, 8.0]
|
|
191
264
|
|
|
192
265
|
|
|
193
266
|
def test_should_cache_account_reading_under_injected_state_path(
|
|
@@ -149,6 +149,44 @@ def test_pairing_keeps_non_python_changes_on_existing_matching_rules(
|
|
|
149
149
|
assert len(all_diagnostics) == 1
|
|
150
150
|
|
|
151
151
|
|
|
152
|
+
def test_pairing_accepts_a_new_empty_package_marker(tmp_path: Path) -> None:
|
|
153
|
+
package_marker_path = PurePosixPath("src/feature_constants/__init__.py")
|
|
154
|
+
all_paths = _diagnostic_paths(
|
|
155
|
+
tmp_path,
|
|
156
|
+
Document(
|
|
157
|
+
package_marker_path, "", None, frozenset(), ContentOrigin.REVISION_DIFF
|
|
158
|
+
),
|
|
159
|
+
)
|
|
160
|
+
assert all_paths == ()
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def test_pairing_accepts_a_module_emptied_of_its_body(tmp_path: Path) -> None:
|
|
164
|
+
all_paths = _diagnostic_paths(
|
|
165
|
+
tmp_path,
|
|
166
|
+
Document(
|
|
167
|
+
PurePosixPath("src/feature.py"),
|
|
168
|
+
"\n",
|
|
169
|
+
_BODY_BEFORE,
|
|
170
|
+
frozenset({1}),
|
|
171
|
+
ContentOrigin.REVISION_DIFF,
|
|
172
|
+
),
|
|
173
|
+
)
|
|
174
|
+
assert all_paths == ()
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def test_pairing_accepts_a_conftest_body_change(tmp_path: Path) -> None:
|
|
178
|
+
all_paths = _diagnostic_paths(
|
|
179
|
+
tmp_path, _body_change_at(PurePosixPath("src/conftest.py"))
|
|
180
|
+
)
|
|
181
|
+
assert all_paths == ()
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def test_pairing_rejects_a_package_marker_with_a_body(tmp_path: Path) -> None:
|
|
185
|
+
package_marker_path = PurePosixPath("src/feature/__init__.py")
|
|
186
|
+
all_paths = _diagnostic_paths(tmp_path, _body_change_at(package_marker_path))
|
|
187
|
+
assert all_paths == (package_marker_path,)
|
|
188
|
+
|
|
189
|
+
|
|
152
190
|
_APPROVED_PRODUCTION_PATH = PurePosixPath(
|
|
153
191
|
"packages/claude-dev-env/scripts/automatic_advisory/state.py"
|
|
154
192
|
)
|
|
@@ -12,10 +12,17 @@ if str(_TESTS_DIRECTORY) not in sys.path:
|
|
|
12
12
|
sys.path.insert(0, str(_TESTS_DIRECTORY))
|
|
13
13
|
|
|
14
14
|
from repository_checks.config.constants import (
|
|
15
|
+
ALL_CHECK_IDS,
|
|
16
|
+
CHECK_ID_CLAUDE_MD_ORPHANS,
|
|
17
|
+
CHECK_ID_ENV_VAR_DOCUMENTATION,
|
|
18
|
+
CHECK_ID_PACKAGE_INVENTORY,
|
|
19
|
+
CHECK_ID_PYTEST_TESTPATHS,
|
|
20
|
+
CHECK_ID_TRACKED_PERSONAL_DATA,
|
|
15
21
|
CHECK_ID_TRACKED_PRIVATE_TERMS,
|
|
16
22
|
FAILED_CHECK_EXIT_CODE,
|
|
17
23
|
FINDINGS_EXIT_CODE,
|
|
18
24
|
)
|
|
25
|
+
from repository_checks.runner import run_repository_checks
|
|
19
26
|
from repository_policy_test_support import (
|
|
20
27
|
commit_tracked_files,
|
|
21
28
|
initialize_repository,
|
|
@@ -77,3 +84,38 @@ def test_should_fail_closed_when_the_private_term_check_cannot_read_a_file(
|
|
|
77
84
|
exit_code, stdout_text, _stderr_text = run_policy(repository_root)
|
|
78
85
|
assert exit_code == FAILED_CHECK_EXIT_CODE
|
|
79
86
|
assert f"error: rule failed: {CHECK_ID_TRACKED_PRIVATE_TERMS}" in stdout_text
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
_COLLECTOR_NAME_BY_CHECK_ID = {
|
|
90
|
+
CHECK_ID_CLAUDE_MD_ORPHANS: "collect_claude_md_orphan_findings",
|
|
91
|
+
CHECK_ID_ENV_VAR_DOCUMENTATION: "collect_env_var_documentation_findings",
|
|
92
|
+
CHECK_ID_PACKAGE_INVENTORY: "collect_package_inventory_findings",
|
|
93
|
+
CHECK_ID_PYTEST_TESTPATHS: "collect_pytest_testpath_findings",
|
|
94
|
+
CHECK_ID_TRACKED_PERSONAL_DATA: "collect_tracked_secret_findings",
|
|
95
|
+
CHECK_ID_TRACKED_PRIVATE_TERMS: "collect_tracked_private_term_findings",
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def test_should_name_a_collector_for_every_check_id() -> None:
|
|
100
|
+
assert tuple(_COLLECTOR_NAME_BY_CHECK_ID) == ALL_CHECK_IDS
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
@pytest.mark.parametrize(
|
|
104
|
+
("check_id", "collector_name"), sorted(_COLLECTOR_NAME_BY_CHECK_ID.items())
|
|
105
|
+
)
|
|
106
|
+
def test_should_fail_closed_under_the_check_id_of_the_collector_that_raised(
|
|
107
|
+
tmp_path: Path,
|
|
108
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
109
|
+
check_id: str,
|
|
110
|
+
collector_name: str,
|
|
111
|
+
) -> None:
|
|
112
|
+
repository_root = seed_clean_repository(tmp_path / "repo")
|
|
113
|
+
|
|
114
|
+
def fail_collector(_repository_root: Path, _all_tracked_paths: object) -> list[object]:
|
|
115
|
+
raise OSError("collector failed")
|
|
116
|
+
|
|
117
|
+
monkeypatch.setattr(f"repository_checks.runner.{collector_name}", fail_collector)
|
|
118
|
+
|
|
119
|
+
report = run_repository_checks(repository_root)
|
|
120
|
+
|
|
121
|
+
assert report.all_failed_check_ids == (check_id,)
|