How nihantra-patel/testcase_manager works
1. Top-level shape
- This repository is a Frappe app with a separate Vue 3 single-page frontend under frontend/.
- The backend serves the app at /testcase_manager, and the built frontend is copied into testcase_manager/www/testcase_manager.html plus testcase_manager/public/frontend/ during build.
2. Main domain objects
- The persistent model is centered on three DocTypes:
- Testcase: one discovered test method/spec.
- Testcase Run: one execution record, including status, timing, output, and traceback.
- Testcase Log: summary counts for a run, used for history/listing.
- These are the key persistence boundaries for the whole system.
3. Discovery subsystem
- testcase_manager/testcase_manager/discovery.py performs AST-based discovery of Python tests (test_*.py) across installed apps without importing them.
- ui_discovery.py separately discovers Cypress/UI specs using the app’s test file conventions.
- Discovery is automatically refreshed by hooks after migrations and on a daily scheduler run.
4. API boundary
- api.py exposes the whitelisted server endpoints consumed by the SPA.
- queries.py provides read-side listing/filtering queries for the UI.
- The frontend talks to these endpoints through frontend/src/api.js.
5. Python test execution path
- executor.py runs selected Python tests, typically in-process, and coordinates inline vs background execution depending on scope.
- It is the core execution engine for method/file/doctype/app/batch runs.
- Run lifecycle is managed so results can be persisted after completion.
6. UI/Cypress execution path
- ui_executor.py runs UI tests via bench run-ui-tests in a background job.
- This path is separate from Python execution because it is slower, headless-browser-based, and always run asynchronously.
- It streams output back just like Python runs, so the frontend treats both execution types similarly.
7. Realtime console and run lifecycle
- Execution output is published through Frappe realtime events, especially for live console updates.
- The frontend’s socket.js, useTestRunner.js, and Console.vue form the live subscription/display layer.
- The UI can stop queued or running jobs, and partial output is preserved in the saved run record.
8. Frontend structure
- The SPA is organized around views in frontend/src/pages/:
- RunnerView: discover/filter/select/run tests.
- HistoryView: browse past runs.
- RunDetailView: inspect one saved run.
- ProfilerView: profile document actions.
- router.js handles history-mode navigation inside the single app, while App.vue is the shell.
9. Test-impact analysis
- impact.py statically analyzes the app’s git diff to infer affected tests without running them.
- It uses import-graph relationships plus DocType links to select candidate tests.
- This is an analysis-only subsystem; it feeds the runner with a narrowed batch selection.
10. Document profiling subsystem
- profiling.py profiles a single document’s submit or cancel using cProfile.
- The operation runs inside a database savepoint and is rolled back, so hooks execute and timings are real, but nothing persists.
- This is a distinct non-persistent execution path from test runs.
11. Routing, hosting, and platform hooks
- hooks.py wires the app into Frappe routing, scheduler events, and log-retention behavior.
- website_route_rules maps SPA routes under /testcase_manager/... to the single HTML entrypoint.
- default_log_clearing_doctypes controls retention for run/log records.
12. Build and deployment boundary
- The frontend is built with Vite and packaged into the Frappe app during bench build.
- The root package.json and frontend/package.json split workspace/build concerns from the app runtime.
- GitHub Actions run backend tests, frontend build/lint checks, and separate UI test jobs, but these are CI concerns rather than runtime dependencies.
13. Architecture summary for a diagram
- A good diagram should show:
- Browser SPA → Frappe whitelisted APIs → discovery/execution/profiling services.
- Discovery populating the Testcase table.
- Execution creating/updating Testcase Run and Testcase Log records.
- Realtime events streaming back to the console over websockets.
- Scheduler/migration hooks keeping discovered tests in sync over time.
Main entry points: api.py API · api.js API Client · router.js Router · executor.py Python Executor
Components 23
Frontend SPA
Vue 3 single-page app and browser runtime
- Browser SPA · User-facing single-page test manager
frontend/src/App.vue - Runner · Discover, filter, select, and launch tests
frontend/src/pages/RunnerView.vue - History · Browse prior test runs
frontend/src/pages/HistoryView.vue - Run Detail · Inspect a saved run and its output
frontend/src/pages/RunDetailView.vue - Profiler · Profile document actions from the UI
frontend/src/pages/ProfilerView.vue - Console · Live run output display
frontend/src/components/Console.vue - API Client · SPA calls into whitelisted backend endpoints
frontend/src/api.js - Realtime Socket · Subscribes to live execution events
frontend/src/socket.js - Run Hook · Coordinates run state and output streaming
frontend/src/useTestRunner.js - Router · History-mode navigation for the app
frontend/src/router.js
Frappe Backend
Server-side APIs, services, and hooks
- API · Whitelisted endpoints consumed by the SPA
testcase_manager/testcase_manager/api.py - Queries · Listing and filtering helpers for the UI
testcase_manager/testcase_manager/queries.py - Python Discovery · Finds Python test methods and files without importing apps
testcase_manager/testcase_manager/discovery.py - UI Discovery · Finds Cypress/UI specs using app conventions
testcase_manager/testcase_manager/ui_discovery.py - Python Executor · Executes selected Python tests and manages run lifecycle
testcase_manager/testcase_manager/executor.py - UI Executor · Runs UI tests asynchronously via bench run-ui-tests
testcase_manager/testcase_manager/ui_executor.py - Impact Analysis · Infers affected tests from git diff and import relationships
testcase_manager/testcase_manager/impact.py - Profiling · Profiles document submit/cancel inside a rollback savepoint
testcase_manager/testcase_manager/profiling.py - Hooks · Wires routing, scheduler events, and log retention
testcase_manager/hooks.py - Site Entry · Bench-served entrypoint for the mounted app
testcase_manager/www/testcase_manager.py
Persistence
DocTypes and stored run data
- Testcase · Persistent record for one discovered test
testcase_manager/testcase_manager/doctype/testcase/testcase.json - Testcase Run · Persistent execution record with status, timing, and output
testcase_manager/testcase_manager/doctype/testcase_run/testcase_run.json - Testcase Log · Persistent summary counts for a run
testcase_manager/testcase_manager/doctype/testcase_log/testcase_log.json
Connections 32
- Browser SPA → Router: navigates · SPA routes between runner, history, detail, and profiler views
- Browser SPA → API Client: uses · Frontend issues data and execution requests through a thin client
- Browser SPA → Realtime Socket: subscribes · Browser listens for live run events and console updates
- Router → Runner: loads · Primary test selection and execution screen
- Router → History: loads · Past run listing screen
- Router → Run Detail: loads · Saved run inspection screen
- Router → Profiler: loads · Document profiling screen
- Runner → API Client: requests · Triggers discovery, filtering, and run actions
- History → API Client: requests · Fetches run history and summaries
- Run Detail → API Client: requests · Loads a single run record and related output
- Profiler → API Client: requests · Starts profiling operations and reads results
- API Client → API: calls · SPA consumes whitelisted backend endpoints
- API → Queries: reads via · List and filter endpoints are backed by query helpers
- API → Python Discovery: triggers · Endpoint surface can refresh discovered tests
- API → Python Executor: triggers · Launches Python test execution
- API → UI Executor: triggers · Launches UI test execution jobs
- API → Impact Analysis: uses · Supports narrowed batch selection from repository changes
- API → Profiling: uses · Exposes profiling workflow to the frontend
- API → Realtime Socket: publishes · Run progress is streamed over realtime events
- Realtime Socket → Console: feeds · Console renders live execution output
- Python Executor → Testcase Run: writes · Persists run status, timing, output, and traceback
- Python Executor → Testcase Log: summarizes · Updates run summary counts for history and listing
- Python Executor → Testcase: consumes · Executes selected discovered tests
- UI Executor → Testcase Run: writes · Persists UI execution record and streamed output
- UI Executor → Testcase Log: summarizes · Updates summary counts after UI runs
- UI Discovery → Testcase: populates · Adds UI-discovered test cases to the persistent catalog
- Python Discovery → Testcase: populates · Refreshes discovered Python tests into the catalog
- Hooks → Python Discovery: schedules · Migration and daily scheduler keep discovery in sync
- Hooks → Site Entry: routes · Maps SPA routes to the single HTML entrypoint
- Site Entry → Browser SPA: serves · Bench serves the built SPA from the Frappe app
- Impact Analysis → Python Executor: narrows selection · Feeds a candidate batch into the run engine
- Profiling → Testcase Run: does not persist · Profiles execute in rollback savepoints rather than stored runs