- Reject unknown flags with exit 2 and never write on --dry-run, even in a TTY - Treat files already matching the new content as up to date after an interrupted update - Remove unmodified orphan files from older versions, keep and report modified ones and shared paths - Degrade malformed manifests instead of blocking installs; readIfExists only maps ENOENT/ENOTDIR to null - Block downgrades from older CLIs (semver), honor uninstall --scope, dedupe targets, fix next-step output and table width - Deeper package verification, LF normalization for .mjs, MIT LICENSE
98 lines
4 KiB
TypeScript
98 lines
4 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { test } from "node:test";
|
|
import { extractBlock, hasBlock, removeBlock, upsertBlock } from "../src/marker.ts";
|
|
|
|
const M = "designpaca";
|
|
|
|
test("빈 문서에 블록을 넣는다", () => {
|
|
const out = upsertBlock("", M, "본문");
|
|
assert.ok(hasBlock(out, M));
|
|
assert.equal(extractBlock(out, M), "본문");
|
|
});
|
|
|
|
test("기존 문서 뒤에 붙이고 원문을 보존한다", () => {
|
|
const doc = "# 내 지침\n\n건드리지 마라.\n";
|
|
const out = upsertBlock(doc, M, "우리 블록");
|
|
assert.ok(out.startsWith("# 내 지침"));
|
|
assert.ok(out.includes("건드리지 마라."));
|
|
assert.equal(extractBlock(out, M), "우리 블록");
|
|
});
|
|
|
|
test("두 번째 호출은 블록 내용만 교체한다", () => {
|
|
const first = upsertBlock("# 문서\n\n앞부분\n", M, "v1");
|
|
const second = upsertBlock(first, M, "v2");
|
|
assert.equal(extractBlock(second, M), "v2");
|
|
assert.ok(!second.includes("v1"));
|
|
assert.ok(second.includes("앞부분"));
|
|
// 블록이 두 개로 늘어나면 안 된다
|
|
assert.equal(second.split("designpaca:start").length - 1, 1);
|
|
});
|
|
|
|
test("블록 뒤에 사용자가 쓴 내용도 보존한다", () => {
|
|
const doc = upsertBlock("앞\n", M, "블록") + "\n뒤에 쓴 내용\n";
|
|
const out = upsertBlock(doc, M, "새 블록");
|
|
assert.ok(out.includes("앞"));
|
|
assert.ok(out.includes("뒤에 쓴 내용"));
|
|
assert.equal(extractBlock(out, M), "새 블록");
|
|
});
|
|
|
|
test("제거하면 우리 블록만 사라진다", () => {
|
|
const doc = upsertBlock("# 문서\n\n내용\n", M, "블록");
|
|
const out = removeBlock(doc, M);
|
|
assert.ok(!hasBlock(out, M));
|
|
assert.ok(out.includes("# 문서"));
|
|
assert.ok(out.includes("내용"));
|
|
});
|
|
|
|
test("블록이 없는 문서를 제거해도 그대로다", () => {
|
|
const doc = "# 문서\n";
|
|
assert.equal(removeBlock(doc, M), doc);
|
|
});
|
|
|
|
test("본문이 마커 문자열을 언급해도 줄 전체가 마커인 블록만 인식한다", () => {
|
|
const doc =
|
|
"# 규칙\n\ndesignpaca 는 `<!-- designpaca:start -->` 블록을 쓴다.\n\n## 내 규칙\n\n지우지 마라.\n";
|
|
const once = upsertBlock(doc, M, "v1");
|
|
assert.ok(once.includes("## 내 규칙"));
|
|
const twice = upsertBlock(once, M, "v2");
|
|
assert.ok(twice.includes("## 내 규칙") && twice.includes("지우지 마라."));
|
|
assert.equal(extractBlock(twice, M), "v2");
|
|
const removed = removeBlock(twice, M);
|
|
assert.equal(removed, doc);
|
|
});
|
|
|
|
test("start/end 줄이 여러 개거나 짝이 맞지 않으면 쓰지 않고 오류로 멈춘다", () => {
|
|
const twoBlocks = upsertBlock("앞\n", M, "a") + "\n" + upsertBlock("", M, "b");
|
|
assert.throws(() => upsertBlock(twoBlocks, M, "c"), /start 2개/);
|
|
assert.throws(() => removeBlock(twoBlocks, M));
|
|
assert.equal(extractBlock(twoBlocks, M), null);
|
|
|
|
const endOnly = "<!-- designpaca:end -->\n본문\n";
|
|
assert.throws(() => upsertBlock(endOnly, M, "x"));
|
|
const reversed = "<!-- designpaca:end -->\n<!-- designpaca:start -->\n";
|
|
assert.throws(() => upsertBlock(reversed, M, "x"));
|
|
});
|
|
|
|
test("제거는 블록 밖의 연속 빈 줄을 정규화하지 않는다", () => {
|
|
const doc = "```\na\n\n\n\nb\n```\n";
|
|
const out = removeBlock(upsertBlock(doc, M, "블록"), M);
|
|
assert.equal(out, doc);
|
|
});
|
|
|
|
test("문서 중간 블록을 빼면 블록 앞뒤 구분 빈 줄 하나만 걷힌다", () => {
|
|
const doc = "A\n\n<!-- designpaca:start -->\nx\n<!-- designpaca:end -->\n\nB\n";
|
|
assert.equal(removeBlock(doc, M), "A\n\nB\n");
|
|
});
|
|
|
|
test("CRLF 문서에는 CRLF 블록을 주입하고 제거하면 원문으로 돌아온다", () => {
|
|
const doc = "# 내 지침\r\n\r\n건드리지 마라.\r\n";
|
|
const out = upsertBlock(doc, M, "첫 줄\n둘째 줄");
|
|
assert.ok(!/(^|[^\r])\n/.test(out), "LF 단독 줄바꿈이 섞이면 안 된다");
|
|
assert.equal(extractBlock(out, M), "첫 줄\r\n둘째 줄");
|
|
assert.equal(removeBlock(out, M), doc);
|
|
});
|
|
|
|
test("LF 문서에는 LF 블록을 주입한다", () => {
|
|
const out = upsertBlock("# 지침\n", M, "본문");
|
|
assert.ok(!out.includes("\r"));
|
|
});
|