Skip to content

Commit a3efa99

Browse files
huacnleecodex
andauthored
feat(longbridge): expand connector actions (#53)
## Summary - Expand Longbridge connector with readonly market, fundamentals, research, screener, and portfolio analysis actions while preserving existing action names. - Add shared Longbridge runtime helpers, lightweight symbol-to-counter-id conversion, and omit unsupported ETF/WT lookup data. - Add provider-local Longbridge OAuth registration/authorization and batch verification fixtures under `src/providers/longbridge/tests`. - Replace keyword `news_search` with symbol-based `news`, and keep IPO endpoints out of this PR. ## Test Plan - `npm run generate:catalog` - `npm test -- src/providers/longbridge/runtime.test.ts src/providers/longbridge/tests/oauth-registration.test.ts` - `npm run fix-check` - Batch verification fixture: `node src/providers/longbridge/tests/verify-actions.ts --runtime-origin http://127.0.0.1:3001 --delay-ms 100` - Full test report: https://wws89t.csb.app/ --------- Co-authored-by: Codex <codex@openai.com>
1 parent 9ecb712 commit a3efa99

13 files changed

Lines changed: 4723 additions & 188 deletions

src/providers/longbridge/README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Longbridge Connector Testing Guide
2+
3+
The Longbridge provider should be verified at two levels:
4+
5+
- Unit tests check action coverage, schemas, endpoint path/query/body mapping, and `symbol` to `counter_id` conversion.
6+
- Integration checks execute `longbridge.*` actions through a local OpenConnector runtime to verify OAuth, runtime envelopes, OpenAPI requests, and response normalization against the real service.
7+
8+
## Local Static Checks
9+
10+
After changing `actions.ts`, `readonly-action-specs.ts`, `runtime.ts`, or verification samples, run:
11+
12+
```sh
13+
npm test -- src/providers/longbridge/runtime.test.ts src/providers/longbridge/tests/oauth-registration.test.ts
14+
npm run generate:catalog
15+
npm run fix-check
16+
```
17+
18+
`runtime.test.ts` verifies that every action has a handler and asserts the HTTP method, path, query, and body mapping for representative endpoints. `generate:catalog` verifies that the Longbridge action schemas can be emitted into the catalog.
19+
20+
## Start A Local Runtime
21+
22+
The default runtime origin is `http://localhost:3000`. The Longbridge OAuth callback URL is:
23+
24+
```text
25+
http://localhost:3000/oauth/callback
26+
```
27+
28+
Start the local runtime:
29+
30+
```sh
31+
OOMOL_CONNECT_ORIGIN="http://localhost:3000" npm run dev
32+
```
33+
34+
If the runtime is configured with an admin token or runtime token, export them in the same shell:
35+
36+
```sh
37+
export OOMOL_CONNECT_ADMIN_TOKEN="<admin-token>"
38+
export OOMOL_CONNECT_RUNTIME_TOKEN="<runtime-token>"
39+
```
40+
41+
`OOMOL_CONNECT_ADMIN_TOKEN` is used by OAuth client configuration and authorization APIs. `OOMOL_CONNECT_RUNTIME_TOKEN` is used by `/v1/actions/*` calls. Leave them unset when the matching runtime auth is disabled.
42+
43+
## Authorize Longbridge OAuth
44+
45+
Longbridge supports dynamic OAuth client registration, so local verification can create a client on demand:
46+
47+
```sh
48+
node src/providers/longbridge/tests/authorize-oauth.ts --runtime-origin http://localhost:3000
49+
```
50+
51+
The script reads the runtime callback URL, creates a Longbridge OAuth client through `/oauth2/register`, stores it in the local runtime, opens the authorization URL, and waits until the Longbridge connection is ready. To print the authorization URL without opening a browser:
52+
53+
```sh
54+
node src/providers/longbridge/tests/authorize-oauth.ts --runtime-origin http://localhost:3000 --no-open
55+
```
56+
57+
## Batch Verify Actions
58+
59+
After authorization completes, run:
60+
61+
```sh
62+
node src/providers/longbridge/tests/verify-actions.ts --runtime-origin http://localhost:3000 --output longbridge-verification-report.json
63+
```
64+
65+
By default, the script verifies only the newly added Longbridge readonly REST actions. Common options:
66+
67+
```sh
68+
# Verify every Longbridge action, including pre-existing account/order/content actions.
69+
node src/providers/longbridge/tests/verify-actions.ts --runtime-origin http://localhost:3000 --include-existing
70+
71+
# Verify only selected actions.
72+
node src/providers/longbridge/tests/verify-actions.ts --runtime-origin http://localhost:3000 --actions dividend,news,screener_search
73+
74+
# Strict mode: exit non-zero when a successful action returns empty normalized output.
75+
node src/providers/longbridge/tests/verify-actions.ts --runtime-origin http://localhost:3000 --fail-on-empty
76+
```
77+
78+
These helper scripts live under `src/providers/longbridge/tests` because they are provider verification fixtures, not public examples. Sample inputs live in `verification-samples.ts`. If an endpoint depends on a real account, order, screener strategy, or currently available upstream data, update the corresponding sample with a valid value before running the integration check.
79+
80+
## Debug A Single Action
81+
82+
Call one action directly through the runtime API:
83+
84+
```sh
85+
curl -s -X POST "http://localhost:3000/v1/actions/longbridge.dividend" \
86+
-H "Content-Type: application/json" \
87+
-H "Authorization: Bearer $OOMOL_CONNECT_RUNTIME_TOKEN" \
88+
-d '{"input":{"symbol":"AAPL.US","page":1,"size":20}}'
89+
```
90+
91+
If runtime token auth is disabled locally, remove the `Authorization` header.
92+
93+
## Interpreting Results
94+
95+
- `OK`: the runtime call succeeded and the normalized output contains non-empty data.
96+
- `EMPTY`: the runtime, OAuth flow, and upstream request succeeded, but the normalized output is empty. Common causes include the selected symbol, date range, market, account state, or current upstream data availability.
97+
- `FAIL`: investigate OAuth authorization, tokens, request parameter mapping, OpenAPI endpoint selection, or response normalization.
98+
99+
When an action returns `EMPTY`, inspect `raw` first to see whether the original Longbridge OpenAPI `data` is empty. If `raw.data` contains data but the normalized output is empty, fix the response mapping in `runtime.ts`. If `raw.data` is empty, update the symbol, date range, or account-related values in `verification-samples.ts`.
100+
101+
The provider converts `symbol` to Longbridge `counter_id` when required. The current converter supports common stock and index symbols only; it does not bundle ETF or WT counter-id lookup data.

0 commit comments

Comments
 (0)