OXYGENHUB
◆ main oxygen-vscode / test / commitbox.test.mjs
2.5 KiB · last changed Commit box: amend mode, previous messages, signing indicator, and a warning before committing conflict markers; 0.9.0 1 month ago source blame history raw
1
import { test } from "node:test";
2
import assert from "node:assert/strict";
3
import { MessageHistory, conflictMarkerLines, parseIdentityShow, placeholder, signingLabel } from "../out/commitbox.mjs";
4
5
const SIGNED = `# identity Andy McCall <[email protected]>
6
  key      f1add784
7
  created  2026-09-26 18:12:11Z (2 days ago)
8
  secret   * available
9
  signing  every change (core.sign = change)
10
`;
11
12
test("signing state from oxy identity show", () => {
13
  const s = parseIdentityShow(SIGNED);
14
  assert.deepEqual(s, { who: "Andy McCall <[email protected]>", secret: true, mode: "change" });
15
  assert.equal(signingLabel(s), "✔ signed as Andy McCall");
16
  const sealed = parseIdentityShow(SIGNED.replace("every change (core.sign = change)", "at push via seals (core.sign = seal)"));
17
  assert.equal(signingLabel(sealed), "◈ sealed at push as Andy McCall");
18
  const keyless = parseIdentityShow(SIGNED.replace("* available", "x not found in the key directory"));
19
  assert.match(signingLabel(keyless), /unsigned: the key for Andy McCall is missing/);
20
  assert.equal(parseIdentityShow("No identity configured; run `oxy identity create`."), null);
21
  assert.match(signingLabel(null), /unsigned: no identity/);
22
  assert.equal(signingLabel(undefined), "", "not known yet");
23
});
24
25
test("placeholder follows the mode", () => {
26
  assert.equal(placeholder({ amend: false, resolution: false, signing: "✔ signed as A" }), "Message (Ctrl+Enter to commit) · ✔ signed as A");
27
  assert.match(placeholder({ amend: true, resolution: false, signing: "" }), /^Amend the last change.*Ctrl\+Enter to amend\)$/);
28
  assert.match(placeholder({ amend: false, resolution: true, signing: "" }), /^Describe the resolution/);
29
});
30
31
test("message history is newest first, unique and bounded", () => {
32
  const h = new MessageHistory(["b", "", "a"]);
33
  h.add("  c  ");
34
  h.add("a");
35
  h.add("");
36
  assert.deepEqual(h.entries, ["a", "c", "b"]);
37
  for (let i = 0; i < 40; i++) {
38
    h.add(`m${i}`);
39
  }
40
  assert.equal(h.entries.length, MessageHistory.LIMIT);
41
  assert.equal(h.entries[0], "m39");
42
});
43
44
test("conflict markers: Oxygen's and Git's, not look-alikes", () => {
45
  const oxy = ['a', '<<<<<<< oxy conflict 1 of 1, side 1 of 2: change k7m2p9 "x"', "one", '======= oxy conflict 1 of 1, side 2 of 2: change q3x8w1 "y"', "two", ">>>>>>> oxy conflict 1 of 1 end", ""].join("\n");
46
  assert.deepEqual(conflictMarkerLines(oxy), [2, 6]);
47
  assert.deepEqual(conflictMarkerLines("x\n<<<<<<< HEAD\ny\n=======\nz\n>>>>>>> feature\r\n"), [2, 6]);
48
  assert.deepEqual(conflictMarkerLines("<<<<<<<< eight\n  <<<<<<< indented\na <<<<<<< b\n"), []);
49
});