@nightloom/isy 1.0.5 → 1.0.6-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 +17 -2
- package/dist/agents/claude.js +3 -2
- package/dist/agents/claude.js.map +1 -1
- package/dist/agents/codex.js +14 -5
- package/dist/agents/codex.js.map +1 -1
- package/dist/agents/index.d.ts +14 -10
- package/dist/agents/index.js +65 -15
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/kimi.js +26 -8
- package/dist/agents/kimi.js.map +1 -1
- package/dist/agents/types.d.ts +12 -3
- package/dist/commands/commit.d.ts +6 -0
- package/dist/commands/commit.js +326 -16
- package/dist/commands/commit.js.map +1 -1
- package/dist/commands/health.js +1 -1
- package/dist/commands/health.js.map +1 -1
- package/dist/commands/init.js +30 -5
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/status.d.ts +2 -0
- package/dist/commands/status.js +7 -4
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/upload.d.ts +8 -1
- package/dist/commands/upload.js +46 -39
- package/dist/commands/upload.js.map +1 -1
- package/dist/detectors.d.ts +32 -0
- package/dist/detectors.js +279 -72
- package/dist/detectors.js.map +1 -1
- package/dist/git.d.ts +52 -0
- package/dist/git.js +166 -9
- package/dist/git.js.map +1 -1
- package/dist/githook.d.ts +18 -7
- package/dist/githook.js +147 -17
- package/dist/githook.js.map +1 -1
- package/dist/hook.d.ts +22 -2
- package/dist/hook.js +28 -3
- package/dist/hook.js.map +1 -1
- package/dist/index.js +14 -5
- package/dist/index.js.map +1 -1
- package/dist/mask-paths.d.ts +4 -3
- package/dist/mask-paths.js +4 -3
- package/dist/mask-paths.js.map +1 -1
- package/dist/parser.d.ts +58 -9
- package/dist/parser.js +337 -58
- package/dist/parser.js.map +1 -1
- package/dist/paths.d.ts +19 -1
- package/dist/paths.js +28 -3
- package/dist/paths.js.map +1 -1
- package/dist/redact.d.ts +2 -0
- package/dist/redact.js +956 -97
- package/dist/redact.js.map +1 -1
- package/dist/stage0.js +27 -8
- package/dist/stage0.js.map +1 -1
- package/dist/state.d.ts +15 -0
- package/dist/state.js +8 -0
- package/dist/state.js.map +1 -1
- package/dist/test/check.test.js +1 -1
- package/dist/test/check.test.js.map +1 -1
- package/dist/test/codex.test.js +27 -4
- package/dist/test/codex.test.js.map +1 -1
- package/dist/test/commit.test.js +1466 -6
- package/dist/test/commit.test.js.map +1 -1
- package/dist/test/e2e-harness.test.d.ts +1 -0
- package/dist/test/e2e-harness.test.js +53 -0
- package/dist/test/e2e-harness.test.js.map +1 -0
- package/dist/test/git.test.js +72 -2
- package/dist/test/git.test.js.map +1 -1
- package/dist/test/hook.test.js +138 -3
- package/dist/test/hook.test.js.map +1 -1
- package/dist/test/init.test.js +60 -1
- package/dist/test/init.test.js.map +1 -1
- package/dist/test/kimi-config.test.js +27 -5
- package/dist/test/kimi-config.test.js.map +1 -1
- package/dist/test/kimi-hook.test.js +1 -1
- package/dist/test/kimi-hook.test.js.map +1 -1
- package/dist/test/kimi-listing.test.js +42 -2
- package/dist/test/kimi-listing.test.js.map +1 -1
- package/dist/test/kimi.test.js +26 -2
- package/dist/test/kimi.test.js.map +1 -1
- package/dist/test/parser.test.js +527 -1
- package/dist/test/parser.test.js.map +1 -1
- package/dist/test/redact.test.js +2442 -14
- package/dist/test/redact.test.js.map +1 -1
- package/dist/test/stage0.test.js +617 -1
- package/dist/test/stage0.test.js.map +1 -1
- package/dist/test/sweep.test.js +99 -3
- package/dist/test/sweep.test.js.map +1 -1
- package/package.json +1 -1
- package/src/agents/claude.ts +3 -2
- package/src/agents/codex.ts +14 -5
- package/src/agents/index.ts +71 -16
- package/src/agents/kimi.ts +28 -8
- package/src/agents/types.ts +12 -3
- package/src/commands/commit.ts +354 -18
- package/src/commands/health.ts +1 -1
- package/src/commands/init.ts +37 -7
- package/src/commands/status.ts +9 -4
- package/src/commands/upload.ts +54 -54
- package/src/detectors.ts +284 -75
- package/src/git.ts +175 -9
- package/src/githook.ts +151 -19
- package/src/hook.ts +30 -3
- package/src/index.ts +15 -5
- package/src/mask-paths.ts +5 -4
- package/src/parser.ts +355 -51
- package/src/paths.ts +30 -3
- package/src/redact.ts +959 -100
- package/src/stage0.ts +28 -8
- package/src/state.ts +18 -0
package/dist/test/parser.test.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
+
import { execFile } from "node:child_process";
|
|
2
3
|
import { existsSync } from "node:fs";
|
|
3
4
|
import { homedir } from "node:os";
|
|
4
5
|
import { join } from "node:path";
|
|
5
6
|
import { readFile, readdir } from "node:fs/promises";
|
|
6
7
|
import { test } from "node:test";
|
|
8
|
+
import { promisify } from "node:util";
|
|
7
9
|
import { claudeAgent } from "../agents/claude.js";
|
|
8
|
-
import {
|
|
10
|
+
import { detectUnverifiedAssumption } from "../detectors.js";
|
|
11
|
+
import { STRUCTURES, commandSegments, mayParse, mayWrite, onAbandonedBranch, onMainPath, parseLines, shellEditPaths, shellReadPaths, shellWrites, gitCommands, shellOnlyLooks, withoutHeredocs, } from "../parser.js";
|
|
9
12
|
import { subagentsOf } from "../subagents.js";
|
|
13
|
+
const execFileAsync = promisify(execFile);
|
|
10
14
|
function jsonl(records) {
|
|
11
15
|
return records.map((record) => JSON.stringify(record));
|
|
12
16
|
}
|
|
@@ -307,6 +311,90 @@ test("names the files sed -i and perl -i rewrite, and not their scripts", () =>
|
|
|
307
311
|
assert.deepEqual(shellEditPaths("sed -n '1,5p' src/a.ts"), []);
|
|
308
312
|
assert.deepEqual(shellEditPaths("sed 's/ -i //' src/a.ts"), [], "-i inside the script");
|
|
309
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
|
+
}
|
|
310
398
|
});
|
|
311
399
|
test("resolves a sed -i path against the directory the command ran in", () => {
|
|
312
400
|
assert.deepEqual(shellEditPaths("sed -i 's/a/b/' ./src/a.ts", "/repo"), ["/repo/src/a.ts"]);
|
|
@@ -316,11 +404,148 @@ test("resolves a sed -i path against the directory the command ran in", () => {
|
|
|
316
404
|
assert.deepEqual(shellEditPaths("cd /elsewhere && sed -i 's/a/b/' a.ts", "/repo"), ["/elsewhere/a.ts"]);
|
|
317
405
|
assert.deepEqual(shellEditPaths("cd $DIR && sed -i 's/a/b/' a.ts", "/repo"), ["a.ts"], "a cd it cannot follow");
|
|
318
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
|
+
});
|
|
319
539
|
test("stops at a redirection so a heredoc write is not read as a lookup", () => {
|
|
320
540
|
assert.deepEqual(shellReadPaths("cat > src/new.ts <<EOF"), []);
|
|
321
541
|
assert.deepEqual(shellReadPaths("cat src/a.ts > /tmp/out.txt"), ["src/a.ts"]);
|
|
322
542
|
assert.deepEqual(shellReadPaths("cat src/a.ts 2>/dev/null"), ["src/a.ts"]);
|
|
323
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
|
+
});
|
|
324
549
|
test("a heredoc body is not part of the command that carries it", () => {
|
|
325
550
|
const command = [
|
|
326
551
|
"python3 - <<'PY'",
|
|
@@ -344,6 +569,76 @@ test("a command splits the way a shell would, not the way a regex does", () => {
|
|
|
344
569
|
"node run.js ",
|
|
345
570
|
'grep -rl "DROP TABLE" .',
|
|
346
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);
|
|
347
642
|
});
|
|
348
643
|
test("tells a shell command that writes a file from one that only looks", () => {
|
|
349
644
|
for (const command of [
|
|
@@ -380,6 +675,26 @@ test("a session counts as editing files however the files were edited", () => {
|
|
|
380
675
|
assert.equal(hasEdits(call("a", "Read", { file_path: "/repo/a.ts" }), call("b", "Bash", { command: "rg -n x src" })), false);
|
|
381
676
|
assert.equal(hasEdits(assistant("a", null, [{ type: "text", text: "nothing to do" }])), false);
|
|
382
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
|
+
});
|
|
383
698
|
test("counts reasoning only when there is text in it", () => {
|
|
384
699
|
const session = parseLines(jsonl([
|
|
385
700
|
assistant("a", null, [{ type: "thinking", thinking: "", signature: "EqMock==" }]),
|
|
@@ -432,6 +747,26 @@ test("follows a compaction back to the work before it", () => {
|
|
|
432
747
|
assert.equal(onMainPath(session, "rewound"), false);
|
|
433
748
|
assert.equal(onAbandonedBranch(session, "rewound"), true);
|
|
434
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
|
+
});
|
|
435
770
|
test("an unknown tool counts as an edit only when it could have named a file", () => {
|
|
436
771
|
// Claude Code 2.1 bookkeeping: known, and a file is not among their arguments anyway.
|
|
437
772
|
assert.equal(mayWrite("TaskCreate", { subject: "a", description: "b" }), false);
|
|
@@ -512,4 +847,195 @@ test("a session whose subagent edited files counts as editing, even without its
|
|
|
512
847
|
]));
|
|
513
848
|
assert.equal(untouched.meta.hasFileEdits, false);
|
|
514
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
|
+
});
|
|
515
1041
|
//# sourceMappingURL=parser.test.js.map
|