@odysx/codemind 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/provider/index.d.ts +52 -10
- package/dist/core/provider/index.js +99 -12
- package/package.json +6 -1
- package/dist/commands/agents.d.ts.map +0 -1
- package/dist/commands/agents.js.map +0 -1
- package/dist/commands/auth.d.ts.map +0 -1
- package/dist/commands/auth.js.map +0 -1
- package/dist/commands/chat.d.ts.map +0 -1
- package/dist/commands/chat.js.map +0 -1
- package/dist/commands/keys.d.ts.map +0 -1
- package/dist/commands/keys.js.map +0 -1
- package/dist/commands/local.d.ts.map +0 -1
- package/dist/commands/local.js.map +0 -1
- package/dist/commands/mcp.d.ts.map +0 -1
- package/dist/commands/mcp.js.map +0 -1
- package/dist/commands/prompts.d.ts.map +0 -1
- package/dist/commands/prompts.js.map +0 -1
- package/dist/commands/skills.d.ts.map +0 -1
- package/dist/commands/skills.js.map +0 -1
- package/dist/core/auth/index.d.ts.map +0 -1
- package/dist/core/auth/index.js.map +0 -1
- package/dist/core/config/index.d.ts.map +0 -1
- package/dist/core/config/index.js.map +0 -1
- package/dist/core/history.d.ts.map +0 -1
- package/dist/core/history.js.map +0 -1
- package/dist/core/markdown-renderer.d.ts.map +0 -1
- package/dist/core/markdown-renderer.js.map +0 -1
- package/dist/core/permissions/index.d.ts.map +0 -1
- package/dist/core/permissions/index.js.map +0 -1
- package/dist/core/provider/external.d.ts.map +0 -1
- package/dist/core/provider/external.js.map +0 -1
- package/dist/core/provider/index.d.ts.map +0 -1
- package/dist/core/provider/index.js.map +0 -1
- package/dist/core/registry/index.d.ts.map +0 -1
- package/dist/core/registry/index.js.map +0 -1
- package/dist/core/schema/types.d.ts.map +0 -1
- package/dist/core/schema/types.js.map +0 -1
- package/dist/core/terminal.d.ts.map +0 -1
- package/dist/core/terminal.js.map +0 -1
- package/dist/core/workspace/index.d.ts.map +0 -1
- package/dist/core/workspace/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/ui/app.d.ts.map +0 -1
- package/dist/ui/app.js.map +0 -1
- package/dist/ui/commands/cases/catalog.d.ts.map +0 -1
- package/dist/ui/commands/cases/catalog.js.map +0 -1
- package/dist/ui/commands/cases/misc.d.ts.map +0 -1
- package/dist/ui/commands/cases/misc.js.map +0 -1
- package/dist/ui/commands/cases/tasks.d.ts.map +0 -1
- package/dist/ui/commands/cases/tasks.js.map +0 -1
- package/dist/ui/commands/runCommand.d.ts.map +0 -1
- package/dist/ui/commands/runCommand.js.map +0 -1
- package/dist/ui/components/AgentPicker.d.ts.map +0 -1
- package/dist/ui/components/AgentPicker.js.map +0 -1
- package/dist/ui/components/AuthPicker.d.ts.map +0 -1
- package/dist/ui/components/AuthPicker.js.map +0 -1
- package/dist/ui/components/Banner.d.ts.map +0 -1
- package/dist/ui/components/Banner.js.map +0 -1
- package/dist/ui/components/CommandMenu.d.ts.map +0 -1
- package/dist/ui/components/CommandMenu.js.map +0 -1
- package/dist/ui/components/ErrorBoundary.d.ts.map +0 -1
- package/dist/ui/components/ErrorBoundary.js.map +0 -1
- package/dist/ui/components/InputBar.d.ts.map +0 -1
- package/dist/ui/components/InputBar.js.map +0 -1
- package/dist/ui/components/KeysPanel.d.ts.map +0 -1
- package/dist/ui/components/KeysPanel.js.map +0 -1
- package/dist/ui/components/MessageView.d.ts.map +0 -1
- package/dist/ui/components/MessageView.js.map +0 -1
- package/dist/ui/components/PermissionPrompt.d.ts.map +0 -1
- package/dist/ui/components/PermissionPrompt.js.map +0 -1
- package/dist/ui/components/Pickers.d.ts.map +0 -1
- package/dist/ui/components/Pickers.js.map +0 -1
- package/dist/ui/components/SearchOverlay.d.ts.map +0 -1
- package/dist/ui/components/SearchOverlay.js.map +0 -1
- package/dist/ui/components/SessionPicker.d.ts.map +0 -1
- package/dist/ui/components/SessionPicker.js.map +0 -1
- package/dist/ui/components/WorkingIndicator.d.ts.map +0 -1
- package/dist/ui/components/WorkingIndicator.js.map +0 -1
- package/dist/ui/controls/ApiKeyEntry.d.ts.map +0 -1
- package/dist/ui/controls/ApiKeyEntry.js.map +0 -1
- package/dist/ui/controls/MultiSelect.d.ts.map +0 -1
- package/dist/ui/controls/MultiSelect.js.map +0 -1
- package/dist/ui/hooks/useAgentPicker.d.ts.map +0 -1
- package/dist/ui/hooks/useAgentPicker.js.map +0 -1
- package/dist/ui/hooks/useAuthFlow.d.ts.map +0 -1
- package/dist/ui/hooks/useAuthFlow.js.map +0 -1
- package/dist/ui/hooks/useKeysFlow.d.ts.map +0 -1
- package/dist/ui/hooks/useKeysFlow.js.map +0 -1
- package/dist/ui/hooks/useSessionPicker.d.ts.map +0 -1
- package/dist/ui/hooks/useSessionPicker.js.map +0 -1
- package/dist/ui/hooks/useTerminalSize.d.ts.map +0 -1
- package/dist/ui/hooks/useTerminalSize.js.map +0 -1
- package/dist/ui/input/keyRouter.d.ts.map +0 -1
- package/dist/ui/input/keyRouter.js.map +0 -1
- package/dist/ui/layouts/ScreenLayout.d.ts.map +0 -1
- package/dist/ui/layouts/ScreenLayout.js.map +0 -1
- package/dist/ui/shared/types.d.ts.map +0 -1
- package/dist/ui/shared/types.js.map +0 -1
- package/dist/ui/theme.d.ts.map +0 -1
- package/dist/ui/theme.js.map +0 -1
- package/dist/ui/utils/markdown.d.ts.map +0 -1
- package/dist/ui/utils/markdown.js.map +0 -1
- package/dist/ui/utils/mentions.d.ts.map +0 -1
- package/dist/ui/utils/mentions.js.map +0 -1
- package/dist/ui/utils/terminal-text.d.ts.map +0 -1
- package/dist/ui/utils/terminal-text.js.map +0 -1
- package/dist/ui/utils/text.d.ts.map +0 -1
- package/dist/ui/utils/text.js.map +0 -1
- package/eslint.config.js +0 -40
- package/graphify-out/GRAPH_REPORT.md +0 -140
- package/graphify-out/cache/1236b1806943f8eb5c64fece9fb448149370f4a1b52b32f0977ad528d7911291.json +0 -1
- package/graphify-out/cache/15cbf641dcc0fd641c18da872214918203a1f64baa7ac8430e4702ef32d18b02.json +0 -1
- package/graphify-out/cache/1abc52745bb46f6cc5a528530e2bc1f368c26e348dff85cdde5cad6f275d7177.json +0 -1
- package/graphify-out/cache/1c7815c37c13177e98895e272285f6151a8d0807478fc843ec452634b3e9912d.json +0 -1
- package/graphify-out/cache/1ec38c39f044f329c78642b61d6394fb8e15d0014335f32947d1f5c7b88c02bc.json +0 -1
- package/graphify-out/cache/20c9b57ff76dbb9d57cbd00659b0a42d2b28dd2abacf1ef4143cc67a5b6fe7f4.json +0 -1
- package/graphify-out/cache/285e11876884eb619e779d540cd957b33e70f14c67ecc26c9b9755aa9cedd717.json +0 -1
- package/graphify-out/cache/2c0a9c49ab51f4e0f07543b4e941bf802b7db31fa607c4cee8e595575be68fe7.json +0 -1
- package/graphify-out/cache/3025e6c2756c79ccaadd51d611f25a8b6630a6a11ce1b4e6e261b3e033dc194f.json +0 -1
- package/graphify-out/cache/4801a686ddfa0a52824a4fc3d65443cbb0ab9f0b030af67d02fccb520c584a08.json +0 -1
- package/graphify-out/cache/4f8fd96f38aa7d0293b4fab60c4581c4f3e68f4533c664c9cd78d1c53bea1cba.json +0 -1
- package/graphify-out/cache/5928e562b0f5700184b810e2403f4aa685e2b93c3c584c10460562b514c40fdd.json +0 -1
- package/graphify-out/cache/66132486efb0a4cfaeea766448f1f15bb33635808714052e7e24e5b00fbc984f.json +0 -1
- package/graphify-out/cache/66ab27669e7ec685130063662af9f30018c267f7639b4af4b0504a98282c383a.json +0 -1
- package/graphify-out/cache/6ff6b3dd433b5ffe96e166263a203dd622397e419dc00bb676824988b7defeab.json +0 -1
- package/graphify-out/cache/7a00a49932177a6215e2590b1ddfd6f1d8494792f693068e9d427d16b165d370.json +0 -1
- package/graphify-out/cache/7b681bc5182f40f707f1c0b16b78af38efffa62a1df315d10878f4de888408ef.json +0 -1
- package/graphify-out/cache/81196d44e50ac0b276d826a531ed10c425a528b298e3fe18e8d5a3eec996e9d5.json +0 -1
- package/graphify-out/cache/8934e9b32dea6e66fdc34fa1681b287ff1335c389917e0fc6ee2fc573e23e87b.json +0 -1
- package/graphify-out/cache/975f6c99807f86b79c80ca40c783618e2080a927eaebe6ea3db37b869f048851.json +0 -1
- package/graphify-out/cache/9ab98f08626fd8190462595e38de828293ad184db8df5e1177b05a8fe290faa1.json +0 -1
- package/graphify-out/cache/9c434a6796d7932b6e87a908c155c09cb2b8d097fc55f141f0302b6600f94749.json +0 -1
- package/graphify-out/cache/ac5cf4c489dc417c1f6ea728d0b6ba12ac7087bc6c2e736697ff3024b4d4e534.json +0 -1
- package/graphify-out/cache/ae5083b5c1dca3e5c6af485e7f6eb8a08ff8b382cdecf92ab5e0902053442afe.json +0 -1
- package/graphify-out/cache/b274057fc2e0118cf2746d1d8060841122bb2a2b0305566fc3f32d3a51e08bcc.json +0 -1
- package/graphify-out/cache/b39beef31da682387f030c0d149f6cd5b3e66effbf936cc8430db15360759dda.json +0 -1
- package/graphify-out/cache/bf3c6a36bb72820bc11cbf4a5c49067d1f62013d4686c019a4dbd9951b1e980e.json +0 -1
- package/graphify-out/cache/c034e156028d1a58b89bce659726e9a4065ddc4d2b560d6bce7a206fdff8dad3.json +0 -1
- package/graphify-out/cache/c619b5bbe8d1f427fbd7816d1e9fcfaf90d7201b020ae6b578166aeb9cb20683.json +0 -1
- package/graphify-out/cache/c8db77a9da0b0f601acfa50a620f31155cdda0d0cc0f2285adcea19e77194ee6.json +0 -1
- package/graphify-out/cache/ca664791ec7741a2077d9e7c10384142d30e7a3b77b388df719c315da608d57d.json +0 -1
- package/graphify-out/cache/cba43a116186bd55c8a63368dea4eee4a8123b2bec0a42df6efb3254f89f9a7a.json +0 -1
- package/graphify-out/cache/cd51cbb3dad1cf34417b9761fe2eb184a9f57d23dc86e45630e63bfa2ecafddc.json +0 -1
- package/graphify-out/cache/d06738cde193b34a136b94104220c17e0212b814b3e4d7ff399105635cae1a03.json +0 -1
- package/graphify-out/cache/d093c19f0169c0398eeb1360895b1c16ecc50abc59f4be8eec3f6fd27c89a6e5.json +0 -1
- package/graphify-out/cache/da8f75c438531d232fe114d5cbf2374576ce842a5fb87c7e5a88b78fdb334e5e.json +0 -1
- package/graphify-out/cache/e35798fa04ddede548a6953bdea506bd7d0788dfed4e8a8ea6ae77b1b60ef5e0.json +0 -1
- package/graphify-out/cache/e5a38c254719000487098782125e15e2e982c07d66b99d359ed1781f30f9fc8c.json +0 -1
- package/graphify-out/cache/e6e4c4a5a7200ee0154585b5d6538f699b0a746dbded3164f8391f06ce7cb212.json +0 -1
- package/graphify-out/cache/ea8d0838df6309b673b031f616b253af957898ee7289d25a541fa6183b732e4e.json +0 -1
- package/graphify-out/cache/ebaee92b0e881efd7a08f3143e2c1803310396b4651d4f77532003c699cc6836.json +0 -1
- package/graphify-out/cache/edf8543318a9e60d56d04704078da6c37202ddd6fdfc83144fe2b94fe19b80ef.json +0 -1
- package/graphify-out/cache/efca19d3668035f11126fc9eccbeab290abfa94babf3f9a8706de81d17aba263.json +0 -1
- package/graphify-out/cache/f1480bb642025ebd6d99986cdd8a7d5726897ec038300e4b095c9c938435dfad.json +0 -1
- package/graphify-out/cache/f459f21277f03865f732affb175b1b092954dae5967f27b3cd1864466e3e24f4.json +0 -1
- package/graphify-out/cache/f899e37e864010b30f4c196e86082d7bd022a0df032005e0407883ebcec36514.json +0 -1
- package/graphify-out/cache/fb3cbe07fbcd97c536cff9c6bc343c35f22d49613f05c53ad30ef67a75c5d93e.json +0 -1
- package/graphify-out/cache/fd3dc682b1ca2f5ae03b50d6b0e045ae50f5701c0a21c5a388d77ef482939d3a.json +0 -1
- package/graphify-out/graph.html +0 -257
- package/graphify-out/graph.json +0 -4396
- package/scripts/e2e-external.mjs +0 -65
- package/scripts/live-agents.mjs +0 -6
- package/scripts/live-stream.mjs +0 -51
- package/src/commands/agents.ts +0 -91
- package/src/commands/auth.ts +0 -39
- package/src/commands/chat.ts +0 -198
- package/src/commands/keys.ts +0 -83
- package/src/commands/local.ts +0 -302
- package/src/commands/mcp.ts +0 -74
- package/src/commands/prompts.ts +0 -58
- package/src/commands/skills.ts +0 -43
- package/src/core/auth/index.ts +0 -101
- package/src/core/config/index.ts +0 -152
- package/src/core/history.ts +0 -79
- package/src/core/markdown-renderer.ts +0 -420
- package/src/core/permissions/index.ts +0 -99
- package/src/core/provider/external.ts +0 -312
- package/src/core/provider/index.ts +0 -517
- package/src/core/registry/index.ts +0 -250
- package/src/core/schema/types.ts +0 -106
- package/src/core/terminal.ts +0 -124
- package/src/core/workspace/index.ts +0 -216
- package/src/index.ts +0 -401
- package/src/ui/app.tsx +0 -644
- package/src/ui/commands/cases/catalog.ts +0 -76
- package/src/ui/commands/cases/misc.ts +0 -293
- package/src/ui/commands/cases/tasks.ts +0 -115
- package/src/ui/commands/runCommand.ts +0 -178
- package/src/ui/components/Banner.tsx +0 -63
- package/src/ui/components/CommandMenu.tsx +0 -63
- package/src/ui/components/ErrorBoundary.tsx +0 -75
- package/src/ui/components/InputBar.tsx +0 -227
- package/src/ui/components/KeysPanel.tsx +0 -115
- package/src/ui/components/MessageView.tsx +0 -226
- package/src/ui/components/Pickers.tsx +0 -234
- package/src/ui/components/SearchOverlay.tsx +0 -65
- package/src/ui/components/WorkingIndicator.tsx +0 -35
- package/src/ui/controls/ApiKeyEntry.tsx +0 -29
- package/src/ui/controls/MultiSelect.tsx +0 -55
- package/src/ui/hooks/useAgentPicker.ts +0 -64
- package/src/ui/hooks/useAuthFlow.ts +0 -47
- package/src/ui/hooks/useKeysFlow.ts +0 -157
- package/src/ui/hooks/useSessionPicker.ts +0 -84
- package/src/ui/hooks/useTerminalSize.ts +0 -36
- package/src/ui/input/keyRouter.ts +0 -627
- package/src/ui/layouts/ScreenLayout.tsx +0 -202
- package/src/ui/shared/types.ts +0 -160
- package/src/ui/theme.ts +0 -53
- package/src/ui/utils/markdown.ts +0 -255
- package/src/ui/utils/mentions.ts +0 -40
- package/src/ui/utils/terminal-text.ts +0 -130
- package/src/ui/utils/text.ts +0 -174
- package/test/commands.test.mjs +0 -127
- package/test/config.test.mjs +0 -123
- package/test/history.test.mjs +0 -42
- package/test/keyrouter.test.mjs +0 -324
- package/test/layout.test.mjs +0 -271
- package/test/markdown.test.mjs +0 -92
- package/test/mentions.test.mjs +0 -51
- package/test/permissions.test.mjs +0 -130
- package/test/provider.test.mjs +0 -287
- package/test/terminal-text.test.mjs +0 -116
- package/test/text.test.mjs +0 -134
- package/test/workspace.test.mjs +0 -101
- package/tsconfig.json +0 -32
package/test/mentions.test.mjs
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// Test: expandMentions (pure, deterministic)
|
|
2
|
-
import { describe, it } from "node:test";
|
|
3
|
-
import assert from "node:assert/strict";
|
|
4
|
-
import { expandMentions } from "../dist/ui/utils/mentions.js";
|
|
5
|
-
|
|
6
|
-
describe("expandMentions", () => {
|
|
7
|
-
const fakeFs = (files) => ({
|
|
8
|
-
readFileSync: (p) => files[p] ?? (() => { throw new Error("not found"); }),
|
|
9
|
-
existsSync: (p) => p in files,
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("no mentions → unchanged", () => {
|
|
13
|
-
const fs = fakeFs({});
|
|
14
|
-
const r = expandMentions("hello world", fs.readFileSync, fs.existsSync);
|
|
15
|
-
assert.strictEqual(r.effective, "hello world");
|
|
16
|
-
assert.deepStrictEqual(r.unreadable, []);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("single @mention → inlined with header", () => {
|
|
20
|
-
const fs = fakeFs({ "a.txt": "line1\nline2" });
|
|
21
|
-
const r = expandMentions("review @a.txt", fs.readFileSync, fs.existsSync);
|
|
22
|
-
assert.ok(r.effective.includes("--- @a.txt ---"));
|
|
23
|
-
assert.ok(r.effective.includes("line1"));
|
|
24
|
-
assert.deepStrictEqual(r.unreadable, []);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("missing file → unreadable list", () => {
|
|
28
|
-
const fs = fakeFs({});
|
|
29
|
-
const r = expandMentions("check @missing.txt", fs.readFileSync, fs.existsSync);
|
|
30
|
-
assert.deepStrictEqual(r.unreadable, ["missing.txt"]);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("caps at 20k chars", () => {
|
|
34
|
-
const big = "x".repeat(25_000);
|
|
35
|
-
const fs = fakeFs({ "big.txt": big });
|
|
36
|
-
const r = expandMentions("@big.txt", fs.readFileSync, fs.existsSync);
|
|
37
|
-
const block = r.effective.split("\n").slice(1).join("\n"); // after header
|
|
38
|
-
assert.ok(block.length < 21_000, "capped near 20k");
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("strips @mention from prompt, keeps in header", () => {
|
|
42
|
-
const fs = fakeFs({ "f.ts": "code" });
|
|
43
|
-
const r = expandMentions("fix @f.ts please", fs.readFileSync, fs.existsSync);
|
|
44
|
-
// @f.ts is stripped from the prompt text portion (before the blocks)
|
|
45
|
-
assert.ok(!r.effective.split("--- @f.ts")[0].includes("@f.ts"), "stripped from prompt");
|
|
46
|
-
assert.ok(r.effective.includes("--- @f.ts ---"), "kept in header");
|
|
47
|
-
assert.ok(r.effective.includes("fix"));
|
|
48
|
-
assert.ok(r.effective.includes("please"));
|
|
49
|
-
assert.ok(r.effective.includes("code"));
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
// Tests: permission policy + folder trust.
|
|
2
|
-
//
|
|
3
|
-
// The policy is a mode × operation-class matrix; the test asserts every cell,
|
|
4
|
-
// not just the paths that happened to be implemented first. The trust store is
|
|
5
|
-
// exercised in a child process with an isolated HOME (its path is resolved at
|
|
6
|
-
// module load), and fails closed when unreadable.
|
|
7
|
-
import { describe, it } from "node:test";
|
|
8
|
-
import assert from "node:assert/strict";
|
|
9
|
-
import { execFileSync } from "node:child_process";
|
|
10
|
-
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
11
|
-
import { tmpdir } from "node:os";
|
|
12
|
-
import { join } from "node:path";
|
|
13
|
-
import {
|
|
14
|
-
PERMISSION_MODES, decide, decideLocal, isPermissionMode,
|
|
15
|
-
} from "../dist/core/permissions/index.js";
|
|
16
|
-
|
|
17
|
-
const runInScratchHome = (body, cwd) => {
|
|
18
|
-
const home = mkdtempSync(join(tmpdir(), "odysx-trust-"));
|
|
19
|
-
try {
|
|
20
|
-
const script = `
|
|
21
|
-
const ws = await import(${JSON.stringify(new URL("../dist/core/workspace/index.js", import.meta.url).href)});
|
|
22
|
-
${body}
|
|
23
|
-
`;
|
|
24
|
-
return execFileSync(process.execPath, ["--input-type=module", "-e", script], {
|
|
25
|
-
cwd,
|
|
26
|
-
env: { ...process.env, HOME: home, USERPROFILE: home, ODYSX_WORKSPACE: "" },
|
|
27
|
-
encoding: "utf-8",
|
|
28
|
-
}).trim();
|
|
29
|
-
} finally {
|
|
30
|
-
rmSync(home, { recursive: true, force: true });
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
describe("permission policy", () => {
|
|
35
|
-
it("covers the full mode × op-class ladder", () => {
|
|
36
|
-
const expected = {
|
|
37
|
-
plan: ["allow", "refuse", "refuse"],
|
|
38
|
-
guide: ["allow", "guide", "guide"],
|
|
39
|
-
manual: ["allow", "ask", "ask"],
|
|
40
|
-
auto: ["allow", "allow", "ask"],
|
|
41
|
-
};
|
|
42
|
-
for (const { id } of PERMISSION_MODES) {
|
|
43
|
-
for (const [i, op] of ["read", "write", "irreversible"].entries()) {
|
|
44
|
-
assert.equal(decide(id, op), expected[id][i], `${id}/${op}`);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("classifies local subcommands into exactly three classes", () => {
|
|
50
|
-
for (const sub of ["read", "ls", "pwd", "which"]) {
|
|
51
|
-
assert.equal(decideLocal(sub, "plan"), "allow", `${sub} must be readable in plan`);
|
|
52
|
-
}
|
|
53
|
-
assert.equal(decideLocal("write", "auto"), "allow");
|
|
54
|
-
assert.equal(decideLocal("write", "plan"), "refuse");
|
|
55
|
-
for (const sub of ["delete", "move", "exec", "unknown"]) {
|
|
56
|
-
// Even in auto, an irreversible op still needs a human.
|
|
57
|
-
assert.equal(decideLocal(sub, "auto"), "ask", `${sub} must ask in auto`);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("rejects unknown modes instead of silently granting anything", () => {
|
|
62
|
-
assert.equal(isPermissionMode("manual"), true);
|
|
63
|
-
assert.equal(isPermissionMode("YOLO"), false);
|
|
64
|
-
assert.equal(isPermissionMode(null), false);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("falls back to manual for an unrecognised persisted mode", () => {
|
|
68
|
-
const out = runInScratchHome(`
|
|
69
|
-
const perms = await import(${JSON.stringify(new URL("../dist/core/permissions/index.js", import.meta.url).href)});
|
|
70
|
-
const cfg = await import(${JSON.stringify(new URL("../dist/core/config/index.js", import.meta.url).href)});
|
|
71
|
-
cfg.updateConfig({ permissionMode: "YOLO" });
|
|
72
|
-
process.stdout.write(perms.getPermissionMode());
|
|
73
|
-
`);
|
|
74
|
-
assert.equal(out, "manual");
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe("folder trust", () => {
|
|
79
|
-
it("starts untrusted and persists an explicit trust decision", () => {
|
|
80
|
-
const out = runInScratchHome(`
|
|
81
|
-
process.stdout.write(String(ws.isFolderTrusted()) + " ");
|
|
82
|
-
ws.trustFolder();
|
|
83
|
-
process.stdout.write(String(ws.isFolderTrusted()));
|
|
84
|
-
`);
|
|
85
|
-
assert.equal(out, "false true");
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("treats a child folder as trusted when its ancestor is trusted", () => {
|
|
89
|
-
const parent = mkdtempSync(join(tmpdir(), "odysx-tree-"));
|
|
90
|
-
const child = join(parent, "packages", "app");
|
|
91
|
-
mkdirSync(child, { recursive: true });
|
|
92
|
-
try {
|
|
93
|
-
const out = runInScratchHome(`
|
|
94
|
-
ws.trustFolder(${JSON.stringify(parent)});
|
|
95
|
-
process.stdout.write(String(ws.isFolderTrusted(${JSON.stringify(child)})));
|
|
96
|
-
`, child);
|
|
97
|
-
assert.equal(out, "true");
|
|
98
|
-
} finally {
|
|
99
|
-
rmSync(parent, { recursive: true, force: true });
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("forgets a folder so the next launch asks again", () => {
|
|
104
|
-
const out = runInScratchHome(`
|
|
105
|
-
ws.trustFolder();
|
|
106
|
-
const removed = ws.untrustFolder(ws.getWorkspaceRoot());
|
|
107
|
-
process.stdout.write(String(removed) + " " + String(ws.isFolderTrusted()));
|
|
108
|
-
`);
|
|
109
|
-
assert.equal(out, "true false");
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("fails closed when the trust file is corrupt", () => {
|
|
113
|
-
const home = mkdtempSync(join(tmpdir(), "odysx-trust-bad-"));
|
|
114
|
-
try {
|
|
115
|
-
mkdirSync(join(home, ".odysx"), { recursive: true });
|
|
116
|
-
writeFileSync(join(home, ".odysx", "trusted-folders.json"), "{not json");
|
|
117
|
-
const script = `
|
|
118
|
-
const ws = await import(${JSON.stringify(new URL("../dist/core/workspace/index.js", import.meta.url).href)});
|
|
119
|
-
process.stdout.write(String(ws.isFolderTrusted()));
|
|
120
|
-
`;
|
|
121
|
-
const out = execFileSync(process.execPath, ["--input-type=module", "-e", script], {
|
|
122
|
-
env: { ...process.env, HOME: home, USERPROFILE: home },
|
|
123
|
-
encoding: "utf-8",
|
|
124
|
-
}).trim();
|
|
125
|
-
assert.equal(out, "false");
|
|
126
|
-
} finally {
|
|
127
|
-
rmSync(home, { recursive: true, force: true });
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
});
|
package/test/provider.test.mjs
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
// Tests: API client plumbing that does not need a live server.
|
|
2
|
-
import { describe, it } from "node:test";
|
|
3
|
-
import assert from "node:assert/strict";
|
|
4
|
-
import { getEventListeners } from "node:events";
|
|
5
|
-
import { readSSE, idleTimeout, apiCall, streamChat } from "../dist/core/provider/index.js";
|
|
6
|
-
|
|
7
|
-
/** Build a Response whose body emits the given chunks with a delay between. */
|
|
8
|
-
const sseResponse = (chunks, delayMs = 0) => {
|
|
9
|
-
const encoder = new TextEncoder();
|
|
10
|
-
const stream = new ReadableStream({
|
|
11
|
-
async start(controller) {
|
|
12
|
-
for (const chunk of chunks) {
|
|
13
|
-
if (delayMs) await new Promise((r) => setTimeout(r, delayMs));
|
|
14
|
-
controller.enqueue(encoder.encode(chunk));
|
|
15
|
-
}
|
|
16
|
-
controller.close();
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
return new Response(stream, { status: 200 });
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
describe("readSSE framing tolerance", () => {
|
|
23
|
-
it("splits on data: with and without a space", async () => {
|
|
24
|
-
const seen = [];
|
|
25
|
-
await readSSE(sseResponse(["data: a\n", "data:b\n"]), (d) => seen.push(d));
|
|
26
|
-
assert.deepEqual(seen, ["a", "b"]);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("handles CRLF line endings", async () => {
|
|
30
|
-
const seen = [];
|
|
31
|
-
await readSSE(sseResponse(["data: one\r\n", "data: two\r\n"]), (d) => seen.push(d));
|
|
32
|
-
assert.deepEqual(seen, ["one", "two"]);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("flushes a final event with no trailing newline", async () => {
|
|
36
|
-
const seen = [];
|
|
37
|
-
await readSSE(sseResponse(["data: a\n", "data: last"]), (d) => seen.push(d));
|
|
38
|
-
assert.deepEqual(seen, ["a", "last"]);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("reassembles an event split across chunks", async () => {
|
|
42
|
-
const seen = [];
|
|
43
|
-
await readSSE(sseResponse(["da", "ta: hel", "lo\n"]), (d) => seen.push(d));
|
|
44
|
-
assert.deepEqual(seen, ["hello"]);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("ignores comments and event: lines", async () => {
|
|
48
|
-
const seen = [];
|
|
49
|
-
await readSSE(sseResponse([": ping\n", "event: token\n", "data: x\n"]), (d) => seen.push(d));
|
|
50
|
-
assert.deepEqual(seen, ["x"]);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("reports activity for each chunk read", async () => {
|
|
54
|
-
let activity = 0;
|
|
55
|
-
await readSSE(sseResponse(["data: a\n", "data: b\n"]), () => {}, undefined, () => activity++);
|
|
56
|
-
assert.equal(activity, 2);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("throws when the response has no body", async () => {
|
|
60
|
-
await assert.rejects(() => readSSE(new Response(null), () => {}), /No response body/);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("cancels the HTTP body when onData throws", async () => {
|
|
64
|
-
// Otherwise an `[ERROR]` frame (or a render failure) leaves the response
|
|
65
|
-
// streaming in the background after the turn has already failed.
|
|
66
|
-
let cancelled = false;
|
|
67
|
-
const stream = new ReadableStream({
|
|
68
|
-
start(controller) {
|
|
69
|
-
controller.enqueue(new TextEncoder().encode("data: a\n"));
|
|
70
|
-
},
|
|
71
|
-
cancel() {
|
|
72
|
-
cancelled = true;
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
await assert.rejects(
|
|
76
|
-
() => readSSE(new Response(stream), () => { throw new Error("frame error"); }),
|
|
77
|
-
/frame error/,
|
|
78
|
-
);
|
|
79
|
-
assert.equal(cancelled, true, "response body should be cancelled");
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
describe("idleTimeout", () => {
|
|
84
|
-
it("fires after silence", async () => {
|
|
85
|
-
const idle = idleTimeout(30);
|
|
86
|
-
assert.equal(idle.signal.aborted, false);
|
|
87
|
-
await new Promise((r) => setTimeout(r, 60));
|
|
88
|
-
assert.equal(idle.signal.aborted, true);
|
|
89
|
-
assert.equal(idle.timedOut(), true);
|
|
90
|
-
idle.clear();
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("keeps resetting while touch() is called", async () => {
|
|
94
|
-
const idle = idleTimeout(40);
|
|
95
|
-
// Three touches 25ms apart: without the reset it would abort at 40ms.
|
|
96
|
-
for (let i = 0; i < 3; i++) {
|
|
97
|
-
await new Promise((r) => setTimeout(r, 25));
|
|
98
|
-
idle.touch();
|
|
99
|
-
}
|
|
100
|
-
assert.equal(idle.signal.aborted, false, "an actively streaming turn must not be cut");
|
|
101
|
-
idle.clear();
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("aborts immediately when the caller's signal is already aborted", () => {
|
|
105
|
-
const external = new AbortController();
|
|
106
|
-
external.abort();
|
|
107
|
-
const idle = idleTimeout(10_000, external.signal);
|
|
108
|
-
assert.equal(idle.signal.aborted, true);
|
|
109
|
-
idle.clear();
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("propagates a later external abort", () => {
|
|
113
|
-
const external = new AbortController();
|
|
114
|
-
const idle = idleTimeout(10_000, external.signal);
|
|
115
|
-
external.abort();
|
|
116
|
-
assert.equal(idle.signal.aborted, true);
|
|
117
|
-
idle.clear();
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("does not report a user abort as a timeout", () => {
|
|
121
|
-
const external = new AbortController();
|
|
122
|
-
const idle = idleTimeout(10_000, external.signal);
|
|
123
|
-
external.abort();
|
|
124
|
-
assert.equal(idle.timedOut(), false);
|
|
125
|
-
idle.clear();
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it("removes its listener from the caller's signal on clear", () => {
|
|
129
|
-
// A shared signal (batch runner, reused controller) otherwise collects a
|
|
130
|
-
// listener per request until Node's MaxListenersExceededWarning prints
|
|
131
|
-
// into the middle of the Ink frame.
|
|
132
|
-
const external = new AbortController();
|
|
133
|
-
const idle = idleTimeout(10_000, external.signal);
|
|
134
|
-
assert.equal(getEventListeners(external.signal, "abort").length, 1);
|
|
135
|
-
idle.clear();
|
|
136
|
-
assert.equal(getEventListeners(external.signal, "abort").length, 0);
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
describe("streamChat completion accounting", () => {
|
|
141
|
-
/** Run streamChat against a stubbed fetch. `stub` is the fetch itself. */
|
|
142
|
-
const runStream = async (stub) => {
|
|
143
|
-
const realFetch = globalThis.fetch;
|
|
144
|
-
globalThis.fetch = stub;
|
|
145
|
-
const calls = { done: 0, usage: [], tokens: "" };
|
|
146
|
-
try {
|
|
147
|
-
await streamChat(
|
|
148
|
-
"/api/v1/llm/chat/stream",
|
|
149
|
-
{ agent_id: "a", message: "hello there", session_id: "s" },
|
|
150
|
-
(t) => { calls.tokens += t; },
|
|
151
|
-
() => { calls.done++; },
|
|
152
|
-
undefined,
|
|
153
|
-
(u) => calls.usage.push(u),
|
|
154
|
-
);
|
|
155
|
-
} finally {
|
|
156
|
-
globalThis.fetch = realFetch;
|
|
157
|
-
}
|
|
158
|
-
return calls;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
/** A fetch that answers with one SSE body built from `chunks`. */
|
|
162
|
-
const sseStub = (chunks) => async () => {
|
|
163
|
-
const encoder = new TextEncoder();
|
|
164
|
-
const stream = new ReadableStream({
|
|
165
|
-
start(controller) {
|
|
166
|
-
for (const c of chunks) controller.enqueue(encoder.encode(c));
|
|
167
|
-
controller.close();
|
|
168
|
-
},
|
|
169
|
-
});
|
|
170
|
-
return new Response(stream, {
|
|
171
|
-
status: 200,
|
|
172
|
-
headers: { "content-type": "text/event-stream" },
|
|
173
|
-
});
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
it("fires onDone and usage exactly once when a [DONE] frame arrives", async () => {
|
|
177
|
-
// Both the `[DONE]` branch and the post-read path used to fire, so every
|
|
178
|
-
// session reported double the real token count.
|
|
179
|
-
const calls = await runStream(sseStub(["data: hi\n", "data: [DONE]\n"]));
|
|
180
|
-
assert.equal(calls.done, 1);
|
|
181
|
-
assert.equal(calls.usage.length, 1);
|
|
182
|
-
assert.equal(calls.tokens, "hi");
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it("still settles the turn when the server omits [DONE]", async () => {
|
|
186
|
-
const calls = await runStream(sseStub(["data: hi\n", "data: there\n"]));
|
|
187
|
-
assert.equal(calls.done, 1);
|
|
188
|
-
assert.equal(calls.usage.length, 1);
|
|
189
|
-
assert.equal(calls.tokens, "hithere");
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it("cancels the response body when an [ERROR] frame throws", async () => {
|
|
193
|
-
let cancelled = false;
|
|
194
|
-
const stub = async () => {
|
|
195
|
-
const encoder = new TextEncoder();
|
|
196
|
-
const stream = new ReadableStream({
|
|
197
|
-
start(controller) {
|
|
198
|
-
controller.enqueue(encoder.encode("data: [ERROR] boom\n"));
|
|
199
|
-
},
|
|
200
|
-
cancel() { cancelled = true; },
|
|
201
|
-
});
|
|
202
|
-
return new Response(stream, {
|
|
203
|
-
status: 200,
|
|
204
|
-
headers: { "content-type": "text/event-stream" },
|
|
205
|
-
});
|
|
206
|
-
};
|
|
207
|
-
await assert.rejects(() => runStream(stub), /boom/);
|
|
208
|
-
assert.equal(cancelled, true, "the HTTP body is not left open");
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
describe("apiCall response validation", () => {
|
|
213
|
-
it("refuses a non-JSON 2xx body instead of treating it as data", async () => {
|
|
214
|
-
// A proxy login page returns 200 text/html; callers then read
|
|
215
|
-
// `data.api_key` off a string and print undefined as a created key.
|
|
216
|
-
const realFetch = globalThis.fetch;
|
|
217
|
-
globalThis.fetch = async () =>
|
|
218
|
-
new Response("<html>sign in</html>", {
|
|
219
|
-
status: 200,
|
|
220
|
-
headers: { "content-type": "text/html" },
|
|
221
|
-
});
|
|
222
|
-
try {
|
|
223
|
-
const res = await apiCall("/api/v1/api-keys");
|
|
224
|
-
assert.equal(res.ok, false);
|
|
225
|
-
assert.match(res.error, /non-JSON/);
|
|
226
|
-
} finally {
|
|
227
|
-
globalThis.fetch = realFetch;
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it("still accepts a JSON body", async () => {
|
|
232
|
-
const realFetch = globalThis.fetch;
|
|
233
|
-
globalThis.fetch = async () =>
|
|
234
|
-
new Response(JSON.stringify({ ok: true }), {
|
|
235
|
-
status: 200,
|
|
236
|
-
headers: { "content-type": "application/json" },
|
|
237
|
-
});
|
|
238
|
-
try {
|
|
239
|
-
const res = await apiCall("/health");
|
|
240
|
-
assert.equal(res.ok, true);
|
|
241
|
-
assert.deepEqual(res.data, { ok: true });
|
|
242
|
-
} finally {
|
|
243
|
-
globalThis.fetch = realFetch;
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
describe("apiCall error mapping", () => {
|
|
249
|
-
/** Run apiCall with a fetch that fails the way undici reports a dead server. */
|
|
250
|
-
const withFailingFetch = async (fn) => {
|
|
251
|
-
const realFetch = globalThis.fetch;
|
|
252
|
-
globalThis.fetch = fn;
|
|
253
|
-
try {
|
|
254
|
-
return await apiCall("/health", { timeoutMs: 500 });
|
|
255
|
-
} finally {
|
|
256
|
-
globalThis.fetch = realFetch;
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
it("maps a refused connection to a readable message", async () => {
|
|
261
|
-
// Stubbed rather than aimed at a closed port: the real config points at
|
|
262
|
-
// localhost, so a developer running the backend made this test pass or
|
|
263
|
-
// fail depending on their machine.
|
|
264
|
-
const err = new Error("fetch failed");
|
|
265
|
-
err.cause = { code: "ECONNREFUSED" };
|
|
266
|
-
const res = await withFailingFetch(async () => { throw err; });
|
|
267
|
-
assert.equal(res.ok, false);
|
|
268
|
-
assert.equal(res.status, 0);
|
|
269
|
-
assert.match(res.error, /Is the server running\?/);
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
it("maps a cause-only network code (the Windows shape)", async () => {
|
|
273
|
-
// The message is often a bare "fetch failed"; only err.cause.code is
|
|
274
|
-
// specific, so the mapping must not depend on the message text.
|
|
275
|
-
const err = new Error("fetch failed");
|
|
276
|
-
err.cause = { code: "EAI_AGAIN" };
|
|
277
|
-
const res = await withFailingFetch(async () => { throw err; });
|
|
278
|
-
assert.equal(res.ok, false);
|
|
279
|
-
assert.match(res.error, /EAI_AGAIN/);
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
it("reports a generic failure verbatim", async () => {
|
|
283
|
-
const res = await withFailingFetch(async () => { throw new Error("kaboom"); });
|
|
284
|
-
assert.equal(res.ok, false);
|
|
285
|
-
assert.equal(res.error, "kaboom");
|
|
286
|
-
});
|
|
287
|
-
});
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
// Tests: sanitization of untrusted text and terminal display width.
|
|
2
|
-
import { describe, it } from "node:test";
|
|
3
|
-
import assert from "node:assert/strict";
|
|
4
|
-
import {
|
|
5
|
-
sanitize, hasControlSequences, displayWidth, truncateToWidth, padToWidth,
|
|
6
|
-
} from "../dist/ui/utils/terminal-text.js";
|
|
7
|
-
|
|
8
|
-
describe("sanitize", () => {
|
|
9
|
-
it("strips SGR colour codes", () => {
|
|
10
|
-
assert.equal(sanitize("a\x1b[31mred\x1b[0mb"), "aredb");
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it("strips a screen-clear sequence", () => {
|
|
14
|
-
assert.equal(sanitize("before\x1b[2Jafter"), "beforeafter");
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("strips an alternate-buffer switch (would escape the TUI)", () => {
|
|
18
|
-
assert.equal(sanitize("x\x1b[?1049hy"), "xy");
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("strips OSC sequences terminated by BEL", () => {
|
|
22
|
-
// Window-title rewrite.
|
|
23
|
-
assert.equal(sanitize("a\x1b]0;pwned\x07b"), "ab");
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("strips OSC sequences terminated by ST", () => {
|
|
27
|
-
assert.equal(sanitize("a\x1b]8;;http://x\x1b\\link\x1b]8;;\x1b\\b"), "alinkb");
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("strips DCS payloads", () => {
|
|
31
|
-
assert.equal(sanitize("a\x1bPq#0;2;0;0;0\x1b\\b"), "ab");
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("keeps newlines and tabs", () => {
|
|
35
|
-
assert.equal(sanitize("a\n\tb"), "a\n\tb");
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("drops a bare carriage return (line overwrite)", () => {
|
|
39
|
-
assert.equal(sanitize("safe\rEVIL"), "safeEVIL");
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("keeps normal unicode text untouched", () => {
|
|
43
|
-
assert.equal(sanitize("héllo — 世界 🚀"), "héllo — 世界 🚀");
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("reports whether anything was stripped", () => {
|
|
47
|
-
assert.equal(hasControlSequences("plain"), false);
|
|
48
|
-
assert.equal(hasControlSequences("x\x1b[2Jy"), true);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe("displayWidth", () => {
|
|
53
|
-
it("counts ASCII by code unit", () => {
|
|
54
|
-
assert.equal(displayWidth("hello"), 5);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("counts CJK as two columns", () => {
|
|
58
|
-
assert.equal(displayWidth("世界"), 4);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("counts an emoji as two columns", () => {
|
|
62
|
-
assert.equal(displayWidth("🚀"), 2);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("does not count a combining accent", () => {
|
|
66
|
-
assert.equal(displayWidth("é"), 1);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("ignores emoji skin-tone modifiers", () => {
|
|
70
|
-
assert.equal(displayWidth("👍🏽"), 2);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("is not fooled by surrogate pairs", () => {
|
|
74
|
-
assert.equal(displayWidth("🚀".repeat(3)), 6);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe("truncateToWidth", () => {
|
|
79
|
-
it("leaves short text alone", () => {
|
|
80
|
-
assert.equal(truncateToWidth("abc", 10), "abc");
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("truncates by display columns, not code units", () => {
|
|
84
|
-
// Three wide glyphs = 6 columns; max 5 means room for two glyphs + ellipsis.
|
|
85
|
-
assert.equal(truncateToWidth("世界世", 5), "世界…");
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("never exceeds the budget", () => {
|
|
89
|
-
for (const max of [1, 2, 3, 4, 5, 10]) {
|
|
90
|
-
assert.ok(displayWidth(truncateToWidth("世界世界世界", max)) <= max, `max=${max}`);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("handles a zero budget", () => {
|
|
95
|
-
assert.equal(truncateToWidth("abc", 0), "");
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe("padToWidth", () => {
|
|
100
|
-
it("pads left-aligned text to a column count", () => {
|
|
101
|
-
assert.equal(padToWidth("世界", 6), "世界 ");
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("pads right-aligned text", () => {
|
|
105
|
-
assert.equal(padToWidth("ab", 4, "right"), " ab");
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("centres with the extra space on the right", () => {
|
|
109
|
-
assert.equal(padToWidth("ab", 5, "center"), " ab ");
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("does not pad when already at or over budget", () => {
|
|
113
|
-
assert.equal(padToWidth("世界", 4), "世界");
|
|
114
|
-
assert.equal(padToWidth("世界", 2), "世界");
|
|
115
|
-
});
|
|
116
|
-
});
|