Skip to content

fix(tools): ignore method calls in scan_managed_lines and validate block schemas (fixes #3042) - #4320

Open
gorky117-cell wants to merge 2 commits into
limitlessprojects:mainfrom
gorky117-cell:fix/issue-3042-managed-gate-lexical-and-schema-validation
Open

gorky117-cell wants to merge 2 commits into
limitlessprojects:mainfrom
gorky117-cell:fix/issue-3042-managed-gate-lexical-and-schema-validation

Conversation

@gorky117-cell

Copy link
Copy Markdown
Contributor

Summary

Resolves #3042 by fixing three validation and lexical scanning bugs in tools/managed_gate.py:

  1. Ignore Method Invocations in scan_managed_lines:
    re.finditer(r"\bmanaged\s*\(", masked) previously treated . as a non-word character boundary, matching receiver method calls like cfg.managed("x", "other") or self.managed(...). Replaced with r"(?<!\.)\bmanaged\s*\(" so method/field calls are never confused for standalone managed(...) block declarations.

  2. Enforce reason and tickets Schema in audit():
    Previously only validated category in VALID. Now ensures reason is present as a non-empty string and tickets (if present) is a list of non-empty strings. Prevents unhandled KeyError: 'reason' crashes in main() check mode and corrupt writes in --rebaseline.

  3. Validate Entries in baseline["blocks"] in main():
    Enforces that baseline keys strictly follow <file>:<line> format (where <line> is integer digits) and that each value is a dictionary with a non-empty reason and valid category.


Verification & Tests

  • Added 3 unit tests to tools/test_managed_gate.py in ManagedGateTests:
    • test_method_calls_do_not_spoof_managed_block: Verifies cfg.managed(...) and self.managed(...) are ignored while valid managed(...) blocks on line 4 are correctly extracted.
    • test_audit_missing_or_empty_reason_fails_closed: Verifies missing reason, blank reason, and invalid tickets fail closed with exit code 2.
    • test_malformed_baseline_entries_fail_closed: Verifies non-dict baseline entries and malformed keys fail closed with exit code 2.
  • Ran full test suite:
    python tools/test_managed_gate.py ManagedGateTests -> 22 tests, 0 failures, 100% PASS.

Signed-off-by: Gaurav Kumar Singh gauravatwork117@gmail.com

…ock schemas (fixes limitlessprojects#3042)

- Use negative lookbehind in scan_managed_lines to prevent matching
  method/field invocations like cfg.managed(...) as managed blocks.
- In audit(), enforce that reported blocks contain a non-empty reason
  string and that tickets (when present) is a list of strings,
  preventing KeyError in main() and corrupted baseline entries.
- In main(), validate that baseline["blocks"] entries follow the
  '<file>:<line>' key schema and dict value schema with valid reasons.
- Add unit test coverage in test_managed_gate.py verifying all three
  reproducer cases fail closed.

Signed-off-by: Gaurav Kumar Singh <gauravatwork117@gmail.com>
@gorky117-cell
gorky117-cell force-pushed the fix/issue-3042-managed-gate-lexical-and-schema-validation branch from f8626d0 to d93a73b Compare November 10, 2026 23:16
…into fix/issue-3042-managed-gate-lexical-and-schema-validation

Signed-off-by: gauravatwork117 <gauravatwork117@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants