Skip to content

Commit 4286be0

Browse files
committed
refactor: remove renumbering functionality
The renumbering was a one-time migration that has been completed. Keep only the global unique numbering for new files.
1 parent de259bc commit 4286be0

File tree

4 files changed

+4
-194
lines changed

4 files changed

+4
-194
lines changed

src/test-llm-autocompletion/README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ LLM_MODEL=anthropic/claude-3-haiku pnpm run test
9696

9797
### Clean Command
9898

99-
The `clean` command removes approval files for test cases that no longer exist and renumbers files to fix duplicates:
99+
The `clean` command removes approval files for test cases that no longer exist:
100100

101101
```bash
102102
pnpm run clean
@@ -107,14 +107,7 @@ This is useful when you've deleted or renamed test cases and want to clean up th
107107
- Scan all approval files in the `approvals/` directory
108108
- Check if each approval corresponds to an existing test case
109109
- Remove approvals for test cases that no longer exist
110-
- **Renumber files** to fix duplicate numbers and gaps (e.g., if you have `approved.1.txt` and `rejected.1.txt`, they will be renumbered to `approved.1.txt` and `rejected.2.txt`)
111-
- Report how many files were cleaned and renumbered
112-
113-
The renumbering feature is particularly useful when:
114-
115-
- You've manually moved files between approved and rejected
116-
- You have legacy files with duplicate numbers from before the global numbering was implemented
117-
- You want to ensure all file numbers are sequential and unique
110+
- Report how many files were cleaned
118111

119112
### Skip Approval Mode
120113

@@ -166,4 +159,3 @@ Is this acceptable? (y/n):
166159
- Each approved/rejected output gets a globally unique numbered file (numbers are unique across both approved and rejected files for the same test case)
167160
- Tests only prompt for input in the terminal when output is new
168161
- The test summary at the end shows how many passed/failed
169-
- To move a file from approved to rejected (or vice versa), simply rename it and run `pnpm run clean` to fix the numbering

src/test-llm-autocompletion/approvals.spec.ts

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach, afterEach, vi } from "vitest"
22
import fs from "fs"
33
import path from "path"
44
import readline from "readline"
5-
import { checkApproval, renumberApprovals } from "./approvals.js"
5+
import { checkApproval } from "./approvals.js"
66

77
const TEST_APPROVALS_DIR = "approvals"
88
const TEST_CATEGORY = "test-category"
@@ -195,71 +195,6 @@ describe("approvals", () => {
195195
})
196196
})
197197

198-
describe("renumberApprovals", () => {
199-
it("should renumber files with duplicate numbers", () => {
200-
const categoryDir = path.join(TEST_APPROVALS_DIR, TEST_CATEGORY)
201-
fs.mkdirSync(categoryDir, { recursive: true })
202-
203-
// Create files with duplicate numbers (approved.1 and rejected.1)
204-
fs.writeFileSync(path.join(categoryDir, `${TEST_NAME}.approved.1.txt`), "output1", "utf-8")
205-
fs.writeFileSync(path.join(categoryDir, `${TEST_NAME}.rejected.1.txt`), "output2", "utf-8")
206-
207-
const result = renumberApprovals(TEST_APPROVALS_DIR)
208-
209-
expect(result.renamedCount).toBeGreaterThan(0)
210-
211-
const files = fs.readdirSync(categoryDir)
212-
const numbers = files.map((f) => {
213-
const match = f.match(/\.(\d+)\.txt$/)
214-
return match ? parseInt(match[1], 10) : 0
215-
})
216-
217-
// All numbers should be unique
218-
const uniqueNumbers = new Set(numbers)
219-
expect(uniqueNumbers.size).toBe(numbers.length)
220-
})
221-
222-
it("should renumber files with gaps", () => {
223-
const categoryDir = path.join(TEST_APPROVALS_DIR, TEST_CATEGORY)
224-
fs.mkdirSync(categoryDir, { recursive: true })
225-
226-
// Create files with gaps (1, 3, 5)
227-
fs.writeFileSync(path.join(categoryDir, `${TEST_NAME}.approved.1.txt`), "output1", "utf-8")
228-
fs.writeFileSync(path.join(categoryDir, `${TEST_NAME}.approved.3.txt`), "output2", "utf-8")
229-
fs.writeFileSync(path.join(categoryDir, `${TEST_NAME}.approved.5.txt`), "output3", "utf-8")
230-
231-
const result = renumberApprovals(TEST_APPROVALS_DIR)
232-
233-
expect(result.renamedCount).toBeGreaterThan(0)
234-
235-
const files = fs.readdirSync(categoryDir)
236-
expect(files).toContain(`${TEST_NAME}.approved.1.txt`)
237-
expect(files).toContain(`${TEST_NAME}.approved.2.txt`)
238-
expect(files).toContain(`${TEST_NAME}.approved.3.txt`)
239-
})
240-
241-
it("should not rename files that are already sequential", () => {
242-
const categoryDir = path.join(TEST_APPROVALS_DIR, TEST_CATEGORY)
243-
fs.mkdirSync(categoryDir, { recursive: true })
244-
245-
// Create files that are already sequential
246-
fs.writeFileSync(path.join(categoryDir, `${TEST_NAME}.approved.1.txt`), "output1", "utf-8")
247-
fs.writeFileSync(path.join(categoryDir, `${TEST_NAME}.rejected.2.txt`), "output2", "utf-8")
248-
fs.writeFileSync(path.join(categoryDir, `${TEST_NAME}.approved.3.txt`), "output3", "utf-8")
249-
250-
const result = renumberApprovals(TEST_APPROVALS_DIR)
251-
252-
expect(result.renamedCount).toBe(0)
253-
})
254-
255-
it("should return zero counts for non-existent directory", () => {
256-
const result = renumberApprovals("non-existent-dir")
257-
258-
expect(result.renamedCount).toBe(0)
259-
expect(result.totalFiles).toBe(0)
260-
})
261-
})
262-
263198
describe("skip-approval mode", () => {
264199
it("should mark new outputs as unknown with newOutput=true", async () => {
265200
const result = await checkApproval(TEST_CATEGORY, TEST_NAME, "input", "output", true)

src/test-llm-autocompletion/approvals.ts

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -121,110 +121,3 @@ export async function checkApproval(
121121

122122
return { isApproved, newOutput: true }
123123
}
124-
125-
export interface RenumberResult {
126-
renamedCount: number
127-
totalFiles: number
128-
}
129-
130-
export function renumberApprovals(approvalsDir: string = "approvals"): RenumberResult {
131-
let renamedCount = 0
132-
let totalFiles = 0
133-
134-
if (!fs.existsSync(approvalsDir)) {
135-
return { renamedCount, totalFiles }
136-
}
137-
138-
// Get all category directories
139-
const categories = fs.readdirSync(approvalsDir, { withFileTypes: true }).filter((d) => d.isDirectory())
140-
141-
for (const category of categories) {
142-
const categoryDir = path.join(approvalsDir, category.name)
143-
const files = fs.readdirSync(categoryDir).filter((f) => f.endsWith(".txt"))
144-
145-
// Group files by test name
146-
const filesByTestName = new Map<string, string[]>()
147-
const pattern = /^(.+)\.(approved|rejected)\.(\d+)\.txt$/
148-
149-
for (const file of files) {
150-
const match = file.match(pattern)
151-
if (match) {
152-
totalFiles++
153-
const testName = match[1]
154-
if (!filesByTestName.has(testName)) {
155-
filesByTestName.set(testName, [])
156-
}
157-
filesByTestName.get(testName)!.push(file)
158-
}
159-
}
160-
161-
// Renumber files for each test name
162-
for (const [testName, testFiles] of filesByTestName) {
163-
// Sort files by their current number
164-
const sortedFiles = testFiles.sort((a, b) => {
165-
const matchA = a.match(pattern)!
166-
const matchB = b.match(pattern)!
167-
return parseInt(matchA[3], 10) - parseInt(matchB[3], 10)
168-
})
169-
170-
// Check if renumbering is needed
171-
const numbers = sortedFiles.map((f) => {
172-
const match = f.match(pattern)!
173-
return parseInt(match[3], 10)
174-
})
175-
176-
// Check for duplicates or gaps
177-
const uniqueNumbers = new Set(numbers)
178-
const needsRenumber = uniqueNumbers.size !== numbers.length || !isSequential(numbers)
179-
180-
if (needsRenumber) {
181-
// Renumber all files sequentially
182-
for (let i = 0; i < sortedFiles.length; i++) {
183-
const oldFile = sortedFiles[i]
184-
const match = oldFile.match(pattern)!
185-
const type = match[2]
186-
const newNumber = i + 1
187-
const newFile = `${testName}.${type}.${newNumber}.txt`
188-
189-
if (oldFile !== newFile) {
190-
const oldPath = path.join(categoryDir, oldFile)
191-
const newPath = path.join(categoryDir, newFile)
192-
193-
// Use a temp file to avoid conflicts
194-
const tempPath = path.join(categoryDir, `${testName}.${type}.temp_${i}.txt`)
195-
fs.renameSync(oldPath, tempPath)
196-
sortedFiles[i] = `${testName}.${type}.temp_${i}.txt`
197-
}
198-
}
199-
200-
// Now rename from temp to final
201-
for (let i = 0; i < sortedFiles.length; i++) {
202-
const tempFile = sortedFiles[i]
203-
if (tempFile.includes(".temp_")) {
204-
const match = tempFile.match(/^(.+)\.(approved|rejected)\.temp_(\d+)\.txt$/)!
205-
const type = match[2]
206-
const newNumber = i + 1
207-
const newFile = `${testName}.${type}.${newNumber}.txt`
208-
209-
const tempPath = path.join(categoryDir, tempFile)
210-
const newPath = path.join(categoryDir, newFile)
211-
fs.renameSync(tempPath, newPath)
212-
renamedCount++
213-
}
214-
}
215-
}
216-
}
217-
}
218-
219-
return { renamedCount, totalFiles }
220-
}
221-
222-
function isSequential(numbers: number[]): boolean {
223-
const sorted = [...numbers].sort((a, b) => a - b)
224-
for (let i = 0; i < sorted.length; i++) {
225-
if (sorted[i] !== i + 1) {
226-
return false
227-
}
228-
}
229-
return true
230-
}

src/test-llm-autocompletion/runner.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import fs from "fs"
44
import path from "path"
55
import { GhostProviderTester } from "./ghost-provider-tester.js"
66
import { testCases, getCategories, TestCase } from "./test-cases.js"
7-
import { checkApproval, renumberApprovals } from "./approvals.js"
7+
import { checkApproval } from "./approvals.js"
88

99
interface TestResult {
1010
testCase: TestCase
@@ -395,16 +395,6 @@ export class TestRunner {
395395
} else {
396396
console.log("No orphaned approval files found.")
397397
}
398-
399-
// Renumber files to fix duplicates and gaps
400-
console.log("\n🔢 Renumbering approval files to fix duplicates and gaps...\n")
401-
const renumberResult = renumberApprovals(approvalsDir)
402-
403-
if (renumberResult.renamedCount > 0) {
404-
console.log(`✅ Renumbered ${renumberResult.renamedCount} files to ensure unique sequential numbering.`)
405-
} else {
406-
console.log("No renumbering needed - all files already have unique sequential numbers.")
407-
}
408398
}
409399
}
410400

0 commit comments

Comments
 (0)