@firstpick/pi-package-webui 0.6.3 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/pi-webui.mjs +449 -13
- package/lib/trust-boundaries.mjs +2 -0
- package/package.json +2 -2
- package/public/app.js +918 -10
- package/public/index.html +66 -2
- package/public/styles.css +450 -2
- package/tests/fixtures/fake-pi.mjs +59 -3
- package/tests/http-endpoints-harness.test.mjs +212 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { spawn, spawnSync } from "node:child_process";
|
|
3
3
|
import { createServer } from "node:http";
|
|
4
|
-
import { chmod, mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
4
|
+
import { chmod, mkdir, mkdtemp, readFile, rm, stat, symlink, writeFile } from "node:fs/promises";
|
|
5
5
|
import { networkInterfaces, tmpdir } from "node:os";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { setTimeout as delay } from "node:timers/promises";
|
|
@@ -70,8 +70,19 @@ function runGitFixture(args, cwd, message) {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
const cwd = await mkdtemp(path.join(tmpdir(), "pi-webui-http-harness-"));
|
|
73
|
-
const
|
|
73
|
+
const harnessSideEffectsRoot = await mkdtemp(path.join(tmpdir(), "pi-webui-http-harness-side-effects-"));
|
|
74
|
+
const settingsFile = path.join(harnessSideEffectsRoot, "webui-settings.json");
|
|
75
|
+
const openCommandLog = path.join(harnessSideEffectsRoot, "open-default.log");
|
|
76
|
+
const openCommandScript = path.join(harnessSideEffectsRoot, "fake-open-default.mjs");
|
|
77
|
+
const fakeOpenBinDir = path.join(harnessSideEffectsRoot, "bin");
|
|
74
78
|
await chmod(fakePi, 0o755);
|
|
79
|
+
await mkdir(fakeOpenBinDir, { recursive: true });
|
|
80
|
+
await writeFile(openCommandScript, `#!/usr/bin/env node\nimport { appendFile } from "node:fs/promises";\nawait appendFile(process.env.PI_WEBUI_OPEN_LOG, "custom-open\\t" + process.argv.slice(2).join("\\t") + "\\n", "utf8");\n`, "utf8");
|
|
81
|
+
await chmod(openCommandScript, 0o755);
|
|
82
|
+
await writeFile(path.join(fakeOpenBinDir, "xdg-open"), `#!/usr/bin/env node\nimport { appendFile } from "node:fs/promises";\nawait appendFile(process.env.PI_WEBUI_OPEN_LOG, "xdg-open\\t" + process.argv.slice(2).join("\\t") + "\\n", "utf8");\n`, "utf8");
|
|
83
|
+
await writeFile(path.join(fakeOpenBinDir, "gio"), `#!/usr/bin/env node\nimport { appendFile } from "node:fs/promises";\nawait appendFile(process.env.PI_WEBUI_OPEN_LOG, "gio\\t" + process.argv.slice(2).join("\\t") + "\\n", "utf8");\n`, "utf8");
|
|
84
|
+
await writeFile(path.join(fakeOpenBinDir, "xdg-mime"), `#!/usr/bin/env node\nconst [,, verb, mode, value = ""] = process.argv;\nif (verb === "query" && mode === "filetype") {\n if (value.endsWith(".piunknown")) console.log("application/x-pi-unknown");\n else if (value.endsWith(".md")) console.log("text/markdown");\n else console.log("text/plain");\n process.exit(0);\n}\nif (verb === "query" && mode === "default") {\n if (value === "text/plain") console.log("fake-text-editor.desktop");\n process.exit(0);\n}\nprocess.exit(1);\n`, "utf8");
|
|
85
|
+
await Promise.all(["xdg-open", "gio", "xdg-mime"].map((name) => chmod(path.join(fakeOpenBinDir, name), 0o755)));
|
|
75
86
|
|
|
76
87
|
const voiceProviderRequests = [];
|
|
77
88
|
const voiceProvider = createServer(async (req, res) => {
|
|
@@ -103,7 +114,12 @@ const child = spawn(process.execPath, [serverScript, "--cwd", cwd, "--host", "0.
|
|
|
103
114
|
GIT_AUTHOR_EMAIL: "pi-webui-test@example.invalid",
|
|
104
115
|
GIT_COMMITTER_NAME: "Pi WebUI Test",
|
|
105
116
|
GIT_COMMITTER_EMAIL: "pi-webui-test@example.invalid",
|
|
117
|
+
PATH: `${fakeOpenBinDir}${path.delimiter}${process.env.PATH || ""}`,
|
|
118
|
+
PI_CODING_AGENT_DIR: path.join(harnessSideEffectsRoot, "agent"),
|
|
106
119
|
PI_WEBUI_SETTINGS_FILE: settingsFile,
|
|
120
|
+
...(process.platform === "linux" ? {} : { PI_WEBUI_OPEN_COMMAND: openCommandScript }),
|
|
121
|
+
PI_WEBUI_OPEN_LOG: openCommandLog,
|
|
122
|
+
FAKE_PI_VOICE_SCRIPTS: "1",
|
|
107
123
|
PI_VOICE_STT_URL: `http://127.0.0.1:${voiceProviderPort}/stt`,
|
|
108
124
|
PI_VOICE_TTS_URL: `http://127.0.0.1:${voiceProviderPort}/tts`,
|
|
109
125
|
},
|
|
@@ -201,6 +217,45 @@ try {
|
|
|
201
217
|
assert.equal(state.status, 200);
|
|
202
218
|
assert.equal(state.body?.data?.model?.provider, "fake", "state should come from the fake pi RPC");
|
|
203
219
|
|
|
220
|
+
const forkSourceTab = await request("127.0.0.1", "/api/tabs", { method: "POST", body: { cwd, title: "fork-running-source" } });
|
|
221
|
+
assert.equal(forkSourceTab.status, 201, `fork source tab should open: ${forkSourceTab.body?.error || ""}`);
|
|
222
|
+
const forkSourceTabId = forkSourceTab.body?.data?.tab?.id;
|
|
223
|
+
assert.ok(forkSourceTabId, "fork source tab should have an id");
|
|
224
|
+
const runningPrompt = "voice test slow fork fixture";
|
|
225
|
+
const runningPromptResponse = await request("127.0.0.1", "/api/prompt", { method: "POST", body: { message: runningPrompt, tab: forkSourceTabId }, timeoutMs: 10_000 });
|
|
226
|
+
assert.equal(runningPromptResponse.status, 200, `slow scripted prompt should start: ${runningPromptResponse.body?.error || ""}`);
|
|
227
|
+
let streamingState;
|
|
228
|
+
for (let attempt = 0; attempt < 30; attempt++) {
|
|
229
|
+
streamingState = await request("127.0.0.1", `/api/state?tab=${encodeURIComponent(forkSourceTabId)}`);
|
|
230
|
+
if (streamingState.body?.data?.isStreaming === true) break;
|
|
231
|
+
await delay(100);
|
|
232
|
+
}
|
|
233
|
+
assert.equal(streamingState?.body?.data?.isStreaming, true, "source tab should still be running before fork");
|
|
234
|
+
const forkMessagesWhileRunning = await request("127.0.0.1", `/api/fork-messages?tab=${encodeURIComponent(forkSourceTabId)}`);
|
|
235
|
+
assert.equal(forkMessagesWhileRunning.status, 200, "fork selector data should load while the source tab is running");
|
|
236
|
+
const runningForkPoint = (forkMessagesWhileRunning.body?.data?.messages || []).find((item) => item.text === runningPrompt);
|
|
237
|
+
assert.ok(runningForkPoint?.entryId, "running prompt should be available as a fork point");
|
|
238
|
+
const forkWhileRunning = await request("127.0.0.1", "/api/fork", { method: "POST", body: { tab: forkSourceTabId, entryId: runningForkPoint.entryId }, timeoutMs: 10_000 });
|
|
239
|
+
assert.equal(forkWhileRunning.status, 200, `fork while running should succeed: ${forkWhileRunning.body?.error || ""}`);
|
|
240
|
+
const forkedTabId = forkWhileRunning.body?.data?.tab?.id;
|
|
241
|
+
assert.ok(forkedTabId, "fork response should include the opened fork tab");
|
|
242
|
+
assert.notEqual(forkedTabId, forkSourceTabId, "forking should create a new tab instead of replacing the running source tab");
|
|
243
|
+
assert.equal(forkWhileRunning.body?.data?.text, runningPrompt, "fork response should restore the selected prompt text for editing");
|
|
244
|
+
assert.ok((forkWhileRunning.body?.data?.tabs || []).some((tab) => tab.id === forkSourceTabId), "fork response should keep the original running tab in the tab list");
|
|
245
|
+
assert.ok((forkWhileRunning.body?.data?.tabs || []).some((tab) => tab.id === forkedTabId), "fork response should include the new fork tab in the tab list");
|
|
246
|
+
assert.match(String(forkWhileRunning.body?.data?.sessionFile || ""), /\.jsonl$/, "fork response should include the new session file");
|
|
247
|
+
const forkSessionContent = await readFile(forkWhileRunning.body.data.sessionFile, "utf8");
|
|
248
|
+
assert.match(forkSessionContent, /"type":"session"/, "forked session file should be written before opening its tab");
|
|
249
|
+
const sourceAfterFork = await request("127.0.0.1", `/api/state?tab=${encodeURIComponent(forkSourceTabId)}`);
|
|
250
|
+
assert.equal(sourceAfterFork.status, 200, "source tab should still respond after forking");
|
|
251
|
+
for (let attempt = 0; attempt < 40 && sourceAfterFork.body?.data?.isStreaming; attempt++) {
|
|
252
|
+
const next = await request("127.0.0.1", `/api/state?tab=${encodeURIComponent(forkSourceTabId)}`);
|
|
253
|
+
if (!next.body?.data?.isStreaming) break;
|
|
254
|
+
await delay(100);
|
|
255
|
+
}
|
|
256
|
+
const closeForkTestTabs = await request("127.0.0.1", "/api/tabs/close", { method: "POST", body: { ids: [forkSourceTabId, forkedTabId] }, timeoutMs: 10_000 });
|
|
257
|
+
assert.equal(closeForkTestTabs.status, 200, "fork test tabs should close before continuing baseline endpoint checks");
|
|
258
|
+
|
|
204
259
|
const gitAvailable = spawnSync("git", ["--version"], { encoding: "utf8" }).status === 0;
|
|
205
260
|
if (gitAvailable) {
|
|
206
261
|
const gitInit = await request("127.0.0.1", "/api/git-workflow/init", { method: "POST", body: { tab: tabId } });
|
|
@@ -694,6 +749,144 @@ try {
|
|
|
694
749
|
assert.equal(copy.body?.data?.status, "succeeded", "native /copy should succeed through the adapter");
|
|
695
750
|
assert.equal(copy.body?.data?.copyText, "fake last text");
|
|
696
751
|
|
|
752
|
+
// File tree/viewer APIs stay scoped to the requested tab cwd and reject unsafe content.
|
|
753
|
+
const filesRoot = path.join(cwd, "files-fixture");
|
|
754
|
+
const viewerRelative = "files-fixture/viewer.txt";
|
|
755
|
+
const markdownRelative = "files-fixture/docs/readme.md";
|
|
756
|
+
const binaryRelative = "files-fixture/binary.bin";
|
|
757
|
+
const noDefaultRelative = "files-fixture/no-default.piunknown";
|
|
758
|
+
const largeRelative = "files-fixture/large.txt";
|
|
759
|
+
const depthEightFileRelative = "deep-search/f1/f2/f3/f4/f5/f6/depth-eight-file.txt";
|
|
760
|
+
const depthEightDirectoryRelative = "deep-search/d1/d2/d3/d4/d5/d6/depth-eight-dir";
|
|
761
|
+
const depthNineFileRelative = "deep-search/t1/t2/t3/t4/t5/t6/t7/too-deep-file.txt";
|
|
762
|
+
await mkdir(path.join(filesRoot, "docs"), { recursive: true });
|
|
763
|
+
await mkdir(path.join(cwd, path.dirname(depthEightFileRelative)), { recursive: true });
|
|
764
|
+
await mkdir(path.join(cwd, depthEightDirectoryRelative), { recursive: true });
|
|
765
|
+
await mkdir(path.join(cwd, path.dirname(depthNineFileRelative)), { recursive: true });
|
|
766
|
+
await writeFile(path.join(cwd, viewerRelative), "hello file viewer\nsecond line\n", "utf8");
|
|
767
|
+
await writeFile(path.join(cwd, markdownRelative), "# File Viewer\n\nMarkdown preview support.\n", "utf8");
|
|
768
|
+
await writeFile(path.join(cwd, noDefaultRelative), "unknown extension should use text/plain editor fallback\n", "utf8");
|
|
769
|
+
await writeFile(path.join(cwd, depthEightFileRelative), "depth 8 search fixture\n", "utf8");
|
|
770
|
+
await writeFile(path.join(cwd, depthNineFileRelative), "depth 9 search fixture\n", "utf8");
|
|
771
|
+
await writeFile(path.join(cwd, binaryRelative), Buffer.from([0, 1, 2, 3]));
|
|
772
|
+
await writeFile(path.join(cwd, largeRelative), Buffer.alloc(2 * 1024 * 1024 + 1, 0x61));
|
|
773
|
+
|
|
774
|
+
const fileTree = await request("127.0.0.1", `/api/files?tab=${encodeURIComponent(tabId)}&path=${encodeURIComponent("files-fixture")}`);
|
|
775
|
+
assert.equal(fileTree.status, 200, `file tree endpoint should list workspace directories: ${fileTree.body?.error || ""}`);
|
|
776
|
+
assert.equal(fileTree.body?.ok, true);
|
|
777
|
+
const fileTreeEntries = fileTree.body?.data?.entries || [];
|
|
778
|
+
assert.equal(fileTreeEntries.find((entry) => entry.name === "docs")?.type, "directory", "file tree should identify subdirectories");
|
|
779
|
+
assert.equal(fileTreeEntries.find((entry) => entry.name === "viewer.txt")?.type, "file", "file tree should identify regular files");
|
|
780
|
+
|
|
781
|
+
const fileSearch = await request("127.0.0.1", `/api/files/search?tab=${encodeURIComponent(tabId)}&q=${encodeURIComponent("readme")}`);
|
|
782
|
+
assert.equal(fileSearch.status, 200, `file search endpoint should search workspace files: ${fileSearch.body?.error || ""}`);
|
|
783
|
+
assert.equal(fileSearch.body?.ok, true);
|
|
784
|
+
const fileSearchEntries = fileSearch.body?.data?.entries || [];
|
|
785
|
+
assert.equal(fileSearchEntries.find((entry) => entry.path === markdownRelative)?.type, "file", "file search should find matching files recursively");
|
|
786
|
+
|
|
787
|
+
const directorySearch = await request("127.0.0.1", `/api/files/search?tab=${encodeURIComponent(tabId)}&q=${encodeURIComponent("docs")}`);
|
|
788
|
+
assert.equal(directorySearch.status, 200, `file search endpoint should search directories: ${directorySearch.body?.error || ""}`);
|
|
789
|
+
assert.equal(directorySearch.body?.data?.entries?.find((entry) => entry.path === "files-fixture/docs")?.type, "directory", "file search should find matching directories");
|
|
790
|
+
|
|
791
|
+
const depthLimitedSearch = await request("127.0.0.1", `/api/files/search?tab=${encodeURIComponent(tabId)}&q=${encodeURIComponent("depth")}`);
|
|
792
|
+
assert.equal(depthLimitedSearch.status, 200, `file search endpoint should honor depth-limited recursive search: ${depthLimitedSearch.body?.error || ""}`);
|
|
793
|
+
assert.equal(depthLimitedSearch.body?.data?.maxDepth, 8, "file search should advertise the recursive depth cap");
|
|
794
|
+
assert.equal(depthLimitedSearch.body?.data?.entries?.find((entry) => entry.path === depthEightFileRelative)?.type, "file", "file search should find matching files at depth 8");
|
|
795
|
+
assert.equal(depthLimitedSearch.body?.data?.entries?.find((entry) => entry.path === depthEightDirectoryRelative)?.type, "directory", "file search should find matching directories at depth 8");
|
|
796
|
+
assert.equal(depthLimitedSearch.body?.data?.entries?.some((entry) => entry.path === depthNineFileRelative), false, "file search should not descend past depth 8");
|
|
797
|
+
|
|
798
|
+
const emptyFileSearch = await request("127.0.0.1", `/api/files/search?tab=${encodeURIComponent(tabId)}&q=`);
|
|
799
|
+
assert.equal(emptyFileSearch.status, 200, "empty file search should be accepted");
|
|
800
|
+
assert.deepEqual(emptyFileSearch.body?.data?.entries, [], "empty file search should not scan the workspace");
|
|
801
|
+
|
|
802
|
+
const textContent = await request("127.0.0.1", `/api/files/content?tab=${encodeURIComponent(tabId)}&path=${encodeURIComponent(viewerRelative)}`);
|
|
803
|
+
assert.equal(textContent.status, 200, `text file should open in WebUI: ${textContent.body?.error || ""}`);
|
|
804
|
+
assert.equal(textContent.body?.data?.content, "hello file viewer\nsecond line\n");
|
|
805
|
+
assert.equal(textContent.body?.data?.language, "text");
|
|
806
|
+
|
|
807
|
+
const markdownContent = await request("127.0.0.1", `/api/files/content?tab=${encodeURIComponent(tabId)}&path=${encodeURIComponent(markdownRelative)}`);
|
|
808
|
+
assert.equal(markdownContent.status, 200, `markdown file should open in WebUI: ${markdownContent.body?.error || ""}`);
|
|
809
|
+
assert.equal(markdownContent.body?.data?.language, "markdown", "markdown files should get markdown viewer support metadata");
|
|
810
|
+
|
|
811
|
+
const emptyDefaultOpen = await request("127.0.0.1", "/api/files/open-default", { method: "POST", body: { tab: tabId, path: "" } });
|
|
812
|
+
assert.equal(emptyDefaultOpen.status, 400, "default editor opens should reject empty paths instead of opening the workspace root");
|
|
813
|
+
assert.match(String(emptyDefaultOpen.body?.error || ""), /Path to open is required/i);
|
|
814
|
+
|
|
815
|
+
const defaultOpen = await request("127.0.0.1", "/api/files/open-default", { method: "POST", body: { tab: tabId, path: viewerRelative } });
|
|
816
|
+
assert.equal(defaultOpen.status, 200, `default editor should open the requested file: ${defaultOpen.body?.error || ""}`);
|
|
817
|
+
assert.equal(defaultOpen.body?.data?.path, viewerRelative, "default editor endpoint should report the requested file path");
|
|
818
|
+
const openedAbsolutePath = path.join(cwd, viewerRelative);
|
|
819
|
+
let openLog = "";
|
|
820
|
+
for (let attempt = 0; attempt < 20; attempt++) {
|
|
821
|
+
openLog = await readFile(openCommandLog, "utf8").catch(() => "");
|
|
822
|
+
if (openLog.includes(openedAbsolutePath)) break;
|
|
823
|
+
await delay(50);
|
|
824
|
+
}
|
|
825
|
+
assert.ok(openLog.includes(openedAbsolutePath), "default editor command should receive the currently opened file path");
|
|
826
|
+
|
|
827
|
+
if (process.platform === "linux") {
|
|
828
|
+
const fallbackOpen = await request("127.0.0.1", "/api/files/open-default", { method: "POST", body: { tab: tabId, path: noDefaultRelative } });
|
|
829
|
+
assert.equal(fallbackOpen.status, 200, `default editor should fall back to the .txt editor for unassociated files: ${fallbackOpen.body?.error || ""}`);
|
|
830
|
+
assert.equal(fallbackOpen.body?.data?.path, noDefaultRelative, "default editor fallback should report the requested file path");
|
|
831
|
+
assert.equal(fallbackOpen.body?.data?.fallbackToTextEditor, true, "unassociated files should be opened through the text/plain fallback");
|
|
832
|
+
assert.equal(fallbackOpen.body?.data?.desktopFile, "fake-text-editor.desktop", "fallback should use the text/plain desktop app association");
|
|
833
|
+
const fallbackAbsolutePath = path.join(cwd, noDefaultRelative);
|
|
834
|
+
for (let attempt = 0; attempt < 20; attempt++) {
|
|
835
|
+
openLog = await readFile(openCommandLog, "utf8").catch(() => "");
|
|
836
|
+
if (openLog.includes(`gio\tlaunch\tfake-text-editor.desktop\t${fallbackAbsolutePath}`)) break;
|
|
837
|
+
await delay(50);
|
|
838
|
+
}
|
|
839
|
+
assert.ok(openLog.includes(`gio\tlaunch\tfake-text-editor.desktop\t${fallbackAbsolutePath}`), "default editor fallback should invoke the text/plain editor for the requested file");
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
const savedFile = await request("127.0.0.1", "/api/files/content", {
|
|
843
|
+
method: "POST",
|
|
844
|
+
body: { tab: tabId, path: viewerRelative, content: "updated from WebUI\n", mtimeMs: textContent.body?.data?.mtimeMs },
|
|
845
|
+
});
|
|
846
|
+
assert.equal(savedFile.status, 200, `file save should succeed from localhost: ${savedFile.body?.error || ""}`);
|
|
847
|
+
assert.equal(await readFile(path.join(cwd, viewerRelative), "utf8"), "updated from WebUI\n", "file save endpoint should write UTF-8 text content");
|
|
848
|
+
|
|
849
|
+
const binaryContent = await request("127.0.0.1", `/api/files/content?tab=${encodeURIComponent(tabId)}&path=${encodeURIComponent(binaryRelative)}`);
|
|
850
|
+
assert.equal(binaryContent.status, 415, "binary files should be rejected by the WebUI file viewer");
|
|
851
|
+
assert.match(String(binaryContent.body?.error || ""), /binary/i);
|
|
852
|
+
|
|
853
|
+
const oversizedContent = await request("127.0.0.1", `/api/files/content?tab=${encodeURIComponent(tabId)}&path=${encodeURIComponent(largeRelative)}`);
|
|
854
|
+
assert.equal(oversizedContent.status, 413, "oversized files should be rejected by the WebUI file viewer");
|
|
855
|
+
assert.match(String(oversizedContent.body?.error || ""), /too large/i);
|
|
856
|
+
|
|
857
|
+
const outsideRoot = await mkdtemp(path.join(tmpdir(), "pi-webui-files-outside-"));
|
|
858
|
+
try {
|
|
859
|
+
const outsideFile = path.join(outsideRoot, "outside.txt");
|
|
860
|
+
await writeFile(outsideFile, "outside\n", "utf8");
|
|
861
|
+
const outsideAbsolute = await request("127.0.0.1", `/api/files/content?tab=${encodeURIComponent(tabId)}&path=${encodeURIComponent(outsideFile)}`);
|
|
862
|
+
assert.equal(outsideAbsolute.status, 403, "absolute paths outside the active tab cwd should be rejected");
|
|
863
|
+
assert.match(String(outsideAbsolute.body?.error || ""), /active tab working directory/i);
|
|
864
|
+
|
|
865
|
+
const symlinkPath = path.join(filesRoot, "outside-link.txt");
|
|
866
|
+
try {
|
|
867
|
+
await symlink(outsideFile, symlinkPath);
|
|
868
|
+
const symlinkEscape = await request("127.0.0.1", `/api/files/content?tab=${encodeURIComponent(tabId)}&path=${encodeURIComponent("files-fixture/outside-link.txt")}`);
|
|
869
|
+
assert.equal(symlinkEscape.status, 403, "symlinks resolving outside the active tab cwd should be rejected");
|
|
870
|
+
assert.match(String(symlinkEscape.body?.error || ""), /escapes the active tab working directory/i);
|
|
871
|
+
} catch (error) {
|
|
872
|
+
if (!["EPERM", "EACCES", "EINVAL", "ENOTSUP"].includes(error?.code)) throw error;
|
|
873
|
+
console.log(`http-endpoints-harness: symlink unavailable (${error.code}); skipping file symlink confinement check`);
|
|
874
|
+
}
|
|
875
|
+
} finally {
|
|
876
|
+
await rmWithRetry(outsideRoot);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
const filesTab = await request("127.0.0.1", "/api/tabs", { method: "POST", body: { cwd: filesRoot, title: "files-fixture" } });
|
|
880
|
+
assert.equal(filesTab.status, 201, `file fixture tab should open: ${filesTab.body?.error || ""}`);
|
|
881
|
+
const filesTabId = filesTab.body?.data?.tab?.id;
|
|
882
|
+
assert.ok(filesTabId, "file fixture tab should have an id");
|
|
883
|
+
const scopedFileContent = await request("127.0.0.1", `/api/files/content?tab=${encodeURIComponent(filesTabId)}&path=${encodeURIComponent("viewer.txt")}`);
|
|
884
|
+
assert.equal(scopedFileContent.status, 200, "file paths should resolve against the requested tab cwd");
|
|
885
|
+
const wrongTabContent = await request("127.0.0.1", `/api/files/content?tab=${encodeURIComponent(tabId)}&path=${encodeURIComponent("viewer.txt")}`);
|
|
886
|
+
assert.equal(wrongTabContent.status, 404, "file paths should not bleed across tab cwd scopes");
|
|
887
|
+
const closeFilesTab = await request("127.0.0.1", "/api/tabs/close", { method: "POST", body: { ids: [filesTabId] }, timeoutMs: 10_000 });
|
|
888
|
+
assert.equal(closeFilesTab.status, 200, "file fixture tab should close after scoped file checks");
|
|
889
|
+
|
|
697
890
|
// Natural Conversation shell: /talk availability drives per-tab status and safety guards.
|
|
698
891
|
const conversationFeature = await request("127.0.0.1", `/api/features/natural-conversation?tab=${encodeURIComponent(tabId)}`);
|
|
699
892
|
assert.equal(conversationFeature.status, 200);
|
|
@@ -738,6 +931,10 @@ try {
|
|
|
738
931
|
assert.equal(blockedBash.status, 409, "user bash should be blocked while Natural Conversation is active");
|
|
739
932
|
assert.match(String(blockedBash.body?.error || ""), /bash is blocked|Natural Conversation Mode is active/);
|
|
740
933
|
|
|
934
|
+
const blockedFileSave = await request("127.0.0.1", "/api/files/content", { method: "POST", body: { tab: tabId, path: viewerRelative, content: "blocked by conversation mode\n" } });
|
|
935
|
+
assert.equal(blockedFileSave.status, 409, "file edits should be blocked while Natural Conversation is active");
|
|
936
|
+
assert.equal(blockedFileSave.body?.error, "file edits are blocked");
|
|
937
|
+
|
|
741
938
|
const allowedConversationPrompt = await request("127.0.0.1", "/api/prompt", { method: "POST", body: { message: "Explain the current repo briefly", tab: tabId } });
|
|
742
939
|
assert.equal(allowedConversationPrompt.status, 200, "ordinary prompts remain allowed while Natural Conversation is active");
|
|
743
940
|
|
|
@@ -816,6 +1013,18 @@ try {
|
|
|
816
1013
|
});
|
|
817
1014
|
assert.equal(remoteDelete.status, 403, "session delete must be localhost-only");
|
|
818
1015
|
|
|
1016
|
+
const remoteFileSave = await request(lan, "/api/files/content", {
|
|
1017
|
+
method: "POST",
|
|
1018
|
+
body: { tab: tabId, path: viewerRelative, content: "remote save should be blocked\n" },
|
|
1019
|
+
});
|
|
1020
|
+
assert.equal(remoteFileSave.status, 403, "file saves must be localhost-only");
|
|
1021
|
+
|
|
1022
|
+
const remoteFileOpenDefault = await request(lan, "/api/files/open-default", {
|
|
1023
|
+
method: "POST",
|
|
1024
|
+
body: { tab: tabId, path: viewerRelative },
|
|
1025
|
+
});
|
|
1026
|
+
assert.equal(remoteFileOpenDefault.status, 403, "opening files in the default editor must be localhost-only");
|
|
1027
|
+
|
|
819
1028
|
const remoteExport = await request(lan, "/api/prompt", {
|
|
820
1029
|
method: "POST",
|
|
821
1030
|
body: { message: "/export", tab: tabId },
|
|
@@ -903,6 +1112,7 @@ try {
|
|
|
903
1112
|
}
|
|
904
1113
|
await new Promise((resolve) => voiceProvider.close(() => resolve()));
|
|
905
1114
|
await rmWithRetry(cwd);
|
|
1115
|
+
await rmWithRetry(harnessSideEffectsRoot);
|
|
906
1116
|
}
|
|
907
1117
|
|
|
908
1118
|
console.log("http-endpoints-harness.test.mjs passed");
|