Kkarthikshet.com
Open source · Developer Tools

TraceGraph AI

Evidence-first prototype that links a GitHub pull request to the UI flows and requirements it affects, using a Neo4j graph built from docs, a Playwright crawl and the PR.

GitHub starsLast commit

Quick start

bash
python -m pip install -e ".[dev]"
python -m playwright install chromium

TraceGraph AI is a narrow, evidence-first prototype for the Testsigma AI Engineer take-home. It builds a Neo4j graph from three real inputs:

  1. an explicitly selected public product document;
  2. a bounded Playwright crawl of an explicitly allowlisted public application; and
  3. a real public GitHub pull request and every file delta returned by GitHub.

It then reports only impact paths that Neo4j can traverse: PR change → changed symbol → observed UI → observed flow → requirement. It does not return fixture flows, fabricate screenshots, or produce an offline “best guess” report.

Current scope and honesty

The prototype deliberately goes deep on provenance, safe collection, and deterministic traversal. It is not a general production crawler.

  • The application URL, document URL, and code repository must describe the same product surface. The historical Saleor storefront/dashboard pairing is not a valid end-to-end evidence chain; select a repository with a public, corresponding UI before recording the final assignment run.
  • Browser crawling defaults to 20 screens, 40 navigations, depth 4, and 300 seconds; server-enforced ceilings are 25 screens, 60 navigations, depth 6, and 600 seconds. A bounded crawl can yield COVERED, PARTIAL, or UNVERIFIED; it never claims ABSENT without a separately recorded exhaustive-coverage certificate.
  • GitHub file counting is authoritative: every file returned by the PR Files API is retained as PRChange evidence. Only parser-supported source extensions (.ts, .tsx, .js, .jsx, .py) are eligible for symbol extraction; templates, lockfiles, and other files remain visible as unmapped review items rather than disappearing from the count.
  • Neo4j is a dedicated active-run index: re-indexing deliberately replaces its TraceGraph nodes, while immutable DOM, screenshot, requirement, PR, report, and manifest artifacts remain on disk. This prevents same-named page nodes from separate runs contaminating a report.
  • Neo4j, Playwright, GitHub, and the selected document are required for a report. A missing dependency returns an error/503; it is not replaced with demo data.

Security model

  • Crawl and document URLs are server-side allowlisted and DNS-resolved; loopback, private, link-local, metadata, and redirect-to-private targets are rejected. In development, the dashboard can explicitly approve the entered public hostname for that single crawl; it does not create a persistent or unrestricted allowlist entry. Production disables this option by default and requires authenticated API access before an operator enables ALLOW_CUSTOM_CRAWL_HOSTS=true.
  • Crawl budgets are server-enforced, navigation is same-domain, and destructive actions are filtered.
  • GitHub accepts only owner/repository and uses the immutable PR head SHA for file retrieval. If GitHub is temporarily unavailable, it may reuse only a previously retrieved, namespaced immutable record for that exact repository and PR; otherwise it fails closed rather than substituting data.
  • Untrusted captured HTML is served as a downloadable text attachment with nosniff; it is never executed under the dashboard origin. Dashboard rendering escapes all crawl/report strings.
  • Cypher is parameterized internally. The exposed explorer accepts a single read-only MATCH … RETURN query and blocks mutation/procedure keywords.
  • Production mode requires API_BEARER_TOKEN for state-changing operations, uses explicit CORS origins, and requires a non-empty Neo4j password. Put the dashboard/API behind your normal authenticated reverse proxy before exposing read endpoints or captured artifacts.

If this repository was ever configured with a real provider key, revoke and rotate that key. .env.example intentionally contains no credentials.

Architecture

TraceGraph is an evidence pipeline, not a free-form agent that guesses an answer. Every run has one selected product surface: a public application, its public documentation, and the matching public repository/PR.

flowchart LR
    Spec[Public specification] --> Sanitize[Safe fetch + sanitise]
    Sanitize --> Extract[LLM requirement extraction]
    Extract --> Req[Requirement evidence]

    App[Allowlisted live application] --> Crawl[Bounded Playwright crawl]
    Crawl --> UI[Pages, DOM, screenshots, UI controls, transitions]

    PR[GitHub PR at immutable head SHA] --> Parse[Source retrieval + parser]
    Parse --> Code[PR changes, code files, symbols]

    Req --> Graph[(Neo4j active-run graph)]
    UI --> Graph
    Code --> Graph

    Graph --> Traverse[Deterministic graph traversal]
    Traverse --> Report[Blast-radius report]
    Report --> Verify[Artifact and path verifier]
    Verify --> QA[Evidence-grounded QA plan]
Component Responsibility Output / failure boundary
Web crawler Validates an allowlisted public URL, runs bounded same-domain Playwright exploration, and persists browser-observed artifacts. Page, UIElement, Transition, DOM, and screenshots. If the browser/crawl fails, there is no substitute crawl evidence.
Specification ingestor Safely fetches or accepts pasted product text, keeps source provenance, and asks an LLM for structured, testable requirement candidates. Requirement records with source evidence and testability. Ambiguous or unavailable source remains UNVERIFIED; requirements are never invented.
Code analyzer Fetches the selected public PR at its immutable head SHA, preserves every GitHub file delta, and extracts symbols from parser-supported source files. PullRequest, PRChange, CodeFile, and CodeSymbol. The report and documentation distinguish total GitHub file changes from parser-supported files and parsed symbols. A temporary GitHub failure can reuse only the exact previously stored PR record; otherwise the run stops.
Mapping + graph builder Creates conservative source-to-UI candidate links and loads all three evidence layers into Neo4j. A single active-run graph; re-indexing replaces graph nodes but keeps immutable disk artifacts and manifests. Weak mappings remain unmapped.
Impact engine Traverses only stored relationships from PR change to UI, flow, and requirement, calculating confidence from hop weights. Deterministic blast radius and raw evidence paths. Missing coverage is reported as a gap, not as zero code change.
Evidence verifier + QA planner Confirms graph-path shape, selected-crawl ownership, DOM/screenshot presence, and observed transitions before creating test candidates. APPROVED, NEEDS_REVIEW, REJECTED, or INSUFFICIENT_EVIDENCE; it never creates a generic fallback test.

The LLM is deliberately bounded. It extracts requirements from a delimited, untrusted document payload. It does not select the PR, crawl the product, create graph edges, calculate confidence, decide blast radius, or promote a claim without evidence. Blast-radius reports use a deterministic renderer over structured graph facts.

Evidence-grounded QA planning

GET /api/agents exposes the authority, tools, deterministic boundary, and human-escalation rule for every pipeline stage. A successful graph build persists the exact crawl_id, repository, PR, revision, and requirement sources it represents. After a report and a completed crawl exist, GET /api/qa-analysis/<pr>?crawl_id=<id> performs a second deterministic verification pass. It rejects a different crawl ID, then checks the exact graph-path shape, that every referenced UI element belongs to the selected crawl, that its page still has both captured DOM and screenshot artifacts, and that a test step corresponds to an observed transition.

The dashboard's QA Intelligence tab renders only those checks. A claim with missing artifacts is REJECTED; a valid path below 0.50 confidence is NEEDS_REVIEW; only a verified path with a browser-observed transition can become an APPROVED test. It never produces a generic fallback checklist, synthetic test case, or ungrounded success state. The sidebar's QA Guidance Assistant is a concise handoff for a QA lead: it lists the observed candidate controls, semantic mappings that need confirmation, changed files with no UI route, and unresolved requirement IDs. It is a deterministic rendering of the selected report, not a chat response or a new source of evidence.

Complete local runbook

Fast path: run the complete local website

After cloning the repository, create .env from .env.example, set a unique NEO4J_PASSWORD plus a real LLM-provider configuration, and then run:

docker compose up -d neo4j
docker compose up -d --build api
docker compose ps

When tracegraph-neo4j is healthy and tracegraph-api is running, open http://localhost:8000. The dashboard, API, and Neo4j are local services; it does not use demo results. To reproduce the reference run, follow steps 4–6 below and use the RealWorld URLs shown there.

1. Prerequisites

Component Required for Notes
Python 3.10+ Host CLI pipeline and tests The CLI owns host Playwright when run outside Docker.
Docker Desktop + Compose Neo4j and local dashboard/API Use Docker Desktop's Linux engine on Windows.
Chromium for Playwright Real browser crawl Installed with python -m playwright install chromium.
One real LLM provider key Requirement extraction OpenAI, Groq, xAI, or Grok-compatible configuration. A mock provider is rejected for an evidence run.
GitHub token (recommended) Public PR retrieval Avoids public API rate limits; scope it read-only.

Choose a public application, product document, and GitHub repository that describe the same product surface. Do not reuse archived report files as a new run's evidence.

2. Configure secrets and allowlists

Create a local environment file. It is gitignored and must never be committed.

cp .env.example .env

Set at least the following values in .env:

Setting Purpose Example shape
NEO4J_PASSWORD Password used by the local Neo4j container Use a unique local secret.
LLM_PROVIDER, provider key, LLM_MODEL Real requirement-extraction provider LLM_PROVIDER=groq plus GROQ_API_KEY=...
ALLOWED_CRAWL_DOMAINS Comma-separated application hosts approved for crawling demo.realworld.show
ALLOWED_DOCUMENT_DOMAINS Comma-separated documentation hosts approved for ingestion github.com,raw.githubusercontent.com
GITHUB_TOKEN Optional read-only token for PR retrieval Leave blank only if public rate limits are acceptable.
TARGET_REPO, TARGET_PR Optional dashboard defaults owner/repository, 123

The crawler validates DNS before navigation and rejects private, loopback, link-local, metadata, and redirect-to-private destinations. Adding a host to an allowlist does not disable those checks.

3. Start local services

Start Neo4j first. -d means detached/background: Compose returns to the shell while the service keeps running.

docker compose up -d neo4j
docker compose ps

The expected state is tracegraph-neo4j with healthy status. Then start the local API/dashboard, which serves the UI on port 8000 and shares the local data/ evidence directory with the host:

docker compose up -d --build api
docker compose ps

Open these local-only services:

URL Purpose
http://localhost:8000 TraceGraph dashboard
http://localhost:8000/api/docs OpenAPI / interactive endpoint docs
http://localhost:7474 Neo4j Browser (bound to loopback only)

Useful diagnostics:

docker compose ps
docker compose logs --tail=100 api
docker compose logs --tail=100 neo4j

To stop local services without deleting evidence or Neo4j data, run docker compose down. Do not add -v unless you intentionally want to delete the local Neo4j volumes.

4. Install host CLI dependencies

Use this when running scripts/run_pipeline.py directly from the host. The dashboard/API container already has its own application dependencies.

python -m pip install -e ".[dev]"
python -m playwright install chromium

5. Run one real end-to-end pipeline

The CLI performs five fail-closed stages: ingest selected specification, crawl the live application, fetch immutable PR code, build Neo4j, and compute the blast radius. It intentionally uses a narrow 5-page/5-action crawl budget for an assignment run. If any stage lacks evidence, it exits without a report.

python scripts/run_pipeline.py \
  --repo OWNER/REPOSITORY \
  --pr 123 \
  --crawl-url https://public-app.example.com/ \
  --spec-url https://docs.example.com/feature

The currently documented, real reference combination is:

  • Application: https://demo.realworld.show/
  • Repository: realworld-apps/angular-realworld-example-app
  • PR: 350
  • Specification: the repository's public README on raw.githubusercontent.com

Use a plain URL in the terminal—not Markdown such as [url](url).

Windows / Docker Desktop

Before using Compose, start Docker Desktop and wait for Engine running. If docker version does not show both Client and Server, it is not ready or is configured for Windows containers rather than Linux containers.

In Windows Command Prompt, the command must be one line because \ is a Bash continuation character:

docker compose up -d neo4j
python scripts/run_pipeline.py --repo realworld-apps/angular-realworld-example-app --pr 350 --crawl-url https://demo.realworld.show/ --spec-url https://raw.githubusercontent.com/realworld-apps/angular-realworld-example-app/main/README.md

In PowerShell, use a backtick for multiline input:

python scripts/run_pipeline.py `
  --repo realworld-apps/angular-realworld-example-app `
  --pr 350 `
  --crawl-url https://demo.realworld.show/ `
  --spec-url https://raw.githubusercontent.com/realworld-apps/angular-realworld-example-app/main/README.md

6. Use the dashboard workflow

  1. Open http://localhost:8000.
  2. In Web Crawler, validate a public target, run a bounded crawl, and inspect the saved screenshots, downloaded DOM snapshots, and transitions.
  3. In Specification, enter either one approved public documentation URL or pasted requirement text, then ingest it. The dashboard never displays a seed requirements table on a first run.
  4. Select the same completed crawl and use Apply to Graph, then build the three-layer graph for the repository and PR.
  5. In Blast Radius, request the provenance-verified report. Changed Files is the total returned by GitHub; parser-supported files and parsed symbols are separate, narrower counts. A template or lockfile is never silently omitted. A graph, completed crawl, public spec, immutable GitHub evidence, and real LLM configuration are all required.
  6. In QA Intelligence, choose the completed crawl used by the report. The evidence verifier checks graph hops, stored DOM/screenshots, and observed transitions before producing reviewer-ready tests.

The dashboard can also be started from the host instead of Compose:

uvicorn app.api.main:app --reload --port 8000

For this host mode, .env must use NEO4J_URI=bolt://localhost:7687. The Compose API uses bolt://neo4j:7687 internally and configures that for you.

7. HTTP API

In development, endpoints are available on the local dashboard/API. In staging or production, operational endpoints require Authorization: Bearer <API_BEARER_TOKEN>. Endpoint schemas and request bodies are available at /api/docs.

Endpoint What it does
GET /api/health Checks API reachability and configured repository/PR defaults.
GET /api/agents, GET /api/agents/{name} Shows the bounded authority and failure behavior of each agent stage.
POST /api/ingest Extracts requirements from approved public documentation or pasted text.
POST /api/crawl/validate-url, POST /api/crawl Validates a target then starts a real browser crawl.
GET /api/crawl/sessions, /api/crawl/{id}/pages, /transitions Lists persisted sessions and captured evidence.
POST /api/crawl/{id}/apply-to-graph Stages exactly one completed crawl for graph construction.
POST /api/analyze-code, POST /api/build-graph Retrieves immutable PR evidence and builds the three-layer graph.
POST /api/analyze-pr/{pr} and GET /api/report/{pr} Creates or reads a provenance-verified blast-radius report.
GET /api/qa-analysis/{pr}?crawl_id={id} Verifies report/crawl evidence and generates only grounded QA cases.
GET /api/graph/nodes, /api/graph/visualize, /api/requirements, /api/flows Reads the active graph and coverage results.
POST /api/graph/query Runs a single guarded read-only Cypher query.

Example read-only checks:

curl http://localhost:8000/api/health
curl http://localhost:8000/api/agents
curl "http://localhost:8000/api/report/350?repo=realworld-apps/angular-realworld-example-app"
curl "http://localhost:8000/api/qa-analysis/350?crawl_id=YOUR_COMPLETED_CRAWL_ID&repo=realworld-apps/angular-realworld-example-app"

8. Evidence output and verification

Each successful run writes immutable, run-specific evidence under data/:

Path Contents
data/artifacts/crawls/<crawl-id>/ Crawl session metadata, full-page screenshots, and DOM snapshots.
data/pr_<normalized-repo>_<pr>_*.jsonl Retrieved immutable PR metadata, changed files, code files, and parsed symbols.
data/requirements.jsonl Requirements from the most recently selected public source.
data/blast_radius_pr_<pr>.json and .md Deterministic graph-traversal report.
data/run_manifests/<run>.json Hashes and provenance references for the exact evidence run.

The reference evidence record is docs/evidence_run_pr_350.md. It documents an actual completed run; rerunning the pipeline creates a new crawl ID and manifest rather than overwriting its provenance.

9. Troubleshooting

Symptom Meaning and resolution
localhost:8000 refused to connect Run docker compose ps, then inspect docker compose logs --tail=100 api. If the API exited with allow_custom_crawl_hosts ... unable to interpret input '', pull the current main branch and run docker compose up -d --build api; blank boolean settings are now handled safely.
dockerDesktopLinuxEngine ... file not found Docker Desktop is stopped. Start it and wait for docker version to show a Server section.
BrowserType.launch: Executable doesn't exist The API image is missing its matching Playwright browser bundle. Pull the latest code, then rebuild/start it with docker compose up -d --build api; do not treat the failed crawl as evidence.
Host ... is not in the configured allowlist Add only the intended public host to ALLOWED_CRAWL_DOMAINS in .env, then re-run the CLI or restart the API. Private and metadata IP protections remain active.
Missing option --repo or --repo is not recognized A Bash \ was pasted into Command Prompt. Use the one-line CMD command above or PowerShell backticks.
Worker required on Vercel Expected: Vercel serverless cannot run a durable Playwright crawl. Use the Docker deployment or a dedicated browser worker.
No report / 409 Treat it as an evidence gate. Check the selected document, completed crawl, Neo4j health, GitHub retrieval, and real LLM configuration; do not substitute output.

Evaluation

Tests exercise parsers, SSRF defenses, API guards, safe failure modes, and deterministic report assembly:

python -m pytest tests -q

Evaluate a generated, provenance-verified JSON report only against a separately human-reviewed JSON file of this form:

{"impacted_requirement_ids": ["REQ-001", "REQ-004"]}
python scripts/run_eval.py --report data/blast_radius_pr_123.json --ground-truth reviewed_truth.json

No hard-coded precision/recall score is claimed by the repository. The evaluation output is meaningful only for the exact captured run and independent human labels.

Graph model

Requirement, Page, UIElement, UserFlow, CodeFile, CodeSymbol, PullRequest, and PRChange are graph nodes. Provenance-bearing relationships include COVERS, IMPLEMENTED_BY, PART_OF, STEP_IN, DEFINED_IN, TOUCHES, MODIFIES, and PART_OF_PR.

Absence is a state, not a missing edge: UNVERIFIED means the bounded crawl did not find evidence; ABSENT is reserved for a future exhaustive-coverage certificate. This prevents “not observed” from being misreported as “not built.”

See the design document for the agent boundaries, schema rationale, confidence handling, evaluation protocol, scope, and next-week priorities.