Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ jobs:
run: |
python -m pip install --disable-pip-version-check -e ".[test]"
node apps/presentation/dashboard/smoke/team-task-revalidation-smoke.mjs
- name: Qualify packaged remote task inspection and recovery
if: matrix.shard == 2
working-directory: apps/presentation/dashboard
run: npm run smoke:remote-authority-inspection
- name: Preserve synthetic remote task inspection views
if: always() && matrix.shard == 2
uses: actions/upload-artifact@v7
with:
name: remote-authority-inspection-${{ github.sha }}
path: output/playwright/remote-authority-inspection/
if-no-files-found: ignore
retention-days: 7
- name: Preserve synthetic original-task recovery views
if: always() && matrix.shard == 2
uses: actions/upload-artifact@v7
Expand Down
1 change: 1 addition & 0 deletions apps/presentation/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"smoke:delivery-review": "tsc --ignoreConfig --target ES2022 --module NodeNext --moduleResolution NodeNext --skipLibCheck --strict --rootDir src --outDir node_modules/.cache/delivery-review src/data/delivery-review.ts src/data/goal-work-map.ts src/data/goal-acceptance-observation.ts src/features/personal-workspace/delivery-review-copy.ts && node smoke/delivery-review-smoke.mjs",
"smoke:team-artifact-comparison": "tsc --noEmit && vite build --ssr smoke/team-artifact-comparison-smoke.mjs --outDir node_modules/.cache/team-comparison --emptyOutDir && node node_modules/.cache/team-comparison/team-artifact-comparison-smoke.js",
"smoke:settings-target": "vite build --ssr smoke/settings-target-smoke.mjs --outDir node_modules/.cache/settings-target --emptyOutDir && node node_modules/.cache/settings-target/settings-target-smoke.js",
"smoke:remote-authority-inspection": "LOOPX_PLAYWRIGHT_PACKAGE=\"$PWD/node_modules/playwright\" node smoke/remote-authority-inspection-browser-smoke.mjs",
"smoke:team-report": "node --no-warnings --experimental-strip-types --test src/features/personal-workspace/markdown-blocks.test.mjs && vite build --ssr smoke/team-report-smoke.mjs --outDir node_modules/.cache/team-report --emptyOutDir && node node_modules/.cache/team-report/team-report-smoke.js",
"build:chat:vite": "tsc --noEmit && vite build --config vite.chat.config.ts",
"smoke:chat-upgrade": "LOOPX_PLAYWRIGHT_PACKAGE=\"$PWD/node_modules/playwright\" node ../../../examples/chat-bundle-upgrade-browser-smoke.mjs",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// Packaged App -> real Chat route -> typed inspection -> synthetic HTTPS peer.
import assert from "node:assert/strict";
import {spawn} from "node:child_process";
import {createInterface} from "node:readline";
import {once} from "node:events";
import {mkdtemp, mkdir, rm} from "node:fs/promises";
import {tmpdir} from "node:os";
import {resolve} from "node:path";
import {fileURLToPath} from "node:url";
import {testPythonCommand} from "../../../../scripts/test-python.mjs";
import {launchBrowser, loadPlaywright} from "../../../../examples/dashboard-browser-smoke-support.mjs";
import {openWorkspacePage} from "../../../../examples/personal-workspace-browser/scenario-context.mjs";

const root = fileURLToPath(new URL("../../../../", import.meta.url));
const temporary = await mkdtemp(resolve(tmpdir(), "loopx-remote-inspection-"));
const output = resolve(root, "output/playwright/remote-authority-inspection");
const baseline = process.env.LOOPX_REMOTE_INSPECT_BASELINE_ASSETS;
const arguments_ = ["fixture", "--root", temporary, ...(baseline ? ["--assets", baseline] : [])];
const python = testPythonCommand(`
import runpy
sys.argv = ${JSON.stringify(arguments_)}
runpy.run_module("tests.control_plane.remote_authority_browser_fixture", run_name="__main__")
`);
const server = spawn(python.command, python.args, {cwd: root,
env: {...process.env, LOOPX_USAGE_PING: "0"}, stdio: ["pipe", "pipe", "pipe"]});
const replies = [], waiting = [];
let diagnostics = "", browser, session, release;
const lines = createInterface({input: server.stdout});
lines.on("line", line => {
const reply = JSON.parse(line);
if (waiting.length) waiting.shift().resolve(reply); else replies.push(reply);
});
server.stderr.on("data", chunk => {diagnostics = (diagnostics + chunk).slice(-4000);});
server.on("exit", code => {for (const waiter of waiting.splice(0)) waiter.reject(new Error(`Fixture exited ${code}: ${diagnostics}`));});
function reply() {
return replies.length ? Promise.resolve(replies.shift()) : new Promise((resolveReply, reject) => {
const timer = setTimeout(() => reject(new Error(`Fixture response timed out: ${diagnostics}`)), 20000);
waiting.push({resolve: value => {clearTimeout(timer); resolveReply(value);}, reject: error => {clearTimeout(timer); reject(error);}});
});
}
async function control(value = {}) {server.stdin.write(JSON.stringify(value) + "\n"); return await reply();}
try {
const {origin} = await reply();
await mkdir(output, {recursive: true});
browser = await launchBrowser(loadPlaywright().chromium);
let hold = false, fail = false, requestHeld;
session = await openWorkspacePage(browser, origin + "/chat/?statusUrl=/status.json", {
apiOptions: {fixturePort: Number(new URL(origin).port)},
viewport: {width: 1440, height: 1000}, gotoWaitUntil: "domcontentloaded",
beforeGoto: async (_api, page) => {
await page.addInitScript(() => localStorage.setItem("loopx-pw-locale", "en"));
await page.route("**/api/chat/goal-configuration/remote-authority/inspect", async route => {
if (hold) await new Promise(resolveRequest => {release = resolveRequest; requestHeld();});
if (fail) await route.abort(); else await route.continue();
});
},
});
const {page} = session;
page.setDefaultTimeout(15000);
await page.goto(origin + "/chat/?statusUrl=/status.json&settings_scope=goal&settings_goal=product-release&settings_tab=capabilities",
{waitUntil: "domcontentloaded"});
await page.locator(".personal-capability-settings").waitFor();
assert.equal((await control()).requests, 0, "discovery never contacts the remote service");
if (baseline) {
assert.equal(await page.getByRole("region", {name: "Remote task connection"}).count(), 0);
await page.screenshot({path: resolve(output, "before-desktop.png")});
await page.setViewportSize({width: 390, height: 844});
await page.screenshot({path: resolve(output, "before-narrow.png")});
} else {
const panel = page.getByRole("region", {name: "Remote task connection"});
await panel.getByRole("button", {name: "Check connection", exact: true}).click();
await panel.getByText("Read verified", {exact: true}).waitFor();
await page.screenshot({path: resolve(output, "success-desktop.png")});
assert.equal((await control({mode: "denied"})).requests, 1);
await panel.getByRole("button", {name: "Check again", exact: true}).click();
await panel.getByText("Read unverified", {exact: true}).waitFor();
await page.screenshot({path: resolve(output, "denied-desktop.png")});
assert.equal((await control({mode: "found"})).requests, 2);
await panel.getByRole("button", {name: "Check again", exact: true}).click();
await panel.getByText("Read verified", {exact: true}).waitFor();
assert.equal((await control()).requests, 3);

hold = true;
const held = new Promise(resolveHeld => {requestHeld = resolveHeld;});
const delayedResponse = page.waitForResponse(response => response.url().endsWith("/remote-authority/inspect"));
await panel.getByRole("button", {name: "Check again", exact: true}).click();
await held;
await panel.getByRole("button", {name: "Checking…", exact: true}).waitFor();
assert.equal(await panel.getByRole("button").isDisabled(), true);
const target = page.locator(".personal-settings-goal-choice select");
const other = await target.locator("option").evaluateAll(options => options.find(option => option.value && option.value !== "product-release").value);
await target.selectOption(other);
hold = false;
release();
await (await delayedResponse).finished();
assert.equal(await panel.getByText("Read verified", {exact: true}).count(), 0, "stale results cannot cross Goals");
await target.selectOption("product-release");
fail = true;
await panel.getByRole("button", {name: "Check connection", exact: true}).click();
await panel.getByRole("alert").waitFor();
fail = false;
await control({mode: "denied"});
await panel.getByRole("button", {name: "Check again", exact: true}).click();
await panel.getByText("Read unverified", {exact: true}).waitFor();
await page.setViewportSize({width: 390, height: 844});
await page.screenshot({path: resolve(output, "denied-narrow.png")});
assert.ok(await panel.evaluate(element => element.getBoundingClientRect().right <= innerWidth + 1), "narrow view has no horizontal overflow");
const editor = page.locator(".personal-capability-detail");
await editor.getByRole("heading", {name: "Periodic reports", exact: true}).scrollIntoViewIfNeeded();
assert.ok(await editor.evaluate(element => element.clientHeight >= 200), "inspection preserves a usable settings editor on narrow screens");
await editor.getByRole("combobox").first().click();
await page.keyboard.press("Escape");
await page.screenshot({path: resolve(output, "settings-narrow.png")});
assert.equal((await control()).unchanged, true, "inspection never mutates local authority");
assert.equal(session.errors.filter(error => !error.includes("net::ERR_FAILED")).length, 0, session.errors.join("\n"));
}
console.log(baseline ? "Captured baseline packaged Goal settings" : "Packaged inspection, denial/recovery, scope fencing, network failure and state parity passed");
} finally {
release?.();
await session?.close();
await browser?.close();
const stopped = server.exitCode === null ? once(server, "exit") : Promise.resolve();
server.stdin.end();
server.kill("SIGTERM");
await stopped;
await rm(temporary, {recursive: true, force: true});
}
22 changes: 22 additions & 0 deletions apps/presentation/dashboard/src/data/remote-authority.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {z} from "zod";
import {requestJson} from "./chat";

// Validate the existing owner's safe projection, never interpret a wire reply
// or accept execution authority in the browser.
const inspectionSchema = z.object({
schema_version: z.literal("loopx_remote_authority_inspection_v1"),
ok: z.boolean(), status: z.enum(["verified", "unavailable"]),
stage: z.string(), reason_code: z.string(), message: z.string(), recommended_action: z.string(),
execution_admitted: z.literal(false), http_status: z.number().int().optional(),
}).strict().refine(value => value.ok === (value.status === "verified"));
export type RemoteAuthorityInspection = z.infer<typeof inspectionSchema>;

export async function inspectGoalRemoteAuthority(goalId: string): Promise<RemoteAuthorityInspection> {
const response = z.object({goal_id: z.string(), inspection: inspectionSchema}).strict().parse(
await requestJson<unknown>("/api/chat/goal-configuration/remote-authority/inspect", {
method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify({goal_id: goalId}),
}),
);
if (response.goal_id !== goalId) throw new Error("Inspection returned a different Goal");
return response.inspection;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import {useLayoutEffect, useRef, useState} from "react";
import {CheckCircle2, LoaderCircle, RefreshCw, AlertTriangle} from "lucide-react";
import {inspectGoalRemoteAuthority, type RemoteAuthorityInspection} from "../../data/remote-authority";
import {useWorkspaceI18n} from "./i18n";

// Presentation copy only; the existing owner decides the diagnostic and authority.
const chineseDiagnostics: Record<string, string> = {
goal_unregistered: "当前 Goal 未注册,请重新选择已有 Goal。",
actor_unregistered: "远程配置中的成员未在此 Goal 注册,请检查成员配置。",
disabled: "此 Goal 尚未启用远程连接,本地任务不受影响。",
binding_incomplete: "此 Goal 的远程连接配置不完整,请补齐已有配置后重试。",
binding_invalid: "此 Goal 的远程连接配置无效,请检查配置格式。",
actor_mismatch: "当前成员与远程配置不一致,请检查成员配置。",
endpoint_invalid: "远程服务地址无效,请使用不含凭据或路径的 HTTPS 地址。",
credential_required: "缺少服务凭据,请在运行 LoopX 的环境中配置后重试。",
credential_invalid: "服务凭据格式无效,请检查运行 LoopX 的环境配置。",
ca_invalid: "无法读取证书文件,请检查证书文件路径和权限。",
dns: "无法解析远程服务地址,请检查地址和网络连接。",
connection_refused: "远程服务拒绝连接,请检查服务是否运行及端口是否正确。",
tls: "安全连接未通过验证,请检查服务证书、域名和证书有效期。",
connection: "连接中断,请检查网络和服务状态后重试。",
timeout: "检查超时,请检查网络和服务响应后重试。",
http: "远程服务返回 HTTP 错误,请检查服务和代理配置。",
response_invalid: "服务响应无法验证,请检查客户端与服务端的兼容性。",
response_too_large: "服务响应超出读取限制,请检查服务地址是否正确。",
unauthenticated: "服务拒绝了当前凭据,请检查凭据是否有效。",
scope_denied: "当前凭据无权读取此 Goal 的任务,请联系服务管理员核对权限。",
rejected: "服务拒绝读取,请联系服务管理员核对配置和访问策略。",
todo_missing: "未找到配置中的检查任务,请核对任务和访问范围。",
read_unverified: "任务读取未通过验证,请检查服务和连接配置。",
read_verified: "已验证配置中的任务读取。此检查不会启动任务。",
registry_unreadable: "无法读取本地 Goal 注册信息,请检查文件格式和访问权限。",
node_unavailable: "本地运行环境不可用,请运行 LoopX 安装诊断并修复。",
probe_unavailable: "本地检查程序未返回有效结果,请运行 LoopX 安装诊断后重试。",
};

export function GoalRemoteAuthorityInspection({goalId}: Readonly<{goalId: string}>) {
const {locale} = useWorkspaceI18n();
const zh = locale === "zh-CN";
const [result, setResult] = useState<RemoteAuthorityInspection | null>(null);
const [failed, setFailed] = useState(false);
const [busy, setBusy] = useState(false);
const generation = useRef(0);
useLayoutEffect(() => {
generation.current++;
setResult(null); setFailed(false); setBusy(false);
return () => {generation.current++;};
}, [goalId]);

async function inspect() {
const current = ++generation.current;
setBusy(true); setFailed(false); setResult(null);
try {
const value = await inspectGoalRemoteAuthority(goalId);
if (current === generation.current) setResult(value);
} catch {
if (current === generation.current) setFailed(true);
} finally {
if (current === generation.current) setBusy(false);
}
}

const title = zh ? "远程任务连接" : "Remote task connection";
const translated = result && zh ? chineseDiagnostics[result.reason_code.replace(/^remote_authority_/, "")] : null;
return <section className="personal-remote-authority" aria-label={title}>
<div className="personal-remote-authority-heading">
<div><h3>{title}</h3><p>{zh ? "读取此 Goal 的已配置任务,不会启动工作。" : "Read this Goal’s configured task without starting work."}</p></div>
<button type="button" disabled={busy} onClick={() => void inspect()}>
{busy ? <LoaderCircle aria-hidden size={16} className="personal-spin" /> : <RefreshCw aria-hidden size={16} />}
{busy ? (zh ? "检查中…" : "Checking…") : result || failed ? (zh ? "重新检查" : "Check again") : (zh ? "检查连接" : "Check connection")}
</button>
</div>
<div aria-live="polite" aria-busy={busy}>
{failed ? <p className="personal-machine-error" role="alert">{zh ? "未能完成检查,请重试。" : "The check could not finish. Please try again."}</p> : null}
{result ? <div className="personal-remote-authority-result" data-verified={result.ok}>
<strong>{result.ok ? <CheckCircle2 aria-hidden size={16} /> : <AlertTriangle aria-hidden size={16} />}
{result.ok ? (zh ? "读取已验证" : "Read verified") : (zh ? "读取未验证" : "Read unverified")}</strong>
<p>{translated || result.message}</p>
{!result.ok && !translated ? <p>{result.recommended_action}</p> : null}
<details><summary>{zh ? "诊断详情" : "Diagnostic details"}</summary>
<code>{result.reason_code}</code>
{result.http_status !== undefined ? <p>HTTP {result.http_status}</p> : null}
<p>{zh ? "检查结果不会授予任务执行权限。" : "This result does not admit task execution."}</p>
</details>
</div> : null}
</div>
</section>;
}
Loading
Loading