Skip to content

Commit

Permalink
Add autofix (#184)
Browse files Browse the repository at this point in the history
This PR addresses Issue: #182 

Copied the Autofix workflow from Iffy. 
Changed it to use pnpm instead of npm

---------

Co-authored-by: Sahil Lavingia <sahil.lavingia@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 27, 2024
1 parent 63ad902 commit 71f4745
Show file tree
Hide file tree
Showing 22 changed files with 4,379 additions and 5,432 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: autofix.ci # needed to securely identify the workflow

on:
pull_request:
push:
branches: ["main"]
permissions:
contents: read

jobs:
autofix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
with:
version: 8

- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- run: pnpm install

- name: Lint
run: pnpm eslint . --fix
shell: bash

- name: Typecheck
shell: bash
run: |
set -eo pipefail
export NODE_OPTIONS="--max_old_space_size=4096"
pnpm run typecheck
- uses: autofix-ci/action@ff86a557419858bb967097bfc916833f5647fa8c
2 changes: 1 addition & 1 deletion app/(dashboard)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { SignedIn, SignedOut } from "@clerk/nextjs";
import { Code } from "bright";
import { ArrowRight } from "lucide-react";
import Link from "next/link";
import { Button } from "@/components/ui/button";
import { Code } from "bright";

export default function HomePage() {
return (
Expand Down
21 changes: 9 additions & 12 deletions app/api/github/webhook/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { revalidateTag } from "next/cache";
import { NextResponse } from "next/server";
import { type NextRequest } from "next/server";
import { getOctokit } from "@/lib/github";

export async function POST(request: NextRequest) {
const octokit = await getOctokit();

let payload;
try {
payload = await request.json();
Expand All @@ -29,16 +26,16 @@ export async function POST(request: NextRequest) {
try {
switch (githubEvent) {
case "push":
await handlePushEvent(payload, octokit);
await handlePushEvent(payload);
break;
case "pull_request":
await handlePullRequestEvent(payload, octokit);
await handlePullRequestEvent(payload);
break;
case "check_run":
await handleCheckRunEvent(payload, octokit);
await handleCheckRunEvent(payload);
break;
case "check_suite":
await handleCheckSuiteEvent(payload, octokit);
await handleCheckSuiteEvent(payload);
break;
default:
console.log(`Unhandled event type: ${githubEvent}`);
Expand All @@ -54,18 +51,18 @@ export async function POST(request: NextRequest) {
}
}

async function handlePushEvent(payload: any, octokit: any) {
const { repository, commits } = payload;
async function handlePushEvent(payload: any) {
const { repository } = payload;
console.log(`New push to ${repository.full_name}`);
}

async function handlePullRequestEvent(payload: any, octokit: any) {
async function handlePullRequestEvent(payload: any) {
const { action, pull_request, repository } = payload;
console.log(`Pull request ${action} in ${repository.full_name}`);
revalidateTag(`pullRequest-${pull_request.id}`);
}

async function handleCheckRunEvent(payload: any, octokit: any) {
async function handleCheckRunEvent(payload: any) {
const { action, check_run, repository } = payload;
console.log(`Check run ${action} in ${repository.full_name}`);
if (check_run.pull_requests && check_run.pull_requests.length > 0) {
Expand All @@ -75,7 +72,7 @@ async function handleCheckRunEvent(payload: any, octokit: any) {
}
}

async function handleCheckSuiteEvent(payload: any, octokit: any) {
async function handleCheckSuiteEvent(payload: any) {
const { action, check_suite, repository } = payload;
console.log(`Check suite ${action} in ${repository.full_name}`);
if (check_suite.pull_requests && check_suite.pull_requests.length > 0) {
Expand Down
1 change: 0 additions & 1 deletion app/api/stripe/checkout/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export async function GET(request: NextRequest) {
throw new Error("Invalid customer data from Stripe.");
}

const customerId = session.customer.id;
const subscriptionId =
typeof session.subscription === "string"
? session.subscription
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import typescriptEslintParser from "@typescript-eslint/parser";

export default [
{
ignores: ["node_modules/**", "dist/**"],
ignores: ["node_modules/**", "dist/**", ".next/**", "packages/shortest/node_modules/**", "packages/shortest/dist/**", "**/*.d.ts"],
},
{
files: ["**/*.ts", "**/*.tsx"],
Expand Down
22 changes: 10 additions & 12 deletions hooks/use-toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ type ToasterToast = ToastProps & {
action?: ToastActionElement;
};

const actionTypes = {
ADD_TOAST: "ADD_TOAST",
UPDATE_TOAST: "UPDATE_TOAST",
DISMISS_TOAST: "DISMISS_TOAST",
REMOVE_TOAST: "REMOVE_TOAST",
} as const;
type ActionTypes = {
ADD_TOAST: "ADD_TOAST";
UPDATE_TOAST: "UPDATE_TOAST";
DISMISS_TOAST: "DISMISS_TOAST";
REMOVE_TOAST: "REMOVE_TOAST";
};

let count = 0;

Expand All @@ -29,23 +29,21 @@ function genId() {
return count.toString();
}

type ActionType = typeof actionTypes;

type Action =
| {
type: ActionType["ADD_TOAST"];
type: ActionTypes["ADD_TOAST"];
toast: ToasterToast;
}
| {
type: ActionType["UPDATE_TOAST"];
type: ActionTypes["UPDATE_TOAST"];
toast: Partial<ToasterToast>;
}
| {
type: ActionType["DISMISS_TOAST"];
type: ActionTypes["DISMISS_TOAST"];
toastId?: ToasterToast["id"];
}
| {
type: ActionType["REMOVE_TOAST"];
type: ActionTypes["REMOVE_TOAST"];
toastId?: ToasterToast["id"];
};

Expand Down
2 changes: 0 additions & 2 deletions lib/db/seed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { stripe } from "../payments/stripe";
import { db } from "./drizzle";
import { users } from "./schema";

async function createStripeProducts() {
console.log("Creating Stripe products and prices...");
Expand Down
7 changes: 0 additions & 7 deletions lib/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,6 @@ export async function getWorkflowLogs(
const octokit = await getOctokit();

try {
// Get workflow run information
const { data: workflowRun } = await octokit.actions.getWorkflowRun({
owner,
repo,
run_id: parseInt(runId),
});

// Download logs
const response = await octokit.actions.downloadWorkflowRunLogs({
owner,
Expand Down
12 changes: 4 additions & 8 deletions lib/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function checkStripeCLI() {
console.log("Stripe CLI is authenticated.");
} catch (error) {
console.log(
"Stripe CLI is not authenticated or the authentication has expired.",
`Stripe CLI is not authenticated or the authentication has expired. ${error}`,
);
console.log("Please run: stripe login");
const answer = await question(
Expand All @@ -53,16 +53,12 @@ async function checkStripeCLI() {
await execAsync("stripe config --list");
console.log("Stripe CLI authentication confirmed.");
} catch (error) {
console.error(
"Failed to verify Stripe CLI authentication. Please try again.",
);
console.error(`Failed to verify Stripe CLI authentication. ${error}`);
process.exit(1);
}
}
} catch (error) {
console.error(
"Stripe CLI is not installed. Please install it and try again.",
);
console.error(`Stripe CLI is not installed. ${error}`);
console.log("To install Stripe CLI, follow these steps:");
console.log("1. Visit: https://docs.stripe.com/stripe-cli");
console.log(
Expand Down Expand Up @@ -209,7 +205,7 @@ volumes:
};
} catch (error) {
console.error(
"Failed to start Docker container or extract environment variables. Please check your Docker installation and try again.",
`Failed to start Docker container or extract environment variables. ${error}`,
);
process.exit(1);
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"test": "shortest",
"prepare": "cd packages/shortest && pnpm build",
"lint": "eslint .",
"lint:fix": "eslint . --fix"

"lint:fix": "eslint . --fix",
"typecheck": "tsc --noEmit --incremental"
},
"dependencies": {
"@ai-sdk/anthropic": "^0.0.50",
Expand Down
8 changes: 4 additions & 4 deletions packages/shortest/src/ai/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ export class AIClient {
async makeRequest(
prompt: string,
browserTool: BrowserTool,
outputCallback?: (
_outputCallback?: (
content: Anthropic.Beta.Messages.BetaContentBlockParam,
) => void,
toolOutputCallback?: (name: string, input: any) => void,
_toolOutputCallback?: (name: string, input: any) => void,
) {
const messages: Anthropic.Beta.Messages.BetaMessageParam[] = [];

Expand Down Expand Up @@ -127,8 +127,8 @@ export class AIClient {

// Log tool results
if (this.debugMode) {
results.forEach((result, i) => {
const { base64_image, ...logResult } = result;
results.forEach((result) => {
const { ...logResult } = result;
console.log(pc.blue("\n🔧 Tool Result:"), logResult);
});
}
Expand Down
13 changes: 9 additions & 4 deletions packages/shortest/src/browser/core/browser-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from "fs";
import { join } from "path";
import pc from "picocolors";
import { Page, Browser } from "playwright";
import { Page } from "playwright";
import { TestContext, BrowserToolConfig, TestFunction } from "../../types";
import { ActionInput, ToolResult, BetaToolType } from "../../types/browser";
import { CallbackError } from "../../types/test";
Expand Down Expand Up @@ -65,6 +65,10 @@ export class BrowserTool extends BaseBrowserTool {
await this.initializeCursor();
break;
} catch (error) {
console.warn(
`Retry ${i + 1}/3: Cursor initialization failed:`,
error,
);
await new Promise((resolve) => setTimeout(resolve, 100));
}
}
Expand Down Expand Up @@ -392,8 +396,8 @@ export class BrowserTool extends BaseBrowserTool {
.waitForLoadState("load", {
timeout: 5000,
})
.catch((e) => {
console.log("⚠️ Load timeout, continuing anyway");
.catch((error) => {
console.log("⚠️ Load timeout, continuing anyway", error);
});

// Switch focus
Expand Down Expand Up @@ -499,6 +503,7 @@ export class BrowserTool extends BaseBrowserTool {

return metadata;
} catch (error) {
console.warn("Failed to get metadata:", error);
// Return whatever metadata we collected
return metadata;
}
Expand Down Expand Up @@ -606,7 +611,7 @@ export class BrowserTool extends BaseBrowserTool {
try {
unlinkSync(file.path);
} catch (error) {
console.warn(`Failed to delete screenshot: ${file.path}`);
console.warn(`Failed to delete screenshot: ${file.path}`, error);
}
}
});
Expand Down
2 changes: 0 additions & 2 deletions packages/shortest/src/browser/integrations/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ export class GitHubTool {
await browserTool.press(this.selectors.otpInput, "Enter");
await navigationPromise;

// Get current URL to verify login success
const currentUrl = await browserTool.getPage().url();
const isLoggedIn =
(await browserTool.findElement(this.selectors.loginForm)) === null;

Expand Down
3 changes: 2 additions & 1 deletion packages/shortest/src/cli/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ async function setup() {
const browser = await chromium.launch();
await browser.close();
}
} catch (err) {
} catch (error) {
console.warn(
pc.yellow("\nWarning: Playwright browser installation failed"),
error,
);
console.log(
pc.cyan("Please run manually: npx playwright install chromium\n"),
Expand Down
2 changes: 1 addition & 1 deletion packages/shortest/src/core/builder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class TestBuilder {
return lines.filter(Boolean).join("\n");
}

static async parseModule(compiledModule: any): Promise<TestFunction[]> {
static async parseModule(_compiledModule: any): Promise<TestFunction[]> {
// Get tests from global registry
const registry = (global as any).__shortest__.registry;
const tests = Array.from(registry.tests.values()).flat();
Expand Down
2 changes: 0 additions & 2 deletions packages/shortest/src/core/compiler/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { mkdirSync, existsSync, writeFileSync } from "fs";
import { tmpdir } from "os";
import { join, resolve } from "path";
import { dirname } from "path";
import { fileURLToPath } from "url";
import { build, BuildOptions } from "esbuild";

export class TestCompiler {
Expand Down
3 changes: 1 addition & 2 deletions packages/shortest/src/core/runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import Anthropic from "@anthropic-ai/sdk";
import { glob } from "glob";
import { APIRequest, BrowserContext } from "playwright";
import * as playwright from "playwright";
import { request, chromium, APIRequestContext } from "playwright";
import { request, APIRequestContext } from "playwright";
import { AIClient } from "../../ai/client";
import { BrowserTool } from "../../browser/core/browser-tool";
import { BrowserManager } from "../../browser/manager";
import { initialize, getConfig } from "../../index";
import { TestFunction, TestContext, ShortestConfig } from "../../types";
import { Logger } from "../../utils/logger";
import { TestBuilder } from "../builder";
import { TestCompiler } from "../compiler";

interface TestResult {
Expand Down
1 change: 0 additions & 1 deletion packages/shortest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
TestContext,
TestChain,
ShortestConfig,
TestHookFunction,
} from "./types";

// Initialize config
Expand Down
3 changes: 0 additions & 3 deletions packages/shortest/src/types/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { AIConfig } from "./ai";
import { BrowserConfig } from "./browser";

export interface ShortestConfig {
headless: boolean;
baseUrl: string;
Expand Down
1 change: 0 additions & 1 deletion packages/shortest/tests/test-ai.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pc from "picocolors";
import * as playwright from "playwright";
import { request } from "playwright";
import { AIClient } from "../src/ai/client";
import { BrowserTool } from "../src/browser/core/browser-tool";
import { BrowserManager } from "../src/browser/manager";
import { getConfig, initialize } from "../src/index";
Expand Down
Loading

0 comments on commit 71f4745

Please sign in to comment.