8Validate the ``.octrc.json`` schema validator and strict-mode enforcement (OI-411).
12- Confirm that ``_validate_octrc_schema()`` accepts well-formed configs.
13- Confirm that it rejects unknown profile names, wrong types, and
14 non-boolean rule values.
15- Confirm tolerance for unknown top-level keys.
27Outputs: list[str] validation errors
34 """An empty dict is valid — nothing to validate."""
35 errors = oct_lint._validate_octrc_schema({})
40 """Configs without a linter section are valid."""
41 errors = oct_lint._validate_octrc_schema({
"other":
"value"})
46 errors = oct_lint._validate_octrc_schema({
"linter":
"bogus"})
48 assert "'linter' must be an object" in errors[0]
52 errors = oct_lint._validate_octrc_schema({
"linter": {
"profile":
"strict"}})
57 errors = oct_lint._validate_octrc_schema({
"linter": {
"profile":
"bogus"}})
58 assert any(
"unknown value 'bogus'" in e
for e
in errors)
62 errors = oct_lint._validate_octrc_schema({
"linter": {
"profile": 123}})
63 assert any(
"'linter.profile' must be a string" in e
for e
in errors)
67 errors = oct_lint._validate_octrc_schema(
68 {
"linter": {
"exclude_dirs_add":
"not_a_list"}}
70 assert any(
"'linter.exclude_dirs_add' must be a list" in e
for e
in errors)
74 errors = oct_lint._validate_octrc_schema(
75 {
"linter": {
"exclude_dirs_add": [
"ok", 42]}}
77 assert any(
"'linter.exclude_dirs_add[1]'" in e
for e
in errors)
81 errors = oct_lint._validate_octrc_schema({
"linter": {
"rules": [
"header"]}})
82 assert any(
"'linter.rules' must be an object" in e
for e
in errors)
86 errors = oct_lint._validate_octrc_schema(
87 {
"linter": {
"rules": {
"header":
"yes"}}}
89 assert any(
"'linter.rules.header' must be a bool" in e
for e
in errors)
96 "exclude_dirs_add": [
"vendor",
"third_party"],
97 "exclude_dirs_remove": [
"tests"],
98 "wildcard_exclude_add": [
"*_generated"],
99 "rules": {
"type_hints":
False,
"header":
True},
102 assert oct_lint._validate_octrc_schema(cfg) == []
106 monkeypatch.delenv(
"OCT_STRICT_CONFIG", raising=
False)
107 assert not oct_lint._strict_config_requested()
111 monkeypatch.setenv(
"OCT_STRICT_CONFIG",
"1")
112 assert oct_lint._strict_config_requested()
113 monkeypatch.setenv(
"OCT_STRICT_CONFIG",
"true")
114 assert oct_lint._strict_config_requested()
115 monkeypatch.setenv(
"OCT_STRICT_CONFIG",
"0")
116 assert not oct_lint._strict_config_requested()
125 """Well-formed git section passes validation."""
128 "protected_branches": [
"main",
"master"],
129 "branch_naming": {
"enabled":
True,
"patterns": [
r"^main$"]},
130 "pre_commit_profile":
"auto",
131 "conventional_commits":
True,
132 "require_changelog_update":
False,
133 "large_file_warn_mb": 10,
138 assert oct_lint._validate_octrc_schema(cfg) == []
142 errors = oct_lint._validate_octrc_schema({
"git":
"bogus"})
143 assert any(
"'git' must be an object" in e
for e
in errors)
147 errors = oct_lint._validate_octrc_schema(
148 {
"git": {
"protected_branches":
"main"}}
150 assert any(
"'git.protected_branches' must be a list" in e
for e
in errors)
154 errors = oct_lint._validate_octrc_schema(
155 {
"git": {
"branch_naming": {
"enabled":
"yes"}}}
157 assert any(
"'git.branch_naming.enabled' must be a bool" in e
for e
in errors)
161 errors = oct_lint._validate_octrc_schema(
162 {
"git": {
"pre_commit_profile":
"turbo"}}
164 assert any(
"unknown value 'turbo'" in e
for e
in errors)
168 errors = oct_lint._validate_octrc_schema(
169 {
"git": {
"timeout":
"fast"}}
171 assert any(
"'git.timeout' must be a number" in e
for e
in errors)
175 errors = oct_lint._validate_octrc_schema(
176 {
"git": {
"timeout": 0}}
178 assert any(
"'git.timeout' must be > 0" in e
for e
in errors)
test_linter_not_object_rejected()
test_empty_config_accepted()
test_strict_config_requested_env(monkeypatch)
test_strict_config_requested_default(monkeypatch)
test_rules_not_dict_rejected()
test_git_protected_branches_not_list_rejected()
test_rule_value_not_bool_rejected()
test_unknown_profile_rejected()
test_exclude_dirs_add_non_string_element_rejected()
test_git_valid_config_accepted()
test_git_pre_commit_profile_invalid_rejected()
test_complete_valid_config_accepted()
test_git_not_object_rejected()
test_git_branch_naming_enabled_not_bool_rejected()
test_profile_wrong_type_rejected()
test_missing_linter_section_accepted()
test_exclude_dirs_add_wrong_type_rejected()
test_git_timeout_zero_rejected()
test_valid_profile_accepted()
test_git_timeout_not_number_rejected()