Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54ba0e845d | ||
|
|
1da980e243 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cobble",
|
||||
"version": "0.28.20",
|
||||
"version": "0.28.21",
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useState } from "react";
|
||||
import Tag from "@moduletrace/twui/elements/Tag";
|
||||
import Button from "@moduletrace/twui/layout/Button";
|
||||
import Link from "@moduletrace/twui/layout/Link";
|
||||
import Row from "@moduletrace/twui/layout/Row";
|
||||
@@ -99,12 +100,18 @@ export default function HookDetailModal({ hook, can_manage = false, onClose, onE
|
||||
{runner?.configured ? (
|
||||
<>
|
||||
<TaskFactRow label="Runner">
|
||||
{runner.running
|
||||
? `Up since ${relativeTime({ at: Number(hook.runner_started_at) || Date.now() })}`
|
||||
: "Down"}
|
||||
{runner.running ? (
|
||||
`Up since ${relativeTime({ at: Number(hook.runner_started_at) || Date.now() })}`
|
||||
) : (
|
||||
<Tag color="error" variant="outlined" className="px-1.5 py-0 text-[11px] font-bold leading-4">
|
||||
Down
|
||||
</Tag>
|
||||
)}
|
||||
</TaskFactRow>
|
||||
{runner.error ? (
|
||||
<TaskFactRow label="Check failed">{runner.error}</TaskFactRow>
|
||||
<TaskFactRow label="Check failed">
|
||||
<Span className="text-error break-words min-w-0">{runner.error}</Span>
|
||||
</TaskFactRow>
|
||||
) : null}
|
||||
<TaskFactRow label="Last checked">
|
||||
{hook.runner_checked_at
|
||||
@@ -136,7 +143,11 @@ export default function HookDetailModal({ hook, can_manage = false, onClose, onE
|
||||
<TaskFactRow label="Last called">
|
||||
{hook.last_called_at ? relativeTime({ at: Number(hook.last_called_at) }) : "Never"}
|
||||
</TaskFactRow>
|
||||
{hook.last_error ? <TaskFactRow label="Last error">{hook.last_error}</TaskFactRow> : null}
|
||||
{hook.last_error ? (
|
||||
<TaskFactRow label="Last error">
|
||||
<Span className="text-error break-words min-w-0">{hook.last_error}</Span>
|
||||
</TaskFactRow>
|
||||
) : null}
|
||||
</Stack>
|
||||
{hook.instructions ? <HookCallAnswer label="Brief" text={hook.instructions} boxed /> : null}
|
||||
{status ? <SettingsStatus status={status} /> : null}
|
||||
|
||||
@@ -289,7 +289,7 @@ export default function HookForm({
|
||||
autoComplete="off"
|
||||
placeholder="whatsapp"
|
||||
defaultValue={hook?.runner_dir || ""}
|
||||
info={`Where it starts, relative to the bot's folder (/home/cb-<bot>/workspace), not to a run's ~: "whatsapp" is /home/cb-<bot>/workspace/whatsapp, while a folder a bot made at ~/whatsapp is "users/<user>/whatsapp". Empty starts in the bot's folder itself.`}
|
||||
info={`Where it starts, relative: "whatsapp" is looked for in your own folder in the bot's (/home/cb-<bot>/workspace/users/<you>, a run's ~) first, then in the bot's folder (/home/cb-<bot>/workspace), and the first one there is used. Empty starts in the bot's folder itself.`}
|
||||
onChange={(e) => setRunnerDir(e.target.value)}
|
||||
/>
|
||||
<Select
|
||||
|
||||
@@ -59,6 +59,7 @@ export default function HookRow({ hook, busy, onOpen, onToggle, onEdit, onCalls,
|
||||
title={title}
|
||||
onOpen={onOpen}
|
||||
badge={badge}
|
||||
badge_tone={badge == "Runner down" ? "error" : undefined}
|
||||
subtitle={hookSubtitle({ hook, show_bot: !compact, show_workspace: !compact })}
|
||||
>
|
||||
<SettingsRowMenu title={`${title} menu`} disabled={busy}>
|
||||
|
||||
@@ -9,7 +9,7 @@ export const HookRunnerProtocol = 1;
|
||||
* Bump with every change to `HookRunnerScript`: every runner restarts once
|
||||
* with the new script.
|
||||
*/
|
||||
export const HookRunnerVersion = "2";
|
||||
export const HookRunnerVersion = "3";
|
||||
|
||||
/**
|
||||
* The process keeper the app runs on a computer for a hook's runner
|
||||
@@ -134,14 +134,15 @@ def stop(runner_id, state, stop_ms):
|
||||
|
||||
def start(runner, env, log_max):
|
||||
runner_id = runner["id"]
|
||||
cwd = runner["cwd"]
|
||||
if not os.path.isdir(cwd):
|
||||
cwds = runner.get("cwds") or [runner["cwd"]]
|
||||
cwd = next((folder for folder in cwds if os.path.isdir(folder)), None)
|
||||
if cwd is None:
|
||||
return {
|
||||
"id": runner_id,
|
||||
"pid": None,
|
||||
"running": False,
|
||||
"started_at": None,
|
||||
"error": "Its folder isn't there: %s" % cwd,
|
||||
"error": "Its folder isn't there: %s" % " or ".join(cwds),
|
||||
}
|
||||
log = log_path(runner_id)
|
||||
try:
|
||||
|
||||
@@ -8,7 +8,7 @@ import composeComputerEnvFiles from "@/src/harness/tools/computer/compose-comput
|
||||
import type { HookRunnerSync } from "@/src/types";
|
||||
import computerNotReadyMessage from "@/src/utils/computer-not-ready-message";
|
||||
import computerRunDirs from "@/src/utils/computer-work-dirs";
|
||||
import hookRunnerDir, { hookRunnerBaseDir, hookRunnerFile } from "@/src/utils/hook-runner-paths";
|
||||
import { hookRunnerBaseDir, hookRunnerDirs, hookRunnerFile } from "@/src/utils/hook-runner-paths";
|
||||
import hookRunnerVersion from "@/src/utils/hook-runner-version";
|
||||
import type { ComputerAddress } from "../computers/grab-computer-target";
|
||||
import grabComputerTarget from "../computers/grab-computer-target";
|
||||
@@ -189,7 +189,7 @@ async function runGroup({
|
||||
workspace_id,
|
||||
});
|
||||
const base = hookRunnerBaseDir({ dirs });
|
||||
const runners: { id: number; command: string; cwd: string; version: string }[] = [];
|
||||
const runners: { id: number; command: string; cwd: string; cwds: string[]; version: string }[] = [];
|
||||
const wanted = new Set<number>();
|
||||
|
||||
for (const hook of group.hooks) {
|
||||
@@ -203,7 +203,7 @@ async function runGroup({
|
||||
user_id: hook.user_id,
|
||||
workspace_id: hook.workspace_id,
|
||||
});
|
||||
const cwd = hookRunnerDir({ dirs: hook_dirs, runner_dir: hook.runner_dir });
|
||||
const cwds = hookRunnerDirs({ dirs: hook_dirs, runner_dir: hook.runner_dir });
|
||||
const envs = await grabComputerEnvs({
|
||||
computer_id: group.computer_id,
|
||||
bot_id: hook.bot_id,
|
||||
@@ -213,7 +213,7 @@ async function runGroup({
|
||||
const version = hookRunnerVersion({
|
||||
script_version: HookRunnerVersion,
|
||||
command: hook.runner_command,
|
||||
dir: cwd,
|
||||
dir: cwds.join("\n"),
|
||||
computer_id: group.computer_id,
|
||||
workspace_id: hook.workspace_id,
|
||||
envs,
|
||||
@@ -227,7 +227,7 @@ async function runGroup({
|
||||
run_as: hook_dirs.run_as,
|
||||
});
|
||||
|
||||
runners.push({ id: Number(hook.id), command: hook.runner_command, cwd, version });
|
||||
runners.push({ id: Number(hook.id), command: hook.runner_command, cwd: cwds[0]!, cwds, version });
|
||||
wanted.add(Number(hook.id));
|
||||
} catch (error) {
|
||||
await recordRunnerFailure({
|
||||
|
||||
@@ -58,6 +58,7 @@ export default async function grabHookProposalView({ proposal_id, user_id }: Par
|
||||
computers: new Map((computers?.payload || []).map((c) => [Number(c.id), c.name || ""])),
|
||||
bot_id: proposal.bot_id,
|
||||
bot_kind: bot.payload?.[0]?.kind || null,
|
||||
user_id: proposal.user_id,
|
||||
}),
|
||||
reason: proposal.reason,
|
||||
};
|
||||
|
||||
@@ -68,8 +68,7 @@ export default function proposeHookTool({
|
||||
onPropose,
|
||||
}: Params): HarnessTool<Args> {
|
||||
const dirs = computerRunDirs({ bot_id, bot_kind: is_coordinator ? "coordinator" : null, user_id, workspace_id });
|
||||
const home_relative = dirs.cwd.slice(dirs.bot_dir.length + 1);
|
||||
const runner_folder = `relative to your bot folder ${dirs.bot_dir}, NOT to your ~ (${dirs.cwd}): a folder you made at ~/whatsapp is "${home_relative}/whatsapp", and "whatsapp" alone is ${dirs.bot_dir}/whatsapp. Empty: ${dirs.bot_dir} itself`;
|
||||
const runner_folder = `relative: the app looks in your ~ (${dirs.cwd}) first, then in your bot folder (${dirs.bot_dir}), and starts in the first one that exists, so a folder you made at ~/whatsapp is just "whatsapp". Empty: ${dirs.bot_dir} itself`;
|
||||
const listed = computers.map((computer) => `${computer.id} (${computer.name || computer.kind})`).join(", ");
|
||||
|
||||
return {
|
||||
|
||||
@@ -5,6 +5,8 @@ import Row from "@moduletrace/twui/layout/Row";
|
||||
import Span from "@moduletrace/twui/layout/Span";
|
||||
import Stack from "@moduletrace/twui/layout/Stack";
|
||||
import Checkbox from "@moduletrace/twui/form/Checkbox";
|
||||
import Tag from "@moduletrace/twui/elements/Tag";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
type Props = {
|
||||
avatar: ReactNode;
|
||||
@@ -21,6 +23,11 @@ type Props = {
|
||||
* A word beside the title, e.g. "Default" or "You".
|
||||
*/
|
||||
badge?: string;
|
||||
/**
|
||||
* `error`: the badge is a fault (a runner that is down), drawn as an
|
||||
* outlined error tag instead of a quiet word.
|
||||
*/
|
||||
badge_tone?: "error";
|
||||
/**
|
||||
* A mark right after the title, e.g. a workspace admin's shield.
|
||||
*/
|
||||
@@ -48,6 +55,7 @@ export default function SettingsListRow({
|
||||
href,
|
||||
onOpen,
|
||||
badge,
|
||||
badge_tone,
|
||||
title_icon,
|
||||
subtitle,
|
||||
selected,
|
||||
@@ -58,7 +66,17 @@ export default function SettingsListRow({
|
||||
<Span className="block text-sm font-bold leading-5 text-ink truncate w-full">
|
||||
{title}
|
||||
{title_icon ? <Span className="ml-1.5 inline-flex align-middle">{title_icon}</Span> : null}
|
||||
{badge ? <Span className="ml-2 text-[11px] font-bold leading-4 text-ink-secondary">{badge}</Span> : null}
|
||||
{badge && badge_tone == "error" ? (
|
||||
<Tag
|
||||
color="error"
|
||||
variant="outlined"
|
||||
className={twMerge("ml-2 inline-flex align-middle", "px-1.5 py-0 text-[11px] font-bold leading-4")}
|
||||
>
|
||||
{badge}
|
||||
</Tag>
|
||||
) : badge ? (
|
||||
<Span className="ml-2 text-[11px] font-bold leading-4 text-ink-secondary">{badge}</Span>
|
||||
) : null}
|
||||
</Span>
|
||||
);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ describe("describeHookProposalDetails", () => {
|
||||
workspace_name: "Launch",
|
||||
computers: new Map([[3, "Main"]]),
|
||||
bot_id: 4,
|
||||
user_id: 1,
|
||||
});
|
||||
|
||||
expect(details).toEqual([
|
||||
@@ -26,6 +27,7 @@ describe("describeHookProposalDetails", () => {
|
||||
data: { title: "Slack", instructions: "Answer.", source: "browser_notifications", watch_computer_id: 2 },
|
||||
computers: new Map([[2, "Desk"]]),
|
||||
bot_id: 4,
|
||||
user_id: 1,
|
||||
});
|
||||
|
||||
expect(details.find((d) => d.label == "Called by")?.value).toBe("Browser notifications on Desk (#2)");
|
||||
@@ -41,6 +43,7 @@ describe("describeHookProposalDetails", () => {
|
||||
current: { id: 7, title: "GitHub pushes", instructions: "Old brief.", enabled: 0 },
|
||||
computers: new Map(),
|
||||
bot_id: 4,
|
||||
user_id: 1,
|
||||
});
|
||||
|
||||
expect(details.map((d) => d.label)).toEqual(["Hook", "Brief now", "New brief", "Switch on"]);
|
||||
@@ -61,6 +64,7 @@ describe("describeHookProposalDetails", () => {
|
||||
},
|
||||
computers: new Map([[1, "Main"]]),
|
||||
bot_id: 4,
|
||||
user_id: 1,
|
||||
});
|
||||
|
||||
expect(details.map((d) => d.label)).toEqual([
|
||||
@@ -78,7 +82,7 @@ describe("describeHookProposalDetails", () => {
|
||||
value: "python3 bridge.py",
|
||||
block: true,
|
||||
});
|
||||
expect(details.find((d) => d.label == "Starts in")?.value).toBe("/home/cb-4/workspace/whatsapp");
|
||||
expect(details.find((d) => d.label == "Starts in")?.value).toBe("/home/cb-4/workspace/users/1/whatsapp, else /home/cb-4/workspace/whatsapp");
|
||||
expect(details.find((d) => d.label == "Runs it on")?.value).toContain("Main (#1)");
|
||||
});
|
||||
|
||||
@@ -89,26 +93,28 @@ describe("describeHookProposalDetails", () => {
|
||||
current: { id: 7, title: "WhatsApp", instructions: "Answer.", enabled: 1 },
|
||||
computers: new Map([[1, "Main"]]),
|
||||
bot_id: 4,
|
||||
user_id: 1,
|
||||
});
|
||||
|
||||
expect(details.map((d) => d.label)).toEqual(["Hook", "Runner now", "New runner", "Will start in", "Runs it on"]);
|
||||
expect(details[1]?.value).toBe("None");
|
||||
expect(details[2]?.value).toBe("python3 bridge.py");
|
||||
expect(details[3]?.value).toBe("/home/cb-4/workspace/whatsapp");
|
||||
expect(details[3]?.value).toBe("/home/cb-4/workspace/users/1/whatsapp, else /home/cb-4/workspace/whatsapp");
|
||||
expect(details[4]?.value).toBe("Main (#1)");
|
||||
});
|
||||
|
||||
test("a runner moved to another folder shows both absolute paths", () => {
|
||||
const details = describeHookProposalDetails({
|
||||
action: "change",
|
||||
data: { runner_command: "./run.sh", runner_dir: "users/1/whatsapp" },
|
||||
data: { runner_command: "./run.sh", runner_dir: "bridge" },
|
||||
current: { id: 2, title: "WhatsApp", enabled: 1, runner_command: "./run.sh", runner_dir: "whatsapp", runner_computer_id: 1 },
|
||||
computers: new Map([[1, "Main"]]),
|
||||
bot_id: 4,
|
||||
user_id: 1,
|
||||
});
|
||||
|
||||
expect(details.find((d) => d.label == "Starts in now")?.value).toBe("/home/cb-4/workspace/whatsapp");
|
||||
expect(details.find((d) => d.label == "Will start in")?.value).toBe("/home/cb-4/workspace/users/1/whatsapp");
|
||||
expect(details.find((d) => d.label == "Starts in now")?.value).toBe("/home/cb-4/workspace/users/1/whatsapp, else /home/cb-4/workspace/whatsapp");
|
||||
expect(details.find((d) => d.label == "Will start in")?.value).toBe("/home/cb-4/workspace/users/1/bridge, else /home/cb-4/workspace/bridge");
|
||||
});
|
||||
|
||||
test("the coordinator's runner starts in its folder in the computer's workspace", () => {
|
||||
@@ -118,9 +124,10 @@ describe("describeHookProposalDetails", () => {
|
||||
current: { id: 2, title: "Bridge", enabled: 1 },
|
||||
computers: new Map(),
|
||||
bot_id: 1,
|
||||
user_id: 1,
|
||||
bot_kind: "coordinator",
|
||||
});
|
||||
|
||||
expect(details.find((d) => d.label == "Will start in")?.value).toBe("/home/gem/workspace/bots/1/bridge");
|
||||
expect(details.find((d) => d.label == "Will start in")?.value).toBe("/home/gem/workspace/bots/1/users/1/bridge, else /home/gem/workspace/bots/1/bridge");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -25,6 +25,10 @@ type Params = {
|
||||
*/
|
||||
bot_id: number | string;
|
||||
bot_kind?: string | null;
|
||||
/**
|
||||
* Whose hook it is: a runner looks in their folder first.
|
||||
*/
|
||||
user_id: number | string;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -41,9 +45,10 @@ export default function describeHookProposalDetails({
|
||||
computers,
|
||||
bot_id,
|
||||
bot_kind,
|
||||
user_id,
|
||||
}: Params): ExtensionProposalDetail[] {
|
||||
const computer = (id?: number | null) => (id ? `${computers.get(Number(id)) || "Computer"} (#${id})` : "");
|
||||
const folder = (dir?: string | null) => hookRunnerStartPath({ bot_id, bot_kind, runner_dir: dir }) || dir || "";
|
||||
const folder = (dir?: string | null) => hookRunnerStartPath({ bot_id, bot_kind, user_id, runner_dir: dir }) || dir || "";
|
||||
|
||||
if (action == "create") {
|
||||
const watching = data.source == "browser_notifications";
|
||||
|
||||
@@ -28,7 +28,7 @@ describe("describeHookRunner", () => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(text).toContain("runner `./run.sh` starts in \"whatsapp\" inside the bot's folder (not your ~) on computer 1");
|
||||
expect(text).toContain("runner `./run.sh` starts in \"whatsapp\" inside your ~ or the bot's folder on computer 1");
|
||||
expect(text).toContain("NOT RUNNING, the check failed (last checked 2026-11-30T08:05:00.000Z)");
|
||||
expect(text).toContain("Its folder isn't there: /home/cb-4/workspace/whatsapp");
|
||||
expect(text).toContain("propose_hook");
|
||||
@@ -46,16 +46,16 @@ describe("describeHookRunner", () => {
|
||||
},
|
||||
}),
|
||||
).toBe(
|
||||
"runner `./run.sh` starts in the bot's folder (not your ~): running since 2026-11-30T08:00:00.000Z, last checked 2026-11-30T08:05:00.000Z",
|
||||
"runner `./run.sh` starts in the bot's folder: running since 2026-11-30T08:00:00.000Z, last checked 2026-11-30T08:05:00.000Z",
|
||||
);
|
||||
});
|
||||
|
||||
test("gives the absolute folder when it knows the bot", () => {
|
||||
const text = describeHookRunner({
|
||||
hook: { ...base, bot_id: 4, bot_kind: "worker", runner_command: "./run.sh", runner_dir: "whatsapp", runner_last_error: "x" },
|
||||
hook: { ...base, bot_id: 4, user_id: 1, bot_kind: "worker", runner_command: "./run.sh", runner_dir: "whatsapp", runner_last_error: "x" },
|
||||
});
|
||||
|
||||
expect(text).toContain('starts in /home/cb-4/workspace/whatsapp (runner_dir "whatsapp", relative to the bot\'s folder, not your ~)');
|
||||
expect(text).toContain('starts in /home/cb-4/workspace/users/1/whatsapp, else /home/cb-4/workspace/whatsapp (runner_dir "whatsapp": your ~ first, else the bot\'s folder)');
|
||||
});
|
||||
|
||||
test("is part of the hook a bot lists", () => {
|
||||
|
||||
@@ -8,8 +8,8 @@ type Params = {
|
||||
|
||||
/**
|
||||
* A hook's runner as a bot reads it, from what the last check stored
|
||||
* (`syncHookRunners`): the command, the folder it starts in (inside the
|
||||
* bot's folder, which is not a run's `~`), whether it is up, and when it
|
||||
* (`syncHookRunners`): the command, the folder it starts in (the owner's
|
||||
* `~` first, else the bot's folder), whether it is up, and when it
|
||||
* isn't, why the check failed. Empty when the hook keeps no runner.
|
||||
*
|
||||
* A failed check says the fix is the runner itself, through a proposal:
|
||||
@@ -21,13 +21,18 @@ export default function describeHookRunner({ hook }: Params) {
|
||||
|
||||
if (!state.configured) return "";
|
||||
|
||||
const folder = hook.bot_id
|
||||
? hookRunnerStartPath({ bot_id: hook.bot_id, bot_kind: hook.bot_kind, runner_dir: hook.runner_dir })
|
||||
const folder = hook.bot_id && hook.user_id
|
||||
? hookRunnerStartPath({
|
||||
bot_id: hook.bot_id,
|
||||
bot_kind: hook.bot_kind,
|
||||
user_id: hook.user_id,
|
||||
runner_dir: hook.runner_dir,
|
||||
})
|
||||
: null;
|
||||
const where = [
|
||||
folder
|
||||
? `starts in ${folder} (runner_dir "${hook.runner_dir || ""}", relative to the bot's folder, not your ~)`
|
||||
: `starts in ${hook.runner_dir ? `"${hook.runner_dir}" inside the bot's folder` : "the bot's folder"} (not your ~)`,
|
||||
? `starts in ${folder} (runner_dir "${hook.runner_dir || ""}": your ~ first, else the bot's folder)`
|
||||
: `starts in ${hook.runner_dir ? `"${hook.runner_dir}" inside your ~ or the bot's folder` : "the bot's folder"}`,
|
||||
hook.runner_computer_id ? `on computer ${hook.runner_computer_id}` : "",
|
||||
]
|
||||
.filter(Boolean)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { BotHookRunnerDir } from "@/src/dict/bot-hook-dict";
|
||||
import type { ComputerRunDirs } from "@/src/utils/computer-work-dirs";
|
||||
import hookRunnerDir, { hookRunnerBaseDir, hookRunnerFile } from "./hook-runner-paths";
|
||||
import hookRunnerDir, { hookRunnerBaseDir, hookRunnerDirs, hookRunnerFile } from "./hook-runner-paths";
|
||||
|
||||
const dirs = {
|
||||
bot_dir: "/home/gem/workspace/bots/3",
|
||||
@@ -69,4 +69,32 @@ describe("hookRunnerDir", () => {
|
||||
test("refuses a null byte", () => {
|
||||
expect(() => hookRunnerDir({ dirs, runner_dir: "whats\0app" })).toThrow("null byte");
|
||||
});
|
||||
});
|
||||
});
|
||||
/**
|
||||
* A runner looks in its owner's `~` first (where a bot builds a bridge it
|
||||
* was asked for), then in the bot's folder, so "whatsapp" finds
|
||||
* `~/whatsapp` and a folder given the old way still works.
|
||||
*/
|
||||
describe("hookRunnerDirs", () => {
|
||||
test("a relative folder is tried in the owner's ~, then in the bot's folder", () => {
|
||||
expect(hookRunnerDirs({ dirs, runner_dir: "whatsapp" })).toEqual([
|
||||
"/home/gem/workspace/bots/3/users/1/whatsapp",
|
||||
"/home/gem/workspace/bots/3/whatsapp",
|
||||
]);
|
||||
});
|
||||
|
||||
test("a folder given from the bot's folder still resolves there", () => {
|
||||
expect(hookRunnerDirs({ dirs, runner_dir: "users/1/whatsapp" })).toEqual([
|
||||
"/home/gem/workspace/bots/3/users/1/users/1/whatsapp",
|
||||
"/home/gem/workspace/bots/3/users/1/whatsapp",
|
||||
]);
|
||||
});
|
||||
|
||||
test("empty is the bot's folder alone", () => {
|
||||
expect(hookRunnerDirs({ dirs, runner_dir: "" })).toEqual([dirs.bot_dir]);
|
||||
});
|
||||
|
||||
test("refuses what hookRunnerDir refuses", () => {
|
||||
expect(() => hookRunnerDirs({ dirs, runner_dir: "../x" })).toThrow("has to stay inside the bot's folder");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -44,4 +44,23 @@ export default function hookRunnerDir({ dirs, runner_dir }: { dirs: ComputerRunD
|
||||
}
|
||||
|
||||
return parts.length ? path.posix.join(dirs.bot_dir, ...parts) : dirs.bot_dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* The folders a runner may start in, in the order the keeper tries them
|
||||
* (it starts in the first one there): the hook owner's own folder in the
|
||||
* bot's (`users/<user>`, the run's `~`, where a bot builds what it was
|
||||
* asked for), then the bot's folder. So "whatsapp" finds a bridge a bot
|
||||
* made at `~/whatsapp`, and a folder given from the bot's folder
|
||||
* (`users/1/whatsapp`, as hooks were set before) still works. Empty is
|
||||
* the bot's folder alone. Refused the same way as `hookRunnerDir`.
|
||||
*/
|
||||
export function hookRunnerDirs({ dirs, runner_dir }: { dirs: ComputerRunDirs; runner_dir?: string | null }) {
|
||||
const in_bot = hookRunnerDir({ dirs, runner_dir });
|
||||
|
||||
if (in_bot == dirs.bot_dir || dirs.cwd == dirs.bot_dir) return [in_bot];
|
||||
|
||||
const in_home = path.posix.join(dirs.cwd, path.posix.relative(dirs.bot_dir, in_bot));
|
||||
|
||||
return [in_home, in_bot];
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import computerRunDirs from "./computer-work-dirs";
|
||||
import hookRunnerDir from "./hook-runner-paths";
|
||||
import { hookRunnerDirs } from "./hook-runner-paths";
|
||||
|
||||
type Params = {
|
||||
bot_id: number | string;
|
||||
@@ -8,22 +8,27 @@ type Params = {
|
||||
* a worker's is `/home/cb-<id>/workspace`.
|
||||
*/
|
||||
bot_kind?: string | null;
|
||||
/**
|
||||
* The hook's owner: the runner looks in their folder (`users/<user>`)
|
||||
* first.
|
||||
*/
|
||||
user_id: number | string;
|
||||
runner_dir?: string | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* The absolute folder a hook's runner starts in, as the bot's account sees
|
||||
* it, the same way `syncHookRunners` works it out: `runner_dir` is relative
|
||||
* to the bot's folder, which is not a run's `~` (that is `users/<user>`
|
||||
* inside it), so a card or a bot reading only "whatsapp" can't tell which
|
||||
* folder it means. Null when the folder would be refused (absolute, `~`,
|
||||
* climbing out), so the caller shows what was given instead.
|
||||
* it, the same way `syncHookRunners` works it out (`hookRunnerDirs`): the
|
||||
* owner's folder (the run's `~`) first, else the bot's folder, written as
|
||||
* "A, else B" so a card or a bot reading only "whatsapp" knows where it
|
||||
* looks. Null when the folder would be refused (absolute, `~`, climbing
|
||||
* out), so the caller shows what was given instead.
|
||||
*/
|
||||
export default function hookRunnerStartPath({ bot_id, bot_kind, runner_dir }: Params) {
|
||||
export default function hookRunnerStartPath({ bot_id, bot_kind, user_id, runner_dir }: Params) {
|
||||
try {
|
||||
const dirs = computerRunDirs({ bot_id, bot_kind, user_id: 0 });
|
||||
const dirs = computerRunDirs({ bot_id, bot_kind, user_id });
|
||||
|
||||
return hookRunnerDir({ dirs, runner_dir });
|
||||
return hookRunnerDirs({ dirs, runner_dir }).join(", else ");
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user