diff options
| author | amankumarsingh77 <amankumarsingh7702@gmail.com> | 2026-07-28 20:32:57 +0530 |
|---|---|---|
| committer | Aman Kumar <145339995+amankumarsingh77@users.noreply.github.com> | 2026-08-02 19:12:46 +0530 |
| commit | 34e5cfdcbe29bbb5f2f46ba54eb67903abd9274d (patch) | |
| tree | f7b421652a7664d97362a308f4a1288cce2ef5b0 /test/profile | |
| parent | 91a2fdeff796bae8e87d9146e2d540550f54dd74 (diff) | |
refactor(test): strip comment noise
Removes suite banners, section dividers, and test-id markers that restate
the test names. Keeps one-line notes for the deleted-binary fixture order,
the never-arriving event consumer, the absent-vs-undefined key distinction,
the unexpected-method-echo rationale, and the real-browser teardown and
Local State flush quirks.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'test/profile')
| -rw-r--r-- | test/profile/browser-process-test.ts | 26 | ||||
| -rw-r--r-- | test/profile/launch-test.ts | 19 | ||||
| -rw-r--r-- | test/profile/list-test.ts | 18 | ||||
| -rw-r--r-- | test/profile/paths-test.ts | 17 | ||||
| -rw-r--r-- | test/profile/store-test.ts | 9 |
5 files changed, 2 insertions, 87 deletions
diff --git a/test/profile/browser-process-test.ts b/test/profile/browser-process-test.ts index 7a86c74..efcb9c8 100644 --- a/test/profile/browser-process-test.ts +++ b/test/profile/browser-process-test.ts @@ -1,14 +1,3 @@ -/** - * Unit tests for browser-process parsing and candidate ranking — no browser. - * - * Ranking exists because a machine can run several Chromium browsers at once. - * Picking the wrong one means launching a profile window into a browser the - * harness is not connected to: the agent sees nothing, and a browser the user - * never pointed us at gets a new window. (That is exactly what happened during - * development before ranking existed.) - * - * Run: npm test - */ import { test, before, after, describe } from "node:test"; import assert from "node:assert/strict"; import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; @@ -23,7 +12,6 @@ import { } from "../../src/profile/browser-process"; describe("browser-process parsing and candidate ranking", () => { - // B1: --user-data-dir parsing test("B1: bare value parsed", () => { assert.equal(parseUserDataDirFlag("/opt/google/chrome/chrome --user-data-dir=/tmp/x --foo"), "/tmp/x"); }); @@ -47,7 +35,6 @@ describe("browser-process parsing and candidate ranking", () => { assert.equal(parseUserDataDirFlag("chrome --user-data-dir="), undefined); }); - // B2: an explicit --user-data-dir is decisive in both directions test("B2: exact user-data-dir match outranks a flagless process", () => { const target = "/tmp/pi-e2e-abc"; const match = rankBrowserCandidate({ exePath: "/opt/google/chrome/chrome", explicitUserDataDir: target }, target); @@ -74,7 +61,6 @@ describe("browser-process parsing and candidate ranking", () => { assert.equal(other, 0); }); - // B3: browser family match decides between flagless processes test("B3: Brave wins for a Brave user-data-dir", () => { const braveDir = join(homedir(), ".config/BraveSoftware/Brave-Browser"); const brave = rankBrowserCandidate({ exePath: "/usr/bin/brave-browser" }, braveDir); @@ -98,7 +84,6 @@ describe("browser-process parsing and candidate ranking", () => { ); }); - // B4: no preference expressed → every candidate is equally acceptable test("B4: without a target dir, candidates rank equally", () => { assert.equal( rankBrowserCandidate({ exePath: "/usr/bin/brave-browser" }), @@ -106,7 +91,6 @@ describe("browser-process parsing and candidate ranking", () => { ); }); - // B5: Windows path comparison ignores case and separator style test("B5 win: case and separator differences still match", { skip: process.platform !== "win32" }, () => { assert.equal( rankBrowserCandidate( @@ -120,9 +104,6 @@ describe("browser-process parsing and candidate ranking", () => { ); }); - // B6: Linux's deleted-binary marker. An in-place `google-chrome` upgrade - // unlinks the running binary, after which /proc/<pid>/exe reads - // "…/chrome (deleted)" — a path spawn() rejects with ENOENT. test("B6: marker stripped from a replaced binary's path", () => { assert.equal(stripDeletedSuffix("/opt/google/chrome/chrome (deleted)"), "/opt/google/chrome/chrome"); }); @@ -135,7 +116,6 @@ describe("browser-process parsing and candidate ranking", () => { assert.equal(stripDeletedSuffix(" (deleted)"), undefined); }); - // B7: only a path that is actually on disk may be handed on as spawnable. describe("B7", () => { let root: string; let real: string; @@ -168,9 +148,6 @@ describe("browser-process parsing and candidate ranking", () => { assert.equal(await spawnableExePath(""), undefined); }); - // The launch gate must never pass on a path it cannot spawn — that is - // what produced a 15s "couldn't open a window" timeout instead of a - // named error. test("B7: resolveBrowserExecutable repairs a replaced-binary path", async () => { assert.equal(await resolveBrowserExecutable({ running: true, exePath: `${real} (deleted)` }), real); }); @@ -183,8 +160,7 @@ describe("browser-process parsing and candidate ranking", () => { }, ); - // A binary genuinely named "… (deleted)" must win over the stripped form. - // Created last, so the checks above see only the ordinary case. + // A binary genuinely named "… (deleted)" must win over the stripped form; created last so the checks above see only the ordinary case. test("B7: a real file named '… (deleted)' is preferred over stripping", async () => { literal = join(root, "chrome (deleted)"); writeFileSync(literal, "#!/bin/sh\n"); diff --git a/test/profile/launch-test.ts b/test/profile/launch-test.ts index 70ca8af..3883f98 100644 --- a/test/profile/launch-test.ts +++ b/test/profile/launch-test.ts @@ -1,14 +1,3 @@ -/** - * Unit tests for openProfileWindow's failure reporting — no browser required. - * - * spawn() reports a missing or non-executable binary asynchronously, as an - * 'error' event, not by throwing. When that event was ignored, a bad executable - * path returned `ok` and the caller's 15s sentinel poll blamed the browser: - * "couldn't open a window in <profile> automatically". These tests pin the - * failure to its real cause instead. - * - * Run: npm test - */ import { test, before, after, describe } from "node:test"; import assert from "node:assert/strict"; import { existsSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from "node:fs"; @@ -28,8 +17,6 @@ describe("openProfileWindow's failure reporting", () => { rmSync(root, { recursive: true, force: true }); }); - // L1: a nonexistent binary — the shape of an in-place browser upgrade, - // where /proc/<pid>/exe still names the unlinked file. describe("L1", () => { const missing = (): string => join(root, "chrome (deleted)"); @@ -51,8 +38,6 @@ describe("openProfileWindow's failure reporting", () => { }); }); - // L2: a file that exists but is not executable — same async 'error' path, - // different errno (EACCES). Skipped where the check is meaningless. test( "L2: a non-executable file fails the launch", { skip: process.platform === "win32" || process.getuid?.() === 0 }, @@ -64,8 +49,6 @@ describe("openProfileWindow's failure reporting", () => { }, ); - // L3: a failed launch leaves no sentinel file behind. The caller only calls - // cleanup() on the success path, so the failure path owns its own tidying. describe("L3", () => { let before_: string | undefined; @@ -91,8 +74,6 @@ describe("openProfileWindow's failure reporting", () => { }); }); - // L4: a launcher that starts succeeds, and the sentinel it advertises is a - // real, readable file — the page the browser is asked to open. describe("L4", () => { let r: Awaited<ReturnType<typeof openProfileWindow>>; diff --git a/test/profile/list-test.ts b/test/profile/list-test.ts index b4397e3..f1db39c 100644 --- a/test/profile/list-test.ts +++ b/test/profile/list-test.ts @@ -1,11 +1,3 @@ -/** - * Unit tests for profile enumeration — no browser required. - * - * Builds throwaway user-data-dirs on disk so both tiers (Local State and the - * Preferences scan) run against real files. - * - * Run: npm test - */ import { test, after, describe } from "node:test"; import assert from "node:assert/strict"; import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs"; @@ -31,7 +23,6 @@ describe("profile enumeration", () => { for (const root of roots) rmSync(root, { recursive: true, force: true }); }); - // L1: tier 1 — names, emails, ordering, last-used marker const makeL1Udd = (): string => { const udd = makeUdd(); writeLocalState(udd, { @@ -73,7 +64,6 @@ describe("profile enumeration", () => { assert.equal(profiles[0]?.lastUsed, false); }); - // L2: profile with no signed-in account falls back to the directory const makeL2Udd = (): string => { const udd = makeUdd(); writeLocalState(udd, { profile: { info_cache: { "Profile 3": { name: "Work" } } } }); @@ -90,7 +80,6 @@ describe("profile enumeration", () => { assert.equal(profiles[0]?.email, undefined); }); - // L3: gaia_name backfills a missing name; ephemeral profiles are skipped const makeL3Udd = (): string => { const udd = makeUdd(); writeLocalState(udd, { @@ -115,7 +104,6 @@ describe("profile enumeration", () => { assert.equal(profiles[0]?.label, "Aman Kumar (gaia@example.com)"); }); - // L4: unlisted profiles are appended alphabetically after profiles_order test("L4: ordered entries first, remainder alphabetical", async () => { const udd = makeUdd(); writeLocalState(udd, { @@ -132,7 +120,6 @@ describe("profile enumeration", () => { assert.equal(profiles.map((p) => p.dir).join(","), "Profile 9,Default,Profile 3"); }); - // L5: corrupt Local State falls through to the Preferences scan const makeL5Udd = (): string => { const udd = makeUdd(); writeLocalState(udd, "{ this is not json"); @@ -140,7 +127,7 @@ describe("profile enumeration", () => { profile: { name: "Fallback Name" }, account_info: [{ email: "fallback@example.com" }], }); - writeProfileDir(udd, "Crash Reports"); // no Preferences → not a profile + writeProfileDir(udd, "Crash Reports"); return udd; }; @@ -154,7 +141,6 @@ describe("profile enumeration", () => { assert.equal(profiles[0]?.label, "Fallback Name (fallback@example.com)"); }); - // L6: missing info_cache also falls through to tier 2 test("L6: missing info_cache → Preferences scan", async () => { const udd = makeUdd(); writeLocalState(udd, { profile: { last_used: "Default" } }); @@ -163,13 +149,11 @@ describe("profile enumeration", () => { assert.equal(profiles[0]?.label, "Tier Two (Profile 1)"); }); - // L7: nothing readable → empty list, never a throw test("L7: unreadable user-data-dir yields an empty list", async () => { const profiles = await listProfiles(join(tmpdir(), "pi-profile-does-not-exist-xyz")); assert.equal(profiles.length, 0); }); - // L8: label formatting is total test("L8: email wins the brackets", () => { assert.equal(formatProfileLabel("A", "a@b.c", "Default"), "A (a@b.c)"); }); diff --git a/test/profile/paths-test.ts b/test/profile/paths-test.ts index feaf7ae..1278446 100644 --- a/test/profile/paths-test.ts +++ b/test/profile/paths-test.ts @@ -1,17 +1,8 @@ -/** - * Unit tests for path resolution — runs on Linux, macOS, and Windows in CI. - * - * Only the branch for the host platform can be exercised, so each assertion is - * guarded by process.platform; the CI matrix is what gives all three coverage. - * - * Run: npm test - */ import { test, describe } from "node:test"; import assert from "node:assert/strict"; import { homedir } from "node:os"; import { join } from "node:path"; -/** Re-import with a fresh module identity so env changes are picked up. */ const freshImport = async (): Promise<typeof import("../../src/profile/paths")> => import(`../../src/profile/paths?cache=${Math.random()}`); @@ -28,7 +19,6 @@ const withEnv = async (key: string, value: string | undefined, fn: () => Promise }; describe("path resolution", () => { - // A1: agent dir default and override test("A1: default agent dir is ~/.pi/agent", async () => { await withEnv("PI_CODING_AGENT_DIR", undefined, async () => { const { agentDir } = await freshImport(); @@ -43,8 +33,6 @@ describe("path resolution", () => { }); }); - // pi's own expandTildePath only understands "~/" — never "~\" — so the agent - // dir must resolve identically or the pin lands where pi does not look. test("A1: '~/' in the agent-dir override expands like pi", async () => { await withEnv("PI_CODING_AGENT_DIR", "~/custom-agent", async () => { assert.equal((await freshImport()).agentDir(), `${homedir()}/custom-agent`); @@ -57,7 +45,6 @@ describe("path resolution", () => { }); }); - // A2: platform candidate list test("A2: candidates are non-empty on this platform", async () => { await withEnv("CHROME_USER_DATA_DIR", undefined, async () => { const dirs = (await freshImport()).userDataDirCandidates(); @@ -133,7 +120,6 @@ describe("path resolution", () => { }); }); - // A3: %LOCALAPPDATA% redirection is honoured (Windows-only behaviour) test("A3 win: redirected LOCALAPPDATA is used", { skip: process.platform !== "win32" }, async () => { await withEnv("LOCALAPPDATA", "D:\\Redirected\\Local", async () => { const dirs = (await freshImport()).userDataDirCandidates(); @@ -141,8 +127,6 @@ describe("path resolution", () => { }); }); - // A4: $CHROME_USER_DATA_DIR override leads the list. This value is ours to - // interpret, so both tilde separators are accepted. test("A4: env override is first and tilde-expanded", async () => { await withEnv("CHROME_USER_DATA_DIR", join("~", "my-chrome-data"), async () => { const dirs = (await freshImport()).userDataDirCandidates(); @@ -157,7 +141,6 @@ describe("path resolution", () => { }); }); - // A5: browser naming test("A5: Chrome recognised", async () => { const { browserNameForUserDataDir } = await freshImport(); assert.equal(browserNameForUserDataDir("/home/u/.config/google-chrome"), "Chrome"); diff --git a/test/profile/store-test.ts b/test/profile/store-test.ts index 8b0d85c..89afd00 100644 --- a/test/profile/store-test.ts +++ b/test/profile/store-test.ts @@ -1,11 +1,3 @@ -/** - * Unit tests for the profile pin store — no browser required. - * - * Redirects pi's agent dir via $PI_CODING_AGENT_DIR so the real - * ~/.pi/agent/browser-harness.json is never touched. - * - * Run: npm test - */ import { test, before, after, describe } from "node:test"; import assert from "node:assert/strict"; import { mkdtempSync, mkdirSync, readdirSync, rmSync, writeFileSync } from "node:fs"; @@ -114,7 +106,6 @@ describe("profile pin store", () => { const blocked = join(sandbox, "blocked"); mkdirSync(blocked, { recursive: true }); writeFileSync(join(blocked, "browser-harness.json"), "{}", "utf8"); - // Point the agent dir at a FILE — mkdir/write must fail cleanly. process.env["PI_CODING_AGENT_DIR"] = join(blocked, "browser-harness.json"); const { writePin: writeAgain } = await import(`../../src/profile/store?nocache=${Date.now()}`); const written = await writeAgain(pin); |
