chore(vendor): import pi 1.3.0
Imported as a linear vendor commit so forge rebases do not replay the upstream root tree. git-subtree-dir: third_party/pi git-subtree-split: 71023aec1546d6d677a65669c5665c0927ce0dd0
This commit is contained in:
@@ -1,7 +1,17 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, realpathSync, rmSync } from "node:fs";
|
||||
import {
|
||||
existsSync,
|
||||
mkdirSync,
|
||||
mkdtempSync,
|
||||
readdirSync,
|
||||
readFileSync,
|
||||
realpathSync,
|
||||
renameSync,
|
||||
rmSync,
|
||||
} from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join, resolve } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { Args } from "../src/cli/args.ts";
|
||||
import { ENV_AGENT_DIR } from "../src/config.ts";
|
||||
@@ -10,7 +20,8 @@ import { SettingsManager } from "../src/core/settings-manager.ts";
|
||||
import { createSessionManager } from "../src/main.ts";
|
||||
|
||||
const cliPath = resolve(__dirname, "../src/cli.ts");
|
||||
const sourceResolverPath = resolve(__dirname, "../src/experimental/source-resolver.ts");
|
||||
// --import takes a module specifier, not a filesystem path.
|
||||
const sourceResolverUrl = pathToFileURL(resolve(__dirname, "../src/experimental/source-resolver.ts")).href;
|
||||
const tempDirs: string[] = [];
|
||||
|
||||
afterEach(() => {
|
||||
@@ -55,7 +66,7 @@ async function runCli(args: string[]): Promise<{ code: number | null; agentDir:
|
||||
mkdirSync(projectDir, { recursive: true });
|
||||
|
||||
const code = await new Promise<number | null>((resolvePromise, reject) => {
|
||||
const child = spawn(process.execPath, ["--import", sourceResolverPath, cliPath, ...args], {
|
||||
const child = spawn(process.execPath, ["--import", sourceResolverUrl, cliPath, ...args], {
|
||||
cwd: projectDir,
|
||||
env: {
|
||||
...process.env,
|
||||
@@ -147,6 +158,62 @@ describe("--session-id", () => {
|
||||
expect(consoleError).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Regression test for #9440.
|
||||
it("looks up exact IDs without building full session listings", async () => {
|
||||
const tempRoot = createTempDir();
|
||||
const projectDir = join(tempRoot, "project");
|
||||
const sessionDir = join(tempRoot, "sessions");
|
||||
mkdirSync(projectDir, { recursive: true });
|
||||
const unrelated = SessionManager.create(projectDir, sessionDir, { id: "unrelated-id" });
|
||||
persistSession(unrelated, "large transcript contents must not be loaded");
|
||||
const list = vi.spyOn(SessionManager, "list").mockRejectedValue(new Error("unexpected full listing"));
|
||||
vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
|
||||
const created = await createSessionManager(
|
||||
args({ sessionId: "fresh-id" }),
|
||||
projectDir,
|
||||
sessionDir,
|
||||
SettingsManager.inMemory(),
|
||||
);
|
||||
|
||||
expect(created.getSessionId()).toBe("fresh-id");
|
||||
expect(list).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("reopens an exact ID from a renamed session file", async () => {
|
||||
const tempRoot = createTempDir();
|
||||
const projectDir = join(tempRoot, "project");
|
||||
const sessionDir = join(tempRoot, "sessions");
|
||||
mkdirSync(projectDir, { recursive: true });
|
||||
const original = SessionManager.create(projectDir, sessionDir, { id: "renamed-id" });
|
||||
persistSession(original, "persist me");
|
||||
const renamedPath = join(sessionDir, "imported-session.jsonl");
|
||||
renameSync(original.getSessionFile()!, renamedPath);
|
||||
|
||||
const reopened = await createSessionManager(
|
||||
args({ sessionId: "renamed-id" }),
|
||||
projectDir,
|
||||
sessionDir,
|
||||
SettingsManager.inMemory(),
|
||||
);
|
||||
|
||||
expect(reopened.getSessionFile()).toBe(renamedPath);
|
||||
});
|
||||
|
||||
it("filters exact IDs by cwd in a custom session directory", () => {
|
||||
const tempRoot = createTempDir();
|
||||
const projectA = join(tempRoot, "project-a");
|
||||
const projectB = join(tempRoot, "project-b");
|
||||
const sessionDir = join(tempRoot, "sessions");
|
||||
mkdirSync(projectA, { recursive: true });
|
||||
mkdirSync(projectB, { recursive: true });
|
||||
const foreign = SessionManager.create(projectB, sessionDir, { id: "foreign-id" });
|
||||
persistSession(foreign, "foreign session");
|
||||
|
||||
expect(SessionManager.findById(projectA, "foreign-id", sessionDir)).toBeUndefined();
|
||||
expect(SessionManager.findById(projectB, "foreign-id", sessionDir)).toBe(foreign.getSessionFile());
|
||||
});
|
||||
|
||||
it("rejects an existing fork target in process", async () => {
|
||||
const tempRoot = createTempDir();
|
||||
const projectDir = join(tempRoot, "project");
|
||||
|
||||
Reference in New Issue
Block a user