mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-30 04:05:43 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a099673413 | ||
|
|
3abb0cb18e |
@@ -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
|
||||
|
||||
@@ -346,59 +346,6 @@ test("replays both sides of compaction with native IDs and isolates rewound bran
|
||||
).toEqual(["u1"]);
|
||||
});
|
||||
|
||||
test("keeps saved messages when auto-title metadata has no ID", () => {
|
||||
const userMessage = { role: "user", content: "hello" };
|
||||
const rows = [
|
||||
{ type: "session", version: 3, id: "session" },
|
||||
{ type: "session_info", name: "Automatic title", autoTitle: true },
|
||||
{ type: "message", id: "u1", parentId: null, message: userMessage },
|
||||
{ type: "session_info", name: "Updated title", autoTitle: true },
|
||||
];
|
||||
|
||||
const history = readPiTranscript(rows.map((row) => JSON.stringify(row)).join("\n"));
|
||||
expect(history.messages).toEqual([userMessage]);
|
||||
expect(history.userEntries).toEqual([{ id: "u1", text: "hello" }]);
|
||||
});
|
||||
|
||||
test("replays the active branch rooted at a model change without a parent ID", () => {
|
||||
const userMessage = { role: "user", content: "after reopening" };
|
||||
const rows = [
|
||||
{ type: "session", version: 3, id: "session" },
|
||||
{
|
||||
type: "message",
|
||||
id: "old",
|
||||
parentId: null,
|
||||
message: { role: "user", content: "old branch" },
|
||||
},
|
||||
{ type: "session_info", name: "Automatic title", autoTitle: true },
|
||||
{ type: "model_change", id: "model", provider: "test", modelId: "test-model" },
|
||||
{ type: "message", id: "u1", parentId: "model", message: userMessage },
|
||||
];
|
||||
|
||||
const history = readPiTranscript(rows.map((row) => JSON.stringify(row)).join("\n"));
|
||||
expect(history.messages).toEqual([userMessage]);
|
||||
expect(history.userEntries).toEqual([{ id: "u1", text: "after reopening" }]);
|
||||
});
|
||||
|
||||
test("replays a message that Pi writes without a parent ID after an ID-less title", () => {
|
||||
const userMessage = { role: "user", content: "after reopening" };
|
||||
const rows = [
|
||||
{ type: "session", version: 3, id: "session" },
|
||||
{
|
||||
type: "message",
|
||||
id: "old",
|
||||
parentId: null,
|
||||
message: { role: "user", content: "old branch" },
|
||||
},
|
||||
{ type: "session_info", name: "Automatic title", autoTitle: true },
|
||||
{ type: "message", id: "u1", message: userMessage },
|
||||
];
|
||||
|
||||
const history = readPiTranscript(rows.map((row) => JSON.stringify(row)).join("\n"));
|
||||
expect(history.messages).toEqual([userMessage]);
|
||||
expect(history.userEntries).toEqual([{ id: "u1", text: "after reopening" }]);
|
||||
});
|
||||
|
||||
test("preserves native custom entries and legacy linear messages without inventing native IDs", async () => {
|
||||
const custom = {
|
||||
type: "custom_message",
|
||||
|
||||
@@ -111,34 +111,22 @@ export function readPiTranscript(contents: string): PiTranscript {
|
||||
}
|
||||
|
||||
function activeBranch(records: z.infer<typeof record>[]): z.infer<typeof record>[] {
|
||||
type TreeEntry = z.infer<typeof record> & { id: string; parentId: string | null };
|
||||
const byId = new Map<string, TreeEntry>();
|
||||
let entry: TreeEntry | undefined;
|
||||
for (const [index, row] of records.entries()) {
|
||||
const { id, parentId } = row;
|
||||
// An automatic title without an ID has no position in the message tree.
|
||||
if (!id && row.type === "session_info") continue;
|
||||
const previous = records[index - 1];
|
||||
const followsIdlessTitle = previous?.type === "session_info" && !previous.id;
|
||||
if (
|
||||
!id ||
|
||||
byId.has(id) ||
|
||||
(parentId === undefined && row.type !== "model_change" && !followsIdlessTitle)
|
||||
) {
|
||||
const byId = new Map<string, (typeof records)[number]>();
|
||||
for (const entry of records) {
|
||||
if (!entry.id || entry.parentId === undefined || byId.has(entry.id))
|
||||
throw new Error("Invalid Pi transcript tree entry");
|
||||
}
|
||||
// After an ID-less title, Pi can append the next entry as a new root.
|
||||
entry = { ...row, id, parentId: parentId ?? null };
|
||||
byId.set(id, entry);
|
||||
byId.set(entry.id, entry);
|
||||
}
|
||||
const branch: TreeEntry[] = [];
|
||||
const branch: z.infer<typeof record>[] = [];
|
||||
const seen = new Set<string>();
|
||||
let entry = records.at(-1);
|
||||
while (entry) {
|
||||
if (seen.has(entry.id)) throw new Error("Cycle in Pi transcript ancestry");
|
||||
seen.add(entry.id);
|
||||
const id = entry.id!;
|
||||
if (seen.has(id)) throw new Error("Cycle in Pi transcript ancestry");
|
||||
seen.add(id);
|
||||
branch.push(entry);
|
||||
if (entry.parentId === null) break;
|
||||
entry = byId.get(entry.parentId);
|
||||
entry = byId.get(entry.parentId!);
|
||||
if (!entry) throw new Error("Missing Pi transcript ancestor");
|
||||
}
|
||||
branch.reverse();
|
||||
|
||||
@@ -401,12 +401,10 @@ test("seeded compacted Pi history survives daemon reload, native rewind and Fork
|
||||
});
|
||||
const records = [
|
||||
{ type: "session", version: 3, id: nativeId, cwd, timestamp },
|
||||
{ type: "session_info", timestamp, name: "Automatic title", autoTitle: true },
|
||||
{ type: "model_change", id: "old-model", timestamp, provider: "openrouter", modelId: "test" },
|
||||
{
|
||||
type: "message",
|
||||
id: "system",
|
||||
parentId: "old-model",
|
||||
parentId: null,
|
||||
timestamp,
|
||||
message: {
|
||||
role: "system",
|
||||
|
||||
Reference in New Issue
Block a user