fix(bridge): synchronize reconciled login state

Route recovered login state through the hook client before dependent services start. Add regression coverage to keep packet actions available after reconciliation.

Fixes #286.
This commit is contained in:
DrSmoothl committed 2026-07-26 15:53:57 +08:00
1 parent b5e10fefc2
commit d05bbe3551
3 files changed
+71 -5

No files matched your search

+8 -1
View File
@@ -507,7 +507,14 @@ export class HookSession extends EventEmitter {
this.log.info('login reconciled via active probe: PID=%d UIN=%s', this.pid, info.uin);
// isRealUin guarantees a pure non-empty digit string, so BigInt() here
// cannot throw (keep that contract if isRealUin's regex is ever changed).
this.handleLoginState({ loggedIn: true, uin: info.uin, uinNumber: BigInt(info.uin) });
// Reconcile through QqHookClient instead of mutating HookSession alone:
// packet sending and login waiters must observe the same state before
// the login event starts Bridge / OneBot initialization.
this.client!.reconcileLoginState({
loggedIn: true,
uin: info.uin,
uinNumber: BigInt(info.uin),
});
}
} finally {
this.probing = false;
+17 -1
View File
@@ -374,6 +374,19 @@ export class QqHookClient extends EventEmitter {
return { ...this.loginState };
}
/**
* Reconcile a login edge that the native hook could not replay after the
* pipe connected. The client remains the single source of truth so packet
* sending, login waiters, and HookSession all observe the same transition.
*/
reconcileLoginState(state: QqHookLoginState): void {
this.applyLoginState({
loggedIn: state.loggedIn,
uin: state.uin || state.uinNumber.toString(),
uinNumber: state.uinNumber,
});
}
async waitForLogin({ timeoutMs = 0 } = {}): Promise<QqHookLoginState> {
await this.connect();
if (this.loginState.loggedIn) {
@@ -750,8 +763,11 @@ export class QqHookClient extends EventEmitter {
const loggedIn = flaggedLoggedIn || statusLoggedIn;
const uinNumber = BigInt(frame.value0);
const uin = frame.msg || uinNumber.toString();
this.applyLoginState({ loggedIn, uin, uinNumber });
}
private applyLoginState(next: QqHookLoginState): void {
const previous = this.loginState;
const next = { loggedIn, uin, uinNumber };
this.loginState = next;
this.emit('loginState', next);
if (previous.loggedIn !== next.loggedIn || previous.uin !== next.uin) {