Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { commandProgramName } from "./commandLabel.ts";
4
5describe("commandProgramName", () => {
6 it.each([
7 ["/bin/zsh -lc 'vp test run apps/web/src/session-logic.test.ts'", "vp"],
8 ["/bin/zsh -lc 'git diff --check'", "git"],
9 ['/bin/zsh -lc "npx -y react-doctor@latest apps/web"', "npx"],
10 ["/bin/zsh -lc 'rg -n \"registerHooks|worker\" apps/web/src'", "rg"],
11 ["/bin/bash --noprofile --norc -l -c 'sed -n 1,270p file.ts'", "sed"],
12 ["/bin/bash -o pipefail -lc 'vp test run'", "vp"],
13 ["/bin/bash --rcfile /tmp/config -c 'git status'", "git"],
14 ["sh -ec 'node scripts/check.js'", "node"],
15 ["fish --command 'rg --files'", "rg"],
16 ["zsh -lc 'CI=1 env -u DEBUG sudo -u root vp test run'", "vp"],
17 ["env CI=1 /bin/zsh -lc '\"/Applications/My Tools/bin/check\" --verbose'", "check"],
18 ["bash -lc \"zsh -c 'git status'\"", "git"],
19 ['"C:\\Program Files\\Git\\bin\\bash.exe" -lc "git status"', "git"],
20 ])("unwraps shell scripts without executing them: %s", (command, program) => {
21 expect(commandProgramName(command)).toBe(program);
22 });
23
24 it.each([
25 ["vp test run", "vp"],
26 ["sudo -u root pnpm test", "pnpm"],
27 ["env --split-string='CI=1 node scripts/check.js'", "node"],
28 ['"C:\\Program Files\\nodejs\\node.exe" script.js', "node.exe"],
29 ["/bin/zsh", "zsh"],
30 ["/bin/bash -l", "bash"],
31 ["zsh script.sh -c 'git status'", "zsh"],
32 ["bash -- -c 'git status'", "bash"],
33 ["bash --rcfile config.sh", "bash"],
34 ["my-shell -c 'git status'", "my-shell"],
35 ])("preserves ordinary programs and actual shell launches: %s", (command, program) => {
36 expect(commandProgramName(command)).toBe(program);
37 });
38
39 it.each([
40 "",
41 "zsh -lc",
42 "zsh -lc ''",
43 "zsh -lc 'git status",
44 "zsh -lc 'env'",
45 'zsh -lc "git \\\"',
46 ])("falls back for missing or malformed scripts: %s", (command) => {
47 expect(commandProgramName(command)).toBeNull();
48 });
49
50 it("bounds nested shell unwrapping", () => {
51 let command = "git status";
52 for (let depth = 0; depth < 9; depth += 1) {
53 command = `sh -c '${command.replaceAll("'", "'\\''")}'`;
54 }
55 expect(commandProgramName(command)).toBeNull();
56 });
57});