Files
penguin-harness/packages/server/test/config.test.ts
T
Yaowei Zheng 45bfae6e94 Initialize repository with harness code and assets
Initial import of all source code, config, and README assets: the
packages workspace (cli, core, server, web, docs, landing, skills),
build scripts, tooling config, and CI workflows.

Includes the data-layout revision made on this branch: the local data
root defaults to ~/.penguin/data (PENGUIN_HOME still overrides; the
installer keeps its binaries in ~/.penguin), and every Agent lives
under <project>/agents/<agent>/ — path helpers, the three
agent-enumeration scans, the system prompt, built-in Skills, tests
and docs all follow the new layout.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018ihk8iQuo3kv2aPjAYEPuR
2026-07-19 14:06:53 +08:00

30 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* resolveServerConfig PORT parsing tests: both the default (missing) and empty string
* (the common `PORT=` empty value in `.env`) fall back to 7364 — Number("") === 0 used
* to make the empty string pass range validation and bind to a random port; explicit
* "0" is preserved (explicit semantics for a random available port); invalid values
* throw. This matches the CLI's resolvePort semantics (packages/cli serve).
*/
import { describe, expect, it } from "vitest";
import { resolveServerConfig } from "../src/config.js";
const base = { PENGUIN_HOME: "/tmp/penguin-config-test" };
describe("resolveServerConfig:PORT 解析", () => {
it("缺省 7364;空串视为未设置(不落到端口 0)", () => {
expect(resolveServerConfig({ ...base }).port).toBe(7364);
expect(resolveServerConfig({ ...base, PORT: "" }).port).toBe(7364);
});
it('显式数值生效;显式 "0" 保留(绑随机可用端口)', () => {
expect(resolveServerConfig({ ...base, PORT: "8930" }).port).toBe(8930);
expect(resolveServerConfig({ ...base, PORT: "0" }).port).toBe(0);
});
it("非整数或超界抛错", () => {
for (const bad of ["abc", "3.14", "-1", "65536"]) {
expect(() => resolveServerConfig({ ...base, PORT: bad }), bad).toThrow(/非法端口/);
}
});
});