test(ai): dropped chdir and env mutation from request-debug recording test
- Replaced `process.chdir(tempDir)` plus `PI_REQ_DEBUG=1` auto-naming with explicit `setNextRequestDebugPath` targets, removing the `previousCwd` save/restore and the `debugFiles` directory-scan helper. - The PI_REQ_DEBUG recording assertions now read each request/response from the path they set, so the test no longer mutates `process.cwd()` or the global debug env flag.
This commit is contained in:
@@ -16,21 +16,17 @@ import { buildModel } from "@oh-my-pi/pi-catalog/build";
|
||||
|
||||
const enc = new TextEncoder();
|
||||
|
||||
let previousCwd: string;
|
||||
let previousDebugFlag: string | undefined;
|
||||
let tempDir: string | undefined;
|
||||
|
||||
beforeEach(async () => {
|
||||
previousCwd = process.cwd();
|
||||
previousDebugFlag = Bun.env.PI_REQ_DEBUG;
|
||||
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "pi-req-debug-"));
|
||||
process.chdir(tempDir);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
clearCustomApis();
|
||||
clearNextRequestDebugPath();
|
||||
process.chdir(previousCwd);
|
||||
if (previousDebugFlag === undefined) delete Bun.env.PI_REQ_DEBUG;
|
||||
else Bun.env.PI_REQ_DEBUG = previousDebugFlag;
|
||||
if (tempDir) await fs.rm(tempDir, { recursive: true, force: true });
|
||||
@@ -53,15 +49,6 @@ function chunkedResponse(chunks: Uint8Array[]): Response {
|
||||
);
|
||||
}
|
||||
|
||||
async function debugFiles(): Promise<{ requestPath: string; responsePath: string }> {
|
||||
const files = await fs.readdir(tempDir!);
|
||||
const requestPath = files.find(file => /^rr-session-\d+\.json$/.test(file));
|
||||
expect(requestPath).toBeDefined();
|
||||
const responsePath = requestPath!.replace(/\.json$/, ".res.log");
|
||||
expect(files.includes(responsePath)).toBe(true);
|
||||
return { requestPath: path.join(tempDir!, requestPath!), responsePath: path.join(tempDir!, responsePath) };
|
||||
}
|
||||
|
||||
function splitResponseLog(bytes: Uint8Array): { headers: string; body: Uint8Array } {
|
||||
const separator = enc.encode("\r\n\r\n");
|
||||
let separatorIndex = -1;
|
||||
@@ -131,7 +118,8 @@ describe("PI_REQ_DEBUG request/response recording", () => {
|
||||
});
|
||||
|
||||
it("records request JSON before fetch and raw response bytes after headers", async () => {
|
||||
Bun.env.PI_REQ_DEBUG = "1";
|
||||
const requestPath = path.join(tempDir!, "v1-messages.json");
|
||||
setNextRequestDebugPath(requestPath);
|
||||
const responseBody = new Uint8Array([0x66, 0x69, 0x72, 0x73, 0x74, 0x00, 0xff, 0x0a]);
|
||||
const fetchImpl: FetchImpl = async () => chunkedResponse([responseBody.subarray(0, 5), responseBody.subarray(5)]);
|
||||
const wrapped = wrapFetchForRequestDebug(fetchImpl);
|
||||
@@ -143,7 +131,7 @@ describe("PI_REQ_DEBUG request/response recording", () => {
|
||||
});
|
||||
expect(new Uint8Array(await response.arrayBuffer())).toEqual(responseBody);
|
||||
|
||||
const { requestPath, responsePath } = await debugFiles();
|
||||
const responsePath = `${requestPath}.res.log`;
|
||||
const request = JSON.parse(await fs.readFile(requestPath, "utf8")) as Record<string, unknown>;
|
||||
expect(request).toMatchObject({
|
||||
protocol: "http",
|
||||
@@ -161,7 +149,8 @@ describe("PI_REQ_DEBUG request/response recording", () => {
|
||||
});
|
||||
|
||||
it("keeps the partial response log when the response body is cancelled", async () => {
|
||||
Bun.env.PI_REQ_DEBUG = "1";
|
||||
const requestPath = path.join(tempDir!, "partial.json");
|
||||
setNextRequestDebugPath(requestPath);
|
||||
const firstChunk = enc.encode("partial");
|
||||
let sent = false;
|
||||
const fetchImpl: FetchImpl = async () =>
|
||||
@@ -182,14 +171,15 @@ describe("PI_REQ_DEBUG request/response recording", () => {
|
||||
expect(firstRead.value).toEqual(firstChunk);
|
||||
await reader.cancel("turn aborted");
|
||||
|
||||
const { responsePath } = await debugFiles();
|
||||
const responsePath = `${requestPath}.res.log`;
|
||||
const log = splitResponseLog(await fs.readFile(responsePath));
|
||||
expect(log.headers).toContain("HTTP 201 Created");
|
||||
expect(log.body).toEqual(firstChunk);
|
||||
});
|
||||
|
||||
it("wraps provider fetch options with request debug recording", async () => {
|
||||
Bun.env.PI_REQ_DEBUG = "1";
|
||||
const requestPath = path.join(tempDir!, "provider.json");
|
||||
setNextRequestDebugPath(requestPath);
|
||||
const fetchMock: FetchImpl = async () => new Response("ok", { headers: { "x-debug": "yes" } });
|
||||
registerCustomApi("req-debug-test", (_model, _context, options) => {
|
||||
const events = new AssistantMessageEventStream();
|
||||
@@ -243,7 +233,7 @@ describe("PI_REQ_DEBUG request/response recording", () => {
|
||||
);
|
||||
await events.result();
|
||||
|
||||
const { requestPath, responsePath } = await debugFiles();
|
||||
const responsePath = `${requestPath}.res.log`;
|
||||
const request = JSON.parse(await fs.readFile(requestPath, "utf8")) as Record<string, unknown>;
|
||||
expect(request.url).toBe("https://provider.test/custom");
|
||||
expect(request.body).toEqual({ ok: true });
|
||||
|
||||
@@ -15,10 +15,6 @@
|
||||
- Changed the advisor advice injected into the primary transcript from a `Advisor (...): - [severity] note` prose block to one `<advisory severity="…" guidance="weigh, don't blindly obey">…</advisory>` element per note, with XML-escaped bodies. (Relocated the shared `escapeXmlText` helper to `@oh-my-pi/pi-utils`.)
|
||||
- Reverted `/dump` and `/advisor dump raw` to the pre-16.x full verbose dump: system prompt, model/thinking config, tool inventory with parameters, and the message transcript rendered with markdown role headings (`## User`, `## Assistant`, `### Tool Call: <name>` with the call's `_i` intent as a `//` comment under the heading and the remaining arguments as a fenced YAML block, `### Tool Result: <name>`, plus `## Bash Execution`/`## File Mention`/summary sections) instead of the model's native-dialect turn envelopes and `<invoke>`/`<parameter>` XML tool calls. Dropped the compact default and the `[raw]` flag on `/dump`; the compact `→ tool(...) ⇒ ok` history format is no longer reachable from `/dump`. `/advisor dump` still defaults to compact, and `/advisor dump raw` now renders the same markdown dump (previously the model's native-dialect envelopes).
|
||||
|
||||
### Removed
|
||||
|
||||
- Removed the built-in `render_mermaid` tool and its `renderMermaid.enabled` setting, so it can no longer be invoked directly
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed same-process `JsRuntime` cleanup so disposing an older inline/direct runtime no longer deletes a newer runtime's JS helper globals; inactive cmux/direct runtimes now re-activate their globals before sequential use while overlapping cross-runtime runs fail explicitly.
|
||||
@@ -35,16 +31,14 @@
|
||||
- Fixed the Agent Hub stacking duplicate `Agent Hub · N running` frames and stranding garbage rows in scrollback while navigating with subagents still streaming. The hub was a non-fullscreen overlay composited over a live transcript, so each time a running subagent's progress grew the frame and scrolled the window the previously-painted hub copy was pushed permanently into the terminal's native scrollback (which the engine can't rewrite). It now renders inline in the editor slot — the same anchored region every other selector and the `ask` tool use — riding the normal append-only commit path, so the transcript commits above it exactly once and the hub repaints in place instead of leaking copies. (Avoids borrowing the alternate screen.)
|
||||
- Fixed every subagent registering itself as its own parent in the agent registry (`parentId === id`), so the Agent Hub rendered each agent as `sub · of <itself>` and the ←← parent-navigation gesture looped on the same agent. The SDK was reusing `parentTaskPrefix` — the agent's own artifact/output-id prefix — as the registry parent link; spawns now pass a separate `parentAgentId` (the spawning agent's id: `Main` for top-level `task` spawns, the parent subagent for nested spawns and eval `agent()`, the focused agent for `/tan`) and the registry records that as the parent.
|
||||
- Fixed messaging a `parked` subagent that was restored from disk (Agent Hub scan, or a resumed/restarted session) failing with `cannot be revived (no reviver registered)` even though its transcript was intact. Such refs carry a session file but no in-memory reviver — the executor's live reviver closure dies with the spawning turn/process — so IRC sends and Agent Hub focus refused them. `AgentLifecycleManager.ensureLive` now cold-revives them through a persisted-subagent reviver factory (installed by the top-level interactive/RPC session) that rebuilds the subagent from its JSONL the way `--resume` rebuilds a session: it reopens the file and replays it through `createAgentSession`, but sources the runtime contract from a now-readable `session_init` record (`SessionManager.peekSessionInit`) so tools, system prompt, output schema, and kind are restored rather than resurrected as a default top-level session. `session_init` now also persists the effective `spawns` allowlist and read-summarization flag so a cold revive keeps the original capability surface (old files without them deny re-spawning rather than defaulting to wildcard). Isolated runs and pre-`session_init` files whose recorded workspace no longer exists stay transcript-only (`history://`).
|
||||
|
||||
### Fixed
|
||||
- Fixed the terminal window-title OSC writes (`setTerminalTitle`/`pushTerminalTitle`/`popTerminalTitle`) leaking escape sequences to a developer's terminal during `bun test`; they now skip when the terminal is headless (the test-runtime default), matching the `ProcessTerminal` render/probe suppression so interactive-mode tests no longer paint to the real terminal
|
||||
|
||||
- Fixed empty CLI sessions being retained after opening `omp` and exiting without a prompt ([#2800](https://github.com/can1357/oh-my-pi/issues/2800)).
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed `hooks/pre/*.ts` and `hooks/post/*.ts` files discovered through `hookCapability` being registered in discovery but never loaded into the extension runner, so their `tool_call` handlers now run without a manual `settings.json` `extensions` entry ([#2796](https://github.com/can1357/oh-my-pi/issues/2796)).
|
||||
|
||||
### Removed
|
||||
|
||||
- Removed the built-in `render_mermaid` tool and its `renderMermaid.enabled` setting, so it can no longer be invoked directly
|
||||
|
||||
## [16.0.2] - 2026-06-16
|
||||
|
||||
### Added
|
||||
@@ -11832,4 +11826,4 @@ Initial public release.
|
||||
|
||||
## [0.7.6] - 2025-11-13
|
||||
|
||||
Previous releases did not maintain a changelog.
|
||||
Previous releases did not maintain a changelog.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# Changelog
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Removed
|
||||
|
||||
- Removed rendering support for the `render_mermaid` tool from the web tool registry
|
||||
@@ -88,4 +89,4 @@
|
||||
|
||||
### Security
|
||||
|
||||
- Hardened transcript Markdown rendering by escaping embedded HTML and allowing only safe link schemes
|
||||
- Hardened transcript Markdown rendering by escaping embedded HTML and allowing only safe link schemes
|
||||
|
||||
@@ -1689,4 +1689,4 @@ Initial release under @oh-my-pi scope. See previous releases at [badlogic/pi-mon
|
||||
|
||||
### Fixed
|
||||
|
||||
- **Readline-style Ctrl+W**: Now skips trailing whitespace before deleting the preceding word, matching standard readline behavior. ([#306](https://github.com/badlogic/pi-mono/pull/306) by [@kim0](https://github.com/kim0))
|
||||
- **Readline-style Ctrl+W**: Now skips trailing whitespace before deleting the preceding word, matching standard readline behavior. ([#306](https://github.com/badlogic/pi-mono/pull/306) by [@kim0](https://github.com/kim0))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# Changelog
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- Added `escapeXmlText` utility to escape XML-significant characters `&`, `<`, and `>` in element body text
|
||||
@@ -147,4 +148,4 @@
|
||||
|
||||
### Added
|
||||
|
||||
- Added an XDG-aware tiny-title model cache directory helper for coding-agent local title models.
|
||||
- Added an XDG-aware tiny-title model cache directory helper for coding-agent local title models.
|
||||
|
||||
Reference in New Issue
Block a user