Skip to content

Commit def620e

Browse files
committed
Treat missing strategy switch KV sync as skipped
1 parent 129c0c9 commit def620e

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

tests/strategy_switch_worker_validation.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,41 @@ assert.deepEqual(accountOptions.longbridge[1].supported_domains, ["us_equity", "
221221
assert.deepEqual(accountOptions.ibkr[0].supported_domains, ["us_equity", "hk_equity"]);
222222
assert.equal(accountOptions.longbridge[0].cash_currency, "HKD");
223223

224+
const kvUnboundSyncResponse = await worker.fetch(
225+
new Request("https://switch.example/api/internal/sync-account-default", {
226+
method: "POST",
227+
headers: {
228+
Authorization: "Bearer test-sync-token",
229+
"Content-Type": "application/json",
230+
},
231+
body: JSON.stringify({
232+
platform: "ibkr",
233+
target_name: "ibkr-primary",
234+
account_selector: "DEMO_IBKR_PRIMARY",
235+
deployment_selector: "demo-ibkr-tqqq",
236+
account_scope: "demo-ibkr-tqqq",
237+
service_name: "interactive-brokers-demo-ibkr-tqqq-service",
238+
strategy_profile: "tqqq_growth_income",
239+
execution_mode: "live",
240+
variable_scope: "default",
241+
plugin_mode: "auto",
242+
}),
243+
}),
244+
{
245+
STRATEGY_SWITCH_SYNC_TOKEN: "test-sync-token",
246+
STRATEGY_SWITCH_ACCOUNT_OPTIONS_JSON: JSON.stringify(accountOptions),
247+
STRATEGY_SWITCH_STRATEGY_PROFILES_JSON: JSON.stringify(strategyProfiles),
248+
},
249+
);
250+
assert.equal(kvUnboundSyncResponse.status, 200);
251+
const kvUnboundSyncBody = await kvUnboundSyncResponse.json();
252+
assert.equal(kvUnboundSyncBody.ok, true);
253+
assert.deepEqual(kvUnboundSyncBody.account_options_sync, {
254+
synced: false,
255+
reason: "kv_not_bound",
256+
skipped: true,
257+
});
258+
224259
const normalizedReservedCashInputs = __test.normalizeSwitchInputs({
225260
platform: "ibkr",
226261
target_name: "ibkr-primary",

web/strategy-switch-console/worker.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,12 @@ async function syncAccountDefaultResponse(request, env) {
740740
const result = await syncDefaultStrategyForAccount(env, accountConfig.options, inputs, {
741741
login: "github-actions",
742742
});
743-
return json({ ok: result.synced, account_options_sync: result }, result.synced ? 200 : 500);
743+
const kvSyncSkipped = result.reason === "kv_not_bound";
744+
const accountOptionsSync = kvSyncSkipped ? { ...result, skipped: true } : result;
745+
return json(
746+
{ ok: result.synced || kvSyncSkipped, account_options_sync: accountOptionsSync },
747+
result.synced || kvSyncSkipped ? 200 : 500,
748+
);
744749
}
745750

746751
function requireInternalSyncToken(request, env) {

0 commit comments

Comments
 (0)