test(matrix): cover native Windows file semantics · openclaw/openclaw@fa1d826
vincentkoc
·
2026-05-05
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import path from "node:path"; |
1 | 2 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 3 | |
3 | 4 | const availabilityState = vi.hoisted(() => ({ |
@@ -37,10 +38,11 @@ describe("isMatrixLegacyCryptoInspectorAvailable", () => {
|
37 | 38 | }); |
38 | 39 | |
39 | 40 | it("detects the source inspector module directly", () => { |
40 | | -availabilityState.currentFilePath = |
41 | | -"/virtual/extensions/matrix/src/legacy-crypto-inspector-availability.js"; |
| 41 | +availabilityState.currentFilePath = path.resolve( |
| 42 | +"/virtual/extensions/matrix/src/legacy-crypto-inspector-availability.js", |
| 43 | +); |
42 | 44 | availabilityState.existingPaths.add( |
43 | | -"/virtual/extensions/matrix/src/matrix/legacy-crypto-inspector.ts", |
| 45 | +path.resolve("/virtual/extensions/matrix/src/matrix/legacy-crypto-inspector.ts"), |
44 | 46 | ); |
45 | 47 | |
46 | 48 | expect(isMatrixLegacyCryptoInspectorAvailable()).toBe(true); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -21,6 +21,8 @@ const DEFAULT_LEGACY_CREDENTIALS = {
|
21 | 21 | createdAt: "2026-03-01T10:00:00.000Z", |
22 | 22 | }; |
23 | 23 | |
| 24 | +const EXPECTS_POSIX_PRIVATE_FILE_MODE = process.platform !== "win32"; |
| 25 | + |
24 | 26 | describe("matrix credentials storage", () => { |
25 | 27 | const tempDirs: string[] = []; |
26 | 28 | |
@@ -74,7 +76,9 @@ describe("matrix credentials storage", () => {
|
74 | 76 | expect(fs.existsSync(credPath)).toBe(true); |
75 | 77 | expect(credPath).toBe(path.join(stateDir, "credentials", "matrix", "credentials-ops.json")); |
76 | 78 | const mode = fs.statSync(credPath).mode & 0o777; |
77 | | -expect(mode).toBe(0o600); |
| 79 | +if (EXPECTS_POSIX_PRIVATE_FILE_MODE) { |
| 80 | +expect(mode).toBe(0o600); |
| 81 | +} |
78 | 82 | }); |
79 | 83 | |
80 | 84 | it("touch updates lastUsedAt while preserving createdAt", async () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -19,6 +19,7 @@ const DATABASE_PREFIX = "openclaw-matrix-persistence-test";
|
19 | 19 | const OTHER_DATABASE_PREFIX = "openclaw-matrix-persistence-other-test"; |
20 | 20 | const cryptoDatabaseName = `${DATABASE_PREFIX}::matrix-sdk-crypto`; |
21 | 21 | const otherCryptoDatabaseName = `${OTHER_DATABASE_PREFIX}::matrix-sdk-crypto`; |
| 22 | +const EXPECTS_POSIX_PRIVATE_FILE_MODE = process.platform !== "win32"; |
22 | 23 | |
23 | 24 | async function clearTestIndexedDbState(): Promise<void> { |
24 | 25 | await clearAllIndexedDbState({ databasePrefix: DATABASE_PREFIX }); |
@@ -62,7 +63,9 @@ describe("Matrix IndexedDB persistence", () => {
|
62 | 63 | expect(fs.existsSync(snapshotPath)).toBe(true); |
63 | 64 | |
64 | 65 | const mode = fs.statSync(snapshotPath).mode & 0o777; |
65 | | -expect(mode).toBe(0o600); |
| 66 | +if (EXPECTS_POSIX_PRIVATE_FILE_MODE) { |
| 67 | +expect(mode).toBe(0o600); |
| 68 | +} |
66 | 69 | |
67 | 70 | await clearTestIndexedDbState(); |
68 | 71 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -11,6 +11,8 @@ function createTempRecoveryKeyPath(): string {
|
11 | 11 | return path.join(dir, "recovery-key.json"); |
12 | 12 | } |
13 | 13 | |
| 14 | +const EXPECTS_POSIX_PRIVATE_FILE_MODE = process.platform !== "win32"; |
| 15 | + |
14 | 16 | function createGeneratedRecoveryKey(params: { |
15 | 17 | keyId: string; |
16 | 18 | name: string; |
@@ -133,7 +135,9 @@ describe("MatrixRecoveryKeyStore", () => {
|
133 | 135 | expect(saved.privateKeyBase64).toBe(Buffer.from([9, 8, 7]).toString("base64")); |
134 | 136 | |
135 | 137 | const mode = fs.statSync(recoveryKeyPath).mode & 0o777; |
136 | | -expect(mode).toBe(0o600); |
| 138 | +if (EXPECTS_POSIX_PRIVATE_FILE_MODE) { |
| 139 | +expect(mode).toBe(0o600); |
| 140 | +} |
137 | 141 | }); |
138 | 142 | |
139 | 143 | it("creates and persists a recovery key when secret storage is missing", async () => { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。