agent-yes 1.303.1 → 1.304.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -0
- package/default.config.yaml +5 -5
- package/dist/{JsonlStore-BpYZZTap.js → JsonlStore-CB_0sfdT.js} +5 -4
- package/dist/{SUPPORTED_CLIS-Dq9Lq9WJ.js → SUPPORTED_CLIS-C_1IiOj3.js} +2 -2
- package/dist/SUPPORTED_CLIS-Do3GHAY1.js +12 -0
- package/dist/{agentShare-suB6yPgO.js → agentShare-BvpEm-Fr.js} +10 -9
- package/dist/{askCli-BU3CNCLU.js → askCli-KmMf-3wA.js} +6 -6
- package/dist/{browser-BmxN1Ur9.js → browser-BAFPmEvN.js} +2 -2
- package/dist/{callback-Ctj3_Wxp.js → callback-BiSUhjw7.js} +6 -6
- package/dist/callback-SqLD2mMX.js +17 -0
- package/dist/{callbackCore-DSJWhqAe.js → callbackCore-BZ_10zyc.js} +1 -1
- package/dist/{callbackCore-BesbQ6-Z.js → callbackCore-Deve5pv3.js} +1 -1
- package/dist/{channels-j5nWuzlQ.js → channels-Y36S0ccW.js} +2 -2
- package/dist/cli.js +118 -13
- package/dist/{cmdDsh-2LP0grim.js → cmdDsh-DZ8bLsH7.js} +1 -1
- package/dist/cmdKill-CzSBfWmx.js +116 -0
- package/dist/{cmdPs-wc1j85fi.js → cmdPs-DBt23Qz0.js} +11 -10
- package/dist/{cwdConflictWarn-skQSMwEh.js → cwdConflictWarn-y-epQyOj.js} +21 -5
- package/dist/{cwdPassthroughHint-BUbWMoz0.js → cwdPassthroughHint-CzWh0hrw.js} +1 -1
- package/dist/{expose-Dawq1LxC.js → expose-Bhsn5yUz.js} +2 -2
- package/dist/forceKill-BDqxx4uQ.js +44 -0
- package/dist/{forkNested-CavHyWzA.js → forkNested-3heLs5XC.js} +45 -5
- package/dist/{globalPidIndex-CRB5KtyL.js → globalPidIndex-BsjlId-h.js} +6 -5
- package/dist/{globalPidIndex-BftWlg2V.js → globalPidIndex-uoz8Esqz.js} +2 -2
- package/dist/{hist-Cs0KFSUW.js → hist-DY16wm7g.js} +1 -1
- package/dist/{identity-DA7YI9km.js → identity-C0MxfwI2.js} +1 -1
- package/dist/{identity-Bk-aG_xl.js → identity-Ckav3-Up.js} +1 -1
- package/dist/index.js +7 -7
- package/dist/{initMsg-CcTqFtsp.js → initMsg-BEVDWYnv.js} +1 -1
- package/dist/{initMsg-D9KJnfgC.js → initMsg-GPU52N-j.js} +1 -1
- package/dist/liagent/box-BSIrRRc_.js +2320 -0
- package/dist/liagent/box-DloywR57.d.ts +409 -0
- package/dist/liagent/box.d.ts +3 -0
- package/dist/liagent/box.js +3 -0
- package/dist/liagent/cli.d.ts +1 -0
- package/dist/liagent/cli.js +908 -0
- package/dist/liagent/client.d.ts +28 -0
- package/dist/liagent/client.js +240 -0
- package/dist/liagent/echo-BvzPSI0x.js +86 -0
- package/dist/liagent/echo-W2RcMEny.d.ts +38 -0
- package/dist/liagent/hub.d.ts +405 -0
- package/dist/liagent/hub.js +1831 -0
- package/dist/liagent/index.d.ts +14 -0
- package/dist/liagent/index.js +10 -0
- package/dist/liagent/liagent.js +339 -0
- package/dist/liagent/mic-audio-C3Shud_F.js +754 -0
- package/dist/liagent/mic-audio-DMCWtEI-.d.ts +317 -0
- package/dist/liagent/mic-button-CtZHFBSG.js +651 -0
- package/dist/liagent/mic-button-Y0ioPetQ.d.ts +248 -0
- package/dist/liagent/mic.d.ts +3 -0
- package/dist/liagent/mic.js +4 -0
- package/dist/liagent/progress-CJs08bXb.js +473 -0
- package/dist/liagent/progress-CfE-meHr.d.ts +205 -0
- package/dist/liagent/progress.d.ts +2 -0
- package/dist/liagent/progress.js +3 -0
- package/dist/liagent/protocol.d.ts +324 -0
- package/dist/liagent/protocol.js +504 -0
- package/dist/liagent/speech-rate-DXeJjRTc.js +42 -0
- package/dist/liagent/state-tree-BZCmAknI.js +353 -0
- package/dist/liagent/tree-BrR7NwMf.js +710 -0
- package/dist/liagent/tree-HB9RhX_H.d.ts +295 -0
- package/dist/liagent/tree.d.ts +2 -0
- package/dist/liagent/tree.js +4 -0
- package/dist/liagent/ui-strings-B03le3fh.d.ts +27 -0
- package/dist/liagent/ui-strings-CJIwW5Gf.js +794 -0
- package/dist/liagent/ui.d.ts +394 -0
- package/dist/liagent/ui.js +5 -0
- package/dist/liagent/voice-D7yeS9VM.js +802 -0
- package/dist/liagent/voice-Qo7SCgi8.d.ts +308 -0
- package/dist/liagent/voice.d.ts +3 -0
- package/dist/liagent/voice.js +4 -0
- package/dist/{notifyDaemon-C7GlfJ1E.js → notifyDaemon-DkUB7GV2.js} +10 -9
- package/dist/{openBrowser-1cIo4dJL.js → openBrowser-CQAOIrD6.js} +1 -1
- package/dist/oxmgrService-DlYHmqyI.js +37 -0
- package/dist/oxmgrService-o9L3I6FX.js +3 -0
- package/dist/{parentLink-DoEWVGld.js → parentLink-BcAYcO9L.js} +2 -2
- package/dist/{parentLink-B58V1RVd.js → parentLink-MBUD3oY2.js} +2 -2
- package/dist/{parentPingLoop-C73bbmCE.js → parentPingLoop-DDO592Wh.js} +5 -5
- package/dist/{pidStore-433kvh9D.js → pidStore-C50VPk3E.js} +3 -3
- package/dist/pidStore-COkPjpW8.js +6 -0
- package/dist/{procStats-BvmrBrOs.js → procStats-DwTxj3rs.js} +1 -1
- package/dist/{remotes-MfdV9M8u.js → remotes-BqLoB5GR.js} +2 -2
- package/dist/{remotes-DevcBeLl.js → remotes-BsMGvAay.js} +3 -3
- package/dist/{roomReplyAlias-DFqg_6IU.js → roomReplyAlias-B-v76TA8.js} +3 -3
- package/dist/roomReplyAlias-BzWUBkQy.js +6 -0
- package/dist/{rustBinary-7VK7oLlW.js → rustBinary-BrJ2p8wy.js} +2 -2
- package/dist/{rustBinary-BV4LxMMn.js → rustBinary-vpfpWj1q.js} +2 -2
- package/dist/{schedule-Dp0qkNO1.js → schedule-Bzjhl6-h.js} +15 -44
- package/dist/schedulesCli-CLqieyQZ.js +784 -0
- package/dist/senderAncestry-CVHeKk1Y.js +173 -0
- package/dist/senderAncestry-KhAUPCQs.js +3 -0
- package/dist/{serve-BpOIIOVc.js → serve-XwFYE0cE.js} +67 -69
- package/dist/{serveRust-CbBrcUrg.js → serveRust-BfWkeL6T.js} +31 -4
- package/dist/{setup-DdIBk6Iv.js → setup-D4-s2VZw.js} +5 -5
- package/dist/{share-w5oRbvlj.js → share-CbFetL5H.js} +1 -1
- package/dist/{share-DrS3LYqf.js → share-_TPYAGWC.js} +1 -1
- package/dist/{shareCmd-DDENkBW2.js → shareCmd-DUBsVI3e.js} +10 -10
- package/dist/spawnGate-Dfj9V76w.js +5 -0
- package/dist/{spawnGate-lr3tvA6U.js → spawnGate-Dj_WaS29.js} +3 -3
- package/dist/{subcommands-DxgvDmZX.js → subcommands-B7YZJL8n.js} +471 -307
- package/dist/subcommands-BZPxFgkT.js +15 -0
- package/dist/{systemPathLink-SjUzgSiq.js → systemPathLink-Y3iC7bYV.js} +1 -1
- package/dist/{terminal-C2h7tpe0.js → terminal-13cGj3h6.js} +2 -2
- package/dist/terminal.js +1 -1
- package/dist/{todoAutomation-TTp_Qz9G.js → todoAutomation-CKlrxuZv.js} +2 -2
- package/dist/{todoCli-BWm5nZE0.js → todoCli-CU9vSJSJ.js} +6 -6
- package/dist/{todoIdentity-BvXZKWJI.js → todoIdentity-CzS1e7VL.js} +2 -2
- package/dist/{todoStore-C9RTz0Vs.js → todoStore-msRCEUi1.js} +2 -2
- package/dist/{tray-BeRSozJz.js → tray-CLktEN3G.js} +1 -1
- package/dist/{trayApp-QQjqhDv1.js → trayApp-5_OlvQcz.js} +2 -2
- package/dist/trayApp-DkAPo0m6.js +5 -0
- package/dist/{ts-6LF7f4fx.js → ts-njuddXQz.js} +126 -57
- package/dist/{versionChecker-Bc62HNf6.js → versionChecker-BJycAanp.js} +2 -2
- package/dist/{webrtcLink-va_gAR77.js → webrtcLink-DcvacEci.js} +1 -1
- package/dist/{webrtcLink-SsInrVHU.js → webrtcLink-WxS1nTIs.js} +1 -1
- package/dist/{webrtcRemote-BlGyNZDC.js → webrtcRemote-C3xQyf3u.js} +2 -2
- package/dist/{widget-Crb5zeHL.js → widget-DmRwOlco.js} +3 -3
- package/dist/widgets.js +1 -1
- package/dist/{workspaceConfig-BLWB5Wu9.js → workspaceConfig-DBgsu81B.js} +1 -1
- package/dist/{ws-DIbwNz8Z.js → ws-ByO6JO6m.js} +3 -3
- package/dist/{ws-BRhPG1Vy.js → ws-D0-Jg88z.js} +9 -8
- package/lab/ui/index.html +1 -1
- package/lab/ui/lab/posts/2026-08-11-slack-term-safe-writes.md +1 -1
- package/package.json +73 -8
- package/ts/JsonlStore.ts +10 -3
- package/ts/cli-idle.bun.spec.ts +1 -1
- package/ts/cli-idle.spec.ts +1 -1
- package/ts/cli.ts +35 -0
- package/ts/cmdKill.bun.spec.ts +155 -0
- package/ts/cmdKill.spec.ts +155 -0
- package/ts/cmdKill.ts +183 -0
- package/ts/composerGuard.edges.spec.ts +91 -0
- package/ts/composerGuard.spec.ts +53 -6
- package/ts/composerGuard.ts +42 -13
- package/ts/conptyModeFilter.spec.ts +30 -0
- package/ts/conptyModeFilter.ts +53 -0
- package/ts/copyLiagent.ts +42 -0
- package/ts/cwdConflictWarn.io.spec.ts +50 -0
- package/ts/cwdConflictWarn.spec.ts +34 -1
- package/ts/cwdConflictWarn.ts +43 -5
- package/ts/cwdGuard.spec.ts +110 -0
- package/ts/cwdGuard.ts +118 -0
- package/ts/forceKill.ts +52 -0
- package/ts/forkNested.bun.spec.ts +41 -0
- package/ts/forkNested.spec.ts +41 -0
- package/ts/forkNested.ts +48 -1
- package/ts/globalPidIndex.edges.spec.ts +125 -0
- package/ts/globalPidIndex.ts +6 -2
- package/ts/index.ts +13 -1
- package/ts/interruptSend.bun.spec.ts +99 -0
- package/ts/interruptSend.spec.ts +99 -0
- package/ts/interruptSend.ts +51 -0
- package/ts/lockRegistry.spec.ts +49 -0
- package/ts/lsRenderCache.spec.ts +58 -0
- package/ts/needsInput.edges.spec.ts +23 -0
- package/ts/parseCliArgs.ts +7 -0
- package/ts/pushGatePlan.spec.ts +147 -0
- package/ts/roomReplyAlias.io.spec.ts +81 -0
- package/ts/schedule.ts +5 -1
- package/ts/schedules.bun.spec.ts +397 -0
- package/ts/schedules.spec.ts +397 -0
- package/ts/schedules.ts +517 -0
- package/ts/schedulesCli.ts +386 -0
- package/ts/sendControl.bun.spec.ts +12 -0
- package/ts/senderAncestry.ts +1 -3
- package/ts/serve.ts +22 -33
- package/ts/serveRust.spec.ts +29 -2
- package/ts/serveRust.ts +27 -2
- package/ts/sizeNego.bun.spec.ts +9 -2
- package/ts/sizeNego.spec.ts +9 -2
- package/ts/sizeNego.ts +10 -5
- package/ts/subcommands.spec.ts +348 -9
- package/ts/subcommands.ts +513 -93
- package/ts/suggestAgents.spec.ts +33 -0
- package/ts/terminal/browser.ts +1 -1
- package/ts/todoParse.spec.ts +22 -1
- package/ts/todoParse.ts +19 -0
- package/dist/SUPPORTED_CLIS-ByO5twge.js +0 -12
- package/dist/callback-D7qfh_7p.js +0 -16
- package/dist/pidStore-BRlKRHXY.js +0 -6
- package/dist/roomReplyAlias-DuEkSSDI.js +0 -6
- package/dist/spawnGate-DeQBTX-o.js +0 -5
- package/dist/subcommands-DmiswRy4.js +0 -14
- package/dist/trayApp-C4TAvRvU.js +0 -5
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
2
|
+
import { execFileSync, spawnSync } from "child_process";
|
|
3
|
+
import { mkdtemp, mkdir, realpath, rm, writeFile } from "fs/promises";
|
|
4
|
+
import { tmpdir } from "os";
|
|
5
|
+
import path from "path";
|
|
6
|
+
|
|
7
|
+
// The pre-push hook decides from the pushed refs whether a push can skip the
|
|
8
|
+
// test gate. These cases pin the two ways that decision must NOT be lenient:
|
|
9
|
+
// a SKILL.md anywhere in the tree is runtime input (ts/index.ts reads every one
|
|
10
|
+
// from cwd up to the repo root), and a ref with no comparison base says nothing
|
|
11
|
+
// about the code under its tip, so it gets the full gate.
|
|
12
|
+
const SCRIPT = path.resolve(__dirname, "..", ".husky", "push-gate-plan.sh");
|
|
13
|
+
const ZERO = "0".repeat(40);
|
|
14
|
+
|
|
15
|
+
// A scratch repo must not inherit GIT_DIR & co from a hook or a worktree, or
|
|
16
|
+
// `git init` here would point at the real repository.
|
|
17
|
+
const env = Object.fromEntries(
|
|
18
|
+
Object.entries(process.env).filter(([k]) => !k.startsWith("GIT_")),
|
|
19
|
+
) as NodeJS.ProcessEnv;
|
|
20
|
+
|
|
21
|
+
function git(cwd: string, ...args: string[]): string {
|
|
22
|
+
return execFileSync(
|
|
23
|
+
"git",
|
|
24
|
+
["-c", "user.name=alice", "-c", "user.email=alice@example.invalid", ...args],
|
|
25
|
+
{ cwd, env, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] },
|
|
26
|
+
).trim();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function commit(
|
|
30
|
+
cwd: string,
|
|
31
|
+
files: Record<string, string>,
|
|
32
|
+
message: string,
|
|
33
|
+
): Promise<string> {
|
|
34
|
+
for (const [file, body] of Object.entries(files)) {
|
|
35
|
+
await mkdir(path.dirname(path.join(cwd, file)), { recursive: true });
|
|
36
|
+
await writeFile(path.join(cwd, file), body);
|
|
37
|
+
}
|
|
38
|
+
git(cwd, "add", "-A");
|
|
39
|
+
git(cwd, "commit", "-q", "--allow-empty", "-m", message);
|
|
40
|
+
return git(cwd, "rev-parse", "HEAD");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function plan(cwd: string, refLines: string): { mode: string; files: string[] } {
|
|
44
|
+
const out = spawnSync("sh", [SCRIPT], { cwd, env, input: refLines, encoding: "utf8" });
|
|
45
|
+
expect(out.status, out.stderr).toBe(0);
|
|
46
|
+
const [mode = "", ...files] = out.stdout.split("\n").filter(Boolean);
|
|
47
|
+
return { mode, files };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe.skipIf(process.platform === "win32")("pre-push gate plan", () => {
|
|
51
|
+
let repo: string;
|
|
52
|
+
let main: string;
|
|
53
|
+
|
|
54
|
+
beforeAll(async () => {
|
|
55
|
+
repo = await realpath(await mkdtemp(path.join(tmpdir(), "ay-push-gate-")));
|
|
56
|
+
git(repo, "init", "-q", "-b", "main");
|
|
57
|
+
main = await commit(
|
|
58
|
+
repo,
|
|
59
|
+
{ "README.md": "# alpha\n", "ts/runtime.ts": "export const v = 1;\n" },
|
|
60
|
+
"init",
|
|
61
|
+
);
|
|
62
|
+
// What the hook compares a new branch against.
|
|
63
|
+
git(repo, "update-ref", "refs/remotes/origin/main", main);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
afterAll(async () => {
|
|
67
|
+
await rm(repo, { recursive: true, force: true });
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("runs the full gate with no ref information", () => {
|
|
71
|
+
expect(plan(repo, "").mode).toBe("full");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("skips a deletion-only push", () => {
|
|
75
|
+
expect(plan(repo, `(delete) ${ZERO} refs/heads/old ${main}\n`).mode).toBe("deletion");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("skips a prose-only push and lists its files", async () => {
|
|
79
|
+
git(repo, "checkout", "-q", "-b", "docs-only", main);
|
|
80
|
+
const tip = await commit(repo, { "docs/guide.md": "words\n", "README.md": "# beta\n" }, "docs");
|
|
81
|
+
const got = plan(repo, `refs/heads/docs-only ${tip} refs/heads/docs-only ${ZERO}\n`);
|
|
82
|
+
expect(got.mode).toBe("prose");
|
|
83
|
+
expect(got.files.sort()).toEqual(["README.md", "docs/guide.md"]);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("treats a code change as full, against the remote sha when it is known", async () => {
|
|
87
|
+
git(repo, "checkout", "-q", "-b", "code", main);
|
|
88
|
+
const tip = await commit(repo, { "ts/runtime.ts": "export const v = 2;\n" }, "code");
|
|
89
|
+
expect(plan(repo, `refs/heads/code ${tip} refs/heads/code ${main}\n`)).toEqual({
|
|
90
|
+
mode: "full",
|
|
91
|
+
files: ["ts/runtime.ts"],
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// ts/index.ts reads every SKILL.md between cwd and the repo root, so a nested
|
|
96
|
+
// one is runtime input, not prose — the root file was the only exemption before.
|
|
97
|
+
it.each(["SKILL.md", "feature/SKILL.md", "docs/SKILL.md"])(
|
|
98
|
+
"treats %s as code, not prose",
|
|
99
|
+
async (file) => {
|
|
100
|
+
git(repo, "checkout", "-q", "-b", `skill-${file.replace(/\W/g, "-")}`, main);
|
|
101
|
+
const tip = await commit(repo, { [file]: "# skill\n" }, "skill");
|
|
102
|
+
const got = plan(repo, `refs/heads/x ${tip} refs/heads/x ${ZERO}\n`);
|
|
103
|
+
expect(got.mode).toBe("full");
|
|
104
|
+
expect(got.files).toEqual([file]);
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
it("still skips a prose push that merely sits next to an unchanged SKILL.md", async () => {
|
|
109
|
+
git(repo, "checkout", "-q", "-b", "near-skill", main);
|
|
110
|
+
await commit(repo, { "feature/SKILL.md": "# skill\n" }, "skill");
|
|
111
|
+
const base = git(repo, "rev-parse", "HEAD");
|
|
112
|
+
const tip = await commit(repo, { "feature/notes.md": "notes\n" }, "notes");
|
|
113
|
+
expect(plan(repo, `refs/heads/near-skill ${tip} refs/heads/near-skill ${base}\n`).mode).toBe(
|
|
114
|
+
"prose",
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// A branch with no common ancestor: its tip is README-only, but the commit
|
|
119
|
+
// under it ships code. Inspecting the tip alone would skip the gate.
|
|
120
|
+
it("runs the full gate when a new branch has no merge base with origin/main", async () => {
|
|
121
|
+
git(repo, "checkout", "-q", "--orphan", "unrelated");
|
|
122
|
+
git(repo, "rm", "-rfq", "--cached", ".");
|
|
123
|
+
await commit(repo, { "ts/runtime.ts": "export const v = 3;\n" }, "code first");
|
|
124
|
+
const tip = await commit(repo, { "README.md": "# unrelated\n" }, "readme tip");
|
|
125
|
+
expect(plan(repo, `refs/heads/unrelated ${tip} refs/heads/unrelated ${ZERO}\n`)).toEqual({
|
|
126
|
+
mode: "full",
|
|
127
|
+
files: [],
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("runs the full gate when the remote sha is unknown and there is no merge base", async () => {
|
|
132
|
+
const tip = git(repo, "rev-parse", "unrelated");
|
|
133
|
+
const unknownRemote = "1".repeat(40);
|
|
134
|
+
expect(
|
|
135
|
+
plan(repo, `refs/heads/unrelated ${tip} refs/heads/unrelated ${unknownRemote}\n`).mode,
|
|
136
|
+
).toBe("full");
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("needs every ref to have a base before it will skip", async () => {
|
|
140
|
+
const docs = git(repo, "rev-parse", "docs-only");
|
|
141
|
+
const unrelated = git(repo, "rev-parse", "unrelated");
|
|
142
|
+
const lines =
|
|
143
|
+
`refs/heads/docs-only ${docs} refs/heads/docs-only ${ZERO}\n` +
|
|
144
|
+
`refs/heads/unrelated ${unrelated} refs/heads/unrelated ${ZERO}\n`;
|
|
145
|
+
expect(plan(repo, lines).mode).toBe("full");
|
|
146
|
+
});
|
|
147
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import path from "path";
|
|
3
|
+
const io = vi.hoisted(() => ({ read: vi.fn(), remotes: vi.fn() }));
|
|
4
|
+
vi.mock("fs/promises", () => ({ readFile: io.read }));
|
|
5
|
+
vi.mock("./remotes.ts", () => ({ readRemotes: io.remotes }));
|
|
6
|
+
vi.mock("os", () => ({ hostname: () => "example-host", homedir: () => "/home/example" }));
|
|
7
|
+
import { fillRoomAlias, hostedRoomMember, roomAliases } from "./roomReplyAlias.ts";
|
|
8
|
+
|
|
9
|
+
describe("room reply routes and host identity", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
vi.stubEnv("AGENT_YES_HOME", "/state/example");
|
|
12
|
+
vi.stubEnv("AY_NAME", " example-member ");
|
|
13
|
+
io.read.mockReset().mockResolvedValue("1111\n");
|
|
14
|
+
io.remotes.mockReset().mockResolvedValue(new Map());
|
|
15
|
+
vi.spyOn(process, "kill").mockReturnValue(true);
|
|
16
|
+
});
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
vi.restoreAllMocks();
|
|
19
|
+
vi.unstubAllEnvs();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("fills a header without a newline and preserves unknown placeholders", () => {
|
|
23
|
+
expect(fillRoomAlias("<ay-msg ab <alias-for-room-r1>>", () => "fleet")).toBe(
|
|
24
|
+
"<ay-msg ab fleet>",
|
|
25
|
+
);
|
|
26
|
+
expect(fillRoomAlias("<ay-msg ab <alias-for-room-r1>>", () => undefined)).toBe(
|
|
27
|
+
"<ay-msg ab <alias-for-room-r1>>",
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
it("chooses the first alias for each valid share room and ignores non-share remotes", async () => {
|
|
31
|
+
const link = `webrtc://room-a:e1.${"a".repeat(64)}@signal.example`;
|
|
32
|
+
io.remotes.mockResolvedValue(
|
|
33
|
+
new Map([
|
|
34
|
+
["first", { url: link }],
|
|
35
|
+
["duplicate", { url: link }],
|
|
36
|
+
["http", { url: "https://example.invalid" }],
|
|
37
|
+
["missing", {}],
|
|
38
|
+
["null", null],
|
|
39
|
+
]),
|
|
40
|
+
);
|
|
41
|
+
expect(await roomAliases()).toEqual(new Map([["room-a", "first"]]));
|
|
42
|
+
});
|
|
43
|
+
it("returns an empty alias map when remote configuration cannot be read", async () => {
|
|
44
|
+
io.remotes.mockRejectedValue(new Error("unreadable configuration"));
|
|
45
|
+
expect(await roomAliases()).toEqual(new Map());
|
|
46
|
+
});
|
|
47
|
+
it("does not read a host lock without a room", async () => {
|
|
48
|
+
expect(await hostedRoomMember(undefined)).toBeUndefined();
|
|
49
|
+
expect(io.read).not.toHaveBeenCalled();
|
|
50
|
+
});
|
|
51
|
+
it("uses the configured member name for a live host lock", async () => {
|
|
52
|
+
expect(await hostedRoomMember("room-a")).toEqual({ id: "room-a", member: "example-member" });
|
|
53
|
+
expect(io.read).toHaveBeenCalledWith(
|
|
54
|
+
path.join("/state/example", ".share-host-room-a.pid"),
|
|
55
|
+
"utf-8",
|
|
56
|
+
);
|
|
57
|
+
expect(process.kill).toHaveBeenCalledWith(1111, 0);
|
|
58
|
+
});
|
|
59
|
+
it("falls back to the hostname for an empty member name or an inaccessible live pid", async () => {
|
|
60
|
+
vi.stubEnv("AY_NAME", " ");
|
|
61
|
+
vi.mocked(process.kill).mockImplementation(() => {
|
|
62
|
+
throw Object.assign(new Error("denied"), { code: "EPERM" });
|
|
63
|
+
});
|
|
64
|
+
expect(await hostedRoomMember("room-a")).toEqual({ id: "room-a", member: "example-host" });
|
|
65
|
+
vi.stubEnv("AY_NAME", undefined);
|
|
66
|
+
expect(await hostedRoomMember("room-a")).toEqual({ id: "room-a", member: "example-host" });
|
|
67
|
+
});
|
|
68
|
+
it("ignores invalid, missing and stale host locks", async () => {
|
|
69
|
+
for (const value of ["0", "-1", "not a pid"]) {
|
|
70
|
+
io.read.mockResolvedValue(value);
|
|
71
|
+
expect(await hostedRoomMember("room-a")).toBeUndefined();
|
|
72
|
+
}
|
|
73
|
+
io.read.mockRejectedValue(Object.assign(new Error("missing"), { code: "ENOENT" }));
|
|
74
|
+
expect(await hostedRoomMember("room-a")).toBeUndefined();
|
|
75
|
+
io.read.mockResolvedValue("1111");
|
|
76
|
+
vi.mocked(process.kill).mockImplementation(() => {
|
|
77
|
+
throw Object.assign(new Error("gone"), { code: "ESRCH" });
|
|
78
|
+
});
|
|
79
|
+
expect(await hostedRoomMember("room-a")).toBeUndefined();
|
|
80
|
+
});
|
|
81
|
+
});
|
package/ts/schedule.ts
CHANGED
|
@@ -81,7 +81,11 @@ export async function cmdSchedule(rest: string[]): Promise<number> {
|
|
|
81
81
|
if (sub === "list" || sub === "ls") {
|
|
82
82
|
// oxmgr lists everything; scheduled agents are the agent-yes-cron-* rows.
|
|
83
83
|
process.stdout.write(`scheduled agents are named '${SCHED_PREFIX}*':\n`);
|
|
84
|
-
|
|
84
|
+
const code = (await run([oxmgrBin, "list"])).code;
|
|
85
|
+
// the shared store's `ay cron` reminders (one listing for both: ay schedules ls)
|
|
86
|
+
process.stdout.write(`\nay cron reminders (fired by the scheduler daemon):\n`);
|
|
87
|
+
await (await import("./schedulesCli.ts")).cmdCron(["ls"]);
|
|
88
|
+
return code;
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
if (sub === "remove" || sub === "rm" || sub === "delete") {
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import {
|
|
4
|
+
type RunState,
|
|
5
|
+
type StoreEntry,
|
|
6
|
+
cronError,
|
|
7
|
+
dueNow,
|
|
8
|
+
fmtTime,
|
|
9
|
+
launchdDaemonPlist,
|
|
10
|
+
legacyRows,
|
|
11
|
+
logFile,
|
|
12
|
+
MAX_SLEEP_MS,
|
|
13
|
+
nextCronId,
|
|
14
|
+
nextRuns,
|
|
15
|
+
parseCron,
|
|
16
|
+
parseCronAdd,
|
|
17
|
+
parseState,
|
|
18
|
+
parseStore,
|
|
19
|
+
pickAutostart,
|
|
20
|
+
renderMessage,
|
|
21
|
+
resolveTarget,
|
|
22
|
+
stateFile,
|
|
23
|
+
storeFile,
|
|
24
|
+
systemdDaemonUnit,
|
|
25
|
+
tick,
|
|
26
|
+
validTz,
|
|
27
|
+
wakeDelay,
|
|
28
|
+
windowsTaskArgs,
|
|
29
|
+
} from "./schedules.ts";
|
|
30
|
+
|
|
31
|
+
const TZ = "Asia/Tokyo";
|
|
32
|
+
// 2026-01-05 (Mon) 00:00 Asia/Tokyo == 2026-01-04T15:00Z
|
|
33
|
+
const T0 = Date.UTC(2026, 0, 4, 15, 0);
|
|
34
|
+
const MIN = 60000;
|
|
35
|
+
const fmt = (ms: number[], tz = TZ) => ms.map((t) => fmtTime(t, tz).slice(0, 16));
|
|
36
|
+
|
|
37
|
+
function entry(over: Partial<StoreEntry> = {}): StoreEntry {
|
|
38
|
+
return {
|
|
39
|
+
name: "c1",
|
|
40
|
+
cron: "*/5 * * * *",
|
|
41
|
+
tz: TZ,
|
|
42
|
+
target: "lane:alpha",
|
|
43
|
+
message: "ping {name} at {now}",
|
|
44
|
+
enabled: true,
|
|
45
|
+
missed: "skip",
|
|
46
|
+
source: "cron",
|
|
47
|
+
since: 0,
|
|
48
|
+
...over,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
describe("parseCron", () => {
|
|
53
|
+
it("expands steps, ranges, lists, names and dow 7", () => {
|
|
54
|
+
const c = parseCron("*/15 9-11,14 1,15 jan-mar 5-7");
|
|
55
|
+
expect(c.minute.values).toEqual([0, 15, 30, 45]);
|
|
56
|
+
expect(c.minute.star).toBe(false);
|
|
57
|
+
expect(c.hour.values).toEqual([9, 10, 11, 14]);
|
|
58
|
+
expect(c.dom.values).toEqual([1, 15]);
|
|
59
|
+
expect(c.month.values).toEqual([1, 2, 3]);
|
|
60
|
+
expect(c.dow.values).toEqual([0, 5, 6]);
|
|
61
|
+
expect(parseCron("* * * * *").dow.star).toBe(true);
|
|
62
|
+
expect(parseCron("5/20 * * * MON").minute.values).toEqual([5, 25, 45]);
|
|
63
|
+
expect(parseCron("0 0 * * */2").dow.values).toEqual([0, 2, 4, 6]);
|
|
64
|
+
expect(parseCron("10-30/10 * * * *").minute.values).toEqual([10, 20, 30]);
|
|
65
|
+
});
|
|
66
|
+
it("rejects bad expressions", () => {
|
|
67
|
+
expect(cronError("* * * *")).toMatch(/5 fields/);
|
|
68
|
+
expect(cronError("60 * * * *")).toMatch(/minute: 60 out of range/);
|
|
69
|
+
expect(cronError("* 5-2 * * *")).toMatch(/backwards/);
|
|
70
|
+
expect(cronError("*/0 * * * *")).toMatch(/bad step/);
|
|
71
|
+
expect(cronError("*/x * * * *")).toMatch(/bad step/);
|
|
72
|
+
expect(cronError("1/2/3 * * * *")).toMatch(/bad term/);
|
|
73
|
+
expect(cronError(", * * * *")).toMatch(/bad term/);
|
|
74
|
+
expect(cronError("* * * foo *")).toMatch(/not a number/);
|
|
75
|
+
expect(cronError("0 9 * * 1-5")).toBeNull();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe("nextRuns", () => {
|
|
80
|
+
it("*/5 in the given tz", () => {
|
|
81
|
+
expect(fmt(nextRuns("*/5 * * * *", TZ, T0, 3))).toEqual([
|
|
82
|
+
"2026-01-05 00:05",
|
|
83
|
+
"2026-01-05 00:10",
|
|
84
|
+
"2026-01-05 00:15",
|
|
85
|
+
]);
|
|
86
|
+
});
|
|
87
|
+
it("ranges and lists; weekdays only", () => {
|
|
88
|
+
// Fri 2026-01-09 17:40 -> next: Fri 18:00, then Mon 09:00
|
|
89
|
+
const fri = Date.UTC(2026, 0, 9, 8, 40);
|
|
90
|
+
expect(fmt(nextRuns("0,30 9-18 * * 1-5", TZ, fri, 3))).toEqual([
|
|
91
|
+
"2026-01-09 18:00",
|
|
92
|
+
"2026-01-09 18:30",
|
|
93
|
+
"2026-01-12 09:00",
|
|
94
|
+
]);
|
|
95
|
+
});
|
|
96
|
+
it("same instant in another tz is a different wall clock", () => {
|
|
97
|
+
const [ny] = nextRuns("0 9 * * *", "America/New_York", T0, 1);
|
|
98
|
+
expect(new Date(ny!).toISOString()).toBe("2026-01-05T14:00:00.000Z");
|
|
99
|
+
const [tk] = nextRuns("0 9 * * *", TZ, T0, 1);
|
|
100
|
+
expect(new Date(tk!).toISOString()).toBe("2026-01-05T00:00:00.000Z");
|
|
101
|
+
});
|
|
102
|
+
it("dom and dow both restricted: either matches (cron OR)", () => {
|
|
103
|
+
// 2026-01-05 Mon: the 13th (Tue) OR Fridays
|
|
104
|
+
expect(fmt(nextRuns("0 0 13 * 5", TZ, T0, 3))).toEqual([
|
|
105
|
+
"2026-01-09 00:00",
|
|
106
|
+
"2026-01-13 00:00",
|
|
107
|
+
"2026-01-16 00:00",
|
|
108
|
+
]);
|
|
109
|
+
});
|
|
110
|
+
it("months and impossible dates", () => {
|
|
111
|
+
expect(fmt(nextRuns("0 12 1 mar *", TZ, T0, 1))).toEqual(["2026-03-01 12:00"]);
|
|
112
|
+
expect(nextRuns("0 0 31 2 *", TZ, T0, 1)).toEqual([]);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe("parseCronAdd", () => {
|
|
117
|
+
it("parses quoted and unquoted cron", () => {
|
|
118
|
+
expect(parseCronAdd(["*/10 * * * *", "lane:alpha", "send", "progress"], {})).toEqual({
|
|
119
|
+
ok: true,
|
|
120
|
+
cron: "*/10 * * * *",
|
|
121
|
+
tz: TZ,
|
|
122
|
+
target: "lane:alpha",
|
|
123
|
+
message: "send progress",
|
|
124
|
+
});
|
|
125
|
+
const r = parseCronAdd(["0", "9", "*", "*", "1-5", "1111", "hi"], { AY_CRON_TZ: "UTC" });
|
|
126
|
+
expect(r).toMatchObject({ ok: true, cron: "0 9 * * 1-5", tz: "UTC", target: "1111" });
|
|
127
|
+
});
|
|
128
|
+
it("validates", () => {
|
|
129
|
+
expect(parseCronAdd(["* * * * *", "x"], {})).toMatchObject({
|
|
130
|
+
ok: false,
|
|
131
|
+
error: expect.stringMatching(/usage/),
|
|
132
|
+
});
|
|
133
|
+
expect(parseCronAdd(["61 * * * *", "x", "m"], {})).toMatchObject({
|
|
134
|
+
ok: false,
|
|
135
|
+
error: expect.stringMatching(/bad cron/),
|
|
136
|
+
});
|
|
137
|
+
expect(parseCronAdd(["* * * * *", "x", "m"], { AY_CRON_TZ: "Mars/Base" })).toMatchObject({
|
|
138
|
+
ok: false,
|
|
139
|
+
error: expect.stringMatching(/unknown tz/),
|
|
140
|
+
});
|
|
141
|
+
expect(parseCronAdd(["* * * * *", "lane:", "m"], {})).toMatchObject({
|
|
142
|
+
ok: false,
|
|
143
|
+
error: expect.stringMatching(/lane name/),
|
|
144
|
+
});
|
|
145
|
+
expect(validTz(TZ)).toBe(true);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe("store", () => {
|
|
150
|
+
it("parses store and state defensively", () => {
|
|
151
|
+
expect(parseStore(null)).toEqual({ version: 1, entries: [] });
|
|
152
|
+
expect(parseStore('{"entries":{}}').entries).toEqual([]);
|
|
153
|
+
expect(parseStore(JSON.stringify({ entries: [entry()] })).entries[0]!.name).toBe("c1");
|
|
154
|
+
expect(parseState(null)).toEqual({ lastTick: 0, last: {} });
|
|
155
|
+
expect(parseState("{bad")).toEqual({ lastTick: 0, last: {} });
|
|
156
|
+
expect(parseState('{"lastTick":5,"last":{"a":{"at":1,"ok":true,"code":0}}}').last.a!.ok).toBe(
|
|
157
|
+
true,
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
it("allocates ids", () => {
|
|
161
|
+
expect(nextCronId({ version: 1, entries: [] })).toBe("c1");
|
|
162
|
+
expect(
|
|
163
|
+
nextCronId({ version: 1, entries: [entry({ name: "c1" }), entry({ name: "c3" })] }),
|
|
164
|
+
).toBe("c2");
|
|
165
|
+
});
|
|
166
|
+
it("paths honor env", () => {
|
|
167
|
+
expect(storeFile({ AY_SCHEDULES_STORE: "/s" })).toBe("/s");
|
|
168
|
+
expect(stateFile({ AY_SCHEDULES_STATE: "/t" })).toBe("/t");
|
|
169
|
+
expect(logFile({ AY_SCHEDULES_LOG: "/l" })).toBe("/l");
|
|
170
|
+
expect(storeFile({}, "/home/alice")).toBe(
|
|
171
|
+
path.join("/home/alice", ".config", "agent-yes", "schedules.json"),
|
|
172
|
+
);
|
|
173
|
+
expect(stateFile({}, "/home/alice")).toMatch(/schedules\.state\.json$/);
|
|
174
|
+
expect(logFile({}, "/home/alice")).toBe(
|
|
175
|
+
path.join("/home/alice", ".local", "share", "agent-yes", "schedules.log"),
|
|
176
|
+
);
|
|
177
|
+
});
|
|
178
|
+
it("renders messages", () => {
|
|
179
|
+
expect(renderMessage(entry(), T0)).toBe("ping c1 at 2026-01-05 00:00 Asia/Tokyo");
|
|
180
|
+
});
|
|
181
|
+
it("legacy oxmgr rows", () => {
|
|
182
|
+
expect(legacyRows("id name\n1 agent-yes-cron-a\n2 other\n")).toEqual(["1 agent-yes-cron-a"]);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
/** Run the daemon loop against a fake clock: one tick per minute, recording fires. */
|
|
187
|
+
function simulate(entries: StoreEntry[], st: RunState, from: number, minutes: number) {
|
|
188
|
+
const fired: string[] = [];
|
|
189
|
+
for (let i = 0; i < minutes; i++) {
|
|
190
|
+
const now = from + i * MIN + 50;
|
|
191
|
+
for (const e of dueNow(entries, st, now)) {
|
|
192
|
+
fired.push(`${e.name}@${fmtTime(now, TZ).slice(11, 16)}`);
|
|
193
|
+
st.last[e.name] = { at: now, ok: true, code: 0 };
|
|
194
|
+
}
|
|
195
|
+
st.lastTick = now;
|
|
196
|
+
}
|
|
197
|
+
return fired;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
describe("scheduler loop (fake clock)", () => {
|
|
201
|
+
it("fires */5 on time, once per slot", () => {
|
|
202
|
+
const st: RunState = { lastTick: T0 - MIN, last: {} };
|
|
203
|
+
expect(simulate([entry()], st, T0, 16)).toEqual([
|
|
204
|
+
"c1@00:00",
|
|
205
|
+
"c1@00:05",
|
|
206
|
+
"c1@00:10",
|
|
207
|
+
"c1@00:15",
|
|
208
|
+
]);
|
|
209
|
+
});
|
|
210
|
+
it("every minute fires every minute", () => {
|
|
211
|
+
const st: RunState = { lastTick: T0 - 30000, last: {} };
|
|
212
|
+
expect(simulate([entry({ cron: "* * * * *", since: T0 - 30000 })], st, T0, 3)).toEqual([
|
|
213
|
+
"c1@00:00",
|
|
214
|
+
"c1@00:01",
|
|
215
|
+
"c1@00:02",
|
|
216
|
+
]);
|
|
217
|
+
});
|
|
218
|
+
it("does not fire before an entry was added", () => {
|
|
219
|
+
const st: RunState = { lastTick: T0 - MIN, last: {} };
|
|
220
|
+
expect(simulate([entry({ since: T0 + 2 * MIN })], st, T0, 6)).toEqual(["c1@00:05"]);
|
|
221
|
+
});
|
|
222
|
+
it("skips disabled entries", () => {
|
|
223
|
+
expect(simulate([entry({ enabled: false })], { lastTick: T0 - MIN, last: {} }, T0, 10)).toEqual(
|
|
224
|
+
[],
|
|
225
|
+
);
|
|
226
|
+
});
|
|
227
|
+
it("restart after downtime: missed=skip fires nothing for the gap", () => {
|
|
228
|
+
const st: RunState = { lastTick: T0, last: {} };
|
|
229
|
+
// daemon down 00:01..00:32, restarts at 00:33
|
|
230
|
+
expect(dueNow([entry()], st, T0 + 33 * MIN)).toEqual([]);
|
|
231
|
+
});
|
|
232
|
+
it("restart after downtime: missed=run-once fires exactly once", () => {
|
|
233
|
+
const st: RunState = { lastTick: T0, last: {} };
|
|
234
|
+
const e = entry({ cron: "0 * * * *", missed: "run-once" });
|
|
235
|
+
expect(simulate([e], st, T0 + 200 * MIN, 3)).toEqual(["c1@03:20"]);
|
|
236
|
+
});
|
|
237
|
+
it("restart exactly on a slot still fires it (on time)", () => {
|
|
238
|
+
const st: RunState = { lastTick: T0, last: {} };
|
|
239
|
+
expect(dueNow([entry()], st, T0 + 30 * MIN + 50).map((e) => e.name)).toEqual(["c1"]);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Event-driven daemon on a fake clock: sleep wakeDelay(), unless the store changes
|
|
245
|
+
* first (`changes`: at -> new entries) or the machine suspends (`suspend`: the
|
|
246
|
+
* wake that was due at or after `from` happens at `until`).
|
|
247
|
+
*/
|
|
248
|
+
function runDaemon(
|
|
249
|
+
initial: StoreEntry[],
|
|
250
|
+
start: number,
|
|
251
|
+
end: number,
|
|
252
|
+
o: {
|
|
253
|
+
changes?: [number, StoreEntry[]][];
|
|
254
|
+
suspend?: { from: number; until: number };
|
|
255
|
+
state?: RunState;
|
|
256
|
+
} = {},
|
|
257
|
+
) {
|
|
258
|
+
let entries = initial;
|
|
259
|
+
let st: RunState = o.state ?? { lastTick: 0, last: {} };
|
|
260
|
+
let now = start;
|
|
261
|
+
const changes = [...(o.changes ?? [])];
|
|
262
|
+
const fired: string[] = [];
|
|
263
|
+
const wakes: string[] = [];
|
|
264
|
+
let suspended = false;
|
|
265
|
+
for (;;) {
|
|
266
|
+
const t = tick(entries, st, now);
|
|
267
|
+
for (const e of t.fire) {
|
|
268
|
+
fired.push(`${e.name}@${fmtTime(now, TZ).slice(11, 16)}`);
|
|
269
|
+
t.state.last[e.name] = { at: now, ok: true, code: 0 };
|
|
270
|
+
}
|
|
271
|
+
st = t.state;
|
|
272
|
+
let next = now + wakeDelay(entries, now);
|
|
273
|
+
if (changes.length && changes[0]![0] < next) {
|
|
274
|
+
const [at, es] = changes.shift()!;
|
|
275
|
+
next = at;
|
|
276
|
+
entries = es;
|
|
277
|
+
}
|
|
278
|
+
if (o.suspend && !suspended && next >= o.suspend.from) {
|
|
279
|
+
suspended = true;
|
|
280
|
+
next = o.suspend.until;
|
|
281
|
+
}
|
|
282
|
+
if (next > end) break;
|
|
283
|
+
now = next;
|
|
284
|
+
wakes.push(fmtTime(now, TZ).slice(11, 16));
|
|
285
|
+
}
|
|
286
|
+
return { fired, wakes };
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
describe("daemon wake-ups (no polling)", () => {
|
|
290
|
+
const hourly = entry({ name: "h", cron: "0 * * * *" });
|
|
291
|
+
it("sleeps until the earliest next fire, capped at a day", () => {
|
|
292
|
+
expect(wakeDelay([hourly, entry({ cron: "*/20 * * * *" })], T0 + 10 * MIN)).toBe(10 * MIN + 50);
|
|
293
|
+
expect(wakeDelay([], T0)).toBe(MAX_SLEEP_MS);
|
|
294
|
+
expect(wakeDelay([entry({ enabled: false })], T0)).toBe(MAX_SLEEP_MS);
|
|
295
|
+
expect(wakeDelay([entry({ cron: "0 0 1 1 *" })], T0)).toBe(MAX_SLEEP_MS);
|
|
296
|
+
});
|
|
297
|
+
it("wakes only at fire times and re-arms after each", () => {
|
|
298
|
+
const r = runDaemon([hourly], T0 + 10 * MIN, T0 + 3 * 60 * MIN + MIN);
|
|
299
|
+
expect(r.fired).toEqual(["h@01:00", "h@02:00", "h@03:00"]);
|
|
300
|
+
expect(r.wakes).toEqual(["01:00", "02:00", "03:00"]);
|
|
301
|
+
});
|
|
302
|
+
it("store changed while sleeping: re-plans at once", () => {
|
|
303
|
+
const r = runDaemon([hourly], T0 + 10 * MIN, T0 + 51 * MIN, {
|
|
304
|
+
changes: [[T0 + 31 * MIN, [hourly, entry({ name: "c2", since: T0 + 31 * MIN })]]],
|
|
305
|
+
});
|
|
306
|
+
expect(r.wakes.slice(0, 3)).toEqual(["00:31", "00:35", "00:40"]);
|
|
307
|
+
expect(r.fired).toEqual(["c2@00:35", "c2@00:40", "c2@00:45", "c2@00:50"]);
|
|
308
|
+
});
|
|
309
|
+
it("slept past the slot (suspend): skip fires nothing, run-once fires once", () => {
|
|
310
|
+
const sus = { from: T0 + 60 * MIN, until: T0 + 200 * MIN };
|
|
311
|
+
const skip = runDaemon([hourly], T0 + 10 * MIN, T0 + 241 * MIN, { suspend: sus });
|
|
312
|
+
expect(skip.fired).toEqual(["h@04:00"]);
|
|
313
|
+
const once = runDaemon([{ ...hourly, missed: "run-once" }], T0 + 10 * MIN, T0 + 241 * MIN, {
|
|
314
|
+
suspend: sus,
|
|
315
|
+
});
|
|
316
|
+
expect(once.fired).toEqual(["h@03:20", "h@04:00"]);
|
|
317
|
+
});
|
|
318
|
+
it("clock jumped backwards: no replay, resumes from the new time", () => {
|
|
319
|
+
const st: RunState = {
|
|
320
|
+
lastTick: T0 + 120 * MIN,
|
|
321
|
+
last: { h: { at: T0 + 120 * MIN, ok: true, code: 0 } },
|
|
322
|
+
};
|
|
323
|
+
const t = tick([hourly], st, T0 + 30 * MIN);
|
|
324
|
+
expect(t.clockBack).toBe(true);
|
|
325
|
+
expect(t.fire).toEqual([]);
|
|
326
|
+
expect(t.state.lastTick).toBe(T0 + 30 * MIN);
|
|
327
|
+
const r = runDaemon([hourly], T0 + 30 * MIN, T0 + 61 * MIN, { state: st });
|
|
328
|
+
expect(r.fired).toEqual(["h@01:00"]);
|
|
329
|
+
});
|
|
330
|
+
it("first start fires nothing missed", () => {
|
|
331
|
+
expect(tick([entry()], { lastTick: 0, last: {} }, T0 + 2 * MIN + 50).fire).toEqual([]);
|
|
332
|
+
expect(tick([entry()], { lastTick: 0, last: {} }, T0 + 50).fire.length).toBe(1);
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
describe("resolveTarget", () => {
|
|
337
|
+
const live = [
|
|
338
|
+
{ pid: 1111, agent_id: "abc123", cwd: "/repo/alpha" },
|
|
339
|
+
{ pid: 2222, agent_id: "abd456", cwd: "/repo/beta" },
|
|
340
|
+
];
|
|
341
|
+
const lane = (ok: boolean, out: string) => () => ({ ok, out });
|
|
342
|
+
it("lanes go through ay lanes id", () => {
|
|
343
|
+
expect(resolveTarget("lane:alpha", live, lane(true, "zz9\n"))).toEqual({
|
|
344
|
+
ok: true,
|
|
345
|
+
agentId: "zz9",
|
|
346
|
+
});
|
|
347
|
+
expect(resolveTarget("lane:alpha", live, lane(false, "no live agent"))).toMatchObject({
|
|
348
|
+
ok: false,
|
|
349
|
+
error: expect.stringMatching(/lane "alpha" has no live agent: no live agent/),
|
|
350
|
+
});
|
|
351
|
+
expect(resolveTarget("lane:alpha", live, lane(false, ""))).toEqual({
|
|
352
|
+
ok: false,
|
|
353
|
+
error: `lane "alpha" has no live agent`,
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
it("agent id, pid, prefix, keyword", () => {
|
|
357
|
+
expect(resolveTarget("abd456", live, lane(false, ""))).toEqual({ ok: true, agentId: "abd456" });
|
|
358
|
+
expect(resolveTarget("1111", live, lane(false, ""))).toEqual({ ok: true, agentId: "abc123" });
|
|
359
|
+
expect(resolveTarget("abc", live, lane(false, ""))).toEqual({ ok: true, agentId: "abc123" });
|
|
360
|
+
expect(resolveTarget("beta", live, lane(false, ""))).toEqual({ ok: true, agentId: "abd456" });
|
|
361
|
+
expect(resolveTarget("ab", live, lane(false, ""))).toMatchObject({
|
|
362
|
+
ok: false,
|
|
363
|
+
error: expect.stringMatching(/matches 2/),
|
|
364
|
+
});
|
|
365
|
+
expect(resolveTarget("gamma", live, lane(false, ""))).toMatchObject({
|
|
366
|
+
ok: false,
|
|
367
|
+
error: expect.stringMatching(/no live agent/),
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
describe("daemon autostart", () => {
|
|
373
|
+
it("prefers oxmgr, then the OS's own", () => {
|
|
374
|
+
const p = (platform: string, hasOxmgr = false, systemdUser = false) =>
|
|
375
|
+
pickAutostart({ platform, hasOxmgr, systemdUser });
|
|
376
|
+
expect(p("linux", true, true)).toBe("oxmgr");
|
|
377
|
+
expect(p("linux", false, true)).toBe("systemd");
|
|
378
|
+
expect(p("linux")).toBe("nohup");
|
|
379
|
+
expect(p("darwin")).toBe("launchd");
|
|
380
|
+
expect(p("win32")).toBe("schtasks");
|
|
381
|
+
expect(p("freebsd")).toBe("nohup");
|
|
382
|
+
});
|
|
383
|
+
it("renders units", () => {
|
|
384
|
+
const u = systemdDaemonUnit(
|
|
385
|
+
["/opt/my bun", "/x/ay.js", "schedules", "daemon", "run"],
|
|
386
|
+
"/usr/bin",
|
|
387
|
+
);
|
|
388
|
+
expect(u).toContain(`ExecStart="/opt/my bun" /x/ay.js schedules daemon run`);
|
|
389
|
+
expect(u).toContain("Restart=always");
|
|
390
|
+
const pl = launchdDaemonPlist(["/x/a&b", "run"], "/usr/bin", "/tmp/l");
|
|
391
|
+
expect(pl).toContain("<string>/x/a&b</string>");
|
|
392
|
+
expect(pl).toContain("<key>KeepAlive</key><true/>");
|
|
393
|
+
expect(windowsTaskArgs(["C:\\Program Files\\ay.exe", "run"])).toContain(
|
|
394
|
+
`"C:\\Program Files\\ay.exe" run`,
|
|
395
|
+
);
|
|
396
|
+
});
|
|
397
|
+
});
|