Skip to content

Commit 7b2e0ec

Browse files
committed
fix(testing): make the no-sdk-mocks guard path-separator agnostic
`relative()` returns host-specific separators, so on Windows the offender check produced `packages\testing\…` and matched none of the forward-slash ALLOWLIST keys. Every allowlisted spec would have been reported as an offender and the guard would have failed for the wrong reason. That direction is the safe one — a false failure, not a false pass — but a guard that cries wolf is a guard someone disables, and this one is now the only thing preventing SDK mocks from returning. Normalizes to POSIX form before the allowlist lookup. The offender list is reported in the same form, so its output stays copy-pasteable into the allowlist on any platform. The sibling stale-entry check needed no change: it feeds allowlist keys through `join()`, which normalizes forward slashes on Windows already. Verified the guard still fails on a planted `vi.mock("@temporalio/workflow")` and names the file in POSIX form. Reported by Copilot on #359.
1 parent cb31620 commit 7b2e0ec

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

packages/testing/src/no-sdk-mocks.spec.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
import { readFile, readdir } from "node:fs/promises";
2-
import { join, relative } from "node:path";
2+
import { join, relative, sep } from "node:path";
33
import { fileURLToPath } from "node:url";
44

55
import { describe, expect, it } from "vitest";
66

77
const WORKSPACE_ROOT = fileURLToPath(new URL("../../../", import.meta.url));
88

9+
/**
10+
* Workspace-relative path in POSIX form, whatever the host separator is.
11+
*
12+
* `relative()` yields `packages\testing\…` on Windows, which matches none of
13+
* the forward-slash {@link ALLOWLIST} keys — every allowlisted spec would be
14+
* reported as an offender and the guard would fail for the wrong reason. A
15+
* guard that cries wolf is a guard someone disables, so normalize before the
16+
* lookup. The offender list is reported in the same form, so its output is
17+
* copy-pasteable into the allowlist on any platform.
18+
*/
19+
function workspaceRelative(absolutePath: string): string {
20+
return relative(WORKSPACE_ROOT, absolutePath).split(sep).join("/");
21+
}
22+
923
/**
1024
* Spec files permitted to mock the Temporal SDK. Every entry needs a reason
1125
* naming why the behavior is unreachable on a real time-skipping server.
@@ -70,7 +84,7 @@ describe("no SDK mocks outside the allowlist", () => {
7084
const offenders: string[] = [];
7185

7286
for (const file of files) {
73-
const rel = relative(WORKSPACE_ROOT, file);
87+
const rel = workspaceRelative(file);
7488
const source = await readFile(file, "utf8");
7589
if (SDK_MOCK.test(source) && !(rel in ALLOWLIST)) {
7690
offenders.push(rel);

0 commit comments

Comments
 (0)