@raidiant/notifai 10.1.0 → 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 (204) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +3 -0
  3. package/dist/cli-bin.d.ts +21 -1
  4. package/dist/cli-bin.js +141 -10
  5. package/dist/cli-bin.js.map +1 -1
  6. package/dist/cli-update-contract.d.ts +7 -0
  7. package/dist/cli-update-contract.js +10 -0
  8. package/dist/cli-update-contract.js.map +1 -0
  9. package/dist/client.d.ts +6 -1
  10. package/dist/client.js +1 -0
  11. package/dist/client.js.map +1 -1
  12. package/dist/codex-wake.d.ts +2 -0
  13. package/dist/codex-wake.js +2 -1
  14. package/dist/codex-wake.js.map +1 -1
  15. package/dist/commands-auth.d.ts +15 -1
  16. package/dist/commands-auth.js +29 -11
  17. package/dist/commands-auth.js.map +1 -1
  18. package/dist/commands-core.d.ts +9 -2
  19. package/dist/commands-core.js +11 -4
  20. package/dist/commands-core.js.map +1 -1
  21. package/dist/commands-devices.d.ts +10 -1
  22. package/dist/commands-devices.js +17 -13
  23. package/dist/commands-devices.js.map +1 -1
  24. package/dist/commands-doctor.js +93 -49
  25. package/dist/commands-doctor.js.map +1 -1
  26. package/dist/commands-hooks.js +47 -10
  27. package/dist/commands-hooks.js.map +1 -1
  28. package/dist/commands-init.d.ts +16 -0
  29. package/dist/commands-init.js +254 -93
  30. package/dist/commands-init.js.map +1 -1
  31. package/dist/commands-send-support.js +3 -0
  32. package/dist/commands-send-support.js.map +1 -1
  33. package/dist/commands-send.d.ts +1 -1
  34. package/dist/commands-send.js +121 -35
  35. package/dist/commands-send.js.map +1 -1
  36. package/dist/commands-skill.js +72 -54
  37. package/dist/commands-skill.js.map +1 -1
  38. package/dist/commands-update.d.ts +10 -0
  39. package/dist/commands-update.js +141 -0
  40. package/dist/commands-update.js.map +1 -0
  41. package/dist/commands.d.ts +2 -1
  42. package/dist/commands.js +2 -1
  43. package/dist/commands.js.map +1 -1
  44. package/dist/hook-adapter.d.ts +2 -0
  45. package/dist/hook-adapter.js +12 -1
  46. package/dist/hook-adapter.js.map +1 -1
  47. package/dist/hooks.d.ts +43 -2
  48. package/dist/hooks.js +163 -21
  49. package/dist/hooks.js.map +1 -1
  50. package/dist/invocation-context.d.ts +1 -0
  51. package/dist/invocation-context.js +9 -1
  52. package/dist/invocation-context.js.map +1 -1
  53. package/dist/main-run.d.ts +1 -0
  54. package/dist/main-run.js +42 -0
  55. package/dist/main-run.js.map +1 -0
  56. package/dist/main.js +10 -31
  57. package/dist/main.js.map +1 -1
  58. package/dist/native-skills.d.ts +13 -3
  59. package/dist/native-skills.js +51 -12
  60. package/dist/native-skills.js.map +1 -1
  61. package/dist/node-floor.d.ts +19 -0
  62. package/dist/node-floor.js +39 -0
  63. package/dist/node-floor.js.map +1 -0
  64. package/dist/orca-session-title.d.ts +5 -4
  65. package/dist/orca-session-title.js +32 -19
  66. package/dist/orca-session-title.js.map +1 -1
  67. package/dist/platform.d.ts +11 -17
  68. package/dist/platform.js +20 -23
  69. package/dist/platform.js.map +1 -1
  70. package/dist/program.d.ts +2 -1
  71. package/dist/program.js +22 -5
  72. package/dist/program.js.map +1 -1
  73. package/dist/question-settlement-process.d.ts +15 -0
  74. package/dist/question-settlement-process.js +35 -0
  75. package/dist/question-settlement-process.js.map +1 -0
  76. package/dist/readiness.d.ts +25 -1
  77. package/dist/readiness.js +32 -2
  78. package/dist/readiness.js.map +1 -1
  79. package/dist/release.d.ts +5 -5
  80. package/dist/release.js +5 -5
  81. package/dist/setup-destinations.d.ts +23 -0
  82. package/dist/setup-destinations.js +44 -0
  83. package/dist/setup-destinations.js.map +1 -0
  84. package/dist/skill-integrity.d.ts +49 -0
  85. package/dist/skill-integrity.js +154 -0
  86. package/dist/skill-integrity.js.map +1 -0
  87. package/dist/skill-source/manifest.json +16 -0
  88. package/dist/skill-source/notifai/SKILL.md +390 -0
  89. package/dist/skill-source/notifai/references/harness-setup.md +220 -0
  90. package/package.json +11 -14
  91. package/src/atomic-file.ts +0 -198
  92. package/src/claude-wake.test.ts +0 -321
  93. package/src/claude-wake.ts +0 -499
  94. package/src/cli-bin.test.ts +0 -38
  95. package/src/cli-bin.ts +0 -67
  96. package/src/cli-release.test.ts +0 -46
  97. package/src/cli-release.ts +0 -78
  98. package/src/client.test.ts +0 -390
  99. package/src/client.ts +0 -345
  100. package/src/codex-wake.test.ts +0 -254
  101. package/src/codex-wake.ts +0 -297
  102. package/src/command-session.ts +0 -38
  103. package/src/commands-agent-sessions.ts +0 -72
  104. package/src/commands-auth.ts +0 -205
  105. package/src/commands-config.ts +0 -336
  106. package/src/commands-core.ts +0 -298
  107. package/src/commands-devices.test.ts +0 -15
  108. package/src/commands-devices.ts +0 -173
  109. package/src/commands-doctor.ts +0 -1440
  110. package/src/commands-guidance.ts +0 -181
  111. package/src/commands-harness-context.ts +0 -207
  112. package/src/commands-hook-shape.ts +0 -69
  113. package/src/commands-hooks.ts +0 -2268
  114. package/src/commands-init.ts +0 -878
  115. package/src/commands-io.ts +0 -108
  116. package/src/commands-logs.ts +0 -243
  117. package/src/commands-project.ts +0 -47
  118. package/src/commands-send-support.test.ts +0 -156
  119. package/src/commands-send-support.ts +0 -311
  120. package/src/commands-send.ts +0 -769
  121. package/src/commands-setup-proof.test.ts +0 -72
  122. package/src/commands-setup-proof.ts +0 -124
  123. package/src/commands-skill.test.ts +0 -44
  124. package/src/commands-skill.ts +0 -204
  125. package/src/commands-sounds.test.ts +0 -106
  126. package/src/commands-sounds.ts +0 -49
  127. package/src/commands.test.ts +0 -7828
  128. package/src/commands.ts +0 -75
  129. package/src/config-schema.test.ts +0 -153
  130. package/src/config-schema.ts +0 -349
  131. package/src/config.test.ts +0 -581
  132. package/src/config.ts +0 -475
  133. package/src/credentials.test.ts +0 -403
  134. package/src/credentials.ts +0 -403
  135. package/src/file-lock-process-worker.test.ts +0 -64
  136. package/src/file-lock.test.ts +0 -320
  137. package/src/file-lock.ts +0 -393
  138. package/src/fixtures/hermes-0.20.6-classic-cli-local.json +0 -50
  139. package/src/fixtures/openclaw-2026.7.1-2-agent-local.json +0 -57
  140. package/src/generated-session-label.ts +0 -155
  141. package/src/guidance-content.ts +0 -278
  142. package/src/guidance-render.ts +0 -56
  143. package/src/guidance.test.ts +0 -327
  144. package/src/guidance.ts +0 -233
  145. package/src/harness-integration.test.ts +0 -294
  146. package/src/harnesses.test.ts +0 -149
  147. package/src/harnesses.ts +0 -164
  148. package/src/hook-adapter.test.ts +0 -496
  149. package/src/hook-adapter.ts +0 -410
  150. package/src/hook-input.test.ts +0 -39
  151. package/src/hook-input.ts +0 -72
  152. package/src/hooks.test.ts +0 -5549
  153. package/src/hooks.ts +0 -3759
  154. package/src/install-hooks.test.ts +0 -1614
  155. package/src/install-hooks.ts +0 -1501
  156. package/src/interactive.test.ts +0 -387
  157. package/src/interactive.ts +0 -858
  158. package/src/invocation-context.test.ts +0 -352
  159. package/src/invocation-context.ts +0 -197
  160. package/src/logging-process-worker.test.ts +0 -45
  161. package/src/logging.test.ts +0 -544
  162. package/src/logging.ts +0 -698
  163. package/src/main.ts +0 -36
  164. package/src/native-skills.test.ts +0 -115
  165. package/src/native-skills.ts +0 -162
  166. package/src/onboarding-docs.test.ts +0 -25
  167. package/src/openclaw-plugin.ts +0 -409
  168. package/src/opencode-plugin.ts +0 -298
  169. package/src/orca-session-title.test.ts +0 -54
  170. package/src/orca-session-title.ts +0 -103
  171. package/src/pack-feedback-slice.test.ts +0 -212
  172. package/src/pack-feedback-slice.ts +0 -187
  173. package/src/platform.test.ts +0 -152
  174. package/src/platform.ts +0 -173
  175. package/src/program.test.ts +0 -282
  176. package/src/program.ts +0 -818
  177. package/src/project-enablement.test.ts +0 -55
  178. package/src/project-enablement.ts +0 -99
  179. package/src/question-caps.test.ts +0 -49
  180. package/src/question-timing.ts +0 -56
  181. package/src/readiness.test.ts +0 -25
  182. package/src/readiness.ts +0 -179
  183. package/src/release.ts +0 -51
  184. package/src/send-attempts.test.ts +0 -143
  185. package/src/send-attempts.ts +0 -188
  186. package/src/send.test.ts +0 -28
  187. package/src/send.ts +0 -436
  188. package/src/session-activation.ts +0 -61
  189. package/src/session-end-log-lock-worker.test.ts +0 -35
  190. package/src/session-labels.test.ts +0 -490
  191. package/src/session-labels.ts +0 -474
  192. package/src/skill.test.ts +0 -415
  193. package/src/sound-ref.test.ts +0 -31
  194. package/src/sound-ref.ts +0 -34
  195. package/src/trust-policy.test.ts +0 -701
  196. package/src/ui/banner.ts +0 -95
  197. package/src/ui/config-view.test.ts +0 -90
  198. package/src/ui/config-view.ts +0 -138
  199. package/src/ui/help.test.ts +0 -16
  200. package/src/ui/help.ts +0 -128
  201. package/src/ui/theme.test.ts +0 -92
  202. package/src/ui/theme.ts +0 -265
  203. package/src/url-policy.ts +0 -399
  204. 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
- })