@lizard-build/cli 4.0.133 → 4.0.135

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.
Files changed (50) hide show
  1. package/dist/commands/git-hosting.js +35 -33
  2. package/dist/commands/git-hosting.js.map +1 -1
  3. package/dist/commands/logs.js +15 -12
  4. package/dist/commands/logs.js.map +1 -1
  5. package/dist/commands/sandbox.js +5 -3
  6. package/dist/commands/sandbox.js.map +1 -1
  7. package/dist/commands/up.d.ts +9 -0
  8. package/dist/commands/up.js +43 -13
  9. package/dist/commands/up.js.map +1 -1
  10. package/dist/lib/checkout.d.ts +7 -0
  11. package/dist/lib/checkout.js +20 -1
  12. package/dist/lib/checkout.js.map +1 -1
  13. package/dist/lib/config.d.ts +6 -1
  14. package/dist/lib/config.js +16 -4
  15. package/dist/lib/config.js.map +1 -1
  16. package/dist/lib/env-guard.js +38 -2
  17. package/dist/lib/env-guard.js.map +1 -1
  18. package/dist/lib/signin.d.ts +9 -0
  19. package/dist/lib/signin.js +19 -2
  20. package/dist/lib/signin.js.map +1 -1
  21. package/dist/lib/skills-data.generated.js +1 -1
  22. package/dist/lib/skills-data.generated.js.map +1 -1
  23. package/dist/lib/terminal.d.ts +20 -0
  24. package/dist/lib/terminal.js +32 -0
  25. package/dist/lib/terminal.js.map +1 -0
  26. package/dist/lib/updater.d.ts +1 -1
  27. package/dist/lib/updater.js +1 -1
  28. package/dist/lib/upload-filter.d.ts +14 -0
  29. package/dist/lib/upload-filter.js +146 -0
  30. package/dist/lib/upload-filter.js.map +1 -0
  31. package/package.json +1 -1
  32. package/skill-data/core/references/deploys.md +1 -1
  33. package/src/commands/git-hosting.ts +35 -33
  34. package/src/commands/logs.ts +16 -12
  35. package/src/commands/sandbox.ts +5 -3
  36. package/src/commands/up.ts +59 -9
  37. package/src/lib/checkout.ts +22 -1
  38. package/src/lib/config.ts +12 -5
  39. package/src/lib/env-guard.ts +37 -2
  40. package/src/lib/signin.ts +24 -2
  41. package/src/lib/terminal.ts +36 -0
  42. package/src/lib/updater.ts +1 -1
  43. package/src/lib/upload-filter.ts +141 -0
  44. package/test/unit/checkout-symlink.test.ts +19 -1
  45. package/test/unit/config.test.ts +21 -0
  46. package/test/unit/env-guard.test.ts +6 -2
  47. package/test/unit/login.test.ts +26 -1
  48. package/test/unit/terminal.test.ts +25 -0
  49. package/test/unit/upload-filter.test.ts +62 -0
  50. package/lizard-wrapper.sh +0 -2
package/src/lib/signin.ts CHANGED
@@ -35,6 +35,9 @@ interface SessionResponse {
35
35
  sessionId: string;
36
36
  sessionSecret: string;
37
37
  expiresIn: number;
38
+ /** Shown here and on the approval page, so the person approves this terminal's session.
39
+ * Older platforms do not send it. */
40
+ userCode?: string;
38
41
  }
39
42
 
40
43
  export interface CheckResponse {
@@ -92,6 +95,17 @@ export interface Pending {
92
95
  sessionId: string;
93
96
  sessionSecret: string;
94
97
  expiresAt: number;
98
+ userCode?: string;
99
+ }
100
+
101
+ /** The platform's confirmation code if it is one (letters, digits, dashes); never other text. */
102
+ export function cleanUserCode(code: unknown): string | undefined {
103
+ return typeof code === "string" && /^[A-Za-z0-9-]{1,32}$/.test(code) ? code : undefined;
104
+ }
105
+
106
+ /** The line that asks the person to check the code in the browser, or null without one. */
107
+ export function userCodeLine(code: string | undefined): string | null {
108
+ return code ? `Confirm this code in your browser: ${chalk.bold(code)}` : null;
95
109
  }
96
110
 
97
111
  export type Resumed =
@@ -175,6 +189,7 @@ export async function resumePending(): Promise<Resumed> {
175
189
  sessionId: saved.sessionId,
176
190
  sessionSecret: saved.sessionSecret,
177
191
  expiresAt: saved.expiresAt ?? saved.createdAt + SESSION_TTL_MS,
192
+ userCode: cleanUserCode(saved.userCode),
178
193
  };
179
194
  let result: CheckResponse;
180
195
  try {
@@ -203,6 +218,7 @@ export async function startSession(provider?: AuthProvider): Promise<Pending> {
203
218
  sessionId: session.sessionId,
204
219
  sessionSecret: session.sessionSecret,
205
220
  expiresAt: now + session.expiresIn * 1000,
221
+ userCode: cleanUserCode(session.userCode),
206
222
  };
207
223
  savePendingAuth({ ...pending, authUrl: authUrlFor(session.sessionId, provider), createdAt: now });
208
224
  return pending;
@@ -245,6 +261,9 @@ export function pendingPayload(
245
261
  const minutes = Math.max(1, Math.round((pending.expiresAt - now) / 60_000));
246
262
  const window = minutes === 1 ? "1 more minute" : `${minutes} more minutes`;
247
263
  const then = opts.nextCommand ? "run nextCommand" : "run the same command again";
264
+ const code = pending.userCode
265
+ ? ` Tell the user to check that the browser shows the code ${pending.userCode} before approving.`
266
+ : "";
248
267
  const lead =
249
268
  why === "waiting"
250
269
  ? "The user has not finished signing in yet. "
@@ -253,16 +272,17 @@ export function pendingPayload(
253
272
  : "";
254
273
  const instruction = single
255
274
  ? `${lead}Sign-in is needed. Give the user authUrl to open. Once the browser says "CLI authorized", ${then}. ` +
256
- `The link works for ${window}; after that a new one is printed.`
275
+ `The link works for ${window}; after that a new one is printed.${code}`
257
276
  : `${lead}Sign-in is needed. Ask the user how they sign in to Lizard and give them that link from authUrls. ` +
258
277
  "Someone who already has an account must use the same method as before: another method opens a second, empty account " +
259
278
  "unless both share a verified email. A new user can pick either. " +
260
- `Once the browser says "CLI authorized", ${then}. The links work for ${window}; after that new ones are printed.`;
279
+ `Once the browser says "CLI authorized", ${then}. The links work for ${window}; after that new ones are printed.${code}`;
261
280
  return {
262
281
  status: "pending" as const,
263
282
  authUrl: single ? authUrls[single]! : authUrlFor(pending.sessionId, opts.flag),
264
283
  authUrls,
265
284
  expiresAt: new Date(pending.expiresAt).toISOString(),
285
+ ...(pending.userCode ? { userCode: pending.userCode } : {}),
266
286
  ...(opts.nextCommand ? { nextCommand: opts.nextCommand } : {}),
267
287
  instruction,
268
288
  };
@@ -329,6 +349,8 @@ export async function signInInteractive(flag?: AuthProvider): Promise<Me> {
329
349
  ["Open one of these links to sign in:", ...methods.map((m) => `${PROVIDER_LABEL[m]}: ${chalk.cyan(authUrlFor(pending.sessionId, m))}`)].join("\n"),
330
350
  );
331
351
  }
352
+ const codeLine = userCodeLine(pending.userCode);
353
+ if (codeLine) p.log.warn(codeLine);
332
354
 
333
355
  // Ctrl+C at a terminal never reaches onCancel: clack holds stdin raw while it
334
356
  // spins and exits on the keypress itself, printing cancelMessage on the way
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Text that someone else wrote (log lines, issue titles, comments, file contents from the
3
+ * server) can carry terminal control sequences: OSC 52 writes the clipboard, OSC 8 hides a link
4
+ * behind other text, CSI moves the cursor to overwrite what was printed, \r rewrites a line.
5
+ * Printed to a terminal, such text is shown, never obeyed.
6
+ */
7
+
8
+ // ESC sequences: CSI (ESC [ ... final), OSC (ESC ] ... BEL | ST), DCS/SOS/PM/APC (ESC P|X|^|_ ... ST),
9
+ // and two-byte ESC sequences; plus their 8-bit C1 forms (CSI 0x9b, OSC 0x9d, DCS 0x90, ...).
10
+ const SEQUENCES =
11
+ /\x1b\[[0-?]*[ -/]*[@-~]|\x1b\][^\x07\x1b\x9c]*(?:\x07|\x1b\\|\x9c)?|\x1b[PX^_][^\x1b\x9c]*(?:\x1b\\|\x9c)?|\x1b[ -/]*[0-~]|\x9b[0-?]*[ -/]*[@-~]|[\x90\x98\x9d\x9e\x9f][^\x07\x1b\x9c]*(?:\x07|\x1b\\|\x9c)?/g;
12
+ // SGR (colors, bold): moves nothing, writes nothing; kept for a service's own colored logs.
13
+ const SGR = /^\x1b\[[0-9;:]*m$/;
14
+ // C0 controls except \t and \n, DEL, and C1 controls.
15
+ const CONTROLS = "[\\x00-\\x08\\x0b-\\x1f\\x7f-\\x9f]";
16
+ // One pass, sequences first, so a kept color code's ESC is not then stripped as a control.
17
+ const ALL = new RegExp(`${SEQUENCES.source}|${CONTROLS}`, "g");
18
+
19
+ /** text without terminal control sequences or control characters (\n and \t stay). */
20
+ export function stripTerminalControls(text: string, opts: { keepColors?: boolean } = {}): string {
21
+ return text.replace(ALL, (m) => (opts.keepColors && SGR.test(m) ? m : ""));
22
+ }
23
+
24
+ /**
25
+ * text made safe for `stream` (stdout by default): stripped when it is a terminal, unchanged
26
+ * when it goes to a file or a pipe (`> log.txt` keeps the bytes the service wrote).
27
+ */
28
+ export function termSafe(text: unknown, opts: { keepColors?: boolean; stream?: NodeJS.WriteStream } = {}): string {
29
+ const s = text == null ? "" : String(text);
30
+ return (opts.stream ?? process.stdout).isTTY ? stripTerminalControls(s, opts) : s;
31
+ }
32
+
33
+ /** termSafe for text printed through info()/warn() (stderr). */
34
+ export function termSafeErr(text: unknown): string {
35
+ return termSafe(text, { stream: process.stderr });
36
+ }
@@ -6,7 +6,7 @@ import os from "node:os";
6
6
  import { spawn } from "node:child_process";
7
7
  import { createPublicKey, verify } from "node:crypto";
8
8
 
9
- export const CURRENT_VERSION = "4.0.133";
9
+ export const CURRENT_VERSION = "4.0.135";
10
10
  const RELEASES_API = "https://api.github.com/repos/lizard-build/lizard-cli/releases/latest";
11
11
  const RELEASE_BASE = "https://github.com/lizard-build/lizard-cli/releases/latest/download";
12
12
 
@@ -0,0 +1,141 @@
1
+ import * as fs from "node:fs";
2
+ import * as os from "node:os";
3
+ import * as path from "node:path";
4
+
5
+ // ── what `lizard up` must not upload by accident ────────────────────────────
6
+
7
+ const SECRET_DIRS = new Set([".ssh", ".aws", ".gnupg"]);
8
+ const SECRET_FILES = new Set([".npmrc", ".pypirc", ".netrc"]);
9
+ const ENV_TEMPLATES = new Set([".env.example", ".env.sample"]);
10
+
11
+ /** A `.env` or `.env.*` file that holds values (not `.env.example` / `.env.sample`). */
12
+ export function isEnvFile(name: string): boolean {
13
+ return (name === ".env" || name.startsWith(".env.")) && !ENV_TEMPLATES.has(name);
14
+ }
15
+
16
+ /**
17
+ * Credentials and keys that a folder walk would otherwise upload: env files, SSH/AWS/GnuPG
18
+ * folders, package-manager and netrc credentials, Docker's login file, private keys.
19
+ * `rel` is a /-separated path relative to the upload root.
20
+ */
21
+ export function isSensitivePath(rel: string): boolean {
22
+ const parts = rel.split("/");
23
+ const name = parts[parts.length - 1];
24
+ if (parts.slice(0, -1).some((d) => SECRET_DIRS.has(d))) return true;
25
+ if (SECRET_DIRS.has(name)) return true;
26
+ if (SECRET_FILES.has(name) || isEnvFile(name)) return true;
27
+ if (name === "config.json" && parts[parts.length - 2] === ".docker") return true;
28
+ if (/^id_(rsa|ed25519|ecdsa)/.test(name)) return true;
29
+ const ext = path.extname(name).toLowerCase();
30
+ return ext === ".pem" || ext === ".key";
31
+ }
32
+
33
+ /** The home folder or a file system root: a walk from there would upload a whole machine. */
34
+ export function isTooBroadToUpload(dir: string): boolean {
35
+ const real = (p: string) => {
36
+ try {
37
+ return fs.realpathSync(p);
38
+ } catch {
39
+ return path.resolve(p);
40
+ }
41
+ };
42
+ const d = real(dir);
43
+ return d === real(os.homedir()) || d === path.parse(d).root;
44
+ }
45
+
46
+ // ── .lizardignore (gitignore syntax) ────────────────────────────────────────
47
+
48
+ interface Rule {
49
+ re: RegExp;
50
+ negate: boolean;
51
+ dirOnly: boolean;
52
+ }
53
+
54
+ function globToRegex(glob: string): string {
55
+ let out = "";
56
+ for (let i = 0; i < glob.length; i++) {
57
+ const c = glob[i];
58
+ if (c === "*") {
59
+ if (glob[i + 1] === "*") {
60
+ const atStart = i === 0 || glob[i - 1] === "/";
61
+ const atEnd = i + 2 === glob.length || glob[i + 2] === "/";
62
+ if (atStart && atEnd) {
63
+ if (glob[i + 2] === "/") {
64
+ out += "(?:.*/)?"; // `**/`: any number of folders, including none
65
+ i += 2;
66
+ } else {
67
+ out += ".*"; // trailing `**`: everything inside
68
+ i += 1;
69
+ }
70
+ continue;
71
+ }
72
+ }
73
+ out += "[^/]*";
74
+ } else if (c === "?") {
75
+ out += "[^/]";
76
+ } else if (c === "[") {
77
+ const close = glob.indexOf("]", i + 2);
78
+ if (close === -1) {
79
+ out += "\\[";
80
+ } else {
81
+ let body = glob.slice(i + 1, close).replace(/\\/g, "\\\\");
82
+ if (body.startsWith("!")) body = "^" + body.slice(1);
83
+ out += `[${body}]`;
84
+ i = close;
85
+ }
86
+ } else if (c === "\\" && i + 1 < glob.length) {
87
+ out += glob[++i].replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
88
+ } else {
89
+ out += c.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
90
+ }
91
+ }
92
+ return out;
93
+ }
94
+
95
+ /** Parse gitignore-syntax text into a matcher for /-separated paths relative to its folder. */
96
+ export function parseIgnore(text: string): (rel: string, isDir?: boolean) => boolean {
97
+ const rules: Rule[] = [];
98
+ for (const raw of text.split(/\r?\n/)) {
99
+ let line = raw.replace(/(?<!\\)\s+$/, "");
100
+ if (!line || line.startsWith("#")) continue;
101
+ let negate = false;
102
+ if (line.startsWith("!")) {
103
+ negate = true;
104
+ line = line.slice(1);
105
+ } else if (line.startsWith("\\!") || line.startsWith("\\#")) {
106
+ line = line.slice(1);
107
+ }
108
+ let dirOnly = false;
109
+ if (line.endsWith("/")) {
110
+ dirOnly = true;
111
+ line = line.replace(/\/+$/, "");
112
+ }
113
+ if (!line) continue;
114
+ const anchored = line.includes("/");
115
+ line = line.replace(/^\//, "");
116
+ const body = globToRegex(line);
117
+ rules.push({ re: new RegExp(`^${anchored ? "" : "(?:.*/)?"}${body}$`), negate, dirOnly });
118
+ }
119
+ const verdict = (p: string, isDir: boolean): boolean | undefined => {
120
+ let v: boolean | undefined;
121
+ for (const r of rules) if ((!r.dirOnly || isDir) && r.re.test(p)) v = !r.negate;
122
+ return v;
123
+ };
124
+ // As in git: a file inside an ignored folder stays ignored.
125
+ return (rel: string, isDir = false) => {
126
+ const parts = rel.split("/");
127
+ for (let i = 1; i <= parts.length; i++) {
128
+ if (verdict(parts.slice(0, i).join("/"), i < parts.length || isDir)) return true;
129
+ }
130
+ return false;
131
+ };
132
+ }
133
+
134
+ /** The matcher for `<root>/.lizardignore`, or null when there is none. */
135
+ export function loadLizardIgnore(root: string): ((rel: string, isDir?: boolean) => boolean) | null {
136
+ try {
137
+ return parseIgnore(fs.readFileSync(path.join(root, ".lizardignore"), "utf8"));
138
+ } catch {
139
+ return null;
140
+ }
141
+ }
@@ -2,7 +2,7 @@ import { describe, it, expect, afterEach, beforeEach, vi } from "vitest";
2
2
  import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, symlinkSync, writeFileSync } from "node:fs";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
- import { saveCheckout, sha256, sync, type Checkout } from "../../src/lib/checkout.js";
5
+ import { isMetadataName, saveCheckout, sha256, sync, type Checkout } from "../../src/lib/checkout.js";
6
6
 
7
7
  // A fake Lizard Git that serves one changeset: `tree` maps paths to contents (a symlink is
8
8
  // { link: target }). Trees are addressed by a made-up hash, blobs by their sha256.
@@ -101,3 +101,21 @@ describe("lizard git sync never writes through a symlink", () => {
101
101
  expect(readFileSync(join(root, "e/x"), "utf8")).toBe("ok");
102
102
  });
103
103
  });
104
+
105
+ describe("lizard git sync never writes into git metadata", () => {
106
+ it.each([".git", ".GIT", ".Git", ".git.", ".git ", ".git. .", ".git::$INDEX_ALLOCATION", "git~1", "GIT~1", "Git~2", ".g\u200cit",
107
+ ".lizard-git", ".LIZARD-GIT", "LIZARD~1"])("%s is metadata", (n) => expect(isMetadataName(n)).toBe(true));
108
+
109
+ it.each([".gitignore", ".gitkeep", ".github", "git", "src", "git~", "my.git"])("%s is an ordinary name", (n) =>
110
+ expect(isMetadataName(n)).toBe(false));
111
+
112
+ it("a changeset with .git paths writes nothing there", async () => {
113
+ mkdirSync(join(root, ".git"));
114
+ const c = checkout({});
115
+ serve({ ".git/hooks/post-checkout": "evil", "GIT~1/config": "evil", "sub/.Git/config": "evil" });
116
+ await sync(root, c).catch(() => {});
117
+ expect(existsSync(join(root, ".git/hooks/post-checkout"))).toBe(false);
118
+ expect(existsSync(join(root, "GIT~1"))).toBe(false);
119
+ expect(existsSync(join(root, "sub/.Git"))).toBe(false);
120
+ });
121
+ });
@@ -3,6 +3,8 @@ import * as fs from "node:fs";
3
3
  import * as os from "node:os";
4
4
  import * as path from "node:path";
5
5
  import {
6
+ configDir,
7
+ saveConfig,
6
8
  setProjectLink,
7
9
  getProjectLink,
8
10
  updateProjectLink,
@@ -121,3 +123,22 @@ describe("ProjectLink schema", () => {
121
123
  expect(link?.workspaceId).toBeUndefined();
122
124
  });
123
125
  });
126
+
127
+ describe.skipIf(process.platform === "win32")("config file permissions", () => {
128
+ test("a new config is 0600 in a 0700 folder", () => {
129
+ saveConfig({});
130
+ expect(fs.statSync(configDir()).mode & 0o777).toBe(0o700);
131
+ expect(fs.statSync(path.join(configDir(), "config.json")).mode & 0o777).toBe(0o600);
132
+ });
133
+
134
+ test("an existing world-readable config is fixed on the next write", () => {
135
+ fs.mkdirSync(configDir(), { recursive: true, mode: 0o755 });
136
+ fs.chmodSync(configDir(), 0o755);
137
+ const file = path.join(configDir(), "config.json");
138
+ fs.writeFileSync(file, "{}", { mode: 0o644 });
139
+ fs.chmodSync(file, 0o644);
140
+ saveConfig({});
141
+ expect(fs.statSync(configDir()).mode & 0o777).toBe(0o700);
142
+ expect(fs.statSync(file).mode & 0o777).toBe(0o600);
143
+ });
144
+ });
@@ -5,9 +5,13 @@ import { writableChanges } from "../../src/commands/gha.js";
5
5
  describe("lizard run: variables that change how programs start are not set locally", () => {
6
6
  it.each(["LD_PRELOAD", "LD_LIBRARY_PATH", "DYLD_INSERT_LIBRARIES", "NODE_OPTIONS", "BASH_ENV", "ENV", "PROMPT_COMMAND", "PATH",
7
7
  "PYTHONSTARTUP", "PYTHONPATH", "PERL5OPT", "RUBYOPT", "GIT_CONFIG_COUNT", "GIT_CONFIG_KEY_0", "GIT_CONFIG_GLOBAL", "GIT_SSH_COMMAND", "GIT_EXEC_PATH",
8
- "BASH_FUNC_ls%%"])("%s is skipped", (n) => expect(isStartupEnvName(n)).toBe(true));
8
+ "BASH_FUNC_ls%%", "GIT_EXTERNAL_DIFF", "GIT_PAGER", "GIT_EDITOR", "GIT_SEQUENCE_EDITOR", "GIT_PROXY_COMMAND", "GIT_SSH", "GIT_ASKPASS",
9
+ "SSH_ASKPASS", "GOFLAGS", "RUSTC_WRAPPER", "RUSTC", "CARGO_BUILD_RUSTC_WRAPPER", "PYTHONWARNINGS", "JDK_JAVA_OPTIONS", "JAVA_TOOL_OPTIONS",
10
+ "_JAVA_OPTIONS", "DOTNET_STARTUP_HOOKS", "npm_config_script_shell", "NPM_CONFIG_NODE_OPTIONS", "Npm_Config_x", "PHPRC", "PHP_INI_SCAN_DIR",
11
+ "PAGER", "EDITOR", "VISUAL", "LESSOPEN", "LESSCLOSE", "BROWSER", "HTTPS_PROXY", "https_proxy", "http_proxy", "ALL_PROXY", "all_proxy",
12
+ "NODE_EXTRA_CA_CERTS", "SSL_CERT_FILE", "SSL_CERT_DIR", "REQUESTS_CA_BUNDLE", "CURL_CA_BUNDLE"])("%s is skipped", (n) => expect(isStartupEnvName(n)).toBe(true));
9
13
 
10
- it.each(["DATABASE_URL", "NODE_ENV", "PORT", "REDIS_URL", "API_KEY", "PATHNAME", "ENVIRONMENT", "GITHUB_TOKEN"])("%s is set", (n) =>
14
+ it.each(["DATABASE_URL", "NODE_ENV", "PORT", "REDIS_URL", "API_KEY", "PATHNAME", "ENVIRONMENT", "GITHUB_TOKEN", "NO_PROXY", "NPM_TOKEN", "EDITOR_THEME"])("%s is set", (n) =>
11
15
  expect(isStartupEnvName(n)).toBe(false));
12
16
  });
13
17
 
@@ -5,7 +5,7 @@ import * as path from "node:path";
5
5
  import { Command } from "commander";
6
6
  import { Readable } from "node:stream";
7
7
  import { registerLogin, accountState, accountInstruction, nextSteps, nextStepsNote, readTokenFromStdin } from "../../src/commands/login.js";
8
- import { authUrlFor, providerFlag, pendingPayload } from "../../src/lib/signin.js";
8
+ import { authUrlFor, providerFlag, pendingPayload, cleanUserCode, userCodeLine } from "../../src/lib/signin.js";
9
9
  import type { Subscription } from "../../src/commands/billing.js";
10
10
  import { requireAuth } from "../../src/lib/auth.js";
11
11
  import { APIError, setBaseURL } from "../../src/lib/api.js";
@@ -157,6 +157,31 @@ describe("sign-in links", () => {
157
157
  });
158
158
  });
159
159
 
160
+ describe("login confirmation code", () => {
161
+ test("a code from the platform is shown and passed to agents", () => {
162
+ const ev = pendingPayload({ sessionId: "s", sessionSecret: "x", expiresAt: Date.now() + 300_000, userCode: "K7QX-M2PA" }, ["github"], "new");
163
+ expect(ev.userCode).toBe("K7QX-M2PA");
164
+ expect(ev.instruction).toContain("K7QX-M2PA");
165
+ expect(userCodeLine("K7QX-M2PA")).toContain("Confirm this code in your browser: ");
166
+ expect(userCodeLine("K7QX-M2PA")).toContain("K7QX-M2PA");
167
+ });
168
+
169
+ test("an older platform sends none: nothing changes", () => {
170
+ const ev = pendingPayload({ sessionId: "s", sessionSecret: "x", expiresAt: Date.now() + 300_000 }, ["github"], "new");
171
+ expect(ev).not.toHaveProperty("userCode");
172
+ expect(ev.instruction).not.toContain("code");
173
+ expect(userCodeLine(undefined)).toBeNull();
174
+ expect(cleanUserCode(undefined)).toBeUndefined();
175
+ });
176
+
177
+ test("only letters, digits and dashes are taken as a code", () => {
178
+ expect(cleanUserCode("K7QX-M2PA")).toBe("K7QX-M2PA");
179
+ expect(cleanUserCode("K7QX\x1b]52;c;aGk=\x07")).toBeUndefined();
180
+ expect(cleanUserCode(42)).toBeUndefined();
181
+ expect(cleanUserCode("")).toBeUndefined();
182
+ });
183
+ });
184
+
160
185
  describe("account state", () => {
161
186
  test("maps the subscription to what the account still needs", () => {
162
187
  expect(accountState(null)).toBe("unknown");
@@ -0,0 +1,25 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { stripTerminalControls } from "../../src/lib/terminal.js";
3
+
4
+ describe("text from others is shown, never obeyed by the terminal", () => {
5
+ it.each([
6
+ ["OSC 52 clipboard write", "a\x1b]52;c;ZWNobyBoaQ==\x07b", "ab"],
7
+ ["OSC 8 hidden link", "\x1b]8;;https://evil\x1b\\click\x1b]8;;\x1b\\", "click"],
8
+ ["cursor up + erase line", "ok\x1b[1A\x1b[2Kfake", "okfake"],
9
+ ["carriage return overwrite", "real\rfake", "realfake"],
10
+ ["8-bit CSI", "a\x9b2Jb", "ab"],
11
+ ["DCS", "a\x1bPq#0;2;0;0;0\x1b\\b", "ab"],
12
+ ["bell, backspace, DEL", "a\x07\x08\x7fb", "ab"],
13
+ ["lone ESC", "a\x1b", "a"],
14
+ ["title set", "\x1b]0;pwned\x07x", "x"],
15
+ ])("%s", (_n, input, want) => expect(stripTerminalControls(input)).toBe(want));
16
+
17
+ it("keeps newlines, tabs and ordinary text, unicode included", () => {
18
+ expect(stripTerminalControls("a\tb\nc → é 日本")).toBe("a\tb\nc → é 日本");
19
+ });
20
+
21
+ it("colors go unless asked to keep them; with keepColors only colors stay", () => {
22
+ expect(stripTerminalControls("\x1b[31mred\x1b[0m")).toBe("red");
23
+ expect(stripTerminalControls("\x1b[31mred\x1b[0m\x1b[2J\x1b]52;c;x\x07", { keepColors: true })).toBe("\x1b[31mred\x1b[0m");
24
+ });
25
+ });
@@ -0,0 +1,62 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { execSync } from "node:child_process";
5
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6
+ import { isSensitivePath, parseIgnore } from "../../src/lib/upload-filter.js";
7
+ import { getUploadFiles } from "../../src/commands/up.js";
8
+
9
+ describe("files that look like secrets", () => {
10
+ it.each([".env", ".env.local", ".env.production", "app/.env", ".ssh/id_rsa", "x/.aws/credentials", ".gnupg/pubring.kbx", ".npmrc",
11
+ ".pypirc", ".netrc", ".docker/config.json", "id_rsa", "id_rsa.pub", "keys/id_ed25519", "id_ecdsa", "server.pem", "tls/server.KEY", ".ssh"])(
12
+ "%s is skipped", (p) => expect(isSensitivePath(p)).toBe(true));
13
+ it.each([".env.example", ".env.sample", "src/env.ts", "config.json", "docker/config.json", "keyboard.ts", "README.md", "environment.yml"])(
14
+ "%s is uploaded", (p) => expect(isSensitivePath(p)).toBe(false));
15
+ });
16
+
17
+ describe(".lizardignore (gitignore syntax)", () => {
18
+ const m = parseIgnore("# comment\n*.log\n/build\ndata/\n!keep.log\ndocs/**/*.pdf\nsecret?.txt\n");
19
+ it.each([["a.log", true], ["x/y/a.log", true], ["keep.log", false], ["build/out.js", true], ["src/build/x", false],
20
+ ["data/a.csv", true], ["a/data/b", true], ["docs/a/b/c.pdf", true], ["docs/c.pdf", true], ["secret1.txt", true], ["secret12.txt", false],
21
+ ["src/index.ts", false]] as const)("%s -> %s", (p, want) => expect(m(p)).toBe(want));
22
+ it("a folder-only rule does not match a file of that name", () => expect(m("data")).toBe(false));
23
+ });
24
+
25
+ describe("lizard up file selection", () => {
26
+ let dir: string;
27
+ beforeEach(() => {
28
+ dir = fs.mkdtempSync(path.join(os.tmpdir(), "lizard-up-files-"));
29
+ const w = (p: string, t = "x") => {
30
+ fs.mkdirSync(path.dirname(path.join(dir, p)), { recursive: true });
31
+ fs.writeFileSync(path.join(dir, p), t);
32
+ };
33
+ w("index.js"); w(".env"); w(".env.example"); w(".ssh/id_rsa"); w("certs/tls.pem"); w("tmp/big.bin"); w("notes.txt");
34
+ w(".lizardignore", "tmp/\nnotes.txt\n");
35
+ });
36
+ afterEach(() => {
37
+ vi.unstubAllEnvs();
38
+ fs.rmSync(dir, { recursive: true, force: true });
39
+ });
40
+
41
+ it("folder walk: secrets skipped and reported, .lizardignore honoured", () => {
42
+ const r = getUploadFiles(dir, false);
43
+ expect(r.files.sort()).toEqual([".env.example", ".lizardignore", "index.js"]);
44
+ expect(r.skipped.sort()).toEqual([".env", ".ssh/", "certs/tls.pem"]);
45
+ });
46
+
47
+ it("refuses the home folder", () => {
48
+ vi.stubEnv("HOME", dir);
49
+ expect(() => getUploadFiles(dir, false)).toThrow(/home folder/);
50
+ });
51
+
52
+ it("git listing: .lizardignore honoured, untracked .env warned about", () => {
53
+ const git = (c: string) => execSync(`git ${c}`, { cwd: dir, stdio: "pipe", env: { ...process.env, GIT_CONFIG_GLOBAL: "/dev/null" } });
54
+ git("init -q");
55
+ git("add index.js");
56
+ const r = getUploadFiles(dir, true);
57
+ expect(r.files).not.toContain("notes.txt");
58
+ expect(r.files).not.toContain("tmp/big.bin");
59
+ expect(r.files).toContain(".env");
60
+ expect(r.untrackedEnv).toEqual([".env"]);
61
+ });
62
+ });
package/lizard-wrapper.sh DELETED
@@ -1,2 +0,0 @@
1
- #!/bin/bash
2
- exec /home/ubuntu/.nvm/versions/node/v22.22.2/bin/node /home/ubuntu/Work/lizard-cli/dist/index.js "$@"