test: remove channel test isolation hack

Remove isolate: true from the channel Vitest config and fix the leaking fake-timer/mock tests so the lane runs under the shared non-isolated runner. Verified with focused scoped-config/channel tests, the full channel Vitest config, git diff --check, and branch-mode autoreview.
This commit is contained in:
Peter Steinberger
2026-05-31 09:09:10 +01:00
committed by GitHub
parent 15c1511817
commit b78dd6a9ca
4 changed files with 39 additions and 13 deletions

View File

@@ -34,7 +34,11 @@ describe("createDraftStreamLoop", () => {
});
afterEach(() => {
if (vi.isFakeTimers()) {
vi.clearAllTimers();
}
vi.useRealTimers();
vi.restoreAllMocks();
});
it("contains immediate background flush rejections and preserves pending text", async () => {
@@ -99,7 +103,9 @@ describe("createDraftStreamLoop", () => {
},
);
} finally {
vi.clearAllTimers();
vi.useRealTimers();
vi.restoreAllMocks();
}
});
@@ -107,18 +113,23 @@ describe("createDraftStreamLoop", () => {
vi.useFakeTimers();
try {
vi.setSystemTime(0);
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
const sendOrEditStreamMessage = vi.fn(async () => true);
const loop = createDraftStreamLoop({
throttleMs: Number.MAX_SAFE_INTEGER,
isStopped: () => false,
sendOrEditStreamMessage: vi.fn(async () => true),
sendOrEditStreamMessage,
});
loop.update("hello");
expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS);
expect(vi.getTimerCount()).toBe(1);
vi.advanceTimersByTime(MAX_TIMER_TIMEOUT_MS - 1);
expect(sendOrEditStreamMessage).not.toHaveBeenCalled();
vi.advanceTimersByTime(1);
expect(sendOrEditStreamMessage).toHaveBeenCalledExactlyOnceWith("hello");
loop.stop();
} finally {
vi.clearAllTimers();
vi.useRealTimers();
}
});

View File

@@ -18,6 +18,7 @@ async function withFakeTimers(run: () => Promise<void>) {
} finally {
vi.clearAllTimers();
vi.useRealTimers();
vi.restoreAllMocks();
}
}
@@ -62,8 +63,11 @@ describe("createTypingCallbacks", () => {
});
afterEach(() => {
vi.clearAllTimers();
if (vi.isFakeTimers()) {
vi.clearAllTimers();
}
vi.useRealTimers();
vi.restoreAllMocks();
});
it("invokes start on reply start", async () => {
@@ -211,15 +215,19 @@ describe("createTypingCallbacks", () => {
it("clamps oversized keepalive intervals before arming timers", async () => {
await withFakeTimers(async () => {
const setIntervalSpy = vi.spyOn(globalThis, "setInterval");
const { callbacks } = createTypingHarness({
const { start, callbacks } = createTypingHarness({
keepaliveIntervalMs: Number.MAX_SAFE_INTEGER,
maxDurationMs: 0,
});
await callbacks.onReplyStart();
await flushMicrotasks();
expect(setIntervalSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS);
expect(vi.getTimerCount()).toBe(1);
await vi.advanceTimersByTimeAsync(MAX_TIMER_TIMEOUT_MS - 1);
expect(start).toHaveBeenCalledTimes(1);
await vi.advanceTimersByTimeAsync(1);
expect(start).toHaveBeenCalledTimes(2);
callbacks.onCleanup?.();
});
});
@@ -387,15 +395,23 @@ describe("createTypingCallbacks", () => {
it("clamps oversized TTLs before arming timers", async () => {
await withFakeTimers(async () => {
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
const { callbacks } = createTypingHarness({
const consoleWarn = vi.spyOn(console, "warn").mockImplementation(() => {});
const { stop, callbacks } = createTypingHarness({
keepaliveIntervalMs: 0,
maxDurationMs: Number.MAX_SAFE_INTEGER,
});
await callbacks.onReplyStart();
await flushMicrotasks();
expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS);
expect(vi.getTimerCount()).toBe(1);
await vi.advanceTimersByTimeAsync(MAX_TIMER_TIMEOUT_MS - 1);
expect(stop).not.toHaveBeenCalled();
await vi.advanceTimersByTimeAsync(1);
expect(stop).toHaveBeenCalledTimes(1);
expect(consoleWarn).toHaveBeenCalledWith(
`[typing] TTL exceeded (${MAX_TIMER_TIMEOUT_MS}ms), auto-stopping typing indicator`,
);
callbacks.onCleanup?.();
});
});

View File

@@ -452,8 +452,8 @@ describe("scoped vitest configs", () => {
expect(testConfig.exclude).not.toContain("chat/slash-command-executor.node.test.ts");
});
it("defaults channel tests to isolated threads", () => {
expectThreadedIsolatedRunner(defaultChannelsConfig);
it("defaults channel tests to threads with the non-isolated runner", () => {
expectThreadedNonIsolatedRunner(defaultChannelsConfig);
});
it("keeps the core channel lane limited to non-extension roots", () => {

View File

@@ -12,7 +12,6 @@ export function createChannelsVitestConfig(env?: Record<string, string | undefin
return createScopedVitestConfig(loadIncludePatternsFromEnv(env) ?? coreChannelTestInclude, {
env,
exclude: ["src/gateway/**", "src/channels/plugins/contracts/**"],
isolate: true,
name: "channels",
passWithNoTests: true,
});