ceulen 0.5.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +317 -12
- package/README.md +87 -91
- package/extensions/lib/advisor-marker.ts +33 -0
- package/extensions/lib/panel.ts +25 -2
- package/extensions/lib/rate.ts +24 -0
- package/extensions/lib/registry.ts +93 -7
- package/extensions/lib/tools.ts +47 -0
- package/extensions/lib/usage-store.ts +33 -0
- package/extensions/modules/advisor/commands/advisor.ts +244 -0
- package/extensions/modules/advisor/configPanel.ts +194 -0
- package/extensions/modules/advisor/index.ts +217 -0
- package/extensions/modules/advisor/lib/config.ts +248 -0
- package/extensions/modules/advisor/lib/emission-guard.ts +153 -0
- package/extensions/modules/advisor/lib/isolated-model.ts +160 -0
- package/extensions/modules/advisor/lib/model-picker.ts +47 -0
- package/extensions/modules/advisor/lib/watcher.ts +286 -0
- package/extensions/modules/advisor/test/compliance.test.ts +125 -0
- package/extensions/modules/advisor/test/config.test.ts +202 -0
- package/extensions/modules/advisor/test/configPanel.test.ts +223 -0
- package/extensions/modules/advisor/test/emission-guard.test.ts +201 -0
- package/extensions/modules/advisor/test/isolated-model.test.ts +311 -0
- package/extensions/modules/advisor/test/model-picker.test.ts +32 -0
- package/extensions/modules/advisor/test/module.test.ts +586 -0
- package/extensions/modules/advisor/test/watcher.test.ts +478 -0
- package/extensions/modules/classifier/configPanel.ts +104 -0
- package/extensions/modules/classifier/index.ts +297 -0
- package/extensions/modules/classifier/lib/settings.ts +95 -0
- package/extensions/modules/classifier/test/classifier.test.ts +475 -0
- package/extensions/modules/composer/index.ts +152 -3
- package/extensions/modules/composer/lib/footer.ts +119 -0
- package/extensions/modules/composer/lib/shapes.ts +265 -26
- package/extensions/modules/composer/test/editor.test.ts +1 -1
- package/extensions/modules/composer/test/footer.test.ts +96 -0
- package/extensions/modules/composer/test/module.test.ts +113 -11
- package/extensions/modules/composer/test/screen.test.ts +29 -1
- package/extensions/modules/composer/test/shapes.test.ts +224 -8
- package/extensions/modules/config/defaultTools.ts +96 -0
- package/extensions/modules/config/index.ts +147 -7
- package/extensions/modules/config/piSettings.ts +254 -69
- package/extensions/modules/config/test/defaultTools.test.ts +122 -0
- package/extensions/modules/config/test/menu.test.ts +64 -0
- package/extensions/modules/config/test/panel.test.ts +38 -23
- package/extensions/modules/config/test/piSettings.test.ts +130 -3
- package/extensions/modules/config/test/renderTools.test.ts +71 -0
- package/extensions/modules/config/test/tools.test.ts +146 -0
- package/extensions/modules/fff/index.ts +2094 -0
- package/extensions/modules/fff/lib/query.ts +129 -0
- package/extensions/modules/fff/test/index.test.ts +607 -0
- package/extensions/modules/fff/test/query.test.ts +71 -0
- package/extensions/modules/munin/configPanel.ts +105 -0
- package/extensions/modules/munin/index.ts +641 -0
- package/extensions/modules/munin/lib/helpers.ts +471 -0
- package/extensions/modules/munin/lib/retry.ts +20 -0
- package/extensions/modules/munin/lib/sdk.ts +218 -0
- package/extensions/modules/munin/test/config.test.ts +168 -0
- package/extensions/modules/munin/test/configPanel.test.ts +161 -0
- package/extensions/modules/munin/test/extension.test.ts +224 -0
- package/extensions/modules/munin/test/helpers.test.ts +523 -0
- package/extensions/modules/munin/test/retry.test.ts +145 -0
- package/extensions/modules/munin/test/stale-protocol.test.ts +554 -0
- package/extensions/modules/plan/configPanel.ts +152 -0
- package/extensions/modules/plan/index.ts +917 -0
- package/extensions/modules/plan/lib/plan-tools.ts +72 -0
- package/extensions/modules/plan/lib/prompt.ts +65 -0
- package/extensions/modules/plan/lib/settings.ts +166 -0
- package/extensions/modules/plan/lib/shell-gate.ts +200 -0
- package/extensions/modules/plan/test/configPanel.test.ts +96 -0
- package/extensions/modules/plan/test/harness.ts +133 -0
- package/extensions/modules/plan/test/module.test.ts +305 -0
- package/extensions/modules/plan/test/settings.test.ts +114 -0
- package/extensions/modules/plan/test/shell-gate.test.ts +103 -0
- package/extensions/modules/ponytail/index.ts +23 -73
- package/extensions/modules/ponytail/lib/config.ts +1 -6
- package/extensions/modules/ponytail/test/extension.test.ts +1 -85
- package/extensions/modules/repair/configPanel.ts +96 -0
- package/extensions/modules/repair/index.ts +414 -0
- package/extensions/modules/repair/lib/auto-bg.ts +333 -0
- package/extensions/modules/repair/lib/edit-repair.ts +155 -0
- package/extensions/modules/repair/lib/editor.ts +251 -0
- package/extensions/modules/repair/lib/guards.ts +34 -0
- package/extensions/modules/repair/lib/input-repair.ts +324 -0
- package/extensions/modules/repair/lib/patch.ts +481 -0
- package/extensions/modules/repair/lib/settings.ts +114 -0
- package/extensions/modules/repair/test/auto-bg.test.ts +405 -0
- package/extensions/modules/repair/test/edit-repair.test.ts +224 -0
- package/extensions/modules/repair/test/editor.test.ts +141 -0
- package/extensions/modules/repair/test/guards.test.ts +64 -0
- package/extensions/modules/repair/test/input-repair.test.ts +231 -0
- package/extensions/modules/repair/test/patch.test.ts +563 -0
- package/extensions/modules/repair/test/settings.test.ts +167 -0
- package/extensions/modules/repair/test/wrapper.test.ts +210 -0
- package/extensions/modules/router/commands/commands.ts +4 -0
- package/extensions/modules/router/lib/client.ts +61 -0
- package/extensions/modules/router/lib/provider.ts +34 -13
- package/extensions/modules/router/lib/systemone.ts +152 -0
- package/extensions/modules/router/test/unit.test.ts +179 -0
- package/extensions/modules/rtk/findFallback.js +68 -0
- package/extensions/modules/rtk/index.ts +248 -0
- package/extensions/modules/rtk/safe-rewrite.js +74 -0
- package/extensions/modules/rtk/test/findFallback.test.js +66 -0
- package/extensions/modules/rtk/test/index.test.js +131 -0
- package/extensions/modules/rtk/test/safe-rewrite.test.js +96 -0
- package/extensions/modules/rtk/version-gate.js +34 -0
- package/extensions/modules/serena/index.ts +629 -0
- package/extensions/modules/serena/lib/detect.ts +73 -0
- package/extensions/modules/serena/lib/env.ts +76 -0
- package/extensions/modules/serena/lib/guidance.ts +26 -0
- package/extensions/modules/serena/lib/normalize.ts +27 -0
- package/extensions/modules/serena/lib/symbol-key.ts +20 -0
- package/extensions/modules/serena/lib/truncate.ts +20 -0
- package/extensions/modules/serena/test/env.test.ts +122 -0
- package/extensions/modules/serena/test/index.test.ts +347 -0
- package/extensions/modules/serena/test/worker.test.ts +562 -0
- package/extensions/modules/serena/worker.ts +858 -0
- package/extensions/modules/steering/configPanel.ts +122 -0
- package/extensions/modules/steering/index.ts +616 -0
- package/extensions/modules/steering/lib/anchor.ts +175 -0
- package/extensions/modules/steering/lib/errors.ts +253 -0
- package/extensions/modules/steering/lib/family.ts +33 -0
- package/extensions/modules/steering/lib/guidance.ts +172 -0
- package/extensions/modules/steering/lib/history.ts +170 -0
- package/extensions/modules/steering/lib/settings.ts +127 -0
- package/extensions/modules/steering/test/anchor-regressions.test.ts +93 -0
- package/extensions/modules/steering/test/anchor-wiring.test.ts +99 -0
- package/extensions/modules/steering/test/anchor.test.ts +160 -0
- package/extensions/modules/steering/test/cache-stats.test.ts +43 -0
- package/extensions/modules/steering/test/errors.test.ts +309 -0
- package/extensions/modules/steering/test/family.test.ts +43 -0
- package/extensions/modules/steering/test/guidance.test.ts +357 -0
- package/extensions/modules/steering/test/harness.ts +93 -0
- package/extensions/modules/steering/test/history.test.ts +118 -0
- package/extensions/modules/steering/test/settings.test.ts +182 -0
- package/extensions/modules/steering/test/status.test.ts +71 -0
- package/extensions/modules/steering/test/toolCall.test.ts +99 -0
- package/extensions/modules/subagent/agents/planner.md +14 -0
- package/extensions/modules/subagent/agents/reviewer.md +42 -0
- package/extensions/modules/subagent/agents/scout.md +47 -0
- package/extensions/modules/subagent/agents/tester.md +12 -0
- package/extensions/modules/subagent/agents/worker.md +18 -0
- package/extensions/modules/subagent/configPanel.ts +219 -0
- package/extensions/modules/subagent/index.ts +2451 -0
- package/extensions/modules/subagent/lib/agents.ts +408 -0
- package/extensions/modules/subagent/lib/background.ts +383 -0
- package/extensions/modules/subagent/lib/herdr.ts +1019 -0
- package/extensions/modules/subagent/lib/history.ts +126 -0
- package/extensions/modules/subagent/lib/model.ts +156 -0
- package/extensions/modules/subagent/lib/render.ts +335 -0
- package/extensions/modules/subagent/lib/result.ts +110 -0
- package/extensions/modules/subagent/lib/roles.ts +296 -0
- package/extensions/modules/subagent/lib/routing.ts +223 -0
- package/extensions/modules/subagent/lib/runner.ts +559 -0
- package/extensions/modules/subagent/lib/schema.ts +21 -0
- package/extensions/modules/subagent/lib/security.ts +752 -0
- package/extensions/modules/subagent/lib/settings.ts +159 -0
- package/extensions/modules/subagent/lib/thread-viewer.ts +319 -0
- package/extensions/modules/subagent/lib/threads.ts +135 -0
- package/extensions/modules/subagent/lib/types.ts +18 -0
- package/extensions/modules/subagent/lib/widget.ts +475 -0
- package/extensions/modules/subagent/test/configPanel.test.ts +132 -0
- package/extensions/modules/subagent/test/herdr-advisor.test.ts +40 -0
- package/extensions/modules/subagent/test/routing.test.ts +350 -0
- package/extensions/modules/subagent/test/widget.test.ts +208 -0
- package/extensions/modules/usage/index.ts +59 -16
- package/extensions/modules/usage/test/genrate.test.ts +70 -0
- package/extensions/modules/usage/test/parsers.test.ts +13 -0
- package/extensions/modules/ux/UPSTREAM +24 -0
- package/extensions/modules/ux/index.ts +393 -0
- package/extensions/modules/ux/lib/audit.ts +562 -0
- package/extensions/modules/ux/lib/config.ts +136 -0
- package/extensions/modules/ux/lib/instructions.ts +77 -0
- package/extensions/modules/ux/test/audit.test.ts +756 -0
- package/extensions/modules/ux/test/extension.test.ts +394 -0
- package/extensions/modules/ux/test/instructions.test.ts +19 -0
- package/extensions/modules/web/configPanel.ts +193 -0
- package/extensions/modules/web/index.ts +978 -0
- package/extensions/modules/web/lib/agy.ts +209 -0
- package/extensions/modules/web/lib/brave.ts +42 -0
- package/extensions/modules/web/lib/cdp.ts +686 -0
- package/extensions/modules/web/lib/chatapi.ts +101 -0
- package/extensions/modules/web/lib/chatgpt.ts +796 -0
- package/extensions/modules/web/lib/chrome.ts +328 -0
- package/extensions/modules/web/lib/config.ts +136 -0
- package/extensions/modules/web/lib/content.ts +99 -0
- package/extensions/modules/web/lib/crawl4ai.ts +172 -0
- package/extensions/modules/web/lib/extract.ts +235 -0
- package/extensions/modules/web/lib/firecrawl.ts +56 -0
- package/extensions/modules/web/lib/format.ts +197 -0
- package/extensions/modules/web/lib/gemini-auth.ts +286 -0
- package/extensions/modules/web/lib/gemini-dr.ts +338 -0
- package/extensions/modules/web/lib/gemini.ts +551 -0
- package/extensions/modules/web/lib/imageapi.ts +559 -0
- package/extensions/modules/web/lib/retry.ts +71 -0
- package/extensions/modules/web/lib/search.ts +237 -0
- package/extensions/modules/web/lib/searxng.ts +69 -0
- package/extensions/modules/web/lib/settings.ts +148 -0
- package/extensions/modules/web/scripts/cdp-smoke.ts +77 -0
- package/extensions/modules/web/scripts/gemini-smoke.ts +107 -0
- package/extensions/modules/web/test/agy.test.ts +383 -0
- package/extensions/modules/web/test/cdp.test.ts +717 -0
- package/extensions/modules/web/test/chat.test.ts +171 -0
- package/extensions/modules/web/test/chatgpt.test.ts +633 -0
- package/extensions/modules/web/test/chrome.test.ts +282 -0
- package/extensions/modules/web/test/config.test.ts +218 -0
- package/extensions/modules/web/test/configPanel.test.ts +132 -0
- package/extensions/modules/web/test/crawl.test.ts +134 -0
- package/extensions/modules/web/test/crawl4ai.test.ts +105 -0
- package/extensions/modules/web/test/extension.test.ts +118 -0
- package/extensions/modules/web/test/extract.test.ts +436 -0
- package/extensions/modules/web/test/fixtures/dr-confirm.bin +12 -0
- package/extensions/modules/web/test/fixtures/dr-plan.bin +20 -0
- package/extensions/modules/web/test/fixtures/interaction.html +31 -0
- package/extensions/modules/web/test/format.test.ts +230 -0
- package/extensions/modules/web/test/gemini-auth.test.ts +465 -0
- package/extensions/modules/web/test/gemini-dr.test.ts +249 -0
- package/extensions/modules/web/test/gemini.test.ts +472 -0
- package/extensions/modules/web/test/hook.test.ts +101 -0
- package/extensions/modules/web/test/image.test.ts +1089 -0
- package/extensions/modules/web/test/retry.test.ts +119 -0
- package/extensions/modules/web/test/screenshot.test.ts +109 -0
- package/extensions/modules/web/test/search.test.ts +210 -0
- package/extensions/modules/web/test/settings.test.ts +165 -0
- package/extensions/modules/web/test/skill.test.ts +72 -0
- package/extensions/modules/web/types.d.ts +3 -0
- package/extensions/modules/web/vendor/package.json +1 -0
- package/extensions/modules/web/vendor/readability/LICENSE.md +13 -0
- package/extensions/modules/web/vendor/readability/Readability-readerable.js +123 -0
- package/extensions/modules/web/vendor/readability/Readability.js +2787 -0
- package/extensions/modules/web/vendor/readability/index.d.ts +64 -0
- package/extensions/modules/web/vendor/readability/index.js +9 -0
- package/extensions/modules/web/vendor/turndown/LICENSE +21 -0
- package/extensions/modules/web/vendor/turndown/turndown.cjs.js +784 -0
- package/extensions/modules/web/vendor/turndown-plugin-gfm/LICENSE +21 -0
- package/extensions/modules/web/vendor/turndown-plugin-gfm/turndown-plugin-gfm.cjs.js +163 -0
- package/extensions/modules/zai/configPanel.ts +151 -0
- package/extensions/modules/zai/index.ts +186 -0
- package/extensions/modules/zai/lib/anthropic.ts +159 -0
- package/extensions/modules/zai/lib/settings.ts +198 -0
- package/extensions/modules/zai/lib/signing.ts +718 -0
- package/extensions/modules/zai/lib/throttle.ts +198 -0
- package/extensions/modules/zai/test/anthropic.test.ts +132 -0
- package/extensions/modules/zai/test/configPanel.test.ts +207 -0
- package/extensions/modules/zai/test/extension.test.ts +249 -0
- package/extensions/modules/zai/test/settings.test.ts +183 -0
- package/extensions/modules/zai/test/signing-wiring.test.ts +108 -0
- package/extensions/modules/zai/test/signing.test.ts +345 -0
- package/extensions/modules/zai/test/throttle.test.ts +329 -0
- package/package.json +19 -4
- package/scripts/validate-themes.mjs +75 -0
- package/skills/munin/SKILL.md +117 -0
- package/skills/ux-capture/SKILL.md +202 -0
- package/skills/ux-design/SKILL.md +279 -0
- package/skills/ux-presets/SKILL.md +484 -0
- package/skills/ux-routing/SKILL.md +46 -0
- package/skills/web/SKILL.md +153 -0
- package/themes/alabaster.json +93 -0
- package/themes/amethyst.json +96 -0
- package/themes/anthracite.json +93 -0
- package/themes/basalt.json +91 -0
- package/themes/birch.json +95 -0
- package/themes/catppuccin-mocha.json +91 -0
- package/themes/dark-abyss.json +91 -0
- package/themes/dark-arctic.json +104 -0
- package/themes/dark-aurora.json +95 -0
- package/themes/dark-catppuccin.json +107 -0
- package/themes/dark-cavern.json +91 -0
- package/themes/dark-celestial.json +106 -0
- package/themes/dark-copper.json +95 -0
- package/themes/dark-cosmos.json +90 -0
- package/themes/dark-cyberpunk.json +102 -0
- package/themes/dark-dracula.json +98 -0
- package/themes/dark-eclipse.json +91 -0
- package/themes/dark-ember.json +95 -0
- package/themes/dark-equinox.json +90 -0
- package/themes/dark-forest.json +96 -0
- package/themes/dark-github.json +105 -0
- package/themes/dark-gruvbox.json +112 -0
- package/themes/dark-lavender.json +95 -0
- package/themes/dark-lunar.json +89 -0
- package/themes/dark-midnight.json +95 -0
- package/themes/dark-monochrome.json +94 -0
- package/themes/dark-monokai.json +98 -0
- package/themes/dark-nebula.json +90 -0
- package/themes/dark-neon-noir.json +100 -0
- package/themes/dark-nord.json +98 -0
- package/themes/dark-ocean.json +101 -0
- package/themes/dark-one.json +100 -0
- package/themes/dark-poimandres.json +115 -0
- package/themes/dark-rainforest.json +91 -0
- package/themes/dark-reef.json +91 -0
- package/themes/dark-retro.json +92 -0
- package/themes/dark-rose-pine.json +96 -0
- package/themes/dark-sakura.json +95 -0
- package/themes/dark-slate.json +95 -0
- package/themes/dark-solarized.json +97 -0
- package/themes/dark-solstice.json +90 -0
- package/themes/dark-starfall.json +91 -0
- package/themes/dark-sunset.json +99 -0
- package/themes/dark-swamp.json +90 -0
- package/themes/dark-synthwave.json +103 -0
- package/themes/dark-taiga.json +91 -0
- package/themes/dark-terminal.json +95 -0
- package/themes/dark-tokyo-night.json +101 -0
- package/themes/dark-tundra.json +91 -0
- package/themes/dark-twilight.json +91 -0
- package/themes/dark-volcanic.json +91 -0
- package/themes/dark.json +80 -0
- package/themes/graphite.json +92 -0
- package/themes/light-arctic.json +107 -0
- package/themes/light-aurora-day.json +91 -0
- package/themes/light-canyon.json +91 -0
- package/themes/light-catppuccin.json +106 -0
- package/themes/light-cirrus.json +90 -0
- package/themes/light-coral.json +95 -0
- package/themes/light-cyberpunk.json +96 -0
- package/themes/light-dawn.json +90 -0
- package/themes/light-dunes.json +91 -0
- package/themes/light-eucalyptus.json +95 -0
- package/themes/light-forest.json +100 -0
- package/themes/light-frost.json +95 -0
- package/themes/light-github.json +115 -0
- package/themes/light-glacier.json +91 -0
- package/themes/light-gruvbox.json +108 -0
- package/themes/light-haze.json +90 -0
- package/themes/light-honeycomb.json +95 -0
- package/themes/light-lagoon.json +91 -0
- package/themes/light-lavender.json +95 -0
- package/themes/light-meadow.json +91 -0
- package/themes/light-mint.json +95 -0
- package/themes/light-monochrome.json +101 -0
- package/themes/light-ocean.json +99 -0
- package/themes/light-one.json +99 -0
- package/themes/light-opal.json +91 -0
- package/themes/light-orchard.json +91 -0
- package/themes/light-paper.json +95 -0
- package/themes/light-poimandres.json +115 -0
- package/themes/light-prism.json +90 -0
- package/themes/light-retro.json +98 -0
- package/themes/light-sand.json +95 -0
- package/themes/light-savanna.json +91 -0
- package/themes/light-solarized.json +102 -0
- package/themes/light-soleil.json +90 -0
- package/themes/light-sunset.json +99 -0
- package/themes/light-synthwave.json +98 -0
- package/themes/light-tokyo-night.json +111 -0
- package/themes/light-wetland.json +91 -0
- package/themes/light-zenith.json +89 -0
- package/themes/light.json +80 -0
- package/themes/limestone.json +94 -0
- package/themes/mahogany.json +97 -0
- package/themes/marble.json +93 -0
- package/themes/mirage.json +79 -0
- package/themes/obsidian.json +91 -0
- package/themes/onyx.json +91 -0
- package/themes/pearl.json +93 -0
- package/themes/porcelain.json +91 -0
- package/themes/quartz.json +96 -0
- package/themes/sandstone.json +95 -0
- package/themes/titanium.json +90 -0
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
// ponytail: vendored from @bacnh85/pi-model-tools 0.9.5 —
|
|
2
|
+
// extensions/test/unit/apply-patch.test.ts (import path adapted; the lib file
|
|
3
|
+
// is lib/patch.ts in ceulen).
|
|
4
|
+
import assert from "node:assert";
|
|
5
|
+
import { describe, it } from "node:test";
|
|
6
|
+
import { mkdtemp, rm, writeFile, readFile } from "node:fs/promises";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import {
|
|
10
|
+
parsePatch,
|
|
11
|
+
seekSequence,
|
|
12
|
+
applyPatchToFiles,
|
|
13
|
+
PatchParseError,
|
|
14
|
+
} from "../lib/patch.js";
|
|
15
|
+
|
|
16
|
+
describe("parsePatch", () => {
|
|
17
|
+
it("parses an update op with context/removed/added", () => {
|
|
18
|
+
const p = parsePatch(
|
|
19
|
+
"*** Begin Patch\n*** Update File: a.ts\n@@ ctx\n-old\n+new\n*** End Patch",
|
|
20
|
+
);
|
|
21
|
+
assert.strictEqual(p.ops.length, 1);
|
|
22
|
+
assert.strictEqual(p.ops[0].kind, "update");
|
|
23
|
+
assert.strictEqual(p.ops[0].path, "a.ts");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("parses an add op", () => {
|
|
27
|
+
const p = parsePatch("*** Add File: new.txt\n+line 1\n+line 2\n*** End Patch");
|
|
28
|
+
assert.strictEqual(p.ops[0].kind, "add");
|
|
29
|
+
assert.strictEqual(p.ops[0].path, "new.txt");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("parses a delete op", () => {
|
|
33
|
+
const p = parsePatch("*** Delete File: old.txt\n*** End Patch");
|
|
34
|
+
assert.strictEqual(p.ops[0].kind, "delete");
|
|
35
|
+
assert.strictEqual(p.ops[0].path, "old.txt");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("parses a rename (update with →)", () => {
|
|
39
|
+
const p = parsePatch("*** Update File: a.ts → b.ts\n@@ ctx\n-x\n+y\n*** End Patch");
|
|
40
|
+
assert.strictEqual(p.ops[0].movePath, "b.ts");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("parses a rename (-> ascii)", () => {
|
|
44
|
+
const p = parsePatch("*** Update File: a.ts -> b.ts\n*** End Patch");
|
|
45
|
+
assert.strictEqual(p.ops[0].movePath, "b.ts");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("throws on payload outside a file section", () => {
|
|
49
|
+
assert.throws(() => parsePatch("+foo\n*** End Patch"), PatchParseError);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("throws on no file ops", () => {
|
|
53
|
+
assert.throws(() => parsePatch("*** Begin Patch\n*** End Patch"), PatchParseError);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("throws on '-' in an Add File section", () => {
|
|
57
|
+
assert.throws(
|
|
58
|
+
() => parsePatch("*** Add File: x\n+a\n-b\n*** End Patch"),
|
|
59
|
+
PatchParseError,
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("treats a bare context line (no leading space) as context", () => {
|
|
64
|
+
// DeepSeek/gpt-oss frequently omit the leading-space context marker.
|
|
65
|
+
const p = parsePatch(
|
|
66
|
+
"*** Update File: a.ts\n@@ alpha\n}\n-x\n+y\n*** End Patch",
|
|
67
|
+
);
|
|
68
|
+
// The '}' is context, not an error.
|
|
69
|
+
assert.strictEqual(p.ops[0].kind, "update");
|
|
70
|
+
assert.doesNotThrow(() => parsePatch("*** Update File: a.ts\n}\n-x\n+y\n*** End Patch"));
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe("seekSequence", () => {
|
|
75
|
+
it("exact match", () => {
|
|
76
|
+
const r = seekSequence(["foo", "bar", "baz"], ["bar", "baz"]);
|
|
77
|
+
assert.strictEqual(r.count, 1);
|
|
78
|
+
assert.strictEqual(r.firstIndex, 1);
|
|
79
|
+
assert.strictEqual(r.exact, true);
|
|
80
|
+
});
|
|
81
|
+
it("rstrip match when trailing whitespace differs", () => {
|
|
82
|
+
const r = seekSequence(["foo ", "bar\t"], ["foo", "bar"]);
|
|
83
|
+
assert.strictEqual(r.count, 1);
|
|
84
|
+
assert.strictEqual(r.exact, false);
|
|
85
|
+
});
|
|
86
|
+
it("trim match when leading whitespace differs", () => {
|
|
87
|
+
const r = seekSequence([" foo", "\tbar"], ["foo", "bar"]);
|
|
88
|
+
assert.strictEqual(r.count, 1);
|
|
89
|
+
assert.strictEqual(r.exact, false);
|
|
90
|
+
});
|
|
91
|
+
it("unicode-normalize match for smart quotes/dashes", () => {
|
|
92
|
+
// file has a smart dash, pattern has ASCII hyphen
|
|
93
|
+
const r = seekSequence(["cost \u2013 low"], ["cost - low"]);
|
|
94
|
+
assert.strictEqual(r.count, 1);
|
|
95
|
+
assert.strictEqual(r.exact, false);
|
|
96
|
+
});
|
|
97
|
+
it("returns 0 when not found", () => {
|
|
98
|
+
const r = seekSequence(["a", "b"], ["z"]);
|
|
99
|
+
assert.strictEqual(r.count, 0);
|
|
100
|
+
assert.strictEqual(r.firstIndex, -1);
|
|
101
|
+
});
|
|
102
|
+
it("returns 0 when pattern longer than lines", () => {
|
|
103
|
+
const r = seekSequence(["a"], ["a", "b", "c"]);
|
|
104
|
+
assert.strictEqual(r.count, 0);
|
|
105
|
+
});
|
|
106
|
+
it("counts multiple matches", () => {
|
|
107
|
+
const r = seekSequence(["x", "x", "x"], ["x"]);
|
|
108
|
+
assert.strictEqual(r.count, 3);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// ── End-to-end apply against a real temp dir ──
|
|
113
|
+
|
|
114
|
+
async function withTempDir<T>(fn: (dir: string) => Promise<T>): Promise<T> {
|
|
115
|
+
const dir = await mkdtemp(join(tmpdir(), "apply-patch-"));
|
|
116
|
+
try {
|
|
117
|
+
return await fn(dir);
|
|
118
|
+
} finally {
|
|
119
|
+
await rm(dir, { recursive: true, force: true });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
describe("applyPatchToFiles — update", () => {
|
|
124
|
+
it("applies a single update hunk", async () => {
|
|
125
|
+
await withTempDir(async (dir) => {
|
|
126
|
+
const file = join(dir, "a.ts");
|
|
127
|
+
await writeFile(file, "alpha\nbeta\ngamma\n", "utf-8");
|
|
128
|
+
// anchor on the unchanged line above the change (alpha stays)
|
|
129
|
+
const parsed = parsePatch(
|
|
130
|
+
"*** Update File: a.ts\n@@ alpha\n-beta\n+BETA\n*** End Patch",
|
|
131
|
+
);
|
|
132
|
+
const res = await applyPatchToFiles(parsed, dir);
|
|
133
|
+
const out = (await readFile(file, "utf-8")).toString();
|
|
134
|
+
assert.strictEqual(out, "alpha\nBETA\ngamma\n");
|
|
135
|
+
assert.strictEqual(res.exact, true);
|
|
136
|
+
assert.match(res.diff, /BETA/);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("applies multiple hunks in one file", async () => {
|
|
141
|
+
await withTempDir(async (dir) => {
|
|
142
|
+
const file = join(dir, "a.ts");
|
|
143
|
+
await writeFile(file, "one\nX\ntwo\nX\nthree\n", "utf-8");
|
|
144
|
+
const parsed = parsePatch(
|
|
145
|
+
"*** Update File: a.ts\n@@ one\n-X\n+1\n@@ two\n-X\n+2\n*** End Patch",
|
|
146
|
+
);
|
|
147
|
+
await applyPatchToFiles(parsed, dir);
|
|
148
|
+
const out = (await readFile(file, "utf-8")).toString();
|
|
149
|
+
assert.strictEqual(out, "one\n1\ntwo\n2\nthree\n");
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("errors when context is not found", async () => {
|
|
154
|
+
await withTempDir(async (dir) => {
|
|
155
|
+
const file = join(dir, "a.ts");
|
|
156
|
+
await writeFile(file, "alpha\nbeta\n", "utf-8");
|
|
157
|
+
// 0.8.1: a bogus @@ label + a UNIQUE removed payload now applies via the
|
|
158
|
+
// anchor-demotion fallback (see label-anchor tests below). This stays an
|
|
159
|
+
// error only because the payload matches nothing either.
|
|
160
|
+
const parsed = parsePatch(
|
|
161
|
+
"*** Update File: a.ts\n@@ nope\n-zeta\n+ZETA\n*** End Patch",
|
|
162
|
+
);
|
|
163
|
+
await assert.rejects(() => applyPatchToFiles(parsed, dir), /not found/);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("errors when context is ambiguous", async () => {
|
|
168
|
+
await withTempDir(async (dir) => {
|
|
169
|
+
const file = join(dir, "a.ts");
|
|
170
|
+
await writeFile(file, "dup\nA\ndup\nA\n", "utf-8");
|
|
171
|
+
// anchor ["dup","A"] genuinely appears twice.
|
|
172
|
+
const parsed = parsePatch(
|
|
173
|
+
"*** Update File: a.ts\n@@ dup\n-A\n+AA\n*** End Patch",
|
|
174
|
+
);
|
|
175
|
+
await assert.rejects(() => applyPatchToFiles(parsed, dir), /ambiguous/);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("preserves BOM and CRLF", async () => {
|
|
180
|
+
await withTempDir(async (dir) => {
|
|
181
|
+
const file = join(dir, "a.ts");
|
|
182
|
+
await writeFile(file, "\uFEFFalpha\r\nbeta\r\n", "utf-8");
|
|
183
|
+
// anchor on the unchanged line above (alpha stays)
|
|
184
|
+
const parsed = parsePatch(
|
|
185
|
+
"*** Update File: a.ts\n@@ alpha\n-beta\n+BETA\n*** End Patch",
|
|
186
|
+
);
|
|
187
|
+
await applyPatchToFiles(parsed, dir);
|
|
188
|
+
const out = (await readFile(file, "utf-8")).toString();
|
|
189
|
+
assert.strictEqual(out, "\uFEFFalpha\r\nBETA\r\n");
|
|
190
|
+
assert.ok(out.startsWith("\uFEFF"), "BOM preserved");
|
|
191
|
+
assert.ok(out.includes("\r\n"), "CRLF preserved");
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("collapses @@ anchor repeated as context line", async () => {
|
|
196
|
+
// Model writes `@@ alpha / alpha` treating @@ as a locator header.
|
|
197
|
+
// The duplicate context line is collapsed so only one "alpha" is matched.
|
|
198
|
+
await withTempDir(async (dir) => {
|
|
199
|
+
const file = join(dir, "a.ts");
|
|
200
|
+
await writeFile(file, "alpha\nbeta\n", "utf-8");
|
|
201
|
+
const parsed = parsePatch(
|
|
202
|
+
"*** Update File: a.ts\n@@ alpha\n alpha\n-beta\n+BETA\n*** End Patch",
|
|
203
|
+
);
|
|
204
|
+
await applyPatchToFiles(parsed, dir);
|
|
205
|
+
const out = (await readFile(file, "utf-8")).toString();
|
|
206
|
+
assert.strictEqual(out, "alpha\nBETA\n");
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("collapses @@ anchor repeated as removed line", async () => {
|
|
211
|
+
// Anchor text equals the first removed line (e.g. @@ line1 / -line1).
|
|
212
|
+
await withTempDir(async (dir) => {
|
|
213
|
+
const file = join(dir, "a.ts");
|
|
214
|
+
await writeFile(file, "X\nfoo\n", "utf-8");
|
|
215
|
+
const parsed = parsePatch(
|
|
216
|
+
"*** Update File: a.ts\n@@ X\n-X\n+Y\n*** End Patch",
|
|
217
|
+
);
|
|
218
|
+
await applyPatchToFiles(parsed, dir);
|
|
219
|
+
const out = (await readFile(file, "utf-8")).toString();
|
|
220
|
+
assert.strictEqual(out, "Y\nfoo\n");
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
describe("applyPatchToFiles — add / delete / multi-file", () => {
|
|
226
|
+
it("adds a new file", async () => {
|
|
227
|
+
await withTempDir(async (dir) => {
|
|
228
|
+
const parsed = parsePatch(
|
|
229
|
+
"*** Add File: new.txt\n+hello\n+world\n*** End Patch",
|
|
230
|
+
);
|
|
231
|
+
await applyPatchToFiles(parsed, dir);
|
|
232
|
+
const out = (await readFile(join(dir, "new.txt"), "utf-8")).toString();
|
|
233
|
+
assert.strictEqual(out, "hello\nworld");
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it("deletes a file", async () => {
|
|
238
|
+
await withTempDir(async (dir) => {
|
|
239
|
+
const file = join(dir, "old.txt");
|
|
240
|
+
await writeFile(file, "bye\n", "utf-8");
|
|
241
|
+
const parsed = parsePatch("*** Delete File: old.txt\n*** End Patch");
|
|
242
|
+
await applyPatchToFiles(parsed, dir);
|
|
243
|
+
await assert.rejects(() => readFile(file, "utf-8"));
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it("applies a multi-file patch", async () => {
|
|
248
|
+
await withTempDir(async (dir) => {
|
|
249
|
+
await writeFile(join(dir, "a.ts"), "x\n1\n", "utf-8");
|
|
250
|
+
await writeFile(join(dir, "b.ts"), "y\n2\n", "utf-8");
|
|
251
|
+
const parsed = parsePatch(
|
|
252
|
+
"*** Update File: a.ts\n@@ x\n-1\n+A\n*** Update File: b.ts\n@@ y\n-2\n+B\n*** End Patch",
|
|
253
|
+
);
|
|
254
|
+
const res = await applyPatchToFiles(parsed, dir);
|
|
255
|
+
assert.strictEqual(res.files.length, 2);
|
|
256
|
+
assert.strictEqual((await readFile(join(dir, "a.ts"), "utf-8")).toString(), "x\nA\n");
|
|
257
|
+
assert.strictEqual((await readFile(join(dir, "b.ts"), "utf-8")).toString(), "y\nB\n");
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("renames a file (update →)", async () => {
|
|
262
|
+
await withTempDir(async (dir) => {
|
|
263
|
+
await writeFile(join(dir, "old.ts"), "ctx\n1\n", "utf-8");
|
|
264
|
+
const parsed = parsePatch(
|
|
265
|
+
"*** Update File: old.ts → new.ts\n@@ ctx\n-1\n+2\n*** End Patch",
|
|
266
|
+
);
|
|
267
|
+
await applyPatchToFiles(parsed, dir);
|
|
268
|
+
assert.strictEqual((await readFile(join(dir, "new.ts"), "utf-8")).toString(), "ctx\n2\n");
|
|
269
|
+
await assert.rejects(() => readFile(join(dir, "old.ts"), "utf-8"));
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("honors an absolute path outside cwd (like pi built-in tools)", async () => {
|
|
274
|
+
await withTempDir(async (dir) => {
|
|
275
|
+
// An absolute path that is NOT under cwd must still work (pi's resolveToCwd
|
|
276
|
+
// allows absolute paths anywhere; apply_patch must match that).
|
|
277
|
+
const outside = join(tmpdir(), "apply-patch-outside-" + Date.now() + ".ts");
|
|
278
|
+
try {
|
|
279
|
+
await writeFile(outside, "ctx\n1\n", "utf-8");
|
|
280
|
+
const parsed = parsePatch(`*** Add File: ${outside}\n+x\n*** End Patch`);
|
|
281
|
+
await assert.rejects(() => applyPatchToFiles(parsed, dir), /already exists/);
|
|
282
|
+
} finally {
|
|
283
|
+
await rm(outside, { force: true });
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
// Regression tests for the bare-blank-line parser hazard and EOF-append path.
|
|
290
|
+
describe("applyPatchToFiles — markdown / blank-line / EOF regression", () => {
|
|
291
|
+
it("bare blank line inside a +block is an added empty line, not context", async () => {
|
|
292
|
+
// Reproduces the failure shape from ISSUE-apply_patch.md: a +block where
|
|
293
|
+
// the model emits the blank SEPARATORS between paragraphs WITHOUT the
|
|
294
|
+
// '+' prefix (bare blank lines). Before the fix each bare blank became a
|
|
295
|
+
// context line, splitting the added block into two hunks; the second
|
|
296
|
+
// sub-hunk landed on matchBlock [""] → wrong spot / "context not found".
|
|
297
|
+
await withTempDir(async (dir) => {
|
|
298
|
+
const file = join(dir, "plan.md");
|
|
299
|
+
const orig = "Some intro.\n\naccount. Re-import by dropping new Excel files.\n";
|
|
300
|
+
await writeFile(file, orig, "utf-8");
|
|
301
|
+
const patch = [
|
|
302
|
+
"*** Begin Patch",
|
|
303
|
+
"*** Update File: plan.md",
|
|
304
|
+
"@@ account. Re-import by dropping new Excel files.",
|
|
305
|
+
"+## STATUS: EXECUTED",
|
|
306
|
+
"", // ← bare blank separator (no '+' prefix)
|
|
307
|
+
"+All steps complete.",
|
|
308
|
+
"+Self-check: 19/19.",
|
|
309
|
+
"", // ← another bare blank separator
|
|
310
|
+
"+Build: clean.",
|
|
311
|
+
"*** End Patch",
|
|
312
|
+
].join("\n");
|
|
313
|
+
await applyPatchToFiles(parsePatch(patch), dir);
|
|
314
|
+
const out = (await readFile(file, "utf-8")).toString();
|
|
315
|
+
assert.strictEqual(
|
|
316
|
+
out,
|
|
317
|
+
"Some intro.\n\naccount. Re-import by dropping new Excel files.\n" +
|
|
318
|
+
"## STATUS: EXECUTED\n\nAll steps complete.\nSelf-check: 19/19.\n\nBuild: clean.\n",
|
|
319
|
+
);
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it("Update with only +lines (no @@ anchor) appends at EOF", async () => {
|
|
324
|
+
await withTempDir(async (dir) => {
|
|
325
|
+
const file = join(dir, "a.txt");
|
|
326
|
+
await writeFile(file, "one\ntwo\nthree\n", "utf-8");
|
|
327
|
+
const parsed = parsePatch("*** Update File: a.txt\n+four\n+five\n*** End Patch");
|
|
328
|
+
await applyPatchToFiles(parsed, dir);
|
|
329
|
+
const out = (await readFile(file, "utf-8")).toString();
|
|
330
|
+
assert.strictEqual(out, "one\ntwo\nthree\nfour\nfive\n");
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it("unresolvable anchor throws a message containing the anchor + nearest region", async () => {
|
|
335
|
+
await withTempDir(async (dir) => {
|
|
336
|
+
const file = join(dir, "a.md");
|
|
337
|
+
await writeFile(file, "alpha\nbeta\ngamma\n", "utf-8");
|
|
338
|
+
const parsed = parsePatch("*** Update File: a.md\n@@ nope-no-such-line\n-zeta\n+ZETA\n*** End Patch");
|
|
339
|
+
await assert.rejects(
|
|
340
|
+
() => applyPatchToFiles(parsed, dir),
|
|
341
|
+
(err: Error) => {
|
|
342
|
+
assert.match(err.message, /Hunk context not found/);
|
|
343
|
+
assert.match(err.message, /nope-no-such-line/);
|
|
344
|
+
assert.match(err.message, /Nearest matching region/i);
|
|
345
|
+
return true;
|
|
346
|
+
},
|
|
347
|
+
);
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it("ambiguous anchor error names the first matching line numbers", async () => {
|
|
352
|
+
await withTempDir(async (dir) => {
|
|
353
|
+
const file = join(dir, "a.txt");
|
|
354
|
+
await writeFile(file, "dup\nA\ndup\nB\ndup\n", "utf-8");
|
|
355
|
+
// Pure addition after a non-unique anchor → matchBlock = ["dup"] → 3 matches.
|
|
356
|
+
const parsed = parsePatch("*** Update File: a.txt\n@@ dup\n+y\n*** End Patch");
|
|
357
|
+
await assert.rejects(
|
|
358
|
+
() => applyPatchToFiles(parsed, dir),
|
|
359
|
+
/ambiguous \(3 matches\)[\s\S]*Found at lines: 1, 3, 5/,
|
|
360
|
+
);
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it("applies the exact failing payload twice in succession (no stale state)", async () => {
|
|
365
|
+
// Pins the fix AND the no-stale-buffer guarantee: the second apply must
|
|
366
|
+
// operate on the file state left by the first, not a stale snapshot.
|
|
367
|
+
await withTempDir(async (dir) => {
|
|
368
|
+
const file = join(dir, "plan.md");
|
|
369
|
+
const orig = "Some intro.\n\naccount. Re-import by dropping new Excel files.\n";
|
|
370
|
+
await writeFile(file, orig, "utf-8");
|
|
371
|
+
const patch = [
|
|
372
|
+
"*** Begin Patch",
|
|
373
|
+
"*** Update File: plan.md",
|
|
374
|
+
"@@ account. Re-import by dropping new Excel files.",
|
|
375
|
+
"+## STATUS: EXECUTED",
|
|
376
|
+
"+",
|
|
377
|
+
"+Self-check: 19/19.",
|
|
378
|
+
"*** End Patch",
|
|
379
|
+
].join("\n");
|
|
380
|
+
// First apply: adds the status block.
|
|
381
|
+
await applyPatchToFiles(parsePatch(patch), dir);
|
|
382
|
+
let out = (await readFile(file, "utf-8")).toString();
|
|
383
|
+
assert.ok(out.includes("## STATUS: EXECUTED"), "first apply should add the block");
|
|
384
|
+
// Second apply with a NEW anchor on the just-added line proves the tool
|
|
385
|
+
// re-reads current bytes (no stale buffer) rather than matching the
|
|
386
|
+
// original anchor a second time (which would now be ambiguous/missing).
|
|
387
|
+
const patch2 = [
|
|
388
|
+
"*** Begin Patch",
|
|
389
|
+
"*** Update File: plan.md",
|
|
390
|
+
"@@ Self-check: 19/19.",
|
|
391
|
+
"+",
|
|
392
|
+
"+E2E: 11/11.",
|
|
393
|
+
"*** End Patch",
|
|
394
|
+
].join("\n");
|
|
395
|
+
await applyPatchToFiles(parsePatch(patch2), dir);
|
|
396
|
+
out = (await readFile(file, "utf-8")).toString();
|
|
397
|
+
assert.ok(out.includes("E2E: 11/11."), "second apply must extend the first");
|
|
398
|
+
assert.strictEqual(
|
|
399
|
+
out,
|
|
400
|
+
"Some intro.\n\naccount. Re-import by dropping new Excel files.\n" +
|
|
401
|
+
"## STATUS: EXECUTED\n\nSelf-check: 19/19.\n\nE2E: 11/11.\n",
|
|
402
|
+
);
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
// Regression tests for 0.8.1: bare-@@ hunk separation + @@-label anchor demotion.
|
|
408
|
+
describe("applyPatchToFiles — bare @@ separators and label anchors", () => {
|
|
409
|
+
it("bare @@ separates consecutive context-free hunks (scattered single-line replacements)", async () => {
|
|
410
|
+
await withTempDir(async (dir) => {
|
|
411
|
+
const file = join(dir, "tong-luan.md");
|
|
412
|
+
await writeFile(file, "vy-1\nmid-a\nt7-1\nmid-b\nch6-1\n", "utf-8");
|
|
413
|
+
const patch = [
|
|
414
|
+
"*** Begin Patch",
|
|
415
|
+
"*** Update File: tong-luan.md",
|
|
416
|
+
"@@",
|
|
417
|
+
"-vy-1",
|
|
418
|
+
"+vy-2",
|
|
419
|
+
"@@",
|
|
420
|
+
"-t7-1",
|
|
421
|
+
"+t7-2",
|
|
422
|
+
"@@",
|
|
423
|
+
"-ch6-1",
|
|
424
|
+
"+ch6-2",
|
|
425
|
+
"*** End Patch",
|
|
426
|
+
].join("\n");
|
|
427
|
+
const result = await applyPatchToFiles(parsePatch(patch), dir);
|
|
428
|
+
assert.strictEqual(result.exact, true);
|
|
429
|
+
assert.strictEqual(await readFile(file, "utf-8"), "vy-2\nmid-a\nt7-2\nmid-b\nch6-2\n");
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it("bare @@ drops the previous hunk's trailing context instead of gluing it to the next hunk", async () => {
|
|
434
|
+
await withTempDir(async (dir) => {
|
|
435
|
+
const file = join(dir, "writer.md");
|
|
436
|
+
await writeFile(
|
|
437
|
+
file,
|
|
438
|
+
["## Mandates", "", "### 1", "forbidden-1", "required-1", "xung-ho", "### 2", "no-euph", "mandatory", "sensation", ""].join("\n"),
|
|
439
|
+
"utf-8",
|
|
440
|
+
);
|
|
441
|
+
const patch = [
|
|
442
|
+
"*** Begin Patch",
|
|
443
|
+
"*** Update File: writer.md",
|
|
444
|
+
"@@",
|
|
445
|
+
"## Mandates",
|
|
446
|
+
"+### 0 new",
|
|
447
|
+
"### 1",
|
|
448
|
+
"forbidden-1",
|
|
449
|
+
"required-1",
|
|
450
|
+
"@@",
|
|
451
|
+
"### 2",
|
|
452
|
+
"no-euph",
|
|
453
|
+
"mandatory",
|
|
454
|
+
"+new-bullet",
|
|
455
|
+
"*** End Patch",
|
|
456
|
+
].join("\n");
|
|
457
|
+
await applyPatchToFiles(parsePatch(patch), dir);
|
|
458
|
+
assert.strictEqual(
|
|
459
|
+
await readFile(file, "utf-8"),
|
|
460
|
+
["## Mandates", "### 0 new", "", "### 1", "forbidden-1", "required-1", "xung-ho", "### 2", "no-euph", "mandatory", "new-bullet", "sensation", ""].join("\n"),
|
|
461
|
+
);
|
|
462
|
+
});
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
it("a @@ label that is not a file line is demoted to a hint when the removed payload is unique", async () => {
|
|
466
|
+
await withTempDir(async (dir) => {
|
|
467
|
+
const file = join(dir, "chuong.html");
|
|
468
|
+
await writeFile(file, "<p>intro</p>\n<p>old paragraph body</p>\n<p>outro</p>\n", "utf-8");
|
|
469
|
+
const patch = [
|
|
470
|
+
"*** Begin Patch",
|
|
471
|
+
"*** Update File: chuong.html",
|
|
472
|
+
"@@ Tay Dung run, dat len eo Lan (paraphrase label)",
|
|
473
|
+
"-<p>old paragraph body</p>",
|
|
474
|
+
"+<p>new paragraph body</p>",
|
|
475
|
+
"*** End Patch",
|
|
476
|
+
].join("\n");
|
|
477
|
+
const result = await applyPatchToFiles(parsePatch(patch), dir);
|
|
478
|
+
assert.strictEqual(result.exact, false); // fuzzy: anchor was ignored
|
|
479
|
+
assert.strictEqual(await readFile(file, "utf-8"), "<p>intro</p>\n<p>new paragraph body</p>\n<p>outro</p>\n");
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it("a @@ label with an ambiguous removed payload still errors", async () => {
|
|
484
|
+
await withTempDir(async (dir) => {
|
|
485
|
+
const file = join(dir, "a.md");
|
|
486
|
+
await writeFile(file, "dup\nmid\ndup\n", "utf-8");
|
|
487
|
+
const patch = [
|
|
488
|
+
"*** Begin Patch",
|
|
489
|
+
"*** Update File: a.md",
|
|
490
|
+
"@@ invented label",
|
|
491
|
+
"-dup",
|
|
492
|
+
"+DUP",
|
|
493
|
+
"*** End Patch",
|
|
494
|
+
].join("\n");
|
|
495
|
+
await assert.rejects(() => applyPatchToFiles(parsePatch(patch), dir), /Hunk context not found/);
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
it("bare @@ at section start, doubled, or trailing stays a no-op", async () => {
|
|
500
|
+
await withTempDir(async (dir) => {
|
|
501
|
+
const file = join(dir, "a.txt");
|
|
502
|
+
await writeFile(file, "one\ntwo\n", "utf-8");
|
|
503
|
+
const patch = [
|
|
504
|
+
"*** Begin Patch",
|
|
505
|
+
"*** Update File: a.txt",
|
|
506
|
+
"@@",
|
|
507
|
+
"@@",
|
|
508
|
+
"-one",
|
|
509
|
+
"+ONE",
|
|
510
|
+
"@@",
|
|
511
|
+
"*** End Patch",
|
|
512
|
+
].join("\n");
|
|
513
|
+
await applyPatchToFiles(parsePatch(patch), dir);
|
|
514
|
+
assert.strictEqual(await readFile(file, "utf-8"), "ONE\ntwo\n");
|
|
515
|
+
});
|
|
516
|
+
});
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
describe("applyPatchToFiles — bare @@ edge cases", () => {
|
|
520
|
+
it("bare @@ after an unclaimed leading context keeps that context (no silent drop)", async () => {
|
|
521
|
+
// `@@ anchor` then a bare `@@` then payload: the leading context was never
|
|
522
|
+
// claimed by a payload hunk, so the bare @@ must NOT discard it — dropping
|
|
523
|
+
// it made [X] ambiguous where [anchor, X] was unique.
|
|
524
|
+
await withTempDir(async (dir) => {
|
|
525
|
+
const file = join(dir, "a.md");
|
|
526
|
+
await writeFile(file, "anchor\nX\nfill\nX\n", "utf-8");
|
|
527
|
+
const patch = [
|
|
528
|
+
"*** Begin Patch",
|
|
529
|
+
"*** Update File: a.md",
|
|
530
|
+
"@@ anchor",
|
|
531
|
+
"@@",
|
|
532
|
+
"-X",
|
|
533
|
+
"+Y",
|
|
534
|
+
"*** End Patch",
|
|
535
|
+
].join("\n");
|
|
536
|
+
await applyPatchToFiles(parsePatch(patch), dir);
|
|
537
|
+
assert.strictEqual(await readFile(file, "utf-8"), "anchor\nY\nfill\nX\n");
|
|
538
|
+
});
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
it("two hunks demoted to the same target error as overlapping instead of silently dropping one", async () => {
|
|
542
|
+
// Different failing labels, identical removed payload: both demote to the
|
|
543
|
+
// same span; before the overlap guard the reverse-order application
|
|
544
|
+
// silently discarded one hunk's added lines.
|
|
545
|
+
await withTempDir(async (dir) => {
|
|
546
|
+
const file = join(dir, "a.md");
|
|
547
|
+
await writeFile(file, "intro\nX\noutro\n", "utf-8");
|
|
548
|
+
const patch = [
|
|
549
|
+
"*** Begin Patch",
|
|
550
|
+
"*** Update File: a.md",
|
|
551
|
+
"@@ label-a",
|
|
552
|
+
"-X",
|
|
553
|
+
"+A",
|
|
554
|
+
"@@ label-b",
|
|
555
|
+
"-X",
|
|
556
|
+
"+B",
|
|
557
|
+
"*** End Patch",
|
|
558
|
+
].join("\n");
|
|
559
|
+
await assert.rejects(() => applyPatchToFiles(parsePatch(patch), dir), /overlap/i);
|
|
560
|
+
assert.strictEqual(await readFile(file, "utf-8"), "intro\nX\noutro\n");
|
|
561
|
+
});
|
|
562
|
+
});
|
|
563
|
+
});
|