@@ -296,3 +296,83 @@ def test_main_missing_tech_spec_file_exits(
296296 assert excinfo .value .code == 1
297297 err = capsys .readouterr ().err
298298 assert f"Error: Tech spec file not found: { missing_tech } " in err
299+
300+
301+ def test_main_nonexistent_target_dir_exits (
302+ monkeypatch : pytest .MonkeyPatch , tmp_path : Path , capsys : pytest .CaptureFixture [str ]
303+ ) -> None :
304+ """Test that main() exits when target directory doesn't exist."""
305+ # Create both input files
306+ prd_file = tmp_path / "prd.md"
307+ tech_spec_file = tmp_path / "tech_spec.md"
308+ prd_file .write_text ("PRD content" )
309+ tech_spec_file .write_text ("Tech spec content" )
310+
311+ # Use non-existent target directory
312+ nonexistent_dir = tmp_path / "nonexistent"
313+
314+ with monkeypatch .context ():
315+ monkeypatch .setenv ("OPENAI_API_KEY" , "test-key" )
316+ monkeypatch .setattr (
317+ "storymachine.cli.OpenAI" , MagicMock (return_value = MagicMock ())
318+ )
319+ monkeypatch .setattr (
320+ sys ,
321+ "argv" ,
322+ [
323+ "storymachine" ,
324+ "--prd" ,
325+ str (prd_file ),
326+ "--tech-spec" ,
327+ str (tech_spec_file ),
328+ "--target-dir" ,
329+ str (nonexistent_dir ),
330+ ],
331+ )
332+
333+ with pytest .raises (SystemExit ) as excinfo :
334+ main ()
335+
336+ assert excinfo .value .code == 1
337+ err = capsys .readouterr ().err
338+ assert f"Error: Target directory not found: { nonexistent_dir } " in err
339+
340+
341+ def test_main_target_is_file_exits (
342+ monkeypatch : pytest .MonkeyPatch , tmp_path : Path , capsys : pytest .CaptureFixture [str ]
343+ ) -> None :
344+ """Test that main() exits when target path is a file, not a directory."""
345+ # Create both input files
346+ prd_file = tmp_path / "prd.md"
347+ tech_spec_file = tmp_path / "tech_spec.md"
348+ target_file = tmp_path / "target.txt"
349+
350+ prd_file .write_text ("PRD content" )
351+ tech_spec_file .write_text ("Tech spec content" )
352+ target_file .write_text ("This is a file, not a directory" )
353+
354+ with monkeypatch .context ():
355+ monkeypatch .setenv ("OPENAI_API_KEY" , "test-key" )
356+ monkeypatch .setattr (
357+ "storymachine.cli.OpenAI" , MagicMock (return_value = MagicMock ())
358+ )
359+ monkeypatch .setattr (
360+ sys ,
361+ "argv" ,
362+ [
363+ "storymachine" ,
364+ "--prd" ,
365+ str (prd_file ),
366+ "--tech-spec" ,
367+ str (tech_spec_file ),
368+ "--target-dir" ,
369+ str (target_file ),
370+ ],
371+ )
372+
373+ with pytest .raises (SystemExit ) as excinfo :
374+ main ()
375+
376+ assert excinfo .value .code == 1
377+ err = capsys .readouterr ().err
378+ assert f"Error: Target path is not a directory: { target_file } " in err
0 commit comments