From 37df67256e7eedc1050f186bcf401dc376cb5e71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A5=87?= <16399091+binaricat@users.noreply.github.com> Date: Mon, 26 Oct 2026 17:39:17 +0000 Subject: [PATCH] feat(examples): prepare fixed public Rfam acceptance candidate --- .github/workflows/test.yml | 1 + docs/plugin-platform/byte-stream-native-qa.md | 40 +++++++--- .../late-transport-integration.md | 14 ++++ .../plugins/database-minimal/protocol.mjs | 16 +++- .../database-minimal/protocol.test.cjs | 57 ++++++++++++++ .../plugins/database-rfam-readonly/README.md | 77 +++++++++++++++++++ .../plugins/database-rfam-readonly/browser.js | 34 ++++++++ .../netcatty.plugin.json | 26 +++++++ .../plugins/database-rfam-readonly/panel.css | 1 + .../plugins/database-rfam-readonly/panel.html | 9 +++ .../plugins/database-rfam-readonly/panel.js | 28 +++++++ .../database-rfam-readonly/prepare.mjs | 31 ++++++++ .../database-rfam-readonly/prepare.test.cjs | 15 ++++ package.json | 1 + 14 files changed, 338 insertions(+), 12 deletions(-) create mode 100644 examples/plugins/database-minimal/protocol.test.cjs create mode 100644 examples/plugins/database-rfam-readonly/README.md create mode 100644 examples/plugins/database-rfam-readonly/browser.js create mode 100644 examples/plugins/database-rfam-readonly/netcatty.plugin.json create mode 100644 examples/plugins/database-rfam-readonly/panel.css create mode 100644 examples/plugins/database-rfam-readonly/panel.html create mode 100644 examples/plugins/database-rfam-readonly/panel.js create mode 100644 examples/plugins/database-rfam-readonly/prepare.mjs create mode 100644 examples/plugins/database-rfam-readonly/prepare.test.cjs diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8f8637936..624536106 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -53,6 +53,7 @@ jobs: run: | npm run check:plugin-contract npm run test:plugin-runtime + npm run test:plugin-examples node --test --import tsx components/settings/tabs/Plugin*.test.tsx - name: Test diff --git a/docs/plugin-platform/byte-stream-native-qa.md b/docs/plugin-platform/byte-stream-native-qa.md index 856bbe048..178a13a24 100644 --- a/docs/plugin-platform/byte-stream-native-qa.md +++ b/docs/plugin-platform/byte-stream-native-qa.md @@ -20,6 +20,15 @@ existing permitted network path. Do not install new software or create local forwarding exceptions as part of this recipe. If no fixture is available, record the database pass as pending. +There is also a separately labeled +[public Rfam candidate](../../examples/plugins/database-rfam-readonly/README.md). +It fixes one public hostname, public account, database, and `SELECT 1 AS value`. +It has only been prepared and checked offline. The parent must obtain exact +package and endpoint authorization before any install, permission activation, +or connection. Its authentication and TLS requirements remain unverified. This +candidate does not replace the owned fixture regression or prove that the GUI +can reach the coding container's private database. + The registered automated fixture uses `mariadb:11.4@sha256:250e1609e93c0e6aecf64bfbab2d84d5e89d2481540fe77447ff6c855c3b1873`. It runs on an internal Docker network, publishes no host ports, generates a @@ -30,8 +39,9 @@ executor with that recognized image, run: NETCATTY_BYTE_STREAM_DATABASE_TEST=1 node --test examples/plugins/database-minimal/protocol.live.test.cjs ``` -That test exercises the protocol and broker. It does not install the plugin or -prove native GUI behavior. For the GUI fixture, have its operator create only +That test exercises the protocol, broker, and installed package's SDK/RPC path +in a Node harness. It does not prove native GUI behavior. For the GUI fixture, +have its operator create only synthetic data and a dedicated SELECT-only account. Run this SQL using the fixture's administration channel, replacing the password placeholder with a fresh disposable password that is never included in screenshots or logs: @@ -56,6 +66,7 @@ Use Node 22 or later and the lockfile. Run these commands in sequence: npm ci npm run test:plugin-runtime npm run test:plugin-contract +npm run test:plugin-examples npm run generate:plugin-contract npm run check:plugin-contract npm run generate:capability-tools @@ -76,8 +87,11 @@ sha256sum /tmp/database-example.ncpkg ``` The two five-file packages built on Node 24.19.0 with the locked dependencies -match byte for byte. Their SHA-256 is -`88c1428343ef724b42a3b867a2d7645fb2b02c26e815ba5b9890e4c30dbc1af4`. +match byte for byte. The current owned-fixture package SHA-256 is +`588cb6766616c2f3057c7c8df1c20dbac947e0d5e9d01b2a928c7581b00a69c5`. +The earlier `6a4fb178` package used hash `88c14283…dbc1af4`. The example-only +protocol now has separate fixed owned-fixture and Rfam entrypoints; the owned +fixture database, query, and opt-in live regression are retained. The six-file assistant package retains SHA-256 `8ef162d13d0a16878fb817462759c9221352d0565dcefebeb102ea3575a918e8`. @@ -133,17 +147,17 @@ The integration executor completed these checks in order on 2026-10-26: | Check | Result | | --- | --- | -| `npm run test:plugin-runtime` | 624 tests: 622 passed, 2 skipped, 0 failed | -| `npm run test:plugin-contract` | 88 passed, 0 skipped, 0 failed | +| `npm run test:plugin-runtime` | 627 tests: 626 passed, 1 native skip, 0 failed | +| `npm run test:plugin-contract` | 90 passed, 0 skipped, 0 failed | +| `npm run test:plugin-examples` | 4 passed, 1 opt-in Docker skip, 0 failed | | Plugin contract generate and drift check | Passed, no generated changes | | Capability tool generation and drift check | Passed, no generated changes | | Codex App Server schema check | Passed | | `npm run lint` | Passed, 0 errors and 7 warnings outside the transport changes | -| `npm run build` | Passed, Vite production build completed in 32 seconds | +| `npm run build` | Passed, Vite production build completed in 40.23 seconds | | Database repeat packaging and both package validations | Passed | -These totals describe the original integrated head `6a4fb178`. The late -transport merge moves the opt-in database test into the example directory. +The late transport merge moves the opt-in database test into the example directory. Run its panel and protocol tests explicitly with `node --test examples/plugins/database-minimal/*.test.cjs`. The database test still requires explicit opt-in and the native Electron suite remains separate. @@ -152,3 +166,11 @@ is not cached. No image was installed and no new live database run is claimed. Native GUI acceptance remains pending on the occupied desktop. Full repository tests and platform packages run in the integration PR's exact-head CI. Record their final workflow conclusions separately from these local results. + +After the late transport merge and Rfam candidate preparation, the registered +runtime suite has 626 passed and one native skip, contract/SDK/CLI has 90 passed, +and `npm run test:plugin-examples` has four passed and one Docker skip. The +example suite is now registered in CI. Public protocol checks use only synthetic +packet bytes and package preparation; no Rfam connection or permission was +activated. Final CI belongs to the current #3993 head, not the older `6a4fb178` +head whose two workflows already succeeded. diff --git a/docs/plugin-platform/late-transport-integration.md b/docs/plugin-platform/late-transport-integration.md index d6d83cc4e..dfae8c0d8 100644 --- a/docs/plugin-platform/late-transport-integration.md +++ b/docs/plugin-platform/late-transport-integration.md @@ -54,3 +54,17 @@ AI wiring status nor their environment-specific broad-test failures replace the connected implementation and exact-head CI evidence on #3993. No main merge, force-push, endpoint-policy relaxation, AI internal review retry, or release is part of this reconciliation. + +## Check the reconciled source + +The merged transport source passed 627 registered runtime tests: 626 passed and +one native Electron test skipped. Contract/SDK/CLI tests passed 90 of 90. The +example panel passed; its opt-in database test remained skipped. The late attach +regression failed against the old #3993 service with two cancel calls instead +of one, then passed after the merge. + +A subsequent example-only Rfam candidate reuses the limited browser protocol +through two fixed entrypoints. Its offline tests check the original owned +fixture database/query and the fixed public database/query, plus rejection of +an unsupported auth plugin. No general query API is exported and no host +database code is introduced. The owned MariaDB live regression remains opt-in. diff --git a/examples/plugins/database-minimal/protocol.mjs b/examples/plugins/database-minimal/protocol.mjs index 1ebe41941..ffeb262bf 100644 --- a/examples/plugins/database-minimal/protocol.mjs +++ b/examples/plugins/database-minimal/protocol.mjs @@ -128,7 +128,7 @@ function greeting(bytes) { } /** stream is a plugin-owned browser adapter over the generic host byte stream. */ -export async function queryExample(stream, username, sessionPassword) { +async function queryFixedExample(stream, username, sessionPassword, database, query) { if (!/^[A-Za-z0-9_]{1,32}$/u.test(username) || typeof sessionPassword !== "string" || sessionPassword.length > 256) { throw new Error("Enter the disposable fixture username and session password"); } @@ -139,10 +139,10 @@ export async function queryExample(stream, username, sessionPassword) { sessionPassword = ""; try { await packets.write(concat(uint32(CLIENT_FLAGS), uint32(MAX_PACKET), Uint8Array.of(45), new Uint8Array(23), - zeroText(username), Uint8Array.of(token.length), token, zeroText("plugin_demo"), zeroText("mysql_native_password")), 1); + zeroText(username), Uint8Array.of(token.length), token, zeroText(database), zeroText("mysql_native_password")), 1); } finally { token.fill(0); nonce.fill(0); } if ((await packets.read(2))[0] !== 0) reject(); - await packets.write(concat(Uint8Array.of(3), encoder.encode(READ_QUERY)), 0); + await packets.write(concat(Uint8Array.of(3), encoder.encode(query)), 0); const count = await packets.read(1); if (count.length !== 1 || count[0] !== 1) reject(); const column = new Cursor(await packets.read(2)); @@ -161,3 +161,13 @@ export async function queryExample(stream, username, sessionPassword) { await stream.close(); } } + +export function queryExample(stream, username, sessionPassword) { + return queryFixedExample(stream, username, sessionPassword, "plugin_demo", READ_QUERY); +} + +// This second fixed profile is a public third-party acceptance candidate. +// No caller can supply a database, query, username, or password to this entry. +export function queryRfamReadOnly(stream) { + return queryFixedExample(stream, "rfamro", "", "Rfam", "SELECT 1 AS value"); +} diff --git a/examples/plugins/database-minimal/protocol.test.cjs b/examples/plugins/database-minimal/protocol.test.cjs new file mode 100644 index 000000000..16a555488 --- /dev/null +++ b/examples/plugins/database-minimal/protocol.test.cjs @@ -0,0 +1,57 @@ +"use strict"; + +const assert = require("node:assert/strict"); +const { Buffer } = require("node:buffer"); +const test = require("node:test"); + +function bytes(...parts) { return Buffer.concat(parts.map((part) => Buffer.from(part))); } +function text(value) { return bytes(Buffer.from(value), [0]); } +function packet(sequence, payload) { return bytes([payload.length & 255, payload.length >>> 8, 0, sequence], payload); } +function greeting(plugin = "mysql_native_password") { + const flags = 1 | 4 | 8 | 0x200 | 0x2000 | 0x8000 | 0x80000; + return bytes([10], text("synthetic-offline-server"), [1, 0, 0, 0], new Uint8Array(8).fill(1), + [0, flags & 255, (flags >>> 8) & 255, 45, 0, 0, (flags >>> 16) & 255, (flags >>> 24) & 255, 21], + new Uint8Array(10), new Uint8Array(12).fill(2), [0], text(plugin)); +} +function streamFixture(plugin) { + const column = bytes(...["def", "synthetic", "", "", "value"].map((value) => bytes([value.length], Buffer.from(value)))); + const eof = [0xfe, 0, 0, 2, 0]; + let pending = bytes(packet(0, greeting(plugin)), packet(2, [0]), packet(1, [1]), + packet(2, column), packet(3, eof), packet(4, [1, 49]), packet(5, eof)); + const writes = []; + let closes = 0; + return { + writes, get closes() { return closes; }, + stream: { + async read() { const value = pending; pending = null; return value; }, + async write(value) { writes.push(Buffer.from(value)); }, + async close() { closes++; }, + }, + }; +} + +test("owned fixture and public Rfam entries each send only their fixed database and query offline", async () => { + const { queryExample, queryRfamReadOnly, READ_QUERY } = await import("./protocol.mjs"); + for (const profile of [ + { run: (stream) => queryExample(stream, "plugin_demo", ""), user: "plugin_demo", database: "plugin_demo", query: READ_QUERY }, + { run: queryRfamReadOnly, user: "rfamro", database: "Rfam", query: "SELECT 1 AS value" }, + ]) { + const f = streamFixture(); + assert.deepEqual(await profile.run(f.stream), { columns: ["value"], rows: [["1"]] }); + assert.equal(f.writes.length, 2); + const response = f.writes[0].subarray(4); + const expectedTail = bytes(text(profile.user), [0], text(profile.database), text("mysql_native_password")); + assert.deepEqual(response.subarray(32), expectedTail); + assert.equal(f.writes[1][4], 3); + assert.equal(f.writes[1].subarray(5).toString(), profile.query); + assert.equal(f.closes, 1); + } +}); + +test("public profile rejects unsupported authentication offline without a fallback", async () => { + const { queryRfamReadOnly } = await import("./protocol.mjs"); + const f = streamFixture("caching_sha2_password"); + await assert.rejects(queryRfamReadOnly(f.stream), /Unsupported or invalid/u); + assert.equal(f.writes.length, 0); + assert.equal(f.closes, 1); +}); diff --git a/examples/plugins/database-rfam-readonly/README.md b/examples/plugins/database-rfam-readonly/README.md new file mode 100644 index 000000000..00d07269a --- /dev/null +++ b/examples/plugins/database-rfam-readonly/README.md @@ -0,0 +1,77 @@ +# Prepare the public Rfam read-only acceptance sample + +This is a public third-party acceptance candidate, separate from the owned +MariaDB fixture. It uses the existing generic byte-stream capability. No host +database business, server-specific production API, or endpoint-policy exception +is added. + +[Rfam's official database documentation](https://docs.rfam.org/en/latest/database.html) +lists `mysql-rfam-public.ebi.ac.uk:4497`, database `Rfam`, public user `rfamro`, +and no password. The sample sends only `SELECT 1 AS value`. It does not read Rfam +tables and offers no query, host, database, or credential input. The documented +public account name is compiled into the example. No private credential is used +or persisted, and the sample has no storage or secret permission. + +## Build the candidate without connecting + +Use the integration head and locked dependencies: + +```sh +npm run build:plugin-runtime-deps +node examples/plugins/database-rfam-readonly/prepare.mjs tcp://mysql-rfam-public.ebi.ac.uk:4497 /tmp/database-rfam-readonly.ncpkg +node packages/plugin-cli/dist/cli.js validate /tmp/database-rfam-readonly.ncpkg +sha256sum /tmp/database-rfam-readonly.ncpkg +``` + +The separate preparation command accepts only that exact endpoint. It performs +no DNS lookup, connection, query, plugin installation, or permission activation. +It creates five files: a manifest, browser bundle, and three panel assets. +The owned fixture's preparation command still rejects public hostnames. + +Package identity and permission scope: + +- ID: `com.netcatty.database-rfam-readonly`, version `0.1.0`. +- Runtime: browser only. Required feature: `network.byte-streams`. +- Required permissions: `commands` and `views` for its own callbacks and panel. +- Optional permission: `network.stream`, resource exactly + `tcp://mysql-rfam-public.ebi.ac.uk:4497`. +- Five-file package: 11,003 bytes. Two builds matched byte for byte with SHA-256 + `a9d56b69a4d2c587a4712d1b2fe395c381bcf8b15e34d476c4ba8b5ca967c35a`. +- Expected result after a separately authorized compatible run: + `{"columns":["value"],"rows":[["1"]]}`. + +## Obtain authorization before native acceptance + +Record the exact integration commit, package hash, ID, version, and permissions. +The parent must obtain authorization for that specific package and public +endpoint before installation, enabling permissions, or querying the service. +No connection or query has been performed as part of preparing this candidate. + +After authorization, use the available native desktop and a disposable profile. +Record the local-import source, exact endpoint prompt, denial, retry, fixed +result, cancellation, and post-revocation recovery. Opening the panel only reads +its endpoint metadata. A connection starts only from **Run fixed public query**. +Do not treat this public service as an isolated synthetic fixture or evidence of +database TLS or native sandbox certification. + +## Stop if the protocol is unsupported + +The reused example protocol supports only protocol 4.1 and +`mysql_native_password`. It uses plain TCP and does not implement MySQL STARTTLS, +auth-plugin switching, or other authentication methods. The service's current +authentication and TLS requirements remain unverified. An unsupported greeting +or server rejection fails closed and closes the byte stream. Record a sanitized +failure and stop. Do not add an authentication fallback or TLS bypass for QA. + +Offline protocol tests inspect synthetic packet bytes for the two fixed +profiles and reject an unsupported auth plugin. They do not contact Rfam or +activate plugin permissions: + +```sh +npm run test:plugin-examples +``` + +The owned MariaDB regression remains at +`examples/plugins/database-minimal/protocol.live.test.cjs`. Its explicit Docker +opt-in, isolated network, temporary account, SELECT result, and server-side write +denial remain separate from this public-service candidate. diff --git a/examples/plugins/database-rfam-readonly/browser.js b/examples/plugins/database-rfam-readonly/browser.js new file mode 100644 index 000000000..f7d7769f3 --- /dev/null +++ b/examples/plugins/database-rfam-readonly/browser.js @@ -0,0 +1,34 @@ +import { CancellationTokenSource } from "@netcatty/plugin-sdk"; +import { queryRfamReadOnly } from "../database-minimal/protocol.mjs"; + +const endpoint = "tcp://mysql-rfam-public.ebi.ac.uk:4497"; +export default { + activate(context) { + let pending; + const register = (suffix, handler) => context.subscriptions.add(context.commands.registerCommand( + `com.netcatty.database-rfam-readonly.${suffix}`, handler, + )); + const cancel = () => { pending?.cancel(); return { cancelled: true }; }; + register("cancel", cancel); + register("endpoint", () => ({ endpoint })); + context.subscriptions.add({ dispose: cancel }); + register("query", async (args) => { + if (args !== undefined && args !== null) throw new Error("The public sample accepts no query or credential parameters"); + if (pending) throw new Error("A public sample request is already active"); + const cancellation = new CancellationTokenSource(); + pending = cancellation; + let connection; + try { + connection = await context.network.connect({ endpoint }, cancellation.token); + return await queryRfamReadOnly({ + read: () => connection.readable.read(), write: (bytes) => connection.writable.write(bytes), + close: () => connection.close(), + }); + } finally { + await connection?.close().catch(() => {}); + cancellation.dispose(); + pending = undefined; + } + }); + }, +}; diff --git a/examples/plugins/database-rfam-readonly/netcatty.plugin.json b/examples/plugins/database-rfam-readonly/netcatty.plugin.json new file mode 100644 index 000000000..c403822dd --- /dev/null +++ b/examples/plugins/database-rfam-readonly/netcatty.plugin.json @@ -0,0 +1,26 @@ +{ + "manifestVersion": 1, + "id": "com.netcatty.database-rfam-readonly", + "name": "database-rfam-readonly", + "displayName": "Rfam public read-only acceptance sample", + "description": "Public third-party sample: one fixed SELECT 1 through an exact approved byte-stream endpoint. Compatibility is unverified.", + "version": "0.1.0", + "publisher": "netcatty", + "license": "GPL-3.0-or-later", + "engines": { "netcatty": ">=0.0.0", "api": ">=0.1.0-internal.1 <0.2.0" }, + "features": { "required": ["network.byte-streams"] }, + "main": { "browser": "browser.js" }, + "activationEvents": ["onCommand:com.netcatty.database-rfam-readonly.query", "onView:com.netcatty.database-rfam-readonly.panel"], + "permissions": { + "required": ["commands", "views"], + "optional": [{ "permission": "network.stream", "resources": ["tcp://mysql-rfam-public.ebi.ac.uk:4497"], "reason": "Run the fixed public Rfam acceptance query only after explicit authorization." }] + }, + "contributes": { + "commands": [ + { "id": "com.netcatty.database-rfam-readonly.query", "title": "Run public Rfam SELECT 1" }, + { "id": "com.netcatty.database-rfam-readonly.cancel", "title": "Cancel public Rfam sample" }, + { "id": "com.netcatty.database-rfam-readonly.endpoint", "title": "Show public Rfam endpoint" } + ], + "views": [{ "id": "com.netcatty.database-rfam-readonly.panel", "title": "Rfam public read-only sample", "location": "modal", "entry": "panel.html" }] + } +} diff --git a/examples/plugins/database-rfam-readonly/panel.css b/examples/plugins/database-rfam-readonly/panel.css new file mode 100644 index 000000000..9cffda0a6 --- /dev/null +++ b/examples/plugins/database-rfam-readonly/panel.css @@ -0,0 +1 @@ +:root{color-scheme:dark light;font:14px system-ui,sans-serif;color:hsl(var(--foreground,210 20% 90%));background:hsl(var(--background,220 15% 12%))}*{box-sizing:border-box}body{margin:0}main{max-width:640px;padding:24px;margin:auto}h1{font-size:24px}.eyebrow{font-size:11px;letter-spacing:.1em;opacity:.7}p{line-height:1.5}#endpoint,pre{overflow-wrap:anywhere;white-space:pre-wrap}label{display:block;margin:16px 0 6px}input{width:100%;padding:10px;border:1px solid hsl(var(--border,220 10% 35%));border-radius:6px;background:hsl(var(--background,220 15% 12%));color:inherit}.actions{display:flex;flex-wrap:wrap;gap:10px;margin:20px 0}button{padding:10px 16px;border:1px solid hsl(var(--border,220 10% 35%));border-radius:6px;color:inherit;background:hsl(var(--secondary,220 12% 22%));cursor:pointer}button:disabled{opacity:.5;cursor:default}input:focus-visible,button:focus-visible{outline:2px solid hsl(var(--primary,210 90% 60%));outline-offset:2px}pre{padding:14px;border:1px solid hsl(var(--border,220 10% 35%));border-radius:6px;min-height:80px} diff --git a/examples/plugins/database-rfam-readonly/panel.html b/examples/plugins/database-rfam-readonly/panel.html new file mode 100644 index 000000000..92cb089b9 --- /dev/null +++ b/examples/plugins/database-rfam-readonly/panel.html @@ -0,0 +1,9 @@ + +Rfam public read-only sample +

PUBLIC THIRD-PARTY ACCEPTANCE SAMPLE

Rfam: SELECT 1

+

This contacts Rfam's public read-only MySQL service. It is not an isolated fixture. The fixed query is SELECT 1 AS value in Rfam, using the documented public account with no password.

+

This sample uses plain TCP. Authentication and TLS compatibility remain unverified. Run only after the package and exact endpoint are authorized.

+

Loading exact endpoint…

+
+
Prepared only. No connection starts until you click Run.
+
diff --git a/examples/plugins/database-rfam-readonly/panel.js b/examples/plugins/database-rfam-readonly/panel.js new file mode 100644 index 000000000..b84405d20 --- /dev/null +++ b/examples/plugins/database-rfam-readonly/panel.js @@ -0,0 +1,28 @@ +/* global window, document */ +"use strict"; +const query = document.getElementById("query"); +const cancel = document.getElementById("cancel"); +const result = document.getElementById("result"); +const command = (suffix) => window.netcattyView.executeCommand(`com.netcatty.database-rfam-readonly.${suffix}`); +window.netcattyView.onDidChangeEnvironment((environment) => { + document.documentElement.style.colorScheme = environment.theme === "light" ? "light" : "dark"; + for (const name of ["--background", "--foreground", "--muted", "--muted-foreground", "--border", "--primary", "--primary-foreground"]) { + const value = environment.themeTokens?.[name]; + if (typeof value === "string" && value.length <= 96) document.documentElement.style.setProperty(name, value); + else document.documentElement.style.removeProperty(name); + } +}); +void command("endpoint").then((value) => { document.getElementById("endpoint").textContent = value.endpoint; }); +query.addEventListener("click", async () => { + query.disabled = true; + cancel.disabled = false; + result.textContent = "Requesting the exact public endpoint…"; + try { result.textContent = JSON.stringify(await command("query"), null, 2); } + catch { result.textContent = "Public sample failed. Authentication, TLS requirements, and service reachability may be unsupported. No fallback is attempted."; } + finally { query.disabled = false; cancel.disabled = true; } +}); +cancel.addEventListener("click", async () => { + cancel.disabled = true; + try { await command("cancel"); result.textContent = "Public sample cancelled."; } + catch { result.textContent = "Could not cancel the public sample."; } +}); diff --git a/examples/plugins/database-rfam-readonly/prepare.mjs b/examples/plugins/database-rfam-readonly/prepare.mjs new file mode 100644 index 000000000..1067779a0 --- /dev/null +++ b/examples/plugins/database-rfam-readonly/prepare.mjs @@ -0,0 +1,31 @@ +import fs from "node:fs/promises"; +import process from "node:process"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; +import { buildPluginPackage } from "@netcatty/plugin-cli"; +import { build } from "esbuild"; + +export const RFAM_ENDPOINT = "tcp://mysql-rfam-public.ebi.ac.uk:4497"; +const root = path.dirname(fileURLToPath(import.meta.url)); + +export async function prepareRfamExample(targetEndpoint, outputPath) { + // This separate sample accepts one documented hostname. It does not change + // the private-fixture preparer, host endpoint policy, or runtime permissions. + if (targetEndpoint !== RFAM_ENDPOINT) throw new Error("Use only the documented exact Rfam sample endpoint"); + const temporary = await fs.mkdtemp(path.join(path.dirname(outputPath), ".rfam-example-")); + try { + for (const file of ["netcatty.plugin.json", "panel.html", "panel.css", "panel.js"]) { + await fs.copyFile(path.join(root, file), path.join(temporary, file)); + } + const bundle = await build({ entryPoints: [path.join(root, "browser.js")], write: false, + bundle: true, minify: true, platform: "browser", format: "esm", nodePaths: [path.resolve(root, "../../../node_modules")] }); + await fs.writeFile(path.join(temporary, "browser.js"), bundle.outputFiles[0].contents); + return await buildPluginPackage(temporary, outputPath); + } finally { await fs.rm(temporary, { recursive: true, force: true }); } +} + +if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) { + const [endpoint, outputPath] = process.argv.slice(2); + if (!endpoint || !outputPath) throw new Error("Usage: node prepare.mjs tcp://mysql-rfam-public.ebi.ac.uk:4497 "); + process.stdout.write(`${JSON.stringify(await prepareRfamExample(endpoint, path.resolve(outputPath)))}\n`); +} diff --git a/examples/plugins/database-rfam-readonly/prepare.test.cjs b/examples/plugins/database-rfam-readonly/prepare.test.cjs new file mode 100644 index 000000000..c0970fb1d --- /dev/null +++ b/examples/plugins/database-rfam-readonly/prepare.test.cjs @@ -0,0 +1,15 @@ +"use strict"; + +const assert = require("node:assert/strict"); +const test = require("node:test"); + +test("public preparation accepts only its exact documented endpoint and private preparation stays private", async () => { + const { prepareRfamExample } = await import("./prepare.mjs"); + const { prepareDatabaseExample } = await import("../database-minimal/prepare.mjs"); + for (const endpoint of ["tcp://example.org:4497", "tcp://mysql-rfam-public.ebi.ac.uk:3306", + "tcp://mysql-rfam-public.ebi.ac.uk:4497/", "tls://mysql-rfam-public.ebi.ac.uk:4497", + "tcp://127.0.0.1:4497", "tcp://10.0.0.9:4497"]) { + await assert.rejects(prepareRfamExample(endpoint, "/unused/output.ncpkg"), /exact Rfam/u); + } + await assert.rejects(prepareDatabaseExample("tcp://mysql-rfam-public.ebi.ac.uk:4497", "/unused/output.ncpkg"), /private IPv4/u); +}); diff --git a/package.json b/package.json index b59cb79fc..81fce0751 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "pretest": "npm run build:plugin-runtime-deps && npm run check:codebuddy-sdk-contract", "test": "node --test --import tsx electron/*.test.cjs electron/preload/*.test.cjs electron/mcp/*.test.cjs electron/shared/*Privacy*.test.cjs electron/scripts/*.test.cjs electron/terminalWorker/*.test.cjs electron/capabilities/*.test.cjs electron/capabilities/*/*.test.cjs electron/capabilities/*/*/*.test.cjs electron/cli/*.test.cjs electron/hostBrowser/*Store.test.cjs electron/hostBrowser/hostBrowserManager.test.cjs electron/bridges/*.test.cjs electron/bridges/*/*.test.cjs electron/bridges/aiBridge/codexAppServer/*.test.cjs electron/bridges/aiBridge/sdk/*.test.cjs scripts/*.test.cjs application/*.test.ts application/app/*.test.ts application/i18n/locales/*.test.ts application/state/*.test.ts application/state/*/*.test.ts components/*.test.ts components/*.test.tsx components/editor/*.test.ts components/editor/*.test.tsx components/notes/*.test.ts components/notes/*.test.tsx components/port-forwarding/*.test.ts components/scripts/*.test.tsx components/systemManager/*.test.ts components/terminalLayer/*.test.ts components/settings/*.test.tsx components/settings/tabs/*.test.ts components/settings/tabs/ai/*.test.ts components/settings/tabs/ai/*.test.tsx components/ai/*.test.ts components/ai/*.test.tsx components/ai/toolArtifacts/*.test.ts components/ai/toolArtifacts/*.test.tsx components/ai-elements/*.test.tsx components/sftp/*.test.ts components/terminal/*.test.ts components/terminal/*.test.tsx components/terminal/runtime/*.test.ts components/vault/*.test.ts components/vault/*.test.tsx domain/*.test.ts domain/*/*.test.ts domain/*/*.test.cjs infrastructure/ai/*.test.ts infrastructure/ai/*/*.test.ts infrastructure/ai/sdk/*.test.ts infrastructure/config/*.test.ts infrastructure/monaco/*.test.ts infrastructure/persistence/*.test.ts infrastructure/services/*.test.ts infrastructure/services/*/*.test.ts lib/*.test.ts packages/*/src/*.test.ts", "test:plugin-contract": "node --test --import tsx packages/*/src/*.test.ts", + "test:plugin-examples": "node --test examples/plugins/database-minimal/*.test.cjs examples/plugins/database-rfam-readonly/*.test.cjs", "pretest:plugin-runtime": "npm run build:plugin-runtime-deps && npm run build --workspace @netcatty/example-starter-plugin", "test:plugin-runtime": "node --test electron/plugins/*.test.cjs domain/pluginRuntimePolicy.test.cjs domain/pluginPermissionDescriptions.test.cjs domain/pluginThemePack.test.cjs", "pretest:plugin-runtime:electron": "npm run build:plugin-runtime-deps",