Compare commits

...
Author SHA1 Message Date
paseo-bot[bot]andClaude Opus 5.5 a099673413 test(cli): reserve lifecycle test ports outside the ephemeral range (#11378)
port() took a port from port 0 and released it before the daemon
listened. Port-0 ports are ephemeral, so the OS could give the same
port to another process in that gap, and the daemon failed with
EADDRINUSE. port() now picks a free port from 20000-31999, below the
ephemeral range of Linux, macOS, and Windows.

Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 03:27:15 +00:00
SunicemanandShane Su 3abb0cb18e Leave unexpanded Windows variable paths unlinked in chat (#11228)
Co-authored-by: Shane Su <26364206+suniceman@users.noreply.github.com>
2026-11-30 03:12:59 +00:00
3 changed files with 45 additions and 6 deletions
@@ -308,6 +308,24 @@ describe("parseAssistantFileLink", () => {
});
});
it.each(["C:/repo", "\\\\host\\share\\repo"])(
"leaves Windows variable paths in inline code unlinked in %s",
(workspaceRoot) => {
expect(classifyAssistantFileLink("%TEMP%\\debug.md", { workspaceRoot })).toBeNull();
expect(classifyAssistantFileLink("%LOCALAPPDATA%/debug.md:3", { workspaceRoot })).toBeNull();
expect(classifyAssistantFileLink("C:\\Temp\\debug.md", { workspaceRoot })?.kind).toBe(
"directFile",
);
},
);
it("allows a literal percent-delimited directory in an authored file link", () => {
expect(
parseAssistantFileLink("%TEMP%/notes.md", { workspaceRoot: "C:/repo", explicitLink: true })
?.path,
).toBe("C:/repo/%TEMP%/notes.md");
});
it("parses absolute Windows hrefs inside the active workspace", () => {
expect(
parseAssistantFileLink("C:/repo/src/app.tsx#L12-L20", {
@@ -393,6 +393,14 @@ function parseWorkspaceRelativeFileLink(
value: string,
options: AssistantHrefParseOptions,
): InlinePathTarget | null {
// cmd.exe variables are shell expressions. The file opener only resolves literal paths.
if (
!options.explicitLink &&
/^(?:[A-Za-z]:[\\/]|[\\/]{2})/.test(options.workspaceRoot ?? "") &&
/^%[^%\\/]+%[\\/]/.test(value)
) {
return null;
}
const parsed = parseLocalPathParts(value, options);
if (!parsed || isAbsolutePath(parsed.path)) {
return null;
@@ -13,13 +13,26 @@ import { connectToDaemon } from "../../utils/client.js";
const repo = fileURLToPath(new URL("../../../../..", import.meta.url));
const cli = path.join(repo, "packages/cli/dist/index.js");
// Reserved ports come from below every OS's ephemeral range (Linux starts at
// 32768, macOS and Windows at 49152). A port from port 0 is ephemeral, and the
// OS may give it to another process between the reservation and the daemon's
// listen. A port from this range is never handed out that way.
const reservedPorts = { first: 20_000, count: 12_000 };
async function port() {
const server = net.createServer();
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
const value = (server.address() as net.AddressInfo).port;
await new Promise<void>((resolve) => server.close(() => resolve()));
if (value === 6767 || value === 6768) throw new Error("Unsafe test port");
return value;
for (let attempt = 0; attempt < 50; attempt++) {
const value = reservedPorts.first + Math.floor(Math.random() * reservedPorts.count);
if (await isFree(value)) return value;
}
throw new Error("No free test port");
}
function isFree(value: number) {
return new Promise<boolean>((resolve) => {
const server = net.createServer();
server.once("error", () => resolve(false));
server.listen(value, "127.0.0.1", () => server.close(() => resolve(true)));
});
}
// Port zero lets the daemon bind its own port, with no gap for another