fix: dismiss a verified prewrite startup tip during release
This commit is contained in:
1 parent
2722d09b59
commit
6a716052f4
2 files changed
+26
-10
No files matched your search
@@ -1041,13 +1041,13 @@ def finish_owned_idle_session(path, *, stop=None):
|
||||
if not acquired or stop is not None and stop.is_set(): return False
|
||||
session, state, identities = _session(path, path.parent)
|
||||
if 'owned_idle_cleanup' in session: return False
|
||||
def read(name):
|
||||
def read(name, *, lines=False):
|
||||
item = path.with_name(name)
|
||||
if item.lstat().st_file_attributes & stat.FILE_ATTRIBUTE_REPARSE_POINT:
|
||||
raise ValueError('OWNED_CLEANUP_REPARSE_POINT')
|
||||
with item.open('rb') as stream: data = stream.read(1024*1024+1)
|
||||
if len(data) > 1024*1024: raise ValueError('OWNED_CLEANUP_RECORD_TOO_LARGE')
|
||||
return json.loads(data)
|
||||
return [json.loads(line) for line in data.splitlines()] if lines else json.loads(data)
|
||||
job = read('request.json')
|
||||
if not isinstance(job, dict): return False
|
||||
if (any(job.get(k) != session.get(k) for k in ('operation_id','operation','library','desktop','block'))
|
||||
@@ -1144,9 +1144,17 @@ def finish_owned_idle_session(path, *, stop=None):
|
||||
if len(modals) != 1:
|
||||
return None
|
||||
with _window_desktop(desktop):
|
||||
observed = _startup_snapshot(modals[0]['hwnd'], client['pid'])
|
||||
tip = _tip_target(observed) if orphan_client is not None and modals[0]['title'] == 'Tip of the Day' else None
|
||||
modal = modals[0]
|
||||
observed = _startup_snapshot(modal['hwnd'], client['pid'])
|
||||
tip = _tip_target(observed) if modal['title'] == 'Tip of the Day' else None
|
||||
if tip is not None:
|
||||
# A preceding cleanup can leave this same Tip visible; no repeated action.
|
||||
if any(event.get('pcb_pid') == client['pid'] and
|
||||
(event.get('stage') == 'startup_close_requested'
|
||||
or event.get('stage') == 'startup_tip_dismissed'
|
||||
and event.get('hwnd') == modal['hwnd'])
|
||||
for event in read('events.jsonl', lines=True)):
|
||||
return None
|
||||
return observed, tip.handle, 'tip'
|
||||
target = _cancel_target(observed)
|
||||
if target is not None and (orphan_client is not None or target[0] == 'database_load_log'):
|
||||
|
||||
@@ -179,7 +179,8 @@ def test_cancelled_prewrite_can_dismiss_exact_late_load_failure(qtbot, tmp_path,
|
||||
assert (root/'result.json').read_bytes() == original
|
||||
|
||||
|
||||
@pytest.mark.parametrize('obstacle', [None, 'tip', 'read_write', 'unknown_prompt', 'save',
|
||||
@pytest.mark.parametrize('obstacle', [None, 'tip', 'cancelled_tip', 'previously_dismissed_tip',
|
||||
'read_write', 'unknown_prompt', 'save',
|
||||
'uncertain_phase', 'live_supervisor', 'live_worker',
|
||||
'wrong_pcb', 'possible_write'])
|
||||
def test_restarted_verify_closes_exact_prewrite_orphan(tmp_path, monkeypatch, obstacle):
|
||||
@@ -190,7 +191,7 @@ def test_restarted_verify_closes_exact_prewrite_orphan(tmp_path, monkeypatch, ob
|
||||
from test_owned_idle_cleanup import owned_fixture
|
||||
from cbb_refresh_verify import failed_session, residual_sessions
|
||||
|
||||
root, job, _, windows, state = owned_fixture(tmp_path, monkeypatch)
|
||||
root, job, result, windows, state = owned_fixture(tmp_path, monkeypatch)
|
||||
create_mutex = win32event.CreateMutex
|
||||
monkeypatch.setattr(win32event, 'CreateMutex', lambda *args: create_mutex(None, False, None))
|
||||
path = root/'session.json'
|
||||
@@ -221,6 +222,13 @@ def test_restarted_verify_closes_exact_prewrite_orphan(tmp_path, monkeypatch, ob
|
||||
dict(stage='startup_prewrite_ready', worker_identity=session['processes'][0],
|
||||
baseline=dict(started_ns=42, files={}), **binding),
|
||||
dict(stage='pcb_worker_started', pcb_pid=12, command=command)]
|
||||
if obstacle in ('cancelled_tip', 'previously_dismissed_tip'):
|
||||
result.update(status='CANCELLED', error_category='TASK_HANDOFF')
|
||||
(root/'result.json').write_text(json.dumps(result), encoding='utf-8')
|
||||
rows.append(dict(stage='startup_cancelled_prewrite', pcb_pid=12, identity_verified=False,
|
||||
write_admitted=False, **binding))
|
||||
if obstacle == 'previously_dismissed_tip':
|
||||
rows.append(dict(stage='startup_tip_dismissed', pcb_pid=12, hwnd=200))
|
||||
if obstacle == 'possible_write':
|
||||
rows.append(dict(stage='startup_supervisor_write_possible', **binding))
|
||||
(root/'events.jsonl').write_text(''.join(json.dumps(row)+'\n' for row in rows), encoding='utf-8')
|
||||
@@ -230,10 +238,10 @@ def test_restarted_verify_closes_exact_prewrite_orphan(tmp_path, monkeypatch, ob
|
||||
monkeypatch.setattr(residual_sessions, '_recorded_process_exited',
|
||||
lambda identity: obstacle != 'live_supervisor' and identity == supervisor)
|
||||
|
||||
if obstacle in ('tip', 'read_write', 'unknown_prompt'):
|
||||
if obstacle in ('tip', 'cancelled_tip', 'previously_dismissed_tip', 'read_write', 'unknown_prompt'):
|
||||
frame = windows[0]
|
||||
frame['enabled'] = False
|
||||
windows.append(dict(hwnd=200, title='Tip of the Day' if obstacle == 'tip' else 'Expedition PCB',
|
||||
windows.append(dict(hwnd=200, title='Tip of the Day' if obstacle.endswith('tip') else 'Expedition PCB',
|
||||
desktop=job['desktop'], children=[], enabled=True, **{'class': '#32770'}))
|
||||
|
||||
def post(window, hwnd, pid, message):
|
||||
@@ -259,8 +267,8 @@ def test_restarted_verify_closes_exact_prewrite_orphan(tmp_path, monkeypatch, ob
|
||||
SimpleNamespace(handle=201)) if obstacle == 'read_write' else None)
|
||||
recovered = residual_sessions.finish_owned_idle_session(path)
|
||||
|
||||
assert recovered is (obstacle in (None, 'tip', 'read_write'))
|
||||
expected_posts = [(201, 12, 245)] if obstacle in ('tip', 'read_write') else []
|
||||
assert recovered is (obstacle in (None, 'tip', 'cancelled_tip', 'read_write'))
|
||||
expected_posts = [(201, 12, 245)] if obstacle in ('tip', 'cancelled_tip', 'read_write') else []
|
||||
if recovered:
|
||||
expected_posts.append((100, 12, 16))
|
||||
assert state['posts'] == expected_posts
|
||||
|
||||
Reference in new issue
Block a user