Skip to content

Commit db68457

Browse files
docs(k8s-proxy): add Developer Workflow page for branches + CI integration (#859)
* docs(k8s-proxy): add Developer Workflow page for branches + CI integration The K8s Record Replay quickstart shows how to capture traffic and generate tests, but it stops short of how a team actually edits that test data over time. New page walks through the two halves of the day-to-day workflow: - Editing test cases and mocks on a Keploy branch — three entry points (MCP from IDE, dashboard UI, `keploy upload test-set --branch …`) all writing to the same branch overlay; `keploy cloud replay --branch-name …` to validate locally before opening a PR. - Wiring up the CI pipeline — `keploy cloud replay --create-branch ${{ github.head_ref }}` on PR open (with the 4-condition approval gate explained), reviewer approval in the dashboard, and `keploy cloud branch-merge --branch ${{ github.head_ref }}` on PR merge. Full GitHub Actions snippets for both jobs. Slotted into the K8s Proxy sidebar category between "K8s Record Replay" and "DaemonSet & Auto-Replay", since it builds on the record/replay basics and is a natural stepping stone toward the deeper architecture / auto-replay content. Only version-4.0.0 is updated. Signed-off-by: Charan Kamarapu <kamarapucharan@gmail.com> * docs(k8s-proxy): polish dev-workflow page — screenshots, MCP/API split, accurate flags Iterations after first review: - Step 1 "Create a Keploy branch": split into Option A (dashboard, with screenshot) and Option B (MCP `create_branch` tool + underlying `POST /client/v1/apps/{appId}/branches/ci` REST endpoint). Drops the CLI `--create-branch` shortcut from this step — it still appears in the CI snippet later where it's actually needed. - Step 2 "Edit test cases or mocks": added a screenshot of the dashboard recordings page so the dashboard path is concrete. Reworded the MCP paragraph to point readers at the live API docs at api.keploy.io/client/v1/docs (the OpenAPI surface the MCP tools are auto-generated from) instead of an in-repo placeholder. - Step 3 / CI snippets: corrected `--app <app-id>` to `--app <namespace>.<deployment>` on every `keploy cloud replay` example. The cloud-replay handler at pkg/service/cloud/cloud.go:367 rejects anything that isn't ns.dep with no UUID fallback. The branch-merge example keeps `<app-id>` — it really does take a UUID (the GraphQL `mergeBranch` mutation's `appId` argument). - Step 3 (validate locally) + CI replay-on-PR snippet: dropped the redundant `--replay-source latest-release`. latest-release is the default (cmd/enterprise/cli/provider/cmd.go:903); passing it explicitly is a no-op. - CI Step 2 "Approve the test-data diff": added a screenshot of the branch diff + approval page in the dashboard. - Dropped the trailing "see DaemonSet & Auto-Replay" link from the recap — that page is about eBPF capture and auto-replay environments, not the branch overlay / approval gate; the link was misleading. All screenshots loaded via useBaseUrl() so the /docs/ baseUrl is prepended automatically. Live PR preview verified in `npm run dev`. Signed-off-by: Charan Kamarapu <kamarapucharan@gmail.com> * docs(k8s-proxy): apply prettier to dev-workflow page CI prettier action targets this file specifically and rejected on list-indent + code-fence-indent (4-space indented nested items inside list bullets, mostly under the create_branch and upload_recording bullet bodies). prettier --write reflows them to 2-space and removes the corresponding leading spaces on adjacent code fences. No prose change — pure formatting. The Vale doc-linter failures on the same PR are pre-existing on origin/main (all errors are on python-microservices.md lines 2077-2539, which this PR does not touch). Signed-off-by: Charan Kamarapu <kamarapucharan@gmail.com> * docs(k8s-proxy): satisfy Vale (Google.EmDash + Vale.Spelling) on dev-workflow page Two Vale rules in the docs repo's Google style pack flagged the new page on top of the python-microservices noise (which is pre-existing on main and unrelated): - Google.EmDash — Google style writes em dashes with no surrounding spaces (`word—word`, not `word — word`). 16 occurrences on this page replaced via `perl -CSD -pe 's/ \\x{2014} /\\x{2014}/g'`. - Vale.Spelling — "PR's" tripped the spell list. Expanded to "pull request's" on the only occurrence (line 118). No prose change beyond punctuation/spacing; prettier still passes. Signed-off-by: Charan Kamarapu <kamarapucharan@gmail.com> --------- Signed-off-by: Charan Kamarapu <kamarapucharan@gmail.com>
1 parent be6f3ef commit db68457

5 files changed

Lines changed: 215 additions & 0 deletions

File tree

47.7 KB
Loading
67.5 KB
Loading
79.2 KB
Loading
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
---
2+
id: k8s-proxy-developer-workflow
3+
title: Developer Workflow with Keploy Proxy
4+
sidebar_label: Developer Workflow
5+
description: How developers edit Keploy test data on branches, validate locally, and gate pull requests with cloud replay + branch-merge in CI.
6+
tags:
7+
- K8s
8+
- Developer Workflow
9+
- CI/CD
10+
- Branches
11+
keywords:
12+
- Keploy branches
13+
- cloud replay
14+
- branch-merge
15+
- CI approval gate
16+
- MCP
17+
- upload test-set
18+
---
19+
20+
# Developer Workflow with Keploy Proxy
21+
22+
import ProductTier from '@site/src/components/ProductTier';
23+
import useBaseUrl from '@docusaurus/useBaseUrl';
24+
25+
<ProductTier tiers="Enterprise" offerings="Self-Hosted, Dedicated" />
26+
27+
Once recording works in your cluster, the next question is how your team edits test data without stepping on each other and how those edits land in `main` only after review. Keploy mirrors the git workflow: every change to a test case or a mock lives on a **Keploy branch**, a teammate reviews the diff in the dashboard, and CI replays the branch on every pull request before folding it into main on merge.
28+
29+
This page walks through the two halves of that workflow:
30+
31+
1. **Editing test cases and mocks on a branch**—how a developer adds a new mock, edits a test case, or uploads a freshly recorded test set.
32+
2. **Wiring up your CI pipeline**—how to run cloud replay against the branch on PR open, gate the merge on review, and merge the branch into main when the PR merges.
33+
34+
The pipeline section assumes the application is already recording—see [K8s Record Replay](/docs/quickstart/k8s-proxy) to set that up first.
35+
36+
---
37+
38+
## Editing test cases and mocks on a branch
39+
40+
### 1. Create a Keploy branch
41+
42+
Every write—adding a mock, editing a test case, uploading a recording—must happen on a branch. Direct writes to `main` are rejected. The branch name typically mirrors your git branch so reviewers can correlate the two.
43+
44+
There are two ways to create one.
45+
46+
**Option A—From the dashboard.** Open your app → **Branches****Create branch** and enter a name (use your git branch name).
47+
48+
<img src={useBaseUrl('/img/k8s-proxy-create-branch.png')} alt="Create a Keploy branch from the dashboard" width="100%" style={{ borderRadius: '5px' }}/>
49+
50+
**Option B—From the MCP server / REST API.** When you're driving Keploy from an IDE agent (Claude Code, Cursor, Windsurf), the agent calls the `create_branch` MCP tool. The same operation is also exposed as a plain REST endpoint for scripts and other automation.
51+
52+
- **MCP tool**: `create_branch`
53+
54+
```json
55+
{
56+
"app_id": "<keploy-app-uuid>",
57+
"name": "feat/discount-flow"
58+
}
59+
```
60+
61+
Returns `{branch_id, name, status, created}`. Find-or-create: passing a name that already exists on a writable branch reuses it (`created: false`); a fresh name mints a new one (`created: true`). Pass the returned `branch_id` to every subsequent write tool—direct writes to `main` are rejected.
62+
63+
- **REST API** (what the MCP tool calls under the hood):
64+
65+
```bash
66+
curl -X POST "$KEPLOY_API_SERVER/client/v1/apps/<app-id>/branches/ci" \
67+
-H "Authorization: Bearer $KEPLOY_API_KEY" \
68+
-H "Content-Type: application/json" \
69+
-d '{"name": "feat/discount-flow"}'
70+
```
71+
72+
`POST /client/v1/apps/{appId}/branches/ci`—same find-or-create semantics. Returns the branch on success; an existing-but-non-writable name (e.g. already merged) returns `ErrBranchNameTaken`.
73+
74+
### 2. Edit test cases or mocks
75+
76+
There are three ways to add or edit test data on the branch. Pick whichever matches how you're working—they all write to the same branch overlay, so the dashboard diff page sees every change regardless of source.
77+
78+
**From your IDE (MCP):** Keploy ships an MCP server that Claude Code, Cursor, and Windsurf can connect to. The agent exposes tools like `create_mock`, `update_mock`, `delete_mock`, `link_mock`, `upload_recording`, and `delete_recording`. All write tools require a `branch_id` argument; calling them without one is rejected, which is what keeps `main` untouched. The full tool surface is auto-generated from the api-server's `/client/v1` OpenAPI spec—browse it at [api.keploy.io/client/v1/docs](https://api.keploy.io/client/v1/docs) for the underlying REST shape each tool wraps.
79+
80+
**From the dashboard UI:** open the **Recordings** page, switch to your branch in the branch selector, and use the **+** menu to add a mock or edit an existing test case inline. Edits flow through the same branch overlay.
81+
82+
<img src={useBaseUrl('/img/k8s-proxy-dashboard-edit.png')} alt="Edit mocks and test cases from the dashboard" width="100%" style={{ borderRadius: '5px' }}/>
83+
84+
**From the CLI (for whole test sets):** if you just recorded a new flow with `keploy record` on your laptop, upload the resulting `keploy/test-set-N/` directory as a single bundle:
85+
86+
```bash
87+
keploy upload test-set \
88+
--app <namespace>.<deployment> \
89+
--branch $(git rev-parse --abbrev-ref HEAD) \
90+
--test-set keploy/test-set-0 \
91+
--name checkout-happy-path
92+
```
93+
94+
This posts the whole bundle (cases + mocks + mapping) to the JWT-gated `/atg/recordings/bundle` endpoint in one request—much faster than emitting the bundle through MCP tool arguments.
95+
96+
### 3. Validate the branch locally
97+
98+
Before opening a pull request, replay the branch from your machine to make sure the changes you made don't break anything. The CLI accepts `--branch-name` to scope the run to your branch overlay:
99+
100+
```bash
101+
keploy cloud replay \
102+
--app <namespace>.<deployment> \
103+
--branch-name $(git rev-parse --abbrev-ref HEAD)
104+
```
105+
106+
The command fetches the test sets and mocks from the branch view, runs each case against your deployed cluster, and prints pass/fail per suite. If a case fails, fix the mock or case on the branch (step 2) and re-run.
107+
108+
### 4. Open a pull request
109+
110+
Push your code changes to git and open the PR as usual. The Keploy branch with the same name now travels alongside your code change—the CI pipeline picks it up on the next step.
111+
112+
---
113+
114+
## Wiring up your CI pipeline
115+
116+
The pipeline has two jobs:
117+
118+
- **On pull-request open / sync**: run `keploy cloud replay` against the pull request's branch. If the branch has changes that haven't been reviewed, the command exits non-zero and the CI job fails with a dashboard URL the reviewer can open.
119+
- **On pull-request merge**: run `keploy cloud branch-merge` to fold the branch's overlay into `main` so subsequent runs against `main` see the new test data.
120+
121+
The examples below use GitHub Actions; the same two commands work in GitLab CI, Jenkins, or any other runner.
122+
123+
### 1. Replay on PR open
124+
125+
```yaml
126+
# .github/workflows/keploy-replay.yml
127+
name: Keploy Replay
128+
on:
129+
pull_request:
130+
types: [opened, synchronize, reopened]
131+
132+
jobs:
133+
replay:
134+
runs-on: ubuntu-latest
135+
steps:
136+
- uses: actions/checkout@v4
137+
138+
- name: Install Keploy
139+
run: curl -sSL https://keploy.io/install.sh | bash
140+
141+
- name: Replay against the PR branch
142+
env:
143+
KEPLOY_API_KEY: ${{ secrets.KEPLOY_API_KEY }}
144+
run: |
145+
keploy cloud replay \
146+
--app <namespace>.<deployment> \
147+
--create-branch ${{ github.head_ref }}
148+
```
149+
150+
What happens on each PR:
151+
152+
- Keploy looks up (or creates) a branch named after `github.head_ref`—the same name your developer used in step 1.
153+
- It replays every test set on the branch overlay against your deployed cluster.
154+
- After the replay finishes, the **CI approval gate** runs. The gate blocks the job (exit code non-zero) when **all four** are true:
155+
1. The job is running in a CI environment.
156+
2. The branch has diffs against main (added / modified / deleted entities).
157+
3. Some local test set passed, so the replay actually exercised changed data.
158+
4. The branch's `Status` is not yet `approved`.
159+
160+
When the gate blocks, the CLI prints a dashboard URL pointing at the branch's diff page. Without all four conditions, the gate is a no-op and the job's pass/fail is determined by the replay result alone.
161+
162+
### 2. Approve the test-data diff in the dashboard
163+
164+
A reviewer (typically the same person reviewing the code PR) opens the URL the CI job printed. The page shows every changed mock and test case side-by-side—added rows in green, modified rows with inline diff, deleted rows in red.
165+
166+
After confirming the changes look right, the reviewer clicks **Approve**. The branch's status flips to `approved`, the gate stops blocking, and the next CI run on that PR turns green without any other change.
167+
168+
<img src={useBaseUrl('/img/k8s-proxy-branch-diff-approval.png')} alt="Branch diff and approval flow in the dashboard" width="100%" style={{ borderRadius: '5px' }}/>
169+
170+
### 3. Merge the branch on PR merge
171+
172+
On PR merge, run `keploy cloud branch-merge` to fold the branch overlay into `main`. After this step, the branch's recordings and mocks are part of the main view; subsequent replays on `main` (e.g., nightly regression runs) include the changes you just merged.
173+
174+
```yaml
175+
# .github/workflows/keploy-branch-merge.yml
176+
name: Keploy Branch Merge
177+
on:
178+
pull_request:
179+
types: [closed]
180+
181+
jobs:
182+
merge:
183+
if: github.event.pull_request.merged == true
184+
runs-on: ubuntu-latest
185+
steps:
186+
- uses: actions/checkout@v4
187+
188+
- name: Install Keploy
189+
run: curl -sSL https://keploy.io/install.sh | bash
190+
191+
- name: Merge the Keploy branch
192+
env:
193+
KEPLOY_API_KEY: ${{ secrets.KEPLOY_API_KEY }}
194+
run: |
195+
keploy cloud branch-merge \
196+
--app <app-id> \
197+
--branch ${{ github.head_ref }}
198+
```
199+
200+
`keploy cloud branch-merge` is idempotent—running it twice on an already-merged branch is a no-op. If the PR was closed without merging, the `if:` guard above keeps the job from firing.
201+
202+
---
203+
204+
## Putting it together
205+
206+
A typical day with this workflow looks like:
207+
208+
1. A developer cuts a git branch and creates a matching Keploy branch with `--create-branch`.
209+
2. They add or edit mocks and test cases on that branch (from their IDE via MCP, the dashboard, or a CLI upload).
210+
3. They replay the branch locally with `keploy cloud replay --branch-name`, fix anything that broke.
211+
4. They push the code change and open a PR.
212+
5. CI replays the branch and either passes or asks for review via the approval gate.
213+
6. A reviewer approves the test-data diff in the dashboard.
214+
7. On PR merge, CI runs `keploy cloud branch-merge` and the new test data lands on `main`.

versioned_sidebars/version-4.0.0-sidebars.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
"collapsed": true,
149149
"items": [
150150
"quickstart/k8s-proxy",
151+
"quickstart/k8s-proxy-developer-workflow",
151152
"running-keploy/k8s-proxy-daemonset-architecture"
152153
]
153154
},

0 commit comments

Comments
 (0)