mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-22 15:06:32 +00:00
style: format server and shared with prettier
A mechanical prettier --write over server/src, server/tests, server/scripts and shared/src with the workspaces' .prettierrc; nothing but layout and import order changes, and every file keeps the same set of imports. shared is formatted throughout and its format baseline is empty. The server baseline keeps the 35 files that Prettier would grow past their lint:size limit (they need a split first, which is not a formatting change), and the generated entity files stay as their generator writes them.
This commit is contained in:
@@ -3,11 +3,16 @@
|
||||
* idempotent, reads/writes work against the plugin's OWN file, and the guard
|
||||
* blocks statements that would let a plugin escape its file (ATTACH/PRAGMA).
|
||||
*/
|
||||
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
||||
import {
|
||||
PluginDataDb,
|
||||
removePluginData,
|
||||
snapshotAllPluginDataDbs,
|
||||
} from '../../../src/nest/plugins/host/plugin-data.service';
|
||||
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { PluginDataDb, removePluginData, snapshotAllPluginDataDbs } from '../../../src/nest/plugins/host/plugin-data.service';
|
||||
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
||||
|
||||
let tmp: string;
|
||||
beforeAll(() => {
|
||||
@@ -41,8 +46,12 @@ describe('PluginDataDb', () => {
|
||||
expect(() => db.exec("ATTACH DATABASE 'trek.db' AS core")).toThrow(/not allowed/);
|
||||
expect(() => db.query('PRAGMA table_info(x)')).toThrow(/not allowed/);
|
||||
// WITH RECURSIVE is the unbounded-CPU vector on the synchronous host — refused
|
||||
expect(() => db.query('WITH RECURSIVE r(x) AS (SELECT 1 UNION ALL SELECT x+1 FROM r) SELECT x FROM r')).toThrow(/not allowed/);
|
||||
expect(() => db.exec('WITH RECURSIVE r(x) AS (SELECT 1 UNION ALL SELECT x+1 FROM r) INSERT INTO t SELECT x FROM r')).toThrow(/not allowed/);
|
||||
expect(() => db.query('WITH RECURSIVE r(x) AS (SELECT 1 UNION ALL SELECT x+1 FROM r) SELECT x FROM r')).toThrow(
|
||||
/not allowed/,
|
||||
);
|
||||
expect(() =>
|
||||
db.exec('WITH RECURSIVE r(x) AS (SELECT 1 UNION ALL SELECT x+1 FROM r) INSERT INTO t SELECT x FROM r'),
|
||||
).toThrow(/not allowed/);
|
||||
expect(() => db.exec(123 as unknown as string)).toThrow(/must be a string/);
|
||||
expect(() => db.query('x'.repeat(100_001))).toThrow(/too long/);
|
||||
db.close();
|
||||
@@ -71,13 +80,20 @@ describe('PluginDataDb', () => {
|
||||
{ sql: 'SELECT id, bal FROM acct ORDER BY id' },
|
||||
]);
|
||||
expect(out.results[0]).toEqual({ changes: 1 });
|
||||
expect(out.results[2]).toEqual({ rows: [{ id: 1, bal: 60 }, { id: 2, bal: 40 }] });
|
||||
expect(out.results[2]).toEqual({
|
||||
rows: [
|
||||
{ id: 1, bal: 60 },
|
||||
{ id: 2, bal: 40 },
|
||||
],
|
||||
});
|
||||
|
||||
// failure path: a later statement throws → the earlier write must NOT persist
|
||||
expect(() => db.tx([
|
||||
{ sql: 'UPDATE acct SET bal = 0 WHERE id = ?', args: [1] },
|
||||
{ sql: 'INSERT INTO nonexistent (x) VALUES (1)' },
|
||||
])).toThrow();
|
||||
expect(() =>
|
||||
db.tx([
|
||||
{ sql: 'UPDATE acct SET bal = 0 WHERE id = ?', args: [1] },
|
||||
{ sql: 'INSERT INTO nonexistent (x) VALUES (1)' },
|
||||
]),
|
||||
).toThrow();
|
||||
expect(db.query('SELECT bal FROM acct WHERE id = 1')).toEqual([{ bal: 60 }]); // unchanged
|
||||
|
||||
// guard + caps apply inside a batch too
|
||||
@@ -87,12 +103,12 @@ describe('PluginDataDb', () => {
|
||||
|
||||
// a raw COMMIT inside the batch must be refused (else it breaks atomicity), but a
|
||||
// CASE ... END expression (END not at statement start) stays allowed
|
||||
expect(() => db.tx([
|
||||
{ sql: 'UPDATE acct SET bal = 0 WHERE id = ?', args: [1] },
|
||||
{ sql: 'COMMIT' },
|
||||
])).toThrow(/transaction-control/);
|
||||
expect(db.tx([{ sql: "SELECT CASE WHEN bal > 0 THEN 'y' ELSE 'n' END AS s FROM acct WHERE id = 1" }]).results[0])
|
||||
.toEqual({ rows: [{ s: 'y' }] });
|
||||
expect(() => db.tx([{ sql: 'UPDATE acct SET bal = 0 WHERE id = ?', args: [1] }, { sql: 'COMMIT' }])).toThrow(
|
||||
/transaction-control/,
|
||||
);
|
||||
expect(
|
||||
db.tx([{ sql: "SELECT CASE WHEN bal > 0 THEN 'y' ELSE 'n' END AS s FROM acct WHERE id = 1" }]).results[0],
|
||||
).toEqual({ rows: [{ s: 'y' }] });
|
||||
// the row cap is now for the WHOLE batch, not per statement
|
||||
db.exec('CREATE TABLE big (n INTEGER)');
|
||||
db.exec('INSERT INTO big (n) VALUES ' + Array.from({ length: 400 }, (_, i) => `(${i})`).join(','));
|
||||
@@ -158,7 +174,9 @@ describe('PluginDataDb', () => {
|
||||
// runs. Each statement committed on its own, as Database#exec ran them, so the
|
||||
// three stay.
|
||||
expect(() =>
|
||||
db.exec('INSERT INTO log VALUES (1); INSERT INTO log VALUES (2); INSERT INTO log VALUES (3); INSERT INTO log VALUES (4);'),
|
||||
db.exec(
|
||||
'INSERT INTO log VALUES (1); INSERT INTO log VALUES (2); INSERT INTO log VALUES (3); INSERT INTO log VALUES (4);',
|
||||
),
|
||||
).toThrow('exec exceeded its 80 ms time budget');
|
||||
// One row back, so the check itself reads the clock only at its start.
|
||||
expect(db.query('SELECT group_concat(n) AS ns FROM (SELECT n FROM log ORDER BY n)')).toEqual([{ ns: '1,2,3' }]);
|
||||
@@ -227,7 +245,9 @@ describe('PluginDataDb', () => {
|
||||
db.exec(' -- nothing to run\n/* nor here */');
|
||||
expect(db.query('SELECT count(*) AS n FROM notes')).toEqual([{ n: 2 }]);
|
||||
// The statements before a failing one have run, and the failure is SQLite's own.
|
||||
expect(() => db.exec("INSERT INTO notes (body) VALUES ('x'); INSERT INTO missing VALUES (1);")).toThrow(/no such table/);
|
||||
expect(() => db.exec("INSERT INTO notes (body) VALUES ('x'); INSERT INTO missing VALUES (1);")).toThrow(
|
||||
/no such table/,
|
||||
);
|
||||
expect(db.query('SELECT count(*) AS n FROM notes')).toEqual([{ n: 3 }]);
|
||||
// A statement left open at the end reports what Database#exec reported.
|
||||
expect(() => db.exec('CREATE TRIGGER t AFTER INSERT ON notes BEGIN SELECT 1;')).toThrow('incomplete input');
|
||||
|
||||
Reference in New Issue
Block a user