Skip to content

fix(catalogue): assert x-operationId shape and correct malformed ids#10

Merged
phil-accelbyte merged 2 commits into
mainfrom
fix/parser-x-operation-id-overflow
May 12, 2026
Merged

fix(catalogue): assert x-operationId shape and correct malformed ids#10
phil-accelbyte merged 2 commits into
mainfrom
fix/parser-x-operation-id-overflow

Conversation

@phil-accelbyte

Copy link
Copy Markdown
Collaborator

Summary

Hardens the catalogue parser against malformed `x-operationId` values and fixes three real-world malformed ids the new assertion immediately caught. Source: PR #34 on the internal Bitbucket mirror.

Parser hardening

The parser used `splitn(5, '/')` which silently folded any overflow into the final segment. For an id like `basic/public/profiles/update/v1/my-zip-code`, this meant `parts[3] = "update"`; the version parse then failed and the operation was dropped without any signal. The command never appeared on the CLI surface — invisible to Clap, tests, or snapshots because the baseline is generated by the same parser.

Now:

  • `split('/')` and require exactly five segments.
  • `debug_assert!` on both segment-count mismatch and non-numeric version (panic in debug, skip in release).
  • New test pairs cover underflow, overflow, and non-numeric-version cases.

Spec fixes the assertion caught

Service Before After
basic `basic/public/profiles/update/v1/my-zip-code` (6 segments — dropped `update-my-zip-code`) `basic/public/profiles/v1/update-my-zip-code`
social `social/public/stat-cycles/v1/export` on GET `/statCycles/{cycleId}` `social/public/stat-cycles/v1/get` (matches admin variant)
lobby `lobby/public/blocks/v1/symc` (typo) `lobby/public/blocks/v1/sync`

Regenerated `tests/fixtures/baselines/{basic,lobby,social}` and `docs/reference/cli-command-catalogue.md`. Operation count: 1961 → 1962.

Test plan

  • `cargo test --lib` — 479 passed
  • `cargo clippy --all-targets -- -D warnings` — clean
  • Manual: `ags basic profiles --help` now lists `update-my-zip-code`
  • Manual: `ags lobby blocks sync --help` works (was `symc`)
  • Manual: `ags social stat-cycles get --namespace --cycle-id ` works on the public scope (was `export`)

The catalogue parser used `splitn(5, '/')` to break an `x-operationId` into
its five expected segments (service/scope/resource/version/method). When an
id contained six or more slashes — e.g. `basic/public/profiles/update/v1/my-zip-code`
— the overflow was folded into the final segment. The version parse then
failed on the misplaced `"update"`, the operation was dropped without any
signal, and the command never appeared on the CLI surface — invisible to
Clap, tests, or snapshots because the baseline is generated by this same
parser.

Replace `splitn` with `split`, require exactly five segments, and
`debug_assert!` on both the segment-count mismatch and a non-numeric
version. Release builds still skip the bad op so one malformed entry does
not poison the whole service. Adds explicit underflow / overflow /
non-numeric-version test pairs (panic in debug, skip in release).

Also fixes three malformed x-operationIds the new assertion immediately
caught in the bundled specs:

- basic: `…/profiles/update/v1/my-zip-code` → `…/profiles/v1/update-my-zip-code`
  (six segments; this previously dropped the `update-my-zip-code` command)
- social: `/statCycles/{cycleId}` GET was tagged `…/v1/export`; corrected
  to `…/v1/get` to match the admin variant and the actual semantics
- lobby: `…/blocks/v1/symc` → `…/blocks/v1/sync` (typo)

Regenerated tests/fixtures/baselines and docs/reference/cli-command-catalogue.md;
operation count 1961 → 1962.
@phil-accelbyte
phil-accelbyte merged commit a4a1989 into main May 12, 2026
5 checks passed
@phil-accelbyte
phil-accelbyte deleted the fix/parser-x-operation-id-overflow branch May 12, 2026 13:35
@phil-accelbyte phil-accelbyte mentioned this pull request May 12, 2026
3 tasks
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.

1 participant