fix(session): complete working directory consumers and validation
This commit is contained in:
1 parent
1c34cd578b
commit
92713fcdbd
59 files changed
+372
-116
No files matched your search
@@ -2328,10 +2328,18 @@ def minimal_snapshot_message(message: object, cwd: Path) -> dict[str, object]:
|
||||
raise AssertionError(f"minimal model request has an unexpected message role: {message}")
|
||||
|
||||
|
||||
def snapshot_directory_replacements(directory: Path, token: str) -> list[tuple[str, str]]:
|
||||
"""Pin the allocated fixture path in plain fields and JSON-quoted context text."""
|
||||
path = str(directory)
|
||||
return [(json.dumps(path, ensure_ascii=False)[1:-1], token), (path, token)]
|
||||
|
||||
|
||||
def minimal_snapshot_text(value: object, cwd: Path) -> object:
|
||||
"""Replace the scenario's temporary working directory everywhere it appears."""
|
||||
if isinstance(value, str):
|
||||
return value.replace(str(cwd), "{{cwd}}")
|
||||
for actual, token in snapshot_directory_replacements(cwd, "{{cwd}}"):
|
||||
value = value.replace(actual, token)
|
||||
return value
|
||||
if isinstance(value, list):
|
||||
return [minimal_snapshot_text(item, cwd) for item in value]
|
||||
if isinstance(value, dict):
|
||||
@@ -2346,7 +2354,7 @@ def build_snapshot_files(
|
||||
cwd: Path,
|
||||
) -> dict[str, str]:
|
||||
"""Render the SDK result and three persisted logs into stable expected outputs."""
|
||||
replacements = [(str(cwd), "{{cwd}}"), (SNAPSHOT_SESSION_ID, "{{parent}}")]
|
||||
replacements = snapshot_directory_replacements(cwd, "{{cwd}}") + [(SNAPSHOT_SESSION_ID, "{{parent}}")]
|
||||
replacements.append((snapshot_workflow_run_id(result), "{{workflow-run}}"))
|
||||
for index, child_id in enumerate(child_ids, start=1):
|
||||
replacements.append((child_id, f"{{{{child-{index}}}}}"))
|
||||
@@ -2418,8 +2426,8 @@ def build_restart_snapshot_files(
|
||||
) -> dict[str, str]:
|
||||
"""Render two SDK processes, isolated model histories, and durable logs."""
|
||||
replacements = [
|
||||
(str(sessions), "{{sessions}}"),
|
||||
(str(cwd), "{{cwd}}"),
|
||||
*snapshot_directory_replacements(sessions, "{{sessions}}"),
|
||||
*snapshot_directory_replacements(cwd, "{{cwd}}"),
|
||||
(RESTART_FIRST_SESSION_ID, "{{session-1}}"),
|
||||
(RESTART_SECOND_SESSION_ID, "{{session-2}}"),
|
||||
]
|
||||
|
||||
Reference in new issue
Block a user