paseo-plugin-genui 0.1.0 → 0.1.2

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.
@@ -1,4 +1,7 @@
1
+ import { mkdir, rm, symlink, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
1
3
  import { describe, expect, it } from "vitest";
4
+ import type { PaseoApi } from "@getpaseo/client";
2
5
  import {
3
6
  collectLoads,
4
7
  compile,
@@ -16,7 +19,14 @@ import {
16
19
  UI_REFERENCE_MORE,
17
20
  } from "./instructions";
18
21
  import { splitTimelineMessage } from "./segment";
19
- import { listGallery, loadGalleryFile, readGallerySpec } from "../server/data-source";
22
+ import {
23
+ listGallery,
24
+ loadAgentAudio,
25
+ loadAgentFile,
26
+ loadAgentImage,
27
+ loadGalleryFile,
28
+ readGallerySpec,
29
+ } from "../server/data-source";
20
30
 
21
31
  describe("paseo-plugin-genui core, instructions, and gallery", () => {
22
32
  it("compiles every example in the agent instructions cleanly", () => {
@@ -119,4 +129,54 @@ describe("paseo-plugin-genui core, instructions, and gallery", () => {
119
129
  expect(valid.ok).toBe(true);
120
130
  expect(valid.report).toContain("No errors.");
121
131
  });
132
+
133
+ it("refuses symlinks and intermediate directory links escaping the workspace root across data, image, and audio reads", async () => {
134
+ const testRoot = path.join("/tmp/opencode", `genui-symlink-test-${Date.now()}`);
135
+ const workspace = path.join(testRoot, "workspace");
136
+ const outside = path.join(testRoot, "outside");
137
+ await mkdir(workspace, { recursive: true });
138
+ await mkdir(outside, { recursive: true });
139
+
140
+ try {
141
+ const secretTxt = path.join(outside, "secret.txt");
142
+ const secretPng = path.join(outside, "secret.png");
143
+ const secretWav = path.join(outside, "secret.wav");
144
+ const insideTxt = path.join(workspace, "allowed.txt");
145
+ await writeFile(secretTxt, "top-secret-outside-line\n", "utf8");
146
+ await writeFile(secretPng, Buffer.from([0x89, 0x50, 0x4e, 0x47]));
147
+ await writeFile(secretWav, Buffer.from("RIFF0000WAVEfmt "));
148
+ await writeFile(insideTxt, "inside-workspace-line\n", "utf8");
149
+
150
+ await symlink(secretTxt, path.join(workspace, "report.txt"));
151
+ await symlink(secretPng, path.join(workspace, "report.png"));
152
+ await symlink(secretWav, path.join(workspace, "report.wav"));
153
+ await symlink(outside, path.join(workspace, "linked-dir"));
154
+
155
+ const mockPaseo = {
156
+ agents: {
157
+ ref: () => ({
158
+ current: () => ({ cwd: workspace }),
159
+ refresh: async () => ({ agent: { cwd: workspace }, project: null }),
160
+ }),
161
+ },
162
+ } as unknown as PaseoApi;
163
+
164
+ const allowed = await loadAgentFile(mockPaseo, "agent_symlink_test", "allowed.txt", { raw: true });
165
+ expect(allowed).toEqual({ ok: true, value: "inside-workspace-line\n" });
166
+
167
+ const directSymlink = await loadAgentFile(mockPaseo, "agent_symlink_test", "report.txt", { raw: true });
168
+ expect(directSymlink.ok).toBe(false);
169
+
170
+ const dirSymlink = await loadAgentFile(mockPaseo, "agent_symlink_test", "linked-dir/secret.txt", { raw: true });
171
+ expect(dirSymlink.ok).toBe(false);
172
+
173
+ const imageSymlink = await loadAgentImage(mockPaseo, "agent_symlink_test", "report.png");
174
+ expect(imageSymlink.ok).toBe(false);
175
+
176
+ const audioSymlink = await loadAgentAudio(mockPaseo, "agent_symlink_test", "report.wav");
177
+ expect(audioSymlink.ok).toBe(false);
178
+ } finally {
179
+ await rm(testRoot, { recursive: true, force: true });
180
+ }
181
+ });
122
182
  });
@@ -0,0 +1,41 @@
1
+ import { readdirSync, readFileSync, statSync } from "node:fs";
2
+ import path from "node:path";
3
+ import ts from "typescript";
4
+ import { describe, expect, it } from "vitest";
5
+
6
+ const root = path.resolve(__dirname, "..");
7
+
8
+ function sourceFiles(dir: string): string[] {
9
+ return readdirSync(dir).flatMap((name) => {
10
+ const full = path.join(dir, name);
11
+ if (statSync(full).isDirectory()) return sourceFiles(full);
12
+ return /\.[cm]?tsx?$/.test(name) && !/\.test\.tsx?$/.test(name) && !name.endsWith(".d.ts") ? [full] : [];
13
+ });
14
+ }
15
+
16
+ function classesIn(file: string): string[] {
17
+ const sf = ts.createSourceFile(file, readFileSync(file, "utf8"), ts.ScriptTarget.ES2022, true);
18
+ const found: string[] = [];
19
+ const visit = (node: ts.Node): void => {
20
+ if (ts.isClassDeclaration(node) || ts.isClassExpression(node)) {
21
+ const { line } = sf.getLineAndCharacterOfPosition(node.getStart(sf));
22
+ found.push(`${path.relative(root, file)}:${line + 1}`);
23
+ }
24
+ ts.forEachChild(node, visit);
25
+ };
26
+ visit(sf);
27
+ return found;
28
+ }
29
+
30
+ describe("Hermes compatibility", () => {
31
+ // Hermes (React Native) has no `class` syntax, and Paseo compiles plugin client
32
+ // bundles for es2020, so `class` would reach it. server/ runs in Node and may use it.
33
+ it("keeps `class` out of client and shared code; use defineClass", () => {
34
+ const files = [
35
+ ...sourceFiles(path.join(root, "client")),
36
+ ...sourceFiles(path.join(root, "shared")),
37
+ path.join(root, "index.client.tsx"),
38
+ ];
39
+ expect(files.flatMap(classesIn)).toEqual([]);
40
+ });
41
+ });