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:
Maurice
2026-10-10 21:23:37 +02:00
parent f4e518b2df
commit 724c88c201
1978 changed files with 78448 additions and 39347 deletions
@@ -5,6 +5,21 @@
* ciphertext, only DECLARED user-scope keys are accepted, and the runtime read
* (ctx.settings) returns the decrypted value.
*/
import { PluginActions } from '../../../src/db/entities/PluginActions.entity';
import { PluginCapabilityAudit } from '../../../src/db/entities/PluginCapabilityAudit.entity';
import { PluginEgressHosts } from '../../../src/db/entities/PluginEgressHosts.entity';
import { PluginErrorLog } from '../../../src/db/entities/PluginErrorLog.entity';
import { PluginSettingsFields } from '../../../src/db/entities/PluginSettingsFields.entity';
import { PluginUserConfig } from '../../../src/db/entities/PluginUserConfig.entity';
import { Plugins } from '../../../src/db/entities/Plugins.entity';
import { PluginUserSettingsService } from '../../../src/nest/plugins/plugin-user-settings.service';
import { PluginsService } from '../../../src/nest/plugins/plugins.service';
import { createSnapshotTestDb } from '../../helpers/db-mock';
import { insertRow, insertRows } from '../../helpers/factories/rows';
import { createTestAddonsService } from '../../helpers/test-addons';
import { sharedTestOrm } from '../../helpers/test-uow';
import Database from 'better-sqlite3';
import { describe, it, expect, beforeEach, vi } from 'vitest';
// Reversible crypto stub so we can assert encrypt-at-rest without a real key env.
@@ -14,22 +29,11 @@ vi.mock('../../../src/nest/common/crypto/apiKeyCrypto', () => ({
}));
const { getDb } = vi.hoisted(() => ({ getDb: { current: null as unknown } }));
vi.mock('../../../src/db/database', () => ({ get db() { return getDb.current; } }));
import { createTestAddonsService } from '../../helpers/test-addons';
import { createSnapshotTestDb } from '../../helpers/db-mock';
import Database from 'better-sqlite3';
import { PluginsService } from '../../../src/nest/plugins/plugins.service';
import { PluginUserSettingsService } from '../../../src/nest/plugins/plugin-user-settings.service';
import { sharedTestOrm } from '../../helpers/test-uow';
import { Plugins } from '../../../src/db/entities/Plugins.entity';
import { PluginErrorLog } from '../../../src/db/entities/PluginErrorLog.entity';
import { PluginEgressHosts } from '../../../src/db/entities/PluginEgressHosts.entity';
import { PluginSettingsFields } from '../../../src/db/entities/PluginSettingsFields.entity';
import { PluginActions } from '../../../src/db/entities/PluginActions.entity';
import { PluginUserConfig } from '../../../src/db/entities/PluginUserConfig.entity';
import { PluginCapabilityAudit } from '../../../src/db/entities/PluginCapabilityAudit.entity';
import { insertRow, insertRows } from '../../helpers/factories/rows';
vi.mock('../../../src/db/database', () => ({
get db() {
return getDb.current;
},
}));
/** Plan 3j Task 2 — PluginsService's own six repositories, over whichever fresh `getDb.current` the caller just set. */
async function makePluginsService(): Promise<PluginsService> {
@@ -61,7 +65,15 @@ async function freshDb() {
await insertRows(await sharedTestOrm(d), PluginSettingsFields, [
{ plugin_id: 'p', field_key: 'apiKey', input_type: 'text', required: 1, secret: 1, scope: 'user', sort_order: 0 },
{ plugin_id: 'p', field_key: 'units', input_type: 'select', required: 0, secret: 0, scope: 'user', sort_order: 1 },
{ plugin_id: 'p', field_key: 'adminOnly', input_type: 'text', required: 0, secret: 1, scope: 'instance', sort_order: 2 },
{
plugin_id: 'p',
field_key: 'adminOnly',
input_type: 'text',
required: 0,
secret: 1,
scope: 'instance',
sort_order: 2,
},
]);
return d;
}
@@ -82,13 +94,13 @@ describe('per-user plugin settings', () => {
it('lists only the user-scope fields, in order', async () => {
const fields = await svc.userSettingsFields('p');
expect(fields.map(f => f.key)).toEqual(['apiKey', 'units']); // not the instance field
expect(fields.map((f) => f.key)).toEqual(['apiKey', 'units']); // not the instance field
expect(fields[0]).toMatchObject({ secret: true, required: true });
});
it('encrypts a secret at rest, masks it to the client, stores a plain field verbatim', async () => {
const masked = await svc.updateUserConfig('p', 42, { apiKey: 'sk-123', units: 'metric' });
expect(masked.apiKey).toBe('••••••••'); // never echoed
expect(masked.apiKey).toBe('••••••••'); // never echoed
expect(masked.units).toBe('metric');
// decrypted runtime read returns the real value; the stored form is ciphertext
expect(await (await userSettings()).readOne('p', 42, 'apiKey')).toBe('sk-123');
@@ -105,14 +117,17 @@ describe('per-user plugin settings', () => {
it('ignores keys that are not declared user-scope fields', async () => {
// apiKey is required — filled here so the save isn't refused; the assertion is
// about adminOnly/bogus being dropped, not about required enforcement.
await svc.updateUserConfig('p', 42, { apiKey: 'sk-123', adminOnly: 'nope', bogus: 'x', units: 'metric' } as Record<string, unknown>);
await svc.updateUserConfig('p', 42, { apiKey: 'sk-123', adminOnly: 'nope', bogus: 'x', units: 'metric' } as Record<
string,
unknown
>);
const cfg = await svc.getUserConfig('p', 42);
expect(cfg.adminOnly).toBeUndefined(); // instance field — not accepted here
expect(cfg.bogus).toBeUndefined();
expect(cfg.units).toBe('metric');
});
it('is per-user — one user cannot see another\'s value', async () => {
it("is per-user — one user cannot see another's value", async () => {
// apiKey is required — filled here so the save isn't refused; the point of this
// test is that user 99 sees none of user 42's values.
await svc.updateUserConfig('p', 42, { apiKey: 'sk-123', units: 'metric' });
@@ -130,9 +145,36 @@ describe('manifest defaults reach the runtime reads', () => {
getDb.current = await freshDb();
svc = await makePluginsService();
await insertRows(await currentOrm(), PluginSettingsFields, [
{ plugin_id: 'p', field_key: 'region', input_type: 'select', required: 0, secret: 0, scope: 'user', sort_order: 3, default_value: JSON.stringify('eu') },
{ plugin_id: 'p', field_key: 'retries', input_type: 'number', required: 0, secret: 0, scope: 'user', sort_order: 4, default_value: JSON.stringify(3) },
{ plugin_id: 'p', field_key: 'endpoint', input_type: 'text', required: 1, secret: 0, scope: 'user', sort_order: 5, default_value: JSON.stringify('https://api.example') },
{
plugin_id: 'p',
field_key: 'region',
input_type: 'select',
required: 0,
secret: 0,
scope: 'user',
sort_order: 3,
default_value: JSON.stringify('eu'),
},
{
plugin_id: 'p',
field_key: 'retries',
input_type: 'number',
required: 0,
secret: 0,
scope: 'user',
sort_order: 4,
default_value: JSON.stringify(3),
},
{
plugin_id: 'p',
field_key: 'endpoint',
input_type: 'text',
required: 1,
secret: 0,
scope: 'user',
sort_order: 5,
default_value: JSON.stringify('https://api.example'),
},
]);
});
@@ -150,7 +192,12 @@ describe('manifest defaults reach the runtime reads', () => {
it('readAll folds defaults in for the fields the user left unset', async () => {
await svc.updateUserConfig('p', 42, { apiKey: 'sk-123', region: 'us' });
expect(await (await userSettings()).readAll('p', 42)).toMatchObject({ apiKey: 'sk-123', region: 'us', retries: 3, endpoint: 'https://api.example' });
expect(await (await userSettings()).readAll('p', 42)).toMatchObject({
apiKey: 'sk-123',
region: 'us',
retries: 3,
endpoint: 'https://api.example',
});
});
it('hasRequired treats a required field with a default as filled', async () => {
@@ -171,7 +218,13 @@ describe('hasRequired applies the same "filled" rule as the save gate', () => {
getDb.current = await freshDb();
svc = await makePluginsService();
await insertRow(await currentOrm(), PluginSettingsFields, {
plugin_id: 'p', field_key: 'consent', input_type: 'checkbox', required: 1, secret: 0, scope: 'user', sort_order: 9,
plugin_id: 'p',
field_key: 'consent',
input_type: 'checkbox',
required: 1,
secret: 0,
scope: 'user',
sort_order: 9,
});
});
@@ -182,7 +235,10 @@ describe('hasRequired applies the same "filled" rule as the save gate', () => {
it('treats a whitespace-only value as empty', async () => {
await insertRow(await currentOrm(), PluginUserConfig, {
plugin_id: 'p', user_id: 42, config: JSON.stringify({ apiKey: ' ', consent: true }), updated_at: '',
plugin_id: 'p',
user_id: 42,
config: JSON.stringify({ apiKey: ' ', consent: true }),
updated_at: '',
});
expect(await (await userSettings()).hasRequired('p', 42)).toBe(false);
});