|
1 | 1 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 2 | +import * as HostProcess from "@t3tools/shared/HostProcess"; |
2 | 3 | import * as Cause from "effect/Cause"; |
3 | 4 | import * as Clock from "effect/Clock"; |
4 | 5 | import * as Duration from "effect/Duration"; |
@@ -1149,76 +1150,80 @@ it.effect("GitVcsDriver forwards execute env to the VCS process", () => { |
1149 | 1150 | ); |
1150 | 1151 | }); |
1151 | 1152 |
|
1152 | | -it.effect("GitVcsDriver flushes checkpoint objects and refs to disk before publishing them", () => { |
1153 | | - const observedArgs: ReadonlyArray<string>[] = []; |
| 1153 | +it.effect.each([ |
| 1154 | + { platform: "linux", fsyncMethods: ["fsync"] }, |
| 1155 | + { platform: "darwin", fsyncMethods: ["fsync", "batch"] }, |
| 1156 | + { platform: "win32", fsyncMethods: ["fsync", "batch"] }, |
| 1157 | +] as const)( |
| 1158 | + "GitVcsDriver flushes checkpoint objects and refs to disk before publishing them on $platform", |
| 1159 | + ({ platform, fsyncMethods }) => { |
| 1160 | + const observedArgs: ReadonlyArray<string>[] = []; |
1154 | 1161 |
|
1155 | | - return Effect.gen(function* () { |
1156 | | - const driver = yield* GitVcsDriver.makeVcsDriverShape(); |
| 1162 | + return Effect.gen(function* () { |
| 1163 | + const driver = yield* GitVcsDriver.makeVcsDriverShape(); |
1157 | 1164 |
|
1158 | | - yield* driver.checkpoints.captureCheckpoint({ |
1159 | | - cwd: "/repo", |
1160 | | - checkpointRef: CheckpointRef.make("refs/t3/checkpoints/thread/turn/1"), |
1161 | | - }); |
| 1165 | + yield* driver.checkpoints.captureCheckpoint({ |
| 1166 | + cwd: "/repo", |
| 1167 | + checkpointRef: CheckpointRef.make("refs/t3/checkpoints/thread/turn/1"), |
| 1168 | + }); |
1162 | 1169 |
|
1163 | | - const writeCommands = ["add", "write-tree", "commit-tree", "update-ref"]; |
1164 | | - const writes = observedArgs.filter((args) => |
1165 | | - writeCommands.some((command) => args.includes(command)), |
1166 | | - ); |
1167 | | - assert.strictEqual(writes.length, 4); |
1168 | | - for (const args of writes) { |
1169 | | - const command = args.findIndex((arg) => writeCommands.includes(arg)); |
1170 | | - for (const setting of [ |
1171 | | - "core.fsync=objects,reference", |
1172 | | - "core.fsyncMethod=fsync", |
1173 | | - "core.fsyncMethod=batch", |
1174 | | - ]) { |
1175 | | - const index = args.indexOf(setting); |
1176 | | - assert.strictEqual(args[index - 1], "-c", args.join(" ")); |
1177 | | - assert.isBelow(index, command); |
1178 | | - } |
1179 | | - assert.isBelow( |
1180 | | - args.indexOf("core.fsyncMethod=fsync"), |
1181 | | - args.indexOf("core.fsyncMethod=batch"), |
| 1170 | + const writeCommands = ["add", "write-tree", "commit-tree", "update-ref"]; |
| 1171 | + const writes = observedArgs.filter((args) => |
| 1172 | + writeCommands.some((command) => args.includes(command)), |
1182 | 1173 | ); |
1183 | | - } |
1184 | | - assert.deepStrictEqual(observedArgs.at(-1), [ |
1185 | | - "-C", |
1186 | | - "/repo", |
1187 | | - "-c", |
1188 | | - "core.fsync=objects,reference", |
1189 | | - "-c", |
1190 | | - "core.fsyncMethod=fsync", |
1191 | | - "-c", |
1192 | | - "core.fsyncMethod=batch", |
1193 | | - "update-ref", |
1194 | | - "refs/t3/checkpoints/thread/turn/1", |
1195 | | - "commit0000", |
1196 | | - ]); |
1197 | | - }).pipe( |
1198 | | - Effect.provide( |
1199 | | - Layer.mergeAll( |
1200 | | - NodeServices.layer, |
1201 | | - Layer.mock(VcsProcess.VcsProcess)({ |
1202 | | - run: (input) => |
1203 | | - Effect.sync(() => { |
1204 | | - observedArgs.push(input.args); |
1205 | | - const stdout = input.args.includes("write-tree") |
1206 | | - ? "tree0000\n" |
1207 | | - : input.args.includes("commit-tree") |
1208 | | - ? "commit0000\n" |
1209 | | - : input.args.includes("--git-common-dir") |
1210 | | - ? ".git\n" |
1211 | | - : ""; |
1212 | | - return { |
1213 | | - exitCode: ChildProcessSpawner.ExitCode(0), |
1214 | | - stdout, |
1215 | | - stderr: "", |
1216 | | - stdoutTruncated: false, |
1217 | | - stderrTruncated: false, |
1218 | | - }; |
1219 | | - }), |
1220 | | - }), |
| 1174 | + assert.strictEqual(writes.length, 4); |
| 1175 | + for (const args of writes) { |
| 1176 | + const command = args.findIndex((arg) => writeCommands.includes(arg)); |
| 1177 | + assert.deepStrictEqual( |
| 1178 | + args.filter((arg) => arg.startsWith("core.fsyncMethod=")), |
| 1179 | + fsyncMethods.map((method) => `core.fsyncMethod=${method}`), |
| 1180 | + ); |
| 1181 | + for (const setting of [ |
| 1182 | + "core.fsync=objects,reference", |
| 1183 | + ...fsyncMethods.map((method) => `core.fsyncMethod=${method}`), |
| 1184 | + ]) { |
| 1185 | + const index = args.indexOf(setting); |
| 1186 | + assert.strictEqual(args[index - 1], "-c", args.join(" ")); |
| 1187 | + assert.isBelow(index, command); |
| 1188 | + } |
| 1189 | + } |
| 1190 | + assert.deepStrictEqual(observedArgs.at(-1), [ |
| 1191 | + "-C", |
| 1192 | + "/repo", |
| 1193 | + "-c", |
| 1194 | + "core.fsync=objects,reference", |
| 1195 | + ...fsyncMethods.flatMap((method) => ["-c", `core.fsyncMethod=${method}`]), |
| 1196 | + "update-ref", |
| 1197 | + "refs/t3/checkpoints/thread/turn/1", |
| 1198 | + "commit0000", |
| 1199 | + ]); |
| 1200 | + }).pipe( |
| 1201 | + Effect.provideService(HostProcess.Platform, platform), |
| 1202 | + Effect.provide( |
| 1203 | + Layer.mergeAll( |
| 1204 | + NodeServices.layer, |
| 1205 | + Layer.mock(VcsProcess.VcsProcess)({ |
| 1206 | + run: (input) => |
| 1207 | + Effect.sync(() => { |
| 1208 | + observedArgs.push(input.args); |
| 1209 | + const stdout = input.args.includes("write-tree") |
| 1210 | + ? "tree0000\n" |
| 1211 | + : input.args.includes("commit-tree") |
| 1212 | + ? "commit0000\n" |
| 1213 | + : input.args.includes("--git-common-dir") |
| 1214 | + ? ".git\n" |
| 1215 | + : ""; |
| 1216 | + return { |
| 1217 | + exitCode: ChildProcessSpawner.ExitCode(0), |
| 1218 | + stdout, |
| 1219 | + stderr: "", |
| 1220 | + stdoutTruncated: false, |
| 1221 | + stderrTruncated: false, |
| 1222 | + }; |
| 1223 | + }), |
| 1224 | + }), |
| 1225 | + ), |
1221 | 1226 | ), |
1222 | | - ), |
1223 | | - ); |
1224 | | -}); |
| 1227 | + ); |
| 1228 | + }, |
| 1229 | +); |
0 commit comments