-
Notifications
You must be signed in to change notification settings - Fork 762
MAINT: Frontend core refactor #1753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rlundeen2
wants to merge
46
commits into
microsoft:main
Choose a base branch
from
rlundeen2:users/rlundeen/2026_05_13_frontend_core_refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 38 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
2d8473a
Adding initializer service
rlundeen2 40cfea2
pre-commit
rlundeen2 eebdb4e
Merge remote-tracking branch 'origin/main' into users/rlundeen/2026_0…
rlundeen2 31ecfc7
Merge branch 'main' into users/rlundeen/2026_05_11_scenario_gaps
rlundeen2 351ee5c
pr feedback
rlundeen2 c0d5a08
pr feedback
rlundeen2 bf1f00d
Merge branch 'users/rlundeen/2026_05_11_scenario_gaps' into users/rlu…
rlundeen2 328ce79
adding custom initializers to rest
rlundeen2 798c2e5
style: Optional -> | None, import inspect to top-level
rlundeen2 cbfc4df
Merge remote-tracking branch 'origin/main' into users/rlundeen/2026_0…
rlundeen2 abb3f62
adding content
rlundeen2 a75d767
self review
rlundeen2 69d9c96
self review
rlundeen2 92873dd
Merge branch 'main' into users/rlundeen/2026_05_13_add_initializer
rlundeen2 7926cc4
Refactor printers: extract formatting into lightweight base classes
rlundeen2 30f6151
Consolidate all printers into pyrit/printer/ module
rlundeen2 de61795
Add deprecation warnings for old printer import paths (removed in 0.1…
rlundeen2 837ed3f
Rename concrete printers to *MemoryPrinter, move pyrit internals out …
rlundeen2 788eceb
Refactor markdown printer, delete dead old ABC files
rlundeen2 f5045a0
refactoring frontend
rlundeen2 91a417a
Add missing __all__ to scenario printer deprecation shim
rlundeen2 f31d0d0
Fix type checker errors in from_dict methods and MemoryPrinter types
rlundeen2 86172c9
Fix ruff lint errors: return types, docstrings, noqa
rlundeen2 d117af2
Fix ty type check: make ScenarioResult identifier params optional
rlundeen2 65becc5
pr feedback
rlundeen2 1eeb7a3
pre-commit
rlundeen2 4f29026
fixing test
rlundeen2 70eea64
Merge remote-tracking branch 'origin/main' into users/rlundeen/2026_0…
rlundeen2 89e3202
Merge branch 'users/rlundeen/2026_05_13_printer_refactor' into users/…
rlundeen2 69ccff3
fixing test
rlundeen2 bf32513
self-review
rlundeen2 880feef
Merge branch 'users/rlundeen/2026_05_13_printer_refactor' into users/…
rlundeen2 b5ab93c
Use printer module for scenario results in CLI
rlundeen2 f97ad2f
Show strategy-level progress during scenario runs
rlundeen2 1169f74
Merge branch 'main' into users/rlundeen/2026_05_13_frontend_core_refa…
rlundeen2 e410c4b
pre-commit
rlundeen2 86bc912
Move setup_frontend into lifespan, share CLI helpers via pyrit.common
rlundeen2 c81b04e
main fix
rlundeen2 4b1e380
Merge remote-tracking branch 'origin/main' into users/rlundeen/2026_0…
rlundeen2 2bdaf6b
lint fixes
rlundeen2 8fa7299
MAINT: Fix GUI test failure and add unit test coverage for refactored…
rlundeen2 dfb10a7
MAINT: Restore scenario-declared CLI parameters (pyrit_scan + pyrit_s…
rlundeen2 6123bb0
Address PR review: typed scenario params, persistent shell loop, dock…
rlundeen2 abc2a40
Fix stop_server_on_port port-substring match and verify backend befor…
rlundeen2 2076587
Merge remote-tracking branch 'origin/main' into users/rlundeen/2026_0…
rlundeen2 eb49a5f
Fix SIM115 in frontend/dev.py and ruff-format test layout
rlundeen2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT license. | ||
|
|
||
| """ | ||
| PyRIT Backend CLI - Thin wrapper around uvicorn for the PyRIT backend server. | ||
|
|
||
| All initialization (config loading, memory setup, initializer execution) is | ||
| handled by the FastAPI lifespan in ``pyrit.backend.main``. This CLI simply | ||
| parses host/port/config-file/log-level/reload and starts uvicorn. | ||
|
|
||
| The config file path is forwarded to the app via the ``PYRIT_CONFIG_FILE`` | ||
| environment variable. | ||
| """ | ||
|
|
||
| import logging | ||
| import os | ||
| import sys | ||
| from argparse import ArgumentParser, Namespace, RawDescriptionHelpFormatter | ||
| from pathlib import Path | ||
| from typing import Optional | ||
|
|
||
| from pyrit.common.cli_helpers import CONFIG_FILE_HELP, validate_log_level_argparse | ||
|
|
||
|
|
||
| def parse_args(*, args: Optional[list[str]] = None) -> Namespace: | ||
| """ | ||
| Parse command-line arguments for the PyRIT backend server. | ||
|
|
||
| Returns: | ||
| Namespace: Parsed command-line arguments. | ||
| """ | ||
| parser = ArgumentParser( | ||
| prog="pyrit_backend", | ||
| description="""PyRIT Backend - Run the PyRIT backend API server | ||
|
|
||
| All configuration (database, initializers, env-files, etc.) is read from | ||
| the config file (~/.pyrit/.pyrit_conf by default, or --config-file). | ||
|
|
||
| Examples: | ||
| # Start backend with default settings | ||
| pyrit_backend | ||
|
|
||
| # Start with a custom config file | ||
| pyrit_backend --config-file ./my_config.yaml | ||
|
|
||
| # Start with custom port and host | ||
| pyrit_backend --host 0.0.0.0 --port 8080 | ||
|
|
||
| # Start with auto-reload for development | ||
| pyrit_backend --reload | ||
| """, | ||
| formatter_class=RawDescriptionHelpFormatter, | ||
| ) | ||
|
|
||
| parser.add_argument( | ||
| "--host", | ||
| type=str, | ||
| default="localhost", | ||
| help="Host to bind the server to (default: localhost)", | ||
| ) | ||
|
|
||
| parser.add_argument( | ||
| "--port", | ||
| type=int, | ||
| default=8000, | ||
| help="Port to bind the server to (default: 8000)", | ||
| ) | ||
|
|
||
| parser.add_argument( | ||
| "--config-file", | ||
| type=Path, | ||
| help=CONFIG_FILE_HELP, | ||
| ) | ||
|
|
||
| parser.add_argument( | ||
| "--log-level", | ||
| type=validate_log_level_argparse, | ||
| default="WARNING", | ||
| help="Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) (default: WARNING)", | ||
| ) | ||
|
|
||
| parser.add_argument( | ||
| "--reload", | ||
| action="store_true", | ||
| help="Enable auto-reload for development (watches for file changes)", | ||
| ) | ||
|
|
||
| return parser.parse_args(args) | ||
|
|
||
|
|
||
| def main(*, args: Optional[list[str]] = None) -> int: | ||
| """ | ||
| Start the PyRIT backend server. | ||
|
|
||
| Returns: | ||
| int: Exit code (0 for success, 1 for error). | ||
| """ | ||
| sys.stdout.reconfigure(errors="replace") # type: ignore[ty:unresolved-attribute] | ||
| sys.stderr.reconfigure(errors="replace") # type: ignore[ty:unresolved-attribute] | ||
|
|
||
| try: | ||
| parsed_args = parse_args(args=args) | ||
| except SystemExit as e: | ||
| return e.code if isinstance(e.code, int) else 1 | ||
|
|
||
| # Forward config file to the FastAPI lifespan via env var | ||
| if parsed_args.config_file is not None: | ||
| os.environ["PYRIT_CONFIG_FILE"] = str(parsed_args.config_file) | ||
|
|
||
| try: | ||
| import uvicorn | ||
|
|
||
| uvicorn.run( | ||
| "pyrit.backend.main:app", | ||
| host=parsed_args.host, | ||
| port=parsed_args.port, | ||
| log_level=logging.getLevelName(parsed_args.log_level).lower() | ||
| if isinstance(parsed_args.log_level, int) | ||
| else parsed_args.log_level.lower(), | ||
| reload=parsed_args.reload, | ||
| ) | ||
| return 0 | ||
| except KeyboardInterrupt: | ||
| print("\n🛑 Backend stopped") | ||
| return 0 | ||
| except Exception as e: | ||
| print(f"\nError: {e}") | ||
| return 1 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a plan for this I want to propose; but I think this is okay for this PR