Quick Fix: reopen after a restart only when its own rebuild caused it
The chat reopened on every shell start while a stale "unseen" result was left over. Now the helper checks the job's unit for a running rebuild (zcli, nixos-rebuild, nh, home-manager) and only then reopens; other restarts keep following a running job quietly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f35dbee430
commit
94530d3bd3
4 files changed
+84
-11
No files matched your search
@@ -143,5 +143,37 @@ class QuickFix(unittest.TestCase):
|
||||
with patch.object(quickfix.subprocess, 'run', return_value=stopped):
|
||||
self.assertTrue(quickfix.handle({'op': 'state'})['running']) # worker process alive
|
||||
|
||||
def test_reopens_only_when_its_own_rebuild_restarted_the_shell(self):
|
||||
request = {'op': 'send', 'text': 'x', 'provider': 'claude', 'options': {}}
|
||||
with patch.object(quickfix, 'start_unit'), patch.object(quickfix, 'unit_active', return_value=True):
|
||||
quickfix.handle(request)
|
||||
with patch.object(quickfix, 'rebuilding', return_value=False):
|
||||
self.assertFalse(quickfix.handle({'op': 'state'})['rebuilt'])
|
||||
with patch.object(quickfix, 'rebuilding', return_value=True):
|
||||
self.assertTrue(quickfix.handle({'op': 'state'})['rebuilt'])
|
||||
# Remembered for the rest of the job, e.g. a second restart.
|
||||
with patch.object(quickfix, 'rebuilding', return_value=False):
|
||||
self.assertTrue(quickfix.handle({'op': 'state'})['rebuilt'])
|
||||
quickfix.save_state(running=False)
|
||||
with patch.object(quickfix, 'rebuilding', return_value=False):
|
||||
quickfix.handle(request)
|
||||
self.assertFalse(quickfix.handle({'op': 'state'})['rebuilt'])
|
||||
|
||||
def test_rebuilding_spots_a_rebuild_in_the_job_unit(self):
|
||||
base = Path(self.tmp.name) / 'cg'
|
||||
(base / 'job').mkdir(parents=True)
|
||||
(base / 'job/cgroup.procs').write_text(str(os.getpid()) + '\n')
|
||||
group = subprocess.CompletedProcess([], 0, '/job\n', '')
|
||||
real = Path
|
||||
def fake_path(*parts):
|
||||
path = real(*parts)
|
||||
return base if str(path) == '/sys/fs/cgroup' else path
|
||||
with patch.object(quickfix.subprocess, 'run', return_value=group), patch.object(quickfix, 'Path', side_effect=fake_path):
|
||||
self.assertFalse(quickfix.rebuilding('x'))
|
||||
argv = b'bash\0/nix/store/abc-zcli/bin/zcli\0rebuild\0'
|
||||
real_read = real.read_bytes
|
||||
with patch.object(real, 'read_bytes', lambda self: argv if self.name == 'cmdline' else real_read(self)):
|
||||
self.assertTrue(quickfix.rebuilding('x'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user