Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/harness/src/server/auth-mcp-wiring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ const authFixture = vi.hoisted(() => ({
},
}));

vi.mock("@sapiom/mcp/auth", () => {
// Partial mock: every export not listed below stays real, so a new auth
// import in the server cannot fail here as a missing mock export.
vi.mock("@sapiom/mcp/auth", async (importOriginal) => {
const actual = await importOriginal<typeof import("@sapiom/mcp/auth")>();
const resolveEnvironment = vi.fn(async (environment?: string) => {
const requested = environment ?? "production";
const name =
Expand All @@ -57,6 +60,7 @@ vi.mock("@sapiom/mcp/auth", () => {
});

return {
...actual,
resolveEnvironment,
readCredentials: vi.fn(async () => authFixture.credential),
readCredentialsOrThrow: vi.fn(async () => {
Expand Down
22 changes: 19 additions & 3 deletions packages/harness/src/server/definition-list-enrichment.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/**
* Wiring regression for SAP-3214: one tenant-scoped list request per pass,
* never a by-id request for a definition the account can't see. Fake Agents
* API counting list and detail requests; `@sapiom/mcp/auth` mocked so the
* disconnect route never touches ~/.sapiom.
* API counting list and detail requests. `@sapiom/mcp/auth` is a PARTIAL
* mock: the credential store and the browser flow are replaced, every other
* export runs for real, and the home directory is redirected to a temp dir
* so nothing real can reach ~/.sapiom.
*/
import {
createServer as createHttpServer,
Expand All @@ -14,7 +16,21 @@ import * as path from "node:path";
import { fileURLToPath } from "node:url";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

vi.mock("@sapiom/mcp/auth", () => ({
// The real module resolves every path through `os.homedir()` internally, so
// a mocked `credentialsFilePath` export alone would not contain a new real
// export. Redirect the home directory instead: the credential store then
// lives under a temp dir that does not exist, the observer sees ENOENT and
// stays quiet, and nothing under the real ~/.sapiom is watched or written.
vi.mock("node:os", async (importOriginal) => ({
...(await importOriginal<typeof import("node:os")>()),
homedir: () => "/tmp/sap3214-enrichment-home",
}));

// Every other export stays real so a new import in the server cannot turn
// this fake into a missing-export failure; with the home redirected above,
// whatever runs for real stays inside the temp home.
vi.mock("@sapiom/mcp/auth", async (importOriginal) => ({
...(await importOriginal<typeof import("@sapiom/mcp/auth")>()),
resolveEnvironment: vi.fn(async (environment?: string) => ({
name: environment === "dev" ? "staging" : "production",
appURL: "https://app.example.test",
Expand Down
Loading