pi-harness-runtime 0.9.7 → 0.9.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 +24 -12
- package/README.md +42 -5
- package/footer-status.ts +108 -11
- package/harness/e2e/minimax-quota-scraper.ts +46 -4
- package/index.ts +224 -16
- package/mirror.ts +194 -18
- package/package.json +1 -1
- package/packages/a2a-adapter/package.json +1 -1
- package/packages/auth/package.json +1 -1
- package/packages/autonomous-refactor/package.json +1 -1
- package/packages/cache-strategy/package.json +1 -1
- package/packages/capability-registry/package.json +1 -1
- package/packages/checkpoint/package.json +1 -1
- package/packages/cli-plugin-sdk/package.json +1 -1
- package/packages/code-generation/package.json +1 -1
- package/packages/code-review/package.json +1 -1
- package/packages/codex-adapter/package.json +1 -1
- package/packages/context-compiler/package.json +1 -1
- package/packages/context-manager/package.json +1 -1
- package/packages/cookie-sanitizer/README.md +141 -0
- package/packages/cookie-sanitizer/dist/atomic-write.d.ts +38 -0
- package/packages/cookie-sanitizer/dist/atomic-write.d.ts.map +1 -0
- package/packages/cookie-sanitizer/dist/atomic-write.js +67 -0
- package/packages/cookie-sanitizer/dist/atomic-write.js.map +1 -0
- package/packages/cookie-sanitizer/dist/detect-format.d.ts +36 -0
- package/packages/cookie-sanitizer/dist/detect-format.d.ts.map +1 -0
- package/packages/cookie-sanitizer/dist/detect-format.js +88 -0
- package/packages/cookie-sanitizer/dist/detect-format.js.map +1 -0
- package/packages/cookie-sanitizer/dist/index.d.ts +41 -0
- package/packages/cookie-sanitizer/dist/index.d.ts.map +1 -0
- package/packages/cookie-sanitizer/dist/index.js +39 -0
- package/packages/cookie-sanitizer/dist/index.js.map +1 -0
- package/packages/cookie-sanitizer/dist/infer-provider.d.ts +29 -0
- package/packages/cookie-sanitizer/dist/infer-provider.d.ts.map +1 -0
- package/packages/cookie-sanitizer/dist/infer-provider.js +96 -0
- package/packages/cookie-sanitizer/dist/infer-provider.js.map +1 -0
- package/packages/cookie-sanitizer/dist/normalize.d.ts +26 -0
- package/packages/cookie-sanitizer/dist/normalize.d.ts.map +1 -0
- package/packages/cookie-sanitizer/dist/normalize.js +75 -0
- package/packages/cookie-sanitizer/dist/normalize.js.map +1 -0
- package/packages/cookie-sanitizer/dist/parse-json.d.ts +45 -0
- package/packages/cookie-sanitizer/dist/parse-json.d.ts.map +1 -0
- package/packages/cookie-sanitizer/dist/parse-json.js +108 -0
- package/packages/cookie-sanitizer/dist/parse-json.js.map +1 -0
- package/packages/cookie-sanitizer/dist/parse-netscape.d.ts +43 -0
- package/packages/cookie-sanitizer/dist/parse-netscape.d.ts.map +1 -0
- package/packages/cookie-sanitizer/dist/parse-netscape.js +99 -0
- package/packages/cookie-sanitizer/dist/parse-netscape.js.map +1 -0
- package/packages/cookie-sanitizer/dist/sync.d.ts +62 -0
- package/packages/cookie-sanitizer/dist/sync.d.ts.map +1 -0
- package/packages/cookie-sanitizer/dist/sync.js +266 -0
- package/packages/cookie-sanitizer/dist/sync.js.map +1 -0
- package/packages/cookie-sanitizer/dist/types.d.ts +100 -0
- package/packages/cookie-sanitizer/dist/types.d.ts.map +1 -0
- package/packages/cookie-sanitizer/dist/types.js +13 -0
- package/packages/cookie-sanitizer/dist/types.js.map +1 -0
- package/packages/cookie-sanitizer/dist/watcher.d.ts +51 -0
- package/packages/cookie-sanitizer/dist/watcher.d.ts.map +1 -0
- package/packages/cookie-sanitizer/dist/watcher.js +148 -0
- package/packages/cookie-sanitizer/dist/watcher.js.map +1 -0
- package/packages/cookie-sanitizer/package.json +27 -0
- package/packages/cookie-sanitizer/src/atomic-write.ts +79 -0
- package/packages/cookie-sanitizer/src/detect-format.ts +102 -0
- package/packages/cookie-sanitizer/src/index.ts +89 -0
- package/packages/cookie-sanitizer/src/infer-provider.ts +103 -0
- package/packages/cookie-sanitizer/src/normalize.ts +92 -0
- package/packages/cookie-sanitizer/src/parse-json.ts +122 -0
- package/packages/cookie-sanitizer/src/parse-netscape.ts +118 -0
- package/packages/cookie-sanitizer/src/sync.ts +304 -0
- package/packages/cookie-sanitizer/src/types.ts +101 -0
- package/packages/cookie-sanitizer/src/watcher.ts +180 -0
- package/packages/cookie-sanitizer/test/infer.test.ts +110 -0
- package/packages/cookie-sanitizer/test/normalize.test.ts +113 -0
- package/packages/cookie-sanitizer/test/parse.test.ts +204 -0
- package/packages/cookie-sanitizer/test/sync.test.ts +231 -0
- package/packages/cookie-sanitizer/test/watcher.test.ts +27 -0
- package/packages/cookie-sanitizer/tsconfig.json +8 -0
- package/packages/cost-optimizer/package.json +1 -1
- package/packages/django-plugin/package.json +1 -1
- package/packages/doc-generator/package.json +1 -1
- package/packages/evaluation-engine/package.json +1 -1
- package/packages/evaluation-runner/package.json +1 -1
- package/packages/experience-replay/package.json +1 -1
- package/packages/feedback-collector/package.json +1 -1
- package/packages/framework-detector/package.json +1 -1
- package/packages/framework-plugin-sdk/package.json +1 -1
- package/packages/frappe-plugin/package.json +1 -1
- package/packages/generic-web-plugin/package.json +1 -1
- package/packages/health-monitor/package.json +1 -1
- package/packages/laravel-plugin/package.json +1 -1
- package/packages/learning-engine/package.json +1 -1
- package/packages/mcp-adapter/package.json +1 -1
- package/packages/memory-engine/package.json +1 -1
- package/packages/model-registry/package.json +1 -1
- package/packages/nextjs-plugin/package.json +1 -1
- package/packages/notification/package.json +1 -1
- package/packages/observability/package.json +1 -1
- package/packages/performance-optimizer/package.json +1 -1
- package/packages/project-analyzer/package.json +1 -1
- package/packages/prompt-compiler/package.json +1 -1
- package/packages/prompt-versioning/package.json +1 -1
- package/packages/provider-adapter-sdk/package.json +1 -1
- package/packages/provider-router/package.json +1 -1
- package/packages/provider-selector/package.json +1 -1
- package/packages/providers/dist/index.d.ts +1 -0
- package/packages/providers/dist/index.d.ts.map +1 -1
- package/packages/providers/dist/index.js +1 -0
- package/packages/providers/dist/index.js.map +1 -1
- package/packages/providers/dist/provider-id.d.ts +39 -0
- package/packages/providers/dist/provider-id.d.ts.map +1 -0
- package/packages/providers/dist/provider-id.js +96 -0
- package/packages/providers/dist/provider-id.js.map +1 -0
- package/packages/providers/package.json +1 -1
- package/packages/providers/src/index.ts +1 -0
- package/packages/providers/src/provider-id.ts +110 -0
- package/packages/quota-manager/package.json +1 -1
- package/packages/rate-limiter/package.json +1 -1
- package/packages/react-vite-plugin/package.json +1 -1
- package/packages/release-manager/package.json +1 -1
- package/packages/requirement-compiler/package.json +1 -1
- package/packages/runtime/package.json +1 -1
- package/packages/scheduler/package.json +1 -1
- package/packages/session/package.json +1 -1
- package/packages/shared-context/package.json +1 -1
- package/packages/skill-registry/package.json +1 -1
- package/packages/sprint-planner/package.json +1 -1
- package/packages/task-compiler/package.json +1 -1
- package/packages/test-data-generator/package.json +1 -1
- package/packages/test-generator/package.json +1 -1
- package/packages/token-estimation/package.json +1 -1
- package/packages/token-optimizer/package.json +1 -1
- package/packages/tui/package.json +1 -1
- package/packages/types/package.json +1 -1
- package/packages/worktree/package.json +1 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalization tests — dedupe, expire, domain-match, tag.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect } from "bun:test";
|
|
6
|
+
import {
|
|
7
|
+
normalize,
|
|
8
|
+
domainMatchesProvider,
|
|
9
|
+
isExpired,
|
|
10
|
+
} from "../src/normalize.js";
|
|
11
|
+
import type { CanonicalCookie } from "../src/types.js";
|
|
12
|
+
|
|
13
|
+
const NOW = 1_700_000_000;
|
|
14
|
+
|
|
15
|
+
function cookie(over: Partial<CanonicalCookie> = {}): CanonicalCookie {
|
|
16
|
+
return {
|
|
17
|
+
name: "n1",
|
|
18
|
+
value: "v1",
|
|
19
|
+
domain: ".minimax.io",
|
|
20
|
+
path: "/",
|
|
21
|
+
secure: false,
|
|
22
|
+
httpOnly: false,
|
|
23
|
+
...over,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe("domainMatchesProvider", () => {
|
|
28
|
+
it("matches minimax subdomains", () => {
|
|
29
|
+
expect(domainMatchesProvider(".minimax.io", "minimax")).toBe(true);
|
|
30
|
+
expect(domainMatchesProvider("platform.minimax.io", "minimax")).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("rejects unrelated domains", () => {
|
|
34
|
+
expect(domainMatchesProvider(".example.com", "minimax")).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("accepts all domains for unknown provider (let downstream reject)", () => {
|
|
38
|
+
expect(domainMatchesProvider(".anything.tld", "weird-provider")).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe("isExpired", () => {
|
|
43
|
+
it("returns false for session cookies", () => {
|
|
44
|
+
expect(isExpired(cookie({ expires: undefined }), NOW)).toBe(false);
|
|
45
|
+
expect(isExpired(cookie({ expires: 0 }), NOW)).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("returns true for past timestamps", () => {
|
|
49
|
+
expect(isExpired(cookie({ expires: NOW - 1 }), NOW)).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("returns false for future timestamps", () => {
|
|
53
|
+
expect(isExpired(cookie({ expires: NOW + 1 }), NOW)).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe("normalize", () => {
|
|
58
|
+
it("dedupes by (domain, name); last wins", () => {
|
|
59
|
+
const input: CanonicalCookie[] = [
|
|
60
|
+
cookie({ name: "n", value: "v1" }),
|
|
61
|
+
cookie({ name: "n", value: "v2" }),
|
|
62
|
+
];
|
|
63
|
+
const out = normalize(input, "minimax", NOW);
|
|
64
|
+
expect(out).toHaveLength(1);
|
|
65
|
+
expect(out[0]?.value).toBe("v2");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("drops empty name/value", () => {
|
|
69
|
+
const input: CanonicalCookie[] = [
|
|
70
|
+
cookie({ name: "" }),
|
|
71
|
+
cookie({ value: "" }),
|
|
72
|
+
cookie({ name: "ok", value: "v" }),
|
|
73
|
+
];
|
|
74
|
+
const out = normalize(input, "minimax", NOW);
|
|
75
|
+
expect(out).toHaveLength(1);
|
|
76
|
+
expect(out[0]?.name).toBe("ok");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("drops expired cookies", () => {
|
|
80
|
+
const input: CanonicalCookie[] = [
|
|
81
|
+
cookie({ expires: NOW - 100 }),
|
|
82
|
+
cookie({ expires: NOW + 100 }),
|
|
83
|
+
];
|
|
84
|
+
const out = normalize(input, "minimax", NOW);
|
|
85
|
+
expect(out).toHaveLength(1);
|
|
86
|
+
expect(out[0]?.expires).toBe(NOW + 100);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("drops cookies whose domain doesn't match provider", () => {
|
|
90
|
+
const input: CanonicalCookie[] = [
|
|
91
|
+
cookie({ domain: ".minimax.io" }),
|
|
92
|
+
cookie({ domain: ".other.com", name: "other" }),
|
|
93
|
+
];
|
|
94
|
+
const out = normalize(input, "minimax", NOW);
|
|
95
|
+
expect(out).toHaveLength(1);
|
|
96
|
+
expect(out[0]?.domain).toBe(".minimax.io");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("tags each surviving cookie with the provider", () => {
|
|
100
|
+
const input: CanonicalCookie[] = [
|
|
101
|
+
cookie({ name: "n1" }),
|
|
102
|
+
cookie({ name: "n2" }),
|
|
103
|
+
];
|
|
104
|
+
const out = normalize(input, "minimax", NOW);
|
|
105
|
+
for (const c of out) {
|
|
106
|
+
expect(c.provider).toBe("minimax");
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("returns empty array on empty input", () => {
|
|
111
|
+
expect(normalize([], "minimax", NOW)).toEqual([]);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser tests — Netscape + EditThisCookie JSON.
|
|
3
|
+
*
|
|
4
|
+
* Critical: never put real cookie VALUES in test fixtures. We use
|
|
5
|
+
* obvious test values like "test-value" or short synthetic strings
|
|
6
|
+
* to keep secrets hygiene.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, it, expect } from "bun:test";
|
|
10
|
+
import { parseNetscape, serializeNetscape } from "../src/parse-netscape.js";
|
|
11
|
+
import { parseEditThisCookieJson } from "../src/parse-json.js";
|
|
12
|
+
import type { CanonicalCookie } from "../src/types.js";
|
|
13
|
+
|
|
14
|
+
describe("parseNetscape", () => {
|
|
15
|
+
it("parses a standard 7-column row", () => {
|
|
16
|
+
const text = [
|
|
17
|
+
"# Netscape HTTP Cookie File",
|
|
18
|
+
"# https://curl.haxx.se/rfc/cookie_spec.html",
|
|
19
|
+
"# This is a generated file! Do not edit.",
|
|
20
|
+
"",
|
|
21
|
+
"#HttpOnly_.minimax.io\tTRUE\t/\tTRUE\t0\ttest_token\ttest-value",
|
|
22
|
+
".minimax.io\tFALSE\t/\tFALSE\t0\ttest_id\ttest-id-value",
|
|
23
|
+
].join("\n");
|
|
24
|
+
const cookies = parseNetscape(text);
|
|
25
|
+
expect(cookies).toHaveLength(2);
|
|
26
|
+
expect(cookies[0]?.name).toBe("test_token");
|
|
27
|
+
expect(cookies[0]?.value).toBe("test-value");
|
|
28
|
+
expect(cookies[0]?.httpOnly).toBe(true);
|
|
29
|
+
expect(cookies[0]?.secure).toBe(true);
|
|
30
|
+
expect(cookies[1]?.name).toBe("test_id");
|
|
31
|
+
expect(cookies[1]?.httpOnly).toBe(false);
|
|
32
|
+
expect(cookies[1]?.secure).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("skips malformed rows (< 7 cols)", () => {
|
|
36
|
+
const text = [
|
|
37
|
+
"# Netscape HTTP Cookie File",
|
|
38
|
+
".minimax.io\tTRUE\t/\tTRUE", // only 4 cols
|
|
39
|
+
".minimax.io\tTRUE\t/\tTRUE\t0\tname\tvalue", // OK
|
|
40
|
+
].join("\n");
|
|
41
|
+
const cookies = parseNetscape(text);
|
|
42
|
+
expect(cookies).toHaveLength(1);
|
|
43
|
+
expect(cookies[0]?.name).toBe("name");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("skips blank lines and comment-only lines", () => {
|
|
47
|
+
const text = [
|
|
48
|
+
"",
|
|
49
|
+
"# comment",
|
|
50
|
+
"#HttpOnly_.minimax.io\tTRUE\t/\tTRUE\t0\tn1\tv1",
|
|
51
|
+
"",
|
|
52
|
+
].join("\n");
|
|
53
|
+
const cookies = parseNetscape(text);
|
|
54
|
+
expect(cookies).toHaveLength(1);
|
|
55
|
+
expect(cookies[0]?.name).toBe("n1");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("returns empty array for empty input", () => {
|
|
59
|
+
expect(parseNetscape("")).toEqual([]);
|
|
60
|
+
expect(parseNetscape("not a real file")).toEqual([]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("treats expires=0 as session cookie (undefined)", () => {
|
|
64
|
+
const text = ".minimax.io\tFALSE\t/\tFALSE\t0\tn1\tv1";
|
|
65
|
+
const cookies = parseNetscape(text);
|
|
66
|
+
expect(cookies[0]?.expires).toBeUndefined();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("preserves non-zero expires as a number", () => {
|
|
70
|
+
const text = ".minimax.io\tFALSE\t/\tFALSE\t1700000000\tn1\tv1";
|
|
71
|
+
const cookies = parseNetscape(text);
|
|
72
|
+
expect(cookies[0]?.expires).toBe(1700000000);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe("serializeNetscape", () => {
|
|
77
|
+
it("round-trips a single cookie", () => {
|
|
78
|
+
const cookies: CanonicalCookie[] = [
|
|
79
|
+
{
|
|
80
|
+
name: "n1",
|
|
81
|
+
value: "v1",
|
|
82
|
+
domain: ".minimax.io",
|
|
83
|
+
path: "/",
|
|
84
|
+
secure: true,
|
|
85
|
+
httpOnly: true,
|
|
86
|
+
expires: 0,
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
const out = serializeNetscape(cookies);
|
|
90
|
+
const back = parseNetscape(out);
|
|
91
|
+
expect(back).toHaveLength(1);
|
|
92
|
+
expect(back[0]?.name).toBe("n1");
|
|
93
|
+
expect(back[0]?.value).toBe("v1");
|
|
94
|
+
expect(back[0]?.httpOnly).toBe(true);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("emits the canonical header on every output", () => {
|
|
98
|
+
const out = serializeNetscape([]);
|
|
99
|
+
expect(out).toContain("# Netscape HTTP Cookie File");
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("drops cookies with empty name or value", () => {
|
|
103
|
+
const cookies: CanonicalCookie[] = [
|
|
104
|
+
{
|
|
105
|
+
name: "",
|
|
106
|
+
value: "v",
|
|
107
|
+
domain: ".x.io",
|
|
108
|
+
path: "/",
|
|
109
|
+
secure: false,
|
|
110
|
+
httpOnly: false,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: "n",
|
|
114
|
+
value: "",
|
|
115
|
+
domain: ".x.io",
|
|
116
|
+
path: "/",
|
|
117
|
+
secure: false,
|
|
118
|
+
httpOnly: false,
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: "ok",
|
|
122
|
+
value: "v",
|
|
123
|
+
domain: ".x.io",
|
|
124
|
+
path: "/",
|
|
125
|
+
secure: false,
|
|
126
|
+
httpOnly: false,
|
|
127
|
+
},
|
|
128
|
+
];
|
|
129
|
+
const out = serializeNetscape(cookies);
|
|
130
|
+
const back = parseNetscape(out);
|
|
131
|
+
expect(back).toHaveLength(1);
|
|
132
|
+
expect(back[0]?.name).toBe("ok");
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe("parseEditThisCookieJson", () => {
|
|
137
|
+
it("parses a Chrome devtools / EditThisCookie export array", () => {
|
|
138
|
+
const text = JSON.stringify([
|
|
139
|
+
{
|
|
140
|
+
domain: ".minimax.io",
|
|
141
|
+
expirationDate: 1700000000,
|
|
142
|
+
hostOnly: false,
|
|
143
|
+
httpOnly: true,
|
|
144
|
+
name: "test_token",
|
|
145
|
+
path: "/",
|
|
146
|
+
secure: true,
|
|
147
|
+
session: false,
|
|
148
|
+
value: "test-value",
|
|
149
|
+
},
|
|
150
|
+
]);
|
|
151
|
+
const cookies = parseEditThisCookieJson(text);
|
|
152
|
+
expect(cookies).toHaveLength(1);
|
|
153
|
+
expect(cookies[0]?.name).toBe("test_token");
|
|
154
|
+
expect(cookies[0]?.httpOnly).toBe(true);
|
|
155
|
+
expect(cookies[0]?.expires).toBe(1700000000);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("parses a single object (not array)", () => {
|
|
159
|
+
const text = JSON.stringify({
|
|
160
|
+
domain: ".minimax.io",
|
|
161
|
+
expirationDate: 1700000000,
|
|
162
|
+
name: "n1",
|
|
163
|
+
value: "v1",
|
|
164
|
+
secure: true,
|
|
165
|
+
httpOnly: false,
|
|
166
|
+
});
|
|
167
|
+
const cookies = parseEditThisCookieJson(text);
|
|
168
|
+
expect(cookies).toHaveLength(1);
|
|
169
|
+
expect(cookies[0]?.name).toBe("n1");
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("treats millisecond timestamps as such (>1e12)", () => {
|
|
173
|
+
const ms = 1700000000000; // ms, not sec
|
|
174
|
+
const text = JSON.stringify([
|
|
175
|
+
{ name: "n", value: "v", expirationDate: ms },
|
|
176
|
+
]);
|
|
177
|
+
const cookies = parseEditThisCookieJson(text);
|
|
178
|
+
expect(cookies[0]?.expires).toBe(Math.floor(ms / 1000));
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("treats session=true as undefined expires", () => {
|
|
182
|
+
const text = JSON.stringify([
|
|
183
|
+
{ name: "n", value: "v", session: true, expirationDate: 9999 },
|
|
184
|
+
]);
|
|
185
|
+
const cookies = parseEditThisCookieJson(text);
|
|
186
|
+
expect(cookies[0]?.expires).toBeUndefined();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("skips records with empty name or value", () => {
|
|
190
|
+
const text = JSON.stringify([
|
|
191
|
+
{ name: "", value: "v", domain: ".x.io" },
|
|
192
|
+
{ name: "n", value: "", domain: ".x.io" },
|
|
193
|
+
{ name: "ok", value: "v", domain: ".x.io" },
|
|
194
|
+
]);
|
|
195
|
+
const cookies = parseEditThisCookieJson(text);
|
|
196
|
+
expect(cookies).toHaveLength(1);
|
|
197
|
+
expect(cookies[0]?.name).toBe("ok");
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("returns [] on invalid JSON", () => {
|
|
201
|
+
expect(parseEditThisCookieJson("not json")).toEqual([]);
|
|
202
|
+
expect(parseEditThisCookieJson("")).toEqual([]);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* End-to-end sync tests.
|
|
3
|
+
*
|
|
4
|
+
* Build a synthetic drop folder in a tmp dir, call sync(), assert
|
|
5
|
+
* the canonical cache was written correctly. No real cookie values
|
|
6
|
+
* are used.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, it, expect, beforeEach, afterEach } from "bun:test";
|
|
10
|
+
import {
|
|
11
|
+
mkdtempSync,
|
|
12
|
+
mkdirSync,
|
|
13
|
+
writeFileSync,
|
|
14
|
+
rmSync,
|
|
15
|
+
existsSync,
|
|
16
|
+
readFileSync,
|
|
17
|
+
} from "node:fs";
|
|
18
|
+
import { join } from "node:path";
|
|
19
|
+
import { tmpdir } from "node:os";
|
|
20
|
+
import {
|
|
21
|
+
sync,
|
|
22
|
+
hasAnyCookieSource,
|
|
23
|
+
inferCachePath,
|
|
24
|
+
DEFAULT_DROP_DIR,
|
|
25
|
+
} from "../src/sync.js";
|
|
26
|
+
import { parseNetscape } from "../src/parse-netscape.js";
|
|
27
|
+
|
|
28
|
+
const NETSCAPE_FIXTURE = [
|
|
29
|
+
"# Netscape HTTP Cookie File",
|
|
30
|
+
"# Test fixture for sync.test.ts",
|
|
31
|
+
".minimax.io\tFALSE\t/\tFALSE\t0\ttest_id\ttest-value-id",
|
|
32
|
+
"#HttpOnly_.minimax.io\tFALSE\t/\tTRUE\t0\ttest_token\ttest-value-token",
|
|
33
|
+
"",
|
|
34
|
+
].join("\n");
|
|
35
|
+
|
|
36
|
+
const JSON_FIXTURE = JSON.stringify([
|
|
37
|
+
{
|
|
38
|
+
domain: ".minimax.io",
|
|
39
|
+
expirationDate: 1700000000,
|
|
40
|
+
name: "test_json",
|
|
41
|
+
value: "test-value-json",
|
|
42
|
+
httpOnly: false,
|
|
43
|
+
secure: true,
|
|
44
|
+
},
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
let TMP_ROOT: string;
|
|
48
|
+
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
TMP_ROOT = mkdtempSync(join(tmpdir(), "cookie-sanitizer-test-"));
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
afterEach(() => {
|
|
54
|
+
if (TMP_ROOT) rmSync(TMP_ROOT, { force: true, recursive: true });
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/** Per-test drop folder under TMP_ROOT. */
|
|
58
|
+
function freshDropDir(): string {
|
|
59
|
+
const sub = join(TMP_ROOT, "drop");
|
|
60
|
+
rmSync(sub, { force: true, recursive: true });
|
|
61
|
+
mkdirSync(sub, { recursive: true });
|
|
62
|
+
return sub;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
describe("sync()", () => {
|
|
66
|
+
it("writes a canonical cache from a Netscape drop file", () => {
|
|
67
|
+
const drop = freshDropDir();
|
|
68
|
+
const cache = join(drop, "out.txt");
|
|
69
|
+
writeFileSync(join(drop, "minimax.txt"), NETSCAPE_FIXTURE);
|
|
70
|
+
|
|
71
|
+
const result = sync({ dropDir: drop, cachePath: cache });
|
|
72
|
+
|
|
73
|
+
expect(result.provider).toBe("minimax");
|
|
74
|
+
expect(result.processedFiles).toContain("minimax.txt");
|
|
75
|
+
expect(result.skippedFiles).toEqual([]);
|
|
76
|
+
expect(result.wrote).toBe(true);
|
|
77
|
+
expect(result.totalCookies).toBe(2);
|
|
78
|
+
expect(result.cachePath).toBe(cache);
|
|
79
|
+
expect(existsSync(cache)).toBe(true);
|
|
80
|
+
|
|
81
|
+
const back = parseNetscape(readFileSync(cache, "utf8"));
|
|
82
|
+
expect(back).toHaveLength(2);
|
|
83
|
+
const names = back.map((c) => c.name).sort();
|
|
84
|
+
expect(names).toEqual(["test_id", "test_token"]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("writes a canonical cache from a JSON drop file", () => {
|
|
88
|
+
const drop = freshDropDir();
|
|
89
|
+
const cache = join(drop, "out.txt");
|
|
90
|
+
writeFileSync(join(drop, "minimax.json"), JSON_FIXTURE);
|
|
91
|
+
|
|
92
|
+
const result = sync({ dropDir: drop, cachePath: cache });
|
|
93
|
+
|
|
94
|
+
expect(result.provider).toBe("minimax");
|
|
95
|
+
expect(result.totalCookies).toBe(1);
|
|
96
|
+
expect(result.wrote).toBe(true);
|
|
97
|
+
const back = parseNetscape(readFileSync(cache, "utf8"));
|
|
98
|
+
expect(back[0]?.name).toBe("test_json");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("merges multiple files (Netscape + JSON) and dedupes", () => {
|
|
102
|
+
const drop = freshDropDir();
|
|
103
|
+
const cache = join(drop, "out.txt");
|
|
104
|
+
writeFileSync(join(drop, "minimax.txt"), NETSCAPE_FIXTURE);
|
|
105
|
+
writeFileSync(join(drop, "extra.json"), JSON_FIXTURE);
|
|
106
|
+
|
|
107
|
+
const result = sync({ dropDir: drop, cachePath: cache });
|
|
108
|
+
expect(result.totalCookies).toBe(3);
|
|
109
|
+
expect(result.processedFiles.sort()).toEqual(["extra.json", "minimax.txt"]);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("skips files with unknown format and reports them", () => {
|
|
113
|
+
const drop = freshDropDir();
|
|
114
|
+
const cache = join(drop, "out.txt");
|
|
115
|
+
writeFileSync(join(drop, "minimax.txt"), NETSCAPE_FIXTURE);
|
|
116
|
+
writeFileSync(join(drop, "garbage.txt"), "this is not a cookie file");
|
|
117
|
+
|
|
118
|
+
const result = sync({ dropDir: drop, cachePath: cache });
|
|
119
|
+
expect(result.wrote).toBe(true);
|
|
120
|
+
expect(result.totalCookies).toBe(2);
|
|
121
|
+
expect(
|
|
122
|
+
result.skippedFiles.find((f) => f.basename === "garbage.txt"),
|
|
123
|
+
).toBeTruthy();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("skips editor temp files and dotfiles", () => {
|
|
127
|
+
const drop = freshDropDir();
|
|
128
|
+
const cache = join(drop, "out.txt");
|
|
129
|
+
writeFileSync(join(drop, "minimax.txt"), NETSCAPE_FIXTURE);
|
|
130
|
+
writeFileSync(join(drop, ".hidden"), NETSCAPE_FIXTURE);
|
|
131
|
+
writeFileSync(join(drop, "minimax.swp"), NETSCAPE_FIXTURE);
|
|
132
|
+
writeFileSync(join(drop, "minimax~"), NETSCAPE_FIXTURE);
|
|
133
|
+
|
|
134
|
+
const result = sync({ dropDir: drop, cachePath: cache });
|
|
135
|
+
expect(result.processedFiles).toEqual(["minimax.txt"]);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("excludes the canonical cache file from input", () => {
|
|
139
|
+
const drop = freshDropDir();
|
|
140
|
+
const cache = join(drop, "out.txt");
|
|
141
|
+
writeFileSync(join(drop, "minimax.txt"), NETSCAPE_FIXTURE);
|
|
142
|
+
// Pre-write the cache to simulate a previous run.
|
|
143
|
+
writeFileSync(cache, NETSCAPE_FIXTURE);
|
|
144
|
+
|
|
145
|
+
const result = sync({ dropDir: drop, cachePath: cache });
|
|
146
|
+
// The cache file itself was excluded from input; only minimax.txt was read.
|
|
147
|
+
expect(result.processedFiles).toEqual(["minimax.txt"]);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("returns null provider when inference fails", () => {
|
|
151
|
+
const drop = freshDropDir();
|
|
152
|
+
const cache = join(drop, "out.txt");
|
|
153
|
+
// Name and domain that don't match any known provider.
|
|
154
|
+
writeFileSync(
|
|
155
|
+
join(drop, "random.txt"),
|
|
156
|
+
"# Netscape HTTP Cookie File\n.example.com\tFALSE\t/\tFALSE\t0\tn1\tv1\n",
|
|
157
|
+
);
|
|
158
|
+
const result = sync({ dropDir: drop, cachePath: cache });
|
|
159
|
+
expect(result.provider).toBe(null);
|
|
160
|
+
expect(result.wrote).toBe(false);
|
|
161
|
+
expect(result.errors.length).toBeGreaterThan(0);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("dryRun=true does not write the cache", () => {
|
|
165
|
+
const drop = freshDropDir();
|
|
166
|
+
const cache = join(drop, "out.txt");
|
|
167
|
+
writeFileSync(join(drop, "minimax.txt"), NETSCAPE_FIXTURE);
|
|
168
|
+
const result = sync({ dropDir: drop, cachePath: cache, dryRun: true });
|
|
169
|
+
expect(result.wrote).toBe(false);
|
|
170
|
+
expect(result.totalCookies).toBe(2);
|
|
171
|
+
expect(existsSync(cache)).toBe(false);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("empty drop folder returns an empty result with no errors", () => {
|
|
175
|
+
const drop = freshDropDir();
|
|
176
|
+
const result = sync({ dropDir: drop, cachePath: join(drop, "out.txt") });
|
|
177
|
+
expect(result.processedFiles).toEqual([]);
|
|
178
|
+
expect(result.totalCookies).toBe(0);
|
|
179
|
+
expect(result.wrote).toBe(false);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("filters out expired cookies", () => {
|
|
183
|
+
const drop = freshDropDir();
|
|
184
|
+
const cache = join(drop, "out.txt");
|
|
185
|
+
const past = 1; // 1970-01-01
|
|
186
|
+
const text = [
|
|
187
|
+
"# Netscape HTTP Cookie File",
|
|
188
|
+
`.minimax.io\tFALSE\t/\tFALSE\t${past}\texpired\texpired-value`,
|
|
189
|
+
".minimax.io\tFALSE\t/\tFALSE\t0\talive\talive-value",
|
|
190
|
+
].join("\n");
|
|
191
|
+
writeFileSync(join(drop, "minimax.txt"), text);
|
|
192
|
+
const result = sync({ dropDir: drop, cachePath: cache });
|
|
193
|
+
expect(result.totalCookies).toBe(1);
|
|
194
|
+
const back = parseNetscape(readFileSync(cache, "utf8"));
|
|
195
|
+
expect(back[0]?.name).toBe("alive");
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe("hasAnyCookieSource", () => {
|
|
200
|
+
it("returns false for empty folder", () => {
|
|
201
|
+
const drop = freshDropDir();
|
|
202
|
+
expect(hasAnyCookieSource(drop)).toBe(false);
|
|
203
|
+
});
|
|
204
|
+
it("returns true when files exist", () => {
|
|
205
|
+
const drop = freshDropDir();
|
|
206
|
+
writeFileSync(join(drop, "minimax.txt"), NETSCAPE_FIXTURE);
|
|
207
|
+
expect(hasAnyCookieSource(drop)).toBe(true);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
describe("inferCachePath", () => {
|
|
212
|
+
it("returns null for empty folder", () => {
|
|
213
|
+
const drop = freshDropDir();
|
|
214
|
+
expect(inferCachePath(drop)).toBe(null);
|
|
215
|
+
});
|
|
216
|
+
it("returns the canonical path for the dominant provider", () => {
|
|
217
|
+
const drop = freshDropDir();
|
|
218
|
+
writeFileSync(join(drop, "minimax.txt"), NETSCAPE_FIXTURE);
|
|
219
|
+
const cachePath = inferCachePath(drop);
|
|
220
|
+
expect(cachePath).toBe(
|
|
221
|
+
join(process.env.HOME ?? "/tmp", ".config", "minimax-cookies.txt"),
|
|
222
|
+
);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
describe("DEFAULT_DROP_DIR", () => {
|
|
227
|
+
it("defaults to ~/.pi-harness-runtime/cookies/", () => {
|
|
228
|
+
const home = process.env.HOME ?? "/tmp";
|
|
229
|
+
expect(DEFAULT_DROP_DIR).toBe(join(home, ".pi-harness-runtime", "cookies"));
|
|
230
|
+
});
|
|
231
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Watcher tests — light-touch. chokidar needs a real fs environment,
|
|
3
|
+
* so we exercise the debouncer + runSync trigger without depending
|
|
4
|
+
* on the chokidar watcher itself (which is exercised in real use).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, it, expect } from "bun:test";
|
|
8
|
+
import { createWatcher } from "../src/watcher.js";
|
|
9
|
+
|
|
10
|
+
describe("CookieWatcher — configuration sanity", () => {
|
|
11
|
+
it("accepts a valid config and constructs without throwing", () => {
|
|
12
|
+
const w = createWatcher(
|
|
13
|
+
"/tmp/does-not-exist-folder",
|
|
14
|
+
{ dropDir: "/tmp/does-not-exist-folder" },
|
|
15
|
+
() => {},
|
|
16
|
+
);
|
|
17
|
+
expect(w).toBeDefined();
|
|
18
|
+
expect(typeof w.start).toBe("function");
|
|
19
|
+
expect(typeof w.stop).toBe("function");
|
|
20
|
+
expect(typeof w.triggerNow).toBe("function");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Note: real chokidar-on-the-filesystem tests are exercised via
|
|
24
|
+
// the live runtime, not in this unit-test file. chokidar requires
|
|
25
|
+
// a real OS-level fs watcher and behaves differently across
|
|
26
|
+
// platforms; we rely on chokidar's own test suite for that.
|
|
27
|
+
});
|