@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,42 @@
|
|
|
1
|
+
# tui
|
|
2
|
+
|
|
3
|
+
## What it answers
|
|
4
|
+
|
|
5
|
+
How a TS CLI paints the same terminal widgets as a Go kit CLI: status lines, badges, pills, spinner, progress bar, gradient animation, confirm and list prompts, all themed from `@hop-top/kit/cli`'s `Theme`. Wrong module for structured output (`@hop-top/kit/output`) and for machine-readable progress events (`@hop-top/kit/progress`).
|
|
6
|
+
|
|
7
|
+
## Use it when
|
|
8
|
+
|
|
9
|
+
- prefixed status line: `status(theme, text, 'info' | 'success' | 'error' | 'warn')`
|
|
10
|
+
- inline label: `badge(theme, text)`, `pills(theme, items)`
|
|
11
|
+
- long-running step in a TTY: `spinner(theme)`, `progress(theme)`
|
|
12
|
+
- yes/no or pick-one prompt: `confirm(theme, ...)`, `list(theme, ...)`
|
|
13
|
+
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { buildTheme } from '@hop-top/kit/cli';
|
|
18
|
+
import { status, badge } from '@hop-top/kit/tui';
|
|
19
|
+
|
|
20
|
+
const theme = buildTheme();
|
|
21
|
+
console.log(status(theme, 'Deployed', 'success'));
|
|
22
|
+
console.log(badge(theme, 'beta'));
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Contract
|
|
26
|
+
|
|
27
|
+
- Status symbols, spinner frames and interval, and animation runes come from [`contracts/parity/parity.json`](../../../../contracts/parity/parity.json) through [`parity.ts`](parity.ts); never inline them.
|
|
28
|
+
- [`parity.test.ts`](parity.test.ts) is the block-registry guard: a block declared in the contract without a loader here fails.
|
|
29
|
+
- Every renderer takes `Theme` as its first argument; there is no module-level default theme.
|
|
30
|
+
- Parity: [`contracts/parity/README.md`](../../../../contracts/parity/README.md), table "Declared blocks", rows `status`, `spinner`, `anim`.
|
|
31
|
+
|
|
32
|
+
## Neighbours
|
|
33
|
+
|
|
34
|
+
- `@hop-top/kit/cli`: `Theme`, `buildTheme`, help layout
|
|
35
|
+
- `@hop-top/kit/output`: tables and structured formats
|
|
36
|
+
- `@hop-top/kit/progress`: JSON progress events for non-TTY consumers
|
|
37
|
+
- Go reference: [`go/console/tui`](../../../../go/console/tui/README.md); Python port: [`hop_top_kit/tui`](../../../py/hop_top_kit/tui/README.md)
|
|
38
|
+
|
|
39
|
+
## See also
|
|
40
|
+
|
|
41
|
+
- [`docs/adopters/guides/tui-component-gallery.md`](../../../../docs/adopters/guides/tui-component-gallery.md)
|
|
42
|
+
- [`docs/adopters/guides/cli-parity-guide.md`](../../../../docs/adopters/guides/cli-parity-guide.md)
|
package/src/tui/parity.test.ts
CHANGED
|
@@ -1,53 +1,142 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Drift guards for tui/parity.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* The loader reads the canonical `contracts/parity/parity.json` directly, so
|
|
5
|
+
* there is no vendored second copy to keep in sync. What remains to protect
|
|
6
|
+
* is the LOADER: a block can be added to parity.json and read as enforced
|
|
7
|
+
* while nothing in TypeScript ever models it.
|
|
8
|
+
*
|
|
9
|
+
* Mirrors `TestParityNoUnloadedBlocks` and `TestParityLoadedBlocksNonZero`
|
|
10
|
+
* in `contracts/parity/parity_test.go`.
|
|
9
11
|
*/
|
|
10
12
|
|
|
11
13
|
import * as fs from 'fs';
|
|
12
14
|
import * as path from 'path';
|
|
13
15
|
import { describe, expect, it } from 'vitest';
|
|
14
16
|
|
|
15
|
-
import { parity } from './parity.js';
|
|
17
|
+
import { PARITY_BLOCKS, parity } from './parity.js';
|
|
18
|
+
|
|
19
|
+
const CANONICAL_PATH = path.join(
|
|
20
|
+
__dirname,
|
|
21
|
+
'..',
|
|
22
|
+
'..',
|
|
23
|
+
'..',
|
|
24
|
+
'..',
|
|
25
|
+
'contracts',
|
|
26
|
+
'parity',
|
|
27
|
+
'parity.json',
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
/** Top-level keys parity.json declares, minus `$`-prefixed schema metadata. */
|
|
31
|
+
function declaredBlocks(): string[] {
|
|
32
|
+
const raw = JSON.parse(fs.readFileSync(CANONICAL_PATH, 'utf8')) as Record<string, unknown>;
|
|
33
|
+
return Object.keys(raw).filter((k) => !k.startsWith('$'));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ─── Drift guard: block registry ─────────────────────────────────────────────
|
|
37
|
+
|
|
38
|
+
describe('parity block registry', () => {
|
|
39
|
+
it('models every block parity.json declares', () => {
|
|
40
|
+
const known = new Set<string>(PARITY_BLOCKS);
|
|
41
|
+
const unknown = declaredBlocks().filter((k) => !known.has(k));
|
|
42
|
+
|
|
43
|
+
expect(
|
|
44
|
+
unknown,
|
|
45
|
+
`contracts/parity/parity.json declares block(s) ${JSON.stringify(unknown)} that the ` +
|
|
46
|
+
`TypeScript loader does not know.\n` +
|
|
47
|
+
`parity.json is a loaded contract, not documentation: an unloaded block is ` +
|
|
48
|
+
`invisible to every test and every consumer.\n` +
|
|
49
|
+
`Fix by adding the block to the ParityData interface and to PARITY_BLOCKS in ` +
|
|
50
|
+
`sdk/ts/src/tui/parity.ts — or, if it is not a cross-language constant, move it ` +
|
|
51
|
+
`to prose in contracts/parity/README.md.`,
|
|
52
|
+
).toEqual([]);
|
|
53
|
+
});
|
|
16
54
|
|
|
17
|
-
|
|
55
|
+
it('does not list blocks parity.json no longer declares', () => {
|
|
56
|
+
const declared = new Set(declaredBlocks());
|
|
57
|
+
const stale = PARITY_BLOCKS.filter((b) => !declared.has(b));
|
|
18
58
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
);
|
|
24
|
-
const canonical = JSON.parse(
|
|
25
|
-
fs.readFileSync(
|
|
26
|
-
path.join(__dirname, '..', '..', '..', '..', 'contracts', 'parity', 'parity.json'),
|
|
27
|
-
'utf8',
|
|
28
|
-
),
|
|
29
|
-
);
|
|
30
|
-
expect(local).toEqual(canonical);
|
|
59
|
+
expect(
|
|
60
|
+
stale,
|
|
61
|
+
`PARITY_BLOCKS lists ${JSON.stringify(stale)} but contracts/parity/parity.json no ` +
|
|
62
|
+
`longer declares it; drop it from PARITY_BLOCKS in sdk/ts/src/tui/parity.ts.`,
|
|
63
|
+
).toEqual([]);
|
|
31
64
|
});
|
|
32
65
|
});
|
|
33
66
|
|
|
34
|
-
// ───
|
|
67
|
+
// ─── Drift guard: loaded values are non-empty ────────────────────────────────
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* A block wired into ParityData under a mismatched key name still parses
|
|
71
|
+
* clean and leaves `undefined` behind — silent, and exactly what this
|
|
72
|
+
* contract exists to prevent. Asserting the key was SEEN is not enough;
|
|
73
|
+
* assert the value actually arrived.
|
|
74
|
+
*/
|
|
75
|
+
describe('parity loaded blocks are non-empty', () => {
|
|
76
|
+
it('status symbols loaded', () => {
|
|
77
|
+
expect(Object.keys(parity.status?.symbols ?? {}).length).toBeGreaterThan(0);
|
|
78
|
+
for (const kind of ['info', 'success', 'error', 'warn'] as const) {
|
|
79
|
+
expect(parity.status.symbols[kind], `status.symbols.${kind}: empty after load`).toBeTruthy();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
35
82
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
expect(parity.
|
|
39
|
-
expect(parity.status.symbols.error).toBeTruthy();
|
|
83
|
+
it('spinner loaded', () => {
|
|
84
|
+
expect(parity.spinner?.frames?.length ?? 0).toBeGreaterThan(0);
|
|
85
|
+
expect(parity.spinner?.interval_ms ?? 0).toBeGreaterThan(0);
|
|
40
86
|
});
|
|
41
87
|
|
|
42
|
-
it('
|
|
43
|
-
expect(parity.
|
|
44
|
-
expect(parity.
|
|
88
|
+
it('anim loaded', () => {
|
|
89
|
+
expect(parity.anim?.runes ?? '').toBeTruthy();
|
|
90
|
+
expect(parity.anim?.interval_ms ?? 0).toBeGreaterThan(0);
|
|
91
|
+
expect(parity.anim?.default_width ?? 0).toBeGreaterThan(0);
|
|
45
92
|
});
|
|
46
93
|
|
|
47
|
-
it('
|
|
48
|
-
expect(parity.help
|
|
94
|
+
it('help loaded', () => {
|
|
95
|
+
expect(parity.help?.section_order?.length ?? 0).toBeGreaterThan(0);
|
|
96
|
+
expect(Object.keys(parity.help?.sections ?? {}).length).toBeGreaterThan(0);
|
|
49
97
|
for (const section of parity.help.section_order) {
|
|
50
|
-
expect(parity.help.sections[section]).toBeDefined();
|
|
98
|
+
expect(parity.help.sections[section], `help.sections[${section}]: missing`).toBeDefined();
|
|
51
99
|
}
|
|
52
100
|
});
|
|
101
|
+
|
|
102
|
+
it('verbosity loaded', () => {
|
|
103
|
+
const v = parity.verbosity;
|
|
104
|
+
expect(v?.flag, `verbosity: incompletely loaded: ${JSON.stringify(v)}`).toBeTruthy();
|
|
105
|
+
expect(
|
|
106
|
+
Object.keys(v?.levels ?? {}).length,
|
|
107
|
+
`verbosity: incompletely loaded: ${JSON.stringify(v)}`,
|
|
108
|
+
).toBeGreaterThan(0);
|
|
109
|
+
expect(
|
|
110
|
+
v?.quiet_override,
|
|
111
|
+
`verbosity: incompletely loaded: ${JSON.stringify(v)}`,
|
|
112
|
+
).toBeTruthy();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('streams loaded', () => {
|
|
116
|
+
const s = parity.streams;
|
|
117
|
+
expect(s?.flag, `streams: incompletely loaded: ${JSON.stringify(s)}`).toBeTruthy();
|
|
118
|
+
expect(s?.label_format, `streams: incompletely loaded: ${JSON.stringify(s)}`).toBeTruthy();
|
|
119
|
+
expect(s?.output, `streams: incompletely loaded: ${JSON.stringify(s)}`).toBeTruthy();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('description and extends loaded', () => {
|
|
123
|
+
expect(parity.description).toBeTruthy();
|
|
124
|
+
expect(parity.extends?.length ?? 0).toBeGreaterThan(0);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// ─── Value pins ──────────────────────────────────────────────────────────────
|
|
129
|
+
|
|
130
|
+
describe('parity pinned values', () => {
|
|
131
|
+
it('pins verbosity contract', () => {
|
|
132
|
+
expect(parity.verbosity.flag).toBe('-V');
|
|
133
|
+
expect(parity.verbosity.levels).toEqual({ '0': 'info', '1': 'debug', '2': 'trace' });
|
|
134
|
+
expect(parity.verbosity.quiet_override).toBe('warn');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('pins streams contract', () => {
|
|
138
|
+
expect(parity.streams.flag).toBe('--stream');
|
|
139
|
+
expect(parity.streams.label_format).toBe('[{name}]');
|
|
140
|
+
expect(parity.streams.output).toBe('stderr');
|
|
141
|
+
});
|
|
53
142
|
});
|
package/src/tui/parity.ts
CHANGED
|
@@ -2,17 +2,30 @@
|
|
|
2
2
|
* @module tui/parity
|
|
3
3
|
* @package @hop-top/kit
|
|
4
4
|
*
|
|
5
|
-
* Cross-language parity constants SoT.
|
|
6
|
-
* `contracts/parity/parity.json
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* Cross-language parity constants SoT. Values are read from the canonical
|
|
6
|
+
* `contracts/parity/parity.json` at build time — tsup/esbuild inlines the
|
|
7
|
+
* JSON into the emitted bundle, so the published package stays
|
|
8
|
+
* self-contained without vendoring a second copy of the file.
|
|
9
9
|
*
|
|
10
10
|
* All TUI modules should import constants from here, not hardcode them.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import parityRaw from '
|
|
13
|
+
import parityRaw from '../../../../contracts/parity/parity.json';
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
/** Display metadata for a single help section. */
|
|
16
|
+
export interface SectionConfig {
|
|
17
|
+
title: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* ParityData models every content block `parity.json` declares.
|
|
22
|
+
*
|
|
23
|
+
* A block present in the JSON but absent here is decoration: nothing loads
|
|
24
|
+
* it, so no test and no consumer can see it drift. `PARITY_BLOCKS` below is
|
|
25
|
+
* the machine-checkable half of that rule.
|
|
26
|
+
*/
|
|
27
|
+
export interface ParityData {
|
|
28
|
+
description: string;
|
|
16
29
|
status: {
|
|
17
30
|
symbols: Record<'info' | 'success' | 'error' | 'warn', string>;
|
|
18
31
|
};
|
|
@@ -29,8 +42,46 @@ interface ParityData {
|
|
|
29
42
|
/** Fang-vocabulary section names in render order. */
|
|
30
43
|
section_order: string[];
|
|
31
44
|
/** Display metadata keyed by fang section name. */
|
|
32
|
-
sections: Record<string,
|
|
45
|
+
sections: Record<string, SectionConfig>;
|
|
46
|
+
};
|
|
47
|
+
verbosity: {
|
|
48
|
+
flag: string;
|
|
49
|
+
/**
|
|
50
|
+
* Maps the stacked `-V` count (as a decimal string) to a log level name.
|
|
51
|
+
* Keys are strings because JSON object keys are.
|
|
52
|
+
*/
|
|
53
|
+
levels: Record<string, string>;
|
|
54
|
+
quiet_override: string;
|
|
33
55
|
};
|
|
56
|
+
streams: {
|
|
57
|
+
flag: string;
|
|
58
|
+
label_format: string;
|
|
59
|
+
output: string;
|
|
60
|
+
};
|
|
61
|
+
/** Sibling contract files the parity suite also covers. */
|
|
62
|
+
extends: string[];
|
|
34
63
|
}
|
|
35
64
|
|
|
65
|
+
/**
|
|
66
|
+
* PARITY_BLOCKS is the registry of top-level `parity.json` keys this loader
|
|
67
|
+
* knows. Every content block in `parity.json` MUST appear here and MUST have
|
|
68
|
+
* a corresponding property on `ParityData` — the drift guard in
|
|
69
|
+
* `parity.test.ts` enforces both directions so a new block cannot be added
|
|
70
|
+
* as decoration.
|
|
71
|
+
*
|
|
72
|
+
* Mirrors `parity.Blocks` in `contracts/parity/parity.go`.
|
|
73
|
+
*
|
|
74
|
+
* Keys starting with `$` are JSON Schema metadata, not content.
|
|
75
|
+
*/
|
|
76
|
+
export const PARITY_BLOCKS = [
|
|
77
|
+
'description',
|
|
78
|
+
'status',
|
|
79
|
+
'spinner',
|
|
80
|
+
'anim',
|
|
81
|
+
'help',
|
|
82
|
+
'verbosity',
|
|
83
|
+
'streams',
|
|
84
|
+
'extends',
|
|
85
|
+
] as const;
|
|
86
|
+
|
|
36
87
|
export const parity: ParityData = parityRaw;
|
package/src/upgrade.test.ts
CHANGED
|
@@ -296,3 +296,294 @@ describe('createChecker', () => {
|
|
|
296
296
|
expect(out.value()).toContain('v2.0.0');
|
|
297
297
|
});
|
|
298
298
|
});
|
|
299
|
+
|
|
300
|
+
// ─── component tags and prereleases ──────────────────────────────────────────
|
|
301
|
+
|
|
302
|
+
interface Rel {
|
|
303
|
+
tag_name: string;
|
|
304
|
+
prerelease?: boolean;
|
|
305
|
+
draft?: boolean;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const API = 'https://api.github.com/repos/acme/mono/releases';
|
|
309
|
+
|
|
310
|
+
/** Serve `pages[n-1]` for `?page=n` on the list endpoint; 404 elsewhere. */
|
|
311
|
+
function mockListing(pages: Rel[][]) {
|
|
312
|
+
return vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
|
|
313
|
+
const url = new URL(String(input));
|
|
314
|
+
if (url.origin + url.pathname !== API) return jsonResponse({}, 404);
|
|
315
|
+
const page = Number(url.searchParams.get('page') ?? '1');
|
|
316
|
+
return jsonResponse(pages[page - 1] ?? []);
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
describe('createChecker: default mode', () => {
|
|
321
|
+
let tmpDir: string;
|
|
322
|
+
beforeEach(() => {
|
|
323
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'upgrade-test-'));
|
|
324
|
+
vi.restoreAllMocks();
|
|
325
|
+
});
|
|
326
|
+
afterEach(() => {
|
|
327
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
328
|
+
vi.restoreAllMocks();
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it('reads releases/latest only, with the latest-release link and bare cache', async () => {
|
|
332
|
+
const spy = vi
|
|
333
|
+
.spyOn(globalThis, 'fetch')
|
|
334
|
+
.mockResolvedValue(jsonResponse({ tag_name: 'v2.0.0' }));
|
|
335
|
+
const out = new StringStream();
|
|
336
|
+
await createChecker({
|
|
337
|
+
name: 'my-tool',
|
|
338
|
+
currentVersion: '1.0.0',
|
|
339
|
+
owner: 'acme',
|
|
340
|
+
repo: 'mono',
|
|
341
|
+
stateDir: tmpDir,
|
|
342
|
+
}).notifyIfAvailable(out as unknown as NodeJS.WritableStream);
|
|
343
|
+
|
|
344
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
345
|
+
expect(String(spy.mock.calls[0][0])).toBe(`${API}/latest`);
|
|
346
|
+
expect(out.value()).toBe(
|
|
347
|
+
'\nA new release of my-tool is available: v1.0.0 → v2.0.0\n' +
|
|
348
|
+
'https://github.com/acme/mono/releases/latest\n',
|
|
349
|
+
);
|
|
350
|
+
const cache = JSON.parse(
|
|
351
|
+
fs.readFileSync(path.join(tmpDir, '.upgrade-my-tool-cache.json'), 'utf8'),
|
|
352
|
+
);
|
|
353
|
+
expect(Object.keys(cache)).toEqual(['version', 'checkedAt']);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it('stays silent for a component tag when no tagPrefix is set', async () => {
|
|
357
|
+
vi.spyOn(globalThis, 'fetch').mockResolvedValue(
|
|
358
|
+
jsonResponse({ tag_name: 'xray/v0.2.0' }),
|
|
359
|
+
);
|
|
360
|
+
const out = new StringStream();
|
|
361
|
+
await createChecker({
|
|
362
|
+
name: 'xray',
|
|
363
|
+
currentVersion: '0.1.0',
|
|
364
|
+
owner: 'acme',
|
|
365
|
+
repo: 'mono',
|
|
366
|
+
stateDir: tmpDir,
|
|
367
|
+
}).notifyIfAvailable(out as unknown as NodeJS.WritableStream);
|
|
368
|
+
expect(out.value()).toBe('');
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
describe('createChecker: tagPrefix and includePrereleases', () => {
|
|
373
|
+
let tmpDir: string;
|
|
374
|
+
beforeEach(() => {
|
|
375
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'upgrade-test-'));
|
|
376
|
+
vi.restoreAllMocks();
|
|
377
|
+
});
|
|
378
|
+
afterEach(() => {
|
|
379
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
380
|
+
vi.restoreAllMocks();
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
async function run(
|
|
384
|
+
currentVersion: string,
|
|
385
|
+
extra: { tagPrefix?: string; includePrereleases?: boolean },
|
|
386
|
+
): Promise<string> {
|
|
387
|
+
const out = new StringStream();
|
|
388
|
+
await createChecker({
|
|
389
|
+
name: 'xray',
|
|
390
|
+
currentVersion,
|
|
391
|
+
owner: 'acme',
|
|
392
|
+
repo: 'mono',
|
|
393
|
+
stateDir: tmpDir,
|
|
394
|
+
...extra,
|
|
395
|
+
}).notifyIfAvailable(out as unknown as NodeJS.WritableStream);
|
|
396
|
+
return out.value();
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
it('notifies for a prefixed tag and links the exact release', async () => {
|
|
400
|
+
mockListing([[{ tag_name: 'xray/v0.2.0' }]]);
|
|
401
|
+
expect(await run('0.1.0', { tagPrefix: 'xray/v' })).toBe(
|
|
402
|
+
'\nA new release of xray is available: v0.1.0 → v0.2.0\n' +
|
|
403
|
+
'https://github.com/acme/mono/releases/tag/xray/v0.2.0\n',
|
|
404
|
+
);
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
it('ignores other components even when their version is higher', async () => {
|
|
408
|
+
mockListing([[{ tag_name: 'kit/v9.0.0' }, { tag_name: 'xray/v0.2.0' }]]);
|
|
409
|
+
expect(await run('0.1.0', { tagPrefix: 'xray/v' })).toContain('v0.1.0 → v0.2.0');
|
|
410
|
+
|
|
411
|
+
fs.rmSync(path.join(tmpDir, '.upgrade-xray-cache.json'));
|
|
412
|
+
mockListing([[{ tag_name: 'kit/v9.0.0' }, { tag_name: 'xray-cli/v9.0.0' }]]);
|
|
413
|
+
expect(await run('0.1.0', { tagPrefix: 'xray/v' })).toBe('');
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
it('picks the highest semver, not the first listed', async () => {
|
|
417
|
+
mockListing([
|
|
418
|
+
[{ tag_name: 'xray/v0.2.1' }, { tag_name: 'xray/v0.10.0' }, { tag_name: 'xray/v0.9.0' }],
|
|
419
|
+
]);
|
|
420
|
+
expect(await run('0.1.0', { tagPrefix: 'xray/v' })).toContain('→ v0.10.0');
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
it('skips drafts', async () => {
|
|
424
|
+
mockListing([[{ tag_name: 'xray/v0.3.0', draft: true }, { tag_name: 'xray/v0.2.0' }]]);
|
|
425
|
+
expect(await run('0.1.0', { tagPrefix: 'xray/v' })).toContain('→ v0.2.0');
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it('does not nudge a stable user onto a prerelease without includePrereleases', async () => {
|
|
429
|
+
mockListing([
|
|
430
|
+
[
|
|
431
|
+
{ tag_name: 'xray/v0.3.0-rc.1', prerelease: true },
|
|
432
|
+
{ tag_name: 'xray/v0.3.0-rc.0' }, // not flagged by GitHub; semver says prerelease
|
|
433
|
+
],
|
|
434
|
+
]);
|
|
435
|
+
expect(await run('0.2.0', { tagPrefix: 'xray/v' })).toBe('');
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it('offers a newer prerelease to a stable user when includePrereleases is on', async () => {
|
|
439
|
+
mockListing([[{ tag_name: 'xray/v0.3.0-rc.1', prerelease: true }]]);
|
|
440
|
+
expect(await run('0.2.0', { tagPrefix: 'xray/v', includePrereleases: true })).toContain(
|
|
441
|
+
'v0.2.0 → v0.3.0-rc.1',
|
|
442
|
+
);
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
it('shows a prerelease user the newer prerelease', async () => {
|
|
446
|
+
mockListing([
|
|
447
|
+
[
|
|
448
|
+
{ tag_name: 'xray/v0.1.0-rc.1', prerelease: true },
|
|
449
|
+
{ tag_name: 'xray/v0.1.0-rc.0', prerelease: true },
|
|
450
|
+
],
|
|
451
|
+
]);
|
|
452
|
+
const o = { tagPrefix: 'xray/v', includePrereleases: true };
|
|
453
|
+
expect(await run('0.1.0-rc.0', o)).toContain('v0.1.0-rc.0 → v0.1.0-rc.1');
|
|
454
|
+
fs.rmSync(path.join(tmpDir, '.upgrade-xray-cache.json'));
|
|
455
|
+
expect(await run('0.1.0-rc.1', o)).toBe('');
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
it('shows a prerelease user the final stable over its own prereleases', async () => {
|
|
459
|
+
mockListing([
|
|
460
|
+
[
|
|
461
|
+
{ tag_name: 'xray/v0.1.0-rc.1', prerelease: true },
|
|
462
|
+
{ tag_name: 'xray/v0.1.0' },
|
|
463
|
+
],
|
|
464
|
+
]);
|
|
465
|
+
expect(
|
|
466
|
+
await run('0.1.0-rc.0', { tagPrefix: 'xray/v', includePrereleases: true }),
|
|
467
|
+
).toContain('v0.1.0-rc.0 → v0.1.0\n');
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
it('shows a prerelease user the final stable without includePrereleases', async () => {
|
|
471
|
+
mockListing([
|
|
472
|
+
[
|
|
473
|
+
{ tag_name: 'xray/v0.1.0-rc.1', prerelease: true },
|
|
474
|
+
{ tag_name: 'xray/v0.1.0' },
|
|
475
|
+
],
|
|
476
|
+
]);
|
|
477
|
+
expect(await run('0.1.0-rc.0', { tagPrefix: 'xray/v' })).toContain('v0.1.0-rc.0 → v0.1.0\n');
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
it('includePrereleases alone lists releases and links the tag as published', async () => {
|
|
481
|
+
mockListing([[{ tag_name: 'v1.0.0-rc.1', prerelease: true }, { tag_name: 'v0.9.0' }]]);
|
|
482
|
+
expect(await run('0.9.0', { includePrereleases: true })).toBe(
|
|
483
|
+
'\nA new release of xray is available: v0.9.0 → v1.0.0-rc.1\n' +
|
|
484
|
+
'https://github.com/acme/mono/releases/tag/v1.0.0-rc.1\n',
|
|
485
|
+
);
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
it('never calls releases/latest in list mode', async () => {
|
|
489
|
+
const spy = mockListing([[{ tag_name: 'xray/v0.2.0' }]]);
|
|
490
|
+
await run('0.1.0', { tagPrefix: 'xray/v' });
|
|
491
|
+
for (const call of spy.mock.calls) {
|
|
492
|
+
expect(String(call[0])).not.toContain('/releases/latest');
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
it('pages until a short page', async () => {
|
|
497
|
+
const filler = (n: number): Rel[] =>
|
|
498
|
+
Array.from({ length: 100 }, (_, i) => ({ tag_name: `kit/v1.${n}.${i}` }));
|
|
499
|
+
const spy = mockListing([filler(0), [{ tag_name: 'xray/v0.2.0' }]]);
|
|
500
|
+
expect(await run('0.1.0', { tagPrefix: 'xray/v' })).toContain('→ v0.2.0');
|
|
501
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
it('fetches at most 3 pages', async () => {
|
|
505
|
+
const filler = (n: number): Rel[] =>
|
|
506
|
+
Array.from({ length: 100 }, (_, i) => ({ tag_name: `kit/v1.${n}.${i}` }));
|
|
507
|
+
const spy = mockListing([filler(0), filler(1), filler(2), [{ tag_name: 'xray/v0.2.0' }]]);
|
|
508
|
+
expect(await run('0.1.0', { tagPrefix: 'xray/v' })).toBe('');
|
|
509
|
+
expect(spy).toHaveBeenCalledTimes(3);
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
it('keeps earlier pages when a later page fails', async () => {
|
|
513
|
+
const full = Array.from({ length: 100 }, (_, i) => ({ tag_name: `xray/v0.2.${i}` }));
|
|
514
|
+
let n = 0;
|
|
515
|
+
vi.spyOn(globalThis, 'fetch').mockImplementation(async () =>
|
|
516
|
+
++n === 1 ? jsonResponse(full) : jsonResponse({}, 500),
|
|
517
|
+
);
|
|
518
|
+
expect(await run('0.1.0', { tagPrefix: 'xray/v' })).toContain('→ v0.2.99');
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
it('is silent when listing fails, returns junk, or throws', async () => {
|
|
522
|
+
vi.spyOn(globalThis, 'fetch').mockResolvedValue(jsonResponse({}, 403));
|
|
523
|
+
expect(await run('0.1.0', { tagPrefix: 'xray/v' })).toBe('');
|
|
524
|
+
vi.spyOn(globalThis, 'fetch').mockResolvedValue(jsonResponse({ message: 'nope' }));
|
|
525
|
+
expect(await run('0.1.0', { tagPrefix: 'xray/v' })).toBe('');
|
|
526
|
+
vi.spyOn(globalThis, 'fetch').mockResolvedValue(
|
|
527
|
+
jsonResponse([null, { tag_name: 7 }, { tag_name: 'xray/vbogus' }]),
|
|
528
|
+
);
|
|
529
|
+
expect(await run('0.1.0', { tagPrefix: 'xray/v' })).toBe('');
|
|
530
|
+
vi.spyOn(globalThis, 'fetch').mockRejectedValue(new Error('offline'));
|
|
531
|
+
expect(await run('0.1.0', { tagPrefix: 'xray/v' })).toBe('');
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
it('keeps the tag link when the result comes from a fresh cache', async () => {
|
|
535
|
+
const spy = mockListing([[{ tag_name: 'xray/v0.2.0' }]]);
|
|
536
|
+
await run('0.1.0', { tagPrefix: 'xray/v' });
|
|
537
|
+
const second = await run('0.1.0', { tagPrefix: 'xray/v' });
|
|
538
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
539
|
+
expect(second).toContain('releases/tag/xray/v0.2.0');
|
|
540
|
+
});
|
|
541
|
+
it.each([
|
|
542
|
+
['path traversal', 'xray/v/../../../../evil/repo/releases/tag/x'],
|
|
543
|
+
['another version', 'xray/v9.9.9'],
|
|
544
|
+
['another component', 'kit/v2.0.0'],
|
|
545
|
+
['not a string', 42],
|
|
546
|
+
['missing', undefined],
|
|
547
|
+
])('treats a cached tag that does not name the version as a miss: %s', async (_label, tag) => {
|
|
548
|
+
fs.writeFileSync(
|
|
549
|
+
path.join(tmpDir, '.upgrade-xray-cache.json'),
|
|
550
|
+
JSON.stringify({ version: '2.0.0', checkedAt: Date.now(), tag }),
|
|
551
|
+
);
|
|
552
|
+
const spy = vi.spyOn(globalThis, 'fetch').mockResolvedValue(
|
|
553
|
+
jsonResponse([{ tag_name: 'xray/v1.5.0', draft: false, prerelease: false }]),
|
|
554
|
+
);
|
|
555
|
+
const out = new StringStream();
|
|
556
|
+
await createChecker({
|
|
557
|
+
name: 'xray',
|
|
558
|
+
currentVersion: '1.0.0',
|
|
559
|
+
owner: 'acme',
|
|
560
|
+
repo: 'mono',
|
|
561
|
+
stateDir: tmpDir,
|
|
562
|
+
tagPrefix: 'xray/v',
|
|
563
|
+
cacheTTL: 60_000,
|
|
564
|
+
}).notifyIfAvailable(out as unknown as NodeJS.WritableStream);
|
|
565
|
+
expect(spy).toHaveBeenCalled();
|
|
566
|
+
expect(out.value()).toContain('https://github.com/acme/mono/releases/tag/xray/v1.5.0');
|
|
567
|
+
expect(out.value()).not.toContain('evil');
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
it('uses a cached tag that names the version, without fetching', async () => {
|
|
571
|
+
fs.writeFileSync(
|
|
572
|
+
path.join(tmpDir, '.upgrade-xray-cache.json'),
|
|
573
|
+
JSON.stringify({ version: '2.0.0', checkedAt: Date.now(), tag: 'xray/v2.0.0' }),
|
|
574
|
+
);
|
|
575
|
+
const spy = vi.spyOn(globalThis, 'fetch');
|
|
576
|
+
const out = new StringStream();
|
|
577
|
+
await createChecker({
|
|
578
|
+
name: 'xray',
|
|
579
|
+
currentVersion: '1.0.0',
|
|
580
|
+
owner: 'acme',
|
|
581
|
+
repo: 'mono',
|
|
582
|
+
stateDir: tmpDir,
|
|
583
|
+
tagPrefix: 'xray/v',
|
|
584
|
+
cacheTTL: 60_000,
|
|
585
|
+
}).notifyIfAvailable(out as unknown as NodeJS.WritableStream);
|
|
586
|
+
expect(spy).not.toHaveBeenCalled();
|
|
587
|
+
expect(out.value()).toContain('https://github.com/acme/mono/releases/tag/xray/v2.0.0');
|
|
588
|
+
});
|
|
589
|
+
});
|