Skip to content

refactor(drogon): share token grant response presentation - #346

Merged
voidvec merged 1 commit into
masterfrom
refactor/token-grant-response-s08
Nov 19, 2026
Merged

voidvec merged 1 commit into
masterfrom
refactor/token-grant-response-s08

Conversation

@voidvec

@voidvec voidvec commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Summary

Authorization-code and refresh-token completion callbacks duplicated JSON/status/header and metrics presentation. Extract that responsibility into a private synchronous adapter with explicit IMetrics, while keeping the original callbacks and authentication/rotation/storage orchestration in place.

The adapter preserves full JSON (including extensions), catalog status mapping, direct-result error headers, status-valued counters and the authorization-code-only success gauge. It does not change public headers, API/SDK contracts or other grants.

Type of change

  • Internal refactor (behavior preserving)

Validation

  • Added real HTTP characterization before extraction: authorization code and refresh success/direct invalid_grant, plus the Basic invalid_client entry counterexample. The same source/config passed 78 assertions before and after extraction, with no credential POST retry.
  • Complete PostgreSQL/Redis-backed main binary: before 747 cases / 62,424 assertions; after 747 cases / 62,452 assertions. Existing broker-profile CSP assertions remain outside this test wiring.
  • All five library binaries: 535 tests passed, including six new response/FakeMetrics tests and actual Int64/extension serialization.
  • EndpointTests_OutOfProcess passed without skip; scripts reported zero failures (62 OAuth cases, 61 admin cases). The existing OAuth summary displays 62/63 because its declared total is one too high.
  • Release/C++17/WERROR build; six repository gates, architecture/macro/manage parity, API/SDK drift passed.
  • Both SPA unit/build passed (52 unit tests); relevant mock E2E: user 63, admin 17. UI sync and bundle-size gates passed. Frontend sources are unchanged.

Independent design and implementation review completed locally. This is the first S08 refactoring slice; client-credentials/device payload extraction and Session responsibility work remain separate batches. S07 formal capacity testing remains blocked by persistent disk space; these functional results do not establish capacity. No merge or deployment is included.

Checklist

  • Tests added; complete backend suite and scoped frontend regression passed locally (details above).
  • CHANGELOG entry added.
  • Public documentation changes: N/A; no public behavior or SDK contract change.
  • API surface checklist: N/A; adapter header is private and not installed. Existing API/SDK drift checks passed.
  • Release/version checklist: N/A; no version bump, release or capacity acceptance.

@voidvec

voidvec commented Nov 17, 2026

Copy link
Copy Markdown
Owner Author

必须处理项

评审基于 2d0e2fa9a3a982c420f3a97abef12c0bc2359d58。

本轮未发现需要阻断合并的新增缺陷。

逐分支对照原回调与新 helper:完整 JSON/扩展字段、错误状态映射、成功 no-store/pragma、直接 grant 错误与入口认证错误的头部差异、以状态值递增的旧 counter,以及仅授权码成功时更新 gauge 的行为均保留。helper 同步返回,回调所有权仍在原位置,没有引入异步捕获或 token/事务编排变化。源码自动收集和私有头非安装边界也已核对。

当前 head 的三平台、ASan+UBSan、SDK smoke 均成功;单元测试覆盖 Int64 序列化、扩展字段、缺省 metrics、异常/空 error 成员,HTTP 测试覆盖真实授权码与 refresh 流程。HTTP 用例在 PostgreSQL 不可用时返回,因此不把所有平台 CI 成功解读为都执行了真实 PostgreSQL 链路。本轮未本地重编;严格 coverage gate/nightly TSan 未运行。

@voidvec

voidvec commented Nov 17, 2026

Copy link
Copy Markdown
Owner Author

建议处理项

评审基于 2d0e2fa9a3a982c420f3a97abef12c0bc2359d58。

暂无独立、可执行的非阻断问题需要追加。现有单元测试与 HTTP characterization 已覆盖本次抽取的主要差异;不建议为这次行为保持型重构顺带改变旧 metrics 语义、统一两类错误响应头,或扩大到其他 grant,这些会改变已明确冻结的行为范围。

@voidvec

voidvec commented Nov 19, 2026

Copy link
Copy Markdown
Owner Author

Deep review follow-up: P2 (Minor) findings

Full behavior-parity and architecture review of 42eb5928..e78b384d completed: no P0/P1 issues. JSON/status/header/metrics presentation verified byte-equivalent before/after (including extensions fidelity, ErrorCatalog mapping, direct-error header semantics, status-valued counters, auth-code-only gauge); adapter layering compliant, private header not installed, both new test files genuinely registered in ctest. CI green.

Four P2 items remain — none blocks merging; all tracked in #359:

  1. Duplicated no-store header logic. TokenGrantResponse.cc:43-44 inlines Cache-Control: no-store / Pragma: no-cache instead of reusing TokenEndpointController::applyNoStoreHeaders (still used by 6 other call sites), and drops the F-019 audit comment. Byte-identical today, but the two implementations can silently drift if the helper evolves. Suggest sinking the logic into a shared detail helper, or at minimum restoring the F-019 comment with a cross-reference.
  2. Silent skip in the characterization test. tests/integration/token/TokenGrantResponseContractTest.cc:34-35 returns with zero assertions and no log when Postgres is unavailable, deviating from the repo convention (CHECK(true); return; + skip log, cf. UpstreamProviderAdminHttpTest.cc:70-74). Memory-only runs silently lose this coverage.
  3. Boundary coverage gaps (pre-existing pass-through behavior, not regressions): non-string error member (asString() throws Json::LogicError, TokenGrantResponse.cc:18), expires_in 0/negative and empty scope pass-through, HTTP-layer metrics deltas (only FakeMetrics unit assertions today), and rotation-failure/storage-failure branches at the HTTP layer.
  4. oauth2_active_tokens gauge semantics (pre-existing, not introduced here). Every auth-code success sets the gauge to a constant 1.0 (TokenGrantResponse.cc:41); since 55b9533 exported gauges through PromExporter this misleading value is externally visible. This PR correctly preserved the existing semantics; the semantics itself needs a decision — tracked in tracking: PR #346 review follow-ups (token grant response presentation) #359.

Verdict: mergeable; P2 cleanup can land as follow-ups per #359.

Extract authorization-code and refresh-token HTTP result presentation
into a private synchronous adapter with explicit metrics. Preserve JSON,
status/header differences and grant-specific metric behavior while
retaining the original callbacks and authentication/storage flows.

Protect the extraction with real HTTP characterization executed before
and after refactoring, plus response and FakeMetrics unit coverage.
@voidvec
voidvec force-pushed the refactor/token-grant-response-s08 branch from e78b384 to 70e9038 Compare November 19, 2026 05:15
@voidvec
voidvec marked this pull request as ready for review November 19, 2026 05:15
@voidvec
voidvec merged commit 9c682c2 into master Nov 19, 2026
12 checks passed
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-19T05:15:15.287901Z
We couldn’t complete this review. Comment @codex review to try again.
70e9038 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

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.

2 participants