Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tscircuit/prompt-benchmarks
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.0.42
Choose a base ref
...
head repository: tscircuit/prompt-benchmarks
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.0.43
Choose a head ref
  • 4 commits
  • 8 files changed
  • 2 contributors

Commits on Feb 20, 2025

  1. v0.0.42

    actions-user committed Feb 20, 2025
    Copy the full SHA
    1599d77 View commit details
  2. added more tests for utils

    ShiboSoftwareDev committed Feb 20, 2025
    Copy the full SHA
    c50a76f View commit details
  3. Merge https://github.com/ShiboSoftwareDev/prompt-benchmarks into more…

    …-tests
    ShiboSoftwareDev committed Feb 20, 2025
    Copy the full SHA
    20979b9 View commit details
  4. Merge pull request #44 from tscircuit/more-tests

    added more tests for utils
    ShiboSoftwareDev authored Feb 20, 2025
    Copy the full SHA
    9f6939b View commit details
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tscircuit/prompt-benchmarks",
"version": "0.0.41",
"version": "0.0.42",
"main": "dist/index.js",
"repository": "github:tscircuit/prompt-benchmarks",
"homepage": "https://github.com/tscircuit/prompt-benchmarks#readme",
29 changes: 29 additions & 0 deletions tests/utils/cleanup-attempt-logs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import fs from "node:fs"
import path from "node:path"
import { describe, it, expect, beforeEach, afterEach } from "bun:test"
import { cleanupAttemptLogs } from "../../lib/utils/cleanup-attempt-logs"

describe("cleanupAttemptLogs", () => {
const logsDir = path.join(__dirname, "temp-cleanup-logs")

beforeEach(() => {
if (fs.existsSync(logsDir)) {
fs.rmSync(logsDir, { recursive: true, force: true })
}
fs.mkdirSync(logsDir, { recursive: true })
fs.writeFileSync(path.join(logsDir, "dummy.txt"), "dummy content")
})

afterEach(() => {
if (fs.existsSync(logsDir)) {
fs.rmSync(logsDir, { recursive: true, force: true })
}
})

it("should remove existing logs and recreate empty directory", () => {
cleanupAttemptLogs(logsDir)
expect(fs.existsSync(logsDir)).toBe(true)
const files = fs.readdirSync(logsDir)
expect(files.length).toBe(0)
})
})
File renamed without changes.
11 changes: 11 additions & 0 deletions tests/utils/generate-random-prompts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { describe, it, expect } from "bun:test"
import { generateRandomPrompts } from "../../lib/utils/generate-random-prompts"

describe("generateRandomPrompts", () => {
it("should return an array of prompts", async () => {
const prompts = await generateRandomPrompts(3)

expect(Array.isArray(prompts)).toBe(true)
expect(prompts.length).toBe(3)
})
})
File renamed without changes.
28 changes: 28 additions & 0 deletions tests/utils/load-problems.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import fs from "node:fs"
import path from "node:path"
import { describe, it, expect, afterEach } from "bun:test"
import { loadProblems } from "../../lib/utils/load-problems"

describe("loadProblems", () => {
const testTomlPath = path.join(__dirname, "test-problems.toml")

afterEach(() => {
if (fs.existsSync(testTomlPath)) {
fs.rmSync(testTomlPath)
}
})

it("should load problems from a TOML file", () => {
const tomlContent = `
problems = [
{ prompt = "Test prompt", title = "Test title", questions = [ { text = "Question 1", answer = true }, { text = "Question 2", answer = false } ] }
]
`
fs.writeFileSync(testTomlPath, tomlContent)
const problems = loadProblems(testTomlPath)
expect(Array.isArray(problems)).toBe(true)
expect(problems.length).toBe(1)
expect(problems[0].prompt).toBe("Test prompt")
expect(problems[0].questions.length).toBe(2)
})
})
35 changes: 35 additions & 0 deletions tests/utils/save-attempt.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import fs from "node:fs"
import path from "node:path"
import { describe, it, expect, beforeEach, afterEach } from "bun:test"
import { saveAttemptLog } from "../../lib/utils/save-attempt"

describe("saveAttemptLog", () => {
const logsDir = path.join(__dirname, "temp-attempt-logs")

beforeEach(() => {
if (fs.existsSync(logsDir)) {
fs.rmSync(logsDir, { recursive: true, force: true })
}
})

afterEach(() => {
if (fs.existsSync(logsDir)) {
fs.rmSync(logsDir, { recursive: true, force: true })
}
})

it("should create logsDir if not exists and write log file", () => {
const fileName = "attempt-log.md"
const prompt = "Test prompt"
const code = "const x = 1;"
const error = "Test error"

saveAttemptLog({ fileName, prompt, logsDir, code, error })
const filePath = path.join(logsDir, fileName)
expect(fs.existsSync(filePath)).toBe(true)
const content = fs.readFileSync(filePath, "utf8")
expect(content).toContain(prompt)
expect(content).toContain(code)
expect(content).toContain(error)
})
})
41 changes: 41 additions & 0 deletions tests/utils/save-prompt.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import fs from "node:fs"
import path from "node:path"
import { describe, it, expect, beforeEach, afterEach } from "bun:test"
import { savePrompt } from "../../lib/utils/save-prompt"

describe("savePrompt", () => {
const testDir = path.join(__dirname, "temp-save-prompt")

beforeEach(() => {
if (fs.existsSync(testDir)) {
fs.rmSync(testDir, { recursive: true, force: true })
}
fs.mkdirSync(testDir, { recursive: true })
})

afterEach(() => {
if (fs.existsSync(testDir)) {
fs.rmSync(testDir, { recursive: true, force: true })
}
})

it("should write a prompt to a file", () => {
const prompt = "Test prompt"
const fileName = "prompt-1.txt"
savePrompt(prompt, fileName, testDir)
const fileContent = fs.readFileSync(path.join(testDir, fileName), "utf8")
expect(fileContent).toBe(prompt)
})

it("should delete the oldest file when ≥10 files exist", () => {
for (let i = 0; i < 10; i++) {
fs.writeFileSync(path.join(testDir, `prompt-${i}.txt`), `dummy ${i}`)
}

const prompt = "New test prompt"
const fileName = "prompt-11.txt"
savePrompt(prompt, fileName, testDir)
expect(fs.existsSync(path.join(testDir, "prompt-0.txt"))).toBe(false)
expect(fs.readFileSync(path.join(testDir, fileName), "utf8")).toBe(prompt)
})
})