# How to Run Routing Regression Tests with test-routing.ps1 After Modifying routing.json

> Learn to run routing regression tests using test-routing.ps1 after modifying routing.json. Ensure accurate task-to-skill mappings with quick or full validation.

- Repository: [ZhaoXu/reverse-skill](https://github.com/zhaoxuya520/reverse-skill)
- Tags: how-to-guide
- Published: 2026-08-09

---

**Run `skills/scripts/test-routing.ps1` with the `-Quick` switch for fast iteration, or without it for full validation, after editing [`skills/config/routing.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/skills/config/routing.json) to ensure all task-to-skill mappings remain correct.**

The **reverse-skill** repository depends on [`routing.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/routing.json) as its single source of truth for routing task hints to appropriate skills. Any change to keyword patterns, priority ordering, or route definitions risks breaking existing mappings. The PowerShell script `test-routing.ps1` provides automated regression testing to catch these issues before deployment.

## How test-routing.ps1 Validates Routing Changes

The regression test script follows a four-stage pipeline defined in `skills/scripts/test-routing.ps1`:

1. **Load benchmark** — Reads [`skills/tests/routing-benchmark.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/skills/tests/routing-benchmark.json) (default path at lines 21-24) containing hint-to-expected-route pairs.

2. **Filter mode** — Applies the `-Quick` switch to run only one case per route (lines 40-41), reducing execution time during iterative development.

3. **Execute router** — Invokes `master-route.ps1` for each hint, extracts the `primary` route ID from generated [`route-scope.md`](https://github.com/zhaoxuya520/reverse-skill/blob/main/route-scope.md) (lines 55-58), and compares against expected values.

4. **Report results** — Aggregates outcomes into [`SUMMARY.txt`](https://github.com/zhaoxuya520/reverse-skill/blob/main/SUMMARY.txt) and exits with code **0** for success or **1** for failure (lines 86-94). Detailed failures write to [`failures.txt`](https://github.com/zhaoxuya520/reverse-skill/blob/main/failures.txt) (lines 90-92).

The underlying routing logic in `master-route.ps1` (lines 22-30) reads [`routing.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/routing.json), evaluates keyword matches, scores routes, and selects the primary route based on priority weights defined in the JSON configuration (lines 108-110 of [`routing.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/routing.json)).

## Running the Regression Test: Complete Workflow

Follow this sequence after modifying [`routing.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/routing.json):

| Step | Action | Command |
|:---|:---|:---|
| 1 | Edit configuration | Modify [`skills/config/routing.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/skills/config/routing.json) with your routing changes |
| 2 | Quick validation | `powershell -File skills/scripts/test-routing.ps1 -Quick` |
| 3 | Full validation | `powershell -NoProfile -ExecutionPolicy Bypass -File skills/scripts/test-routing.ps1` |
| 4 | Review results | Open [`SUMMARY.txt`](https://github.com/zhaoxuya520/reverse-skill/blob/main/SUMMARY.txt) in the generated log directory under `%TEMP%` |
| 5 | Fix failures | Adjust [`routing.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/routing.json) and repeat until exit code is `0` |

## PowerShell Commands for Routing Regression Testing

### Standard Full Test

Execute all ~162 benchmark cases to validate complete routing correctness:

```powershell
powershell -NoProfile -ExecutionPolicy Bypass -File skills/scripts/test-routing.ps1

```

### Quick Regression Test

Validate one case per route for rapid iteration during development:

```powershell
powershell -File skills/scripts/test-routing.ps1 -Quick

```

### Custom Benchmark and Logging

Point to alternative test data and specify output location:

```powershell
powershell -File skills/scripts/test-routing.ps1 `
    -Benchmark .\custom-benchmark.json `
    -LogDir C:\Users\Me\reverse-skill-logs

```

## Interpreting Test Output

A successful run produces output similar to:

```

=== test-routing | 162 cases (quick=False) ===
PASS R1 -> decompile APK with jadx apktool smali
PASS R2 -> analyze PE header structure
...
=== ROUTING TEST SUMMARY ===
TOTAL=162
PASS=162
FAIL=0
QUICK=False
LogDir=C:\Users\Me\AppData\Local\Temp\rs-routing-test-20260809-142530
OVERALL: PASS

```

Failed runs show mismatches explicitly:

```

[FAIL] hint='playwright browser automation' expect=R19 got=R3

```

Check [`failures.txt`](https://github.com/zhaoxuya520/reverse-skill/blob/main/failures.txt) in the log directory for complete details on each mismatch.

## Key Source Files in the Routing System

| File | Purpose | Location |
|:---|:---|:---|
| `test-routing.ps1` | Regression test orchestrator | `skills/scripts/test-routing.ps1` |
| `master-route.ps1` | Core routing engine | `skills/scripts/master-route.ps1` |
| [`routing.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/routing.json) | Route definitions and keyword mappings | [`skills/config/routing.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/skills/config/routing.json) |
| [`routing-benchmark.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/routing-benchmark.json) | Test dataset of hint-to-route pairs | [`skills/tests/routing-benchmark.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/skills/tests/routing-benchmark.json) |

## Summary

- **Always run** `test-routing.ps1` after editing [`routing.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/routing.json) to prevent regressions
- **Use `-Quick`** for fast feedback during iterative routing adjustments
- **Check exit codes**: `0` indicates success, `1` signals failures requiring fixes
- **Inspect [`failures.txt`](https://github.com/zhaoxuya520/reverse-skill/blob/main/failures.txt)** in the generated log directory to identify specific hint-to-route mismatches
- **Maintain benchmark parity**: Update [`routing-benchmark.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/routing-benchmark.json) when adding new routes or changing expected behaviors

## Frequently Asked Questions

### What does the `-Quick` parameter do in test-routing.ps1?

The `-Quick` switch filters the benchmark to run only one test case per defined route. According to lines 40-41 of `test-routing.ps1`, this reduces the full ~162-case suite to approximately 20-30 cases, enabling rapid validation during routing configuration iterations.

### Why does test-routing.ps1 exit with code 1?

Exit code 1 indicates at least one routing test failed—meaning the actual route selected by `master-route.ps1` differed from the expected route in [`routing-benchmark.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/routing-benchmark.json). Examine [`failures.txt`](https://github.com/zhaoxuya520/reverse-skill/blob/main/failures.txt) in the generated log directory for specific mismatch details, adjust [`routing.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/routing.json) accordingly, and re-run.

### Can I use a custom benchmark file instead of the default?

Yes. Pass the `-Benchmark` parameter with a path to your alternative JSON file. The benchmark must follow the same schema as [`routing-benchmark.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/routing-benchmark.json): an array of objects with `hint` and `expect` properties. Example: `powershell -File skills/scripts/test-routing.ps1 -Benchmark .\my-tests.json`.

### Where are test results saved?

Results write to a timestamped directory under `%TEMP%` by default (pattern: `rs-routing-test-YYYYMMDD-HHMMSS`). The directory contains [`SUMMARY.txt`](https://github.com/zhaoxuya520/reverse-skill/blob/main/SUMMARY.txt) with aggregate statistics and [`failures.txt`](https://github.com/zhaoxuya520/reverse-skill/blob/main/failures.txt) with detailed error information. Use `-LogDir` to specify an alternative location.