pi-free-catalog 0.1.0 → 0.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 +14 -1
- package/PUBLISHING-fa.md +21 -9
- package/README-fa.md +4 -4
- package/README.md +12 -6
- package/package.json +4 -3
- package/src/catalog.js +11 -4
- package/test/catalog.test.mjs +18 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 0.1.
|
|
3
|
+
## 0.1.2 — 2026-10-17
|
|
4
|
+
|
|
5
|
+
- Storage: the saved catalog state is now gzipped and compact instead of pretty-printed. On a real catalog this is ~27 MB → ~1.3 MB (about 95% smaller), cutting startup load time and the bytes rewritten on every refresh. `load()` accepts gzipped state and plain JSON, so pre-0.1.2 catalogs still load unchanged.
|
|
6
|
+
- Fixed: `atomicJSON` wrote machine-read state with 2-space indentation, roughly doubling the file for no benefit. Indentation remains off for the catalog; user-facing exports (`/free-export`, `scripts/catalog.mjs`) stay readable plain JSON.
|
|
7
|
+
- Tests: added a regression test asserting the saved state is gzip-magic, far smaller than pretty JSON, round-trips through `load()`, and that a legacy plain-JSON cache still loads.
|
|
8
|
+
|
|
9
|
+
## 0.1.1 — 2026-10-17
|
|
10
|
+
|
|
11
|
+
- Public npm release of the unscoped package `pi-free-catalog` (MIT), superseding 0.1.0.
|
|
12
|
+
- Fixed: `test/package.test.mjs` assumed `npm pack --json` returns an array. npm 12 returns an object keyed by package name, so the assertion threw. It now accepts both shapes, which means `prepublishOnly` verification passes on npm 11 and npm 12.
|
|
13
|
+
- Docs: removed the false "has not been published / provisional name" statements from README.md, README-fa.md and PUBLISHING-fa.md; install instructions now reference the real published name and version.
|
|
14
|
+
- package.json: added `author`; host-provided peer packages now use the `"*"` range prescribed by Pi's `docs/packages.md`.
|
|
15
|
+
|
|
16
|
+
## 0.1.0 — 2026-10-17 — first published release
|
|
4
17
|
|
|
5
18
|
- New independent dual-provider extension, free-kilo + free-zen.
|
|
6
19
|
- Await all five live catalog/price/capability sources on every load.
|
package/PUBLISHING-fa.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# انتشار در npm و نصب تکدستوری در Pi
|
|
2
2
|
|
|
3
|
-
این بسته
|
|
3
|
+
این بسته روی npm منتشر شده است: `pi-free-catalog` (بدون scope، نسخهٔ 0.1.2، نگهدارنده: `aminmza`). این راهنما برای انتشار نسخههای بعدی و بازتولید همین فرایند است. یک بسته هر دو provider را منتشر میکند؛ نیازی به انتشار دو بسته نیست.
|
|
4
4
|
|
|
5
5
|
## ۱. پیشنیاز
|
|
6
6
|
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
طبق مستندات فعلی npm، انتشار بسته به 2FA یا روش مجاز token نیاز دارد. پیشنهاد این راهنما **login و انتشار تعاملی با 2FA** است. رمز، OTP، توکن یا فایل `.npmrc` را در چت/سورس نگذارید. برای CI در آینده trusted publishing را بررسی کنید، نه قراردادن توکن در کد.
|
|
13
13
|
|
|
14
|
-
## ۲. نام
|
|
14
|
+
## ۲. نام و scope بسته
|
|
15
15
|
|
|
16
16
|
داخل پوشهٔ استخراجشده:
|
|
17
17
|
|
|
@@ -23,7 +23,7 @@ npm login
|
|
|
23
23
|
npm whoami
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
این بسته بدون scope منتشر شده است و نیازی به تغییر نام ندارد. فقط اگر میخواهید نسخهٔ خودتان را با scope منتشر کنید، نام را عوض کنید:
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
29
|
NPM_USER="$(npm whoami)"
|
|
@@ -62,7 +62,7 @@ npm publish --access public
|
|
|
62
62
|
برای بررسی پس از انتشار:
|
|
63
63
|
|
|
64
64
|
```bash
|
|
65
|
-
npm view "
|
|
65
|
+
npm view "pi-free-catalog@0.1.2" version dist.integrity dist.shasum
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
## ۵. نصب در Pi با یک دستور
|
|
@@ -70,16 +70,16 @@ npm view "@${NPM_USER}/pi-free-catalog@0.1.0" version dist.integrity
|
|
|
70
70
|
برای همان حساب ناشر و در همان shell:
|
|
71
71
|
|
|
72
72
|
```bash
|
|
73
|
-
pi install "npm
|
|
73
|
+
pi install "npm:pi-free-catalog@0.1.2"
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
برای دیگران،
|
|
76
|
+
برای دیگران، همان نام منتشرشده را بدهید:
|
|
77
77
|
|
|
78
78
|
```bash
|
|
79
|
-
pi install npm
|
|
79
|
+
pi install npm:pi-free-catalog@0.1.2
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
این نام واقعاً روی npm منتشر شده است. پس از نصب، Pi را دوباره اجرا کنید و providerهای `free-kilo` و `free-zen` را انتخاب کنید. npm بسته را نصب میکند؛ کاتالوگ مدلها در هر اجرای خود افزونه از سرویسها بهروز میشود، نه از fixtureهای npm.
|
|
83
83
|
|
|
84
84
|
## ۶. نسخهٔ بعدی
|
|
85
85
|
|
|
@@ -94,10 +94,22 @@ npm publish --access public
|
|
|
94
94
|
|
|
95
95
|
تغییرات و سازگاری را در CHANGELOG ثبت کنید. اگر نسخهٔ جدید User-Agent/README نسخهٔ محصول را تغییر میدهد، آن برچسبها را هم هماهنگ کنید. از افزایش جعلی نسخهٔ پروتکل سازگاری برای پنهانکردن خطای API استفاده نکنید؛ سازگاری را واقعاً تست کنید.
|
|
96
96
|
|
|
97
|
+
## ۷. نکتهٔ عملی: 2FA و انتشار مرحلهای در npm 12
|
|
98
|
+
|
|
99
|
+
npm 12 انتشار را با «staged publishing» انجام میدهد و اثبات حضور (2FA) را به مرحلهای بعد موکول میکند؛ خانوادهٔ دستورهای `npm stage publish|list|view|approve|reject` برای همین کار است.
|
|
100
|
+
|
|
101
|
+
نکتهٔ مهم در محیط بدون TTY (Termux یا CI): کتابخانهٔ npm فقط زمانی جریان احراز هویت مرورگری را اجرا میکند که هر دو ورودی و خروجی TTY باشند؛ در غیر این صورت بیدرنگ خطای `EOTP` میدهد. روی Termux از pty استفاده کنید:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
printf '\n' | script -qec 'npm publish ./pi-free-catalog-0.1.2.tgz --tag latest --access public' /dev/null
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
سپس URL چاپشده را در مرورگر تأیید کنید. ممکن است npm یک نسخهٔ جایگزین `0.0.0-stage` (stub) هم در registry بسازد؛ این نسخهٔ خالی است و برچسب `latest` را تغییر نمیدهد.
|
|
108
|
+
|
|
97
109
|
## مستندات رسمی بررسیشده
|
|
98
110
|
|
|
99
111
|
- https://docs.npmjs.com/cli/v11/commands/npm-publish
|
|
100
112
|
- https://docs.npmjs.com/requiring-2fa-for-package-publishing-and-settings-modification
|
|
101
113
|
- https://docs.npmjs.com/trusted-publishers
|
|
102
114
|
|
|
103
|
-
|
|
115
|
+
نسخهٔ فعلی منتشرشده `pi-free-catalog@0.1.2` است؛ نسخههای بعدی با همان حساب npm و 2FA منتشر میشوند. بررسی کد و مجوز MIT پیش از انتشار همچنان لازم است.
|
package/README-fa.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# افزونهٔ زندهٔ مدلهای رایگان Pi — نسخهٔ 0.1.
|
|
1
|
+
# افزونهٔ زندهٔ مدلهای رایگان Pi — نسخهٔ 0.1.2
|
|
2
2
|
|
|
3
3
|
یک بسته با دو provider مستقل: **`free-kilo`** و **`free-zen`**. پیادهسازی مستقل است؛ افزونهٔ رسمی Kilo/OpenCode نیست. روی **Pi 1.3.0 و Node 22.23.3** آزمایش شده؛ حداقل Node اعلامشده **22.19** است. نسخههای قدیمی Pi تضمین نمیشوند.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**روی npm منتشر شده است:** بستهٔ بدون scope با نام `pi-free-catalog` (نسخهٔ 0.1.2، مجوز MIT، نگهدارنده: `aminmza`). برای نصب از registry: `pi install npm:pi-free-catalog@0.1.2`
|
|
6
6
|
|
|
7
7
|
## نصب محلی
|
|
8
8
|
|
|
@@ -30,7 +30,7 @@ pi
|
|
|
30
30
|
|
|
31
31
|
## همهٔ اطلاعات چه زمانی تازه میشود؟
|
|
32
32
|
|
|
33
|
-
در شروع، درخواستها موازی و با timeout دوازدهثانیهای برای هر منبع ارسال میشوند. بدنهها حداکثر ۱۶ MiB هستند. بدنهٔ خام منابع، مشخصات، قیمت، قابلیتها، وضعیت و زمان دریافت در فایل زیر ذخیره
|
|
33
|
+
در شروع، درخواستها موازی و با timeout دوازدهثانیهای برای هر منبع ارسال میشوند. بدنهها حداکثر ۱۶ MiB هستند. بدنهٔ خام منابع، مشخصات، قیمت، قابلیتها، وضعیت و زمان دریافت در فایل زیر ذخیره میشود (فشرده با gzip و بدون تو رفتگی؛ حدود ۱ تا ۲ مگابایت):
|
|
34
34
|
|
|
35
35
|
```text
|
|
36
36
|
~/.pi/agent/free-catalog/catalog.json
|
|
@@ -124,4 +124,4 @@ node scripts/catalog.mjs /tmp/free-catalog-live.json
|
|
|
124
124
|
|
|
125
125
|
اسکریپتهای `scripts/live_pi.py`، `scripts/observe_live.py` و recorder محافظ `scripts/wire.mjs` نیز همراه سورس هستند. اجرای آنها اختیاری و نیازمند Python 3، Pi نصبشده و مسیرهای `PI_NODE`، `PI_CLI`، `PI_TEST_DISPATCHER` و `FREE_TEST_DIR` است. ابتدا snapshot را با `catalog.mjs` در `FREE_TEST_DIR/live-catalog.json` بنویسید. توضیح دقیقتر در README انگلیسی آمده است. دادههای این آزمونها فقط fixture محلیاند؛ آنها را روی پوشهٔ پروژه/اطلاعات محرمانهٔ خود اجرا نکنید. نتیجهٔ هر مدل را از JSON بخوانید؛ خروج موفق اسکریپت به معنی موفقیت همهٔ مدلهای upstream نیست.
|
|
126
126
|
|
|
127
|
-
گزارش اجرای واقعی این نسخه و فایل شواهد، جدا از بستهٔ قابل انتشار تحویل شدهاند.
|
|
127
|
+
گزارش اجرای واقعی این نسخه و فایل شواهد، جدا از بستهٔ قابل انتشار تحویل شدهاند. روند انتشار نسخههای بعدی در **PUBLISHING-fa.md** آمده است؛ انتشار از حساب npm نگهدارنده با 2FA انجام میشود.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# pi-free-catalog
|
|
2
2
|
|
|
3
|
-
Live, auditable **anonymous Kilo + OpenCode Zen** model discovery for **Pi 1.3.x / Node >=22.19**. One Pi package, two separate providers: `free-kilo` and `free-zen`. This package is an independent integration, not an official service client.
|
|
3
|
+
Live, auditable **anonymous Kilo + OpenCode Zen** model discovery for **Pi 1.3.x / Node >=22.19**. One Pi package, two separate providers: `free-kilo` and `free-zen`. This package is an independent integration, not an official service client. It is published on npm as [`pi-free-catalog`](https://www.npmjs.com/package/pi-free-catalog) under the MIT license, maintained by `aminmza`.
|
|
4
4
|
|
|
5
5
|
[فارسی](README-fa.md) · [Publishing instructions](PUBLISHING-fa.md)
|
|
6
6
|
|
|
@@ -15,7 +15,13 @@ pi
|
|
|
15
15
|
|
|
16
16
|
There is no build step and no third-party runtime dependency beyond Pi's peer packages. Do not `npm install -g` this as a standalone agent. Choose `free-kilo` or `free-zen` in Pi's model picker. You do not need a personal API key, login or OpenCode CLI process. Disable other extensions modifying these requests when diagnosing conflicts.
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
## Install from npm
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pi install npm:pi-free-catalog@0.1.2
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Pin the exact version for reproducibility. `pi -e npm:pi-free-catalog` loads the package for a single invocation without changing your settings.
|
|
19
25
|
|
|
20
26
|
## Non-negotiable: no silent omissions
|
|
21
27
|
|
|
@@ -32,9 +38,9 @@ Once YOU publish, installation becomes `pi install npm:@YOUR_USERNAME/pi-free-ca
|
|
|
32
38
|
|
|
33
39
|
## Refresh, history and retirement
|
|
34
40
|
|
|
35
|
-
Startup awaits bounded parallel source requests (12-second timeout per source, 16 MiB per body). Full raw JSON, exact IDs, metadata, source timestamps, classification and lifecycle history are saved under `<Pi agent directory>/free-catalog/catalog.json
|
|
41
|
+
Startup awaits bounded parallel source requests (12-second timeout per source, 16 MiB per body). Full raw JSON, exact IDs, metadata, source timestamps, classification and lifecycle history are saved under `<Pi agent directory>/free-catalog/catalog.json` (gzip-compressed, compact; roughly 1–2 MB for a live catalog). Normal location: `~/.pi/agent/free-catalog/`.
|
|
36
42
|
|
|
37
|
-
After five minutes, the next agent turn/request revalidates. `/free-refresh` explicitly fetches everything immediately. No permanent background timer. History retains every seen ID; the recent transition event log is bounded to 2,000 events, not the ID inventory.
|
|
43
|
+
After five minutes, the next agent turn/request revalidates. `/free-refresh` explicitly fetches everything immediately. No permanent background timer. History retains every seen ID; the recent transition event log is bounded to 2,000 events, not the ID inventory. The file's size is dominated by the retained raw per-source payloads that make offline evidence and failure fallback possible, not by history; it is bounded by the upstream catalog size and does not grow on repeated refreshes.
|
|
38
44
|
|
|
39
45
|
- Explicit upstream retirement / elapsed explicit retirement date: retired, removed from callable models, retained in history.
|
|
40
46
|
- Missing from a successful catalog: **not-listed**, NOT proven retired; removed from callable models, retained in history. Reappearance restores it automatically.
|
|
@@ -86,7 +92,7 @@ npm install
|
|
|
86
92
|
npm run verify
|
|
87
93
|
```
|
|
88
94
|
|
|
89
|
-
Verification runs syntax checks, offline automated tests against compressed real catalog fixtures (2026-10-17), mocked lifecycle/transport/security tests, real Pi SDK stream/classifier normalization tests, and npm package-content inspection. These are **not live inference claims**. Peer SDK 1.3.0 was used; fixture expectations do not pin the production catalog.
|
|
95
|
+
Verification runs syntax checks, offline automated tests against compressed real catalog fixtures (2026-10-17), mocked lifecycle/transport/security tests, real Pi SDK stream/classifier normalization tests, and npm package-content inspection. These are **not live inference claims**. Peer SDK 1.3.0 was used; fixture expectations do not pin the production catalog. The packaging test accepts both `npm pack --json` output shapes (an array on npm 11, a name-keyed object on npm 12 and later). A storage test asserts the saved state stays gzip-compressed and compact, round-trips, and that a pre-0.1.2 plain-JSON cache still loads.
|
|
90
96
|
|
|
91
97
|
Opt-in live catalog inspection (network, no inference):
|
|
92
98
|
|
|
@@ -96,7 +102,7 @@ node scripts/catalog.mjs /tmp/free-catalog-live.json
|
|
|
96
102
|
|
|
97
103
|
Opt-in real Pi CLI tests are in `scripts/live_pi.py` and `scripts/observe_live.py` (Python 3 + Node + installed Pi peer packages). Set absolute `PI_NODE`, `PI_CLI`, `PI_TEST_DISPATCHER`, and `FREE_TEST_DIR`; generate `FREE_TEST_DIR/live-catalog.json` with `catalog.mjs` first. `PI_TEST_DISPATCHER` is Pi's installed `dist/core/http-dispatcher.js`. `PI_CLI` is its `dist/cli.js`. The separate test-only `wire.mjs` enforces a confirmed-free allowlist and 120 POST attempts/service, records request payloads/HTTP statuses, and is never loaded in production. The suite uses isolated HOME/settings, random fixtures, default tools ON and strict named read/write/edit/bash verification. It exits processes on deadlines. Inspect `inference-results.json`; process exit 0 alone does not mean all upstream models passed. Re-running reuses completed case IDs; use a new evidence directory for a fresh complete run.
|
|
98
104
|
|
|
99
|
-
|
|
105
|
+
Releases are published from the `aminmza` npm account with 2FA enabled. See [PUBLISHING-fa.md](PUBLISHING-fa.md). Never share npm tokens or commit `.npmrc`, credentials, caches or live test files.
|
|
100
106
|
|
|
101
107
|
## Sources
|
|
102
108
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-free-catalog",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Live, auditable anonymous Kilo and OpenCode free model catalogs for Pi. No name-based free filtering.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"author": "Amin Mozaffari <aminmozaffari1185@gmail.com>",
|
|
7
8
|
"keywords": [
|
|
8
9
|
"pi-package",
|
|
9
10
|
"pi",
|
|
@@ -15,8 +16,8 @@
|
|
|
15
16
|
"node": ">=22.19.0"
|
|
16
17
|
},
|
|
17
18
|
"peerDependencies": {
|
|
18
|
-
"@earendil-works/pi-ai": "
|
|
19
|
-
"@earendil-works/pi-coding-agent": "
|
|
19
|
+
"@earendil-works/pi-ai": "*",
|
|
20
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
20
21
|
},
|
|
21
22
|
"pi": {
|
|
22
23
|
"extensions": [
|
package/src/catalog.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readFile, mkdir, writeFile, rename } from 'node:fs/promises';
|
|
2
|
+
import { gzipSync, gunzipSync } from 'node:zlib';
|
|
2
3
|
import { dirname } from 'node:path';
|
|
3
4
|
import { randomUUID } from 'node:crypto';
|
|
4
5
|
|
|
@@ -145,11 +146,14 @@ export function summary(state) {
|
|
|
145
146
|
}
|
|
146
147
|
return result;
|
|
147
148
|
}
|
|
148
|
-
export async function atomicJSON(file, data) {
|
|
149
|
+
export async function atomicJSON(file, data, {gzip=false}={}) {
|
|
149
150
|
await mkdir(dirname(file),{recursive:true,mode:0o700});
|
|
150
151
|
const temp = `${file}.${process.pid}.${randomUUID()}.tmp`;
|
|
151
|
-
|
|
152
|
+
// Compact when gzipping: indentation is pure waste for machine-read state.
|
|
153
|
+
const body = gzip ? gzipSync(JSON.stringify(data)) : JSON.stringify(data,null,2);
|
|
154
|
+
await writeFile(temp,body,{mode:0o600}); await rename(temp,file);
|
|
152
155
|
}
|
|
156
|
+
export const isGzip = (buf) => buf.length >= 2 && buf[0] === 0x1f && buf[1] === 0x8b;
|
|
153
157
|
export class Catalog {
|
|
154
158
|
constructor({file,fetch:fetcher=globalThis.fetch,timeout=12000,now=()=>Date.now(),maxAge=300000}={}) {
|
|
155
159
|
this.file=file;this.fetcher=fetcher;this.timeout=timeout;this.now=now;this.maxAge=maxAge;this.state={schemaVersion:1,sources:{},entries:{},history:[]};this.lastAttempt=0;
|
|
@@ -157,7 +161,10 @@ export class Catalog {
|
|
|
157
161
|
async load() {
|
|
158
162
|
if (!this.file) return;
|
|
159
163
|
try {
|
|
160
|
-
|
|
164
|
+
// Accepts gzipped state (current) and plain JSON (pre-0.1.2 catalogs).
|
|
165
|
+
const buf=await readFile(this.file);
|
|
166
|
+
const text=isGzip(buf)?gunzipSync(buf).toString('utf8'):buf.toString('utf8');
|
|
167
|
+
const state=JSON.parse(text);
|
|
161
168
|
if (state.schemaVersion===1 && state.entries && state.sources) this.state=state;
|
|
162
169
|
} catch(error) { if(error.code!=='ENOENT') this.cacheWarning=String(error); }
|
|
163
170
|
}
|
|
@@ -184,7 +191,7 @@ export class Catalog {
|
|
|
184
191
|
// Never let Pi's startup refresh cancellation invalidate a successful startup snapshot.
|
|
185
192
|
if(signal?.aborted){this.lastAttempt=previousAttempt;throw signal.reason || new Error('Catalog refresh cancelled');}
|
|
186
193
|
this.state=reconcile(sources,old,new Date(this.now()).toISOString());
|
|
187
|
-
if(this.file) try{await atomicJSON(this.file,this.state);}catch(e){this.cacheWarning=String(e);}
|
|
194
|
+
if(this.file) try{await atomicJSON(this.file,this.state,{gzip:true});}catch(e){this.cacheWarning=String(e);}
|
|
188
195
|
return this.state;
|
|
189
196
|
}
|
|
190
197
|
async ensureFresh() { if(this.now()-this.lastAttempt>=this.maxAge) await this.refresh(); }
|
package/test/catalog.test.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import test from 'node:test';
|
|
|
2
2
|
import assert from 'node:assert/strict';
|
|
3
3
|
import { mkdtemp, readFile, writeFile, rm } from 'node:fs/promises';
|
|
4
4
|
import { tmpdir } from 'node:os';
|
|
5
|
+
import { gunzipSync } from 'node:zlib';
|
|
5
6
|
import { join } from 'node:path';
|
|
6
7
|
import { Catalog, reconcile, recordKey, summary, priceClass, validateSource } from '../src/catalog.js';
|
|
7
8
|
import { registrations, report } from '../src/models.js';
|
|
@@ -93,7 +94,23 @@ test('startup load is followed by new network calls, updates saved cache, concur
|
|
|
93
94
|
const fetch=async(...a)=>{calls++;return fetcher()(...a);};
|
|
94
95
|
const a=new Catalog({file,fetch});await a.refresh();assert.equal(calls,5);
|
|
95
96
|
const b=new Catalog({file,fetch});await b.load();await Promise.all([b.refresh(),b.refresh()]);assert.equal(calls,10);
|
|
96
|
-
assert.equal(JSON.parse(await readFile(file
|
|
97
|
+
assert.equal(JSON.parse(gunzipSync(await readFile(file)).toString('utf8')).schemaVersion,1);assert.equal(summary(b.state).kilo.free,17);
|
|
98
|
+
}finally{await rm(dir,{recursive:true,force:true});}
|
|
99
|
+
});
|
|
100
|
+
test('saved state is gzipped and compact, round-trips, and legacy plain caches still load',async()=>{
|
|
101
|
+
const dir=await mkdtemp(join(tmpdir(),'pi-free-gz-'));try{
|
|
102
|
+
const file=join(dir,'catalog.json');
|
|
103
|
+
const a=new Catalog({file,fetch:fetcher()});await a.refresh();
|
|
104
|
+
const raw=await readFile(file);
|
|
105
|
+
assert.equal(raw[0],0x1f);assert.equal(raw[1],0x8b);
|
|
106
|
+
const parsed=JSON.parse(gunzipSync(raw).toString('utf8'));assert.equal(parsed.schemaVersion,1);
|
|
107
|
+
const pretty=Buffer.byteLength(JSON.stringify(parsed,null,2));
|
|
108
|
+
assert.ok(raw.length*3<pretty,`gzipped ${raw.length} should be far below pretty ${pretty}`);
|
|
109
|
+
const b=new Catalog({file,fetch:fetcher()});await b.load();
|
|
110
|
+
assert.equal(summary(b.state).kilo.free,17);
|
|
111
|
+
assert.equal(Object.keys(b.state.entries).length,Object.keys(parsed.entries).length);
|
|
112
|
+
const legacy=join(dir,'legacy.json');await writeFile(legacy,JSON.stringify(parsed,null,2));
|
|
113
|
+
const c=new Catalog({file:legacy,fetch:fetcher()});await c.load();assert.equal(summary(c.state).kilo.free,17);
|
|
97
114
|
}finally{await rm(dir,{recursive:true,force:true});}
|
|
98
115
|
});
|
|
99
116
|
test('fresh paid price beats stale free source and blocks dispatch',async()=>{
|