Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ Document new variables in `README.md` and `.env.example`; don't read `env` ad ho
- Run `npm run format`.
- British English.
- Use `resolve()` from `$app/paths` for internal links and `goto` (`svelte/no-navigation-without-resolve`).
- **Redirects**: never wrap `throw redirect()` in try-catch; put it after the try-catch.
- **Redirects and errors**: `redirect()` and `error()` throw by themselves, so call them without `throw` (`only-throw-error`). Never call `redirect()` inside a try-catch; put it after the try-catch.

```typescript
try {
await operation();
} catch (err) {
return fail(500, { error: 'Failed' });
}
throw redirect(303, '/path');
redirect(303, '/path');
```

- **Public routes**: add unauthenticated paths to `PUBLIC_PATHS` in `hooks.server.ts`. `/metrics` and `/healthz` are permanently public — never put auth in front of them.
Expand Down
4 changes: 1 addition & 3 deletions e2e/storage/context-menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ test.describe('Storage S3 — Context Menu', () => {
await page.getByRole('button', { name: 'Delete permanently' }).click();

await expect(page.getByText('This folder is empty')).toBeVisible();
await expect(await objectExists(client, credentials.bucket, `${prefix}ctx-del.txt`)).toBe(
false
);
expect(await objectExists(client, credentials.bucket, `${prefix}ctx-del.txt`)).toBe(false);
} finally {
await deleteKnownKeys(client, credentials.bucket, cleanupKeys);
}
Expand Down
12 changes: 4 additions & 8 deletions e2e/storage/delete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ test.describe('Storage S3 — Delete & Selection', () => {
await page.getByRole('dialog').getByRole('button', { name: 'Delete permanently' }).click();

await expect(page.getByText('This folder is empty')).toBeVisible();
await expect(await objectExists(client, credentials.bucket, `${prefix}remove-me.txt`)).toBe(
expect(await objectExists(client, credentials.bucket, `${prefix}remove-me.txt`)).toBe(false);
expect(await objectExists(client, credentials.bucket, `${prefix}archive/nested.txt`)).toBe(
false
);
await expect(
await objectExists(client, credentials.bucket, `${prefix}archive/nested.txt`)
).toBe(false);
} finally {
await deleteKnownKeys(client, credentials.bucket, cleanupKeys);
}
Expand Down Expand Up @@ -151,7 +149,7 @@ test.describe('Storage S3 — Delete & Selection', () => {
page.getByRole('menuitem', { name: 'Download' }).click()
]);
expect(await download.failure()).toBeNull();
expect(await readFile((await download.path())!, 'utf8')).toBe(body);
expect(await readFile(await download.path(), 'utf8')).toBe(body);
}

await page.getByRole('button', { name: 'Toggle selection mode' }).click();
Expand Down Expand Up @@ -193,9 +191,7 @@ test.describe('Storage S3 — Delete & Selection', () => {

await expect(page.getByText('This action cannot be undone.')).not.toBeVisible();
await expect(rowByName(page, 'keep-me.txt')).toBeVisible();
await expect(await objectExists(client, credentials.bucket, `${prefix}keep-me.txt`)).toBe(
true
);
expect(await objectExists(client, credentials.bucket, `${prefix}keep-me.txt`)).toBe(true);
} finally {
await deleteKnownKeys(client, credentials.bucket, cleanupKeys);
}
Expand Down
8 changes: 4 additions & 4 deletions e2e/storage/download.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test.describe('Storage S3 — Download', () => {

expect(download.suggestedFilename()).toBe('download-me.txt');
expect(await download.failure()).toBeNull();
expect(await readFile((await download.path())!, 'utf8')).toBe('download content');
expect(await readFile(await download.path(), 'utf8')).toBe('download content');
} finally {
await deleteKnownKeys(client, credentials.bucket, cleanupKeys);
}
Expand Down Expand Up @@ -135,7 +135,7 @@ test.describe('Storage S3 — Download', () => {
]);
expect(download.suggestedFilename()).toMatch(/\.zip$/);
expect(await download.failure()).toBeNull();
const zip = new AdmZip(await readFile((await download.path())!));
const zip = new AdmZip(await readFile(await download.path()));
// Entries are named relative to the current folder; the content is the full key.
const entryName = (key: string) => key.slice(prefix.length);
expect(
Expand Down Expand Up @@ -168,7 +168,7 @@ test.describe('Storage S3 — Download', () => {
history.getByRole('button', { name: 'Download all', exact: true }).first().click()
]);
expect(await redownload.failure()).toBeNull();
const recreatedZip = new AdmZip(await readFile((await redownload.path())!));
const recreatedZip = new AdmZip(await readFile(await redownload.path()));
for (const key of cleanupKeys) expect(recreatedZip.readAsText(entryName(key))).toBe(key);
} finally {
await deleteKnownKeys(client, credentials.bucket, cleanupKeys);
Expand Down Expand Up @@ -197,7 +197,7 @@ test.describe('Storage S3 — Download', () => {
const [download] = await Promise.all([page.waitForEvent('download'), downloadBtn.click()]);
expect(download.suggestedFilename()).toMatch(/\.zip$/);
expect(await download.failure()).toBeNull();
const zip = new AdmZip(await readFile((await download.path())!));
const zip = new AdmZip(await readFile(await download.path()));
// Entries are named relative to the current folder; the content is the full key.
for (const key of cleanupKeys) expect(zip.readAsText(key.slice(prefix.length))).toBe(key);
} finally {
Expand Down
4 changes: 2 additions & 2 deletions e2e/storage/permissions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ test.describe('Storage S3 — Permissions', () => {
uploadModal.getByText('Access denied. You do not have permission to upload here.')
).toBeVisible();
await uploadModal.getByRole('button', { name: 'Done' }).click();
await expect(await objectExists(adminClient, restrictedBucket, blockedKey)).toBe(false);
expect(await objectExists(adminClient, restrictedBucket, blockedKey)).toBe(false);

await page.getByRole('button', { name: 'Toggle selection mode' }).click();
await page.getByLabel(`Select ${existingKey}`).check();
Expand All @@ -78,7 +78,7 @@ test.describe('Storage S3 — Permissions', () => {
.filter({ hasText: 'Access denied. You do not have permission to delete this item.' });
await expect(errorToast).toBeVisible();
await expect(rowByName(page, existingKey)).toBeVisible();
await expect(await getObjectText(adminClient, restrictedBucket, existingKey)).toBe('keep me');
expect(await getObjectText(adminClient, restrictedBucket, existingKey)).toBe('keep me');
} finally {
await deleteKnownKeys(adminClient, restrictedBucket, [existingKey, blockedKey]);
}
Expand Down
26 changes: 12 additions & 14 deletions e2e/storage/upload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ test.describe('Storage S3 — Upload', () => {
await expect(uploadModal.getByText('2 uploaded · 0 skipped · 0 failed')).toBeVisible();
await uploadModal.getByRole('button', { name: 'Done' }).click();
await expect(rowByName(page, fixture.name)).toBeVisible();
await expect(await getObjectText(client, credentials.bucket, key)).toBe(fixture.fullText);
expect(await getObjectText(client, credentials.bucket, key)).toBe(fixture.fullText);
} finally {
await transfer.dispose();
}
Expand Down Expand Up @@ -137,20 +137,20 @@ test.describe('Storage S3 — Upload', () => {
await expect(rowByName(page, csvFixture.name)).toBeVisible();
await expect(rowByName(page, imageFixture.name)).toBeVisible();

await expect(
expect(
await getObjectText(client, credentials.bucket, `${prefix}${textFixture.name}`)
).toContain(textFixture.expectedSnippet);
await expect(
expect(
await getObjectText(client, credentials.bucket, `${prefix}${csvFixture.name}`)
).toContain(csvFixture.expectedCell);

await expect(
expect(
(await headObject(client, credentials.bucket, `${prefix}${textFixture.name}`)).ContentType
).toBe('text/plain');
await expect(
expect(
(await headObject(client, credentials.bucket, `${prefix}${csvFixture.name}`)).ContentType
).toBe('text/csv');
await expect(
expect(
(await headObject(client, credentials.bucket, `${prefix}${imageFixture.name}`)).ContentType
).toBe('image/svg+xml');

Expand Down Expand Up @@ -254,19 +254,17 @@ test.describe('Storage S3 — Upload', () => {
await expect(rowByName(page, 'fresh.txt')).toBeVisible();
await expect(rowByName(page, 'renamed.txt')).toBeVisible();

await expect(await getObjectText(client, credentials.bucket, `${prefix}replace.txt`)).toBe(
expect(await getObjectText(client, credentials.bucket, `${prefix}replace.txt`)).toBe(
'new replace'
);
await expect(await getObjectText(client, credentials.bucket, `${prefix}skip.txt`)).toBe(
'old skip'
);
await expect(await getObjectText(client, credentials.bucket, `${prefix}taken.txt`)).toBe(
expect(await getObjectText(client, credentials.bucket, `${prefix}skip.txt`)).toBe('old skip');
expect(await getObjectText(client, credentials.bucket, `${prefix}taken.txt`)).toBe(
'old taken'
);
await expect(await getObjectText(client, credentials.bucket, `${prefix}renamed.txt`)).toBe(
expect(await getObjectText(client, credentials.bucket, `${prefix}renamed.txt`)).toBe(
'new taken'
);
await expect(await getObjectText(client, credentials.bucket, `${prefix}fresh.txt`)).toBe(
expect(await getObjectText(client, credentials.bucket, `${prefix}fresh.txt`)).toBe(
'brand new'
);
} finally {
Expand Down Expand Up @@ -297,7 +295,7 @@ test.describe('Storage S3 — Upload', () => {
await uploadModal.getByRole('button', { name: 'Upload', exact: true }).click();

await expect(uploadModal.getByRole('alert')).toContainText('Nothing was uploaded');
await expect(await getObjectText(client, credentials.bucket, key)).toBe('old content');
expect(await getObjectText(client, credentials.bucket, key)).toBe('old content');

// Once the check works again, the retry finds the conflict instead of overwriting.
await page.unroute('**/api/storage/download?*', failHead);
Expand Down
9 changes: 5 additions & 4 deletions e2e/support/start-mock-trino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ http
res.end('<html>502 Bad Gateway from proxy.internal</html>');
return;
}
pollQuery(executing[1], Number(executing[2])).then((page) => sendJson(res, page));
void pollQuery(executing[1], Number(executing[2])).then((page) => sendJson(res, page));
return;
}
if (req.method === 'GET' && url.pathname === '/v1/info') {
Expand All @@ -377,8 +377,8 @@ http
}

let body = '';
req.on('data', (c: Buffer) => (body += c));
req.on('end', async () => {
req.on('data', (c: Buffer) => (body += c.toString()));
const respond = async () => {
// Logged on arrival, so tests can act while a gated submit is still pending.
const id = `q-mock-${++queryCounter}`;
queries.set(id, { sql: body, pages: [] });
Expand Down Expand Up @@ -406,6 +406,7 @@ http
// Unique id per submit so cancellations can be traced back to the statement.
const match = routes.find(([key]) => body.includes(key));
sendJson(res, { ...(match ? match[1] : DEFAULT_RESPONSE), id });
});
};
req.on('end', () => void respond());
})
.listen(MOCK_TRINO_PORT, 'localhost', () => console.log(`Mock Trino on :${MOCK_TRINO_PORT}`));
45 changes: 25 additions & 20 deletions e2e/trino/connection-form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { MOCK_TRINO_URL } from '../support/mock-trino';
* The test server is env-configured, so the real action rejects every save.
* This only exercises the client-side success path.
*/
function interceptSaveSuccess(page: import('@playwright/test').Page) {
page.route(
async function interceptSaveSuccess(page: import('@playwright/test').Page) {
await page.route(
(url) => url.pathname === '/trino' && url.search === '?/save',
async (route, request) => {
// Echo the client's form id back, otherwise superforms ignores the response.
Expand Down Expand Up @@ -59,11 +59,11 @@ function interceptSaveSuccess(page: import('@playwright/test').Page) {
* - __data.json uses devalue.stringify with indexed arrays where booleans
* are stored at positions referenced by the shape object at index 0
*/
function interceptPageData(
async function interceptPageData(
page: import('@playwright/test').Page,
overrides: Record<string, boolean>
) {
page.route('**/trino', async (route, request) => {
await page.route('**/trino', async (route, request) => {
if (request.resourceType() !== 'document') return route.continue();
const response = await route.fetch();
let html = await response.text();
Expand All @@ -75,7 +75,7 @@ function interceptPageData(
await route.fulfill({ response, body: html });
});

page.route('**/trino/__data.json*', async (route) => {
await page.route('**/trino/__data.json*', async (route) => {
const response = await route.fetch();
const json = await response.json();
for (const node of json.nodes ?? []) {
Expand All @@ -91,17 +91,22 @@ function interceptPageData(
});
}

/** Capture the fields posted by the next `?/save` request and abort it. */
function captureSave(page: import('@playwright/test').Page): Promise<URLSearchParams> {
return new Promise((resolve) => {
page.route(
(url) => url.pathname === '/trino' && url.search === '?/save',
async (route, request) => {
resolve(new URLSearchParams(request.postData() ?? ''));
await route.abort();
}
);
});
/**
* Capture the fields posted by the next `?/save` request and abort it.
* Resolves once the route is registered; `posted` resolves with the captured fields.
*/
async function captureSave(
page: import('@playwright/test').Page
): Promise<{ posted: Promise<URLSearchParams> }> {
const { promise, resolve } = Promise.withResolvers<URLSearchParams>();
await page.route(
(url) => url.pathname === '/trino' && url.search === '?/save',
async (route, request) => {
resolve(new URLSearchParams(request.postData() ?? ''));
await route.abort();
}
);
return { posted: promise };
}

// ---------------------------------------------------------------------------
Expand All @@ -115,7 +120,7 @@ test.describe('Connection form (insecure TLS allowed)', () => {
localStorage.removeItem('trino_url');
localStorage.removeItem('trino_tls_insecure');
});
interceptPageData(page, { trinoConfigured: false, allowInsecureTls: true });
await interceptPageData(page, { trinoConfigured: false, allowInsecureTls: true });
});

test('skipping TLS verification is posted, persisted and shown in the summary', async ({
Expand All @@ -128,7 +133,7 @@ test.describe('Connection form (insecure TLS allowed)', () => {
await page.getByLabel('Skip TLS certificate verification').check();
await expect(page.getByText('TLS unverified')).toBeVisible();

const posted = captureSave(page);
const { posted } = await captureSave(page);
await page.getByRole('button', { name: 'Save' }).click();

expect((await posted).get('tlsInsecure')).toBe('on');
Expand Down Expand Up @@ -166,7 +171,7 @@ test.describe('Connection form (manual mode)', () => {
localStorage.removeItem('trino_password');
});

interceptPageData(page, { trinoConfigured: false });
await interceptPageData(page, { trinoConfigured: false });
});

test('connection form is visible', async ({ page }) => {
Expand Down Expand Up @@ -353,7 +358,7 @@ test.describe('Connection form (manual mode)', () => {

test('saving a connection clears previous query results', async ({ page }) => {
await setTabSql(page, 'SELECT id, name FROM users');
interceptSaveSuccess(page);
await interceptSaveSuccess(page);

await page.goto('/trino');
await waitForHydration(page);
Expand Down
7 changes: 7 additions & 0 deletions e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// Lets the typescript-eslint project service type-check the E2E tests, which the root
// tsconfig (based on the one SvelteKit generates) doesn't cover.
"extends": "../tsconfig.json",
"include": ["./**/*.ts"],
"exclude": []
}
40 changes: 37 additions & 3 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default defineConfig(
includeIgnoreFile(gitignorePath),
{ ignores: ['src/lib/editor/generated/**'] },
js.configs.recommended,
...ts.configs.recommended,
...ts.configs.recommendedTypeChecked,
...svelte.configs.recommended,
{ ...security.configs.recommended, files: ['**/*.ts'] },
prettier,
Expand All @@ -44,15 +44,37 @@ export default defineConfig(
}
},
{
files: ['**/*.svelte', '**/*.svelte.ts', '**/*.svelte.js'],
languageOptions: {
parserOptions: {
projectService: true,
projectService: {
// Root config files that no tsconfig includes.
allowDefaultProject: [
'drizzle.config.ts',
'playwright.config.ts',
'vitest.arch.config.ts'
]
},
extraFileExtensions: ['.svelte'],
parser: ts.parser
}
},
rules: {
// Untyped JSON, third-party data and test mocks make up nearly all of the ~1,000 hits;
// svelte-check with `strict` already covers the typed code. See #411.
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
// Mostly async functions that implement an async interface without awaiting; style, not bugs.
'@typescript-eslint/require-await': 'off'
}
},
{
// Plain JS files (root configs, server.js, CLI scripts) are outside every tsconfig.
files: ['**/*.js', '**/*.mjs'],
...ts.configs.disableTypeChecked
},
{
files: ['src/**/*.svelte'],
plugins: { 'better-tailwindcss': betterTailwindcss },
Expand Down Expand Up @@ -101,6 +123,18 @@ export default defineConfig(
files: ['**/*.{test,spec}.ts', 'e2e/**/*.ts', 'src/architecture-tests/**/*.ts'],
rules: { 'security/detect-non-literal-fs-filename': 'off' }
},
{
files: ['**/*.{test,spec}.ts', '**/*.test-utils.ts'],
rules: {
// `expect(mock.method).toHaveBeenCalled()` passes methods around unbound by design.
'@typescript-eslint/unbound-method': 'off',
// Async `mockImplementation()`s for mocks typed with a void return.
'@typescript-eslint/no-misused-promises': [
'error',
{ checksVoidReturn: { arguments: false } }
]
}
},
{
files: ['src/**/*.ts'],
ignores: ['src/**/*.test.ts', 'src/**/*.spec.ts'],
Expand Down
Loading
Loading