|
33 | 33 | import java.nio.file.Files; |
34 | 34 | import java.nio.file.Path; |
35 | 35 |
|
| 36 | +import static io.github.cowwoc.requirements13.java.DefaultJavaValidators.requireThat; |
| 37 | + |
36 | 38 | /** |
37 | 39 | * Exercises all handler code paths in a single JVM invocation for AOT training. |
38 | 40 | * <p> |
@@ -71,80 +73,103 @@ public static void main(String[] args) throws Exception |
71 | 73 | try (AbstractClaudeHook scope = new MainClaudeHook()) |
72 | 74 | { |
73 | 75 | System.setIn(originalIn); |
| 76 | + System.exit(run(scope)); |
| 77 | + } |
| 78 | + } |
74 | 79 |
|
75 | | - // Hook handlers all accept the unified ClaudeHook scope |
76 | | - new PreToolUseHook(scope).run(scope); |
77 | | - new PostBashHook().run(scope); |
78 | | - new PreReadHook(scope).run(scope); |
79 | | - new PostReadHook(scope).run(scope); |
80 | | - new PostToolUseHook(scope).run(scope); |
81 | | - new UserPromptSubmitHook(scope).run(scope); |
82 | | - new PreAskHook(scope).run(scope); |
83 | | - new PreWriteHook(scope).run(scope); |
84 | | - new PreIssueHook(scope).run(scope); |
85 | | - new SessionEndHook(scope).run(scope); |
86 | | - new SessionStartHook(scope, Path.of("/tmp/aot-training-env")).run(scope); |
87 | | - new SubagentStartHook(scope).run(scope); |
| 80 | + /** |
| 81 | + * Exercises all hook handler and skill constructor code paths for AOT training. |
| 82 | + * <p> |
| 83 | + * SYNC: Keep handler list synchronized with HANDLERS array in hooks/build-jlink.sh. |
| 84 | + * When adding a new handler, update both locations: |
| 85 | + * <ul> |
| 86 | + * <li>Add launcher entry to HANDLERS array in build-jlink.sh</li> |
| 87 | + * <li>Add training invocation to this method</li> |
| 88 | + * </ul> |
| 89 | + * |
| 90 | + * @param scope the hook scope providing access to services and configuration |
| 91 | + * @throws NullPointerException if {@code scope} is null |
| 92 | + * @throws Exception if training fails |
| 93 | + * @return 0 on success, non-zero on failure |
| 94 | + */ |
| 95 | + @SuppressWarnings("ResultOfMethodCallIgnored") |
| 96 | + public static int run(AbstractClaudeHook scope) throws Exception |
| 97 | + { |
| 98 | + requireThat(scope, "scope").isNotNull(); |
88 | 99 |
|
89 | | - // Skill handlers - construct to load class graphs. |
90 | | - // Calling getOutput() would read the filesystem, which is unnecessary for training. |
91 | | - // GetDiffOutput and GetCleanupOutput accept JvmScope (no session required). |
92 | | - // GetStatusOutput and GetOutput require AbstractClaudeTool (session-aware); use referenceClass() instead. |
93 | | - new GetDiffOutput(scope); |
94 | | - new GetCleanupOutput(scope); |
95 | | - referenceClass(GetStatusOutput.class); |
96 | | - referenceClass(GetOutput.class); |
| 100 | + // Hook handlers all accept the unified ClaudeHook scope |
| 101 | + new PreToolUseHook(scope).run(scope); |
| 102 | + new PostBashHook().run(scope); |
| 103 | + new PreReadHook(scope).run(scope); |
| 104 | + new PostReadHook(scope).run(scope); |
| 105 | + new PostToolUseHook(scope).run(scope); |
| 106 | + new UserPromptSubmitHook(scope).run(scope); |
| 107 | + new PreAskHook(scope).run(scope); |
| 108 | + new PreWriteHook(scope).run(scope); |
| 109 | + new PreIssueHook(scope).run(scope); |
| 110 | + new SessionEndHook(scope).run(scope); |
| 111 | + new SessionStartHook(scope).run(scope); |
| 112 | + new SubagentStartHook(scope).run(scope); |
97 | 113 |
|
98 | | - // VerifyAudit training - create temp directory with plan.md for prepare() and minimal JSON for report() |
99 | | - Path tempDir = Files.createTempDirectory("aot-training-"); |
100 | | - try |
101 | | - { |
102 | | - Path planFile = tempDir.resolve("plan.md"); |
103 | | - Files.writeString(planFile, """ |
104 | | - # Plan |
105 | | - ## Post-conditions |
106 | | - - [ ] Test criterion |
107 | | - ## Files to Modify |
108 | | - - test.md |
109 | | - """); |
| 114 | + // Skill handlers - construct to load class graphs. |
| 115 | + // Calling getOutput() would read the filesystem, which is unnecessary for training. |
| 116 | + // GetDiffOutput and GetCleanupOutput accept JvmScope (no session required). |
| 117 | + // GetStatusOutput and GetOutput require AbstractClaudeTool (session-aware); use referenceClass() instead. |
| 118 | + new GetDiffOutput(scope); |
| 119 | + new GetCleanupOutput(scope); |
| 120 | + referenceClass(GetStatusOutput.class); |
| 121 | + referenceClass(GetOutput.class); |
110 | 122 |
|
111 | | - VerifyAudit audit = new VerifyAudit(scope); |
112 | | - String prepareArgs = """ |
113 | | - { |
114 | | - "issue_id": "aot-training", |
115 | | - "issue_path": "%s", |
116 | | - "worktree_path": "%s" |
117 | | - } |
118 | | - """.formatted(tempDir.toString(), tempDir.toString()); |
119 | | - audit.prepare(prepareArgs); |
120 | | - audit.report("test-issue", "{\"criteria_results\": [], \"file_results\": {\"modify\": {}, \"delete\": {}}}"); |
121 | | - } |
122 | | - finally |
123 | | - { |
124 | | - Files.deleteIfExists(tempDir.resolve("plan.md")); |
125 | | - Files.deleteIfExists(tempDir); |
126 | | - } |
| 123 | + // VerifyAudit training - create temp directory with plan.md for prepare() and minimal JSON for report() |
| 124 | + Path tempDir = Files.createTempDirectory("aot-training-"); |
| 125 | + try |
| 126 | + { |
| 127 | + Path planFile = tempDir.resolve("plan.md"); |
| 128 | + Files.writeString(planFile, """ |
| 129 | + # Plan |
| 130 | + ## Post-conditions |
| 131 | + - [ ] Test criterion |
| 132 | + ## Files to Modify |
| 133 | + - test.md |
| 134 | + """); |
127 | 135 |
|
128 | | - // Reference arg-based classes to force class loading without invoking main() |
129 | | - // (their main() calls System.exit on missing args) |
130 | | - referenceClass(EnforceStatusOutput.class); |
131 | | - referenceClass(TokenCounter.class); |
132 | | - referenceClass(GetCheckpointOutput.class); |
133 | | - referenceClass(GetIssueCompleteOutput.class); |
134 | | - referenceClass(GetNextIssueOutput.class); |
135 | | - referenceClass(SessionAnalyzer.class); |
136 | | - referenceClass(ProgressBanner.class); |
137 | | - referenceClass(EmpiricalTestRunner.class); |
138 | | - referenceClass(WorkPrepare.class); |
139 | | - referenceClass(MarkdownWrapper.class); |
140 | | - referenceClass(BatchReader.class); |
141 | | - referenceClass(GetSubagentStatusOutput.class); |
142 | | - referenceClass(HookRegistrar.class); |
143 | | - referenceClass(StatusAlignmentValidator.class); |
144 | | - referenceClass(GetSkill.class); |
145 | | - referenceClass(GetFile.class); |
146 | | - referenceClass(Feedback.class); |
| 136 | + VerifyAudit audit = new VerifyAudit(scope); |
| 137 | + String prepareArgs = """ |
| 138 | + { |
| 139 | + "issue_id": "aot-training", |
| 140 | + "issue_path": "%s", |
| 141 | + "worktree_path": "%s" |
| 142 | + } |
| 143 | + """.formatted(tempDir.toString(), tempDir.toString()); |
| 144 | + audit.prepare(prepareArgs); |
| 145 | + audit.report("test-issue", "{\"criteria_results\": [], \"file_results\": {\"modify\": {}, \"delete\": {}}}"); |
| 146 | + } |
| 147 | + finally |
| 148 | + { |
| 149 | + Files.deleteIfExists(tempDir.resolve("plan.md")); |
| 150 | + Files.deleteIfExists(tempDir); |
147 | 151 | } |
| 152 | + |
| 153 | + // Reference arg-based classes to force class loading without invoking main() |
| 154 | + // (their main() calls System.exit on missing args) |
| 155 | + referenceClass(EnforceStatusOutput.class); |
| 156 | + referenceClass(TokenCounter.class); |
| 157 | + referenceClass(GetCheckpointOutput.class); |
| 158 | + referenceClass(GetIssueCompleteOutput.class); |
| 159 | + referenceClass(GetNextIssueOutput.class); |
| 160 | + referenceClass(SessionAnalyzer.class); |
| 161 | + referenceClass(ProgressBanner.class); |
| 162 | + referenceClass(EmpiricalTestRunner.class); |
| 163 | + referenceClass(WorkPrepare.class); |
| 164 | + referenceClass(MarkdownWrapper.class); |
| 165 | + referenceClass(BatchReader.class); |
| 166 | + referenceClass(GetSubagentStatusOutput.class); |
| 167 | + referenceClass(HookRegistrar.class); |
| 168 | + referenceClass(StatusAlignmentValidator.class); |
| 169 | + referenceClass(GetSkill.class); |
| 170 | + referenceClass(GetFile.class); |
| 171 | + referenceClass(Feedback.class); |
| 172 | + return 0; |
148 | 173 | } |
149 | 174 |
|
150 | 175 | /** |
|
0 commit comments