Skip to content

Commit 4fc6edd

Browse files
committed
fix: Address review findings — let-binding crash paths, Step.Name, perf
Review fixes on top of the RFC 0008 wrap-actions commit: - enter_environment/exit_environment no longer raise a raw ExpressionError out of the public API when an extra `let` binding fails to evaluate: the action fails through _fail_action_before_start with the callback, leaving the environment entered-but-failed exactly like a failed onEnter subprocess. - enter_environment(step_name=...) seeds Step.Name (RFC 0007 §7.3.1) before the extra bindings evaluate, remembered per environment and re-seeded at exit — openjd-rs parity (the Rust runtime threads the per-step resolved symtab into both enter and exit). - let-binding RHS parsing memoized and single-sourced via openjd.model.evaluate_let_bindings (was re-parsed through the Rust engine per env-enter/exit/task). - Wrap environment embedded-file paths allocated once per environment and reused across wrap-hook invocations (stable Env.File.*, no O(task-count) temp-file growth); contents still re-resolved per task. - One resolve_optional_int_field(ge=, le=) replaces three disagreeing optional-int resolvers — this also adds the previously missing non-positive check to Session._resolve_action_timeout (openjd-rs parity). - Complexity/duplication reductions: _fail_action, shared runner cancel() via _cancel_with_effective_cancelation, _make_env_script_runner, _try_inject_wrapped_symbols, WRAP_HOOK_ACTION_NAMES single-sourced, SimplifiedEnvironmentVariableChanges.effective_items() (no more private poking from _collect_session_env_list), whole-field detection via FormatString.whole_field_expression(). - pyproject: note that the openjd-model pin floor must be the first release containing model PR #318's surface. Tests: 647 passed (12 new regression tests: failure paths, Step.Name enter+exit, parse memoization, int-field bounds, wrap-file reuse); pre-existing environment failures unchanged. mypy/black/ruff clean. Signed-off-by: David Leong <116610336+leongdl@users.noreply.github.com>
1 parent d1ec0d2 commit 4fc6edd

10 files changed

Lines changed: 891 additions & 351 deletions

‎pyproject.toml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ classifiers = [
3131
"Topic :: Software Development :: Libraries"
3232
]
3333
dependencies = [
34+
# NOTE (version-skew guard): this branch requires openjd-model features that
35+
# only exist as of openjd-model-for-python PR #318 (FormatString.resolve_value,
36+
# FormatString.whole_field_expression, evaluate_let_bindings, Step.let).
37+
# Before release, bump the version floor below to the first openjd-model
38+
# release that includes PR #318's surface.
3439
"openjd-model >= 0.10,< 0.12",
3540
"pywin32 >= 307; platform_system == 'Windows'",
3641
"psutil >= 5.9,< 7.3; platform_system == 'Windows'",

‎src/openjd/sessions/_embedded_files.py‎

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -231,32 +231,65 @@ def allocate_file_paths(
231231
else:
232232
self._logger.info("Writing embedded files for Task to disk.")
233233

234+
records = self.allocate_records(files)
235+
self._define_symbols(records, symtab)
236+
return records
237+
238+
def allocate_records(self, files: EmbeddedFilesListType) -> list["_FileRecord"]:
239+
"""Allocate the on-disk paths for the embedded files, without logging
240+
or defining any symbols.
241+
242+
Used by the Session to pre-allocate a wrap environment's file records
243+
once (RFC 0008); each wrap-hook invocation then defines the symbols
244+
and logs through :meth:`register_file_paths` against its own symbol
245+
table.
246+
247+
Raises:
248+
RuntimeError: If a file path could not be allocated.
249+
"""
234250
try:
235251
records = list[_FileRecord]()
236252
# Generate the symbol table values and filenames
237253
for file in files:
238254
# Raises: OSError
239255
symbol, filename = self._get_symtab_entry(file)
240256
records.append(_FileRecord(symbol=symbol, filename=filename, file=file))
241-
242-
# Add symbols to the symbol table. For EXPR evaluation the
243-
# Env.File.*/Task.File.* symbols are host-format path values
244-
# (property access like `.parent` works), matching openjd-rs;
245-
# the legacy (non-EXPR) interpolation path ignores the type and
246-
# keeps the string form.
247-
for record in records:
248-
symtab[record.symbol] = str(record.filename)
249-
symtab.expr_types[record.symbol] = "PATH"
250-
self._logger.info(
251-
f"Mapping: {record.symbol} -> {record.filename}",
252-
extra=LogExtraInfo(
253-
openjd_log_content=LogContent.FILE_PATH | LogContent.PARAMETER_INFO
254-
),
255-
)
256257
return records
257258
except (OSError, ValueError) as err:
258259
raise RuntimeError(f"Could not write embedded file: {err}")
259260

261+
def register_file_paths(self, records: list["_FileRecord"], symtab: SymbolTable) -> None:
262+
"""Define the ``Env.File.*``/``Task.File.*`` symbols in ``symtab``
263+
for already-allocated records, without allocating new paths.
264+
265+
Used to reuse a wrap environment's embedded-file records across
266+
wrap-hook invocations (RFC 0008): the on-disk paths are allocated
267+
once so the symbols stay stable and unnamed files do not accumulate,
268+
while the contents are re-resolved and rewritten per invocation via
269+
:meth:`write_file_contents`.
270+
"""
271+
if self._scope == EmbeddedFilesScope.ENV:
272+
self._logger.info("Writing embedded files for Environment to disk.")
273+
else:
274+
self._logger.info("Writing embedded files for Task to disk.")
275+
self._define_symbols(records, symtab)
276+
277+
def _define_symbols(self, records: list["_FileRecord"], symtab: SymbolTable) -> None:
278+
# Add symbols to the symbol table. For EXPR evaluation the
279+
# Env.File.*/Task.File.* symbols are host-format path values
280+
# (property access like `.parent` works), matching openjd-rs;
281+
# the legacy (non-EXPR) interpolation path ignores the type and
282+
# keeps the string form.
283+
for record in records:
284+
symtab[record.symbol] = str(record.filename)
285+
symtab.expr_types[record.symbol] = "PATH"
286+
self._logger.info(
287+
f"Mapping: {record.symbol} -> {record.filename}",
288+
extra=LogExtraInfo(
289+
openjd_log_content=LogContent.FILE_PATH | LogContent.PARAMETER_INFO
290+
),
291+
)
292+
260293
def write_file_contents(self, records: list["_FileRecord"], symtab: SymbolTable) -> None:
261294
"""Resolve each allocated file's ``data`` against ``symtab`` and write
262295
it to disk. See :meth:`allocate_file_paths`."""

0 commit comments

Comments
 (0)