Test processing of unprocessed envelopes

Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
automated-signal 2025-02-04 20:02:59 -06:00 committed by GitHub
parent 2c01e6f4b8
commit 83b076b5c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 113 additions and 10 deletions

View file

@ -1005,9 +1005,7 @@ async function createWindow() {
mainWindow.webContents.send('ci:event', 'db-initialized', {});
const shouldShowWindow =
!app.getLoginItemSettings().wasOpenedAsHidden &&
!startInTray &&
!config.get<boolean>('ciIsBackupIntegration');
!app.getLoginItemSettings().wasOpenedAsHidden && !startInTray;
if (shouldShowWindow) {
getLogger().info('showing main window');
@ -2748,12 +2746,11 @@ ipc.on('get-config', async event => {
: getEnvironment(),
isMockTestEnvironment: Boolean(process.env.MOCK_TEST),
ciMode,
ciForceUnprocessed: config.get<boolean>('ciForceUnprocessed'),
devTools: defaultWebPrefs.devTools,
// Should be already computed and cached at this point
dnsFallback: await getDNSFallback(),
disableIPv6: DISABLE_IPV6,
ciBackupPath: config.get<string | null>('ciBackupPath') || undefined,
ciIsBackupIntegration: config.get<boolean>('ciIsBackupIntegration'),
nodeVersion: process.versions.node,
hostname: os.hostname(),
osRelease: os.release(),

View file

@ -17,8 +17,7 @@
"registrationChallengeUrl": "https://signalcaptchas.org/staging/registration/generate.html",
"updatesEnabled": false,
"ciMode": false,
"ciBackupPath": null,
"ciIsBackupIntegration": false,
"ciForceUnprocessed": false,
"forcePreloadBundle": false,
"openDevTools": false,
"buildCreation": 0,

View file

@ -42,13 +42,18 @@ export type CIType = {
unlink: () => void;
print: (...args: ReadonlyArray<unknown>) => void;
resetReleaseNotesFetcher(): void;
forceUnprocessed: boolean;
};
export type GetCIOptionsType = Readonly<{
deviceName: string;
forceUnprocessed: boolean;
}>;
export function getCI({ deviceName }: GetCIOptionsType): CIType {
export function getCI({
deviceName,
forceUnprocessed,
}: GetCIOptionsType): CIType {
const eventListeners = new Map<string, Array<ResolveType>>();
const completedEvents = new Map<string, Array<unknown>>();
@ -208,5 +213,6 @@ export function getCI({ deviceName }: GetCIOptionsType): CIType {
getPendingEventCount,
print,
resetReleaseNotesFetcher,
forceUnprocessed,
};
}

View file

@ -0,0 +1,96 @@
// Copyright 2025 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import createDebug from 'debug';
import { StorageState } from '@signalapp/mock-server';
import * as durations from '../../util/durations';
import type { App } from '../playwright';
import { Bootstrap } from '../bootstrap';
export const debug = createDebug('mock:test:unprocessed');
describe('unprocessed', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
let bootstrap: Bootstrap;
let app: App;
beforeEach(async () => {
bootstrap = new Bootstrap({ contactCount: 1 });
await bootstrap.init();
let state = StorageState.getEmpty();
const {
phone,
contacts: [alice],
} = bootstrap;
state = state.addContact(alice, {
identityKey: alice.publicKey.serialize(),
profileKey: alice.profileKey.serialize(),
whitelisted: true,
});
state = state.pin(alice);
await phone.setStorageState(state);
app = await bootstrap.link();
});
afterEach(async function (this: Mocha.Context) {
if (!bootstrap) {
return;
}
await bootstrap.maybeSaveLogs(this.currentTest, app);
await app.close();
await bootstrap.teardown();
});
it('generates and loads unprocessed envelopes', async () => {
const {
desktop,
contacts: [alice],
} = bootstrap;
debug('closing');
await app.close();
debug('queueing messages');
const sends = new Array<Promise<void>>();
for (let i = 0; i < 100; i += 1) {
sends.push(
alice.sendText(desktop, `hello: ${i}`, {
timestamp: bootstrap.getTimestamp(),
})
);
}
debug('starting app with unprocessed forced');
[app] = await Promise.all([
bootstrap.startApp({
ciForceUnprocessed: true,
}),
...sends,
]);
debug('waiting for the window');
await app.getWindow();
debug('restarting normally');
await app.close();
app = await bootstrap.startApp();
const page = await app.getWindow();
debug('opening conversation');
await page
.locator(`[data-testid="${alice.device.aci}"] >> "${alice.profileName}"`)
.click();
await page.locator('.module-message__text >> "hello: 5"').waitFor();
});
});

View file

@ -1144,6 +1144,11 @@ export default class MessageReceiver
return;
}
// Force save of unprocessed envelopes for testing
if (window.SignalCI?.forceUnprocessed) {
return;
}
// Now, queue and process decrypted envelopes. We drop the promise so that the next
// decryptAndCacheBatch batch does not have to wait for the decrypted envelopes to be
// processed, which can be an asynchronous blocking operation

View file

@ -40,11 +40,10 @@ export const rendererConfigSchema = z.object({
contentProxyUrl: configRequiredStringSchema,
crashDumpsPath: configRequiredStringSchema,
ciMode: z.enum(['full', 'benchmark']).or(z.literal(false)),
ciForceUnprocessed: z.boolean(),
devTools: z.boolean(),
disableIPv6: z.boolean(),
dnsFallback: DNSFallbackSchema,
ciBackupPath: configOptionalStringSchema,
ciIsBackupIntegration: z.boolean(),
environment: environmentSchema,
isMockTestEnvironment: z.boolean(),
homePath: configRequiredStringSchema,

View file

@ -19,5 +19,6 @@ if (config.ciMode) {
const { getCI } = require('../../CI');
window.SignalCI = getCI({
deviceName: window.getTitle(),
forceUnprocessed: config.ciForceUnprocessed,
});
}