From e1e2b8832d6658d4fa8191ed2b3fbd91d5eb8f43 Mon Sep 17 00:00:00 2001 From: Christian Findlay <16697547+MelbourneDeveloper@users.noreply.github.com> Date: Sat, 30 May 2026 10:13:45 +1000 Subject: [PATCH 1/2] refactor: wire EXTENSION_ID/ENV_VARS/OUTPUT_CHANNEL_NAME through call sites main defined these constants in src/constants.ts but the call sites still hardcoded the derived strings. Source them from constants so the brand name lives in exactly one place: - logger.ts: DIFFR_LOG_LEVEL literal -> ENV_VARS.logLevel - runTests.ts: DIFFR_E2E + "nimblesite.diffr" -> ENV_VARS.e2e + EXTENSION_ID - flow.ts: "Output -> Diffr" -> OUTPUT_CHANNEL_NAME - {activation,commands,contentProvider}.test.ts: drop local EXTENSION_ID literal, import from constants Co-Authored-By: Claude Opus 4.8 --- src/commands/flow.ts | 4 ++-- src/logger.ts | 6 ++---- src/test/runTests.ts | 5 +++-- src/test/suite/activation.test.ts | 3 +-- src/test/suite/commands.test.ts | 4 +--- src/test/suite/contentProvider.test.ts | 3 +-- 6 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/commands/flow.ts b/src/commands/flow.ts index 077208e..bf08199 100644 --- a/src/commands/flow.ts +++ b/src/commands/flow.ts @@ -1,5 +1,5 @@ import * as vscode from "vscode"; -import { LOG_EVENTS, REF_TYPES, REV_KINDS, SIDE_B_KINDS, TITLE_PREFIX, UI_TEXT } from "../constants"; +import { LOG_EVENTS, OUTPUT_CHANNEL_NAME, REF_TYPES, REV_KINDS, SIDE_B_KINDS, TITLE_PREFIX, UI_TEXT } from "../constants"; import type { GitRepo } from "../git/GitRepo"; import type { GitRunner } from "../git/GitRunner"; import type { GitApi } from "../vscodeGitApi"; @@ -29,7 +29,7 @@ export const reportGitError = ({ output, op, e }: { output: vscode.OutputChannel if (e.stderr !== undefined && e.stderr !== "") { output.appendLine(e.stderr); } - void vscode.window.showErrorMessage(`${TITLE_PREFIX} ${op} failed (see Output → Diffr).`); + void vscode.window.showErrorMessage(`${TITLE_PREFIX} ${op} failed (see Output → ${OUTPUT_CHANNEL_NAME}).`); }; export const resolveSideB = async ({ diff --git a/src/logger.ts b/src/logger.ts index c24d509..24cbe7f 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -1,7 +1,5 @@ import pino, { type Logger as PinoLogger, type Level, multistream } from "pino"; -import { LOG_LEVELS } from "./constants"; - -const ENV_LOG_LEVEL_VAR = "DIFFR_LOG_LEVEL"; +import { ENV_VARS, LOG_LEVELS } from "./constants"; export interface Logger { trace: (fields: object, msg?: string) => void; @@ -18,7 +16,7 @@ export interface LogStreamEntry { const streams: LogStreamEntry[] = [{ stream: process.stdout }]; -const envLevel = process.env[ENV_LOG_LEVEL_VAR]; +const envLevel = process.env[ENV_VARS.logLevel]; const buildPino = (): PinoLogger => pino( diff --git a/src/test/runTests.ts b/src/test/runTests.ts index a665d3b..b0d4208 100644 --- a/src/test/runTests.ts +++ b/src/test/runTests.ts @@ -2,6 +2,7 @@ import * as path from "node:path"; import { spawnSync } from "node:child_process"; import { existsSync } from "node:fs"; import { runTests } from "@vscode/test-electron"; +import { ENV_VARS, EXTENSION_ID } from "../constants"; const repoRoot = path.resolve(__dirname, "..", ".."); const extensionDevelopmentPath = repoRoot; @@ -30,7 +31,7 @@ const main = async (): Promise => { } const coverageDir = process.env["NODE_V8_COVERAGE"]; const extensionTestsEnv: Record = { - DIFFR_E2E: "1", + [ENV_VARS.e2e]: "1", }; if (coverageDir !== undefined && coverageDir !== "") { extensionTestsEnv["NODE_V8_COVERAGE"] = coverageDir; @@ -39,7 +40,7 @@ const main = async (): Promise => { extensionDevelopmentPath, extensionTestsPath, extensionTestsEnv, - launchArgs: [workspacePath, "--disable-telemetry", "--enable-proposed-api", "nimblesite.diffr"], + launchArgs: [workspacePath, "--disable-telemetry", "--enable-proposed-api", EXTENSION_ID], }); }; diff --git a/src/test/suite/activation.test.ts b/src/test/suite/activation.test.ts index 895a4ba..e006461 100644 --- a/src/test/suite/activation.test.ts +++ b/src/test/suite/activation.test.ts @@ -1,9 +1,8 @@ import { strict as assert } from "node:assert"; import * as vscode from "vscode"; -import { COMMAND_IDS, OUTPUT_CHANNEL_NAME } from "../../constants"; +import { COMMAND_IDS, EXTENSION_ID, OUTPUT_CHANNEL_NAME } from "../../constants"; import { tick } from "./helpers"; -const EXTENSION_ID = "nimblesite.diffr"; const TICK_MS = 20; const ALL_COMMAND_IDS: readonly string[] = Object.values(COMMAND_IDS); diff --git a/src/test/suite/commands.test.ts b/src/test/suite/commands.test.ts index 2974520..0aef5c1 100644 --- a/src/test/suite/commands.test.ts +++ b/src/test/suite/commands.test.ts @@ -1,6 +1,6 @@ import { strict as assert } from "node:assert"; import * as vscode from "vscode"; -import { COMMAND_IDS } from "../../constants"; +import { COMMAND_IDS, EXTENSION_ID } from "../../constants"; import { accept, allDiffTabs, @@ -16,8 +16,6 @@ import { workspaceRoot, } from "./helpers"; -const EXTENSION_ID = "nimblesite.diffr"; - const ensureActivated = async (): Promise => { const ext = vscode.extensions.getExtension(EXTENSION_ID); if (ext !== undefined && !ext.isActive) { diff --git a/src/test/suite/contentProvider.test.ts b/src/test/suite/contentProvider.test.ts index 0a6bb21..3abfd18 100644 --- a/src/test/suite/contentProvider.test.ts +++ b/src/test/suite/contentProvider.test.ts @@ -1,9 +1,8 @@ import { strict as assert } from "node:assert"; import * as vscode from "vscode"; +import { EXTENSION_ID } from "../../constants"; import { readSeedShas, waitForRepoReady } from "./helpers"; -const EXTENSION_ID = "nimblesite.diffr"; - const readDiffr = async (uriString: string): Promise => { const doc = await vscode.workspace.openTextDocument(vscode.Uri.parse(uriString)); return doc.getText(); From ae475f015ec56ef51c74a43e33b4185d0641b786 Mon Sep 17 00:00:00 2001 From: Christian Findlay <16697547+MelbourneDeveloper@users.noreply.github.com> Date: Sat, 30 May 2026 10:45:50 +1000 Subject: [PATCH 2/2] style: wrap long constants import in flow.ts (prettier) CI runs 'make fmt CHECK=1' before lint/test/build; the extended import exceeded prettier's print width. Reflow to satisfy the format check. Co-Authored-By: Claude Opus 4.8 --- src/commands/flow.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/commands/flow.ts b/src/commands/flow.ts index bf08199..e692be2 100644 --- a/src/commands/flow.ts +++ b/src/commands/flow.ts @@ -1,5 +1,13 @@ import * as vscode from "vscode"; -import { LOG_EVENTS, OUTPUT_CHANNEL_NAME, REF_TYPES, REV_KINDS, SIDE_B_KINDS, TITLE_PREFIX, UI_TEXT } from "../constants"; +import { + LOG_EVENTS, + OUTPUT_CHANNEL_NAME, + REF_TYPES, + REV_KINDS, + SIDE_B_KINDS, + TITLE_PREFIX, + UI_TEXT, +} from "../constants"; import type { GitRepo } from "../git/GitRepo"; import type { GitRunner } from "../git/GitRunner"; import type { GitApi } from "../vscodeGitApi";