mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-17 01:46:07 +00:00
fix(agent-runner): close sandbox skill authoring flow
This commit is contained in:
@@ -239,6 +239,7 @@ async function runFilesystemChecks(checks) {
|
||||
}
|
||||
const contains = textList(check.contains);
|
||||
const notContains = textList(check.not_contains || check.notContains);
|
||||
const expectedJson = check.json_equals ?? check.jsonEquals;
|
||||
const expectedExitCode = Number.isInteger(check.exit_code)
|
||||
? check.exit_code
|
||||
: Number.isInteger(check.expected_exit_code)
|
||||
@@ -257,18 +258,31 @@ async function runFilesystemChecks(checks) {
|
||||
}
|
||||
const missing = contains.filter((needle) => !text.includes(needle));
|
||||
const forbidden = notContains.filter((needle) => text.includes(needle));
|
||||
let jsonError = "";
|
||||
let jsonMatches = null;
|
||||
if (expectedJson !== undefined) {
|
||||
try {
|
||||
jsonMatches = JSON.stringify(sortJson(JSON.parse(text))) === JSON.stringify(sortJson(expectedJson));
|
||||
if (!jsonMatches) jsonError = "JSON content does not match json_equals.";
|
||||
} catch (error) {
|
||||
jsonMatches = false;
|
||||
jsonError = `Invalid JSON: ${error.message}`;
|
||||
}
|
||||
}
|
||||
const failed = missing.length > 0 || forbidden.length > 0 || jsonMatches === false;
|
||||
results.push({
|
||||
index,
|
||||
status: missing.length || forbidden.length ? "fail" : "pass",
|
||||
status: failed ? "fail" : "pass",
|
||||
type: "file",
|
||||
path,
|
||||
missing,
|
||||
forbidden,
|
||||
json_matches: jsonMatches,
|
||||
reason: missing.length
|
||||
? `Missing expected text: ${missing.join(", ")}`
|
||||
: forbidden.length
|
||||
? `Found forbidden text: ${forbidden.join(", ")}`
|
||||
: "",
|
||||
: jsonError,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
@@ -310,6 +324,16 @@ async function runFilesystemChecks(checks) {
|
||||
};
|
||||
}
|
||||
|
||||
function sortJson(value) {
|
||||
if (Array.isArray(value)) return value.map(sortJson);
|
||||
if (!value || typeof value !== "object") return value;
|
||||
return Object.fromEntries(
|
||||
Object.keys(value)
|
||||
.sort()
|
||||
.map((key) => [key, sortJson(value[key])]),
|
||||
);
|
||||
}
|
||||
|
||||
function pipelineIdFromUrl(url) {
|
||||
if (!url) return "";
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { env } from "node:process";
|
||||
import {
|
||||
apiJson,
|
||||
ensureEvidence,
|
||||
evidencePaths,
|
||||
loadEnvFiles,
|
||||
resetAndAuthLocalUser,
|
||||
writeResult,
|
||||
} from "./lib/langbot-e2e.mjs";
|
||||
|
||||
const DEFAULT_LOCAL_PASSWORD = "LangBotE2ELocalPass!2026";
|
||||
const caseId = "reset-sandbox-skill";
|
||||
|
||||
await loadEnvFiles();
|
||||
const paths = evidencePaths(caseId);
|
||||
await ensureEvidence(paths);
|
||||
|
||||
const nameArgument = process.argv.find((argument) => argument.startsWith("--name="));
|
||||
const skillName = nameArgument?.slice("--name=".length).trim() || "";
|
||||
const backendUrl = env.LANGBOT_BACKEND_URL || "";
|
||||
const result = {
|
||||
source: "setup_automation",
|
||||
case_id: caseId,
|
||||
run_id: paths.runId,
|
||||
status: "fail",
|
||||
reason: "",
|
||||
skill_name: skillName,
|
||||
existed: false,
|
||||
deleted: false,
|
||||
evidence_collected: ["api_diagnostic"],
|
||||
};
|
||||
|
||||
try {
|
||||
if (!backendUrl) throw new Error("LANGBOT_BACKEND_URL is not configured.");
|
||||
if (!skillName || !/^[A-Za-z0-9_-]+$/.test(skillName)) {
|
||||
throw new Error("--name must contain only letters, numbers, hyphens, or underscores.");
|
||||
}
|
||||
|
||||
const user = env.LANGBOT_E2E_LOGIN_USER || "";
|
||||
if (!user) throw new Error("LANGBOT_E2E_LOGIN_USER is required.");
|
||||
const password = env.LANGBOT_E2E_LOGIN_PASSWORD || DEFAULT_LOCAL_PASSWORD;
|
||||
const auth = await resetAndAuthLocalUser({ backendUrl, user, password });
|
||||
const listed = await apiJson(backendUrl, "/api/v1/skills", { token: auth.token });
|
||||
if (listed.status >= 400 || listed.json.code !== 0) {
|
||||
throw new Error(listed.json.msg || `Skill listing failed with HTTP ${listed.status}.`);
|
||||
}
|
||||
|
||||
result.existed = (listed.json.data?.skills || []).some((skill) => skill?.name === skillName);
|
||||
if (result.existed) {
|
||||
const deleted = await apiJson(
|
||||
backendUrl,
|
||||
`/api/v1/skills/${encodeURIComponent(skillName)}`,
|
||||
{ method: "DELETE", token: auth.token },
|
||||
);
|
||||
if (deleted.status >= 400 || deleted.json.code !== 0) {
|
||||
throw new Error(deleted.json.msg || `Skill deletion failed with HTTP ${deleted.status}.`);
|
||||
}
|
||||
result.deleted = true;
|
||||
}
|
||||
|
||||
result.status = "pass";
|
||||
result.reason = result.deleted
|
||||
? `Removed stale sandbox skill ${skillName}.`
|
||||
: `Sandbox skill ${skillName} was already absent.`;
|
||||
} catch (error) {
|
||||
result.status = /ECONNREFUSED|fetch failed|not configured|required/.test(error.message)
|
||||
? "env_issue"
|
||||
: "fail";
|
||||
result.reason = error.message;
|
||||
}
|
||||
|
||||
await writeResult(paths, result);
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
process.exit(result.status === "pass" ? 0 : result.status === "env_issue" ? 2 : 1);
|
||||
Reference in New Issue
Block a user