Skip to content

Commit d2e6dcb

Browse files
committed
🤖 Simplify tool policy tests using improved helpers
Now that waitForEvent and assertStreamSuccess provide detailed diagnostics, we can remove the test-specific logging code. The tests now: - Wait for either stream-end or stream-error (prevents timeout) - Rely on helper functions for error diagnostics - Are much more readable and maintainable All the diagnostic logging happens automatically in the helpers, making it a general fix for all integration tests, not just these two. _Generated with `cmux`_
1 parent 188f337 commit d2e6dcb

File tree

1 file changed

+6
-46
lines changed

1 file changed

+6
-46
lines changed

tests/ipcMain/sendMessage.test.ts

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -834,34 +834,14 @@ describeIntegration("IpcMain sendMessage integration tests", () => {
834834
// Wait for stream to complete (longer timeout for tool policy tests)
835835
const collector = createEventCollector(env.sentEvents, workspaceId);
836836

837-
// Wait for either stream-end or stream-error to get diagnostic info
837+
// Wait for either stream-end or stream-error
838+
// (helpers will log diagnostic info on failure)
838839
await Promise.race([
839840
collector.waitForEvent("stream-end", 30000),
840841
collector.waitForEvent("stream-error", 30000),
841842
]);
842843

843-
// Log all events for debugging
844-
const allEvents = collector.getEvents();
845-
console.log(
846-
`[${provider}] Collected events:`,
847-
allEvents.map((e) => ("type" in e ? e.type : "unknown"))
848-
);
849-
850-
// If there was an error, log it for debugging
851-
if (collector.hasError()) {
852-
const errorEvent = allEvents.find((e) => "type" in e && e.type === "stream-error");
853-
if (errorEvent && "error" in errorEvent) {
854-
console.error(`[${provider}] Stream error:`, errorEvent.error);
855-
if ("errorType" in errorEvent) {
856-
console.error(`[${provider}] Error type:`, errorEvent.errorType);
857-
}
858-
}
859-
// Fail the test with the actual error message
860-
throw new Error(
861-
`Stream ended with error instead of completing successfully. Check logs above for details.`
862-
);
863-
}
864-
844+
// This will throw with detailed error info if stream didn't complete successfully
865845
assertStreamSuccess(collector);
866846

867847
// Verify file still exists (bash tool was disabled, so deletion shouldn't have happened)
@@ -913,34 +893,14 @@ describeIntegration("IpcMain sendMessage integration tests", () => {
913893
// Wait for stream to complete (longer timeout for tool policy tests)
914894
const collector = createEventCollector(env.sentEvents, workspaceId);
915895

916-
// Wait for either stream-end or stream-error to get diagnostic info
896+
// Wait for either stream-end or stream-error
897+
// (helpers will log diagnostic info on failure)
917898
await Promise.race([
918899
collector.waitForEvent("stream-end", 30000),
919900
collector.waitForEvent("stream-error", 30000),
920901
]);
921902

922-
// Log all events for debugging
923-
const allEvents = collector.getEvents();
924-
console.log(
925-
`[${provider}] Collected events:`,
926-
allEvents.map((e) => ("type" in e ? e.type : "unknown"))
927-
);
928-
929-
// If there was an error, log it for debugging
930-
if (collector.hasError()) {
931-
const errorEvent = allEvents.find((e) => "type" in e && e.type === "stream-error");
932-
if (errorEvent && "error" in errorEvent) {
933-
console.error(`[${provider}] Stream error:`, errorEvent.error);
934-
if ("errorType" in errorEvent) {
935-
console.error(`[${provider}] Error type:`, errorEvent.errorType);
936-
}
937-
}
938-
// Fail the test with the actual error message
939-
throw new Error(
940-
`Stream ended with error instead of completing successfully. Check logs above for details.`
941-
);
942-
}
943-
903+
// This will throw with detailed error info if stream didn't complete successfully
944904
assertStreamSuccess(collector);
945905

946906
// Verify file content unchanged (file_edit tools and bash were disabled)

0 commit comments

Comments
 (0)