|
1 | | -import { ClickHouse, TASK_RUN_INDEX, PAYLOAD_INDEX } from "@internal/clickhouse"; |
| 1 | +import { ClickHouse, getTaskRunField, getPayloadField } from "@internal/clickhouse"; |
2 | 2 | import { containerTest } from "@internal/testcontainers"; |
3 | 3 | import { Logger } from "@trigger.dev/core/logger"; |
4 | 4 | import { readFile } from "node:fs/promises"; |
@@ -889,13 +889,13 @@ describe("RunsReplicationService (part 2/2)", () => { |
889 | 889 | await setTimeout(1000); |
890 | 890 |
|
891 | 891 | expect(batchFlushedEvents?.[0].taskRunInserts).toHaveLength(2); |
892 | | - // Use TASK_RUN_INDEX for type-safe array access |
893 | | - expect(batchFlushedEvents?.[0].taskRunInserts[0][TASK_RUN_INDEX.run_id]).toEqual(run.id); |
894 | | - expect(batchFlushedEvents?.[0].taskRunInserts[0][TASK_RUN_INDEX.status]).toEqual( |
| 892 | + // Use getTaskRunField for type-safe array access |
| 893 | + expect(getTaskRunField(batchFlushedEvents![0].taskRunInserts[0], "run_id")).toEqual(run.id); |
| 894 | + expect(getTaskRunField(batchFlushedEvents![0].taskRunInserts[0], "status")).toEqual( |
895 | 895 | "PENDING_VERSION" |
896 | 896 | ); |
897 | | - expect(batchFlushedEvents?.[0].taskRunInserts[1][TASK_RUN_INDEX.run_id]).toEqual(run.id); |
898 | | - expect(batchFlushedEvents?.[0].taskRunInserts[1][TASK_RUN_INDEX.status]).toEqual( |
| 897 | + expect(getTaskRunField(batchFlushedEvents![0].taskRunInserts[1], "run_id")).toEqual(run.id); |
| 898 | + expect(getTaskRunField(batchFlushedEvents![0].taskRunInserts[1], "status")).toEqual( |
899 | 899 | "COMPLETED_SUCCESSFULLY" |
900 | 900 | ); |
901 | 901 |
|
@@ -1063,22 +1063,22 @@ describe("RunsReplicationService (part 2/2)", () => { |
1063 | 1063 |
|
1064 | 1064 | // Verify sorting order: organization_id, project_id, environment_id, created_at, run_id |
1065 | 1065 | for (let i = 1; i < batchFlushedEvents[0]?.taskRunInserts.length; i++) { |
1066 | | - const prev = batchFlushedEvents[0]?.taskRunInserts[i - 1]; |
1067 | | - const curr = batchFlushedEvents[0]?.taskRunInserts[i]; |
| 1066 | + const prev = batchFlushedEvents[0]!.taskRunInserts[i - 1]; |
| 1067 | + const curr = batchFlushedEvents[0]!.taskRunInserts[i]; |
1068 | 1068 |
|
1069 | 1069 | const prevKey = [ |
1070 | | - prev[TASK_RUN_INDEX.organization_id], |
1071 | | - prev[TASK_RUN_INDEX.project_id], |
1072 | | - prev[TASK_RUN_INDEX.environment_id], |
1073 | | - prev[TASK_RUN_INDEX.created_at], |
1074 | | - prev[TASK_RUN_INDEX.run_id], |
| 1070 | + getTaskRunField(prev, "organization_id"), |
| 1071 | + getTaskRunField(prev, "project_id"), |
| 1072 | + getTaskRunField(prev, "environment_id"), |
| 1073 | + getTaskRunField(prev, "created_at"), |
| 1074 | + getTaskRunField(prev, "run_id"), |
1075 | 1075 | ]; |
1076 | 1076 | const currKey = [ |
1077 | | - curr[TASK_RUN_INDEX.organization_id], |
1078 | | - curr[TASK_RUN_INDEX.project_id], |
1079 | | - curr[TASK_RUN_INDEX.environment_id], |
1080 | | - curr[TASK_RUN_INDEX.created_at], |
1081 | | - curr[TASK_RUN_INDEX.run_id], |
| 1077 | + getTaskRunField(curr, "organization_id"), |
| 1078 | + getTaskRunField(curr, "project_id"), |
| 1079 | + getTaskRunField(curr, "environment_id"), |
| 1080 | + getTaskRunField(curr, "created_at"), |
| 1081 | + getTaskRunField(curr, "run_id"), |
1082 | 1082 | ]; |
1083 | 1083 |
|
1084 | 1084 | const keysAreEqual = prevKey.every((val, idx) => val === currKey[idx]); |
@@ -1106,9 +1106,9 @@ describe("RunsReplicationService (part 2/2)", () => { |
1106 | 1106 |
|
1107 | 1107 | // Verify payloadInserts are also sorted by run_id |
1108 | 1108 | for (let i = 1; i < batchFlushedEvents[0]?.payloadInserts.length; i++) { |
1109 | | - const prev = batchFlushedEvents[0]?.payloadInserts[i - 1]; |
1110 | | - const curr = batchFlushedEvents[0]?.payloadInserts[i]; |
1111 | | - expect(prev[PAYLOAD_INDEX.run_id] <= curr[PAYLOAD_INDEX.run_id]).toBeTruthy(); |
| 1109 | + const prev = batchFlushedEvents[0]!.payloadInserts[i - 1]; |
| 1110 | + const curr = batchFlushedEvents[0]!.payloadInserts[i]; |
| 1111 | + expect(getPayloadField(prev, "run_id") <= getPayloadField(curr, "run_id")).toBeTruthy(); |
1112 | 1112 | } |
1113 | 1113 |
|
1114 | 1114 | await runsReplicationService.stop(); |
|
0 commit comments