Owner decision D23: Lutra runs fetch, pull (merge or rebase per the new git.pull.mode setting), push (upstream set on the first push) and clone through the user's git. Any HTTPS or SSH server works; sign-in stays with git's credential helper (its own window is allowed for network calls only) and the ssh agent. Terminal prompts stay off, ext:: is refused, and URL userinfo is redacted in every message, progress line and remote listing. - vcs: Call::network with a 30 min timeout, a stderr progress sink and a Cancel flag that kills git's process group; remote.rs with clone_repo, fetch, pull, push (--porcelain rejections), remotes and add/set-url/ remove; explained refusals (rejected push, sign-in, host key, not found, unreachable, no upstream, local changes, conflicts). - engine: git.fetch/pull/push/clone/cancel/remotes/remoteAdd/remoteSetUrl/ remoteRemove, one network call at a time, gitProgress events, gitChanged after changes. - ui: status-bar progress with Cancel and ahead/behind, vcs.fetch/pull/ push/clone/manageRemotes (Git menu, no default shortcuts), Clone Repository and Manage Remotes dialogs; desktop pick_dir IPC. - Tests against local bare repositories only (vcs 8, engine 3, Vitest 11) plus unit and property tests; docs updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
206 lines
7.1 KiB
TypeScript
206 lines
7.1 KiB
TypeScript
/**
|
|
* Tests of the message catalog: the `t` helper (lookup, interpolation,
|
|
* missing keys) and a scan of the frontend source that every literal key
|
|
* passed to `t` exists in `en.json`.
|
|
*/
|
|
import { readdirSync, readFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import en from "../../src/i18n/en.json";
|
|
import { hasMessage, t } from "../../src/i18n";
|
|
|
|
/** Root of the frontend source tree. */
|
|
const SRC = join(import.meta.dirname, "..", "..", "src");
|
|
|
|
/**
|
|
* Lists the `.ts` and `.vue` files below a directory.
|
|
*
|
|
* @param dir - the directory.
|
|
*/
|
|
function sourceFiles(dir: string): string[] {
|
|
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
const path = join(dir, entry.name);
|
|
if (entry.isDirectory()) {
|
|
return sourceFiles(path);
|
|
}
|
|
return /\.(ts|vue)$/.test(entry.name) ? [path] : [];
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Every call of `t` with a literal first argument, and every literal
|
|
* `labelKey` (UI commands, whose labels the palette looks up), by file.
|
|
*/
|
|
const usedKeys = sourceFiles(SRC).flatMap((file) =>
|
|
[...readFileSync(file, "utf8").matchAll(/(?:\bt\(|\blabelKey:)\s*(["'`])([^"'`]*)\1/g)].map((m) => ({
|
|
file,
|
|
key: m[2] ?? "",
|
|
})),
|
|
);
|
|
|
|
/**
|
|
* Keys the source never passes to `t` literally because they arrive at
|
|
* runtime: theme labels from `theme.list`, the settings' `labelKey`,
|
|
* `descriptionKey`, section names and enum value names from
|
|
* `settings.list`, the `messageKey` of
|
|
* `notification` events (engine and desktop host), the keys the
|
|
* notifications store passes through a constant, and the Changes
|
|
* window's commit toasts (M4.2), the branch toasts (M4.5) and the remote
|
|
* toasts (M4.10), passed as
|
|
* `messageKey`.
|
|
*/
|
|
const RUNTIME_KEYS = new Set([
|
|
"notification.command.failed",
|
|
"notification.lsp.failed",
|
|
"notification.lsp.message",
|
|
"notification.lsp.renamed",
|
|
"notification.project.notLocal",
|
|
"notification.project.openFailed",
|
|
"notification.project.unsavedChanges",
|
|
"notification.recovery.corrupt",
|
|
"notification.recovery.unavailable",
|
|
"notification.recovery.writeFailed",
|
|
"notification.save.failed",
|
|
"notification.vcs.branchCreated",
|
|
"notification.vcs.checkedOut",
|
|
"notification.vcs.checkoutFailed",
|
|
"notification.vcs.checkoutNotSaved",
|
|
"notification.vcs.historyNoFile",
|
|
"notification.vcs.commitNotSaved",
|
|
"notification.vcs.committed",
|
|
"notification.vcs.newBranchFailed",
|
|
"notification.vcs.cloned",
|
|
"notification.vcs.fetchFailed",
|
|
"notification.vcs.fetched",
|
|
"notification.vcs.pullFailed",
|
|
"notification.vcs.pullNotSaved",
|
|
"notification.vcs.pulled",
|
|
"notification.vcs.pushFailed",
|
|
"notification.vcs.pushed",
|
|
"notification.vcs.pushedUpstream",
|
|
"notification.vcs.remoteCancelled",
|
|
"notification.settings.corrupt",
|
|
"notification.settings.corruptNotMoved",
|
|
"notification.settings.unavailable",
|
|
"notification.toolchain.downloadDone",
|
|
"notification.toolchain.downloadFailed",
|
|
"notification.toolchain.downloadStarted",
|
|
"notification.toolchain.phpMissing",
|
|
"notification.vfs.pumpFailed",
|
|
"notification.watch.failed",
|
|
"settings.appearance.theme.description",
|
|
"settings.appearance.theme.label",
|
|
"settings.appearance.theme.value.lutraDark",
|
|
"settings.appearance.theme.value.lutraLight",
|
|
"settings.appearance.theme.value.system",
|
|
"settings.editor.autosave.idleSeconds.description",
|
|
"settings.editor.autosave.idleSeconds.label",
|
|
"settings.editor.autosave.onBlur.description",
|
|
"settings.editor.autosave.onBlur.label",
|
|
"settings.editor.autosave.onTabSwitch.description",
|
|
"settings.editor.autosave.onTabSwitch.label",
|
|
"settings.editor.completion.autoPopup.description",
|
|
"settings.editor.completion.autoPopup.label",
|
|
"settings.editor.completion.delayMs.description",
|
|
"settings.editor.completion.delayMs.label",
|
|
"settings.editor.fontSize.description",
|
|
"settings.editor.fontSize.label",
|
|
"settings.editor.hover.delayMs.description",
|
|
"settings.editor.hover.delayMs.label",
|
|
"settings.git.executable.description",
|
|
"settings.git.executable.label",
|
|
"settings.git.pull.mode.description",
|
|
"settings.git.pull.mode.label",
|
|
"settings.git.pull.mode.value.merge",
|
|
"settings.git.pull.mode.value.rebase",
|
|
"settings.php.executable.description",
|
|
"settings.php.executable.label",
|
|
"settings.phpactor.autoDownload.description",
|
|
"settings.phpactor.autoDownload.label",
|
|
"settings.phpactor.path.description",
|
|
"settings.phpactor.path.label",
|
|
"settings.section.appearance",
|
|
"settings.section.editor",
|
|
"settings.section.git",
|
|
"settings.section.php",
|
|
"settings.ui.language.description",
|
|
"settings.ui.language.label",
|
|
"settings.ui.language.value.en",
|
|
"theme.lutraDark",
|
|
"theme.lutraLight",
|
|
]);
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
describe("t", () => {
|
|
it("returns the message of a key", () => {
|
|
expect(t("common.cancel")).toBe("Cancel");
|
|
});
|
|
|
|
it("fills in placeholders", () => {
|
|
expect(t("editor.tabs.close", { name: "index.php" })).toBe("Close index.php");
|
|
expect(t("app.statusBar.version", { name: "Lutra", version: "0.1.0" })).toBe("Lutra 0.1.0");
|
|
});
|
|
|
|
it("formats numbers", () => {
|
|
expect(t("common.toolWindow.hide", { title: 3 })).toBe("Hide 3");
|
|
});
|
|
|
|
it("keeps a placeholder without a value", () => {
|
|
expect(t("editor.tabs.close")).toBe("Close {name}");
|
|
expect(t("editor.tabs.close", { other: "x" })).toBe("Close {name}");
|
|
});
|
|
|
|
it("does not resolve placeholders from the prototype", () => {
|
|
expect(t("editor.tabs.close", {})).toBe("Close {name}");
|
|
expect(t("common.error.unexpectedResult", { command: "{name}" })).toBe(
|
|
"unexpected result of {name}",
|
|
);
|
|
});
|
|
|
|
it("returns the key and warns on a missing key", () => {
|
|
const warn = vi.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
expect(t("no.such.key")).toBe("no.such.key");
|
|
expect(warn).toHaveBeenCalledWith(expect.stringContaining("no.such.key"));
|
|
});
|
|
|
|
it("does not treat prototype names as keys", () => {
|
|
vi.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
expect(hasMessage("toString")).toBe(false);
|
|
expect(t("toString")).toBe("toString");
|
|
});
|
|
});
|
|
|
|
describe("en.json", () => {
|
|
it("uses flat dotted keys of known areas with string values", () => {
|
|
for (const [key, value] of Object.entries(en)) {
|
|
expect(key).toMatch(
|
|
/^(app|command|project|editor|common|palette|theme|recovery|notification|settings|find|goto|structure|menu|terminal|problems|nav|vcs)\.[A-Za-z0-9]+(\.[A-Za-z0-9]+)*$/,
|
|
);
|
|
expect(typeof value).toBe("string");
|
|
expect(value.trim()).not.toBe("");
|
|
}
|
|
});
|
|
|
|
it("is sorted by key", () => {
|
|
const keys = Object.keys(en);
|
|
expect(keys).toEqual([...keys].sort());
|
|
});
|
|
|
|
it("contains every key the source passes to t", () => {
|
|
expect(usedKeys.length).toBeGreaterThan(0);
|
|
const missing = usedKeys.filter(({ key }) => !hasMessage(key));
|
|
expect(missing).toEqual([]);
|
|
});
|
|
|
|
it("has every runtime key", () => {
|
|
expect([...RUNTIME_KEYS].filter((key) => !hasMessage(key))).toEqual([]);
|
|
});
|
|
|
|
it("has no unused keys", () => {
|
|
const used = new Set([...usedKeys.map(({ key }) => key), ...RUNTIME_KEYS]);
|
|
expect(Object.keys(en).filter((key) => !used.has(key))).toEqual([]);
|
|
});
|
|
});
|