Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions apps/api/tests/workers/diagnosis-runner-do.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ async function seedRun(runId: string, userId: string): Promise<void> {

async function duringModelAwait(
runner: DurableObjectStub<DiagnosisRunner>,
runId: string,
action: (instance: DiagnosisRunner) => Promise<void>
): Promise<void> {
// The full Workers pool has no AI binding/account credentials. Configure this DO's own
Expand Down Expand Up @@ -69,7 +70,16 @@ async function duringModelAwait(
});
vi.stubGlobal('fetch', upstream);
try {
await runDurableObjectAlarm(runner);
// Keep start's immediate alarm behind the fixture barrier, then drive the
// real alarm explicitly. Otherwise the automatic handler can still be running
// when runDurableObjectAlarm() observes no scheduled alarm and returns false.
await runInDurableObject(runner, async (instance) => {
await instance.ctx.blockConcurrencyWhile(async () => {
await instance.start(runId);
await instance.ctx.storage.setAlarm(Date.now() + 60_000);
});
});
expect(await runDurableObjectAlarm(runner)).toBe(true);
if (boundaryError) throw boundaryError; // The production alarm handles model errors itself.
expect(upstream).toHaveBeenCalledTimes(1);
} finally {
Expand Down Expand Up @@ -173,9 +183,8 @@ describe('DiagnosisRunner DO durability and fault injection', () => {
const runId = 'diagnosis-do-cancel-race-001';
await seedRun(runId, 'diagnosis-user-cancel-race');
const runner = stub(runId);
await runner.start(runId);

await duringModelAwait(runner, async (instance) => {
await duringModelAwait(runner, runId, async (instance) => {
await instance.cancel(runId);
expect(
await instance.env.DATABASE.prepare(
Expand Down Expand Up @@ -212,9 +221,8 @@ describe('DiagnosisRunner DO durability and fault injection', () => {
const runId = 'diagnosis-do-deadline-race-001';
await seedRun(runId, 'diagnosis-user-deadline-race');
const runner = stub(runId);
await runner.start(runId);

await duringModelAwait(runner, async (instance) => {
await duringModelAwait(runner, runId, async (instance) => {
await instance.env.DATABASE.prepare(
"UPDATE debug_diagnosis_runs SET deadline_at='2020-01-01T00:00:00.000Z',heartbeat_at='2020-01-01T00:00:00.000Z' WHERE id=?"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,26 @@ describe('resumable archive cursor', () => {
});

it('reports the session cap when every slot is occupied by an existing migration', async () => {
vi.useFakeTimers({ toFake: ['Date'] });
onTestFinished(() => vi.useRealTimers());
const { projectId, sessionId, source } = await seedCandidate('occupied-slots', LARGE_MESSAGES);
const first = await tick({
PROJECT_DATA_ARCHIVE_WALL_TIME_MS: '150',
PROJECT_DATA_ARCHIVE_SWEEP_SESSIONS: '1',
const { bucket, puts } = countingR2(env.PROJECT_DATA_ARCHIVE_R2 as R2Bucket, {
// As in the large-cursor case, actual copy writes consume the tick budget.
// A fast or loaded runner must leave the same occupied migration slot.
beforePut: () => vi.setSystemTime(Date.now() + 25),
});
const first = await withR2(bucket, () =>
tick({
PROJECT_DATA_ARCHIVE_WALL_TIME_MS: '150',
PROJECT_DATA_ARCHIVE_SWEEP_SESSIONS: '1',
})
);
expect(first).toMatchObject({ yielded: 1, migrated: 0, failed: 0 });
expect(puts.size).toBeGreaterThan(0);
expect(await readJournal(projectId, sessionId)).toMatchObject({
state: 'copying',
lease_owner: null,
});
expect(first.yielded).toBe(1);
const pending = await source.createSession(null, 'Waiting behind occupied slot');
await source.persistMessageBatch(pending, messagesFor('waiting-behind-slot', 20));
await source.stopSession(pending);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"typescript-eslint": "catalog:",
"valibot": "catalog:",
"vitest": "catalog:",
"yaml": "2.9.0",
"yaml": "2.9.1",
"zod": "catalog:"
},
"packageManager": "pnpm@9.15.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/cloud-init/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"tsup": "8.5.1",
"typescript": "catalog:",
"vitest": "catalog:",
"yaml": "2.9.0"
"yaml": "2.9.1"
}
}
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"dependencies": {
"valibot": "catalog:",
"yaml": "2.9.0",
"yaml": "2.9.1",
"zod": "catalog:"
}
}
Loading
Loading