mirror of
https://ghproxy.cflmy.top/https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-11-29 08:39:35 +08:00
fix(adapter-qq): name platform failures, answer clicks, render mentions (#9190)
Three defects found against the live QQ API:
- A refused request lost the platform's own code and message: every 4xx whose body carried no known code became the
status rule's anonymous sentence, so a missing 主动消息 permission (40034105), a spent passive budget (40034128) and
a refused interaction id (40034025) read alike. The client now names both in the error it raises, `classify()` keeps
that sentence for a code the table does not list, and the three verified codes joined the table.
- A click's reply carried the interaction id verbatim, which the message body refuses (only `PUT /interactions/{id}`
takes the bare id): the body now spells `INTERACTION_CREATE:<id>`, and a refusal of that field falls back to one
active send instead of leaving the click dead.
- Neither mode declared `<at>`, so a mention reached the chat as the core fallback's plain `@name` and nobody was
notified. The markdown mode writes QQ's text-chain tag for the `user` and `all` variants; the text mode keeps the
readable fallback, so a mention-bearing message resolves to markdown.
Each fix carries the spec case that pins it and the refreshed markdown goldens. Logged as I14 in vendor/im/README.md.
Fixes #9183
This commit is contained in:
1 parent
7355ddbb7d
commit
dc6a0bfc7e
11 files changed
+191
-16
No files matched your search
Vendored
+3
-1
@@ -16,7 +16,7 @@ The upstream line these packages follow is Satori PR #416 (`feat/v5`, "migrate t
|
||||
|
||||
## Local modifications
|
||||
|
||||
Keep this log exhaustive: every divergence from the Satori pin must be covered by an entry. Each entry has a stable ID; remove an entry when its divergence no longer exists, never renumber or reuse IDs, and give a new entry the next free `I` number (the next is I14). An entry describes the current divergence, its rationale and the constraints a sync must keep, not the history of how it arose. Every change under `vendor/im/**/src` must update this file in the same commit (enforced by `scripts/check-vendor-manifest.sh`).
|
||||
Keep this log exhaustive: every divergence from the Satori pin must be covered by an entry. Each entry has a stable ID; remove an entry when its divergence no longer exists, never renumber or reuse IDs, and give a new entry the next free `I` number (the next is I15). An entry describes the current divergence, its rationale and the constraints a sync must keep, not the history of how it arose. Every change under `vendor/im/**/src` must update this file in the same commit (enforced by `scripts/check-vendor-manifest.sh`).
|
||||
|
||||
- **I1 · Package set and provenance**: five packages come from the Satori pin — `element/`, `core/`, `adapter-lark/`, `adapter-qq/` and `markdown/` — with independently pinned `element`, `http` and `fetch-file` dependencies in the `vendor/` root. Their upstream sources are replaced wholesale (I3–I5, I11, I12) and no upstream IM source is copied verbatim: the platform routes, wire envelopes, protobuf/JSON gateway formats and token endpoints carry over, the rendering pipeline does not. Following PR #416, the protocol module is part of `core/` (`src/protocol.ts`), not a package of its own. Runtime service names, events and `satori:` URLs keep their upstream names. Retire: DSH-owned; permanent unless upstreamed into Satori.
|
||||
|
||||
@@ -44,6 +44,8 @@ Keep this log exhaustive: every divergence from the Satori pin must be covered b
|
||||
|
||||
- **I13 · Core rc.12 compatibility**: `core/src/session.ts` reads `bot.ctx[Context.root]` instead of `bot.ctx.root`. Retire: when `core/` synchronizes against Cordis Core rc.12.
|
||||
|
||||
- **I14 · `adapter-qq/` mentions, interaction ids and platform-named failures**: `<at>` is registered in the `markdown` mode only — the `user` variant writes `<qqbot-at-user id="…" />` (the id stripped to `[A-Za-z0-9_-]`, an id the tag cannot carry renders nothing) and the `all` variant writes `<qqbot-at-everyone />`, because QQ reads those tags only inside a markdown body; `here` and `role` stay undeclared and take the core's readable fallback, so the text mode keeps `@name` and a message carrying a mention resolves to markdown. A click's `event_id` goes out as `INTERACTION_CREATE:<id>` (`eventIdOf`, prefix passed through when the id already carries it), because the gateway reports the interaction as a bare uuid that a message body refuses with `40034025`; a refusal of that field falls back to one active send, which cannot duplicate anything because the refusal published nothing. `QqApi.request` names the platform's own `code` and `message` in the error it raises (`… answered 400 (code 40034105: 主动消息失败, 无权限)`), and `classify` keeps that sentence for a code the table does not list instead of the status rule's anonymous one; `40034105` (permission), `40034128` (invalid) and `40034025` (invalid) joined the table. Covered by `vendor/im/adapter-qq/tests/{api,errors,send,markdown}.spec.ts` and the refreshed markdown goldens. Retire: DSH-owned; permanent unless upstreamed into Satori.
|
||||
|
||||
## Sync procedure
|
||||
|
||||
The upstream is a moving PR line (#416), and there is no copy-over sync because the sources are rewritten. Diff upstream between the pinned commit and the target commit, port each relevant change into the rewritten modules (for `adapter-qq/` see the I12 caveat), keep the I8 contracts intact, update this log and the manifest commit, then re-run `pnpm run rescope-vendor --apply` per root B7 and run the `vendor/im/*/tests` suites plus the `packages/experimental/im*` tests.
|
||||
Vendored
+30
-2
@@ -283,6 +283,29 @@ function codeOf(body: unknown): number | undefined {
|
||||
return typeof code === 'number' ? code : undefined
|
||||
}
|
||||
|
||||
/** The platform's own sentence of an answer body, if it carries one. */
|
||||
function platformMessageOf(body: unknown): string | undefined {
|
||||
const message = (body as { message?: unknown } | undefined)?.message
|
||||
return typeof message === 'string' && message.trim() ? message.trim() : undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* The platform's own code and sentence of an answer body, as the detail a request failure carries.
|
||||
*
|
||||
* The taxonomy names the codes it knows (`errors.ts`), but a code it does not must still reach the operator: dropping
|
||||
* it left `40034105 主动消息失败, 无权限`, `40034128 被动回复时间或者次数超过限制` and `40034025 event_id 无效` behind one
|
||||
* anonymous sentence.
|
||||
*
|
||||
* @param body - decoded answer body.
|
||||
* @returns ` (code 40034105: 主动消息失败, 无权限)`, or `''` when the body names no code.
|
||||
*/
|
||||
function detailOf(body: unknown): string {
|
||||
const code = codeOf(body)
|
||||
if (code === undefined) return ''
|
||||
const message = platformMessageOf(body)
|
||||
return message === undefined ? ` (code ${code})` : ` (code ${code}: ${message})`
|
||||
}
|
||||
|
||||
/** `Retry-After` of an answer in milliseconds (the header is in seconds). */
|
||||
function retryAfterOf(response: Response): number | undefined {
|
||||
const value = Number(response.headers.get('retry-after'))
|
||||
@@ -355,7 +378,7 @@ export class QqApi {
|
||||
const body = parseBody(text)
|
||||
const code = codeOf(body)
|
||||
if (response.status >= 400) {
|
||||
throw new QqApiError(`${method} ${path} answered ${response.status}`, {
|
||||
throw new QqApiError(`${method} ${path} answered ${response.status}${detailOf(body)}`, {
|
||||
code,
|
||||
status: response.status,
|
||||
body,
|
||||
@@ -365,7 +388,12 @@ export class QqApi {
|
||||
// A `code` in a 2xx body is still a failure (audit rejection, quota …) unless the body also carries the
|
||||
// object the route promises (a message `id`).
|
||||
if (code !== undefined && code !== 0 && !(body && typeof body === 'object' && 'id' in body)) {
|
||||
throw new QqApiError(`${method} ${path} answered code ${code}`, { code, status: response.status, body })
|
||||
const message = platformMessageOf(body)
|
||||
throw new QqApiError(`${method} ${path} answered code ${code}${message === undefined ? '' : `: ${message}`}`, {
|
||||
code,
|
||||
status: response.status,
|
||||
body,
|
||||
})
|
||||
}
|
||||
if (expect === 'text') return text as T
|
||||
if (expect === 'none') return undefined as T
|
||||
|
||||
Vendored
+17
-4
@@ -64,8 +64,8 @@ export interface QqErrorRule {
|
||||
}
|
||||
|
||||
/**
|
||||
* Platform error code table. Codes outside this table and the quota range below are classified `invalid`: the platform
|
||||
* rejected the request, but the taxonomy cannot say why.
|
||||
* Platform error code table. Codes outside this table and the quota range below are classified `invalid` and keep the
|
||||
* platform's own sentence (see {@link classify}): the platform rejected the request, and its text says why.
|
||||
*/
|
||||
export const QQ_ERRORS: Readonly<Record<number, QqErrorRule>> = {
|
||||
/** Same `(msg_id, msg_seq)` sent twice. `send.ts` bumps `msg_seq` and retries once. */
|
||||
@@ -96,6 +96,15 @@ export const QQ_ERRORS: Readonly<Record<number, QqErrorRule>> = {
|
||||
22009: { kind: 'rate-limit', message: 'message quota exceeded' },
|
||||
/** 主动消息 frequency limit. */
|
||||
40034100: { kind: 'rate-limit', message: 'active-message frequency limit exceeded' },
|
||||
/**
|
||||
* The chat grants no 主动消息 permission, and the reply could not answer an inbound event: nothing was being
|
||||
* answered, or the passive window of the event it answers is spent.
|
||||
*/
|
||||
40034105: { kind: 'permission', message: 'this chat does not allow active messages' },
|
||||
/** The passive window or the reply budget of the event being answered is spent. */
|
||||
40034128: { kind: 'invalid', message: 'the passive window or reply budget of the answered event is spent' },
|
||||
/** The interaction id this reply answers is not the form the message body takes. */
|
||||
40034025: { kind: 'invalid', message: 'the platform rejected the event id of the answer' },
|
||||
}
|
||||
|
||||
/** Lowest / highest code of the quota family the platform answers with `304…`. */
|
||||
@@ -159,7 +168,8 @@ function isAbort(error: unknown): boolean {
|
||||
* or a 4xx (it definitively rejected the request) and `'unknown'` for a 5xx or a transport failure, whose request
|
||||
* may have reached the platform; a network failure and a 5xx are `retryable`; a cancellation is `fatal` and its
|
||||
* `published` is `'unknown'`, because the request may already have been written and answered — only a `published`
|
||||
* the thrown error itself carries overrides that.
|
||||
* the thrown error itself carries overrides that. A code the table does not list keeps the platform's own sentence,
|
||||
* which the client put into the error, so an unclassified refusal still says what the platform refused.
|
||||
*
|
||||
* @param error - the thrown value.
|
||||
* @returns the classified error; an already classified `PlatformError` passes through.
|
||||
@@ -192,7 +202,10 @@ export function classify(error: unknown): PlatformError {
|
||||
// a 5xx leaves publication unknown unless the caller decided otherwise.
|
||||
init.published = error.published
|
||||
?? (error.code !== undefined || (error.status !== undefined && error.status < 500) ? 'no' : 'unknown')
|
||||
return new PlatformError(kind, fallback?.message ?? error.message, init)
|
||||
// A code the table does not list keeps the platform's own sentence, which the client put into the error
|
||||
// (`… answered 400 (code 40034105: 主动消息失败, 无权限)`); a bare HTTP status takes the status rule's sentence.
|
||||
const message = rule === undefined && error.code !== undefined ? error.message : fallback?.message ?? error.message
|
||||
return new PlatformError(kind, message, init)
|
||||
}
|
||||
|
||||
const response = responseOf(error)
|
||||
|
||||
+22
@@ -72,6 +72,25 @@ function list(el: Element<'ul' | 'ol'>, ctx: RenderContext<QqTypes>): QqNode[] {
|
||||
return out
|
||||
}
|
||||
|
||||
/**
|
||||
* The `<qqbot-at-everyone />` text-chain tag of QQ.
|
||||
*
|
||||
* QQ reads these tags only inside a markdown body (`msg_type: 2`) — a plain text body shows them verbatim — which is
|
||||
* why only this mode declares `<at>`. A message carrying a mention therefore prices the text mode's readable `@name`
|
||||
* fallback and resolves to markdown.
|
||||
*/
|
||||
const MENTION_ALL = '<qqbot-at-everyone />'
|
||||
|
||||
/**
|
||||
* The `<qqbot-at-user>` tag of one person.
|
||||
* @param id - platform user id (the member's `member_openid` in a group).
|
||||
* @returns the tag, or an empty string for an id that names nobody.
|
||||
*/
|
||||
function mentionTagOf(id: string) {
|
||||
const safe = id.replace(/[^A-Za-z0-9_-]/g, '')
|
||||
return safe ? `<qqbot-at-user id="${safe}" />` : ''
|
||||
}
|
||||
|
||||
/** Build the `markdown` mode. */
|
||||
export function createMarkdownMode(settings: QqModeSettings): Mode<QqTypes> {
|
||||
const linkText = (label: string, href: string) => settings.linkPolicy === 'keep'
|
||||
@@ -82,6 +101,9 @@ export function createMarkdownMode(settings: QqModeSettings): Mode<QqTypes> {
|
||||
.register('text', el => escapeMarkdown(el.attrs.content))
|
||||
.register('p', (el, ctx) => block(ctx.render(el.children)))
|
||||
.register('br', () => '\n')
|
||||
.register('at', el => el.attrs.type === 'all' ? MENTION_ALL : mentionTagOf(el.attrs.id ?? ''), {
|
||||
variants: ['user', 'all'],
|
||||
})
|
||||
.register('b', (el, ctx) => wrapInline(ctx.render(el.children), '**', '**'))
|
||||
.register('i', (el, ctx) => wrapInline(ctx.render(el.children), '*', '*'))
|
||||
.register('s', (el, ctx) => wrapInline(ctx.render(el.children), '~~', '~~'))
|
||||
|
||||
Vendored
+43
-3
@@ -18,6 +18,10 @@
|
||||
* only the id is unknown — the failure is reported as `published: 'unknown'` (dsh-im records `uncertain`) instead of
|
||||
* sending a duplicate.
|
||||
*
|
||||
* A click's `event_id` goes out as `INTERACTION_CREATE:<id>` ({@link eventIdOf}): the gateway reports the interaction
|
||||
* as a bare uuid, and a message body carrying that bare id is refused with `40034025`. A refusal of the field itself
|
||||
* falls back to one active send, which cannot duplicate anything because the refusal published nothing.
|
||||
*
|
||||
* Outside the passive window (`target.referrer` absent, window closed, or budget spent) the body simply carries no
|
||||
* passive field: that is a 主动 message, which the platform accepts under its own frequency quota and refuses with
|
||||
* `22009` / `40034100` / `40054002`, classified by `errors.ts`.
|
||||
@@ -52,6 +56,27 @@ export const DELETE_WINDOW_MS = 2 * 60 * 1000
|
||||
/** Platform code of the `(msg_id, msg_seq)` dedupe rejection . */
|
||||
export const DEDUPE_CODE = 40054005
|
||||
|
||||
/**
|
||||
* Prefix the message body's `event_id` carries. The gateway reports the interaction as `d.id` (a bare uuid) and
|
||||
* `PUT /interactions/{id}` takes it verbatim, but a message that answers the click carries
|
||||
* `event_id: INTERACTION_CREATE:<d.id>`: the bare id is refused with `400 40034025 请求参数event_id无效`.
|
||||
*/
|
||||
export const EVENT_ID_PREFIX = 'INTERACTION_CREATE:'
|
||||
|
||||
/** Platform code of an `event_id` the platform will not take as a message body field. */
|
||||
export const INVALID_EVENT_ID_CODE = 40034025
|
||||
|
||||
/**
|
||||
* `event_id` of a click in the form the message body expects.
|
||||
*
|
||||
* @param id - interaction id of `Target.referrer` (`QQReferrer.event_id`).
|
||||
* @returns the id with {@link EVENT_ID_PREFIX}; an id that already carries the prefix passes through, so a referrer
|
||||
* built from a stored body stays usable.
|
||||
*/
|
||||
export function eventIdOf(id: string): string {
|
||||
return id.startsWith(EVENT_ID_PREFIX) ? id : `${EVENT_ID_PREFIX}${id}`
|
||||
}
|
||||
|
||||
/**
|
||||
* `SentPart.kind` of one body: the `msg_type` it was sent with.
|
||||
*
|
||||
@@ -151,7 +176,7 @@ function fillRequest(
|
||||
if (ticket) {
|
||||
if (ticket.field === 'event_id') {
|
||||
// A click is answered with `event_id`; `msg_seq` is only read together with `msg_id`.
|
||||
request.event_id = ticket.key
|
||||
request.event_id = eventIdOf(ticket.key)
|
||||
} else {
|
||||
request.msg_id = ticket.key
|
||||
request.msg_seq = ticket.seq
|
||||
@@ -168,6 +193,11 @@ function isDedupe(error: unknown) {
|
||||
return QqApiError.is(error) && error.code === DEDUPE_CODE
|
||||
}
|
||||
|
||||
/** Whether a failure is the platform refusing the `event_id` carried by the body (see {@link EVENT_ID_PREFIX}). */
|
||||
function isInvalidEventId(error: unknown) {
|
||||
return QqApiError.is(error) && error.code === INVALID_EVENT_ID_CODE
|
||||
}
|
||||
|
||||
/**
|
||||
* The failure of a retried part whose sequence the platform already accepted: the message exists, its id does not.
|
||||
*
|
||||
@@ -205,7 +235,9 @@ export async function sendMessagePayload(
|
||||
const idempotencyKey = partKey(ctx)
|
||||
const referrer = referrerOf(target)
|
||||
let ticket = claim(bot, referrer, idempotencyKey)
|
||||
for (let attempt = 1; ; attempt++) {
|
||||
let dedupeRetried = false
|
||||
let eventIdFellBack = false
|
||||
for (;;) {
|
||||
const request = fillRequest(body, ticket, ctx.quote)
|
||||
try {
|
||||
const answer = await bot.api.sendMessage(address, request, ctx.options.signal)
|
||||
@@ -218,10 +250,18 @@ export async function sendMessagePayload(
|
||||
raw: answer,
|
||||
}
|
||||
} catch (error) {
|
||||
if (!isDedupe(error) || attempt > 1) throw error
|
||||
// A click whose event id the platform refuses falls back to one active send: the refusal published nothing, so the
|
||||
// reply without the passive field cannot duplicate it.
|
||||
if (isInvalidEventId(error) && ticket?.field === 'event_id' && !eventIdFellBack) {
|
||||
eventIdFellBack = true
|
||||
ticket = undefined
|
||||
continue
|
||||
}
|
||||
if (!isDedupe(error) || dedupeRetried) throw error
|
||||
if (ticket?.reused) throw alreadyPublished(bot, ticket, error)
|
||||
const next = claim(bot, referrer, idempotencyKey, true)
|
||||
if (!next) throw error
|
||||
dedupeRetried = true
|
||||
ticket = next
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -170,6 +170,9 @@ describe('QqApi', () => {
|
||||
expect(error.code).toBe(40054010)
|
||||
expect(error.status).toBe(400)
|
||||
expect(error.body).toEqual({ code: 40054010, message: '不允许发送URL' })
|
||||
// The platform's own code and sentence reach the operator, so a refusal the table does not list still says what
|
||||
// was refused.
|
||||
expect(error.message).toBe('POST /v2/groups/G/messages answered 400 (code 40054010: 不允许发送URL)')
|
||||
})
|
||||
|
||||
it('turns a code in a 2xx body into a failure', async () => {
|
||||
@@ -177,6 +180,7 @@ describe('QqApi', () => {
|
||||
const error = await api.sendMessage({ kind: 'group', id: 'G' }, { msg_type: 2 }).catch(error => error)
|
||||
expect(error).toBeInstanceOf(QqApiError)
|
||||
expect(error.code).toBe(40034029)
|
||||
expect(error.message).toBe('POST /v2/groups/G/messages answered code 40034029: keyboard too large')
|
||||
})
|
||||
|
||||
it('accepts a `code: 0` body and an answer the route does not type', async () => {
|
||||
|
||||
+19
@@ -35,6 +35,9 @@ describe('QQ error table', () => {
|
||||
[304004, 'invalid'],
|
||||
[22009, 'rate-limit'],
|
||||
[40034100, 'rate-limit'],
|
||||
[40034105, 'permission'],
|
||||
[40034128, 'invalid'],
|
||||
[40034025, 'invalid'],
|
||||
]
|
||||
|
||||
it.each(table)('classifies %i as %s', (code, kind) => {
|
||||
@@ -61,6 +64,22 @@ describe('QQ error table', () => {
|
||||
expect(error.published).toBe('no')
|
||||
})
|
||||
|
||||
it('keeps the platform sentence for a code the table does not list', () => {
|
||||
// The client put the platform's code and text into the error; an unlisted code must reach the operator with them
|
||||
// instead of behind the anonymous status rule.
|
||||
const sentence = 'POST /v2/groups/G/messages answered 400 (code 40034111: 主动消息失败, 无权限)'
|
||||
const error = classify(new QqApiError(sentence, {
|
||||
code: 40034111,
|
||||
status: 400,
|
||||
body: { code: 40034111, message: '主动消息失败, 无权限' },
|
||||
}))
|
||||
expect(error.kind).toBe('invalid')
|
||||
expect(error.code).toBe(40034111)
|
||||
expect(error.message).toBe(sentence)
|
||||
// A status-only refusal keeps the status rule's own sentence.
|
||||
expect(classify(apiError(undefined, 400)).message).toBe('the platform rejected the request')
|
||||
})
|
||||
|
||||
it('covers every documented code with a non-empty message', () => {
|
||||
for (const [code, rule] of Object.entries(QQ_ERRORS)) {
|
||||
expect(rule.message, code).not.toHaveLength(0)
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
{
|
||||
"msg_type": 2,
|
||||
"markdown": {
|
||||
"content": "@Alice please take a look"
|
||||
"content": "<qqbot-at-user id=\"u-alice\" /> please take a look"
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -60,7 +60,7 @@
|
||||
{
|
||||
"msg_type": 2,
|
||||
"markdown": {
|
||||
"content": "@所有人 build is green again"
|
||||
"content": "<qqbot-at-everyone /> build is green again"
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -595,7 +595,7 @@
|
||||
{
|
||||
"msg_type": 2,
|
||||
"markdown": {
|
||||
"content": "**Everything at once**\n\n— subtitle text\n\nplain **bold***italic*under~~strike~~secret`inline-code`link-text@Alice@所有人@在线成员@Admins#general:party:green-text\nafter the break\n\n# Heading one\n\n## Heading two\n\n**Heading three**\n\n**Heading four**\n\n**Heading five**\n\n**Heading six**\n\n- first item\n- ☑ done task\n- parent item\n - child item\n\n3. third item\n4. fourth item\n\n> quoted line\n>\n> > deeper quote\n\n```ts\nconst answer = 42\n```\n\n***\n\nName: apple\nQty: 3\nsecond paragraph\n\n**▸ More information**\n\nhidden body text\n\n— fine print note\n\n"
|
||||
"content": "**Everything at once**\n\n— subtitle text\n\nplain **bold***italic*under~~strike~~secret`inline-code`link-text<qqbot-at-user id=\"u-alice\" /><qqbot-at-everyone />@在线成员@Admins#general:party:green-text\nafter the break\n\n# Heading one\n\n## Heading two\n\n**Heading three**\n\n**Heading four**\n\n**Heading five**\n\n**Heading six**\n\n- first item\n- ☑ done task\n- parent item\n - child item\n\n3. third item\n4. fourth item\n\n> quoted line\n>\n> > deeper quote\n\n```ts\nconst answer = 42\n```\n\n***\n\nName: apple\nQty: 3\nsecond paragraph\n\n**▸ More information**\n\nhidden body text\n\n— fine print note\n\n"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
+3
-3
@@ -49,7 +49,7 @@
|
||||
{
|
||||
"msg_type": 2,
|
||||
"markdown": {
|
||||
"content": "@Alice please take a look"
|
||||
"content": "<qqbot-at-user id=\"u-alice\" /> please take a look"
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -60,7 +60,7 @@
|
||||
{
|
||||
"msg_type": 2,
|
||||
"markdown": {
|
||||
"content": "@所有人 build is green again"
|
||||
"content": "<qqbot-at-everyone /> build is green again"
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -460,7 +460,7 @@
|
||||
{
|
||||
"msg_type": 2,
|
||||
"markdown": {
|
||||
"content": "**Everything at once**\n\n— subtitle text\n\nplain **bold***italic*under~~strike~~secret`inline-code`link-text@Alice@所有人@在线成员@Admins#general:party:green-text\nafter the break\n\n# Heading one\n\n## Heading two\n\n**Heading three**\n\n**Heading four**\n\n**Heading five**\n\n**Heading six**\n\n- first item\n- ☑ done task\n- parent item\n - child item\n\n3. third item\n4. fourth item\n\n> quoted line\n>\n> > deeper quote\n\n```ts\nconst answer = 42\n```\n\n***\n\nName: apple\nQty: 3\nsecond paragraph\n\n**▸ More information**\n\nhidden body text\n\n— fine print note\n\n"
|
||||
"content": "**Everything at once**\n\n— subtitle text\n\nplain **bold***italic*under~~strike~~secret`inline-code`link-text<qqbot-at-user id=\"u-alice\" /><qqbot-at-everyone />@在线成员@Admins#general:party:green-text\nafter the break\n\n# Heading one\n\n## Heading two\n\n**Heading three**\n\n**Heading four**\n\n**Heading five**\n\n**Heading six**\n\n- first item\n- ☑ done task\n- parent item\n - child item\n\n3. third item\n4. fourth item\n\n> quoted line\n>\n> > deeper quote\n\n```ts\nconst answer = 42\n```\n\n***\n\nName: apple\nQty: 3\nsecond paragraph\n\n**▸ More information**\n\nhidden body text\n\n— fine print note\n\n"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
+17
@@ -51,6 +51,23 @@ describe('QQ markdown mode', () => {
|
||||
].join('\n\n'))])
|
||||
})
|
||||
|
||||
it('renders user and @everyone mentions as the tags QQ notifies from', async () => {
|
||||
// QQ reads `<qqbot-at-user>` and `<qqbot-at-everyone />` only inside a markdown body; the text mode keeps the
|
||||
// readable `@name` fallback, so a message carrying a mention resolves to this mode.
|
||||
const bot = await mountQQ({ markdown: true })
|
||||
const { payloads } = await bot.render(group, [
|
||||
h('p', h('at', { type: 'user', id: 'u-alice', name: 'Alice' }), ' please take a look'),
|
||||
h('p', h('at', { type: 'all', name: '所有人' }), ' build is green again'),
|
||||
// `here` and `role` have no QQ tag: they keep the core's readable fallback.
|
||||
h('p', h('at', { type: 'here', name: '在线成员' })),
|
||||
])
|
||||
expect(payloads).toEqual([markdown([
|
||||
'<qqbot-at-user id="u-alice" /> please take a look',
|
||||
'<qqbot-at-everyone /> build is green again',
|
||||
'@在线成员',
|
||||
].join('\n\n'))])
|
||||
})
|
||||
|
||||
it('renders inline code as a plain span and a code block as a verbatim fence', async () => {
|
||||
const bot = await mountQQ({ markdown: true })
|
||||
const code = 'const a = 1\n\nif (a) {\n b(`x|y`) // #1\n}'
|
||||
|
||||
+30
@@ -13,6 +13,7 @@ import QQBot, {
|
||||
Config,
|
||||
DELETE_WINDOW_MS,
|
||||
deleteSentPart,
|
||||
INVALID_EVENT_ID_CODE,
|
||||
messageKindOf,
|
||||
sendMessagePayload,
|
||||
type QQConfig,
|
||||
@@ -132,6 +133,35 @@ describe('sendMessagePayload — passive replies', () => {
|
||||
expect(calls[0]!.data).toEqual({ msg_type: 0, content: 'pressed', event_id: 'INTERACTION_CREATE:abc' })
|
||||
})
|
||||
|
||||
it('adds the interaction prefix to a click id the gateway reported bare', async () => {
|
||||
// `d.id` of the `INTERACTION_CREATE` frame is a bare uuid and `PUT /interactions/{id}` takes it verbatim, but the
|
||||
// message body refusing it with 40034025 is what a click looked like as a dead button.
|
||||
const { bot, calls } = await mount()
|
||||
const click = clickReferrer('1b13d569-4610-4ab9-bc51-feecc5def6d4')
|
||||
await sendMessagePayload(bot, { msg_type: 0, content: 'pressed' }, { ...group, referrer: click }, context())
|
||||
expect(calls[0]!.data).toEqual({
|
||||
msg_type: 0,
|
||||
content: 'pressed',
|
||||
event_id: 'INTERACTION_CREATE:1b13d569-4610-4ab9-bc51-feecc5def6d4',
|
||||
})
|
||||
})
|
||||
|
||||
it('falls back to one active send when the platform refuses the event id', async () => {
|
||||
const { bot, calls } = await mount((_call, index) => index === 0
|
||||
? { status: 400, body: { code: INVALID_EVENT_ID_CODE, message: '请求参数event_id无效' } }
|
||||
: { body: { id: 'ROBOT1.0_after_fallback' } })
|
||||
const part = await sendMessagePayload(bot, { msg_type: 0, content: 'pressed' }, {
|
||||
...group,
|
||||
referrer: clickReferrer('bare-id'),
|
||||
}, context())
|
||||
// The refusal published nothing, so the reply without the passive field cannot duplicate it.
|
||||
expect(calls.map(call => call.data)).toEqual([
|
||||
{ msg_type: 0, content: 'pressed', event_id: 'INTERACTION_CREATE:bare-id' },
|
||||
{ msg_type: 0, content: 'pressed' },
|
||||
])
|
||||
expect(part.id).toBe('ROBOT1.0_after_fallback')
|
||||
})
|
||||
|
||||
it('strips passive fields a payload must not carry and re-fills them', async () => {
|
||||
const { bot, calls } = await mount()
|
||||
const payload = { msg_type: 0, content: 'x', msg_id: 'STALE', msg_seq: 99, event_id: 'STALE' }
|
||||
|
||||
Reference in new issue
Block a user