feat(logging): complete runtime trace diagnostics
Complete byte-level diagnostics for network, upload, runtime lifecycle, authenticated write, and background operation paths. Preserve streaming behavior, file-storage boundaries, and default log volume while making failures, retries, cancellation, and final outcomes independently diagnosable. Add focused regression coverage for correlation, partial data, resource context ownership, and terminal-state accuracy.
This commit is contained in:
27 files changed
+4029
-352
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { currentRequestId, runWithRequestId } from '@snowluma/common/logger';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { OneBotManager } from '../src/manager';
|
||||
import type { OneBotConfig } from '../src/types';
|
||||
@@ -34,4 +35,23 @@ describe('OneBotManager config apply value ownership', () => {
|
||||
expect(instance.reloadConfig).toHaveBeenNthCalledWith(1, a);
|
||||
expect(instance.reloadConfig).toHaveBeenNthCalledWith(2, b);
|
||||
});
|
||||
|
||||
it('does not attach a caller operation to reconfigured network resources', async () => {
|
||||
const manager = new OneBotManager();
|
||||
const observedRequestIds: Array<number | undefined> = [];
|
||||
let observeDeferred!: () => void;
|
||||
const instance = {
|
||||
reloadConfig: vi.fn(async () => {
|
||||
observedRequestIds.push(currentRequestId());
|
||||
observeDeferred = () => observedRequestIds.push(currentRequestId());
|
||||
return { applied: true, errors: [], statuses: [] };
|
||||
}),
|
||||
};
|
||||
(manager as unknown as { instances: Map<string, unknown> }).instances.set('10001', instance);
|
||||
|
||||
await runWithRequestId(5101, () => manager.reloadConfig('10001', config('#reload')));
|
||||
observeDeferred();
|
||||
|
||||
expect(observedRequestIds).toEqual([undefined, undefined]);
|
||||
});
|
||||
});
|
||||
@@ -1,3 +1,4 @@
|
||||
import { currentRequestId, runWithRequestId } from '@snowluma/common/logger';
|
||||
import { mkdtempSync, rmSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import path from 'node:path';
|
||||
@@ -44,6 +45,50 @@ describe('database migration estimates', () => {
|
||||
});
|
||||
|
||||
describe('OneBotManager database preparation', () => {
|
||||
it('detaches migration and network startup from the login operation', () => {
|
||||
let callbacks!: DatabaseMigrationCallbacks;
|
||||
const observedRequestIds: Array<number | undefined> = [];
|
||||
const task: DatabaseMigrationTask = {
|
||||
beginMigration: vi.fn(() => observedRequestIds.push(currentRequestId())),
|
||||
cancel: vi.fn(),
|
||||
start: vi.fn((next) => {
|
||||
observedRequestIds.push(currentRequestId());
|
||||
callbacks = next;
|
||||
}),
|
||||
};
|
||||
const instance = {
|
||||
...fakeInstance('10001', async () => undefined),
|
||||
waitUntilNetworkReady: vi.fn(() => {
|
||||
observedRequestIds.push(currentRequestId());
|
||||
return new Promise(() => undefined);
|
||||
}),
|
||||
startLoginHistorySync: vi.fn(),
|
||||
} as unknown as OneBotInstance;
|
||||
const manager = new OneBotManager({
|
||||
createDatabaseMigrationTask: () => task,
|
||||
createInstance: () => {
|
||||
observedRequestIds.push(currentRequestId());
|
||||
return instance;
|
||||
},
|
||||
});
|
||||
let startListener!: (uin: string, bridge: never) => void;
|
||||
manager.bind({
|
||||
addSessionStartedListener: (listener) => { startListener = listener; },
|
||||
addSessionClosedListener: vi.fn(),
|
||||
} as never);
|
||||
const bridge = {
|
||||
activePid: null,
|
||||
identity: { nickname: 'test' },
|
||||
fetchFriends: vi.fn(() => new Promise(() => undefined)),
|
||||
fetchGroups: vi.fn(() => new Promise(() => undefined)),
|
||||
};
|
||||
|
||||
runWithRequestId(5201, () => startListener('10001', bridge as never));
|
||||
callbacks.onReady();
|
||||
|
||||
expect(observedRequestIds).toEqual([undefined, undefined, undefined, undefined]);
|
||||
});
|
||||
|
||||
it('surfaces preparation as unavailable and ignores a stale completion after logout', async () => {
|
||||
let callbacks!: DatabaseMigrationCallbacks;
|
||||
const cancel = vi.fn();
|
||||
|
||||
Reference in new issue
Block a user