test_isolation.py file-level

at main · View file ↗ · Intel ↗

History
1 files
1 commits
0 hotspots
0 🧊 dead
0 💥 blast risk
sha256:f docs: recenter public story on governance loop · · Oct 11, 2026
1 import json
2 import os
3 from pathlib import Path
4 import shutil
5 import subprocess
6
7 import pytest
8 import yaml
9
10 from tests.v1.conftest import KIT, command, status
11
12
13 def assert_selected(result, wanted, other):
14 assert result.returncode == 0, result.stderr
15 assert 'Unique content for ' + wanted.name + '\n' in result.stdout
16 assert 'Unique content for ' + other.name + '\n' not in result.stdout
17 assert str(wanted) in result.stdout
18 assert status(wanted)['repository']['id'] in result.stdout
19
20
21 def test_cwd_and_explicit_C_select_only_intended_repository(pair, tmp_path):
22 a,b=pair
23 assert status(a)['repository']['id'] != status(b)['repository']['id']
24 assert status(a)['next']['action_id'] == status(b)['next']['action_id'] == 'SAME-ACTION'
25 for wanted,other in ((a,b),(b,a)):
26 (wanted/'nested').mkdir()
27 for cwd in (wanted,wanted/'nested'):
28 assert_selected(command('next',cwd=cwd),wanted,other)
29 for cwd in (other,tmp_path,wanted/'nested'):
30 assert_selected(command('-C',wanted,'next',cwd=cwd),wanted,other)
31 assert_selected(command('next','-C',wanted,cwd=cwd),wanted,other)
32 assert command('-C',wanted/'nested','next').returncode != 0
33 assert command('next',cwd=tmp_path).returncode != 0
34
35
36 @pytest.mark.parametrize('file', ['.overseer/config.yaml','docs/NEXT.md'])
37 def test_copied_config_or_next_fails_without_foreign_prompt(pair, file):
38 a,b=pair
39 shutil.copyfile(a/file,b/file)
40 for cmd in ('next','status'):
41 r=command('-C',b,cmd)
42 assert r.returncode != 0
43 assert 'Unique content for '+a.name not in r.stdout
44 if file.endswith('config.yaml'):
45 assert command('-C',b,'sync').returncode != 0
46 assert command('-C',b,'init').returncode != 0
47
48
49 def test_copied_config_and_next_still_fail(pair):
50 a,b=pair
51 for file in ('.overseer/config.yaml','docs/NEXT.md'):
52 shutil.copyfile(a/file,b/file)
53 assert command('-C',b,'next').returncode != 0
54
55
56 def test_foreign_explicit_config_refused(pair):
57 a,b=pair
58 r=command('-C',b,'--config',a/'.overseer/config.yaml','next')
59 assert r.returncode != 0 and not r.stdout
60
61
62 def test_bound_launchers_respect_cwd_explicit_path_and_copy_location(pair,tmp_path):
63 a,b=pair
64 for root,other in ((a,b),(b,a)):
65 launcher=root/'.overseer/bin/ok'
66 assert_selected(command('next',cwd=root,executable=launcher),root,other)
67 assert command('next',cwd=other,executable=launcher).returncode != 0
68 assert_selected(command('-C',root,'next',cwd=other,executable=launcher),root,other)
69 assert command('-C',other,'next',cwd=root,executable=launcher).returncode != 0
70 shutil.copyfile(a/'.overseer/bin/ok',b/'.overseer/bin/ok')
71 for cwd,args in ((b,()),(a,()),(b,('-C',a))):
72 r=command(*args,'next',cwd=cwd,executable=b/'.overseer/bin/ok')
73 assert r.returncode != 0 and not r.stdout
74
75
76 @pytest.mark.parametrize('name',['session-start-next.sh','session-end-closeout.sh'])
77 def test_hook_context_and_copied_hook_fail_closed(pair,name):
78 a,b=pair
79 hook=a/'.cursor/hooks'/name
80 event=json.dumps({'workspace_roots':[str(a)]})
81 r=command(cwd=a,executable=hook,input=event)
82 assert r.returncode == 0
83 payload=json.loads(r.stdout)
84 assert 'Unique content for '+a.name in payload['additional_context']
85 for cwd,roots in ((b,[str(a)]),(a,[str(b)]),(a,[str(a),str(b)])):
86 r=command(cwd=cwd,executable=hook,input=json.dumps({'workspace_roots':roots}))
87 assert r.returncode != 0 and not r.stdout
88 shutil.copyfile(hook,b/'.cursor/hooks'/name)
89 for cwd in (a,b):
90 r=command(cwd=cwd,executable=b/'.cursor/hooks'/name,input='{}')
91 assert r.returncode != 0 and not r.stdout
92
93
94 def test_environment_poisoning_cannot_select_neighbor(pair,tmp_path):
95 a,b=pair
96 poison=tmp_path/'poison';poison.mkdir()
97 marker=tmp_path/'executed'
98 for name in ('python3','git','ok'):
99 p=poison/name;p.write_text('#!/bin/sh\ntouch '+str(marker)+'\nexit 99\n');p.chmod(0o755)
100 (poison/'sitecustomize.py').write_text('raise RuntimeError("poison")\n')
101 (poison/'cli').mkdir();(poison/'cli/__init__.py').write_text('raise RuntimeError("poison")\n')
102 env={'PATH':str(poison),'PYTHONPATH':str(poison),'PYTHONHOME':str(poison),
103 'VIRTUAL_ENV':str(b), 'GIT_DIR':str(b/'.git'),'GIT_WORK_TREE':str(b),
104 'OVERSEER_OK':str(b/'.overseer/bin/ok'),'GIT_CONFIG_COUNT':'1',
105 'GIT_CONFIG_KEY_0':'core.worktree','GIT_CONFIG_VALUE_0':str(b)}
106 assert_selected(command('-C',a,'next',cwd=b,env=env),a,b)
107 r=command(cwd=a,executable=a/'.cursor/hooks/session-start-next.sh',env=env,input='{}')
108 assert r.returncode == 0, r.stderr
109 assert not marker.exists()
110
111
112 def test_runtime_from_neighbor_refused(pair):
113 a,b=pair
114 path=b/'.overseer/config.yaml'
115 config=yaml.safe_load(path.read_text());config['runtime']['root']=str(a)
116 path.write_text(yaml.safe_dump(config))
117 for cmd in ('next','sync','status'):
118 r=command('-C',b,cmd)
119 assert r.returncode != 0 and not r.stdout
120
121
122 def test_duplicate_C_or_bound_override_refused(pair):
123 a,b=pair
124 for args in [('-C',a,'next','-C',b),('-C',a,'next','--repo='+str(b)),
125 ('--bound-root',str(b),'next')]:
126 r=command(*args,cwd=a,executable=a/'.overseer/bin/ok')
127 assert r.returncode != 0 and not r.stdout
128
129
130 def test_symlink_repository_alias_resolves_same_physical_root(pair,tmp_path):
131 a,b=pair
132 alias=tmp_path/'alias';alias.symlink_to(a,target_is_directory=True)
133 assert_selected(command('-C',alias,'next'),a,b)
134
135
136 def test_source_shim_copied_without_runtime_does_not_fall_back(pair):
137 a,b=pair
138 (b/'cli').mkdir();shutil.copy2(KIT/'cli/ok',b/'cli/ok')
139 r=command('-C',b,'next',cwd=a,executable=b/'cli/ok')
140 assert r.returncode != 0 and not r.stdout and 'no runtime fallback' in r.stderr
141
142
143 def test_relative_bound_launcher_from_child_directory(pair):
144 a,b=pair
145 (a/'child').mkdir()
146 assert_selected(command('next',cwd=a/'child',executable='../.overseer/bin/ok'),a,b)