Skip to content

fix: resolve 13 pre-existing pytest failures - #15

Merged
alexps9 merged 1 commit into
mainfrom
fix/pytest-known-failures
Jul 16, 2026
Merged

fix: resolve 13 pre-existing pytest failures#15
alexps9 merged 1 commit into
mainfrom
fix/pytest-known-failures

Conversation

@alexps9

@alexps9 alexps9 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Background

main had 13 pre-existing pytest failures unrelated to the earlier CI or documentation changes. This PR fixes all 13.

Changes

  • Fixed PolicyRule.matches() so condition_expr is the source of truth when present. This restores correct matching for rules using OR and NOT.
  • Added extract_condition_atoms() to extract condition fields from nested AND/OR/NOT expressions.
  • Changed unsupported legacy DSL features from parse errors to warnings, allowing supported rules in the same file to load.
  • Updated rule loaders to detect JSON by content, including JSON stored in .rules files.
  • Fixed RuntimeManager so weaker review outcomes cannot override stronger decisions such as deny.
  • Synced the client-side PolicyRule schema with the server v3 implementation, preserving TRACE rule fields.
  • Fixed one invalid adapter test assertion and two outdated Chinese assertions in the LLM DSL generator tests.
  • Normalized CLI output paths with as_posix() for Windows compatibility.

Validation

  • pytest: 290 passed, up from 277 passed / 13 failed
  • ruff check: passed for all changed files
  • node --test: 175 passed

Root causes and fixes:

- PolicyRule.matches() ANDed the flattened `conditions` list on top of
  `condition_expr`, breaking any rule using OR/NOT (trace boolean
  conditions, console/legacy DSL rules with OR). `condition_expr` is now
  the sole source of truth when set; `conditions` remains for
  introspection only.
- Added `extract_condition_atoms()` to flatten AND/OR/NOT expressions into
  their referenced field atoms, used by the console DSL parser and the
  legacy `.rules` compat parser to populate `PolicyRule.conditions` for
  introspection (previously only naive top-level AND-split atoms were
  captured).
- `dsl_compat.parse_legacy_rules` treated "unsupported DSL feature" blocks
  (history_arg, exists_path, allowlist.*, etc.) as hard errors, failing
  the whole file even when most rules were valid. Downgraded to warnings
  so tutorial/example `.rules` files load their supported subset.
- `shared.rules.loader.load_rules_file` (and the client-side mirror)
  assumed `.rules`-suffixed files are always legacy DSL text; now sniffs
  for JSON content first so JSON rule lists written to a `.rules` path
  still load.
- RuntimeManager could downgrade an already-won `deny` decision back to
  `human_check` when enqueuing review tickets for non-winning plugin
  outcomes. Escalation now only happens when the current decision is
  actually weaker than the ticket being escalated (rank-based comparison).
- Ported the shared v3 PolicyRule schema (agent_id, condition_expr,
  trace_clause, principal/tool/target views) into the client-side
  agentguard.schemas.policy so client-only rule loading (Guard(policy=...))
  supports TRACE clauses, matching the server-side engine.
- Removed a stray/misplaced assertion in the llamaindex streaming adapter
  test that asserted a tool_invoke event which the test explicitly says
  should never happen (wrap_tools=False), which crashed with
  "coroutine raised StopIteration" via bare next().
- Updated two llm_dsl_generator tests whose Chinese prompt-section
  assertions were stale after the prompt templates were translated to
  English in a prior commit.
- Fixed a Windows-only path-separator artifact in `agentguard check` output
  (Path str uses backslashes on Windows) by printing as_posix().

All 290 tests pass (was 277 passed / 13 failed). No new lint issues in
changed files (ruff clean); node --test unaffected (175 passed).

Co-authored-by: Cursor <cursoragent@cursor.com>
@alexps9
alexps9 requested a review from a team as a code owner July 16, 2026 07:23
@alexps9
alexps9 requested review from lhahah and removed request for a team July 16, 2026 07:23

@alexps9 alexps9 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clean to merge

@alexps9
alexps9 merged commit 3456d4f into main Jul 16, 2026
10 of 11 checks passed
@alexps9
alexps9 deleted the fix/pytest-known-failures branch July 16, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant