Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127import assert from "node:assert/strict";import { readFile } from "node:fs/promises";import { resolve } from "node:path";import { test } from "node:test";import { build } from "esbuild";import { compile } from "octane/compiler";
const file = resolve("src/components/skill-script-output.tsx");const compiled = compile(await readFile(file, "utf8"), file, { mode: "server",});const bundle = await build({ stdin: { contents: `${compiled.code}\nexport { renderToStaticMarkup } from "octane/server";`, resolveDir: resolve("src/components"), loader: "ts", }, bundle: true, write: false, platform: "node", format: "esm", target: "es2022",});const { skillScriptOutput, SkillScriptOutput, renderToStaticMarkup } = await import( `data:text/javascript;base64,${Buffer.from(bundle.outputFiles[0].text).toString("base64")}` );const output = () => ({ kind: "skill-script", skill: { source: "installed", name: "report-helper", version: "1.2.3", fingerprint: "a".repeat(64), }, path: "scripts/report.js", result: { ok: false, result: null, stdout: "<script>globalThis.executed = true</script>\n雪🦊", stderr: "Synthetic script failure", exitCode: 1, error: { code: "script_failed", message: "Skill script failed. <script>inert error</script>", }, truncated: true, }, workspace: { files: [{ path: "result.txt", content: "Private file body" }], truncated: true, },});
test("script output projects bounded display fields without walking arbitrary results or files", () => { const value = output(); Object.defineProperty(value.result, "result", { get() { throw new Error("Arbitrary return value was inspected"); }, }); Object.defineProperty(value.workspace.files[0], "content", { get() { throw new Error("Workspace content was inspected"); }, }); const projected = skillScriptOutput(value); assert.ok(projected); assert.equal("result" in projected.result, false); assert.deepEqual(projected.workspace.files, [{ path: "result.txt" }]); for (const invalid of [ null, {}, { ...output(), kind: "mcp" }, { ...output(), workspace: { files: Array.from({ length: 9 }, () => ({ path: "x.txt" })), truncated: false, }, }, ]) { assert.equal(skillScriptOutput(invalid), undefined); } for (const text of [ "x".repeat(8193), "\u0001".repeat(1400), "🦊".repeat(2100), ]) { const invalid = output(); invalid.result.stdout = text; assert.equal( skillScriptOutput(invalid), undefined, "escaped JSON bytes enforce the display budget", ); } const longError = output(); longError.result.error.message = "x".repeat(241); assert.equal(skillScriptOutput(longError), undefined); const boundary = output(); boundary.result.stdout = "x".repeat(8190); assert.ok(skillScriptOutput(boundary));});
test("compiled Skill output is collapsed, shows exit status and renders script text inertly", () => { const value = skillScriptOutput(output()); const { html } = renderToStaticMarkup(SkillScriptOutput, { output: value }); assert.match(html, /<details[^>]*>/); assert.doesNotMatch(html, /<details[^>]*\bopen\b/); assert.match(html, /Exit status 1/); assert.match(html, /Output truncated/); assert.match(html, /<script>/); assert.doesNotMatch(html, /<script>/); assert.match(html, /Synthetic script failure/); assert.match( html, /Skill script failed\. <script>inert error<\/script>/, ); assert.match(html, /report-helper/); assert.match(html, /1\.2\.3/); assert.match(html, /Changed files in this invocation/); assert.match(html, /result\.txt/); assert.doesNotMatch(html, /Private file body/); assert.match(html, /text-sm/);});