Skip to content

Commit 8475dc3

Browse files
fix(test): ensure fake timers cleanup in manifest timeout test
Wrap the initToolTypesManifest timeout test in try/finally so vi.useRealTimers() runs even when assertions fail. Also ruff-format test_tool_dispatch_sync.py manifest validation helper (CI gate).
1 parent d6f4cfd commit 8475dc3

2 files changed

Lines changed: 23 additions & 22 deletions

File tree

static/js/render/tool_types_manifest.test.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,29 @@ describe('initToolTypesManifest', () => {
4949

5050
it('warns when fetch times out', async () => {
5151
vi.useFakeTimers();
52-
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
53-
vi.stubGlobal(
54-
'fetch',
55-
vi.fn((_url, init) =>
56-
new Promise((_resolve, reject) => {
57-
init?.signal?.addEventListener('abort', () => {
58-
reject(Object.assign(new Error('aborted'), { name: 'AbortError' }));
59-
});
60-
}),
61-
),
62-
);
52+
try {
53+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
54+
vi.stubGlobal(
55+
'fetch',
56+
vi.fn((_url, init) =>
57+
new Promise((_resolve, reject) => {
58+
init?.signal?.addEventListener('abort', () => {
59+
reject(Object.assign(new Error('aborted'), { name: 'AbortError' }));
60+
});
61+
}),
62+
),
63+
);
6364

64-
const promise = initToolTypesManifest();
65-
await vi.advanceTimersByTimeAsync(5000);
66-
await promise;
65+
const promise = initToolTypesManifest();
66+
await vi.advanceTimersByTimeAsync(5000);
67+
await promise;
6768

68-
expect(getManifestToolTypes()).toBeNull();
69-
expect(warn).toHaveBeenCalledWith(
70-
'[tool registry] Could not load /static/tool_types.json: timed out after 5000ms',
71-
);
72-
vi.useRealTimers();
69+
expect(getManifestToolTypes()).toBeNull();
70+
expect(warn).toHaveBeenCalledWith(
71+
'[tool registry] Could not load /static/tool_types.json: timed out after 5000ms',
72+
);
73+
} finally {
74+
vi.useRealTimers();
75+
}
7376
});
7477
});

tests/test_tool_dispatch_sync.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ def _load_manifest_tool_types(path: Path) -> frozenset[str]:
9696
raise ValueError(msg)
9797
for i, item in enumerate(raw):
9898
if not isinstance(item, str):
99-
msg = (
100-
f"Invalid tool_types[{i}] in {path}: expected string, got {type(item).__name__}"
101-
)
99+
msg = f"Invalid tool_types[{i}] in {path}: expected string, got {type(item).__name__}"
102100
raise ValueError(msg)
103101
return frozenset(raw)
104102

0 commit comments

Comments
 (0)