Files
Netcatty/components/terminal/autocompleteDescriptionI18n.batch3.test.ts
T
rnarany 51d9f715da feat(autocomplete): localize common commands and polish terminal hints (#4172)
* feat(autocomplete): add zh-CN descriptions for zip, unzip, make, nano

Cover 32 missing Fig descriptions, generate zh-TW, add batch coverage tests, and record source and semantic checks.

* fix(autocomplete): correct zip, unzip, and make semantics

Limit zip -9 to the compression level, warn that unzip -0 is a suspect upstream option, and describe make -N as the Apple/NeXT compatibility extension.

* fix(autocomplete): simplify unzip -0 warning and correct NeXT note

Keep the -O gbk version caveat in the research record and describe Next/NeXT as a capitalization difference.

* feat(autocomplete): complete remaining common command descriptions

Add 177 zh-CN descriptions for python, python3, node, vim, sort, awk, and sed; generate zh-TW, cover the batch with real Fig specs, and record one deferred shared node key.

* fix(autocomplete): correct sed n and sort parallel semantics

Add the automatic-print condition to sed n, remove the universal CPU default from sort --parallel, and remove duplicated adopted-entry sections from the source record.

* fix: repair macOS terminal setup and align autocomplete details

- Read OSC 7 setup payloads through base64 stdin so BSD/macOS works
- Keep the FIDO askpass socket path within the Unix sun_path limit
- Align autocomplete descriptions in a shared fixed column
- Fix an invalid optional-parameter declaration and lint warnings
- Harden macOS-sensitive OSC 7, SFTP, temp-dir and privacy tests

* feat(autocomplete): add zh-CN descriptions for file and text utilities

Cover ln, stat, wc, cut, uniq, tee and xargs with 70 localized
descriptions. Add coverage and localization tests, preload the new common
specs, and record the upstream wc/xargs wording corrections.

* fix(autocomplete): keep popup scrollbars draggable

Panel mousedown handlers no longer preventDefault across the whole box, so the right-side detail scrollbar and the suggestion list scrollbar can be dragged while padding clicks still preserve terminal focus.

* fix(autocomplete): keep detail panel open while selecting text

Delay row hover clearing so the pointer can move into the right-side detail panel, and allow native text selection there without stealing terminal focus on ordinary padding clicks.
2026-11-07 20:00:43 +08:00

208 lines
6.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import type { FigSpec } from "./autocomplete/figSpecLoader.ts";
const HERE = path.dirname(fileURLToPath(import.meta.url));
const ROOT = path.resolve(HERE, "../..");
const SPEC_DIR = path.join(ROOT, "node_modules/@withfig/autocomplete/build");
const DICT_DIR = path.join(HERE, "autocomplete");
const COMMANDS = ["ln", "stat", "wc", "cut", "uniq", "tee", "xargs"] as const;
const specs = Object.fromEntries(
await Promise.all(
COMMANDS.map(async (name) => {
const mod = await import(pathToFileURL(path.join(SPEC_DIR, `${name}.js`)).href);
return [name, mod.default?.default ?? mod.default] as const;
}),
),
) as Record<(typeof COMMANDS)[number], FigSpec>;
const simplified = JSON.parse(
fs.readFileSync(path.join(DICT_DIR, "descriptions.zh-CN.json"), "utf8"),
) as Record<string, string>;
const traditional = JSON.parse(
fs.readFileSync(path.join(DICT_DIR, "descriptions.zh-TW.json"), "utf8"),
) as Record<string, string>;
Object.defineProperty(globalThis, "localStorage", {
value: {
getItem: () => null,
setItem: () => {},
removeItem: () => {},
clear: () => {},
},
configurable: true,
});
Object.defineProperty(globalThis, "window", {
value: {
netcatty: {
listFigSpecs: async () => [...COMMANDS],
loadFigSpec: async (commandName: string) =>
(specs as Record<string, FigSpec>)[commandName] ?? null,
},
},
configurable: true,
});
const { getCompletions } = await import("./autocomplete/completionEngine.ts");
function collectDescriptions(
node: unknown,
out = new Set<string>(),
seen = new WeakSet<object>(),
): Set<string> {
if (!node || typeof node !== "object" || seen.has(node)) return out;
seen.add(node);
const record = node as { description?: unknown };
if (typeof record.description === "string" && record.description.trim()) {
out.add(record.description);
}
for (const value of Object.values(node)) {
if (Array.isArray(value)) {
for (const item of value) collectDescriptions(item, out, seen);
} else if (value && typeof value === "object") {
collectDescriptions(value, out, seen);
}
}
return out;
}
const batchDescriptions = [...new Set(COMMANDS.flatMap((name) => [...collectDescriptions(specs[name])]))];
function suggestionNamed(
suggestions: Awaited<ReturnType<typeof getCompletions>>,
displayText: string,
) {
return suggestions.find((suggestion) => suggestion.displayText === displayText);
}
test("batch 3 specs have complete zh-CN and zh-TW description coverage", () => {
const missing = batchDescriptions.filter(
(description) => !(typeof simplified[description] === "string" && simplified[description].length > 0),
);
const missingTraditional = batchDescriptions.filter(
(description) => !(typeof traditional[description] === "string" && traditional[description].length > 0),
);
assert.deepEqual(missing, []);
assert.deepEqual(missingTraditional, []);
assert.ok(batchDescriptions.length >= 70);
});
test("batch 3 spot checks correct verified semantics and upstream wording", () => {
assert.equal(
simplified["World, line, character, and byte count"],
"统计单词数、行数、字符数和字节数",
);
assert.equal(
traditional["World, line, character, and byte count"],
"統計單詞數、行數、字元數和位元組數",
);
assert.equal(
simplified["Terminal if the arguments will not fit in the maximum line length"],
"若参数超出最大行长度则终止",
);
assert.equal(
traditional["Terminal if the arguments will not fit in the maximum line length"],
"若引數超出最大行長度則終止",
);
assert.equal(
simplified["Report or omit repeated line"],
"报告或省略重复行",
);
assert.equal(
traditional["Report or omit repeated line"],
"報告或省略重複行",
);
assert.equal(
simplified["Use delim as the field delimiter character instead of the tab character"],
"使用 delim 作为字段分隔符,而不是制表符",
);
assert.equal(
traditional["Use delim as the field delimiter character instead of the tab character"],
"使用 delim 作為欄位分隔符,而不是製表符",
);
});
test("ln, stat, wc, cut, uniq, tee and xargs descriptions localize without changing insertion text", async () => {
const cases = [
{
input: "ln -",
option: "-s",
key: "Create a symbolic link",
zhCn: "创建符号链接",
},
{
input: "stat -",
option: "-f",
key: "Display information using the specified format; similar to printf(3) formats in that they start with %, are then followed by a sequence of formatting characters, and end in a character that selects the field of the struct stat which is to be formatted",
zhCn: "按指定格式显示信息;类似 printf(3):以 % 开头,后接格式化字符,并以选择 struct stat 待格式化字段的字符结尾",
},
{
input: "wc -",
option: "-l",
key: "Output the number of lines to the standard input",
zhCn: "输出行数",
},
{
input: "cut -",
option: "-d",
key: "Use delim as the field delimiter character instead of the tab character",
zhCn: "使用 delim 作为字段分隔符,而不是制表符",
},
{
input: "uniq -",
option: "-c",
key: "Prefix lines by the number of occurrences",
zhCn: "在每行前加上出现次数",
},
{
input: "tee -",
option: "-a",
key: "Append the output to the files rather than overwriting them",
zhCn: "将输出追加到文件而不是覆盖",
},
{
input: "xargs -",
option: "-0",
key: "Use NUL (0x00) as a separator, instead of whitespace",
zhCn: "使用 NUL(0x00)而非空白作为分隔符",
},
];
for (const { input, option, key, zhCn } of cases) {
const command = input.split(" ")[0];
const localized = await getCompletions(input, {
locale: "zh-CN",
skipPathCompletion: true,
maxResults: 100,
});
const suggestion = suggestionNamed(localized, option);
assert.equal(suggestion?.text, `${command} ${option}`);
assert.equal(suggestion?.description, zhCn);
for (const locale of ["en", "ru", undefined]) {
const fallback = await getCompletions(input, {
locale,
skipPathCompletion: true,
maxResults: 100,
});
const fallbackSuggestion = suggestionNamed(fallback, option);
assert.equal(fallbackSuggestion?.text, `${command} ${option}`);
assert.equal(fallbackSuggestion?.description, key);
}
}
const traditionalResults = await getCompletions("uniq -", {
locale: "zh-TW",
skipPathCompletion: true,
maxResults: 100,
});
assert.equal(suggestionNamed(traditionalResults, "-c")?.description, "在每行前加上出現次數");
});