@raidiant/notifai 10.1.1 → 10.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/commands-core.d.ts +1 -1
  3. package/dist/commands-init.js +9 -6
  4. package/dist/commands-init.js.map +1 -1
  5. package/dist/commands-send-support.js +3 -0
  6. package/dist/commands-send-support.js.map +1 -1
  7. package/dist/commands-skill.js +72 -54
  8. package/dist/commands-skill.js.map +1 -1
  9. package/dist/invocation-context.d.ts +1 -0
  10. package/dist/invocation-context.js +9 -1
  11. package/dist/invocation-context.js.map +1 -1
  12. package/dist/native-skills.d.ts +13 -3
  13. package/dist/native-skills.js +51 -12
  14. package/dist/native-skills.js.map +1 -1
  15. package/dist/node-floor.d.ts +2 -1
  16. package/dist/node-floor.js +9 -5
  17. package/dist/node-floor.js.map +1 -1
  18. package/dist/orca-session-title.d.ts +5 -4
  19. package/dist/orca-session-title.js +32 -19
  20. package/dist/orca-session-title.js.map +1 -1
  21. package/dist/platform.d.ts +11 -17
  22. package/dist/platform.js +20 -23
  23. package/dist/platform.js.map +1 -1
  24. package/dist/release.d.ts +5 -5
  25. package/dist/release.js +5 -5
  26. package/dist/setup-destinations.js +1 -1
  27. package/dist/setup-destinations.js.map +1 -1
  28. package/dist/skill-integrity.d.ts +49 -0
  29. package/dist/skill-integrity.js +154 -0
  30. package/dist/skill-integrity.js.map +1 -0
  31. package/dist/skill-source/manifest.json +16 -0
  32. package/dist/skill-source/notifai/SKILL.md +390 -0
  33. package/dist/skill-source/notifai/references/harness-setup.md +220 -0
  34. package/package.json +11 -14
  35. package/src/atomic-file.ts +0 -198
  36. package/src/claude-wake.test.ts +0 -321
  37. package/src/claude-wake.ts +0 -499
  38. package/src/cli-bin.test.ts +0 -176
  39. package/src/cli-bin.ts +0 -233
  40. package/src/cli-release.test.ts +0 -46
  41. package/src/cli-release.ts +0 -78
  42. package/src/cli-update-contract.ts +0 -9
  43. package/src/cli-update.test.ts +0 -125
  44. package/src/client.test.ts +0 -390
  45. package/src/client.ts +0 -352
  46. package/src/codex-wake.test.ts +0 -254
  47. package/src/codex-wake.ts +0 -301
  48. package/src/command-session.ts +0 -38
  49. package/src/commands-agent-sessions.ts +0 -72
  50. package/src/commands-auth.ts +0 -238
  51. package/src/commands-config.ts +0 -336
  52. package/src/commands-core.ts +0 -312
  53. package/src/commands-devices.ts +0 -180
  54. package/src/commands-doctor.ts +0 -1501
  55. package/src/commands-guidance.ts +0 -181
  56. package/src/commands-harness-context.ts +0 -207
  57. package/src/commands-hook-shape.ts +0 -69
  58. package/src/commands-hooks.ts +0 -2318
  59. package/src/commands-init.ts +0 -1055
  60. package/src/commands-io.ts +0 -108
  61. package/src/commands-logs.ts +0 -243
  62. package/src/commands-project.ts +0 -47
  63. package/src/commands-send-support.test.ts +0 -156
  64. package/src/commands-send-support.ts +0 -311
  65. package/src/commands-send.ts +0 -875
  66. package/src/commands-setup-proof.test.ts +0 -72
  67. package/src/commands-setup-proof.ts +0 -124
  68. package/src/commands-skill.test.ts +0 -44
  69. package/src/commands-skill.ts +0 -204
  70. package/src/commands-sounds.test.ts +0 -106
  71. package/src/commands-sounds.ts +0 -49
  72. package/src/commands-update.ts +0 -180
  73. package/src/commands.test.ts +0 -8297
  74. package/src/commands.ts +0 -77
  75. package/src/config-schema.test.ts +0 -153
  76. package/src/config-schema.ts +0 -349
  77. package/src/config.test.ts +0 -581
  78. package/src/config.ts +0 -475
  79. package/src/credentials.test.ts +0 -403
  80. package/src/credentials.ts +0 -403
  81. package/src/file-lock-process-worker.test.ts +0 -64
  82. package/src/file-lock.test.ts +0 -320
  83. package/src/file-lock.ts +0 -393
  84. package/src/fixtures/hermes-0.20.6-classic-cli-local.json +0 -50
  85. package/src/fixtures/openclaw-2026.7.1-2-agent-local.json +0 -57
  86. package/src/generated-session-label.ts +0 -155
  87. package/src/guidance-content.ts +0 -278
  88. package/src/guidance-render.ts +0 -56
  89. package/src/guidance.test.ts +0 -327
  90. package/src/guidance.ts +0 -233
  91. package/src/harness-integration.test.ts +0 -294
  92. package/src/harnesses.test.ts +0 -149
  93. package/src/harnesses.ts +0 -164
  94. package/src/hook-adapter.test.ts +0 -496
  95. package/src/hook-adapter.ts +0 -424
  96. package/src/hook-input.test.ts +0 -39
  97. package/src/hook-input.ts +0 -72
  98. package/src/hooks.test.ts +0 -5824
  99. package/src/hooks.ts +0 -4011
  100. package/src/install-hooks.test.ts +0 -1614
  101. package/src/install-hooks.ts +0 -1501
  102. package/src/interactive.test.ts +0 -387
  103. package/src/interactive.ts +0 -858
  104. package/src/invocation-context.test.ts +0 -352
  105. package/src/invocation-context.ts +0 -197
  106. package/src/logging-process-worker.test.ts +0 -45
  107. package/src/logging.test.ts +0 -544
  108. package/src/logging.ts +0 -698
  109. package/src/main-run.ts +0 -45
  110. package/src/main.ts +0 -12
  111. package/src/native-skills.test.ts +0 -115
  112. package/src/native-skills.ts +0 -162
  113. package/src/node-floor.test.ts +0 -27
  114. package/src/node-floor.ts +0 -37
  115. package/src/onboarding-docs.test.ts +0 -25
  116. package/src/openclaw-plugin.ts +0 -409
  117. package/src/opencode-plugin.ts +0 -298
  118. package/src/orca-session-title.test.ts +0 -54
  119. package/src/orca-session-title.ts +0 -103
  120. package/src/pack-feedback-slice.test.ts +0 -212
  121. package/src/pack-feedback-slice.ts +0 -187
  122. package/src/platform.test.ts +0 -152
  123. package/src/platform.ts +0 -173
  124. package/src/program.test.ts +0 -317
  125. package/src/program.ts +0 -842
  126. package/src/project-enablement.test.ts +0 -55
  127. package/src/project-enablement.ts +0 -99
  128. package/src/question-caps.test.ts +0 -49
  129. package/src/question-settlement-process.ts +0 -47
  130. package/src/question-timing.ts +0 -56
  131. package/src/readiness.test.ts +0 -25
  132. package/src/readiness.ts +0 -212
  133. package/src/release.ts +0 -51
  134. package/src/send-attempts.test.ts +0 -143
  135. package/src/send-attempts.ts +0 -188
  136. package/src/send.test.ts +0 -28
  137. package/src/send.ts +0 -436
  138. package/src/session-activation.ts +0 -61
  139. package/src/session-end-log-lock-worker.test.ts +0 -35
  140. package/src/session-labels.test.ts +0 -490
  141. package/src/session-labels.ts +0 -474
  142. package/src/setup-destinations.test.ts +0 -41
  143. package/src/setup-destinations.ts +0 -50
  144. package/src/skill.test.ts +0 -426
  145. package/src/sound-ref.test.ts +0 -31
  146. package/src/sound-ref.ts +0 -34
  147. package/src/trust-policy.test.ts +0 -701
  148. package/src/ui/banner.ts +0 -95
  149. package/src/ui/config-view.test.ts +0 -90
  150. package/src/ui/config-view.ts +0 -138
  151. package/src/ui/help.test.ts +0 -16
  152. package/src/ui/help.ts +0 -128
  153. package/src/ui/theme.test.ts +0 -92
  154. package/src/ui/theme.ts +0 -265
  155. package/src/url-policy.ts +0 -399
  156. package/tsconfig.json +0 -10
@@ -1,403 +0,0 @@
1
- import {
2
- chmodSync,
3
- existsSync,
4
- mkdirSync,
5
- mkdtempSync,
6
- readFileSync,
7
- readdirSync,
8
- rmSync,
9
- statSync,
10
- writeFileSync,
11
- } from 'node:fs'
12
- import os from 'node:os'
13
- import path from 'node:path'
14
- import { afterAll, describe, expect, it } from 'vitest'
15
- import {
16
- FileStore,
17
- KeychainStore,
18
- WindowsDpapiStore,
19
- defaultCredentialStore,
20
- windowsDpapiOperation,
21
- type MachineCredential,
22
- type ProcessRunner,
23
- type RunCommandSpec,
24
- } from './credentials.js'
25
-
26
- const tmp = mkdtempSync(path.join(os.tmpdir(), 'notifai-cred-'))
27
- afterAll(() => rmSync(tmp, { recursive: true, force: true }))
28
-
29
- const SAMPLE: MachineCredential = {
30
- machineId: 'mach_fixture',
31
- secret: 'fixture-secret',
32
- baseUrl: 'https://example.test',
33
- machineName: 'fixture-machine',
34
- }
35
-
36
- const OTHER: MachineCredential = {
37
- machineId: 'mach_other',
38
- secret: 'other-secret',
39
- baseUrl: 'https://other.test',
40
- machineName: 'other-machine',
41
- }
42
-
43
- function sandbox(name: string): {
44
- env: NodeJS.ProcessEnv
45
- local: string
46
- roaming: string
47
- config: string
48
- } {
49
- const root = path.join(tmp, name)
50
- const local = path.join(root, 'local')
51
- const roaming = path.join(root, 'roaming')
52
- const config = path.join(root, 'config')
53
- mkdirSync(local, { recursive: true })
54
- mkdirSync(roaming, { recursive: true })
55
- mkdirSync(config, { recursive: true })
56
- return {
57
- local,
58
- roaming,
59
- config,
60
- env: {
61
- LOCALAPPDATA: local,
62
- APPDATA: roaming,
63
- XDG_CONFIG_HOME: config,
64
- SystemRoot: 'C:\\Windows',
65
- },
66
- }
67
- }
68
-
69
- function writeRaw(file: string, contents: string): void {
70
- mkdirSync(path.dirname(file), { recursive: true })
71
- writeFileSync(file, contents)
72
- }
73
-
74
- function mockDpapi(options: { failProtect?: boolean; failUnprotect?: boolean } = {}): {
75
- runner: ProcessRunner
76
- calls: RunCommandSpec[]
77
- } {
78
- const vault = new Map<string, string>()
79
- const calls: RunCommandSpec[] = []
80
- const runner: ProcessRunner = {
81
- run(spec) {
82
- calls.push({
83
- command: spec.command,
84
- args: spec.args,
85
- input: spec.input,
86
- ...(spec.timeoutMs === undefined ? {} : { timeoutMs: spec.timeoutMs }),
87
- })
88
- const operation = windowsDpapiOperation(spec.args)
89
- if (operation === 'protect') {
90
- if (options.failProtect) return { status: 1, stdout: Buffer.alloc(0) }
91
- const token = Buffer.from(`dpapi:${vault.size}`, 'utf8').toString('base64')
92
- vault.set(token, spec.input.toString('utf8'))
93
- return { status: 0, stdout: Buffer.from(token, 'utf8') }
94
- }
95
- if (operation === 'unprotect') {
96
- if (options.failUnprotect) return { status: 1, stdout: Buffer.alloc(0) }
97
- const token = spec.input.toString('utf8').trim()
98
- const plain = vault.get(token)
99
- if (plain === undefined) return { status: 1, stdout: Buffer.alloc(0) }
100
- return { status: 0, stdout: Buffer.from(plain, 'utf8') }
101
- }
102
- return { status: 1, stdout: Buffer.alloc(0) }
103
- },
104
- }
105
- return { runner, calls }
106
- }
107
-
108
- function assertNoSecretInArgs(calls: RunCommandSpec[]): void {
109
- for (const call of calls) {
110
- const argv = [call.command, ...call.args].join('\0')
111
- for (const credential of [SAMPLE, OTHER]) {
112
- for (const value of Object.values(credential)) expect(argv).not.toContain(value)
113
- expect(argv).not.toContain(JSON.stringify(credential))
114
- }
115
- expect(argv).not.toContain('machineId')
116
- }
117
- }
118
-
119
- describe('defaultCredentialStore', () => {
120
- it('selects the DPAPI store on win32', () => {
121
- const { env } = sandbox('default-win32')
122
- const store = defaultCredentialStore(env, { platform: 'win32', run: mockDpapi().runner })
123
- expect(store).toBeInstanceOf(WindowsDpapiStore)
124
- expect(store.describe()).toMatch(/Windows DPAPI current-user/)
125
- expect(store.describe()).toContain(path.join(env.LOCALAPPDATA!, 'notifai', 'credentials.dpapi'))
126
- })
127
-
128
- it('keeps the explicit file escape hatch on win32 under APPDATA', () => {
129
- const { env } = sandbox('default-file-win32')
130
- const store = defaultCredentialStore(
131
- { ...env, NOTIFAI_CREDENTIALS: 'file', XDG_CONFIG_HOME: undefined },
132
- { platform: 'win32' },
133
- )
134
- expect(store).toBeInstanceOf(FileStore)
135
- expect(store.describe()).toContain(path.join(env.APPDATA!, 'notifai', 'credentials.json'))
136
- expect(store.describe()).toMatch(/plaintext file/)
137
- expect(store.describe()).toMatch(/POSIX mode bits are not protection on NTFS/)
138
- expect(store.describe()).not.toMatch(/0600/)
139
- })
140
-
141
- it('preserves macOS Keychain when available', () => {
142
- const store = defaultCredentialStore({}, { platform: 'darwin', keychainAvailable: true })
143
- expect(store.describe()).toBe('macOS Keychain (io.notifai.cli)')
144
- })
145
-
146
- it('falls back to the 0600 file store on linux', () => {
147
- const { env } = sandbox('default-linux')
148
- const store = defaultCredentialStore(env, { platform: 'linux' })
149
- expect(store).toBeInstanceOf(FileStore)
150
- expect(store.describe()).toMatch(/plaintext file/)
151
- expect(store.describe()).toMatch(/mode 0600/)
152
- expect(store.describe()).not.toMatch(/NTFS/)
153
- })
154
-
155
- it('uses the file store on macOS when Keychain is unavailable', () => {
156
- const { env } = sandbox('default-darwin-file')
157
- const store = defaultCredentialStore(env, { platform: 'darwin', keychainAvailable: false })
158
- expect(store).toBeInstanceOf(FileStore)
159
- expect(store.describe()).toMatch(/mode 0600/)
160
- })
161
- })
162
-
163
- describe('FileStore', () => {
164
- it('saves, loads, overwrites, and clears atomically', () => {
165
- const { env } = sandbox('file-roundtrip')
166
- const store = new FileStore(env, { platform: 'linux' })
167
- expect(store.load()).toBeNull()
168
- store.save(SAMPLE)
169
- const file = path.join(env.XDG_CONFIG_HOME!, 'notifai', 'credentials.json')
170
- expect(existsSync(file)).toBe(true)
171
- if (process.platform !== 'win32') {
172
- expect(statSync(file).mode & 0o777).toBe(0o600)
173
- }
174
- expect(JSON.parse(readFileSync(file, 'utf8'))).toEqual({
175
- format: 'notifai.machine-credential.v1',
176
- ...SAMPLE,
177
- })
178
- expect(store.load()).toEqual(SAMPLE)
179
- store.save(OTHER)
180
- expect(store.load()).toEqual(OTHER)
181
- store.clear()
182
- expect(existsSync(file)).toBe(false)
183
- expect(store.load()).toBeNull()
184
- })
185
-
186
- it('treats malformed JSON as missing', () => {
187
- const { env } = sandbox('file-malformed')
188
- const file = path.join(env.XDG_CONFIG_HOME!, 'notifai', 'credentials.json')
189
- writeRaw(file, '{not-json')
190
- expect(new FileStore(env).load()).toBeNull()
191
- })
192
-
193
- it('treats incomplete objects as missing', () => {
194
- const { env } = sandbox('file-incomplete')
195
- const file = path.join(env.XDG_CONFIG_HOME!, 'notifai', 'credentials.json')
196
- writeRaw(file, `${JSON.stringify({ machineId: 'mach_fixture' })}\n`)
197
- expect(new FileStore(env).load()).toBeNull()
198
- })
199
-
200
- it('reads the unversioned v1 shape while making every new save explicit', () => {
201
- const { env } = sandbox('file-unversioned-v1')
202
- const file = path.join(env.XDG_CONFIG_HOME!, 'notifai', 'credentials.json')
203
- writeRaw(file, `${JSON.stringify(SAMPLE)}\n`)
204
- const store = new FileStore(env)
205
- expect(store.load()).toEqual(SAMPLE)
206
- store.save(SAMPLE)
207
- expect(JSON.parse(readFileSync(file, 'utf8'))).toMatchObject({
208
- format: 'notifai.machine-credential.v1',
209
- })
210
- })
211
-
212
- it('creates the credential directory mode 0700 on POSIX', () => {
213
- if (process.platform === 'win32') return
214
- const { env } = sandbox('file-dir-mode')
215
- const store = new FileStore(env, { platform: 'linux' })
216
- store.save(SAMPLE)
217
- const dir = path.join(env.XDG_CONFIG_HOME!, 'notifai')
218
- expect(statSync(dir).mode & 0o777).toBe(0o700)
219
- })
220
-
221
- it('tightens an existing world-readable credential directory on POSIX', () => {
222
- if (process.platform === 'win32') return
223
- const { env } = sandbox('file-dir-chmod')
224
- const dir = path.join(env.XDG_CONFIG_HOME!, 'notifai')
225
- mkdirSync(dir, { recursive: true, mode: 0o755 })
226
- chmodSync(dir, 0o755)
227
- expect(statSync(dir).mode & 0o777).toBe(0o755)
228
- const store = new FileStore(env, { platform: 'linux' })
229
- store.save(SAMPLE)
230
- expect(statSync(dir).mode & 0o777).toBe(0o700)
231
- })
232
-
233
- it('does not interpret or erase a credential from a future format epoch', () => {
234
- const { env } = sandbox('file-future-format')
235
- const file = path.join(env.XDG_CONFIG_HOME!, 'notifai', 'credentials.json')
236
- const future = `${JSON.stringify({ format: 'notifai.machine-credential.v2', ...SAMPLE })}\n`
237
- writeRaw(file, future)
238
- expect(new FileStore(env).load()).toBeNull()
239
- expect(readFileSync(file, 'utf8')).toBe(future)
240
- })
241
- })
242
-
243
- describe('KeychainStore', () => {
244
- it('sends the serialized credential through stdin and never process argv', () => {
245
- const calls: RunCommandSpec[] = []
246
- const runner: ProcessRunner = {
247
- run(spec) {
248
- calls.push(spec)
249
- return { status: 0, stdout: Buffer.alloc(0) }
250
- },
251
- }
252
- const store = new KeychainStore({ run: runner })
253
- store.save(SAMPLE)
254
- store.save(OTHER)
255
-
256
- expect(calls).toHaveLength(2)
257
- for (const [index, call] of calls.entries()) {
258
- expect(call.command).toBe('security')
259
- expect(call.args).toEqual(['-q', '-i'])
260
- expect(call.timeoutMs).toBe(15_000)
261
- expect(call.input.toString('ascii')).toMatch(
262
- /^add-generic-password -U -s io\.notifai\.cli -a machine -X [0-9a-f]+\n$/,
263
- )
264
- const encoded = call.input.toString('ascii').match(/-X ([0-9a-f]+)\n$/)?.[1]
265
- expect(encoded).toBeDefined()
266
- expect(JSON.parse(Buffer.from(encoded!, 'hex').toString('utf8'))).toEqual({
267
- format: 'notifai.machine-credential.v1',
268
- ...(index === 0 ? SAMPLE : OTHER),
269
- })
270
- expect(call.input.toString('utf8')).not.toContain(index === 0 ? SAMPLE.secret : OTHER.secret)
271
- }
272
- assertNoSecretInArgs(calls)
273
- })
274
-
275
- it('fails closed when the Keychain helper rejects the write', () => {
276
- const runner: ProcessRunner = {
277
- run() {
278
- return { status: 1, stdout: Buffer.alloc(0) }
279
- },
280
- }
281
- expect(() => new KeychainStore({ run: runner }).save(SAMPLE)).toThrow(
282
- /Keychain credential save failed/,
283
- )
284
- })
285
- })
286
-
287
- describe('WindowsDpapiStore', () => {
288
- it('round-trips through real Windows CurrentUser DPAPI without plaintext on disk', () => {
289
- if (process.platform !== 'win32') return
290
-
291
- const local = path.join(tmp, 'real dpapi & Ω', 'local app data')
292
- mkdirSync(local, { recursive: true })
293
- const env = { ...process.env, LOCALAPPDATA: local }
294
- const store = new WindowsDpapiStore(env)
295
- store.save(SAMPLE)
296
-
297
- const file = path.join(local, 'notifai', 'credentials.dpapi')
298
- const onDisk = readFileSync(file, 'utf8')
299
- expect(onDisk).not.toContain(SAMPLE.secret)
300
- expect(onDisk).not.toContain(SAMPLE.machineId)
301
- expect(new WindowsDpapiStore(env).load()).toEqual(SAMPLE)
302
-
303
- store.clear()
304
- expect(existsSync(file)).toBe(false)
305
- })
306
-
307
- it('protects under LOCALAPPDATA and never writes roaming or config trees', () => {
308
- const { env, roaming, config } = sandbox('dpapi-location')
309
- const { runner, calls } = mockDpapi()
310
- const store = new WindowsDpapiStore(env, { run: runner })
311
- store.save(SAMPLE)
312
- const file = path.join(env.LOCALAPPDATA!, 'notifai', 'credentials.dpapi')
313
- expect(existsSync(file)).toBe(true)
314
- const onDisk = readFileSync(file, 'utf8')
315
- expect(onDisk).not.toContain(SAMPLE.secret)
316
- expect(onDisk).not.toContain(SAMPLE.machineId)
317
- expect(JSON.parse(onDisk)).toMatchObject({ format: 'notifai.dpapi.current-user.v1' })
318
- expect(readdirSync(roaming, { recursive: true })).toEqual([])
319
- expect(existsSync(config) ? readdirSync(config, { recursive: true }) : []).toEqual([])
320
- expect(store.load()).toEqual(SAMPLE)
321
- expect(store.describe()).toBe(`Windows DPAPI current-user (${file})`)
322
- expect(calls[0]?.command).toMatch(/powershell\.exe$/i)
323
- expect(calls[0]?.args).toEqual(
324
- expect.arrayContaining(['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass']),
325
- )
326
- expect(calls.every((call) => call.timeoutMs === 30_000)).toBe(true)
327
- assertNoSecretInArgs(calls)
328
- })
329
-
330
- it('overwrites and clears the protected blob', () => {
331
- const { env } = sandbox('dpapi-overwrite')
332
- const { runner, calls } = mockDpapi()
333
- const store = new WindowsDpapiStore(env, { run: runner })
334
- store.save(SAMPLE)
335
- store.save(OTHER)
336
- expect(store.load()).toEqual(OTHER)
337
- store.clear()
338
- expect(store.load()).toBeNull()
339
- expect(
340
- existsSync(path.join(env.LOCALAPPDATA!, 'notifai', 'credentials.dpapi')),
341
- ).toBe(false)
342
- assertNoSecretInArgs(calls)
343
- })
344
-
345
- it('returns null for missing, malformed, and corrupt envelopes', () => {
346
- const { env } = sandbox('dpapi-corrupt')
347
- const { runner } = mockDpapi()
348
- const store = new WindowsDpapiStore(env, { run: runner })
349
- expect(store.load()).toBeNull()
350
- const file = path.join(env.LOCALAPPDATA!, 'notifai', 'credentials.dpapi')
351
- writeRaw(file, 'not-json')
352
- expect(store.load()).toBeNull()
353
- writeRaw(file, `${JSON.stringify({ format: 'unknown', data: 'AAAA' })}\n`)
354
- expect(store.load()).toBeNull()
355
- writeRaw(
356
- file,
357
- `${JSON.stringify({ format: 'notifai.dpapi.current-user.v1', data: '@@@' })}\n`,
358
- )
359
- expect(store.load()).toBeNull()
360
- })
361
-
362
- it('leaves the existing blob in place when protection fails', () => {
363
- const { env } = sandbox('dpapi-protect-fail')
364
- const good = mockDpapi()
365
- const store = new WindowsDpapiStore(env, { run: good.runner })
366
- store.save(SAMPLE)
367
- const failing = mockDpapi({ failProtect: true })
368
- const broken = new WindowsDpapiStore(env, { run: failing.runner })
369
- expect(() => broken.save(OTHER)).toThrow(/Windows credential protection failed/)
370
- expect(store.load()).toEqual(SAMPLE)
371
- const onDisk = readFileSync(path.join(env.LOCALAPPDATA!, 'notifai', 'credentials.dpapi'), 'utf8')
372
- expect(onDisk).not.toContain(OTHER.secret)
373
- assertNoSecretInArgs([...good.calls, ...failing.calls])
374
- })
375
-
376
- it('returns null when unprotect fails', () => {
377
- const { env } = sandbox('dpapi-unprotect-fail')
378
- const saved = mockDpapi()
379
- new WindowsDpapiStore(env, { run: saved.runner }).save(SAMPLE)
380
- const failing = mockDpapi({ failUnprotect: true })
381
- expect(new WindowsDpapiStore(env, { run: failing.runner }).load()).toBeNull()
382
- assertNoSecretInArgs([...saved.calls, ...failing.calls])
383
- })
384
-
385
- it('refuses to save when LOCALAPPDATA is missing', () => {
386
- const store = new WindowsDpapiStore({}, { run: mockDpapi().runner })
387
- expect(store.load()).toBeNull()
388
- expect(() => store.save(SAMPLE)).toThrow(/LOCALAPPDATA is missing/)
389
- expect(store.describe()).toBe('Windows DPAPI current-user (LOCALAPPDATA unset)')
390
- store.clear()
391
- })
392
-
393
- it('does not invoke a process for a missing or corrupt file', () => {
394
- const { env } = sandbox('dpapi-no-process')
395
- const { runner, calls } = mockDpapi()
396
- const store = new WindowsDpapiStore(env, { run: runner })
397
- expect(store.load()).toBeNull()
398
- const file = path.join(env.LOCALAPPDATA!, 'notifai', 'credentials.dpapi')
399
- writeRaw(file, 'corrupt')
400
- expect(store.load()).toBeNull()
401
- expect(calls).toEqual([])
402
- })
403
- })