55import org .junit .jupiter .api .io .TempDir ;
66import picocli .CommandLine ;
77
8+ import java .io .IOException ;
89import java .nio .file .Files ;
910import java .nio .file .Path ;
1011
11- import static org .junit . jupiter .api .Assertions .* ;
12+ import static org .assertj . core .api .Assertions .assertThat ;
1213
1314@ QuarkusTest
1415class InitSkillsCommandTest {
@@ -18,14 +19,14 @@ void shouldGenerateAllSkillFiles(@TempDir Path tempDir) {
1819 CommandLine commandLine = new CommandLine (new InitSkillsCommand ());
1920 int exitCode = commandLine .execute ("--dir" , tempDir .toString ());
2021
21- assertEquals ( 0 , exitCode );
22- assertFalse ( Files . exists ( tempDir .resolve ("AGENTS.md" )));
23- assertTrue ( Files . exists ( tempDir .resolve (".agents/skills/dochia-test/SKILL.md" )));
24- assertTrue ( Files . exists ( tempDir .resolve (".agents/skills/dochia-fuzz/SKILL.md" )));
25- assertTrue ( Files . exists ( tempDir .resolve (".agents/skills/dochia-replay/SKILL.md" )));
26- assertTrue ( Files . exists ( tempDir .resolve (".agents/skills/dochia-list/SKILL.md" )));
27- assertTrue ( Files . exists ( tempDir .resolve (".agents/skills/dochia-explain/SKILL.md" )));
28- assertTrue ( Files . exists ( tempDir .resolve (".agents/skills/dochia-test/references/report-output.md" )));
22+ assertThat ( exitCode ). isZero ( );
23+ assertThat ( tempDir .resolve ("AGENTS.md" )). doesNotExist ( );
24+ assertThat ( tempDir .resolve (".agents/skills/dochia-test/SKILL.md" )). exists ( );
25+ assertThat ( tempDir .resolve (".agents/skills/dochia-fuzz/SKILL.md" )). exists ( );
26+ assertThat ( tempDir .resolve (".agents/skills/dochia-replay/SKILL.md" )). exists ( );
27+ assertThat ( tempDir .resolve (".agents/skills/dochia-list/SKILL.md" )). exists ( );
28+ assertThat ( tempDir .resolve (".agents/skills/dochia-explain/SKILL.md" )). exists ( );
29+ assertThat ( tempDir .resolve (".agents/skills/dochia-test/references/report-output.md" )). exists ( );
2930 }
3031
3132 @ Test
@@ -37,10 +38,9 @@ void shouldNotOverwriteExistingFilesWithoutForce(@TempDir Path tempDir) throws E
3738 CommandLine commandLine = new CommandLine (new InitSkillsCommand ());
3839 int exitCode = commandLine .execute ("--dir" , tempDir .toString ());
3940
40- assertEquals (0 , exitCode );
41- assertEquals ("existing content" , Files .readString (skillFile ));
42- // Other skills should still be created
43- assertTrue (Files .exists (tempDir .resolve (".agents/skills/dochia-fuzz/SKILL.md" )));
41+ assertThat (exitCode ).isZero ();
42+ assertThat (Files .readString (skillFile )).isEqualTo ("existing content" );
43+ assertThat (tempDir .resolve (".agents/skills/dochia-fuzz/SKILL.md" )).exists ();
4444 }
4545
4646 @ Test
@@ -52,10 +52,25 @@ void shouldOverwriteExistingFilesWithForce(@TempDir Path tempDir) throws Excepti
5252 CommandLine commandLine = new CommandLine (new InitSkillsCommand ());
5353 int exitCode = commandLine .execute ("--dir" , tempDir .toString (), "--force" );
5454
55- assertEquals (0 , exitCode );
56- String content = Files .readString (skillFile );
57- assertNotEquals ("existing content" , content );
58- assertTrue (content .contains ("dochia-test" ));
55+ assertThat (exitCode ).isZero ();
56+ assertThat (Files .readString (skillFile ))
57+ .isNotEqualTo ("existing content" )
58+ .contains ("dochia-test" );
59+ }
60+
61+ @ Test
62+ void shouldOverwriteExistingFilesWithShortForceFlag (@ TempDir Path tempDir ) throws Exception {
63+ Path skillFile = tempDir .resolve (".agents/skills/dochia-test/SKILL.md" );
64+ Files .createDirectories (skillFile .getParent ());
65+ Files .writeString (skillFile , "existing content" );
66+
67+ CommandLine commandLine = new CommandLine (new InitSkillsCommand ());
68+ int exitCode = commandLine .execute ("--dir" , tempDir .toString (), "-f" );
69+
70+ assertThat (exitCode ).isZero ();
71+ assertThat (Files .readString (skillFile ))
72+ .isNotEqualTo ("existing content" )
73+ .contains ("dochia-test" );
5974 }
6075
6176 @ Test
@@ -64,23 +79,77 @@ void shouldContainValidSkillFrontmatter(@TempDir Path tempDir) throws Exception
6479 commandLine .execute ("--dir" , tempDir .toString ());
6580
6681 String testSkill = Files .readString (tempDir .resolve (".agents/skills/dochia-test/SKILL.md" ));
67- assertTrue (testSkill .startsWith ("---" ));
68- assertTrue (testSkill .contains ("name: dochia-test" ));
69- assertTrue (testSkill .contains ("description:" ));
70- assertTrue (testSkill .contains ("metadata:" ));
71- assertTrue (testSkill .contains ("triggers:" ));
72- assertTrue (testSkill .contains ("examples:" ));
82+ assertThat (testSkill )
83+ .startsWith ("---" )
84+ .contains ("name: dochia-test" )
85+ .contains ("description:" )
86+ .contains ("metadata:" )
87+ .contains ("triggers:" )
88+ .contains ("examples:" );
7389
7490 String fuzzSkill = Files .readString (tempDir .resolve (".agents/skills/dochia-fuzz/SKILL.md" ));
75- assertTrue (fuzzSkill .contains ("name: dochia-fuzz" ));
76- assertTrue (fuzzSkill .contains ("metadata:" ));
91+ assertThat (fuzzSkill )
92+ .contains ("name: dochia-fuzz" )
93+ .contains ("metadata:" );
7794 }
7895
7996 @ Test
8097 void shouldReadResources () {
8198 InitSkillsCommand command = new InitSkillsCommand ();
8299 String content = command .readResource ("skills/dochia-test/SKILL.md" );
83- assertNotNull (content );
84- assertTrue (content .contains ("dochia-test" ));
100+
101+ assertThat (content ).isNotNull ().contains ("dochia-test" );
102+ }
103+
104+ @ Test
105+ void shouldReturnNullForNonexistentResource () {
106+ InitSkillsCommand command = new InitSkillsCommand ();
107+ String content = command .readResource ("nonexistent/resource.md" );
108+
109+ assertThat (content ).isNull ();
110+ }
111+
112+ @ Test
113+ void shouldReturnFalseWhenResourceNotFound (@ TempDir Path tempDir ) throws IOException {
114+ InitSkillsCommand command = new InitSkillsCommand ();
115+ Path target = tempDir .resolve ("nonexistent/SKILL.md" );
116+
117+ boolean result = command .writeResourceFile ("nonexistent/resource.md" , target );
118+
119+ assertThat (result ).isFalse ();
120+ assertThat (target ).doesNotExist ();
121+ }
122+
123+ @ Test
124+ void shouldReturnZeroExitCodeOnSuccess (@ TempDir Path tempDir ) {
125+ InitSkillsCommand command = new InitSkillsCommand ();
126+ CommandLine commandLine = new CommandLine (command );
127+ commandLine .execute ("--dir" , tempDir .toString ());
128+
129+ assertThat (command .getExitCode ()).isZero ();
130+ }
131+
132+ @ Test
133+ void shouldUseShortDirFlag (@ TempDir Path tempDir ) {
134+ CommandLine commandLine = new CommandLine (new InitSkillsCommand ());
135+ int exitCode = commandLine .execute ("-d" , tempDir .toString ());
136+
137+ assertThat (exitCode ).isZero ();
138+ assertThat (tempDir .resolve (".agents/skills/dochia-test/SKILL.md" )).exists ();
139+ }
140+
141+ @ Test
142+ void shouldBeIdempotentWhenRunTwiceWithForce (@ TempDir Path tempDir ) throws Exception {
143+ CommandLine commandLine1 = new CommandLine (new InitSkillsCommand ());
144+ commandLine1 .execute ("--dir" , tempDir .toString ());
145+
146+ String firstRun = Files .readString (tempDir .resolve (".agents/skills/dochia-test/SKILL.md" ));
147+
148+ CommandLine commandLine2 = new CommandLine (new InitSkillsCommand ());
149+ commandLine2 .execute ("--dir" , tempDir .toString (), "--force" );
150+
151+ String secondRun = Files .readString (tempDir .resolve (".agents/skills/dochia-test/SKILL.md" ));
152+
153+ assertThat (secondRun ).isEqualTo (firstRun );
85154 }
86155}
0 commit comments