Skip to content

fix(routes): register an empty route location at the controller root - #99

Merged
Upd4ting merged 1 commit into
mainfrom
fix/ant-1393-empty-route-location
Nov 9, 2026
Merged

Upd4ting merged 1 commit into
mainfrom
fix/ant-1393-empty-route-location

Conversation

@Upd4ting

@Upd4ting Upd4ting commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Why

The docs say @Get("") registers the controller root, so Controller("/users") with @Get("") should register /users. It registered /users/, which is what getRegisteredRoutes() and every RouteHandler.location consumer saw.

Fixes #75

What changes

ProcessCallback in src/routes.ts no longer appends / when the route location is empty. The full location is the controller location, and an empty controller location still falls back to /. Every other combination keeps the old join, ${controller.location}/${location ?? key} with repeated slashes collapsed.

The issue asked whether to change the code or the docs. This PR changes the code, because the docs state the intended contract and @antelopejs/api serves both forms the same way. Its registerHandler splits the location on / and drops empty parts, so no served route changes. Only the registered location string does.

flowchart LR
  A["@Get(location)"] --> B{"location ?? key is empty?"}
  B -- yes --> C["controller.location, or / when that is empty"]
  B -- no --> D["controller.location + / + segment"]
  C --> E["collapse repeated slashes"]
  D --> E
  E --> F["RegisterRoute"]
Loading

Proof

src/tests/route-decorators.test.ts gains two cases. The first fails on any implementation that keeps the trailing slash for an empty location. The second fails on one that turns Controller("/") with @Get("") into an empty location.

Before the fix (pnpm exec ajs module test . -f dist/tests/route-decorators.test.js on main's src/routes.ts):

  Route decorators
    1) register an empty location at the controller root, without a trailing slash
    ✔ register an empty location under the root controller at /
    ✔ refuse an accessor, which has no method to register
    ✔ refuse a method of a class that Controller did not create
    ✔ refuse a symbol-keyed method without a location, which has no path segment
    ✔ accept a symbol-keyed method given a location


  5 passing (30ms)
  1 failing

  1) Route decorators
       register an empty location at the controller root, without a trailing slash:

      AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
+ actual - expected

  [
+   '/empty-location/'
-   '/empty-location'
  ]

      + expected - actual

       [
      -  "/empty-location/"
      +  "/empty-location"
       ]

      at Context.<anonymous> (dist/tests/route-decorators.test.js:93:31)
      at process.processImmediate (node:internal/timers:574:21)

After the fix:

  Route decorators
    ✔ register an empty location at the controller root, without a trailing slash
    ✔ register an empty location under the root controller at /
    ✔ refuse an accessor, which has no method to register
    ✔ refuse a method of a class that Controller did not create
    ✔ refuse a symbol-keyed method without a location, which has no path segment
    ✔ accept a symbol-keyed method given a location


  6 passing (16ms)

pnpm run checks: Checks: 9 passed, 0 failed. The full suite includes routing.test.ts, which serves a @Post("") route over HTTP.

@Upd4ting
Upd4ting force-pushed the fix/ant-1393-empty-route-location branch from c0ad2c1 to 2baf300 Compare November 9, 2026 14:53
@Upd4ting
Upd4ting merged commit 66860cf into main Nov 9, 2026
7 checks passed
@Upd4ting
Upd4ting deleted the fix/ant-1393-empty-route-location branch November 9, 2026 16:17
Upd4ting added a commit that referenced this pull request Nov 10, 2026
## Why

The verify-interface skill still listed #75 and
#76 as open known findings. Both are closed. #99 registers `@Get("")` at
the controller root, and #101 refuses `@Connection` on handlers that
never receive a connection. An agent reading the skill learned behaviour
that is no longer true. The `route-locations` journey also stripped one
trailing slash, so it pinned neither form of the root location.

## What changed

- `features/README.md`: the Known findings section is removed. Its table
held only #75 and #76, and its "No journey pins either behaviour" line
went with it.
- `features/routes.md`: the #75 gotcha is removed. The `route-locations`
sub-feature now names the root location it pins.
- `scenarios-second.ts`: `route-locations` compares `r.handler.location`
as registered and drops `.replace(/\/$/, "")`. The expected line already
held `/users` for `@Get("")`, so it now pins the root form exactly.
- `@Connection`: #101 already covers the refusal in the
`injected-values` journey (`connectionOnGet`, listed in
`features/parameter-sources.md`). This PR does not change it.

## Proof

Verify journeys the retired findings pointed at, run on this branch's
packed build:

```text
$ antelopejs-verify journey "$RUN" routes
PASS routes/route-locations (0.0 s)
PASS routes/route-errors (0.0 s)
$ antelopejs-verify journey "$RUN" parameter-sources injected-values
PASS parameter-sources/injected-values (0.0 s)
$ antelopejs-verify journey "$RUN" --plan
PASS smoke/core-calls (0.4 s)
PASS smoke/export-surface (0.0 s)
```

The same `route-locations` journey with `src/routes.ts` set back to the
pre-#99 join (`${controller.location}/${segment}`), a local change that
was not committed:

```text
FAIL routes/route-locations (0.0 s)
    02-run-the-route-locations-scenario: route-locations answers as docs/ states (expected "{\"routes\":[[\"handler\",\"get\",\"/users/listUsers\",\"listUsers\",null],[\"handler\",\"get\",\"/users\",\"root\",null],...
```

With the strip in place, that regression would pass.

`pnpm run checks`:

```text
Checks: 9 passed, 0 failed.
```

```mermaid
flowchart LR
  A["@get(&quot;&quot;) on Controller(&quot;/users&quot;)"] --> B[ProcessCallback]
  B --> C["location /users"]
  C --> D{"route-locations journey"}
  D -- "before: strip one trailing slash" --> E["/users and /users/ both pass"]
  D -- "after: compare as registered" --> F["only /users passes"]
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@Get("") registers the controller location with a trailing slash, but docs say it registers the controller root

1 participant