Skip to content

Commit

Permalink
rearrange
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole White committed Mar 5, 2024
1 parent 4028ca5 commit 1a3481a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/handlers/testing/exec/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export enum EventName {

// Zod schemas for event data
const zConsoleLogSchema = z.object({
ctx: z.enum(['cmd', 'cli', 'cli-server']),
ctx: z.enum(['cmd', 'cli']),
level: z.enum(['debug', 'info', 'warn', 'error']),
message: z.string(),
});
Expand Down
30 changes: 21 additions & 9 deletions src/handlers/testing/exec/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,25 @@ class RunManager {
async handleEndRun(args: { testExternalId: string }): Promise<void> {
emitter.emit(EventName.RUN_ENDED, { testExternalId: args.testExternalId });
const runId = this.currentRunId({ testExternalId: args.testExternalId });
await this.post(`/runs/${runId}/end`);
delete this.testExternalIdToRunId[args.testExternalId];
if (this.ciContext) {
await commentOnPullRequest({
context: this.ciContext,
evaluations: this.evaluations,
});
try {
await commentOnPullRequest({
context: this.ciContext,
evaluations: this.evaluations,
});
} catch (err) {
emitter.emit(EventName.CONSOLE_LOG, {
ctx: 'cli',
level: 'error',
message: `Failed to comment on PR: ${err}`,
});
}
}

try {
await this.post(`/runs/${runId}/end`);
} finally {
delete this.testExternalIdToRunId[args.testExternalId];
}
}

Expand Down Expand Up @@ -319,7 +331,7 @@ function createHonoApp(runManager: RunManager): Hono {

app.onError((err, c) => {
emitter.emit(EventName.CONSOLE_LOG, {
ctx: 'cli-server',
ctx: 'cli',
level: 'error',
message: `${c.req.method} ${c.req.path}: ${err.message}`,
});
Expand All @@ -332,7 +344,7 @@ function createHonoApp(runManager: RunManager): Hono {
) => {
if (!result.success) {
emitter.emit(EventName.CONSOLE_LOG, {
ctx: 'cli-server',
ctx: 'cli',
level: 'error',
message: `${c.req.method} ${c.req.path}: ${result.error}`,
});
Expand Down Expand Up @@ -558,7 +570,7 @@ export async function exec(args: {
const serverAddress = `http://localhost:${addressInfo.port}`;

emitter.emit(EventName.CONSOLE_LOG, {
ctx: 'cli-server',
ctx: 'cli',
level: 'info',
message: `Listening on ${serverAddress}`,
});
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/testing/exec/util/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function findAvailablePort(args: {
if ((err as { code?: string } | undefined)?.code === 'EADDRINUSE') {
const nextPort = port + 1;
emitter.emit(EventName.CONSOLE_LOG, {
ctx: 'cli-server',
ctx: 'cli',
level: 'info',
message: `Port ${port} is in use, trying port ${nextPort}...`,
});
Expand Down

0 comments on commit 1a3481a

Please sign in to comment.