claude-yes 1.11.2-beta.1 → 1.12.0-beta.1
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/cli.test.ts +61 -52
- package/package.json +7 -1
package/cli.test.ts
CHANGED
|
@@ -1,70 +1,79 @@
|
|
|
1
|
-
import { execaCommand } from
|
|
1
|
+
import { execaCommand } from "execa";
|
|
2
2
|
import { fromStdio } from "from-node-stream";
|
|
3
3
|
import { exec } from "node:child_process";
|
|
4
|
-
import { existsSync } from
|
|
5
|
-
import { readFile, unlink } from
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import { readFile, unlink } from "node:fs/promises";
|
|
6
6
|
import sflow from "sflow";
|
|
7
7
|
import { beforeAll, describe, expect, it } from "vitest";
|
|
8
8
|
import { createIdleWatcher } from "./createIdleWatcher";
|
|
9
|
-
import { sleepms } from
|
|
9
|
+
import { sleepms } from "./utils";
|
|
10
10
|
|
|
11
11
|
beforeAll(async () => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
await execaCommand(`bun run build`).then(() =>
|
|
13
|
+
console.log("Build successful"),
|
|
14
|
+
);
|
|
15
|
+
});
|
|
15
16
|
|
|
16
|
-
describe(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
describe("CLI Tests", () => {
|
|
18
|
+
it("Write file with auto bypass permission prompt", async () => {
|
|
19
|
+
const flagFile = "./.cache/flag.json";
|
|
20
|
+
// clean
|
|
21
|
+
await unlink(flagFile).catch(() => {});
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const p = exec(
|
|
24
|
+
`node dist/cli.js --exit-on-idle=3s "just write {on: 1} into ./.cache/flag.json"`,
|
|
25
|
+
);
|
|
26
|
+
const tr = new TransformStream<string, string>();
|
|
27
|
+
const w = tr.writable.getWriter();
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
const exit = async () =>
|
|
30
|
+
await sflow(["\r", "/exit", "\r", "\r"])
|
|
31
|
+
.forEach(async (e) => {
|
|
32
|
+
await sleepms(200);
|
|
33
|
+
await w.write(e);
|
|
34
|
+
})
|
|
35
|
+
.run();
|
|
30
36
|
|
|
31
|
-
|
|
37
|
+
// ping function to exit claude when idle
|
|
32
38
|
|
|
33
|
-
|
|
39
|
+
const { ping } = createIdleWatcher(() => exit(), 3000);
|
|
34
40
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
const output = await sflow(tr.readable)
|
|
42
|
+
.by(fromStdio(p))
|
|
43
|
+
.log()
|
|
44
|
+
.forEach(() => ping())
|
|
45
|
+
.text();
|
|
38
46
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// expect the file content to be 'on'
|
|
45
|
-
expect(await new Response(await readFile(flagFile)).json()).toEqual({ on: 1 });
|
|
47
|
+
// expect the file exists
|
|
48
|
+
expect(existsSync(flagFile)).toBe(true);
|
|
49
|
+
// expect the output contains the file path
|
|
50
|
+
expect(output).toContain(flagFile);
|
|
46
51
|
|
|
47
|
-
|
|
52
|
+
// expect the file content to be 'on'
|
|
53
|
+
expect(await new Response(await readFile(flagFile)).json()).toEqual({
|
|
54
|
+
on: 1,
|
|
55
|
+
});
|
|
48
56
|
|
|
49
|
-
|
|
50
|
-
}, 30e3);
|
|
57
|
+
expect(p.exitCode).toBe(0); // expect the process to exit successfully
|
|
51
58
|
|
|
52
|
-
it
|
|
53
|
-
|
|
54
|
-
const tr = new TransformStream<string, string>()
|
|
55
|
-
const output = (await sflow(tr.readable).by(fromStdio(p)).log().text())
|
|
56
|
-
expect(output).toContain('hello');
|
|
57
|
-
await sleepms(1000); // wait for process exit
|
|
58
|
-
expect(p.exitCode).toBe(0);
|
|
59
|
-
}, 30e3);
|
|
60
|
-
|
|
61
|
-
it('CLI --exit-on-idle flag with custom timeout', async () => {
|
|
62
|
-
const p = exec(`node dist/cli.js --exit-on-idle=1s "echo hello"`);
|
|
63
|
-
const tr = new TransformStream<string, string>()
|
|
64
|
-
const output = (await sflow(tr.readable).by(fromStdio(p)).log().text())
|
|
65
|
-
expect(output).toContain('hello');
|
|
66
|
-
await sleepms(1000); // wait for process exit
|
|
67
|
-
expect(p.exitCode).toBe(0);
|
|
68
|
-
}, 30e3);
|
|
69
|
-
})
|
|
59
|
+
// 30 seconds timeout for this test, it usually takes 13s to run (10s for claude to solve this problem, 3s for idle watcher to exit)
|
|
60
|
+
}, 30e3);
|
|
70
61
|
|
|
62
|
+
it.skip("CLI --exit-on-idle flag with default timeout", async () => {
|
|
63
|
+
const p = exec(`node dist/cli.js "echo hello" --exit-on-idle`);
|
|
64
|
+
const tr = new TransformStream<string, string>();
|
|
65
|
+
const output = await sflow(tr.readable).by(fromStdio(p)).log().text();
|
|
66
|
+
expect(output).toContain("hello");
|
|
67
|
+
await sleepms(1000); // wait for process exit
|
|
68
|
+
expect(p.exitCode).toBe(0);
|
|
69
|
+
}, 30e3);
|
|
70
|
+
|
|
71
|
+
it("CLI --exit-on-idle flag with custom timeout", async () => {
|
|
72
|
+
const p = exec(`node dist/cli.js --exit-on-idle=1s "echo hello"`);
|
|
73
|
+
const tr = new TransformStream<string, string>();
|
|
74
|
+
const output = await sflow(tr.readable).by(fromStdio(p)).log().text();
|
|
75
|
+
expect(output).toContain("hello");
|
|
76
|
+
await sleepms(1000); // wait for process exit
|
|
77
|
+
expect(p.exitCode).toBe(0);
|
|
78
|
+
}, 30e3);
|
|
79
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-yes",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0-beta.1",
|
|
4
4
|
"homepage": "https://github.com/snomiao/claude-yes#readme",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "snomiao <snomiao@gmail.com>",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"execa": "^9.6.0",
|
|
42
42
|
"from-node-stream": "^0.0.11",
|
|
43
43
|
"husky": "^9.1.7",
|
|
44
|
+
"lint-staged": "^16.1.4",
|
|
44
45
|
"minimist": "^1.2.8",
|
|
45
46
|
"prettier": "^3.6.2",
|
|
46
47
|
"semantic-release": "^24.2.6",
|
|
@@ -63,6 +64,11 @@
|
|
|
63
64
|
"bun-pty": "^0.3.2",
|
|
64
65
|
"node-pty": "^1.0.0"
|
|
65
66
|
},
|
|
67
|
+
"lint-staged": {
|
|
68
|
+
"*.{ts,js,json,md}": [
|
|
69
|
+
"prettier --write"
|
|
70
|
+
]
|
|
71
|
+
},
|
|
66
72
|
"description": "A wrapper tool that automates interactions with the Claude CLI by automatically handling common prompts and responses.",
|
|
67
73
|
"main": "index.js",
|
|
68
74
|
"directories": {
|