Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions .github/workflows/code-qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,22 @@ jobs:
- name: Run knip checks
run: npm run knip

unit-test:
test-extension:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm run install:all
- name: Run unit tests
run: npx jest --silent

test-webview:
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -56,7 +71,15 @@ jobs:
- name: Install dependencies
run: npm run install:all
- name: Run unit tests
run: npm test
working-directory: webview-ui
run: npx jest --silent

unit-test:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a branch rule dictating that "unit-test" must pass in order for the PR to be merged, hence this composite job.

needs: [test-extension, test-webview]
runs-on: ubuntu-latest
steps:
- name: NO-OP
run: echo "All unit tests passed."

check-openrouter-api-key:
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
"build": "npm run build:webview && npm run vsix",
"build:webview": "cd webview-ui && npm run build",
"changeset": "changeset",
"check-types": "tsc --noEmit",
"check-types": "tsc --noEmit && cd webview-ui && npm run check-types",
"compile": "tsc -p . --outDir out && node esbuild.js",
"compile:integration": "tsc -p tsconfig.integration.json",
"install:all": "npm install && cd webview-ui && npm install",
Expand All @@ -289,8 +289,7 @@
"package": "npm run build:webview && npm run check-types && npm run lint && node esbuild.js --production",
"pretest": "npm run compile && npm run compile:integration",
"dev": "cd webview-ui && npm run dev",
"test": "jest && npm run test:webview",
"test:webview": "cd webview-ui && npm run test",
"test": "jest && cd webview-ui && npm run test",
"test:integration": "npm run build && npm run compile:integration && npx dotenvx run -f .env.integration -- node ./out-integration/test/runTest.js",
"prepare": "husky",
"publish:marketplace": "vsce publish && ovsx publish",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference types="jest" />
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since @types/mocha and @types/jest both define expect, beforeEach, afterEach, etc we need to indicate which version of these global functions are being used. I'm not sure what the "correct" fix for this is, but it's unfortunate that we have this conflict.

Mocha is only needed for integration tests, and it seems like that could live in a separate package (kind of like webview-ui).


import { applyContextMatching, applyDMP, applyGitFallback } from "../edit-strategies"
import { Hunk } from "../types"

Expand Down Expand Up @@ -275,7 +277,7 @@ describe("applyGitFallback", () => {
expect(result.result.join("\n")).toEqual("line1\nnew line2\nline3")
expect(result.confidence).toBe(1)
expect(result.strategy).toBe("git-fallback")
})
}, 10_000)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this implies that whatever we’re doing with git in the experimental diff algo is taking between 5 and 10 seconds?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I encountered this timeout while debugging, and increasing it seemed to suddenly make the problems go away. Undoing this change seemed to make the problem reliably come back. One theory I had was that it impacted the order or sequencing of the tests such that the failure stopped happening. I added the --randomize flag to jest to test that theory but we get a bunch of other failures since some of our tests do seem to rely on being run in a particular order (which we should fix).


it("should return original content with 0 confidence when changes cannot be applied", async () => {
const hunk = {
Expand All @@ -291,5 +293,5 @@ describe("applyGitFallback", () => {
expect(result.result).toEqual(content)
expect(result.confidence).toBe(0)
expect(result.strategy).toBe("git-fallback")
})
}, 10_000)
})
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { simpleGit, SimpleGit } from "simple-git"
import { CheckpointServiceFactory } from "../CheckpointServiceFactory"
import { LocalCheckpointService } from "../LocalCheckpointService"

const tmpDir = path.join(os.tmpdir(), "test-LocalCheckpointService")

describe("LocalCheckpointService", () => {
const taskId = "test-task"

Expand All @@ -29,7 +31,7 @@ describe("LocalCheckpointService", () => {
textFileContent?: string
}) => {
// Create a temporary directory for testing.
await fs.mkdir(workspaceDir)
await fs.mkdir(workspaceDir, { recursive: true })

// Initialize git repo.
const git = simpleGit(workspaceDir)
Expand All @@ -49,7 +51,7 @@ describe("LocalCheckpointService", () => {
}

beforeEach(async () => {
const workspaceDir = path.join(os.tmpdir(), `checkpoint-service-test-${Date.now()}`)
const workspaceDir = path.join(tmpDir, `checkpoint-service-test-${Date.now()}`)
const repo = await initRepo({ workspaceDir })

testFile = repo.testFile
Expand All @@ -60,10 +62,13 @@ describe("LocalCheckpointService", () => {
})

afterEach(async () => {
await fs.rm(service.workspaceDir, { recursive: true, force: true })
jest.restoreAllMocks()
})

afterAll(async () => {
await fs.rm(tmpDir, { recursive: true, force: true })
})

describe("getDiff", () => {
it("returns the correct diff between commits", async () => {
await fs.writeFile(testFile, "Ahoy, world!")
Expand Down Expand Up @@ -316,7 +321,7 @@ describe("LocalCheckpointService", () => {

describe("create", () => {
it("initializes a git repository if one does not already exist", async () => {
const workspaceDir = path.join(os.tmpdir(), `checkpoint-service-test2-${Date.now()}`)
const workspaceDir = path.join(tmpDir, `checkpoint-service-test2-${Date.now()}`)
await fs.mkdir(workspaceDir)
const newTestFile = path.join(workspaceDir, "test.txt")
await fs.writeFile(newTestFile, "Hello, world!")
Expand Down Expand Up @@ -364,7 +369,7 @@ describe("LocalCheckpointService", () => {
})

it("respects existing git user configuration", async () => {
const workspaceDir = path.join(os.tmpdir(), `checkpoint-service-test-config2-${Date.now()}`)
const workspaceDir = path.join(tmpDir, `checkpoint-service-test-config2-${Date.now()}`)
const userName = "Custom User"
const userEmail = "[email protected]"
await initRepo({ workspaceDir, userName, userEmail })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ jest.mock("globby", () => ({
globby: jest.fn().mockResolvedValue([]),
}))

const tmpDir = path.join(os.tmpdir(), "test-ShadowCheckpointService")

describe("ShadowCheckpointService", () => {
const taskId = "test-task"

let workspaceGit: SimpleGit
let shadowGit: SimpleGit
let testFile: string
let service: ShadowCheckpointService

Expand All @@ -35,7 +36,7 @@ describe("ShadowCheckpointService", () => {
textFileContent?: string
}) => {
// Create a temporary directory for testing.
await fs.mkdir(workspaceDir)
await fs.mkdir(workspaceDir, { recursive: true })

// Initialize git repo.
const git = simpleGit(workspaceDir)
Expand All @@ -57,8 +58,8 @@ describe("ShadowCheckpointService", () => {
beforeEach(async () => {
jest.mocked(require("globby").globby).mockClear().mockResolvedValue([])

const shadowDir = path.join(os.tmpdir(), `shadow-${Date.now()}`)
const workspaceDir = path.join(os.tmpdir(), `workspace-${Date.now()}`)
const shadowDir = path.join(tmpDir, `shadow-${Date.now()}`)
const workspaceDir = path.join(tmpDir, `workspace-${Date.now()}`)
const repo = await initRepo({ workspaceDir })

testFile = repo.testFile
Expand All @@ -69,15 +70,16 @@ describe("ShadowCheckpointService", () => {
})

workspaceGit = repo.git
shadowGit = service.git
})

afterEach(async () => {
await fs.rm(service.shadowDir, { recursive: true, force: true })
await fs.rm(service.workspaceDir, { recursive: true, force: true })
jest.restoreAllMocks()
})

afterAll(async () => {
await fs.rm(tmpDir, { recursive: true, force: true })
})

describe("getDiff", () => {
it("returns the correct diff between commits", async () => {
await fs.writeFile(testFile, "Ahoy, world!")
Expand Down Expand Up @@ -299,8 +301,8 @@ describe("ShadowCheckpointService", () => {

describe("create", () => {
it("initializes a git repository if one does not already exist", async () => {
const shadowDir = path.join(os.tmpdir(), `shadow2-${Date.now()}`)
const workspaceDir = path.join(os.tmpdir(), `workspace2-${Date.now()}`)
const shadowDir = path.join(tmpDir, `shadow2-${Date.now()}`)
const workspaceDir = path.join(tmpDir, `workspace2-${Date.now()}`)
await fs.mkdir(workspaceDir)

const newTestFile = path.join(workspaceDir, "test.txt")
Expand Down
3 changes: 2 additions & 1 deletion webview-ui/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "react-app"
"extends": "react-app",
"ignorePatterns": ["!.storybook"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
Loading
Loading