@panomc/sdk 1.0.0-dev.8 → 2.0.0-dev.1

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.
Files changed (166) hide show
  1. package/api/routes.core.json +3702 -0
  2. package/bin/api/__tests__/api-compat.test.mjs +97 -0
  3. package/bin/api/__tests__/check-paths.test.mjs +113 -0
  4. package/bin/api/__tests__/cli.test.mjs +44 -0
  5. package/bin/api/__tests__/extract-routes.test.mjs +132 -0
  6. package/bin/api/__tests__/fixtures/core-new/Pano/api/paths.old-new.json +82 -0
  7. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/error/NotExists.kt +10 -0
  8. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/model/Bases.kt +21 -0
  9. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/api/GetSiteInfoAPI.kt +19 -0
  10. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/api/auth/HostSsoAPI.kt +10 -0
  11. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/api/panel/PanelAddonsAPI.kt +28 -0
  12. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/api/plugins/GetPluginUiZipAPI.kt +9 -0
  13. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/template/IndexTemplate.kt +9 -0
  14. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/error/NotExists.kt +10 -0
  15. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/model/Bases.kt +21 -0
  16. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/api/GetSiteInfoAPI.kt +19 -0
  17. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/api/auth/HostSsoAPI.kt +10 -0
  18. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/api/panel/PanelAddonsAPI.kt +28 -0
  19. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/api/plugins/GetPluginUiZipAPI.kt +9 -0
  20. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/template/IndexTemplate.kt +9 -0
  21. package/bin/api/__tests__/fixtures/plugin-new/api/paths.old-new.json +66 -0
  22. package/bin/api/__tests__/fixtures/plugin-new/build.gradle.kts +42 -0
  23. package/bin/api/__tests__/fixtures/plugin-new/gradle.properties +4 -0
  24. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/base/DemoApis.kt +13 -0
  25. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/error/Errors.kt +16 -0
  26. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/error/Plain.kt +4 -0
  27. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/routes/GetThingsAPI.kt +16 -0
  28. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/routes/PanelThingAPI.kt +11 -0
  29. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/routes/ValidatedAPI.kt +18 -0
  30. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/routes/WebhookAPI.kt +23 -0
  31. package/bin/api/__tests__/fixtures/plugin-new/src/panel/Things.js +4 -0
  32. package/bin/api/__tests__/fixtures/plugin-new/src/theme/Logo.svelte +9 -0
  33. package/bin/api/__tests__/fixtures/plugin-new/src/theme/api.js +29 -0
  34. package/bin/api/__tests__/fixtures/plugin-old/build.gradle.kts +22 -0
  35. package/bin/api/__tests__/fixtures/plugin-old/gradle.properties +4 -0
  36. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/base/DemoApis.kt +13 -0
  37. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/error/Errors.kt +16 -0
  38. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/error/Plain.kt +4 -0
  39. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/routes/GetThingsAPI.kt +16 -0
  40. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/routes/PanelThingAPI.kt +11 -0
  41. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/routes/ValidatedAPI.kt +18 -0
  42. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/routes/WebhookAPI.kt +23 -0
  43. package/bin/api/__tests__/fixtures/plugin-old/src/panel/Things.js +4 -0
  44. package/bin/api/__tests__/fixtures/plugin-old/src/theme/Logo.svelte +9 -0
  45. package/bin/api/__tests__/fixtures/plugin-old/src/theme/api.js +29 -0
  46. package/bin/api/__tests__/fixtures/refusals/gradle.properties +1 -0
  47. package/bin/api/__tests__/fixtures/refusals/src/main/kotlin/x/Bad.kt +39 -0
  48. package/bin/api/__tests__/fixtures/unresolved/src/main/kotlin/x/Orphan.kt +19 -0
  49. package/bin/api/__tests__/helpers.mjs +48 -0
  50. package/bin/api/__tests__/migrate-v1.test.mjs +377 -0
  51. package/bin/api/__tests__/openapi-snapshot.test.mjs +120 -0
  52. package/bin/api/api-compat.mjs +204 -0
  53. package/bin/api/check-paths.mjs +135 -0
  54. package/bin/api/cli.mjs +83 -0
  55. package/bin/api/extract-routes.mjs +129 -0
  56. package/bin/api/js-scan.mjs +337 -0
  57. package/bin/api/kotlin.mjs +366 -0
  58. package/bin/api/migrate-v1.mjs +330 -0
  59. package/bin/api/openapi-snapshot.mjs +112 -0
  60. package/bin/api/project.mjs +172 -0
  61. package/bin/api/rename-table.mjs +66 -0
  62. package/bin/api/util.mjs +194 -0
  63. package/bin/pano-api.js +5 -0
  64. package/build/plugin-api-rollup.js +46 -0
  65. package/core/css/pano-tokens.css +225 -0
  66. package/core/favicon/apple-touch-icon.png +0 -0
  67. package/core/favicon/favicon-96x96.png +0 -0
  68. package/core/favicon/favicon.ico +0 -0
  69. package/core/favicon/favicon.svg +1 -0
  70. package/core/favicon/site.webmanifest +21 -0
  71. package/core/favicon/web-app-manifest-192x192.png +0 -0
  72. package/core/favicon/web-app-manifest-512x512.png +0 -0
  73. package/core/favicon_old/android-icon-144x144.png +0 -0
  74. package/core/favicon_old/android-icon-192x192.png +0 -0
  75. package/core/favicon_old/android-icon-36x36.png +0 -0
  76. package/core/favicon_old/android-icon-48x48.png +0 -0
  77. package/core/favicon_old/android-icon-72x72.png +0 -0
  78. package/core/favicon_old/android-icon-96x96.png +0 -0
  79. package/core/favicon_old/apple-icon-114x114.png +0 -0
  80. package/core/favicon_old/apple-icon-120x120.png +0 -0
  81. package/core/favicon_old/apple-icon-144x144.png +0 -0
  82. package/core/favicon_old/apple-icon-152x152.png +0 -0
  83. package/core/favicon_old/apple-icon-180x180.png +0 -0
  84. package/core/favicon_old/apple-icon-57x57.png +0 -0
  85. package/core/favicon_old/apple-icon-60x60.png +0 -0
  86. package/core/favicon_old/apple-icon-72x72.png +0 -0
  87. package/core/favicon_old/apple-icon-76x76.png +0 -0
  88. package/core/favicon_old/apple-icon-precomposed.png +0 -0
  89. package/core/favicon_old/apple-icon.png +0 -0
  90. package/core/favicon_old/browserconfig.xml +11 -0
  91. package/core/favicon_old/favicon-16x16.png +0 -0
  92. package/core/favicon_old/favicon-32x32.png +0 -0
  93. package/core/favicon_old/favicon-96x96.png +0 -0
  94. package/core/favicon_old/favicon.ico +0 -0
  95. package/core/favicon_old/manifest.json +41 -0
  96. package/core/favicon_old/ms-icon-144x144.png +0 -0
  97. package/core/favicon_old/ms-icon-150x150.png +0 -0
  98. package/core/favicon_old/ms-icon-310x310.png +0 -0
  99. package/core/favicon_old/ms-icon-70x70.png +0 -0
  100. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.eot +0 -0
  101. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.svg +483 -0
  102. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.ttf +0 -0
  103. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.woff +0 -0
  104. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.woff2 +0 -0
  105. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.eot +0 -0
  106. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.svg +486 -0
  107. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.ttf +0 -0
  108. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.woff +0 -0
  109. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.woff2 +0 -0
  110. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.eot +0 -0
  111. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.svg +484 -0
  112. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.ttf +0 -0
  113. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.woff +0 -0
  114. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.woff2 +0 -0
  115. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.eot +0 -0
  116. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.svg +486 -0
  117. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.ttf +0 -0
  118. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.woff +0 -0
  119. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.woff2 +0 -0
  120. package/core/js/ControllerRegistry.js +421 -0
  121. package/core/js/NotificationManager.js +62 -0
  122. package/core/js/PluginAPI.js +39 -0
  123. package/core/js/PluginManager.js +851 -0
  124. package/core/js/RouteMatcher.js +142 -0
  125. package/core/js/__tests__/ControllerRegistry.test.js +378 -0
  126. package/core/js/__tests__/NotificationManager.test.js +57 -0
  127. package/core/js/__tests__/PluginAPI.test.js +25 -0
  128. package/core/js/__tests__/RouteMatcher.test.js +33 -0
  129. package/core/js/__tests__/accessClient.test.js +582 -0
  130. package/core/js/__tests__/api.util.v1.test.js +336 -0
  131. package/core/js/__tests__/appStores.test.js +47 -0
  132. package/core/js/__tests__/devBounce.test.js +28 -0
  133. package/core/js/__tests__/html.util.test.js +18 -0
  134. package/core/js/__tests__/pluginFolder.util.test.js +106 -0
  135. package/core/js/__tests__/pluginPackage.test.js +134 -0
  136. package/core/js/__tests__/pluginUiZip.test.js +47 -0
  137. package/core/js/__tests__/sdkLevel.test.js +34 -0
  138. package/core/js/api.util.js +433 -0
  139. package/core/js/appStores.js +93 -0
  140. package/core/js/basePath.js +10 -0
  141. package/core/js/html.util.js +26 -0
  142. package/core/js/pluginFolder.util.js +95 -0
  143. package/core/js/tooltip.util.js +59 -0
  144. package/core/js/variables.js +95 -0
  145. package/core/js/version.util.js +100 -0
  146. package/core/scss/_pano-tokens.scss +51 -0
  147. package/core/scss/custom-bootstrap.scss +210 -0
  148. package/core/scss/fonts.scss +85 -0
  149. package/core/scss/main.scss +389 -0
  150. package/core/scss/themes.scss +122 -0
  151. package/package.json +63 -11
  152. package/src/__tests__/controllers.test.js +220 -0
  153. package/src/__tests__/views.spike.test.js +472 -0
  154. package/src/components/{index.js → panel.js} +9 -6
  155. package/src/components/theme.js +18 -0
  156. package/src/controllers.js +127 -0
  157. package/src/index.js +1 -1
  158. package/src/runtime-specifiers.js +88 -0
  159. package/src/svelte.js +3 -2
  160. package/src/types.js +5 -3
  161. package/src/utils/api.js +42 -1
  162. package/src/utils/auth.js +8 -0
  163. package/src/utils/component.js +4 -2
  164. package/src/utils/route.js +16 -0
  165. package/src/utils/text.js +8 -0
  166. package/src/views.js +29 -0
@@ -0,0 +1,336 @@
1
+ import { afterEach, beforeEach, describe, expect, mock, test } from 'bun:test';
2
+ import { readable, writable } from 'svelte/store';
3
+
4
+ // TC-34: transport on /api/v1 and the plugin-scoped client (doc 04 section 9).
5
+
6
+ const state = { apiUrl: 'http://127.0.0.1:8088/api', browser: false };
7
+
8
+ function mockHost() {
9
+ mock.module('$lib/variables.js', () => ({
10
+ get API_URL() {
11
+ return state.apiUrl;
12
+ },
13
+ CSRF_HEADER: 'X-CSRF-Token',
14
+ }));
15
+ mock.module('$app/env', () => ({
16
+ get browser() {
17
+ return state.browser;
18
+ },
19
+ }));
20
+ mock.module('../appStores.js', () => ({ page: readable({ data: {} }) }));
21
+ mock.module('$lib/Store.js', () => ({ initialized: writable(true) }));
22
+ mock.module('$lib/components/ToastContainer.svelte', () => ({ show: async () => {} }));
23
+ }
24
+
25
+ mockHost();
26
+
27
+ // Bun snapshots a mock factory's values, so a change is applied by registering the mock again
28
+ // (the imports of api.util.js are live bindings and see the new values).
29
+ function setHost(next) {
30
+ Object.assign(state, next);
31
+ mockHost();
32
+ }
33
+
34
+ const mod = await import('../api.util.js');
35
+ const { default: ApiUtil, resolveApiUrl, createPluginApi, networkErrorBody } = mod;
36
+
37
+ const realFetch = globalThis.fetch;
38
+ const realLog = console.log;
39
+
40
+ /** @param {(url: string, init: any) => Response | Promise<Response>} impl */
41
+ function recordingFetch(impl) {
42
+ const calls = [];
43
+ const fn = async (url, init) => {
44
+ calls.push({ url, init });
45
+ return impl(url, init);
46
+ };
47
+ fn.calls = calls;
48
+ return fn;
49
+ }
50
+
51
+ const json = (body, status = 200) =>
52
+ new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json' } });
53
+
54
+ beforeEach(() => {
55
+ setHost({ apiUrl: 'http://127.0.0.1:8088/api', browser: false });
56
+ console.log = () => {};
57
+ });
58
+
59
+ afterEach(() => {
60
+ globalThis.fetch = realFetch;
61
+ console.log = realLog;
62
+ });
63
+
64
+ describe('resolveApiUrl: the four cases', () => {
65
+ test('website (.panomc.com): API_URL + path, no /v1', () => {
66
+ expect(resolveApiUrl('/resources', { apiUrl: 'https://api.panomc.com' })).toBe('https://api.panomc.com/resources');
67
+ expect(
68
+ resolveApiUrl('/resources', { apiUrl: 'https://api.panomc.com', hasEventFetch: true, browser: true, prod: true }),
69
+ ).toBe('https://api.panomc.com/resources');
70
+ // the /api refusal does not apply to the website API
71
+ expect(resolveApiUrl('/api/x', { apiUrl: 'https://api-dev.panomc.com' })).toBe('https://api-dev.panomc.com/api/x');
72
+ });
73
+
74
+ test('SSR with request.fetch: relative /api/v1', () => {
75
+ expect(resolveApiUrl('/posts', { apiUrl: 'http://127.0.0.1:8088/api', hasEventFetch: true })).toBe('/api/v1/posts');
76
+ expect(resolveApiUrl('/posts', { apiUrl: 'http://10.0.0.5:8088/api', hasEventFetch: true, prod: true })).toBe(
77
+ '/api/v1/posts',
78
+ );
79
+ });
80
+
81
+ test('browser, production: relative /api/v1', () => {
82
+ expect(resolveApiUrl('/posts', { apiUrl: 'http://10.0.0.5:8088/api', browser: true, prod: true })).toBe('/api/v1/posts');
83
+ });
84
+
85
+ test('browser, loopback API_URL in dev: relative /api/v1', () => {
86
+ for (const apiUrl of ['http://localhost:8088/api', 'http://127.0.0.1:8088/api', 'http://0.0.0.0:8088/api']) {
87
+ expect(resolveApiUrl('/posts', { apiUrl, browser: true })).toBe('/api/v1/posts');
88
+ }
89
+ });
90
+
91
+ test('SSR without an event: absolute API_URL + /v1', () => {
92
+ expect(resolveApiUrl('/posts', { apiUrl: 'http://127.0.0.1:8088/api' })).toBe('http://127.0.0.1:8088/api/v1/posts');
93
+ expect(resolveApiUrl('/posts', { apiUrl: 'http://backend:8088/api/' })).toBe('http://backend:8088/api/v1/posts');
94
+ });
95
+
96
+ test('browser, dev, non-loopback API_URL: absolute API_URL + /v1', () => {
97
+ expect(resolveApiUrl('/posts', { apiUrl: 'http://backend:8088/api', browser: true })).toBe(
98
+ 'http://backend:8088/api/v1/posts',
99
+ );
100
+ });
101
+
102
+ test('a path without a leading slash gets one', () => {
103
+ expect(resolveApiUrl('posts?page=2', { apiUrl: 'http://127.0.0.1:8088/api', hasEventFetch: true })).toBe(
104
+ '/api/v1/posts?page=2',
105
+ );
106
+ });
107
+ });
108
+
109
+ describe('/api refusal', () => {
110
+ test('throws in dev with the fix in the message', () => {
111
+ expect(() => resolveApiUrl('/api/posts', { apiUrl: 'http://127.0.0.1:8088/api' })).toThrow(
112
+ "[pano] path must not start with /api: write '/posts'",
113
+ );
114
+ expect(() => resolveApiUrl('/api/v1/posts', { apiUrl: 'http://127.0.0.1:8088/api', hasEventFetch: true })).toThrow(
115
+ "write '/v1/posts'",
116
+ );
117
+ });
118
+
119
+ test('does not throw in production, and "/apiary" is not an /api path', () => {
120
+ expect(() => resolveApiUrl('/api/posts', { apiUrl: 'http://127.0.0.1:8088/api', prod: true })).not.toThrow();
121
+ expect(resolveApiUrl('/apiary', { apiUrl: 'http://127.0.0.1:8088/api', hasEventFetch: true })).toBe('/api/v1/apiary');
122
+ });
123
+
124
+ test('ApiUtil.get rejects before any request is made', async () => {
125
+ const fetchMock = recordingFetch(() => json({}));
126
+ globalThis.fetch = fetchMock;
127
+ await expect(ApiUtil.get({ path: '/api/posts' })).rejects.toThrow('must not start with /api');
128
+ expect(fetchMock.calls.length).toBe(0);
129
+ });
130
+ });
131
+
132
+ describe('ApiUtil requests', () => {
133
+ test('SSR with request.fetch calls the relative URL through request.fetch', async () => {
134
+ const eventFetch = recordingFetch(() => json({ items: [], page: { number: 1 } }));
135
+ const direct = recordingFetch(() => json({}));
136
+ globalThis.fetch = direct;
137
+
138
+ const body = await ApiUtil.get({ path: '/posts', csrfToken: 'x', request: { fetch: eventFetch } });
139
+
140
+ expect(body).toEqual({ items: [], page: { number: 1 } });
141
+ expect(eventFetch.calls.map((c) => c.url)).toEqual(['/api/v1/posts']);
142
+ expect(direct.calls.length).toBe(0);
143
+ });
144
+
145
+ test('SSR without an event calls the absolute URL', async () => {
146
+ const fetchMock = recordingFetch(() => json({ ok: 1 }));
147
+ globalThis.fetch = fetchMock;
148
+
149
+ await ApiUtil.get({ path: '/posts', csrfToken: 'x' });
150
+
151
+ expect(fetchMock.calls[0].url).toBe('http://127.0.0.1:8088/api/v1/posts');
152
+ });
153
+
154
+ test('browser (loopback API_URL) calls the relative URL', async () => {
155
+ setHost({ browser: true });
156
+ const fetchMock = recordingFetch(() => json({ ok: 1 }));
157
+ globalThis.fetch = fetchMock;
158
+
159
+ await ApiUtil.get({ path: '/posts', csrfToken: 'x' });
160
+
161
+ expect(fetchMock.calls[0].url).toBe('/api/v1/posts');
162
+ });
163
+
164
+ test('website API_URL keeps its form', async () => {
165
+ setHost({ apiUrl: 'https://api.panomc.com' });
166
+ const fetchMock = recordingFetch(() => json({ ok: 1 }));
167
+ globalThis.fetch = fetchMock;
168
+
169
+ await ApiUtil.get({ path: '/resources', csrfToken: 'x' });
170
+ await ApiUtil.get({ path: '/resources', csrfToken: 'x', request: { fetch: fetchMock } });
171
+
172
+ expect(fetchMock.calls.map((c) => c.url)).toEqual([
173
+ 'https://api.panomc.com/resources',
174
+ 'https://api.panomc.com/resources',
175
+ ]);
176
+ });
177
+
178
+ test('a non-2xx answer returns the envelope unchanged', async () => {
179
+ const envelope = { error: { code: 'NOT_EXISTS', message: 'gone', details: { id: 3 }, fields: { id: 'NOT_FOUND' } } };
180
+ globalThis.fetch = recordingFetch(() => json(envelope, 404));
181
+
182
+ expect(await ApiUtil.get({ path: '/posts/3', csrfToken: 'x' })).toEqual(envelope);
183
+ });
184
+
185
+ test('POST sends the CSRF header and a JSON body', async () => {
186
+ const fetchMock = recordingFetch(() => json({}));
187
+ globalThis.fetch = fetchMock;
188
+
189
+ await ApiUtil.post({ path: '/auth/login', body: { a: 1 }, csrfToken: 'tok' });
190
+
191
+ const { url, init } = fetchMock.calls[0];
192
+ expect(url).toBe('http://127.0.0.1:8088/api/v1/auth/login');
193
+ expect(init.method).toBe('POST');
194
+ expect(init.body).toBe('{"a":1}');
195
+ expect(init.headers['X-CSRF-Token']).toBe('tok');
196
+ expect(init.headers['Content-Type']).toBe('application/json');
197
+ });
198
+
199
+ test('a network failure returns { error: { code: NETWORK_ERROR } }', async () => {
200
+ globalThis.fetch = recordingFetch(() => {
201
+ throw new TypeError('fetch failed');
202
+ });
203
+
204
+ const result = await ApiUtil.post({ path: '/posts', csrfToken: 'x', body: {} });
205
+
206
+ expect(result).toEqual({ error: { code: 'NETWORK_ERROR' } });
207
+ expect(networkErrorBody).toEqual({ error: { code: 'NETWORK_ERROR' } });
208
+ });
209
+
210
+ test('DISABLED_FOR_DEMO is read from error.code and resolves nothing', async () => {
211
+ globalThis.fetch = recordingFetch(() => json({ error: { code: 'DISABLED_FOR_DEMO' } }, 403));
212
+ const handled = [];
213
+
214
+ const result = await ApiUtil.post({
215
+ path: '/panel/settings',
216
+ csrfToken: 'x',
217
+ body: {},
218
+ handler: (body) => handled.push(body),
219
+ });
220
+
221
+ expect(result).toBeUndefined();
222
+ expect(handled).toEqual([]);
223
+ });
224
+
225
+ test('the old string form is no longer the demo marker', async () => {
226
+ globalThis.fetch = recordingFetch(() => json({ error: 'DISABLED_FOR_DEMO' }, 403));
227
+
228
+ expect(await ApiUtil.post({ path: '/x', csrfToken: 'x', body: {} })).toEqual({ error: 'DISABLED_FOR_DEMO' });
229
+ });
230
+ });
231
+
232
+ describe('resolveApiUrl unversioned (plugin endpoints)', () => {
233
+ test('the four cases leave the version segment out', () => {
234
+ expect(resolveApiUrl('/plugins/p/x', { unversioned: true, hasEventFetch: true })).toBe('/api/plugins/p/x');
235
+ expect(resolveApiUrl('/plugins/p/x', { unversioned: true, browser: true, prod: true })).toBe('/api/plugins/p/x');
236
+ expect(resolveApiUrl('/plugins/p/x', { unversioned: true, apiUrl: 'http://127.0.0.1:8088/api' })).toBe(
237
+ 'http://127.0.0.1:8088/api/plugins/p/x',
238
+ );
239
+ expect(resolveApiUrl('/plugins/p/x', { unversioned: true })).toBe('/api/plugins/p/x');
240
+ expect(resolveApiUrl('/plugins/p/x', { hasEventFetch: true })).toBe('/api/v1/plugins/p/x');
241
+ });
242
+ });
243
+
244
+ describe('ApiUtil routes a plugin\'s own path outside /api/v1', () => {
245
+ test('/plugins/<id>/x and /api/plugins/<id>/x go to /api/plugins; core /plugins/<id>/_/x stays under /api/v1', async () => {
246
+ const fetchMock = recordingFetch(() => json({}));
247
+ globalThis.fetch = fetchMock;
248
+
249
+ await ApiUtil.get({ path: '/plugins/pano-plugin-market/store/products', csrfToken: 'x' });
250
+ await ApiUtil.get({ path: '/api/plugins/pano-plugin-market/store/products', csrfToken: 'x' });
251
+ await ApiUtil.get({ path: '/plugins/pano-plugin-market/panel/products', csrfToken: 'x' });
252
+ await ApiUtil.get({ path: '/plugins/pano-plugin-market/_/ui.zip', csrfToken: 'x' });
253
+
254
+ expect(fetchMock.calls.map((c) => c.url)).toEqual([
255
+ 'http://127.0.0.1:8088/api/plugins/pano-plugin-market/store/products',
256
+ 'http://127.0.0.1:8088/api/plugins/pano-plugin-market/store/products',
257
+ 'http://127.0.0.1:8088/api/plugins/pano-plugin-market/panel/products',
258
+ 'http://127.0.0.1:8088/api/v1/plugins/pano-plugin-market/_/ui.zip',
259
+ ]);
260
+ });
261
+
262
+ test('on the server (event fetch) the relative URL is /api/plugins, which the theme hook sends to the backend', async () => {
263
+ const eventFetch = recordingFetch(() => json({ items: [] }));
264
+ await ApiUtil.get({ path: '/plugins/pano-plugin-market/store/products', csrfToken: 'x', request: { fetch: eventFetch } });
265
+ expect(eventFetch.calls[0].url).toBe('/api/plugins/pano-plugin-market/store/products');
266
+ });
267
+ });
268
+
269
+ describe('createPluginApi', () => {
270
+ test('prefixes /api/plugins/<id> and /api/plugins/<id>/panel (unversioned)', async () => {
271
+ const fetchMock = recordingFetch(() => json({ items: [] }));
272
+ globalThis.fetch = fetchMock;
273
+ const api = createPluginApi('pano-plugin-market');
274
+
275
+ await api.get({ path: '/store/products', csrfToken: 'x' });
276
+ await api.post({ path: '/cart/items', body: { id: 1 }, csrfToken: 'x' });
277
+ await api.put({ path: '/cart/items/1', body: {}, csrfToken: 'x' });
278
+ await api.delete({ path: '/cart/items/1', csrfToken: 'x' });
279
+ await api.customRequest({ path: '/ping', data: { method: 'PATCH' }, csrfToken: 'x' });
280
+ await api.panel.get({ path: '/products', csrfToken: 'x' });
281
+ await api.panel.post({ path: '/products', body: {}, csrfToken: 'x' });
282
+ await api.panel.put({ path: '/products/1', body: {}, csrfToken: 'x' });
283
+ await api.panel.delete({ path: '/products/1', csrfToken: 'x' });
284
+ await api.panel.customRequest({ path: '/ping', data: { method: 'PATCH' }, csrfToken: 'x' });
285
+
286
+ const base = 'http://127.0.0.1:8088/api';
287
+ expect(fetchMock.calls.map((c) => [c.init?.method ?? 'GET', c.url])).toEqual([
288
+ ['GET', `${base}/plugins/pano-plugin-market/store/products`],
289
+ ['POST', `${base}/plugins/pano-plugin-market/cart/items`],
290
+ ['PUT', `${base}/plugins/pano-plugin-market/cart/items/1`],
291
+ ['DELETE', `${base}/plugins/pano-plugin-market/cart/items/1`],
292
+ ['PATCH', `${base}/plugins/pano-plugin-market/ping`],
293
+ ['GET', `${base}/plugins/pano-plugin-market/panel/products`],
294
+ ['POST', `${base}/plugins/pano-plugin-market/panel/products`],
295
+ ['PUT', `${base}/plugins/pano-plugin-market/panel/products/1`],
296
+ ['DELETE', `${base}/plugins/pano-plugin-market/panel/products/1`],
297
+ ['PATCH', `${base}/plugins/pano-plugin-market/panel/ping`],
298
+ ]);
299
+ });
300
+
301
+ test('passes the other options through (request.fetch, token, handler)', async () => {
302
+ const eventFetch = recordingFetch(() => json({ n: 1 }));
303
+ const api = createPluginApi('pano-plugin-faq');
304
+
305
+ const result = await api.get({
306
+ path: '/faq',
307
+ csrfToken: 'x',
308
+ token: 'jwt',
309
+ request: { fetch: eventFetch },
310
+ handler: (body) => body.n + 1,
311
+ });
312
+
313
+ expect(result).toBe(2);
314
+ expect(eventFetch.calls[0].url).toBe('/api/plugins/pano-plugin-faq/faq');
315
+ expect(eventFetch.calls[0].init.headers.Authorization).toBe('Bearer jwt');
316
+ });
317
+
318
+ test('a path without a leading slash is accepted; a path starting with /api throws in dev', async () => {
319
+ const fetchMock = recordingFetch(() => json({}));
320
+ globalThis.fetch = fetchMock;
321
+ const api = createPluginApi('pano-plugin-faq');
322
+
323
+ await api.get({ path: 'faq', csrfToken: 'x' });
324
+ expect(fetchMock.calls[0].url).toBe('http://127.0.0.1:8088/api/plugins/pano-plugin-faq/faq');
325
+
326
+ await expect(api.get({ path: '/api/faq' })).rejects.toThrow('must not start with /api');
327
+ await expect(api.panel.get({ path: '/api/faq' })).rejects.toThrow('must not start with /api');
328
+ expect(fetchMock.calls.length).toBe(1);
329
+ });
330
+
331
+ test('needs the full plugin id', () => {
332
+ expect(() => createPluginApi('')).toThrow('full plugin id');
333
+ expect(() => createPluginApi(undefined)).toThrow('full plugin id');
334
+ expect(() => createPluginApi('a/b')).toThrow('full plugin id');
335
+ });
336
+ });
@@ -0,0 +1,47 @@
1
+ import { describe, expect, mock, test } from 'bun:test';
2
+ import { get } from 'svelte/store';
3
+
4
+ // The server side of the `$app/stores` shapes over `$app/state`. A flag stands for "the host's component context is
5
+ // current": SvelteKit's server `page` throws when it is not.
6
+ const state = { rendering: true, url: new URL('https://pano.example/store') };
7
+
8
+ mock.module('$app/env', () => ({ browser: false, dev: false }));
9
+ mock.module('$app/state', () => {
10
+ const read = (name) => {
11
+ if (!state.rendering) throw new Error(`Can only read \`page.${name}\` on the server during rendering`);
12
+ return name === 'url' ? state.url : name === 'data' ? { from: state.url.pathname } : null;
13
+ };
14
+ return {
15
+ page: new Proxy({}, { get: (_, name) => read(String(name)) }),
16
+ navigating: { from: null, to: null, type: null, willUnload: null, delta: null, complete: null },
17
+ };
18
+ });
19
+
20
+ const stores = await import('../appStores.js');
21
+
22
+ describe('appStores on the server', () => {
23
+ test('a read outside the host render throws while no request was captured', () => {
24
+ state.rendering = false;
25
+ expect(() => get(stores.page)).toThrow('during rendering');
26
+ });
27
+
28
+ test('during the host render the page is read from $app/state', () => {
29
+ state.rendering = true;
30
+ expect(get(stores.page).url.pathname).toBe('/store');
31
+ expect(get(stores.page).data).toEqual({ from: '/store' });
32
+ });
33
+
34
+ test('a read outside it gets the page captured by the host app layout', () => {
35
+ state.rendering = true;
36
+ state.url = new URL('https://pano.example/support');
37
+ stores.captureRequestState();
38
+
39
+ state.rendering = false;
40
+ expect(get(stores.page).url.pathname).toBe('/support');
41
+ });
42
+
43
+ test('navigating is null while the server renders', () => {
44
+ state.rendering = false;
45
+ expect(get(stores.navigating)).toBeNull();
46
+ });
47
+ });
@@ -0,0 +1,28 @@
1
+ import { describe, expect, test } from "bun:test";
2
+
3
+ import { devBounceTarget } from "../variables.js";
4
+
5
+ const apiUrl = "http://127.0.0.1:18500/api";
6
+
7
+ describe("devBounceTarget", () => {
8
+ test("a page on the vite port bounces to the Pano dev server", () => {
9
+ expect(devBounceTarget({ apiUrl, currentHref: "http://127.0.0.1:18502/support?a=1#x" })).toBe("http://127.0.0.1:18500/support?a=1#x");
10
+ });
11
+
12
+ test("the base path is added when the page lacks it", () => {
13
+ expect(devBounceTarget({ apiUrl, currentHref: "http://localhost:3001/users", basePath: "/panel" })).toBe("http://127.0.0.1:18500/panel/users");
14
+ });
15
+
16
+ test("a page already on the API port stays", () => {
17
+ expect(devBounceTarget({ apiUrl, currentHref: "http://127.0.0.1:18500/" })).toBeNull();
18
+ });
19
+
20
+ test("another host stays (LAN, tunnel)", () => {
21
+ expect(devBounceTarget({ apiUrl, currentHref: "https://dev.example.com/" })).toBeNull();
22
+ });
23
+
24
+ test("the view catalogue stays on the vite port: Pano serves the built theme, where it is a 404", () => {
25
+ expect(devBounceTarget({ apiUrl, currentHref: "http://127.0.0.1:18502/__pano/views/market/ProductCard?bare=1" })).toBeNull();
26
+ expect(devBounceTarget({ apiUrl, currentHref: "http://127.0.0.1:18502/__pano/views" })).toBeNull();
27
+ });
28
+ });
@@ -0,0 +1,18 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import { escapeHtml, escapeValues } from '../html.util.js';
3
+
4
+ describe('html.util (TC-5)', () => {
5
+ test('escapes all five characters', () => {
6
+ expect(escapeHtml(`& < > " '`)).toBe('&amp; &lt; &gt; &quot; &#39;');
7
+ });
8
+ test('escapeValues escapes strings only, copy', () => {
9
+ const src = { a: '<b>', n: 5, z: null, t: true };
10
+ const out = escapeValues(src);
11
+ expect(out).toEqual({ a: '&lt;b&gt;', n: 5, z: null, t: true });
12
+ expect(src.a).toBe('<b>');
13
+ expect(out).not.toBe(src);
14
+ });
15
+ test('non-object gives {}', () => {
16
+ for (const v of [null, undefined, 'x', 3, [1]]) expect(escapeValues(v)).toEqual({});
17
+ });
18
+ });
@@ -0,0 +1,106 @@
1
+ import { afterEach, describe, expect, test } from "bun:test";
2
+ import fs from "fs";
3
+ import os from "os";
4
+ import path from "path";
5
+ import { removePluginUiFiles, replacePluginUiFiles } from "../pluginFolder.util.js";
6
+
7
+ const roots = [];
8
+ function tmp() {
9
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "plugin-folder-"));
10
+ roots.push(dir);
11
+ return dir;
12
+ }
13
+ afterEach(() => {
14
+ for (const r of roots.splice(0)) fs.rmSync(r, { recursive: true, force: true });
15
+ });
16
+
17
+ function seed(folder, tag) {
18
+ fs.mkdirSync(path.join(folder, "client"), { recursive: true });
19
+ fs.mkdirSync(path.join(folder, "server"), { recursive: true });
20
+ fs.writeFileSync(path.join(folder, "client", "a.js"), tag);
21
+ fs.writeFileSync(path.join(folder, "server", "a.js"), tag);
22
+ fs.writeFileSync(path.join(folder, "manifest.json"), tag);
23
+ }
24
+
25
+ describe("plugin folder sync", () => {
26
+ test("replace keeps foreign files and swaps UI folders", () => {
27
+ const root = tmp();
28
+ const folder = path.join(root, "plugin");
29
+ seed(folder, "old");
30
+ fs.writeFileSync(path.join(folder, "config.conf"), "cfg");
31
+ fs.writeFileSync(path.join(folder, "secret.key"), "key");
32
+ fs.writeFileSync(path.join(folder, "client", "stale.js"), "x");
33
+ const staging = path.join(root, ".staging");
34
+ seed(staging, "new");
35
+
36
+ replacePluginUiFiles(staging, folder);
37
+
38
+ expect(fs.readFileSync(path.join(folder, "config.conf"), "utf8")).toBe("cfg");
39
+ expect(fs.readFileSync(path.join(folder, "secret.key"), "utf8")).toBe("key");
40
+ expect(fs.readFileSync(path.join(folder, "client", "a.js"), "utf8")).toBe("new");
41
+ expect(fs.existsSync(path.join(folder, "client", "stale.js"))).toBe(false);
42
+ expect(fs.existsSync(staging)).toBe(false);
43
+ });
44
+
45
+ test("replace works when the folder only holds plugin data", () => {
46
+ const root = tmp();
47
+ const folder = path.join(root, "plugin");
48
+ fs.mkdirSync(folder);
49
+ fs.writeFileSync(path.join(folder, "secret.key"), "key");
50
+ const staging = path.join(root, ".staging");
51
+ seed(staging, "new");
52
+
53
+ replacePluginUiFiles(staging, folder);
54
+
55
+ expect(fs.readFileSync(path.join(folder, "secret.key"), "utf8")).toBe("key");
56
+ expect(fs.existsSync(path.join(folder, "server", "a.js"))).toBe(true);
57
+ });
58
+
59
+ test("remove keeps foreign files; deletes the folder when nothing else is left", () => {
60
+ const root = tmp();
61
+ const folder = path.join(root, "plugin");
62
+ seed(folder, "old");
63
+ fs.writeFileSync(path.join(folder, "config.conf"), "cfg");
64
+ removePluginUiFiles(folder);
65
+ expect(fs.readdirSync(folder)).toEqual(["config.conf"]);
66
+
67
+ const empty = path.join(root, "plain");
68
+ seed(empty, "old");
69
+ removePluginUiFiles(empty);
70
+ expect(fs.existsSync(empty)).toBe(false);
71
+ });
72
+
73
+ test("replace leaves unchanged entries untouched and swaps only what changed", () => {
74
+ const root = tmp();
75
+ const folder = path.join(root, "plugin");
76
+ seed(folder, "same");
77
+ const inode = (rel) => fs.statSync(path.join(folder, rel)).ino;
78
+ const before = { client: inode("client/a.js"), server: inode("server/a.js"), manifest: inode("manifest.json") };
79
+
80
+ const staging = path.join(root, "staging");
81
+ seed(staging, "same");
82
+ fs.writeFileSync(path.join(staging, "server", "a.js"), "new");
83
+ replacePluginUiFiles(staging, folder);
84
+
85
+ expect(inode("client/a.js")).toBe(before.client);
86
+ expect(inode("manifest.json")).toBe(before.manifest);
87
+ expect(inode("server/a.js")).not.toBe(before.server);
88
+ expect(fs.readFileSync(path.join(folder, "server", "a.js"), "utf8")).toBe("new");
89
+ expect(fs.existsSync(staging)).toBe(false);
90
+ });
91
+
92
+ test("replace notices an added or removed file in an entry", () => {
93
+ const root = tmp();
94
+ const folder = path.join(root, "plugin");
95
+ seed(folder, "same");
96
+ fs.writeFileSync(path.join(folder, "client", "stale.js"), "x");
97
+
98
+ const staging = path.join(root, "staging");
99
+ seed(staging, "same");
100
+ fs.writeFileSync(path.join(staging, "server", "extra.js"), "y");
101
+ replacePluginUiFiles(staging, folder);
102
+
103
+ expect(fs.existsSync(path.join(folder, "client", "stale.js"))).toBe(false);
104
+ expect(fs.existsSync(path.join(folder, "server", "extra.js"))).toBe(true);
105
+ });
106
+ });
@@ -0,0 +1,134 @@
1
+ import { afterEach, describe, expect, test } from "bun:test";
2
+ import fs from "fs";
3
+ import os from "os";
4
+ import path from "path";
5
+ import {
6
+ UI_OWNED_ENTRIES,
7
+ readPluginPackage,
8
+ removePluginUiFiles,
9
+ replacePluginUiFiles,
10
+ } from "../pluginFolder.util.js";
11
+ import { GET, resolveUiFile } from "../../../../theme-core/src/routes/plugins-ui-file.js";
12
+
13
+ const roots = [];
14
+ function tmp() {
15
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "plugin-package-"));
16
+ roots.push(dir);
17
+ return dir;
18
+ }
19
+ afterEach(() => {
20
+ for (const r of roots.splice(0)) fs.rmSync(r, { recursive: true, force: true });
21
+ });
22
+
23
+ describe("package entries", () => {
24
+ test("UI_OWNED_ENTRIES lists the package entries", () => {
25
+ for (const e of ["client", "server", "manifest.json", "contract", "pano-plugin.json", "controllers", "samples"]) {
26
+ expect(UI_OWNED_ENTRIES).toContain(e);
27
+ }
28
+ });
29
+
30
+ test("replace and remove handle package entries and keep plugin data", () => {
31
+ const root = tmp();
32
+ const staging = path.join(root, "staging");
33
+ const folder = path.join(root, "plugin");
34
+ fs.mkdirSync(path.join(staging, "contract"), { recursive: true });
35
+ fs.writeFileSync(path.join(staging, "contract", "a.json"), "{}");
36
+ fs.writeFileSync(path.join(staging, "pano-plugin.json"), '{"namespace":"x"}');
37
+ fs.mkdirSync(folder);
38
+ fs.writeFileSync(path.join(folder, "config.conf"), "keep");
39
+ replacePluginUiFiles(staging, folder);
40
+ expect(fs.existsSync(path.join(folder, "contract", "a.json"))).toBe(true);
41
+ removePluginUiFiles(folder);
42
+ expect(fs.existsSync(path.join(folder, "contract"))).toBe(false);
43
+ expect(fs.existsSync(path.join(folder, "pano-plugin.json"))).toBe(false);
44
+ expect(fs.readFileSync(path.join(folder, "config.conf"), "utf8")).toBe("keep");
45
+ });
46
+ });
47
+
48
+ describe("readPluginPackage", () => {
49
+ test("folder without pano-plugin.json is an old plugin", () => {
50
+ expect(readPluginPackage(tmp())).toBeNull();
51
+ });
52
+
53
+ test("folder with pano-plugin.json gives namespace, styles, views", () => {
54
+ const dir = tmp();
55
+ fs.writeFileSync(
56
+ path.join(dir, "pano-plugin.json"),
57
+ JSON.stringify({ namespace: "market", styles: ["a.css"], views: { "market:Card": { contract: 1 } } }),
58
+ );
59
+ const pkg = readPluginPackage(dir);
60
+ expect(pkg.namespace).toBe("market");
61
+ expect(pkg.styles).toEqual(["a.css"]);
62
+ expect(Object.keys(pkg.views)).toEqual(["market:Card"]);
63
+ });
64
+
65
+ test("broken or non-object json counts as no package", () => {
66
+ const dir = tmp();
67
+ fs.writeFileSync(path.join(dir, "pano-plugin.json"), "{nope");
68
+ expect(readPluginPackage(dir)).toBeNull();
69
+ fs.writeFileSync(path.join(dir, "pano-plugin.json"), "[]");
70
+ expect(readPluginPackage(dir)).toBeNull();
71
+ });
72
+ });
73
+
74
+ describe("plugins-ui-file route", () => {
75
+ function setup() {
76
+ const root = tmp();
77
+ fs.mkdirSync(path.join(root, "p1", "contract"), { recursive: true });
78
+ fs.mkdirSync(path.join(root, "p1", "contract-evil"), { recursive: true });
79
+ fs.mkdirSync(path.join(root, "p1", "client"), { recursive: true });
80
+ fs.writeFileSync(path.join(root, "p1", "contract", "V.svelte"), "<p/>");
81
+ fs.writeFileSync(path.join(root, "p1", "contract-evil", "s.txt"), "secret");
82
+ fs.writeFileSync(path.join(root, "p1", "client", "client.mjs"), "x");
83
+ return root;
84
+ }
85
+
86
+ test("resolves a file inside the kind", () => {
87
+ const root = setup();
88
+ const r = resolveUiFile("p1", "contract", "V.svelte", root);
89
+ expect(r.filePath).toBe(path.join(path.resolve(root), "p1", "contract", "V.svelte"));
90
+ });
91
+
92
+ test("traversal is refused", () => {
93
+ const root = setup();
94
+ expect(resolveUiFile("p1", "contract", "../client/client.mjs", root).status).toBe(403);
95
+ expect(resolveUiFile("p1", "contract", "../contract-evil/s.txt", root).status).toBe(403);
96
+ expect(resolveUiFile("p1", "contract", "..\\x", root).status).toBe(403);
97
+ expect(resolveUiFile("..", "contract", "x", root).status).toBe(403);
98
+ expect(resolveUiFile("p1/../p2", "contract", "x", root).status).toBe(403);
99
+ });
100
+
101
+ test("unknown kind and client are 404", () => {
102
+ const root = setup();
103
+ expect(resolveUiFile("p1", "client", "client.mjs", root).status).toBe(404);
104
+ expect(resolveUiFile("p1", "server", "x", root).status).toBe(404);
105
+ expect(resolveUiFile("p1", "nope", "x", root).status).toBe(404);
106
+ });
107
+
108
+ test("GET serves with ETag and 304, 404 when missing", async () => {
109
+ const root = setup();
110
+ const cwd = process.cwd();
111
+ fs.mkdirSync(path.join(root, "plugins"));
112
+ fs.renameSync(path.join(root, "p1"), path.join(root, "plugins", "p1"));
113
+ process.chdir(root);
114
+ try {
115
+ const mk = (inm) => ({
116
+ params: { pluginId: "p1", kind: "contract", file: "V.svelte" },
117
+ request: new Request("http://x/", { headers: inm ? { "if-none-match": inm } : {} }),
118
+ });
119
+ const res = await GET(mk());
120
+ expect(res.status).toBe(200);
121
+ expect(res.headers.get("content-type")).toContain("text/plain");
122
+ expect(res.headers.get("x-content-type-options")).toBe("nosniff");
123
+ const etag = res.headers.get("etag");
124
+ expect(etag).toBeTruthy();
125
+ expect((await GET(mk(etag))).status).toBe(304);
126
+ const missing = await GET({ params: { pluginId: "p1", kind: "contract", file: "nope.js" }, request: new Request("http://x/") });
127
+ expect(missing.status).toBe(404);
128
+ const bad = await GET({ params: { pluginId: "p1", kind: "contract", file: "../client/client.mjs" }, request: new Request("http://x/") });
129
+ expect(bad.status).toBe(403);
130
+ } finally {
131
+ process.chdir(cwd);
132
+ }
133
+ });
134
+ });