From a356dc266130d3562f5f2e802973287a0737f3c6 Mon Sep 17 00:00:00 2001 From: mohammed naji Date: Sat, 25 Jul 2026 03:28:15 +0400 Subject: [PATCH 1/5] test(windows): expose catalog ACL probe boundary --- ...sole-dashboard-application-service.test.ts | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/tests/console-dashboard-application-service.test.ts b/tests/console-dashboard-application-service.test.ts index f3928cf4..b9f8c54c 100644 --- a/tests/console-dashboard-application-service.test.ts +++ b/tests/console-dashboard-application-service.test.ts @@ -1,6 +1,6 @@ import { chmod, link, mkdir, mkdtemp, readFile, rm, symlink, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; -import { join } from "node:path"; +import { basename, join } from "node:path"; import { afterEach, describe, expect, it } from "vitest"; import { discoverConsoleConfigCatalog } from "../src/console/console-config-catalog.js"; import { ConsoleDashboardApplicationService } from "../src/console/console-dashboard-application-service.js"; @@ -65,6 +65,48 @@ describe("Console dashboard application service", () => { await expect(verifyWindowsConfigPathSecurity(configPath, "file")).resolves.toBe(true); }); + it.runIf(process.platform === "win32")("reports the production ACL result for every catalog candidate", async () => { + const root = await mkdtemp(join(tmpdir(), "miftah-console-dashboard-acl-catalog-")); + temporaryDirectories.push(root); + const directory = await createPrivateConsoleDirectory(root); + await writeConfig(join(directory, "gsc.json"), { + version: "3", + name: "gsc", + defaultProfile: "default", + upstream: { transport: "stdio", command: "uvx", args: ["mcp-search-console@0.3.2"] }, + profiles: { default: {} } + }); + await writeConfig(join(directory, "sentry.json"), { + version: "3", + name: "sentry", + defaultProfile: "default", + upstream: { transport: "stdio", command: "npx", args: ["--yes", "@sentry/mcp-server@0.36.0"] }, + profiles: { default: {} } + }); + + const aclProbes: Array<{ candidate: string; kind: "file" | "directory"; trusted: boolean }> = []; + const catalog = await discoverConsoleConfigCatalog({ + configDirectory: directory, + windowsAclVerifier: async (path, kind) => { + const trusted = await verifyWindowsConfigPathSecurity(path, kind).catch(() => false); + aclProbes.push({ candidate: kind === "directory" ? "directory" : basename(path), kind, trusted }); + return trusted; + } + }); + + expect({ + aclProbes, + configurationNames: catalog.configurations.map((configuration) => configuration.metadata.name) + }).toEqual({ + aclProbes: [ + { candidate: "directory", kind: "directory", trusted: true }, + { candidate: "gsc.json", kind: "file", trusted: true }, + { candidate: "sentry.json", kind: "file", trusted: true } + ], + configurationNames: ["gsc", "sentry"] + }); + }); + it("discovers safe standard-directory configurations without exposing source details", async () => { const root = await mkdtemp(join(tmpdir(), "miftah-console-dashboard-")); temporaryDirectories.push(root); From d10736ae28cc374a531362e9f42d48b334afc11b Mon Sep 17 00:00:00 2001 From: mohammed naji Date: Sat, 25 Jul 2026 03:42:44 +0400 Subject: [PATCH 2/5] test(windows): trace dashboard catalog verifier --- ...sole-dashboard-application-service.test.ts | 113 ++++++++++-------- 1 file changed, 65 insertions(+), 48 deletions(-) diff --git a/tests/console-dashboard-application-service.test.ts b/tests/console-dashboard-application-service.test.ts index b9f8c54c..c935a34d 100644 --- a/tests/console-dashboard-application-service.test.ts +++ b/tests/console-dashboard-application-service.test.ts @@ -1,7 +1,7 @@ import { chmod, link, mkdir, mkdtemp, readFile, rm, symlink, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import { basename, join } from "node:path"; -import { afterEach, describe, expect, it } from "vitest"; +import { afterEach, describe, expect, it, vi } from "vitest"; import { discoverConsoleConfigCatalog } from "../src/console/console-config-catalog.js"; import { ConsoleDashboardApplicationService } from "../src/console/console-dashboard-application-service.js"; import { buildPresetConfig } from "../src/config/presets.js"; @@ -13,6 +13,22 @@ import { import { startOAuthCompatibilityProbe } from "./helpers/fake-remote-upstream.js"; const temporaryDirectories: string[] = []; +const catalogAclDiagnostic = vi.hoisted(() => ({ + verifier: undefined as undefined | ((path: string, kind: "file" | "directory") => Promise) +})); + +vi.mock("../src/console/console-config-catalog.js", async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + discoverConsoleConfigCatalog: (options: Parameters[0]) => { + const verifier = catalogAclDiagnostic.verifier; + return actual.discoverConsoleConfigCatalog( + verifier === undefined ? options : { ...options, windowsAclVerifier: verifier } + ); + } + }; +}); function supportedKnownConnectorOptions(): { readonly preset: string; @@ -37,6 +53,7 @@ function importableClientEntry(): { readonly command: string; readonly args: rea } afterEach(async () => { + catalogAclDiagnostic.verifier = undefined; await Promise.all(temporaryDirectories.splice(0).map((directory) => rm(directory, { recursive: true, force: true }))); }); @@ -48,6 +65,18 @@ async function writeCatalogFixture(path: string, value: unknown): Promise await writeFile(path, `${JSON.stringify(value, null, 2)}\n`, { mode: 0o600 }); } +function catalogFixtureLabel(path: string, kind: "file" | "directory"): "directory" | "gsc" | "sentry" | "other" { + if (kind === "directory") return "directory"; + switch (basename(path).toLocaleLowerCase("en-US")) { + case "gsc.json": + return "gsc"; + case "sentry.json": + return "sentry"; + default: + return "other"; + } +} + describe("Console dashboard application service", () => { it.runIf(process.platform === "win32")("creates fixture files that pass the production Windows ACL verifier", async () => { const root = await mkdtemp(join(tmpdir(), "miftah-console-dashboard-acl-")); @@ -65,48 +94,6 @@ describe("Console dashboard application service", () => { await expect(verifyWindowsConfigPathSecurity(configPath, "file")).resolves.toBe(true); }); - it.runIf(process.platform === "win32")("reports the production ACL result for every catalog candidate", async () => { - const root = await mkdtemp(join(tmpdir(), "miftah-console-dashboard-acl-catalog-")); - temporaryDirectories.push(root); - const directory = await createPrivateConsoleDirectory(root); - await writeConfig(join(directory, "gsc.json"), { - version: "3", - name: "gsc", - defaultProfile: "default", - upstream: { transport: "stdio", command: "uvx", args: ["mcp-search-console@0.3.2"] }, - profiles: { default: {} } - }); - await writeConfig(join(directory, "sentry.json"), { - version: "3", - name: "sentry", - defaultProfile: "default", - upstream: { transport: "stdio", command: "npx", args: ["--yes", "@sentry/mcp-server@0.36.0"] }, - profiles: { default: {} } - }); - - const aclProbes: Array<{ candidate: string; kind: "file" | "directory"; trusted: boolean }> = []; - const catalog = await discoverConsoleConfigCatalog({ - configDirectory: directory, - windowsAclVerifier: async (path, kind) => { - const trusted = await verifyWindowsConfigPathSecurity(path, kind).catch(() => false); - aclProbes.push({ candidate: kind === "directory" ? "directory" : basename(path), kind, trusted }); - return trusted; - } - }); - - expect({ - aclProbes, - configurationNames: catalog.configurations.map((configuration) => configuration.metadata.name) - }).toEqual({ - aclProbes: [ - { candidate: "directory", kind: "directory", trusted: true }, - { candidate: "gsc.json", kind: "file", trusted: true }, - { candidate: "sentry.json", kind: "file", trusted: true } - ], - configurationNames: ["gsc", "sentry"] - }); - }); - it("discovers safe standard-directory configurations without exposing source details", async () => { const root = await mkdtemp(join(tmpdir(), "miftah-console-dashboard-")); temporaryDirectories.push(root); @@ -133,11 +120,26 @@ describe("Console dashboard application service", () => { profiles: { work: {} } }); - // Keep the production-only ACL boundary explicit on Windows: catalog - // discovery deliberately suppresses individual untrusted candidates. + // Instrument the exact dashboard catalog invocation on Windows. The mock + // delegates to the real catalog and real verifier; it only records safe + // fixture labels so a fail-closed omission identifies its boundary. + const aclProbes: Array<{ + candidate: "directory" | "gsc" | "sentry" | "other"; + kind: "file" | "directory"; + outcome: "trusted" | "untrusted" | "error"; + }> = []; if (process.platform === "win32") { - await expect(verifyWindowsConfigPathSecurity(gscPath, "file")).resolves.toBe(true); - await expect(verifyWindowsConfigPathSecurity(sentryPath, "file")).resolves.toBe(true); + catalogAclDiagnostic.verifier = async (path, kind) => { + const candidate = catalogFixtureLabel(path, kind); + try { + const trusted = await verifyWindowsConfigPathSecurity(path, kind); + aclProbes.push({ candidate, kind, outcome: trusted ? "trusted" : "untrusted" }); + return trusted; + } catch (error) { + aclProbes.push({ candidate, kind, outcome: "error" }); + throw error; + } + }; } const service = new ConsoleDashboardApplicationService({ @@ -146,7 +148,22 @@ describe("Console dashboard application service", () => { launcher: { command: process.execPath, args: ["serve"] } }); - const initial = await service.configMetadata(); + const initial = await service.configMetadata().finally(() => { + catalogAclDiagnostic.verifier = undefined; + }); + if (process.platform === "win32") { + expect({ + aclProbeSummary: [...aclProbes].sort((left, right) => left.candidate.localeCompare(right.candidate)), + serviceConfigurationNames: initial.catalog?.configurations.map((configuration) => configuration.name) + }).toEqual({ + aclProbeSummary: [ + { candidate: "directory", kind: "directory", outcome: "trusted" }, + { candidate: "gsc", kind: "file", outcome: "trusted" }, + { candidate: "sentry", kind: "file", outcome: "trusted" } + ], + serviceConfigurationNames: ["gsc", "sentry"] + }); + } expect(initial).toMatchObject({ initialized: false, restartRequiredForExistingClients: true, From db0c5b42b565c187d7f158f94119b12b140a9fbe Mon Sep 17 00:00:00 2001 From: mohammed naji Date: Sat, 25 Jul 2026 03:54:18 +0400 Subject: [PATCH 3/5] test(windows): diagnose catalog file identity --- ...sole-dashboard-application-service.test.ts | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/console-dashboard-application-service.test.ts b/tests/console-dashboard-application-service.test.ts index c935a34d..a2ab62ee 100644 --- a/tests/console-dashboard-application-service.test.ts +++ b/tests/console-dashboard-application-service.test.ts @@ -1,4 +1,4 @@ -import { chmod, link, mkdir, mkdtemp, readFile, rm, symlink, writeFile } from "node:fs/promises"; +import { chmod, link, lstat, mkdir, mkdtemp, readFile, rm, symlink, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import { basename, join } from "node:path"; import { afterEach, describe, expect, it, vi } from "vitest"; @@ -77,6 +77,22 @@ function catalogFixtureLabel(path: string, kind: "file" | "directory"): "directo } } +async function compareFileIdentities(first: string, second: string): Promise<{ + readonly bigintIdentity: "same" | "different"; + readonly numberIdentity: "same" | "different"; +}> { + const [firstNumber, secondNumber, firstBigInt, secondBigInt] = await Promise.all([ + lstat(first), + lstat(second), + lstat(first, { bigint: true }), + lstat(second, { bigint: true }) + ]); + return { + numberIdentity: firstNumber.dev === secondNumber.dev && firstNumber.ino === secondNumber.ino ? "same" : "different", + bigintIdentity: firstBigInt.dev === secondBigInt.dev && firstBigInt.ino === secondBigInt.ino ? "same" : "different" + }; +} + describe("Console dashboard application service", () => { it.runIf(process.platform === "win32")("creates fixture files that pass the production Windows ACL verifier", async () => { const root = await mkdtemp(join(tmpdir(), "miftah-console-dashboard-acl-")); @@ -120,6 +136,10 @@ describe("Console dashboard application service", () => { profiles: { work: {} } }); + const fixtureIdentity = process.platform === "win32" + ? await compareFileIdentities(gscPath, sentryPath) + : undefined; + // Instrument the exact dashboard catalog invocation on Windows. The mock // delegates to the real catalog and real verifier; it only records safe // fixture labels so a fail-closed omission identifies its boundary. @@ -154,6 +174,7 @@ describe("Console dashboard application service", () => { if (process.platform === "win32") { expect({ aclProbeSummary: [...aclProbes].sort((left, right) => left.candidate.localeCompare(right.candidate)), + fixtureIdentity, serviceConfigurationNames: initial.catalog?.configurations.map((configuration) => configuration.name) }).toEqual({ aclProbeSummary: [ @@ -161,6 +182,7 @@ describe("Console dashboard application service", () => { { candidate: "gsc", kind: "file", outcome: "trusted" }, { candidate: "sentry", kind: "file", outcome: "trusted" } ], + fixtureIdentity: { bigintIdentity: "different", numberIdentity: "different" }, serviceConfigurationNames: ["gsc", "sentry"] }); } From 9f3caca22ea4718077f4333b293c92d0009788ca Mon Sep 17 00:00:00 2001 From: mohammed naji Date: Sat, 25 Jul 2026 04:06:58 +0400 Subject: [PATCH 4/5] test(windows): trace catalog post-ACL stages --- src/console/console-config-catalog.ts | 157 ++++++++++++++++-- ...sole-dashboard-application-service.test.ts | 82 ++++++++- 2 files changed, 220 insertions(+), 19 deletions(-) diff --git a/src/console/console-config-catalog.ts b/src/console/console-config-catalog.ts index 0da31cbe..9bd7fbb7 100644 --- a/src/console/console-config-catalog.ts +++ b/src/console/console-config-catalog.ts @@ -26,10 +26,50 @@ export interface ConsoleConfigCatalogDiscoveryOptions { readonly ownerUid?: number; /** Test seam for Windows DACL verification. */ readonly windowsAclVerifier?: WindowsConfigAclVerifier; + /** Test-only opaque diagnostic observer for one catalog invocation. */ + readonly candidateStageObserver?: ConsoleConfigCatalogCandidateStageObserver; } export type WindowsConfigAclVerifier = (path: string, kind: "file" | "directory") => Promise; +/** Opaque test-only stages for diagnosing a rejected catalog candidate. */ +export type ConsoleConfigCatalogCandidateStage = + | "acl" + | "open" + | "opened-validation" + | "read" + | "after-read-validation" + | "decode" + | "parse" + | "migration-source" + | "close" + | "dedupe" + | "metadata" + | "accepted" + | "candidate"; + +/** A stage outcome never carries a path, filesystem identity, config value, or error detail. */ +export type ConsoleConfigCatalogCandidateOutcome = "success" | "rejected" | "duplicate" | "error"; + +export interface ConsoleConfigCatalogCandidateStageEvent { + /** Stable only within one discovery invocation; never derived from a pathname. */ + readonly candidateIndex: number; + readonly stage: ConsoleConfigCatalogCandidateStage; + readonly outcome: ConsoleConfigCatalogCandidateOutcome; +} + +/** Test-only observer for opaque candidate diagnostics. */ +export type ConsoleConfigCatalogCandidateStageObserver = (event: ConsoleConfigCatalogCandidateStageEvent) => void; + +function observeCandidateStage( + observer: ConsoleConfigCatalogCandidateStageObserver | undefined, + candidateIndex: number, + stage: ConsoleConfigCatalogCandidateStage, + outcome: ConsoleConfigCatalogCandidateOutcome +): void { + observer?.({ candidateIndex, stage, outcome }); +} + export interface DiscoveredConsoleConfiguration { /** Canonical local path retained only in the in-process registry. */ readonly path: string; @@ -137,12 +177,28 @@ async function trustedDirectory( return canonical; } +async function closeTrustedConfigurationHandle( + handle: Awaited>, + candidateIndex: number, + candidateStageObserver: ConsoleConfigCatalogCandidateStageObserver | undefined +): Promise { + try { + await handle.close(); + } catch (error) { + observeCandidateStage(candidateStageObserver, candidateIndex, "close", "error"); + throw error; + } + observeCandidateStage(candidateStageObserver, candidateIndex, "close", "success"); +} + async function readTrustedConfiguration( path: string, directory: string, ownerUid: number | undefined, platform: NodeJS.Platform, - windowsAclVerifier: WindowsConfigAclVerifier + windowsAclVerifier: WindowsConfigAclVerifier, + candidateIndex: number, + candidateStageObserver: ConsoleConfigCatalogCandidateStageObserver | undefined ): Promise<{ readonly path: string; readonly identity: string; @@ -154,40 +210,97 @@ async function readTrustedConfiguration( if (!isWithin(directory, canonical)) return undefined; const resolved = await stat(canonical); if (!isTrustedFile(resolved, ownerUid, platform) || !sameEntry(observed, resolved)) return undefined; - if (!(await hasTrustedWindowsAcl(canonical, "file", platform, windowsAclVerifier))) return undefined; + if (!(await hasTrustedWindowsAcl(canonical, "file", platform, windowsAclVerifier))) { + observeCandidateStage(candidateStageObserver, candidateIndex, "acl", "rejected"); + return undefined; + } + observeCandidateStage(candidateStageObserver, candidateIndex, "acl", "success"); - const handle = await open(canonical, readOnlyFlags); + let handle: Awaited>; try { - const opened = await handle.stat(); + handle = await open(canonical, readOnlyFlags); + } catch (error) { + observeCandidateStage(candidateStageObserver, candidateIndex, "open", "error"); + throw error; + } + observeCandidateStage(candidateStageObserver, candidateIndex, "open", "success"); + try { + let opened: Stats; + try { + opened = await handle.stat(); + } catch (error) { + observeCandidateStage(candidateStageObserver, candidateIndex, "opened-validation", "error"); + throw error; + } if ( !isTrustedFile(opened, ownerUid, platform) || !sameEntry(observed, opened) || opened.size > maximumConfigurationBytes ) { + observeCandidateStage(candidateStageObserver, candidateIndex, "opened-validation", "rejected"); return undefined; } - const content = await handle.readFile(); - const afterRead = await handle.stat(); + observeCandidateStage(candidateStageObserver, candidateIndex, "opened-validation", "success"); + let content: Buffer; + try { + content = await handle.readFile(); + } catch (error) { + observeCandidateStage(candidateStageObserver, candidateIndex, "read", "error"); + throw error; + } + observeCandidateStage(candidateStageObserver, candidateIndex, "read", "success"); + let afterRead: Stats; + try { + afterRead = await handle.stat(); + } catch (error) { + observeCandidateStage(candidateStageObserver, candidateIndex, "after-read-validation", "error"); + throw error; + } if ( !isTrustedFile(afterRead, ownerUid, platform) || !sameEntry(observed, afterRead) || afterRead.size !== opened.size || content.byteLength > maximumConfigurationBytes ) { + observeCandidateStage(candidateStageObserver, candidateIndex, "after-read-validation", "rejected"); return undefined; } - const text = new TextDecoder("utf-8", { fatal: true }).decode(content); + observeCandidateStage(candidateStageObserver, candidateIndex, "after-read-validation", "success"); + let text: string; + try { + text = new TextDecoder("utf-8", { fatal: true }).decode(content); + } catch (error) { + observeCandidateStage(candidateStageObserver, candidateIndex, "decode", "error"); + throw error; + } + observeCandidateStage(candidateStageObserver, candidateIndex, "decode", "success"); + let config: ReturnType; + try { + config = loadConfigFromText(text, canonical); + } catch (error) { + observeCandidateStage(candidateStageObserver, candidateIndex, "parse", "error"); + throw error; + } + observeCandidateStage(candidateStageObserver, candidateIndex, "parse", "success"); + let migrationSource: ReturnType; + try { + migrationSource = createConfigMigrationSource(content, afterRead); + } catch (error) { + observeCandidateStage(candidateStageObserver, candidateIndex, "migration-source", "error"); + throw error; + } + observeCandidateStage(candidateStageObserver, candidateIndex, "migration-source", "success"); return { path: canonical, identity: `${opened.dev}:${opened.ino}`, trustedConfiguration: { - config: loadConfigFromText(text, canonical), + config, contentDigest: createHash("sha256").update(content).digest("base64url"), - migrationSource: createConfigMigrationSource(content, afterRead) + migrationSource } }; } finally { - await handle.close(); + await closeTrustedConfigurationHandle(handle, candidateIndex, candidateStageObserver); } } @@ -201,6 +314,7 @@ export async function discoverConsoleConfigCatalog( const platform = options.platform ?? process.platform; const ownerUid = options.ownerUid ?? defaultOwnerUid(platform); const windowsAclVerifier = options.windowsAclVerifier ?? verifyWindowsConfigPathSecurity; + const candidateStageObserver = options.candidateStageObserver; let directory: string | undefined; try { directory = await trustedDirectory(resolve(options.configDirectory), ownerUid, platform, windowsAclVerifier); @@ -229,19 +343,32 @@ export async function discoverConsoleConfigCatalog( const identities = new Set(); const configurations: DiscoveredConsoleConfiguration[] = []; - for (const name of names) { + for (const [candidateIndex, name] of names.entries()) { try { const discovered = await readTrustedConfiguration( join(directory, name), directory, ownerUid, platform, - windowsAclVerifier + windowsAclVerifier, + candidateIndex, + candidateStageObserver ); if (discovered === undefined) continue; - if (identities.has(discovered.identity)) continue; + if (identities.has(discovered.identity)) { + observeCandidateStage(candidateStageObserver, candidateIndex, "dedupe", "duplicate"); + continue; + } identities.add(discovered.identity); - const summary = consoleInitializedConfigMetadata(discovered.trustedConfiguration.config); + observeCandidateStage(candidateStageObserver, candidateIndex, "dedupe", "success"); + let summary: ReturnType; + try { + summary = consoleInitializedConfigMetadata(discovered.trustedConfiguration.config); + } catch (error) { + observeCandidateStage(candidateStageObserver, candidateIndex, "metadata", "error"); + throw error; + } + observeCandidateStage(candidateStageObserver, candidateIndex, "metadata", "success"); const configuration: DiscoveredConsoleConfiguration = { path: discovered.path, initializedMetadata: summary, @@ -262,7 +389,9 @@ export async function discoverConsoleConfigCatalog( }; trustedConfigurations.set(configuration, discovered.trustedConfiguration); configurations.push(configuration); + observeCandidateStage(candidateStageObserver, candidateIndex, "accepted", "success"); } catch { + observeCandidateStage(candidateStageObserver, candidateIndex, "candidate", "error"); // A malformed, raced, or untrusted candidate is never a Console entry. } } diff --git a/tests/console-dashboard-application-service.test.ts b/tests/console-dashboard-application-service.test.ts index a2ab62ee..72ee512c 100644 --- a/tests/console-dashboard-application-service.test.ts +++ b/tests/console-dashboard-application-service.test.ts @@ -2,7 +2,10 @@ import { chmod, link, lstat, mkdir, mkdtemp, readFile, rm, symlink, writeFile } import { tmpdir } from "node:os"; import { basename, join } from "node:path"; import { afterEach, describe, expect, it, vi } from "vitest"; -import { discoverConsoleConfigCatalog } from "../src/console/console-config-catalog.js"; +import { + discoverConsoleConfigCatalog, + type ConsoleConfigCatalogCandidateStageEvent +} from "../src/console/console-config-catalog.js"; import { ConsoleDashboardApplicationService } from "../src/console/console-dashboard-application-service.js"; import { buildPresetConfig } from "../src/config/presets.js"; import { verifyWindowsConfigPathSecurity } from "../src/cli/windows-config-acl.js"; @@ -16,6 +19,9 @@ const temporaryDirectories: string[] = []; const catalogAclDiagnostic = vi.hoisted(() => ({ verifier: undefined as undefined | ((path: string, kind: "file" | "directory") => Promise) })); +const catalogStageDiagnostic = vi.hoisted(() => ({ + observer: undefined as undefined | ((event: ConsoleConfigCatalogCandidateStageEvent) => void) +})); vi.mock("../src/console/console-config-catalog.js", async (importOriginal) => { const actual = await importOriginal(); @@ -23,9 +29,13 @@ vi.mock("../src/console/console-config-catalog.js", async (importOriginal) => { ...actual, discoverConsoleConfigCatalog: (options: Parameters[0]) => { const verifier = catalogAclDiagnostic.verifier; - return actual.discoverConsoleConfigCatalog( - verifier === undefined ? options : { ...options, windowsAclVerifier: verifier } - ); + const observer = catalogStageDiagnostic.observer; + const instrumentedOptions = { + ...options, + ...(verifier === undefined ? {} : { windowsAclVerifier: verifier }), + ...(observer === undefined ? {} : { candidateStageObserver: observer }) + }; + return actual.discoverConsoleConfigCatalog(instrumentedOptions); } }; }); @@ -54,6 +64,7 @@ function importableClientEntry(): { readonly command: string; readonly args: rea afterEach(async () => { catalogAclDiagnostic.verifier = undefined; + catalogStageDiagnostic.observer = undefined; await Promise.all(temporaryDirectories.splice(0).map((directory) => rm(directory, { recursive: true, force: true }))); }); @@ -93,6 +104,24 @@ async function compareFileIdentities(first: string, second: string): Promise<{ }; } +function catalogStageSummary( + events: readonly ConsoleConfigCatalogCandidateStageEvent[], + configurationNames: readonly string[] | undefined +): readonly { + readonly candidate: "gsc" | "sentry"; + readonly stages: readonly Omit[]; + readonly accepted: boolean; +}[] { + const candidates = ["gsc", "sentry"] as const; + return candidates.map((candidate, candidateIndex) => ({ + candidate, + stages: events + .filter((event) => event.candidateIndex === candidateIndex) + .map(({ stage, outcome }) => ({ stage, outcome })), + accepted: configurationNames?.includes(candidate) ?? false + })); +} + describe("Console dashboard application service", () => { it.runIf(process.platform === "win32")("creates fixture files that pass the production Windows ACL verifier", async () => { const root = await mkdtemp(join(tmpdir(), "miftah-console-dashboard-acl-")); @@ -139,6 +168,10 @@ describe("Console dashboard application service", () => { const fixtureIdentity = process.platform === "win32" ? await compareFileIdentities(gscPath, sentryPath) : undefined; + const candidateStages: ConsoleConfigCatalogCandidateStageEvent[] = []; + catalogStageDiagnostic.observer = (event) => { + candidateStages.push(event); + }; // Instrument the exact dashboard catalog invocation on Windows. The mock // delegates to the real catalog and real verifier; it only records safe @@ -170,7 +203,46 @@ describe("Console dashboard application service", () => { const initial = await service.configMetadata().finally(() => { catalogAclDiagnostic.verifier = undefined; - }); + catalogStageDiagnostic.observer = undefined; + }); + expect(catalogStageSummary(candidateStages, initial.catalog?.configurations.map((configuration) => configuration.name))).toEqual([ + { + candidate: "gsc", + stages: [ + { stage: "acl", outcome: "success" }, + { stage: "open", outcome: "success" }, + { stage: "opened-validation", outcome: "success" }, + { stage: "read", outcome: "success" }, + { stage: "after-read-validation", outcome: "success" }, + { stage: "decode", outcome: "success" }, + { stage: "parse", outcome: "success" }, + { stage: "migration-source", outcome: "success" }, + { stage: "close", outcome: "success" }, + { stage: "dedupe", outcome: "success" }, + { stage: "metadata", outcome: "success" }, + { stage: "accepted", outcome: "success" } + ], + accepted: true + }, + { + candidate: "sentry", + stages: [ + { stage: "acl", outcome: "success" }, + { stage: "open", outcome: "success" }, + { stage: "opened-validation", outcome: "success" }, + { stage: "read", outcome: "success" }, + { stage: "after-read-validation", outcome: "success" }, + { stage: "decode", outcome: "success" }, + { stage: "parse", outcome: "success" }, + { stage: "migration-source", outcome: "success" }, + { stage: "close", outcome: "success" }, + { stage: "dedupe", outcome: "success" }, + { stage: "metadata", outcome: "success" }, + { stage: "accepted", outcome: "success" } + ], + accepted: true + } + ]); if (process.platform === "win32") { expect({ aclProbeSummary: [...aclProbes].sort((left, right) => left.candidate.localeCompare(right.candidate)), From ea84cf945d2d1c074c7fc8c0dca9f1bb1e17120f Mon Sep 17 00:00:00 2001 From: mohammed naji Date: Sat, 25 Jul 2026 04:39:41 +0400 Subject: [PATCH 5/5] chore(review): clarify catalog diagnostic boundary --- src/console/console-config-catalog.ts | 7 +++++-- tests/console-dashboard-application-service.test.ts | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/console/console-config-catalog.ts b/src/console/console-config-catalog.ts index 9bd7fbb7..980621dc 100644 --- a/src/console/console-config-catalog.ts +++ b/src/console/console-config-catalog.ts @@ -61,6 +61,8 @@ export interface ConsoleConfigCatalogCandidateStageEvent { /** Test-only observer for opaque candidate diagnostics. */ export type ConsoleConfigCatalogCandidateStageObserver = (event: ConsoleConfigCatalogCandidateStageEvent) => void; +type TrustedConfigurationFileHandle = Awaited>; + function observeCandidateStage( observer: ConsoleConfigCatalogCandidateStageObserver | undefined, candidateIndex: number, @@ -178,7 +180,7 @@ async function trustedDirectory( } async function closeTrustedConfigurationHandle( - handle: Awaited>, + handle: TrustedConfigurationFileHandle, candidateIndex: number, candidateStageObserver: ConsoleConfigCatalogCandidateStageObserver | undefined ): Promise { @@ -186,6 +188,7 @@ async function closeTrustedConfigurationHandle( await handle.close(); } catch (error) { observeCandidateStage(candidateStageObserver, candidateIndex, "close", "error"); + // Candidate discovery deliberately fails closed if any guarded-read cleanup fails. throw error; } observeCandidateStage(candidateStageObserver, candidateIndex, "close", "success"); @@ -216,7 +219,7 @@ async function readTrustedConfiguration( } observeCandidateStage(candidateStageObserver, candidateIndex, "acl", "success"); - let handle: Awaited>; + let handle: TrustedConfigurationFileHandle; try { handle = await open(canonical, readOnlyFlags); } catch (error) { diff --git a/tests/console-dashboard-application-service.test.ts b/tests/console-dashboard-application-service.test.ts index 72ee512c..c6966222 100644 --- a/tests/console-dashboard-application-service.test.ts +++ b/tests/console-dashboard-application-service.test.ts @@ -112,6 +112,7 @@ function catalogStageSummary( readonly stages: readonly Omit[]; readonly accepted: boolean; }[] { + // The catalog sorts the only two JSON fixtures alphabetically: gsc is index 0, sentry is index 1. const candidates = ["gsc", "sentry"] as const; return candidates.map((candidate, candidateIndex) => ({ candidate,