@nightloom/isy 1.0.6-next.0 → 1.0.7-next.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 +7 -5
- package/dist/agents/codex-records.js +10 -1
- package/dist/agents/codex-records.js.map +1 -1
- package/dist/commands/commit.js +21 -1
- package/dist/commands/commit.js.map +1 -1
- package/dist/commands/upload.d.ts +1 -0
- package/dist/commands/upload.js +13 -5
- package/dist/commands/upload.js.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/parser.js +1 -0
- package/dist/parser.js.map +1 -1
- package/dist/redact.js +12 -5
- package/dist/redact.js.map +1 -1
- package/dist/subagents.js +7 -5
- package/dist/subagents.js.map +1 -1
- package/package.json +3 -2
- package/src/agents/codex-records.ts +10 -1
- package/src/commands/commit.ts +22 -1
- package/src/commands/upload.ts +13 -6
- package/src/index.ts +8 -2
- package/src/parser.ts +1 -0
- package/src/redact.ts +13 -5
- package/src/subagents.ts +7 -5
- package/dist/test/analyze.test.d.ts +0 -1
- package/dist/test/analyze.test.js +0 -412
- package/dist/test/analyze.test.js.map +0 -1
- package/dist/test/check.test.d.ts +0 -1
- package/dist/test/check.test.js +0 -215
- package/dist/test/check.test.js.map +0 -1
- package/dist/test/cli.test.d.ts +0 -1
- package/dist/test/cli.test.js +0 -142
- package/dist/test/cli.test.js.map +0 -1
- package/dist/test/codex.test.d.ts +0 -1
- package/dist/test/codex.test.js +0 -666
- package/dist/test/codex.test.js.map +0 -1
- package/dist/test/commit.test.d.ts +0 -1
- package/dist/test/commit.test.js +0 -1898
- package/dist/test/commit.test.js.map +0 -1
- package/dist/test/e2e-harness.test.d.ts +0 -1
- package/dist/test/e2e-harness.test.js +0 -53
- package/dist/test/e2e-harness.test.js.map +0 -1
- package/dist/test/git.test.d.ts +0 -1
- package/dist/test/git.test.js +0 -145
- package/dist/test/git.test.js.map +0 -1
- package/dist/test/health.test.d.ts +0 -1
- package/dist/test/health.test.js +0 -156
- package/dist/test/health.test.js.map +0 -1
- package/dist/test/hook.test.d.ts +0 -1
- package/dist/test/hook.test.js +0 -343
- package/dist/test/hook.test.js.map +0 -1
- package/dist/test/init.test.d.ts +0 -1
- package/dist/test/init.test.js +0 -162
- package/dist/test/init.test.js.map +0 -1
- package/dist/test/kimi-cli.test.d.ts +0 -1
- package/dist/test/kimi-cli.test.js +0 -231
- package/dist/test/kimi-cli.test.js.map +0 -1
- package/dist/test/kimi-code.test.d.ts +0 -1
- package/dist/test/kimi-code.test.js +0 -302
- package/dist/test/kimi-code.test.js.map +0 -1
- package/dist/test/kimi-config.test.d.ts +0 -1
- package/dist/test/kimi-config.test.js +0 -246
- package/dist/test/kimi-config.test.js.map +0 -1
- package/dist/test/kimi-hook.test.d.ts +0 -1
- package/dist/test/kimi-hook.test.js +0 -163
- package/dist/test/kimi-hook.test.js.map +0 -1
- package/dist/test/kimi-listing.test.d.ts +0 -1
- package/dist/test/kimi-listing.test.js +0 -233
- package/dist/test/kimi-listing.test.js.map +0 -1
- package/dist/test/kimi.test.d.ts +0 -1
- package/dist/test/kimi.test.js +0 -418
- package/dist/test/kimi.test.js.map +0 -1
- package/dist/test/mask-paths.test.d.ts +0 -1
- package/dist/test/mask-paths.test.js +0 -275
- package/dist/test/mask-paths.test.js.map +0 -1
- package/dist/test/notes.test.d.ts +0 -1
- package/dist/test/notes.test.js +0 -41
- package/dist/test/notes.test.js.map +0 -1
- package/dist/test/pairing.test.d.ts +0 -1
- package/dist/test/pairing.test.js +0 -138
- package/dist/test/pairing.test.js.map +0 -1
- package/dist/test/parser.test.d.ts +0 -1
- package/dist/test/parser.test.js +0 -1041
- package/dist/test/parser.test.js.map +0 -1
- package/dist/test/plan.test.d.ts +0 -1
- package/dist/test/plan.test.js +0 -35
- package/dist/test/plan.test.js.map +0 -1
- package/dist/test/redact.test.d.ts +0 -1
- package/dist/test/redact.test.js +0 -3053
- package/dist/test/redact.test.js.map +0 -1
- package/dist/test/settings.test.d.ts +0 -1
- package/dist/test/settings.test.js +0 -32
- package/dist/test/settings.test.js.map +0 -1
- package/dist/test/stage0.test.d.ts +0 -1
- package/dist/test/stage0.test.js +0 -1304
- package/dist/test/stage0.test.js.map +0 -1
- package/dist/test/subagents.test.d.ts +0 -1
- package/dist/test/subagents.test.js +0 -290
- package/dist/test/subagents.test.js.map +0 -1
- package/dist/test/sweep.test.d.ts +0 -1
- package/dist/test/sweep.test.js +0 -434
- package/dist/test/sweep.test.js.map +0 -1
- package/dist/test/update.test.d.ts +0 -1
- package/dist/test/update.test.js +0 -26
- package/dist/test/update.test.js.map +0 -1
- package/dist/test/upload.test.d.ts +0 -1
- package/dist/test/upload.test.js +0 -393
- package/dist/test/upload.test.js.map +0 -1
package/dist/test/parser.test.js
DELETED
|
@@ -1,1041 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { execFile } from "node:child_process";
|
|
3
|
-
import { existsSync } from "node:fs";
|
|
4
|
-
import { homedir } from "node:os";
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import { readFile, readdir } from "node:fs/promises";
|
|
7
|
-
import { test } from "node:test";
|
|
8
|
-
import { promisify } from "node:util";
|
|
9
|
-
import { claudeAgent } from "../agents/claude.js";
|
|
10
|
-
import { detectUnverifiedAssumption } from "../detectors.js";
|
|
11
|
-
import { STRUCTURES, commandSegments, mayParse, mayWrite, onAbandonedBranch, onMainPath, parseLines, shellEditPaths, shellReadPaths, shellWrites, gitCommands, shellOnlyLooks, withoutHeredocs, } from "../parser.js";
|
|
12
|
-
import { subagentsOf } from "../subagents.js";
|
|
13
|
-
const execFileAsync = promisify(execFile);
|
|
14
|
-
function jsonl(records) {
|
|
15
|
-
return records.map((record) => JSON.stringify(record));
|
|
16
|
-
}
|
|
17
|
-
function assistant(uuid, parentUuid, content) {
|
|
18
|
-
return {
|
|
19
|
-
type: "assistant",
|
|
20
|
-
uuid,
|
|
21
|
-
parentUuid,
|
|
22
|
-
sessionId: "s1",
|
|
23
|
-
timestamp: "2026-08-14T09:00:00Z",
|
|
24
|
-
cwd: "/repo",
|
|
25
|
-
gitBranch: "feat/x",
|
|
26
|
-
version: "2.0.0",
|
|
27
|
-
message: { role: "assistant", content },
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function toolResult(uuid, parentUuid, toolUseId, extra = {}) {
|
|
31
|
-
return {
|
|
32
|
-
type: "user",
|
|
33
|
-
uuid,
|
|
34
|
-
parentUuid,
|
|
35
|
-
sessionId: "s1",
|
|
36
|
-
timestamp: "2026-08-14T09:00:01Z",
|
|
37
|
-
message: {
|
|
38
|
-
role: "user",
|
|
39
|
-
content: [{ type: "tool_result", tool_use_id: toolUseId, content: "ok" }],
|
|
40
|
-
},
|
|
41
|
-
...extra,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
test("survives malformed lines without losing valid records", () => {
|
|
45
|
-
const lines = [
|
|
46
|
-
...jsonl([assistant("a", null, [{ type: "text", text: "hi" }])]),
|
|
47
|
-
"\0\0\0\0",
|
|
48
|
-
"",
|
|
49
|
-
" ",
|
|
50
|
-
"[1,2,3]",
|
|
51
|
-
...jsonl([assistant("b", "a", [{ type: "text", text: "bye" }])]),
|
|
52
|
-
];
|
|
53
|
-
const session = parseLines(lines);
|
|
54
|
-
assert.equal(session.records.length, 2);
|
|
55
|
-
assert.equal(session.skipped.malformedJson, 1);
|
|
56
|
-
assert.equal(session.skipped.notAnObject, 1);
|
|
57
|
-
assert.equal(session.skipped.blank, 2);
|
|
58
|
-
assert.equal(session.skipped.lines, 6);
|
|
59
|
-
});
|
|
60
|
-
test("keeps records whose type is absent from the known set", () => {
|
|
61
|
-
const session = parseLines(jsonl([
|
|
62
|
-
{ type: "bridge-session", sessionId: "s1" },
|
|
63
|
-
{ type: "brand-new-type", sessionId: "s1" },
|
|
64
|
-
{ sessionId: "s1" },
|
|
65
|
-
]));
|
|
66
|
-
assert.equal(session.records.length, 3);
|
|
67
|
-
assert.deepEqual(session.skipped.unknownTypes, { "brand-new-type": 1, unknown: 1 });
|
|
68
|
-
});
|
|
69
|
-
test("reads message.content when it is a plain string", () => {
|
|
70
|
-
const session = parseLines(jsonl([
|
|
71
|
-
{ type: "user", uuid: "a", parentUuid: null, message: { role: "user", content: "plain text" } },
|
|
72
|
-
]));
|
|
73
|
-
assert.equal(session.blocks.length, 1);
|
|
74
|
-
assert.equal(session.blocks[0]?.type, "text");
|
|
75
|
-
assert.equal(session.blocks[0]?.text, "plain text");
|
|
76
|
-
});
|
|
77
|
-
test("a recorded API request repeats the conversation without adding to it", () => {
|
|
78
|
-
const edit = { type: "tool_use", id: "toolu_1", name: "Edit", input: { file_path: "/repo/a.ts", old_string: "a", new_string: "b" } };
|
|
79
|
-
const session = parseLines(jsonl([
|
|
80
|
-
assistant("a", null, [edit]),
|
|
81
|
-
toolResult("b", "a", "toolu_1"),
|
|
82
|
-
// Claude Code 2.1.309 writes the messages of its next request as blobs.
|
|
83
|
-
{ type: "api-request-blob", sessionId: "s1", hash: "h1", message: { role: "assistant", content: [edit] } },
|
|
84
|
-
{ type: "api-request-blob", sessionId: "s1", hash: "h2", message: { role: "user", content: [{ type: "tool_result", tool_use_id: "toolu_1", content: "ok" }] } },
|
|
85
|
-
{ type: "api-request", sessionId: "s1", id: "r1", params: { model: "claude-opus-5-5" }, tail: ["h1", "h2"] },
|
|
86
|
-
]));
|
|
87
|
-
assert.equal(session.records.length, 5);
|
|
88
|
-
assert.equal(session.toolUses.length, 1);
|
|
89
|
-
assert.equal([...session.fileEdits.values()].reduce((sum, list) => sum + list.length, 0), 1);
|
|
90
|
-
assert.deepEqual(session.skipped.unknownTypes, {});
|
|
91
|
-
});
|
|
92
|
-
test("links a tool_use to its tool_result and normalizes stdout and stderr", () => {
|
|
93
|
-
const session = parseLines(jsonl([
|
|
94
|
-
assistant("a", null, [
|
|
95
|
-
{ type: "tool_use", id: "toolu_1", name: "Bash", input: { command: "npm test" } },
|
|
96
|
-
]),
|
|
97
|
-
{
|
|
98
|
-
...toolResult("b", "a", "toolu_1"),
|
|
99
|
-
toolUseResult: { stdout: "1 failed", stderr: "AssertionError", interrupted: false },
|
|
100
|
-
message: {
|
|
101
|
-
role: "user",
|
|
102
|
-
content: [
|
|
103
|
-
{ type: "tool_result", tool_use_id: "toolu_1", is_error: true, content: "FAILED" },
|
|
104
|
-
],
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
]));
|
|
108
|
-
const use = session.toolUses[0];
|
|
109
|
-
assert.equal(use?.name, "Bash");
|
|
110
|
-
assert.equal(use?.input.command, "npm test");
|
|
111
|
-
assert.equal(use?.result?.isError, true);
|
|
112
|
-
assert.equal(use?.result?.text, "FAILED");
|
|
113
|
-
assert.equal(use?.result?.stdout, "1 failed");
|
|
114
|
-
assert.equal(use?.result?.stderr, "AssertionError");
|
|
115
|
-
assert.equal(use?.result?.recordIndex, 1);
|
|
116
|
-
});
|
|
117
|
-
test("accepts a tool_result whose content is an array of text parts", () => {
|
|
118
|
-
const session = parseLines(jsonl([
|
|
119
|
-
assistant("a", null, [{ type: "tool_use", id: "toolu_1", name: "Read", input: { file_path: "/repo/a.ts" } }]),
|
|
120
|
-
{
|
|
121
|
-
...toolResult("b", "a", "toolu_1"),
|
|
122
|
-
message: {
|
|
123
|
-
role: "user",
|
|
124
|
-
content: [
|
|
125
|
-
{
|
|
126
|
-
type: "tool_result",
|
|
127
|
-
tool_use_id: "toolu_1",
|
|
128
|
-
content: [{ type: "text", text: "line one" }, { type: "text", text: "line two" }],
|
|
129
|
-
},
|
|
130
|
-
],
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
]));
|
|
134
|
-
assert.equal(session.toolUses[0]?.result?.text, "line one\nline two");
|
|
135
|
-
});
|
|
136
|
-
test("builds a per-file edit timeline and expands MultiEdit", () => {
|
|
137
|
-
const session = parseLines(jsonl([
|
|
138
|
-
assistant("a", null, [
|
|
139
|
-
{
|
|
140
|
-
type: "tool_use",
|
|
141
|
-
id: "toolu_1",
|
|
142
|
-
name: "Edit",
|
|
143
|
-
input: { file_path: "/repo/a.ts", old_string: "one", new_string: "two" },
|
|
144
|
-
},
|
|
145
|
-
]),
|
|
146
|
-
assistant("b", "a", [
|
|
147
|
-
{
|
|
148
|
-
type: "tool_use",
|
|
149
|
-
id: "toolu_2",
|
|
150
|
-
name: "MultiEdit",
|
|
151
|
-
input: {
|
|
152
|
-
file_path: "/repo/a.ts",
|
|
153
|
-
edits: [
|
|
154
|
-
{ old_string: "two", new_string: "three" },
|
|
155
|
-
{ old_string: "three", new_string: "four" },
|
|
156
|
-
],
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
]),
|
|
160
|
-
assistant("c", "b", [
|
|
161
|
-
{ type: "tool_use", id: "toolu_3", name: "Write", input: { file_path: "/repo/b.ts", content: "body" } },
|
|
162
|
-
]),
|
|
163
|
-
]));
|
|
164
|
-
const edits = session.fileEdits.get("/repo/a.ts");
|
|
165
|
-
assert.equal(edits?.length, 3);
|
|
166
|
-
assert.equal(edits?.[0]?.oldString, "one");
|
|
167
|
-
assert.equal(edits?.[1]?.newString, "three");
|
|
168
|
-
assert.equal(edits?.[2]?.newString, "four");
|
|
169
|
-
assert.equal(session.fileEdits.get("/repo/b.ts")?.[0]?.content, "body");
|
|
170
|
-
assert.equal(session.meta.editToolUses, 3);
|
|
171
|
-
});
|
|
172
|
-
test("collects files touched by lookup tools", () => {
|
|
173
|
-
const session = parseLines(jsonl([
|
|
174
|
-
assistant("a", null, [
|
|
175
|
-
{ type: "tool_use", id: "t1", name: "Read", input: { file_path: "/repo/a.ts" } },
|
|
176
|
-
{ type: "tool_use", id: "t2", name: "Grep", input: { pattern: "foo", path: "/repo/src" } },
|
|
177
|
-
{ type: "tool_use", id: "t3", name: "Bash", input: { command: "ls /repo/secret" } },
|
|
178
|
-
]),
|
|
179
|
-
]));
|
|
180
|
-
assert.deepEqual([...session.filesRead].sort(), ["/repo/a.ts", "/repo/src"]);
|
|
181
|
-
});
|
|
182
|
-
test("marks a branch that never reaches the session tip as off the main path", () => {
|
|
183
|
-
const session = parseLines(jsonl([
|
|
184
|
-
assistant("a", null, [{ type: "text", text: "start" }]),
|
|
185
|
-
assistant("abandoned", "a", [
|
|
186
|
-
{ type: "tool_use", id: "t1", name: "Edit", input: { file_path: "/repo/a.ts" } },
|
|
187
|
-
]),
|
|
188
|
-
assistant("c", "a", [{ type: "text", text: "retry" }]),
|
|
189
|
-
assistant("d", "c", [{ type: "text", text: "done" }]),
|
|
190
|
-
]));
|
|
191
|
-
assert.equal(onMainPath(session, "d"), true);
|
|
192
|
-
assert.equal(onMainPath(session, "c"), true);
|
|
193
|
-
assert.equal(onMainPath(session, "a"), true);
|
|
194
|
-
assert.equal(onMainPath(session, "abandoned"), false);
|
|
195
|
-
});
|
|
196
|
-
test("does not loop forever when parentUuid links form a cycle", () => {
|
|
197
|
-
const session = parseLines(jsonl([
|
|
198
|
-
assistant("a", "b", [{ type: "text", text: "one" }]),
|
|
199
|
-
assistant("b", "a", [{ type: "text", text: "two" }]),
|
|
200
|
-
]));
|
|
201
|
-
assert.deepEqual([...session.mainPath].sort(), ["a", "b"]);
|
|
202
|
-
});
|
|
203
|
-
test("summarizes session metadata", () => {
|
|
204
|
-
const session = parseLines(jsonl([
|
|
205
|
-
{ type: "user", uuid: "u", parentUuid: null, sessionId: "s1", timestamp: "2026-08-14T09:00:00Z", cwd: "/repo", gitBranch: "main", version: "2.0.0", message: { role: "user", content: "go" } },
|
|
206
|
-
{ ...assistant("a", "u", [{ type: "thinking", thinking: "considering" }]), timestamp: "2026-08-14T10:00:00Z" },
|
|
207
|
-
{ ...assistant("b", "a", [{ type: "text", text: "done" }]), isSidechain: true, timestamp: "2026-08-14T11:00:00Z" },
|
|
208
|
-
]));
|
|
209
|
-
assert.equal(session.sessionId, "s1");
|
|
210
|
-
assert.equal(session.meta.cwd, "/repo");
|
|
211
|
-
assert.equal(session.meta.claudeVersion, "2.0.0");
|
|
212
|
-
assert.equal(session.meta.startedAt, "2026-08-14T09:00:00Z");
|
|
213
|
-
assert.equal(session.meta.endedAt, "2026-08-14T11:00:00Z");
|
|
214
|
-
assert.equal(session.meta.assistantRecords, 2);
|
|
215
|
-
assert.equal(session.meta.sidechainRecords, 1);
|
|
216
|
-
assert.equal(session.meta.thinkingBlocks, 1);
|
|
217
|
-
});
|
|
218
|
-
test("a subagent decides neither where the session ran nor when it ended", () => {
|
|
219
|
-
const session = parseLines(jsonl([
|
|
220
|
-
{ ...assistant("a", null, [{ type: "text", text: "start" }]), timestamp: "2026-08-14T09:00:00Z" },
|
|
221
|
-
{ ...assistant("b", "a", [{ type: "text", text: "done" }]), timestamp: "2026-08-14T12:00:00Z" },
|
|
222
|
-
// A subagent whose call is nowhere follows the whole session (`subagents.ts`).
|
|
223
|
-
{ ...assistant("s", null, [{ type: "text", text: "work" }]), isSidechain: true, timestamp: "2026-08-14T10:00:00Z", cwd: "/jobs/wf", gitBranch: "HEAD", version: "2.0.1" },
|
|
224
|
-
]));
|
|
225
|
-
assert.equal(session.meta.cwd, "/repo");
|
|
226
|
-
assert.equal(session.meta.gitBranch, "feat/x");
|
|
227
|
-
assert.equal(session.meta.claudeVersion, "2.0.0");
|
|
228
|
-
assert.equal(session.meta.endedAt, "2026-08-14T12:00:00Z");
|
|
229
|
-
// Read alone, a subagent's file is all there is to go by.
|
|
230
|
-
const alone = parseLines(jsonl([{ ...assistant("s", null, []), isSidechain: true, cwd: "/jobs/wf" }]));
|
|
231
|
-
assert.equal(alone.meta.cwd, "/jobs/wf");
|
|
232
|
-
});
|
|
233
|
-
const corpus = join(homedir(), ".claude", "projects");
|
|
234
|
-
/** Object lines in a file: what one subagent adds to its session once spliced in. */
|
|
235
|
-
async function recordCount(path) {
|
|
236
|
-
return (await readFile(path, "utf8")).split("\n").filter((line) => line.trim().startsWith("{")).length;
|
|
237
|
-
}
|
|
238
|
-
test("parses real Claude Code transcripts", { skip: !existsSync(corpus) }, async () => {
|
|
239
|
-
const projects = await readdir(corpus);
|
|
240
|
-
const files = [];
|
|
241
|
-
for (const project of projects) {
|
|
242
|
-
let entries;
|
|
243
|
-
try {
|
|
244
|
-
entries = await readdir(join(corpus, project));
|
|
245
|
-
}
|
|
246
|
-
catch {
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
for (const entry of entries) {
|
|
250
|
-
if (entry.endsWith(".jsonl"))
|
|
251
|
-
files.push(join(corpus, project, entry));
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
assert.ok(files.length > 0, "expected at least one transcript in the local corpus");
|
|
255
|
-
let records = 0;
|
|
256
|
-
let toolUses = 0;
|
|
257
|
-
let linkedResults = 0;
|
|
258
|
-
for (const file of files) {
|
|
259
|
-
// Counted before the parse: a session still running only grows, so what
|
|
260
|
-
// the parse reads can be more than this, never less.
|
|
261
|
-
let spliced = 0;
|
|
262
|
-
for (const agent of await subagentsOf(file))
|
|
263
|
-
spliced += await recordCount(agent.path);
|
|
264
|
-
// Read the way the upload reads it: the session with its subagents.
|
|
265
|
-
const session = await claudeAgent.parsedSession(file);
|
|
266
|
-
records += session.records.length;
|
|
267
|
-
toolUses += session.toolUses.length;
|
|
268
|
-
linkedResults += session.toolUses.filter((use) => use.result).length;
|
|
269
|
-
assert.ok(session.meta.sidechainRecords >= spliced, `${file}: every subagent record is read in`);
|
|
270
|
-
for (const use of session.toolUses) {
|
|
271
|
-
assert.equal(typeof use.id, "string");
|
|
272
|
-
assert.equal(typeof use.name, "string");
|
|
273
|
-
}
|
|
274
|
-
for (const [filePath, edits] of session.fileEdits) {
|
|
275
|
-
assert.ok(filePath.length > 0);
|
|
276
|
-
assert.ok(edits.length > 0);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
assert.ok(records > 0);
|
|
280
|
-
assert.ok(toolUses > 0);
|
|
281
|
-
assert.ok(linkedResults / toolUses > 0.9, "most tool calls should resolve to a result");
|
|
282
|
-
});
|
|
283
|
-
test("picks file paths out of shell commands that read a file", () => {
|
|
284
|
-
assert.deepEqual(shellReadPaths("cat src/app.ts"), ["src/app.ts"]);
|
|
285
|
-
assert.deepEqual(shellReadPaths("sed -n '190,240p' src/routes/products.ts"), ["src/routes/products.ts"]);
|
|
286
|
-
assert.deepEqual(shellReadPaths("git show main:server/src/index.ts"), ["server/src/index.ts"]);
|
|
287
|
-
assert.deepEqual(shellReadPaths("rg -n 'drain' src/queue.ts"), ["src/queue.ts"]);
|
|
288
|
-
});
|
|
289
|
-
test("does not treat a write as a shell read", () => {
|
|
290
|
-
assert.deepEqual(shellReadPaths("rm -rf src/app.ts"), []);
|
|
291
|
-
assert.deepEqual(shellReadPaths("echo hi > src/app.ts"), []);
|
|
292
|
-
assert.deepEqual(shellReadPaths("npm test"), []);
|
|
293
|
-
});
|
|
294
|
-
test("a case-insensitive grep is a read, and sed -i in any spelling is not", () => {
|
|
295
|
-
assert.deepEqual(shellReadPaths("grep -i total src/cart.ts"), ["src/cart.ts"]);
|
|
296
|
-
assert.deepEqual(shellReadPaths("sed -Ei 's/a/b/' src/cart.ts"), []);
|
|
297
|
-
assert.deepEqual(shellReadPaths("sed -i.bak 's/a/b/' src/cart.ts"), []);
|
|
298
|
-
});
|
|
299
|
-
test("keeps a glob read as the glob, for the detectors to match", () => {
|
|
300
|
-
assert.deepEqual(shellReadPaths("cat src/*.ts test/*.js README.md"), ["src/*.ts", "test/*.js", "README.md"]);
|
|
301
|
-
});
|
|
302
|
-
test("names the files sed -i and perl -i rewrite, and not their scripts", () => {
|
|
303
|
-
assert.deepEqual(shellEditPaths("sed -i 's/a b/c d/; s/x/y/' test/money.test.js README.md"), ["test/money.test.js", "README.md"]);
|
|
304
|
-
assert.deepEqual(shellEditPaths("sed -i -e 's/a/b/' -e 's/c/d/' src/a.ts"), ["src/a.ts"]);
|
|
305
|
-
assert.deepEqual(shellEditPaths("sed -i '' 's/a/b/' src/a.ts"), ["src/a.ts"], "BSD sed's empty backup suffix");
|
|
306
|
-
assert.deepEqual(shellEditPaths("sed -ie 's/a/b/' src/a.ts"), ["src/a.ts"], "-ie is -i with a suffix");
|
|
307
|
-
assert.deepEqual(shellEditPaths("perl -pi -e 's/a/b/' src/a.ts"), ["src/a.ts"]);
|
|
308
|
-
assert.deepEqual(shellEditPaths("sudo sed -i 's/a/b/' /etc/hosts"), ["/etc/hosts"]);
|
|
309
|
-
assert.deepEqual(shellEditPaths(`sed -i "s/banker's/away/" README.md && npm test`), ["README.md"]);
|
|
310
|
-
// Not an edit: no -i, or a glob this cannot list.
|
|
311
|
-
assert.deepEqual(shellEditPaths("sed -n '1,5p' src/a.ts"), []);
|
|
312
|
-
assert.deepEqual(shellEditPaths("sed 's/ -i //' src/a.ts"), [], "-i inside the script");
|
|
313
|
-
assert.deepEqual(shellEditPaths("sed -i 's/a/b/' src/*.ts"), []);
|
|
314
|
-
assert.deepEqual(shellEditPaths("sed -i '$a K=v' src/a.ts"), ["src/a.ts"], "sed's own `$`, the last line");
|
|
315
|
-
assert.deepEqual(shellEditPaths("sed -i '$d' src/a.ts"), ["src/a.ts"]);
|
|
316
|
-
assert.deepEqual(shellEditPaths('sed -i "$SCRIPT" src/a.ts'), ["src/a.ts"], "a quoted variable is the one script");
|
|
317
|
-
assert.deepEqual(shellEditPaths("sed -i $FLAGS 's/a/b/' src/a.ts"), ["src/a.ts"], "a bare one can be flags");
|
|
318
|
-
assert.deepEqual(shellEditPaths(`sed -i 's/a/b/' "$FILE" $OTHER "$DIR/a.ts"`), [], "a variable names no file");
|
|
319
|
-
assert.deepEqual(shellEditPaths("perl -p -i -e 's/a/b/' src/a.ts"), ["src/a.ts"]);
|
|
320
|
-
assert.deepEqual(shellEditPaths("perl -0pi -e 's/a/b/' src/a.ts"), ["src/a.ts"]);
|
|
321
|
-
assert.deepEqual(shellEditPaths("perl -pe 's/a/b/' src/a.ts"), []);
|
|
322
|
-
assert.deepEqual(shellEditPaths(`ruby -pi -e 'sub("a","b")' src/a.ts`), ["src/a.ts"]);
|
|
323
|
-
assert.deepEqual(shellEditPaths(`ruby -i.bak -pe 'sub("a","b")' src/a.ts`), ["src/a.ts"]);
|
|
324
|
-
assert.deepEqual(shellEditPaths("ruby -ne 'puts 1' src/a.ts"), []);
|
|
325
|
-
assert.deepEqual(shellEditPaths("awk -i inplace '{print}' src/a.ts"), ["src/a.ts"]);
|
|
326
|
-
assert.deepEqual(shellEditPaths("gawk -i inplace -v x=1 -F : '{print}' src/a.ts src/b.ts"), ["src/a.ts", "src/b.ts"]);
|
|
327
|
-
assert.deepEqual(shellEditPaths("gawk --include=inplace '{print}' src/a.ts"), ["src/a.ts"]);
|
|
328
|
-
assert.deepEqual(shellEditPaths("awk -i lib.awk '{print}' src/a.ts"), [], "-i only loads a library");
|
|
329
|
-
assert.deepEqual(shellEditPaths("awk '{print}' src/a.ts"), []);
|
|
330
|
-
assert.deepEqual(shellEditPaths("for f in a b; do sed -i 's/a/b/' src/a.ts; done"), ["src/a.ts"]);
|
|
331
|
-
assert.deepEqual(shellEditPaths("if true; then sudo sed -i 's/a/b/' src/a.ts; fi"), ["src/a.ts"]);
|
|
332
|
-
assert.deepEqual(shellEditPaths("perl script.pl -input src/a.ts"), [], "a flag of the script's own");
|
|
333
|
-
});
|
|
334
|
-
test("whether a command wrote agrees with what it names as edited, for every in-place editor", () => {
|
|
335
|
-
for (const command of [
|
|
336
|
-
"sed -i 's/a/b/' a.ts",
|
|
337
|
-
"perl -pi -e 's/a/b/' a.ts",
|
|
338
|
-
"perl -0pi -e 's/a/b/' a.ts",
|
|
339
|
-
"perl -p -i -e 's/a/b/' a.ts",
|
|
340
|
-
"ruby -pi -e 'x' a.ts",
|
|
341
|
-
"awk -i inplace '{print}' a.ts",
|
|
342
|
-
"gawk --include=inplace '{print}' a.ts",
|
|
343
|
-
"for f in x; do sed -i 's/a/b/' a.ts; done",
|
|
344
|
-
]) {
|
|
345
|
-
assert.equal(shellWrites(command), true, command);
|
|
346
|
-
assert.deepEqual(shellEditPaths(command), ["a.ts"], command);
|
|
347
|
-
}
|
|
348
|
-
for (const command of ["sed 's/a/b/' a.ts", "perl -pe 's/a/b/' a.ts", "ruby -ne 'x' a.ts", "awk '{print}' a.ts", "awk -i lib.awk '{print}' a.ts"]) {
|
|
349
|
-
assert.equal(shellWrites(command), false, command);
|
|
350
|
-
assert.deepEqual(shellEditPaths(command), [], command);
|
|
351
|
-
}
|
|
352
|
-
});
|
|
353
|
-
test("telling an in-place edit or a heredoc from anything else gets through 200 KB of text built to stall it", () => {
|
|
354
|
-
const fill = (unit) => unit.repeat(Math.ceil(200_000 / unit.length));
|
|
355
|
-
for (const command of [
|
|
356
|
-
`perl ${fill("-a ")}`,
|
|
357
|
-
`perl ${fill("-a ")}x`,
|
|
358
|
-
`ruby ${fill("-a")}`,
|
|
359
|
-
`ruby -${"a".repeat(200_000)}`,
|
|
360
|
-
`perl${" ".repeat(200_000)}-a`,
|
|
361
|
-
`perl ${fill("-a ")}'x' y`,
|
|
362
|
-
`awk ${fill("-i ")}`,
|
|
363
|
-
`awk -i${" ".repeat(200_000)}x`,
|
|
364
|
-
`awk --include=${" ".repeat(200_000)}x`,
|
|
365
|
-
`gawk ${fill("--include ")}`,
|
|
366
|
-
fill("do "),
|
|
367
|
-
fill("do "),
|
|
368
|
-
`${fill("do ")}sed -i x y`,
|
|
369
|
-
`${fill("sudo\t")}awk`,
|
|
370
|
-
fill("<<\\"),
|
|
371
|
-
`<<${" ".repeat(200_000)}`,
|
|
372
|
-
`cat ${fill("<<-\\")}`,
|
|
373
|
-
`echo ${fill('\\"')} > a.txt`,
|
|
374
|
-
`echo "${fill('\\"')} > a.txt`,
|
|
375
|
-
`echo ${fill('"\\')} > a.txt`,
|
|
376
|
-
`sed -i ${fill('\\"')} a.txt`,
|
|
377
|
-
`sed -i "${fill('\\"')} a.txt`,
|
|
378
|
-
]) {
|
|
379
|
-
const started = Date.now();
|
|
380
|
-
shellWrites(command);
|
|
381
|
-
shellEditPaths(command);
|
|
382
|
-
withoutHeredocs(command);
|
|
383
|
-
const took = Date.now() - started;
|
|
384
|
-
assert.ok(took < 1000, `took ${took}ms on ${JSON.stringify(command.slice(0, 24))}`);
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
test("an escaped quote opens nothing, so what follows it is no argument", () => {
|
|
388
|
-
assert.equal(shellWrites('echo \\"a\\" > b.txt'), true);
|
|
389
|
-
assert.equal(shellWrites("echo it\\'s > b.txt"), true);
|
|
390
|
-
assert.equal(shellWrites('echo "a \\" > b.txt"'), false);
|
|
391
|
-
assert.equal(shellWrites("sed 's/ -i //' a.ts"), false);
|
|
392
|
-
assert.deepEqual(shellEditPaths("sed -i 's/a/b/' my\\ dir/a.ts"), ["my\\ dir/a.ts"]);
|
|
393
|
-
});
|
|
394
|
-
test("a heredoc's body is cut whichever way its delimiter is quoted", () => {
|
|
395
|
-
for (const opener of ["<<EOF", "<<-EOF", "<<'EOF'", '<<"EOF"', "<<\\EOF"]) {
|
|
396
|
-
assert.equal(withoutHeredocs(`cat > a.txt ${opener}\nDROP DATABASE\nEOF\nnpm test`).includes("DROP DATABASE"), false, opener);
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
test("resolves a sed -i path against the directory the command ran in", () => {
|
|
400
|
-
assert.deepEqual(shellEditPaths("sed -i 's/a/b/' ./src/a.ts", "/repo"), ["/repo/src/a.ts"]);
|
|
401
|
-
// Masked, the working directory is "." and paths come out repo-relative, as Edit's do.
|
|
402
|
-
assert.deepEqual(shellEditPaths("sed -i 's/a/b/' ./src/a.ts", "."), ["src/a.ts"]);
|
|
403
|
-
assert.deepEqual(shellEditPaths("cd pkg && sed -i 's/a/b/' a.ts", "/repo"), ["/repo/pkg/a.ts"]);
|
|
404
|
-
assert.deepEqual(shellEditPaths("cd /elsewhere && sed -i 's/a/b/' a.ts", "/repo"), ["/elsewhere/a.ts"]);
|
|
405
|
-
assert.deepEqual(shellEditPaths("cd $DIR && sed -i 's/a/b/' a.ts", "/repo"), ["a.ts"], "a cd it cannot follow");
|
|
406
|
-
});
|
|
407
|
-
test("a directory no filesystem could hold is no directory, so what is edited in it stays as typed", () => {
|
|
408
|
-
const long = "b".repeat(3000);
|
|
409
|
-
assert.deepEqual(shellEditPaths("sed -i x a.ts", `/${"a".repeat(4096)}`), ["a.ts"]);
|
|
410
|
-
assert.deepEqual(shellEditPaths(`cd /${"a".repeat(4096)} && sed -i x a.ts`, "/repo"), ["a.ts"]);
|
|
411
|
-
assert.deepEqual(shellEditPaths(`cd ${long} && cd ${long} && sed -i x a.ts`, "/repo"), ["a.ts"], "a chain of cd past it");
|
|
412
|
-
assert.deepEqual(shellEditPaths(`cd ${long} && cd ${long} && cd /back && sed -i x a.ts`, "/repo"), ["/back/a.ts"], "a cd that names a real one");
|
|
413
|
-
assert.deepEqual(shellEditPaths(`cd ${long} && sed -i x a.ts`, "/repo"), [`/repo/${long}/a.ts`], "under it");
|
|
414
|
-
const word = `${"../".repeat(2000)}a.ts`;
|
|
415
|
-
assert.deepEqual(shellEditPaths(`sed -i x ${word}`, "/repo"), [word], "a word past it");
|
|
416
|
-
assert.deepEqual(shellEditPaths(`cd ${"a/".repeat(1000)} && sed -i x ${long}/a.ts`, "/repo"), [`${long}/a.ts`], "a word that goes past it from there");
|
|
417
|
-
});
|
|
418
|
-
test("what one session's shell commands spell out is bounded over the whole transcript", () => {
|
|
419
|
-
const words = (record) => Array.from({ length: 100 }, (_, word) => `f${record}_${word}`).join(" ");
|
|
420
|
-
const records = Array.from({ length: 1000 }, (_, index) => ({
|
|
421
|
-
...assistant(`u${index}`, index === 0 ? null : `u${index - 1}`, [
|
|
422
|
-
{ type: "tool_use", id: `t${index}`, name: "Bash", input: { command: `sed -i x ${words(index)}` } },
|
|
423
|
-
]),
|
|
424
|
-
cwd: `/${"a".repeat(4090)}`,
|
|
425
|
-
}));
|
|
426
|
-
const session = parseLines(jsonl(records));
|
|
427
|
-
const chars = [...session.fileEdits.keys()].reduce((sum, path) => sum + path.length, 0);
|
|
428
|
-
assert.ok(session.fileEdits.size > 1000, `kept ${session.fileEdits.size}`);
|
|
429
|
-
assert.ok(chars <= 32 * 1024 * 1024, `spelled out ${chars} characters`);
|
|
430
|
-
assert.equal(session.meta.hasFileEdits, true);
|
|
431
|
-
});
|
|
432
|
-
test("a shell edit past what a session may spell out still counts as one, and only adds no path", () => {
|
|
433
|
-
// Words past what they may cost, for few bytes of command.
|
|
434
|
-
const spent = Array.from({ length: 600 }, (_, index) => assistant(`u${index}`, index === 0 ? null : `u${index - 1}`, [
|
|
435
|
-
{ type: "tool_use", id: `t${index}`, name: "Bash", input: { command: `cat ${"a.ts ".repeat(1_000)}` } },
|
|
436
|
-
]));
|
|
437
|
-
const session = parseLines(jsonl([
|
|
438
|
-
...spent,
|
|
439
|
-
assistant("u600", "u599", [{ type: "tool_use", id: "t600", name: "Bash", input: { command: "sed -i x z.ts" } }]),
|
|
440
|
-
]));
|
|
441
|
-
assert.equal(session.meta.hasFileEdits, true);
|
|
442
|
-
assert.equal(session.fileEdits.size, 0);
|
|
443
|
-
assert.equal(parseLines(jsonl([spent[0]])).meta.hasFileEdits, false, "the same look, under it");
|
|
444
|
-
assert.deepEqual(shellEditPaths("sed -i x z.ts", "/repo", { left: 8 }), []);
|
|
445
|
-
assert.deepEqual(shellReadPaths("cat z.ts", { left: 8 }), []);
|
|
446
|
-
assert.deepEqual(shellEditPaths("sed -i x z.ts", "/repo", { left: 1000 }), ["/repo/z.ts"]);
|
|
447
|
-
});
|
|
448
|
-
test("a session with more shell than the longest real ones is read to its end", () => {
|
|
449
|
-
const session = parseLines(jsonl([
|
|
450
|
-
...Array.from({ length: 400 }, (_, index) => assistant(`u${index}`, index === 0 ? null : `u${index - 1}`, [
|
|
451
|
-
{ type: "tool_use", id: `t${index}`, name: "Bash", input: { command: `echo ${"a".repeat(50_000)}` } },
|
|
452
|
-
])),
|
|
453
|
-
assistant("u400", "u399", [{ type: "tool_use", id: "t400", name: "Bash", input: { command: "sed -i x z.ts" } }]),
|
|
454
|
-
]));
|
|
455
|
-
assert.equal(session.fileEdits.size, 1);
|
|
456
|
-
assert.ok(session.toolUses.every((use) => typeof use.input.command === "string"));
|
|
457
|
-
});
|
|
458
|
-
test("a command too long to read counts as a write nobody can name, and nothing reads it after", () => {
|
|
459
|
-
for (const command of [`cat ${"a".repeat(10 * 1024 * 1024)}`, `cat "${"a".repeat(10 * 1024 * 1024)}"`]) {
|
|
460
|
-
const session = parseLines(jsonl([
|
|
461
|
-
assistant("u0", null, [{ type: "tool_use", id: "t0", name: "Bash", input: { command } }]),
|
|
462
|
-
]));
|
|
463
|
-
assert.equal(session.meta.hasFileEdits, true);
|
|
464
|
-
assert.deepEqual(session.toolUses[0].input, {});
|
|
465
|
-
assert.equal(session.filesRead.size, 0);
|
|
466
|
-
}
|
|
467
|
-
});
|
|
468
|
-
test("a long list of edits to a file already edited goes in whole", () => {
|
|
469
|
-
const edit = { old_string: "a", new_string: "b" };
|
|
470
|
-
const session = parseLines(jsonl([
|
|
471
|
-
assistant("u0", null, [
|
|
472
|
-
{ type: "tool_use", id: "t0", name: "Edit", input: { file_path: "a.ts", ...edit } },
|
|
473
|
-
{ type: "tool_use", id: "t1", name: "MultiEdit", input: { file_path: "a.ts", edits: Array.from({ length: 200_000 }, () => edit) } },
|
|
474
|
-
]),
|
|
475
|
-
]));
|
|
476
|
-
assert.equal(session.fileEdits.get("a.ts")?.length, 200_001);
|
|
477
|
-
});
|
|
478
|
-
test("a transcript of 50 MB built to cost the most goes through a gigabyte of heap in seconds", async () => {
|
|
479
|
-
const source = `
|
|
480
|
-
import { parseLines } from "./src/parser.ts";
|
|
481
|
-
const MB = 1024 * 1024;
|
|
482
|
-
const size = 50 * MB;
|
|
483
|
-
const lineWith = (index, cwd, content) => JSON.stringify({
|
|
484
|
-
type: "assistant", uuid: "u" + index, cwd, message: { role: "assistant", content },
|
|
485
|
-
});
|
|
486
|
-
const record = (index, cwd, command) =>
|
|
487
|
-
lineWith(index, cwd, [{ type: "tool_use", id: "t" + index, name: "Bash", input: { command } }]);
|
|
488
|
-
const filled = (line) => Array.from({ length: Math.ceil(size / line(0).length) }, (_, index) => line(index));
|
|
489
|
-
const dir = "/" + "a".repeat(4000);
|
|
490
|
-
const words = (name) => Array.from({ length: 100 }, (_, word) => name + word).join(" ");
|
|
491
|
-
const longest = (unit) => unit.repeat(Math.floor((MB - 32) / unit.length));
|
|
492
|
-
const shapes = {
|
|
493
|
-
"a long directory and words of its own on every record": () => filled((index) => record(index, dir, "sed -i x " + words("r" + index + "_"))),
|
|
494
|
-
"a long directory on every word of the longest commands": () => filled((index) => record(index, dir, "sed -i x " + longest("a "))),
|
|
495
|
-
"a long directory followed back and forth": () => filled((index) => record(index, dir, longest("cd a;cd ..;") + "sed -i x a")),
|
|
496
|
-
"a path of nothing but parents": () => filled((index) => record(index, "/r", "sed -i x " + longest("../") + "a")),
|
|
497
|
-
"no directory, and a word for every two bytes": () => filled((index) => record(index, undefined, "sed -i x " + longest("a "))),
|
|
498
|
-
"a heredoc of short lines": () => filled((index) => record(index, "/r", "sed -i x a\\ncat <<E\\n" + longest("ab\\n"))),
|
|
499
|
-
"one word as long as the transcript": () => [record(0, "/r", "sed -i x " + "a".repeat(size))],
|
|
500
|
-
"records of nothing but empty blocks": () => filled((index) => lineWith(index, "/r", Array(MB / 8).fill({}))),
|
|
501
|
-
"one line of nothing but empty blocks": () => [lineWith(0, "/r", Array(Math.floor(size / 3)).fill({}))],
|
|
502
|
-
"one array of nothing but numbers": () => ['{"type":"user","x":[' + "1,".repeat(40 * MB) + "1]}"],
|
|
503
|
-
};
|
|
504
|
-
for (const [name, build] of Object.entries(shapes)) {
|
|
505
|
-
const lines = build();
|
|
506
|
-
const started = performance.now();
|
|
507
|
-
const session = parseLines(lines);
|
|
508
|
-
if (!session.meta.hasFileEdits) throw new Error(name + ": no edit seen");
|
|
509
|
-
console.log(name, Math.round(performance.now() - started));
|
|
510
|
-
}
|
|
511
|
-
`;
|
|
512
|
-
const { stdout } = await execFileAsync(process.execPath, ["--max-old-space-size=1024", "--import", "tsx", "--input-type=module", "-e", source], { cwd: join(import.meta.dirname, "..", ".."), timeout: 300_000 });
|
|
513
|
-
const rows = stdout.trim().split("\n");
|
|
514
|
-
assert.equal(rows.length, 10, stdout);
|
|
515
|
-
for (const line of rows) {
|
|
516
|
-
const took = Number(line.slice(line.lastIndexOf(" ")));
|
|
517
|
-
assert.ok(took < 20_000, line);
|
|
518
|
-
}
|
|
519
|
-
});
|
|
520
|
-
test("repeated interpreter words cost a read of the line, not one for each word", () => {
|
|
521
|
-
for (const command of [
|
|
522
|
-
"node ".repeat(200_000),
|
|
523
|
-
`<< ${"node ".repeat(200_000)}`,
|
|
524
|
-
`${"node ".repeat(200_000)}<<`,
|
|
525
|
-
`${"node <\n".repeat(200_000)}`,
|
|
526
|
-
`python3 ${"python3.1.1 ".repeat(100_000)}`,
|
|
527
|
-
]) {
|
|
528
|
-
const started = performance.now();
|
|
529
|
-
shellWrites(command);
|
|
530
|
-
const took = performance.now() - started;
|
|
531
|
-
assert.ok(took < 2000, `took ${took}ms on ${JSON.stringify(command.slice(0, 24))}`);
|
|
532
|
-
}
|
|
533
|
-
assert.equal(shellWrites(`python3 - <<'PY'\nopen('a','w')\nPY`), true);
|
|
534
|
-
assert.equal(shellWrites(`cd x && node <<'JS'\nx\nJS`), true);
|
|
535
|
-
assert.equal(shellWrites(`echo <<E\nx\nE\nnode a.js`), false, "the interpreter on another line");
|
|
536
|
-
assert.equal(shellWrites("node a.js <<< word"), true, "as a here-string has always read");
|
|
537
|
-
assert.equal(shellWrites("cat <<E node\nx\nE"), false, "behind the opener");
|
|
538
|
-
});
|
|
539
|
-
test("stops at a redirection so a heredoc write is not read as a lookup", () => {
|
|
540
|
-
assert.deepEqual(shellReadPaths("cat > src/new.ts <<EOF"), []);
|
|
541
|
-
assert.deepEqual(shellReadPaths("cat src/a.ts > /tmp/out.txt"), ["src/a.ts"]);
|
|
542
|
-
assert.deepEqual(shellReadPaths("cat src/a.ts 2>/dev/null"), ["src/a.ts"]);
|
|
543
|
-
});
|
|
544
|
-
test("a here-string has no body, so the lines after it still ran", () => {
|
|
545
|
-
const command = "grep -c x <<< word\nnpm run build\nword";
|
|
546
|
-
assert.equal(withoutHeredocs(command), command);
|
|
547
|
-
assert.equal(withoutHeredocs(`tr a b <<<"$x"\nnpm run build`), `tr a b <<<"$x"\nnpm run build`);
|
|
548
|
-
});
|
|
549
|
-
test("a heredoc body is not part of the command that carries it", () => {
|
|
550
|
-
const command = [
|
|
551
|
-
"python3 - <<'PY'",
|
|
552
|
-
"old = 'npm install decimal.js'",
|
|
553
|
-
"run('cat src/app.ts')",
|
|
554
|
-
"PY",
|
|
555
|
-
"npm run build",
|
|
556
|
-
].join("\n");
|
|
557
|
-
assert.equal(withoutHeredocs(command), "python3 - <<'PY'\nnpm run build");
|
|
558
|
-
// The file named inside the body was never read: the agent wrote it as text.
|
|
559
|
-
assert.deepEqual(shellReadPaths(command), []);
|
|
560
|
-
});
|
|
561
|
-
test("a command splits the way a shell would, not the way a regex does", () => {
|
|
562
|
-
// The `|` lives inside a search pattern, so this is one command, not two.
|
|
563
|
-
assert.deepEqual(commandSegments('grep -E "DELETE FROM|DROP TABLE" src'), [
|
|
564
|
-
'grep -E "DELETE FROM|DROP TABLE" src',
|
|
565
|
-
]);
|
|
566
|
-
assert.deepEqual(commandSegments("npm ci && npm test"), ["npm ci ", " npm test"]);
|
|
567
|
-
// A substitution runs a command of its own and is judged as one.
|
|
568
|
-
assert.deepEqual(commandSegments('node run.js $(grep -rl "DROP TABLE" .)'), [
|
|
569
|
-
"node run.js ",
|
|
570
|
-
'grep -rl "DROP TABLE" .',
|
|
571
|
-
]);
|
|
572
|
-
// What a backslash escapes neither opens nor closes a quote nor ends a command.
|
|
573
|
-
assert.deepEqual(commandSegments("echo don\\'t; rm a"), ["echo don\\'t", " rm a"]);
|
|
574
|
-
assert.deepEqual(commandSegments('echo \\"a; rm b'), ['echo \\"a', " rm b"]);
|
|
575
|
-
assert.deepEqual(commandSegments('echo "c:\\\\"; rm c'), ['echo "c:\\\\"', " rm c"]);
|
|
576
|
-
assert.deepEqual(commandSegments('echo "a\\"; b"; rm d'), ['echo "a\\"; b"', " rm d"]);
|
|
577
|
-
assert.deepEqual(commandSegments("find . -exec rm {} \\; && ls"), ["find . -exec rm {} \\; ", " ls"]);
|
|
578
|
-
// At the end of a line it joins that line to the next, and here it is still where a segment ends.
|
|
579
|
-
assert.deepEqual(commandSegments("a \\\nb"), ["a \\", "b"]);
|
|
580
|
-
});
|
|
581
|
-
test("a marker's colon is no revision's, so a masked path the shell read stays whole", () => {
|
|
582
|
-
const masked = "~/.claude/projects/[ISY_REDACTED:project]/memory/notes.md";
|
|
583
|
-
assert.deepEqual(shellReadPaths(`cat ${masked}`), [masked]);
|
|
584
|
-
assert.deepEqual(shellReadPaths(`git show main:${masked}`), [masked]);
|
|
585
|
-
assert.deepEqual(shellReadPaths("cat [ISY_REDACTED:a]/[ISY_REDACTED:b]/c.md"), ["[ISY_REDACTED:a]/[ISY_REDACTED:b]/c.md"]);
|
|
586
|
-
assert.deepEqual(shellReadPaths("git show main:src/a.ts"), ["src/a.ts"]);
|
|
587
|
-
const session = parseLines([
|
|
588
|
-
JSON.stringify({ type: "assistant", message: { role: "assistant", content: [{ type: "tool_use", id: "t1", name: "Bash", input: { command: `cat ${masked}` } }] } }),
|
|
589
|
-
JSON.stringify({ type: "user", message: { role: "user", content: [{ type: "tool_result", tool_use_id: "t1", content: "x" }] } }),
|
|
590
|
-
JSON.stringify({ type: "assistant", message: { role: "assistant", content: [{ type: "tool_use", id: "t2", name: "Edit", input: { file_path: masked, old_string: "x", new_string: "y" } }] } }),
|
|
591
|
-
JSON.stringify({ type: "user", message: { role: "user", content: [{ type: "tool_result", tool_use_id: "t2", content: "ok" }] } }),
|
|
592
|
-
]);
|
|
593
|
-
assert.ok(session.filesRead.has(masked));
|
|
594
|
-
assert.deepEqual(detectUnverifiedAssumption(session), []);
|
|
595
|
-
});
|
|
596
|
-
test("a load path, a required library or a program named like an editor edits nothing", () => {
|
|
597
|
-
for (const command of [
|
|
598
|
-
"ruby -Ilib -Itest test/foo_test.rb",
|
|
599
|
-
"ruby -Ilib -e 'puts 1'",
|
|
600
|
-
"bundle exec ruby -Ilib -Itest test/foo_test.rb",
|
|
601
|
-
"ruby -rdigest -e 'puts 1'",
|
|
602
|
-
"ruby -ruri -e 'puts 1'",
|
|
603
|
-
"ruby -rfileutils -e 'puts 1'",
|
|
604
|
-
"ruby -rbigdecimal x.rb",
|
|
605
|
-
"ruby -W:no-experimental x.rb",
|
|
606
|
-
"ruby -Eiso-8859-1 x.rb",
|
|
607
|
-
"ruby-build -i",
|
|
608
|
-
"ruby-install -i /opt",
|
|
609
|
-
"perl -Ilib t/x.t",
|
|
610
|
-
"perl -Mstrict -e 1",
|
|
611
|
-
"perl -MList::Util=sum -e 1",
|
|
612
|
-
"perl -Mlib=lib t/x.t",
|
|
613
|
-
"perl -ei a.ts",
|
|
614
|
-
"awk -f -i inplace f",
|
|
615
|
-
"gawk -v -i inplace f",
|
|
616
|
-
]) {
|
|
617
|
-
assert.equal(shellWrites(command), false, command);
|
|
618
|
-
assert.deepEqual(shellEditPaths(command), [], command);
|
|
619
|
-
}
|
|
620
|
-
for (const command of [
|
|
621
|
-
"perl -pi -e 's/a/b/' a.ts",
|
|
622
|
-
"perl -0pi -e 's/a/b/' a.ts",
|
|
623
|
-
"perl -0777pi -e 's/a/b/' a.ts",
|
|
624
|
-
"perl -wpi -e 's/a/b/' a.ts",
|
|
625
|
-
"perl -i -pe 's/a/b/' a.ts",
|
|
626
|
-
"perl -i.bak -pe 's/a/b/' a.ts",
|
|
627
|
-
"perl -pie 's/a/b/' a.ts",
|
|
628
|
-
"perl -Ilib -pi -e 's/a/b/' a.ts",
|
|
629
|
-
"perl -CSDA -Mutf8 -pi -e 's/a/b/' a.ts",
|
|
630
|
-
"ruby -i.bak -pe 'x' a.ts",
|
|
631
|
-
"ruby -rjson -pi -e 'x' a.ts",
|
|
632
|
-
"gawk -i inplace '{print}' a.ts",
|
|
633
|
-
"awk -f x.awk -i inplace a.ts",
|
|
634
|
-
]) {
|
|
635
|
-
assert.equal(shellWrites(command), true, command);
|
|
636
|
-
}
|
|
637
|
-
const session = parseLines([
|
|
638
|
-
JSON.stringify({ type: "assistant", message: { role: "assistant", content: [{ type: "tool_use", id: "t1", name: "Bash", input: { command: "ruby -Ilib -Itest test/foo_test.rb" } }] } }),
|
|
639
|
-
JSON.stringify({ type: "user", message: { role: "user", content: [{ type: "tool_result", tool_use_id: "t1", content: "1 runs, 0 failures" }] } }),
|
|
640
|
-
]);
|
|
641
|
-
assert.equal(session.meta.hasFileEdits, false);
|
|
642
|
-
});
|
|
643
|
-
test("tells a shell command that writes a file from one that only looks", () => {
|
|
644
|
-
for (const command of [
|
|
645
|
-
"sed -i 's/old/new/' src/a.ts",
|
|
646
|
-
"perl -pi -e 's/a/b/' src/a.ts",
|
|
647
|
-
"python3 - <<'PY'\nopen('src/a.ts', 'w').write('x')\nPY",
|
|
648
|
-
"cat <<'EOF' > src/a.ts\nbody\nEOF",
|
|
649
|
-
"echo x >> src/a.ts",
|
|
650
|
-
"npm run gen && printf ok | tee src/out.txt",
|
|
651
|
-
"git apply fix.patch",
|
|
652
|
-
"mv src/a.ts src/b.ts",
|
|
653
|
-
]) {
|
|
654
|
-
assert.equal(shellWrites(command), true, command);
|
|
655
|
-
}
|
|
656
|
-
for (const command of [
|
|
657
|
-
"rg -n 'drain' src 2>/dev/null",
|
|
658
|
-
"npm test 2>&1 | tail -20",
|
|
659
|
-
"grep -n \"=> \" src/a.ts",
|
|
660
|
-
"sed -n '1,40p' src/a.ts",
|
|
661
|
-
"cat src/a.ts > /dev/null",
|
|
662
|
-
"git diff > /tmp/p.diff",
|
|
663
|
-
"ls src",
|
|
664
|
-
]) {
|
|
665
|
-
assert.equal(shellWrites(command), false, command);
|
|
666
|
-
}
|
|
667
|
-
});
|
|
668
|
-
test("a session counts as editing files however the files were edited", () => {
|
|
669
|
-
const call = (id, name, input) => assistant(id, null, [{ type: "tool_use", id: `toolu_${id}`, name, input }]);
|
|
670
|
-
const hasEdits = (...records) => parseLines(jsonl(records)).meta.hasFileEdits;
|
|
671
|
-
assert.equal(hasEdits(call("a", "Edit", { file_path: "/repo/a.ts", old_string: "a", new_string: "b" })), true);
|
|
672
|
-
assert.equal(hasEdits(call("a", "Bash", { command: "sed -i 's/a/b/' src/a.ts" })), true);
|
|
673
|
-
// Kimi and whatever comes next: an editor under a name nobody told the parser about.
|
|
674
|
-
assert.equal(hasEdits(call("a", "Grep", { pattern: "x" }), call("b", "StrReplaceFile", { path: "a.ts" })), true);
|
|
675
|
-
assert.equal(hasEdits(call("a", "Read", { file_path: "/repo/a.ts" }), call("b", "Bash", { command: "rg -n x src" })), false);
|
|
676
|
-
assert.equal(hasEdits(assistant("a", null, [{ type: "text", text: "nothing to do" }])), false);
|
|
677
|
-
});
|
|
678
|
-
test("a session that committed counts as editing files, however the files changed", () => {
|
|
679
|
-
const call = (id, command) => assistant(id, null, [{ type: "tool_use", id: `toolu_${id}`, name: "Bash", input: { command } }]);
|
|
680
|
-
const hasEdits = (...records) => parseLines(jsonl(records)).meta.hasFileEdits;
|
|
681
|
-
for (const command of ["gofmt -w . && git add . && git commit -m x", "git -C app commit -am x", "npm run format; git commit"]) {
|
|
682
|
-
assert.equal(hasEdits(call("a", command)), true, command);
|
|
683
|
-
}
|
|
684
|
-
for (const command of [
|
|
685
|
-
"git status",
|
|
686
|
-
"git log --grep commit",
|
|
687
|
-
"grep -rn 'git commit' .",
|
|
688
|
-
"echo \"git commit\"",
|
|
689
|
-
"cat <<'EOF'\ngit commit -m x\nEOF",
|
|
690
|
-
"npm --prefix tools/commit test",
|
|
691
|
-
]) {
|
|
692
|
-
assert.equal(hasEdits(call("a", command)), false, command);
|
|
693
|
-
}
|
|
694
|
-
// Nothing to commit, or a hook that said no: it put nothing anywhere.
|
|
695
|
-
const failed = { ...toolResult("b", "a", "toolu_a"), message: { role: "user", content: [{ type: "tool_result", tool_use_id: "toolu_a", is_error: true, content: "nothing to commit" }] } };
|
|
696
|
-
assert.equal(hasEdits(call("a", "git commit -m x"), failed), false);
|
|
697
|
-
});
|
|
698
|
-
test("counts reasoning only when there is text in it", () => {
|
|
699
|
-
const session = parseLines(jsonl([
|
|
700
|
-
assistant("a", null, [{ type: "thinking", thinking: "", signature: "EqMock==" }]),
|
|
701
|
-
assistant("b", "a", [{ type: "thinking", thinking: " \n", signature: "EqMock==" }]),
|
|
702
|
-
assistant("c", "b", [{ type: "redacted_thinking", data: "EmwKAhgB" }]),
|
|
703
|
-
assistant("d", "c", [{ type: "thinking", thinking: "the retry path is not covered", signature: "EqMock==" }]),
|
|
704
|
-
]));
|
|
705
|
-
assert.equal(session.meta.thinkingBlocks, 1);
|
|
706
|
-
assert.equal(session.meta.hiddenThinkingBlocks, 3);
|
|
707
|
-
assert.deepEqual(session.blocks.map((block) => block.text), [undefined, " \n", undefined, "the retry path is not covered"]);
|
|
708
|
-
});
|
|
709
|
-
test("knows every record type Claude Code 2.1 writes", () => {
|
|
710
|
-
const session = parseLines(jsonl([
|
|
711
|
-
{ type: "atis-latch", atis: "", sessionId: "s1" },
|
|
712
|
-
{ type: "cost-state", sessionId: "s1", totalCostUSD: 0.1 },
|
|
713
|
-
{ type: "ai-title", aiTitle: "Fix add", sessionId: "s1" },
|
|
714
|
-
{ type: "last-prompt", lastPrompt: "fix it", leafUuid: "a", sessionId: "s1" },
|
|
715
|
-
{ type: "queue-operation", operation: "enqueue", sessionId: "s1" },
|
|
716
|
-
{ type: "content-replacement", sessionId: "s1", replacements: [] },
|
|
717
|
-
{ type: "worktree-state", sessionId: "s1" },
|
|
718
|
-
{ type: "custom-title", customTitle: "x", sessionId: "s1" },
|
|
719
|
-
{ type: "attribution-snapshot", sessionId: "s1" },
|
|
720
|
-
{ type: "progress", sessionId: "s1" },
|
|
721
|
-
{ type: "tools-used", tools: ["Read", "Bash"], sessionId: "s1" },
|
|
722
|
-
]));
|
|
723
|
-
assert.deepEqual(session.skipped.unknownTypes, {});
|
|
724
|
-
});
|
|
725
|
-
test("follows a compaction back to the work before it", () => {
|
|
726
|
-
const session = parseLines(jsonl([
|
|
727
|
-
assistant("a", null, [{ type: "text", text: "start" }]),
|
|
728
|
-
assistant("rewound", "a", [
|
|
729
|
-
{ type: "tool_use", id: "t1", name: "Edit", input: { file_path: "/repo/a.ts" } },
|
|
730
|
-
]),
|
|
731
|
-
assistant("b", "a", [{ type: "text", text: "kept" }]),
|
|
732
|
-
// Claude Code starts the chain over at a compaction: no parent, only a logical one.
|
|
733
|
-
{
|
|
734
|
-
type: "system",
|
|
735
|
-
subtype: "compact_boundary",
|
|
736
|
-
uuid: "boundary",
|
|
737
|
-
parentUuid: null,
|
|
738
|
-
logicalParentUuid: "b",
|
|
739
|
-
sessionId: "s1",
|
|
740
|
-
compactMetadata: { trigger: "manual", preTokens: 1280 },
|
|
741
|
-
},
|
|
742
|
-
{ type: "user", uuid: "summary", parentUuid: "boundary", isCompactSummary: true, message: { role: "user", content: "summary" } },
|
|
743
|
-
assistant("c", "summary", [{ type: "text", text: "after" }]),
|
|
744
|
-
]));
|
|
745
|
-
for (const uuid of ["c", "summary", "boundary", "b", "a"])
|
|
746
|
-
assert.equal(onMainPath(session, uuid), true, uuid);
|
|
747
|
-
assert.equal(onMainPath(session, "rewound"), false);
|
|
748
|
-
assert.equal(onAbandonedBranch(session, "rewound"), true);
|
|
749
|
-
});
|
|
750
|
-
test("records that share a way back share what is found at its end", () => {
|
|
751
|
-
const session = parseLines(jsonl([
|
|
752
|
-
assistant("a", null, []),
|
|
753
|
-
assistant("side", "a", []),
|
|
754
|
-
assistant("side2", "side", []),
|
|
755
|
-
assistant("lost", "gone-from-this-file", []),
|
|
756
|
-
assistant("lost2", "lost", []),
|
|
757
|
-
{ ...assistant("loop1", "loop2", []) },
|
|
758
|
-
{ ...assistant("loop2", "loop1", []) },
|
|
759
|
-
assistant("loop3", "loop2", []),
|
|
760
|
-
assistant("b", "a", []),
|
|
761
|
-
]));
|
|
762
|
-
const known = new Map();
|
|
763
|
-
for (const uuid of ["side2", "side", "lost2", "lost", "loop3", "loop2", "loop1", "a", "b", "nobody"]) {
|
|
764
|
-
assert.equal(onAbandonedBranch(session, uuid, known), onAbandonedBranch(session, uuid), uuid);
|
|
765
|
-
}
|
|
766
|
-
assert.equal(onAbandonedBranch(session, "side2", known), true);
|
|
767
|
-
assert.equal(onAbandonedBranch(session, "lost2", known), false);
|
|
768
|
-
assert.equal(onAbandonedBranch(session, "loop3", known), false);
|
|
769
|
-
});
|
|
770
|
-
test("an unknown tool counts as an edit only when it could have named a file", () => {
|
|
771
|
-
// Claude Code 2.1 bookkeeping: known, and a file is not among their arguments anyway.
|
|
772
|
-
assert.equal(mayWrite("TaskCreate", { subject: "a", description: "b" }), false);
|
|
773
|
-
assert.equal(mayWrite("SubagentHandback", { message: "done" }), false);
|
|
774
|
-
assert.equal(mayWrite("EnterWorktree", { name: "fix" }), false);
|
|
775
|
-
// A tool this parser has never heard of, told nothing about a file.
|
|
776
|
-
assert.equal(mayWrite("ScheduleSomething", { when: "tomorrow", note: "x" }), false);
|
|
777
|
-
// Told about a file, handed code, or with arguments nobody could read.
|
|
778
|
-
assert.equal(mayWrite("StrReplaceFile", { path: "a.ts", edit: {} }), true);
|
|
779
|
-
assert.equal(mayWrite("exec", { script: "tools.apply_patch(p)" }), true);
|
|
780
|
-
assert.equal(mayWrite("apply_patch", {}), true);
|
|
781
|
-
// Code runners write wherever their code says.
|
|
782
|
-
assert.equal(mayWrite("PowerShell", { command: "Set-Content a.ts x" }), true);
|
|
783
|
-
assert.equal(mayWrite("REPL", { code: "fs.writeFileSync('a')" }), true);
|
|
784
|
-
// Writers that never name a file: a patch Codex's adapter could not parse, a git merge.
|
|
785
|
-
assert.equal(mayWrite("apply_patch", { input: "*** Begin Patch\r\n" }), true);
|
|
786
|
-
assert.equal(mayWrite("TowerMerge", { branch: "tower/m1" }), true);
|
|
787
|
-
// Kimi Code's Tower bookkeeping, some of it with no arguments at all.
|
|
788
|
-
assert.equal(mayWrite("TowerInit", {}), false);
|
|
789
|
-
assert.equal(mayWrite("TowerStatus", {}), false);
|
|
790
|
-
assert.equal(mayWrite("TowerFinding", { file: "a.ts", note: "x" }), false);
|
|
791
|
-
// The edit tools are counted on their own.
|
|
792
|
-
assert.equal(mayWrite("Edit", { file_path: "a.ts" }), false);
|
|
793
|
-
// An MCP tool counts when its name says it writes and it is told where.
|
|
794
|
-
assert.equal(mayWrite("mcp__fs__write_file", { path: "a.ts", content: "x" }), true);
|
|
795
|
-
assert.equal(mayWrite("mcp__serena__replace_symbol_body", { name_path: "f", relative_path: "a.ts", body: "x" }), true);
|
|
796
|
-
assert.equal(mayWrite("mcp__fs__editFile", { path: "a.ts", edits: [] }), true);
|
|
797
|
-
assert.equal(mayWrite("mcp__fs__read_file", { path: "a.ts" }), false);
|
|
798
|
-
assert.equal(mayWrite("mcp__github__get_file_contents", { owner: "o", repo: "r", path: "a.ts" }), false);
|
|
799
|
-
assert.equal(mayWrite("mcp__github__create_issue", { owner: "o", repo: "r", title: "t" }), false);
|
|
800
|
-
});
|
|
801
|
-
test("a subagent that never came back may have edited", () => {
|
|
802
|
-
const launch = (name = "Agent") => [
|
|
803
|
-
assistant("a", null, [
|
|
804
|
-
{ type: "tool_use", id: "toolu_agent", name, input: { prompt: "fix it", run_in_background: true } },
|
|
805
|
-
]),
|
|
806
|
-
// A background subagent answers at once, and with no count of its edits.
|
|
807
|
-
toolResult("b", "a", "toolu_agent", {
|
|
808
|
-
toolUseResult: { isAsync: true, status: "async_launched", agentId: "ad7e" },
|
|
809
|
-
}),
|
|
810
|
-
];
|
|
811
|
-
const hasEdits = (records) => parseLines(jsonl(records)).meta.hasFileEdits;
|
|
812
|
-
// Uploaded without its file: nothing says it did not edit.
|
|
813
|
-
assert.equal(hasEdits(launch()), true);
|
|
814
|
-
assert.equal(hasEdits(launch("TowerSpawn")), true);
|
|
815
|
-
// Its records came along, and they say what it did — here, nothing.
|
|
816
|
-
const read = {
|
|
817
|
-
...assistant("s1", null, [{ type: "tool_use", id: "toolu_s1", name: "Read", input: { file_path: "/repo/a.ts" } }]),
|
|
818
|
-
isSidechain: true,
|
|
819
|
-
agentId: "ad7e",
|
|
820
|
-
parentToolUseID: "toolu_agent",
|
|
821
|
-
};
|
|
822
|
-
assert.equal(hasEdits([...launch(), read]), false);
|
|
823
|
-
// A call that failed started nothing.
|
|
824
|
-
const refused = {
|
|
825
|
-
...toolResult("b", "a", "toolu_agent"),
|
|
826
|
-
message: {
|
|
827
|
-
role: "user",
|
|
828
|
-
content: [{ type: "tool_result", tool_use_id: "toolu_agent", content: "unknown agent type", is_error: true }],
|
|
829
|
-
},
|
|
830
|
-
};
|
|
831
|
-
assert.equal(hasEdits([launch()[0], refused]), false);
|
|
832
|
-
});
|
|
833
|
-
test("a session whose subagent edited files counts as editing, even without its records", () => {
|
|
834
|
-
const session = parseLines(jsonl([
|
|
835
|
-
assistant("a", null, [
|
|
836
|
-
{ type: "tool_use", id: "toolu_agent", name: "Agent", input: { description: "fix", prompt: "fix it" } },
|
|
837
|
-
]),
|
|
838
|
-
toolResult("b", "a", "toolu_agent", {
|
|
839
|
-
toolUseResult: { status: "completed", agentId: "ad7e", toolStats: { readCount: 1, editFileCount: 1 } },
|
|
840
|
-
}),
|
|
841
|
-
]));
|
|
842
|
-
assert.equal(session.meta.editToolUses, 0);
|
|
843
|
-
assert.equal(session.meta.hasFileEdits, true);
|
|
844
|
-
const untouched = parseLines(jsonl([
|
|
845
|
-
assistant("a", null, [{ type: "tool_use", id: "toolu_agent", name: "Agent", input: { prompt: "look" } }]),
|
|
846
|
-
toolResult("b", "a", "toolu_agent", { toolUseResult: { agentId: "ad7e", toolStats: { editFileCount: 0 } } }),
|
|
847
|
-
]));
|
|
848
|
-
assert.equal(untouched.meta.hasFileEdits, false);
|
|
849
|
-
});
|
|
850
|
-
test("a git command is told by what the shell runs, not by the words in it", () => {
|
|
851
|
-
const cases = [
|
|
852
|
-
["git commit -m x", ["commit"]],
|
|
853
|
-
["git add . && git commit -am x", ["add", "commit"]],
|
|
854
|
-
["cd app && git -C sub -c user.name='A B' --no-pager commit", ["commit"]],
|
|
855
|
-
["GIT_AUTHOR_NAME=x sudo git rebase main", ["rebase"]],
|
|
856
|
-
["if git pull --rebase; then echo ok; fi", ["pull"]],
|
|
857
|
-
["(git cherry-pick abc)", ["cherry-pick"]],
|
|
858
|
-
["git commit-tree abc", ["commit-tree"]],
|
|
859
|
-
["pytest tests/git/ -x", []],
|
|
860
|
-
["tail -f ~/git/app/server.log", []],
|
|
861
|
-
["cd ~/git/other && npm test", []],
|
|
862
|
-
["npm --prefix tools/commit run dev", []],
|
|
863
|
-
['echo "git commit -m x"', []],
|
|
864
|
-
["cat > note.md <<'EOF'\ngit commit -m x\nEOF", []],
|
|
865
|
-
["git --version", []],
|
|
866
|
-
];
|
|
867
|
-
for (const [command, expected] of cases)
|
|
868
|
-
assert.deepEqual(gitCommands(command), expected, command);
|
|
869
|
-
});
|
|
870
|
-
test("telling a git command from anything else gets through 200 KB of text built to stall it", () => {
|
|
871
|
-
for (const text of [
|
|
872
|
-
"git ".repeat(50_000),
|
|
873
|
-
`git ${"-x ".repeat(66_000)}`,
|
|
874
|
-
`git ${"-C a ".repeat(40_000)}`,
|
|
875
|
-
`${"a=b ".repeat(50_000)}git commit`,
|
|
876
|
-
`${"( ".repeat(100_000)}git`,
|
|
877
|
-
`git commit "${'\\"'.repeat(100_000)}`,
|
|
878
|
-
]) {
|
|
879
|
-
const started = performance.now();
|
|
880
|
-
gitCommands(text);
|
|
881
|
-
const took = performance.now() - started;
|
|
882
|
-
assert.ok(took < 1000, `took ${Math.round(took)} ms`);
|
|
883
|
-
}
|
|
884
|
-
});
|
|
885
|
-
test("a command only looks when every part of it is known to, and anything else nobody can say", () => {
|
|
886
|
-
for (const command of [
|
|
887
|
-
"git status",
|
|
888
|
-
"git log --oneline -5 | head -3",
|
|
889
|
-
"git add -A && git commit -m 'run npm install' && git push",
|
|
890
|
-
"git switch -c topic",
|
|
891
|
-
"gh pr create --fill",
|
|
892
|
-
"cd src && ls -la; pwd",
|
|
893
|
-
"# what is there\ncat README.md",
|
|
894
|
-
"grep -rn 'npm run build' . | sort | uniq",
|
|
895
|
-
"for f in a b; do cat $f; done",
|
|
896
|
-
"if [ -f a ]; then echo yes; fi",
|
|
897
|
-
"cat > docs/notes.md <<'EOF'\nnpm run build\nEOF",
|
|
898
|
-
"sed -i 's/a/b/' a.txt",
|
|
899
|
-
"",
|
|
900
|
-
]) {
|
|
901
|
-
assert.equal(shellOnlyLooks(command), true, command);
|
|
902
|
-
}
|
|
903
|
-
for (const command of [
|
|
904
|
-
"npm run format",
|
|
905
|
-
"npm install",
|
|
906
|
-
"cargo fmt",
|
|
907
|
-
"python3 -c \"open('a','w')\"",
|
|
908
|
-
"python3 - <<'PY'\nprint(1)\nPY",
|
|
909
|
-
"npx prettier --write src/a.ts",
|
|
910
|
-
"./scripts/gen.sh",
|
|
911
|
-
"git apply fix.patch",
|
|
912
|
-
"git pull",
|
|
913
|
-
"git stash pop",
|
|
914
|
-
"git status && make",
|
|
915
|
-
"cat a.txt | xargs rm",
|
|
916
|
-
"echo $(npm run build)",
|
|
917
|
-
"touch a.txt",
|
|
918
|
-
"curl -o a.txt http://x/y",
|
|
919
|
-
]) {
|
|
920
|
-
assert.equal(shellOnlyLooks(command), false, command);
|
|
921
|
-
}
|
|
922
|
-
// A write whose target only the shell can spell out, or that a flag hides.
|
|
923
|
-
for (const command of [
|
|
924
|
-
"sed -i 's/one/two/' src/*.txt",
|
|
925
|
-
"sed -i 's/one/two/' $(git ls-files '*.txt')",
|
|
926
|
-
"sed -i 's/one/two/' $(grep -rl one src)",
|
|
927
|
-
'for f in src/*.txt; do sed -i "s/one/two/" "$f"; done',
|
|
928
|
-
"for f in a b; do echo x > src/$f.txt; done",
|
|
929
|
-
"awk -i inplace '{print}' src/*.txt",
|
|
930
|
-
'cat README > "src/$(echo a).txt"',
|
|
931
|
-
'printf x > "$OUT"',
|
|
932
|
-
"sed -i 's/a/b/' src/{a,b}.txt",
|
|
933
|
-
"sudo sed -i 's/one/two/' src/*.txt",
|
|
934
|
-
"cd src && sed -i 's/one/two/' *.txt",
|
|
935
|
-
"git checkout other -- src/a.txt",
|
|
936
|
-
"git checkout stash@{0} -- .",
|
|
937
|
-
"git checkout HEAD~1 src/a.txt",
|
|
938
|
-
"git checkout other src/a.txt",
|
|
939
|
-
"git checkout -p other -- f",
|
|
940
|
-
"git checkout --ours a.txt",
|
|
941
|
-
"git -C app checkout other -- a.txt",
|
|
942
|
-
"yq -i '.a=1' chart.yaml",
|
|
943
|
-
"yq e -i '.a=1' chart.yaml",
|
|
944
|
-
"sort -o src/a.txt src/a.txt",
|
|
945
|
-
"sort -u --output=a.txt a.txt",
|
|
946
|
-
"uniq in.txt out.txt",
|
|
947
|
-
"uniq -c in.txt out.txt",
|
|
948
|
-
"gh pr checkout 12",
|
|
949
|
-
`awk '{print > "out.txt"}' a.txt`,
|
|
950
|
-
`awk -F: '{printf "%s", $1 > "out.txt"}' a.txt`,
|
|
951
|
-
`awk "{print > \\"out.txt\\"}" a.txt`,
|
|
952
|
-
`awk '{print | "sort > out.txt"}' a.txt`,
|
|
953
|
-
`awk 'BEGIN { system("touch a") }'`,
|
|
954
|
-
"sed -n 'w out.txt' a.txt",
|
|
955
|
-
"sed -n '/x/w out.txt' a.txt",
|
|
956
|
-
"sed 's/a/b/w out.txt' a.txt",
|
|
957
|
-
"sed 's/a/b/gw out.txt' a.txt",
|
|
958
|
-
"sudo sed -n '1,5{w out.txt\n}' a.txt",
|
|
959
|
-
"sed -n '1,5w out.txt' a.txt",
|
|
960
|
-
"sed -n '$W out.txt' a.txt",
|
|
961
|
-
"git log --output=history.txt",
|
|
962
|
-
"git diff --output=change.patch",
|
|
963
|
-
"git -C app log --output history.txt",
|
|
964
|
-
"gh release download v1 --pattern '*.tgz'",
|
|
965
|
-
"gh run download 123 -n build",
|
|
966
|
-
"gh repo clone owner/vendored vendor/lib",
|
|
967
|
-
"gh gist clone abc",
|
|
968
|
-
"xxd -r dump.hex out.bin",
|
|
969
|
-
"xxd -r -p dump.hex out.bin",
|
|
970
|
-
"xxd a.bin dump.hex",
|
|
971
|
-
]) {
|
|
972
|
-
assert.equal(shellOnlyLooks(command), false, command);
|
|
973
|
-
}
|
|
974
|
-
// The same words where nothing is written: these name no target at all.
|
|
975
|
-
for (const command of [
|
|
976
|
-
"git checkout main",
|
|
977
|
-
"git checkout -",
|
|
978
|
-
"git checkout -b feat",
|
|
979
|
-
"git checkout -b feat origin/main",
|
|
980
|
-
"git checkout -q feat | tail -3",
|
|
981
|
-
"git -C app checkout --track origin/x",
|
|
982
|
-
"cat src/*.txt",
|
|
983
|
-
"grep -n one src/*.txt",
|
|
984
|
-
"echo $(date)",
|
|
985
|
-
"yq '.a' chart.yaml",
|
|
986
|
-
"sort -u a.txt",
|
|
987
|
-
"sort a.txt | uniq -c",
|
|
988
|
-
"uniq a.txt",
|
|
989
|
-
"ls src/*.txt 2>/dev/null",
|
|
990
|
-
'echo "$x" > /tmp/out',
|
|
991
|
-
"awk '$1 > 5 {print}' a.txt",
|
|
992
|
-
"awk '{print $1}' a.txt | sort",
|
|
993
|
-
"awk '{print}' a.txt > out.txt",
|
|
994
|
-
"awk -F'>' '{print $2}' a.txt",
|
|
995
|
-
"sed -n '1,5p' a.txt",
|
|
996
|
-
"sed -n 's/a/b/p' a.txt",
|
|
997
|
-
"sed -E 's/(\\w+) (\\w+)/\\2/' a.txt",
|
|
998
|
-
"git log --oneline -3",
|
|
999
|
-
"git diff --stat",
|
|
1000
|
-
"gh pr view 12",
|
|
1001
|
-
"gh release view v1",
|
|
1002
|
-
"gh run view 123",
|
|
1003
|
-
"xxd a.bin",
|
|
1004
|
-
"xxd -r dump.hex",
|
|
1005
|
-
]) {
|
|
1006
|
-
assert.equal(shellOnlyLooks(command), true, command);
|
|
1007
|
-
}
|
|
1008
|
-
});
|
|
1009
|
-
test("a line is charged what its objects, arrays and keys will cost once parsed", () => {
|
|
1010
|
-
const charged = (line) => {
|
|
1011
|
-
const structures = { left: 1000 };
|
|
1012
|
-
assert.equal(mayParse(line, structures), true);
|
|
1013
|
-
return 1000 - structures.left;
|
|
1014
|
-
};
|
|
1015
|
-
assert.equal(charged("{}"), 3);
|
|
1016
|
-
assert.equal(charged("[[]]"), 6);
|
|
1017
|
-
assert.equal(charged('{"a":0,"b" :1,"c"\t: 2}'), 6);
|
|
1018
|
-
assert.equal(charged('"a colon: in words"'), 0);
|
|
1019
|
-
assert.equal(charged("[0.5,0.5,0.5,0.5]"), 4);
|
|
1020
|
-
});
|
|
1021
|
-
test("objects of hundreds of small keys fit a session only as far as a heap holds them", () => {
|
|
1022
|
-
// Parsed, one of these takes 25 KB out of 2.4 KB of line.
|
|
1023
|
-
const keys = Array.from({ length: 342 }, (_, i) => `"k${i}":0`).join(",");
|
|
1024
|
-
const line = `{"type":"user","x":{${keys}}}`;
|
|
1025
|
-
const structures = { left: STRUCTURES };
|
|
1026
|
-
let fit = 0;
|
|
1027
|
-
while (mayParse(line, structures))
|
|
1028
|
-
fit += 1;
|
|
1029
|
-
assert.ok(fit * 25_000 < 1_300_000_000, `${fit} of them fit`);
|
|
1030
|
-
});
|
|
1031
|
-
test("arrays of small numbers fit a session only as far as a heap holds them", () => {
|
|
1032
|
-
// Parsed, each of these takes 24 bytes out of 4 of line.
|
|
1033
|
-
const items = 3_000;
|
|
1034
|
-
const line = `{"type":"user","x":[${"0.5,".repeat(items)}0]}`;
|
|
1035
|
-
const structures = { left: STRUCTURES };
|
|
1036
|
-
let fit = 0;
|
|
1037
|
-
while (mayParse(line, structures))
|
|
1038
|
-
fit += 1;
|
|
1039
|
-
assert.ok(fit * items * 24 < 1_300_000_000, `${fit} of them fit`);
|
|
1040
|
-
});
|
|
1041
|
-
//# sourceMappingURL=parser.test.js.map
|