refactor: cut cyclomatic complexity of five hot spots and pin their behavior with tests
Risk labels, menu callback parsing, settings callbacks, table cell width and markdown link targets now use tables and small helpers (CC <= 10).
This commit is contained in:
1 parent
bf4a2021e8
commit
6a6e75fe32
8 files changed
+648
-294
No files matched your search
@@ -2394,3 +2394,45 @@ test("Settings menu marks one-line on/off checkbox controls symmetrically", () =
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
test("Menu callback parser maps every status alias and model action, and ignores the rest", () => {
|
||||
for (const action of ["model", "thinking", "queue", "settings"] as const) {
|
||||
for (const prefix of ["menu", "status"]) {
|
||||
assert.deepEqual(parseTelegramMenuCallbackAction(`${prefix}:${action}`), {
|
||||
kind: "status",
|
||||
action,
|
||||
});
|
||||
}
|
||||
}
|
||||
for (const action of [
|
||||
"noop",
|
||||
"scope",
|
||||
"page",
|
||||
"pages",
|
||||
"open",
|
||||
"pick",
|
||||
"pick-selected",
|
||||
"scope-enable",
|
||||
"scope-disable",
|
||||
"scope-toggle",
|
||||
]) {
|
||||
assert.deepEqual(parseTelegramMenuCallbackAction(`model:${action}:7`), {
|
||||
kind: "model",
|
||||
action,
|
||||
value: "7",
|
||||
});
|
||||
}
|
||||
assert.deepEqual(parseTelegramMenuCallbackAction("thinking:set:"), {
|
||||
kind: "thinking:set",
|
||||
level: "",
|
||||
});
|
||||
assert.deepEqual(parseTelegramMenuCallbackAction("model:unknown:1"), {
|
||||
kind: "ignore",
|
||||
});
|
||||
assert.deepEqual(parseTelegramMenuCallbackAction("menu:other"), {
|
||||
kind: "ignore",
|
||||
});
|
||||
assert.deepEqual(parseTelegramMenuCallbackAction(undefined), {
|
||||
kind: "ignore",
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user