Repository navigation
Expand file tree
/
Copy pathvsixPolicy.test.mjs
More file actions
298 lines (276 loc) · 8.25 KB
/
Copy pathvsixPolicy.test.mjs
File metadata and controls
298 lines (276 loc) · 8.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
import test from 'node:test';
import assert from 'node:assert/strict';
import {
assertSafeVsixEntries,
assertCodexBundleMarkers,
} from './vsixPolicy.mjs';
import { assertPackagedManifest } from './verify-vsix.mjs';
const minimalEntries = [
'[Content_Types].xml',
'extension.vsixmanifest',
'extension/package.json',
'extension/out/extension.js',
'extension/out/webview.js',
'extension/out/codexView.js',
];
const validBundle = [
"provider === 'codex'",
'renderTodayData(provider)',
'renderSessionData(provider)',
'renderSettingsPanel(provider)',
'data-provider-target',
].join('\n');
const sourceMain = './out/extension.js';
test('VSIX policy accepts runtime files and normal publication assets', () => {
assert.doesNotThrow(() => assertSafeVsixEntries([
...minimalEntries,
'extension/README.md',
'extension/CHANGELOG.md',
'extension/LICENSE',
'extension/icon.png',
'extension/package.nls.json',
]));
});
test('VSIX policy rejects development, dependency, and secret material', () => {
for (const entry of [
'extension/src/webview.ts',
'extension/out/test/codexView.test.js',
'extension/tests/ui/codex-visual.spec.mjs',
'extension/docs/private.md',
'extension/.github/workflows/test.yml',
'extension/.codex/private.json',
'extension/AGENTS.md',
'extension/node_modules/left-pad/index.js',
'extension/node_modules/@playwright/test/index.js',
'extension/issue87-benchmark.cjs',
'extension/issue87-prototype-benchmark.cjs',
'extension/out/claudeIncrementalPrototype.js',
'extension/.env.local',
'extension/private.pem',
'extension/private.key',
]) {
assert.throws(
() => assertSafeVsixEntries([...minimalEntries, entry]),
/forbidden VSIX entry/,
entry,
);
}
});
test('VSIX policy rejects internal Superpowers review material', () => {
assert.throws(
() => assertSafeVsixEntries([
...minimalEntries,
'extension/.superpowers/sdd/review-a45ff9e..51ad1d0.diff',
]),
/forbidden VSIX entry/,
);
});
test('VSIX policy rejects dormant v2.3.1 preparation seams and review documents', () => {
for (const entry of [
'extension/out/adviceEffectiveness/evidencePreparation.js',
'extension/out/adviceEffectiveness/feedback.js',
'extension/out/adviceEffectiveness/legacyBridge.js',
'extension/out/adviceEffectiveness/legacyPersonalization.js',
'extension/out/adviceEffectiveness/modelExperiment.js',
'extension/out/adviceDemoSample.js',
'extension/out/adviceSummary.js',
'extension/AI-ADVICE-INTEGRATION-V2.3.1.md',
'extension/V2.3.1-CANDIDATE-CONTRACT.zh-CN.md',
]) {
assert.throws(
() => assertSafeVsixEntries([...minimalEntries, entry]),
/forbidden VSIX entry/,
entry,
);
}
});
test('VSIX policy rejects unsafe or non-canonical archive paths', () => {
for (const entry of [
'/extension/out/extra.js',
'C:\\extension\\out\\extra.js',
'\\\\server\\share\\extra.js',
'extension\\out\\extra.js',
'extension/out/evil\0.js',
'extension/./out/extra.js',
'extension/out/../private.json',
'extension/out/',
'../extension/out/extra.js',
'unexpected-root-file.txt',
'_rels/.rels',
]) {
assert.throws(
() => assertSafeVsixEntries([...minimalEntries, entry]),
/unsafe VSIX entry/,
entry,
);
}
});
test('VSIX policy rejects archive paths with empty segments', () => {
for (const entry of [
'extension//.superpowers/sdd/private.md',
'extension/out//test/private.js',
'extension//node_modules/pkg/index.js',
]) {
assert.throws(
() => assertSafeVsixEntries([...minimalEntries, entry]),
/unsafe VSIX entry/,
entry,
);
}
});
test('VSIX policy rejects malformed entry inventories', () => {
assert.throws(() => assertSafeVsixEntries(null), /VSIX entries must be an array/);
assert.throws(() => assertSafeVsixEntries([...minimalEntries, 42]), /unsafe VSIX entry/);
assert.throws(() => assertSafeVsixEntries([...minimalEntries, '']), /unsafe VSIX entry/);
});
test('VSIX policy rejects duplicate archive entries', () => {
assert.throws(
() => assertSafeVsixEntries([...minimalEntries, 'extension/icon.png', 'extension/icon.png']),
/duplicate VSIX entry: extension\/icon\.png/,
);
});
test('VSIX policy requires the manifest and basic runtime bundles', () => {
for (const required of [
'[Content_Types].xml',
'extension.vsixmanifest',
'extension/package.json',
'extension/out/extension.js',
'extension/out/webview.js',
'extension/out/codexView.js',
]) {
assert.throws(
() => assertSafeVsixEntries(minimalEntries.filter((entry) => entry !== required)),
new RegExp(`missing required VSIX entry: ${required.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`),
required,
);
}
});
test('bundle policy requires current Codex product and host-state markers', () => {
assert.doesNotThrow(() => assertCodexBundleMarkers(validBundle));
for (const marker of [
"provider === 'codex'",
'renderTodayData(provider)',
'renderSessionData(provider)',
'renderSettingsPanel(provider)',
'data-provider-target',
]) {
assert.throws(
() => assertCodexBundleMarkers(validBundle.replace(marker, '')),
/missing bundle marker/,
marker,
);
}
});
test('bundle policy rejects retired flat tabs and legacy Codex storage', () => {
for (const marker of [
'ccu.codex.ui.v1',
'data-codex-tab-button="recent"',
'data-codex-tab-button="7d"',
'data-codex-tab-button="30d"',
'data-codex-tab-button="all"',
'data-codex-tab-button="threads"',
'data-codex-tab-button="projects"',
'data-codex-tab-button="behavior"',
'data-codex-tab-button="settings"',
'data-codex-page="overview"',
'data-codex-page="explore"',
'data-codex-page="recommendations"',
'data-codex-action',
'hostState.codexUi = nextState',
]) {
assert.throws(
() => assertCodexBundleMarkers(`${validBundle}\n${marker}`),
/retired bundle marker/,
marker,
);
}
});
test('bundle policy rejects non-text input', () => {
assert.throws(() => assertCodexBundleMarkers(null), /bundle must be text/);
});
test('packaged manifest policy returns its verified runtime main entry', () => {
assert.equal(
assertPackagedManifest(
{ version: '2.1.1', main: './out/extension.js' },
'2.1.1',
sourceMain,
minimalEntries,
),
'extension/out/extension.js',
);
});
test('packaged manifest policy rejects a runtime main that differs from the source manifest', () => {
assert.throws(
() => assertPackagedManifest(
{ version: '2.1.1', main: './out/evil.js' },
'2.1.1',
sourceMain,
[...minimalEntries, 'extension/out/evil.js'],
),
/VSIX main mismatch/,
);
});
test('packaged manifest policy rejects version mismatches', () => {
assert.throws(
() => assertPackagedManifest(
{ version: '9.9.9', main: './out/extension.js' },
'2.1.1',
sourceMain,
minimalEntries,
),
/VSIX version mismatch: expected 2\.1\.1, got 9\.9\.9/,
);
});
test('packaged manifest policy rejects unsafe or missing runtime mains', () => {
for (const main of [
'',
'/out/extension.js',
'C:\\out\\extension.js',
'.\\out\\extension.js',
'./out/../private.js',
'./out//extension.js',
'./README.md',
]) {
assert.throws(
() => assertPackagedManifest(
{ version: '2.1.1', main },
'2.1.1',
sourceMain,
minimalEntries,
),
/invalid VSIX main|missing VSIX main entry/,
main,
);
}
assert.throws(
() => assertPackagedManifest(
{ version: '2.1.1', main: './out/missing.js' },
'2.1.1',
'./out/missing.js',
minimalEntries,
),
/missing VSIX main entry: extension\/out\/missing\.js/,
);
});
test('packaged manifest policy rejects an invalid source runtime main', () => {
for (const expectedMain of [
undefined,
42,
'',
'/out/extension.js',
'./out/../extension.js',
'./out//extension.js',
'./README.md',
]) {
assert.throws(
() => assertPackagedManifest(
{ version: '2.1.1', main: './out/extension.js' },
'2.1.1',
expectedMain,
minimalEntries,
),
/invalid source main/,
String(expectedMain),
);
}
});