Skip to content

Commit 63fcdf8

Browse files
d-csclaude
andcommitted
test(run-engine): getSnapshotsSince must reject a since snapshot from a different run (red)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 4e63af3 commit 63fcdf8

1 file changed

Lines changed: 111 additions & 0 deletions

File tree

internal-packages/run-engine/src/engine/tests/getSnapshotsSince.test.ts

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,117 @@ describe("RunEngine getSnapshotsSince", () => {
436436
}
437437
});
438438

439+
containerTest(
440+
"returns null when the since snapshot belongs to a different run",
441+
async ({ prisma, redisOptions }) => {
442+
const authenticatedEnvironment = await setupAuthenticatedEnvironment(prisma, "PRODUCTION");
443+
444+
const engine = new RunEngine({
445+
prisma,
446+
worker: {
447+
redis: redisOptions,
448+
workers: 1,
449+
tasksPerWorker: 10,
450+
pollIntervalMs: 100,
451+
},
452+
queue: {
453+
redis: redisOptions,
454+
},
455+
runLock: {
456+
redis: redisOptions,
457+
},
458+
machines: {
459+
defaultMachine: "small-1x",
460+
machines: {
461+
"small-1x": {
462+
name: "small-1x" as const,
463+
cpu: 0.5,
464+
memory: 0.5,
465+
centsPerMs: 0.0001,
466+
},
467+
},
468+
baseCostInCents: 0.0001,
469+
},
470+
tracer: trace.getTracer("test", "0.0.0"),
471+
});
472+
473+
try {
474+
const taskIdentifier = "test-task";
475+
await setupBackgroundWorker(engine, authenticatedEnvironment, taskIdentifier);
476+
477+
const runA = await engine.trigger(
478+
{
479+
number: 1,
480+
friendlyId: generateFriendlyId("run"),
481+
environment: authenticatedEnvironment,
482+
taskIdentifier,
483+
payload: "{}",
484+
payloadType: "application/json",
485+
context: {},
486+
traceContext: {},
487+
traceId: "t_foreign_snapshot",
488+
spanId: "s_foreign_snapshot_a",
489+
workerQueue: "main",
490+
queue: "task/test-task",
491+
isTest: false,
492+
tags: [],
493+
},
494+
prisma
495+
);
496+
497+
const runB = await engine.trigger(
498+
{
499+
number: 2,
500+
friendlyId: generateFriendlyId("run"),
501+
environment: authenticatedEnvironment,
502+
taskIdentifier,
503+
payload: "{}",
504+
payloadType: "application/json",
505+
context: {},
506+
traceContext: {},
507+
traceId: "t_foreign_snapshot",
508+
spanId: "s_foreign_snapshot_b",
509+
workerQueue: "main",
510+
queue: "task/test-task",
511+
isTest: false,
512+
tags: [],
513+
},
514+
prisma
515+
);
516+
517+
await setTimeout(500);
518+
await engine.dequeueFromWorkerQueue({
519+
consumerId: "test_foreign_snapshot",
520+
workerQueue: "main",
521+
});
522+
523+
const runASnapshots = await prisma.taskRunExecutionSnapshot.findMany({
524+
where: { runId: runA.id, isValid: true },
525+
orderBy: { createdAt: "asc" },
526+
});
527+
const runBSnapshots = await prisma.taskRunExecutionSnapshot.findMany({
528+
where: { runId: runB.id, isValid: true },
529+
orderBy: { createdAt: "asc" },
530+
});
531+
532+
expect(runASnapshots.length).toBeGreaterThanOrEqual(1);
533+
expect(runBSnapshots.length).toBeGreaterThanOrEqual(1);
534+
535+
const runASnapshot = runASnapshots[0];
536+
537+
// Poll run B using a snapshot id that belongs to run A
538+
const result = await engine.getSnapshotsSince({
539+
runId: runB.id,
540+
snapshotId: runASnapshot.id,
541+
});
542+
543+
expect(result).toBeNull();
544+
} finally {
545+
await engine.quit();
546+
}
547+
}
548+
);
549+
439550
// Direct database tests for the core function
440551
containerTest(
441552
"direct test: large waitpoint scenario - 100 waitpoints with 10KB outputs",

0 commit comments

Comments
 (0)