Skip to content

Commit 181ba3f

Browse files
committed
Store the new client form test in the generated mirror (#2799)
generate only reads tracked files, so the test's files/ mirror appears once the test is committed; the core/ tree does not equal ds-bot/ + patches without it.
1 parent 5b8d980 commit 181ba3f

8 files changed

Lines changed: 207 additions & 8 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Feishu's app mode drew the App Secret as a bare `.bt-secret-input` — the masked field the Secrets page only ever places inside a bordered `.bt-q-field` wrapper — so it showed as a grey `Paste or type the key` line under the App ID box with no box and no label, and the form read as if only the App ID could be filled in. The connector form now gives every masked credential that same wrapper, so app mode shows an App Secret box beside the App ID box and the webhook field gets the border it was missing too ([#2799](https://github.com/ThinkFlowLab/FlyBot/issues/2799)).

‎core/client.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18645,7 +18645,7 @@ function statusText2(connector) {
1864518645
}
1864618646
function CredentialField({ credential, value, onChange, onEnter, autoFocus }) {
1864718647
const label = t(credential.label);
18648-
if (credential.masked) return (0, import_react39.createElement)(MaskedInput, { value, onChange, onEnter, label, autoFocus });
18648+
if (credential.masked) return (0, import_react39.createElement)("label", { className: "bt-q-field bt-secret-field" }, (0, import_react39.createElement)(MaskedInput, { value, onChange, onEnter, label, autoFocus }));
1864918649
return (0, import_react39.createElement)(
1865018650
"label",
1865118651
{ className: "bt-q-field" },

‎core/src/client/connectors.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ function statusText(connector) {
5252
}
5353

5454
// One credential of the form (#1266): the definition says which fields a mode needs and whether a
55-
// field is masked. A masked one is the same field the Secrets page uses, so it never comes back.
55+
// field is masked. A masked one is the same field the Secrets page uses, so it never comes back; it
56+
// is also drawn like the Secrets page draws it, inside the bordered `.bt-q-field` wrapper its bare
57+
// `.bt-secret-input` needs, or the field shows as a placeholder line and the form reads as the
58+
// unmasked fields only (#2799).
5659
function CredentialField({ credential, value, onChange, onEnter, autoFocus }) {
5760
const label = t(credential.label)
58-
if (credential.masked) return h(MaskedInput, { value, onChange, onEnter, label, autoFocus })
61+
if (credential.masked) return h('label', { className: 'bt-q-field bt-secret-field' }, h(MaskedInput, { value, onChange, onEnter, label, autoFocus }))
5962
return h('label', { className: 'bt-q-field' },
6063
h('input', {
6164
className: 'bt-input', type: 'text', value, 'aria-label': label, placeholder: label, spellCheck: false, autoFocus,
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// #2799: in Feishu's app mode the App Secret is a masked credential. The masked input is the Secrets
2+
// page's bare `.bt-secret-input` — no border, no background — because it only reads as a field
3+
// inside a `.bt-q-field` wrapper. The connector form drew it without one, so the App Secret appeared
4+
// as a grey placeholder line under the App ID box and the form looked like "App ID only".
5+
import assert from 'node:assert/strict'
6+
import { test } from 'node:test'
7+
import { fileURLToPath } from 'node:url'
8+
import { runInNewContext } from 'node:vm'
9+
import { build } from 'esbuild'
10+
import { FEISHU_MODES } from '../src/host/connectors.js'
11+
12+
// The client bundle is built once, as the Settings page loads it, and run with a small React stand-in
13+
// whose hook state is fed per render (the same shape core/test/feishu.test.js uses).
14+
const { outputFiles } = await build({
15+
stdin: {
16+
contents: "export { ConnectorsPage } from './src/client/connectors.js'",
17+
resolveDir: fileURLToPath(new URL('..', import.meta.url)),
18+
},
19+
bundle: true, format: 'cjs', platform: 'browser', write: false, logLevel: 'silent',
20+
external: ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'],
21+
})
22+
const h = (type, props, ...children) => ({ type, props: { ...props, children } })
23+
let states = []
24+
const react = {
25+
createElement: h, Fragment: Symbol('F'), useEffect() {}, useLayoutEffect() {},
26+
useState: v => [states.length > 0 ? states.shift() : (typeof v === 'function' ? v() : v), () => {}],
27+
useMemo: f => f(), useRef: current => ({ current }), useCallback: f => f, useSyncExternalStore: (_s, get) => get(),
28+
}
29+
const browser = { exports: {} }
30+
runInNewContext(outputFiles[0].text, {
31+
module: browser, exports: browser.exports, document: { hidden: false }, navigator: { language: 'en' }, localStorage: { getItem: () => null, setItem() {} },
32+
window: { matchMedia: () => ({ matches: false }) }, setTimeout, clearTimeout,
33+
require: (name) => {
34+
if (name === 'react') return react
35+
if (name === 'react-dom') return { createPortal: node => node }
36+
if (name === '@deepseek-ai/dsh-client-ui-primitives') return {}
37+
throw new Error(`Unexpected platform module ${name}`)
38+
},
39+
})
40+
const { ConnectorsPage } = browser.exports
41+
42+
const expand = (node) => {
43+
if (node === null || node === undefined || typeof node === 'boolean') return null
44+
if (Array.isArray(node)) return node.map(expand)
45+
if (typeof node !== 'object') return node
46+
if (typeof node.type === 'function') return expand(node.type(node.props))
47+
return { ...node, props: { ...node.props, children: expand(node.props.children) } }
48+
}
49+
const all = (node, out = []) => { if (node && typeof node === 'object') { if (Array.isArray(node)) node.forEach(child => all(child, out)); else { out.push(node); all(node.props?.children, out) } } return out }
50+
const text = node => (node === null || node === undefined ? '' : Array.isArray(node) ? node.map(text).join('') : typeof node === 'object' ? text(node.props.children) : String(node))
51+
const holds = (node, target) => node === target || (node && typeof node === 'object' && (Array.isArray(node) ? node.some(child => holds(child, target)) : holds(node.props?.children, target)))
52+
const classes = node => String(node?.props?.className ?? '').split(/\s+/).filter(Boolean)
53+
54+
const actions = { connectorConnect: async () => {}, connectorDisconnect: async () => {}, connectorRetry: async () => {}, connectorSend: async () => {} }
55+
const FEISHU_OFF = { id: 'feishu', name: 'Feishu', state: 'off', kind: 'channel', account: null, mode: null, modes: FEISHU_MODES, allowed: [] }
56+
57+
// ConnectorRow's hook order: form, bots, token, apps, picking, busy, error, message, copyState, mode,
58+
// values. Everything after `mode` is left to its initializer.
59+
const renderForm = (mode, values = {}) => {
60+
states = [true, false, '', [], false, false, null, '', 'idle', mode, values]
61+
const tree = expand(h(ConnectorsPage, { roster: { connectors: [{ ...FEISHU_OFF, mode }], bots: [], self: { memberId: 'me' } }, actions }))
62+
states = []
63+
return tree
64+
}
65+
66+
const fieldWrapperOf = (tree, input) => all(tree).find(node => classes(node).includes('bt-q-field') && holds(node, input))
67+
const connectButton = tree => all(tree).find(node => node.type === 'button' && text(node) === 'Connect')
68+
69+
test('#2799: app mode draws the masked App Secret inside the same bordered field wrapper as the App ID', () => {
70+
const tree = renderForm('app')
71+
const inputs = all(tree).filter(node => node.type === 'input')
72+
assert.deepEqual(inputs.map(node => node.props['aria-label']), ['App ID', 'App Secret'], 'app mode asks for both credentials')
73+
74+
const appId = inputs[0]
75+
const secret = inputs[1]
76+
const idWrapper = fieldWrapperOf(tree, appId)
77+
const secretWrapper = fieldWrapperOf(tree, secret)
78+
assert.ok(idWrapper, 'the App ID sits in a bordered .bt-q-field, as it always has')
79+
assert.ok(secretWrapper, 'the App Secret field has no bordered wrapper: it renders as a bare .bt-secret-input, so the form reads as App ID only')
80+
assert.deepEqual(classes(secretWrapper), ['bt-q-field', 'bt-secret-field'], 'the App Secret uses the same wrapper the Secrets page puts around MaskedInput')
81+
assert.equal(secret.props.placeholder, 'Paste or type the key')
82+
assert.equal(text(secretWrapper), '', 'the label stays the aria-label the field already carries, not a second visible row')
83+
})
84+
85+
test('#2799: the webhook mode is unchanged — one masked field, still wrapped', () => {
86+
const tree = renderForm('webhook')
87+
const inputs = all(tree).filter(node => node.type === 'input')
88+
assert.deepEqual(inputs.map(node => node.props['aria-label']), ['Webhook URL'], 'webhook mode still asks for one credential')
89+
assert.ok(fieldWrapperOf(tree, inputs[0]), 'and that field keeps its bordered wrapper')
90+
})
91+
92+
test('#2799: Connect stays disabled until both app fields have text', () => {
93+
assert.equal(connectButton(renderForm('app', { app_id: 'cli_aa78608ba6f9dbb4' })).props.disabled, true, 'the App ID alone is not enough')
94+
assert.equal(connectButton(renderForm('app', { app_secret: 'app-secret-value' })).props.disabled, true, 'nor is the App Secret alone')
95+
assert.equal(connectButton(renderForm('app', { app_id: 'cli_aa78608ba6f9dbb4', app_secret: 'app-secret-value' })).props.disabled, false, 'both fields filled enable Connect')
96+
})

‎docs/subsystems/core-client.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ Settings → Connectors (`src/client/connectors.js`) lists one row per connector
274274

275275
The Feishu row (#1263) is a **sender** (`kind: 'sender'` from the host, not an id the client knows): the input is labelled **Feishu webhook URL** and its link goes to Feishu's custom-bot page, never to GitHub's token page. Because a sender has no tools there is no **Choose Bots** button and no *On for N Bots* line, and the Bot-settings **Connectors** card skips it (`connectedConnectors` drops `kind === 'sender'`), so no switch is offered that would change nothing. Once it is ready the row carries a text field with **Send**, which is the only caller of `connector-send`; a refused webhook shows **Could not connect: …** with **Try again** beside it.
276276

277-
The same row is the whole act of connecting Feishu (#1266): it draws one row, not two, and the form has a **mode** — **Custom bot webhook** (one masked URL, outbound only, exactly phase 1) or **App (long connection)** (App ID + App Secret, one field per `credential` the definition declares, the App ID not masked because it is not a secret). Connect submits `{ mode, credentials }` through `connectorConnect`, which passes an object body straight to `connector-connect` and keeps the older single `token` body for every other row; the status line names the mode that is live, and **Disconnect** clears both. With `kind: 'channel'` the row offers the same per-Bot **Choose Bots** switch GitHub and Composio have (`connectedConnectors` includes a channel, so `connector-bots.js` lists it; off by default, never for a Bot shared with someone else) — a webhook-only row still shows no switch. App mode also renders **允许的飞书用户**: the refused senders the host reports, each with **Allow** / **Block** (`connector-allow` / `connector-block`), plus a paste-an-`open_id` field for the case where nobody has messaged yet; nobody is allowed until the owner adds them, so connecting the app never lets a stranger spend the owner's tokens.
277+
The same row is the whole act of connecting Feishu (#1266): it draws one row, not two, and the form has a **mode** — **Custom bot webhook** (one masked URL, outbound only, exactly phase 1) or **App (long connection)** (App ID + App Secret, one field per `credential` the definition declares, the App ID not masked because it is not a secret). Connect submits `{ mode, credentials }` through `connectorConnect`, which passes an object body straight to `connector-connect` and keeps the older single `token` body for every other row; the status line names the mode that is live, and **Disconnect** clears both. A masked credential is drawn the way the Secrets page draws one — inside the bordered `.bt-q-field` wrapper its bare `.bt-secret-input` needs — so app mode shows an App Secret box beside the App ID box rather than a grey placeholder line that read as App ID only (#2799). With `kind: 'channel'` the row offers the same per-Bot **Choose Bots** switch GitHub and Composio have (`connectedConnectors` includes a channel, so `connector-bots.js` lists it; off by default, never for a Bot shared with someone else) — a webhook-only row still shows no switch. App mode also renders **允许的飞书用户**: the refused senders the host reports, each with **Allow** / **Block** (`connector-allow` / `connector-block`), plus a paste-an-`open_id` field for the case where nobody has messaged yet; nobody is allowed until the owner adds them, so connecting the app never lets a stranger spend the owner's tokens.
278278

279279
A row in the `error` state offers **Copy error** beside **Try again** (#2027): it hands the connector's stored `error` — up to the 2,000-character host window from [core-host](core-host.md) — to the shared `copiedToClipboard()`, reads **Copied** only when the write landed and **Could not copy the error** when the page has no clipboard or the write was refused, and is drawn only while the connector is in that state, so a `ready`/`off` row's actions are unchanged. Tests: `core/test/connectors-page.test.js`.
280280

‎patches/ds-bot/0001-core-fixes.patch‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ diff --git a/src/client/browser-pane.js b/src/client/browser-pane.js
229229
diff --git a/src/client/connectors.js b/src/client/connectors.js
230230
--- a/src/client/connectors.js
231231
+++ b/src/client/connectors.js
232-
@@ -1,41 +1,230 @@
232+
@@ -1,41 +1,233 @@
233233
-import { createElement as h, useRef, useState } from 'react'
234234
+import { createElement as h, useCallback, useEffect, useRef, useState } from 'react'
235235
import { useMorph } from './motion.js'
@@ -288,10 +288,13 @@ diff --git a/src/client/connectors.js b/src/client/connectors.js
288288

289289
-function ConnectorRow({ connector, actions }) {
290290
+// One credential of the form (#1266): the definition says which fields a mode needs and whether a
291-
+// field is masked. A masked one is the same field the Secrets page uses, so it never comes back.
291+
+// field is masked. A masked one is the same field the Secrets page uses, so it never comes back; it
292+
+// is also drawn like the Secrets page draws it, inside the bordered `.bt-q-field` wrapper its bare
293+
+// `.bt-secret-input` needs, or the field shows as a placeholder line and the form reads as the
294+
+// unmasked fields only (#2799).
292295
+function CredentialField({ credential, value, onChange, onEnter, autoFocus }) {
293296
+ const label = t(credential.label)
294-
+ if (credential.masked) return h(MaskedInput, { value, onChange, onEnter, label, autoFocus })
297+
+ if (credential.masked) return h('label', { className: 'bt-q-field bt-secret-field' }, h(MaskedInput, { value, onChange, onEnter, label, autoFocus }))
295298
+ return h('label', { className: 'bt-q-field' },
296299
+ h('input', {
297300
+ className: 'bt-input', type: 'text', value, 'aria-label': label, placeholder: label, spellCheck: false, autoFocus,

‎patches/ds-bot/0008-client-bundle.patch‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22651,7 +22651,7 @@ diff --git a/client.js b/client.js
2265122651
- const [error, setError] = (0, import_react25.useState)(null);
2265222652
+function CredentialField({ credential, value, onChange, onEnter, autoFocus }) {
2265322653
+ const label = t(credential.label);
22654-
+ if (credential.masked) return (0, import_react39.createElement)(MaskedInput, { value, onChange, onEnter, label, autoFocus });
22654+
+ if (credential.masked) return (0, import_react39.createElement)("label", { className: "bt-q-field bt-secret-field" }, (0, import_react39.createElement)(MaskedInput, { value, onChange, onEnter, label, autoFocus }));
2265522655
+ return (0, import_react39.createElement)(
2265622656
+ "label",
2265722657
+ { className: "bt-q-field" },

0 commit comments

Comments
 (0)