fix(server): apply biome formatting and replace console.log with logger
- Applied biome auto-fix to resolve all 5 formatting/linting errors - Fixed import sorting in index.ts, protocol.ts, and migration.test.ts - Fixed typeof expression parentheses in protocol.ts - Created logger.ts utility with createLogger function - Replaced console.log with logger.info for production code - All biome checks passing, TypeScript compilation successful - All 28 tests passing Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { describe, it, expect, beforeAll, afterAll, beforeEach } from "vitest";
|
||||
import { readFile, writeFile, mkdir, rm } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import type { Record, Worker, Device } from "../types";
|
||||
import { join } from "node:path";
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||
import type { Device, Record, Worker } from "../types";
|
||||
|
||||
describe("Server TypeScript Migration", () => {
|
||||
describe("Type Safety Tests", () => {
|
||||
@@ -136,12 +136,7 @@ describe("Server TypeScript Migration", () => {
|
||||
|
||||
describe("Build Configuration", () => {
|
||||
it("should have tsconfig.json with strict mode", async () => {
|
||||
const tsconfig = JSON.parse(
|
||||
await readFile(
|
||||
join(process.cwd(), "tsconfig.json"),
|
||||
"utf-8"
|
||||
)
|
||||
);
|
||||
const tsconfig = JSON.parse(await readFile(join(process.cwd(), "tsconfig.json"), "utf-8"));
|
||||
|
||||
expect(tsconfig.compilerOptions.strict).toBe(true);
|
||||
expect(tsconfig.compilerOptions.noImplicitAny).toBe(true);
|
||||
@@ -149,36 +144,21 @@ describe("Server TypeScript Migration", () => {
|
||||
});
|
||||
|
||||
it("should have tsconfig.json with proper module settings", async () => {
|
||||
const tsconfig = JSON.parse(
|
||||
await readFile(
|
||||
join(process.cwd(), "tsconfig.json"),
|
||||
"utf-8"
|
||||
)
|
||||
);
|
||||
const tsconfig = JSON.parse(await readFile(join(process.cwd(), "tsconfig.json"), "utf-8"));
|
||||
|
||||
expect(tsconfig.compilerOptions.module).toBe("ESNext");
|
||||
expect(tsconfig.compilerOptions.moduleResolution).toBe("bundler");
|
||||
});
|
||||
|
||||
it("should have tsconfig.json with output directory", async () => {
|
||||
const tsconfig = JSON.parse(
|
||||
await readFile(
|
||||
join(process.cwd(), "tsconfig.json"),
|
||||
"utf-8"
|
||||
)
|
||||
);
|
||||
const tsconfig = JSON.parse(await readFile(join(process.cwd(), "tsconfig.json"), "utf-8"));
|
||||
|
||||
expect(tsconfig.compilerOptions.outDir).toBe("./dist");
|
||||
expect(tsconfig.compilerOptions.rootDir).toBe("./src");
|
||||
});
|
||||
|
||||
it("should generate declaration files", async () => {
|
||||
const tsconfig = JSON.parse(
|
||||
await readFile(
|
||||
join(process.cwd(), "tsconfig.json"),
|
||||
"utf-8"
|
||||
)
|
||||
);
|
||||
const tsconfig = JSON.parse(await readFile(join(process.cwd(), "tsconfig.json"), "utf-8"));
|
||||
|
||||
expect(tsconfig.compilerOptions.declaration).toBe(true);
|
||||
});
|
||||
|
||||
@@ -3,17 +3,20 @@ import { createServer } from "node:http";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import express, { type Request, type Response } from "express";
|
||||
import { WebSocketServer, type WebSocket } from "ws";
|
||||
import { type WebSocket, WebSocketServer } from "ws";
|
||||
import { createLogger } from "./logger.js";
|
||||
import { MSG, WS } from "./protocol.js";
|
||||
import type {
|
||||
Record,
|
||||
RecordSummary,
|
||||
Worker,
|
||||
Device,
|
||||
RegisterMessage,
|
||||
Record,
|
||||
RecordMessage,
|
||||
RecordSummary,
|
||||
RegisterMessage,
|
||||
Worker,
|
||||
} from "./types.js";
|
||||
|
||||
const logger = createLogger("server");
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const DATA_DIR = join(__dirname, "../data/records");
|
||||
const FRONTEND_DIR = join(__dirname, "../../frontend/dist");
|
||||
@@ -32,9 +35,7 @@ async function loadRecords(): Promise<void> {
|
||||
for (const f of files) {
|
||||
if (!f.endsWith(".json")) continue;
|
||||
try {
|
||||
const data = JSON.parse(
|
||||
await readFile(join(DATA_DIR, f), "utf8")
|
||||
) as Record;
|
||||
const data = JSON.parse(await readFile(join(DATA_DIR, f), "utf8")) as Record;
|
||||
records.set(data.id, data);
|
||||
} catch {
|
||||
// Ignore invalid files
|
||||
@@ -129,9 +130,7 @@ function broadcastWorkers(): void {
|
||||
const workerList = [...workers.values()];
|
||||
for (const client of dashboardClients) {
|
||||
if (client.readyState === 1) {
|
||||
client.send(
|
||||
JSON.stringify({ type: MSG.WORKERS, workers: workerList })
|
||||
);
|
||||
client.send(JSON.stringify({ type: MSG.WORKERS, workers: workerList }));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -169,9 +168,7 @@ workerWss.on("connection", (ws: WebSocket) => {
|
||||
for (const client of dashboardClients) {
|
||||
if (client.readyState === 1) {
|
||||
const { stdout, stderr, ...summary } = rec;
|
||||
client.send(
|
||||
JSON.stringify({ type: MSG.NEW_RECORD, record: summary })
|
||||
);
|
||||
client.send(JSON.stringify({ type: MSG.NEW_RECORD, record: summary }));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -194,4 +191,4 @@ dashboardWss.on("connection", (ws: WebSocket) => {
|
||||
ws.on("close", () => dashboardClients.delete(ws));
|
||||
});
|
||||
|
||||
server.listen(PORT, () => console.log(`Dashboard server on port ${PORT}`));
|
||||
server.listen(PORT, () => logger.info(`Dashboard server on port ${PORT}`));
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// Simple logger utility for server startup messages
|
||||
// Note: @uncaged/workflow-util does not exist in this monorepo,
|
||||
// so we use a minimal logger that wraps console for consistency
|
||||
|
||||
export interface Logger {
|
||||
info: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
}
|
||||
|
||||
export function createLogger(name: string): Logger {
|
||||
return {
|
||||
info: (message: string) => console.log(`[${name}] ${message}`),
|
||||
error: (message: string) => console.error(`[${name}] ${message}`),
|
||||
warn: (message: string) => console.warn(`[${name}] ${message}`),
|
||||
};
|
||||
}
|
||||
@@ -16,6 +16,6 @@ export const WS = {
|
||||
DASHBOARD: "/ws/dashboard",
|
||||
} as const;
|
||||
|
||||
export type MessageType = typeof MSG[keyof typeof MSG];
|
||||
export type ApiEndpoint = typeof API[keyof typeof API];
|
||||
export type WebSocketEndpoint = typeof WS[keyof typeof WS];
|
||||
export type MessageType = (typeof MSG)[keyof typeof MSG];
|
||||
export type ApiEndpoint = (typeof API)[keyof typeof API];
|
||||
export type WebSocketEndpoint = (typeof WS)[keyof typeof WS];
|
||||
|
||||
Reference in New Issue
Block a user