mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-23 16:55:51 +00:00
style: 完成所有文件的lint
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { describe, test, expect, beforeEach, mock } from "bun:test";
|
||||
import { describe, test, expect, beforeEach, mock } from 'bun:test'
|
||||
|
||||
// Mock config with very short timeout for testing
|
||||
const mockConfig = {
|
||||
port: 3000,
|
||||
host: "0.0.0.0",
|
||||
apiKeys: ["test-api-key"],
|
||||
baseUrl: "http://localhost:3000",
|
||||
host: '0.0.0.0',
|
||||
apiKeys: ['test-api-key'],
|
||||
baseUrl: 'http://localhost:3000',
|
||||
pollTimeout: 8,
|
||||
heartbeatInterval: 20,
|
||||
jwtExpiresIn: 3600,
|
||||
@@ -13,12 +13,12 @@ const mockConfig = {
|
||||
webCorsOrigins: [],
|
||||
wsIdleTimeout: 30,
|
||||
wsKeepaliveInterval: 20,
|
||||
};
|
||||
}
|
||||
|
||||
mock.module("../config", () => ({
|
||||
mock.module('../config', () => ({
|
||||
config: mockConfig,
|
||||
getBaseUrl: () => "http://localhost:3000",
|
||||
}));
|
||||
getBaseUrl: () => 'http://localhost:3000',
|
||||
}))
|
||||
|
||||
import {
|
||||
storeReset,
|
||||
@@ -28,84 +28,91 @@ import {
|
||||
storeUpdateSession,
|
||||
storeGetEnvironment,
|
||||
storeGetSession,
|
||||
} from "../store";
|
||||
import { getEventBus, getAllEventBuses, removeEventBus } from "../transport/event-bus";
|
||||
import { runDisconnectMonitorSweep } from "../services/disconnect-monitor";
|
||||
} from '../store'
|
||||
import {
|
||||
getEventBus,
|
||||
getAllEventBuses,
|
||||
removeEventBus,
|
||||
} from '../transport/event-bus'
|
||||
import { runDisconnectMonitorSweep } from '../services/disconnect-monitor'
|
||||
|
||||
describe("Disconnect Monitor Logic", () => {
|
||||
describe('Disconnect Monitor Logic', () => {
|
||||
beforeEach(() => {
|
||||
storeReset();
|
||||
storeReset()
|
||||
for (const [key] of getAllEventBuses()) {
|
||||
removeEventBus(key);
|
||||
removeEventBus(key)
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
test("environment times out when lastPollAt is too old", () => {
|
||||
const env = storeCreateEnvironment({ secret: "s" });
|
||||
const timeoutMs = 300 * 1000; // 5 minutes
|
||||
test('environment times out when lastPollAt is too old', () => {
|
||||
const env = storeCreateEnvironment({ secret: 's' })
|
||||
const timeoutMs = 300 * 1000 // 5 minutes
|
||||
|
||||
// Simulate lastPollAt being 6 minutes ago
|
||||
const oldDate = new Date(Date.now() - timeoutMs - 60000);
|
||||
storeUpdateEnvironment(env.id, { lastPollAt: oldDate });
|
||||
const oldDate = new Date(Date.now() - timeoutMs - 60000)
|
||||
storeUpdateEnvironment(env.id, { lastPollAt: oldDate })
|
||||
|
||||
runDisconnectMonitorSweep();
|
||||
runDisconnectMonitorSweep()
|
||||
|
||||
const updated = storeGetEnvironment(env.id);
|
||||
expect(updated?.status).toBe("disconnected");
|
||||
});
|
||||
const updated = storeGetEnvironment(env.id)
|
||||
expect(updated?.status).toBe('disconnected')
|
||||
})
|
||||
|
||||
test("environment stays active when lastPollAt is recent", () => {
|
||||
const env = storeCreateEnvironment({ secret: "s" });
|
||||
runDisconnectMonitorSweep();
|
||||
test('environment stays active when lastPollAt is recent', () => {
|
||||
const env = storeCreateEnvironment({ secret: 's' })
|
||||
runDisconnectMonitorSweep()
|
||||
|
||||
const updated = storeGetEnvironment(env.id);
|
||||
expect(updated?.status).toBe("active");
|
||||
});
|
||||
const updated = storeGetEnvironment(env.id)
|
||||
expect(updated?.status).toBe('active')
|
||||
})
|
||||
|
||||
test("session becomes inactive when updatedAt is too old", () => {
|
||||
const session = storeCreateSession({});
|
||||
storeUpdateSession(session.id, { status: "running" });
|
||||
const rec = storeGetSession(session.id);
|
||||
expect(rec).toBeTruthy();
|
||||
if (!rec) return;
|
||||
test('session becomes inactive when updatedAt is too old', () => {
|
||||
const session = storeCreateSession({})
|
||||
storeUpdateSession(session.id, { status: 'running' })
|
||||
const rec = storeGetSession(session.id)
|
||||
expect(rec).toBeTruthy()
|
||||
if (!rec) return
|
||||
|
||||
rec.updatedAt = new Date(Date.now() - 300 * 1000 * 2 - 60000);
|
||||
rec.updatedAt = new Date(Date.now() - 300 * 1000 * 2 - 60000)
|
||||
|
||||
runDisconnectMonitorSweep();
|
||||
runDisconnectMonitorSweep()
|
||||
|
||||
const updated = storeGetSession(session.id);
|
||||
expect(updated?.status).toBe("inactive");
|
||||
});
|
||||
const updated = storeGetSession(session.id)
|
||||
expect(updated?.status).toBe('inactive')
|
||||
})
|
||||
|
||||
test("session stays running when recently updated", () => {
|
||||
const session = storeCreateSession({});
|
||||
storeUpdateSession(session.id, { status: "running" });
|
||||
test('session stays running when recently updated', () => {
|
||||
const session = storeCreateSession({})
|
||||
storeUpdateSession(session.id, { status: 'running' })
|
||||
|
||||
runDisconnectMonitorSweep();
|
||||
runDisconnectMonitorSweep()
|
||||
|
||||
const updated = storeGetSession(session.id);
|
||||
expect(updated?.status).toBe("running");
|
||||
});
|
||||
const updated = storeGetSession(session.id)
|
||||
expect(updated?.status).toBe('running')
|
||||
})
|
||||
|
||||
test("session timeout publishes an inactive session_status event", () => {
|
||||
const session = storeCreateSession({});
|
||||
storeUpdateSession(session.id, { status: "idle" });
|
||||
const rec = storeGetSession(session.id);
|
||||
expect(rec).toBeTruthy();
|
||||
if (!rec) return;
|
||||
rec.updatedAt = new Date(Date.now() - 300 * 1000 * 2 - 60000);
|
||||
test('session timeout publishes an inactive session_status event', () => {
|
||||
const session = storeCreateSession({})
|
||||
storeUpdateSession(session.id, { status: 'idle' })
|
||||
const rec = storeGetSession(session.id)
|
||||
expect(rec).toBeTruthy()
|
||||
if (!rec) return
|
||||
rec.updatedAt = new Date(Date.now() - 300 * 1000 * 2 - 60000)
|
||||
|
||||
const bus = getEventBus(session.id);
|
||||
const events: Array<{ type: string; payload: { status?: string } }> = [];
|
||||
bus.subscribe((event) => {
|
||||
events.push({ type: event.type, payload: event.payload as { status?: string } });
|
||||
});
|
||||
const bus = getEventBus(session.id)
|
||||
const events: Array<{ type: string; payload: { status?: string } }> = []
|
||||
bus.subscribe(event => {
|
||||
events.push({
|
||||
type: event.type,
|
||||
payload: event.payload as { status?: string },
|
||||
})
|
||||
})
|
||||
|
||||
runDisconnectMonitorSweep();
|
||||
runDisconnectMonitorSweep()
|
||||
|
||||
expect(events).toContainEqual({
|
||||
type: "session_status",
|
||||
payload: { status: "inactive" },
|
||||
});
|
||||
});
|
||||
});
|
||||
type: 'session_status',
|
||||
payload: { status: 'inactive' },
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user