|
1 | 1 | import assert from "node:assert/strict"; |
2 | | -import { mkdtemp, readFile, writeFile } from "node:fs/promises"; |
| 2 | +import { mkdir, mkdtemp, readFile, writeFile } from "node:fs/promises"; |
3 | 3 | import os from "node:os"; |
4 | 4 | import path from "node:path"; |
5 | 5 | import test from "node:test"; |
@@ -278,3 +278,122 @@ test("sync-artur CLI blocks an unbackported destination commit", async () => { |
278 | 278 | ); |
279 | 279 | assert.equal(synchronized, false); |
280 | 280 | }); |
| 281 | + |
| 282 | +test("sync-artur CLI proceeds when drift is acknowledged in source main", async () => { |
| 283 | + const acknowledgedCommit = "6cf7474224eaeb97aca9e77a6a4bedb26045df01"; |
| 284 | + const sourceMain = await mkdtemp(path.join(os.tmpdir(), "artur-sync-ack-src-")); |
| 285 | + await mkdir(path.join(sourceMain, "scripts/release-notes"), { recursive: true }); |
| 286 | + await writeFile( |
| 287 | + path.join(sourceMain, "scripts/release-notes/acknowledged-drift.json"), |
| 288 | + JSON.stringify([{ commit: acknowledgedCommit, reason: "already present in source" }]), |
| 289 | + ); |
| 290 | + const output = await mkdtemp(path.join(os.tmpdir(), "artur-sync-ack-out-")); |
| 291 | + const approvalPath = path.join(output, "approved.json"); |
| 292 | + const resultPath = path.join(output, "result.json"); |
| 293 | + await writeFile( |
| 294 | + approvalPath, |
| 295 | + JSON.stringify({ |
| 296 | + version: "2026.08.0", |
| 297 | + previousSourceCommit: "a".repeat(40), |
| 298 | + targetSourceCommit: "b".repeat(40), |
| 299 | + notesPath: "docs/releases/artur/2026.08.0.md", |
| 300 | + releaseNotesPullRequest: 193, |
| 301 | + releaseNotesApprovedBy: ["zak"], |
| 302 | + }), |
| 303 | + ); |
| 304 | + const expected = { |
| 305 | + version: "2026.08.0", |
| 306 | + sourceCommit: "b".repeat(40), |
| 307 | + destinationBaseCommit: "c".repeat(40), |
| 308 | + notesPath: "docs/releases/artur/2026.08.0.md", |
| 309 | + added: [], |
| 310 | + modified: [], |
| 311 | + deleted: [], |
| 312 | + preserved: [], |
| 313 | + driftCommits: [], |
| 314 | + }; |
| 315 | + let synchronized = false; |
| 316 | + await runCli( |
| 317 | + [ |
| 318 | + "sync-artur", |
| 319 | + "--version", |
| 320 | + "2026.08.0", |
| 321 | + "--approval", |
| 322 | + approvalPath, |
| 323 | + "--source-main", |
| 324 | + sourceMain, |
| 325 | + "--source-snapshot", |
| 326 | + "/source-snapshot", |
| 327 | + "--destination", |
| 328 | + "/destination", |
| 329 | + "--previous-destination-ref", |
| 330 | + "baseline", |
| 331 | + "--output", |
| 332 | + resultPath, |
| 333 | + ], |
| 334 | + { |
| 335 | + findDrift: async () => [acknowledgedCommit], |
| 336 | + sync: async () => { |
| 337 | + synchronized = true; |
| 338 | + return expected; |
| 339 | + }, |
| 340 | + }, |
| 341 | + ); |
| 342 | + assert.equal(synchronized, true); |
| 343 | + const record = JSON.parse(await readFile(resultPath, "utf8")); |
| 344 | + assert.deepEqual(record.driftCommits, []); |
| 345 | + assert.deepEqual(record.acknowledgedDrift, [acknowledgedCommit]); |
| 346 | +}); |
| 347 | + |
| 348 | +test("sync-artur CLI still blocks drift that is not acknowledged", async () => { |
| 349 | + const sourceMain = await mkdtemp(path.join(os.tmpdir(), "artur-sync-ack-neg-")); |
| 350 | + await mkdir(path.join(sourceMain, "scripts/release-notes"), { recursive: true }); |
| 351 | + await writeFile( |
| 352 | + path.join(sourceMain, "scripts/release-notes/acknowledged-drift.json"), |
| 353 | + JSON.stringify([{ commit: "e".repeat(40), reason: "unrelated" }]), |
| 354 | + ); |
| 355 | + const output = await mkdtemp(path.join(os.tmpdir(), "artur-sync-ack-neg-out-")); |
| 356 | + const approvalPath = path.join(output, "approved.json"); |
| 357 | + await writeFile( |
| 358 | + approvalPath, |
| 359 | + JSON.stringify({ |
| 360 | + version: "2026.08.0", |
| 361 | + previousSourceCommit: "a".repeat(40), |
| 362 | + targetSourceCommit: "b".repeat(40), |
| 363 | + notesPath: "docs/releases/artur/2026.08.0.md", |
| 364 | + releaseNotesPullRequest: 193, |
| 365 | + releaseNotesApprovedBy: ["zak"], |
| 366 | + }), |
| 367 | + ); |
| 368 | + let synchronized = false; |
| 369 | + await assert.rejects( |
| 370 | + runCli( |
| 371 | + [ |
| 372 | + "sync-artur", |
| 373 | + "--version", |
| 374 | + "2026.08.0", |
| 375 | + "--approval", |
| 376 | + approvalPath, |
| 377 | + "--source-main", |
| 378 | + sourceMain, |
| 379 | + "--source-snapshot", |
| 380 | + "/source-snapshot", |
| 381 | + "--destination", |
| 382 | + "/destination", |
| 383 | + "--previous-destination-ref", |
| 384 | + "baseline", |
| 385 | + "--output", |
| 386 | + path.join(output, "result.json"), |
| 387 | + ], |
| 388 | + { |
| 389 | + findDrift: async () => ["f".repeat(40)], |
| 390 | + sync: async () => { |
| 391 | + synchronized = true; |
| 392 | + throw new Error("must not run"); |
| 393 | + }, |
| 394 | + }, |
| 395 | + ), |
| 396 | + /not backported.*ffff/i, |
| 397 | + ); |
| 398 | + assert.equal(synchronized, false); |
| 399 | +}); |
0 commit comments