@appchy/jarvis 0.1.120 → 0.1.121

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.
@@ -3248,13 +3248,101 @@ def test_starting_while_a_run_is_live_names_whose_it_is_rather_than_attaching():
3248
3248
  "machine": "here", "started": gate._now().isoformat(),
3249
3249
  "gates": ["tests"], "current": "tests", "done": [],
3250
3250
  "finished": None, "read": False})
3251
- out = _said(lambda: gate.cmd_verify({"task": "beta", "async": True}))
3252
- assert out["state"] == "running", out
3251
+ out = _said(lambda: gate.cmd_verify({"task": "beta", "start": True}))
3252
+ # `busy` and not `running`: the slot is taken and it is somebody
3253
+ # else's. Reporting both as `running` is how a session read a held
3254
+ # checkout as its own gates making progress.
3255
+ assert out["state"] == "busy", out
3256
+ assert out["run"]["task"] == "alpha", out
3253
3257
  assert "alpha" in out["message"], out["message"]
3258
+ # Not a queue, and it says so rather than letting a refused caller
3259
+ # believe a call is coming.
3260
+ assert "Nothing is holding your place" in out["message"], out["message"]
3254
3261
  finally:
3255
3262
  gate.VERIFY = old
3256
3263
 
3257
3264
 
3265
+ def test_a_held_slot_never_reports_as_the_callers_own_progress():
3266
+ # The measured half of this: asking for progress answered `18s, 0 of 9` and then
3267
+ # `322s, 8 of 9` two minutes apart, for two different runs, and a caller could
3268
+ # tell neither a fresh start from somebody else's long one nor whether its own
3269
+ # request had taken effect. Every gate-shaped field describes the CALLER's item,
3270
+ # so on a slot that is not theirs they are empty and the run sits on its own.
3271
+ with tempfile.TemporaryDirectory() as tmp:
3272
+ v = _tree(tmp)
3273
+ e = _epic(v, "an-epic")
3274
+ _task(e / "in-progress", "alpha", body="# T\n")
3275
+ _task(e / "in-progress", "beta", body="# T\n")
3276
+ with _work_dir(tmp) as root:
3277
+ old, gate.VERIFY = gate.VERIFY, {"tests": "true", "lint": "true"}
3278
+ try:
3279
+ gate._write_run(root, {"task": "alpha", "pid": os.getpid(),
3280
+ "machine": "here", "session": peers.me(),
3281
+ "started": gate._now().isoformat(),
3282
+ "gates": ["lint", "tests"], "current": "tests",
3283
+ "done": ["lint"], "finished": None, "read": False})
3284
+ out = _said(lambda: gate.cmd_verify({"task": "beta", "status": True}))
3285
+ assert out["state"] == "busy", out
3286
+ assert out["gate"] == "" and out["done"] == [] and out["gates"] == [], \
3287
+ "another item's progress was reported as this caller's"
3288
+ assert out["elapsedSeconds"] == 0 and out["passed"] is False, out
3289
+ # …and what IS true about the checkout is said, in one place.
3290
+ assert out["run"]["task"] == "alpha", out
3291
+ assert out["run"]["gate"] == "tests" and out["run"]["done"] == ["lint"], out
3292
+ assert "'beta'" in out["message"], out["message"]
3293
+
3294
+ # The same run, asked about by the item it IS proving, is progress.
3295
+ mine = _said(lambda: gate.cmd_verify({"task": "alpha", "status": True}))
3296
+ assert mine["state"] == "running", mine
3297
+ assert mine["done"] == ["lint"], mine
3298
+ finally:
3299
+ gate.VERIFY = old
3300
+
3301
+
3302
+ def test_a_refused_verify_names_a_reachable_holder_when_there_is_one():
3303
+ # The sibling refusal's join, made for the completion gate, applied to the one
3304
+ # mechanism in this epic that actually refuses: the id was always in the run file
3305
+ # and led nowhere, so the only move left was to ask again on a timer.
3306
+ with tempfile.TemporaryDirectory() as tmp:
3307
+ v = _tree(tmp)
3308
+ e = _epic(v, "an-epic")
3309
+ _task(e / "in-progress", "alpha", body="# T\n")
3310
+ with _work_dir(tmp) as root, tempfile.TemporaryDirectory() as sess:
3311
+ old, gate.VERIFY = gate.VERIFY, {"tests": "true"}
3312
+ keep = os.environ.get(peers.SESSIONS)
3313
+ os.environ[peers.SESSIONS] = sess
3314
+ peers._RUNNING.clear()
3315
+ try:
3316
+ Path(sess, "1.json").write_text(json.dumps(
3317
+ {"sessionId": "aaaabbbb-0000-0000-0000-000000000000",
3318
+ "name": "jarvis-22", "pid": os.getpid(), "cwd": str(root.parent)}))
3319
+ gate._write_run(root, {
3320
+ "task": "alpha", "pid": os.getpid(), "machine": peers.here(),
3321
+ "session": "aaaabbbb-0000-0000-0000-000000000000",
3322
+ "started": gate._now().isoformat(), "gates": ["tests"],
3323
+ "current": "tests", "done": [], "finished": None, "read": False})
3324
+ said = gate._busy(gate.live_run(root))
3325
+ assert "jarvis-22" in said, said
3326
+ assert "SendMessage" in said, said
3327
+ # How far through, because "started 190s ago" cannot answer whether
3328
+ # this is nearly over or has just begun.
3329
+ assert "gate 1 of 1" in said, said
3330
+
3331
+ # A run that recorded no session says nothing about who — an
3332
+ # enrichment we can lose, never a guess we invent.
3333
+ gate._write_run(root, {**gate.read_run(root), "session": ""})
3334
+ quiet = gate._busy(gate.live_run(root))
3335
+ assert "jarvis-22" not in quiet and "started by" not in quiet, quiet
3336
+ assert "corrupt each other" in quiet, quiet
3337
+ finally:
3338
+ gate.VERIFY = old
3339
+ peers._RUNNING.clear()
3340
+ if keep is None:
3341
+ os.environ.pop(peers.SESSIONS, None)
3342
+ else:
3343
+ os.environ[peers.SESSIONS] = keep
3344
+
3345
+
3258
3346
  def test_a_finished_run_for_another_task_is_not_handed_over_as_this_ones():
3259
3347
  # The wrong-verdict half. A result proven for one item says nothing about
3260
3348
  # another, and reporting it would put a green gate on work nobody ran.
@@ -3271,8 +3359,193 @@ def test_a_finished_run_for_another_task_is_not_handed_over_as_this_ones():
3271
3359
  out = _said(lambda: gate.cmd_verify({"task": "beta", "status": True}))
3272
3360
  assert out["state"] == "idle", out
3273
3361
  assert out["passed"] is False, out
3362
+ # …and it says WHICH kind of nothing this is. "No gates have run"
3363
+ # covering both "nobody ran anything" and "the last run proved
3364
+ # somebody else's item" is what a caller cannot act on.
3365
+ assert out["reason"] == "other", out
3366
+ assert "'alpha'" in out["message"], out["message"]
3367
+ finally:
3368
+ gate.VERIFY = old
3369
+
3370
+
3371
+ def test_a_run_that_stopped_without_recording_says_so_rather_than_reading_as_never_run():
3372
+ # The half nobody could prove. A run whose process is gone leaves a file every
3373
+ # door correctly treats as absent, and the next start OVERWRITES it — so the
3374
+ # session that lost four minutes of gates learned it only by noticing the slot
3375
+ # now named somebody else's item. Reported from the receiving end, 2026-09-12.
3376
+ with tempfile.TemporaryDirectory() as tmp:
3377
+ v = _tree(tmp)
3378
+ e = _epic(v, "an-epic")
3379
+ _task(e / "in-progress", "alpha", body="# T\n")
3380
+ _task(e / "in-progress", "beta", body="# T\n")
3381
+ with _work_dir(tmp) as root:
3382
+ old, gate.VERIFY = gate.VERIFY, {"tests": "true"}
3383
+ try:
3384
+ dead = {"task": "alpha", "pid": 2 ** 31 - 1, "machine": "here",
3385
+ "session": "aaaabbbb-0000-0000-0000-000000000000",
3386
+ "started": gate._now().isoformat(),
3387
+ "gates": ["lint", "tests"], "current": "tests",
3388
+ "done": ["lint"], "finished": None, "read": False}
3389
+ gate._write_run(root, dead)
3390
+ out = _said(lambda: gate.cmd_verify({"task": "alpha", "status": True}))
3391
+ assert out["state"] == "idle" and out["reason"] == "lost", out
3392
+ assert "gate 2 of 2" in out["message"], out["message"]
3393
+ assert "without recording" in out["message"], out["message"]
3394
+
3395
+ # And it survives the run that replaces it, which is the case that
3396
+ # actually happened: the slot is claimed by another item, and the
3397
+ # session whose gates vanished is still told — being behind a
3398
+ # stranger's run and having lost your own are two facts, and the
3399
+ # only thing it had to go on was the slot naming somebody else.
3400
+ gate._write_run(root, gate._begin(root, "beta", os.getpid()))
3401
+ assert gate.read_run(root)["lost"]["task"] == "alpha", gate.read_run(root)
3402
+ still = _said(lambda: gate.cmd_verify({"task": "alpha", "status": True}))
3403
+ assert still["state"] == "busy" and still["reason"] == "lost", still
3404
+ assert still["run"]["task"] == "beta", still
3405
+ assert "without recording" in still["message"], still["message"]
3406
+
3407
+ # A run that FINISHED is not a lost one, however long ago it was.
3408
+ gate._write_run(root, {**dead, "finished": gate._now().isoformat(),
3409
+ "passed": True, "sha": "", "results": []})
3410
+ done = _said(lambda: gate.cmd_verify({"task": "alpha", "status": True}))
3411
+ assert done["state"] == "finished", done
3412
+ finally:
3413
+ gate.VERIFY = old
3414
+
3415
+
3416
+ def test_a_result_the_code_moved_past_names_both_commits():
3417
+ # `moved` and `no gates have run` were one sentence, and this is the mode that
3418
+ # cost the most: a gate run only counted if nobody committed for four minutes,
3419
+ # and three sessions were committing every few minutes. The result was recorded
3420
+ # against a HEAD that no longer existed and read as never having run.
3421
+ with tempfile.TemporaryDirectory() as tmp:
3422
+ try:
3423
+ repo = _git_repo(tmp, push=False)
3424
+ ran = _git(repo, "rev-parse", "HEAD").stdout.strip()
3425
+ (repo / "src.txt").write_text("the code moved\n")
3426
+ _git(repo, "add", "-A"); _git(repo, "commit", "-qm", "somebody committed")
3427
+ head = _git(repo, "rev-parse", "HEAD").stdout.strip()
3428
+
3429
+ old, gate.VERIFY = gate.VERIFY, {"tests": "true"}
3430
+ with _work_dir(str(repo / "work")) as root:
3431
+ try:
3432
+ gate._write_run(root, {
3433
+ "task": "alpha", "pid": os.getpid(), "machine": "here",
3434
+ "session": "", "started": gate._now().isoformat(),
3435
+ "head": ran, "gates": ["tests"], "current": "",
3436
+ "done": ["tests"], "finished": gate._now().isoformat(),
3437
+ "passed": True, "sha": ran, "read": False,
3438
+ "results": [{"name": "tests", "status": "PASS", "said": ""}]})
3439
+ out = _said(lambda: gate.cmd_verify({"task": "alpha", "status": True}))
3440
+ assert out["reason"] == "moved", out
3441
+ assert ran[:12] in out["message"], out["message"]
3442
+ assert head[:12] in out["message"], out["message"]
3443
+ assert out["passed"] is False, "a stale green must not read as proven"
3444
+
3445
+ # A commit a push rebased away is a DIFFERENT answer: the code it
3446
+ # measured may be identical, and naming a hash nobody can open is
3447
+ # worse than saying it is gone.
3448
+ gate._write_run(root, {**gate.read_run(root), "read": False,
3449
+ "sha": "0" * 40, "head": "0" * 40})
3450
+ gone = _said(lambda: gate.cmd_verify({"task": "alpha", "status": True}))
3451
+ assert gone["reason"] == "gone", gone
3452
+ assert "rebased" in gone["message"], gone["message"]
3453
+ finally:
3454
+ gate.VERIFY = old
3455
+ finally:
3456
+ config.apply(config.DEFAULTS)
3457
+
3458
+
3459
+ def test_the_slot_is_held_from_before_the_child_starts():
3460
+ # The check-then-spawn this replaces left the slot unheld for the whole of a
3461
+ # Python interpreter's startup — hundreds of milliseconds, not an instant — so
3462
+ # two sessions polling one board could both walk through it and the second run's
3463
+ # build would delete the artifact the first one's log check was about to read.
3464
+ with tempfile.TemporaryDirectory() as tmp:
3465
+ v = _tree(tmp)
3466
+ e = _epic(v, "an-epic")
3467
+ _task(e / "in-progress", "alpha", body="# T\n")
3468
+ with _work_dir(tmp) as root:
3469
+ old, gate.VERIFY = gate.VERIFY, {"tests": "true"}
3470
+ spawned = []
3471
+ real = gate.subprocess.Popen
3472
+ try:
3473
+ # The claim has to be in place BEFORE anything is spawned, or a lost
3474
+ # race still leaves a child running gates nothing is tracking. Only
3475
+ # the verify child is intercepted — everything else here, `git`
3476
+ # included, still runs for real.
3477
+ class Sham:
3478
+ pid = os.getpid()
3479
+
3480
+ def watch(argv, **kw):
3481
+ if "--detached" not in argv:
3482
+ return real(argv, **kw)
3483
+ spawned.append(gate.live_run(root))
3484
+ return Sham()
3485
+ gate.subprocess.Popen = watch
3486
+ out = _said(lambda: gate.cmd_verify({"task": "alpha", "start": True}))
3487
+ assert out["state"] == "started", out
3488
+ assert spawned and spawned[0] and spawned[0]["task"] == "alpha", \
3489
+ "the slot was open while the child was being spawned"
3490
+
3491
+ # A second start over a live claim is refused, and starts nothing.
3492
+ spawned.clear()
3493
+ again = _said(lambda: gate.cmd_verify({"task": "alpha", "start": True}))
3494
+ assert again["state"] == "busy", again
3495
+ assert spawned == [], "a refused start spawned a run anyway"
3496
+
3497
+ # A slot whose process is gone is taken over rather than waited for:
3498
+ # a lock that outlives its holder strands every future verify.
3499
+ gate._write_run(root, {**gate.read_run(root), "pid": 2 ** 31 - 1})
3500
+ free = _said(lambda: gate.cmd_verify({"task": "alpha", "start": True}))
3501
+ assert free["state"] == "started", free
3502
+ finally:
3503
+ gate.subprocess.Popen = real
3504
+ gate.VERIFY = old
3505
+
3506
+
3507
+ def test_a_pid_somebody_else_owns_is_alive_not_dead():
3508
+ # Two readings of one pid: `peers._live` treats a kernel refusal as alive and
3509
+ # this treated it as dead, so a run owned by another user read as over and a
3510
+ # second run could start over a live one. One question, one answer.
3511
+ real = gate.os.kill
3512
+ try:
3513
+ def refuse(pid, sig):
3514
+ raise PermissionError(1, "Operation not permitted")
3515
+ gate.os.kill = refuse
3516
+ assert gate._alive(4242) is True
3517
+ finally:
3518
+ gate.os.kill = real
3519
+ # pid 0 asks about the whole process group and a negative one about another
3520
+ # group, so either would answer "alive" about something that is not this run.
3521
+ assert gate._alive(0) is False and gate._alive(-1) is False
3522
+
3523
+
3524
+ def test_the_doors_that_start_are_told_apart_from_the_one_that_asks():
3525
+ # `--async` only ever started a run, and it READ like "ask me in the background":
3526
+ # a session polling with it set a fresh nine-gate run going every time the
3527
+ # previous one ended. The parser turns any `--word` into a flag, so an unread one
3528
+ # fell through to the BLOCKING door — the caller waiting minutes for a run it
3529
+ # never asked to start. A typo and a renamed flag both say so now.
3530
+ with tempfile.TemporaryDirectory() as tmp:
3531
+ v = _tree(tmp)
3532
+ _epic(v, "an-epic")
3533
+ with _work_dir(tmp):
3534
+ old, gate.VERIFY = gate.VERIFY, {"tests": "true"}
3535
+ try:
3536
+ for flag in ("async", "stat", "wait"):
3537
+ try:
3538
+ gate.cmd_verify({"task": "alpha", flag: True})
3539
+ except SystemExit as e:
3540
+ assert e.code, f"--{flag} exited 0"
3541
+ else:
3542
+ raise AssertionError(f"--{flag} was accepted and ignored")
3274
3543
  finally:
3275
3544
  gate.VERIFY = old
3545
+ # The help names each door by whether it STARTS, which is the only distinction
3546
+ # that matters when one of them costs four minutes.
3547
+ help_ = entry.__doc__ or ""
3548
+ assert "--start" in help_ and "--status only SAYS" in help_, help_
3276
3549
 
3277
3550
 
3278
3551
  def test_a_second_verify_is_refused_while_one_is_running():
package/harness/work.py CHANGED
@@ -91,10 +91,13 @@ cannot finish has somewhere to put the reason instead of stalling or guessing:
91
91
  status what shipped · what waits on you · what is at risk
92
92
  method the METHOD in full — how work is done here. The session
93
93
  block names it; this is the body, on request.
94
- verify [--task <name>] [--async] RUN verify.* (shell=False) and record the result;
95
- --async starts them and returns, then reports
96
- progress and finally the result. One at a time
97
- per checkout: two corrupt each other.
94
+ verify <name> [--start | --status] RUN verify.* (shell=False) and record the result.
95
+ Which door you pick decides whether a run STARTS:
96
+ (no flag) starts them here and waits for the table
97
+ --start starts them in the background, answers at once
98
+ --status only SAYS where the run stands — starts nothing
99
+ One run at a time per checkout: two corrupt each
100
+ other. Refused while one is going, and told whose.
98
101
  observed <task> --ac AC-01 --saw "…" an eyes-on, for what a test cannot prove
99
102
  ask <task> --question "…" [--options "a | b"] [--owner who] [--durable]
100
103
  park a question, move on — exits 0, never blocks
@@ -326,7 +329,7 @@ def _writes(cmd: str, flags: dict) -> bool:
326
329
  """Does THIS invocation change the board?
327
330
 
328
331
  The command name answers it for all but one. `verify` writes the result of a run
329
- it EXECUTES, and two of its four doors execute nothing: `--async` starts a
332
+ it EXECUTES, and two of its four doors execute nothing: `--start` starts a
330
333
  detached child that commits its own result, and `--status` only reports. Both
331
334
  write to `work/.verify`, which is gitignored, so neither has anything of its own
332
335
  to land — and both were driving a commit that swept up whatever the person had
@@ -336,7 +339,7 @@ def _writes(cmd: str, flags: dict) -> bool:
336
339
  """
337
340
  if cmd not in git.WRITES:
338
341
  return False
339
- if cmd == "verify" and (flags.get("async") or flags.get("status")):
342
+ if cmd == "verify" and (flags.get("start") or flags.get("status")):
340
343
  return False
341
344
  return True
342
345
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appchy/jarvis",
3
- "version": "0.1.120",
3
+ "version": "0.1.121",
4
4
  "description": "Jarvis — local AI coding assistant CLI",
5
5
  "private": false,
6
6
  "type": "module",
@@ -63,10 +63,10 @@
63
63
  "@jarvis/errors": "1.0.0",
64
64
  "@jarvis/logger": "1.0.0",
65
65
  "@jarvis/rpc": "1.0.0",
66
- "@jarvis/types": "1.0.0",
67
66
  "@jarvis/typescript-config": "1.0.0",
68
67
  "@jarvis/ui": "0.1.0",
69
- "@jarvis/vitest-config": "1.0.0"
68
+ "@jarvis/vitest-config": "1.0.0",
69
+ "@jarvis/types": "1.0.0"
70
70
  },
71
71
  "scripts": {
72
72
  "dev": "tsx watch src/bin.ts start --foreground",