test: Backend-e2e in CI stabil (eigene Jahre, Sperren, ein Server je App)
Backend E2E / e2e (push) Failing after 7m26s
Backend Image / build-and-push (push) Failing after 4m20s
Frontend Image / build-and-push (push) Successful in 15m44s

- daily-evaluation nutzt die Jahre 2011/2012 statt 2001, damit der Job nicht
  die Daten von autopilot und reminders liest und verändert.
- throttler: app.listen(0) einmal je App statt eines Servers je Anfrage
  (ECONNRESET bei 40 parallelen Anfragen).
- outbox-claims: 120 s Zeitlimit für 2000 sequentielle Anweisungen.
- migration-harness: eine `migrate deploy` zur Zeit über eine eigene
  Advisory-Sperre (P1002 bei parallelen Migrations-Suites).
- authority-notices und authority-notices-herd laufen über
  exclusive-suite nacheinander; Herd-Wiederholung räumt eigene Entwürfe.

Refs #32

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Nick.RosenloecherandClaude Opus 5.5 committed 2026-10-16 16:55:56 +02:00
1 parent 258e90828f
commit 6edae3efec
7 files changed
+217 -140

No files matched your search

+102 -100
View File
@@ -25,8 +25,10 @@ const NOTHING_NEW = {
/**
* The job evaluates the whole database. The e2e files share it and run in
* parallel, so the evaluation runs on days in 2001: no other file has
* records there, and the events of this file stay its own. Called through
* parallel, so the evaluation runs on days in 2011 and 2012: no other file has
* records there (autopilot and reminders own 2001; this file used to share it,
* so its "nothing new" counts picked up their colonies and its phenology step
* wrote season rows for their apiaries), and the events of this file stay its own. Called through
* TimeEventsStep.run(day) instead of runCli, which would also write JobRun
* rows that test/jobs.e2e-spec.ts counts.
*/
@@ -66,7 +68,7 @@ describe('daily-evaluation (e2e)', () => {
phenologyStep = app.get(PhenologyStep);
expiryStep = app.get(SuggestionsExpiryStep);
// The real AutopilotStep, but on the colonies of this file only: other
// files share the database and must not be reconciled on a 2001 day.
// files share the database and must not be reconciled on a 2011 day.
autopilotStep = new AutopilotStep(
{
colony: {
@@ -107,18 +109,18 @@ describe('daily-evaluation (e2e)', () => {
});
ids[`queen:${name}`] = created.id;
};
await queen('aged', { hatchYear: 1999, status: 'ACTIVE' });
await queen('young', { hatchYear: 2000, status: 'ACTIVE' });
await queen('reserve', { hatchYear: 1999, status: 'RESERVE' });
await queen('aged', { hatchYear: 2009, status: 'ACTIVE' });
await queen('young', { hatchYear: 2010, status: 'ACTIVE' });
await queen('reserve', { hatchYear: 2009, status: 'RESERVE' });
// Living, created 2001-04-20 and never measured: varroa due 2001-05-18.
// Living, created 2011-04-20 and never measured: varroa due 2011-05-18.
const living = await prisma.colony.create({
data: {
code: `DE-E2E-${suffix}-living`,
apiaryId: apiary.id,
colonyType: 'PRODUCTION_COLONY',
currentQueenId: ids['queen:aged'],
createdAt: d('2001-04-20'),
createdAt: d('2011-04-20'),
},
});
ids.living = living.id;
@@ -128,15 +130,15 @@ describe('daily-evaluation (e2e)', () => {
apiaryId: apiary.id,
colonyType: 'PRODUCTION_COLONY',
status: 'DECEASED',
createdAt: d('2001-04-20'),
createdAt: d('2011-04-20'),
},
});
ids.dead = dead.id;
// Inspected 2001-04-28, in the swarm season (every 7 days): the next
// inspection is due 2001-05-05 and overdue on 2001-05-06.
// Inspected 2011-04-28, in the swarm season (every 7 days): the next
// inspection is due 2011-05-05 and overdue on 2011-05-06.
for (const colonyId of [living.id, dead.id]) {
await prisma.inspection.create({
data: { colonyId, userId: user.id, date: d('2001-04-28') },
data: { colonyId, userId: user.id, date: d('2011-04-28') },
});
}
@@ -157,18 +159,18 @@ describe('daily-evaluation (e2e)', () => {
});
ids[`treatment:${name}`] = created.id;
};
// 2001-05-10 + 7 = 2001-05-17, in the window of 2001-05-20.
// 2011-05-10 + 7 = 2011-05-17, in the window of 2011-05-20.
await treatment('ending', {
date: d('2001-05-08'),
endDate: d('2001-05-10'),
date: d('2011-05-08'),
endDate: d('2011-05-10'),
withdrawalPeriodDays: 7,
});
// 2001-05-01 + 7 = 2001-05-08, before the window.
// 2011-05-01 + 7 = 2011-05-08, before the window.
await treatment('ended-earlier', {
date: d('2001-05-01'),
date: d('2011-05-01'),
withdrawalPeriodDays: 7,
});
await treatment('no-withdrawal', { date: d('2001-05-15') });
await treatment('no-withdrawal', { date: d('2011-05-15') });
const task = async (
name: string,
@@ -179,8 +181,8 @@ describe('daily-evaluation (e2e)', () => {
});
ids[`task:${name}`] = created.id;
};
await task('open', { dueDate: d('2001-05-18'), status: 'OPEN' });
await task('done', { dueDate: d('2001-05-18'), status: 'DONE' });
await task('open', { dueDate: d('2011-05-18'), status: 'OPEN' });
await task('done', { dueDate: d('2011-05-18'), status: 'DONE' });
});
afterAll(async () => {
@@ -222,10 +224,10 @@ describe('daily-evaluation (e2e)', () => {
});
it('running the job twice yields exactly one WithdrawalEnded per treatment and day', async () => {
const first = await step.run('2001-05-20');
const second = await step.run('2001-05-20');
const first = await step.run('2011-05-20');
const second = await step.run('2011-05-20');
// The next day the occurrence is still in the window - and still known.
const nextDay = await step.run('2001-05-21');
const nextDay = await step.run('2011-05-21');
expect(first.WithdrawalEnded).toBeGreaterThanOrEqual(1);
expect(second).toEqual(NOTHING_NEW);
@@ -234,8 +236,8 @@ describe('daily-evaluation (e2e)', () => {
{
type: 'WithdrawalEnded',
aggregateType: 'Treatment',
payload: { colonyId: ids.living, endedOn: '2001-05-17' },
dedupeKey: `WithdrawalEnded:${ids['treatment:ending']}:2001-05-17`,
payload: { colonyId: ids.living, endedOn: '2011-05-17' },
dedupeKey: `WithdrawalEnded:${ids['treatment:ending']}:2011-05-17`,
actorUserId: null,
},
]);
@@ -278,11 +280,11 @@ describe('daily-evaluation (e2e)', () => {
afterEach(async () => {
await prisma.notification.deleteMany({
where: { relatedType: 'ComplianceItem', relatedId: 'tsk-report:2001' },
where: { relatedType: 'ComplianceItem', relatedId: 'tsk-report:2011' },
});
await prisma.authorityNotice.deleteMany({ where: { year: 2001 } });
await prisma.authorityNotice.deleteMany({ where: { year: 2011 } });
await prisma.domainEvent.deleteMany({
where: { aggregateId: 'tsk:2001' },
where: { aggregateId: 'tsk:2011' },
});
await prisma.complianceSettings.update({
where: { id: 'singleton' },
@@ -291,25 +293,25 @@ describe('daily-evaluation (e2e)', () => {
});
async function expectOneDraftAndNotices(): Promise<void> {
expect(await eventsOf('tsk:2001')).toEqual([
expect(await eventsOf('tsk:2011')).toEqual([
{
type: 'TskReferenceDayReached',
aggregateType: 'Compliance',
payload: { year: 2001, referenceDay: '2001-03-03' },
dedupeKey: 'TskReferenceDayReached:tsk:2001:2001-03-03',
payload: { year: 2011, referenceDay: '2011-03-03' },
dedupeKey: 'TskReferenceDayReached:tsk:2011:2011-03-03',
actorUserId: null,
},
]);
const drafts = await prisma.authorityNotice.findMany({
where: { kind: 'TSK_REPORT', year: 2001 },
where: { kind: 'TSK_REPORT', year: 2011 },
});
expect(drafts).toHaveLength(1);
expect(drafts[0]).toMatchObject({
status: 'DRAFT',
openKey: 'TSK_REPORT:2001',
openKey: 'TSK_REPORT:2011',
});
const notifications = await prisma.notification.findMany({
where: { relatedType: 'ComplianceItem', relatedId: 'tsk-report:2001' },
where: { relatedType: 'ComplianceItem', relatedId: 'tsk-report:2011' },
select: { userId: true, priority: true, category: true, message: true },
});
// One copy per recipient, written once - and every permitted user that
@@ -331,17 +333,17 @@ describe('daily-evaluation (e2e)', () => {
category: 'COMPLIANCE',
});
expect(row.message).toMatch(
/^TSK-Stichtag 03\.03\.2001: \d+ Völker gezählt\. Bitte prüfen und melden\.$/,
/^TSK-Stichtag 03\.03\.2011: \d+ Völker gezählt\. Bitte prüfen und melden\.$/,
);
}
}
it('daily evaluation twice on the reference day: one event, one draft', async () => {
const first = await step.run('2001-03-03');
const second = await step.run('2001-03-03');
await drainDomainEvents(app, ['tsk:2001']);
await step.run('2001-03-04');
await drainDomainEvents(app, ['tsk:2001']);
const first = await step.run('2011-03-03');
const second = await step.run('2011-03-03');
await drainDomainEvents(app, ['tsk:2011']);
await step.run('2011-03-04');
await drainDomainEvents(app, ['tsk:2011']);
expect(first.TskReferenceDayReached).toBe(1);
expect(second.TskReferenceDayReached).toBe(0);
@@ -349,9 +351,9 @@ describe('daily-evaluation (e2e)', () => {
});
it('catches up a missed reference day on the 5th exactly once', async () => {
const catchUp = await step.run('2001-03-05');
const again = await step.run('2001-03-05');
await drainDomainEvents(app, ['tsk:2001']);
const catchUp = await step.run('2011-03-05');
const again = await step.run('2011-03-05');
await drainDomainEvents(app, ['tsk:2011']);
expect(catchUp.TskReferenceDayReached).toBe(1);
expect(again.TskReferenceDayReached).toBe(0);
@@ -360,14 +362,14 @@ describe('daily-evaluation (e2e)', () => {
});
it('records due tasks and varroa checks only for open tasks and living colonies', async () => {
await step.run('2001-05-20');
await step.run('2011-05-20');
expect(await eventsOf(ids['task:open'])).toEqual([
{
type: 'TaskDue',
aggregateType: 'Task',
payload: { dueOn: '2001-05-18' },
dedupeKey: `TaskDue:${ids['task:open']}:2001-05-18`,
payload: { dueOn: '2011-05-18' },
dedupeKey: `TaskDue:${ids['task:open']}:2011-05-18`,
actorUserId: null,
},
]);
@@ -377,12 +379,12 @@ describe('daily-evaluation (e2e)', () => {
type: 'VarroaMeasurementDue',
aggregateType: 'Colony',
payload: {
dueOn: '2001-05-18',
dueOn: '2011-05-18',
lastMeasuredOn: null,
kind: 'INTERVAL',
anchor: 'none',
},
dedupeKey: `VarroaMeasurementDue:${ids.living}:2001-05-18`,
dedupeKey: `VarroaMeasurementDue:${ids.living}:2011-05-18`,
actorUserId: null,
},
]);
@@ -390,9 +392,9 @@ describe('daily-evaluation (e2e)', () => {
});
it('InspectionOverdue follows the segment interval', async () => {
await step.run('2001-05-12');
await step.run('2011-05-12');
// SCHWARMZEIT since 2001-04-15: 2001-04-28 + 7 = 2001-05-05, not + 21.
// SCHWARMZEIT since 2011-04-15: 2011-04-28 + 7 = 2011-05-05, not + 21.
expect(
(await eventsOf(ids.living)).filter(
(event) => event.type === 'InspectionOverdue',
@@ -402,11 +404,11 @@ describe('daily-evaluation (e2e)', () => {
type: 'InspectionOverdue',
aggregateType: 'Colony',
payload: {
dueOn: '2001-05-05',
lastInspectedOn: '2001-04-28',
dueOn: '2011-05-05',
lastInspectedOn: '2011-04-28',
firstOfYear: false,
},
dedupeKey: `InspectionOverdue:${ids.living}:2001-05-06`,
dedupeKey: `InspectionOverdue:${ids.living}:2011-05-06`,
actorUserId: null,
},
]);
@@ -414,50 +416,50 @@ describe('daily-evaluation (e2e)', () => {
});
it('records no inspection in WINTERRUHE and the first one the day after FRUEHJAHR begins', async () => {
await step.run('2002-03-10');
await step.run('2012-03-10');
expect(
(await eventsOf(ids.living)).filter((event) =>
event.dedupeKey?.endsWith(':2002-03-21'),
event.dedupeKey?.endsWith(':2012-03-21'),
),
).toEqual([]);
// FRUEHJAHR begins 2002-03-20; the colony was last inspected in 2001.
await step.run('2002-03-21');
// FRUEHJAHR begins 2012-03-20; the colony was last inspected in 2011.
await step.run('2012-03-21');
expect(
(await eventsOf(ids.living)).filter((event) =>
event.dedupeKey?.endsWith(':2002-03-21'),
event.dedupeKey?.endsWith(':2012-03-21'),
),
).toEqual([
{
type: 'InspectionOverdue',
aggregateType: 'Colony',
payload: {
dueOn: '2002-03-20',
lastInspectedOn: '2001-04-28',
dueOn: '2012-03-20',
lastInspectedOn: '2011-04-28',
firstOfYear: true,
},
dedupeKey: `InspectionOverdue:${ids.living}:2002-03-21`,
dedupeKey: `InspectionOverdue:${ids.living}:2012-03-21`,
actorUserId: null,
},
]);
});
it('reports the current queen of a living colony once she is aged, on any job day of the year', async () => {
await step.run('2001-09-09');
await step.run('2001-09-10');
await step.run('2011-09-09');
await step.run('2011-09-10');
// One per queen and year: the 2002 run of the test above added its own.
// One per queen and year: the 2012 run of the test above added its own.
const events = await eventsOf(ids['queen:aged']);
expect(events.map((event) => event.dedupeKey)).toEqual([
`QueenAged:${ids['queen:aged']}:2001-01-01`,
`QueenAged:${ids['queen:aged']}:2002-01-01`,
`QueenAged:${ids['queen:aged']}:2011-01-01`,
`QueenAged:${ids['queen:aged']}:2012-01-01`,
]);
expect(events.slice(0, 1)).toEqual([
{
type: 'QueenAged',
aggregateType: 'Queen',
payload: { hatchYear: 1999, colonyId: ids.living },
dedupeKey: `QueenAged:${ids['queen:aged']}:2001-01-01`,
payload: { hatchYear: 2009, colonyId: ids.living },
dedupeKey: `QueenAged:${ids['queen:aged']}:2011-01-01`,
actorUserId: null,
},
]);
@@ -466,7 +468,7 @@ describe('daily-evaluation (e2e)', () => {
});
describe('phenology step', () => {
const DAY = '2001-04-30';
const DAY = '2011-04-30';
let weatherApiaryId = '';
beforeAll(async () => {
@@ -481,8 +483,8 @@ describe('daily-evaluation (e2e)', () => {
// 10 degrees every day from January 1st to April 29th: GTS 965.
const days: Prisma.ApiaryWeatherDayCreateManyInput[] = [];
for (
let t = d('2001-01-01').getTime();
t <= d('2001-04-29').getTime();
let t = d('2011-01-01').getTime();
t <= d('2011-04-29').getTime();
t += 86_400_000
) {
days.push({
@@ -497,7 +499,7 @@ describe('daily-evaluation (e2e)', () => {
data: {
apiaryId: apiary.id,
phase: 'HOLUNDER',
date: d('2001-04-29'),
date: d('2011-04-29'),
userId: ids.user,
},
});
@@ -510,8 +512,8 @@ describe('daily-evaluation (e2e)', () => {
await prisma.phenologyReport.deleteMany({
where: { apiaryId: weatherApiaryId },
});
// Rows of 2001 would feed the season of the other tests of this file.
await prisma.apiaryPhenology.deleteMany({ where: { year: 2001 } });
// Rows of 2011 would feed the season of the other tests of this file.
await prisma.apiaryPhenology.deleteMany({ where: { year: 2011 } });
await prisma.apiary.deleteMany({ where: { id: weatherApiaryId } });
});
@@ -530,7 +532,7 @@ describe('daily-evaluation (e2e)', () => {
expect(Number(result.phenologyApiaries)).toBeGreaterThanOrEqual(2);
const rows = await prisma.apiaryPhenology.findMany({
where: { apiaryId: { in: [ids.apiary, weatherApiaryId] }, year: 2001 },
where: { apiaryId: { in: [ids.apiary, weatherApiaryId] }, year: 2011 },
orderBy: { apiaryId: 'asc' },
});
expect(rows).toHaveLength(2);
@@ -545,7 +547,7 @@ describe('daily-evaluation (e2e)', () => {
// A report for HOLUNDER beats GTS and calendar.
expect(byApiary.get(weatherApiaryId)).toMatchObject({
gts: 965,
gtsThroughDay: d('2001-04-29'),
gtsThroughDay: d('2011-04-29'),
estimatedPhase: 'APFEL',
reportedPhase: 'HOLUNDER',
effectivePhase: 'HOLUNDER',
@@ -579,25 +581,25 @@ describe('daily-evaluation (e2e)', () => {
});
describe('autopilot and suggestions-expiry steps', () => {
/** Living colony, inspected 2001-05-03 and measured 2001-05-10. */
/** Living colony, inspected 2011-05-03 and measured 2011-05-10. */
async function lateColony(name: string): Promise<string> {
const colony = await prisma.colony.create({
data: {
code: `DE-E2E-${suffix}-ap-${name}`,
apiaryId: ids.apiary,
colonyType: 'PRODUCTION_COLONY',
createdAt: d('2001-04-20'),
createdAt: d('2011-04-20'),
},
});
autopilotColonyIds.push(colony.id);
await prisma.inspection.create({
data: { colonyId: colony.id, userId: ids.user, date: d('2001-05-03') },
data: { colonyId: colony.id, userId: ids.user, date: d('2011-05-03') },
});
await prisma.varroaMeasurement.create({
data: {
colonyId: colony.id,
userId: ids.user,
date: d('2001-05-10'),
date: d('2011-05-10'),
method: 'NATURAL_MITE_FALL',
},
});
@@ -613,10 +615,10 @@ describe('daily-evaluation (e2e)', () => {
it('running autopilot and expiry twice yields the same suggestion counts', async () => {
const colonyId = await lateColony('twice');
const first = await autopilotStep.run('2001-05-12');
const firstExpiry = await expiryStep.run('2001-05-12');
const second = await autopilotStep.run('2001-05-12');
const secondExpiry = await expiryStep.run('2001-05-12');
const first = await autopilotStep.run('2011-05-12');
const firstExpiry = await expiryStep.run('2011-05-12');
const second = await autopilotStep.run('2011-05-12');
const secondExpiry = await expiryStep.run('2011-05-12');
expect(first).toMatchObject({
autopilotColonies: 1,
@@ -635,13 +637,13 @@ describe('daily-evaluation (e2e)', () => {
it('an OPEN suggestion past expiresAt becomes EXPIRED', async () => {
const colonyId = await lateColony('expires');
await autopilotStep.run('2001-05-12');
await autopilotStep.run('2011-05-12');
// expiresAt = 2001-06-11
expect(await expiryStep.run('2001-06-11')).toEqual({
// expiresAt = 2011-06-11
expect(await expiryStep.run('2011-06-11')).toEqual({
suggestionsExpired: 0,
});
expect(await expiryStep.run('2001-06-12')).toEqual({
expect(await expiryStep.run('2011-06-12')).toEqual({
suggestionsExpired: expect.any(Number) as number,
});
@@ -651,10 +653,10 @@ describe('daily-evaluation (e2e)', () => {
it('an expired INSPECT suggestion of the same anchor is proposed again on the next sync (dedupeKey was released)', async () => {
const colonyId = await lateColony('again');
await autopilotStep.run('2001-05-12');
await expiryStep.run('2001-06-12');
await autopilotStep.run('2011-05-12');
await expiryStep.run('2011-06-12');
const result = await autopilotStep.run('2001-06-12');
const result = await autopilotStep.run('2011-06-12');
expect(result.suggestionsOpened).toBeGreaterThanOrEqual(1);
expect((await inspectSuggestions(colonyId)).map((s) => s.status)).toEqual(
@@ -666,13 +668,13 @@ describe('daily-evaluation (e2e)', () => {
const colonyId = await lateColony('overdue20');
await prisma.inspection.updateMany({
where: { colonyId },
data: { date: d('2001-04-10') },
data: { date: d('2011-04-10') },
});
await step.run('2001-05-12');
await autopilotStep.run('2001-05-12');
await step.run('2011-05-12');
await autopilotStep.run('2011-05-12');
// Due 2001-04-17: the event of 04-18 is outside the 7-day catch-up.
// Due 2011-04-17: the event of 04-18 is outside the 7-day catch-up.
expect(
await prisma.domainEvent.count({
where: { aggregateId: colonyId, type: 'InspectionOverdue' },
@@ -680,19 +682,19 @@ describe('daily-evaluation (e2e)', () => {
).toBe(0);
const [suggestion] = await inspectSuggestions(colonyId);
expect(suggestion).toMatchObject({ status: 'OPEN', priority: 'HIGH' });
expect(suggestion.dueDate?.toISOString().slice(0, 10)).toBe('2001-04-17');
expect(suggestion.dueDate?.toISOString().slice(0, 10)).toBe('2011-04-17');
});
it('a RESOLVED autopilot suggestion whose condition returns is proposed again', async () => {
const colonyId = await lateColony('returns');
await autopilotStep.run('2001-05-12');
await autopilotStep.run('2011-05-12');
const fresh = await prisma.inspection.create({
data: { colonyId, userId: ids.user, date: d('2001-05-12') },
data: { colonyId, userId: ids.user, date: d('2011-05-12') },
});
const resolved = await autopilotStep.run('2001-05-12');
const resolved = await autopilotStep.run('2011-05-12');
await prisma.inspection.delete({ where: { id: fresh.id } });
const returned = await autopilotStep.run('2001-05-12');
const returned = await autopilotStep.run('2011-05-12');
expect(resolved.suggestionsResolved).toBeGreaterThanOrEqual(1);
expect(returned.suggestionsOpened).toBeGreaterThanOrEqual(1);