@srobroek/pi-worktrunk-merge-policy 0.7.3 → 0.7.4
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
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## worktrunk [0.7.4](https://github.com/srobroek/harness-plugins/compare/worktrunk--v0.7.3...worktrunk--v0.7.4) (2026-11-29)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* ship trunk-dev and worktrunk to OMP, bound the provisioning hook, fail the Claude agent guard closed ([0411610](https://github.com/srobroek/harness-plugins/commit/041161067223ab93ba3ce802d60ef4c64e91b0e0)), closes [#170](https://github.com/srobroek/harness-plugins/issues/170)
|
|
6
|
+
|
|
1
7
|
## worktrunk [0.7.3](https://github.com/srobroek/harness-plugins/compare/worktrunk--v0.7.2...worktrunk--v0.7.3) (2026-11-25)
|
|
2
8
|
|
|
3
9
|
### Bug Fixes
|
package/extensions/worktrunk.js
CHANGED
|
@@ -2215,7 +2215,10 @@ import { dirname, isAbsolute, join, resolve as resolve2 } from "path";
|
|
|
2215
2215
|
var APPROVALS_FIX = "wt config approvals add --yes";
|
|
2216
2216
|
var MERGE_FIX = "wt merge --no-squash --no-ff";
|
|
2217
2217
|
var WORKTREE_FIX = "wt switch -y --create --no-cd --base <base-commit> --format json <branch>";
|
|
2218
|
-
var
|
|
2218
|
+
var PROVISIONING_COPY_TIMEOUT_SECONDS = 600;
|
|
2219
|
+
var PROVISIONING_COPY_WRAPPER = "use POSIX (); $t=shift; $p=fork; defined $p or do{print STDERR q{copy-ignored: fork failed: },$!,$/; exit 125}; if(!$p){setpgrp(0,0); exec @ARGV; print STDERR q{copy-ignored: cannot run }.$ARGV[0].q{: }.$!.$/; POSIX::_exit(127)} $SIG{ALRM}=sub{kill q{TERM},-$p; select undef,undef,undef,2; kill q{KILL},-$p; print STDERR q{copy-ignored: timed out after }.$t.q{s; killed its process group}.$/; exit 124}; alarm $t; waitpid $p,0; exit($?&127 ? 128+($?&127) : $?>>8)";
|
|
2220
|
+
var provisioningCopyCommand = (seconds) => `perl -e '${PROVISIONING_COPY_WRAPPER}' ${seconds} wt step copy-ignored --require-include`;
|
|
2221
|
+
var PROVISIONING_COPY_COMMAND = provisioningCopyCommand(PROVISIONING_COPY_TIMEOUT_SECONDS);
|
|
2219
2222
|
var PROVISIONING_UV_COMMAND = "uv sync";
|
|
2220
2223
|
var PROVISIONING_FIX = "rerun with --apply; project hooks require `wt config approvals add` before the next worktree";
|
|
2221
2224
|
var DEFAULT_TIMEOUT_MS = 60000;
|
package/package.json
CHANGED
|
@@ -22,7 +22,25 @@ APPROVALS_FIX = "wt config approvals add --yes"
|
|
|
22
22
|
MERGE_FIX = "wt merge --no-squash --no-ff"
|
|
23
23
|
WORKTREE_FIX = "wt switch -y --create --no-cd --base <base-commit> --format json <branch>"
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
# Seconds before the provisioning copy is killed, so a stuck walk cannot block lane setup.
|
|
26
|
+
PROVISIONING_COPY_TIMEOUT_SECONDS = 600
|
|
27
|
+
# Perl wrapper (perl is on macOS and Linux; stock macOS has no `timeout`). It runs the command in its own process
|
|
28
|
+
# group, kills the whole group on timeout (so `git` children die too), says so on stderr and exits 124. A command it
|
|
29
|
+
# cannot exec prints an error and exits 127. It holds no double quote or backslash: the hook sits in a TOML string.
|
|
30
|
+
PROVISIONING_COPY_WRAPPER = (
|
|
31
|
+
"use POSIX (); $t=shift; $p=fork; defined $p or do{print STDERR q{copy-ignored: fork failed: },$!,$/; exit 125}; "
|
|
32
|
+
"if(!$p){setpgrp(0,0); exec @ARGV; print STDERR q{copy-ignored: cannot run }.$ARGV[0].q{: }.$!.$/; POSIX::_exit(127)} "
|
|
33
|
+
"$SIG{ALRM}=sub{kill q{TERM},-$p; select undef,undef,undef,2; kill q{KILL},-$p; "
|
|
34
|
+
"print STDERR q{copy-ignored: timed out after }.$t.q{s; killed its process group}.$/; exit 124}; "
|
|
35
|
+
"alarm $t; waitpid $p,0; exit($?&127 ? 128+($?&127) : $?>>8)"
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def provisioning_copy_command(seconds: int) -> str:
|
|
40
|
+
return f"perl -e '{PROVISIONING_COPY_WRAPPER}' {seconds} wt step copy-ignored --require-include"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
PROVISIONING_COPY_COMMAND = provisioning_copy_command(PROVISIONING_COPY_TIMEOUT_SECONDS)
|
|
26
44
|
PROVISIONING_UV_COMMAND = "uv sync"
|
|
27
45
|
PROVISIONING_FIX = "rerun with --apply; project hooks require `wt config approvals add` before the next worktree"
|
|
28
46
|
|
|
@@ -7,9 +7,13 @@ import contextlib
|
|
|
7
7
|
import importlib.util
|
|
8
8
|
import io
|
|
9
9
|
import json
|
|
10
|
+
import os
|
|
10
11
|
from pathlib import Path
|
|
12
|
+
import shutil
|
|
13
|
+
import subprocess
|
|
11
14
|
import sys
|
|
12
15
|
import tempfile
|
|
16
|
+
import time
|
|
13
17
|
import unittest
|
|
14
18
|
from unittest.mock import patch
|
|
15
19
|
|
|
@@ -282,7 +286,61 @@ class PreflightRegressionTests(unittest.TestCase):
|
|
|
282
286
|
self.assertIn("[post-start]", result.detail)
|
|
283
287
|
self.assertIn("copy-ignored", result.detail)
|
|
284
288
|
|
|
285
|
-
def
|
|
289
|
+
def test_provisioning_copy_hook_is_bounded_and_still_recognised(self) -> None:
|
|
290
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
291
|
+
root = Path(directory)
|
|
292
|
+
home = root / "home"
|
|
293
|
+
with patch.object(Path, "home", return_value=home):
|
|
294
|
+
absent = preflight.check_provisioning_hook(FakeContext(root))
|
|
295
|
+
self.assertIn("setpgrp", absent.detail)
|
|
296
|
+
config = home / ".config" / "worktrunk" / "config.toml"
|
|
297
|
+
config.parent.mkdir(parents=True)
|
|
298
|
+
config.write_text(
|
|
299
|
+
f"[post-start]\ncopy-ignored = {json.dumps(preflight.PROVISIONING_COPY_COMMAND)}\n", encoding="utf-8"
|
|
300
|
+
)
|
|
301
|
+
with patch.object(Path, "home", return_value=home):
|
|
302
|
+
result = preflight.check_provisioning_hook(FakeContext(root))
|
|
303
|
+
self.assertEqual(result.status, "pass")
|
|
304
|
+
|
|
305
|
+
def _run_copy_hook(self, seconds: int, path: str) -> subprocess.CompletedProcess[str]:
|
|
306
|
+
return subprocess.run(
|
|
307
|
+
["/bin/sh", "-c", preflight.provisioning_copy_command(seconds)],
|
|
308
|
+
env={"PATH": path},
|
|
309
|
+
capture_output=True,
|
|
310
|
+
text=True,
|
|
311
|
+
check=False,
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
def _fake_wt(self, directory: str, script: str) -> str:
|
|
315
|
+
wt = Path(directory) / "wt"
|
|
316
|
+
wt.write_text(f"#!/bin/sh\n{script}\n", encoding="utf-8")
|
|
317
|
+
wt.chmod(0o755)
|
|
318
|
+
return directory
|
|
319
|
+
|
|
320
|
+
def test_copy_hook_wrapper_passes_exit_code_through(self) -> None:
|
|
321
|
+
perl_dir = str(Path(shutil.which("perl") or "/usr/bin/perl").parent)
|
|
322
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
323
|
+
done = self._run_copy_hook(5, f"{self._fake_wt(directory, 'exit 3')}:{perl_dir}")
|
|
324
|
+
self.assertEqual(done.returncode, 3)
|
|
325
|
+
|
|
326
|
+
def test_copy_hook_wrapper_kills_the_process_group_on_timeout(self) -> None:
|
|
327
|
+
perl_dir = str(Path(shutil.which("perl") or "/usr/bin/perl").parent)
|
|
328
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
329
|
+
marker = Path(directory) / "child.pid"
|
|
330
|
+
bin_dir = self._fake_wt(directory, f"sleep 30 &\necho $! > {marker}\nwait")
|
|
331
|
+
done = self._run_copy_hook(1, f"{bin_dir}:{perl_dir}:/bin")
|
|
332
|
+
self.assertEqual(done.returncode, 124)
|
|
333
|
+
self.assertIn("timed out after 1s", done.stderr)
|
|
334
|
+
pid = int(marker.read_text(encoding="utf-8").strip())
|
|
335
|
+
time.sleep(0.3)
|
|
336
|
+
with self.assertRaises(ProcessLookupError):
|
|
337
|
+
os.kill(pid, 0)
|
|
338
|
+
|
|
339
|
+
def test_copy_hook_wrapper_errors_when_wt_cannot_run(self) -> None:
|
|
340
|
+
perl_dir = str(Path(shutil.which("perl") or "/usr/bin/perl").parent)
|
|
341
|
+
done = self._run_copy_hook(5, perl_dir)
|
|
342
|
+
self.assertEqual(done.returncode, 127)
|
|
343
|
+
self.assertIn("cannot run wt", done.stderr)
|
|
286
344
|
with tempfile.TemporaryDirectory() as directory:
|
|
287
345
|
root = Path(directory)
|
|
288
346
|
(root / "pyproject.toml").write_text("[project]\nname = \"example\"\n", encoding="utf-8")
|
|
@@ -326,7 +384,7 @@ class PreflightRegressionTests(unittest.TestCase):
|
|
|
326
384
|
self.assertEqual(result["status"], "pass")
|
|
327
385
|
self.assertEqual(
|
|
328
386
|
config.read_text(encoding="utf-8"),
|
|
329
|
-
original +
|
|
387
|
+
original + f"\n[post-start]\ncopy-ignored = {json.dumps(preflight.PROVISIONING_COPY_COMMAND)}\n",
|
|
330
388
|
)
|
|
331
389
|
self.assertIn("wt config approvals add", result["detail"])
|
|
332
390
|
|