OXYGENHUB
◆ main oxygen-vscode / test / settle.test.mjs
2.9 KiB · last changed Withdraw tags, verify the transparency log, shallow clones, keep a side or both sides of a conflict, commit and amend by paths, merge remote bookmarks (closes #11) 6 days ago source blame history raw
1
// Settling conflicts with oxy's one-command answers: the choices offered for
2
// a binary file's or subrepo pin's conflict, the candidates removed, and the
3
// words for a withdrawal and for oxy resolve --both.
4
5
import { test } from "node:test";
6
import assert from "node:assert/strict";
7
import { candidatesOf, isReplaceConflict, keptBothSummary, replaceChoices, withdrawQuestion } from "../out/settle.mjs";
8
9
const replace = { kind: "replace", path: "img/logo.png", changes: ["4189430d989317c02de6b3c12f1c433f", "9c0c8ef6b612ef990bc72f812ff732cc"], resolved: false };
10
11
test("a binary file's conflict offers each side, then the working copy's version", () => {
12
  assert.equal(isReplaceConflict(replace), true);
13
  assert.equal(isReplaceConflict({ kind: "text", path: "a.txt" }), false);
14
  const choices = replaceChoices(replace, false, new Map([["9c0c8ef6b612ef990bc72f812ff732cc", "New logo"]]));
15
  assert.deepEqual(
16
    choices.map((c) => [c.action, c.change, c.label, c.description]),
17
    [
18
      ["keep-side", "4189430d989317c02de6b3c12f1c433f", "$(check) Keep side 1", "4189430d"],
19
      ["keep-side", "9c0c8ef6b612ef990bc72f812ff732cc", "$(check) Keep side 2", '9c0c8ef6 "New logo"'],
20
      ["keep-current", undefined, "$(edit) Keep what the working copy holds now", "img/logo.png"],
21
    ],
22
  );
23
});
24
25
test("a subrepo pin's conflict keeps the pin the subrepo holds, or opens it to move it", () => {
26
  const choices = replaceChoices({ ...replace, path: "libs/lib" }, true);
27
  assert.deepEqual(choices.map((c) => c.action), ["keep-current", "open-subrepo"]);
28
  assert.match(choices[0].label, /Keep the pin the subrepo holds now/);
29
});
30
31
test("only the file's own candidates are removed", () => {
32
  assert.deepEqual(candidatesOf("logo.png", ["logo.png", "logo.png.oxy-conflict-2", "logo.png.oxy-conflict-3", "other.png.oxy-conflict-2", "logo.png.bak"]), ["logo.png.oxy-conflict-2", "logo.png.oxy-conflict-3"]);
33
  assert.deepEqual(candidatesOf("a", []), []);
34
});
35
36
test("withdrawing a tag says it is signed, kept and logged", () => {
37
  const q = withdrawQuestion("v1.2");
38
  assert.equal(q.message, "Withdraw tag v1.2?");
39
  assert.match(q.detail, /signed/);
40
  assert.match(q.detail, /kept/);
41
  assert.match(q.detail, /logged/);
42
  assert.match(q.detail, /never be used again/);
43
});
44
45
test("oxy resolve --both's result in one line", () => {
46
  assert.deepEqual(keptBothSummary({ kept: [{ path: "a.txt", conflicts: [1, 2] }, { path: "b.txt", conflicts: [1] }], left: [] }), {
47
    message: "kept every side of 3 conflicts in 2 files",
48
    settled: true,
49
    warn: false,
50
  });
51
  const mixed = keptBothSummary({ kept: [{ path: "a.txt", conflicts: [1] }], left: [{ path: "a.txt", conflict: 2, why: "both sides changed these lines; edit the markers" }] });
52
  assert.equal(mixed.settled, true);
53
  assert.equal(mixed.warn, true);
54
  assert.match(mixed.message, /a\.txt conflict 2 keeps its markers: both sides changed these lines/);
55
  assert.deepEqual(keptBothSummary({ kept: [], left: [] }).settled, false);
56
});