harbor run -t openthoughts/tasktrove-exp-rpt-curriculum-hard-curriculum-hard-0403harbor download openthoughts/tasktrove-exp-rpt-curriculum-hard-curriculum-hard-0403# Harder Task: End-to-End Template Update Test Utilities with Concurrency and Edge-Case Robustness
Difficulty uplifted: introduce performance constraints, edge-case handling, and concurrency requirements while preserving the original Python-based test utilities goal.
Overview
- Implement a self-contained Python package at /app/test_utils with an e2e_commands.py module exporting a class CommandTester.
- The class simulates an mlt.json-like configuration and supports operations used by end-to-end tests to drive template updates.
- The implementation must be robust to edge cases (empty input, Unicode, very large values) and thread-safe to support concurrent access in tests.
- No external dependencies allowed.
What to implement (in /app/test_utils/ as a package)
- Create a package test_utils with:
- __init__.py (empty or minimal)
- e2e_commands.py containing the class CommandTester with the exact signatures described below.
Class and methods (must be exactly as specified, with enhanced behavior and safety)
1) Class
- CommandTester
2) Methods
- def init(self, project_name: str) -> None
- Initialize an internal state representing an mlt.json-like configuration.
- By default, set:
- template_name = project_name
- template_git_sha = some placeholder string (e.g., "deadbeef")
- Store these values in an internal dictionary (e.g., self.mlt_json).
- Requirements:
- The internal state must be reset to a clean, predictable baseline on every call.
- Accept Unicode project_name without error and store exactly as provided.
- Ensure memory usage remains O(n) with respect to the amount of keys stored (no unbounded growth per call).
- def config(self, subcommand: str, config_name: str, config_value=None) -> None
- Modify the internal mlt.json representation based on the command.
- Supported behavior:
- If subcommand == "set": set self.mlt_json[config_name] = config_value
- If subcommand == "remove": remove the key named config_name from self.mlt_json if present.
- Special case for tests: if config_name == "template_git_sha" and subcommand == "remove", also remove "template_name" if it exists. This ensures that after the call, neither template_name nor template_git_sha remains, enabling the error path in update_template().
- The method should not raise errors for unknown keys; it should simply modify the internal dict accordingly.
- Edge cases:
- Accept None as a valid config_value for "set" (store None as the value).
- Accept empty strings and extremely large strings; ensure operation completes deterministically.
- If config_name contains dots (e.g., "nested.key"), interpret as a flat key with the dot included (do not perform recursive nesting unless explicitly designed to, to keep compatibility with tests).
- Concurrency safety:
- All modifications must be thread-safe. Acquire an internal lock for each operation to prevent data races when tests run in parallel.
- def update_template(self) -> str
- Simulate performing a template update based on the current internal mlt_json state.
- Behavior:
- If neither "template_name" nor "template_git_sha" is present in self.mlt_json:
- Return exactly the string:
"ERROR: mlt.json does not have either template_name or template_git_sha. Template update is not possible."
- If "template_git_sha" is present:
- Return a string containing (and matching on containment of) the message:
"Latest template changes have merged using git, please review change"
(the tests will search for this substring, so ensure it is included)
- Otherwise (i.e., template_name exists but no template_git_sha):
- Return a non-error message, e.g.:
"Template update skipped; no git SHA provided."
- Thread-safety:
- Access to self.mlt_json must be synchronized to ensure consistent reads even if other threads mutate the state concurrently.
- Performance:
- The operation should be O(1) time with respect to key lookup, and memory usage should be bounded by the number of keys in self.mlt_json.
Notes on testing flow and edge cases
- The test suite imports CommandTester via: from test_utils.e2e_commands import CommandTester.
- Expected test flow (including edge cases):
- test_no_update: self.init('hello-world'); self.update_template() – ensure no crash; no explicit assertion required.
- test_invalid_update: self.init('hello-world'); self.config(subcommand="remove", config_name="template_git_sha"); cmd_output = self.update_template(); expect the exact error string to be contained in cmd_output.
- test_valid_update: (optional in test suite) after self.init('hello-world') and self.config(subcommand="set", config_name="template_git_sha", config_value="abcdef12345"), self.update_template() should contain the git-based success message.
- Stress/edge-case tests to consider:
- Unicode project names, config_name values with Unicode characters.
- Very long strings for template_git_sha and template_name.
- Empty strings, None values, and non-string config_value types (e.g., integers) should not raise errors and should be stored as-is.
- Concurrent invocations of init, config, and update_template from multiple threads to validate thread-safety and no data corruption.
File placement reminder
- Implement the code in /app/test_utils/e2e_commands.py as a package module (and create /app/test_utils/__init__.py).
Actionable deliverables
- A self-contained Python package at /app/test_utils with:
- __init__.py
- e2e_commands.py containing the described CommandTester class and methods with the exact signatures and enhanced behaviors:
- Thread-safe state management via internal locking
- Correct handling of the special remove-case for template_git_sha
- Edge-case tolerant input handling (unicode, empty, large values)
- Deterministic outputs as specified for update_template, including the exact error string when applicable and the required substring for success cases
Constraints
- No external dependencies beyond the Python standard library.
- Maintain Pythonic type hints and clear documentation within the module.
- Ensure compatibility with the existing tests that import CommandTester from test_utils.e2e_commands.
- Preserve the exact method names and signatures; only internal behavior and safety enhancements are added.