Files
lbinyamin a3eeaf58cc fix(webhooks): stop dropping the created webhook and its console link (FORGE-696) (#187)
## What

`cx webhooks create` printed no `Created webhook` line and emitted an
empty list for `-o json` / `-o agents` against every real team. The code
gated on

```rust
if let Some(webhook) = resp.webhook {   // never true
```

expecting a `{"webhook": {...}}` envelope, but the API returns the
created object **bare** (`{"id": "..."}`). The condition was never true,
so the row was silently dropped and no "View in Coralogix" link was ever
tagged — while `list`/`get`/`update`/`delete` on the very same webhook
all worked correctly.

## Why it's a separate PR

This is a pre-existing bug on `master`, not a console-link change. It
originally landed inside #176; per review discussion it's been pulled
out into its own PR so the fix and its verification stand on their own.

It is **stacked on #176** rather than targeting `master`, because the
fix and the `create` console link are one change — the link is
unreachable until the response handling is fixed, and `console_url.rs` /
`tag_console_link_for_profile` only exist on the #176 branch. Splitting
them would mean shipping a link that provably never prints. **Merge #176
first.**

## How

- `create` now returns the raw response, like `get`/`update` always
have, instead of deserializing into a wrapper that doesn't exist.
- `webhook_id_from_response()` accepts the nested and bare shapes, and a
string or numeric id.
- `webhook_name_from_request()` — the response carries only an id, so
the display name comes from the request. That's *not* a flat `name`: the
real outgoing-webhook payload nests it under `data`. Reading it wrong is
what printed `Created webhook '<unnamed>'`, so it gets four unit tests
of its own.

## Verification

Confirmed the bare-response regression test **fails against the pre-fix
code**:

```
test webhooks_create_prints_console_link_with_bare_response ... FAILED
stderr did not contain the console link:
  Reading webhook definition from ...
  Creating webhook...
```

and passes after. Also verified live against `kb-demo` while the fix was
still in #176:

```
$ cx -p kb-demo -o json --yes webhooks create --from-file webhook_create_repro.json
Created webhook 'cx-cli-repro-bug-verify' (ID: 78ea6cf7-eb42-4918-9eb3-bf3878cd05e3) in profile 'kb-demo'.
```

Tests: 8 unit tests, a new create test in `tests/webhooks/main.rs`
(which had **no** create coverage at all), and two console-link tests in
`tests/console_urls/main.rs`. Full suite, `cargo fmt`, and `cargo clippy
--locked -D warnings` all clean.

## Note on the `-o json` shape

`create` now returns `{id, consoleUrl}` rather than the old curated
`{id, name, type, url, created_at}`. That's intentional — it matches
`get`/`update`, and the live create response genuinely only returns
`{id}`, so there is nothing else to curate from.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: cx-saga[bot] <294118815+cx-saga[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-08-16 08:59:33 +00:00
..