@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.
- package/CHANGELOG.md +37 -0
- package/README.md +3 -0
- package/dist/cli-bin.d.ts +21 -1
- package/dist/cli-bin.js +141 -10
- package/dist/cli-bin.js.map +1 -1
- package/dist/cli-update-contract.d.ts +7 -0
- package/dist/cli-update-contract.js +10 -0
- package/dist/cli-update-contract.js.map +1 -0
- package/dist/client.d.ts +6 -1
- package/dist/client.js +1 -0
- package/dist/client.js.map +1 -1
- package/dist/codex-wake.d.ts +2 -0
- package/dist/codex-wake.js +2 -1
- package/dist/codex-wake.js.map +1 -1
- package/dist/commands-auth.d.ts +15 -1
- package/dist/commands-auth.js +29 -11
- package/dist/commands-auth.js.map +1 -1
- package/dist/commands-core.d.ts +9 -2
- package/dist/commands-core.js +11 -4
- package/dist/commands-core.js.map +1 -1
- package/dist/commands-devices.d.ts +10 -1
- package/dist/commands-devices.js +17 -13
- package/dist/commands-devices.js.map +1 -1
- package/dist/commands-doctor.js +93 -49
- package/dist/commands-doctor.js.map +1 -1
- package/dist/commands-hooks.js +47 -10
- package/dist/commands-hooks.js.map +1 -1
- package/dist/commands-init.d.ts +16 -0
- package/dist/commands-init.js +254 -93
- package/dist/commands-init.js.map +1 -1
- package/dist/commands-send-support.js +3 -0
- package/dist/commands-send-support.js.map +1 -1
- package/dist/commands-send.d.ts +1 -1
- package/dist/commands-send.js +121 -35
- package/dist/commands-send.js.map +1 -1
- package/dist/commands-skill.js +72 -54
- package/dist/commands-skill.js.map +1 -1
- package/dist/commands-update.d.ts +10 -0
- package/dist/commands-update.js +141 -0
- package/dist/commands-update.js.map +1 -0
- package/dist/commands.d.ts +2 -1
- package/dist/commands.js +2 -1
- package/dist/commands.js.map +1 -1
- package/dist/hook-adapter.d.ts +2 -0
- package/dist/hook-adapter.js +12 -1
- package/dist/hook-adapter.js.map +1 -1
- package/dist/hooks.d.ts +43 -2
- package/dist/hooks.js +163 -21
- package/dist/hooks.js.map +1 -1
- package/dist/invocation-context.d.ts +1 -0
- package/dist/invocation-context.js +9 -1
- package/dist/invocation-context.js.map +1 -1
- package/dist/main-run.d.ts +1 -0
- package/dist/main-run.js +42 -0
- package/dist/main-run.js.map +1 -0
- package/dist/main.js +10 -31
- package/dist/main.js.map +1 -1
- package/dist/native-skills.d.ts +13 -3
- package/dist/native-skills.js +51 -12
- package/dist/native-skills.js.map +1 -1
- package/dist/node-floor.d.ts +19 -0
- package/dist/node-floor.js +39 -0
- package/dist/node-floor.js.map +1 -0
- package/dist/orca-session-title.d.ts +5 -4
- package/dist/orca-session-title.js +32 -19
- package/dist/orca-session-title.js.map +1 -1
- package/dist/platform.d.ts +11 -17
- package/dist/platform.js +20 -23
- package/dist/platform.js.map +1 -1
- package/dist/program.d.ts +2 -1
- package/dist/program.js +22 -5
- package/dist/program.js.map +1 -1
- package/dist/question-settlement-process.d.ts +15 -0
- package/dist/question-settlement-process.js +35 -0
- package/dist/question-settlement-process.js.map +1 -0
- package/dist/readiness.d.ts +25 -1
- package/dist/readiness.js +32 -2
- package/dist/readiness.js.map +1 -1
- package/dist/release.d.ts +5 -5
- package/dist/release.js +5 -5
- package/dist/setup-destinations.d.ts +23 -0
- package/dist/setup-destinations.js +44 -0
- package/dist/setup-destinations.js.map +1 -0
- package/dist/skill-integrity.d.ts +49 -0
- package/dist/skill-integrity.js +154 -0
- package/dist/skill-integrity.js.map +1 -0
- package/dist/skill-source/manifest.json +16 -0
- package/dist/skill-source/notifai/SKILL.md +390 -0
- package/dist/skill-source/notifai/references/harness-setup.md +220 -0
- package/package.json +11 -14
- package/src/atomic-file.ts +0 -198
- package/src/claude-wake.test.ts +0 -321
- package/src/claude-wake.ts +0 -499
- package/src/cli-bin.test.ts +0 -38
- package/src/cli-bin.ts +0 -67
- package/src/cli-release.test.ts +0 -46
- package/src/cli-release.ts +0 -78
- package/src/client.test.ts +0 -390
- package/src/client.ts +0 -345
- package/src/codex-wake.test.ts +0 -254
- package/src/codex-wake.ts +0 -297
- package/src/command-session.ts +0 -38
- package/src/commands-agent-sessions.ts +0 -72
- package/src/commands-auth.ts +0 -205
- package/src/commands-config.ts +0 -336
- package/src/commands-core.ts +0 -298
- package/src/commands-devices.test.ts +0 -15
- package/src/commands-devices.ts +0 -173
- package/src/commands-doctor.ts +0 -1440
- package/src/commands-guidance.ts +0 -181
- package/src/commands-harness-context.ts +0 -207
- package/src/commands-hook-shape.ts +0 -69
- package/src/commands-hooks.ts +0 -2268
- package/src/commands-init.ts +0 -878
- package/src/commands-io.ts +0 -108
- package/src/commands-logs.ts +0 -243
- package/src/commands-project.ts +0 -47
- package/src/commands-send-support.test.ts +0 -156
- package/src/commands-send-support.ts +0 -311
- package/src/commands-send.ts +0 -769
- package/src/commands-setup-proof.test.ts +0 -72
- package/src/commands-setup-proof.ts +0 -124
- package/src/commands-skill.test.ts +0 -44
- package/src/commands-skill.ts +0 -204
- package/src/commands-sounds.test.ts +0 -106
- package/src/commands-sounds.ts +0 -49
- package/src/commands.test.ts +0 -7828
- package/src/commands.ts +0 -75
- package/src/config-schema.test.ts +0 -153
- package/src/config-schema.ts +0 -349
- package/src/config.test.ts +0 -581
- package/src/config.ts +0 -475
- package/src/credentials.test.ts +0 -403
- package/src/credentials.ts +0 -403
- package/src/file-lock-process-worker.test.ts +0 -64
- package/src/file-lock.test.ts +0 -320
- package/src/file-lock.ts +0 -393
- package/src/fixtures/hermes-0.20.6-classic-cli-local.json +0 -50
- package/src/fixtures/openclaw-2026.7.1-2-agent-local.json +0 -57
- package/src/generated-session-label.ts +0 -155
- package/src/guidance-content.ts +0 -278
- package/src/guidance-render.ts +0 -56
- package/src/guidance.test.ts +0 -327
- package/src/guidance.ts +0 -233
- package/src/harness-integration.test.ts +0 -294
- package/src/harnesses.test.ts +0 -149
- package/src/harnesses.ts +0 -164
- package/src/hook-adapter.test.ts +0 -496
- package/src/hook-adapter.ts +0 -410
- package/src/hook-input.test.ts +0 -39
- package/src/hook-input.ts +0 -72
- package/src/hooks.test.ts +0 -5549
- package/src/hooks.ts +0 -3759
- package/src/install-hooks.test.ts +0 -1614
- package/src/install-hooks.ts +0 -1501
- package/src/interactive.test.ts +0 -387
- package/src/interactive.ts +0 -858
- package/src/invocation-context.test.ts +0 -352
- package/src/invocation-context.ts +0 -197
- package/src/logging-process-worker.test.ts +0 -45
- package/src/logging.test.ts +0 -544
- package/src/logging.ts +0 -698
- package/src/main.ts +0 -36
- package/src/native-skills.test.ts +0 -115
- package/src/native-skills.ts +0 -162
- package/src/onboarding-docs.test.ts +0 -25
- package/src/openclaw-plugin.ts +0 -409
- package/src/opencode-plugin.ts +0 -298
- package/src/orca-session-title.test.ts +0 -54
- package/src/orca-session-title.ts +0 -103
- package/src/pack-feedback-slice.test.ts +0 -212
- package/src/pack-feedback-slice.ts +0 -187
- package/src/platform.test.ts +0 -152
- package/src/platform.ts +0 -173
- package/src/program.test.ts +0 -282
- package/src/program.ts +0 -818
- package/src/project-enablement.test.ts +0 -55
- package/src/project-enablement.ts +0 -99
- package/src/question-caps.test.ts +0 -49
- package/src/question-timing.ts +0 -56
- package/src/readiness.test.ts +0 -25
- package/src/readiness.ts +0 -179
- package/src/release.ts +0 -51
- package/src/send-attempts.test.ts +0 -143
- package/src/send-attempts.ts +0 -188
- package/src/send.test.ts +0 -28
- package/src/send.ts +0 -436
- package/src/session-activation.ts +0 -61
- package/src/session-end-log-lock-worker.test.ts +0 -35
- package/src/session-labels.test.ts +0 -490
- package/src/session-labels.ts +0 -474
- package/src/skill.test.ts +0 -415
- package/src/sound-ref.test.ts +0 -31
- package/src/sound-ref.ts +0 -34
- package/src/trust-policy.test.ts +0 -701
- package/src/ui/banner.ts +0 -95
- package/src/ui/config-view.test.ts +0 -90
- package/src/ui/config-view.ts +0 -138
- package/src/ui/help.test.ts +0 -16
- package/src/ui/help.ts +0 -128
- package/src/ui/theme.test.ts +0 -92
- package/src/ui/theme.ts +0 -265
- package/src/url-policy.ts +0 -399
- package/tsconfig.json +0 -10
package/src/logging.test.ts
DELETED
|
@@ -1,544 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process'
|
|
2
|
-
import {
|
|
3
|
-
appendFileSync,
|
|
4
|
-
existsSync,
|
|
5
|
-
mkdtempSync,
|
|
6
|
-
readFileSync,
|
|
7
|
-
statSync,
|
|
8
|
-
writeFileSync,
|
|
9
|
-
} from 'node:fs'
|
|
10
|
-
import os from 'node:os'
|
|
11
|
-
import path from 'node:path'
|
|
12
|
-
import { describe, expect, it } from 'vitest'
|
|
13
|
-
import {
|
|
14
|
-
LOG_SCHEMA_VERSION,
|
|
15
|
-
activeLogPath,
|
|
16
|
-
archiveLogPaths,
|
|
17
|
-
argvFlagNames,
|
|
18
|
-
createLogger,
|
|
19
|
-
logsDiskUsage,
|
|
20
|
-
nullLogger,
|
|
21
|
-
readLogRecords,
|
|
22
|
-
renderRecord,
|
|
23
|
-
serialize,
|
|
24
|
-
shape,
|
|
25
|
-
type LogRecord,
|
|
26
|
-
} from './logging.js'
|
|
27
|
-
|
|
28
|
-
function sandbox(): NodeJS.ProcessEnv {
|
|
29
|
-
return { XDG_STATE_HOME: mkdtempSync(path.join(os.tmpdir(), 'notifai-logs-')) }
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function lines(env: NodeJS.ProcessEnv): LogRecord[] {
|
|
33
|
-
return readFileSync(activeLogPath(env), 'utf8')
|
|
34
|
-
.split('\n')
|
|
35
|
-
.filter((line) => line.trim() !== '')
|
|
36
|
-
.map((line) => JSON.parse(line) as LogRecord)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async function waitUntil(predicate: () => boolean, deadline: number): Promise<void> {
|
|
40
|
-
while (!predicate()) {
|
|
41
|
-
if (Date.now() >= deadline) throw new Error('timed out waiting for rotation workers')
|
|
42
|
-
await new Promise((resolve) => setTimeout(resolve, 5))
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface RotationRun {
|
|
47
|
-
env: NodeJS.ProcessEnv
|
|
48
|
-
worker: number
|
|
49
|
-
records: number
|
|
50
|
-
maxBytes: number
|
|
51
|
-
maxFiles: number
|
|
52
|
-
startPath: string
|
|
53
|
-
/**
|
|
54
|
-
* When the rendezvous has failed, as an absolute instant every participant
|
|
55
|
-
* reads the same way. A per-side countdown would let the first worker to
|
|
56
|
-
* report ready abandon a parent that is still waiting for the last one.
|
|
57
|
-
*/
|
|
58
|
-
deadline: number
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function rotationWorker(run: RotationRun): { readyPath: string; done: Promise<void> } {
|
|
62
|
-
const { env, worker } = run
|
|
63
|
-
const readyPath = path.join(env['XDG_STATE_HOME']!, `rotation-ready-${worker}`)
|
|
64
|
-
const vitest = path.join(process.cwd(), 'node_modules', 'vitest', 'vitest.mjs')
|
|
65
|
-
const child = spawn(
|
|
66
|
-
process.execPath,
|
|
67
|
-
[vitest, 'run', 'src/logging-process-worker.test.ts', '--reporter=dot', '--maxWorkers=1'],
|
|
68
|
-
{
|
|
69
|
-
cwd: process.cwd(),
|
|
70
|
-
env: {
|
|
71
|
-
...process.env,
|
|
72
|
-
...env,
|
|
73
|
-
NOTIFAI_ROTATION_WORKER: String(worker),
|
|
74
|
-
NOTIFAI_ROTATION_RECORDS: String(run.records),
|
|
75
|
-
NOTIFAI_ROTATION_MAX_BYTES: String(run.maxBytes),
|
|
76
|
-
NOTIFAI_ROTATION_MAX_FILES: String(run.maxFiles),
|
|
77
|
-
NOTIFAI_ROTATION_READY: readyPath,
|
|
78
|
-
NOTIFAI_ROTATION_START: run.startPath,
|
|
79
|
-
NOTIFAI_ROTATION_DEADLINE: String(run.deadline),
|
|
80
|
-
},
|
|
81
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
82
|
-
},
|
|
83
|
-
)
|
|
84
|
-
const stdout: Buffer[] = []
|
|
85
|
-
const stderr: Buffer[] = []
|
|
86
|
-
child.stdout.on('data', (chunk: Buffer) => stdout.push(chunk))
|
|
87
|
-
child.stderr.on('data', (chunk: Buffer) => stderr.push(chunk))
|
|
88
|
-
const done = new Promise<void>((resolve, reject) => {
|
|
89
|
-
child.once('error', reject)
|
|
90
|
-
child.once('exit', (code) => {
|
|
91
|
-
if (code === 0) resolve()
|
|
92
|
-
else {
|
|
93
|
-
reject(
|
|
94
|
-
new Error(
|
|
95
|
-
`rotation worker ${worker} exited ${String(code)}\n${Buffer.concat(stdout).toString()}\n${Buffer.concat(stderr).toString()}`,
|
|
96
|
-
),
|
|
97
|
-
)
|
|
98
|
-
}
|
|
99
|
-
})
|
|
100
|
-
})
|
|
101
|
-
return { readyPath, done }
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
describe('the record', () => {
|
|
105
|
-
it('is one self-describing JSON object per line', () => {
|
|
106
|
-
const env = sandbox()
|
|
107
|
-
const logger = createLogger({ env, cmd: 'send', runId: 'r_test' })
|
|
108
|
-
logger.info('send.submitted', { request_id: 'req_1' })
|
|
109
|
-
logger.info('send.outcome', { request_id: 'req_1' })
|
|
110
|
-
|
|
111
|
-
const written = lines(env)
|
|
112
|
-
expect(written).toHaveLength(2)
|
|
113
|
-
// Every line stands alone: a line pulled out by grep, with no header and no
|
|
114
|
-
// neighbours, still says what it is and which run it belongs to.
|
|
115
|
-
for (const record of written) {
|
|
116
|
-
expect(record.v).toBe(LOG_SCHEMA_VERSION)
|
|
117
|
-
expect(record.run).toBe('r_test')
|
|
118
|
-
expect(record.cmd).toBe('send')
|
|
119
|
-
expect(record.pid).toBe(process.pid)
|
|
120
|
-
expect(() => new Date(record.ts).toISOString()).not.toThrow()
|
|
121
|
-
}
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
it('carries the project and session once bound', () => {
|
|
125
|
-
const env = sandbox()
|
|
126
|
-
const logger = createLogger({ env })
|
|
127
|
-
logger.bind({ project: 'notifai', session: 'sess-1' })
|
|
128
|
-
logger.info('hook.start', {})
|
|
129
|
-
expect(lines(env)[0]).toMatchObject({ project: 'notifai', session: 'sess-1' })
|
|
130
|
-
})
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
describe('level', () => {
|
|
134
|
-
it('records nothing at off', () => {
|
|
135
|
-
const env = sandbox()
|
|
136
|
-
const logger = createLogger({ env, settings: { level: 'off' } })
|
|
137
|
-
logger.error('cli.error', {})
|
|
138
|
-
expect(logsDiskUsage(env).files).toBe(0)
|
|
139
|
-
expect(logger.enabled).toBe(false)
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
it('drops debug below debug, and keeps it at debug', () => {
|
|
143
|
-
const quiet = sandbox()
|
|
144
|
-
createLogger({ env: quiet, settings: { level: 'info' } }).debug('http.call', {})
|
|
145
|
-
expect(logsDiskUsage(quiet).files).toBe(0)
|
|
146
|
-
|
|
147
|
-
const loud = sandbox()
|
|
148
|
-
createLogger({ env: loud, settings: { level: 'debug' } }).debug('http.call', {})
|
|
149
|
-
expect(lines(loud)).toHaveLength(1)
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
it('keeps errors at the error level and nothing else', () => {
|
|
153
|
-
const env = sandbox()
|
|
154
|
-
const logger = createLogger({ env, settings: { level: 'error' } })
|
|
155
|
-
logger.info('cli.end', {})
|
|
156
|
-
logger.error('cli.error', {})
|
|
157
|
-
expect(lines(env).map((record) => record.event)).toEqual(['cli.error'])
|
|
158
|
-
})
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
describe('redaction', () => {
|
|
162
|
-
it('never writes a machine token, wherever it appears', () => {
|
|
163
|
-
const env = sandbox()
|
|
164
|
-
const logger = createLogger({ env })
|
|
165
|
-
logger.info('http.call', {
|
|
166
|
-
authorization: 'Bearer nfm_abc123.supersecretvalue',
|
|
167
|
-
message: 'rejected credential nfm_abc123.supersecretvalue for this machine',
|
|
168
|
-
nested: { poll_verifier: 'v_secret', fine: 'kept' },
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
const raw = readFileSync(activeLogPath(env), 'utf8')
|
|
172
|
-
expect(raw).not.toContain('supersecretvalue')
|
|
173
|
-
expect(raw).not.toContain('v_secret')
|
|
174
|
-
expect(raw).toContain('kept')
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
it('redacts by key name regardless of the value', () => {
|
|
178
|
-
expect(shape({ api_key: 12345, token: null, other: 'ok' })).toEqual({
|
|
179
|
-
api_key: '[redacted]',
|
|
180
|
-
token: '[redacted]',
|
|
181
|
-
other: 'ok',
|
|
182
|
-
})
|
|
183
|
-
})
|
|
184
|
-
|
|
185
|
-
it('truncates a long string instead of carrying it whole', () => {
|
|
186
|
-
const shaped = shape({ detail: 'x'.repeat(1000) }) as { detail: string }
|
|
187
|
-
expect(shaped.detail.length).toBeLessThan(500)
|
|
188
|
-
expect(shaped.detail).toContain('+600 chars')
|
|
189
|
-
})
|
|
190
|
-
|
|
191
|
-
it('never persists notification content, answers, or raw argv at debug', () => {
|
|
192
|
-
const env = sandbox()
|
|
193
|
-
const logger = createLogger({ env, settings: { level: 'debug' } })
|
|
194
|
-
logger.debug('cli.start', {
|
|
195
|
-
argv: ['send', '--title', 'SECRET_TITLE', '--body', 'SECRET_BODY'],
|
|
196
|
-
title: 'SECRET_TITLE',
|
|
197
|
-
body: 'SECRET_BODY',
|
|
198
|
-
question: 'SECRET_QUESTION',
|
|
199
|
-
text: 'SECRET_REPLY',
|
|
200
|
-
answers: ['SECRET_ANSWER'],
|
|
201
|
-
choices: ['SECRET_CHOICE'],
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
const raw = readFileSync(activeLogPath(env), 'utf8')
|
|
205
|
-
expect(raw).not.toContain('SECRET_TITLE')
|
|
206
|
-
expect(raw).not.toContain('SECRET_BODY')
|
|
207
|
-
expect(raw).not.toContain('SECRET_QUESTION')
|
|
208
|
-
expect(raw).not.toContain('SECRET_REPLY')
|
|
209
|
-
expect(raw).not.toContain('SECRET_ANSWER')
|
|
210
|
-
expect(raw).not.toContain('SECRET_CHOICE')
|
|
211
|
-
const record = JSON.parse(raw) as LogRecord
|
|
212
|
-
expect(record.data).toMatchObject({
|
|
213
|
-
title_chars: 'SECRET_TITLE'.length,
|
|
214
|
-
body_chars: 'SECRET_BODY'.length,
|
|
215
|
-
question_chars: 'SECRET_QUESTION'.length,
|
|
216
|
-
text_chars: 'SECRET_REPLY'.length,
|
|
217
|
-
answers_count: 1,
|
|
218
|
-
choices_count: 1,
|
|
219
|
-
argv_count: 5,
|
|
220
|
-
flags: ['--title', '--body'],
|
|
221
|
-
})
|
|
222
|
-
expect(record.data).not.toHaveProperty('argv')
|
|
223
|
-
expect(record.data).not.toHaveProperty('title')
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
it('strips inline --name=value assignments so notification content is never logged', () => {
|
|
227
|
-
const inlineTitle = 'private title words'
|
|
228
|
-
const inlineBody = 'private body words'
|
|
229
|
-
expect(
|
|
230
|
-
argvFlagNames(['send', `--title=${inlineTitle}`, `--body=${inlineBody}`, '--reply', '--']),
|
|
231
|
-
).toEqual(['--title', '--body', '--reply'])
|
|
232
|
-
|
|
233
|
-
const env = sandbox()
|
|
234
|
-
const logger = createLogger({ env, settings: { level: 'debug' } })
|
|
235
|
-
logger.debug('cli.start', {
|
|
236
|
-
argv: ['send', `--title=${inlineTitle}`, `--body=${inlineBody}`, 'plain'],
|
|
237
|
-
})
|
|
238
|
-
|
|
239
|
-
const raw = readFileSync(activeLogPath(env), 'utf8')
|
|
240
|
-
expect(raw).not.toContain(inlineTitle)
|
|
241
|
-
expect(raw).not.toContain(inlineBody)
|
|
242
|
-
expect(shape({ argv: ['send', `--title=${inlineTitle}`, '--choice=yes'] })).toEqual({
|
|
243
|
-
flags: ['--title', '--choice'],
|
|
244
|
-
argv_count: 3,
|
|
245
|
-
})
|
|
246
|
-
const record = JSON.parse(raw) as LogRecord
|
|
247
|
-
expect(record.data).toMatchObject({
|
|
248
|
-
flags: ['--title', '--body'],
|
|
249
|
-
argv_count: 4,
|
|
250
|
-
})
|
|
251
|
-
})
|
|
252
|
-
|
|
253
|
-
it('refuses to recurse for ever into a cyclic object', () => {
|
|
254
|
-
const cyclic: Record<string, unknown> = {}
|
|
255
|
-
cyclic['self'] = cyclic
|
|
256
|
-
expect(() => JSON.stringify(shape(cyclic))).not.toThrow()
|
|
257
|
-
})
|
|
258
|
-
})
|
|
259
|
-
|
|
260
|
-
describe('record size', () => {
|
|
261
|
-
it('drops an oversized payload rather than the event', () => {
|
|
262
|
-
const record: LogRecord = {
|
|
263
|
-
v: LOG_SCHEMA_VERSION,
|
|
264
|
-
ts: new Date(0).toISOString(),
|
|
265
|
-
level: 'info',
|
|
266
|
-
event: 'send.submitted',
|
|
267
|
-
run: 'r_1',
|
|
268
|
-
cmd: 'send',
|
|
269
|
-
pid: 1,
|
|
270
|
-
data: Object.fromEntries(Array.from({ length: 400 }, (_, i) => [`k${i}`, 'y'.repeat(300)])),
|
|
271
|
-
}
|
|
272
|
-
const line = serialize(record)
|
|
273
|
-
// Small enough to land in one write, which is what makes concurrent
|
|
274
|
-
// appends safe — and the event survives even though its detail did not.
|
|
275
|
-
expect(Buffer.byteLength(line)).toBeLessThan(8_000)
|
|
276
|
-
const parsed = JSON.parse(line) as LogRecord
|
|
277
|
-
expect(parsed.event).toBe('send.submitted')
|
|
278
|
-
expect(parsed.data).toMatchObject({ dropped: expect.any(String) })
|
|
279
|
-
})
|
|
280
|
-
})
|
|
281
|
-
|
|
282
|
-
describe('rotation', () => {
|
|
283
|
-
it('rotates at the byte cap and keeps only the configured files', () => {
|
|
284
|
-
const env = sandbox()
|
|
285
|
-
const logger = createLogger({ env, settings: { maxBytes: 700, maxFiles: 3 } })
|
|
286
|
-
for (let i = 0; i < 60; i += 1) logger.info('cli.end', { i, pad: 'p'.repeat(50) })
|
|
287
|
-
|
|
288
|
-
const usage = logsDiskUsage(env)
|
|
289
|
-
expect(usage.files).toBe(3)
|
|
290
|
-
expect(archiveLogPaths(env)).toHaveLength(2)
|
|
291
|
-
// The whole point: bounded. Every retained file obeys the configured cap,
|
|
292
|
-
// however long the agent runs.
|
|
293
|
-
expect(usage.bytes).toBeLessThanOrEqual(3 * 700)
|
|
294
|
-
for (const file of [activeLogPath(env), ...archiveLogPaths(env)]) {
|
|
295
|
-
expect(statSync(file).size).toBeLessThanOrEqual(700)
|
|
296
|
-
}
|
|
297
|
-
})
|
|
298
|
-
|
|
299
|
-
it('leaves a marker in the fresh file so a gap is explained, not inferred', () => {
|
|
300
|
-
const env = sandbox()
|
|
301
|
-
const logger = createLogger({ env, settings: { maxBytes: 700, maxFiles: 3 } })
|
|
302
|
-
for (let i = 0; i < 20; i += 1) logger.info('cli.end', { i, pad: 'p'.repeat(40) })
|
|
303
|
-
expect(lines(env).some((record) => record.event === 'log.rotated')).toBe(true)
|
|
304
|
-
})
|
|
305
|
-
|
|
306
|
-
it('keeps only the active file when asked for one', () => {
|
|
307
|
-
const env = sandbox()
|
|
308
|
-
const logger = createLogger({ env, settings: { maxBytes: 300, maxFiles: 1 } })
|
|
309
|
-
for (let i = 0; i < 30; i += 1) logger.info('cli.end', { i, pad: 'p'.repeat(40) })
|
|
310
|
-
expect(archiveLogPaths(env)).toHaveLength(0)
|
|
311
|
-
expect(logsDiskUsage(env).files).toBe(1)
|
|
312
|
-
expect(statSync(activeLogPath(env)).size).toBeLessThanOrEqual(300)
|
|
313
|
-
})
|
|
314
|
-
|
|
315
|
-
it('keeps an indivisible record whole when an internal test injects an impossible cap', () => {
|
|
316
|
-
const env = sandbox()
|
|
317
|
-
const logger = createLogger({ env, settings: { maxBytes: 64, maxFiles: 3 } })
|
|
318
|
-
logger.info('cli.end', { sequence: 1 })
|
|
319
|
-
logger.info('cli.end', { sequence: 2 })
|
|
320
|
-
|
|
321
|
-
const files = [activeLogPath(env), ...archiveLogPaths(env)]
|
|
322
|
-
expect(files).toHaveLength(2)
|
|
323
|
-
for (const file of files) {
|
|
324
|
-
const records = readFileSync(file, 'utf8').split('\n').filter((line) => line !== '')
|
|
325
|
-
expect(records).toHaveLength(1)
|
|
326
|
-
expect(() => JSON.parse(records[0]!) as unknown).not.toThrow()
|
|
327
|
-
expect(statSync(file).size).toBeGreaterThan(64)
|
|
328
|
-
}
|
|
329
|
-
})
|
|
330
|
-
|
|
331
|
-
it('enforces the byte cap and preserves each record across overlapping processes', async () => {
|
|
332
|
-
const env = sandbox()
|
|
333
|
-
const workers = 4
|
|
334
|
-
const recordsPerWorker = 50
|
|
335
|
-
const maxBytes = 4_000
|
|
336
|
-
const maxFiles = 100
|
|
337
|
-
const startPath = path.join(env['XDG_STATE_HOME']!, 'rotation-start')
|
|
338
|
-
// Four cold Vitest processes have to reach the barrier before any of them
|
|
339
|
-
// writes, and a busy CI host schedules them far apart. The budget is shared,
|
|
340
|
-
// so it bounds the whole rendezvous rather than each side of it.
|
|
341
|
-
const deadline = Date.now() + 20_000
|
|
342
|
-
const children = Array.from({ length: workers }, (_, worker) =>
|
|
343
|
-
rotationWorker({ env, worker, records: recordsPerWorker, maxBytes, maxFiles, startPath, deadline }),
|
|
344
|
-
)
|
|
345
|
-
|
|
346
|
-
await waitUntil(() => children.every(({ readyPath }) => existsSync(readyPath)), deadline)
|
|
347
|
-
writeFileSync(startPath, 'go')
|
|
348
|
-
await Promise.all(children.map(({ done }) => done))
|
|
349
|
-
|
|
350
|
-
const files = [activeLogPath(env), ...archiveLogPaths(env)]
|
|
351
|
-
expect(files.length).toBeGreaterThan(1)
|
|
352
|
-
// The stat/rotate/append transaction is cross-process: no writer gets to
|
|
353
|
-
// consume budget another writer already claimed.
|
|
354
|
-
for (const file of files) expect(statSync(file).size).toBeLessThanOrEqual(maxBytes)
|
|
355
|
-
|
|
356
|
-
const seen = new Map<string, number>()
|
|
357
|
-
let retainedRecords = 0
|
|
358
|
-
for (const file of files) {
|
|
359
|
-
for (const line of readFileSync(file, 'utf8').split('\n')) {
|
|
360
|
-
if (line.trim() === '') continue
|
|
361
|
-
const record = JSON.parse(line) as LogRecord
|
|
362
|
-
if (record.event !== 'cli.end') continue
|
|
363
|
-
retainedRecords += 1
|
|
364
|
-
const key = `${String(record.data?.['worker'])}:${String(record.data?.['sequence'])}`
|
|
365
|
-
seen.set(key, (seen.get(key) ?? 0) + 1)
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
// Retention has room for every record, so neither a rotation nor an archive
|
|
369
|
-
// name race may lose or duplicate one.
|
|
370
|
-
expect(retainedRecords).toBe(workers * recordsPerWorker)
|
|
371
|
-
expect(seen.size).toBe(workers * recordsPerWorker)
|
|
372
|
-
// Name the offending records: a bare boolean would report a duplication bug
|
|
373
|
-
// as "expected false to be true" and leave the next reader nothing to go on.
|
|
374
|
-
expect([...seen].filter(([, count]) => count !== 1)).toEqual([])
|
|
375
|
-
}, 90_000)
|
|
376
|
-
})
|
|
377
|
-
|
|
378
|
-
describe('failure isolation', () => {
|
|
379
|
-
it('a sink that cannot write never throws at the caller', () => {
|
|
380
|
-
const env = sandbox()
|
|
381
|
-
// The logs directory's place is taken by a regular file, so every write
|
|
382
|
-
// below fails. A command must not care.
|
|
383
|
-
writeFileSync(path.join(env['XDG_STATE_HOME']!, 'notifai'), 'in the way')
|
|
384
|
-
const logger = createLogger({ env })
|
|
385
|
-
expect(() => logger.info('cli.end', { exit: 0 })).not.toThrow()
|
|
386
|
-
expect(logger.enabled).toBe(false)
|
|
387
|
-
})
|
|
388
|
-
|
|
389
|
-
it('the null logger accepts everything and records nothing', () => {
|
|
390
|
-
const logger = nullLogger()
|
|
391
|
-
expect(() => {
|
|
392
|
-
logger.info('cli.end', {})
|
|
393
|
-
logger.bind({ cmd: 'x' })
|
|
394
|
-
logger.adopt({ level: 'debug' })
|
|
395
|
-
}).not.toThrow()
|
|
396
|
-
expect(logger.enabled).toBe(false)
|
|
397
|
-
})
|
|
398
|
-
})
|
|
399
|
-
|
|
400
|
-
describe('reading', () => {
|
|
401
|
-
function seed(env: NodeJS.ProcessEnv): void {
|
|
402
|
-
const logger = createLogger({ env, runId: 'r_1', cmd: 'send' })
|
|
403
|
-
logger.bind({ project: 'alpha' })
|
|
404
|
-
logger.info('send.submitted', { request_id: 'req_alpha' })
|
|
405
|
-
logger.error('cli.error', { message: 'boom' })
|
|
406
|
-
const other = createLogger({ env, runId: 'r_2', cmd: 'ask' })
|
|
407
|
-
other.bind({ project: 'beta' })
|
|
408
|
-
other.info('ask.registered', { request_id: 'req_beta' })
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
it('returns records oldest first, so the result reads forwards', () => {
|
|
412
|
-
const env = sandbox()
|
|
413
|
-
seed(env)
|
|
414
|
-
const { records } = readLogRecords(env)
|
|
415
|
-
expect(records.map((record) => record.event)).toEqual([
|
|
416
|
-
'send.submitted',
|
|
417
|
-
'cli.error',
|
|
418
|
-
'ask.registered',
|
|
419
|
-
])
|
|
420
|
-
})
|
|
421
|
-
|
|
422
|
-
it('is bounded, and says when there is more behind it', () => {
|
|
423
|
-
const env = sandbox()
|
|
424
|
-
seed(env)
|
|
425
|
-
const { records, more } = readLogRecords(env, { limit: 1 })
|
|
426
|
-
// The newest, not the oldest: a limit exists to answer "what just
|
|
427
|
-
// happened", so cutting the recent end would defeat it.
|
|
428
|
-
expect(records.map((record) => record.event)).toEqual(['ask.registered'])
|
|
429
|
-
expect(more).toBe(true)
|
|
430
|
-
})
|
|
431
|
-
|
|
432
|
-
it('filters by run, project, event, and severity', () => {
|
|
433
|
-
const env = sandbox()
|
|
434
|
-
seed(env)
|
|
435
|
-
expect(readLogRecords(env, { run: 'r_1' }).records).toHaveLength(2)
|
|
436
|
-
expect(readLogRecords(env, { project: 'beta' }).records).toHaveLength(1)
|
|
437
|
-
expect(readLogRecords(env, { event: ['cli.error'] }).records).toHaveLength(1)
|
|
438
|
-
expect(readLogRecords(env, { level: 'error' }).records.map((r) => r.event)).toEqual(['cli.error'])
|
|
439
|
-
})
|
|
440
|
-
|
|
441
|
-
it('finds every record touching one notification request', () => {
|
|
442
|
-
const env = sandbox()
|
|
443
|
-
seed(env)
|
|
444
|
-
const { records } = readLogRecords(env, { request: 'req_alpha' })
|
|
445
|
-
expect(records).toHaveLength(1)
|
|
446
|
-
expect(records[0]!.event).toBe('send.submitted')
|
|
447
|
-
})
|
|
448
|
-
|
|
449
|
-
it('matches every structured request identity without prefix false positives', () => {
|
|
450
|
-
const env = sandbox()
|
|
451
|
-
const logger = createLogger({ env })
|
|
452
|
-
logger.info('send.submitted', { request_id: 'req_1' })
|
|
453
|
-
logger.info('send.submitted', { request_id: 'req_10' })
|
|
454
|
-
logger.info('hook.answer', { request_ids: ['req_1', 'req_10'], answered: false })
|
|
455
|
-
logger.error('cli.error', { request_ids: ['req_10'], message: 'req_1' })
|
|
456
|
-
|
|
457
|
-
const { records } = readLogRecords(env, { request: 'req_1' })
|
|
458
|
-
expect(records).toHaveLength(2)
|
|
459
|
-
expect(records.map((record) => record.event)).toEqual(['send.submitted', 'hook.answer'])
|
|
460
|
-
})
|
|
461
|
-
|
|
462
|
-
it('honours a time floor', () => {
|
|
463
|
-
const env = sandbox()
|
|
464
|
-
const early = createLogger({ env, now: () => Date.parse('2026-08-01T00:00:00Z') })
|
|
465
|
-
early.info('cli.end', { when: 'old' })
|
|
466
|
-
const late = createLogger({ env, now: () => Date.parse('2026-08-11T00:00:00Z') })
|
|
467
|
-
late.info('cli.end', { when: 'new' })
|
|
468
|
-
|
|
469
|
-
const { records } = readLogRecords(env, { since: Date.parse('2026-08-10T00:00:00Z') })
|
|
470
|
-
expect(records).toHaveLength(1)
|
|
471
|
-
expect(records[0]!.data).toMatchObject({ when: 'new' })
|
|
472
|
-
})
|
|
473
|
-
|
|
474
|
-
it('reads across archives when the active file is not enough', () => {
|
|
475
|
-
const env = sandbox()
|
|
476
|
-
const logger = createLogger({ env, settings: { maxBytes: 500, maxFiles: 5 } })
|
|
477
|
-
for (let i = 0; i < 30; i += 1) logger.info('cli.end', { i })
|
|
478
|
-
expect(archiveLogPaths(env).length).toBeGreaterThan(0)
|
|
479
|
-
const { records, files } = readLogRecords(env, { limit: 30, event: ['cli.end'] })
|
|
480
|
-
expect(files.length).toBeGreaterThan(1)
|
|
481
|
-
expect(records.length).toBeGreaterThan(lines(env).filter((r) => r.event === 'cli.end').length)
|
|
482
|
-
})
|
|
483
|
-
|
|
484
|
-
it('skips damaged and unknown-future lines without throwing away the file', () => {
|
|
485
|
-
const env = sandbox()
|
|
486
|
-
seed(env)
|
|
487
|
-
// A half-written line is what a crashed process leaves behind, and a
|
|
488
|
-
// reader that dies on it loses every good record around it.
|
|
489
|
-
appendFileSync(activeLogPath(env), '{"v":1,"ts":"2026-0\n')
|
|
490
|
-
appendFileSync(activeLogPath(env), 'not json at all\n')
|
|
491
|
-
appendFileSync(
|
|
492
|
-
activeLogPath(env),
|
|
493
|
-
`${JSON.stringify({
|
|
494
|
-
v: LOG_SCHEMA_VERSION + 1,
|
|
495
|
-
ts: '2026-08-18T12:00:00.000Z',
|
|
496
|
-
level: 'info',
|
|
497
|
-
event: 'future.event',
|
|
498
|
-
})}\n`,
|
|
499
|
-
)
|
|
500
|
-
expect(readLogRecords(env).records.map((record) => record.event)).toEqual([
|
|
501
|
-
'send.submitted',
|
|
502
|
-
'cli.error',
|
|
503
|
-
'ask.registered',
|
|
504
|
-
])
|
|
505
|
-
})
|
|
506
|
-
|
|
507
|
-
it('reports nothing at all rather than failing when there is no log', () => {
|
|
508
|
-
expect(readLogRecords(sandbox())).toMatchObject({ records: [], more: false })
|
|
509
|
-
})
|
|
510
|
-
})
|
|
511
|
-
|
|
512
|
-
describe('rendering', () => {
|
|
513
|
-
it('puts the fixed columns first so lines can be scanned, not read', () => {
|
|
514
|
-
const line = renderRecord({
|
|
515
|
-
v: 1,
|
|
516
|
-
ts: '2026-08-11T12:04:31.123Z',
|
|
517
|
-
level: 'info',
|
|
518
|
-
event: 'hook.gate',
|
|
519
|
-
run: 'r_1',
|
|
520
|
-
cmd: 'hook stop',
|
|
521
|
-
pid: 1,
|
|
522
|
-
data: { verdict: 'held', reason: 'notifications-off', source: 'default' },
|
|
523
|
-
})
|
|
524
|
-
expect(line).toContain('2026-08-11 12:04:31')
|
|
525
|
-
expect(line).toContain('hook.gate')
|
|
526
|
-
expect(line).toContain('reason=notifications-off')
|
|
527
|
-
expect(line).toContain('source=default')
|
|
528
|
-
})
|
|
529
|
-
|
|
530
|
-
it('stays on one line whatever the payload', () => {
|
|
531
|
-
const line = renderRecord({
|
|
532
|
-
v: 1,
|
|
533
|
-
ts: '2026-08-11T12:04:31.123Z',
|
|
534
|
-
level: 'error',
|
|
535
|
-
event: 'cli.error',
|
|
536
|
-
run: 'r_1',
|
|
537
|
-
cmd: 'send',
|
|
538
|
-
pid: 1,
|
|
539
|
-
data: { message: 'first\nsecond\nthird', big: 'z'.repeat(300) },
|
|
540
|
-
})
|
|
541
|
-
expect(line).not.toContain('\n')
|
|
542
|
-
expect(line.length).toBeLessThan(200)
|
|
543
|
-
})
|
|
544
|
-
})
|