chore(lint): keep the fixes within the lint ratchets

No promise in a condition, sequential awaits through a reduce instead of a loop, no non-null assertions or any in the new tests, an awaited act, one options object for a stop edit and a handled rejection for the offline copy.
This commit is contained in:
Maurice
2026-11-23 16:09:34 +01:00
parent f6d52727f7
commit 8a9f5367b1
15 changed files with 65 additions and 31 deletions
@@ -362,11 +362,14 @@ export class DawarichSyncService {
* @txIndependent one stay at a time after its network read.
*/
private async rereadUnnamed(nameStay: StayNamer): Promise<void> {
for (const stay of nameStay.unnamed.slice(0, MAX_UNNAMED_STAY_REREADS)) {
// One after another: a read that finds the budget spent stops the rest.
await nameStay.unnamed.slice(0, MAX_UNNAMED_STAY_REREADS).reduce<Promise<boolean>>(async (going, stay) => {
if (!(await going)) return false;
const found = await nameStay.read(stay.startedAt, stay.endedAt);
if (found === undefined) return;
if (found === undefined) return false;
if (found !== null) await this.suggestions.renameNewVisit(stay.id, found);
}
return true;
}, Promise.resolve(true));
}
/**
@@ -47,7 +47,7 @@ export function tripEventSink(addons: AddonsService, orm: MikroORM | undefined,
return (tripId, event, meta) => {
const addonId = tripAddonOfEvent(event);
const before = queues.get(tripId);
if (!addonId && !before) return deliver(tripId, event, meta);
if (!addonId && before === undefined) return deliver(tripId, event, meta);
const ask = () => (addonId ? addons.isEnabledForTrip(tripId, addonId) : Promise.resolve(true));
const on = (orm && addonId ? withRequestContext(orm, ask) : ask()).catch(() => false);
const queued = (before ?? Promise.resolve())
@@ -82,10 +82,7 @@ afterAll(async () => {
describe('Postgres backup round trip', () => {
it('PGRT-001: a dump restores over a changed schema, dropping what came later, views and functions included', async (ctx) => {
if (unfit) {
console.log(`PGRT-001 skipped: ${unfit}`);
ctx.skip();
}
if (unfit) ctx.skip(`PGRT-001 skipped: ${unfit}`);
await asOwner((run) =>
oneByOne(
[
@@ -54,9 +54,9 @@ describe('script-settings', () => {
'SCRIPTSET-001: a PostgreSQL %i server gets the script without SET transaction_timeout, and nothing else changes',
async (major) => {
const expected = SCRIPT.replace('SET transaction_timeout = 0;\n', '');
for (const size of [1, 3, 7, 64, 1 << 20]) {
expect(await filtered(SCRIPT, major, size), `chunks of ${size}`).toBe(expected);
}
const sizes = [1, 3, 7, 64, 1 << 20];
const results = await Promise.all(sizes.map((size) => filtered(SCRIPT, major, size)));
results.forEach((result, i) => expect(result, `chunks of ${sizes[i]}`).toBe(expected));
},
);
@@ -459,7 +459,7 @@ describe('migrate-encryption.ts rotates the stores the app writes', () => {
token: string | null;
}>;
after.close();
expect(decryptWith('new-key', rows[0].token!)).toBe('wanderer-token');
expect(decryptWith('new-key', String(rows[0].token))).toBe('wanderer-token');
expect(rows[1].token).toBeNull();
}, 30000);
+3 -3
View File
@@ -688,7 +688,7 @@ describe('Tool: upload_trip_file', () => {
name: 'upload_trip_file',
arguments: { tripId: trip.id, filename: 'receipt.pdf', content: pdf, budget_item_id: expense.id },
}),
) as any;
) as { file: { id: number } };
expect((await linkRows(data.file.id)).map((l) => l.budget_item_id)).toEqual([expense.id]);
const foreign = await h.client.callTool({
name: 'upload_trip_file',
@@ -713,8 +713,8 @@ describe('Tool: upload_trip_file', () => {
name: 'upload_trip_file',
arguments: { tripId: trip.id, filename: 'ticket.pdf', content: pdf },
}),
) as any
).file.id as number;
) as { file: { id: number } }
).file.id;
const receipt = await upload();
const refused = await h.client.callTool({
name: 'update_trip_file',
+6 -2
View File
@@ -386,8 +386,12 @@ describe('listFiles', () => {
const files = (await svc.listFiles(trip.id, false, true)) as Record<string, unknown>[];
expect(files.map((f) => f.id).sort()).toEqual([onBooking.id, onPlace.id, receipt.id].sort());
expect(await svc.isAttached((await svc.getFileById(receipt.id, trip.id))!)).toBe(true);
expect(await svc.isAttached((await svc.getFileById(loose.id, trip.id))!)).toBe(false);
const [receiptRow, looseRow] = await Promise.all([
svc.getFileById(receipt.id, trip.id),
svc.getFileById(loose.id, trip.id),
]);
expect(receiptRow && (await svc.isAttached(receiptRow))).toBe(true);
expect(looseRow && (await svc.isAttached(looseRow))).toBe(false);
});
});
@@ -129,14 +129,16 @@ describe('the mail tools', () => {
it('are listed only while the import is on, since every call needs it', async () => {
expect(tools).toHaveLength(7);
for (const name of tools) {
// One tool after another: each takes the next answer of the settings stub.
await tools.reduce(async (previous, name) => {
await previous;
const entry = getEntry(MailIngestMcp as unknown as ClassRef, name);
const when = entry?.kind === 'tool' ? entry.options.when : undefined;
expect(when, name).toBeTypeOf('function');
settings.isAvailable.mockResolvedValueOnce(false);
expect(await when?.(ctx, mcp()), name).toBe(false);
expect(await when?.(ctx, mcp()), name).toBe(true);
}
}, Promise.resolve());
});
});
@@ -1548,10 +1548,12 @@ describe('ReservationsService — referenced ids stay inside the trip', () => {
const foreignDay = await findRow(orm, Days, { trip: theirs.id }) as { id: number };
const foreignAcc = createDayAccommodation(testDb, theirs.id, foreignPlace.id, foreignDay.id, foreignDay.id);
for (const accommodation_id of [3000000000, foreignAcc.id]) {
const dropped = async (accommodation_id: number) => {
const { reservation } = await svc.create(String(mine.id), { title: 'Hotel', type: 'hotel', accommodation_id });
expect(await findRow(orm, Reservations, { id: reservation.id })).toMatchObject({ accommodation_id: null });
}
};
await dropped(3000000000);
await dropped(foreignAcc.id);
});
it('RESV-SCOPE-011: a stay whose refs resolve to nothing is refused, never written and never dropped in silence', async () => {