Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 63 additions & 2 deletions tests/e2e/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def temp_non_git_dir(self):
with tempfile.TemporaryDirectory() as temp_dir:
yield Path(temp_dir)

def run_cli(self, args, cwd=None, use_test_runner=False):
def run_cli(self, args, cwd=None, use_test_runner=False, input: str | None = None):
"""Run the CLI and return result."""
if use_test_runner:
# Use test runner that patches collect_var_value
Expand All @@ -46,7 +46,7 @@ def run_cli(self, args, cwd=None, use_test_runner=False):

cmd = ["python", str(cli_path)] + args

result = subprocess.run(cmd, cwd=cwd, capture_output=True, text=True)
result = subprocess.run(cmd, cwd=cwd, input=input, capture_output=True, text=True)
return result

def test_init_in_git_repo(self, temp_git_repo):
Expand Down Expand Up @@ -595,3 +595,64 @@ def test_create_spec_with_var_and_output_file(self, temp_non_git_dir):
assert output_file.exists()
content = output_file.read_text()
assert "Project: MyApp, Version: 1.0.0" in content

def test_create_spec_pipe_mode(self, temp_non_git_dir):
"""Test create-spec with stdin pipe mode (no template file argument)."""
# Template content to pipe via stdin
template_content = (
"# Task Template\n\n## Ticket description\n\n{{ ticket.id }}\n\n{{ ticket.description }}\n\n"
"## Additional context\n\n{{ additional_context }}"
)

# Run create-spec command without template file argument, piping template via stdin
result = self.run_cli(
[
"create-spec",
"--verbose",
"--var",
"ticket={\"id\":1}",
"--var",
"additional_context=test context",
],
cwd=temp_non_git_dir,
input=template_content,
)

assert result.returncode == 0

# Verify rendered template output contains expected content
assert "# Task Template" in result.stdout
assert "## Ticket description" in result.stdout
assert "1" in result.stdout # ticket.id
assert "## Additional context" in result.stdout
assert "test context" in result.stdout

def test_create_spec_pipe_mode_with_output_file(self, temp_non_git_dir):
"""Test create-spec with stdin pipe mode and --output flag."""
# Template content to pipe via stdin
template_content = "Piped template: {{ message }}"

# Define output file
output_file = temp_non_git_dir / "piped_output.md"

# Run create-spec command with stdin and --output
result = self.run_cli(
[
"create-spec",
"--verbose",
"--var",
"message=Hello from pipe!",
"--output",
str(output_file),
],
cwd=temp_non_git_dir,
input=template_content,
)

assert result.returncode == 0
assert f"Rendered template saved to: {output_file}" in result.stderr

# Verify file was created and contains expected content
assert output_file.exists()
content = output_file.read_text()
assert "Piped template: Hello from pipe!" in content