Skip to content

Commit 65542b4

Browse files
committed
Cleaned up bugs made during merging
1 parent d38a9d2 commit 65542b4

5 files changed

Lines changed: 56 additions & 39 deletions

File tree

memory_management.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ def list_memory_files(memory_folder: str) -> list[str]:
6262
names.append(os.path.relpath(full_path, memory_folder))
6363
return sorted(names)
6464

65-
@staticmethod
66-
def memory_folder_for(conformance_tests_folder: str, module_name: str) -> str:
67-
"""Return the .memory folder path for a module (the per-module memory root)."""
68-
return os.path.join(conformance_tests_folder, module_name, CODEPLAIN_MEMORY_SUBFOLDER)
69-
7065
@staticmethod
7166
def write_agent_memory_file(
7267
memory_folder: str, file_name: str, content: str, subfolder: str = AGENT_MEMORY_SUBFOLDER
@@ -116,9 +111,9 @@ def sync_global_memories(target_memory_folder: str, source_memory_folders: list[
116111
console.debug(f"Synced {copied} global memory note(s) into {target_global}.")
117112
return copied
118113

119-
def __init__(self, codeplain_api, module_name: str, conformance_tests_folder: str):
114+
def __init__(self, codeplain_api, memory_folder: str):
120115
self.codeplain_api = codeplain_api
121-
self.memory_folder = MemoryManager.memory_folder_for(conformance_tests_folder, module_name)
116+
self.memory_folder = memory_folder
122117

123118
def create_conformance_tests_memory(
124119
self, render_context: RenderContext, exit_code: int, conformance_tests_issue: str

module_renderer.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,7 @@ def _sync_global_memories(self, memory_manager: MemoryManager) -> None:
155155
within a full render (modules rendered earlier feed later ones) and across renders.
156156
"""
157157
all_modules = self.plain_module.all_required_modules + [self.plain_module]
158-
source_memory_folders = [
159-
MemoryManager.memory_folder_for(self.args.conformance_tests_folder, module.module_name)
160-
for module in all_modules
161-
]
158+
source_memory_folders = [module.module_memory_folder for module in all_modules]
162159
MemoryManager.sync_global_memories(memory_manager.memory_folder, source_memory_folders)
163160

164161
def render_module(self) -> None:

render_machine/actions/review_conformance_fix_action.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,20 +302,26 @@ def _commit_approved_fix(self, render_context: RenderContext, tracked_paths: lis
302302
)
303303

304304
candidate_repos = [os.path.abspath(render_context.build_folder)]
305-
conformance_root = os.path.abspath(render_context.conformance_tests.conformance_tests_folder)
306-
# Conformance repos are per module; derive the touched ones from the tracked
307-
# paths, plus the current testing module's repo for side effects (e.g. files
308-
# written by run_command) that were never routed through the tracked tools.
305+
modules_base_folder = os.path.abspath(render_context.conformance_tests.modules_base_folder)
306+
# Conformance repos are per module (<modules_base>/<module>/tests); derive the
307+
# touched ones from the tracked paths, plus the current testing module's repo
308+
# for side effects (e.g. files written by run_command) that were never routed
309+
# through the tracked tools.
309310
conformance_module_folders = {
310311
os.path.abspath(
311312
render_context.conformance_tests.get_module_conformance_tests_folder(ctx.current_testing_module_name)
312313
)
313314
}
314315
for path in tracked_paths:
315316
absolute_path = os.path.abspath(path)
316-
if absolute_path.startswith(conformance_root + os.sep):
317-
module_dir = os.path.relpath(absolute_path, conformance_root).split(os.sep)[0]
318-
conformance_module_folders.add(os.path.join(conformance_root, module_dir))
317+
if not absolute_path.startswith(modules_base_folder + os.sep):
318+
continue
319+
module_name = os.path.relpath(absolute_path, modules_base_folder).split(os.sep)[0]
320+
tests_folder = os.path.abspath(
321+
render_context.conformance_tests.get_module_conformance_tests_folder(module_name)
322+
)
323+
if absolute_path.startswith(tests_folder + os.sep):
324+
conformance_module_folders.add(tests_folder)
319325
candidate_repos.extend(sorted(conformance_module_folders))
320326

321327
committed_repos = []

render_machine/agent/tools.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -168,31 +168,32 @@ def _get_allowed_write_folders(render_context: RenderContext) -> list[str]:
168168
ctx.get_current_conformance_test_folder_name(),
169169
)
170170
folders.append(os.path.normpath(os.path.abspath(folder)))
171-
elif render_context.conformance_tests_folder:
172-
folders.append(os.path.normpath(os.path.abspath(render_context.conformance_tests_folder)))
171+
elif render_context.should_run_conformance_tests():
172+
module_tests_folder = render_context.conformance_tests.get_module_conformance_tests_folder(
173+
render_context.module_name
174+
)
175+
folders.append(os.path.normpath(os.path.abspath(module_tests_folder)))
173176

174177
return folders
175178

176179

177180
def _get_allowed_read_folders(render_context: RenderContext) -> list[str]:
178181
"""Return normalized absolute paths of folders the agent can read from.
179182
180-
This is the write set, plus the module's memory folder, plus the whole
181-
conformance-tests root. Agents may browse and read persisted memory notes (via
183+
This is the write set, plus the module's memory folder, plus every module's
184+
conformance-tests folder. Agents may browse and read persisted memory notes (via
182185
read_file/grep/ls_files) on demand, but may only add to them through the dedicated
183186
write_memory tool — so the memory folder is intentionally readable here while staying
184-
out of the write set. The conformance-tests root is readable (read-only) so agents can
185-
consult sibling modules' conformance tests as reference examples of how a conformance
187+
out of the write set. Sibling modules' conformance-tests folders are readable
188+
(read-only) so agents can consult them as reference examples of how a conformance
186189
test project for this project is laid out, built, and wired to run in isolation.
187190
"""
188191
folders = list(_get_allowed_write_folders(render_context))
189192
memory_manager = getattr(render_context, "memory_manager", None)
190193
memory_folder = getattr(memory_manager, "memory_folder", None) if memory_manager else None
191194
if memory_folder:
192195
folders.append(os.path.normpath(os.path.abspath(memory_folder)))
193-
conformance_root = getattr(render_context, "conformance_tests_folder", None)
194-
if conformance_root:
195-
folders.append(os.path.normpath(os.path.abspath(conformance_root)))
196+
folders.extend(_get_all_module_tests_folders(render_context))
196197
return folders
197198

198199

@@ -235,8 +236,7 @@ def build_sandbox_contract(render_context: RenderContext) -> str:
235236
if script
236237
]
237238
modules_root = _get_modules_root(render_context)
238-
conformance_root = getattr(render_context, "conformance_tests_folder", None)
239-
conformance_root = os.path.normpath(os.path.abspath(conformance_root)) if conformance_root else None
239+
sibling_tests_folders = _get_all_module_tests_folders(render_context)
240240

241241
lines = ["You can WRITE (create/edit/delete files) ONLY inside these folders:"]
242242
lines.extend(f"- {folder}" for folder in write_folders)
@@ -249,9 +249,9 @@ def build_sandbox_contract(render_context: RenderContext) -> str:
249249
lines.append("- The test/setup scripts (read-only harness files):")
250250
lines.extend(f" - {script}" for script in scripts)
251251
lines.append("- Temporary files under /tmp and /var/folders (e.g. saved test output).")
252-
if conformance_root:
252+
if sibling_tests_folders:
253253
lines.append(
254-
f"- Every module's conformance tests under the conformance-tests root ({conformance_root}) "
254+
f"- Every module's conformance tests ({os.path.join(modules_root, '<module>', 'tests')}) "
255255
"(read-only). Sibling modules' conformance tests can be a good source of information — they "
256256
"already build and pass in this project's test harness. Explore them with ls_files/grep to "
257257
"find a relevant one rather than reading them all."
@@ -284,14 +284,27 @@ def build_sandbox_contract(render_context: RenderContext) -> str:
284284

285285

286286
def _get_modules_root(render_context: RenderContext) -> str:
287-
"""Return the directory that holds all per-module build folders.
287+
"""Return the directory that holds all per-module folders.
288288
289-
Build folders are constructed as ``<modules_root>/<module_name>`` (e.g.
290-
``plain_modules/module_2``), so the modules root is the build folder's parent. Its
291-
other children are sibling module folders, which contain confusing near-duplicates
292-
of the current build folder's code.
289+
Module folders are constructed as ``<modules_root>/<module_name>`` (e.g.
290+
``plain_modules/module_2``), each holding the module's ``code/`` (the build folder)
291+
and ``tests/`` trees. Sibling module folders contain confusing near-duplicates of
292+
the current build folder's code.
293293
"""
294-
return os.path.dirname(os.path.normpath(os.path.abspath(render_context.build_folder)))
294+
return os.path.normpath(os.path.abspath(render_context.plain_module.build_folder))
295+
296+
297+
def _get_all_module_tests_folders(render_context: RenderContext) -> list[str]:
298+
"""Return the existing conformance-tests folders of every module under the modules root."""
299+
modules_root = _get_modules_root(render_context)
300+
if not os.path.isdir(modules_root):
301+
return []
302+
folders = []
303+
for module_name in sorted(os.listdir(modules_root)):
304+
tests_folder = render_context.conformance_tests.get_module_conformance_tests_folder(module_name)
305+
if os.path.isdir(tests_folder):
306+
folders.append(os.path.normpath(os.path.abspath(tests_folder)))
307+
return folders
295308

296309

297310
def _check_read_access(full_path: str, render_context: RenderContext) -> str | None:

tests/test_agent_tools.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,21 @@
1818
from render_machine.agent import tools
1919
from render_machine.agent.agent_runner import TERMINAL_TOOLS
2020
from render_machine.agent.tool_executor import DEFAULT_TOOLS
21+
from render_machine.conformance_tests import CONFORMANCE_TESTS_DEFINITION_FILE_NAME, ConformanceTests
2122

2223

2324
def _fake_render_context(build_folder: str) -> SimpleNamespace:
2425
"""Minimal render-context stand-in accepted by the file tools."""
26+
modules_root = os.path.dirname(os.path.normpath(os.path.abspath(build_folder)))
2527
return SimpleNamespace(
2628
build_folder=build_folder,
29+
plain_module=SimpleNamespace(build_folder=modules_root),
2730
conformance_tests_running_context=None,
28-
conformance_tests_folder=None,
31+
conformance_tests=ConformanceTests(
32+
modules_base_folder=modules_root,
33+
conformance_tests_definition_file_name=CONFORMANCE_TESTS_DEFINITION_FILE_NAME,
34+
),
35+
should_run_conformance_tests=lambda: False,
2936
memory_manager=None,
3037
conformance_tests_script=None,
3138
prepare_environment_script=None,
@@ -251,7 +258,6 @@ def test_tracking_conformance_test_file_change_does_not_rearm_preparation(projec
251258
Path(test_path).write_text("assert True\n", encoding="utf-8")
252259

253260
render_context = _fake_render_context(build_folder)
254-
render_context.conformance_tests_folder = conformance_folder
255261
render_context.conformance_tests_running_context = _conformance_ctx()
256262

257263
tools._track_file_change(test_path, render_context)

0 commit comments

Comments
 (0)