@hop-top/kit 0.5.0-alpha.1 → 0.5.0-alpha.11
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 +275 -0
- package/LICENSE +1 -1
- package/LICENSE-cobra.txt +174 -0
- package/NOTICE +15 -0
- package/README.md +55 -259
- package/dist/aim-DZHwwiIc.d.ts +139 -0
- package/dist/aim.d.ts +1 -116
- package/dist/aim.js +13 -414
- package/dist/alias-D9_qFlyP.d.ts +174 -0
- package/dist/alias.d.ts +2 -73
- package/dist/alias.js +27 -207
- package/dist/api-DAexsu2H.d.ts +77 -0
- package/dist/api.d.ts +1 -62
- package/dist/api.js +10 -164
- package/dist/auth-2-jfgiHn.d.ts +34 -0
- package/dist/auth.d.ts +1 -26
- package/dist/auth.js +6 -40
- package/dist/chunk-3FIKGFKI.js +54 -0
- package/dist/chunk-4FMALWYB.js +669 -0
- package/dist/chunk-4GPCWBBA.js +143 -0
- package/dist/chunk-4UE5TCMQ.js +104 -0
- package/dist/chunk-65VPWMPV.js +1134 -0
- package/dist/chunk-6HFAEZ52.js +29 -0
- package/dist/chunk-6SVOHNIC.js +17 -0
- package/dist/chunk-BDNNPRX6.js +41 -0
- package/dist/chunk-BRNEKPWX.js +37 -0
- package/dist/chunk-BXJ2J27B.js +219 -0
- package/dist/chunk-CSJWB6D3.js +151 -0
- package/dist/chunk-CXBZTONY.js +65 -0
- package/dist/chunk-EE4M2UOF.js +818 -0
- package/dist/chunk-GFRAYYRD.js +817 -0
- package/dist/chunk-IVQHLI56.js +1890 -0
- package/dist/chunk-IZ6Q4SE3.js +178 -0
- package/dist/chunk-JKMQSAJP.js +174 -0
- package/dist/chunk-K7E34Q3A.js +1445 -0
- package/dist/chunk-KVG7YCTS.js +115 -0
- package/dist/chunk-L23O2FFE.js +51 -0
- package/dist/chunk-MFVUENZR.js +1549 -0
- package/dist/chunk-ML7D5DWY.js +263 -0
- package/dist/chunk-MQXYDYRD.js +968 -0
- package/dist/chunk-POR5L2DG.js +247 -0
- package/dist/chunk-QJVSKKRQ.js +369 -0
- package/dist/chunk-QQQYCWSC.js +240 -0
- package/dist/chunk-R5U7XKVJ.js +16 -0
- package/dist/chunk-RYKLVOVK.js +309 -0
- package/dist/chunk-SNVGDYX7.js +187 -0
- package/dist/chunk-T6OZMPPV.js +68 -0
- package/dist/chunk-UKZIAQA7.js +26 -0
- package/dist/chunk-VGOA5Y7S.js +251 -0
- package/dist/chunk-VWGP4NVJ.js +513 -0
- package/dist/chunk-WBVO43HU.js +355 -0
- package/dist/chunk-WUOAQVOA.js +86 -0
- package/dist/chunk-XJTRY453.js +868 -0
- package/dist/chunk-YOBAUCVN.js +583 -0
- package/dist/cli-RSRk1M36.d.ts +707 -0
- package/dist/cli.d.ts +7 -309
- package/dist/cli.js +125 -945
- package/dist/completion-csVun6SP.d.ts +112 -0
- package/dist/completion-values-By-mnjNt.d.ts +142 -0
- package/dist/completion-values.d.ts +1 -0
- package/dist/completion-values.js +29 -0
- package/dist/completion.d.ts +3 -0
- package/dist/completion.js +34 -0
- package/dist/compliance-AxFf-uMy.d.ts +60 -0
- package/dist/compliance.d.ts +1 -0
- package/dist/compliance.js +17 -0
- package/dist/config-CaK60ByQ.d.ts +241 -0
- package/dist/config.d.ts +1 -97
- package/dist/config.js +8 -78
- package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
- package/dist/errcorrect.d.ts +1 -37
- package/dist/errcorrect.js +8 -68
- package/dist/error-Do8Qji43.d.ts +231 -0
- package/dist/id/index.d.ts +2 -83
- package/dist/id/index.js +14 -65
- package/dist/index-BKJZClJx.d.ts +1486 -0
- package/dist/index-C3Zw4wDJ.d.ts +359 -0
- package/dist/index-CGE5yLBj.d.ts +328 -0
- package/dist/index-VLDcI5NF.d.ts +95 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +132 -0
- package/dist/llm-DYuR7_uX.d.ts +1069 -0
- package/dist/llm-anthropic-Cd_I2xXB.d.ts +67 -0
- package/dist/llm-anthropic.d.ts +2 -0
- package/dist/llm-anthropic.js +13 -0
- package/dist/llm-openai-DyFrucmV.d.ts +87 -0
- package/dist/llm-openai.d.ts +2 -0
- package/dist/llm-openai.js +19 -0
- package/dist/llm.d.ts +1 -188
- package/dist/llm.js +101 -356
- package/dist/log-CkaxMX3U.d.ts +115 -0
- package/dist/log.d.ts +2 -0
- package/dist/log.js +14 -0
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/index.js +185 -0
- package/dist/netpolicy-Brx5XZUB.d.ts +151 -0
- package/dist/netpolicy.d.ts +1 -0
- package/dist/netpolicy.js +25 -0
- package/dist/output-CjZWmL8s.d.ts +420 -0
- package/dist/output.d.ts +3 -213
- package/dist/output.js +135 -447
- package/dist/parity-CvMuYcVI.d.ts +61 -0
- package/dist/progress-CAzyxeWl.d.ts +38 -0
- package/dist/progress.d.ts +1 -30
- package/dist/progress.js +6 -55
- package/dist/provenance-SMFHm5gx.d.ts +30 -0
- package/dist/provenance.d.ts +1 -24
- package/dist/provenance.js +6 -31
- package/dist/routellm-B0nv59mH.d.ts +111 -0
- package/dist/routellm.d.ts +2 -64
- package/dist/routellm.js +13 -255
- package/dist/rpc-D31Lg0Kc.d.ts +32 -0
- package/dist/rpc.d.ts +2 -25
- package/dist/rpc.js +4 -98
- package/dist/safety-CUaYEjZc.d.ts +30 -0
- package/dist/safety.d.ts +1 -24
- package/dist/safety.js +6 -43
- package/dist/scope-BrhYB4ij.d.ts +141 -0
- package/dist/scope.d.ts +1 -121
- package/dist/scope.js +20 -377
- package/dist/serve-D8yWMrTc.d.ts +646 -0
- package/dist/serve.d.ts +3 -0
- package/dist/serve.js +75 -0
- package/dist/sqlstore.js +6 -39
- package/dist/stream-CrjeCp0M.d.ts +44 -0
- package/dist/stream.d.ts +1 -35
- package/dist/stream.js +8 -51
- package/dist/telemetry/index.d.ts +1 -315
- package/dist/telemetry/index.js +26 -599
- package/dist/toolspec-DcPwwoAZ.d.ts +368 -0
- package/dist/toolspec.d.ts +2 -0
- package/dist/toolspec.js +37 -0
- package/dist/tui/index.d.ts +6 -298
- package/dist/tui/index.js +17 -381
- package/dist/upgrade-C3RWGwRi.d.ts +125 -0
- package/dist/upgrade.d.ts +1 -95
- package/dist/upgrade.js +6 -114
- package/dist/xdg-DB7Shoib.d.ts +179 -0
- package/dist/xdg.d.ts +1 -169
- package/dist/xdg.js +14 -128
- package/package.json +192 -24
- package/src/README.md +15 -0
- package/src/alias.conformance.test.ts +250 -0
- package/src/alias.test.ts +206 -2
- package/src/alias.ts +196 -21
- package/src/cli.help-command.test.ts +105 -0
- package/src/cli.offline.test.ts +93 -0
- package/src/cli.parity.test.ts +192 -0
- package/src/cli.root.conformance.test.ts +166 -0
- package/src/cli.test.ts +95 -1
- package/src/cli.ts +234 -25
- package/src/completion-scripts.ts +16 -0
- package/src/completion-values.test.ts +76 -16
- package/src/completion-values.ts +170 -66
- package/src/completion.conformance.test.ts +298 -0
- package/src/completion.test.ts +268 -145
- package/src/completion.ts +772 -121
- package/src/compliance.test.ts +196 -2
- package/src/compliance.ts +440 -20
- package/src/config-merge.test.ts +425 -0
- package/src/config.test.ts +228 -1
- package/src/config.ts +429 -16
- package/src/delegation.test.ts +299 -0
- package/src/delegation.ts +807 -0
- package/src/gen/crud_pb.ts +7 -7
- package/src/id/README.md +38 -0
- package/src/id/contract.test.ts +1 -1
- package/src/id/index.test.ts +1 -1
- package/src/id/index.ts +3 -2
- package/src/index.test.ts +71 -0
- package/src/index.ts +46 -0
- package/src/llm-anthropic.conformance.test.ts +1135 -0
- package/src/llm-anthropic.test.ts +152 -0
- package/src/llm-anthropic.ts +940 -0
- package/src/llm-choice-hermetic.test.ts +335 -0
- package/src/llm-config.test.ts +232 -0
- package/src/llm-config.ts +106 -0
- package/src/llm-endpoint.ts +254 -0
- package/src/llm-error.ts +17 -0
- package/src/llm-errors.ts +152 -0
- package/src/llm-file.ts +126 -0
- package/src/llm-http.ts +317 -0
- package/src/llm-keys.ts +167 -0
- package/src/llm-media.conformance.test.ts +87 -0
- package/src/llm-media.test.ts +279 -0
- package/src/llm-media.ts +322 -0
- package/src/llm-openai.conformance.test.ts +407 -0
- package/src/llm-openai.test.ts +510 -0
- package/src/llm-openai.ts +708 -0
- package/src/llm-payload.ts +155 -0
- package/src/llm-quote.ts +46 -0
- package/src/llm-routellm.conformance.test.ts +44 -0
- package/src/llm-toolnames.conformance.test.ts +112 -0
- package/src/llm-toolnames.test.ts +132 -0
- package/src/llm-toolnames.ts +298 -0
- package/src/llm-uri.ts +99 -0
- package/src/llm.test.ts +43 -15
- package/src/llm.toolcall.test.ts +175 -0
- package/src/llm.ts +602 -190
- package/src/log.parity.test.ts +105 -0
- package/src/log.test.ts +270 -1
- package/src/log.ts +228 -49
- package/src/mcp/README.md +63 -0
- package/src/mcp/args-separator.test.ts +164 -0
- package/src/mcp/args.test.ts +223 -0
- package/src/mcp/args.ts +160 -0
- package/src/mcp/audit.test.ts +520 -0
- package/src/mcp/audit.ts +70 -0
- package/src/mcp/bridge.test.ts +250 -0
- package/src/mcp/bridge.ts +286 -0
- package/src/mcp/conformance.test.ts +357 -0
- package/src/mcp/dispatch.ts +359 -0
- package/src/mcp/identity.test.ts +166 -0
- package/src/mcp/identity.ts +72 -0
- package/src/mcp/index.ts +176 -0
- package/src/mcp/legacy-notify.test.ts +59 -0
- package/src/mcp/legacy.ts +367 -0
- package/src/mcp/mcp.test.ts +707 -0
- package/src/mcp/modern-confirm.test.ts +520 -0
- package/src/mcp/modern-confirm.ts +484 -0
- package/src/mcp/modern.ts +788 -0
- package/src/mcp/stdio.test.ts +313 -0
- package/src/mcp/stdio.ts +254 -0
- package/src/mcp/tasks.ts +82 -0
- package/src/mcp/testtree.ts +250 -0
- package/src/mcp/toolname.test.ts +147 -0
- package/src/mcp/types.ts +689 -0
- package/src/netpolicy.test.ts +280 -0
- package/src/netpolicy.ts +256 -0
- package/src/output/README.md +46 -0
- package/src/output/builtins.ts +5 -5
- package/src/output/dispatch.ts +10 -2
- package/src/output/error.ts +459 -0
- package/src/output/formatter.ts +29 -5
- package/src/output/formatters/README.md +50 -0
- package/src/output/formatters/csv.ts +48 -12
- package/src/output/formatters/json.ts +4 -25
- package/src/output/formatters/project.ts +34 -0
- package/src/output/formatters/table.ts +8 -6
- package/src/output/formatters/text.ts +7 -3
- package/src/output/formatters/yaml.ts +5 -22
- package/src/output/projection.test.ts +298 -0
- package/src/output/projection.ts +33 -59
- package/src/output/template.ts +11 -21
- package/src/output.surface.test.ts +41 -0
- package/src/output.ts +64 -3
- package/src/plan.ts +89 -0
- package/src/policy.ts +472 -0
- package/src/published-types.test.ts +133 -0
- package/src/routellm.test.ts +209 -28
- package/src/routellm.toolcall.test.ts +521 -0
- package/src/routellm.ts +213 -177
- package/src/router/README.md +44 -0
- package/src/router/server.test.ts +41 -0
- package/src/router/server.ts +11 -0
- package/src/safety.test.ts +19 -9
- package/src/scope-defaults.json +29 -29
- package/src/serve.test.ts +1257 -0
- package/src/serve.ts +1665 -0
- package/src/sideeffect.ts +105 -0
- package/src/telemetry/README.md +48 -0
- package/src/telemetry/client.test.ts +31 -0
- package/src/telemetry/client.ts +12 -6
- package/src/telemetry/offline.test.ts +64 -0
- package/src/toolspec-internal.ts +279 -0
- package/src/toolspec-manifest.test.ts +167 -0
- package/src/toolspec-manifest.ts +415 -0
- package/src/toolspec-spec-schemas.ts +12 -0
- package/src/toolspec-spec.test.ts +273 -0
- package/src/toolspec-spec.ts +458 -0
- package/src/toolspec.from-command.test.ts +350 -0
- package/src/toolspec.test.ts +2 -2
- package/src/toolspec.ts +222 -0
- package/src/triton/README.md +34 -0
- package/src/tui/README.md +42 -0
- package/src/tui/parity.test.ts +120 -31
- package/src/tui/parity.ts +58 -7
- package/src/upgrade.test.ts +291 -0
- package/src/upgrade.ts +116 -7
- package/src/wizard.test.ts +7 -7
- package/test/llm/conformance-helpers.ts +100 -0
- package/test/output/csv.test.ts +164 -0
- package/test/output/dispatch.test.ts +1 -2
- package/test/output/error.test.ts +277 -0
- package/test/output/smoke-capture.ts +2 -2
- package/test/output/smoke.test.ts +2 -2
- package/test/output/taxonomy-contract.test.ts +148 -0
- package/test/setup-env.ts +16 -0
- package/test/toolspec/fixture.ts +79 -0
- package/tsconfig.json +3 -1
- package/tsconfig.test.json +10 -0
- package/vitest.config.ts +9 -0
- package/src/tui/parity.json +0 -74
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Load-bearing coverage for the verbosity wiring in `log.ts`.
|
|
3
|
+
*
|
|
4
|
+
* These feed a *constructed* ParityData (never the shared parity.json) whose
|
|
5
|
+
* values differ from the shipped contract, and assert the level mapping
|
|
6
|
+
* follows it. A port that re-hardcodes info/debug/trace/warn fails here.
|
|
7
|
+
*
|
|
8
|
+
* Mirrors `go/console/log/parity_wiring_test.go`.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { describe, expect, it } from 'vitest';
|
|
12
|
+
|
|
13
|
+
import { quietLevel, verbosityLevel } from './log';
|
|
14
|
+
import { parity, type ParityData } from './tui/parity';
|
|
15
|
+
|
|
16
|
+
/** A ParityData carrying only the given verbosity block. */
|
|
17
|
+
function contractData(
|
|
18
|
+
levels: Record<string, string>,
|
|
19
|
+
quiet: string,
|
|
20
|
+
): ParityData {
|
|
21
|
+
return { verbosity: { flag: '-V', levels, quiet_override: quiet } } as unknown as ParityData;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// ─── Load-bearing: behavior must follow the contract, not literals ───────────
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Swaps the level names away from the shipped info/debug/trace. If
|
|
28
|
+
* `withVerbose`'s mapping is hardcoded, the resolved levels stay at the
|
|
29
|
+
* shipped values and this fails.
|
|
30
|
+
*/
|
|
31
|
+
describe('verbosityLevel follows contract not literals', () => {
|
|
32
|
+
const d = contractData({ '0': 'error', '1': 'warn', '2': 'info' }, 'fatal');
|
|
33
|
+
|
|
34
|
+
it('resolves each count through the contract levels table', () => {
|
|
35
|
+
expect(verbosityLevel(d, 0), 'count 0 must resolve via levels["0"], not a hardcoded info')
|
|
36
|
+
.toBe('error');
|
|
37
|
+
expect(verbosityLevel(d, 1), 'count 1 must resolve via levels["1"], not a hardcoded debug')
|
|
38
|
+
.toBe('warn');
|
|
39
|
+
expect(verbosityLevel(d, 2), 'count 2 must resolve via levels["2"], not a hardcoded trace')
|
|
40
|
+
.toBe('info');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('clamps counts above the highest declared key', () => {
|
|
44
|
+
expect(verbosityLevel(d, 7)).toBe('info');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('resolves quiet through the contract override', () => {
|
|
48
|
+
expect(quietLevel(d), 'quiet must resolve via quiet_override, not a hardcoded warn')
|
|
49
|
+
.toBe('fatal');
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Proves the mapping is table-driven rather than a three-branch if/else: a
|
|
55
|
+
* contract declaring a 4th level must be honored.
|
|
56
|
+
*/
|
|
57
|
+
describe('verbosityLevel honors a contract beyond the shipped 0/1/2', () => {
|
|
58
|
+
const d = contractData({ '0': 'warn', '3': 'trace' }, 'error');
|
|
59
|
+
|
|
60
|
+
it('falls back to the nearest lower declared key', () => {
|
|
61
|
+
expect(verbosityLevel(d, 0)).toBe('warn');
|
|
62
|
+
expect(verbosityLevel(d, 2)).toBe('warn');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('honors a key the shipped contract does not declare', () => {
|
|
66
|
+
expect(verbosityLevel(d, 3)).toBe('trace');
|
|
67
|
+
expect(quietLevel(d)).toBe('error');
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// ─── Requirement pin: observable behavior unchanged ──────────────────────────
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Pins the wiring to the values actually declared in parity.json, so the
|
|
75
|
+
* refactor cannot silently change observable behavior. NOT load-bearing:
|
|
76
|
+
* it keeps passing if a literal is restored, by design.
|
|
77
|
+
*/
|
|
78
|
+
describe('verbosityLevel matches shipped contract', () => {
|
|
79
|
+
it('resolves the historical -V level ladder', () => {
|
|
80
|
+
expect(parity.verbosity.levels).toEqual({ '0': 'info', '1': 'debug', '2': 'trace' });
|
|
81
|
+
expect(parity.verbosity.quiet_override).toBe('warn');
|
|
82
|
+
|
|
83
|
+
expect(verbosityLevel(parity, 0)).toBe('info');
|
|
84
|
+
expect(verbosityLevel(parity, 1)).toBe('debug');
|
|
85
|
+
expect(verbosityLevel(parity, 2)).toBe('trace');
|
|
86
|
+
expect(verbosityLevel(parity, 3)).toBe('trace');
|
|
87
|
+
expect(quietLevel(parity)).toBe('warn');
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// ─── Degradation ─────────────────────────────────────────────────────────────
|
|
92
|
+
|
|
93
|
+
describe('verbosityLevel degrades safely', () => {
|
|
94
|
+
it('falls back on an empty contract', () => {
|
|
95
|
+
const empty = contractData({}, '');
|
|
96
|
+
expect(verbosityLevel(empty, 0)).toBe('info');
|
|
97
|
+
expect(quietLevel(empty), 'absent quiet_override falls back to warn').toBe('warn');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('falls back on unrecognized level names', () => {
|
|
101
|
+
const bogus = contractData({ '0': 'nonsense', x: 'debug' }, 'nonsense');
|
|
102
|
+
expect(verbosityLevel(bogus, 0), 'unrecognized level name falls back to info').toBe('info');
|
|
103
|
+
expect(quietLevel(bogus)).toBe('warn');
|
|
104
|
+
});
|
|
105
|
+
});
|
package/src/log.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
-
import { createLogger } from './log';
|
|
2
|
+
import { createLogger, withVerbose, type LogRecord } from './log';
|
|
3
3
|
|
|
4
4
|
function makeStderr(): { write: ReturnType<typeof vi.fn>; captured: () => string } {
|
|
5
5
|
const chunks: string[] = [];
|
|
@@ -143,3 +143,272 @@ describe('log key-value edge cases', () => {
|
|
|
143
143
|
});
|
|
144
144
|
});
|
|
145
145
|
});
|
|
146
|
+
|
|
147
|
+
// ---------------------------------------------------------------------------
|
|
148
|
+
// Default output regression — no options must stay byte-identical
|
|
149
|
+
// ---------------------------------------------------------------------------
|
|
150
|
+
|
|
151
|
+
describe('log default output (regression pin)', () => {
|
|
152
|
+
it('writes exact LEVEL msg k=v lines to process.stderr', () => {
|
|
153
|
+
withStderr((captured) => {
|
|
154
|
+
const log = createLogger({ noColor: true });
|
|
155
|
+
log.info('start', 'port', 8080, 'path', '/my dir');
|
|
156
|
+
log.warn('w');
|
|
157
|
+
log.error('e', 'code', 2);
|
|
158
|
+
log.debug('d');
|
|
159
|
+
expect(captured()).toBe(
|
|
160
|
+
'INFO start port=8080 path="/my dir"\n'
|
|
161
|
+
+ 'WARN w\n'
|
|
162
|
+
+ 'ERRO e code=2\n'
|
|
163
|
+
+ 'DEBU d\n',
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('keeps the themed ANSI prefixes when no option is passed', () => {
|
|
169
|
+
withStderr((captured) => {
|
|
170
|
+
const log = createLogger();
|
|
171
|
+
log.info('i');
|
|
172
|
+
log.error('e');
|
|
173
|
+
expect(captured()).toBe(
|
|
174
|
+
'\x1b[38;2;133;129;131mINFO\x1b[0m i\n'
|
|
175
|
+
+ '\x1b[1m\x1b[38;2;237;74;94mERRO\x1b[0m\x1b[22m e\n',
|
|
176
|
+
);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// ---------------------------------------------------------------------------
|
|
182
|
+
// Injectable output stream
|
|
183
|
+
// ---------------------------------------------------------------------------
|
|
184
|
+
|
|
185
|
+
describe('log output option', () => {
|
|
186
|
+
function sink(): { output: { write(chunk: string): boolean }; text: () => string } {
|
|
187
|
+
const chunks: string[] = [];
|
|
188
|
+
return {
|
|
189
|
+
output: { write: (chunk: string) => { chunks.push(chunk); return true; } },
|
|
190
|
+
text: () => chunks.join(''),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
it('createLogger writes to the injected output, not stderr', () => {
|
|
195
|
+
withStderr((captured) => {
|
|
196
|
+
const s = sink();
|
|
197
|
+
const log = createLogger({ noColor: true, output: s.output });
|
|
198
|
+
log.info('hello', 'k', 'v');
|
|
199
|
+
expect(s.text()).toBe('INFO hello k=v\n');
|
|
200
|
+
expect(captured()).toBe('');
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('withVerbose writes to the injected output, not stderr', () => {
|
|
205
|
+
withStderr((captured) => {
|
|
206
|
+
const s = sink();
|
|
207
|
+
const log = withVerbose({ noColor: true, verbose: 1, output: s.output });
|
|
208
|
+
log.debug('dbg');
|
|
209
|
+
expect(s.text()).toBe('DEBU dbg\n');
|
|
210
|
+
expect(captured()).toBe('');
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('injected output still honors quiet', () => {
|
|
215
|
+
const s = sink();
|
|
216
|
+
const log = createLogger({ quiet: true, noColor: true, output: s.output });
|
|
217
|
+
log.info('hidden');
|
|
218
|
+
log.warn('shown');
|
|
219
|
+
expect(s.text()).toBe('WARN shown\n');
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// ---------------------------------------------------------------------------
|
|
224
|
+
// Shared sink helper for option tests
|
|
225
|
+
// ---------------------------------------------------------------------------
|
|
226
|
+
|
|
227
|
+
function capture(): { output: { write(chunk: string): boolean }; text: () => string } {
|
|
228
|
+
const chunks: string[] = [];
|
|
229
|
+
return {
|
|
230
|
+
output: { write: (chunk: string) => { chunks.push(chunk); return true; } },
|
|
231
|
+
text: () => chunks.join(''),
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function emitAll(log: ReturnType<typeof createLogger>): void {
|
|
236
|
+
log.trace('t');
|
|
237
|
+
log.debug('d');
|
|
238
|
+
log.info('i');
|
|
239
|
+
log.warn('w');
|
|
240
|
+
log.error('e');
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// ---------------------------------------------------------------------------
|
|
244
|
+
// level option
|
|
245
|
+
// ---------------------------------------------------------------------------
|
|
246
|
+
|
|
247
|
+
describe('log level option', () => {
|
|
248
|
+
it('sets the threshold on createLogger', () => {
|
|
249
|
+
const s = capture();
|
|
250
|
+
emitAll(createLogger({ noColor: true, output: s.output, level: 'warn' }));
|
|
251
|
+
expect(s.text()).toBe('WARN w\nERRO e\n');
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('can lower createLogger below its debug default', () => {
|
|
255
|
+
const s = capture();
|
|
256
|
+
emitAll(createLogger({ noColor: true, output: s.output, level: 'trace' }));
|
|
257
|
+
expect(s.text()).toBe('TRAC t\nDEBU d\nINFO i\nWARN w\nERRO e\n');
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('wins over the verbose count on withVerbose', () => {
|
|
261
|
+
const s = capture();
|
|
262
|
+
emitAll(withVerbose({ noColor: true, output: s.output, verbose: 2, level: 'error' }));
|
|
263
|
+
expect(s.text()).toBe('ERRO e\n');
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it("'silent' drops everything", () => {
|
|
267
|
+
const s = capture();
|
|
268
|
+
emitAll(createLogger({ output: s.output, level: 'silent' }));
|
|
269
|
+
emitAll(withVerbose({ output: s.output, verbose: 2, level: 'silent' }));
|
|
270
|
+
expect(s.text()).toBe('');
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('quiet only raises: lower level is lifted to warn', () => {
|
|
274
|
+
const s = capture();
|
|
275
|
+
emitAll(createLogger({ noColor: true, output: s.output, level: 'debug', quiet: true }));
|
|
276
|
+
expect(s.text()).toBe('WARN w\nERRO e\n');
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('quiet never lowers: error and silent stay put', () => {
|
|
280
|
+
const s = capture();
|
|
281
|
+
emitAll(createLogger({ noColor: true, output: s.output, level: 'error', quiet: true }));
|
|
282
|
+
emitAll(createLogger({ noColor: true, output: s.output, level: 'silent', quiet: true }));
|
|
283
|
+
expect(s.text()).toBe('ERRO e\n');
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
// ---------------------------------------------------------------------------
|
|
288
|
+
// success
|
|
289
|
+
// ---------------------------------------------------------------------------
|
|
290
|
+
|
|
291
|
+
describe('log success', () => {
|
|
292
|
+
it('renders SUCC label with key-values', () => {
|
|
293
|
+
const s = capture();
|
|
294
|
+
createLogger({ noColor: true, output: s.output }).success('deployed', 'env', 'prod');
|
|
295
|
+
expect(s.text()).toBe('SUCC deployed env=prod\n');
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it('uses the theme success colour (Guac #52CF84), not bold', () => {
|
|
299
|
+
const s = capture();
|
|
300
|
+
createLogger({ output: s.output }).success('ok');
|
|
301
|
+
expect(s.text()).toBe('\x1b[38;2;82;207;132mSUCC\x1b[0m ok\n');
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it('is filtered exactly like info', () => {
|
|
305
|
+
const s = capture();
|
|
306
|
+
createLogger({ noColor: true, output: s.output, level: 'info' }).success('a');
|
|
307
|
+
withVerbose({ noColor: true, output: s.output }).success('b');
|
|
308
|
+
createLogger({ noColor: true, output: s.output, quiet: true }).success('hidden');
|
|
309
|
+
createLogger({ noColor: true, output: s.output, level: 'warn' }).success('hidden');
|
|
310
|
+
expect(s.text()).toBe('SUCC a\nSUCC b\n');
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
// ---------------------------------------------------------------------------
|
|
315
|
+
// format: 'json' (charm JSONFormatter shape)
|
|
316
|
+
// ---------------------------------------------------------------------------
|
|
317
|
+
|
|
318
|
+
describe("log format: 'json'", () => {
|
|
319
|
+
it('emits {"level","msg",...kv} with no time/pid/hostname or ANSI', () => {
|
|
320
|
+
const s = capture();
|
|
321
|
+
createLogger({ format: 'json', output: s.output })
|
|
322
|
+
.info('start', 'port', 8080, 'path', '/my dir', 'ok', true);
|
|
323
|
+
expect(s.text()).toBe('{"level":"info","msg":"start","port":8080,"path":"/my dir","ok":true}\n');
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it('uses charm level strings', () => {
|
|
327
|
+
const s = capture();
|
|
328
|
+
emitAll(createLogger({ format: 'json', output: s.output, level: 'trace' }));
|
|
329
|
+
expect(s.text()).toBe(
|
|
330
|
+
'{"level":"trace","msg":"t"}\n'
|
|
331
|
+
+ '{"level":"debug","msg":"d"}\n'
|
|
332
|
+
+ '{"level":"info","msg":"i"}\n'
|
|
333
|
+
+ '{"level":"warn","msg":"w"}\n'
|
|
334
|
+
+ '{"level":"error","msg":"e"}\n',
|
|
335
|
+
);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it('marks success as level info + kind success', () => {
|
|
339
|
+
const s = capture();
|
|
340
|
+
createLogger({ format: 'json', output: s.output }).success('deployed', 'env', 'prod');
|
|
341
|
+
expect(s.text()).toBe('{"level":"info","msg":"deployed","kind":"success","env":"prod"}\n');
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it('honors level filtering and withVerbose', () => {
|
|
345
|
+
const s = capture();
|
|
346
|
+
const log = withVerbose({ format: 'json', output: s.output, quiet: true });
|
|
347
|
+
log.info('hidden');
|
|
348
|
+
log.warn('shown');
|
|
349
|
+
expect(s.text()).toBe('{"level":"warn","msg":"shown"}\n');
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it("format: 'text' is the default line format", () => {
|
|
353
|
+
const s = capture();
|
|
354
|
+
createLogger({ format: 'text', noColor: true, output: s.output }).info('x', 'k', 1);
|
|
355
|
+
expect(s.text()).toBe('INFO x k=1\n');
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
// ---------------------------------------------------------------------------
|
|
360
|
+
// formatter hook
|
|
361
|
+
// ---------------------------------------------------------------------------
|
|
362
|
+
|
|
363
|
+
describe('log formatter hook', () => {
|
|
364
|
+
const GLYPHS: Record<string, string> = { info: 'ℹ', warn: '▲', error: '●' };
|
|
365
|
+
const glyph = (rec: LogRecord): string =>
|
|
366
|
+
`${rec.kind === 'success' ? '✓' : GLYPHS[rec.level] ?? '·'} ${rec.msg}`;
|
|
367
|
+
|
|
368
|
+
it('writes the returned string, appending a missing newline', () => {
|
|
369
|
+
const s = capture();
|
|
370
|
+
const log = createLogger({ output: s.output, formatter: glyph });
|
|
371
|
+
log.info('hi');
|
|
372
|
+
log.success('done');
|
|
373
|
+
log.error('boom');
|
|
374
|
+
expect(s.text()).toBe('ℹ hi\n✓ done\n● boom\n');
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it('does not double an existing trailing newline', () => {
|
|
378
|
+
const s = capture();
|
|
379
|
+
createLogger({ output: s.output, formatter: (r) => `${r.msg}\n` }).info('x');
|
|
380
|
+
expect(s.text()).toBe('x\n');
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('receives level, msg, fields and kind', () => {
|
|
384
|
+
const recs: LogRecord[] = [];
|
|
385
|
+
const log = createLogger({
|
|
386
|
+
output: capture().output,
|
|
387
|
+
formatter: (r) => { recs.push(r); return ''; },
|
|
388
|
+
});
|
|
389
|
+
log.warn('w', 'port', 8080, 'host', 'h');
|
|
390
|
+
log.success('s');
|
|
391
|
+
expect(recs).toEqual([
|
|
392
|
+
{ level: 'warn', msg: 'w', fields: { port: 8080, host: 'h' } },
|
|
393
|
+
{ level: 'info', msg: 's', fields: {}, kind: 'success' },
|
|
394
|
+
]);
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it('wins over format and noColor', () => {
|
|
398
|
+
const s = capture();
|
|
399
|
+
const log = withVerbose({
|
|
400
|
+
output: s.output, format: 'json', noColor: false, formatter: (r) => `[${r.level}] ${r.msg}`,
|
|
401
|
+
});
|
|
402
|
+
log.info('plain');
|
|
403
|
+
expect(s.text()).toBe('[info] plain\n');
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it('is not called for filtered lines', () => {
|
|
407
|
+
const s = capture();
|
|
408
|
+
const log = createLogger({ output: s.output, quiet: true, formatter: (r) => r.msg });
|
|
409
|
+
log.info('hidden');
|
|
410
|
+
log.success('hidden');
|
|
411
|
+
log.warn('shown');
|
|
412
|
+
expect(s.text()).toBe('shown\n');
|
|
413
|
+
});
|
|
414
|
+
});
|