|
1 | 1 | // Pure mapping coverage; storage routing and failures use real stores in the integration suite. |
2 | 2 | import { describe, expect, it } from "vitest"; |
3 | | -import { generateWaitpointId } from "@trigger.dev/core/v3/isomorphic"; |
| 3 | +import { |
| 4 | + generateFriendlyId, |
| 5 | + generateRunOpsId, |
| 6 | + generateRunOpsIdV2, |
| 7 | + generateWaitpointId, |
| 8 | + RunId, |
| 9 | +} from "@trigger.dev/core/v3/isomorphic"; |
| 10 | +import { MEMORYDB_SHARD_KEY } from "@internal/run-store"; |
4 | 11 | import type { |
5 | 12 | WaitpointCompletion, |
6 | 13 | WaitpointRecordInput, |
@@ -126,6 +133,66 @@ describe("storeRecordToCompletedWaitpointRecord — envelope fidelity", () => { |
126 | 133 | expect(record.output).toEqual({ inline: '{"type":"BUILT_IN_ERROR"}' }); |
127 | 134 | }); |
128 | 135 |
|
| 136 | + // Catches: a MemoryDB child's RUN success mapped to deriveFromRun, or its stored output changed. |
| 137 | + it("keeps a MemoryDB child's stored RUN success output, in either id form", () => { |
| 138 | + const childId = generateRunOpsIdV2(MEMORYDB_SHARD_KEY); |
| 139 | + const forms = [ |
| 140 | + { outputType: "application/json", output: null }, |
| 141 | + { outputType: "text/plain", output: { inline: "" } }, |
| 142 | + { outputType: "application/json", output: { inline: '{"v":1}' } }, |
| 143 | + { outputType: "application/store", output: { inline: `packets/run_${childId}/output.json` } }, |
| 144 | + ]; |
| 145 | + for (const completedByTaskRunId of [childId, `run_${childId}`]) { |
| 146 | + for (const form of forms) { |
| 147 | + const record = mapStoreRecord( |
| 148 | + storeEntry( |
| 149 | + generateWaitpointId("RUN"), |
| 150 | + { type: "RUN", completedByTaskRunId }, |
| 151 | + storeCompletion(form) |
| 152 | + ) |
| 153 | + ); |
| 154 | + expect([record.output, record.outputType]).toEqual([form.output, form.outputType]); |
| 155 | + } |
| 156 | + } |
| 157 | + }); |
| 158 | + |
| 159 | + // Catches: a RUN success of a cuid, nanoid, generation 1 or generation 2 child that keeps its stored output. |
| 160 | + it("keeps a RUN success of every other child id shape on deriveFromRun, also with a null output", () => { |
| 161 | + const shapes = { |
| 162 | + cuid: RunId.generate().id, |
| 163 | + nanoid: generateFriendlyId("run"), |
| 164 | + v1: generateRunOpsId(), |
| 165 | + v2: generateRunOpsIdV2("a"), |
| 166 | + }; |
| 167 | + for (const [shape, completedByTaskRunId] of Object.entries(shapes)) { |
| 168 | + for (const output of [{ inline: '{"v":1}' }, null]) { |
| 169 | + const record = mapStoreRecord( |
| 170 | + storeEntry( |
| 171 | + generateWaitpointId("RUN"), |
| 172 | + { type: "RUN", completedByTaskRunId }, |
| 173 | + storeCompletion({ output }) |
| 174 | + ) |
| 175 | + ); |
| 176 | + expect([shape, record.output]).toEqual([shape, { deriveFromRun: true }]); |
| 177 | + } |
| 178 | + } |
| 179 | + }); |
| 180 | + |
| 181 | + // Catches: a MemoryDB child's RUN error that does not keep its stored error output inline. |
| 182 | + it("carries a MemoryDB child's RUN ERROR inline", () => { |
| 183 | + const record = mapStoreRecord( |
| 184 | + storeEntry( |
| 185 | + generateWaitpointId("RUN"), |
| 186 | + { type: "RUN", completedByTaskRunId: generateRunOpsIdV2(MEMORYDB_SHARD_KEY) }, |
| 187 | + storeCompletion({ outputIsError: true, output: { inline: '{"type":"BUILT_IN_ERROR"}' } }) |
| 188 | + ) |
| 189 | + ); |
| 190 | + expect([record.outputIsError, record.output]).toEqual([ |
| 191 | + true, |
| 192 | + { inline: '{"type":"BUILT_IN_ERROR"}' }, |
| 193 | + ]); |
| 194 | + }); |
| 195 | + |
129 | 196 | it("preserves timestamps and type-specific metadata", () => { |
130 | 197 | const id = generateWaitpointId("DATETIME"); |
131 | 198 | const record = mapStoreRecord( |
|
0 commit comments