Skip to content

Commit 1e8b458

Browse files
chore: drop the committed gh device ID; test hygiene on the flagged blocks
- Remove .local/state/gh/device-id: the GitHub CLI's persisted device ID (a pseudonymous telemetry identifier) was swept in by an add -A during a refresh round. It is gitignored; nothing else under .local/ is tracked on this or any sibling unit (checked all six). - DiffViewProvider.spec: the 25 added as-any casts in the changed blocks become bracket access for private members and documented unknown-based structural casts for the VS Code doubles (same pattern as the sibling unit's thread); the file's no-explicit-any suppression drops 310 -> 285, nothing else moves. - safeWriteJson.lockKey.spec: the cleanup-safety-net test now asserts WHAT the single console.error reported - the message carries '[Original Error Caught]' and the second argument IS the commit failure - and that no call carries the cleanup-error text. A regression that logs the ENOENT cleanup instead of the commit failure can no longer pass on the count alone. Negative control: making the cleanup log unconditionally reddens the upgraded test (plus two neighbors that lean on the same silence). 158/158 green across the two specs, eslint clean, prettier clean, tsc clean.
1 parent c411f97 commit 1e8b458

4 files changed

Lines changed: 53 additions & 32 deletions

File tree

‎.local/state/gh/device-id‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎src/eslint-suppressions.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@
11561156
},
11571157
"integrations/editor/__tests__/DiffViewProvider.spec.ts": {
11581158
"@typescript-eslint/no-explicit-any": {
1159-
"count": 310
1159+
"count": 285
11601160
}
11611161
},
11621162
"integrations/editor/__tests__/EditorUtils.spec.ts": {

‎src/integrations/editor/__tests__/DiffViewProvider.spec.ts‎

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,19 +2750,19 @@ describe("DiffViewProvider", () => {
27502750
describe("saveChanges method with diagnostic settings", () => {
27512751
beforeEach(() => {
27522752
// Setup common mocks for saveChanges tests
2753-
;(diffViewProvider as any).relPath = "test.ts"
2754-
;(diffViewProvider as any).newContent = "new content"
2755-
;(diffViewProvider as any).activeDiffEditor = {
2753+
diffViewProvider["relPath"] = "test.ts"
2754+
diffViewProvider["newContent"] = "new content"
2755+
diffViewProvider["activeDiffEditor"] = {
27562756
document: {
27572757
getText: vi.fn().mockReturnValue("new content"),
27582758
isDirty: false,
27592759
save: vi.fn().mockResolvedValue(undefined),
27602760
},
2761-
}
2762-
;(diffViewProvider as any).preDiagnostics = []
2761+
} as unknown as vscode.TextEditor // Structural double: only the members saveChanges reads (documented cast, AGENTS.md).
2762+
diffViewProvider["preDiagnostics"] = []
27632763

27642764
// Mock vscode functions
2765-
vi.mocked(vscode.window.showTextDocument).mockResolvedValue({} as any)
2765+
vi.mocked(vscode.window.showTextDocument).mockResolvedValue({} as unknown as vscode.TextEditor) // Structural double: identity only (AGENTS.md).
27662766
vi.mocked(vscode.languages.getDiagnostics).mockReturnValue([])
27672767
})
27682768

@@ -2771,7 +2771,7 @@ describe("DiffViewProvider", () => {
27712771
mockDelay.mockClear()
27722772

27732773
// Mock closeAllDiffViews
2774-
;(diffViewProvider as any).closeAllDiffViews = vi.fn().mockResolvedValue(undefined)
2774+
diffViewProvider["closeAllDiffViews"] = vi.fn().mockResolvedValue(undefined)
27752775

27762776
const result = await diffViewProvider.saveChanges(true, 3000)
27772777

@@ -2786,7 +2786,7 @@ describe("DiffViewProvider", () => {
27862786
mockDelay.mockClear()
27872787

27882788
// Mock closeAllDiffViews
2789-
;(diffViewProvider as any).closeAllDiffViews = vi.fn().mockResolvedValue(undefined)
2789+
diffViewProvider["closeAllDiffViews"] = vi.fn().mockResolvedValue(undefined)
27902790

27912791
const result = await diffViewProvider.saveChanges(false, 2000)
27922792

@@ -2801,7 +2801,7 @@ describe("DiffViewProvider", () => {
28012801
mockDelay.mockClear()
28022802

28032803
// Mock closeAllDiffViews
2804-
;(diffViewProvider as any).closeAllDiffViews = vi.fn().mockResolvedValue(undefined)
2804+
diffViewProvider["closeAllDiffViews"] = vi.fn().mockResolvedValue(undefined)
28052805

28062806
const result = await diffViewProvider.saveChanges()
28072807

@@ -2822,7 +2822,7 @@ describe("DiffViewProvider", () => {
28222822
mockDelay.mockClear()
28232823

28242824
// Mock closeAllDiffViews
2825-
;(diffViewProvider as any).closeAllDiffViews = vi.fn().mockResolvedValue(undefined)
2825+
diffViewProvider["closeAllDiffViews"] = vi.fn().mockResolvedValue(undefined)
28262826

28272827
await diffViewProvider.saveChanges(true, 5000)
28282828

@@ -2846,18 +2846,24 @@ describe("DiffViewProvider", () => {
28462846
visibleRanges: [{ start: { line: 42 } }],
28472847
}
28482848

2849-
vi.mocked(vscode.window).visibleTextEditors = [mockEditor as any]
2850-
vi.mocked(vscode.window.showTextDocument).mockResolvedValue(mockEditor as any)
2849+
vi.mocked(vscode.window).visibleTextEditors = [mockEditor as unknown as vscode.TextEditor]
2850+
vi.mocked(vscode.window.showTextDocument).mockResolvedValue(mockEditor as unknown as vscode.TextEditor)
28512851
vi.mocked(vscode.workspace.onDidOpenTextDocument).mockImplementation((callback) => {
2852-
setTimeout(() => callback({ uri: { fsPath: `${mockCwd}/scroll.ts`, scheme: "file" } } as any), 0)
2852+
setTimeout(
2853+
() =>
2854+
callback({
2855+
uri: { fsPath: `${mockCwd}/scroll.ts`, scheme: "file" },
2856+
} as unknown as vscode.TextDocument),
2857+
0,
2858+
)
28532859
return { dispose: vi.fn() }
28542860
})
28552861
vi.mocked(vscode.window.onDidChangeVisibleTextEditors).mockReturnValue({ dispose: vi.fn() })
2856-
;(diffViewProvider as any).editType = "modify"
2862+
diffViewProvider["editType"] = "modify"
28572863

28582864
await diffViewProvider.open("scroll.ts")
28592865

2860-
expect((diffViewProvider as any).preEditScrollLine).toBe(42)
2866+
expect(diffViewProvider["preEditScrollLine"]).toBe(42)
28612867
})
28622868

28632869
it("should set preEditScrollLine to undefined when the visible editor has no visibleRanges", async () => {
@@ -2873,37 +2879,45 @@ describe("DiffViewProvider", () => {
28732879
// No visibleRanges, so the capture in open() yields undefined.
28742880
}
28752881

2876-
vi.mocked(vscode.window).visibleTextEditors = [mockEditorNoRanges as any]
2877-
vi.mocked(vscode.window.showTextDocument).mockResolvedValue(mockEditorNoRanges as any)
2882+
vi.mocked(vscode.window).visibleTextEditors = [mockEditorNoRanges as unknown as vscode.TextEditor]
2883+
vi.mocked(vscode.window.showTextDocument).mockResolvedValue(
2884+
mockEditorNoRanges as unknown as vscode.TextEditor,
2885+
)
28782886
vi.mocked(vscode.workspace.onDidOpenTextDocument).mockImplementation((callback) => {
2879-
setTimeout(() => callback({ uri: { fsPath: `${mockCwd}/new.ts`, scheme: "file" } } as any), 0)
2887+
setTimeout(
2888+
() =>
2889+
callback({
2890+
uri: { fsPath: `${mockCwd}/new.ts`, scheme: "file" },
2891+
} as unknown as vscode.TextDocument),
2892+
0,
2893+
)
28802894
return { dispose: vi.fn() }
28812895
})
28822896
vi.mocked(vscode.window.onDidChangeVisibleTextEditors).mockReturnValue({ dispose: vi.fn() })
2883-
;(diffViewProvider as any).editType = "modify"
2897+
diffViewProvider["editType"] = "modify"
28842898

28852899
await diffViewProvider.open("new.ts")
28862900

2887-
expect((diffViewProvider as any).preEditScrollLine).toBeUndefined()
2901+
expect(diffViewProvider["preEditScrollLine"]).toBeUndefined()
28882902
})
28892903

28902904
it("saveChanges() calls revealRange(AtTop) when documentWasOpen and preEditScrollLine is set", async () => {
28912905
const mockRevealRange = vi.fn()
28922906
const mockSavedEditor = { revealRange: mockRevealRange }
28932907

2894-
vi.mocked(vscode.window.showTextDocument).mockResolvedValue(mockSavedEditor as any)
2895-
;(diffViewProvider as any).closeAllDiffViews = vi.fn().mockResolvedValue(undefined)
2896-
;(diffViewProvider as any).documentWasOpen = true
2897-
;(diffViewProvider as any).preEditScrollLine = 30
2908+
vi.mocked(vscode.window.showTextDocument).mockResolvedValue(mockSavedEditor as unknown as vscode.TextEditor)
2909+
diffViewProvider["closeAllDiffViews"] = vi.fn().mockResolvedValue(undefined)
2910+
diffViewProvider["documentWasOpen"] = true
2911+
diffViewProvider["preEditScrollLine"] = 30
28982912
// saveChanges early-exits without relPath, newContent, activeDiffEditor
2899-
;(diffViewProvider as any).newContent = "content"
2900-
;(diffViewProvider as any).activeDiffEditor = {
2913+
diffViewProvider["newContent"] = "content"
2914+
diffViewProvider["activeDiffEditor"] = {
29012915
document: {
29022916
getText: vi.fn().mockReturnValue("content"),
29032917
isDirty: false,
29042918
save: vi.fn().mockResolvedValue(undefined),
29052919
},
2906-
}
2920+
} as unknown as vscode.TextEditor // Structural double: only the members saveChanges reads (documented cast, AGENTS.md).
29072921

29082922
await diffViewProvider.saveChanges(false)
29092923

‎src/utils/__tests__/safeWriteJson.lockKey.spec.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,14 +372,22 @@ it("does not log a cleanup error when the safety net finds the temp file already
372372
mockedRealpath.mockImplementation(async (t) => String(t))
373373
mockedLstat.mockImplementation(async (t) => symlinkStat(t))
374374

375-
const renameSpy = vi.spyOn(fs, "rename").mockRejectedValue(new Error("commit rename failed"))
375+
const commitFailure = new Error("commit rename failed")
376+
const renameSpy = vi.spyOn(fs, "rename").mockRejectedValue(commitFailure)
376377
const unlinkSpy = vi.spyOn(fs, "unlink").mockRejectedValue(enoent)
377378
const consoleError = vi.spyOn(console, "error").mockImplementation(() => {})
378379

379380
await expect(safeWriteJson(target, { id: "task-1" })).rejects.toThrow("commit rename failed")
380381

381-
// Only the original failure is reported.
382-
expect(consoleError).toHaveBeenCalledTimes(1)
382+
// Only the original failure is reported - and reported AS the original failure:
383+
// a regression that logs the ENOENT cleanup error instead of the commit failure
384+
// (or drops the commit failure and logs only the cleanup) must not pass on the
385+
// call count alone.
386+
const reported = consoleError.mock.calls.map((call) => String(call[0]))
387+
expect(reported).toHaveLength(1)
388+
expect(reported[0]).toContain("[Original Error Caught]")
389+
expect(consoleError.mock.calls[0][1]).toBe(commitFailure)
390+
expect(reported.some((message) => message.includes("Failed to clean up temporary new file"))).toBe(false)
383391

384392
renameSpy.mockRestore()
385393
unlinkSpy.mockRestore()

0 commit comments

Comments
 (0)